Passing params to cythonized ode_system()
Hi, I am trying to code a batch process to solve an ODE many times over a range of parameters. I am using a modified version of an example in the sage documentation:
%cython
cimport sage.gsl.ode
import sage.gsl.ode
include 'gsl.pxi'
cdef class duffing_osc(sage.gsl.ode.ode_system):
cdef int c_f(self,double t, double *y,double *dydt):
dydt[0]=y[1]
dydt[1]=y[0]-params[0]*y[1]-y[0]*y[0]*y[0]+params[1]*cos(params[2]*t)
return GSL_SUCCESS
cdef int c_j(self, double t,double *y,double *dfdy,double *dfdt):
dfdy[0]=0
dfdy[1]=1.0
dfdy[2]=-3*y[0]*y[0]+1
dfdy[3]=-params[0]*y[1]
dfdt[0]=0
dfdt[1]=-params[1]*params[2]*sin(params[2]*t)
return GSL_SUCCESS
Now, the problem of course is that when trying to generate the .spyx file, param is undeclared, since I can't overload the c_f and c_j functions. Is there a way I can further modify my derived class (duffing_osc) so that when I instantiate an object I can pass in the parameters, such as d = duffing_osc(params). Then I suppose I would have to change params[i] to self.params[i] in my definitions for c_f and c_j.