[SciPy-user] passing vector to integrate.ode

A.Reeve asreeve@maine....
Tue Jul 14 13:08:22 CDT 2009


I'm attempting to use the scipy integrators to solve a suite of similar 
ODE's within a finite volume model (one system of equations in each grid 
cell of the model). Currently, I'm looping over each cell in the model and 
applying ode from scipy integrate. Is it possible to speed this up by 
passing vectors of my parameters to the ode method?

Here's what I'm currently doing:

---
from scipy.integrate import ode
import numpy as N

def MDiff1(t,C,k,porI,porM):
     #function for conc exchange between mobile and immobile domains
     #C[0] is mobile and and C[1] is immobile concentration
     dCI=(k/porI)*(C[0]-C[1])
     dCM=(k/porM)*(C[1]-C[0])
     return N.array([dCM,dCI])


porI=N.array([.5,.5,.5])
porM=N.array([.2,.2,.2])
dt=5000.
k=1.e-6

CMob=N.array([10.,10.,10.])
CIm=N.array([10.1,5.,1.])

r = ode(MDiff1)
r.set_integrator('vode', method='adams')

for i in range(1): #loop over time
     for j in range(3): #loop over cells
         r.set_initial_value(N.array([CMob[j],CIm[j]]))
         r.set_f_params(k,porI[j],porM[j])
         r.integrate(r.t+dt)
         print (i+1)*r.t,r.y#, r.y[0]*porM+r.y[1]*porI
         CMob[j],CIm[j]=r.y
---

In my simulation, CMob, CIm, porM, and porI are vectors with lenths in 
the thousands. Are there better (faster) ways of doing this?


Andrew Reeve
Dept. of Earth Sciences
University of Maine


More information about the SciPy-user mailing list