From 3f8e9ead31b311398384e38f3c904a523503d29e Mon Sep 17 00:00:00 2001
From: PeterMeisrimelModelon
<92585725+PeterMeisrimelModelon@users.noreply.github.com>
Date: Wed, 24 Jan 2024 11:05:58 +0100
Subject: [PATCH] Unifying numpy imports
---
doc/sphinx/source/tutorialCVodeDisc.py | 2 +-
examples/cvode_basic.py | 4 +-
examples/cvode_basic_backward.py | 4 +-
examples/cvode_stability.py | 8 +-
examples/cvode_with_disc.py | 6 +-
examples/cvode_with_initial_sensitivity.py | 24 +-
examples/cvode_with_jac.py | 7 +-
examples/cvode_with_jac_sparse.py | 4 +-
examples/cvode_with_jac_spgmr.py | 8 +-
examples/cvode_with_parameters.py | 8 +-
examples/cvode_with_parameters_fcn.py | 14 +-
examples/cvode_with_parameters_modified.py | 8 +-
examples/dasp3_basic.py | 8 +-
examples/dopri5_basic.py | 4 +-
examples/dopri5_with_disc.py | 8 +-
examples/euler_basic.py | 4 +-
examples/euler_vanderpol.py | 8 +-
examples/euler_with_disc.py | 8 +-
examples/glimda_vanderpol.py | 4 +-
examples/ida_basic_backward.py | 4 +-
examples/ida_with_disc.py | 8 +-
examples/ida_with_initial_sensitivity.py | 26 +-
examples/ida_with_jac.py | 10 +-
examples/ida_with_jac_spgmr.py | 11 +-
examples/ida_with_parameters.py | 10 +-
.../ida_with_user_defined_handle_result.py | 10 +-
examples/kinsol_ors.py | 10 +-
examples/kinsol_with_jac.py | 6 +-
examples/lsodar_bouncing_ball.py | 9 +-
examples/lsodar_vanderpol.py | 6 +-
examples/lsodar_with_disc.py | 8 +-
examples/mech_system_pendulum.py | 29 +-
examples/radau5dae_time_events.py | 7 +-
examples/radau5dae_vanderpol.py | 6 +-
examples/radau5ode_vanderpol.py | 6 +-
examples/radau5ode_with_disc.py | 7 +-
examples/radau5ode_with_disc_sparse.py | 6 +-
examples/radau5ode_with_jac_sparse.py | 4 +-
examples/rodasode_vanderpol.py | 8 +-
examples/rungekutta34_basic.py | 4 +-
examples/rungekutta34_with_disc.py | 8 +-
examples/rungekutta4_basic.py | 4 +-
src/algebraic.pxd | 8 +-
src/algebraic.pyx | 8 +-
src/explicit_ode.pxd | 10 +-
src/explicit_ode.pyx | 41 ++-
src/implicit_ode.pxd | 6 +-
src/implicit_ode.pyx | 25 +-
src/lib/radau_core.py | 8 +-
src/lib/sundials_callbacks.pxi | 22 +-
src/lib/sundials_callbacks_ida_cvode.pxi | 132 +++----
src/lib/sundials_callbacks_kinsol.pxi | 50 +--
src/ode.pxd | 8 +-
src/ode.pyx | 36 +-
src/problem.pxd | 12 +-
src/problem.pyx | 22 +-
src/solvers/dasp3.py | 32 +-
src/solvers/euler.pyx | 87 +++--
src/solvers/glimda.py | 18 +-
src/solvers/kinsol.pyx | 20 +-
src/solvers/odepack.py | 196 +++++-----
src/solvers/radar5.py | 46 +--
src/solvers/radau5.py | 336 +++++++++---------
src/solvers/rosenbrock.py | 16 +-
src/solvers/runge_kutta.py | 50 +--
src/solvers/sdirk_dae.pyx | 38 +-
src/solvers/sundials.pyx | 88 ++---
src/special_systems.pyx | 44 +--
src/support.pxd | 3 -
src/support.pyx | 6 +-
tests/solvers/test_euler.py | 28 +-
tests/solvers/test_glimda.py | 16 +-
tests/solvers/test_odepack.py | 44 +--
tests/solvers/test_radau5.py | 110 +++---
tests/solvers/test_rosenbrock.py | 8 +-
tests/solvers/test_rungekutta.py | 10 +-
tests/test_examples.py | 1 -
tests/test_solvers.py | 2 +-
78 files changed, 960 insertions(+), 975 deletions(-)
diff --git a/doc/sphinx/source/tutorialCVodeDisc.py b/doc/sphinx/source/tutorialCVodeDisc.py
index e3dd0332..b7bf59c4 100644
--- a/doc/sphinx/source/tutorialCVodeDisc.py
+++ b/doc/sphinx/source/tutorialCVodeDisc.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
-Tutorial example showing how to use the explicit solver CVode for a discontinious problem.
+Tutorial example showing how to use the explicit solver CVode for a discontinuous problem.
To run the example simply type,
run tutorialCVodeDisc.py (in IPython)
diff --git a/examples/cvode_basic.py b/examples/cvode_basic.py
index c17cf024..ce56f90c 100644
--- a/examples/cvode_basic.py
+++ b/examples/cvode_basic.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import numpy as N
+import numpy as np
import nose
from assimulo.solvers import CVode
from assimulo.problem import Explicit_Problem
@@ -37,7 +37,7 @@ def run_example(with_plots=True):
#Define the rhs
def f(t,y):
ydot = -y[0]
- return N.array([ydot])
+ return np.array([ydot])
#Define an Assimulo problem
exp_mod = Explicit_Problem(f, y0=4, name = r'CVode Test Example: $\dot y = - y$')
diff --git a/examples/cvode_basic_backward.py b/examples/cvode_basic_backward.py
index c299a19c..6a546c01 100644
--- a/examples/cvode_basic_backward.py
+++ b/examples/cvode_basic_backward.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import numpy as N
+import numpy as np
import nose
from assimulo.solvers import CVode
from assimulo.problem import Explicit_Problem
@@ -34,7 +34,7 @@ def run_example(with_plots=True):
#Define the rhs
def f(t,y):
ydot = -y[0]
- return N.array([ydot])
+ return np.array([ydot])
#Define an Assimulo problem
exp_mod = Explicit_Problem(f,t0=5, y0=0.02695, name = r'CVode Test Example (reverse time): $\dot y = - y$ ')
diff --git a/examples/cvode_stability.py b/examples/cvode_stability.py
index 2a8b3bd2..859f5339 100644
--- a/examples/cvode_stability.py
+++ b/examples/cvode_stability.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import numpy as N
+import numpy as np
import nose
from assimulo.solvers import CVode
from assimulo.problem import Explicit_Problem
@@ -54,9 +54,9 @@ def handle_result(self, solver, t, y):
def f(t,y):
yd_0 = y[1]
yd_1 = my*((1.-y[0]**2)*y[1]-y[0])
- yd_2 = N.sin(t*y[1])
+ yd_2 = np.sin(t*y[1])
- return N.array([yd_0,yd_1, yd_2])
+ return np.array([yd_0,yd_1, yd_2])
y0 = [2.0,-0.6, 0.1] #Initial conditions
@@ -89,7 +89,7 @@ def f(t,y):
#Basic test
x1 = y[:,0]
- nose.tools.assert_less(N.abs(float(x1[-1]) - 1.8601438), 1e-1)
+ nose.tools.assert_less(np.abs(float(x1[-1]) - 1.8601438), 1e-1)
return exp_mod, exp_sim
diff --git a/examples/cvode_with_disc.py b/examples/cvode_with_disc.py
index 26f409ca..e2041c53 100644
--- a/examples/cvode_with_disc.py
+++ b/examples/cvode_with_disc.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import numpy as N
+import numpy as np
import nose
from assimulo.solvers import CVode
from assimulo.problem import Explicit_Problem
@@ -50,7 +50,7 @@ def rhs(self,t,y,sw):
yd_1 = 0.0
yd_2 = 0.0
- return N.array([yd_0,yd_1,yd_2])
+ return np.array([yd_0,yd_1,yd_2])
#Sets a name to our function
name = 'ODE with discontinuities and a function with consistency problem'
@@ -65,7 +65,7 @@ def state_events(self,t,y,sw):
event_1 = -y[2] + 1.0
event_2 = -t + 1.0
- return N.array([event_0,event_1,event_2])
+ return np.array([event_0,event_1,event_2])
#Responsible for handling the events.
diff --git a/examples/cvode_with_initial_sensitivity.py b/examples/cvode_with_initial_sensitivity.py
index 84c21858..8404c55f 100644
--- a/examples/cvode_with_initial_sensitivity.py
+++ b/examples/cvode_with_initial_sensitivity.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import numpy as N
+import numpy as np
import nose
from assimulo.solvers import CVode
from assimulo.problem import Explicit_Problem
@@ -57,12 +57,12 @@ def f(t, y, p):
yd_1 = k21*y1-(k02+k12)*y2
yd_2 = k31*y1-k13*y3
- return N.array([yd_0,yd_1,yd_2])
+ return np.array([yd_0,yd_1,yd_2])
#The initial conditions
y0 = [0.0,0.0,0.0] #Initial conditions for y
p0 = [0.0, 0.0, 0.0] #Initial conditions for parameters
- yS0 = N.array([[1,0,0],[0,1,0],[0,0,1.]])
+ yS0 = np.array([[1,0,0],[0,1,0],[0,0,1.]])
#Create an Assimulo explicit problem
exp_mod = Explicit_Problem(f, y0, p0=p0,name='Example: Computing Sensitivities')
@@ -93,25 +93,25 @@ def f(t, y, p):
legend_text=r"$\mathrm{{d}}{}/\mathrm{{d}}{}$"
P.figure(1)
P.subplot(221)
- P.plot(t, N.array(exp_sim.p_sol[0])[:,0],
- t, N.array(exp_sim.p_sol[0])[:,1],
- t, N.array(exp_sim.p_sol[0])[:,2])
+ P.plot(t, np.array(exp_sim.p_sol[0])[:,0],
+ t, np.array(exp_sim.p_sol[0])[:,1],
+ t, np.array(exp_sim.p_sol[0])[:,2])
P.title(title_text.format('p_1'))
P.legend((legend_text.format('y_1','p_1'),
legend_text.format('y_1','p_2'),
legend_text.format('y_1','p_3')))
P.subplot(222)
- P.plot(t, N.array(exp_sim.p_sol[1])[:,0],
- t, N.array(exp_sim.p_sol[1])[:,1],
- t, N.array(exp_sim.p_sol[1])[:,2])
+ P.plot(t, np.array(exp_sim.p_sol[1])[:,0],
+ t, np.array(exp_sim.p_sol[1])[:,1],
+ t, np.array(exp_sim.p_sol[1])[:,2])
P.title(title_text.format('p_2'))
P.legend((legend_text.format('y_2','p_1'),
legend_text.format('y_2','p_2'),
legend_text.format('y_2','p_3')))
P.subplot(223)
- P.plot(t, N.array(exp_sim.p_sol[2])[:,0],
- t, N.array(exp_sim.p_sol[2])[:,1],
- t, N.array(exp_sim.p_sol[2])[:,2])
+ P.plot(t, np.array(exp_sim.p_sol[2])[:,0],
+ t, np.array(exp_sim.p_sol[2])[:,1],
+ t, np.array(exp_sim.p_sol[2])[:,2])
P.title(title_text.format('p_3'))
P.legend((legend_text.format('y_3','p_1'),
legend_text.format('y_3','p_2'),
diff --git a/examples/cvode_with_jac.py b/examples/cvode_with_jac.py
index 8ca3c19e..bb34a162 100644
--- a/examples/cvode_with_jac.py
+++ b/examples/cvode_with_jac.py
@@ -15,12 +15,11 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import numpy as N
+import numpy as np
import nose
from assimulo.solvers import CVode
from assimulo.problem import Explicit_Problem
-
def run_example(with_plots=True):
r"""
Example for demonstrating the use of a user supplied Jacobian
@@ -45,11 +44,11 @@ def run_example(with_plots=True):
def f(t,y):
yd_0 = y[1]
yd_1 = -9.82
- return N.array([yd_0,yd_1])
+ return np.array([yd_0,yd_1])
#Defines the Jacobian
def jac(t,y):
- j = N.array([[0,1.],[0,0]])
+ j = np.array([[0,1.],[0,0]])
return j
#Defines an Assimulo explicit problem
diff --git a/examples/cvode_with_jac_sparse.py b/examples/cvode_with_jac_sparse.py
index e4dd330c..d7da5cc3 100644
--- a/examples/cvode_with_jac_sparse.py
+++ b/examples/cvode_with_jac_sparse.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import numpy as N
+import numpy as np
import scipy.sparse as SP
import nose
from assimulo.solvers import CVode
@@ -50,7 +50,7 @@ def f(t,y):
yd_0 = -0.04*y[0] + 1e4*y[1]*y[2]
yd_2 = 3e7*y[1]*y[1]
yd_1 = -yd_0 - yd_2
- return N.array([yd_0,yd_1,yd_2])
+ return np.array([yd_0,yd_1,yd_2])
#Defines the Jacobian
def jac(t,y):
diff --git a/examples/cvode_with_jac_spgmr.py b/examples/cvode_with_jac_spgmr.py
index 0ddcb8ec..58f0aa51 100644
--- a/examples/cvode_with_jac_spgmr.py
+++ b/examples/cvode_with_jac_spgmr.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import numpy as N
+import numpy as np
import nose
from assimulo.solvers import CVode
from assimulo.problem import Explicit_Problem
@@ -48,12 +48,12 @@ def f(t,y):
yd_0 = y[1]
yd_1 = -9.82
- return N.array([yd_0,yd_1])
+ return np.array([yd_0,yd_1])
#Defines the Jacobian*vector product
def jacv(t,y,fy,v):
- j = N.array([[0,1.],[0,0]])
- return N.dot(j,v)
+ j = np.array([[0,1.],[0,0]])
+ return np.dot(j,v)
y0 = [1.0,0.0] #Initial conditions
diff --git a/examples/cvode_with_parameters.py b/examples/cvode_with_parameters.py
index 9388ce3e..177b34ee 100644
--- a/examples/cvode_with_parameters.py
+++ b/examples/cvode_with_parameters.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import numpy as N
+import numpy as np
import nose
from assimulo.solvers import CVode
from assimulo.problem import Explicit_Problem
@@ -50,7 +50,7 @@ def f(t, y, p):
yd_1 = p[0]*y[0]-p[1]*y[1]*y[2]-p[2]*y[1]**2
yd_2 = p[2]*y[1]**2
- return N.array([yd_0,yd_1,yd_2])
+ return np.array([yd_0,yd_1,yd_2])
#The initial conditions
y0 = [1.0,0.0,0.0] #Initial conditions for y
@@ -65,11 +65,11 @@ def f(t, y, p):
#Create an Assimulo explicit solver (CVode)
exp_sim = CVode(exp_mod)
- #Sets the solver paramters
+ #Sets the solver parameters
exp_sim.iter = 'Newton'
exp_sim.discr = 'BDF'
exp_sim.rtol = 1.e-4
- exp_sim.atol = N.array([1.0e-8, 1.0e-14, 1.0e-6])
+ exp_sim.atol = np.array([1.0e-8, 1.0e-14, 1.0e-6])
exp_sim.sensmethod = 'SIMULTANEOUS' #Defines the sensitivity method used
exp_sim.suppress_sens = False #Dont suppress the sensitivity variables in the error test.
exp_sim.report_continuously = True
diff --git a/examples/cvode_with_parameters_fcn.py b/examples/cvode_with_parameters_fcn.py
index 8e1f95b5..f25c448d 100644
--- a/examples/cvode_with_parameters_fcn.py
+++ b/examples/cvode_with_parameters_fcn.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import numpy as N
+import numpy as np
import nose
from assimulo.solvers import CVode
from assimulo.problem import Explicit_Problem
@@ -50,19 +50,19 @@ def f(t, y, p):
yd_1 = p[0]*y[0]-p[1]*y[1]*y[2]-p[2]*y[1]**2
yd_2 = p[2]*y[1]**2
- return N.array([yd_0,yd_1,yd_2])
+ return np.array([yd_0,yd_1,yd_2])
def jac(t,y, p):
- J = N.array([[-p[0], p[1]*y[2], p[1]*y[1]],
+ J = np.array([[-p[0], p[1]*y[2], p[1]*y[1]],
[p[0], -p[1]*y[2]-2*p[2]*y[1], -p[1]*y[1]],
[0.0, 2*p[2]*y[1],0.0]])
return J
def fsens(t, y, s, p):
- J = N.array([[-p[0], p[1]*y[2], p[1]*y[1]],
+ J = np.array([[-p[0], p[1]*y[2], p[1]*y[1]],
[p[0], -p[1]*y[2]-2*p[2]*y[1], -p[1]*y[1]],
[0.0, 2*p[2]*y[1],0.0]])
- P = N.array([[-y[0],y[1]*y[2],0],
+ P = np.array([[-y[0],y[1]*y[2],0],
[y[0], -y[1]*y[2], -y[1]**2],
[0,0,y[1]**2]])
return J.dot(s)+P
@@ -82,11 +82,11 @@ def fsens(t, y, s, p):
#Create an Assimulo explicit solver (CVode)
exp_sim = CVode(exp_mod)
- #Sets the solver paramters
+ #Sets the solver parameters
exp_sim.iter = 'Newton'
exp_sim.discr = 'BDF'
exp_sim.rtol = 1.e-4
- exp_sim.atol = N.array([1.0e-8, 1.0e-14, 1.0e-6])
+ exp_sim.atol = np.array([1.0e-8, 1.0e-14, 1.0e-6])
exp_sim.sensmethod = 'SIMULTANEOUS' #Defines the sensitivity method used
exp_sim.suppress_sens = False #Dont suppress the sensitivity variables in the error test.
exp_sim.report_continuously = True
diff --git a/examples/cvode_with_parameters_modified.py b/examples/cvode_with_parameters_modified.py
index 2510c1ee..d3288ccc 100644
--- a/examples/cvode_with_parameters_modified.py
+++ b/examples/cvode_with_parameters_modified.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import numpy as N
+import numpy as np
import nose
from assimulo.solvers import CVode
from assimulo.problem import Explicit_Problem
@@ -48,7 +48,7 @@ def f(t, y, p):
yd_1 = p[0]*y[0]-p[1]*y[1]*y[2]-p3*y[1]**2
yd_2 = p3*y[1]**2
- return N.array([yd_0,yd_1,yd_2])
+ return np.array([yd_0,yd_1,yd_2])
#The initial conditions
y0 = [1.0,0.0,0.0] #Initial conditions for y
@@ -63,11 +63,11 @@ def f(t, y, p):
#Create an Assimulo explicit solver (CVode)
exp_sim = CVode(exp_mod)
- #Sets the paramters
+ #Sets the parameters
exp_sim.iter = 'Newton'
exp_sim.discr = 'BDF'
exp_sim.rtol = 1.e-4
- exp_sim.atol = N.array([1.0e-8, 1.0e-14, 1.0e-6])
+ exp_sim.atol = np.array([1.0e-8, 1.0e-14, 1.0e-6])
exp_sim.sensmethod = 'SIMULTANEOUS' #Defines the sensitivity method used
exp_sim.suppress_sens = False #Dont suppress the sensitivity variables in the error test.
exp_sim.report_continuously = True
diff --git a/examples/dasp3_basic.py b/examples/dasp3_basic.py
index 9561479b..d9b1fbb2 100644
--- a/examples/dasp3_basic.py
+++ b/examples/dasp3_basic.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
-import numpy as N
+import numpy as np
import nose
try:
@@ -56,7 +56,7 @@ def run_example(with_plots=True):
#Define the slow rhs
def dydt(t,y,z):
eps=(1./3)*1.e-3
- yp = N.array([-(.6*z[0]+.8*y[2])*y[0]+10.*y[1],
+ yp = np.array([-(.6*z[0]+.8*y[2])*y[0]+10.*y[1],
-10.*y[1]+ 1.6*z[0] *y[2],
-1.33*eps**2*y[2]*(y[0]+2.*z[0])])
return yp
@@ -64,14 +64,14 @@ def dydt(t,y,z):
#Define the fast rhs
def dzdt(t,y,z):
eps=(1./3)*1.e-3
- zp = N.array([1.6*z[0]*y[2]-.6*z[0]*y[0]
+ zp = np.array([1.6*z[0]*y[2]-.6*z[0]*y[0]
-45.*(eps*z[0])**2+.8*y[2]*y[0]])
return zp
#The initial values
y0 = [ 3.0, 0.216, 1.0]
z0 = [1.35]
- eps = N.array([.33333333e-3])
+ eps = np.array([.33333333e-3])
#Define an Assimulo problem
exp_mod = SingPerturbed_Problem(dydt, dzdt,
diff --git a/examples/dopri5_basic.py b/examples/dopri5_basic.py
index 35d50b7b..5ef285e0 100644
--- a/examples/dopri5_basic.py
+++ b/examples/dopri5_basic.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import numpy as N
+import numpy as np
import nose
from assimulo.solvers import Dopri5
from assimulo.problem import Explicit_Problem
@@ -35,7 +35,7 @@ def run_example(with_plots=True):
#Defines the rhs
def f(t,y):
ydot = -y[0]
- return N.array([ydot])
+ return np.array([ydot])
#Define an Assimulo problem
exp_mod = Explicit_Problem(f, 4.0,
diff --git a/examples/dopri5_with_disc.py b/examples/dopri5_with_disc.py
index 3d50ed45..9f7e45cf 100644
--- a/examples/dopri5_with_disc.py
+++ b/examples/dopri5_with_disc.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import numpy as N
+import numpy as np
import nose
from assimulo.solvers import Dopri5
from assimulo.problem import Explicit_Problem
@@ -34,7 +34,7 @@
#Extend Assimulos problem definition
class Extended_Problem(Explicit_Problem):
- #Sets the initial conditons directly into the problem
+ #Sets the initial conditions directly into the problem
y0 = [0.0, -1.0, 0.0]
sw0 = [False,True,True]
@@ -50,7 +50,7 @@ def rhs(self,t,y,sw):
yd_1 = 0.0
yd_2 = 0.0
- return N.array([yd_0,yd_1,yd_2])
+ return np.array([yd_0,yd_1,yd_2])
#Sets a name to our function
name = 'ODE with discontinuities and a function with consistency problem'
@@ -65,7 +65,7 @@ def state_events(self,t,y,sw):
event_1 = -y[2] + 1.0
event_2 = -t + 1.0
- return N.array([event_0,event_1,event_2])
+ return np.array([event_0,event_1,event_2])
#Responsible for handling the events.
diff --git a/examples/euler_basic.py b/examples/euler_basic.py
index bb2b73aa..6bd2d27d 100644
--- a/examples/euler_basic.py
+++ b/examples/euler_basic.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import numpy as N
+import numpy as np
import nose
from assimulo.solvers import ExplicitEuler
from assimulo.problem import Explicit_Problem
@@ -36,7 +36,7 @@ def run_example(with_plots=True):
#Defines the rhs
def f(t,y):
ydot = -y[0]
- return N.array([ydot])
+ return np.array([ydot])
#Define an Assimulo problem
exp_mod = Explicit_Problem(f, 4.0,
diff --git a/examples/euler_vanderpol.py b/examples/euler_vanderpol.py
index a24c764b..0379e8a5 100644
--- a/examples/euler_vanderpol.py
+++ b/examples/euler_vanderpol.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import numpy as N
+import numpy as np
import nose
from assimulo.solvers import ImplicitEuler
from assimulo.problem import Explicit_Problem
@@ -47,7 +47,7 @@ def f(t,y):
yd_0 = y[1]
yd_1 = my*((1.-y[0]**2)*y[1]-y[0])
- return N.array([yd_0,yd_1])
+ return np.array([yd_0,yd_1])
#Define the Jacobian
def jac(t,y):
@@ -56,7 +56,7 @@ def jac(t,y):
jd_10 = -1.0*my-2*y[0]*y[1]*my
jd_11 = my*(1.-y[0]**2)
- return N.array([[jd_00,jd_01],[jd_10,jd_11]])
+ return np.array([[jd_00,jd_01],[jd_10,jd_11]])
y0 = [2.0,-0.6] #Initial conditions
@@ -86,7 +86,7 @@ def jac(t,y):
#Basic test
x1 = y[:,0]
- nose.tools.assert_less(N.abs(float(x1[-1]) - 1.8601438), 1e-1)
+ nose.tools.assert_less(np.abs(float(x1[-1]) - 1.8601438), 1e-1)
return exp_mod, exp_sim
diff --git a/examples/euler_with_disc.py b/examples/euler_with_disc.py
index 9d64948e..a6ca36c5 100644
--- a/examples/euler_with_disc.py
+++ b/examples/euler_with_disc.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import numpy as N
+import numpy as np
import nose
from assimulo.solvers import ExplicitEuler
from assimulo.problem import Explicit_Problem
@@ -34,7 +34,7 @@
#Extend Assimulos problem definition
class Extended_Problem(Explicit_Problem):
- #Sets the initial conditons directly into the problem
+ #Sets the initial conditions directly into the problem
y0 = [0.0, -1.0, 0.0]
sw0 = [False,True,True]
@@ -50,7 +50,7 @@ def rhs(self,t,y,sw):
yd_1 = 0.0
yd_2 = 0.0
- return N.array([yd_0,yd_1,yd_2])
+ return np.array([yd_0,yd_1,yd_2])
#Sets a name to our function
name = 'ODE with discontinuities and a function with consistency problem'
@@ -65,7 +65,7 @@ def state_events(self,t,y,sw):
event_1 = -y[2] + 1.0
event_2 = -t + 1.0
- return N.array([event_0,event_1,event_2])
+ return np.array([event_0,event_1,event_2])
#Responsible for handling the events.
diff --git a/examples/glimda_vanderpol.py b/examples/glimda_vanderpol.py
index 3bf01976..cc892ad9 100644
--- a/examples/glimda_vanderpol.py
+++ b/examples/glimda_vanderpol.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import numpy as N
+import numpy as np
import nose
from assimulo.solvers import GLIMDA
from assimulo.problem import Implicit_Problem
@@ -50,7 +50,7 @@ def f(t,y,yd):
res_0 = yd[0]-yd_0
res_1 = yd[1]-yd_1
- return N.array([res_0,res_1])
+ return np.array([res_0,res_1])
y0 = [2.0,-0.6] #Initial conditions
yd0 = [-.6,-200000.]
diff --git a/examples/ida_basic_backward.py b/examples/ida_basic_backward.py
index 7a34bb15..be5777a0 100644
--- a/examples/ida_basic_backward.py
+++ b/examples/ida_basic_backward.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import numpy as N
+import numpy as np
import nose
from assimulo.solvers import IDA
from assimulo.problem import Implicit_Problem
@@ -35,7 +35,7 @@ def run_example(with_plots=True):
#Define the rhs
def f(t,y,yd):
res = yd[0] + y[0]
- return N.array([res])
+ return np.array([res])
#Define an Assimulo problem
imp_mod = Implicit_Problem(f,t0=5, y0=0.02695, yd0=-0.02695,
diff --git a/examples/ida_with_disc.py b/examples/ida_with_disc.py
index 152763a3..6f3b35fb 100644
--- a/examples/ida_with_disc.py
+++ b/examples/ida_with_disc.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import numpy as N
+import numpy as np
import nose
from assimulo.solvers import IDA
from assimulo.problem import Implicit_Problem
@@ -34,7 +34,7 @@
#Extend Assimulos problem definition
class Extended_Problem(Implicit_Problem):
- #Sets the initial conditons directly into the problem
+ #Sets the initial conditions directly into the problem
y0 = [0.0, -1.0, 0.0]
yd0 = [-1.0, 0.0, 0.0]
sw0 = [False,True,True]
@@ -53,7 +53,7 @@ def res(self,t,y,yd,sw):
res_1 = -y[1] + (-1.0 if sw[1] else 3.0)
res_2 = -y[2] + (0.0 if sw[2] else 2.0)
- return N.array([res_0,res_1,res_2])
+ return np.array([res_0,res_1,res_2])
#Sets a name to our function
name = 'ODE with discontinuities and a function with consistency problem'
@@ -68,7 +68,7 @@ def state_events(self,t,y,yd,sw):
event_1 = -y[2] + 1.0
event_2 = -t + 1.0
- return N.array([event_0,event_1,event_2])
+ return np.array([event_0,event_1,event_2])
#Responsible for handling the events.
diff --git a/examples/ida_with_initial_sensitivity.py b/examples/ida_with_initial_sensitivity.py
index bf3b3813..70dac11e 100644
--- a/examples/ida_with_initial_sensitivity.py
+++ b/examples/ida_with_initial_sensitivity.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import numpy as N
+import numpy as np
import nose
from assimulo.solvers import IDA
from assimulo.problem import Implicit_Problem
@@ -57,13 +57,13 @@ def f(t, y, yd,p):
res_1 = -yd2 + k21*y1-(k02+k12)*y2
res_2 = -yd3 + k31*y1-k13*y3
- return N.array([res_0,res_1,res_2])
+ return np.array([res_0,res_1,res_2])
#The initial conditions
y0 = [0.0,0.0,0.0] #Initial conditions for y
yd0 = [49.3,0.,0.]
p0 = [0.0, 0.0, 0.0] #Initial conditions for parameters
- yS0 = N.array([[1,0,0],[0,1,0],[0,0,1.]])
+ yS0 = np.array([[1,0,0],[0,1,0],[0,0,1.]])
#Create an Assimulo implicit problem
imp_mod = Implicit_Problem(f,y0,yd0,p0=p0,name='Example: Computing Sensitivities')
@@ -74,7 +74,7 @@ def f(t, y, yd,p):
#Create an Assimulo explicit solver (IDA)
imp_sim = IDA(imp_mod)
- #Sets the paramters
+ #Sets the parameters
imp_sim.rtol = 1e-7
imp_sim.atol = 1e-6
imp_sim.pbar = [1,1,1] #pbar is used to estimate the tolerances for the parameters
@@ -90,21 +90,21 @@ def f(t, y, yd,p):
import pylab as P
P.figure(1)
P.subplot(221)
- P.plot(t, N.array(imp_sim.p_sol[0])[:,0],
- t, N.array(imp_sim.p_sol[0])[:,1],
- t, N.array(imp_sim.p_sol[0])[:,2])
+ P.plot(t, np.array(imp_sim.p_sol[0])[:,0],
+ t, np.array(imp_sim.p_sol[0])[:,1],
+ t, np.array(imp_sim.p_sol[0])[:,2])
P.title("Parameter p1")
P.legend(("p1/dy1","p1/dy2","p1/dy3"))
P.subplot(222)
- P.plot(t, N.array(imp_sim.p_sol[1])[:,0],
- t, N.array(imp_sim.p_sol[1])[:,1],
- t, N.array(imp_sim.p_sol[1])[:,2])
+ P.plot(t, np.array(imp_sim.p_sol[1])[:,0],
+ t, np.array(imp_sim.p_sol[1])[:,1],
+ t, np.array(imp_sim.p_sol[1])[:,2])
P.title("Parameter p2")
P.legend(("p2/dy1","p2/dy2","p2/dy3"))
P.subplot(223)
- P.plot(t, N.array(imp_sim.p_sol[2])[:,0],
- t, N.array(imp_sim.p_sol[2])[:,1],
- t, N.array(imp_sim.p_sol[2])[:,2])
+ P.plot(t, np.array(imp_sim.p_sol[2])[:,0],
+ t, np.array(imp_sim.p_sol[2])[:,1],
+ t, np.array(imp_sim.p_sol[2])[:,2])
P.title("Parameter p3")
P.legend(("p3/dy1","p3/dy2","p3/dy3"))
P.subplot(224)
diff --git a/examples/ida_with_jac.py b/examples/ida_with_jac.py
index 577e54b9..9a92981f 100644
--- a/examples/ida_with_jac.py
+++ b/examples/ida_with_jac.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import numpy as N
+import numpy as np
from assimulo.solvers import IDA
from assimulo.problem import Implicit_Problem
import nose
@@ -51,11 +51,11 @@ def f(t,y,yd):
res_3 = yd[3]+y[4]*y[1]+9.82
res_4 = y[2]**2+y[3]**2-y[4]*(y[0]**2+y[1]**2)-y[1]*9.82
- return N.array([res_0,res_1,res_2,res_3,res_4])
+ return np.array([res_0,res_1,res_2,res_3,res_4])
#Defines the Jacobian
def jac(c,t,y,yd):
- jacobian = N.zeros([len(y),len(y)])
+ jacobian = np.zeros([len(y),len(y)])
#Derivative
jacobian[0,0] = 1*c
@@ -80,7 +80,7 @@ def jac(c,t,y,yd):
return jacobian
- #The initial conditons
+ #The initial conditions
y0 = [1.0,0.0,0.0,0.0,5] #Initial conditions
yd0 = [0.0,0.0,0.0,-9.82,0.0] #Initial conditions
@@ -95,7 +95,7 @@ def jac(c,t,y,yd):
#Create an Assimulo implicit solver (IDA)
imp_sim = IDA(imp_mod) #Create a IDA solver
- #Sets the paramters
+ #Sets the parameters
imp_sim.atol = 1e-6 #Default 1e-6
imp_sim.rtol = 1e-6 #Default 1e-6
imp_sim.suppress_alg = True #Suppres the algebraic variables on the error test
diff --git a/examples/ida_with_jac_spgmr.py b/examples/ida_with_jac_spgmr.py
index 1db858de..19e60622 100644
--- a/examples/ida_with_jac_spgmr.py
+++ b/examples/ida_with_jac_spgmr.py
@@ -15,12 +15,11 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import numpy as N
+import numpy as np
import nose
from assimulo.solvers import IDA
from assimulo.problem import Implicit_Problem
-
def run_example(with_plots=True):
r"""
An example for IDA with scaled preconditioned GMRES method
@@ -48,14 +47,14 @@ def res(t,y,yd):
res_0 = yd[0] - y[1]
res_1 = yd[1] + 9.82
- return N.array([res_0,res_1])
+ return np.array([res_0,res_1])
#Defines the Jacobian*vector product
def jacv(t,y,yd,res,v,c):
- jy = N.array([[0,-1.],[0,0]])
- jyd = N.array([[1,0.],[0,1]])
+ jy = np.array([[0,-1.],[0,0]])
+ jyd = np.array([[1,0.],[0,1]])
j = jy+c*jyd
- return N.dot(j,v)
+ return np.dot(j,v)
#Initial conditions
y0 = [1.0,0.0]
diff --git a/examples/ida_with_parameters.py b/examples/ida_with_parameters.py
index 4a7198be..da28452f 100644
--- a/examples/ida_with_parameters.py
+++ b/examples/ida_with_parameters.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import numpy as N
+import numpy as np
import nose
from assimulo.solvers import IDA
from assimulo.problem import Implicit_Problem
@@ -50,9 +50,9 @@ def f(t, y, yd, p):
res2 = p[0]*y[0]-p[1]*y[1]*y[2]-p[2]*y[1]**2-yd[1]
res3 = y[0]+y[1]+y[2]-1
- return N.array([res1,res2,res3])
+ return np.array([res1,res2,res3])
- #The initial conditons
+ #The initial conditions
y0 = [1.0, 0.0, 0.0] #Initial conditions for y
yd0 = [0.1, 0.0, 0.0] #Initial conditions for dy/dt
p0 = [0.040, 1.0e4, 3.0e7] #Initial conditions for parameters
@@ -63,8 +63,8 @@ def f(t, y, yd, p):
#Create an Assimulo implicit solver (IDA)
imp_sim = IDA(imp_mod) #Create a IDA solver
- #Sets the paramters
- imp_sim.atol = N.array([1.0e-8, 1.0e-14, 1.0e-6])
+ #Sets the parameters
+ imp_sim.atol = np.array([1.0e-8, 1.0e-14, 1.0e-6])
imp_sim.algvar = [1.0,1.0,0.0]
imp_sim.suppress_alg = False #Suppres the algebraic variables on the error test
imp_sim.report_continuously = True #Store data continuous during the simulation
diff --git a/examples/ida_with_user_defined_handle_result.py b/examples/ida_with_user_defined_handle_result.py
index 09e76ad8..9e2d26b2 100644
--- a/examples/ida_with_user_defined_handle_result.py
+++ b/examples/ida_with_user_defined_handle_result.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import numpy as N
+import numpy as np
from assimulo.solvers import IDA
from assimulo.problem import Implicit_Problem
import nose
@@ -53,7 +53,7 @@ def f(t,y,yd):
res_3 = yd[3]+y[4]*y[1]+9.82
res_4 = y[2]**2+y[3]**2-y[4]*(y[0]**2+y[1]**2)-y[1]*9.82
- return N.array([res_0,res_1,res_2,res_3,res_4])
+ return np.array([res_0,res_1,res_2,res_3,res_4])
def handle_result(solver, t ,y, yd):
global order
@@ -64,7 +64,7 @@ def handle_result(solver, t ,y, yd):
solver.yd_sol.extend([yd])
- #The initial conditons
+ #The initial conditions
y0 = [1.0,0.0,0.0,0.0,5] #Initial conditions
yd0 = [0.0,0.0,0.0,-9.82,0.0] #Initial conditions
@@ -78,7 +78,7 @@ def handle_result(solver, t ,y, yd):
#Create an Assimulo implicit solver (IDA)
imp_sim = IDA(imp_mod) #Create a IDA solver
- #Sets the paramters
+ #Sets the parameters
imp_sim.atol = 1e-6 #Default 1e-6
imp_sim.rtol = 1e-6 #Default 1e-6
imp_sim.suppress_alg = True #Suppres the algebraic variables on the error test
@@ -100,7 +100,7 @@ def handle_result(solver, t ,y, yd):
P.title(imp_mod.name)
P.figure(2)
- P.plot([0] + N.add.accumulate(N.diff(t)).tolist(), order)
+ P.plot([0] + np.add.accumulate(np.diff(t)).tolist(), order)
P.title("Used order during the integration")
P.xlabel("Time")
P.ylabel("Order")
diff --git a/examples/kinsol_ors.py b/examples/kinsol_ors.py
index e1744cee..046cbb5c 100644
--- a/examples/kinsol_ors.py
+++ b/examples/kinsol_ors.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import numpy as N
+import numpy as np
import scipy.linalg as LIN
import scipy.io as IO
import scipy.sparse as SPARSE
@@ -57,7 +57,7 @@ def run_example(with_plots=True):
solvePrec = LINSP.factorized(Prec)
#Create the RHS
- b = A.dot(N.ones(A.shape[0]))
+ b = A.dot(np.ones(A.shape[0]))
#Define the res
def res(x):
@@ -77,7 +77,7 @@ def prec_setup(u,f, uscale, fscale):
def prec_solve(r):
return solvePrec(r)
- y0 = N.random.rand(A.shape[0])
+ y0 = np.random.rand(A.shape[0])
#Define an Assimulo problem
alg_mod = Algebraic_Problem(res, y0=y0, jac=jac, jacv=jacv, name = 'ORS Example')
@@ -105,8 +105,8 @@ def setup_param(solver):
#Solve Preconditioned system
y_prec = alg_solver_prec.solve()
- print("Error , in y: ", LIN.norm(y-N.ones(len(y))))
- print("Error (preconditioned), in y: ", LIN.norm(y_prec-N.ones(len(y_prec))))
+ print("Error , in y: ", LIN.norm(y-np.ones(len(y))))
+ print("Error (preconditioned), in y: ", LIN.norm(y_prec-np.ones(len(y_prec))))
if with_plots:
import pylab as P
diff --git a/examples/kinsol_with_jac.py b/examples/kinsol_with_jac.py
index 8171d447..6fcf0f38 100644
--- a/examples/kinsol_with_jac.py
+++ b/examples/kinsol_with_jac.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import numpy as N
+import numpy as np
import nose
from assimulo.solvers import KINSOL
from assimulo.problem import Algebraic_Problem
@@ -36,10 +36,10 @@ def run_example(with_plots=True):
def res(y):
r1 = 2*y[0]+3*y[1]-6
r2 = 4*y[0]+9*y[1]-15
- return N.array([r1,r2])
+ return np.array([r1,r2])
def jac(y):
- return N.array([[2.,3.],[4.,9.]])
+ return np.array([[2.,3.],[4.,9.]])
#Define an Assimulo problem
alg_mod = Algebraic_Problem(res, y0=[0,0], jac=jac, name='KINSOL example with Jac')
diff --git a/examples/lsodar_bouncing_ball.py b/examples/lsodar_bouncing_ball.py
index d7d8a2e9..ecba77cb 100644
--- a/examples/lsodar_bouncing_ball.py
+++ b/examples/lsodar_bouncing_ball.py
@@ -15,8 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import nose
-import numpy as N
+import numpy as np
from assimulo.solvers import LSODAR
from assimulo.problem import Explicit_Problem
@@ -28,7 +27,7 @@
#Extend Assimulos problem definition
class Extended_Problem(Explicit_Problem):
- #Sets the initial conditons directly into the problem
+ #Sets the initial conditions directly into the problem
y0 = [2.0, 0] # position and (downward) velocity
sw0=[True,False]
@@ -42,7 +41,7 @@ def rhs(self,t,y,sw):
"""
yd_0 = y[1]
yd_1 = self.g
- return N.array([yd_0,yd_1])
+ return np.array([yd_0,yd_1])
#Sets a name to our function
name = 'Bouncing Ball Problem'
@@ -56,7 +55,7 @@ def state_events(self,t,y,sw):
event_0 = y[0] if sw[0] else 5 # hits the ground
event_1 = y[1] if sw[1] else 5 # velocity changes sign at topmost point
- return N.array([event_0,event_1])
+ return np.array([event_0,event_1])
#Responsible for handling the events.
diff --git a/examples/lsodar_vanderpol.py b/examples/lsodar_vanderpol.py
index 1b35386d..3d19e0e2 100644
--- a/examples/lsodar_vanderpol.py
+++ b/examples/lsodar_vanderpol.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import numpy as N
+import numpy as np
import nose
from assimulo.solvers import LSODAR
from assimulo.problem import Explicit_Problem
@@ -47,7 +47,7 @@ def f(t,y):
yd_0 = y[1]
yd_1 = my*((1.-y[0]**2)*y[1]-y[0])
- return N.array([yd_0,yd_1])
+ return np.array([yd_0,yd_1])
y0 = [2.0,-0.6] #Initial conditions
@@ -75,7 +75,7 @@ def f(t,y):
#Basic test
x1 = y[:,0]
- nose.tools.assert_less(N.abs(x1[-1] - 1.706168035), 1e-3)
+ nose.tools.assert_less(np.abs(x1[-1] - 1.706168035), 1e-3)
return exp_mod, exp_sim
diff --git a/examples/lsodar_with_disc.py b/examples/lsodar_with_disc.py
index 3a286af7..e77e775d 100644
--- a/examples/lsodar_with_disc.py
+++ b/examples/lsodar_with_disc.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import numpy as N
+import numpy as np
import nose
from assimulo.solvers import LSODAR
from assimulo.problem import Explicit_Problem
@@ -34,7 +34,7 @@
#Extend Assimulos problem definition
class Extended_Problem(Explicit_Problem):
- #Sets the initial conditons directly into the problem
+ #Sets the initial conditions directly into the problem
y0 = [0.0, -1.0, 0.0]
sw0 = [False,True,True]
@@ -50,7 +50,7 @@ def rhs(self,t,y,sw):
yd_1 = 0.0
yd_2 = 0.0
- return N.array([yd_0,yd_1,yd_2])
+ return np.array([yd_0,yd_1,yd_2])
#Sets a name to our function
name = 'ODE with discontinuities and a function with consistency problem'
@@ -65,7 +65,7 @@ def state_events(self,t,y,sw):
event_1 = -y[2] + 1.0
event_2 = -t + 1.0
- return N.array([event_0,event_1,event_2])
+ return np.array([event_0,event_1,event_2])
#Responsible for handling the events.
def handle_event(self, solver, event_info):
diff --git a/examples/mech_system_pendulum.py b/examples/mech_system_pendulum.py
index 3a632f70..6f13bdcc 100644
--- a/examples/mech_system_pendulum.py
+++ b/examples/mech_system_pendulum.py
@@ -15,37 +15,36 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import assimulo.special_systems as ass
-import numpy as N
+import numpy as np
import nose
import scipy.linalg as sl
+from assimulo.special_systems import Mechanical_System
from assimulo.solvers import IDA, ODASSL
-
def pendulum():
g=13.7503671
n_p=2
n_la=1
def forces(t, p, v):
- return N.array([0.,-g])
+ return np.array([0.,-g])
def GT(p):
- return N.array([p[0],p[1]]).reshape((2,1))
+ return np.array([p[0],p[1]]).reshape((2,1))
def constr3(t,y):
p=y[0:2]
- return N.array([p[0]**2+p[1]**2-1.])
+ return np.array([p[0]**2+p[1]**2-1.])
def constr2(t,y):
p,v=y[0:2],y[2:4]
- return N.array([p[0]*v[0]+p[1]*v[1]])
+ return np.array([p[0]*v[0]+p[1]*v[1]])
def constr1(t,y):
p,v,la=y[0:2],y[2:4],y[4:5]
- return N.array([v[0]**2+v[1]**2 - la[0] * (p[0]**2 + p[1]**2) - p[1] * g])
- return ass.Mechanical_System(n_p, forces, n_la,
- [1.,0.], [0.,0.],
- [0],
- [0.,0.], [0.,-g], GT=GT,
- constr3 = constr3,
- constr2 = constr2,
- constr1 = constr1)
+ return np.array([v[0]**2+v[1]**2 - la[0] * (p[0]**2 + p[1]**2) - p[1] * g])
+ return Mechanical_System(n_p, forces, n_la,
+ [1.,0.], [0.,0.],
+ [0],
+ [0.,0.], [0.,-g], GT=GT,
+ constr3 = constr3,
+ constr2 = constr2,
+ constr1 = constr1)
def run_example(index="ind1", with_plots=True, with_test=False):
my_pend_sys=pendulum()
diff --git a/examples/radau5dae_time_events.py b/examples/radau5dae_time_events.py
index c61ee2b9..ed6a1cd5 100644
--- a/examples/radau5dae_time_events.py
+++ b/examples/radau5dae_time_events.py
@@ -15,12 +15,11 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import numpy as N
+import numpy as np
import nose
from assimulo.solvers import Radau5DAE
from assimulo.problem import Implicit_Problem
-
class VanDerPolProblem(Implicit_Problem):
def __init__(self, **kargs):
Implicit_Problem.__init__(self, **kargs)
@@ -34,7 +33,7 @@ def res(self, t,y,yd):
res_0 = yd[0]-yd_0
res_1 = yd[1]-yd_1
- return N.array([res_0,res_1])
+ return np.array([res_0,res_1])
def time_events(self, t,y,yd,sw):
events = [1.0, 2.0, 2.5, 3.0]
@@ -74,7 +73,7 @@ def run_example(with_plots=True):
#Basic test
x1 = y[:,0]
- nose.tools.assert_less(N.abs(float(x1[-1]) - 1.14330840983), 1e-3)
+ nose.tools.assert_less(np.abs(float(x1[-1]) - 1.14330840983), 1e-3)
return imp_mod, imp_sim
if __name__=='__main__':
diff --git a/examples/radau5dae_vanderpol.py b/examples/radau5dae_vanderpol.py
index e84358f3..c50cd84b 100644
--- a/examples/radau5dae_vanderpol.py
+++ b/examples/radau5dae_vanderpol.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import numpy as N
+import numpy as np
import nose
from assimulo.solvers import Radau5DAE
from assimulo.problem import Implicit_Problem
@@ -50,7 +50,7 @@ def f(t,y,yd):
res_0 = yd[0]-yd_0
res_1 = yd[1]-yd_1
- return N.array([res_0,res_1])
+ return np.array([res_0,res_1])
y0 = [2.0,-0.6] #Initial conditions
yd0 = [-.6,-200000.]
@@ -86,7 +86,7 @@ def f(t,y,yd):
#Basic test
x1 = y[:,0]
- nose.tools.assert_less(N.abs(float(x1[-1]) - 1.706168035), 1e-3)
+ nose.tools.assert_less(np.abs(float(x1[-1]) - 1.706168035), 1e-3)
return imp_mod, imp_sim
diff --git a/examples/radau5ode_vanderpol.py b/examples/radau5ode_vanderpol.py
index 6a046c09..f425a388 100644
--- a/examples/radau5ode_vanderpol.py
+++ b/examples/radau5ode_vanderpol.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import numpy as N
+import numpy as np
import nose
from assimulo.solvers import Radau5ODE
from assimulo.problem import Explicit_Problem
@@ -46,7 +46,7 @@ def f(t,y):
yd_0 = y[1]
yd_1 = my*((1.-y[0]**2)*y[1]-y[0])
- return N.array([yd_0,yd_1])
+ return np.array([yd_0,yd_1])
y0 = [2.0,-0.6] #Initial conditions
@@ -76,7 +76,7 @@ def f(t,y):
#Basic test
x1 = y[:,0]
- nose.tools.assert_less(N.abs(float(x1[-1]) - 1.706168035), 1e-3)
+ nose.tools.assert_less(np.abs(float(x1[-1]) - 1.706168035), 1e-3)
return exp_mod, exp_sim
diff --git a/examples/radau5ode_with_disc.py b/examples/radau5ode_with_disc.py
index af14b49e..d4b6f386 100644
--- a/examples/radau5ode_with_disc.py
+++ b/examples/radau5ode_with_disc.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import numpy as N
+import numpy as np
import nose
from assimulo.solvers import Radau5ODE
from assimulo.problem import Explicit_Problem
@@ -50,7 +50,7 @@ def rhs(self,t,y,sw):
yd_1 = 0.0
yd_2 = 0.0
- return N.array([yd_0,yd_1,yd_2])
+ return np.array([yd_0,yd_1,yd_2])
#Sets a name to our function
name = 'ODE with discontinuities and a function with consistency problem'
@@ -65,8 +65,7 @@ def state_events(self,t,y,sw):
event_1 = -y[2] + 1.0
event_2 = -t + 1.0
- return N.array([event_0,event_1,event_2])
-
+ return np.array([event_0,event_1,event_2])
#Responsible for handling the events.
def handle_event(self, solver, event_info):
diff --git a/examples/radau5ode_with_disc_sparse.py b/examples/radau5ode_with_disc_sparse.py
index 3a994040..bed2de1c 100644
--- a/examples/radau5ode_with_disc_sparse.py
+++ b/examples/radau5ode_with_disc_sparse.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import numpy as N
+import numpy as np
import scipy.sparse as sp
import nose
from assimulo.solvers import Radau5ODE
@@ -51,7 +51,7 @@ def rhs(self,t,y,sw):
yd_1 = 0.0
yd_2 = 0.0
- return N.array([yd_0,yd_1,yd_2])
+ return np.array([yd_0,yd_1,yd_2])
def jac(self, t, y):
return sp.csc_matrix((len(y), len(y)), dtype = 'float')
@@ -71,7 +71,7 @@ def state_events(self,t,y,sw):
event_1 = -y[2] + 1.0
event_2 = -t + 1.0
- return N.array([event_0,event_1,event_2])
+ return np.array([event_0,event_1,event_2])
#Responsible for handling the events.
diff --git a/examples/radau5ode_with_jac_sparse.py b/examples/radau5ode_with_jac_sparse.py
index 3fece4d3..4264300d 100644
--- a/examples/radau5ode_with_jac_sparse.py
+++ b/examples/radau5ode_with_jac_sparse.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import numpy as N
+import numpy as np
import scipy.sparse as SP
import nose
from assimulo.solvers import Radau5ODE
@@ -48,7 +48,7 @@ def f(t,y):
yd_0 = -0.04*y[0] + 1e4*y[1]*y[2]
yd_2 = 3e7*y[1]*y[1]
yd_1 = -yd_0 - yd_2
- return N.array([yd_0,yd_1,yd_2])
+ return np.array([yd_0,yd_1,yd_2])
#Defines the Jacobian
def jac(t,y):
diff --git a/examples/rodasode_vanderpol.py b/examples/rodasode_vanderpol.py
index ca0e37d5..61aa5a6d 100644
--- a/examples/rodasode_vanderpol.py
+++ b/examples/rodasode_vanderpol.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import numpy as N
+import numpy as np
import nose
from assimulo.solvers import RodasODE
from assimulo.problem import Explicit_Problem
@@ -47,13 +47,13 @@ def f(t,y):
yd_0 = y[1]
yd_1 = my*((1.-y[0]**2)*y[1]-y[0])
- return N.array([yd_0,yd_1])
+ return np.array([yd_0,yd_1])
#Define the jacobian
def jac(t,y):
eps = 1.e-6
my = 1./eps
- j = N.array([[0.0,1.0],[my*((-2.0*y[0])*y[1]-1.0), my*(1.0-y[0]**2)]])
+ j = np.array([[0.0,1.0],[my*((-2.0*y[0])*y[1]-1.0), my*(1.0-y[0]**2)]])
return j
y0 = [2.0,-0.6] #Initial conditions
@@ -86,7 +86,7 @@ def jac(t,y):
#Basic test
x1 = y[:,0]
- nose.tools.assert_less(N.abs(float(x1[-1]) - 1.706168035), 1e-3)
+ nose.tools.assert_less(np.abs(float(x1[-1]) - 1.706168035), 1e-3)
return exp_mod, exp_sim
diff --git a/examples/rungekutta34_basic.py b/examples/rungekutta34_basic.py
index 24167e63..978dbb33 100644
--- a/examples/rungekutta34_basic.py
+++ b/examples/rungekutta34_basic.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import numpy as N
+import numpy as np
import nose
from assimulo.solvers import RungeKutta34
from assimulo.problem import Explicit_Problem
@@ -36,7 +36,7 @@ def run_example(with_plots=True):
#Defines the rhs
def f(t,y):
ydot = -y[0]
- return N.array([ydot])
+ return np.array([ydot])
#Define an Assimulo problem
exp_mod = Explicit_Problem(f, 4.0,
diff --git a/examples/rungekutta34_with_disc.py b/examples/rungekutta34_with_disc.py
index 21bae04f..51764300 100644
--- a/examples/rungekutta34_with_disc.py
+++ b/examples/rungekutta34_with_disc.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import numpy as N
+import numpy as np
import nose
from assimulo.solvers import RungeKutta34
from assimulo.problem import Explicit_Problem
@@ -34,7 +34,7 @@
#Extend Assimulos problem definition
class Extended_Problem(Explicit_Problem):
- #Sets the initial conditons directly into the problem
+ #Sets the initial conditions directly into the problem
y0 = [0.0, -1.0, 0.0]
sw0 = [False,True,True]
@@ -50,7 +50,7 @@ def rhs(self,t,y,sw):
yd_1 = 0.0
yd_2 = 0.0
- return N.array([yd_0,yd_1,yd_2])
+ return np.array([yd_0,yd_1,yd_2])
#Sets a name to our function
name = 'ODE with discontinuities and a function with consistency problem'
@@ -65,7 +65,7 @@ def state_events(self,t,y,sw):
event_1 = -y[2] + 1.0
event_2 = -t + 1.0
- return N.array([event_0,event_1,event_2])
+ return np.array([event_0,event_1,event_2])
#Responsible for handling the events.
diff --git a/examples/rungekutta4_basic.py b/examples/rungekutta4_basic.py
index 4a3a7473..eaa139e4 100644
--- a/examples/rungekutta4_basic.py
+++ b/examples/rungekutta4_basic.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import numpy as N
+import numpy as np
import nose
from assimulo.solvers import RungeKutta4
from assimulo.problem import Explicit_Problem
@@ -37,7 +37,7 @@ def run_example(with_plots=True):
#Defines the rhs
def f(t,y):
ydot = -y[0]
- return N.array([ydot])
+ return np.array([ydot])
#Define an Assimulo problem
exp_mod = Explicit_Problem(f, 4.0,
diff --git a/src/algebraic.pxd b/src/algebraic.pxd
index 285b46df..aa9d535b 100644
--- a/src/algebraic.pxd
+++ b/src/algebraic.pxd
@@ -15,16 +15,16 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import numpy as N
-cimport numpy as N
+import numpy as np
+cimport numpy as np
cdef class Algebraic:
cdef public object problem
cdef public dict options, solver_options, problem_info
cdef public dict statistics
- cdef public N.ndarray y
- cdef public N.ndarray y0
+ cdef public np.ndarray y
+ cdef public np.ndarray y0
cdef _reset_solution_variables(self)
diff --git a/src/algebraic.pyx b/src/algebraic.pyx
index f71452bd..c1053006 100644
--- a/src/algebraic.pyx
+++ b/src/algebraic.pyx
@@ -17,8 +17,8 @@
# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION
-import numpy as N
-cimport numpy as N
+import numpy as np
+cimport numpy as np
from timeit import default_timer as timer
from assimulo.exception import Algebraic_Exception, AssimuloException
@@ -44,8 +44,8 @@ cdef class Algebraic:
self.problem = problem
if hasattr(problem, 'y0'):
- self.y0 = N.array(problem.y0,dtype=realtype) if len(N.array(problem.y0,dtype=realtype).shape)>0 else N.array([problem.y0],dtype=realtype)
- self.y = N.array(problem.y0,dtype=realtype) if len(N.array(problem.y0,dtype=realtype).shape)>0 else N.array([problem.y0],dtype=realtype)
+ self.y0 = np.array(problem.y0,dtype=realtype) if len(np.array(problem.y0,dtype=realtype).shape)>0 else np.array([problem.y0],dtype=realtype)
+ self.y = np.array(problem.y0,dtype=realtype) if len(np.array(problem.y0,dtype=realtype).shape)>0 else np.array([problem.y0],dtype=realtype)
self.problem_info["dim"] = len(self.y0)
else:
raise Algebraic_Exception('y0 must be specified in the problem.')
diff --git a/src/explicit_ode.pxd b/src/explicit_ode.pxd
index c83ff540..17082230 100644
--- a/src/explicit_ode.pxd
+++ b/src/explicit_ode.pxd
@@ -15,16 +15,16 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import numpy as N
-cimport numpy as N
+import numpy as np
+cimport numpy as np
from assimulo.ode cimport ODE
cdef class Explicit_ODE(ODE):
- cpdef _simulate(self, double t0, double tfinal,N.ndarray output_list,int COMPLETE_STEP, int INTERPOLATE_OUTPUT,int TIME_EVENT)
- cpdef report_solution(self, double t, N.ndarray y, opts)
- cpdef event_locator(self, double t_low, double t_high, N.ndarray y_high)
+ cpdef _simulate(self, double t0, double tfinal,np.ndarray output_list,int COMPLETE_STEP, int INTERPOLATE_OUTPUT,int TIME_EVENT)
+ cpdef report_solution(self, double t, np.ndarray y, opts)
+ cpdef event_locator(self, double t_low, double t_high, np.ndarray y_high)
cdef extern from "string.h":
void *memcpy(void *s1, void *s2, int n)
diff --git a/src/explicit_ode.pyx b/src/explicit_ode.pyx
index f91b8074..8712fcac 100644
--- a/src/explicit_ode.pyx
+++ b/src/explicit_ode.pyx
@@ -21,8 +21,8 @@ cimport cython
import itertools
import sys
-import numpy as N
-cimport numpy as N
+import numpy as np
+cimport numpy as np
from timeit import default_timer as timer
from assimulo.ode cimport ODE
@@ -39,20 +39,20 @@ realtype = float
@cython.wraparound(False)
cdef void py2c_d(double* dest, object source, int dim):
"""Copy 1D numpy (double) array to (double *) C vector."""
- if not (isinstance(source, N.ndarray) and source.flags.contiguous and source.dtype == N.float64):
- source = N.ascontiguousarray(source, dtype=N.float64)
+ if not (isinstance(source, np.ndarray) and source.flags.contiguous and source.dtype == np.float64):
+ source = np.ascontiguousarray(source, dtype=np.float64)
assert source.size >= dim, "The dimension of the vector is {} and not equal to the problem dimension {}. Please verify the output vectors from the min/max/nominal/evalute methods in the Problem class.".format(source.size, dim)
- memcpy(dest, N.PyArray_DATA(source), dim*sizeof(double))
+ memcpy(dest, np.PyArray_DATA(source), dim*sizeof(double))
@cython.boundscheck(False)
@cython.wraparound(False)
-cdef void c2py_d(N.ndarray[double, ndim=1, mode='c'] dest, double* source, int dim):
+cdef void c2py_d(np.ndarray[double, ndim=1, mode='c'] dest, double* source, int dim):
"""Copy (double *) C vector to 1D numpy array."""
- memcpy(N.PyArray_DATA(dest), source, dim*sizeof(double))
+ memcpy(np.PyArray_DATA(dest), source, dim*sizeof(double))
cdef int callback_event(int n_y, int n_g, double t, double* y_in, double* g_out, void* f_event_EXT) noexcept:
"""Event indicator callback function to event_locator.c"""
- cdef N.ndarray[double, ndim=1, mode="c"]y_py = N.empty(n_y, dtype = N.double)
+ cdef np.ndarray[double, ndim=1, mode="c"]y_py = np.empty(n_y, dtype = np.double)
c2py_d(y_py, y_in, n_y)
ret, g_high = (f_event_EXT)(t, y_py)
if ret < 0: ## immediate return, no not try to copy g_high
@@ -119,7 +119,7 @@ cdef class Explicit_ODE(ODE):
See information in the __init__ method.
"""
- y0 = N.array(y0) if len(N.array(y0).shape)>0 else N.array([y0])
+ y0 = np.array(y0) if len(np.array(y0).shape)>0 else np.array([y0])
if len(self.y) != len(y0):
raise Explicit_ODE_Exception('y0 must be of the same length as the original problem.')
@@ -129,12 +129,12 @@ cdef class Explicit_ODE(ODE):
self.y = y0
if sw0 is not None:
- self.sw = (N.array(sw0,dtype=bool) if len(N.array(sw0,dtype=bool).shape)>0 else N.array([sw0],dtype=bool)).tolist()
+ self.sw = (np.array(sw0,dtype=bool) if len(np.array(sw0,dtype=bool).shape)>0 else np.array([sw0],dtype=bool)).tolist()
#Clear logs
self.clear_logs()
- cpdef _simulate(self, double t0, double tfinal, N.ndarray output_list, int REPORT_CONTINUOUSLY, int INTERPOLATE_OUTPUT,
+ cpdef _simulate(self, double t0, double tfinal, np.ndarray output_list, int REPORT_CONTINUOUSLY, int INTERPOLATE_OUTPUT,
int TIME_EVENT):
"""
INTERNAL FUNCTION, FOR SIMULATION USE METHOD SIMULATE.
@@ -181,7 +181,7 @@ cdef class Explicit_ODE(ODE):
cdef double tevent
cdef int flag, output_index
cdef dict opts
- cdef double eps = N.finfo(float).eps*100 #Machine Epsilon
+ cdef double eps = np.finfo(float).eps*100 #Machine Epsilon
cdef backward = 1 if self.backward else 0
y0 = self.y
@@ -274,7 +274,7 @@ cdef class Explicit_ODE(ODE):
if self.t == tfinal: #Finished simulation (might occur due to event at the final time)
break
- cpdef report_solution(self, double t, N.ndarray y, opts):
+ cpdef report_solution(self, double t, np.ndarray y, opts):
'''Is called after each successful step in case the complete step
option is active. Here possible interpolation is done and the result
handeled. Furthermore possible step events are checked.
@@ -330,17 +330,17 @@ cdef class Explicit_ODE(ODE):
return flag_initialize
- cpdef event_locator(self, double t_low, double t_high, N.ndarray y_high):
+ cpdef event_locator(self, double t_low, double t_high, np.ndarray y_high):
'''Checks if an event occurs in [t_low, t_high], if that is the case event
localization is started. Event localization finds the earliest small interval
that contains a change in domain. The right endpoint of this interval is then
returned as the time to restart the integration at.
'''
cdef int n_g = self.problem_info["dimRoot"]
- cdef N.ndarray[double, mode="c", ndim=1] g_low_c = N.array(self.g_old)
- cdef N.ndarray[double, mode="c", ndim=1] g_mid_c = N.empty(n_g, dtype = N.double)
- cdef N.ndarray[double, mode="c", ndim=1] g_high_c = N.empty(n_g, dtype = N.double)
- cdef N.ndarray[double, mode="c", ndim=1] y_high_c = N.array(y_high)
+ cdef np.ndarray[double, mode="c", ndim=1] g_low_c = np.array(self.g_old)
+ cdef np.ndarray[double, mode="c", ndim=1] g_mid_c = np.empty(n_g, dtype = np.double)
+ cdef np.ndarray[double, mode="c", ndim=1] g_high_c = np.empty(n_g, dtype = np.double)
+ cdef np.ndarray[double, mode="c", ndim=1] y_high_c = np.array(y_high)
cdef int nstatefcns = 0
cdef int ret = f_event_locator(len(y_high), n_g, 1.e-13, t_low, &t_high,
&y_high_c[0], &g_low_c[0], &g_mid_c[0], &g_high_c[0],
@@ -350,7 +350,7 @@ cdef class Explicit_ODE(ODE):
self.statistics["nstatefcns"] += nstatefcns
if ret == ID_PY_EVENT:
- event_info = N.zeros(n_g, dtype = int)
+ event_info = np.zeros(n_g, dtype = int)
for i in range(n_g):
if (g_low_c[i] > 0) != (g_high_c[i] > 0):
event_info[i] = 1 if g_high_c[i] > 0 else -1
@@ -397,8 +397,7 @@ cdef class Explicit_ODE(ODE):
'the number of variables.')
for i in range(len(mask)):
if mask[i]:
- P.plot(self.t_sol, N.array(self.y_sol)[:,i],**kwargs)
-
+ P.plot(self.t_sol, np.array(self.y_sol)[:,i],**kwargs)
P.show()
else:
diff --git a/src/implicit_ode.pxd b/src/implicit_ode.pxd
index ccea18ad..4d0c3c96 100644
--- a/src/implicit_ode.pxd
+++ b/src/implicit_ode.pxd
@@ -15,10 +15,10 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import numpy as N
-cimport numpy as N
+import numpy as np
+cimport numpy as np
from assimulo.ode cimport ODE
cdef class Implicit_ODE(ODE):
- cpdef _simulate(self, double t0, double tfinal,N.ndarray output_list,int COMPLETE_STEP, int INTERPOLATE_OUTPUT,int TIME_EVENT)
+ cpdef _simulate(self, double t0, double tfinal,np.ndarray output_list,int COMPLETE_STEP, int INTERPOLATE_OUTPUT,int TIME_EVENT)
diff --git a/src/implicit_ode.pyx b/src/implicit_ode.pyx
index 2ee634ce..0fcec740 100644
--- a/src/implicit_ode.pyx
+++ b/src/implicit_ode.pyx
@@ -20,8 +20,8 @@
import itertools
import sys
import warnings
-import numpy as N
-cimport numpy as N
+import numpy as np
+cimport numpy as np
from timeit import default_timer as timer
from assimulo.ode cimport ODE
@@ -60,7 +60,7 @@ cdef class Implicit_ODE(ODE):
if hasattr(problem, 'yd0'):
- self.yd0 = N.array(problem.yd0,dtype=realtype) if len(N.array(problem.yd0,dtype=realtype).shape)>0 else N.array([problem.yd0],dtype=realtype)
+ self.yd0 = np.array(problem.yd0,dtype=realtype) if len(np.array(problem.yd0,dtype=realtype).shape)>0 else np.array([problem.yd0],dtype=realtype)
else:
if isinstance(self.problem, cExplicit_Problem): #The problem is an explicit, get the yd0 values from the right-hand-side
self.problem_info["type"] = 0 #Change to explicit problem
@@ -109,8 +109,8 @@ cdef class Implicit_ODE(ODE):
See information in the __init__ method.
"""
- y0 = N.array(y0) if len(N.array(y0).shape)>0 else N.array([y0])
- yd0 = N.array(yd0) if len(N.array(yd0).shape)>0 else N.array([yd0])
+ y0 = np.array(y0) if len(np.array(y0).shape)>0 else np.array([y0])
+ yd0 = np.array(yd0) if len(np.array(yd0).shape)>0 else np.array([yd0])
if len(self.y) != len(y0) or len(self.yd) != len(yd0):
raise Implicit_ODE_Exception('y0/yd0 must be of the same length as the original problem.')
@@ -121,12 +121,12 @@ cdef class Implicit_ODE(ODE):
self.yd = yd0
if sw0 is not None:
- self.sw = (N.array(sw0,dtype=bool) if len(N.array(sw0,dtype=bool).shape)>0 else N.array([sw0],dtype=bool)).tolist()
+ self.sw = (np.array(sw0,dtype=bool) if len(np.array(sw0,dtype=bool).shape)>0 else np.array([sw0],dtype=bool)).tolist()
#Clear logs
self.clear_logs()
- cpdef _simulate(self, double t0, double tfinal,N.ndarray output_list,int REPORT_CONTINUOUSLY, int INTERPOLATE_OUTPUT,
+ cpdef _simulate(self, double t0, double tfinal,np.ndarray output_list,int REPORT_CONTINUOUSLY, int INTERPOLATE_OUTPUT,
int TIME_EVENT):
"""
INTERNAL FUNCTION, FOR SIMULATION USE METHOD SIMULATE.
@@ -158,7 +158,7 @@ cdef class Implicit_ODE(ODE):
cdef int flag, output_index
cdef dict opts
cdef int type = self.problem_info["type"]
- cdef double eps = N.finfo(float).eps*100 #Machine Epsilon
+ cdef double eps = np.finfo(float).eps*100 #Machine Epsilon
cdef backward = 1 if self.backward else 0
y0 = self.y
@@ -408,7 +408,7 @@ cdef class Implicit_ODE(ODE):
(t_low, g_low) = (t_mid, g_mid[0:n_g])
side = 2
- event_info = N.array([0] * n_g)
+ event_info = np.array([0] * n_g)
for i in xrange(n_g):
if (g_low[i] > 0) != (g_high[i] > 0):
event_info[i] = 1 if g_high[i] > 0 else -1
@@ -459,7 +459,7 @@ cdef class Implicit_ODE(ODE):
'the number of variables.')
for i in range(len(mask)):
if mask[i]:
- P.plot(self.t_sol, N.array(self.y_sol)[:,i], **kwargs)
+ P.plot(self.t_sol, np.array(self.y_sol)[:,i], **kwargs)
P.xlabel('time')
P.ylabel('state')
@@ -481,7 +481,7 @@ cdef class Implicit_ODE(ODE):
'the number of variables.')
for i in range(len(mask)):
if mask[i]:
- P.plot(self.t_sol, N.array(self.yd_sol)[:,i], **kwargs)
+ P.plot(self.t_sol, np.array(self.yd_sol)[:,i], **kwargs)
P.xlabel('time')
P.ylabel('state derivatives')
@@ -496,6 +496,3 @@ cdef class OverdeterminedDAE(Implicit_ODE):
def check_instance(self):
if not isinstance(self.problem, (Overdetermined_Problem, Implicit_Problem)):
raise Implicit_ODE_Exception('The problem needs to be a subclass of Overdetermined_Problem or of Implicit_Problem.')
-
-
-
diff --git a/src/lib/radau_core.py b/src/lib/radau_core.py
index 36d2fc4a..f388b9c2 100644
--- a/src/lib/radau_core.py
+++ b/src/lib/radau_core.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import numpy as N
+import numpy as np
from assimulo.ode import NORMAL
class Radau_Exception(Exception):
@@ -60,7 +60,7 @@ def plot_stepsize(self):
"""
import pylab as P
- P.semilogy(N.diff(self.t),drawstyle='steps-post')
+ P.semilogy(np.diff(self.t),drawstyle='steps-post')
P.title(self.problem.name)
P.ylabel('Step length')
P.xlabel('Number of steps')
@@ -357,10 +357,10 @@ def _get_usejac(self):
def _set_atol(self,atol):
- self.options["atol"] = N.array(atol,dtype=float) if len(N.array(atol,dtype=float).shape)>0 else N.array([atol],dtype=float)
+ self.options["atol"] = np.array(atol,dtype=float) if len(np.array(atol,dtype=float).shape)>0 else np.array([atol],dtype=float)
if len(self.options["atol"]) == 1:
- self.options["atol"] = self.options["atol"]*N.ones(self._leny)
+ self.options["atol"] = self.options["atol"]*np.ones(self._leny)
elif len(self.options["atol"]) != self._leny:
raise Radau_Exception("atol must be of length one or same as the dimension of the problem.")
diff --git a/src/lib/sundials_callbacks.pxi b/src/lib/sundials_callbacks.pxi
index 2d0753f3..1ea78894 100644
--- a/src/lib/sundials_callbacks.pxi
+++ b/src/lib/sundials_callbacks.pxi
@@ -33,9 +33,9 @@ cdef N_Vector N_VNewEmpty_Euclidean(long int n) noexcept:
return v
cdef inline N_Vector arr2nv(x) noexcept:
- x=N.array(x)
+ x=np.array(x)
cdef long int n = len(x)
- cdef N.ndarray[realtype, ndim=1,mode='c'] ndx=x
+ cdef np.ndarray[realtype, ndim=1,mode='c'] ndx=x
cdef void* data_ptr=PyArray_DATA(ndx)
IF SUNDIALS_VERSION >= (6,0,0):
cdef SUNDIALS.SUNContext ctx = NULL
@@ -48,34 +48,34 @@ cdef inline N_Vector arr2nv(x) noexcept:
return v
cdef inline N_Vector arr2nv_euclidean(x) noexcept:
- x=N.array(x)
+ x=np.array(x)
cdef long int n = len(x)
- cdef N.ndarray[realtype, ndim=1,mode='c'] ndx=x
+ cdef np.ndarray[realtype, ndim=1,mode='c'] ndx=x
cdef void* data_ptr=PyArray_DATA(ndx)
cdef N_Vector v=N_VNewEmpty_Euclidean(n)
memcpy((v.content).data, data_ptr, n*sizeof(realtype))
return v
cdef inline void arr2nv_inplace(x, N_Vector out) noexcept:
- x=N.array(x)
+ x=np.array(x)
cdef long int n = len(x)
- cdef N.ndarray[realtype, ndim=1,mode='c'] ndx=x
+ cdef np.ndarray[realtype, ndim=1,mode='c'] ndx=x
cdef void* data_ptr=PyArray_DATA(ndx)
memcpy((out.content).data, data_ptr, n*sizeof(realtype))
-cdef inline N.ndarray nv2arr(N_Vector v) noexcept:
+cdef inline np.ndarray nv2arr(N_Vector v) noexcept:
cdef long int n = (v.content).length
cdef realtype* v_data = (v.content).data
- cdef N.ndarray[realtype, ndim=1, mode='c'] x=N.empty(n)
+ cdef np.ndarray[realtype, ndim=1, mode='c'] x=np.empty(n)
memcpy(PyArray_DATA(x), v_data, n*sizeof(realtype))
return x
-cdef inline void nv2arr_inplace(N_Vector v, N.ndarray o) noexcept:
+cdef inline void nv2arr_inplace(N_Vector v, np.ndarray o) noexcept:
cdef long int n = (v.content).length
cdef realtype* v_data = (v.content).data
memcpy(PyArray_DATA(o), v_data, n*sizeof(realtype))
-cdef inline void nv2mat_inplace(int Ns, N_Vector *v, N.ndarray o) noexcept:
+cdef inline void nv2mat_inplace(int Ns, N_Vector *v, np.ndarray o) noexcept:
cdef long int i,j, Nf
for i in range(Ns):
Nf = (v[i].content).length
@@ -84,6 +84,6 @@ cdef inline void nv2mat_inplace(int Ns, N_Vector *v, N.ndarray o) noexcept:
cdef inline realtype2arr(realtype *data, int n) noexcept:
"""Create new numpy array from realtype*"""
- cdef N.ndarray[realtype, ndim=1, mode='c'] x=N.empty(n)
+ cdef np.ndarray[realtype, ndim=1, mode='c'] x=np.empty(n)
memcpy(PyArray_DATA(x), data, n*sizeof(realtype))
return x
diff --git a/src/lib/sundials_callbacks_ida_cvode.pxi b/src/lib/sundials_callbacks_ida_cvode.pxi
index eaa776cb..d200c589 100644
--- a/src/lib/sundials_callbacks_ida_cvode.pxi
+++ b/src/lib/sundials_callbacks_ida_cvode.pxi
@@ -25,7 +25,7 @@ cdef int cv_rhs(realtype t, N_Vector yv, N_Vector yvdot, void* problem_data) noe
right-hand-side function.
"""
cdef ProblemData pData = problem_data
- cdef N.ndarray y = pData.work_y
+ cdef np.ndarray y = pData.work_y
cdef realtype* resptr=(yvdot.content).data
cdef int i
@@ -60,8 +60,8 @@ cdef int cv_sens_rhs_all(int Ns, realtype t, N_Vector yv, N_Vector yvdot,
N_Vector tmp1, N_Vector tmp2) noexcept:
cdef ProblemData pData = problem_data
- cdef N.ndarray y = pData.work_y
- cdef N.ndarray s = pData.work_ys
+ cdef np.ndarray y = pData.work_y
+ cdef np.ndarray s = pData.work_ys
cdef realtype* resptr
cdef int i, j
@@ -81,7 +81,7 @@ cdef int cv_sens_rhs_all(int Ns, realtype t, N_Vector yv, N_Vector yvdot,
resptr[j] = sens_rhs[j,i]
return CV_SUCCESS
- except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
+ except(np.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
return CV_REC_ERR
except Exception:
traceback.print_exc()
@@ -99,7 +99,7 @@ IF SUNDIALS_VERSION >= (3,0,0):
"""
cdef ProblemData pData = problem_data
cdef SUNMatrixContent_Sparse Jacobian = Jac.content
- cdef N.ndarray y = pData.work_y
+ cdef np.ndarray y = pData.work_y
cdef int i
cdef sunindextype nnz = Jacobian.NNZ
cdef int ret_nnz
@@ -137,7 +137,7 @@ IF SUNDIALS_VERSION >= (3,0,0):
colptrs[i] = jac.indptr[i]
return CVDLS_SUCCESS
- except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
+ except(np.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
return CVDLS_JACFUNC_RECVR #Recoverable Error (See Sundials description)
except Exception:
traceback.print_exc()
@@ -152,15 +152,15 @@ ELSE:
Sparse Jacobian function.
"""
cdef ProblemData pData = problem_data
- cdef N.ndarray y = pData.work_y
+ cdef np.ndarray y = pData.work_y
cdef int i
cdef int nnz = Jacobian.NNZ
cdef int ret_nnz
cdef int dim = Jacobian.N
cdef realtype* data = Jacobian.data
- cdef N.ndarray[realtype, ndim=1, mode='c'] jdata
- cdef N.ndarray[int, ndim=1, mode='c'] jindices
- cdef N.ndarray[int, ndim=1, mode='c'] jindptr
+ cdef np.ndarray[realtype, ndim=1, mode='c'] jdata
+ cdef np.ndarray[int, ndim=1, mode='c'] jindices
+ cdef np.ndarray[int, ndim=1, mode='c'] jindptr
IF SUNDIALS_VERSION >= (2,6,3):
cdef int* rowvals = Jacobian.rowvals[0]
@@ -204,7 +204,7 @@ ELSE:
memcpy(colptrs, jindptr.data, (dim+1)*sizeof(int))
return CVDLS_SUCCESS
- except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
+ except(np.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
return CVDLS_JACFUNC_RECVR #Recoverable Error (See Sundials description)
except Exception:
traceback.print_exc()
@@ -221,7 +221,7 @@ IF SUNDIALS_VERSION >= (3,0,0):
cdef SUNMatrixContent_Dense Jacobian = Jac.content
cdef ProblemData pData = problem_data
cdef realtype* col_i=Jacobian.cols[0]
- cdef N.ndarray y = pData.work_y
+ cdef np.ndarray y = pData.work_y
cdef int i,j, Neq = pData.dim
nv2arr_inplace(yv, y)
@@ -233,7 +233,7 @@ IF SUNDIALS_VERSION >= (3,0,0):
jac=(pData.JAC)(t,y,sw=pData.sw,p=p)
else:
jac=(pData.JAC)(t,y,p)
- except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
+ except(np.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
return CVDLS_JACFUNC_RECVR #Recoverable Error (See Sundials description)
except Exception:
traceback.print_exc()
@@ -244,7 +244,7 @@ IF SUNDIALS_VERSION >= (3,0,0):
jac=(pData.JAC)(t,y,sw=pData.sw)
else:
jac=(pData.JAC)(t,y)
- except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
+ except(np.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
return CVDLS_JACFUNC_RECVR #Recoverable Error (See Sundials description)
except Exception:
traceback.print_exc()
@@ -271,7 +271,7 @@ ELSE:
"""
cdef ProblemData pData = problem_data
cdef realtype* col_i=DENSE_COL(Jacobian,0)
- cdef N.ndarray y = pData.work_y
+ cdef np.ndarray y = pData.work_y
cdef int i,j
nv2arr_inplace(yv, y)
@@ -283,7 +283,7 @@ ELSE:
jac=(pData.JAC)(t,y,sw=pData.sw,p=p)
else:
jac=(pData.JAC)(t,y,p)
- except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
+ except(np.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
return CVDLS_JACFUNC_RECVR #Recoverable Error (See Sundials description)
except Exception:
traceback.print_exc()
@@ -294,7 +294,7 @@ ELSE:
jac=(pData.JAC)(t,y,sw=pData.sw)
else:
jac=(pData.JAC)(t,y)
- except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
+ except(np.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
return CVDLS_JACFUNC_RECVR #Recoverable Error (See Sundials description)
except Exception:
traceback.print_exc()
@@ -321,9 +321,9 @@ cdef int cv_jacv(N_Vector vv, N_Vector Jv, realtype t, N_Vector yv, N_Vector fyv
Jacobian times vector function.
"""
cdef ProblemData pData = problem_data
- cdef N.ndarray y = nv2arr(yv)
- cdef N.ndarray v = nv2arr(vv)
- cdef N.ndarray fy = nv2arr(fyv)
+ cdef np.ndarray y = nv2arr(yv)
+ cdef np.ndarray v = nv2arr(vv)
+ cdef np.ndarray fy = nv2arr(fyv)
cdef int i
cdef realtype* jacvptr=(Jv.content).data
@@ -340,7 +340,7 @@ cdef int cv_jacv(N_Vector vv, N_Vector Jv, realtype t, N_Vector yv, N_Vector fyv
jacvptr[i] = jacv[i]
return SPGMR_SUCCESS
- except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
+ except(np.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
return SPGMR_ATIMES_FAIL_REC
except Exception:
traceback.print_exc()
@@ -356,7 +356,7 @@ cdef int cv_jacv(N_Vector vv, N_Vector Jv, realtype t, N_Vector yv, N_Vector fyv
jacvptr[i] = jacv[i]
return SPGMR_SUCCESS
- except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
+ except(np.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
return SPGMR_ATIMES_FAIL_REC
except Exception:
traceback.print_exc()
@@ -370,8 +370,8 @@ IF SUNDIALS_VERSION >= (3,0,0):
For information see CVODES documentation 4.6.9
"""
cdef ProblemData pData = problem_data
- cdef N.ndarray y = nv2arr(yy)
- cdef N.ndarray fy = nv2arr(fyy)
+ cdef np.ndarray y = nv2arr(yy)
+ cdef np.ndarray fy = nv2arr(fyy)
cdef object ret
try:
@@ -392,9 +392,9 @@ IF SUNDIALS_VERSION >= (3,0,0):
For information see CVODES documentation 4.6.8
"""
cdef ProblemData pData = problem_data
- cdef N.ndarray y = nv2arr(yy)
- cdef N.ndarray r = nv2arr(rr)
- cdef N.ndarray fy = nv2arr(fyy)
+ cdef np.ndarray y = nv2arr(yy)
+ cdef np.ndarray r = nv2arr(rr)
+ cdef np.ndarray fy = nv2arr(fyy)
cdef realtype* zptr=(z.content).data
cdef int i
@@ -417,8 +417,8 @@ ELSE:
For information see CVODES documentation 4.6.9
"""
cdef ProblemData pData = problem_data
- cdef N.ndarray y = nv2arr(yy)
- cdef N.ndarray fy = nv2arr(fyy)
+ cdef np.ndarray y = nv2arr(yy)
+ cdef np.ndarray fy = nv2arr(fyy)
cdef object ret
try:
@@ -439,9 +439,9 @@ ELSE:
For information see CVODES documentation 4.6.8
"""
cdef ProblemData pData = problem_data
- cdef N.ndarray y = nv2arr(yy)
- cdef N.ndarray r = nv2arr(rr)
- cdef N.ndarray fy = nv2arr(fyy)
+ cdef np.ndarray y = nv2arr(yy)
+ cdef np.ndarray r = nv2arr(rr)
+ cdef np.ndarray fy = nv2arr(fyy)
cdef realtype* zptr=(z.content).data
cdef int i
@@ -461,9 +461,9 @@ cdef int cv_prec(realtype t, N Vector yv, N Vector fyv,
void *problem_data, N Vector tmp):
cdef ProblemData pData = problem_data
- cdef N.ndarray y = nv2arr(yv)
- cdef N.ndarray fy = nv2arr(fyv)
- cdef N.ndarray r = nv2arr(rv)
+ cdef np.ndarray y = nv2arr(yv)
+ cdef np.ndarray fy = nv2arr(fyv)
+ cdef np.ndarray r = nv2arr(rv)
cdef int i
cdef realtype* zptr=(z.content).data
@@ -486,7 +486,7 @@ cdef int cv_root(realtype t, N_Vector yv, realtype *gout, void* problem_data) no
Root-finding function.
"""
cdef ProblemData pData = problem_data
- cdef N.ndarray y = pData.work_y
+ cdef np.ndarray y = pData.work_y
cdef int i
nv2arr_inplace(yv, y)
@@ -511,9 +511,9 @@ cdef int ida_res(realtype t, N_Vector yv, N_Vector yvdot, N_Vector residual, voi
residual function.
"""
cdef ProblemData pData = problem_data
- cdef N.ndarray[realtype, ndim=1, mode='c'] res #Used for return from the user function
- cdef N.ndarray y = pData.work_y
- cdef N.ndarray yd = pData.work_yd
+ cdef np.ndarray[realtype, ndim=1, mode='c'] res #Used for return from the user function
+ cdef np.ndarray y = pData.work_y
+ cdef np.ndarray yd = pData.work_yd
cdef realtype* resptr=(residual.content).data
cdef int i
@@ -533,7 +533,7 @@ cdef int ida_res(realtype t, N_Vector yv, N_Vector yvdot, N_Vector residual, voi
resptr[i] = res[i]
return IDA_SUCCESS
- except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
+ except(np.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
return IDA_REC_ERR # recoverable error (see Sundials description)
except Exception:
traceback.print_exc()
@@ -551,7 +551,7 @@ cdef int ida_res(realtype t, N_Vector yv, N_Vector yvdot, N_Vector residual, voi
resptr[i] = res[i]
return IDA_SUCCESS
- except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
+ except(np.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
return IDA_REC_ERR # recoverable error (see Sundials description)
except Exception:
traceback.print_exc()
@@ -566,10 +566,10 @@ IF SUNDIALS_VERSION >= (3,0,0):
"""
cdef SUNMatrixContent_Dense Jacobian = Jac.content
cdef ProblemData pData = problem_data
- cdef N.ndarray[realtype, ndim=2, mode='c'] jac #Used for return from the user function
+ cdef np.ndarray[realtype, ndim=2, mode='c'] jac #Used for return from the user function
cdef realtype* col_i=Jacobian.cols[0]
- cdef N.ndarray y = pData.work_y
- cdef N.ndarray yd = pData.work_yd
+ cdef np.ndarray y = pData.work_y
+ cdef np.ndarray yd = pData.work_yd
cdef int i,j, Neq = pData.dim
nv2arr_inplace(yv, y)
@@ -588,7 +588,7 @@ IF SUNDIALS_VERSION >= (3,0,0):
for j in range(Neq):
col_i[j] = jac[j,i]
return IDADLS_SUCCESS
- except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
+ except(np.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
return IDADLS_JACFUNC_RECVR #Recoverable Error
except Exception:
traceback.print_exc()
@@ -605,7 +605,7 @@ IF SUNDIALS_VERSION >= (3,0,0):
for j in range(Neq):
col_i[j] = jac[j,i]
return IDADLS_SUCCESS
- except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
+ except(np.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
return IDADLS_JACFUNC_RECVR #Recoverable Error
except Exception:
traceback.print_exc()
@@ -618,10 +618,10 @@ ELSE:
Jacobian function.
"""
cdef ProblemData pData = problem_data
- cdef N.ndarray[realtype, ndim=2, mode='c'] jac #Used for return from the user function
+ cdef np.ndarray[realtype, ndim=2, mode='c'] jac #Used for return from the user function
cdef realtype* col_i=DENSE_COL(Jacobian,0)
- cdef N.ndarray y = pData.work_y
- cdef N.ndarray yd = pData.work_yd
+ cdef np.ndarray y = pData.work_y
+ cdef np.ndarray yd = pData.work_yd
cdef int i,j
nv2arr_inplace(yv, y)
@@ -640,7 +640,7 @@ ELSE:
for j in range(Neq):
col_i[j] = jac[j,i]
return IDADLS_SUCCESS
- except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
+ except(np.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
return IDADLS_JACFUNC_RECVR #Recoverable Error
except Exception:
traceback.print_exc()
@@ -657,7 +657,7 @@ ELSE:
for j in range(Neq):
col_i[j] = jac[j,i]
return IDADLS_SUCCESS
- except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
+ except(np.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
return IDADLS_JACFUNC_RECVR #Recoverable Error
except Exception:
traceback.print_exc()
@@ -670,9 +670,9 @@ cdef int ida_root(realtype t, N_Vector yv, N_Vector yvdot, realtype *gout, void*
root function.
"""
cdef ProblemData pData = problem_data
- cdef N.ndarray[realtype, ndim=1, mode='c'] root #Used for return from the user function
- cdef N.ndarray y = pData.work_y
- cdef N.ndarray yd = pData.work_yd
+ cdef np.ndarray[realtype, ndim=1, mode='c'] root #Used for return from the user function
+ cdef np.ndarray y = pData.work_y
+ cdef np.ndarray yd = pData.work_yd
cdef int i
nv2arr_inplace(yv, y)
@@ -699,10 +699,10 @@ cdef int ida_jacv(realtype t, N_Vector yy, N_Vector yp, N_Vector rr, N_Vector vv
Jacobian times vector function.
"""
cdef ProblemData pData = problem_data
- cdef N.ndarray y = nv2arr(yy)
- cdef N.ndarray yd = nv2arr(yp)
- cdef N.ndarray v = nv2arr(vv)
- cdef N.ndarray res = nv2arr(rr)
+ cdef np.ndarray y = nv2arr(yy)
+ cdef np.ndarray yd = nv2arr(yp)
+ cdef np.ndarray v = nv2arr(vv)
+ cdef np.ndarray res = nv2arr(rr)
cdef int i
cdef realtype* jacvptr=(Jv.content).data
@@ -719,7 +719,7 @@ cdef int ida_jacv(realtype t, N_Vector yy, N_Vector yp, N_Vector rr, N_Vector vv
jacvptr[i] = jacv[i]
return SPGMR_SUCCESS
- except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
+ except(np.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
return SPGMR_ATIMES_FAIL_REC
except Exception:
traceback.print_exc()
@@ -735,7 +735,7 @@ cdef int ida_jacv(realtype t, N_Vector yy, N_Vector yp, N_Vector rr, N_Vector vv
jacvptr[i] = jacv[i]
return SPGMR_SUCCESS
- except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
+ except(np.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
return SPGMR_ATIMES_FAIL_REC
except Exception:
traceback.print_exc()
@@ -794,11 +794,11 @@ cdef class ProblemData:
int memSizeJac #dim*dim*sizeof(realtype) used when copying memory
int verbose #Defines the verbosity
object PREC_DATA #Arbitrary data from the preconditioner
- N.ndarray work_y
- N.ndarray work_yd
- N.ndarray work_ys
+ np.ndarray work_y
+ np.ndarray work_yd
+ np.ndarray work_ys
cdef create_work_arrays(self):
- self.work_y = N.empty(self.dim)
- self.work_yd = N.empty(self.dim)
- self.work_ys = N.empty((self.dim, self.dimSens))
+ self.work_y = np.empty(self.dim)
+ self.work_yd = np.empty(self.dim)
+ self.work_ys = np.empty((self.dim, self.dimSens))
diff --git a/src/lib/sundials_callbacks_kinsol.pxi b/src/lib/sundials_callbacks_kinsol.pxi
index 213e0536..4cadca78 100644
--- a/src/lib/sundials_callbacks_kinsol.pxi
+++ b/src/lib/sundials_callbacks_kinsol.pxi
@@ -29,7 +29,7 @@ IF SUNDIALS_VERSION >= (3,0,0):
cdef SUNMatrixContent_Dense Jacobian = Jac.content
cdef ProblemDataEquationSolver pData = problem_data
cdef realtype* col_i=Jacobian.cols[0]
- cdef N.ndarray x = nv2arr(xv)
+ cdef np.ndarray x = nv2arr(xv)
cdef int i,j, Neq = pData.dim
try:
@@ -52,7 +52,7 @@ ELSE:
"""
cdef ProblemDataEquationSolver pData = problem_data
cdef realtype* col_i=DENSE_COL(Jacobian,0)
- cdef N.ndarray x = nv2arr(xv)
+ cdef np.ndarray x = nv2arr(xv)
cdef int i,j
try:
@@ -70,8 +70,8 @@ ELSE:
cdef int kin_jacv(N_Vector vv, N_Vector Jv, N_Vector vx, int* new_u,
void *problem_data) noexcept:
cdef ProblemDataEquationSolver pData = problem_data
- cdef N.ndarray x = nv2arr(vx)
- cdef N.ndarray v = nv2arr(vv)
+ cdef np.ndarray x = nv2arr(vx)
+ cdef np.ndarray v = nv2arr(vv)
cdef int i
cdef realtype* jacvptr=(Jv.content).data
@@ -83,7 +83,7 @@ cdef int kin_jacv(N_Vector vv, N_Vector Jv, N_Vector vx, int* new_u,
jacvptr[i] = jacv[i]
return SPGMR_SUCCESS
- except (N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
+ except (np.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
return SPGMR_ATIMES_FAIL_REC
except Exception:
traceback.print_exc()
@@ -94,7 +94,7 @@ cdef int kin_res(N_Vector xv, N_Vector fval, void *problem_data) noexcept:
Residual fct called by KINSOL
"""
cdef ProblemDataEquationSolver pData = problem_data
- cdef N.ndarray x = nv2arr(xv)
+ cdef np.ndarray x = nv2arr(xv)
cdef realtype* resptr = (fval.content).data
cdef int i
@@ -104,7 +104,7 @@ cdef int kin_res(N_Vector xv, N_Vector fval, void *problem_data) noexcept:
for i in range(pData.dim):
resptr[i] = res[i]
return KIN_SUCCESS
- except (N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
+ except (np.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
return KIN_REC_ERR
except Exception:
traceback.print_exc()
@@ -123,14 +123,14 @@ IF SUNDIALS_VERSION >= (3,0,0):
"""
cdef ProblemDataEquationSolver pData = problem_data
- cdef N.ndarray fscale = nv2arr(fscaleN)
- cdef N.ndarray uscale = nv2arr(uscaleN)
- cdef N.ndarray r = nv2arr(v)
+ cdef np.ndarray fscale = nv2arr(fscaleN)
+ cdef np.ndarray uscale = nv2arr(uscaleN)
+ cdef np.ndarray r = nv2arr(v)
cdef realtype* zptr=(v.content).data
try:
zres = (pData.PREC_SOLVE)(r)
- except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
+ except(np.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
return KIN_REC_ERR
except Exception:
traceback.print_exc()
@@ -148,14 +148,14 @@ IF SUNDIALS_VERSION >= (3,0,0):
"""
cdef ProblemDataEquationSolver pData = problem_data
- cdef N.ndarray fscale = nv2arr(fscaleN)
- cdef N.ndarray uscale = nv2arr(uscaleN)
- cdef N.ndarray u = nv2arr(uN)
- cdef N.ndarray fval = nv2arr(fvalN)
+ cdef np.ndarray fscale = nv2arr(fscaleN)
+ cdef np.ndarray uscale = nv2arr(uscaleN)
+ cdef np.ndarray u = nv2arr(uN)
+ cdef np.ndarray fval = nv2arr(fvalN)
try:
(pData.PREC_SETUP)(u, fval, uscale, fscale)
- except (N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
+ except (np.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
return KIN_REC_ERR
except Exception:
traceback.print_exc()
@@ -176,14 +176,14 @@ ELSE:
"""
cdef ProblemDataEquationSolver pData = problem_data
- cdef N.ndarray fscale = nv2arr(fscaleN)
- cdef N.ndarray uscale = nv2arr(uscaleN)
- cdef N.ndarray r = nv2arr(v)
+ cdef np.ndarray fscale = nv2arr(fscaleN)
+ cdef np.ndarray uscale = nv2arr(uscaleN)
+ cdef np.ndarray r = nv2arr(v)
cdef realtype* zptr=(v.content).data
try:
zres = (pData.PREC_SOLVE)(r)
- except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
+ except(np.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
return KIN_REC_ERR
except Exception:
traceback.print_exc()
@@ -201,14 +201,14 @@ ELSE:
"""
cdef ProblemDataEquationSolver pData = problem_data
- cdef N.ndarray fscale = nv2arr(fscaleN)
- cdef N.ndarray uscale = nv2arr(uscaleN)
- cdef N.ndarray u = nv2arr(uN)
- cdef N.ndarray fval = nv2arr(fvalN)
+ cdef np.ndarray fscale = nv2arr(fscaleN)
+ cdef np.ndarray uscale = nv2arr(uscaleN)
+ cdef np.ndarray u = nv2arr(uN)
+ cdef np.ndarray fval = nv2arr(fvalN)
try:
(pData.PREC_SETUP)(u, fval, uscale, fscale)
- except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
+ except(np.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
return KIN_REC_ERR
except Exception:
traceback.print_exc()
diff --git a/src/ode.pxd b/src/ode.pxd
index 9d3d43c0..9d819306 100644
--- a/src/ode.pxd
+++ b/src/ode.pxd
@@ -15,8 +15,8 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import numpy as N
-cimport numpy as N
+import numpy as np
+cimport numpy as np
from assimulo.support cimport Statistics
@@ -34,8 +34,8 @@ cdef class ODE:
cdef public int display_counter
cdef public int chattering_clear_counter
cdef public int chattering_ok_print
- cdef public N.ndarray y,yd, p
- cdef public N.ndarray y0, yd0, p0, sw0
+ cdef public np.ndarray y,yd, p
+ cdef public np.ndarray y0, yd0, p0, sw0
cdef double elapsed_step_time, time_integration_start
cdef int time_limit_activated, display_progress_activated
cdef double clock_start
diff --git a/src/ode.pyx b/src/ode.pyx
index 1a34403a..9707e217 100644
--- a/src/ode.pyx
+++ b/src/ode.pyx
@@ -17,8 +17,8 @@
# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION
-import numpy as N
-cimport numpy as N
+import numpy as np
+cimport numpy as np
import itertools
import multiprocessing
from timeit import default_timer as timer
@@ -67,7 +67,7 @@ cdef class ODE:
#Data object for storing the event data
self.event_data = []
- self._event_info = N.array([])
+ self._event_info = np.array([])
if problem is None:
raise ODE_Exception('The problem needs to be a subclass of a Problem.')
@@ -92,7 +92,7 @@ cdef class ODE:
self.problem_info["step_events"] = True
if hasattr(problem, 'y0'):
- self.y0 = N.array(problem.y0,dtype=realtype) if len(N.array(problem.y0,dtype=realtype).shape)>0 else N.array([problem.y0],dtype=realtype)
+ self.y0 = np.array(problem.y0,dtype=realtype) if len(np.array(problem.y0,dtype=realtype).shape)>0 else np.array([problem.y0],dtype=realtype)
self.problem_info["dim"] = len(self.y0)
else:
raise ODE_Exception('y0 must be specified in the problem.')
@@ -103,12 +103,12 @@ cdef class ODE:
self.problem_info["neq"] = self.problem_info["dim"]
if hasattr(problem, "p0"):
- self.p0 = N.array(problem.p0,dtype=realtype) if len(N.array(problem.p0,dtype=realtype).shape)>0 else N.array([problem.p0],dtype=realtype)
+ self.p0 = np.array(problem.p0,dtype=realtype) if len(np.array(problem.p0,dtype=realtype).shape)>0 else np.array([problem.p0],dtype=realtype)
self.problem_info["dimSens"] = len(self.p0)
self.p = self.p0.copy()
if hasattr(problem, "sw0"):
- self.sw0 = N.array(problem.sw0,dtype=bool) if len(N.array(problem.sw0,dtype=bool).shape)>0 else N.array([problem.sw0],dtype=bool)
+ self.sw0 = np.array(problem.sw0,dtype=bool) if len(np.array(problem.sw0,dtype=bool).shape)>0 else np.array([problem.sw0],dtype=bool)
self.problem_info["switches"] = True
self.sw = self.sw0.tolist()
@@ -272,18 +272,18 @@ cdef class ODE:
#Determine the output list
if ncp != 0:
- output_list = N.linspace(t0,tfinal,ncp+1)[1:]
+ output_list = np.linspace(t0,tfinal,ncp+1)[1:]
output_index = 0
elif ncp_list is not None:
if self.options["backward"]:
- output_list = N.array(ncp_list, dtype=realtype, ndmin=1)[N.logical_and(N.array(ncp_list, dtype=realtype, ndmin=1)=tfinal)]
- output_list = -N.sort(-output_list)
+ output_list = np.array(ncp_list, dtype=realtype, ndmin=1)[np.logical_and(np.array(ncp_list, dtype=realtype, ndmin=1)=tfinal)]
+ output_list = -np.sort(-output_list)
if output_list[-1] > tfinal: #Add the last point if necessary!
- output_list = N.append(output_list, tfinal)
+ output_list = np.append(output_list, tfinal)
else:
- output_list = N.array(ncp_list, dtype=realtype, ndmin=1)[N.logical_and(N.array(ncp_list, dtype=realtype, ndmin=1)>t0,N.array(ncp_list, dtype=realtype, ndmin=1)<=tfinal)]
+ output_list = np.array(ncp_list, dtype=realtype, ndmin=1)[np.logical_and(np.array(ncp_list, dtype=realtype, ndmin=1)>t0,np.array(ncp_list, dtype=realtype, ndmin=1)<=tfinal)]
if output_list[-1] < tfinal: #Add the last point if necessary!
- output_list = N.append(output_list, tfinal)
+ output_list = np.append(output_list, tfinal)
output_index = 0
else:
output_list = None
@@ -330,9 +330,9 @@ cdef class ODE:
#Return the results
if isinstance(self.problem, (Explicit_Problem, Delay_Explicit_Problem, SingPerturbed_Problem)):
- return self.t_sol, N.array(self.y_sol)
+ return self.t_sol, np.array(self.y_sol)
else:
- return self.t_sol, N.array(self.y_sol), N.array(self.yd_sol)
+ return self.t_sol, np.array(self.y_sol), np.array(self.yd_sol)
def _simulate(self,t0, tfinal, output_list, REPORT_CONTINUOUSLY, INTERPOLATE_OUTPUT, TIME_EVENT):
pass
@@ -586,7 +586,7 @@ cdef class ODE:
Reduces a tol vector to a scalar if it is an ndarray and all entries are the same.
Used for printing solver options in a more compact way
"""
- if isinstance(tol_vec, N.ndarray) and (tol_vec == tol_vec[0]).all():
+ if isinstance(tol_vec, np.ndarray) and (tol_vec == tol_vec[0]).all():
return tol_vec[0]
else:
return tol_vec
@@ -595,11 +595,11 @@ cdef class ODE:
self.chattering_clear_counter = 0
if event_info[0] is not None and len(event_info[0]) > 0:
if self.chattering_check is None:
- self.chattering_check = abs(N.array(event_info[0]))
+ self.chattering_check = abs(np.array(event_info[0]))
else:
- self.chattering_check += abs(N.array(event_info[0]))
+ self.chattering_check += abs(np.array(event_info[0]))
if max(self.chattering_check) > 5 and self.chattering_ok_print:
self.chattering_ok_print = 0
self.log_message("Warning: Possible chattering detected at t = %e in state event(s): "%self.t +
- str(N.where(self.chattering_check == max(self.chattering_check))[0]), NORMAL)
+ str(np.where(self.chattering_check == max(self.chattering_check))[0]), NORMAL)
diff --git a/src/problem.pxd b/src/problem.pxd
index ef88a0b2..a0ac016e 100644
--- a/src/problem.pxd
+++ b/src/problem.pxd
@@ -15,8 +15,8 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import numpy as N
-cimport numpy as N
+import numpy as np
+cimport numpy as np
cdef class cProblem:
cdef public int _sensitivity_result
@@ -27,14 +27,14 @@ cdef class cProblem:
cpdef finalize(self,object solver)
cdef class cImplicit_Problem(cProblem):
- cpdef res_internal(self, N.ndarray[double, ndim=1] res, double t, N.ndarray[double, ndim=1] y, N.ndarray[double, ndim=1] yd)
+ cpdef res_internal(self, np.ndarray[double, ndim=1] res, double t, np.ndarray[double, ndim=1] y, np.ndarray[double, ndim=1] yd)
cdef class cOverdetermined_Problem(cProblem):
- cpdef res_internal(self, N.ndarray[double, ndim=1] res, double t, N.ndarray[double, ndim=1] y, N.ndarray[double, ndim=1] yd)
+ cpdef res_internal(self, np.ndarray[double, ndim=1] res, double t, np.ndarray[double, ndim=1] y, np.ndarray[double, ndim=1] yd)
cdef class cExplicit_Problem(cProblem):
- cpdef int rhs_internal(self, N.ndarray[double, ndim=1] yd, double t, N.ndarray[double, ndim=1] y)
- cpdef N.ndarray res(self, t, y, yd, sw=*)
+ cpdef int rhs_internal(self, np.ndarray[double, ndim=1] yd, double t, np.ndarray[double, ndim=1] y)
+ cpdef np.ndarray res(self, t, y, yd, sw=*)
cdef class cDelay_Explicit_Problem(cExplicit_Problem):
pass
diff --git a/src/problem.pyx b/src/problem.pyx
index a65ac01f..66c80538 100644
--- a/src/problem.pyx
+++ b/src/problem.pyx
@@ -17,8 +17,8 @@
# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION
-import numpy as N
-cimport numpy as N
+import numpy as np
+cimport numpy as np
from assimulo.support import set_type_shape_array
@@ -86,7 +86,7 @@ cdef class cImplicit_Problem(cProblem):
self.yd0 = set_type_shape_array(yd0)
- def handle_result(self, solver, double t, N.ndarray[double, ndim=1] y, N.ndarray[double, ndim=1] yd):
+ def handle_result(self, solver, double t, np.ndarray[double, ndim=1] y, np.ndarray[double, ndim=1] yd):
"""
Method for specifying how the result is handled. By default the
data is stored in three vectors: solver.(t/y/yd).
@@ -102,7 +102,7 @@ cdef class cImplicit_Problem(cProblem):
for i in range(solver.problem_info["dimSens"]):
solver.p_sol[i] += [solver.interpolate_sensitivity(t, i=i)]
- cpdef res_internal(self, N.ndarray[double, ndim=1] res, double t, N.ndarray[double, ndim=1] y, N.ndarray[double, ndim=1] yd):
+ cpdef res_internal(self, np.ndarray[double, ndim=1] res, double t, np.ndarray[double, ndim=1] y, np.ndarray[double, ndim=1] yd):
try:
res[:] = self.res(t,y,yd)
except Exception:
@@ -120,7 +120,7 @@ cdef class cOverdetermined_Problem(cProblem):
self.yd0 = set_type_shape_array(yd0)
- def handle_result(self, solver, double t, N.ndarray[double, ndim=1] y, N.ndarray[double, ndim=1] yd):
+ def handle_result(self, solver, double t, np.ndarray[double, ndim=1] y, np.ndarray[double, ndim=1] yd):
"""
Method for specifying how the result is to be handled. As default the
data is stored in three vectors: solver.(t/y/yd).
@@ -131,7 +131,7 @@ cdef class cOverdetermined_Problem(cProblem):
solver.y_sol.extend([y])
solver.yd_sol.extend([yd])
- cpdef res_internal(self, N.ndarray[double, ndim=1] res, double t, N.ndarray[double, ndim=1] y, N.ndarray[double, ndim=1] yd):
+ cpdef res_internal(self, np.ndarray[double, ndim=1] res, double t, np.ndarray[double, ndim=1] y, np.ndarray[double, ndim=1] yd):
try:
res[:] = self.res(t,y,yd)
except Exception:
@@ -145,7 +145,7 @@ cdef class cExplicit_Problem(cProblem):
cProblem.__init__(self, y0, t0, p0, sw0, name)
if rhs is not None:
self.rhs = rhs
- def handle_result(self, solver, double t, N.ndarray[double, ndim=1] y):
+ def handle_result(self, solver, double t, np.ndarray[double, ndim=1] y):
"""
Method for specifying how the result is to be handled. As default the
data is stored in two vectors: solver.(t/y).
@@ -160,14 +160,14 @@ cdef class cExplicit_Problem(cProblem):
for i in range(solver.problem_info["dimSens"]):
solver.p_sol[i] += [solver.interpolate_sensitivity(t, i=i)]
- cpdef int rhs_internal(self, N.ndarray[double, ndim=1] yd, double t, N.ndarray[double, ndim=1] y):
+ cpdef int rhs_internal(self, np.ndarray[double, ndim=1] yd, double t, np.ndarray[double, ndim=1] y):
try:
yd[:] = self.rhs(t,y)
except Exception:
return ID_FAIL
return ID_OK
- cpdef N.ndarray res(self, t, y, yd, sw=None):
+ cpdef np.ndarray res(self, t, y, yd, sw=None):
if sw == None:
return yd-self.rhs(t,y)
else:
@@ -206,7 +206,7 @@ cdef class cSingPerturbed_Problem(cExplicit_Problem):
# classical explicit problem without exposing the structure
# of a singularly perturbed problem
if yy0 is not None and zz0 is not None:
- y0 = N.hstack((self.yy0,self.zz0))
+ y0 = np.hstack((self.yy0,self.zz0))
elif yy0 is not None:
y0 = self.yy0
elif zz0 is not None:
@@ -224,7 +224,7 @@ cdef class cSingPerturbed_Problem(cExplicit_Problem):
# a diagonal matrix
if self.eps != None:
zzdot /= self.eps
- return N.hstack((yydot,zzdot))
+ return np.hstack((yydot,zzdot))
class Delay_Explicit_Problem(cDelay_Explicit_Problem):
pass
diff --git a/src/solvers/dasp3.py b/src/solvers/dasp3.py
index 650315af..3318aebf 100644
--- a/src/solvers/dasp3.py
+++ b/src/solvers/dasp3.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
-import numpy as N
+import numpy as np
from assimulo.problem import SingPerturbed_Problem
from assimulo.exception import Explicit_ODE_Exception, DASP3_Exception
@@ -69,13 +69,13 @@ def __init__(self, problem):
self.m=self.problem.m
# Set initial values
- self.wsy=N.empty((10*self.n,))
+ self.wsy=np.empty((10*self.n,))
self.wsy[:self.n]=self.problem.yy0
- self.wsz=N.empty((max(9*self.m,1),)) # array must be at least 1 element long
+ self.wsz=np.empty((max(9*self.m,1),)) # array must be at least 1 element long
self.wsz[:self.m]=self.problem.zz0
# - Default values
- self.options["atol"] = 1.0e-6*N.ones(self.problem_info["dim"]) #Absolute tolerance
+ self.options["atol"] = 1.0e-6*np.ones(self.problem_info["dim"]) #Absolute tolerance
self.options["rtol"] = 1.0e-6 #Relative tolerance
self.statistics.add_key("nyder", "Number of slow function evaluations (Y)")
@@ -93,15 +93,15 @@ def _solout(self, t, wsy, wsz, n, m, jstop):
This method is called after every successful step taken by DASP3
"""
self._tlist.append(t)
- self._ylist.append(N.hstack((wsy[:n],wsz[:m])))
+ self._ylist.append(np.hstack((wsy[:n],wsz[:m])))
if self._opts["report_continuously"]:
- initialize_flag = self.report_solution(t, N.hstack((wsy[:n],wsz[:m])), self._opts)
+ initialize_flag = self.report_solution(t, np.hstack((wsy[:n],wsz[:m])), self._opts)
if initialize_flag:
jstop = -1
else:
self._tlist.append(t)
- self._ylist.append(N.hstack((wsy[:n],wsz[:m])))
+ self._ylist.append(np.hstack((wsy[:n],wsz[:m])))
return jstop
@@ -113,13 +113,13 @@ def integrate(self, t, y, tf, opts):
m = self.problem.m
n = self.problem.n
- a = N.empty((m,m))
- w = N.empty((m,m))
- slu= N.empty((2*m,))
- ips= N.empty((m,),'int32')
- ind = N.empty((2*m,),'int32')
- eq= N.empty((m,),'bool')
- wght=N.ones((m+n,))
+ a = np.empty((m,m))
+ w = np.empty((m,m))
+ slu= np.empty((2*m,))
+ ips= np.empty((m,),'int32')
+ ind = np.empty((2*m,),'int32')
+ eq= np.empty((m,),'bool')
+ wght=np.ones((m+n,))
#Store the opts
self._opts = opts
@@ -156,10 +156,10 @@ def print_statistics(self, verbose=NORMAL):
def _set_atol(self,atol):
- self.options["atol"] = N.array(atol,dtype=float) if len(N.array(atol,dtype=float).shape)>0 else N.array([atol],dtype=float)
+ self.options["atol"] = np.array(atol,dtype=float) if len(np.array(atol,dtype=float).shape)>0 else np.array([atol],dtype=float)
if len(self.options["atol"]) == 1:
- self.options["atol"] = self.options["atol"]*N.ones(self.problem_info["dim"])
+ self.options["atol"] = self.options["atol"]*np.ones(self.problem_info["dim"])
elif len(self.options["atol"]) != self.problem_info["dim"]:
raise DASP3_Exception("atol must be of length one or same as the dimension of the problem.")
diff --git a/src/solvers/euler.pyx b/src/solvers/euler.pyx
index 7f696b69..1d98e4fa 100644
--- a/src/solvers/euler.pyx
+++ b/src/solvers/euler.pyx
@@ -17,9 +17,8 @@
# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION
-cimport numpy as N
-import numpy as N
-import numpy.linalg as LIN
+cimport numpy as np
+import numpy as np
import scipy.sparse as sp
from assimulo.explicit_ode cimport Explicit_ODE
@@ -49,8 +48,8 @@ cdef class ImplicitEuler(Explicit_ODE):
with :math:`h` being the step-size and :math:`y_n` the previous
solution to the equation.
"""
- cdef N.ndarray yd1
- cdef N.ndarray _old_jac
+ cdef np.ndarray yd1
+ cdef np.ndarray _old_jac
cdef object f
cdef public object event_func
cdef int _leny
@@ -58,10 +57,10 @@ cdef class ImplicitEuler(Explicit_ODE):
cdef int _needjac
cdef int _curjac
cdef int _steps_since_last_jac
- cdef N.ndarray _yold
- cdef N.ndarray _ynew
- #cdef N.ndarray _event_info
- cdef public N.ndarray g_old
+ cdef np.ndarray _yold
+ cdef np.ndarray _ynew
+ #cdef np.ndarray _event_info
+ cdef public np.ndarray g_old
cdef double _told
cdef double _h
cdef double _inith
@@ -73,13 +72,13 @@ cdef class ImplicitEuler(Explicit_ODE):
self.options["h"] = 0.01
self.options["usejac"] = True if (self.problem_info["jac_fcn"]) else False
self.options["newt"] = 7 #Maximum number of newton iterations
- self.options["atol"] = 1.0e-6*N.ones(self.problem_info["dim"]) #Absolute tolerance
+ self.options["atol"] = 1.0e-6*np.ones(self.problem_info["dim"]) #Absolute tolerance
self.options["rtol"] = 1.0e-6 #Relative tolerance
#Internal temporary result vector
- self.yd1 = N.array([0.0]*len(self.y0))
- self._yold = N.array([0.0]*len(self.y0))
- self._ynew = N.array([0.0]*len(self.y0))
+ self.yd1 = np.array([0.0]*len(self.y0))
+ self._yold = np.array([0.0]*len(self.y0))
+ self._ynew = np.array([0.0]*len(self.y0))
#Solver support
self.supports["report_continuously"] = True
@@ -88,7 +87,7 @@ cdef class ImplicitEuler(Explicit_ODE):
self._leny = len(self.y) #Dimension of the problem
- self._eps = N.finfo('double').eps
+ self._eps = np.finfo('double').eps
self._needjac = True #Do we need a new jacobian?
self._curjac = False #Is the current jacobian up to date?
self._steps_since_last_jac = 0 #Keep track on how long ago we updated the jacobian
@@ -107,7 +106,7 @@ cdef class ImplicitEuler(Explicit_ODE):
return self.problem.rhs(t, y, self.sw)
self.f = f
self.event_func = event_func
- self._event_info = N.array([0] * self.problem_info["dimRoot"])
+ self._event_info = np.array([0] * self.problem_info["dimRoot"])
ret, self.g_old = self.event_func(self.t, self.y)
if ret < 0:
raise self._py_err
@@ -141,7 +140,7 @@ cdef class ImplicitEuler(Explicit_ODE):
usejac = property(_get_usejac,_set_usejac)
- cpdef step(self,double t,N.ndarray y,double tf,dict opts):
+ cpdef step(self,double t,np.ndarray y,double tf,dict opts):
cdef double h
h = self.options["h"]
@@ -153,7 +152,7 @@ cdef class ImplicitEuler(Explicit_ODE):
t, y = self._step(t,y,h)
return ID_COMPLETE, t, y
- cpdef integrate(self, double t,N.ndarray y,double tf, dict opts):
+ cpdef integrate(self, double t,np.ndarray y,double tf, dict opts):
cdef double h
cdef list tr,yr
@@ -261,10 +260,10 @@ cdef class ImplicitEuler(Explicit_ODE):
def _set_atol(self,atol):
- self.options["atol"] = N.array(atol,dtype=float) if len(N.array(atol,dtype=float).shape)>0 else N.array([atol],dtype=float)
+ self.options["atol"] = np.array(atol,dtype=float) if len(np.array(atol,dtype=float).shape)>0 else np.array([atol],dtype=float)
if len(self.options["atol"]) == 1:
- self.options["atol"] = self.options["atol"]*N.ones(self._leny)
+ self.options["atol"] = self.options["atol"]*np.ones(self._leny)
elif len(self.options["atol"]) != self._leny:
raise AssimuloException("atol must be of length one or same as the dimension of the problem.")
@@ -335,10 +334,10 @@ cdef class ImplicitEuler(Explicit_ODE):
if isinstance(jac, sp.csc_matrix):
jac = jac.toarray()
else: #Calculate a numeric jacobian
- delt = N.array([(self._eps*max(abs(yi),1.e-5))**0.5 for yi in y])*N.identity(self._leny) #Calculate a disturbance
- Fdelt = N.array([self.f(t,y+e) for e in delt]) #Add the disturbance (row by row)
+ delt = np.array([(self._eps*max(abs(yi),1.e-5))**0.5 for yi in y])*np.identity(self._leny) #Calculate a disturbance
+ Fdelt = np.array([self.f(t,y+e) for e in delt]) #Add the disturbance (row by row)
grad = ((Fdelt-self.f(t,y)).T/delt.diagonal()).T
- jac = N.array(grad).T
+ jac = np.array(grad).T
self.statistics["nfcnjacs"] += 1+self._leny #Add the number of function evaluations
@@ -347,7 +346,7 @@ cdef class ImplicitEuler(Explicit_ODE):
- cdef double WRMS(self, N.ndarray x, N.ndarray w):
+ cdef double WRMS(self, np.ndarray x, np.ndarray w):
"""
Calculates the Weighted Root-mean-square.
"""
@@ -361,17 +360,17 @@ cdef class ImplicitEuler(Explicit_ODE):
return (sum/N)**0.5
- cdef tuple _step(self,double t,N.ndarray y,double h):
+ cdef tuple _step(self,double t,np.ndarray y,double h):
"""
This calculates the next step in the integration.
"""
cdef double new_norm = 0
cdef double old_norm = 0
cdef double tn1 = t+h
- cdef N.ndarray yn = y.copy() #Old y
- #cdef N.ndarray yn1 = y.copy() #First newton guess
- cdef N.ndarray yn1 = y+h*self.f(t,y) #First newton guess
- cdef N.ndarray I = N.eye(self._leny)
+ cdef np.ndarray yn = y.copy() #Old y
+ #cdef np.ndarray yn1 = y.copy() #First newton guess
+ cdef np.ndarray yn1 = y+h*self.f(t,y) #First newton guess
+ cdef np.ndarray I = np.eye(self._leny)
self.statistics["nfcns"] += 1
FLAG_CONV = False
@@ -389,12 +388,12 @@ cdef class ImplicitEuler(Explicit_ODE):
#jac = self._jacobian(tn1, yn1)
- #ynew = yn1 - N.dot(LIN.inv(h*jac-I),(yn-yn1+h*self.problem.rhs(tn1,yn1)))
- ynew = yn1 - LIN.solve(h*jac-I, yn-yn1+h*self.f(tn1,yn1) )
+ #ynew = yn1 - np.dot(np.linalg.inv(h*jac-I),(yn-yn1+h*self.problem.rhs(tn1,yn1)))
+ ynew = yn1 - np.linalg.solve(h*jac-I, yn-yn1+h*self.f(tn1,yn1) )
self.statistics["nfcns"] += 1
- #print tn1, self.WRMS(ynew-yn1, 1.0/(self.rtol*N.abs(yn1)+self.atol))
- new_norm = self.WRMS(ynew-yn1, 1.0/(self.rtol*N.abs(yn1)+self.atol))
+ #print tn1, self.WRMS(ynew-yn1, 1.0/(self.rtol*np.abs(yn1)+self.atol))
+ new_norm = self.WRMS(ynew-yn1, 1.0/(self.rtol*np.abs(yn1)+self.atol))
if new_norm < 0.1: #Newton converged
FLAG_CONV = True
@@ -505,13 +504,13 @@ cdef class ExplicitEuler(Explicit_ODE):
with :math:`h` being the step-size and :math:`y_n` the previous
solution to the equation.
"""
- cdef N.ndarray yd1
+ cdef np.ndarray yd1
cdef object f
cdef public object event_func
- cdef N.ndarray _yold
- cdef N.ndarray _ynew
- #cdef N.ndarray _event_info
- cdef public N.ndarray g_old
+ cdef np.ndarray _yold
+ cdef np.ndarray _ynew
+ #cdef np.ndarray _event_info
+ cdef public np.ndarray g_old
cdef double _told
cdef double _h
cdef double _inith
@@ -525,9 +524,9 @@ cdef class ExplicitEuler(Explicit_ODE):
#Internal temporary result vector
- self.yd1 = N.array([0.0]*len(self.y0))
- self._yold = N.array([0.0]*len(self.y0))
- self._ynew = N.array([0.0]*len(self.y0))
+ self.yd1 = np.array([0.0]*len(self.y0))
+ self._yold = np.array([0.0]*len(self.y0))
+ self._ynew = np.array([0.0]*len(self.y0))
self._inith = 0 #Used for taking an initial step of correct length after an event.
#Solver support
@@ -548,7 +547,7 @@ cdef class ExplicitEuler(Explicit_ODE):
return self.problem.rhs(t, y, self.sw)
self.f = f
self.event_func = event_func
- self._event_info = N.array([0] * self.problem_info["dimRoot"])
+ self._event_info = np.array([0] * self.problem_info["dimRoot"])
ret, self.g_old = self.event_func(self.t, self.y)
if ret < 0:
raise self._py_err
@@ -556,7 +555,7 @@ cdef class ExplicitEuler(Explicit_ODE):
else:
self.f = self.problem.rhs
- cpdef step(self,double t,N.ndarray y,double tf,dict opts):
+ cpdef step(self,double t,np.ndarray y,double tf,dict opts):
cdef double h
h = self.options["h"]
@@ -568,7 +567,7 @@ cdef class ExplicitEuler(Explicit_ODE):
t, y = self._step(t,y,h)
return ID_COMPLETE, t, y
- cpdef integrate(self, double t,N.ndarray y,double tf, dict opts):
+ cpdef integrate(self, double t,np.ndarray y,double tf, dict opts):
cdef double h
cdef list tr,yr
@@ -634,7 +633,7 @@ cdef class ExplicitEuler(Explicit_ODE):
return flag, tr, yr
- cdef tuple _step(self,double t,N.ndarray y,double h):
+ cdef tuple _step(self,double t,np.ndarray y,double h):
"""
This calculates the next step in the integration.
"""
diff --git a/src/solvers/glimda.py b/src/solvers/glimda.py
index 31c72427..a2571608 100644
--- a/src/solvers/glimda.py
+++ b/src/solvers/glimda.py
@@ -15,8 +15,8 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import numpy as N
import sys
+import numpy as np
from assimulo.exception import GLIMDA_Exception
from assimulo.ode import ID_PY_COMPLETE, NORMAL
@@ -58,10 +58,10 @@ def __init__(self, problem):
self.options["minord"] = 1 #Minimum order used
self.options["order"] = 0 #Variable order (0) or fixed order (1-3)
self.options["maxsteps"] = 100000 #Maximum number of steps
- self.options["atol"] = 1.0e-6*N.ones(self.problem_info["dim"]) #Absolute tolerance
+ self.options["atol"] = 1.0e-6*np.ones(self.problem_info["dim"]) #Absolute tolerance
self.options["rtol"] = 1.0e-6 #Relative tolerance
- self.options["maxh"] = N.inf #Maximum step-size.
- self.options["minh"] = N.finfo(N.double).eps #Minimum step-size
+ self.options["maxh"] = np.inf #Maximum step-size.
+ self.options["minh"] = np.finfo(np.double).eps #Minimum step-size
self.options["maxretry"] = 15 #Maximum number of consecutive retries
#Solver support
@@ -129,8 +129,8 @@ def integrate(self, t, y, yd, tf, opts):
IADCONST = 1 #The leading term (A,D) is constant
#Options vectors
- IOPT = N.array([0]*9) #Integer options
- ROPT = N.array([0.0]*11) #Real options
+ IOPT = np.array([0]*9) #Integer options
+ ROPT = np.array([0.0]*11) #Real options
#Setting work options
IOPT[0] = self._get_print_level() #Print level (default 2)
@@ -168,7 +168,7 @@ def integrate(self, t, y, yd, tf, opts):
yret, ydret, istats, flag = glimda(res_dummy, qeval_dummy, dfdy_dummy,
dfdx_dummy,dqdx_dummy,t,tf,y.copy(),yd.copy(),self.inith,
- self.atol, self.rtol*N.ones(self.problem_info["dim"]),ITOL,INUMA,INUMD,INUMB,
+ self.atol, self.rtol*np.ones(self.problem_info["dim"]),ITOL,INUMA,INUMD,INUMB,
IODE, IADCONST, IOPT, ROPT, self._solout)
#print self._tlist, self._ylist
#Checking return
@@ -340,10 +340,10 @@ def _get_min_h(self):
def _set_atol(self,atol):
- self.options["atol"] = N.array(atol,dtype=float) if len(N.array(atol,dtype=float).shape)>0 else N.array([atol],dtype=float)
+ self.options["atol"] = np.array(atol,dtype=float) if len(np.array(atol,dtype=float).shape)>0 else np.array([atol],dtype=float)
if len(self.options["atol"]) == 1:
- self.options["atol"] = self.options["atol"]*N.ones(self._leny)
+ self.options["atol"] = self.options["atol"]*np.ones(self._leny)
elif len(self.options["atol"]) != self._leny:
raise GLIMDA_Exception("atol must be of length one or same as the dimension of the problem.")
diff --git a/src/solvers/kinsol.pyx b/src/solvers/kinsol.pyx
index 709795e6..d37102dd 100644
--- a/src/solvers/kinsol.pyx
+++ b/src/solvers/kinsol.pyx
@@ -17,8 +17,8 @@
# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION
-import numpy as N
-cimport numpy as N
+import numpy as np
+cimport numpy as np
from assimulo.algebraic cimport Algebraic
@@ -66,7 +66,7 @@ cdef class KINSOL(Algebraic):
self.pData = ProblemDataEquationSolver()
- self._eps = N.finfo('double').eps
+ self._eps = np.finfo('double').eps
self._added_linear_solver = False
#Populate the ProblemData
@@ -76,11 +76,11 @@ cdef class KINSOL(Algebraic):
self.options["ftol"] = self._eps**(1.0/3.0)
self.options["stol"] = self._eps**(2.0/3.0)
self.options["strategy"] = KIN_LINESEARCH
- self.options["y_scale"] = N.array([1.0]*self.problem_info["dim"])
- self.options["f_scale"] = N.array([1.0]*self.problem_info["dim"])
- #self.options["y_nominal"] = N.array([1.0]*self.problem_info["dim"])
- #self.options["y_min"] = N.array([MIN_VALUE]*self.problem_info["dim"])
- #self.options["y_max"] = N.array([MAX_VALUE]*self.problem_info["dim"])
+ self.options["y_scale"] = np.array([1.0]*self.problem_info["dim"])
+ self.options["f_scale"] = np.array([1.0]*self.problem_info["dim"])
+ #self.options["y_nominal"] = np.array([1.0]*self.problem_info["dim"])
+ #self.options["y_min"] = np.array([MIN_VALUE]*self.problem_info["dim"])
+ #self.options["y_max"] = np.array([MAX_VALUE]*self.problem_info["dim"])
self.options["linear_solver"] = "DENSE"
self.options["max_iter"] = 200 #Maximum number of nonlinear iterations
self.options["no_initial_setup"] = False #Specifies wheter or not a call to the setup function should be made
@@ -138,7 +138,7 @@ cdef class KINSOL(Algebraic):
elif self.options["y_min"]:
self.options["y_scale"][i] = max(1.0, abs(self.options["y_min"][i]))
else:
- self.options["y_scale"] = N.array([value]) if isinstance(value, (float, int)) else N.array(value)
+ self.options["y_scale"] = np.array([value]) if isinstance(value, (float, int)) else np.array(value)
arr2nv_inplace(self.options["y_scale"], self.y_scale)
@@ -149,7 +149,7 @@ cdef class KINSOL(Algebraic):
if isinstance(value, str) and value.upper() == "AUTOMATIC":
pass
else:
- self.options["f_scale"] = N.array([value]) if isinstance(value, (float, int)) else N.array(value)
+ self.options["f_scale"] = np.array([value]) if isinstance(value, (float, int)) else np.array(value)
arr2nv_inplace(self.options["f_scale"], self.f_scale)
diff --git a/src/solvers/odepack.py b/src/solvers/odepack.py
index 44aad118..70d13d71 100644
--- a/src/solvers/odepack.py
+++ b/src/solvers/odepack.py
@@ -17,7 +17,7 @@
import sys
import logging
-import numpy as N
+import numpy as np
import scipy.linalg as Sc
import scipy.sparse as sp
@@ -40,7 +40,7 @@ def g_dummy(t,y):
return y
def jac_dummy(t,y):
- return N.zeros((len(y),len(y)))
+ return np.zeros((len(y),len(y)))
class LSODAR(Explicit_ODE):
"""
@@ -70,7 +70,7 @@ def __init__(self, problem):
Explicit_ODE.__init__(self, problem) #Calls the base class
#Default values
- self.options["atol"] = 1.0e-6*N.ones(self.problem_info["dim"]) #Absolute tolerance
+ self.options["atol"] = 1.0e-6*np.ones(self.problem_info["dim"]) #Absolute tolerance
self.options["rtol"] = 1.0e-6 #Relative tolerance
self.options["usejac"] = False
self.options["maxsteps"] = 100000
@@ -91,10 +91,10 @@ def __init__(self, problem):
self.supports["report_continuously"] = True
self.supports["interpolated_output"] = True
- self._RWORK = N.array([0.0]*(22 + self.problem_info["dim"] *
+ self._RWORK = np.array([0.0]*(22 + self.problem_info["dim"] *
max(16,self.problem_info["dim"]+9) +
3*self.problem_info["dimRoot"]))
- self._IWORK = N.array([0]*(20 + self.problem_info["dim"]))
+ self._IWORK = np.array([0]*(20 + self.problem_info["dim"]))
def initialize(self):
@@ -151,11 +151,11 @@ def autostart(self,t,y,sw0=[]):
t0=t
tf=RWORK[0]
T=abs(tf-t0)
- direction=N.sign(tf-t0)
+ direction=np.sign(tf-t0)
#Perturb initial condition and compute rough Lipschitz constant
cent=Sc.norm(y)/normscale/100.
- v0=y+cent*N.random.rand(len(y),1)
+ v0=y+cent*np.random.rand(len(y),1)
u0prime=f(t,y,sw0)
v0prime=f(t,v0,sw0)
Lip=Sc.norm(u0prime-v0prime)/Sc.norm(y-v0)
@@ -173,9 +173,9 @@ def autostart(self,t,y,sw0=[]):
#step 4: new estimate of Lipschitz constant
u0comprime=f(t0,u0comp,sw0)
L=Sc.norm(u0comprime-u0prime)/dunorm
- M=N.dot(du,u0comprime-u0prime)/dunorm**2
+ M=np.dot(du,u0comprime-u0prime)/dunorm**2
#step 5: construct a refined starting stepsize
- theta1=tolscale/N.sqrt(errnorm)
+ theta1=tolscale/np.sqrt(errnorm)
theta2=tolscale/abs(h*(L+M/2))
h=h*(theta1+theta2)/2
h=direction*min(3e-3*T,abs(h))
@@ -248,7 +248,7 @@ def integrate_start(self, t, y):
#RWORK[6]=dls001.hmin
#RWORK[5]=dls001.hmxi
- number_of_fevals=N.array([1,2,4,7,11])
+ number_of_fevals=np.array([1,2,4,7,11])
# d) Reset statistics
IWORK[9:13]=[0]*4
dls001.nst=1
@@ -285,7 +285,7 @@ def integrate(self, t, y, tf, opts):
ISTATE, RWORK, IWORK = self.integrate_start( t, y)
JT = 1 if self.usejac else 2#Jacobian type indicator
- JROOT = N.array([0]*self.problem_info["dimRoot"])
+ JROOT = np.array([0]*self.problem_info["dimRoot"])
#Setting work options
RWORK[0] = tf #Do not integrate past tf
@@ -311,7 +311,7 @@ def state_events(t,y):
else:
g_fcn = g_dummy
- #jac_dummy = (lambda t,y:N.zeros((len(y),len(y)))) if not self.usejac else self.problem.jac
+ #jac_dummy = (lambda t,y:np.zeros((len(y),len(y)))) if not self.usejac else self.problem.jac
jac_fcn = jac_dummy if not self.usejac else self._jacobian
#Extra args to rhs and state_events
@@ -332,7 +332,7 @@ def state_events(t,y):
#Tolerances:
atol = self.atol
- rtol = self.rtol*N.ones(self.problem_info["dim"])
+ rtol = self.rtol*np.ones(self.problem_info["dim"])
rhs = self.problem.rhs
#if normal_mode == 0:
@@ -486,10 +486,10 @@ def _get_usejac(self):
def _set_atol(self,atol):
- self.options["atol"] = N.array(atol,dtype=float) if len(N.array(atol,dtype=float).shape)>0 else N.array([atol],dtype=float)
+ self.options["atol"] = np.array(atol,dtype=float) if len(np.array(atol,dtype=float).shape)>0 else np.array([atol],dtype=float)
if len(self.options["atol"]) == 1:
- self.options["atol"] = self.options["atol"]*N.ones(self._leny)
+ self.options["atol"] = self.options["atol"]*np.ones(self._leny)
elif len(self.options["atol"]) != self._leny:
raise ODEPACK_Exception("atol must be of length one or same as the dimension of the problem.")
@@ -673,17 +673,17 @@ class RKStarterNordsieck(object):
See: Mohammadi (2013): https://lup.lub.lu.se/luur/download?func=downloadFile&recordOId=4196026&fileOId=4196027
"""
# Gamma matrix of Gear's RK starter which produce Nordsieck vector at t0
- Gamma_0=[N.array([[1.,0.], # 1st order
+ Gamma_0=[np.array([[1.,0.], # 1st order
[0.,1.]]),
- N.array([[1.,0.,0.], # 2nd order
+ np.array([[1.,0.,0.], # 2nd order
[0.,1.,-1.],
[0.,0.,1.]]),
- N.array([[1.,0.,0.,0.], # 3rd order
+ np.array([[1.,0.,0.,0.], # 3rd order
[0.,1.,-5./3.,1.],
[0.,0.,3.,-2.],
[0.,0.,0.,1.],
[0.,0.,-4./3.,0.]]),
- N.array([[1.,0.,0.,0.,0.], # 4th order
+ np.array([[1.,0.,0.,0.,0.], # 4th order
[0.,1.,-5./6.,4./9.,-1./9.],
[0.,0.,0.,0.,0.],
[0.,0.,1./2.,-4./9.,1./9.],
@@ -693,19 +693,19 @@ class RKStarterNordsieck(object):
# A matrices of RK starter with equidistanced states
- A_s=[ N.array([1]), # 1st order
- N.array([[0.,0],[1,0]]), # 2nd order
- N.array([[0.,0.,0.,0.,0.],[1./2,0.,0.,0.,0.], # 3rd order
+ A_s=[ np.array([1]), # 1st order
+ np.array([[0.,0],[1,0]]), # 2nd order
+ np.array([[0.,0.,0.,0.,0.],[1./2,0.,0.,0.,0.], # 3rd order
[0.,3./4,0.,0.,0.],[2./9,1./3,4./9,0.,0.],
[17./72,1./6,2./9,-1./8,0.]]),
- N.array([[0.,0.,0.,0.,0.,0.,0.], # 4th order
+ np.array([[0.,0.,0.,0.,0.,0.,0.], # 4th order
[1./6.,0.,0.,0.,0.,0.,0.],
[0.,1./6.,0.,0.,0.,0.,0.],
[0.,0.,1./3.,0.,0.,0.,0.],
[1./18.,1./9.,1./9.,1./18.,0.,0.,0.],
[2.5,-3.,-3.,2.25,2.25,0.,0.],
[10./45.,-8./45.,-8./45.,-4./45.,13./15.,1./45.,0.]]),
- N.array([[0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.], # 5th order
+ np.array([[0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.], # 5th order
[1./20,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.],
[3./160,9./160,0.,0.,0.,0.,0., 0.,0.,0.,0.,0.,0.,0.],
[3./40,-9./40,6./20,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.],
@@ -724,54 +724,54 @@ class RKStarterNordsieck(object):
38892959/120069679,11804845./141497517,0.]], dtype=object)]
co_ord_s=[[],[],[4],[4,6],[6,9,11]]
- b_s=[ N.array([1]),
- N.array([1./2,1./2]),
- N.array([1./6,0.,0.,1./6,2./3]),
- N.array([29./1062.,83./531.,83./531.,83./1062.,2./531.,56./531.,251./531.]), # b-vectors of of 1st to 5th order RK starter method
- N.array([0.03877310906055409,0.,3021245/89251943,5956469/58978530,851373/32201684,11559106/149527791,11325471/112382620,0.,-12983/235976962,17692261/82454251,0.,
+ b_s=[ np.array([1]),
+ np.array([1./2,1./2]),
+ np.array([1./6,0.,0.,1./6,2./3]),
+ np.array([29./1062.,83./531.,83./531.,83./1062.,2./531.,56./531.,251./531.]), # b-vectors of of 1st to 5th order RK starter method
+ np.array([0.03877310906055409,0.,3021245/89251943,5956469/58978530,851373/32201684,11559106/149527791,11325471/112382620,0.,-12983/235976962,17692261/82454251,0.,
38892959/120069679,11804845./141497517,0.])]
- C_s=[ N.array([0.]),
- N.array([0.]),
- N.array([0.,1./2,3./4,1.,1./2,1.]),
- N.array([0.,1./6,1./6,1./3,1./3,1.,1.,2./3,1.]),
- N.array([0.,1./20,3./40,3./20,1./4,7./28,1./4,2./4,1.,2./4,3./4,3./4,1.,1.])] # C-values in Butcher tableau of 8-stages Runge-Kutta
+ C_s=[ np.array([0.]),
+ np.array([0.]),
+ np.array([0.,1./2,3./4,1.,1./2,1.]),
+ np.array([0.,1./6,1./6,1./3,1./3,1.,1.,2./3,1.]),
+ np.array([0.,1./20,3./40,3./20,1./4,7./28,1./4,2./4,1.,2./4,3./4,3./4,1.,1.])] # C-values in Butcher tableau of 8-stages Runge-Kutta
# A matrices of RK starter with non-equidistanced stages
- A_n=[ N.array([1]),
- N.array([[0.,0.],[0.,0.]]),
- N.array([[0.,0.,0.,0.],[1./2,0.,0.,0.],[0.,1./2,0.,0.],[0.,0.,1.,0.]]), # 3rd order
- N.array([[0.,0.,0.,0.,0.,0.],[2./5,0.,0.,0.,0.,0.],[-3./20,3./4,0.,0.,0.,0.], # 4th order
+ A_n=[ np.array([1]),
+ np.array([[0.,0.],[0.,0.]]),
+ np.array([[0.,0.,0.,0.],[1./2,0.,0.,0.],[0.,1./2,0.,0.],[0.,0.,1.,0.]]), # 3rd order
+ np.array([[0.,0.,0.,0.,0.,0.],[2./5,0.,0.,0.,0.,0.],[-3./20,3./4,0.,0.,0.,0.], # 4th order
[19./44,-15./44,40./44,0.,0.,0.],[-31./64,185./192,5./64,-11./192,0.,0.],[11./72,25./72,25./72,11./72,0.,0.]])]
- b_n=[ N.array([0.]),
- N.array([1./2.,1./2.]),
- N.array([[5./24,1./6,1./6,-1/24],[1./6,1./3,1./3,1./6]]),
- N.array([[802./5625,68./225,-67./225,-143./5625,144./625,6./125],[699./5000,81./200,-39./200,99./5000,144./625,0.],[11./72,25./72,25./72,11./72,0.,0.]])]
+ b_n=[ np.array([0.]),
+ np.array([1./2.,1./2.]),
+ np.array([[5./24,1./6,1./6,-1/24],[1./6,1./3,1./3,1./6]]),
+ np.array([[802./5625,68./225,-67./225,-143./5625,144./625,6./125],[699./5000,81./200,-39./200,99./5000,144./625,0.],[11./72,25./72,25./72,11./72,0.,0.]])]
- C_n=[ N.array([0.]),
- N.array([0.]),
- N.array([0.,1./2,1./2,1.]),
- N.array([0.,2./5,3./5,1.,1./2,1.])]
+ C_n=[ np.array([0.]),
+ np.array([0.]),
+ np.array([0.,1./2,1./2,1.]),
+ np.array([0.,2./5,3./5,1.,1./2,1.])]
#co_ord_n=[[],[],[1./2,1.],[2./5,3./5,1.]]
- #A=N.array([[1.,0.,0.,0.],
+ #A=np.array([[1.,0.,0.,0.],
# [1.,1./9.,1./27,1./81.],
# [1.,4./9.,8./27,16./81.],
# [1.,1.,1.,1.]])
- A=[N.array([0.]), # Convert the state values to Nordsieck vector
- N.array([0.]),
- N.array([1.]),
- N.array([[1./4,1./8],[1.,1.]]),
- N.array([[1./9,1./27,1./81.],
+ A=[np.array([0.]), # Convert the state values to Nordsieck vector
+ np.array([0.]),
+ np.array([1.]),
+ np.array([[1./4,1./8],[1.,1.]]),
+ np.array([[1./9,1./27,1./81.],
[4./9.,8./27,16./81],
[1.,1.,1.]]),
- N.array([[1./16,1./64,1./256,1./1024],
+ np.array([[1./16,1./64,1./256,1./1024],
[1./4,1./8,1./16,1./32],
[9./16,27./64,81./256,243./1024],
[1.,1.,1.,1.]])]
- scale=N.array([1, 1, 1/2., 1./6., 1./24., 1./120.]).reshape(-1,1)
+ scale=np.array([1, 1, 1/2., 1./6., 1./24., 1./120.]).reshape(-1,1)
def __init__(self, rhs, H, method='RKs_f', eval_at=0., number_of_steps=4):
@@ -818,16 +818,16 @@ def RKs_f(self,t0,y0,sw0):
b_s=b_s[s-1]
co_ord_s=co_ord_s[s-1]
H=(s-1)*self.H
- K=N.zeros((N.size(A_s,0),len(y0)))
- for i in range(N.size(A_s,0)):
- K[i,:]=self.f(t0+C_s[i]*H,y0+H*N.dot(A_s[i,:],K),sw0)
- y=N.zeros((s,len(y0)))
+ K=np.zeros((np.size(A_s,0),len(y0)))
+ for i in range(np.size(A_s,0)):
+ K[i,:]=self.f(t0+C_s[i]*H,y0+H*np.dot(A_s[i,:],K),sw0)
+ y=np.zeros((s,len(y0)))
y[0,:]=y0
for i in range(1,s):
if i==s-1:
- y[i,:]=y0+H*N.dot(b_s,K)
+ y[i,:]=y0+H*np.dot(b_s,K)
else:
- y[i,:]=y0+H*N.dot(A_s[co_ord_s[i-1],:],K)
+ y[i,:]=y0+H*np.dot(A_s[co_ord_s[i-1],:],K)
return y
def RKn_f(self,t0,y0,sw0):
s=self.number_of_steps
@@ -837,13 +837,13 @@ def RKn_f(self,t0,y0,sw0):
C_n=C_n[s-1]
b_n=b_n[s-1]
- K=N.zeros((N.size(A_n,0),len(y0)))
- for i in range(N.size(A_n,0)):
- K[i,:]=self.f(t0+C_n[i]*H,y0+H*N.dot(A_n[i,:],K),sw0)
- y=N.zeros((s,len(y0)))
+ K=np.zeros((np.size(A_n,0),len(y0)))
+ for i in range(np.size(A_n,0)):
+ K[i,:]=self.f(t0+C_n[i]*H,y0+H*np.dot(A_n[i,:],K),sw0)
+ y=np.zeros((s,len(y0)))
y[0,:]=y0
for i in range(1,s):
- y[i,:]=y0+H*N.dot(b_n[i-1],K)
+ y[i,:]=y0+H*np.dot(b_n[i-1],K)
return y
@@ -861,7 +861,7 @@ def rk_like4(self, t0, y0, sw0):
k4 = h*f(y0 + 3./4. * k1 + 9./4. * k3)
k5 = h*f(y0 + k1/2. + k2 + k3/2. + 2. * k4)
k6 = h*f(y0+k1/12.+2. * k2 + k3/4. + 2./3. * k4 + 2. * k5)
- return N.array([y0,k1,k2,k3,k4,k5,k6])
+ return np.array([y0,k1,k2,k3,k4,k5,k6])
def rk_like3(self, t0, y0, sw0):
"""
rk_like computes Runge-Kutta stages
@@ -875,7 +875,7 @@ def rk_like3(self, t0, y0, sw0):
k2 = h*f(y0 + k1)
k3 = h*f(y0 + k1+ k2)
k4 = h*f(y0 + 3./2. * k1)
- return N.array([y0,k1,k2,k3,k4])
+ return np.array([y0,k1,k2,k3,k4])
def rk_like2(self, t0, y0, sw0):
"""
rk_like2 computes Runge-Kutta 2nd-stages
@@ -886,7 +886,7 @@ def rk_like2(self, t0, y0, sw0):
h=self.H/2.
k1=h*f(y0)
k2=h*f(y0+k1)
- return N.array([y0,k1,k2])
+ return np.array([y0,k1,k2])
def rk_like13(self, t0, y0, sw0):
"""
rk_like6 computes Runge-Kutta 8th-stages
@@ -894,15 +894,15 @@ def rk_like13(self, t0, y0, sw0):
h = self.H
self.Gamma_2=self.Gamma_0[3]
f=lambda y: self.f(t0 , y , sw0)
- K=N.zeros((6,len(y0)))
- sol=N.zeros((3,len(y0)))
- b=N.zeros((2,len(y0))) #remove the fifth stage value that is for error estimation
- nord = N.zeros((4,len(y0))) #Nordsieck vector
+ K=np.zeros((6,len(y0)))
+ sol=np.zeros((3,len(y0)))
+ b=np.zeros((2,len(y0))) #remove the fifth stage value that is for error estimation
+ nord = np.zeros((4,len(y0))) #Nordsieck vector
for i in range(5):
- K[i,:]= f(y0+h*N.dot(self.Gamma_2[i,:],K))
+ K[i,:]= f(y0+h*np.dot(self.Gamma_2[i,:],K))
c=0
for i in range(3):
- sol[i,:]=y0+h*N.dot(self.Gamma_2[i+3,:],K)
+ sol[i,:]=y0+h*np.dot(self.Gamma_2[i+3,:],K)
if i!=0:
b[c,:]=sol[i,:]-y0-(c+1)*h/2*K[0,:]
c+=1
@@ -917,15 +917,15 @@ def rk_like14(self, t0, y0, sw0):
h = self.H
Gamma_2=self.Gamma_0[4]
f=lambda y: self.f(t0 , y , sw0)
- K=N.zeros((8,len(y0)))
- sol=N.zeros((4,len(y0)))
- b=N.zeros((3,len(y0))) #remove the fifth stage value that is for error estimation
- nord = N.zeros((5,len(y0))) #Nordsieck vector
+ K=np.zeros((8,len(y0)))
+ sol=np.zeros((4,len(y0)))
+ b=np.zeros((3,len(y0))) #remove the fifth stage value that is for error estimation
+ nord = np.zeros((5,len(y0))) #Nordsieck vector
for i in range(7):
- K[i,:]= f(y0+h*N.dot(Gamma_2[i,:],K))
+ K[i,:]= f(y0+h*np.dot(Gamma_2[i,:],K))
c=0
for i in range(4):
- sol[i,:]=y0+h*N.dot(Gamma_2[i+4,:],K)
+ sol[i,:]=y0+h*np.dot(Gamma_2[i+4,:],K)
if i!=1:
b[c,:]=sol[i,:]-y0-(c+1)*h/3*K[0,:]
c+=1
@@ -940,15 +940,15 @@ def rk_like15(self, t0, y0, sw0):
h = self.H
Gamma_2=self.Gamma_0[5]
f=lambda y: self.f(t0 , y , sw0)
- K=N.zeros((14,len(y0)))
- sol=N.zeros((8,len(y0)))
- b=N.zeros((4,len(y0))) #remove the fifth stage value that is for error estimation
- nord = N.zeros((6,len(y0))) #Nordsieck vector
+ K=np.zeros((14,len(y0)))
+ sol=np.zeros((8,len(y0)))
+ b=np.zeros((4,len(y0))) #remove the fifth stage value that is for error estimation
+ nord = np.zeros((6,len(y0))) #Nordsieck vector
for i in range(13):
- K[i,:]= f(y0+h*N.dot(Gamma_2[i,:],K))
+ K[i,:]= f(y0+h*np.dot(Gamma_2[i,:],K))
c=0
for i in range(8):
- sol[i,:]=y0+h*N.dot(Gamma_2[i+6,:],K)
+ sol[i,:]=y0+h*np.dot(Gamma_2[i+6,:],K)
if (i!=1) and (i!=2) and (i!=4) and (i!=6):
b[c,:]=sol[i,:]-y0-(c+1)*h/4*K[0,:]
c+=1
@@ -960,42 +960,42 @@ def nordsieck(self,k):
"""
Nordsieck array computed at initial point
"""
- nord=self.scale[:self.number_of_steps+1]*N.dot(self.Gamma_0[self.number_of_steps-1].T,k)
+ nord=self.scale[:self.number_of_steps+1]*np.dot(self.Gamma_0[self.number_of_steps-1].T,k)
return nord
def Nordsieck_RKn(self,t0,y,sw0):
s=self.number_of_steps
H=(s-1)*self.H
- co_nord=[N.array([1./2,1.]),N.array([2./5,3./5,1.])]
- l=N.size(y,0)
+ co_nord=[np.array([1./2,1.]),np.array([2./5,3./5,1.])]
+ l=np.size(y,0)
y0=y[0,:]
yf=self.f(t0,y0,sw0)
if l==3:
- co=N.array([co_nord[0]])
- nord_n=N.vander(co_nord[0],self.number_of_steps+1)
+ co=np.array([co_nord[0]])
+ nord_n=np.vander(co_nord[0],self.number_of_steps+1)
b=y[1:]-y0-co.T*yf
nord=Sc.solve(nord_n[0:2,0:2],b)
elif l==4:
- co=N.array([co_nord[1]])
- nord_n=N.vander(co_nord[1],self.number_of_steps+1)
+ co=np.array([co_nord[1]])
+ nord_n=np.vander(co_nord[1],self.number_of_steps+1)
b=y[1:]-y0-H*co.T*yf
nord=Sc.solve(nord_n[0:3,0:3],b)
- nord=N.vstack((y0,H*yf,nord[::-1]))
+ nord=np.vstack((y0,H*yf,nord[::-1]))
return nord
def Nordsieck_RKs(self,t0,y,sw0):
s=self.number_of_steps
H=(s-1)*self.H
- co_nord=[N.array([1]),N.array([1./2,1]),N.array([1./3,2./3,1]),
- N.array([1./4,2./4,3./4,1.])]
+ co_nord=[np.array([1]),np.array([1./2,1]),np.array([1./3,2./3,1]),
+ np.array([1./4,2./4,3./4,1.])]
A=self.A
y0=y[0,:]
yf=self.f(t0,y0,sw0)
co=co_nord[s-2]
- co=N.array([co])
+ co=np.array([co])
b=y[1:]-y0-H*co.T*yf
nord=Sc.solve(A[s],b)
- nord=N.vstack((y0,H*yf,nord))
+ nord=np.vstack((y0,H*yf,nord))
return nord
diff --git a/src/solvers/radar5.py b/src/solvers/radar5.py
index 6ded7715..b676bd1a 100644
--- a/src/solvers/radar5.py
+++ b/src/solvers/radar5.py
@@ -16,7 +16,7 @@
# along with this program. If not, see .
import sys
-import numpy as N
+import numpy as np
import pylab as P
from assimulo.ode import NORMAL, ID_PY_COMPLETE, ID_PY_EVENT
@@ -57,9 +57,9 @@ def __init__(self, problem):
self.options["quot2"] = 1.2 #Parameters for changing step-size (upper bound)
self.options["fac1"] = 0.2 #Parameters for step-size selection (lower bound)
self.options["fac2"] = 8.0 #Parameters for step-size selection (upper bound)
- self.options["maxh"] = N.inf #Maximum step-size.
+ self.options["maxh"] = np.inf #Maximum step-size.
self.options["safe"] = 0.9 #Safety factor
- self.options["atol"] = 1.0e-6*N.ones(self.problem_info["dim"]) #Absolute tolerance
+ self.options["atol"] = 1.0e-6*np.ones(self.problem_info["dim"]) #Absolute tolerance
self.options["rtol"] = 1.0e-6 #Relative tolerance
self.options["usejac"] = True if self.problem_info["jac_fcn"] else False
self.options["maxsteps"] = 10000
@@ -70,7 +70,7 @@ def __init__(self, problem):
self.options["mxst"] = 100 # The maximum number of stored dense output points
self.options["usejaclag"] = True if self.problem_info["jaclag_fcn"] else False
- SQ6 = N.sqrt(6.0)
+ SQ6 = np.sqrt(6.0)
C1 = (4.0-SQ6)/10.0
C2 = (4.0+SQ6)/10.0
self.C1M1 = C1-1.0
@@ -96,9 +96,9 @@ def __init__(self, problem):
flat_lagcompmap = []
for comp in self.problem.lagcompmap:
flat_lagcompmap.extend(comp)
- self._nrdens = len(N.unique(flat_lagcompmap))
- self._ipast = N.unique(flat_lagcompmap).tolist()+[0]
- self._grid = N.array([])
+ self._nrdens = len(np.unique(flat_lagcompmap))
+ self._ipast = np.unique(flat_lagcompmap).tolist()+[0]
+ self._grid = np.array([])
# if hasattr(problem, 'pbar'):
@@ -127,7 +127,7 @@ def _solout(self,nr, told, t, hold, y, cont,irtrn):
while output_list[output_index] <= t:
self._tlist.append(output_list[output_index])
- yval = N.empty(self._leny)
+ yval = np.empty(self._leny)
for i in range(self._leny):
# yval[i] = radar5.contr5(i+1,self.problem_info["dim"],output_list[output_index],t,hold)
yval[i] = radar5.contr5(i+1,self.problem_info["dim"],output_list[output_index],cont,t,hold)
@@ -144,7 +144,7 @@ def _solout(self,nr, told, t, hold, y, cont,irtrn):
#def coutput(self,t):
#Nx = self.problem_info["dim"]
- #y = N.zeros(Nx)
+ #y = np.zeros(Nx)
#theta, pos = radar5.lagr5(10, t, None, self.arglag, self.past, self.problem.phi, self.problem.ipast)
#for i in range(1,Nx+1):
@@ -159,11 +159,11 @@ def coutput(self, t, i = -1):
i: solution component (default -1 gives the whole vector)
"""
Nx = self.problem_info["dim"]
- y = N.zeros(Nx)
+ y = np.zeros(Nx)
# t belongs to the interval (tk[ik], tk[ik+1])
- ik = N.searchsorted(self.tk, t) - 1
+ ik = np.searchsorted(self.tk, t) - 1
I = self.idif*ik
@@ -175,7 +175,7 @@ def coutput(self, t, i = -1):
# The line below this comment is what's effectively happening,
# but it is unfortunately extremely slow compared to the
# vectorized version below that doesn't use the cpoly function:
- #return N.array([self.cpoly(i, I, theta) for i in range(self.problem_info["dim"])])
+ #return np.array([self.cpoly(i, I, theta) for i in range(self.problem_info["dim"])])
nrds = self._nrdens
I = I + 1
I2 = I + self.problem_info["dim"]
@@ -233,11 +233,11 @@ def integrate(self, t, y, tf, opts):
MLMAS = self.problem_info["dim"] #The mass matrix is full
MUMAS = self.problem_info["dim"] #See MLMAS
IOUT = 1 #solout is called after every step
- WORK = N.array([0.0]*30) #Work (double) vector
- IWORK = N.array([0]*30) #Work (integer) vector
+ WORK = np.array([0.0]*30) #Work (double) vector
+ IWORK = np.array([0]*30) #Work (integer) vector
#Setting work options
- WORK[0] = N.finfo(N.double).eps # Rounding unit
+ WORK[0] = np.finfo(np.double).eps # Rounding unit
WORK[1] = self.safe
WORK[2] = self.thet
WORK[3] = self.fnewt
@@ -261,9 +261,9 @@ def integrate(self, t, y, tf, opts):
self.idif = 4*self._nrdens + 2
lrpast = self.mxst*self.idif
- past = N.zeros(lrpast)
+ past = np.zeros(lrpast)
- #past = N.zeros(self.mxst*(4*self.problem.nrdens+2))
+ #past = np.zeros(self.mxst*(4*self.problem.nrdens+2))
# print WORK
# print IWORK
@@ -284,7 +284,7 @@ def integrate(self, t, y, tf, opts):
y.copy(), \
tf, \
self.inith, \
- self.rtol*N.ones(self.problem_info["dim"]), \
+ self.rtol*np.ones(self.problem_info["dim"]), \
self.atol, \
ITOL, \
jac_dummy, \
@@ -315,8 +315,8 @@ def integrate(self, t, y, tf, opts):
t, y, h, iwork, flag, past = a[0]
#self.past = copy.deepcopy(past)
self.past = past
- self.tk = N.trim_zeros(self.past[::self.idif], 'b')
- self.hk = N.trim_zeros(self.past[self.idif-1:-1:self.idif], 'b')
+ self.tk = np.trim_zeros(self.past[::self.idif], 'b')
+ self.hk = np.trim_zeros(self.past[self.idif-1:-1:self.idif], 'b')
#Checking return
if flag == 1:
@@ -374,7 +374,7 @@ def plot_stepsize(self):
"""
Plots the step-size.
"""
- P.semilogy(N.diff(self.t),drawstyle='steps-post')
+ P.semilogy(np.diff(self.t),drawstyle='steps-post')
P.title(self.problem.name)
P.ylabel('Step length')
P.xlabel('Number of steps')
@@ -677,10 +677,10 @@ def _get_usejaclag(self):
def _set_atol(self,atol):
- self.options["atol"] = N.array(atol,dtype=float) if len(N.array(atol,dtype=float).shape)>0 else N.array([atol],dtype=float)
+ self.options["atol"] = np.array(atol,dtype=float) if len(np.array(atol,dtype=float).shape)>0 else np.array([atol],dtype=float)
if len(self.options["atol"]) == 1:
- self.options["atol"] = self.options["atol"]*N.ones(self._leny)
+ self.options["atol"] = self.options["atol"]*np.ones(self._leny)
elif len(self.options["atol"]) != self._leny:
raise Radar_Exception("atol must be of length one or same as the dimension of the problem.")
diff --git a/src/solvers/radau5.py b/src/solvers/radau5.py
index 4a105604..6b368b10 100644
--- a/src/solvers/radau5.py
+++ b/src/solvers/radau5.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import numpy as N
+import numpy as np
import scipy as S
import scipy.sparse as sp
@@ -106,7 +106,7 @@ def __init__(self, problem):
self.options["fac2"] = 8.0 #Parameters for step-size selection (upper bound)
self.options["maxh"] = None #Maximum step-size.
self.options["safe"] = 0.9 #Safety factor
- self.options["atol"] = 1.0e-6*N.ones(self.problem_info["dim"]) #Absolute tolerance
+ self.options["atol"] = 1.0e-6*np.ones(self.problem_info["dim"]) #Absolute tolerance
self.options["rtol"] = 1.0e-6 #Relative tolerance
self.options["usejac"] = True if self.problem_info["jac_fcn"] else False
self.options["maxsteps"] = 100000
@@ -120,7 +120,7 @@ def __init__(self, problem):
self._leny = len(self.y) #Dimension of the problem
self._type = '(explicit)'
self._event_info = None
- self._werr = N.zeros(self._leny)
+ self._werr = np.zeros(self._leny)
def _get_linear_solver(self):
return self.options["linear_solver"]
@@ -245,7 +245,7 @@ def f(t, y):
return rhs, [ret]
except BaseException as E:
rhs = y.copy()
- if isinstance(E, (N.linalg.LinAlgError, ZeroDivisionError, AssimuloRecoverableError)): ## recoverable
+ if isinstance(E, (np.linalg.LinAlgError, ZeroDivisionError, AssimuloRecoverableError)): ## recoverable
ret = 1 #Recoverable error
else:
self._py_err = E
@@ -255,7 +255,7 @@ def f(t, y):
self.event_func = event_func
self._event_info = [0] * self.problem_info["dimRoot"]
ret, self.g_old = self.event_func(self.t, self.y)
- self.g_old = N.array(self.g_old)
+ self.g_old = np.array(self.g_old)
if ret < 0:
raise self._py_err
self.statistics["nstatefcns"] += 1
@@ -266,7 +266,7 @@ def f(t, y):
rhs = self.problem.rhs(t, y)
except BaseException as E:
rhs = y.copy()
- if isinstance(E, (N.linalg.LinAlgError, ZeroDivisionError, AssimuloRecoverableError)): ## recoverable
+ if isinstance(E, (np.linalg.LinAlgError, ZeroDivisionError, AssimuloRecoverableError)): ## recoverable
ret = 1 #Recoverable error
else:
self._py_err = E
@@ -275,7 +275,7 @@ def f(t, y):
self.f = f
def interpolate(self, time):
- y = N.empty(self._leny)
+ y = np.empty(self._leny)
self.rad_memory.interpolate(time, y)
return y
@@ -283,7 +283,7 @@ def get_weighted_local_errors(self):
"""
Returns the vector of weighted estimated local errors at the current step.
"""
- return N.abs(self._werr)
+ return np.abs(self._werr)
def _solout(self, nrsol, told, t, y, werr):
"""
@@ -342,8 +342,8 @@ def _jacobian(self, t, y):
if isinstance(jac, sp.csc_matrix) and (self.options["linear_solver"] == "DENSE"):
jac = jac.toarray()
except BaseException as E:
- jac = N.eye(len(y))
- if isinstance(E, (N.linalg.LinAlgError, ZeroDivisionError, AssimuloRecoverableError)): ## recoverable
+ jac = np.eye(len(y))
+ if isinstance(E, (np.linalg.LinAlgError, ZeroDivisionError, AssimuloRecoverableError)): ## recoverable
ret = 1 #Recoverable error
else:
self._py_err = E
@@ -369,7 +369,7 @@ def integrate(self, t, y, tf, opts):
self._py_err = None ## reset
self._opts = opts
self.rad_memory.reinit()
- t, y, flag = self.radau5.radau5_py_solve(self.f, t, y.copy(), tf, self.inith, self.rtol*N.ones(self.problem_info["dim"]), self.atol,
+ t, y, flag = self.radau5.radau5_py_solve(self.f, t, y.copy(), tf, self.inith, self.rtol*np.ones(self.problem_info["dim"]), self.atol,
jac_dummy, IJAC, self._solout, IOUT, self.rad_memory)
#Retrieving statistics
@@ -459,7 +459,7 @@ def __init__(self, problem):
self.options["quot2"] = 1.2 #Parameters for changing step-size (upper bound)
self.options["fac1"] = 0.2 #Parameters for step-size selection (lower bound)
self.options["fac2"] = 8.0 #Parameters for step-size selection (upper bound)
- self.options["maxh"] = N.inf #Maximum step-size.
+ self.options["maxh"] = np.inf #Maximum step-size.
self.options["safe"] = 0.9 #Safety factor
self.options["atol"] = 1.0e-6 #Absolute tolerance
self.options["rtol"] = 1.0e-6 #Relative tolerance
@@ -476,8 +476,8 @@ def __init__(self, problem):
self._leny = len(self.y) #Dimension of the problem
self._oldh = 0.0 #Old stepsize
self._olderr = 1.0 #Old error
- self._eps = N.finfo('double').eps
- self._col_poly = N.zeros(self._leny*3)
+ self._eps = np.finfo('double').eps
+ self._col_poly = np.zeros(self._leny*3)
self._type = '(explicit)'
self._curiter = 0 #Number of current iterations
@@ -485,10 +485,10 @@ def __init__(self, problem):
self.f = problem.rhs_internal
#Internal temporary result vector
- self.Y1 = N.array([0.0]*len(self.y0))
- self.Y2 = N.array([0.0]*len(self.y0))
- self.Y3 = N.array([0.0]*len(self.y0))
- self._f0 = N.array([0.0]*len(self.y0))
+ self.Y1 = np.array([0.0]*len(self.y0))
+ self.Y2 = np.array([0.0]*len(self.y0))
+ self.Y3 = np.array([0.0]*len(self.y0))
+ self._f0 = np.array([0.0]*len(self.y0))
#Solver support
self.supports["one_step_mode"] = True
@@ -523,8 +523,8 @@ def step_generator(self, t, y, tf, opts):
self._tc = t
self._yc = y
- if self.h > N.abs(tf-t):
- self.h = N.abs(tf-t)
+ if self.h > np.abs(tf-t):
+ self.h = np.abs(tf-t)
if t < tf:
yield ID_PY_OK, t, y
@@ -576,7 +576,7 @@ def _step(self, t, y):
"""
This calculates the next step in the integration.
"""
- self._scaling = N.array(abs(y)*self.rtol + self.atol) #The scaling used.
+ self._scaling = np.array(abs(y)*self.rtol + self.atol) #The scaling used.
while True: #Loop for integrating one step.
@@ -663,15 +663,15 @@ def _radau_F(self, Z, t, y):
self.statistics["nfcns"] += 3
- return N.hstack((N.hstack((self.Y1,self.Y2)),self.Y3))
+ return np.hstack((np.hstack((self.Y1,self.Y2)),self.Y3))
def calc_start_values(self):
"""
Calculate newton starting values.
"""
if self._first:
- Z = N.zeros(self._leny*3)
- W = N.zeros(self._leny*3)
+ Z = np.zeros(self._leny*3)
+ W = np.zeros(self._leny*3)
else:
Z = self._Z
cq = self.C*self.h/self._oldh#self._oldoldh#self._oldh
@@ -682,7 +682,7 @@ def calc_start_values(self):
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]))
- W = N.dot(self.T2,Z)
+ W = np.dot(self.T2,Z)
return Z, W
@@ -713,7 +713,7 @@ def newton(self,t,y):
self._needLU = False
- if min(abs(N.diag(self._U1))) 0:
thq = newnrm/oldnrm
if i == 1:
self._theta = thq
else:
- self._theta = N.sqrt(thq*thqold)
+ self._theta = np.sqrt(thq*thqold)
thqold = thq
if self._theta < 0.99: #Convergence
@@ -760,10 +760,10 @@ def newton(self,t,y):
oldnrm = max(newnrm,self._eps) #Store oldnorm
W = W+Z #Perform the iteration
- Z = N.dot(self.T3,W) #Calculate the new Z values
+ Z = np.dot(self.T3,W) #Calculate the new Z values
if self._fac_con*newnrm <= self.fnewt: #Convergence?
- self._itfail = False;
+ self._itfail = False
break
else: #Iteration failed
@@ -828,17 +828,17 @@ def estimate_error(self):
temp = 1./self.h*(self.E[0]*self._Z[:self._leny]+self.E[1]*self._Z[self._leny:2*self._leny]+self.E[2]*self._Z[2*self._leny:3*self._leny])
scal = self._scaling#/self.h
- err_v = N.linalg.solve(self._U1,N.linalg.solve(self._L1,N.linalg.solve(self._P1,self._f0+temp)))
- err = N.linalg.norm(err_v/scal)
- err = max(err/N.sqrt(self._leny),1.e-10)
+ err_v = np.linalg.solve(self._U1,np.linalg.solve(self._L1,np.linalg.solve(self._P1,self._f0+temp)))
+ err = np.linalg.norm(err_v/scal)
+ err = max(err/np.sqrt(self._leny),1.e-10)
if (self._rejected or self._first) and err >= 1.: #If the step was rejected, use the more expensive error estimation
self.statistics["nfcns"] += 1
- err_new = N.array([0.0]*self._leny)
+ err_new = np.array([0.0]*self._leny)
self.f(err_new,self._tc,self._yc+err_v)
- err_v = N.linalg.solve(self._U1,N.linalg.solve(self._L1,N.linalg.solve(self._P1,err_new+temp)))
- err = N.linalg.norm(err_v/scal)
- err = max(err/N.sqrt(self._leny),1.e-10)
+ err_v = np.linalg.solve(self._U1,np.linalg.solve(self._L1,np.linalg.solve(self._P1,err_new+temp)))
+ err = np.linalg.norm(err_v/scal)
+ err = max(err/np.sqrt(self._leny),1.e-10)
return err
@@ -854,10 +854,10 @@ def jacobian(self, t, y):
if self.usejac: #Retrieve the user-defined jacobian
cjac = self.problem.jac(t,y)
else: #Calculate a numeric jacobian
- delt = N.array([(self._eps*max(abs(yi),1.e-5))**0.5 for yi in y])*N.identity(self._leny) #Calculate a disturbance
- Fdelt = N.array([self.problem.rhs(t,y+e) for e in delt]) #Add the disturbance (row by row)
+ delt = np.array([(self._eps*max(abs(yi),1.e-5))**0.5 for yi in y])*np.identity(self._leny) #Calculate a disturbance
+ Fdelt = np.array([self.problem.rhs(t,y+e) for e in delt]) #Add the disturbance (row by row)
grad = ((Fdelt-self.problem.rhs(t,y)).T/delt.diagonal()).T
- cjac = N.array(grad).T
+ cjac = np.array(grad).T
self.statistics["nfcnjacs"] += 1+self._leny #Add the number of function evaluations
@@ -878,37 +878,37 @@ def interpolate(self, t, k=0):
def _load_parameters(self):
#Parameters
- A = N.zeros([3,3])
- A[0,0] = (88.-7.*N.sqrt(6.))/360.0
- A[0,1] = (296.-169.*N.sqrt(6.))/1800.0
- A[0,2] = (-2.0+3.0*N.sqrt(6.))/225.0
- A[1,0] = (296.0+169.0*N.sqrt(6.))/1800.0
- A[1,1] = (88.+7.*N.sqrt(6.))/360.0
- A[1,2] = (-2.-3.*N.sqrt(6.))/225.0
- A[2,0] = (16.0-N.sqrt(6.))/36.0
- A[2,1] = (16.0+N.sqrt(6.))/36.0
+ A = np.zeros([3,3])
+ A[0,0] = (88.-7.*np.sqrt(6.))/360.0
+ A[0,1] = (296.-169.*np.sqrt(6.))/1800.0
+ A[0,2] = (-2.0+3.0*np.sqrt(6.))/225.0
+ A[1,0] = (296.0+169.0*np.sqrt(6.))/1800.0
+ A[1,1] = (88.+7.*np.sqrt(6.))/360.0
+ A[1,2] = (-2.-3.*np.sqrt(6.))/225.0
+ A[2,0] = (16.0-np.sqrt(6.))/36.0
+ A[2,1] = (16.0+np.sqrt(6.))/36.0
A[2,2] = (1.0/9.0)
- C = N.zeros([3,1])
- C[0,0]=(4.0-N.sqrt(6.0))/10.0
- C[1,0]=(4.0+N.sqrt(6.0))/10.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
- B = N.zeros([1,3])
- B[0,0]=(16.0-N.sqrt(6.0))/36.0
- B[0,1]=(16.0+N.sqrt(6.0))/36.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
- E = N.zeros(3)
- E[0] = -13.0-7.*N.sqrt(6.)
- E[1] = -13.0+7.0*N.sqrt(6.)
+ E = np.zeros(3)
+ E[0] = -13.0-7.*np.sqrt(6.)
+ E[1] = -13.0+7.0*np.sqrt(6.)
E[2] = -1.0
E = 1.0/3.0*E
- Ainv = N.linalg.inv(A)
- [eig, T] = N.linalg.eig(Ainv)
- eig = N.array([eig[2],eig[0],eig[1]])
- J = N.diag(eig)
+ Ainv = np.linalg.inv(A)
+ [eig, T] = np.linalg.eig(Ainv)
+ eig = np.array([eig[2],eig[0],eig[1]])
+ J = np.diag(eig)
self._alpha = eig[1]
self._beta = eig[2]
@@ -920,13 +920,13 @@ def _load_parameters(self):
T[:,0] = temp2
T[:,1] = temp0
T[:,2] = temp1
- Tinv = N.linalg.inv(T)
+ Tinv = np.linalg.inv(T)
- I = N.eye(self._leny)
- I3 = N.eye(3)
- T1 = N.kron(J,I)
- T2 = N.kron(Tinv,I)
- T3 = N.kron(T,I)
+ I = np.eye(self._leny)
+ I3 = np.eye(3)
+ T1 = np.kron(J,I)
+ T2 = np.kron(Tinv,I)
+ T3 = np.kron(T,I)
self.A = A
self.B = B
@@ -977,9 +977,9 @@ def __init__(self, problem):
self.options["quot2"] = 1.2 #Parameters for changing step-size (upper bound)
self.options["fac1"] = 0.2 #Parameters for step-size selection (lower bound)
self.options["fac2"] = 8.0 #Parameters for step-size selection (upper bound)
- self.options["maxh"] = N.inf #Maximum step-size.
+ self.options["maxh"] = np.inf #Maximum step-size.
self.options["safe"] = 0.9 #Safety factor
- self.options["atol"] = 1.0e-6*N.ones(self.problem_info["dim"]) #Absolute tolerance
+ self.options["atol"] = 1.0e-6*np.ones(self.problem_info["dim"]) #Absolute tolerance
self.options["rtol"] = 1.0e-6 #Relative tolerance
self.options["usejac"] = True if self.problem_info["jac_fcn"] else False
self.options["maxsteps"] = 100000
@@ -1035,11 +1035,11 @@ def f(t, y):
res = self.problem.res(t, y[:leny], y[leny:2*leny], self.sw)
except BaseException as E:
res = y[:leny].copy()
- if isinstance(E, (N.linalg.LinAlgError, ZeroDivisionError, AssimuloRecoverableError)): ## recoverable
+ if isinstance(E, (np.linalg.LinAlgError, ZeroDivisionError, AssimuloRecoverableError)): ## recoverable
ret = -1 #Recoverable error
else:
ret = -2 #Non-recoverable
- return N.append(y[leny:2*leny],res), [ret]
+ return np.append(y[leny:2*leny],res), [ret]
self._f = f
self.event_func = event_func
self._event_info = [0] * self.problem_info["dimRoot"]
@@ -1053,15 +1053,15 @@ def f(t, y):
res = self.problem.res(t, y[:leny], y[leny:2*leny])
except BaseException as E:
res = y[:leny].copy()
- if isinstance(E, (N.linalg.LinAlgError, ZeroDivisionError, AssimuloRecoverableError)): ## recoverable
+ if isinstance(E, (np.linalg.LinAlgError, ZeroDivisionError, AssimuloRecoverableError)): ## recoverable
ret = -1 #Recoverable error
else:
ret = -2 #Non-recoverable
- return N.append(y[leny:2*leny],res), [ret]
+ return np.append(y[leny:2*leny],res), [ret]
self._f = f
def interpolate(self, time, k=0):
- y = N.empty(self._leny*2)
+ y = np.empty(self._leny*2)
for i in range(self._leny*2):
# Note: index shift to Fortan based indices
y[i] = self.radau5.contr5(i+1, time, self.cont)
@@ -1113,7 +1113,7 @@ def _solout(self, nrsol, told, t, y, cont, werr, lrc, irtrn):
return irtrn
def _mas_f(self, am):
- #return N.array([[1]*self._leny+[0]*self._leny])
+ #return np.array([[1]*self._leny+[0]*self._leny])
return self._mass_matrix
def integrate(self, t, y, yd, tf, opts):
@@ -1129,8 +1129,8 @@ def integrate(self, t, y, yd, tf, opts):
MLMAS = 0 #The mass matrix is only defined on the diagonal
MUMAS = 0 #The mass matrix is only defined on the diagonal
IOUT = 1 #solout is called after every step
- WORK = N.array([0.0]*(5*((self.problem_info["dim"]*2)**2+12)+20)) #Work (double) vector
- IWORK = N.array([0]*(3*(self.problem_info["dim"]*2)+20),dtype=N.intc) #Work (integer) vector
+ WORK = np.array([0.0]*(5*((self.problem_info["dim"]*2)**2+12)+20)) #Work (double) vector
+ IWORK = np.array([0]*(3*(self.problem_info["dim"]*2)+20),dtype=np.intc) #Work (integer) vector
#Setting work options
WORK[1] = self.safe
@@ -1165,14 +1165,14 @@ def integrate(self, t, y, yd, tf, opts):
self._opts = opts
#Create y = [y, yd]
- y = N.append(y,yd)
+ y = np.append(y,yd)
#Create mass matrix
- #self._mass_matrix = N.array([[1]*self._leny+[0]*self._leny])
- self._mass_matrix = N.array([[0]*self._leny])
+ #self._mass_matrix = np.array([[1]*self._leny+[0]*self._leny])
+ self._mass_matrix = np.array([[0]*self._leny])
- atol = N.append(self.atol, self.atol)
+ atol = np.append(self.atol, self.atol)
- t, y, h, iwork, flag = self.radau5.radau5(self._f, t, y.copy(), tf, self.inith, self.rtol*N.ones(self.problem_info["dim"]*2), atol,
+ t, y, h, iwork, flag = self.radau5.radau5(self._f, t, y.copy(), tf, self.inith, self.rtol*np.ones(self.problem_info["dim"]*2), atol,
ITOL, jac_dummy, IJAC, MLJAC, MUJAC, self._mas_f, IMAS, MLMAS, MUMAS, self._solout,
IOUT, WORK, IWORK)
@@ -1255,11 +1255,11 @@ def __init__(self, problem):
self.options["quot2"] = 1.2 #Parameters for changing step-size (upper bound)
self.options["fac1"] = 0.2 #Parameters for step-size selection (lower bound)
self.options["fac2"] = 8.0 #Parameters for step-size selection (upper bound)
- self.options["maxh"] = N.inf #Maximum step-size.
+ self.options["maxh"] = np.inf #Maximum step-size.
self.options["safe"] = 0.9 #Safety factor
- self.options["atol"] = N.array([1.0e-6]*self._leny) #Absolute tolerance
+ self.options["atol"] = np.array([1.0e-6]*self._leny) #Absolute tolerance
self.options["rtol"] = 1.0e-6 #Relative tolerance
- self.options["index"] = N.array([1]*self._leny+[2]*self._leny)
+ self.options["index"] = np.array([1]*self._leny+[2]*self._leny)
self.options["usejac"] = True if self.problem_info["jac_fcn"] else False
self.options["maxsteps"] = 10000
@@ -1272,20 +1272,20 @@ def __init__(self, problem):
self._rejected = True #Is the last step rejected?
self._oldh = 0.0 #Old stepsize
self._olderr = 1.0 #Old error
- self._eps = N.finfo('double').eps
- self._col_poly = N.zeros(self._2leny*3)
+ self._eps = np.finfo('double').eps
+ self._col_poly = np.zeros(self._2leny*3)
self._type = '(implicit)'
self._curiter = 0 #Number of current iterations
#RES-Function
self.f = problem.res_internal
- self.RES = N.array([0.0]*len(self.y0))
+ self.RES = np.array([0.0]*len(self.y0))
#Internal temporary result vector
- self.Y1 = N.array([0.0]*len(self.y0))
- self.Y2 = N.array([0.0]*len(self.y0))
- self.Y3 = N.array([0.0]*len(self.y0))
- self._f0 = N.array([0.0]*len(self.y0))
+ self.Y1 = np.array([0.0]*len(self.y0))
+ self.Y2 = np.array([0.0]*len(self.y0))
+ self.Y3 = np.array([0.0]*len(self.y0))
+ self._f0 = np.array([0.0]*len(self.y0))
#Solver support
@@ -1310,9 +1310,9 @@ def _set_index(self, index):
"""
if len(index) == self._2leny:
- ind = N.array(index)
+ ind = np.array(index)
elif len(index) == self._leny:
- ind = N.array(index+(N.array(index)+1).tolist())
+ ind = np.array(index+(np.array(index)+1).tolist())
else:
raise Implicit_ODE_Exception('Wrong number of variables in the index vector.')
self.options["index"] = ind
@@ -1349,7 +1349,7 @@ def step_generator(self, t, y, yd, tf, opts):
if self.fnewt == 0:
self.fnewt = max(10.*self._eps/self.rtol,min(0.03,self.rtol**0.5))
- self._f0 = self._ode_f(t,N.append(y,yd))
+ self._f0 = self._ode_f(t,np.append(y,yd))
self.statistics["nfcns"] +=1
self._tc = t
self._yc = y
@@ -1363,8 +1363,8 @@ def step_generator(self, t, y, yd, tf, opts):
self._yc = y
self._ydc = yd
- if self.h > N.abs(tf-t):
- self.h = N.abs(tf-t)
+ if self.h > np.abs(tf-t):
+ self.h = np.abs(tf-t)
if t < tf:
yield ID_PY_OK, t,y,yd
@@ -1414,10 +1414,10 @@ def integrate(self, t, y, yd, tf, opts):
def _ode_f(self, t, y):
#self.res_fcn(t,y[:self._leny],y[self._leny:])
- #return N.hstack((y[self._leny:],self.res_fcn(t,y[:self._leny],y[self._leny:])))
+ #return np.hstack((y[self._leny:],self.res_fcn(t,y[:self._leny],y[self._leny:])))
self.f(self.RES,t,y[:self._leny],y[self._leny:])
- return N.hstack((y[self._leny:],self.RES))
+ return np.hstack((y[self._leny:],self.RES))
def _radau_F(self, Z, t, y, yd):
@@ -1425,7 +1425,7 @@ def _radau_F(self, Z, t, y, yd):
Z2 = Z[self._2leny:2*self._2leny]
Z3 = Z[2*self._2leny:3*self._2leny]
- q = N.append(y,yd)
+ q = np.append(y,yd)
sol1 = self._ode_f(t+self.C[0]*self.h, q+Z1)
sol2 = self._ode_f(t+self.C[1]*self.h, q+Z2)
@@ -1433,13 +1433,13 @@ def _radau_F(self, Z, t, y, yd):
self.statistics["nfcns"] += 3
- return N.hstack((N.hstack((sol1,sol2)),sol3))
+ return np.hstack((np.hstack((sol1,sol2)),sol3))
def _step(self, t, y, yd):
"""
This calculates the next step in the integration.
"""
- self._scaling = N.array(abs(N.append(y,yd))*self.rtol + self.atol.tolist()*2) #The scaling used.
+ self._scaling = np.array(abs(np.append(y,yd))*self.rtol + self.atol.tolist()*2) #The scaling used.
while True: #Loop for integrating one step.
@@ -1469,7 +1469,7 @@ def _step(self, t, y, yd):
tn = t+self.h #Preform the step
yn = y+self._Z[2*self._2leny:3*self._2leny][:self._leny]
ydn = yd+self._Z[2*self._2leny:3*self._2leny][self._leny:]
- self._f0 = self._ode_f(t,N.append(yn,ydn))
+ self._f0 = self._ode_f(t,np.append(yn,ydn))
self.statistics["nfcns"] += 1
self._oldoldh = self._oldh #Store the old(old) step-size for use in the test below.
@@ -1532,7 +1532,7 @@ def newton(self,t,y,yd):
self._needLU = False
- if min(abs(N.diag(self._U1))) 0:
thq = newnrm/oldnrm
if i == 1:
self._theta = thq
else:
- self._theta = N.sqrt(thq*thqold)
+ self._theta = np.sqrt(thq*thqold)
thqold = thq
if self._theta < 0.99: #Convergence
@@ -1583,7 +1583,7 @@ def newton(self,t,y,yd):
oldnrm = max(newnrm,self._eps) #Store oldnorm
W = W+Z #Perform the iteration
- Z = N.dot(self.T3,W) #Calculate the new Z values
+ Z = np.dot(self.T3,W) #Calculate the new Z values
if self._fac_con*newnrm <= self.fnewt: #Convergence?
self._itfail = False
@@ -1615,21 +1615,21 @@ def newton(self,t,y,yd):
def estimate_error(self):
temp = 1./self.h*(self.E[0]*self._Z[:self._2leny]+self.E[1]*self._Z[self._2leny:2*self._2leny]+self.E[2]*self._Z[2*self._2leny:3*self._2leny])
- temp = N.dot(self.M,temp)
+ temp = np.dot(self.M,temp)
self._scaling = self._scaling/self.h**(self.index-1)#hfac
scal = self._scaling#/self.h
- err_v = N.linalg.solve(self._U1,N.linalg.solve(self._L1,N.linalg.solve(self._P1,self._f0+temp)))
- err = N.linalg.norm(err_v/scal)
- err = max(err/N.sqrt(self._2leny),1.e-10)
+ err_v = np.linalg.solve(self._U1,np.linalg.solve(self._L1,np.linalg.solve(self._P1,self._f0+temp)))
+ err = np.linalg.norm(err_v/scal)
+ err = max(err/np.sqrt(self._2leny),1.e-10)
if (self._rejected or self._first) and err >= 1.: #If the step was rejected, use the more expensive error estimation
self.statistics["nfcns"] += 1
- err_v = self._ode_f(self._tc,N.append(self._yc,self._ydc)+err_v)
- err_v = N.linalg.solve(self._U1,N.linalg.solve(self._L1,N.linalg.solve(self._P1,err_v+temp)))
- err = N.linalg.norm(err_v/scal)
- err = max(err/N.sqrt(self._2leny),1.e-10)
+ err_v = self._ode_f(self._tc,np.append(self._yc,self._ydc)+err_v)
+ err_v = np.linalg.solve(self._U1,np.linalg.solve(self._L1,np.linalg.solve(self._P1,err_v+temp)))
+ err = np.linalg.norm(err_v/scal)
+ err = max(err/np.sqrt(self._2leny),1.e-10)
return err
@@ -1662,15 +1662,15 @@ def jacobian(self, t, y, yd):
self._needLU = True #A new LU-decomposition is needed
self._needjac = False #A new jacobian is not needed
- q = N.append(y,yd)
+ q = np.append(y,yd)
if self.usejac: #Retrieve the user-defined jacobian
cjac = self.problem.jac(t,y,yd)
else: #Calculate a numeric jacobian
- delt = N.array([(self._eps*max(abs(yi),1.e-5))**0.5 for yi in q])*N.identity(self._2leny) #Calculate a disturbance
- Fdelt = N.array([self._ode_f(t,q+e) for e in delt]) #Add the disturbance (row by row)
+ delt = np.array([(self._eps*max(abs(yi),1.e-5))**0.5 for yi in q])*np.identity(self._2leny) #Calculate a disturbance
+ Fdelt = np.array([self._ode_f(t,q+e) for e in delt]) #Add the disturbance (row by row)
grad = ((Fdelt-self._ode_f(t,q)).T/delt.diagonal()).T
- cjac = N.array(grad).T
+ cjac = np.array(grad).T
self.statistics["nfcnjacs"] += 1+self._2leny #Add the number of function evaluations
self.statistics["njacs"] += 1 #add the number of jacobian evaluation
@@ -1729,8 +1729,8 @@ def calc_start_values(self):
Calculate newton starting values.
"""
if self._first:
- Z = N.zeros(self._2leny*3)
- W = N.zeros(self._2leny*3)
+ Z = np.zeros(self._2leny*3)
+ W = np.zeros(self._2leny*3)
else:
Z = self._Z
cq = self.C*self.h/self._oldh#self._oldoldh#self._oldh
@@ -1741,46 +1741,46 @@ def calc_start_values(self):
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]))
- W = N.dot(self.T2,Z)
+ W = np.dot(self.T2,Z)
return Z, W
def _load_parameters(self):
#Parameters
- A = N.zeros([3,3])
- A[0,0] = (88.-7.*N.sqrt(6.))/360.0
- A[0,1] = (296.-169.*N.sqrt(6.))/1800.0
- A[0,2] = (-2.0+3.0*N.sqrt(6.))/225.0
- A[1,0] = (296.0+169.0*N.sqrt(6.))/1800.0
- A[1,1] = (88.+7.*N.sqrt(6.))/360.0
- A[1,2] = (-2.-3.*N.sqrt(6.))/225.0
- A[2,0] = (16.0-N.sqrt(6.))/36.0
- A[2,1] = (16.0+N.sqrt(6.))/36.0
+ A = np.zeros([3,3])
+ A[0,0] = (88.-7.*np.sqrt(6.))/360.0
+ A[0,1] = (296.-169.*np.sqrt(6.))/1800.0
+ A[0,2] = (-2.0+3.0*np.sqrt(6.))/225.0
+ A[1,0] = (296.0+169.0*np.sqrt(6.))/1800.0
+ A[1,1] = (88.+7.*np.sqrt(6.))/360.0
+ A[1,2] = (-2.-3.*np.sqrt(6.))/225.0
+ A[2,0] = (16.0-np.sqrt(6.))/36.0
+ A[2,1] = (16.0+np.sqrt(6.))/36.0
A[2,2] = (1.0/9.0)
- C = N.zeros([3,1])
- C[0,0]=(4.0-N.sqrt(6.0))/10.0
- C[1,0]=(4.0+N.sqrt(6.0))/10.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
- B = N.zeros([1,3])
- B[0,0]=(16.0-N.sqrt(6.0))/36.0
- B[0,1]=(16.0+N.sqrt(6.0))/36.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
- E = N.zeros(3)
- E[0] = -13.0-7.*N.sqrt(6.)
- E[1] = -13.0+7.0*N.sqrt(6.)
+ E = np.zeros(3)
+ E[0] = -13.0-7.*np.sqrt(6.)
+ E[1] = -13.0+7.0*np.sqrt(6.)
E[2] = -1.0
E = 1.0/3.0*E
- M = N.array([[1.,0.],[0.,0.]])
+ M = np.array([[1.,0.],[0.,0.]])
- Ainv = N.linalg.inv(A)
- [eig, T] = N.linalg.eig(Ainv)
- eig = N.array([eig[2],eig[0],eig[1]])
- J = N.diag(eig)
+ Ainv = np.linalg.inv(A)
+ [eig, T] = np.linalg.eig(Ainv)
+ eig = np.array([eig[2],eig[0],eig[1]])
+ J = np.diag(eig)
self._alpha = eig[1]
self._beta = eig[2]
@@ -1792,14 +1792,14 @@ def _load_parameters(self):
T[:,0] = temp2
T[:,1] = temp0
T[:,2] = temp1
- Tinv = N.linalg.inv(T)
-
- I = N.eye(self._2leny)
- M = N.kron(M,N.eye(self._leny))
- I3 = N.eye(3)
- T1 = N.kron(J,M)
- T2 = N.kron(Tinv,I)
- T3 = N.kron(T,I)
+ Tinv = np.linalg.inv(T)
+
+ I = np.eye(self._2leny)
+ M = np.kron(M,np.eye(self._leny))
+ I3 = np.eye(3)
+ T1 = np.kron(J,M)
+ T2 = np.kron(Tinv,I)
+ T3 = np.kron(T,I)
self.A = A
self.B = B
diff --git a/src/solvers/rosenbrock.py b/src/solvers/rosenbrock.py
index e32a54cc..6e689b0c 100644
--- a/src/solvers/rosenbrock.py
+++ b/src/solvers/rosenbrock.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import numpy as N
+import numpy as np
import scipy.sparse as sp
from assimulo.ode import NORMAL, ID_PY_EVENT, ID_PY_COMPLETE
@@ -32,7 +32,7 @@ def _set_atol(self,atol):
self.options["atol"] = set_type_shape_array(atol)
if len(self.options["atol"]) == 1:
- self.options["atol"] = self.options["atol"]*N.ones(self._leny)
+ self.options["atol"] = self.options["atol"]*np.ones(self._leny)
elif len(self.options["atol"]) != self._leny:
raise Rodas_Exception("atol must be of length one or same as the dimension of the problem.")
@@ -290,9 +290,9 @@ def __init__(self, problem):
self.options["inith"] = 0.01
self.options["fac1"] = 0.2 #Parameters for step-size selection (lower bound)
self.options["fac2"] = 6.0 #Parameters for step-size selection (upper bound)
- self.options["maxh"] = N.inf #Maximum step-size.
+ self.options["maxh"] = np.inf #Maximum step-size.
self.options["safe"] = 0.9 #Safety factor
- self.options["atol"] = 1.0e-6*N.ones(self.problem_info["dim"]) #Absolute tolerance
+ self.options["atol"] = 1.0e-6*np.ones(self.problem_info["dim"]) #Absolute tolerance
self.options["rtol"] = 1.0e-6 #Relative tolerance
self.options["usejac"] = True if self.problem_info["jac_fcn"] else False
self.options["maxsteps"] = 10000
@@ -331,7 +331,7 @@ def f(t, y):
self.f = self.problem.rhs
def interpolate(self, time):
- y = N.empty(self._leny)
+ y = np.empty(self._leny)
for i in range(self._leny):
y[i] = rodas.contro(i+1, time, self.cont)
@@ -397,8 +397,8 @@ def integrate(self, t, y, tf, opts):
MLMAS = self.problem_info["dim"] #The mass matrix is full
MUMAS = self.problem_info["dim"] #The mass matrix is full
IOUT = 1 #Solout is called after every accepted step
- WORK = N.array([0.0]*(2*self.problem_info["dim"]**2+14*self.problem_info["dim"]+20))
- IWORK = N.array([0]*(self.problem_info["dim"]+20))
+ WORK = np.array([0.0]*(2*self.problem_info["dim"]**2+14*self.problem_info["dim"]+20))
+ IWORK = np.array([0]*(self.problem_info["dim"]+20))
#Setting work options
WORK[1] = self.maxh
@@ -423,7 +423,7 @@ def integrate(self, t, y, tf, opts):
#Store the opts
self._opts = opts
- t, y, h, iwork, flag = rodas.rodas(self.f, IFCN, t, y.copy(), tf, self.inith, self.rtol*N.ones(self.problem_info["dim"]), self.atol,
+ t, y, h, iwork, flag = rodas.rodas(self.f, IFCN, t, y.copy(), tf, self.inith, self.rtol*np.ones(self.problem_info["dim"]), self.atol,
ITOL, jac_dummy, IJAC, MLJAC, MUJAC, dfx_dummy, IDFX, mas_dummy, IMAS, MLMAS, MUMAS, self._solout, IOUT, WORK, IWORK)
#Checking return
diff --git a/src/solvers/runge_kutta.py b/src/solvers/runge_kutta.py
index 32b2eff2..913f8c15 100644
--- a/src/solvers/runge_kutta.py
+++ b/src/solvers/runge_kutta.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import numpy as N
+import numpy as np
from assimulo.ode import ID_PY_EVENT, ID_PY_COMPLETE, NORMAL, ID_PY_OK
from assimulo.explicit_ode import Explicit_ODE
@@ -57,9 +57,9 @@ def __init__(self, problem):
self.options["fac1"] = 0.2 #Parameters for step-size selection (lower bound)
self.options["fac2"] = 10.0 #Parameters for step-size selection (upper bound)
self.options["beta"] = 0.04
- self.options["maxh"] = N.inf #Maximum step-size.
+ self.options["maxh"] = np.inf #Maximum step-size.
self.options["inith"] = 0.0
- self.options["atol"] = 1.0e-6*N.ones(self.problem_info["dim"]) #Absolute tolerance
+ self.options["atol"] = 1.0e-6*np.ones(self.problem_info["dim"]) #Absolute tolerance
self.options["rtol"] = 1.0e-6 #Relative tolerance
self.options["maxsteps"] = 100000
@@ -97,7 +97,7 @@ def f(t, y):
self.f = self.problem.rhs
def interpolate(self, time):
- y = N.empty(self._leny)
+ y = np.empty(self._leny)
for i in range(self._leny):
y[i] = dopri5.contd5(i+1, time, self.cont, self.lrc)
@@ -145,8 +145,8 @@ def _solout(self, nrsol, told, t, y, cont, lrc, irtrn):
def integrate(self, t, y, tf, opts):
ITOL = 1 #Both atol and rtol are vectors
IOUT = 2 #Dense out in solout
- WORK = N.array([0.0]*(8*self.problem_info["dim"]+5*self.problem_info["dim"]+21))
- IWORK = N.array([0]*(self.problem_info["dim"]+21))
+ WORK = np.array([0.0]*(8*self.problem_info["dim"]+5*self.problem_info["dim"]+21))
+ IWORK = np.array([0]*(self.problem_info["dim"]+21))
#Setting work options
WORK[1] = self.safe
@@ -169,7 +169,7 @@ def integrate(self, t, y, tf, opts):
#Store the opts
self._opts = opts
- t, y, iwork, flag = dopri5.dopri5(self.f, t, y.copy(), tf, self.rtol*N.ones(self.problem_info["dim"]), self.atol, ITOL, self._solout, IOUT, WORK, IWORK)
+ t, y, iwork, flag = dopri5.dopri5(self.f, t, y.copy(), tf, self.rtol*np.ones(self.problem_info["dim"]), self.atol, ITOL, self._solout, IOUT, WORK, IWORK)
#Checking return
if flag == 1:
@@ -208,10 +208,10 @@ def print_statistics(self, verbose=NORMAL):
def _set_atol(self,atol):
- self.options["atol"] = N.array(atol,dtype=float) if len(N.array(atol,dtype=float).shape)>0 else N.array([atol],dtype=float)
+ self.options["atol"] = np.array(atol,dtype=float) if len(np.array(atol,dtype=float).shape)>0 else np.array([atol],dtype=float)
if len(self.options["atol"]) == 1:
- self.options["atol"] = self.options["atol"]*N.ones(self._leny)
+ self.options["atol"] = self.options["atol"]*np.ones(self._leny)
elif len(self.options["atol"]) != self._leny:
raise Dopri5_Exception("atol must be of length one or same as the dimension of the problem.")
@@ -452,11 +452,11 @@ def __init__(self, problem):
self.options["maxsteps"] = 10000
#Internal temporary result vector
- self.Y1 = N.array([0.0]*len(self.y0))
- self.Y2 = N.array([0.0]*len(self.y0))
- self.Y3 = N.array([0.0]*len(self.y0))
- self.Y4 = N.array([0.0]*len(self.y0))
- self.Z3 = N.array([0.0]*len(self.y0))
+ self.Y1 = np.array([0.0]*len(self.y0))
+ self.Y2 = np.array([0.0]*len(self.y0))
+ self.Y3 = np.array([0.0]*len(self.y0))
+ self.Y4 = np.array([0.0]*len(self.y0))
+ self.Z3 = np.array([0.0]*len(self.y0))
#Solver support
self.supports["report_continuously"] = True
@@ -521,7 +521,7 @@ def _get_initial_step(self):
def _set_atol(self,atol):
try:
- atol_arr = N.array(atol, dtype=float)
+ atol_arr = np.array(atol, dtype=float)
if (atol_arr <= 0.0).any():
raise Explicit_ODE_Exception('Absolute tolerance must be a positive float or a float vector.')
except (ValueError,TypeError):
@@ -620,7 +620,7 @@ def _iter(self,t,y,tf,opts):
self.set_problem_data()
maxsteps = self.options["maxsteps"]
h = self.options["inith"]
- h = min(h, N.abs(tf-t))
+ h = min(h, np.abs(tf-t))
self.f(self.Y1, t, y)
flag = ID_PY_OK
@@ -648,7 +648,7 @@ def _iter(self,t,y,tf,opts):
pass
opts["output_index"] = output_index
h=self.adjust_stepsize(h,error)
- h=min(h, N.abs(tf-t))
+ h=min(h, np.abs(tf-t))
else:
break
else:
@@ -697,7 +697,7 @@ def _step(self, t, y, h):
"""
self.statistics["nfcns"] += 5
- scaling = N.array(abs(y)*self.rtol + self.atol) # to normalize the error
+ scaling = np.array(abs(y)*self.rtol + self.atol) # to normalize the error
f = self.f
f(self.Y2, t + h/2., y + h*self.Y1/2.)
@@ -705,7 +705,7 @@ def _step(self, t, y, h):
f(self.Z3, t + h, y - h*self.Y1 + 2.0*h*self.Y2)
f(self.Y4, t + h, y + h*self.Y3)
- error = N.linalg.norm(h/6.0*(2.0*self.Y2 + self.Z3 - 2.0*self.Y3 - self.Y4)/scaling) #normalized
+ error = np.linalg.norm(h/6.0*(2.0*self.Y2 + self.Z3 - 2.0*self.Y3 - self.Y4)/scaling) #normalized
t_next = t + h
y_next = y + h/6.0*(self.Y1 + 2.0*self.Y2 + 2.0*self.Y3 + self.Y4)
@@ -784,10 +784,10 @@ def __init__(self, problem):
self.options["h"] = 0.01
#Internal temporary result vector
- self.Y1 = N.array([0.0]*len(self.y0))
- self.Y2 = N.array([0.0]*len(self.y0))
- self.Y3 = N.array([0.0]*len(self.y0))
- self.Y4 = N.array([0.0]*len(self.y0))
+ self.Y1 = np.array([0.0]*len(self.y0))
+ self.Y2 = np.array([0.0]*len(self.y0))
+ self.Y3 = np.array([0.0]*len(self.y0))
+ self.Y4 = np.array([0.0]*len(self.y0))
#RHS-Function
self.f = problem.rhs_internal
@@ -838,12 +838,12 @@ def _get_h(self):
def _iter(self,t,y,tf):
h = self.options["h"]
- h = min(h, N.abs(tf-t))
+ h = min(h, np.abs(tf-t))
while t+h < tf:
t, y = self._step(t, y, h)
yield ID_PY_OK, t,y
- h=min(h, N.abs(tf-t))
+ h=min(h, np.abs(tf-t))
else:
t, y = self._step(t, y, h)
yield ID_PY_COMPLETE, t, y
diff --git a/src/solvers/sdirk_dae.pyx b/src/solvers/sdirk_dae.pyx
index f7f1b36d..f5668503 100644
--- a/src/solvers/sdirk_dae.pyx
+++ b/src/solvers/sdirk_dae.pyx
@@ -16,7 +16,7 @@
# along with this program. If not, see .
import sys
-import numpy as N
+import numpy as np
from assimulo.exception import ODEPACK_Exception, RKStarter_Exception
from assimulo.ode import ID_PY_COMPLETE, ID_PY_EVENT, NORMAL
@@ -56,7 +56,7 @@ class SDIRK_DAE(Implicit_ODE):
Implicit_ODE.__init__(self, problem) #Calls the base class
#Default values
- self.options["atol"] = 1.0e-6*N.ones(self.problem_info["dim"]) #Absolute tolerance
+ self.options["atol"] = 1.0e-6*np.ones(self.problem_info["dim"]) #Absolute tolerance
self.options["rtol"] = 1.0e-6 #Relative tolerance
self.options["usejac"] = False
self.options["hmax"] = 0.
@@ -90,11 +90,11 @@ class SDIRK_DAE(Implicit_ODE):
# first call or classical restart after a discontinuity
ISTATE=1
- RWORK = N.array([0.0]*(22 + self.problem_info["dim"] *
+ RWORK = np.array([0.0]*(22 + self.problem_info["dim"] *
max(16,self.problem_info["dim"]+9) +
3*self.problem_info["dimRoot"]))
# Integer work array
- IWORK = N.array([0]*(20 + self.problem_info["dim"]))
+ IWORK = np.array([0]*(20 + self.problem_info["dim"]))
return ISTATE, RWORK, IWORK
@@ -109,7 +109,7 @@ class SDIRK_DAE(Implicit_ODE):
ISTATE, RWORK, IWORK = self.integrate_start( t, y)
JT = 1 if self.usejac else 2#Jacobian type indicator
- JROOT = N.array([0]*self.problem_info["dimRoot"])
+ JROOT = np.array([0]*self.problem_info["dimRoot"])
#Setting work options
RWORK[0] = tf #Do not integrate past tf
@@ -125,7 +125,7 @@ class SDIRK_DAE(Implicit_ODE):
#Dummy methods
g_dummy = (lambda t:x) if not self.problem_info["state_events"] else self.problem.state_events
- jac_dummy = (lambda t,y:N.zeros((len(y),len(y)))) if not self.usejac else self.problem.jac
+ jac_dummy = (lambda t,y:np.zeros((len(y),len(y)))) if not self.usejac else self.problem.jac
#Extra args to rhs and state_events
rhs_extra_args = (self.sw,) if self.problem_info["switches"] else ()
@@ -148,7 +148,7 @@ class SDIRK_DAE(Implicit_ODE):
while (ISTATE == 2 or ISTATE == 1) and t < tf:
y, t, ISTATE, RWORK, IWORK, roots = dlsodar(self.problem.rhs, y.copy(), t, tf, ITOL,
- self.rtol*N.ones(self.problem_info["dim"]), self.atol,
+ self.rtol*np.ones(self.problem_info["dim"]), self.atol,
ITASK, ISTATE, IOPT, RWORK, IWORK, jac_dummy, JT, g_dummy, JROOT,
f_extra_args = rhs_extra_args, g_extra_args = g_extra_args)
@@ -189,7 +189,7 @@ class SDIRK_DAE(Implicit_ODE):
output_index += 1
y, t, ISTATE, RWORK, IWORK, roots = dlsodar(self.problem.rhs, y.copy(), t, tout, ITOL,
- self.rtol*N.ones(self.problem_info["dim"]), self.atol,
+ self.rtol*np.ones(self.problem_info["dim"]), self.atol,
ITASK, ISTATE, IOPT, RWORK, IWORK, jac_dummy, JT, g_dummy, JROOT,
f_extra_args = rhs_extra_args, g_extra_args = g_extra_args)
@@ -297,10 +297,10 @@ class SDIRK_DAE(Implicit_ODE):
def _set_atol(self,atol):
- self.options["atol"] = N.array(atol,dtype=float) if len(N.array(atol,dtype=float).shape)>0 else N.array([atol],dtype=float)
+ self.options["atol"] = np.array(atol,dtype=float) if len(np.array(atol,dtype=float).shape)>0 else np.array([atol],dtype=float)
if len(self.options["atol"]) == 1:
- self.options["atol"] = self.options["atol"]*N.ones(self._leny)
+ self.options["atol"] = self.options["atol"]*np.ones(self._leny)
elif len(self.options["atol"]) != self._leny:
raise ODEPACK_Exception("atol must be of length one or same as the dimension of the problem.")
@@ -463,17 +463,17 @@ class RKStarterNordsieck(object):
See: Mohammadi (2013): https://lup.lub.lu.se/luur/download?func=downloadFile&recordOId=4196026&fileOId=4196027
"""
- Gamma_0=[N.array([[1.,0.], # 1st order
+ Gamma_0=[np.array([[1.,0.], # 1st order
[0.,1.]]),
- N.array([[1.,0.,0.], # 2nd order
+ np.array([[1.,0.,0.], # 2nd order
[0.,1.,-1.],
[0.,0.,1.]]),
- N.array([[1.,0.,0.,0.], # 3rd order
+ np.array([[1.,0.,0.,0.], # 3rd order
[0.,1.,-5./3.,1.],
[0.,0.,3.,-2.],
[0.,0.,0.,1.],
[0.,0.,-4./3.,0.]]),
- N.array([[1.,0.,0.,0.,0.], # 4th order
+ np.array([[1.,0.,0.,0.,0.], # 4th order
[0.,1.,-5./6.,4./9.,-1./9.],
[0.,0.,0.,0.,0.],
[0.,0.,1./2.,-4./9.,1./9.],
@@ -481,7 +481,7 @@ class RKStarterNordsieck(object):
[0.,0.,-3.,10./3.,-4./3.],
[0.,0.,1.,-11./9.,5./9.]])]
- scale=N.array([1, 1, 1/2., 1./6., 1./24., 1./120.]).reshape(-1,1)
+ scale=np.array([1, 1, 1/2., 1./6., 1./24., 1./120.]).reshape(-1,1)
def __init__(self, rhs, H, eval_at=0.,number_of_steps=4):
"""
@@ -530,7 +530,7 @@ class RKStarterNordsieck(object):
k4 = h*f(y0 + 3./4. * k1 + 9./4. * k3)
k5 = h*f(y0 + k1/2. + k2 + k3/2. + 2. * k4)
k6 = h*f(y0+k1/12.+2. * k2 + k3/4. + 2./3. * k4 + 2. * k5)
- return N.array([y0,k1,k2,k3,k4,k5,k6])
+ return np.array([y0,k1,k2,k3,k4,k5,k6])
def rk_like3(self, t0, y0, sw0):
"""
rk_like computes Runge-Kutta stages
@@ -544,7 +544,7 @@ class RKStarterNordsieck(object):
k2 = h*f(y0 + k1)
k3 = h*f(y0 + k1+ k2)
k4 = h*f(y0 + 3./2. * k1)
- return N.array([y0,k1,k2,k3,k4])
+ return np.array([y0,k1,k2,k3,k4])
def rk_like2(self, t0, y0, sw0):
"""
rk_like2 computes Runge-Kutta 2nd-stages
@@ -555,12 +555,12 @@ class RKStarterNordsieck(object):
h=self.H/2
k1=h*f(y0)
k2=h*f(y0+k1)
- return N.array([y0,k1,k2])
+ return np.array([y0,k1,k2])
def nordsieck(self,k):
"""
Nordsieck array computed at initial point
"""
- nord=self.scale[:self.number_of_steps+1]*N.dot(self.Gamma_0[self.number_of_steps-1].T,k)
+ nord=self.scale[:self.number_of_steps+1]*np.dot(self.Gamma_0[self.number_of_steps-1].T,k)
return nord
def __call__(self, t0 , y0, sw0=[]):
"""
diff --git a/src/solvers/sundials.pyx b/src/solvers/sundials.pyx
index da7ac200..079c0ecd 100644
--- a/src/solvers/sundials.pyx
+++ b/src/solvers/sundials.pyx
@@ -17,8 +17,8 @@
# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION
-import numpy as N
-cimport numpy as N
+import numpy as np
+cimport numpy as np
import scipy.sparse as sparse
@@ -71,9 +71,9 @@ cdef class IDA(Implicit_ODE):
cdef public object event_func
#cdef public dict statistics
cdef object pt_root, pt_fcn, pt_jac, pt_jacv, pt_sens
- cdef public N.ndarray yS0
- #cdef N.ndarray _event_info
- cdef public N.ndarray g_old
+ cdef public np.ndarray yS0
+ #cdef np.ndarray _event_info
+ cdef public np.ndarray g_old
cdef SUNDIALS.SUNMatrix sun_matrix
cdef SUNDIALS.SUNLinearSolver sun_linearsolver
@@ -86,7 +86,7 @@ cdef class IDA(Implicit_ODE):
self.set_problem_data()
#Solver options
- self.options["atol"] = N.array([1.0e-6]*self.problem_info["dim"]) #The absolute tolerance
+ self.options["atol"] = np.array([1.0e-6]*self.problem_info["dim"]) #The absolute tolerance
self.options["rtol"] = 1.0e-6 #The relative tolerance
self.options["lsoff"] = False #Turn on or off the linesearch algorithm
self.options["tout1"] = 0.0001 #Direction of initial calculation
@@ -100,7 +100,7 @@ cdef class IDA(Implicit_ODE):
self.options["usejac"] = True if (self.problem_info["jac_fcn"] or self.problem_info["jacv_fcn"]) else False
self.options["usesens"] = True if self.problem_info["dimSens"] > 0 else False
self.options["inith"] = 0.0 #Initial step-size
- self.options["algvar"] = N.array([1.0]*self.problem_info["dim"])
+ self.options["algvar"] = np.array([1.0]*self.problem_info["dim"])
self.options["sensmethod"] = 'STAGGERED'
self.options["dqtype"] = "CENTERED"
self.options["dqrhomax"] = 0.0
@@ -117,7 +117,7 @@ cdef class IDA(Implicit_ODE):
if hasattr(problem, 'pbar'):
self.pbar = problem.pbar
elif hasattr(problem, 'p0'):
- self.pbar = N.array([N.abs(x) if N.abs(x) > 0 else 1.0 for x in self.p0])
+ self.pbar = np.array([np.abs(x) if np.abs(x) > 0 else 1.0 for x in self.p0])
if hasattr(problem, 'algvar'):
self.algvar = problem.algvar
if hasattr(problem, 'yS0'):
@@ -132,8 +132,8 @@ cdef class IDA(Implicit_ODE):
self.pData.memSize = self.pData.dim*sizeof(realtype)
#Set the ndarray to the problem struct
- #self.yTemp = N.zeros(self.pData.dim, dtype=float, order='c')
- #self.ydTemp = N.zeros(self.pData.dim, dtype=float, order='c')
+ #self.yTemp = np.zeros(self.pData.dim, dtype=float, order='c')
+ #self.ydTemp = np.zeros(self.pData.dim, dtype=float, order='c')
#self.pData.y = self.yTemp
#self.pData.yd = self.ydTemp
@@ -423,7 +423,7 @@ cdef class IDA(Implicit_ODE):
self.event_func = event_func
self.g_old = self.event_func(self.t, self.y, self.yd)
self.statistics["nstatefcns"] += 1
- self._event_info = N.array([0] * self.problem_info["dimRoot"])
+ self._event_info = np.array([0] * self.problem_info["dimRoot"])
cdef initialize_sensitivity_options(self):
"""
@@ -517,12 +517,12 @@ cdef class IDA(Implicit_ODE):
if self.pData.dimSens > 0:
self.initialize_sensitivity_options()
- cpdef integrate(self,double t,N.ndarray[ndim=1, dtype=realtype] y,N.ndarray[ndim=1, dtype=realtype] yd,double tf,dict opts):
+ cpdef integrate(self,double t,np.ndarray[ndim=1, dtype=realtype] y,np.ndarray[ndim=1, dtype=realtype] yd,double tf,dict opts):
cdef int flag, output_index, normal_mode
cdef N_Vector yout, ydout
cdef double tret = 0.0, tout
cdef list tr = [], yr = [], ydr = []
- cdef N.ndarray output_list
+ cdef np.ndarray output_list
yout = arr2nv(y)
ydout = arr2nv(yd)
@@ -619,12 +619,12 @@ cdef class IDA(Implicit_ODE):
return flag, tr, yr, ydr
- cpdef step(self,double t,N.ndarray y, N.ndarray yd, double tf,dict opts):
+ cpdef step(self,double t,np.ndarray y, np.ndarray yd, double tf,dict opts):
cdef int flag
cdef N_Vector yout, ydout
cdef double tret = t
cdef double tr
- cdef N.ndarray yr, ydr
+ cdef np.ndarray yr, ydr
yout = arr2nv(y)
ydout = arr2nv(yd)
@@ -735,7 +735,7 @@ cdef class IDA(Implicit_ODE):
cpdef get_last_estimated_errors(self):
cdef flag
- cdef N.ndarray err, pyweight, pyele
+ cdef np.ndarray err, pyweight, pyele
IF SUNDIALS_VERSION >= (6,0,0):
cdef SUNDIALS.SUNContext ctx = NULL
cdef void* comm = NULL
@@ -763,14 +763,14 @@ cdef class IDA(Implicit_ODE):
return err
- cpdef N.ndarray interpolate(self,double t,int k = 0):
+ cpdef np.ndarray interpolate(self,double t,int k = 0):
"""
Calls the internal IDAGetDky for the interpolated values at time t.
t must be within the last internal step. k is the derivative of y which
can be from zero to the current order.
"""
cdef flag
- cdef N.ndarray res
+ cdef np.ndarray res
IF SUNDIALS_VERSION >= (6,0,0):
cdef SUNDIALS.SUNContext ctx = NULL
cdef void* comm = NULL
@@ -820,7 +820,7 @@ cdef class IDA(Implicit_ODE):
ELSE:
cdef N_Vector dkyS=N_VNew_Serial(self.pData.dim)
cdef flag
- cdef N.ndarray res
+ cdef np.ndarray res
if i==-1:
@@ -836,7 +836,7 @@ cdef class IDA(Implicit_ODE):
N_VDestroy(dkyS)
- return N.array(matrix)
+ return np.array(matrix)
else:
flag = SUNDIALS.IDAGetSensDky1(self.ida_mem, t, k, i, dkyS)
@@ -1003,11 +1003,11 @@ cdef class IDA(Implicit_ODE):
See SUNDIALS IDA documentation 4.5.2 for more details.
"""
- #self.options["atol"] = N.array(atol,dtype=float) if len(N.array(atol,dtype=float).shape)>0 else N.array([atol],dtype=float)
+ #self.options["atol"] = np.array(atol,dtype=float) if len(np.array(atol,dtype=float).shape)>0 else np.array([atol],dtype=float)
self.options["atol"] = set_type_shape_array(atol)
if len(self.options["atol"]) == 1:
- self.options["atol"] = self.options["atol"]*N.ones(self.pData.dim)
+ self.options["atol"] = self.options["atol"]*np.ones(self.pData.dim)
elif len(self.options["atol"]) != self.pData.dim:
raise AssimuloException("atol must be of length one or same as the dimension of the problem.")
if (self.options["atol"]<=0.0).any():
@@ -1181,7 +1181,7 @@ cdef class IDA(Implicit_ODE):
linear_solver = property(_get_linear_solver, _set_linear_solver)
def _set_algvar(self,algvar):
- self.options["algvar"] = N.array(algvar,dtype=float) if len(N.array(algvar,dtype=float).shape)>0 else N.array([algvar],dtype=float)
+ self.options["algvar"] = np.array(algvar,dtype=float) if len(np.array(algvar,dtype=float).shape)>0 else np.array([algvar],dtype=float)
if len(self.options["algvar"]) != self.pData.dim:
raise AssimuloException('When setting the algebraic variables, the' \
@@ -1519,9 +1519,9 @@ cdef class CVode(Explicit_ODE):
cdef public object event_func
#cdef public dict statistics
cdef object pt_root, pt_fcn, pt_jac, pt_jacv, pt_sens,pt_prec_solve,pt_prec_setup
- cdef public N.ndarray yS0
- #cdef N.ndarray _event_info
- cdef public N.ndarray g_old
+ cdef public np.ndarray yS0
+ #cdef np.ndarray _event_info
+ cdef public np.ndarray g_old
cdef SUNDIALS.SUNMatrix sun_matrix
cdef SUNDIALS.SUNLinearSolver sun_linearsolver
cdef SUNDIALS.SUNNonlinearSolver sun_nonlinearsolver
@@ -1538,7 +1538,7 @@ cdef class CVode(Explicit_ODE):
self.set_problem_data()
#Solver options
- self.options["atol"] = N.array([1.0e-6]*self.problem_info["dim"]) #The absolute tolerance
+ self.options["atol"] = np.array([1.0e-6]*self.problem_info["dim"]) #The absolute tolerance
self.options["rtol"] = 1.0e-6 #The relative tolerance
self.options["maxh"] = 0.0 #Maximum step-size
self.options["minh"] = 0.0 #Minimal step-size
@@ -1579,7 +1579,7 @@ cdef class CVode(Explicit_ODE):
if hasattr(problem, 'pbar'):
self.pbar = problem.pbar
elif hasattr(problem, 'p0'):
- self.pbar = N.array([N.abs(x) if N.abs(x) > 0 else 1.0 for x in self.problem.p0])
+ self.pbar = np.array([np.abs(x) if np.abs(x) > 0 else 1.0 for x in self.problem.p0])
if hasattr(problem, 'yS0'):
self.yS0 = problem.yS0
@@ -1634,7 +1634,7 @@ cdef class CVode(Explicit_ODE):
"""
Returns the vector of weighted estimated local errors at the current step.
"""
- return N.abs(self.get_local_errors()*self.get_error_weights())
+ return np.abs(self.get_local_errors()*self.get_error_weights())
cpdef get_last_order(self):
"""
@@ -1721,8 +1721,8 @@ cdef class CVode(Explicit_ODE):
self.pData.memSize = self.pData.dim*sizeof(realtype)
#Set the ndarray to the problem struct
- #self.yTemp = N.zeros(self.pData.dim, dtype=float, order='c')
- #self.ydTemp = N.zeros(self.pData.dim, dtype=float, order='c')
+ #self.yTemp = np.zeros(self.pData.dim, dtype=float, order='c')
+ #self.ydTemp = np.zeros(self.pData.dim, dtype=float, order='c')
#self.pData.y = self.yTemp
#self.pData.yd = self.ydTemp
@@ -1913,17 +1913,17 @@ cdef class CVode(Explicit_ODE):
self.event_func = event_func
self.g_old = self.event_func(self.t, self.y)
self.statistics["nstatefcns"] += 1
- self._event_info = N.array([0] * self.problem_info["dimRoot"])
+ self._event_info = np.array([0] * self.problem_info["dimRoot"])
- cpdef N.ndarray interpolate(self,double t,int k = 0):
+ cpdef np.ndarray interpolate(self,double t,int k = 0):
"""
Calls the internal CVodeGetDky for the interpolated values at time t.
t must be within the last internal step. k is the derivative of y which
can be from zero to the current order.
"""
cdef flag
- cdef N.ndarray res
+ cdef np.ndarray res
IF SUNDIALS_VERSION >= (6,0,0):
cdef SUNDIALS.SUNContext ctx = NULL
cdef void* comm = NULL
@@ -1944,7 +1944,7 @@ cdef class CVode(Explicit_ODE):
return res
- cpdef N.ndarray interpolate_sensitivity(self, realtype t, int k = 0, int i=-1):
+ cpdef np.ndarray interpolate_sensitivity(self, realtype t, int k = 0, int i=-1):
"""
This method calls the internal method CVodeGetSensDky which computes the k-th derivatives
of the interpolating polynomials for the sensitivity variables at time t.
@@ -1974,7 +1974,7 @@ cdef class CVode(Explicit_ODE):
ELSE:
cdef N_Vector dkyS=N_VNew_Serial(self.pData.dim)
cdef int flag
- cdef N.ndarray res
+ cdef np.ndarray res
if i==-1:
@@ -1989,7 +1989,7 @@ cdef class CVode(Explicit_ODE):
N_VDestroy(dkyS)
- return N.array(matrix)
+ return np.array(matrix)
else:
flag = SUNDIALS.CVodeGetSensDky1(self.cvode_mem, t, k, i, dkyS)
if flag <0:
@@ -2012,12 +2012,12 @@ cdef class CVode(Explicit_ODE):
self.initialize_cvode()
- cpdef step(self,double t,N.ndarray y,double tf,dict opts):
+ cpdef step(self,double t,np.ndarray y,double tf,dict opts):
cdef int flag
cdef N_Vector yout
cdef double tret = t
cdef double tr
- cdef N.ndarray yr
+ cdef np.ndarray yr
yout = arr2nv(y)
@@ -2057,12 +2057,12 @@ cdef class CVode(Explicit_ODE):
return flag, tr, yr
- cpdef integrate(self,double t,N.ndarray[ndim=1, dtype=realtype] y,double tf,dict opts):
+ cpdef integrate(self,double t,np.ndarray[ndim=1, dtype=realtype] y,double tf,dict opts):
cdef int flag, output_index, normal_mode
cdef N_Vector yout
cdef double tret = self.t, tout
cdef list tr = [], yr = []
- cdef N.ndarray output_list
+ cdef np.ndarray output_list
if self.options["norm"] == "EUCLIDEAN":
yout = arr2nv_euclidean(y)
@@ -2447,7 +2447,7 @@ cdef class CVode(Explicit_ODE):
#Tolerances
self.nv_atol = arr2nv(self.options["atol"])
- if SUNDIALS_CVODE_RTOL_VEC and isinstance(self.options["rtol"], N.ndarray):
+ if SUNDIALS_CVODE_RTOL_VEC and isinstance(self.options["rtol"], np.ndarray):
self.nv_rtol = arr2nv(self.options["rtol"])
flag = SUNDIALS.CVodeVVtolerances(self.cvode_mem, self.nv_rtol, self.nv_atol)
else:
@@ -2592,7 +2592,7 @@ cdef class CVode(Explicit_ODE):
self.options["atol"] = set_type_shape_array(atol)
if len(self.options["atol"]) == 1:
- self.options["atol"] = self.options["atol"]*N.ones(self.pData.dim)
+ self.options["atol"] = self.options["atol"]*np.ones(self.pData.dim)
elif len(self.options["atol"]) != self.pData.dim:
raise AssimuloException("atol must be of length one or same as the dimension of the problem.")
if (self.options["atol"]<=0.0).any():
@@ -2622,7 +2622,7 @@ cdef class CVode(Explicit_ODE):
"""
rtol = set_type_shape_array(rtol) ## convert to appropriate numpy array
- rtol = N.array([rtol[0]]) if N.all(N.isclose(rtol, rtol[0])) else rtol ## reduce if possible
+ rtol = np.array([rtol[0]]) if np.all(np.isclose(rtol, rtol[0])) else rtol ## reduce if possible
if (rtol<0.0).any():
raise AssimuloException('Relative tolerance(s) must be a non-negative.')
if rtol.size == 1:
diff --git a/src/special_systems.pyx b/src/special_systems.pyx
index 8ed7dd2d..97af77ff 100644
--- a/src/special_systems.pyx
+++ b/src/special_systems.pyx
@@ -17,8 +17,8 @@
# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION
-import numpy as N
-cimport numpy as N
+import numpy as np
+cimport numpy as np
from assimulo.problem import Implicit_Problem, Overdetermined_Problem
from assimulo.support import set_type_shape_array
@@ -107,10 +107,10 @@ cdef class cMechanical_System:
elif index=='ind3':
constraint=self.constr3
elif index in ('ovstab2', 'ggl2'):
- constraint=lambda t,y: N.hstack((self.constr2(t,y),
+ constraint=lambda t,y: np.hstack((self.constr2(t,y),
self.constr3(t,y)))
elif index=='ovstab1':
- constraint=lambda t,y: N.hstack((self.constr1(t,y),
+ constraint=lambda t,y: np.hstack((self.constr1(t,y),
self.constr3(t,y),
self.constr2(t,y)))
else:
@@ -121,18 +121,18 @@ cdef class cMechanical_System:
def with_constraint(t,y,yd):
p,v,la=y[0:n_p], y[n_p:n_v], y[n_v:]
residual=func(t,y,yd)
- return N.hstack((
+ return np.hstack((
residual[0:n_p],
- residual[n_p:n_v]+N.dot(self.GT(p),la.reshape(-1,)),
+ residual[n_p:n_v]+np.dot(self.GT(p),la.reshape(-1,)),
constraint(t,y)
))
else:
def with_constraint(t,y,yd):
p,v,la,mue=y[0:n_p], y[n_p:n_v], y[n_v:n_v+n_la],y[n_v+n_la:]
residual=func(t,y,yd)
- return N.hstack((
- residual[0:n_p]+N.dot(self.GT(p),mue.reshape(-1,)),
- residual[n_p:n_v]+N.dot(self.GT(p),la.reshape(-1,)),
+ return np.hstack((
+ residual[0:n_p]+np.dot(self.GT(p),mue.reshape(-1,)),
+ residual[n_p:n_v]+np.dot(self.GT(p),la.reshape(-1,)),
constraint(t,y)
))
@@ -141,9 +141,9 @@ cdef class cMechanical_System:
def res(t,y,yd):
p,pd=y[0:n_p], yd[0:n_p]
v,vd=y[n_p:n_v], yd[n_p:n_v]
- Mvd = N.dot(M,vd) if M is not None else vd
+ Mvd = np.dot(M,vd) if M is not None else vd
- return N.hstack((pd - v, Mvd - self.forces(t,p,v)))
+ return np.hstack((pd - v, Mvd - self.forces(t,p,v)))
if n_la==0:
return res
@@ -158,13 +158,13 @@ cdef class cMechanical_System:
raise ValueError(index_error)
# 1. Treatment of initial conditions depending on the index
- y0=N.hstack((self.pos0,self.vel0))
- yd0=N.hstack((self.posd0,self.veld0))
+ y0=np.hstack((self.pos0,self.vel0))
+ yd0=np.hstack((self.posd0,self.veld0))
if self.constrained:
if index is None or index=='ind0':
raise ValueError(index_error)
- y0=N.hstack((y0,self.lam0))
- yd0=N.hstack((yd0,N.zeros(self.lam0.shape)))
+ y0=np.hstack((y0,self.lam0))
+ yd0=np.hstack((yd0,np.zeros(self.lam0.shape)))
# 2. Indicating algebraic variables
if index == 'ind1':
algvar = (self.pos0.size + self.vel0.size) * [1]\
@@ -184,16 +184,16 @@ cdef class cMechanical_System:
+ self.lam0.size*[0]
neq=len(algvar)+self.lam0.size
elif index == 'ggl1':
- mue = N.zeros(self.lam0.shape)
- gamma = N.zeros(self.lam0.shape)
- y0 = N.hstack((y0,mue,gamma))
- yd0 = N.hstack((yd0,mue,gamma))
+ mue = np.zeros(self.lam0.shape)
+ gamma = np.zeros(self.lam0.shape)
+ y0 = np.hstack((y0,mue,gamma))
+ yd0 = np.hstack((yd0,mue,gamma))
algvar = (self.pos0.size + self.vel0.size) * [1] \
+ 3*self.lam0.size*[0]
elif index == 'ggl2':
- mue = N.zeros(self.lam0.shape)
- y0 = N.hstack((y0,mue))
- yd0 = N.hstack((yd0,N.zeros(mue.shape)))
+ mue = np.zeros(self.lam0.shape)
+ y0 = np.hstack((y0,mue))
+ yd0 = np.hstack((yd0,np.zeros(mue.shape)))
algvar = (self.pos0.size + self.vel0.size) * [1] \
+ 2*self.lam0.size*[0]
elif index is None:
diff --git a/src/support.pxd b/src/support.pxd
index 3648edc6..93e04c47 100644
--- a/src/support.pxd
+++ b/src/support.pxd
@@ -15,9 +15,6 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import numpy as N
-cimport numpy as N
-
cdef class Statistics:
cdef public object statistics_msg
cdef public object statistics
diff --git a/src/support.pyx b/src/support.pyx
index 214179bb..9f0ca002 100644
--- a/src/support.pyx
+++ b/src/support.pyx
@@ -17,8 +17,8 @@
# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION
-import numpy as N
-cimport numpy as N
+import numpy as np
+cimport numpy as np
from collections import OrderedDict
@@ -28,7 +28,7 @@ def set_type_shape_array(var, datatype=realtype):
"""
Helper function to convert a scalar or list to a 1D-array
"""
- return N.array(var, dtype = datatype).reshape(-1,)
+ return np.array(var, dtype = datatype).reshape(-1,)
cdef class Statistics:
def __init__(self):
diff --git a/tests/solvers/test_euler.py b/tests/solvers/test_euler.py
index f7c0547f..daa3e8aa 100644
--- a/tests/solvers/test_euler.py
+++ b/tests/solvers/test_euler.py
@@ -20,7 +20,7 @@
from assimulo.solvers.euler import ExplicitEuler, ImplicitEuler
from assimulo.problem import Explicit_Problem
from assimulo.exception import AssimuloException, TimeLimitExceeded
-import numpy as N
+import numpy as np
import scipy.sparse as sp
float_regex = "[\s]*[\d]*.[\d]*((e|E)(\+|\-)\d\d|)"
@@ -30,8 +30,8 @@ class Extended_Problem(Explicit_Problem):
#Sets the initial conditions directly into the problem
y0 = [0.0, -1.0, 0.0]
sw0 = [False,True,True]
- event_array = N.array([0.0,0.0,0.0])
- rhs_array = N.array([0.0,0.0,0.0])
+ event_array = np.array([0.0,0.0,0.0])
+ rhs_array = np.array([0.0,0.0,0.0])
#The right-hand-side function (rhs)
def rhs(self,t,y,sw):
@@ -155,7 +155,7 @@ def test_h(self):
@testattr(stddist = True)
def test_time_event(self):
- f = lambda t,y: N.array(1.0)
+ f = lambda t,y: np.array(1.0)
global tnext
global nevent
tnext = 0.0
@@ -230,8 +230,8 @@ def test_switches(self):
"""
This tests that the switches are actually turned when override.
"""
- f = lambda t,x,sw: N.array([1.0])
- state_events = lambda t,x,sw: N.array([x[0]-1.])
+ f = lambda t,x,sw: np.array([1.0])
+ state_events = lambda t,x,sw: np.array([x[0]-1.])
def handle_event(solver, event_info):
solver.sw = [False] #Override the switches to point to another instance
@@ -292,8 +292,8 @@ def test_usejac_csc_matrix(self):
"""
This tests the functionality of the property usejac.
"""
- f = lambda t,x: N.array([x[1], -9.82]) #Defines the rhs
- jac = lambda t,x: sp.csc_matrix(N.array([[0.,1.],[0.,0.]])) #Defines the jacobian
+ f = lambda t,x: np.array([x[1], -9.82]) #Defines the rhs
+ jac = lambda t,x: sp.csc_matrix(np.array([[0.,1.],[0.,0.]])) #Defines the jacobian
exp_mod = Explicit_Problem(f, [1.0,0.0])
exp_mod.jac = jac
@@ -321,7 +321,7 @@ def test_h(self):
@testattr(stddist = True)
def test_time_event(self):
- f = lambda t,y: N.array(1.0)
+ f = lambda t,y: np.array(1.0)
global tnext
global nevent
tnext = 0.0
@@ -388,18 +388,18 @@ def test_stiff_problem(self):
t,y = simulator.simulate(1)
- y_correct = lambda t: N.exp(-15*t)
+ y_correct = lambda t: np.exp(-15*t)
- abs_err = N.abs(y[:,0]-y_correct(N.array(t)))
- nose.tools.assert_less(N.max(abs_err), 0.1)
+ abs_err = np.abs(y[:,0]-y_correct(np.array(t)))
+ nose.tools.assert_less(np.max(abs_err), 0.1)
@testattr(stddist = True)
def test_switches(self):
"""
This tests that the switches are actually turned when override.
"""
- f = lambda t,x,sw: N.array([1.0])
- state_events = lambda t,x,sw: N.array([x[0]-1.])
+ f = lambda t,x,sw: np.array([1.0])
+ state_events = lambda t,x,sw: np.array([x[0]-1.])
def handle_event(solver, event_info):
solver.sw = [False] #Override the switches to point to another instance
diff --git a/tests/solvers/test_glimda.py b/tests/solvers/test_glimda.py
index 6489e85c..ba7d06be 100644
--- a/tests/solvers/test_glimda.py
+++ b/tests/solvers/test_glimda.py
@@ -21,7 +21,7 @@
from assimulo.problem import Implicit_Problem, Explicit_Problem
from assimulo.exception import GLIMDA_Exception
-import numpy as N
+import numpy as np
class Test_GLIMDA:
"""
@@ -41,7 +41,7 @@ def f(t,y,yd):
res_0 = yd[0]-yd_0
res_1 = yd[1]-yd_1
- return N.array([res_0,res_1])
+ return np.array([res_0,res_1])
y0 = [2.0,-0.6] #Initial conditions
yd0 = [-.6,-200000.]
@@ -64,7 +64,7 @@ def test_simulate_explicit(self):
"""
Test a simulation of an explicit problem using GLIMDA.
"""
- f = lambda t,y:N.array(-y)
+ f = lambda t,y:np.array(-y)
y0 = [1.0]
problem = Explicit_Problem(f,y0)
@@ -74,7 +74,7 @@ def test_simulate_explicit(self):
t,y = simulator.simulate(1.0)
- nose.tools.assert_almost_equal(float(y[-1]), float(N.exp(-1.0)),4)
+ nose.tools.assert_almost_equal(float(y[-1]), float(np.exp(-1.0)),4)
@testattr(stddist = True)
def test_maxord(self):
@@ -143,8 +143,8 @@ def test_minh(self):
"""
Tests the minimum stepsize of GLIMDA.
"""
- nose.tools.assert_equal(self.sim.minh, N.finfo(N.double).eps)
- nose.tools.assert_equal(self.sim.options["minh"], N.finfo(N.double).eps)
+ nose.tools.assert_equal(self.sim.minh, np.finfo(np.double).eps)
+ nose.tools.assert_equal(self.sim.options["minh"], np.finfo(np.double).eps)
self.sim.minh = 1e-5
@@ -171,8 +171,8 @@ def test_maxh(self):
"""
Tests the maximum stepsize of GLIMDA.
"""
- nose.tools.assert_equal(self.sim.maxh, N.inf)
- nose.tools.assert_equal(self.sim.options["maxh"], N.inf)
+ nose.tools.assert_equal(self.sim.maxh, np.inf)
+ nose.tools.assert_equal(self.sim.options["maxh"], np.inf)
self.sim.maxh = 1e5
diff --git a/tests/solvers/test_odepack.py b/tests/solvers/test_odepack.py
index 50e8718f..dc0fe731 100644
--- a/tests/solvers/test_odepack.py
+++ b/tests/solvers/test_odepack.py
@@ -22,18 +22,18 @@
from assimulo.problem import Explicit_Problem
from assimulo.exception import TimeLimitExceeded
-import numpy as N
+import numpy as np
import scipy.sparse as sp
float_regex = "[\s]*[\d]*.[\d]*((e|E)(\+|\-)\d\d|)"
class Extended_Problem(Explicit_Problem):
- #Sets the initial conditons directly into the problem
+ #Sets the initial conditions directly into the problem
y0 = [0.0, -1.0, 0.0]
sw0 = [False,True,True]
- event_array = N.array([0.0,0.0,0.0])
- rhs_array = N.array([0.0,0.0,0.0])
+ event_array = np.array([0.0,0.0,0.0])
+ rhs_array = np.array([0.0,0.0,0.0])
#The right-hand-side function (rhs)
def rhs(self,t,y,sw):
@@ -132,12 +132,12 @@ def f(t,y):
yd_0 = y[1]
yd_1 = my*((1.-y[0]**2)*y[1]-y[0])
- return N.array([yd_0,yd_1])
+ return np.array([yd_0,yd_1])
def jac(t,y):
eps = 1.e-6
my = 1./eps
- J = N.zeros([2,2])
+ J = np.zeros([2,2])
J[0,0]=0.
J[0,1]=1.
@@ -149,7 +149,7 @@ def jac(t,y):
def jac_sparse(t,y):
eps = 1.e-6
my = 1./eps
- J = N.zeros([2,2])
+ J = np.zeros([2,2])
J[0,0]=0.
J[0,1]=1.
@@ -216,8 +216,8 @@ def test_readcommon(self):
This tests the LSODAR's subroutine dsrcar (read functionality).
"""
self.sim.simulate(1.) #Simulate 2 seconds
- r=N.ones((245,),'d')
- i=N.ones((55,),'i')
+ r=np.ones((245,),'d')
+ i=np.ones((55,),'i')
dsrcar(r,i,1)
nose.tools.assert_almost_equal(r[217], 2.22044605e-16, 20)
nose.tools.assert_equal(i[36], 3)
@@ -227,8 +227,8 @@ def test_writereadcommon(self):
"""
This tests the LSODAR's subroutine dsrcar (write and read functionality).
"""
- r=N.ones((245,),'d')
- i=N.ones((55,),'i')
+ r=np.ones((245,),'d')
+ i=np.ones((55,),'i')
dsrcar(r,i,2)
r[0]=100.
i[0]=10
@@ -243,24 +243,24 @@ def test_rkstarter(self):
"""
pass
"""
- A=N.array([[0.,1.],[-4.,0.]])
+ A=np.array([[0.,1.],[-4.,0.]])
def f(t,x,sw0):
- return N.dot(A,N.array(x))
+ return np.dot(A,np.array(x))
H = 1.e-8
# Compute the exact solution at h=0,H/4,H/2,3H/4,H
- T=N.array([0.,H/4.,H/2.,3./4.*H,H])
- y0=N.array([1.,0.])
+ T=np.array([0.,H/4.,H/2.,3./4.*H,H])
+ y0=np.array([1.,0.])
from scipy.linalg import expm
- exact=N.array([N.dot(expm(A*t),y0) for t in T])
+ exact=np.array([np.dot(expm(A*t),y0) for t in T])
#polynomial interpolation
from scipy import polyfit
coeff = polyfit(T,exact,4)
- d1coeff=N.array([4,3,2,1]).reshape(-1,1)*coeff[:-1,:]
- d2coeff=N.array([3,2,1]).reshape(-1,1)*d1coeff[:-1,:]
- d3coeff=N.array([2,1]).reshape(-1,1)*d2coeff[:-1,:]
- d4coeff=N.array([1]).reshape(-1,1)*d3coeff[:-1,:]
+ d1coeff=np.array([4,3,2,1]).reshape(-1,1)*coeff[:-1,:]
+ d2coeff=np.array([3,2,1]).reshape(-1,1)*d1coeff[:-1,:]
+ d3coeff=np.array([2,1]).reshape(-1,1)*d2coeff[:-1,:]
+ d4coeff=np.array([1]).reshape(-1,1)*d3coeff[:-1,:]
h=H/4.
- nordsieck_at_0=N.array([coeff[-1,:],h*d1coeff[-1,:],h**2/2.*d2coeff[-1,:],
+ nordsieck_at_0=np.array([coeff[-1,:],h*d1coeff[-1,:],h**2/2.*d2coeff[-1,:],
h**3/6.*d3coeff[-1,:],h**4/24.*d4coeff[-1,:]])
rkNordsieck=odepack.RKStarterNordsieck(f,H)
computed=rkNordsieck(0,y0)
@@ -274,7 +274,7 @@ def test_interpol(self):
t_sol,y_sol=self.sim.simulate(1.,ncp_list=[0.5])
self.sim.reset()
t_sol1,y_sol1=self.sim.simulate(0.5)
- ind05=N.nonzero(N.array(t_sol)==0.5)[0][0]
+ ind05=np.nonzero(np.array(t_sol)==0.5)[0][0]
nose.tools.assert_almost_equal(y_sol[ind05,0],y_sol1[-1,0],6)
@testattr(stddist = True)
diff --git a/tests/solvers/test_radau5.py b/tests/solvers/test_radau5.py
index a681eb57..2e5ca5d4 100644
--- a/tests/solvers/test_radau5.py
+++ b/tests/solvers/test_radau5.py
@@ -25,7 +25,7 @@
from assimulo.lib.radau_core import Radau_Exception
from assimulo.exception import TimeLimitExceeded
import scipy.sparse as sp
-import numpy as N
+import numpy as np
import re
float_regex = "[\s]*[\d]*.[\d]*((e|E)(\+|\-)\d\d|)"
@@ -63,14 +63,14 @@ def jac(self, t, y):
if self.jac_raise:
raise KeyboardInterrupt('jac')
else:
- return -N.eye(self.dim)
+ return -np.eye(self.dim)
def state_events(self,t,y,sw):
if self.event_raise:
self.n_e += 1
if self.n_e % self.event_n == 0:
raise KeyboardInterrupt('event')
- return N.ones(len(sw))
+ return np.ones(len(sw))
def handle_event(self, solver, event_info):
pass
@@ -80,8 +80,8 @@ class Extended_Problem(Explicit_Problem):
#Sets the initial conditions directly into the problem
y0 = [0.0, -1.0, 0.0]
sw0 = [False,True,True]
- event_array = N.array([0.0,0.0,0.0])
- rhs_array = N.array([0.0,0.0,0.0])
+ event_array = np.array([0.0,0.0,0.0])
+ rhs_array = np.array([0.0,0.0,0.0])
#The right-hand-side function (rhs)
def rhs(self,t,y,sw):
@@ -179,12 +179,12 @@ def f(t,y):
yd_0 = y[1]
yd_1 = my*((1.-y[0]**2)*y[1]-y[0])
- return N.array([yd_0,yd_1])
+ return np.array([yd_0,yd_1])
def jac(t,y):
eps = 1.e-6
my = 1./eps
- J = N.zeros([2,2])
+ J = np.zeros([2,2])
J[0,0]=0.
J[0,1]=1.
@@ -360,7 +360,7 @@ def test_maxh(self):
"""
self.sim.maxh = 0.01
self.sim.simulate(0.5)
- nose.tools.assert_less_equal(max(N.diff(self.sim.t_sol))-N.finfo('double').eps, 0.01)
+ nose.tools.assert_less_equal(max(np.diff(self.sim.t_sol))-np.finfo('double').eps, 0.01)
@testattr(stddist = True)
def test_newt(self):
@@ -438,12 +438,12 @@ def f(t,y):
yd_0 = y[1]
yd_1 = my*((1.-y[0]**2)*y[1]-y[0])
- return N.array([yd_0,yd_1])
+ return np.array([yd_0,yd_1])
def jac(t,y):
eps = 1.e-6
my = 1./eps
- J = N.zeros([2,2])
+ J = np.zeros([2,2])
J[0,0]=0.
J[0,1]=1.
@@ -455,7 +455,7 @@ def jac(t,y):
def jac_sparse(t,y):
eps = 1.e-6
my = 1./eps
- J = N.zeros([2,2])
+ J = np.zeros([2,2])
J[0,0]=0.
J[0,1]=1.
@@ -659,7 +659,7 @@ def test_maxh(self):
"""
self.sim.maxh = 0.01
self.sim.simulate(0.5)
- nose.tools.assert_less_equal(max(N.diff(self.sim.t_sol))-N.finfo('double').eps, 0.01)
+ nose.tools.assert_less_equal(max(np.diff(self.sim.t_sol))-np.finfo('double').eps, 0.01)
@testattr(stddist = True)
def test_newt(self):
@@ -744,8 +744,8 @@ def test_switches(self):
"""
This tests that the switches are actually turned when override.
"""
- f = lambda t,x,sw: N.array([1.0])
- state_events = lambda t,x,sw: N.array([x[0]-1.])
+ f = lambda t,x,sw: np.array([1.0])
+ state_events = lambda t,x,sw: np.array([x[0]-1.])
def handle_event(solver, event_info):
solver.sw = [False] #Override the switches to point to another instance
@@ -797,8 +797,8 @@ def test_repeated_unexpected_step_rejections(self):
This tests the error for repeated unexpected step rejections
"""
def f(t, y):
- raise N.linalg.LinAlgError()
- y0 = N.array([1.])
+ raise np.linalg.LinAlgError()
+ y0 = np.array([1.])
prob = Explicit_Problem(f, y0)
sim = Radau5ODE(prob)
@@ -812,7 +812,7 @@ def test_sparse_solver_jac_disabled(self):
This tests the trying to simulate using the sparse linear solver, with no analytical jacobian provided.
"""
f = lambda t, y: [y]
- y0 = N.array([1.])
+ y0 = np.array([1.])
prob = Explicit_Problem(f, y0)
sim = Radau5ODE(prob)
@@ -828,7 +828,7 @@ def test_solver_no_jac(self):
This tests the error when trying to simulate using an analytical jacobian, with none provided
"""
f = lambda t, y: [y]
- y0 = N.array([1.])
+ y0 = np.array([1.])
prob = Explicit_Problem(f, y0)
sim = Radau5ODE(prob)
@@ -845,7 +845,7 @@ def test_solver_sparse_jac_wrong_format(self):
"""
f = lambda t, y: [y]
jac = lambda t, y: sp.spdiags([1], 0, 1, 1, format = 'csr')
- y0 = N.array([1.])
+ y0 = np.array([1.])
prob = Explicit_Problem(f, y0)
prob.jac = jac
prob.jac_nnz = 1
@@ -865,8 +865,8 @@ def test_solver_sparse_jac_nnz_too_small(self):
"""
n = 5
f = lambda t, y: y
- jac = lambda t, y: sp.eye(n, n, dtype = N.double, format = 'csc')
- y0 = N.array([1.]*n)
+ jac = lambda t, y: sp.eye(n, n, dtype = np.double, format = 'csc')
+ y0 = np.array([1.]*n)
prob = Explicit_Problem(f, y0)
prob.jac = jac
prob.jac_nnz = 1
@@ -886,8 +886,8 @@ def test_solver_sparse_jac_nnz_zero(self):
"""
n = 5
f = lambda t, y: [0.]*n
- jac = lambda t, y: sp.csc_matrix((n, n), dtype = N.double)
- y0 = N.array([1.]*n)
+ jac = lambda t, y: sp.csc_matrix((n, n), dtype = np.double)
+ y0 = np.array([1.]*n)
prob = Explicit_Problem(f, y0)
prob.jac = jac
prob.jac_nnz = 0
@@ -905,7 +905,7 @@ def test_sparse_solver_no_nnz(self):
"""
f = lambda t, y: [y]
jac = lambda t, y: sp.spdiags([1], 0, 1, 1, format = 'csc')
- y0 = N.array([1.])
+ y0 = np.array([1.])
prob = Explicit_Problem(f, y0)
prob.jac = jac
@@ -924,7 +924,7 @@ def test_sparse_solver_invalid_nnz_type(self):
"""
f = lambda t, y: [y]
jac = lambda t, y: sp.spdiags([1], 0, 1, 1, format = 'csc')
- y0 = N.array([1.])
+ y0 = np.array([1.])
for nnz in [None, "test"]:
prob = Explicit_Problem(f, y0)
@@ -946,7 +946,7 @@ def test_sparse_solver_invalid_nnz_negative(self):
"""
f = lambda t, y: [y]
jac = lambda t, y: sp.spdiags([1], 0, 1, 1, format = 'csc')
- y0 = N.array([1.])
+ y0 = np.array([1.])
for nnz in [-2, -10]:
prob = Explicit_Problem(f, y0)
@@ -968,7 +968,7 @@ def test_sparse_solver_invalid_nnz_too_large(self):
"""
f = lambda t, y: [y]
jac = lambda t, y: sp.spdiags([1], 0, 1, 1, format = 'csc')
- y0 = N.array([1.])
+ y0 = np.array([1.])
for nnz in [5, 100]:
prob = Explicit_Problem(f, y0)
@@ -988,19 +988,19 @@ def test_sparse_solver_jacobian(self):
## Take trivial problem with somewhat arbitrary jacobians
## Test that functions for internal processing of jacobian do not produces segfaults
jacobians = [
- (lambda t, y: sp.csc_matrix(N.array([[1., 1., 1.], [1., 1., 1.], [1., 1., 1.]])), 9),
- (lambda t, y: sp.csc_matrix(N.array([[0., 1., 1.], [1., 0., 1.], [1., 1., 0.]])), 6),
- (lambda t, y: sp.csc_matrix(N.array([[0., 1., 1.], [1., 1., 1.], [1., 1., 1.]])), 8),
- (lambda t, y: sp.csc_matrix(N.array([[0., 0., 0.], [0., 1., 0.], [0., 0., 0.]])), 1),
- (lambda t, y: sp.csc_matrix(N.array([[0., 0., 0.], [1., 0., 0.], [0., 0., 0.]])), 1),
- (lambda t, y: sp.csc_matrix(N.array([[0., 0., 0.], [0., 0., 0.], [0., 1., 0.]])), 1),
- (lambda t, y: sp.csc_matrix(N.array([[0., 0., 1.], [0., 0., 0.], [0., 0., 0.]])), 1),
- (lambda t, y: sp.csc_matrix(N.array([[1., 0., 0.], [0., 0., 0.], [0., 0., 0.]])), 1),
+ (lambda t, y: sp.csc_matrix(np.array([[1., 1., 1.], [1., 1., 1.], [1., 1., 1.]])), 9),
+ (lambda t, y: sp.csc_matrix(np.array([[0., 1., 1.], [1., 0., 1.], [1., 1., 0.]])), 6),
+ (lambda t, y: sp.csc_matrix(np.array([[0., 1., 1.], [1., 1., 1.], [1., 1., 1.]])), 8),
+ (lambda t, y: sp.csc_matrix(np.array([[0., 0., 0.], [0., 1., 0.], [0., 0., 0.]])), 1),
+ (lambda t, y: sp.csc_matrix(np.array([[0., 0., 0.], [1., 0., 0.], [0., 0., 0.]])), 1),
+ (lambda t, y: sp.csc_matrix(np.array([[0., 0., 0.], [0., 0., 0.], [0., 1., 0.]])), 1),
+ (lambda t, y: sp.csc_matrix(np.array([[0., 0., 1.], [0., 0., 0.], [0., 0., 0.]])), 1),
+ (lambda t, y: sp.csc_matrix(np.array([[1., 0., 0.], [0., 0., 0.], [0., 0., 0.]])), 1),
]
for i, (jac, nnz) in enumerate(jacobians):
f = lambda t, y: y
- y0 = 1.*N.ones(3)
+ y0 = 1.*np.ones(3)
prob = Explicit_Problem(f, y0)
prob.jac = jac
prob.jac_nnz = nnz
@@ -1039,7 +1039,7 @@ def test_linear_solver(self):
def test_keyboard_interrupt_fcn(self):
"""Test that KeyboardInterrupts in right-hand side terminate the simulation. Radau5 + C + explicit problem."""
- y0 = N.array([1., 1.])
+ y0 = np.array([1., 1.])
aux = KeyboardInterruptAux(dim = len(y0), fcn = True)
prob = Explicit_Problem(aux.f, y0)
sim = Radau5ODE(prob)
@@ -1053,7 +1053,7 @@ def test_keyboard_interrupt_fcn(self):
def test_keyboard_interrupt_jac(self):
"""Test that KeyboardInterrupts in jacobian terminate the simulation. Radau5 + C + explicit problem."""
- y0 = N.array([1., 1.])
+ y0 = np.array([1., 1.])
aux = KeyboardInterruptAux(dim = len(y0), jac = True)
prob = Explicit_Problem(aux.f, y0)
prob.jac = aux.jac
@@ -1070,7 +1070,7 @@ def test_keyboard_interrupt_jac(self):
def test_keyboard_interrupt_jac_sparse(self):
"""Test that KeyboardInterrupts in jacobian terminate the simulation. Radau5 + C + explicit problem + sparse jac."""
- y0 = N.array([1., 1.])
+ y0 = np.array([1., 1.])
aux = KeyboardInterruptAux(dim = len(y0), jac = True)
prob = Explicit_Problem(aux.f, y0)
prob.jac = aux.jac
@@ -1089,9 +1089,9 @@ def test_keyboard_interrupt_jac_sparse(self):
def test_keyboard_interrupt_event_indicator(self):
"""Test that KeyboardInterrupts in event indicator function resp. solout callback correctly terminate solution."""
- y0 = N.array([1.])
+ y0 = np.array([1.])
aux = KeyboardInterruptAux(dim = len(y0), event = True, event_n = 3)
- prob = Explicit_Problem(aux.f, y0, sw0 = N.array([1.]))
+ prob = Explicit_Problem(aux.f, y0, sw0 = np.array([1.]))
prob.state_events = aux.state_events
prob.handle_event = aux.handle_event
sim = Radau5ODE(prob)
@@ -1168,7 +1168,7 @@ def f(t,y,yd):
res_0 = yd[0]-yd_0
res_1 = yd[1]-yd_1
- return N.array([res_0,res_1])
+ return np.array([res_0,res_1])
y0 = [2.0,-0.6] #Initial conditions
yd0 = [-.6,-200000.]
@@ -1232,7 +1232,7 @@ def test_simulate_explicit(self):
"""
Test a simulation of an explicit problem using Radau5DAE.
"""
- f = lambda t,y:N.array(-y)
+ f = lambda t,y:np.array(-y)
y0 = [1.0]
problem = Explicit_Problem(f,y0)
@@ -1242,7 +1242,7 @@ def test_simulate_explicit(self):
t,y = simulator.simulate(1.0)
- nose.tools.assert_almost_equal(float(y[-1]), float(N.exp(-1.0)),4)
+ nose.tools.assert_almost_equal(float(y[-1]), float(np.exp(-1.0)),4)
@testattr(stddist = True)
def test_time_event(self):
@@ -1347,15 +1347,15 @@ def test_maxh(self):
"""
self.sim.maxh = 0.01
self.sim.simulate(0.5)
- nose.tools.assert_less_equal(max(N.diff(self.sim.t_sol))-N.finfo('double').eps, 0.01)
+ nose.tools.assert_less_equal(max(np.diff(self.sim.t_sol))-np.finfo('double').eps, 0.01)
@testattr(stddist = True)
def test_switches(self):
"""
This tests that the switches are actually turned when override.
"""
- res = lambda t,x,xd,sw: N.array([1.0 - xd])
- state_events = lambda t,x,xd,sw: N.array([x[0]-1.])
+ res = lambda t,x,xd,sw: np.array([1.0 - xd])
+ state_events = lambda t,x,xd,sw: np.array([x[0]-1.])
def handle_event(solver, event_info):
solver.sw = [False] #Override the switches to point to another instance
@@ -1390,8 +1390,8 @@ def test_step_size_too_small(self):
This tests the error for too small step-sizes
"""
f = lambda t, y, yd: -y
- y0 = N.array([1.])
- yd0 = N.array([0.])
+ y0 = np.array([1.])
+ yd0 = np.array([0.])
prob = Implicit_Problem(f, y0, yd0)
@@ -1413,8 +1413,8 @@ def test_repeated_unexpected_step_rejections(self):
This tests the error for repeated unexpected step rejections in Radau5DAE.
"""
def f(t, y, yd):
- raise N.linalg.LinAlgError()
- prob = Implicit_Problem(f, N.array([1.]), N.array([1.]))
+ raise np.linalg.LinAlgError()
+ prob = Implicit_Problem(f, np.array([1.]), np.array([1.]))
sim = Radau5DAE(prob)
err_msg = f'Repeated unexpected step rejections.'
@@ -1440,7 +1440,7 @@ def f(t,y,yd):
res_0 = yd[0]-yd_0
res_1 = yd[1]-yd_1
- return N.array([res_0,res_1])
+ return np.array([res_0,res_1])
y0 = [2.0,-0.6] #Initial conditions
yd0 = [-.6,-200000.]
@@ -1561,14 +1561,14 @@ def test_maxh(self):
"""
self.sim.maxh = 0.01
self.sim.simulate(0.5)
- nose.tools.assert_less_equal(max(N.diff(self.sim.t_sol))-N.finfo('double').eps, 0.01)
+ nose.tools.assert_less_equal(max(np.diff(self.sim.t_sol))-np.finfo('double').eps, 0.01)
@testattr(stddist = True)
def test_keyboard_interrupt_fcn(self):
"""Test that KeyboardInterrupts in right-hand side terminate the simulation. Radau5 + C + implicit problem."""
- y0 = N.array([1., 1.])
- yd = N.array([0., 0.])
+ y0 = np.array([1., 1.])
+ yd = np.array([0., 0.])
aux = KeyboardInterruptAux(dim = len(y0), fcn = True)
prob = Implicit_Problem(aux.f_impl, y0, yd)
sim = Radau5DAE(prob)
diff --git a/tests/solvers/test_rosenbrock.py b/tests/solvers/test_rosenbrock.py
index 90ab6ee7..04cdc1b9 100644
--- a/tests/solvers/test_rosenbrock.py
+++ b/tests/solvers/test_rosenbrock.py
@@ -20,7 +20,7 @@
from assimulo.solvers.rosenbrock import RodasODE
from assimulo.problem import Explicit_Problem
from assimulo.exception import TimeLimitExceeded
-import numpy as N
+import numpy as np
import scipy.sparse as sp
float_regex = "[\s]*[\d]*.[\d]*((e|E)(\+|\-)\d\d|)"
@@ -34,19 +34,19 @@ def f(t,y):
yd_0 = y[1]
yd_1 = my*((1.-y[0]**2)*y[1]-y[0])
- return N.array([yd_0,yd_1])
+ return np.array([yd_0,yd_1])
#Define the jacobian
def jac(t,y):
eps = 1.e-6
my = 1./eps
- j = N.array([[0.0,1.0],[my*((-2.0*y[0])*y[1]-1.0), my*(1.0-y[0]**2)]])
+ j = np.array([[0.0,1.0],[my*((-2.0*y[0])*y[1]-1.0), my*(1.0-y[0]**2)]])
return j
def jac_sparse(t,y):
eps = 1.e-6
my = 1./eps
- J = N.zeros([2,2])
+ J = np.zeros([2,2])
J[0,0]=0.
J[0,1]=1.
diff --git a/tests/solvers/test_rungekutta.py b/tests/solvers/test_rungekutta.py
index 4882f4ca..0634242e 100644
--- a/tests/solvers/test_rungekutta.py
+++ b/tests/solvers/test_rungekutta.py
@@ -20,7 +20,7 @@
from assimulo.solvers.runge_kutta import Dopri5, RungeKutta34, RungeKutta4
from assimulo.problem import Explicit_Problem
from assimulo.exception import Explicit_ODE_Exception, TimeLimitExceeded
-import numpy as N
+import numpy as np
float_regex = "[\s]*[\d]*.[\d]*((e|E)(\+|\-)\d\d|)"
@@ -86,8 +86,8 @@ def test_switches(self):
"""
This tests that the switches are actually turned when override.
"""
- f = lambda t,x,sw: N.array([1.0])
- state_events = lambda t,x,sw: N.array([x[0]-1.])
+ f = lambda t,x,sw: np.array([1.0])
+ state_events = lambda t,x,sw: np.array([x[0]-1.])
def handle_event(solver, event_info):
solver.sw = [False] #Override the switches to point to another instance
@@ -217,8 +217,8 @@ def test_switches(self):
"""
This tests that the switches are actually turned when override.
"""
- f = lambda t,x,sw: N.array([1.0])
- state_events = lambda t,x,sw: N.array([x[0]-1.])
+ f = lambda t,x,sw: np.array([1.0])
+ state_events = lambda t,x,sw: np.array([x[0]-1.])
def handle_event(solver, event_info):
solver.sw = [False] #Override the switches to point to another instance
diff --git a/tests/test_examples.py b/tests/test_examples.py
index 18cd51cd..2e667481 100644
--- a/tests/test_examples.py
+++ b/tests/test_examples.py
@@ -15,7 +15,6 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import nose
from assimulo import testattr
from assimulo.exception import AssimuloException
from assimulo.examples import *
diff --git a/tests/test_solvers.py b/tests/test_solvers.py
index 156e083b..58543c82 100644
--- a/tests/test_solvers.py
+++ b/tests/test_solvers.py
@@ -19,7 +19,7 @@
import numpy as np
from assimulo import testattr
from assimulo.problem import Explicit_Problem, Implicit_Problem
-from assimulo.solvers import Radau5DAE, Radau5ODE, Dopri5, RodasODE
+from assimulo.solvers import Radau5DAE, Dopri5, RodasODE
def res(t,y,yd,sw):
return np.array([yd+y])