Reputation: 21
I have made 3 models in dymola and want to rum them sequentially (one after the other) in such a way that the output of one should pass on as an input to the next. My models calculate temperature and the final temperature of one model should be the initial temperature of the next model. can you please suggest a way for this? Could stategraph be used for this purpose and how?
Upvotes: 2
Views: 381
Reputation: 6665
Even though this question is quite old, it is definitely a problem others might face also, so here answer (a little late...).
In Dymola the described problem can be solved very easily with the function DymolaCommands.SimulatorAPI.simulateExtendedModel
. It allows setting the start and stop-time for a simulation, initialize states and read the final values of variables.
Here is an example how an modelica function could look like which uses simulateExtendedModel
to carry over the simulation result from Model1
to Model2
. It is assumed that a temperature sensor is used in both models to measure the temperature of interest and the start temperature of a heat capacitor is initialized:
function Script
protected
Modelica.SIunits.Temperature T[1] "Stores the final temperature at simulation end";
Boolean ok "Indicates if simulation completed without error";
String models[:] = {"MyLib.Model1", "MyLib.Model2"} "Full class paths for models to simulate";
algorithm
// Simulation 1 with model 1 from 0s to 1s
(ok, T) :=DymolaCommands.SimulatorAPI.simulateExtendedModel(
models[1],
startTime=0,
stopTime=1,
finalNames={"temperatureSensor.T"},
resultFile=models[1]);
// Simulation 2 with model 2 from 1s to 2s
(ok, T) :=DymolaCommands.SimulatorAPI.simulateExtendedModel(
models[2],
startTime=1,
stopTime=2,
initialNames={"heatCapacitor.T"},
initialValues={T[1]},
finalNames={"temperatureSensor.T"},
resultFile=models[2]);
// Plot temperature output of all models
for m in models loop
createPlot(
id=1,
heading="temperatureSensor.T",
y={"temperatureSensor.T"},
legends={m},
filename=m+".mat",
erase=m==models[1],
grid=true,
position={0, 0, 700, 400});
end for;
end Script;
Note the second return value of simulateExtendedModel
is a vector (as one could access more than one final values with finalNames
), hence the variable T
is vectorized.
Upvotes: 2