Skip to content

Commit

Permalink
Extend and update synchronous tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rfranke committed Mar 5, 2016
1 parent 6739ebe commit 2cb99bf
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 12 deletions.
1 change: 1 addition & 0 deletions openmodelica/cppruntime/Makefile
Expand Up @@ -6,6 +6,7 @@ WhenStatement1.mos \
BouncingBall.mos \
clockedTest.mos \
clockedEventTest.mos \
clockedSolverTest.mos \
clockedTypesTest.mos \
mathFunctionsTest.mos \
functionPointerTest.mos \
Expand Down
22 changes: 10 additions & 12 deletions openmodelica/cppruntime/clockedEventTest.mos
Expand Up @@ -6,23 +6,21 @@
setCommandLineOptions("+simCodeTarget=Cpp");

loadString("
model EventClock
Boolean pulse(start = false, fixed = true);
Integer count(start = 0);
model EventClock \"See Modelica 3.3 spec, section 16.3 Clock Constructors\"
Integer nextInterval(start = 1);
Real nextTick(start = 0);
equation
when sample(0, 0.1) then
pulse = not pre(pulse);
end when;
when Clock(pulse) then
count = previous(count) + 1;
when Clock(time > hold(nextTick) / 210) then
nextInterval = previous(nextInterval) + 1;
nextTick = previous(nextTick) + nextInterval;
end when;
end EventClock;
");
getErrorString();

simulate(EventClock);
val(count, 0.0);
val(count, 1.0);
val(nextInterval, 0.0);
val(nextInterval, 1.0);
getErrorString();

// Result:
Expand All @@ -34,7 +32,7 @@ getErrorString();
// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'EventClock', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''",
// messages = ""
// end SimulationResult;
// 1.0
// 6.0
// 2.0
// 21.0
// ""
// endResult
53 changes: 53 additions & 0 deletions openmodelica/cppruntime/clockedSolverTest.mos
@@ -0,0 +1,53 @@
// name: clockedSolverTest
// keywords: synchronous clocked equations, continuous equations
// status: correct
// teardown_command: rm -f *SolverMethod*

setCommandLineOptions("+simCodeTarget=Cpp");

loadString("
model SolverMethod \"Continuous PI controller in a clocked partition;
see Modelica 3.3 spec, section 16.8.3 Associating a Solver to a Partition\"
parameter Real Ti = 200/1000, k = 2;
parameter Real ref = 1;
Real x(start = 0, fixed = true);
Real xd(start = 0);
Real vd, e, u;
equation
// controller
vd = sample(x, Clock(Clock(50,1000), solverMethod = \"ImplicitEuler\"));
e = ref-vd;
der(xd) = e/Ti;
u = k*(e + xd);
// physical model
0.2*der(x) = hold(u);
end SolverMethod;
");
getErrorString();

simulate(SolverMethod);
val(x, 0.0);
val(x, 0.3);
val(x, 1.0);
val(xd, 0.0);
val(xd, 0.3);
val(xd, 1.0);
getErrorString();

// Result:
// true
// true
// ""
// record SimulationResult
// resultFile = "SolverMethod_res.mat",
// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'SolverMethod', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''",
// messages = ""
// end SimulationResult;
// 0.0
// 1.214168548583985
// 0.998146335431809
// 0.25
// 0.186729431152344
// -0.0010129555314779
// ""
// endResult

0 comments on commit 2cb99bf

Please sign in to comment.