|
| 1 | +# Authors: B. Malengier, russel (scipy trac) |
| 2 | +""" |
| 3 | +Tests for differential algebraic equation solvers. |
| 4 | +Here we test onroot and ontstop |
| 5 | +""" |
| 6 | +import numpy as np |
| 7 | + |
| 8 | +from scikits.odes import ode |
| 9 | +from scikits.odes.sundials.cvode import StatusEnum |
| 10 | +from scikits.odes.sundials.common_defs import DTYPE |
| 11 | + |
| 12 | +#data |
| 13 | +g = 9.81 # gravitational constant |
| 14 | + |
| 15 | +Y0 = 1000.0 # Initial height |
| 16 | +Y1 = 10.0 # Bottom height - when reached, changes to Y0 (teleport) |
| 17 | +T1 = 10.0 # stop time |
| 18 | +v0 = 0.0 # Initial speed |
| 19 | + |
| 20 | +#initial data at t=0, y[0] = Y, y[1] = \dot{Y} |
| 21 | +y0 = [Y0, v0] |
| 22 | +t_end1 = 10.0 # Time of free fall for experiments 1,2 |
| 23 | +t_end2 = 100.0 # Time of free fall for experiments 3,4 |
| 24 | + |
| 25 | +atol = 1e-4 |
| 26 | +rtol = 1e-4 |
| 27 | + |
| 28 | + |
| 29 | +def rhs_fn_except(t, y, ydot): |
| 30 | + """ rhs equations for the problem """ |
| 31 | + if t > 5: |
| 32 | + raise Exception("We can't go above t = 10") |
| 33 | + ydot[0] = y[1] |
| 34 | + ydot[1] = -g |
| 35 | + |
| 36 | +def test_cvode_rhs_exception(): |
| 37 | + #test calling sequence. End is reached before root is found |
| 38 | + tspan = np.arange(0, t_end1 + 1, 1.0, DTYPE) |
| 39 | + solver = ode('cvode', rhs_fn_except, old_api=False) |
| 40 | + soln = solver.solve(tspan, y0) |
0 commit comments