Last active
September 10, 2015 01:48
-
-
Save r-barnes/8a6e4a5c729271d12273 to your computer and use it in GitHub Desktop.
Sample Model for Syntax Highlighting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package bob | |
import Modelica.Constants; | |
function mu | |
input Real t; | |
output Real y; | |
algorithm | |
y := 2.4*abs(cos(Constants.pi/12*t)); | |
end mu; | |
function sigma | |
input Real t; | |
output Real y; | |
algorithm | |
y := 0.2+0.8*abs(sin(Constants.pi/12*t)); | |
end sigma; | |
function omega | |
input Real t; | |
output Real y; | |
algorithm | |
y := if t<6 then 0 else 0.8*abs(cos(Constants.pi/12*t)); | |
end omega; | |
function f | |
input Modelica.SIunits.Mass x; | |
output Modelica.SIunits.Mass y; | |
algorithm | |
y := 2.5*x/(1+0.01*x); | |
end f; | |
function g | |
input Modelica.SIunits.Mass x; | |
output Modelica.SIunits.Mass y; | |
algorithm | |
y := 5*x; | |
end g; | |
optimization BatchReactor(objective=-x2(finalTime), startTime = 0, finalTime = 36) | |
parameter Modelica.SIunits.Mass x1_0 = 0.3*0.05 "Lefsa"; | |
parameter Modelica.SIunits.Mass x2_0 = 0 "Potatoes"; | |
parameter Modelica.SIunits.Mass x3_0 = 0.3*0.95 "Carrots"; | |
Real x1(start=x1_0, fixed=true, min=0, max=100); | |
Real x2(start=x2_0, fixed=true, min=0, max=100); | |
Real x3(start=x3_0, fixed=true, min=0, max=100); | |
input Real v (min=0, max=1); | |
input Real v1(min=0, max=1); | |
equation | |
der(x1) = v1*g(x3)-mu(time)*x1; | |
der(x2) = (v-v1)*g(x3); | |
der(x3) = sigma(time)*f(x1)-v*g(x3)-omega(time)*x3; | |
constraint | |
v1<=v; | |
end BatchReactor; | |
end bob; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment