Problem on simulations...

8 posts / 0 new
Last post
mamuller
Offline
Joined: 2010-09-08
Problem on simulations...

Hello

I'm just starting with Modelica and JModelica.org. Before going for complicated optimizations, I'm trying to run simple dynamic simulations, in order to get to know the basics of this framework.

I wrote some simple models in the Modelica language and simulated then on JModelica, but then I found some strange problems: the results I got with JModelica didn't match the simulation of the same .mo files simulated on OpenModelica. And this last one match with other results I got from other simulation tools...

To illustrate, I made a Modelica file with 2 very simple models and 2 python scripts to simulate them on JModelica.

The first model, Test1, have a final value of J = .13, while the same model simulated on OpenModelica gives the final value of 0.006.

[img_assist|nid=300|title=|desc=JModelica's final value is about twice the one found on other simulation tools.|link=none|align=left|width=100|height=75]

[img_assist|nid=301|title=|desc=OpenModelica's final result matches other (non-modelica) simulation tools|link=none|align=left|width=100|height=60]

The second, shows an even stranger behavior: the initial condition isn't satisfied. It is defined by the "start" attribute on the variables definitions, like Real x1(start=4.605);, but it gives something like x1 = 20. OpenModelica satisfies the stated initial condition.

[img_assist|nid=302|title=|desc=JModelica's initial condition is wrong.|link=none|align=left|width=NaN|height=100]

[img_assist|nid=303|title=|desc=OpenModelica gives the right initial condition|link=none|align=left|width=100|height=60]

The simulation command on JModelica and OpenModelica is quite analogous:
JModelica: jmodelica.simulate(model,alg_args={'start_time':0.,'final_time':tfinal})
openmodelica: simulate(model,stopTime = tfinal)

I would like to have a feedback on this. Maybe I am missing something, but I believe it could be a bug or something.
What do you think?

Thanks and regards.

mamuller
Offline
Joined: 2010-09-08
I don't know what happened

I don't know what happened with the images, I uploaded and inserted them, thought they would in the body of the message...

jmattsson
Offline
Joined: 2009-10-18
One part of your problem is

One part of your problem is that the row
N = 10^12*exp(-x1);
triggers a bug in the c code generation. I am working on that, but a simple fix in your end is to use 1e12 instead of 10^12.

mamuller
Offline
Joined: 2010-09-08
Thank you for your answer,

Thank you for your answer, jmattsson.

I've changed the modelica code, but still get the wrong result.

With your suggestion, the initial value is x1.x[0] = 26.001937466750999, which is indeed different of the one I got before (x1.x[0] = 18.934470055172) but still different from the one I stated: Real x1(start=4.605);

Although I will keep this detail in mind for the other models I'm testing.

Regards.

hubertus
Offline
Joined: 2009-04-24
Initialization of states

In JModelica you have to set fixed=true for variables in order to be sure that the start value is actually used as start value. The Modelica specification does say that the default is fixed=false, and nothing can be expected w.r.t. such a value being used as start value, even for a state. Other Modelica tools often assume fixed=true for states after state selection, even though this can lead to unexpected results in case of high index problems (a variable that the user expects to be a state gets the desired start value, but is de-selected in stateselection). I think your problem will work fine if you set fixed=true for the states in the problem.

Regards

Hubertus

mamuller
Offline
Joined: 2010-09-08
Thank you, hubertus! That

Thank you, hubertus!

That worked, both simulations returned the right results.

But it isn't clear for me. I'm new to JModelica and Modelica and one thing I've been wondered is what this fixed attribute means. I haven't seen it on other Modelica examples, besides the JModelica ones.

What does the attribute fixed? To which variables should I make it true? Just the real states of the model? Any remarks for algebraic variables, inputs?

What does it means to "select a state"?

Is there any documentation on the use of Modelica language inside JModelica?

Best Regards.

hubertus
Offline
Joined: 2009-04-24
Fixed, state selection

The fixed attribute determines wether a start value for a variable is the exact value it should have at the beginnning of simulation (if set to true)or if it is a guess value. By default fixed is true for parameters/constants and false for other variables. Many other Modelica simulators also set it to true for dynamic states (in the ODe case, the variabels which have a der()-operator applied to them. In the high.index DAE-case, not all variables that have a der()-operator are also states. The dummy-derivative algorithm by S.E: Mattsson/ G. Söderlind is usually used to determine which of the variables that appear differentiated are used as real states in the integrator, and the application of that algorithm is usually called state-selection. Often there are several variables that can be selected as states, and the algorithm does not say which ones have to be selected. This can easily lead to different results between simulators, because different initial values can be chosen from the same Modelica code. In order to get the same result with JModelica as with another simulator, set the fixed attribute to true for those variales that the other simultor has chosen as states. The behavior of JModelica is, btw., exactly according to the specification, and we considered it better to choose the variabels with fixed=true explicitly.

There is no documentation for the use of the Modelica language inside JModelica. You can find a few useful documents at www.modelia.org.

mamuller
Offline
Joined: 2010-09-08
hubertus, I think I

hubertus,

I think I understand the difference. By default, for dynamic states, the start attribute value is a guess for the numeric resolution and if one wants to have it as a initial condition, one must set the attribute fixed to true.

I agree that it is the correct thing to do, in order to prevent initialization problems on higher index problems.

But there should be some documentation on it, first because this kind of issue may not be clear to everyone and second because, as you said, JModelica differs from other common Modelica tools on this aspect.

I've browsed around Modelica main site and found a lot of information. I dug what I needed to start getting things done around here.

I think it would be very nice if there would have something like a quick reference on the most relevant Modelica language aspects and also, of course, Optimica. But it's just my opinion as a beginner.

Thank you again for the help so far. Maybe I'll come up with some other difficulties I may have.
Best regards.

Login or register to post comments