Automation of tests and storing the results in Dymola

69 Views Asked by At

I have written a tester for one of my component models and I want to test it with a large set of boundary conditions. I dont want to manually change the values in the boundaries and note down the end results, since that would take forever. I therefore tried to automate that process by reading an .mat file that contains my set of boundary conditions and storing the last value in time of the variables that I am interested in in another .mat file that I will then post process. In that .mat file, each line represents one model run and each column the last value in time for the particular variables that I want to store. However, I cant overcome the error Warning: Undeclared variable or command: Model.Variable. Below my code that I have written in the scripts section of Dymola:

openModel("pathToModel");

startTime :=0;
stopTime :=30;

data := readMatrix("BC.mat", "BC_MatrixName", nrows, ncols);

resultsMatrix := zeros(size(data, 1), 2);

for i in 1:size(data, 1) loop

  SubmodelBoundary1.value1 := data[i, 1];
  ... More Bc's

  simulateModel("ModelName", start=startTime, stop=stopTime, method="dassl', tolerance=1e-4);

  resultsMatrix[i, 1] := ModelName.VarName[end];

end for;

I tried multiple different ways of accessing the variable. I have also made sure that the variable that I want to read is set to public in the model. When I try to write the variable to the file before I call the simulateModel() function, it is possible as well. Please note that I didnt include the writeMatrix() command needed at the end, since that works for me.

If someone could help me with how I can access variables after the simulating the model that would be awesome. Thank you in advance for your help.

1

There are 1 best solutions below

4
Hans Olsson On

Dymola supports running multiple simulations of one model with different parameters.

If it were only one parameter you could use sweep parameter available in the GUI. Multiple parameters is also supported, but simulates all possibly combinations of parameters (or a Monte-Carlo subset), which isn't what you want.

However, there is a low level scripting command that can be configured to run the specific cases:

simulateMultiExtendedModel("ModelName", 
  start=startTime, 
  stop=stopTime, 
  method="dassl", 
  tolerance=1e-4, 
  initialNames={"SubmodelBoundary1.value1", ...}, 
  initialValues=data, 
  finalNames={"VarName", ...});

Alternatively: Use DymolaCommands.SimulatorAPI.simulateMultiExtendedModel that also contain some documentation for this functionality.

Note that this command will run simulations in parallel.