JModelica Users Guide - Version 2.10 5.3.2.1のシミュレーションを行います。これは、5.2の Van der Pol ossilator モデルに、制御信号 u として正弦波を入力します。
入力信号のオブジェクトを作成します。
import numpy as N
t = N.linspace(0.,10.,100)
u = N.sin(t)
u_traj = N.transpose(N.vstack((t,u)))
input_object = ('u', u_traj)
モデルの FMU は VDP.ipynb で作成済みなので読み込みます。inputオプションを指定してシミュレーションを実行します。
from pyfmi import load_fmu
model = load_fmu("VDP.fmu")
res = model.simulate(final_time=10, input=input_object)
シミュレーション結果を取得してプロットします。
%matplotlib notebook
import matplotlib.pyplot as plt
u = res['u']
x1 = res['x1']
x2 = res['x2']
t = res['time']
plt.figure(1)
plt.plot(t, u, t, x1, t, x2)
plt.legend(('u', 'x1', 'x2'))
plt.title('Van der Pol scillator.')
plt.ylabel('Angle (rad)')
plt.xlabel('Time (s)')