Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #13676 > unrolled thread
| Started by | Marco Gabiccini <m.gabiccini@ing.unipi.it> |
|---|---|
| First post | 2013-03-02 08:44 +0000 |
| Last post | 2013-03-04 03:58 +0000 |
| Articles | 3 — 2 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
Strange behavior of System Modeler Marco Gabiccini <m.gabiccini@ing.unipi.it> - 2013-03-02 08:44 +0000
Re: Strange behavior of System Modeler awnl <awnl@gmx-topmail.de> - 2013-03-04 03:58 +0000
Re: Strange behavior of System Modeler awnl <awnl@gmx-topmail.de> - 2013-03-04 03:58 +0000
| From | Marco Gabiccini <m.gabiccini@ing.unipi.it> |
|---|---|
| Date | 2013-03-02 08:44 +0000 |
| Subject | Strange behavior of System Modeler |
| Message-ID | <kgse56$jar$1@smc.vnet.net> |
Hi all, I have just started studying WSM and the Modelica language by implementing the simple pendulum model (class) es. described on p.33 of Peter Fritzson's book Introduction to "Modeling and Simulation of Technical and Physical Systems with Modelica". The code (pendulum equation written as a DAE) is: model DAEExample "DAEExample" constant Real PI=3.14159265358979; parameter Real m=1,g=9.81,l=0.5; output Real F; output Real x(start=0.5),y(start=0); output Real vx,vy; equation m*der(vx)=-x/l*F; m*der(vy)=-y/l*F - m*g; der(x)=vx; der(y)=vy; x^2 + y^2=l^2; end DAEExample; I run the example in WSM and I get totally meaningless results. The solver is the default one (DASSL) which, I think, is the right one for handling DAEs. Any ideas? Thanks, Marco Marco Gabiccini, PhD Assistant Professor of Applied Mechanics and Robotics Dept. of Mechanical, Nuclear and Production Engineering University of Pisa Via Diotisalvi 2, 56122 Pisa PI Italy Phone: +39-050-221.80.77 Fax: +39-050-221.80.65 Homepage: http://www.dimnp.unipi.it/gabiccini-m/
[toc] | [next] | [standalone]
| From | awnl <awnl@gmx-topmail.de> |
|---|---|
| Date | 2013-03-04 03:58 +0000 |
| Message-ID | <kh164p$sat$1@smc.vnet.net> |
| In reply to | #13676 |
Hi,
>
> I have just started studying WSM and the Modelica language by
> implementing the simple pendulum model (class) es. described on p.33 of
> Peter Fritzson's book Introduction to "Modeling and Simulation of
> Technical and Physical Systems with Modelica". The code (pendulum
> equation written as a DAE) is:
> model DAEExample "DAEExample"
> constant Real PI=3.14159265358979;
> parameter Real m=1,g=9.81,l=0.5;
> output Real F;
> output Real x(start=0.5),y(start=0);
> output Real vx,vy;
> equation
> m*der(vx)=-x/l*F;
> m*der(vy)=-y/l*F - m*g;
> der(x)=vx;
> der(y)=vy;
> x^2 + y^2=l^2;
> end DAEExample;
>
> I run the example in WSM and I get totally meaningless results. The
> solver is the default one (DASSL) which, I think, is the right one
> for handling DAEs.
>
> Any ideas?
If your meaningless results look similar to the ones I get it might be a deficiency of the WSM solver. The way it is written the problem is quite "unfriendly" for a numeric DAE solver and needs some more involved tricks to be solved, see e.g.:
<https://www.modelica.org/events/workshop2000/proceedings/old/Mattsson.pdf>
where the tricks that Dymola uses to get this solved are described. It came as a pleasant surprise to me that Mathematicas NDSolve (with the IndexReduction option) solves this correctly, so it might be a problem that WRI actually knows how to solve and you probably want to report this.
A workaround is of course to use a formulation that is more "friendly" to the solver, e.g. by reformulating in terms of polar coordinates (but I think Peter Fritzson might well use it in this form to demonstrate something...).
hth,
albert
(* Mathematica code for the above: *)
m=1;g=9.81;l=0.5;
res=NDSolve[{
m*vx'[t]==-x[t]/l*f[t],
m*vy'[t]==-y[t]/l*f[t]-m*g,
x'[t]==vx[t],
y'[t]==vy[t],
x[t]^2+y[t]^2==l^2,
x[0]==0.5,
vx[0]==0,
y[0]==0,
vy[0]==0
},{x,vx,y,vy,f},{t,0,5},
Method->{"IndexReduction"->Automatic}
]
xsol=x/.res[[1]]
ysol=y/.res[[1]]
Plot[{xsol[t],ysol[t]},{t,0,5}]
[toc] | [prev] | [next] | [standalone]
| From | awnl <awnl@gmx-topmail.de> |
|---|---|
| Date | 2013-03-04 03:58 +0000 |
| Message-ID | <kh164v$sb0$1@smc.vnet.net> |
| In reply to | #13676 |
Hi, > > I have just started studying WSM and the Modelica language by implementing the simple pendulum model (class) es. described on p.33 of Peter Fritzson's book Introduction to "Modeling and Simulation of Technical and Physical Systems with Modelica". The code (pendulum equation written as a DAE) is: > > model DAEExample "DAEExample" > constant Real PI=3.14159265358979; > parameter Real m=1,g=9.81,l=0.5; > output Real F; > output Real x(start=0.5),y(start=0); > output Real vx,vy; > equation > m*der(vx)=-x/l*F; > m*der(vy)=-y/l*F - m*g; > der(x)=vx; > der(y)=vy; > x^2 + y^2=l^2; > end DAEExample; > > I run the example in WSM and I get totally meaningless results. > The solver is the default one (DASSL) which, I think, is the right one for handling DAEs. > > Any ideas? Just a followup to my recent post: you can use manual state selection (dynamic state selection is one of the tricks that Dymola uses to get this right) to get correct solutions with WSM like this: model DAEExample constant Real PI=3.14159265358979; parameter Real m=1,g=9.81,l=0.5; Real F; Real x(start=0.5,stateSelect=StateSelect.always); Real y(start=0); Real vx(start=0); Real vy(start=0); equation m*der(vx) = -x/l*F; m*der(vy) = -y/l*F - m*g; der(x) = vx; der(y) = vy; x^2 + y^2 = l^2; end DAEExample; hth, albert
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web