Search code examples
modelicadymola

modify model's parameters in dymola's script file


I am trying to use a .mos file in Dymola to do multiple simulations, here is an example from claytex's blog:

openModel("C:/Dymola/Testing/Test1.mo")
translateModel ("Test1");
for i in 1:10 loop
         a=i;
         simulate();
         system("copy dsres.mat results"+String(i) +".mat");
end for;

It seems when I translate a model in the script file, I could modify the model's parameters again, which is different when I use Dymola's GUI. In Dymola's GUI, if I try to modify the parameter after I translate the model, I have to re-translate the model. My question is:
In Dymola's script file, when I modify the parameter, how does Dymola deal with it?


Solution

  • The above comment by "user2024223" is correct, but I think "variable browser" is not stressed enough and some more explanation could help:

    When changing the model's parameters after translation, make sure you are not using the model editing (either "Graphical" or "Text"-Ribbon), because this will change the model's code and therefore (usually) force re-translation. The same is true for the "Model View" in the "Simulation" Ribbon.

    The code will not be changed if you use the "Variable Browser" in the "Simulation"-Ribbon. An alternative (which actually does the same) is typing the parameter value in the "Commands"-line. E.g. this could be J1.J=5 for the CoupledClutches example. Both of the variants in the paragraph should behave similarly to the script.