Skip to content

Commit

Permalink
Exit intialization mode before first doStep()
Browse files Browse the repository at this point in the history
in Modelica import
  • Loading branch information
t-sommer committed May 3, 2023
1 parent d0ee0cf commit d45a98a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
13 changes: 9 additions & 4 deletions fmpy/modelica/templates/FMI2_CS.mo
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
parameter Modelica.Units.SI.Time communicationStepSize = @=communicationStepSize=@ annotation(Dialog(tab="FMI", group="Parameters"));
@@ endblock @@
@@ block equations @@
Boolean initialized;

initial algorithm

Expand All @@ -23,17 +24,21 @@ initial algorithm
FMI2Set@=variable.type=@(instance, {@=variable.valueReference=@}, 1, {'@=variable.name=@_start'});
@@ endfor @@

FMI2ExitInitializationMode(instance);

algorithm

when sample(startTime, communicationStepSize) then
when {initial(), sample(startTime, communicationStepSize)} then

@@ for variable in inputs @@
FMI2Set@=variable.type=@(instance, {@=variable.valueReference=@}, 1, {'@=variable.name=@'});
@@ endfor @@

FMI2DoStep(instance, time, communicationStepSize, true);
if time >= communicationStepSize + startTime then
if not initialized then
FMI2ExitInitializationMode(instance);
initialized := true;
end if;
FMI2DoStep(instance, time, communicationStepSize, true);
end if;

@@ for variable in outputs @@
'@=variable.name=@' := FMI2Get@=variable.type=@Scalar(instance, @=variable.valueReference=@);
Expand Down
13 changes: 9 additions & 4 deletions fmpy/modelica/templates/FMI3_CS.mo
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
parameter Modelica.Units.SI.Time communicationStepSize = @=communicationStepSize=@ annotation(Dialog(tab="FMI", group="Parameters"));
@@ endblock @@
@@ block equations @@
Boolean initialized;

initial algorithm

Expand All @@ -22,17 +23,21 @@ initial algorithm
FMI3Set@=variable.type=@(instance, {@=variable.valueReference=@}, 1, {'@=variable.name=@_start'});
@@ endfor @@

FMI3ExitInitializationMode(instance);

algorithm

when sample(startTime, communicationStepSize) then
when {initial(), sample(startTime, communicationStepSize)} then

@@ for variable in inputs @@
FMI3Set@=variable.type=@(instance, {@=variable.valueReference=@}, 1, {'@=variable.name=@'});
@@ endfor @@

FMI3DoStep(instance, time, communicationStepSize);
if time >= communicationStepSize + startTime then
if not initialized then
FMI3ExitInitializationMode(instance);
initialized := true;
end if;
FMI3DoStep(instance, time, communicationStepSize);
end if;

@@ for variable in outputs @@
'@=variable.name=@' := FMI3Get@=variable.type=@Scalar(instance, @=variable.valueReference=@);
Expand Down

0 comments on commit d45a98a

Please sign in to comment.