下面这个问题 ,我试图编译和仿真与JModelica一个Modelica的模型。 该模型是:
package friction1D
function coulombFriction
input Real relVel;
input Real shearForce;
input Real normalForce;
input Real statfricco;
input Real kinfricco;
input Real inertia;
input Real relAcc;
output Real fricForce;
algorithm
if (relVel == 0) and (abs(shearForce - inertia * relAcc) < statfricco * normalForce) then
fricForce := shearForce - inertia * relAcc;
else
fricForce := kinfricco * normalForce * sign(relVel);
end if;
end coulombFriction;
model fricexample_1
//parameters
parameter Real kco = 0.3;
parameter Real sco = 0.4;
parameter Real nfo = 1.0;
parameter Real mass = 1;
Real sfo;
Real ffo;
Real x;
Real v;
initial equation
x = 0;
v = 0;
algorithm
sfo := 1 * sin(time);
equation
v = der(x);
mass * der(v) = sfo - ffo;
ffo = coulombFriction(relVel = v, shearForce = sfo, normalForce = nfo, statfricco = sco, kinfricco = kco, inertia = mass, relAcc = der(v));
annotation(
experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-8, Interval = 0.02),
__OpenModelica_simulationFlags(lv = "LOG_STATS", outputFormat = "mat", s = "dassl"));end fricexample_1;
end friction1D;
和Python代码是:
from pymodelica import compile_fmu
from pyfmi import load_fmu
model_name = 'friction1D'
mofile = 'friction1D.mo'
fmu_name = compile_fmu(model_name, mofile)
sim = load_fmu(fmu_name)
res = sim.simulate(final_time=10)
当我试图召唤回结果的time = res['time']
命令似乎是工作的罚款,但对人lother变量,例如, vel = res['v']
它返回此错误:
---------------------------------------------------------------------------
VariableNotFoundError Traceback (most recent call last)
<ipython-input-19-a29270f8b1ab> in <module>()
----> 1 vel = res['v']
C:\Users\foobar\AppData\Roaming\JModelica.org-2.10\install\Python_64\pyfmi\common\algorithm_drivers.pyc in __getitem__(self, key)
176 Name of the variable/parameter/constant.
177 """
--> 178 val_x = self.result_data.get_variable_data(key).x
179
180 if self.result_data.is_variable(key):
C:\Users\foobar\AppData\Roaming\JModelica.org-2.10\install\Python_64\pyfmi\common\io.pyc in get_variable_data(self, name)
1160 varInd = 0;
1161 else:
-> 1162 varInd = self.get_variable_index(name)
1163
1164 dataInd = self.raw['dataInfo'][1][varInd]
C:\Users\foobar\AppData\Roaming\JModelica.org-2.10\install\Python_64\pyfmi\common\io.pyc in get_variable_index(self, name)
151 else:
152 raise VariableNotFoundError("Cannot find variable " +
--> 153 name + " in data file.")
154
155
VariableNotFoundError: Cannot find variable v in data file.
我将不胜感激,如果你能帮助我知道问题是什么,我怎么能解决这个问题。
PS1。 我已经发布了这个问题也将Modelica的语言不和谐的通道 。
PS2。 我认为这个问题的产生是因为我解决一个包。 相反,如果一个简单的模型进行仿真,它可以检索的变量。
PS3。 我想我解决了这个问题。 行model_name = 'friction1D'
需要改变到model_name = 'friction1D.fricexample_1'
。 基本上,它应该是<packageName>.<modelName>