0 modelica
我正在尝试在Modelica中执行一个字符串.该字符串将保存在变量中,以便在需要时能够更改它.
function Test
input String inComp="resistor.R:=2";
output String outComp;
algorithm
outComp:=inComp;
end Test;
Run Code Online (Sandbox Code Playgroud)
能否请您
我正在使用Dymola.
我需要做的是以下内容.
- 从文本文件中读取组件名称(或在执行函数时输入它们) - 然后更改这些组件的参数.这段代码就是一个例子:
function Test
input String inComp="resistor"; //Entered by the user, or read from a text file
output Real result;
algorithm
inComp.R :=2 ; /*This is incorrect since it wouldn't understand that
I want to enter : resistor.R := 2; */
result := inComp.R ; //In order to view the result
end Test;
Run Code Online (Sandbox Code Playgroud)
在Modelica中,您通常不会尝试做什么.可能有些工具有一个"反射API"允许这个(或者可能是一个带有命令字符串并执行它的内置函数)但是当然没有可以跨工具工作的通用API.
如果你想在Dymola中运行一系列具有不同参数值的模拟,我可以建议至少有三种不同的想要继续进行.
for j in {1.0, 1.1, 1.2, 1.5, 1.8} loop
J1.J := j;
simulateModel("Modelica.Mechanics.Rotational.Examples.CoupledClutches",
resultFile="CoupledClutches_"+String(j));
end for;
function RunLoop
algorithm
for j in {1.0, 1.1, 1.2, 1.5, 1.8} loop
simulateModel("Modelica.Mechanics.Rotational.Examples.CoupledClutches(J1(J="+String(j)+"))",
resultFile="CoupledClutches_"+String(j));
end for;
end RunLoop;
simulateExtendedModel,simulateMultiExtendedModel它实际上与上面几乎完全相同,但是以更干净的方式(类型document("simulateExtendedModel")和document("simulateMultiExtendedModel")在Dymola命令窗口中获取更多信息).好的,那应该给你一个开始.如果这些都不能用于任何原因,那么只需更新问题,无论您有什么额外要求.
| 归档时间: |
|
| 查看次数: |
1075 次 |
| 最近记录: |