我在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文件修改此向量?
答案 0 :(得分:1)
如果不重新编译模型,则无法更改某些参数。
在ScalarVariable
中搜索isValueChangeable
属性。
如果为isValueChangeable = "false"
,则无法通过xml文件更改该值。
之所以会发生,是因为:
annotation(Evaluate=true)
,基本上使它成为常数经过更多分析后,有关编辑的更多信息:
bodyShape1.r
的前端强制评估,因此使其成为不可更改的常量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=newInst
和Model -override
一起正常工作