Tags and keywords
The Modelica By Example target code is:
within ModelicaByExample.Components.LotkaVolterra.Interfaces;
partial model Interaction "Used to describe interactions between two species"
Species a "Species A"
annotation ...
Species b "Species B"
annotation ...
protected
Real a_growth "Growth in population of species A (if positive)";
Real a_decline "Decline in population of species A (if positive)";
Real b_growth "Growth in population of species B (if positive)";
Real b_decline "Decline in population of species B (if positive)";
equation
a_decline = -a_growth;
a.rate = a_decline;
b_decline = -b_growth;
b.rate = b_decline;
end Interaction;
within ModelicaByExample.Components.LotkaVolterra.Components;
model Predation "Model of predation"
extends Interfaces.Interaction;
parameter Real beta "Prey (Species A) consumed";
parameter Real delta "Predators (Species B) fed";
equation
b_growth = delta*a.population*b.population;
a_decline = beta*a.population*b.population;
end Predation;
The exported Modelica code for Interaction
is:
model Interaction
Interaction _Interaction;
model Interaction
SpeciesFlowElement a;
SpeciesFlowElement b;
Rate a_growth;
Rate a_decline;
Rate b_growth;
Rate b_decline;
equation
a_decline=-a_growth;
a.r=a_decline;
b_decline=-b_growth;
b.r=b_decline;
end Interaction;
connector SpeciesFlowElement
Population p;
flow Rate r;
end SpeciesFlowElement;
type Rate=Real(unit="1/s");
type Population=Real;
end Interaction;
The exported Modelica code for Predation
is:
model Predation
Predation _Predation;
model Predation
extends Interaction;
parameter Rate beta;
parameter Rate delta;
equation
b_growth=delta*a.p*b.p;
a_decline=beta*a.p*b.p;
end Predation;
model Interaction
SpeciesFlowElement a;
SpeciesFlowElement b;
Rate a_growth;
Rate a_decline;
Rate b_growth;
Rate b_decline;
equation
a_decline=-a_growth;
a.r=a_decline;
b_decline=-b_growth;
b.r=b_decline;
end Interaction;
type Rate=Real(unit="1/s");
connector SpeciesFlowElement
Population p;
flow Rate r;
end SpeciesFlowElement;
type Population=Real;
end Predation;