如何通过处理 XML 文件来更改 Modelica MultiBody 组件参数?

How can I change Modelica MultiBody component parameters by working on the XML file?

我在 Modelica 中创建了一个简单的钟摆模型。之后,我构建了模型,以便生成 .xml 文件和 .exe 文件。

 model TestJAVA_v2
 inner Modelica.Mechanics.MultiBody.World world annotation(
Placement(visible = true, transformation(origin = {-86, 28}, extent = {{-10, 
-10}, {10, 10}}, rotation = 0)));
 Modelica.Mechanics.MultiBody.Joints.Revolute revolute1(n = {1, 0, 0}, 
 phi(fixed = true, start = 0.785398))  annotation(
 Placement(visible = true, transformation(origin = {-46, 28}, extent = 
 {{-10, 
-10}, {10, 10}}, rotation = 0)));
 Modelica.Mechanics.MultiBody.Parts.PointMass pointMass1 annotation(
 Placement(visible = true, transformation(origin = {16, 28}, extent = {{-10, 
-10}, {10, 10}}, rotation = 0)));
 Modelica.Mechanics.MultiBody.Parts.BodyShape bodyShape1(r = {0, 1, 1}, r_CM 
 = bodyShape1.r / 2)  annotation(
 Placement(visible = true, transformation(origin = {-14, 26}, extent = 
 {{-10, 
-10}, {10, 10}}, rotation = 0)));
equation
connect(bodyShape1.frame_b, pointMass1.frame_a) annotation(
Line(points = {{-4, 26}, {16, 26}, {16, 28}, {16, 28}}, color = {95, 95, 
95}));
connect(revolute1.frame_b, bodyShape1.frame_a) annotation(
Line(points = {{-36, 28}, {-24, 28}, {-24, 26}, {-24, 26}}, color = {95, 95, 
95}));
connect(world.frame_b, revolute1.frame_a) annotation(
Line(points = {{-76, 28}, {-58, 28}, {-58, 28}, {-56, 28}}, color = {95, 95, 
95}));
annotation(
uses(Modelica(version = "3.2.2")),
experiment(StartTime = 0, StopTime = 15, Tolerance = 0.001, Interval = 
0.0010002),
__OpenModelica_simulationFlags(iim = "none", lv = "LOG_STATS", s = 
 "dassl"));
end TestJAVA_v2;

使用 xml 解析器,我能够更改 BodyShape 的质量和矢量 r(从 frame_a 到 frame_b 的矢量在 frame_a 中解析)。但是仿真后发现只有质量变了,而元件的长度没有变。是否可以通过 xml 文件修改此向量?

某些参数在不重新编译模型的情况下无法更改。

ScalarVariable 中搜索 isValueChangeable 属性。 如果 isValueChangeable = "false" 那么您不能通过 xml 文件更改该值。

这可能是因为:

  1. 参数是结构性的(数组维度取决于它)
  2. 参数有 annotation(Evaluate=true) 这基本上使它成为一个常数

更多关于编辑的信息,经过更多分析:

  • 当前前端强制对 bodyShape1.r 求值,因此它使其成为无法更改的常量
  • 您可以使用夜间构建 (v1.13) 和 运行 omc -d=newInst 或在 OMEdit 中将 OMC 标志设置为 -d=newInst 以使用允许的新前端实现bodyShape1.r 可变。

-d=newInst 你得到:

  <ScalarVariable
    name = "bodyShape1.r[1]"
    valueReference = "1711"
    description = "Vector from frame_a to frame_b resolved in frame_a"
    variability = "parameter" isDiscrete = "true"
    causality = "internal" isValueChangeable = "true"
    alias = "noAlias"
    classIndex = "86" classType = "rPar"
    isProtected = "false" hideResult = "false"
    fileName = "c:/home/adrpo33/dev/OpenModelica/build/lib/omlibrary/Modelica 3.2.2/Mechanics/MultiBody/Parts.mo" startLine = "1038" startColumn = "5" endLine = "1039" endColumn = "59" fileWritable = "true">
    <Real start="0.0" fixed="true" useNominal="false" unit="m" />
  </ScalarVariable>

其中有 isValueChangeable = "true".

adrpo33@computer MINGW64 /c/home/adrpo33/dev/OMTesting/mb
$ ./TestJAVA_v2.exe -override=bodyShape1.r[1]=2 -lv=LOG_ALL | grep 'bodyShape1.r\['
LOG_SOLVER        | info    | read override values: bodyShape1.r[1]=2
LOG_SOLVER        | info    | override bodyShape1.r[1] = 2
|                 | |       | | Real bodyShape1.r[1](start=2, fixed=true, {nominal=1}, min=-1.79769e+308, max=1.79769e+308)
|                 | |       | | Real bodyShape1.r[2](start=1, fixed=true, {nominal=1}, min=-1.79769e+308, max=1.79769e+308)
|                 | |       | | Real bodyShape1.r[3](start=1, fixed=true, {nominal=1}, min=-1.79769e+308, max=1.79769e+308)
|                 | |       | | | [87] parameter Real bodyShape1.r[1](start=2, fixed=true) = 2
|                 | |       | | | [88] parameter Real bodyShape1.r[2](start=1, fixed=true) = 1
|                 | |       | | | [89] parameter Real bodyShape1.r[3](start=1, fixed=true) = 1

似乎与 omc -d=newInstModel -override

配合得很好