I am trying to set up a simple parametric study in Dymola. I am having some problems with the name of the result files, which obviously should be different in order to not overwrite the previous one. However, it looks like the String() operator is not working as expected. First, I simply tried to use the code from here. Then I tried to change few things in the syntax, without success. For example, what's wrong with the following code?
openModel("C:/MySimulations/Test1.mo")
translateModel ("Test1");
for i in 1:10 loop
a=i;
simulateModel(resultFile="Test"+String(i));
end for;
The simulation simply does not start. However, if I remove String(i)
the simulation runs correctly ten times, but it only stores one (the last) result file. I am using Dymola 2022.
I don't known why, but for some reason you have to use an intermediate variable:
translateModel ("Modelica.Blocks.Examples.PID_Controller");
for i in 1:2 loop
result = "Test"+String(i);
simulateModel(resultFile=result);
end for;
Modelica scripts are weird sometimes...
As an alternative you can put your script into a function. In this case your original code works. There are other benefits as well: you can integrate your script into a package or run the usual check on it. The only downside is, that you have to declare all variables you use.
function batchSimulate
algorithm
translateModel( "Modelica.Blocks.Examples.PID_Controller");
for i in 1:2 loop
simulateModel(resultFile="Test" + String(i));
end for;
annotation(__Dymola_interactive=true);
end batchSimulate;