Skip to content

Commit

Permalink
no message
Browse files Browse the repository at this point in the history
  • Loading branch information
zeta-plusplus committed Jun 30, 2024
1 parent 8e7e5c4 commit 4a50f3d
Show file tree
Hide file tree
Showing 11 changed files with 136 additions and 4 deletions.
11 changes: 11 additions & 0 deletions Examples/System/getCPUclock_ex01.mo
Original file line number Diff line number Diff line change
@@ -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;
3 changes: 3 additions & 0 deletions Examples/System/package.order
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
RunPyScript00_ex01
RunPyScript01_ex01
C_runPyScript00_ex01
getCPUclock_ex01
terminateWhenTriggered_ex01
terminateByCPUtimer_ex01
13 changes: 13 additions & 0 deletions Examples/System/terminateByCPUtimer_ex01.mo
Original file line number Diff line number Diff line change
@@ -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;
14 changes: 14 additions & 0 deletions Examples/System/terminateWhenTriggered_ex01.mo
Original file line number Diff line number Diff line change
@@ -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;
8 changes: 8 additions & 0 deletions Input/getCPUclock.bak-mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
within InteractiveSimulation.Input;

block getCPUclock




end getCPUclock;
4 changes: 2 additions & 2 deletions Output/dispVarPyConsole02_00.mo
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]";


/* ---------------------------------------------
Expand Down
37 changes: 37 additions & 0 deletions System/getCPUclock.mo
Original file line number Diff line number Diff line change
@@ -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;
3 changes: 3 additions & 0 deletions System/package.order
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
Functions
getCPUclock
terminateWhenTriggered
terminateByCPUtimer
RunPyScript00
RunPyScript01
RunPyScript02
Expand Down
26 changes: 26 additions & 0 deletions System/terminateByCPUtimer.mo
Original file line number Diff line number Diff line change
@@ -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;
17 changes: 17 additions & 0 deletions System/terminateWhenTriggered.mo
Original file line number Diff line number Diff line change
@@ -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;
4 changes: 2 additions & 2 deletions package.mo
Original file line number Diff line number Diff line change
@@ -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"))
);
Expand Down

0 comments on commit 4a50f3d

Please sign in to comment.