我正在尝试学习modelica,并开始编写教程中的一些简单示例:“面向对象建模和仿真简介” OpenModelica“作者:Peter Fritzson Link。我正在和dymola合作。 有一个名为Moon Landing的例子,我无法运行。 启动模拟后,我无法绘制任何变量。 这是我的代码:
model Example
class Rocket "rocket class"
parameter String name;
Real mass(start = 1038.3);
Real altitude(start = 59404);
Real velocity(start = -2003);
Real thrust;
Real acceleration;
Real gravity;
parameter Real massLossRate=0.000277;
equation
acceleration = (thrust-mass*gravity)/mass;
der(mass) = -massLossRate * abs(thrust);
der(altitude)=velocity;
der(velocity)=acceleration;
end Rocket;
class CelesticalBody
constant Real g = 6.672e-11;
parameter Real radius;
parameter String name;
parameter Real mass;
end CelesticalBody;
class MoonLanding
parameter Real force1 = 36350;
parameter Real force2 = 1308;
protected
parameter Real thrustEndTime = 210;
parameter Real thrustDecreaseTime = 43.2;
public
Rocket apollo(name="apollo13");
CelesticalBody moon(name="moon",mass = 7.382e22, radius=1.738e6);
equation
apollo.thrust = if (time < thrustDecreaseTime) then force1
else if
(time < thrustEndTime) then force2
else 0;
apollo.gravity = moon.g*moon.mass/(apollo.altitude+moon.radius)^2;
end MoonLanding;
end Example;
有人知道错误可能在哪里吗?
答案 0 :(得分:2)
正如@ Rene-Just-Nielsen所说,你必须模拟Example.MoonLanding,你应该让一个包(不是模型)和MoonLanding(Rocket,CelestialBody)模型(不是类):
package Example
model Rocket "rocket class"
...
end Rocket;
model CelestialBody
...
end CelestialBody
model MoonLanding
...
end MoonLanding;
end Example;
(基本上答案不是我的,而是Rene的,我同意。)
将它们标记为“包”和“模型”的一些额外好处是:
package Example
)会在Dymola中出错,因此会检测到此特定错误。time
,但只有模型和块可以使用time
(这仅作为警告提供)。