モデルをコンパイルしてFMUを作成します。
from pymodelica import compile_fmu
fmu_name = compile_fmu("Modelica.Fluid.Examples.Tanks.EmptyTanks")
FMUをロードします。
from pyfmi import load_fmu
model = load_fmu(fmu_name)
オプションでソルバーを LSODAR に変えてシミュレーションを実行します。 オプションの詳細は help(opts) で確認できます。
opts = model.simulate_options()
opts['solver'] = "LSODAR"
res = model.simulate(options=opts)
シミュレーション結果を取得します。
level1 = res['tank1.level']
level2 = res['tank2.level']
mflow = res['pipe.port_a.m_flow']
t = res['time']
プロットします。
%matplotlib notebook
import matplotlib.pyplot as plt
plt.figure(1)
plt.subplot(2,1,1)
plt.plot(t, level1, t, level2)
plt.ylabel('Tank Level (m)')
plt.legend(['Tank1 Level','Tank2 Level'])
plt.subplot(2,1,2)
plt.plot(t,mflow)
plt.ylabel('mass flow rate (kg/s)')
plt.legend(['Pipe Mass Flow Rate'])
plt.xlabel('Time (s)')
plt.show()