diff --git a/Examples/System/getCPUclock_ex01.mo b/Examples/System/getCPUclock_ex01.mo new file mode 100644 index 0000000..5437993 --- /dev/null +++ b/Examples/System/getCPUclock_ex01.mo @@ -0,0 +1,11 @@ +within InteractiveSimulation.Examples.System; + +model getCPUclock_ex01 + extends Modelica.Icons.Example; + InteractiveSimulation.System.getCPUclock CPUtime annotation( + Placement(transformation(origin = {-22, 56}, extent = {{-10, -10}, {10, 10}}))); +equation + +annotation( + experiment(StartTime = 0, StopTime = 100, Tolerance = 1e-06, Interval = 0.001)); +end getCPUclock_ex01; diff --git a/Examples/System/package.order b/Examples/System/package.order index 663acdf..48710d8 100644 --- a/Examples/System/package.order +++ b/Examples/System/package.order @@ -1,3 +1,6 @@ RunPyScript00_ex01 RunPyScript01_ex01 C_runPyScript00_ex01 +getCPUclock_ex01 +terminateWhenTriggered_ex01 +terminateByCPUtimer_ex01 diff --git a/Examples/System/terminateByCPUtimer_ex01.mo b/Examples/System/terminateByCPUtimer_ex01.mo new file mode 100644 index 0000000..d986119 --- /dev/null +++ b/Examples/System/terminateByCPUtimer_ex01.mo @@ -0,0 +1,13 @@ +within InteractiveSimulation.Examples.System; + +model terminateByCPUtimer_ex01 + extends Modelica.Icons.Example; + InteractiveSimulation.System.terminateByCPUtimer terminateByCPUtimer(tTerminate = 5) annotation( + Placement(transformation(origin = {-32, 48}, extent = {{-10, -10}, {10, 10}}))); + InteractiveSimulation.System.getCPUclock CPUtime annotation( + Placement(transformation(origin = {-62, 76}, extent = {{-10, -10}, {10, 10}}))); +equation + +annotation( + experiment(StartTime = 0, StopTime = 1000, Tolerance = 1e-06, Interval = 0.001)); +end terminateByCPUtimer_ex01; diff --git a/Examples/System/terminateWhenTriggered_ex01.mo b/Examples/System/terminateWhenTriggered_ex01.mo new file mode 100644 index 0000000..bd8240f --- /dev/null +++ b/Examples/System/terminateWhenTriggered_ex01.mo @@ -0,0 +1,14 @@ +within InteractiveSimulation.Examples.System; + +model terminateWhenTriggered_ex01 + extends Modelica.Icons.Example; + InteractiveSimulation.System.terminateWhenTriggered TerminateWhenTriggered annotation( + Placement(transformation(origin = {22, 38}, extent = {{-10, -10}, {10, 10}}))); + Modelica.Blocks.Sources.BooleanStep sourceTrigger(startTime = 50) annotation( + Placement(transformation(origin = {-22, 38}, extent = {{-10, -10}, {10, 10}}))); +equation + connect(sourceTrigger.y, TerminateWhenTriggered.u_trigger) annotation( + Line(points = {{-10, 38}, {10, 38}}, color = {255, 0, 255})); +annotation( + experiment(StartTime = 0, StopTime = 100, Tolerance = 1e-06, Interval = 0.001)); +end terminateWhenTriggered_ex01; diff --git a/Input/getCPUclock.bak-mo b/Input/getCPUclock.bak-mo new file mode 100644 index 0000000..7033af2 --- /dev/null +++ b/Input/getCPUclock.bak-mo @@ -0,0 +1,8 @@ +within InteractiveSimulation.Input; + +block getCPUclock + + + + +end getCPUclock; diff --git a/Output/dispVarPyConsole02_00.mo b/Output/dispVarPyConsole02_00.mo index aa2ce7e..3cdcaa4 100644 --- a/Output/dispVarPyConsole02_00.mo +++ b/Output/dispVarPyConsole02_00.mo @@ -7,7 +7,7 @@ block dispVarPyConsole02_00 import Modelica.Utilities.Streams; import Modelica.Utilities.Files; import Modelica.Utilities.System; - import Modelica.SIunits; + import units = Modelica.Units.SI; import InteractiveSimulation.Output.Functions; /******************************************************** Declaration @@ -22,7 +22,7 @@ block dispVarPyConsole02_00 parameter String nameVariables[nVariables] = {"var1"}; - parameter Modelica.SIunits.Time tInterval = 0.1 "in [s]"; + parameter units.Time tInterval = 0.1 "in [s]"; /* --------------------------------------------- diff --git a/System/getCPUclock.mo b/System/getCPUclock.mo new file mode 100644 index 0000000..4c2e768 --- /dev/null +++ b/System/getCPUclock.mo @@ -0,0 +1,37 @@ +within InteractiveSimulation.System; + +model getCPUclock + "CPU time since commence of simulation" + parameter Integer sigDigits=4; + + import units= Modelica.Units.SI; + + discrete units.Time tCPUsimBegin; + units.Time tCPUnow; + + + Modelica.Blocks.Interfaces.RealOutput y_CPUtime(quantity = "Time", unit = "s", displayUnit = "s") "[s]" annotation( + Placement(transformation(origin = {110, -2}, extent = {{-10, -10}, {10, 10}}), iconTransformation(origin = {110, 0}, extent = {{-10, -10}, {10, 10}}))); + +//*************************************************************************** +initial algorithm + + tCPUsimBegin:= Modelica_DeviceDrivers.OperatingSystem.clock(dummy=0.0) /1000.0; + +algorithm + tCPUnow:= Modelica_DeviceDrivers.OperatingSystem.clock(dummy=0.0) /1000.0; + + //----------------------------------- + when (time==0.0)then + tCPUsimBegin:= tCPUnow; + end when; + //----------------------------------- + + y_CPUtime:= tCPUnow-tCPUsimBegin; + + annotation( + defaultComponentName = "CPUtime", + Icon(graphics = {Rectangle(fillColor = {255, 255, 255}, fillPattern = FillPattern.Solid, extent = {{-100, 100}, {100, -100}}), Text(origin = {-1, 34}, extent = {{-95, 22}, {95, -22}}, textString = "CPU time"), Text(origin = {0, -27}, extent = {{-80, 13}, {80, -13}}, textString = DynamicSelect("0.0", String(y_CPUtime, sigDigits, 0, true))), Text(origin = {65, -46}, extent = {{-19, 10}, {19, -10}}, textString = "[s]")})); + + +end getCPUclock; diff --git a/System/package.order b/System/package.order index aaa7111..8fb4232 100644 --- a/System/package.order +++ b/System/package.order @@ -1,4 +1,7 @@ Functions +getCPUclock +terminateWhenTriggered +terminateByCPUtimer RunPyScript00 RunPyScript01 RunPyScript02 diff --git a/System/terminateByCPUtimer.mo b/System/terminateByCPUtimer.mo new file mode 100644 index 0000000..9330c03 --- /dev/null +++ b/System/terminateByCPUtimer.mo @@ -0,0 +1,26 @@ +within InteractiveSimulation.System; + +model terminateByCPUtimer + import units= Modelica.Units.SI; + + parameter units.Time tTerminate=100; + parameter Integer sigDigits=4; + + + getCPUclock CPUtime annotation( + Placement(transformation(origin = {-38, 50}, extent = {{-10, -10}, {10, 10}}))); + terminateWhenTriggered TerminateWhenTriggered annotation( + Placement(transformation(origin = {34, 50}, extent = {{-10, -10}, {10, 10}}))); + +algorithm + + if(tTerminate<=CPUtime.y_CPUtime)then + TerminateWhenTriggered.u_trigger:=true; + else + TerminateWhenTriggered.u_trigger:=false; + end if; + + annotation( + Icon(graphics = {Rectangle(fillColor = {255, 255, 255}, fillPattern = FillPattern.Solid, extent = {{-100, 100}, {100, -100}}), Text(origin = {1, 49}, extent = {{-93, 33}, {93, -33}}, textString = "terminate +by CPU timer"), Text(origin = {0, -51}, extent = {{-80, 13}, {80, -13}}, textString = DynamicSelect("0.0", String(CPUtime.y_CPUtime, sigDigits, 0, true))), Text(origin = {65, -70}, extent = {{-19, 10}, {19, -10}}, textString = "[s]"), Text(origin = {-60, -22}, extent = {{-26, 12}, {26, -12}}, textString = "current:")})); +end terminateByCPUtimer; diff --git a/System/terminateWhenTriggered.mo b/System/terminateWhenTriggered.mo new file mode 100644 index 0000000..19249db --- /dev/null +++ b/System/terminateWhenTriggered.mo @@ -0,0 +1,17 @@ +within InteractiveSimulation.System; + +model terminateWhenTriggered + Modelica.Blocks.Interfaces.BooleanInput u_trigger annotation( + Placement(transformation(origin = {-120, 0}, extent = {{-20, -20}, {20, 20}}), iconTransformation(origin = {-110, 0}, extent = {{-10, -10}, {10, 10}}))); + +algorithm + + when(u_trigger==true)then + terminate("terminate trigger is set true"); + end when; + + annotation( + defaultComponentName = "TerminateWhenTriggered", + Icon(graphics = {Rectangle(fillColor = {255, 255, 255}, fillPattern = FillPattern.Solid, extent = {{-100, 100}, {100, -100}}), Text(origin = {-1, 0}, extent = {{-93, 40}, {93, -40}}, textString = "Terminate +by trigger")})); +end terminateWhenTriggered; diff --git a/package.mo b/package.mo index 0331897..cc2c3a4 100644 --- a/package.mo +++ b/package.mo @@ -1,6 +1,6 @@ package InteractiveSimulation - extends Modelica.Icons.UtilitiesPackage; - + extends Modelica.Icons.Package; + annotation( uses(Modelica_DeviceDrivers(version = "2.1.1"), Modelica(version = "4.0.0")) );