diff --git a/simulation/modelica/synchronous/Makefile b/simulation/modelica/synchronous/Makefile index 6a5bff3429e..8bb59e292a3 100644 --- a/simulation/modelica/synchronous/Makefile +++ b/simulation/modelica/synchronous/Makefile @@ -1,6 +1,7 @@ TEST = ../../../rtest -v TESTFILES = \ +boolSubClocks.mos \ Bug3503.mos \ EventClock.mos \ EventClock_cpp.mos \ diff --git a/simulation/modelica/synchronous/boolSubClocks.mo b/simulation/modelica/synchronous/boolSubClocks.mo new file mode 100644 index 00000000000..65ef1981bae --- /dev/null +++ b/simulation/modelica/synchronous/boolSubClocks.mo @@ -0,0 +1,56 @@ +within ; +model boolSubClocks +// Rational interval clock 1 +Clock u = Clock(3, 10); // ticks: 0, 3/10, 6/10 +Clock y1 = shiftSample(u,3); // ticks: 9/10, 12/10, +Clock y2 = backSample(y1,2); // ticks: 3/10, 6/10, +//Clock y3 = backSample(y1,4); // error (ticks before u) +Clock y4 = shiftSample(u,2,3); // ticks: 2/10, 5/10, +Clock y5 = backSample(y4,1,3); // ticks: 1/10, 4/10, +// Boolean clock +Clock v = Clock(sin(2*Modelica.Constants.pi*time) > 0, 0); // ticks: 0, 1.0, 2.0, 3.0, +Clock z1 = shiftSample(v,3); // ticks: 3.0, 4.0, +Clock z2 = backSample(z1,2); // ticks: 1.0, 2.0, + +Real x1,x2,x3,x4,x5,x6; +Real a1,a2,a3; +Real b1,b2; +equation + when sample(1.3, 0.5) then + b1 = time; + end when; + when u then + x1 = sample(time); + end when; + when y1 then + x2 = sample(time); + end when; + when y2 then + x3 = sample(time); + end when; + when y4 then + x4 = sample(time); + end when; + when y5 then + x5 = sample(time); + end when; + when u then + x6 = sample(time); + end when; + + when v then + a1 = sample(time); + end when; + when z1 then + a2 = sample(time); + end when; + when z2 then + a3 = sample(time); + end when; + when sample(0.8, 1.5) then + b2 = 1.5*time; + end when; + annotation (uses(Modelica(version="3.2.1")), + experiment(StopTime=5), + __Dymola_experimentSetupOutput); +end boolSubClocks; diff --git a/simulation/modelica/synchronous/boolSubClocks.mos b/simulation/modelica/synchronous/boolSubClocks.mos new file mode 100644 index 00000000000..e221e2e1603 --- /dev/null +++ b/simulation/modelica/synchronous/boolSubClocks.mos @@ -0,0 +1,52 @@ +// name: boolSubClocks +// keywords: synchronous features, cpp +// status: correct +// +loadModel(Modelica, languageStandard="3.3");getErrorString(); + +loadFile("boolSubClocks.mo"); +setCommandLineOptions("+simCodeTarget=Cpp"); getErrorString(); + +simulate(boolSubClocks); getErrorString(); +val(a1,2.5); +val(a2,2.5); +val(a2,3.0); +val(a3,2.5); +val(x1,0.5); +val(x1,1.0); +val(x2,0.5); +val(x2,1.0); +val(x3,2.5); +val(x4,0.5); +val(x4,1.0); +val(x5,0.5); +val(x5,1.0); + +// Result: +// true +// "" +// true +// true +// "" +// record SimulationResult +// resultFile = "boolSubClocks_res.mat", +// simulationOptions = "startTime = 0.0, stopTime = 5.0, numberOfIntervals = 500, tolerance = 1e-006, method = 'dassl', fileNamePrefix = 'boolSubClocks', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''", +// messages = "" +// end SimulationResult; +// "Warning: Requested package Modelica of version 3.2.1, but this package was already loaded with version 3.2.2. You might experience problems if these versions are incompatible. +// Warning: The initial conditions are not fully specified. For more information set -d=initialization. In OMEdit Tools->Options->Simulation->OMCFlags, in OMNotebook call setCommandLineOptions("-d=initialization"). +// " +// 2.000000000159155 +// 0.0 +// 0.0 +// 2.000000000159155 +// 0.3 +// 0.8999999999999999 +// 0.0 +// 0.8999999999999999 +// 2.4 +// 0.5 +// 0.8 +// 0.4 +// 1.0 +// endResult