Lotka-Volterra Equations Revisited - RegionalPopulation

Gallery
Tutorial
Click on the image to view it full size

The Modelica By Example target code is:


within ModelicaByExample.Components.LotkaVolterra.Components;
model RegionalPopulation "Population of animals in a specific region"
  encapsulated type InitializationOptions = enumeration(
      Free "No initial conditions",
      FixedPopulation "Specify initial population",
      SteadyState "Population initially in steady state");
parameter InitializationOptions init=InitializationOptions.Free
    annotation ...
parameter Real initial_population
    annotation ...
Interfaces.Species species
    annotation ...
protected
  Real population(start=10) = species.population "Population in this region";
initial equation
  if init==InitializationOptions.FixedPopulation then
    population = initial_population;
  elseif init==InitializationOptions.SteadyState then
    der(population) = 0;
  else
  end if;
equation
  der(population) = species.rate;
  assert(population>=0, "Population must be greater than or equal to zero");
end RegionalPopulation;

Firstly, recall that:

Additionally:

So the case of initialisation against steady state is handled in this SysML/SysPhS trail by an extending block RegionalPopulation_Steady (which is not needed in the simpler usage examples). The simpler case of initialisation against an initial population is handled at first by the explicit default 10 for p:Population.

The exported Modelica code for interface block RegionalPopulation is:


model RegionalPopulation
  RegionalPopulation _RegionalPopulation;
  model RegionalPopulation
    SpeciesFlowElement s;
    parameter Population p0;
  protected
    Population p(start=10.0,fixed=true);
  equation
    der(p)=s.r;
    p=s.p;
  end RegionalPopulation;
  connector SpeciesFlowElement
    Population p;
    flow Rate r;
  end SpeciesFlowElement;
  type Population=Real;
  type Rate=Real(unit="1/s");
end RegionalPopulation;
Up next
Notes
Snippets (quotes/extracts)
Visit also
Visit also (backlinks)
Related slides (includes other tutorials)
Related slides (backlinks, includes other tutorials)
External links