-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TST: Add check for throwing exception inside RHS
- Loading branch information
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
packages/scikits-odes/src/scikits/odes/tests/test_error_handling.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Authors: B. Malengier, russel (scipy trac) | ||
""" | ||
Tests for differential algebraic equation solvers. | ||
Here we test onroot and ontstop | ||
""" | ||
import numpy as np | ||
|
||
from scikits.odes import ode | ||
from scikits.odes.sundials.cvode import StatusEnum | ||
from scikits.odes.sundials.common_defs import DTYPE | ||
|
||
#data | ||
g = 9.81 # gravitational constant | ||
|
||
Y0 = 1000.0 # Initial height | ||
Y1 = 10.0 # Bottom height - when reached, changes to Y0 (teleport) | ||
T1 = 10.0 # stop time | ||
v0 = 0.0 # Initial speed | ||
|
||
#initial data at t=0, y[0] = Y, y[1] = \dot{Y} | ||
y0 = [Y0, v0] | ||
t_end1 = 10.0 # Time of free fall for experiments 1,2 | ||
t_end2 = 100.0 # Time of free fall for experiments 3,4 | ||
|
||
atol = 1e-4 | ||
rtol = 1e-4 | ||
|
||
|
||
def rhs_fn_except(self, t, y, ydot): | ||
""" rhs equations for the problem """ | ||
if t > 5: | ||
raise Exception("We can't go above t = 10") | ||
ydot[0] = y[1] | ||
ydot[1] = -g | ||
|
||
def test_cvode_rhs_exception(self): | ||
#test calling sequence. End is reached before root is found | ||
tspan = np.arange(0, t_end1 + 1, 1.0, DTYPE) | ||
solver = ode('cvode', rhs_fn_except, old_api=False) | ||
soln = solver.solve(tspan, y0) |