SinkOrSource - Reproduction - Starvation

Gallery
Tutorial

The Modelica By Example target code is:


within ModelicaByExample.Components.LotkaVolterra.Interfaces;
partial model SinkOrSource "Used to describe single species effects"

  Species species
    annotation ...
protected
  Real growth "Growth in the population (if positive)";
  Real decline "Decline in the population (if positive)";
equation
  decline = -growth;
  species.rate = decline;
end SinkOrSource;

within ModelicaByExample.Components.LotkaVolterra.Components;
model Reproduction "Model of reproduction"
  extends Interfaces.SinkOrSource;
  parameter Real alpha "Birth rate proportionality constant";
equation
  growth = alpha*species.population "Growth is proporational to population";
end Reproduction;

within ModelicaByExample.Components.LotkaVolterra.Components;
model Starvation "Model of starvation"
  extends Interfaces.SinkOrSource;
  parameter Real gamma "Starvation coefficient";
equation
  decline = gamma*species.population
    "Decline is proporational to population (competition)";
end Starvation;

The exported Modelica code for SinkOrSource is:


model SinkOrSource
  SinkOrSource _SinkOrSource;
  model SinkOrSource
    Rate growth;
    Rate decline;
    SpeciesFlowElement s;
  equation
    decline=-growth;
    s.r=decline;
  end SinkOrSource;
  type Rate=Real(unit="1/s");
  connector SpeciesFlowElement
    Population p;
    flow Rate r;
  end SpeciesFlowElement;
  type Population=Real;
end SinkOrSource;

The exported Modelica code for Reproduction is:


model Reproduction
  Reproduction _Reproduction;
  model Reproduction
    extends SinkOrSource;
    parameter Rate alpha;
  equation
    growth=alpha*s.p;
  end Reproduction;
  model SinkOrSource
    Rate growth;
    Rate decline;
    SpeciesFlowElement s;
  equation
    decline=-growth;
    s.r=decline;
  end SinkOrSource;
  type Rate=Real(unit="1/s");
  connector SpeciesFlowElement
    Population p;
    flow Rate r;
  end SpeciesFlowElement;
  type Population=Real;
end Reproduction;

The exported Modelica code for Starvation is:


model Starvation
  Starvation _Starvation;
  model Starvation
    extends SinkOrSource;
    parameter Rate gamma;
  equation
    decline=gamma*s.p;
  end Starvation;
  model SinkOrSource
    Rate growth;
    Rate decline;
    SpeciesFlowElement s;
  equation
    decline=-growth;
    s.r=decline;
  end SinkOrSource;
  type Rate=Real(unit="1/s");
  connector SpeciesFlowElement
    Population p;
    flow Rate r;
  end SpeciesFlowElement;
  type Population=Real;
end Starvation;
Up next
Notes
Snippets (quotes/extracts)
Visit also
Visit also (backlinks)
Related slides (includes other tutorials)
Related slides (backlinks, includes other tutorials)
External links