我刚开始从Dymola和Modelica开始。
我从Modelica库的某些部分制作了一个小型模型。
该模型由“ DynamiCpipe”,“ MassFlowsource_T”,“固定式布基”和在给定时间增加质量流量的步骤组成。
我的目标是改变管道的直径和长度,看看质量流稳定所需的时间。
我写了一个小脚本,以改变直径和管道的长度,然后将质量流写入.CSV文件。
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;
剧本清真寺有效,但我得到了:
警告:设置Pipe.lenght对模型没有影响。
翻译后,您只能设置字面的起始价值和未评估的参数。
我已经尝试将注释更改为评估= false,但失败了。
我找到了这个解决方案,但我不知道如何将其应用于我的问题。
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)
首先要检查的东西:您的仿真设置转换选项卡中的前两个框是未选中的,正确吗?如果没有,请取消选中它们,然后重试。
顺便说一句:这对应于
evaluate = false;
andadvedical.evaluatealSotop = false;
来自脚本。鉴于您的参数未通过上述设置来评估您的参数,因此Dymola可能会出于多种原因来评估
pipe.length.length
。鉴于它是一个长度而不是结构性参数,这对我来说并没有很多意义,但是如果没有模型,这很难判断。即使在需要变化的评估参数的情况下,也可能进行的事情,正在为每个模拟使用更改的参数重新翻译模型。这将需要额外的时间(尤其是如果模拟与模拟相比,仿真很快),但这是唯一的选择。这意味着您需要将
translatemodel(“ modelica_rohrmodel”);
转移到循环中,然后将其扩展到translatemodel(“ modelica_rohrmodel(pipe.length =“+realString(i)) )
;这有点蛮力,但应该起作用...
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.

BTW: This corresponds to
Evaluate = false;
andAdvanced.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 totranslateModel("Modelica_Rohrmodel(pipe.length="+realString(i)+")")
;This is a bit brute force, but should work...
我认为,与使用dymola使用脚本更改管道直径和长度相比,使用Dymola的长度是使用“扫描参数”,如果是最近下载,则应该在Dymola中使用。
https:// .claytex.com/tech-blog/how-to-to-a-a-a-a-a-a-a-pare-s-s-weep-in-in-dymola/
I think what would be easier than using a script to change pipe diameter and length for each simulation with dymola is to use "Sweep Parameters" which should be available in your Dymola if it's a recent download.
https://www.claytex.com/tech-blog/how-to-easily-run-a-parameter-sweep-in-dymola/