我正在运行 OpenModelica 并尝试运行 Modelica 物理建模简介中的示例。我已将示例 9.1 - 9.4 复制到一个包中。该文件现在如下所示:
package gravityPackage
//Test of gravity taken from Intro to Physical modeling with Modelica
//
//
//
//
//
model ParticleField
inner function gravity = TwoBodyField;
Particle p1(x_init = {2,-2,0}, v_init = {0.7,0,0});
Particle p2(x_init = {0,0.5,0}, v_init = {-1,-1,0});
Particle p3(x_init = {0.5,2,0}, v_init = {-1,-0.5,0});
end ParticleField;
function TwoBodyField
extends GravityField;
protected
Modelica.SIunits.Position b1[3],b2[3];
Modelica.SIunits.Velocity n1[3],n2[3];
algorithm
b1:={0,0,0};
b2:={0,1,0};
n1:=-(x - b1) / sqrt((x - b1) * (x - b1));
n2:=-(x - b2) / sqrt((x - b2) * (x - b2));
g:=n1 / ((x - b1) * (x - b1)) + n2 / ((x - b2) * (x - b2));
end TwoBodyField;
partial function GravityField
input Modelica.SIunits.Position x[3];
output Modelica.SIunits.Acceleration g[3];
end GravityField;
model Particle
parameter Modelica.SIunits.Position x_init[3];
parameter Modelica.SIunits.Velocity v_init[3];
protected
outer function gravity = GravityField;
//outer function gravity=ParticleField;
//outer function gravity=TwoBodyField;
Modelica.SIunits.Position x[3](start = x_init);
Modelica.SIunits.Velocity v[3](start = v_init);
Modelica.SIunits.Acceleration a[3];
equation
v = der(x);
a = der(v);
a = gravity(x);
end Particle;
end gravityPackage;
但是,如果我去 OMShell 并尝试运行它,我会得到:
>> loadFile("gravityPackage.mo")
true
>> simulate(gravityPackage.ParticleField)
record SimulationResult
resultFile = "",
simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 0.000001, method = 'dassl', fileNamePrefix = 'gravityPackage.ParticleField', options = '', outputFormat = 'mat', variableFilter = '.*', measureTime = false, cflags = '', simflags = ''",
messages = "Simulation failed for model: gravityPackage.ParticleField
[gravityPackage.mo:34:11-34:42:writable] Warning: No corresponding 'inner' declaration found for class gravity declared as 'outer '.
Continuing flattening by only considering the 'outer' class declaration.
[gravityPackage.mo:43:5-43:19:writable] Error: Failed to instantiate equation
a = gravity(x);.
Error: Error occurred while flattening model gravityPackage.ParticleField
",
timeFrontend = 0.0,
timeBackend = 0.0,
timeSimCode = 0.0,
timeTemplates = 0.0,
timeCompile = 0.0,
timeSimulation = 0.0,
timeTotal = 0.0
end SimulationResult;
>>
所以,显然有一些与范围相关的东西我没有得到正确的。所有的代码,除了包,都是直接从书中复制过来的。我相信该软件包对于将其放入单个文件中是必要的(尽管我尝试了其他一些方法但没有成功)。任何建议表示赞赏。
谢谢,