ODE のシステムを解くために scipy.integrate を使用しています。私のコードの要約は次のようになります。
# step 1: import all necessary modules and functions imports here
import numpy as np
from scipy.integrate import ode
# step 2: define ode sys
def ode_rhs(t, y, p1, p2, ..., pn):
''' do some stuff to define rhs'''
return ydot
# step 3: set parameters p1, p2, ..., pn
"""
p1 = ...
p2 = ...
...
pn = ...
"""
# step 4: set time parameters
ts = 0.0
tf = 340.
# step 5: set initial conditions
y0 = np.zeros(some_shape)
# step 6: set ode solver
#backend = 'dopri5'
backend = 'vode'
r = ode(ode_rhs).set_integrator(backend, method='BDF', atol=1e-12, rtol=1e-6)
r.set_initial_value(y0,ts)
# step 7: store solution
t = [ts]
y = [y0]
# step 8: call ode rhs and integrate
while r.successful() and r.t < tf:
r.set_f_params(p1, p2, ..., pn)
r.integrate(tf, step=True)
t.append(r.t)
y.append(r.y)
# step 9: process output for plotting
t = array(t)
y = array(y).T
ソルバーは、解を進めるために使用する任意のタイム ステップで y の値を出力します。私が必要とするのは、ソルバーによって内部的に使用されるタイムステップではなく、特定の時間 (0、1、2、... 339) での出力です。r.integrate(t+dt) を使用することもできました。ただし、シミュレーション時間を短縮するには、可変ステッピングを使用する必要があります。