aboutsummaryrefslogtreecommitdiffstats
path: root/modelica-parser-lalrpop/examples
diff options
context:
space:
mode:
Diffstat (limited to 'modelica-parser-lalrpop/examples')
-rw-r--r--modelica-parser-lalrpop/examples/README1
-rw-r--r--modelica-parser-lalrpop/examples/modelica_models/bar.mo17
-rw-r--r--modelica-parser-lalrpop/examples/modelica_models/breaking_pendulum.mo21
-rw-r--r--modelica-parser-lalrpop/examples/modelica_models/heat_tank.mo17
-rw-r--r--modelica-parser-lalrpop/examples/modelica_models/minimal.mo (renamed from modelica-parser-lalrpop/examples/minimal.modelica)0
-rw-r--r--modelica-parser-lalrpop/examples/modelica_models/minimal2.mo (renamed from modelica-parser-lalrpop/examples/minimal2.modelica)0
-rw-r--r--modelica-parser-lalrpop/examples/modelica_models/minimal3.mo (renamed from modelica-parser-lalrpop/examples/minimal3.modelica)0
-rw-r--r--modelica-parser-lalrpop/examples/modelica_models/polynomial_evaluator.mo14
-rw-r--r--modelica-parser-lalrpop/examples/modelica_models/simple_circuit.mo17
-rw-r--r--modelica-parser-lalrpop/examples/modelica_models/vsourceac.mo8
-rw-r--r--modelica-parser-lalrpop/examples/parse_file.rs34
11 files changed, 129 insertions, 0 deletions
diff --git a/modelica-parser-lalrpop/examples/README b/modelica-parser-lalrpop/examples/README
new file mode 100644
index 0000000..24da3aa
--- /dev/null
+++ b/modelica-parser-lalrpop/examples/README
@@ -0,0 +1 @@
+Most of the examples in `modelica_models` came from the Modelica 1.0 standard.
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/minimal.modelica b/modelica-parser-lalrpop/examples/modelica_models/minimal.mo
index 85335a5..85335a5 100644
--- a/modelica-parser-lalrpop/examples/minimal.modelica
+++ b/modelica-parser-lalrpop/examples/modelica_models/minimal.mo
diff --git a/modelica-parser-lalrpop/examples/minimal2.modelica b/modelica-parser-lalrpop/examples/modelica_models/minimal2.mo
index 69790b0..69790b0 100644
--- a/modelica-parser-lalrpop/examples/minimal2.modelica
+++ b/modelica-parser-lalrpop/examples/modelica_models/minimal2.mo
diff --git a/modelica-parser-lalrpop/examples/minimal3.modelica b/modelica-parser-lalrpop/examples/modelica_models/minimal3.mo
index 1e9a211..1e9a211 100644
--- a/modelica-parser-lalrpop/examples/minimal3.modelica
+++ b/modelica-parser-lalrpop/examples/modelica_models/minimal3.mo
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;
diff --git a/modelica-parser-lalrpop/examples/parse_file.rs b/modelica-parser-lalrpop/examples/parse_file.rs
new file mode 100644
index 0000000..1eb4e65
--- /dev/null
+++ b/modelica-parser-lalrpop/examples/parse_file.rs
@@ -0,0 +1,34 @@
+
+extern crate modelica_parser;
+
+use std::env;
+use std::io::Read;
+use std::fs::File;
+use std::process::exit;
+
+
+fn main() {
+
+ let args: Vec<String> = env::args().collect();
+
+ if args.len() <= 1 {
+ println!("I'm a modelica parser! Pass me one or more files to parse...");
+ exit(-1);
+ }
+
+ for input in &args[1..] {
+ let mut s = String::new();
+ if let Err(err) = File::open(input).and_then(|mut f| f.read_to_string(&mut s)) {
+ println!("=== {}: I/O Error {}",
+ input, err);
+ continue;
+ }
+
+ let result = modelica_parser::parser::parse_model(&s);
+
+ match result {
+ Ok(_) => println!("=== {}: OK", input),
+ Err(err) => println!("=== {}: ERROR\n{}", input, modelica_parser::pp_parseerror(&s, err)),
+ }
+ }
+}