title: algebraic constraint to terminate ODE integration with scipy
body: <p>I'm using Scipy 14.0 to solve a system of ordinary differential equations describing the dynamics of a gas bubble rising vertically (in the z direction) in a standing still fluid because of buoyancy forces. In particular, I have an equation expressing the rising velocity U as a function of bubble radius R, i.e. U=dz/dt=f(R), and one expressing the radius variation as a function of R and U, i.e. dR/dT=f(R,U). All the rest appearing in the code below are material properties.
  I'd like to implement something to account for the physical constraint on z which, obviously, is limited by the liquid height H. I consequently implemented a sort of z&lt;=H constraint in order to stop integration in advance if needed: I used set_solout in order to do so. The situation is that the code runs and gives good results, but set_solout is not working at all (it seems like z_constraint is never called actually...). Do you know why? 
  Is there somebody with a more clever idea, may be also in order to interrupt exactly when z=H (i.e. a final value problem) ? is this the right way/tool or should I reformulate the problem?</p>
  
  <p>thanks in advance</p>
  
  <p>Emi</p>
  
  <pre><code>from scipy.integrate import ode 
  
  Db0 = 0.001 # init bubble radius
  y0, t0 = [ Db0/2 , 0. ], 0. #init conditions
  H = 1
  
  def y_(t,y,g,p0,rho_g,mi_g,sig_g,H):
      R = y[0] 
      z = y[1]
      z_ = ( R**2 * g * rho_g ) / ( 3*mi_g )  #velocity
      R_ = ( R/3 * g * rho_g * z_ ) / ( p0 + rho_g*g*(H-z) + 4/3*sig_g/R ) #R dynamics    
      return [R_, z_]
  
  def z_constraint(t,y):
      H = 1  #should rather be a variable..
      z = y[1] 
      if z &gt;= H:
          flag = -1 
      else:
          flag = 0
      return flag
  
  r = ode( y_ )
  r.set_integrator('dopri5')
  r.set_initial_value(y0, t0)
  r.set_f_params(g, 5*1e5, 2000, 40, 0.31, H)
  r.set_solout(z_constraint)
  
  t1 = 6
  dt = 0.1
  
  while r.successful() and r.t &lt; t1:
      r.integrate(r.t+dt)
  </code></pre>