diff --git a/examples/glimda_vanderpol.py b/examples/glimda_vanderpol.py index 8cc75939..b45f3b0a 100644 --- a/examples/glimda_vanderpol.py +++ b/examples/glimda_vanderpol.py @@ -86,7 +86,7 @@ def f(t,y,yd): #Basic test x1 = y[:,0] - assert float(x1[-1]) == pytest.approx(1.706168035, abs = 1e-3) + assert x1[-1][0] == pytest.approx(1.706168035, abs = 1e-3) return imp_mod, imp_sim diff --git a/src/ode.pyx b/src/ode.pyx index 9707e217..20df8f1c 100644 --- a/src/ode.pyx +++ b/src/ode.pyx @@ -58,9 +58,9 @@ cdef class ODE: "sensitivity_calculations":False, "interpolated_sensitivity_output":False, "rtol_as_vector":False} - self.problem_info = {"dim":0,"dimRoot":0,"dimSens":0,"state_events":False,"step_events":False,"time_events":False - ,"jac_fcn":False, "sens_fcn":False, "jacv_fcn":False,"switches":False,"type":0,"jaclag_fcn":False,'prec_solve':False,'prec_setup':False - ,"jac_fcn_nnz": -1} + self.problem_info = {"dim":0,"dimRoot":0,"dimSens":0,"state_events":False,"step_events":False,"time_events":False, + "jac_fcn":False, "sens_fcn":False, "jacv_fcn":False,"switches":False,"type":0,"jaclag_fcn":False, + 'prec_solve':False, 'prec_setup':False, "jac_fcn_nnz": -1} #Type of the problem #0 = Explicit #1 = Implicit diff --git a/src/solvers/radau5.py b/src/solvers/radau5.py index 16efa4ce..0c66f156 100644 --- a/src/solvers/radau5.py +++ b/src/solvers/radau5.py @@ -642,11 +642,11 @@ def _step(self, t, y): def _collocation_pol(self, Z, col_poly, leny): - col_poly[2*leny:3*leny] = Z[:leny] / self.C[0,0] - col_poly[leny:2*leny] = ( Z[:leny] - Z[leny:2*leny] ) / (self.C[0,0]-self.C[1,0]) - col_poly[:leny] = ( Z[leny:2*leny] -Z[2*leny:3*leny] ) / (self.C[1,0]-1.) - col_poly[2*leny:3*leny] = ( col_poly[leny:2*leny] - col_poly[2*leny:3*leny] ) / self.C[1,0] - col_poly[leny:2*leny] = ( col_poly[leny:2*leny] - col_poly[:leny] ) / (self.C[0,0]-1.) + col_poly[2*leny:3*leny] = Z[:leny] / self.C[0] + col_poly[leny:2*leny] = ( Z[:leny] - Z[leny:2*leny] ) / (self.C[0]-self.C[1]) + col_poly[:leny] = ( Z[leny:2*leny] -Z[2*leny:3*leny] ) / (self.C[1]-1.) + col_poly[2*leny:3*leny] = ( col_poly[leny:2*leny] - col_poly[2*leny:3*leny] ) / self.C[1] + col_poly[leny:2*leny] = ( col_poly[leny:2*leny] - col_poly[:leny] ) / (self.C[0]-1.) col_poly[2*leny:3*leny] = col_poly[leny:2*leny]-col_poly[2*leny:3*leny] return col_poly @@ -657,9 +657,9 @@ def _radau_F(self, Z, t, y): Z2 = Z[self._leny:2*self._leny] Z3 = Z[2*self._leny:3*self._leny] - self.f(self.Y1,t+self.C[0]*self.h, y+Z1) - self.f(self.Y2,t+self.C[1]*self.h, y+Z2) - self.f(self.Y3,t+self.C[2]*self.h, y+Z3) + self.f(self.Y1, t + self.C[0] * self.h, y + Z1) + self.f(self.Y2, t + self.C[1] * self.h, y + Z2) + self.f(self.Y3, t + self.C[2] * self.h, y + Z3) self.statistics["nfcns"] += 3 @@ -678,9 +678,9 @@ def calc_start_values(self): newtval = self._col_poly leny = self._leny - Z[:leny] = cq[0,0]*(newtval[:leny]+(cq[0,0]-self.C[1,0]+1.)*(newtval[leny:2*leny]+(cq[0,0]-self.C[0,0]+1.)*newtval[2*leny:3*leny])) - Z[leny:2*leny] = cq[1,0]*(newtval[:leny]+(cq[1,0]-self.C[1,0]+1.)*(newtval[leny:2*leny]+(cq[1,0]-self.C[0,0]+1.)*newtval[2*leny:3*leny])) - Z[2*leny:3*leny]= cq[2,0]*(newtval[:leny]+(cq[2,0]-self.C[1,0]+1.)*(newtval[leny:2*leny]+(cq[2,0]-self.C[0,0]+1.)*newtval[2*leny:3*leny])) + Z[:leny] = cq[0]*(newtval[:leny]+(cq[0]-self.C[1]+1.)*(newtval[leny:2*leny]+(cq[0]-self.C[0]+1.)*newtval[2*leny:3*leny])) + Z[leny:2*leny] = cq[1]*(newtval[:leny]+(cq[1]-self.C[1]+1.)*(newtval[leny:2*leny]+(cq[1]-self.C[0]+1.)*newtval[2*leny:3*leny])) + Z[2*leny:3*leny]= cq[2]*(newtval[:leny]+(cq[2]-self.C[1]+1.)*(newtval[leny:2*leny]+(cq[2]-self.C[0]+1.)*newtval[2*leny:3*leny])) W = np.dot(self.T2,Z) @@ -872,7 +872,7 @@ def interpolate(self, t, k=0): s = (t-self._newt)/self._oldh Z = self._col_poly - yout = self._yc+s*(Z[:leny]+(s-self.C[1,0]+1.)*(Z[leny:2*leny]+(s-self.C[0,0]+1.)*Z[2*leny:3*leny])) + yout = self._yc+s*(Z[:leny]+(s-self.C[1]+1.)*(Z[leny:2*leny]+(s-self.C[0]+1.)*Z[2*leny:3*leny])) return yout def _load_parameters(self): @@ -889,15 +889,15 @@ def _load_parameters(self): A[2,1] = (16.0+np.sqrt(6.))/36.0 A[2,2] = (1.0/9.0) - C = np.zeros([3,1]) - C[0,0]=(4.0-np.sqrt(6.0))/10.0 - C[1,0]=(4.0+np.sqrt(6.0))/10.0 - C[2,0]=1.0 + C = np.zeros([3]) + C[0]=(4.0-np.sqrt(6.0))/10.0 + C[1]=(4.0+np.sqrt(6.0))/10.0 + C[2]=1.0 - B = np.zeros([1,3]) - B[0,0]=(16.0-np.sqrt(6.0))/36.0 - B[0,1]=(16.0+np.sqrt(6.0))/36.0 - B[0,2]=1.0/9.0 + B = np.zeros([3]) + B[0]=(16.0-np.sqrt(6.0))/36.0 + B[1]=(16.0+np.sqrt(6.0))/36.0 + B[2]=1.0/9.0 E = np.zeros(3) E[0] = -13.0-7.*np.sqrt(6.) @@ -1641,7 +1641,7 @@ def interpolate(self, t, k=0): s = (t-self._newt)/self._oldh Z = self._col_poly - diff = s*(Z[:leny]+(s-self.C[1,0]+1.)*(Z[leny:2*leny]+(s-self.C[0,0]+1.)*Z[2*leny:3*leny])) + diff = s*(Z[:leny]+(s-self.C[1]+1.)*(Z[leny:2*leny]+(s-self.C[0]+1.)*Z[2*leny:3*leny])) yout = self._yc + diff[:self._leny] ydout = self._ydc+ diff[self._leny:] @@ -1715,11 +1715,11 @@ def adjust_stepsize(self, err, predict=False): def _collocation_pol(self, Z, col_poly, leny): - col_poly[2*leny:3*leny] = Z[:leny] / self.C[0,0] - col_poly[leny:2*leny] = ( Z[:leny] - Z[leny:2*leny] ) / (self.C[0,0]-self.C[1,0]) - col_poly[:leny] = ( Z[leny:2*leny] -Z[2*leny:3*leny] ) / (self.C[1,0]-1.) - col_poly[2*leny:3*leny] = ( col_poly[leny:2*leny] - col_poly[2*leny:3*leny] ) / self.C[1,0] - col_poly[leny:2*leny] = ( col_poly[leny:2*leny] - col_poly[:leny] ) / (self.C[0,0]-1.) + col_poly[2*leny:3*leny] = Z[:leny] / self.C[0] + col_poly[leny:2*leny] = ( Z[:leny] - Z[leny:2*leny] ) / (self.C[0]-self.C[1]) + col_poly[:leny] = ( Z[leny:2*leny] -Z[2*leny:3*leny] ) / (self.C[1]-1.) + col_poly[2*leny:3*leny] = ( col_poly[leny:2*leny] - col_poly[2*leny:3*leny] ) / self.C[1] + col_poly[leny:2*leny] = ( col_poly[leny:2*leny] - col_poly[:leny] ) / (self.C[0]-1.) col_poly[2*leny:3*leny] = col_poly[leny:2*leny]-col_poly[2*leny:3*leny] return col_poly @@ -1737,9 +1737,9 @@ def calc_start_values(self): newtval = self._col_poly leny = self._2leny - Z[:leny] = cq[0,0]*(newtval[:leny]+(cq[0,0]-self.C[1,0]+1.)*(newtval[leny:2*leny]+(cq[0,0]-self.C[0,0]+1.)*newtval[2*leny:3*leny])) - Z[leny:2*leny] = cq[1,0]*(newtval[:leny]+(cq[1,0]-self.C[1,0]+1.)*(newtval[leny:2*leny]+(cq[1,0]-self.C[0,0]+1.)*newtval[2*leny:3*leny])) - Z[2*leny:3*leny]= cq[2,0]*(newtval[:leny]+(cq[2,0]-self.C[1,0]+1.)*(newtval[leny:2*leny]+(cq[2,0]-self.C[0,0]+1.)*newtval[2*leny:3*leny])) + Z[:leny] = cq[0]*(newtval[:leny]+(cq[0]-self.C[1]+1.)*(newtval[leny:2*leny]+(cq[0]-self.C[0]+1.)*newtval[2*leny:3*leny])) + Z[leny:2*leny] = cq[1]*(newtval[:leny]+(cq[1]-self.C[1]+1.)*(newtval[leny:2*leny]+(cq[1]-self.C[0]+1.)*newtval[2*leny:3*leny])) + Z[2*leny:3*leny]= cq[2]*(newtval[:leny]+(cq[2]-self.C[1]+1.)*(newtval[leny:2*leny]+(cq[2]-self.C[0]+1.)*newtval[2*leny:3*leny])) W = np.dot(self.T2,Z) @@ -1759,15 +1759,15 @@ def _load_parameters(self): A[2,1] = (16.0+np.sqrt(6.))/36.0 A[2,2] = (1.0/9.0) - C = np.zeros([3,1]) - C[0,0]=(4.0-np.sqrt(6.0))/10.0 - C[1,0]=(4.0+np.sqrt(6.0))/10.0 - C[2,0]=1.0 + C = np.zeros([3]) + C[0]=(4.0-np.sqrt(6.0))/10.0 + C[1]=(4.0+np.sqrt(6.0))/10.0 + C[2]=1.0 - B = np.zeros([1,3]) - B[0,0]=(16.0-np.sqrt(6.0))/36.0 - B[0,1]=(16.0+np.sqrt(6.0))/36.0 - B[0,2]=1.0/9.0 + B = np.zeros([3]) + B[0]=(16.0-np.sqrt(6.0))/36.0 + B[1]=(16.0+np.sqrt(6.0))/36.0 + B[2]=1.0/9.0 E = np.zeros(3) E[0] = -13.0-7.*np.sqrt(6.) diff --git a/tests/solvers/test_euler.py b/tests/solvers/test_euler.py index 1c4e8ed1..156206e2 100644 --- a/tests/solvers/test_euler.py +++ b/tests/solvers/test_euler.py @@ -195,7 +195,7 @@ def test_integrator(self): values = self.simulator.simulate(1) assert self.simulator.t_sol[-1] == pytest.approx(1.0) - assert float(self.simulator.y_sol[-1]) == pytest.approx(2.0) + assert self.simulator.y_sol[-1][0] == pytest.approx(2.0) def test_step(self): """ @@ -207,7 +207,7 @@ def test_step(self): self.simulator.simulate(1) assert self.simulator.t_sol[-1] == pytest.approx(1.0) - assert float(self.simulator.y_sol[-1]) == pytest.approx(2.0) + assert self.simulator.y_sol[-1][0] == pytest.approx(2.0) def test_exception(self): """ @@ -356,7 +356,7 @@ def test_integrator(self): values = self.simulator.simulate(1) assert self.simulator.t_sol[-1] == pytest.approx(1.0) - assert float(self.simulator.y_sol[-1]) == pytest.approx(2.0) + assert self.simulator.y_sol[-1][0] == pytest.approx(2.0) def test_step(self): """ @@ -368,7 +368,7 @@ def test_step(self): self.simulator.simulate(1) assert self.simulator.t_sol[-1] == pytest.approx(1.0) - assert float(self.simulator.y_sol[-1]) == pytest.approx(2.0) + assert self.simulator.y_sol[-1][0] == pytest.approx(2.0) def test_stiff_problem(self): f = lambda t,y: -15.0*y diff --git a/tests/solvers/test_glimda.py b/tests/solvers/test_glimda.py index 5b638b61..d8ec85d8 100644 --- a/tests/solvers/test_glimda.py +++ b/tests/solvers/test_glimda.py @@ -74,7 +74,7 @@ def test_simulate_explicit(self): t,y = simulator.simulate(1.0) - assert float(y[-1]) == pytest.approx(float(np.exp(-1.0)),4) + assert y[-1][0] == pytest.approx(np.exp(-1.0),4) def test_maxord(self): """ diff --git a/tests/solvers/test_radau5.py b/tests/solvers/test_radau5.py index 689eff14..5160a241 100644 --- a/tests/solvers/test_radau5.py +++ b/tests/solvers/test_radau5.py @@ -283,7 +283,6 @@ def test_collocation_polynomial(self): assert self.sim.statistics["nsteps"] < 300 #assert self.sim.y[-2][0] == pytest.approx(1.71505001, abs = 1e-4) - print assert self.sim.y_sol[-1][0] == pytest.approx(1.7061680350, abs = 1e-4) self.sim.report_continuously = True @@ -746,6 +745,7 @@ def test_nmax_steps(self): with pytest.raises(Radau5Error, match = err_msg): sim.simulate(1.) + @pytest.mark.filterwarnings("ignore::RuntimeWarning") def test_step_size_too_small(self): """ This tests the error for too small step-sizes @@ -1192,7 +1192,7 @@ def test_simulate_explicit(self): t,y = simulator.simulate(1.0) - assert float(y[-1]) == pytest.approx(float(np.exp(-1.0)),4) + assert y[-1][0] == pytest.approx(np.exp(-1.0),4) def test_time_event(self): f = lambda t,y,yd: y-yd @@ -1326,6 +1326,7 @@ def test_nmax_steps(self): with pytest.raises(Radau5Error, match = err_msg): sim.simulate(1.) + @pytest.mark.filterwarnings("ignore::RuntimeWarning") def test_step_size_too_small(self): """ This tests the error for too small step-sizes diff --git a/tests/solvers/test_rungekutta.py b/tests/solvers/test_rungekutta.py index d01326c4..d9505bd5 100644 --- a/tests/solvers/test_rungekutta.py +++ b/tests/solvers/test_rungekutta.py @@ -44,7 +44,7 @@ def test_integrator(self): values = self.simulator.simulate(1) assert self.simulator.t_sol[-1] == pytest.approx(1.0) - assert float(self.simulator.y_sol[-1]) == pytest.approx(2.0) + assert self.simulator.y_sol[-1][0] == pytest.approx(2.0) def test_time_event(self): f = lambda t,y: [1.0] @@ -303,7 +303,7 @@ def test_integrate(self): values = self.simulator.simulate(1) assert self.simulator.t_sol[-1] == pytest.approx(1.0) - assert float(self.simulator.y_sol[-1]) == pytest.approx(2.0) + assert self.simulator.y_sol[-1][0] == pytest.approx(2.0) def test_step(self): self.simulator.report_continuously = True @@ -312,4 +312,4 @@ def test_step(self): self.simulator.simulate(1) assert self.simulator.t_sol[-1] == pytest.approx(1.0) - assert float(self.simulator.y_sol[-1]) == pytest.approx(2.0) + assert self.simulator.y_sol[-1][0] == pytest.approx(2.0) diff --git a/tests/solvers/test_sundials.py b/tests/solvers/test_sundials.py index 3e1a13ed..1bf8a87a 100644 --- a/tests/solvers/test_sundials.py +++ b/tests/solvers/test_sundials.py @@ -583,7 +583,7 @@ def test_interpolate(self): t100 = sim.t_sol sim.reset() sim.simulate(10.) - assert float(y100[-2]) == pytest.approx(float(sim.interpolate(9.9, 0)), abs = 1e-5) + assert y100[-2][0] == pytest.approx(sim.interpolate(9.9, 0)[0], abs = 1e-5) def test_ncp_list(self): f = lambda t,y:np.array(-y) @@ -594,7 +594,7 @@ def test_ncp_list(self): t, y = sim.simulate(7, ncp_list=np.arange(0, 7, 0.1)) #Simulate 5 seconds - assert float(y[-1]) == pytest.approx(0.00364832, abs = 1e-4) + assert y[-1][0] == pytest.approx(0.00364832, abs = 1e-4) def test_handle_result(self): """ @@ -918,7 +918,7 @@ def test_simulate_explicit(self): t,y = simulator.simulate(1.0) - assert float(y[-1]) == pytest.approx(float(np.exp(-1.0)),4) + assert y[-1][0] == pytest.approx(np.exp(-1.0),4) def test_init(self): """ diff --git a/tests/test_examples.py b/tests/test_examples.py index 7634dc5d..91c04f09 100644 --- a/tests/test_examples.py +++ b/tests/test_examples.py @@ -15,6 +15,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . +import pytest from assimulo.exception import AssimuloException from assimulo.examples import * @@ -37,6 +38,7 @@ def test_kinsol_basic(self): def test_kinsol_with_jac(self): kinsol_with_jac.run_example(with_plots=False) + @pytest.mark.filterwarnings("ignore::Warning") # SparseEfficiencyWarning def test_kinsol_ors(self): kinsol_ors.run_example(with_plots=False) diff --git a/tests/test_solvers.py b/tests/test_solvers.py index fd5063e9..98942680 100644 --- a/tests/test_solvers.py +++ b/tests/test_solvers.py @@ -48,18 +48,18 @@ def test_radau5dae_state_events(self): t,y,yd = solver.simulate(2,33) - assert float(y[-1]) == pytest.approx(0.135, abs = 1e-3) + assert y[-1][0] == pytest.approx(0.135, abs = 1e-3) def test_dopri5_state_events(self): solver = Dopri5(self.eproblem) t,y = solver.simulate(2,33) - assert float(y[-1]) == pytest.approx(0.135, abs = 1e-3) + assert y[-1][0] == pytest.approx(0.135, abs = 1e-3) def test_rodasode_state_events(self): solver = RodasODE(self.eproblem) t,y = solver.simulate(2,33) - assert float(y[-1]) == pytest.approx(0.135, abs = 1e-3) + assert y[-1][0] == pytest.approx(0.135, abs = 1e-3)