Skip to content

Commit

Permalink
Add test for when not initial()
Browse files Browse the repository at this point in the history
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Dec 5, 2016
1 parent ee38431 commit e952f3d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions flattening/modelica/equations/Makefile
Expand Up @@ -50,6 +50,7 @@ WatchDog2EquationWhen.mo \
WaveEquationSample.mo \
WhenEquation.mo \
WhenNestedEquation.mo \
WhenNotInitial.mo \
WhenNotValid.mo \
WhenValidResult.mo \
WhenSemantics1.mo \
Expand Down
24 changes: 24 additions & 0 deletions flattening/modelica/equations/WhenNotInitial.mo
@@ -0,0 +1,24 @@
// status: incorrect

model WhenNotInitial
discrete Real r(start=0, fixed=true);
equation
when not initial() then
r=1;
end when;
end WhenNotInitial;

// Result:
// Error processing file: WhenNotInitial.mo
// [flattening/modelica/equations/WhenNotInitial.mo:6:3-8:11:writable] Warning: The standard says that initial() may only be used as a when condition (when initial() or when {..., initial(), ...}), but got condition not initial().
// [flattening/modelica/equations/WhenNotInitial.mo:6:3-8:11:writable] Error: Failed to instantiate equation
// when not initial() then
// r = 1;
// end when;.
// Error: Error occurred while flattening model WhenNotInitial
//
// # Error encountered! Exiting...
// # Please check the error message and the flags.
//
// Execution failed!
// endResult
6 changes: 5 additions & 1 deletion simulation/modelica/initialization/discreteTest06.mos
Expand Up @@ -17,16 +17,18 @@ package initializationTests
initial equation
pre(y) = 0;

equation
equation
der(x) = y;

// Disallowed in MLS 3.2r1
when initial() or time > 0.5 then
y = pre(y) + 1.0;
end when;
end discreteTest6;
end initializationTests;
"); getErrorString();

OpenModelica.Scripting.setCommandLineOptions("--std=3.1"); getErrorString();
OpenModelica.Scripting.setDebugFlags("pedantic"); getErrorString();
simulate(initializationTests.discreteTest6, startTime=0.0, stopTime=0.0); getErrorString();
res := OpenModelica.Scripting.readSimulationResult("initializationTests.discreteTest6_res.mat", {time, x, y}, 2); getErrorString();
Expand All @@ -36,6 +38,8 @@ res := OpenModelica.Scripting.readSimulationResult("initializationTests.discrete
// ""
// true
// ""
// true
// ""
// record SimulationResult
// resultFile = "initializationTests.discreteTest6_res.mat",
// simulationOptions = "startTime = 0.0, stopTime = 0.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'initializationTests.discreteTest6', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''",
Expand Down

0 comments on commit e952f3d

Please sign in to comment.