1212
1313from numpy .testing import TestCase , run_module_suite
1414
15- from scikits .odes import dae
16- from scikits .odes .sundials .ida import StatusEnumIDA
17- from scikits .odes .sundials .common_defs import DTYPE
15+ from .. import dae
16+ from ..sundials import log_error_handler , ontstop_stop , onroot_stop
17+ from ..sundials .ida import StatusEnumIDA
18+ from ..sundials .common_defs import DTYPE
19+
20+ COMMON_ARGS = {
21+ "old_api" : False ,
22+ "err_handler" : log_error_handler
23+ }
1824
1925#data
2026g = 9.81 # gravitational constant
@@ -65,12 +71,6 @@ def onroot_va(t, y, ydot, solver):
6571
6672 return 0
6773
68- def onroot_vb (t , y , ydot , solver ):
69- """
70- onroot function to stop solver when root is found
71- """
72- return 1
73-
7474def onroot_vc (t , y , ydot , solver ):
7575 """
7676 onroot function to reset the solver back at the start, but keep the current
@@ -105,12 +105,6 @@ def ontstop_va(t, y, ydot, solver):
105105
106106 return 0
107107
108- def ontstop_vb (t , y , ydot , solver ):
109- """
110- ontstop function to stop solver when tstop is reached
111- """
112- return 1
113-
114108def ontstop_vc (t , y , ydot , solver ):
115109 """
116110 ontstop function to reset the solver back at the start, but keep the current
@@ -134,7 +128,7 @@ def test_ida_rootfn_noroot(self):
134128 #test calling sequence. End is reached before root is found
135129 tspan = np .arange (0 , t_end1 + 1 , 1.0 , DTYPE )
136130 solver = dae ('ida' , rhs_fn , nr_rootfns = 1 , rootfn = root_fn ,
137- old_api = False )
131+ ** COMMON_ARGS )
138132 soln = solver .solve (tspan , y0 , yp0 )
139133 assert soln .flag == StatusEnumIDA .SUCCESS , "ERROR: Error occurred"
140134 assert allclose ([soln .values .t [- 1 ], soln .values .y [- 1 ,0 ], soln .values .y [- 1 ,1 ]],
@@ -145,7 +139,7 @@ def test_ida_rootfn(self):
145139 #test root finding and stopping: End is reached at a root
146140 tspan = np .arange (0 , t_end2 + 1 , 1.0 , DTYPE )
147141 solver = dae ('ida' , rhs_fn , nr_rootfns = 1 , rootfn = root_fn ,
148- old_api = False )
142+ ** COMMON_ARGS )
149143 soln = solver .solve (tspan , y0 , yp0 )
150144 assert soln .flag == StatusEnumIDA .ROOT_RETURN , "ERROR: Root not found!"
151145 assert allclose ([soln .roots .t [0 ], soln .roots .y [0 ,0 ], soln .roots .y [0 ,1 ]],
@@ -157,7 +151,7 @@ def test_ida_rootfnacc(self):
157151 tspan = np .arange (0 , t_end2 + 1 , 1.0 , DTYPE )
158152 solver = dae ('ida' , rhs_fn , nr_rootfns = 1 , rootfn = root_fn ,
159153 onroot = onroot_va ,
160- old_api = False )
154+ ** COMMON_ARGS )
161155 soln = solver .solve (tspan , y0 , yp0 )
162156 assert soln .flag == StatusEnumIDA .SUCCESS , "ERROR: Error occurred"
163157 assert allclose ([soln .values .t [- 1 ], soln .values .y [- 1 ,0 ], soln .values .y [- 1 ,1 ]],
@@ -172,8 +166,8 @@ def test_ida_rootfn_stop(self):
172166 #test root finding and stopping: End is reached at a root with a function
173167 tspan = np .arange (0 , t_end2 + 1 , 1.0 , DTYPE )
174168 solver = dae ('ida' , rhs_fn , nr_rootfns = 1 , rootfn = root_fn ,
175- onroot = onroot_vb ,
176- old_api = False )
169+ onroot = onroot_stop ,
170+ ** COMMON_ARGS )
177171 soln = solver .solve (tspan , y0 , yp0 )
178172 assert soln .flag == StatusEnumIDA .ROOT_RETURN , "ERROR: Root not found!"
179173 assert allclose ([soln .roots .t [- 1 ], soln .roots .y [- 1 ,0 ], soln .roots .y [- 1 ,1 ]],
@@ -185,7 +179,7 @@ def test_ida_rootfn_test(self):
185179 tspan = np .arange (0 , t_end2 + 1 , 1.0 , DTYPE )
186180 solver = dae ('ida' , rhs_fn , nr_rootfns = 1 , rootfn = root_fn ,
187181 onroot = onroot_vc ,
188- old_api = False )
182+ ** COMMON_ARGS )
189183 soln = solver .solve (tspan , y0 , yp0 )
190184 assert soln .flag == StatusEnumIDA .ROOT_RETURN , "ERROR: Not sufficient root found"
191185 assert allclose ([soln .values .t [- 1 ], soln .values .y [- 1 ,0 ], soln .values .y [- 1 ,1 ]],
@@ -201,7 +195,7 @@ def test_ida_rootfn_two(self):
201195 tspan = np .arange (0 , t_end2 + 1 , 1.0 , DTYPE )
202196 solver = dae ('ida' , rhs_fn , nr_rootfns = 2 , rootfn = root_fn2 ,
203197 onroot = onroot_vc ,
204- old_api = False )
198+ ** COMMON_ARGS )
205199 soln = solver .solve (tspan , y0 , yp0 )
206200 assert soln .flag == StatusEnumIDA .ROOT_RETURN , "ERROR: Not sufficient root found"
207201 assert allclose ([soln .values .t [- 1 ], soln .values .y [- 1 ,0 ], soln .values .y [- 1 ,1 ]],
@@ -217,7 +211,7 @@ def test_ida_rootfn_end(self):
217211 tspan = np .arange (0 , 30 + 1 , 1.0 , DTYPE )
218212 solver = dae ('ida' , rhs_fn , nr_rootfns = 1 , rootfn = root_fn3 ,
219213 onroot = onroot_vc ,
220- old_api = False )
214+ ** COMMON_ARGS )
221215 soln = solver .solve (tspan , y0 , yp0 )
222216 assert soln .flag == StatusEnumIDA .ROOT_RETURN , "ERROR: Not sufficient root found"
223217 assert allclose ([soln .values .t [- 1 ], soln .values .y [- 1 ,0 ], soln .values .y [- 1 ,1 ]],
@@ -234,7 +228,7 @@ def test_ida_tstopfn_notstop(self):
234228 n = 0
235229 tspan = np .arange (0 , t_end1 + 1 , 1.0 , DTYPE )
236230 solver = dae ('ida' , rhs_fn , tstop = T1 + 1 , ontstop = ontstop_va ,
237- old_api = False )
231+ ** COMMON_ARGS )
238232 soln = solver .solve (tspan , y0 , yp0 )
239233 assert soln .flag == StatusEnumIDA .SUCCESS , "ERROR: Error occurred"
240234 assert allclose ([soln .values .t [- 1 ], soln .values .y [- 1 ,0 ], soln .values .y [- 1 ,1 ]],
@@ -247,7 +241,7 @@ def test_ida_tstopfn(self):
247241 n = 0
248242 tspan = np .arange (0 , t_end2 + 1 , 1.0 , DTYPE )
249243 solver = dae ('ida' , rhs_fn , tstop = T1 ,
250- old_api = False )
244+ ** COMMON_ARGS )
251245 soln = solver .solve (tspan , y0 , yp0 )
252246 assert soln .flag == StatusEnumIDA .TSTOP_RETURN , "ERROR: Tstop not found!"
253247 assert allclose ([soln .tstop .t [0 ], soln .tstop .y [0 ,0 ], soln .tstop .y [0 ,1 ]],
@@ -263,7 +257,7 @@ def test_ida_tstopfnacc(self):
263257 n = 0
264258 tspan = np .arange (0 , t_end2 + 1 , 1.0 , DTYPE )
265259 solver = dae ('ida' , rhs_fn , tstop = T1 , ontstop = ontstop_va ,
266- old_api = False )
260+ ** COMMON_ARGS )
267261 soln = solver .solve (tspan , y0 , yp0 )
268262 assert soln .flag == StatusEnumIDA .SUCCESS , "ERROR: Error occurred"
269263 assert allclose ([soln .values .t [- 1 ], soln .values .y [- 1 ,0 ], soln .values .y [- 1 ,1 ]],
@@ -279,8 +273,8 @@ def test_ida_tstopfn_stop(self):
279273 global n
280274 n = 0
281275 tspan = np .arange (0 , t_end2 + 1 , 1.0 , DTYPE )
282- solver = dae ('ida' , rhs_fn , tstop = T1 , ontstop = ontstop_vb ,
283- old_api = False )
276+ solver = dae ('ida' , rhs_fn , tstop = T1 , ontstop = ontstop_stop ,
277+ ** COMMON_ARGS )
284278
285279 soln = solver .solve (tspan , y0 , yp0 )
286280 assert soln .flag == StatusEnumIDA .TSTOP_RETURN , "ERROR: Error occurred"
@@ -300,7 +294,7 @@ def test_ida_tstopfn_test(self):
300294 n = 0
301295 tspan = np .arange (0 , t_end2 + 1 , 1.0 , DTYPE )
302296 solver = dae ('ida' , rhs_fn , tstop = T1 , ontstop = ontstop_vc ,
303- old_api = False )
297+ ** COMMON_ARGS )
304298
305299 soln = solver .solve (tspan , y0 , yp0 )
306300 assert soln .flag == StatusEnumIDA .TSTOP_RETURN , "ERROR: Error occurred"
0 commit comments