Changing evaluated Parameters after translation in Dymola

Viewed 91

i'am just getting started with Dymola and Modelica in general. I've made a small model from parts of the Modelica library. The model consists of the "DynamicPipe", the "MassFlowSource_T", the "FixedBoundary" and a Step to increase the mass flow at a given time. My goal is to vary the diameter and the length of the pipe and see how long it takes for the mass flow to stabilize.

I've written a small script to vary the diameter and the length of the pipe an write the mass flow to a .csv file.

openModel("C:\Dymola\Modelica_Rohrmodel.mo")
translateModel("Modelica_Rohrmodel");

for j in 0.0 : 0.1 : 1 loop
  
  pipe.diameter = j;
  
  for i in 0 : 5 : 100 loop
    
    pipe.length = i;
    
    simulate();
    
    fileName="Modelica_Rohrmodel.mat";
    
    n=readTrajectorySize(fileName);
    
    names={"boundary.ports[1].m_flow"};
    
    traj=readTrajectory(fileName,names,n);
    
    traj_transposed=transpose(traj);
    
    CSVfile="Massflow"+String(j)+"_"+String(i)+".csv";
    
    DataFiles.writeCSVmatrix(CSVfile, names, traj_transposed);
    
  end for;
end for;

The script moslty works, but i get: Warning: setting pipe.lenght has no effect in model. After translation you can only set literal start-values and non-evaluated parameters.

I've already tried to change the annotation to Evaluate=false, but failed.

https://www.claytex.com/blog/methods/modifying-evaluated-parameters-in-multiple-simulations/ I found this solution, but I don't know how to apply it to my problem.

2 Answers

First something to check: The first two boxes in your simulation setup's Translation tab are unchecked, correct? If not, uncheck them and try again. Simulation Setup BTW: This corresponds to Evaluate = false; and Advanced.EvaluateAlsoTop = false; from scripts.

Given your parameters are not evaluated by the above setting, it is possible that Dymola decides that it needs to evaluate pipe.length for multiple reasons. It does not make a lot of sense to me, given it is a length and not a structural parameter, but this is difficult to judge without having the model.

Something that is possible even with evaluated parameter which needs to be varied, is re-translating the model for every simulation with changed parameters. This will take additional time (especially if the simulation is quick compared to the simulation), but is the only option then. This would mean you need to move translateModel("Modelica_Rohrmodel"); into the loop and extend it to translateModel("Modelica_Rohrmodel(pipe.length="+realString(i)+")");

This is a bit brute force, but should work...

Related