Skip to content

Commit

Permalink
Added state machine tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhard-thiele committed Sep 18, 2015
1 parent 25b7068 commit 0a122d1
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 0 deletions.
12 changes: 12 additions & 0 deletions simulation/modelica/statemachines/DeadEnd.mo
@@ -0,0 +1,12 @@
within;
model DeadEnd
model State1
end State1;
State1 state1;
model State2
end State2;
State2 state2;
equation
transition(state1, state2, true, immediate=false);
initialState(state1);
end DeadEnd;
21 changes: 21 additions & 0 deletions simulation/modelica/statemachines/DeadEnd.mos
@@ -0,0 +1,21 @@
// name: DeadEnd
// keywords: state machines
// status: correct
//

loadFile("DeadEnd.mo");
simulate(DeadEnd, startTime=0, stopTime=2, numberOfIntervals=0); getErrorString();
val(state1.active,2);
val(state2.active,2);

// Result:
// true
// record SimulationResult
// resultFile = "DeadEnd_res.mat",
// simulationOptions = "startTime = 0.0, stopTime = 2.0, numberOfIntervals = 0, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'DeadEnd', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''",
// messages = ""
// end SimulationResult;
// ""
// 0.0
// 1.0
// endResult
69 changes: 69 additions & 0 deletions simulation/modelica/statemachines/MLS33_17_3_7NA.mo
@@ -0,0 +1,69 @@
within ;
block MLS33_17_3_7NA "Example from the MLS 3.3, Section 17.3.7, No Annotations"
inner Integer v(start=0);
model State1
inner Integer count(start=0);
inner outer output Integer v;
StateA stateA;
StateB stateB;
StateC stateC;
StateD stateD;
StateX stateX;
StateY stateY;
model StateA
outer output Integer v;
equation
v = previous(v) + 2;
end StateA;

model StateB
outer output Integer v;
equation
v = previous(v) - 1;
end StateB;

model StateC
outer output Integer count;
equation
count = previous(count) + 1;
end StateC;

model StateD
end StateD;
equation
initialState(stateA);
transition(stateA, stateB, v >= 6, immediate=false);
transition(stateB, stateC, v == 0, immediate=false);
transition(stateC, stateA, true, immediate=false, priority=2);
transition(stateC, stateD, count >= 2, immediate=false);
public
model StateX
outer input Integer v;
Integer i(start=0);
Integer w;
equation
i = previous(i) + 1;
w = v;
end StateX;

model StateY
Integer j(start=0);
equation
j = previous(j) + 1;
end StateY;
equation
transition(stateX, stateY, stateX.i > 20, immediate=false);
initialState(stateX);
end State1;
State1 state1;
model State2
outer output Integer v;
equation
v = previous(v) + 5;
end State2;
State2 state2;
equation
transition(state1, state2, activeState(state1.stateD) and activeState(state1.stateY), immediate=false);
transition(state2, state1, v >= 20, immediate=false);
initialState(state1);
end MLS33_17_3_7NA;
20 changes: 20 additions & 0 deletions simulation/modelica/statemachines/MLS33_17_3_7NA.mos
@@ -0,0 +1,20 @@
// name: MLS33_17_3_7NA
// keywords: state machines
// status: correct
//

loadFile("MLS33_17_3_7NA.mo");
simulate(MLS33_17_3_7NA, startTime=0, stopTime=30, numberOfIntervals=0); getErrorString();
val(v,30.0);

// Result:
// true
// record SimulationResult
// resultFile = "MLS33_17_3_7NA_res.mat",
// simulationOptions = "startTime = 0.0, stopTime = 30.0, numberOfIntervals = 0, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'MLS33_17_3_7NA', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''",
// messages = ""
// end SimulationResult;
// "Warning: The initial conditions are not fully specified. Use +d=initialization for more information.
// "
// 18.0
// endResult
3 changes: 3 additions & 0 deletions simulation/modelica/statemachines/Makefile
Expand Up @@ -6,10 +6,13 @@ Maraninchi2003_2.mos \
SMMin.mos \
TicksInState.mos \
TimeInState.mos \
MLS33_17_3_7NA.mos \
DeadEnd.mos \

# test that currently fail. Move up when fixed.
# Run make failingtest
FAILINGTESTFILES = \
SingleState.mos \


# Dependency files that are not .mo .mos or Makefile
Expand Down
8 changes: 8 additions & 0 deletions simulation/modelica/statemachines/SingleState.mo
@@ -0,0 +1,8 @@
within;
model SingleState
model State1
end State1;
State1 state1;
equation
initialState(state1);
end SingleState;
18 changes: 18 additions & 0 deletions simulation/modelica/statemachines/SingleState.mos
@@ -0,0 +1,18 @@
// name: SingleState
// keywords: state machines
// status: correct
//

loadFile("SingleState.mo");
simulate(SingleState, startTime=0, stopTime=2, numberOfIntervals=0); getErrorString();

// Result:
// true
// record SimulationResult
// resultFile = "SingleState_res.mat",
// simulationOptions = "startTime = 0.0, stopTime = 20.0, numberOfIntervals = 0, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'DeadEnd', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''",
// messages = ""
// end SimulationResult;
// "Warning: The initial conditions are not fully specified. Use +d=initialization for more information.
// "
// endResult

0 comments on commit 0a122d1

Please sign in to comment.