[SciPy-Dev] dopri ODE integrator solout integration constraints
Janick Martinez Esturo
martinez@isg.cs.uni-magdeburg...
Fri Sep 17 07:40:01 CDT 2010
Hi,
I need to be able to observe and possibly stop an ODE integration using
the scipy.integrate.ode dopri5 and dopri853 integrators. However, the
supporting call of the _solout method is completely disabled as the
fortran iout parameter is set to zero inside the wrapper code. I therefore
attached a patch that does not break the existing interface and enables the
usage of a costum _solout method by overwriting the method in a derived class
as follows:
from scipy.integrate.ode import ode, dopri5, IntegratorBase
class mydopri5(dopri5):
name = 'mydopri5'
def _solout(self, nr,xold,x,y,nd,icomp,con):
print("Costum solout with variable access ", x, y)
return(1) #Note: return -1 to break
def reset(self,n,has_jac):
super(mydopri5, self).reset(n, has_jac)
self._iout = 1
self.call_args = [self.rtol,self.atol,self._solout,self._iout,self.work,self.iwork]
if mydopri5.runner:
IntegratorBase.integrator_classes.append(mydopri5)
y0, t0 = [1.0, 2.0], 0
def f(t, y):
return [y[0] + y[1], -y[1]**2]
r = ode(f).set_integrator('mydopri5')
r.set_initial_value(y0, t0)
r.integrate(10)
print r.t, r.y
Here I derived from dopri5 overwrote the reset method to be called with
iout=1 and implemented a simple _solout callback.
I'm using this code in a productive environment and just wanted to know if
there is a chance that the patch might get included in a future release of
scipy or what would be necessary to to so? I'm not experienced with Fortran
libs, but it might be interesting to make the Fortran CONTD5 function
also avaible to be called from the _solout method in order to interpolate
intermediate values correctly, but that would require a little bit more efford
i guess.
Any comments about this would be nice.
Greets Janick
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: scipy-dopri_solout.patch
Url: http://mail.scipy.org/pipermail/scipy-dev/attachments/20100917/90a55fb2/attachment.pl
More information about the SciPy-Dev
mailing list