コード例 #1
0
def model(F, beta, y0, ta, dt):
    """
  Run model for given volume flow rate <F> and toxin coef <beta> for total
  time array <ta> in hours at timestep <dt>, also in hours.  Returns the 
  last solution 3-tuple for L, S, and C.
  """
    # Additional parameters being passed to the ODE function
    a_L = 0.1124
    a_S = 0.0325
    K_L = 19.0288
    K_S = 20.1818
    V = 1.0
    C_0 = 0.02

    L_params = [K_L, F, V]
    S_params = [K_S, F, V, beta]
    C_params = [a_L, a_S, K_L, K_S, F, V, C_0]

    # Call function that integrates the ODE:
    r = ode(f)
    r.set_integrator('dopri5', atol=1e-6, rtol=1e-5)
    r.set_initial_value(y0, ta)
    r.set_f_params(dLdt, dSdt, dCdt, L_params, S_params, C_params)

    sol = []
    sol.append(y0)
    for t in ta[:-1]:
        r.integrate(r.t + dt)
        sol.append(r.y)
    sol = array(sol).T

    return sol[:, -1]
コード例 #2
0
ファイル: killerYeast.py プロジェクト: pf4d/ode_plot
def model(F, beta, y0, ta, dt):
  """
  Run model for given volume flow rate <F> and toxin coef <beta> for total
  time array <ta> in hours at timestep <dt>, also in hours.  Returns the 
  last solution 3-tuple for L, S, and C.
  """ 
  # Additional parameters being passed to the ODE function
  a_L  = 0.1124
  a_S  = 0.0325
  K_L  = 19.0288
  K_S  = 20.1818
  V    = 1.0
  C_0  = 0.02
  
  L_params = [K_L, F, V]
  S_params = [K_S, F, V, beta]
  C_params = [a_L, a_S, K_L, K_S, F, V, C_0]
  
  # Call function that integrates the ODE:
  r = ode(f)
  r.set_integrator('dopri5', atol=1e-6, rtol=1e-5)
  r.set_initial_value(y0, ta)
  r.set_f_params(dLdt, dSdt, dCdt, L_params, S_params, C_params)
  
  sol = []
  sol.append(y0)
  for t in ta[:-1]:
    r.integrate(r.t + dt)
    sol.append(r.y)
  sol = array(sol).T
  
  return sol[:,-1]
コード例 #3
0
        def predict_fn(state, dt):
            train_size, state = state
            solver = ode(dr_dt).set_integrator('dopri5')
            solver.set_initial_value(state, 0).set_f_params(train_size)
            solver.integrate(dt)

            return train_size, solver.y
コード例 #4
0
        def predict_fn(state, dt):
            state = state

            solver = ode(dr_dt).set_integrator('dopri5')
            solver.set_initial_value(state, 0)
            solver.integrate(dt)

            return solver.y
コード例 #5
0
        def predict(dt, fx_train=0., fx_test=0.):
            r = ode(dfx_dt).set_integrator('dopri5')

            fx = fl(np.concatenate((fx_train, fx_test), axis=0))
            train_size, output_dim = fx_train.shape
            r.set_initial_value(fx, 0).set_f_params(train_size * output_dim)
            r.integrate(dt)
            fx = ufl(r.y)

            return fx[:train_size], fx[train_size:]
コード例 #6
0
ファイル: bootstrap.py プロジェクト: pf4d/ode_plot
def integrate(params, f, ta, dt):
    t0 = ta[0]
    u0 = params[0]
    p0 = params[1:]

    # Call function that integrates the ODE:
    r = ode(f)
    r.set_integrator("dopri5", atol=1e-8, rtol=1e-5)
    r.set_initial_value(u0, t0)
    r.set_f_params(p0)

    sol = []
    sol.append(u0)
    for t in ta[:-1]:
        r.integrate(r.t + dt)
        sol.append(r.y)
    sol = array(sol).T
    return sol
コード例 #7
0
def integrate(params, f, ta, dt):
    t0 = ta[0]
    u0 = params[0]
    p0 = params[1:]

    # Call function that integrates the ODE:
    r = ode(f)
    r.set_integrator('dopri5', atol=1e-8, rtol=1e-5)
    r.set_initial_value(u0, t0)
    r.set_f_params(p0)

    sol = []
    sol.append(u0)
    for t in ta[:-1]:
        r.integrate(r.t + dt)
        sol.append(r.y)
    sol = array(sol).T
    return sol
