ThirdSpeciesWolf

Gallery
Tutorial
Click on the image to view it full size

The Modelica By Example target code is:


within ModelicaByExample.Components.LotkaVolterra.Examples;
model ThirdSpecies "Adding a third species to Lotka-Volterra"
  import ModelicaByExample.Components.LotkaVolterra.Components.RegionalPopulation.InitializationOptions.FixedPopulation;
  extends ClassicLotkaVolterra(rabbits(initial_population=25), foxes(initial_population=2));
  Components.RegionalPopulation wolves(init=FixedPopulation, initial_population=4)
    annotation ...
  Components.Starvation wolf_starvation(gamma=0.4)
    annotation ...
  Components.Predation wolf_predation(beta=0.04, delta=0.08) "Wolves eating Foxes"
    annotation ...
  Components.Predation wolf_rabbit_predation(beta=0.02, delta=0.01) "Wolves eating rabbits"
    annotation ...
equation
  connect(wolf_predation.b, wolves.species) annotation ...
  connect(wolf_rabbit_predation.a, rabbits.species) annotation ...
  connect(wolf_predation.a, foxes.species) annotation ...
  connect(wolf_starvation.species, wolves.species) annotation ...
  connect(wolves.species, wolf_rabbit_predation.b) annotation ...
  annotation ...
end ThirdSpecies;

(In this SysML trail version the base was called FoxRabbitWithInit and the extension ThirdSpeciesWolf.)

The Modelica By Example page also gives this patch diagram:

This page contains content quoted, copied, or adapted for educational purposes from the Modelica By Example tutorials for educational purposes. The original © copyright is retained by Dr. Michael M. Tiller.

The exported complete Modelica code for the SysML/SysPhS block ThirdSpeciesWolf is:


model ThirdSpeciesWolf
  ThirdSpeciesWolf _ThirdSpeciesWolf;
  model ThirdSpeciesWolf
    extends FoxRabbitWithInit(redeclare RegionalPopulation r(p.start=25.0,p.fixed=true),redeclare RegionalPopulation f(p.start=2.0,p.fixed=true));
    RegionalPopulation w(p.start=4.0,p.fixed=true);
    Predation wfP(beta.start=0.04,beta.fixed=true,delta.start=0.08,delta.fixed=true);
    Predation wrP(beta.start=0.02,beta.fixed=true,delta.start=0.01,delta.fixed=true);
    Starvation wS(gamma.start=0.4,gamma.fixed=true);
  equation
    connect(frP.a,r.s);
    connect(r.s,rR.s);
    connect(wrP.a,r.s);
    connect(f.s,frP.b);
    connect(fS.s,f.s);
    connect(wS.s,w.s);
    connect(w.s,wrP.b);
    connect(w.s,wfP.b);
    connect(wfP.a,f.s);
  end ThirdSpeciesWolf;
  model FoxRabbitWithInit
    replaceable RegionalPopulation f;
    replaceable RegionalPopulation r;
    Starvation fS(gamma.start=0.4,gamma.fixed=true);
    Reproduction rR(alpha.start=0.1,alpha.fixed=true);
    Predation frP(beta.start=0.02,beta.fixed=true,delta.start=0.02,delta.fixed=true);
  equation
    connect(fS.s,f.s);
    connect(frP.b,f.s);
    connect(frP.a,r.s);
    connect(r.s,rR.s);
  end FoxRabbitWithInit;
  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;
  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 Starvation
    extends SinkOrSource;
    parameter Rate gamma;
  equation
    decline=gamma*s.p;
  end Starvation;
  connector SpeciesFlowElement
    Population p;
    flow Rate r;
  end SpeciesFlowElement;
  model Reproduction
    extends SinkOrSource;
    parameter Rate alpha;
  equation
    growth=alpha*s.p;
  end Reproduction;
  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;
  model SinkOrSource
    Rate growth;
    Rate decline;
    SpeciesFlowElement s;
  equation
    decline=-growth;
    s.r=decline;
  end SinkOrSource;
  type Population=Real;
  type Rate=Real(unit="1/s");
end ThirdSpeciesWolf;

Dr Darren says:

It executes better if you choose nice icons.

The next Modelica By Example section on Speed Measurement Revisited is skipped here because:

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