Lotka-Volterra Systems - QuiescentModelWithModifications

Click on the image to view it full size
The Modelica By Example target code (using 'initial equation') is:

model ClassicModel "This is the typical equation-oriented model"
  parameter Real alpha=0.1 "Reproduction rate of prey";
  parameter Real beta=0.02 "Mortality rate of predator per prey";
  parameter Real gamma=0.4 "Mortality rate of predator";
  parameter Real delta=0.02 "Reproduction rate of predator per prey";
  parameter Real x0=10 "Start value of prey population";
  parameter Real y0=10 "Start value of predator population";
  Real x(start=x0) "Prey population";
  Real y(start=y0) "Predator population";
  der(x) = x*(alpha-beta*y);
  der(y) = y*(delta*x-gamma);
end ClassicModel;

model QuiescentModelWithInheritance "Steady state model with inheritance"
  extends ClassicModel;
initial equation
  der(x) = 0;
  der(y) = 0;
end QuiescentModelWithInheritance;

model QuiescentModelWithModifications "Steady state model with modifications"
  extends QuiescentModelWithInheritance(gamma=0.3, delta=0.01);
end QuiescentModelWithModifications;

Because of various limitation of SysPhS-1.1 some workarounds were once again required to get this one to work. Indeed for the sake of demonstrating inheritance and redefinition of values, in this trail version the QuiescentModelUsingStart was extended.

The exported Modelica code is:

model QuiescentModelWithModifications
  QuiescentModelWithModifications _QuiescentModelWithModifications;
  model QuiescentModelWithModifications
    extends QuiescentModelUsingStart(redeclare Real gamma(start=0.3,fixed=true),redeclare Real delta(start=0.01,fixed=true),redeclare Real x(start=30.0,fixed=true));
  end QuiescentModelWithModifications;
  model QuiescentModelUsingStart
    parameter Real alpha(start=0.1,fixed=true);
    parameter Real beta(start=0.02,fixed=true);
    replaceable parameter Real gamma(start=0.4,fixed=true);
    replaceable parameter Real delta(start=0.02,fixed=true);
    replaceable Real x(start=20.0,fixed=true);
    Real y(start=5.0,fixed=true);
    Real dx(start=0.0,fixed=true);
    Real dy(start=0.0,fixed=true);
  end QuiescentModelUsingStart;
end QuiescentModelWithModifications;

Because of the lack of explicit support for 'initial equation', additional variables dx and dy with equations dx = der(x) and dy = der(y) with start values 0 were introduced in the SysPhS version. But they are not in fact compatible with the non-fixed 'start' values in the Modelica University version. That doesn't matter for the Modelica University version, but it does matter if you try to mimic it with SysPhS, because currently (in SysPhS-1.1) default values are always assumed to be 'fixed', not mere "suggestions" for iteration variables:

Wolfram SystemModeler correctly complains if you use x(start=10,fixed=true) and y(start=10,fixed=true).

To get around this, in the SysPhS version a HACK was used, the "correct" steady values x=30 and y=5 were chosen as forced default values (not that here in fact x is also an override). Then it validates in Wolfram SystemModeler and runs (and you can see it indeed flat-lines at those values).

Up next
Snippets (quotes/extracts)
Visit also
Visit also (backlinks)
Related slides (includes other tutorials)
Related slides (backlinks, includes other tutorials)
External links