Skip to content

Commit

Permalink
TST: Add check for throwing exception inside RHS
Browse files Browse the repository at this point in the history
  • Loading branch information
aragilar committed Dec 12, 2024
1 parent 34641c8 commit 0ff0455
Showing 1 changed file with 40 additions and 0 deletions.
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)

0 comments on commit 0ff0455

Please sign in to comment.