FoxRabbitWithInit

Gallery
Tutorial
Click on the image to view it full size

The Modelica By Example page does not show the code for the usage comparison, but it does give 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 FoxRabbitWithInit is:


model FoxRabbitWithInit
  FoxRabbitWithInit _FoxRabbitWithInit;
  model FoxRabbitWithInit
    RegionalPopulation f;
    RegionalPopulation r;
    Starvation fS(gamma.start=0.4,gamma.fixed=true);
    Reproduction rR(alpha.start=0.1,alpha.fixed=true);
    Predation fP(beta.start=0.02,beta.fixed=true,delta.start=0.02,delta.fixed=true);
  equation
    connect(fS.s,f.s);
    connect(fP.b,f.s);
    connect(fP.a,r.s);
    connect(r.s,rR.s);
  end FoxRabbitWithInit;
  model RegionalPopulation
    SpeciesFlowElement s;
    Population p(start=10.0,fixed=true);
    parameter Population p0;
  equation
    der(p)=s.r;
    p=s.p;
  end RegionalPopulation;
  model Starvation
    extends SinkOrSource;
    parameter Rate gamma;
  equation
    decline=gamma*s.p;
  end Starvation;
  model Reproduction
    extends SinkOrSource;
    parameter Rate alpha;
  equation
    growth=alpha*s.p;
  end Reproduction;
  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;
  connector SpeciesFlowElement
    Population p;
    flow Rate r;
  end SpeciesFlowElement;
  model SinkOrSource
    Rate growth;
    Rate decline;
    SpeciesFlowElement s;
  equation
    decline=-growth;
    s.r=decline;
  end SinkOrSource;
  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 Population=Real;
  type Rate=Real(unit="1/s");
end FoxRabbitWithInit;
Up next
Notes
Snippets (quotes/extracts)
Visit also
Visit also (backlinks)
Related slides (includes other tutorials)
Related slides (backlinks, includes other tutorials)
External links