コード例 #8
0
ファイル: Tanabe65MN.py プロジェクト: ABI-Software/abics
    def solve(self, targetT):
        temperature = np.zeros(self.nDofs * 4 + 1)
        temperature[0:-1] = np.reshape(self.temperature, (-1, 1))[:, 0]
        temperature[-1] = self.cbcTemp

        def dTbydt(time, temp, obj):
            return obj.dTbydt(temp)

        def JacdTbydt(time, temp, obj):
            #The argument is passed to jac function too
            return self.dt2bydt2(temp)

        tl = [0, targetT]
        if isinstance(targetT, np.ndarray):
            tl = list(targetT)
        elif isinstance(targetT, list):
            tl = targetT

        r = ode(dTbydt).set_integrator('vode', method='bdf')
        #r = ode(dTbydt).set_integrator('dopri5')
        r.set_initial_value(temperature,
                            tl[0]).set_f_params(self).set_jac_params(self)
        ts = 1
        if tl[-1] > 1:
            ts = np.ceil(tl[-1] / 1)

        dt = float(tl[-1]) / ts
        while r.successful() and r.t < tl[-1]:
            temperature = r.integrate(r.t + dt)
            self.temperature = np.reshape(temperature[:-1], (-1, 4))
            self.cbcTemp = temperature[-1]
        if r.t < tl[-1]:
            temperature = r.integrate(tl[-1])
            self.temperature = np.reshape(temperature[:-1], (-1, 4))
            self.cbcTemp = temperature[-1]

        #Compute the wettedness based on the final value
        Emax = self.getEmax(self.temperature)
        Emax[Emax == 0] = 1.0  #Avoid divide by zero
        Esw = self.Esw
        Esw[Esw < 0] = 0.0
        self.wettedness = 0.06 + 0.94 * Esw / Emax  #Using formula 14 of Journal of Atmaca and Yigit, Thermal Biology 31 (2006) 442-452
コード例 #9
0
ファイル: kuramoto.py プロジェクト: hilbert9221/NRI-MPM
    def solve(self, t: list, y: np.ndarray, w: np.ndarray,
              k: np.ndarray) -> np.ndarray:
        """
        Solves Kuramoto ODE for time series `t` with initial parameters passed when initiated object.

        General Kuramoto ODE of m'th harmonic order.

        Args:
            t: time steps
            y: phase
            w: iterable frequency
            k: 3D coupling matrix, unless 1st order
            
        Return:
            phase: output of the integrator
        """
        dt = t[1] - t[0]

        kODE = ode(self.kuramoto_ODE, jac=self.kuramoto_ODE_jac)
        # 5th-order Runge-Kutta methods
        kODE.set_integrator("dopri5")

        # Set parameters into model
        kODE.set_initial_value(y.copy(), t[0])
        kODE.set_f_params((w.copy(), k.copy()))
        kODE.set_jac_params((w.copy(), k.copy()))

        phase = np.empty((self.size, len(t)))

        # Run ODE integrator
        for idx, _t in enumerate(t[1:]):
            phase[:, idx] = kODE.y
            kODE.integrate(_t)

        phase[:, -1] = kODE.y

        return phase
コード例 #10
0
y0 = [20.0, 10.0]

# Additional parameters being passed to the ODE function
alpha = 0.01
beta = 0.02
gamma = 0.02
delta = 0.04

t0 = 0  # Starting time for simulation
tf = 20  # Time to end the simulation
dt = 0.01  # time step for integrator
ta = arange(t0, tf + dt, dt)  # Time span
ys = linspace(0, max(y0), 1000)  # ys for plotting dy/dt

# Call function that integrates the ODE:
r = ode(f)
r.set_integrator('dopri5', atol=1e-6, rtol=1e-3)
r.set_initial_value(y0, t0)
r.set_f_params(dudt, dvdt, alpha, beta, gamma, delta)

sol = []
sol.append(y0)
for t in ta[:-1]:
    r.integrate(r.t + dt)
    sol.append(r.y)
sol = array(sol).T

#Plot the solution:
fig = figure(figsize=(12, 5))
ax1 = fig.add_subplot(121)
ax1.plot(ta, sol[0], '-', lw=2.0, label=r'$u$')
コード例 #11
0
ファイル: predPrey.py プロジェクト: pf4d/ode_plot
y0 = [20.0, 10.0]

# Additional parameters being passed to the ODE function
alpha = 0.01
beta = 0.02
gamma = 0.02
delta = 0.04

t0 = 0  # Starting time for simulation
tf = 20  # Time to end the simulation
dt = 0.01  # time step for integrator
ta = arange(t0, tf + dt, dt)  # Time span
ys = linspace(0, max(y0), 1000)  # ys for plotting dy/dt

# Call function that integrates the ODE:
r = ode(f)
r.set_integrator("dopri5", atol=1e-6, rtol=1e-3)
r.set_initial_value(y0, t0)
r.set_f_params(dudt, dvdt, alpha, beta, gamma, delta)

sol = []
sol.append(y0)
for t in ta[:-1]:
    r.integrate(r.t + dt)
    sol.append(r.y)
sol = array(sol).T

# Plot the solution:
fig = figure(figsize=(12, 5))
ax1 = fig.add_subplot(121)
ax1.plot(ta, sol[0], "-", lw=2.0, label=r"$u$")
コード例 #12
0
        def predict(dt, fx=0.):
            r = ode(dfx_dt).set_integrator('dopri5')
            r.set_initial_value(fl(fx), 0)
            r.integrate(dt)

            return ufl(r.y)