Opened 10 years ago

Closed 10 years ago

Last modified 7 years ago

#3129 closed defect (fixed)

ModelicaByExample.Components.LotkaVolterra.Examples.ThreeSpecies_Quiescent doesn't simulate

Reported by: Adrian Pop Owned by: Lennart Ochel
Priority: high Milestone: 1.9.4
Component: Backend Version: trunk
Keywords: Cc: Michael Tiller

Description

There is only this model in ModelicaByExample that does not simulate:
https://test.openmodelica.org/libraries/ModelicaByExample/files/ModelicaByExample.Components.LotkaVolterra.Examples.ThreeSpecies_Quiescent.sim

The model is here:
https://github.com/xogeny/ModelicaBook
or in the OpenModelica installation

Change History (20)

comment:1 by Lennart Ochel, 10 years ago

Owner: changed from somebody to Lennart Ochel
Status: newaccepted

comment:2 by Lennart Ochel, 10 years ago

Actually, I do not see any issue. I think the model is not that well-constructed. The initial solution (0, 0, 0) for all three populations seem to be valid.

[1] Real foxes.population(start=10, nominal=1) = -4.70198e-038 (pre: 10)
[2] Real rabbits.population(start=10, nominal=1) = 0 (pre: 10)
[3] Real wolves.population(start=10, nominal=1) = 2.35099e-038 (pre: 10)

Due to numerical reasons, an assertion is triggered.
BTW: It would be good if the assertion would be a bit more helpful (see #3074). That means in this particular case, it would be good to show the assertion itself as well (foxes.population >= 0.0).

Last edited 10 years ago by Lennart Ochel (previous) (diff)

comment:3 by Lennart Ochel, 10 years ago

I just noticed that the Simulation output is not in the description:

assert            | debug   | Population must be greater than zero
assert            | info    | simulation terminated by an assertion at initialization

comment:4 by Adrian Pop, 10 years ago

Cc: Michael Tiller added

Michael, can you fix this model?

comment:5 by Lennart Ochel, 10 years ago

There is a non-linear system during initialization that need to be solved. Actually, I did not check if there is another suitable solution for this model. But if that is the case, it would probably help to modify the following start attributes:

Notification: List of all iteration variables (DAE kind: initialization)
Iteration variables of torn nonlinear equation system:
  wolves.population:VARIABLE(start = 10.0 protected = true )  "Population in this region".ModelicaByExample.Components.LotkaVolterra.Examples.ThreeSpecies_Quiescent, .ModelicaByExample.Components.LotkaVolterra.Components.RegionalPopulation$wolves, .Real type: Real 
  foxes.population:VARIABLE(start = 10.0 protected = true )  "Population in this region".ModelicaByExample.Components.LotkaVolterra.Examples.ThreeSpecies_Quiescent, .ModelicaByExample.Components.LotkaVolterra.Components.RegionalPopulation$foxes, .Real type: Real 
  rabbits.population:VARIABLE(start = 10.0 protected = true )  "Population in this region".ModelicaByExample.Components.LotkaVolterra.Examples.ThreeSpecies_Quiescent, .ModelicaByExample.Components.LotkaVolterra.Components.RegionalPopulation$rabbits, .Real type: Real

You get the above output using +d=iterationVars as omc debug flag.

comment:6 by Lennart Ochel, 10 years ago

A suitable solution seem to be:

[1] Real foxes.population = 1.66667
[2] Real rabbits.population = 26.6667
[3] Real wolves.population = 3.33333

This one can be achieved e.g. if either start value of foxes.population is set to 2 or start value of rabbits.population is set to 100.

comment:7 by Adrian Pop, 10 years ago

Lennart, maybe you can fork https://github.com/xogeny/ModelicaBook on github and then do a pull request :)

in reply to:  7 comment:8 by Lennart Ochel, 10 years ago

Replying to adrpo:

Lennart, maybe you can fork https://github.com/xogeny/ModelicaBook on github and then do a pull request :)

https://github.com/xogeny/ModelicaBook/pull/228

comment:9 by Martin Sjölund, 10 years ago

Why not add the assertions to the initial NLS so the NLS solver knows the solution is out of bounds? :)

in reply to:  9 comment:10 by Lennart Ochel, 10 years ago

Replying to sjoelund.se:

Why not add the assertions to the initial NLS so the NLS solver knows the solution is out of bounds? :)

In that case the NLS solver would still try to find the trivial solution (0, 0, 0) as it is valid.

comment:11 by Martin Sjölund, 10 years ago

Not if it knows to look for constraints or you feed it back high residuals to show that the region is invalid :)

comment:12 by Lennart Ochel, 10 years ago

The zero-solution is valid. I just think it is not the one of interest. Hence, one has to either specify additional constrains or set proper start values.

comment:13 by Martin Sjölund, 10 years ago

It's not valid if it triggers an assertion...

in reply to:  13 ; comment:14 by Lennart Ochel, 10 years ago

The assertion is not part of the alg. loop. Therefore, nothing is wrong with the calculated solution. If the NLS solver should be aware of the additional constraint on population, I propose following changes:

  • ModelicaByExample/Components/LotkaVolterra/Components/RegionalPopulation.mo

    a b  
    1313model RegionalPopulation "Population of animals in a specific region"
    1414    annotation (Placement(transformation(extent={{-10,90},{10,110}}),
    1515        iconTransformation(extent={{-10,90},{10,110}})));
    1616protected
    17   Real population(start=10) = species.population "Population in this region";
     17  Real population(start=10, min=0) = species.population "Population in this region";
    1818initial equation
    1919  if init==InitializationOptions.FixedPopulation then
  • ModelicaByExample/Components/LotkaVolterra/Components/RegionalPopulation.mo

    a b  
    2323initial equation
    2424  end if;
    2525equation
    2626  der(population) = species.rate;
    27   assert(population>=0, "Population must be greater than zero");
    2827  annotation (Diagram(graphics={Rectangle(
    2928          extent={{-100,100},{100,-100}},
    3029          lineColor={0,127,0},

in reply to:  14 ; comment:15 by Martin Sjölund, 10 years ago

Replying to lochel:

The assertion is not part of the alg. loop.

You are wrong here. It is part of the alg. loop. It is just not part of the alg. loop generated by OpenModelica.

comment:16 by Martin Sjölund, 10 years ago

Note that in Modelica, a min-attribute on a Real should expand to a corresponding assertion.
If you would argue that a min-attribute is part of the algebraic loop, so should assertions that depend only on variables in that same algebraic loop.
Related would be setting an initial equation assert(phi > -pi and phi < pi, "..."); because you want all tools to initialize to the same angle.

in reply to:  15 comment:17 by Lennart Ochel, 10 years ago

Replying to sjoelund.se:

Replying to lochel:

The assertion is not part of the alg. loop.

You are wrong here. It is part of the alg. loop. It is just not part of the alg. loop generated by OpenModelica.

Hmm ... I might agree. In that case we should open a ticket about it :-)

comment:18 by Lennart Ochel, 10 years ago

Resolution: fixed
Status: acceptedclosed

Merged #228

comment:19 by Dietmar Winkler, 9 years ago

Milestone: Futurepre1.9.4

It doesn't make sense to keep closed ticket in the "Future" milestone that were simply forgotten to assign to the correct milestone in the past.

comment:20 by Martin Sjölund, 7 years ago

Milestone: pre1.9.41.9.4

Removing the pre1.9.4 milestone in favor of 1.9.4.

Note: See TracTickets for help on using tickets.