diff options
Diffstat (limited to 'modelica-parser-lalrpop/examples/modelica_models')
9 files changed, 116 insertions, 0 deletions
diff --git a/modelica-parser-lalrpop/examples/modelica_models/bar.mo b/modelica-parser-lalrpop/examples/modelica_models/bar.mo new file mode 100644 index 0000000..288f3b4 --- /dev/null +++ b/modelica-parser-lalrpop/examples/modelica_models/bar.mo @@ -0,0 +1,17 @@ +model Bar "Massless bar with two mechanical cuts." + MbsCut a b; + parameter + Position3 r[3] = [0, 0, 0] + "Position vector from the origin of cut-frame A" + " to the origin of cut-frame B"; +equation + // Kinematic relationships of cut-frame A and B + b.S = a.S; + b.r0 = a.r0 + a.S*r; + // Relations between the forces and torques acting at + // cut-frame A and B + 0 = a.f + b.f; + 0 = a.t + b.t - cross(r, a.f); + // The function cross defines the cross product + // of two vectors +end Bar; diff --git a/modelica-parser-lalrpop/examples/modelica_models/breaking_pendulum.mo b/modelica-parser-lalrpop/examples/modelica_models/breaking_pendulum.mo new file mode 100644 index 0000000..87b58d3 --- /dev/null +++ b/modelica-parser-lalrpop/examples/modelica_models/breaking_pendulum.mo @@ -0,0 +1,21 @@ +model BreakingPendulum3 + parameter Real m=1, g=9.81; + input Boolean Broken; + input Real u; + Real pos[2], vel[2]; + constant Real PI=3.141592653589793; + Real phi(start=PI/4), phid; + Real L=0.5, Ldot; +equation + pos = [L*sin(phi); -L*cos(phi)]; + vel = der(pos); + phid = der(phi); + Ldot = der(L); + 0 = if not Broken then [ + // Equations of pendulum + m*der(phid) + m*g*L*sin(phi) - u; + der(Ldot)] + else + // Equations of free flying mass + m*der(vel) = m*[0; -g]; +end BreakingPendulum3; diff --git a/modelica-parser-lalrpop/examples/modelica_models/heat_tank.mo b/modelica-parser-lalrpop/examples/modelica_models/heat_tank.mo new file mode 100644 index 0000000..dde1ae0 --- /dev/null +++ b/modelica-parser-lalrpop/examples/modelica_models/heat_tank.mo @@ -0,0 +1,17 @@ +model HeatTankT + parameter Area=1; + connector TankStream + Real pressure; + flow Real volumeFlowRate; + Real temp; + end TankStream; + TankStream Inlet, Outlet; + Real level; + Real temp; +equation + Area*der(level) = Inlet.volumeFlowRate + Outlet.volumeFlowRate; + Outlet.pressure = Inlet.pressure; +Area*level*der(temp) = Inlet.volumeFlowRate*Inlet.temp + + Outlet.volumeFlowRate*Outlet.temp; +Outlet.temp = temp; +end HeatTankT; diff --git a/modelica-parser-lalrpop/examples/modelica_models/minimal.mo b/modelica-parser-lalrpop/examples/modelica_models/minimal.mo new file mode 100644 index 0000000..85335a5 --- /dev/null +++ b/modelica-parser-lalrpop/examples/modelica_models/minimal.mo @@ -0,0 +1,6 @@ +model FirstOrder + parameter Real c; + Real x; +equation + der(x) = -c*x; +end FirstOrder; diff --git a/modelica-parser-lalrpop/examples/modelica_models/minimal2.mo b/modelica-parser-lalrpop/examples/modelica_models/minimal2.mo new file mode 100644 index 0000000..69790b0 --- /dev/null +++ b/modelica-parser-lalrpop/examples/modelica_models/minimal2.mo @@ -0,0 +1,8 @@ +model FirstOrder + parameter Real c; + Real x; +equation + connect(c, x); + 1 = c; + (5 + 4) = x; +end FirstOrder; diff --git a/modelica-parser-lalrpop/examples/modelica_models/minimal3.mo b/modelica-parser-lalrpop/examples/modelica_models/minimal3.mo new file mode 100644 index 0000000..1e9a211 --- /dev/null +++ b/modelica-parser-lalrpop/examples/modelica_models/minimal3.mo @@ -0,0 +1,8 @@ +model MinimalModel + parameter Real a; + Real b; +equation + connect(a, b); + a = 1; + b = (abs(a) + 2) / 4; +end FirstOrder; diff --git a/modelica-parser-lalrpop/examples/modelica_models/polynomial_evaluator.mo b/modelica-parser-lalrpop/examples/modelica_models/polynomial_evaluator.mo new file mode 100644 index 0000000..f11d375 --- /dev/null +++ b/modelica-parser-lalrpop/examples/modelica_models/polynomial_evaluator.mo @@ -0,0 +1,14 @@ +block PolynomialEvaluator + parameter Real a[:]; + input Real x; + output Real y; +protected + constant n = size(a, 1)-1; + Real xpowers[n+1]; +equation + xpowers[1] = 1; + for i in 1:n loop + xpowers[i+1] = xpowers[i]*x; + end for; + y = transpose(a) * xpowers; +end PolynomialEvaluator; diff --git a/modelica-parser-lalrpop/examples/modelica_models/simple_circuit.mo b/modelica-parser-lalrpop/examples/modelica_models/simple_circuit.mo new file mode 100644 index 0000000..7c22a35 --- /dev/null +++ b/modelica-parser-lalrpop/examples/modelica_models/simple_circuit.mo @@ -0,0 +1,17 @@ +model circuit + Resistor R1(R=10); + Capacitor C(C=0.01); + Resistor R2(R=100); + Inductor L(L=0.1); + VsourceAC AC; + Ground G; + +equation + connect (AC.p, R1.p); // Capacitor circuit + connect (R1.n, C.p); + connect (C.n, AC.n); + connect (R1.p, R2.p); // Inductor circuit + connect (R2.n, L.p); + connect (L.n, C.n); + connect (AC.n, G.p); // Ground +end circuit; diff --git a/modelica-parser-lalrpop/examples/modelica_models/vsourceac.mo b/modelica-parser-lalrpop/examples/modelica_models/vsourceac.mo new file mode 100644 index 0000000..133c861 --- /dev/null +++ b/modelica-parser-lalrpop/examples/modelica_models/vsourceac.mo @@ -0,0 +1,8 @@ +model VsourceAC "Sin-wave voltage source" + extends TwoPin; + parameter Voltage VA = 220 "Amplitude"; + parameter Real f(unit="Hz") = 50 "Frequency"; + constant Real PI=3.141592653589793; +equation + v = VA*sin(2*PI*f*time); +end VsourceAC; |