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..20c11264 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$')
@@ -57,13 +57,13 @@ def f(t,y):
#Plot
if with_plots:
- import pylab as P
- P.plot(t1, y1, color="b")
- P.plot(t2, y2, color="r")
- P.title(exp_mod.name)
- P.ylabel('y')
- P.xlabel('Time')
- P.show()
+ import pylab as pl
+ pl.plot(t1, y1, color="b")
+ pl.plot(t2, y2, color="r")
+ pl.title(exp_mod.name)
+ pl.ylabel('y')
+ pl.xlabel('Time')
+ pl.show()
#Basic test
nose.tools.assert_almost_equal(y2[-1][0], 0.00347746, 5)
diff --git a/examples/cvode_basic_backward.py b/examples/cvode_basic_backward.py
index c299a19c..c5454800 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$ ')
@@ -54,12 +54,12 @@ def f(t,y):
#Plot
if with_plots:
- import pylab as P
- P.plot(t, y, color="b")
- P.title(exp_mod.name)
- P.ylabel('y')
- P.xlabel('Time')
- P.show()
+ import pylab as pl
+ pl.plot(t, y, color="b")
+ pl.title(exp_mod.name)
+ pl.ylabel('y')
+ pl.xlabel('Time')
+ pl.show()
#Basic test
nose.tools.assert_almost_equal(y[-1][0], 4.00000000, 3)
diff --git a/examples/cvode_gyro.py b/examples/cvode_gyro.py
index 605a152f..eb9590a1 100644
--- a/examples/cvode_gyro.py
+++ b/examples/cvode_gyro.py
@@ -75,12 +75,12 @@ def f(t, u):
# Plot
if with_plots:
- import pylab as P
- P.plot(t, y/10000.)
- P.xlabel('Time')
- P.ylabel('States, scaled by $10^4$')
- P.title(exp_mod.name)
- P.show()
+ import pylab as pl
+ pl.plot(t, y/10000.)
+ pl.xlabel('Time')
+ pl.ylabel('States, scaled by $10^4$')
+ pl.title(exp_mod.name)
+ pl.show()
#Basic tests
nose.tools.assert_almost_equal(y[-1][0], 692.800241862)
diff --git a/examples/cvode_stability.py b/examples/cvode_stability.py
index 2a8b3bd2..4a7a7eaf 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
@@ -76,20 +76,20 @@ def f(t,y):
#Plot
if with_plots:
- import pylab as P
- P.subplot(211)
- P.plot(t,y[:,2])
- P.ylabel("State: $y_1$")
- P.subplot(212)
- P.plot(t,exp_mod.order)
- P.ylabel("Order")
- P.suptitle(exp_mod.name)
- P.xlabel("Time")
- P.show()
+ import pylab as pl
+ pl.subplot(211)
+ pl.plot(t,y[:,2])
+ pl.ylabel("State: $y_1$")
+ pl.subplot(212)
+ pl.plot(t,exp_mod.order)
+ pl.ylabel("Order")
+ pl.suptitle(exp_mod.name)
+ pl.xlabel("Time")
+ pl.show()
#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..1752b2cb 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.
@@ -148,12 +148,12 @@ def run_example(with_plots=True):
#Plot
if with_plots:
- import pylab as P
- P.plot(t,y)
- P.title(exp_mod.name)
- P.ylabel('States')
- P.xlabel('Time')
- P.show()
+ import pylab as pl
+ pl.plot(t,y)
+ pl.title(exp_mod.name)
+ pl.ylabel('States')
+ pl.xlabel('Time')
+ pl.show()
#Basic test
nose.tools.assert_almost_equal(y[-1][0],8.0)
diff --git a/examples/cvode_with_initial_sensitivity.py b/examples/cvode_with_initial_sensitivity.py
index 84c21858..848eeb16 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')
@@ -88,39 +88,39 @@ def f(t, y, p):
#Plot
if with_plots:
- import pylab as P
+ import pylab as pl
title_text=r"Sensitivity w.r.t. ${}$"
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.title(title_text.format('p_1'))
- P.legend((legend_text.format('y_1','p_1'),
+ pl.figure(1)
+ pl.subplot(221)
+ pl.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])
+ pl.title(title_text.format('p_1'))
+ pl.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.title(title_text.format('p_2'))
- P.legend((legend_text.format('y_2','p_1'),
+ pl.subplot(222)
+ pl.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])
+ pl.title(title_text.format('p_2'))
+ pl.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.title(title_text.format('p_3'))
- P.legend((legend_text.format('y_3','p_1'),
+ pl.subplot(223)
+ pl.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])
+ pl.title(title_text.format('p_3'))
+ pl.legend((legend_text.format('y_3','p_1'),
legend_text.format('y_3','p_2'),
legend_text.format('y_3','p_3')))
- P.subplot(224)
- P.title('ODE Solution')
- P.plot(t, y)
- P.suptitle(exp_mod.name)
- P.show()
+ pl.subplot(224)
+ pl.title('ODE Solution')
+ pl.plot(t, y)
+ pl.suptitle(exp_mod.name)
+ pl.show()
#Basic test
nose.tools.assert_almost_equal(y[-1][0], 1577.6552477, 5)
diff --git a/examples/cvode_with_jac.py b/examples/cvode_with_jac.py
index 8ca3c19e..7bb4d1fe 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
@@ -71,12 +70,12 @@ def jac(t,y):
#Plot
if with_plots:
- import pylab as P
- P.plot(t,y,linestyle="dashed",marker="o") #Plot the solution
- P.xlabel('Time')
- P.ylabel('State')
- P.title(exp_mod.name)
- P.show()
+ import pylab as pl
+ pl.plot(t,y,linestyle="dashed",marker="o") #Plot the solution
+ pl.xlabel('Time')
+ pl.ylabel('State')
+ pl.title(exp_mod.name)
+ pl.show()
#Basic tests
nose.tools.assert_almost_equal(y[-1][0],-121.75000000,4)
diff --git a/examples/cvode_with_jac_sparse.py b/examples/cvode_with_jac_sparse.py
index e4dd330c..ca0ccb6b 100644
--- a/examples/cvode_with_jac_sparse.py
+++ b/examples/cvode_with_jac_sparse.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 scipy.sparse as SP
+import numpy as np
+import scipy.sparse as sps
import nose
from assimulo.solvers import CVode
from assimulo.problem import Explicit_Problem
@@ -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):
@@ -59,7 +59,7 @@ def jac(t,y):
rowvals = [0, 1, 0, 1, 2, 0, 1]
data = [-0.04, 0.04, 1e4*y[2], -1e4*y[2]-6e7*y[1], 6e7*y[1], 1e4*y[1], -1e4*y[1]]
- J = SP.csc_matrix((data, rowvals, colptrs))
+ J = sps.csc_matrix((data, rowvals, colptrs))
return J
#Defines an Assimulo explicit problem
@@ -85,12 +85,12 @@ def jac(t,y):
#Plot
if with_plots:
- import pylab as P
- P.plot(t,y[:,1],linestyle="dashed",marker="o") #Plot the solution
- P.xlabel('Time')
- P.ylabel('State')
- P.title(exp_mod.name)
- P.show()
+ import pylab as pl
+ pl.plot(t,y[:,1],linestyle="dashed",marker="o") #Plot the solution
+ pl.xlabel('Time')
+ pl.ylabel('State')
+ pl.title(exp_mod.name)
+ pl.show()
#Basic tests
nose.tools.assert_almost_equal(y[-1][0],0.9851,3)
diff --git a/examples/cvode_with_jac_spgmr.py b/examples/cvode_with_jac_spgmr.py
index 0ddcb8ec..3914b901 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
@@ -77,12 +77,12 @@ def jacv(t,y,fy,v):
#Plot
if with_plots:
- import pylab as P
- P.plot(t,y)
- P.xlabel('Time')
- P.ylabel('State')
- P.title(exp_mod.name)
- P.show()
+ import pylab as pl
+ pl.plot(t,y)
+ pl.xlabel('Time')
+ pl.ylabel('State')
+ pl.title(exp_mod.name)
+ pl.show()
#Basic tests
nose.tools.assert_almost_equal(y[-1][0],-121.75000000,4)
diff --git a/examples/cvode_with_parameters.py b/examples/cvode_with_parameters.py
index 9388ce3e..9746e1ad 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
@@ -79,12 +79,12 @@ def f(t, y, p):
#Plot
if with_plots:
- import pylab as P
- P.plot(t, y)
- P.title(exp_mod.name)
- P.xlabel('Time')
- P.ylabel('State')
- P.show()
+ import pylab as pl
+ pl.plot(t, y)
+ pl.title(exp_mod.name)
+ pl.xlabel('Time')
+ pl.ylabel('State')
+ pl.show()
#Basic test
nose.tools.assert_almost_equal(y[-1][0], 9.05518032e-01, 4)
diff --git a/examples/cvode_with_parameters_fcn.py b/examples/cvode_with_parameters_fcn.py
index 8e1f95b5..ee6156bd 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
@@ -96,12 +96,12 @@ def fsens(t, y, s, p):
#Plot
if with_plots:
- import pylab as P
- P.plot(t, y)
- P.title(exp_mod.name)
- P.xlabel('Time')
- P.ylabel('State')
- P.show()
+ import pylab as pl
+ pl.plot(t, y)
+ pl.title(exp_mod.name)
+ pl.xlabel('Time')
+ pl.ylabel('State')
+ pl.show()
#Basic test
nose.tools.assert_almost_equal(y[-1][0], 9.05518032e-01, 4)
diff --git a/examples/cvode_with_parameters_modified.py b/examples/cvode_with_parameters_modified.py
index 2510c1ee..396b934c 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
@@ -77,12 +77,12 @@ def f(t, y, p):
#Plot
if with_plots:
- import pylab as P
- P.plot(t, y)
- P.xlabel('Time')
- P.ylabel('State')
- P.title(exp_mod.name)
- P.show()
+ import pylab as pl
+ pl.plot(t, y)
+ pl.xlabel('Time')
+ pl.ylabel('State')
+ pl.title(exp_mod.name)
+ pl.show()
#Basic test
nose.tools.assert_almost_equal(y[-1][0], 9.05518032e-01, 4)
diff --git a/examples/dasp3_basic.py b/examples/dasp3_basic.py
index 9561479b..eaa83eed 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,
@@ -91,13 +91,13 @@ def dzdt(t,y,z):
#Plot
if with_plots:
- import pylab as P
- P.semilogy(t, y, color="b")
- P.grid()
- P.title(exp_mod.name+r' $\varepsilon = \frac{1}{3} 10^{-3}$')
- P.xlabel('Time')
- P.ylabel('y')
- P.show()
+ import pylab as pl
+ pl.semilogy(t, y, color="b")
+ pl.grid()
+ pl.title(exp_mod.name+r' $\varepsilon = \frac{1}{3} 10^{-3}$')
+ pl.xlabel('Time')
+ pl.ylabel('y')
+ pl.show()
#Basic test
nose.tools.assert_almost_equal(y[-1,0], 10.860063849896818, 3)
diff --git a/examples/dopri5_basic.py b/examples/dopri5_basic.py
index 35d50b7b..413d6a48 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,
@@ -48,12 +48,12 @@ def f(t,y):
#Plot
if with_plots:
- import pylab as P
- P.plot(t,y)
- P.title(exp_mod.name)
- P.xlabel('Time')
- P.ylabel('State')
- P.show()
+ import pylab as pl
+ pl.plot(t,y)
+ pl.title(exp_mod.name)
+ pl.xlabel('Time')
+ pl.ylabel('State')
+ pl.show()
#Basic test
nose.tools.assert_almost_equal(y[-1][0],0.02695199,5)
diff --git a/examples/dopri5_with_disc.py b/examples/dopri5_with_disc.py
index 3d50ed45..5cf21136 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.
@@ -147,12 +147,12 @@ def run_example(with_plots=True):
#Plot
if with_plots:
- import pylab as P
- P.plot(t,y)
- P.title(exp_mod.name)
- P.ylabel('States')
- P.xlabel('Time')
- P.show()
+ import pylab as pl
+ pl.plot(t,y)
+ pl.title(exp_mod.name)
+ pl.ylabel('States')
+ pl.xlabel('Time')
+ pl.show()
#Basic test
nose.tools.assert_almost_equal(y[-1][0],8.0)
diff --git a/examples/euler_basic.py b/examples/euler_basic.py
index bb2b73aa..40de392d 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,
@@ -52,13 +52,13 @@ def f(t,y):
#Plot
if with_plots:
- import pylab as P
- P.plot(t1, y1, color="b")
- P.plot(t2, y2, color="r")
- P.title(exp_mod.name)
- P.ylabel('y')
- P.xlabel('Time')
- P.show()
+ import pylab as pl
+ pl.plot(t1, y1, color="b")
+ pl.plot(t2, y2, color="r")
+ pl.title(exp_mod.name)
+ pl.ylabel('y')
+ pl.xlabel('Time')
+ pl.show()
#Basic test
nose.tools.assert_almost_equal(y2[-1][0], 0.02628193)
diff --git a/examples/euler_vanderpol.py b/examples/euler_vanderpol.py
index a24c764b..d9212f5a 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
@@ -77,16 +77,16 @@ def jac(t,y):
#Plot
if with_plots:
- import pylab as P
- P.plot(t,y[:,0], marker='o')
- P.title(exp_mod.name)
- P.ylabel("State: $y_1$")
- P.xlabel("Time")
- P.show()
+ import pylab as pl
+ pl.plot(t,y[:,0], marker='o')
+ pl.title(exp_mod.name)
+ pl.ylabel("State: $y_1$")
+ pl.xlabel("Time")
+ pl.show()
#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..8707ecbc 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.
@@ -144,12 +144,12 @@ def run_example(with_plots=True):
#Plot
if with_plots:
- import pylab as P
- P.plot(t,y)
- P.title("Solution of a differential equation with discontinuities")
- P.ylabel('States')
- P.xlabel('Time')
- P.show()
+ import pylab as pl
+ pl.plot(t,y)
+ pl.title("Solution of a differential equation with discontinuities")
+ pl.ylabel('States')
+ pl.xlabel('Time')
+ pl.show()
#Basic test
nose.tools.assert_almost_equal(y[-1][0],8.0)
diff --git a/examples/glimda_vanderpol.py b/examples/glimda_vanderpol.py
index 3bf01976..834d5181 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.]
@@ -72,17 +72,17 @@ def f(t,y,yd):
#Plot
if with_plots:
- import pylab as P
- P.subplot(211)
- P.plot(t,y[:,0])#, marker='o')
- P.xlabel('Time')
- P.ylabel('State')
- P.subplot(212)
- P.plot(t,yd[:,0]*1.e-5)#, marker='o')
- P.xlabel('Time')
- P.ylabel('State derivatives scaled with $10^{-5}$')
- P.suptitle(imp_mod.name)
- P.show()
+ import pylab as pl
+ pl.subplot(211)
+ pl.plot(t,y[:,0])#, marker='o')
+ pl.xlabel('Time')
+ pl.ylabel('State')
+ pl.subplot(212)
+ pl.plot(t,yd[:,0]*1.e-5)#, marker='o')
+ pl.xlabel('Time')
+ pl.ylabel('State derivatives scaled with $10^{-5}$')
+ pl.suptitle(imp_mod.name)
+ pl.show()
#Basic test
x1 = y[:,0]
diff --git a/examples/ida_basic_backward.py b/examples/ida_basic_backward.py
index 7a34bb15..e7698879 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,
@@ -54,12 +54,12 @@ def f(t,y,yd):
#Plot
if with_plots:
- import pylab as P
- P.plot(t, y, color="b")
- P.xlabel('Time')
- P.ylabel('State')
- P.title(imp_mod.name)
- P.show()
+ import pylab as pl
+ pl.plot(t, y, color="b")
+ pl.xlabel('Time')
+ pl.ylabel('State')
+ pl.title(imp_mod.name)
+ pl.show()
#Basic test
nose.tools.assert_almost_equal(y[-1][0], 4.00000000, 3)
diff --git a/examples/ida_with_disc.py b/examples/ida_with_disc.py
index 152763a3..1905b66f 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.
@@ -150,12 +150,12 @@ def run_example(with_plots=True):
#Plot
if with_plots:
- import pylab as P
- P.plot(t,y)
- P.title(imp_mod.name)
- P.ylabel('States')
- P.xlabel('Time')
- P.show()
+ import pylab as pl
+ pl.plot(t,y)
+ pl.title(imp_mod.name)
+ pl.ylabel('States')
+ pl.xlabel('Time')
+ pl.show()
#Basic test
nose.tools.assert_almost_equal(y[-1][0],8.0)
diff --git a/examples/ida_with_initial_sensitivity.py b/examples/ida_with_initial_sensitivity.py
index bf3b3813..3081eb45 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
@@ -87,31 +87,31 @@ def f(t, y, yd,p):
#Plot
if with_plots:
- 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.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.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.title("Parameter p3")
- P.legend(("p3/dy1","p3/dy2","p3/dy3"))
- P.subplot(224)
- P.title('ODE Solution')
- P.plot(t, y)
- P.suptitle(imp_mod.name)
- P.show()
+ import pylab as pl
+ pl.figure(1)
+ pl.subplot(221)
+ pl.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])
+ pl.title("Parameter p1")
+ pl.legend(("p1/dy1","p1/dy2","p1/dy3"))
+ pl.subplot(222)
+ pl.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])
+ pl.title("Parameter p2")
+ pl.legend(("p2/dy1","p2/dy2","p2/dy3"))
+ pl.subplot(223)
+ pl.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])
+ pl.title("Parameter p3")
+ pl.legend(("p3/dy1","p3/dy2","p3/dy3"))
+ pl.subplot(224)
+ pl.title('ODE Solution')
+ pl.plot(t, y)
+ pl.suptitle(imp_mod.name)
+ pl.show()
#Basic test
nose.tools.assert_almost_equal(y[-1][0], 1577.6552477,3)
diff --git a/examples/ida_with_jac.py b/examples/ida_with_jac.py
index 577e54b9..9cfa3027 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
@@ -114,12 +114,12 @@ def jac(c,t,y,yd):
#Plot
if with_plots:
- import pylab as P
- P.plot(t,y,linestyle="dashed",marker="o") #Plot the solution
- P.xlabel('Time')
- P.ylabel('State')
- P.title(imp_mod.name)
- P.show()
+ import pylab as pl
+ pl.plot(t,y,linestyle="dashed",marker="o") #Plot the solution
+ pl.xlabel('Time')
+ pl.ylabel('State')
+ pl.title(imp_mod.name)
+ pl.show()
return imp_mod, imp_sim
diff --git a/examples/ida_with_jac_spgmr.py b/examples/ida_with_jac_spgmr.py
index 1db858de..4650a5ae 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]
@@ -83,12 +82,12 @@ def jacv(t,y,yd,res,v,c):
#Plot
if with_plots:
- import pylab as P
- P.plot(t,y)
- P.xlabel('Time')
- P.ylabel('State')
- P.title(imp_mod.name)
- P.show()
+ import pylab as pl
+ pl.plot(t,y)
+ pl.xlabel('Time')
+ pl.ylabel('State')
+ pl.title(imp_mod.name)
+ pl.show()
return imp_mod,imp_sim
if __name__=='__main__':
diff --git a/examples/ida_with_parameters.py b/examples/ida_with_parameters.py
index 4a7198be..6c5cc9f5 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
@@ -87,12 +87,12 @@ def f(t, y, yd, p):
#Plot
if with_plots:
- import pylab as P
- P.plot(t, y)
- P.title(imp_mod.name)
- P.xlabel('Time')
- P.ylabel('State')
- P.show()
+ import pylab as pl
+ pl.plot(t, y)
+ pl.title(imp_mod.name)
+ pl.xlabel('Time')
+ pl.ylabel('State')
+ pl.show()
return imp_mod, imp_sim
diff --git a/examples/ida_with_user_defined_handle_result.py b/examples/ida_with_user_defined_handle_result.py
index 09e76ad8..365305ec 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
@@ -92,19 +92,19 @@ def handle_result(solver, t ,y, yd):
#Plot
if with_plots:
- import pylab as P
- P.figure(1)
- P.plot(t,y,linestyle="dashed",marker="o") #Plot the solution
- P.xlabel('Time')
- P.ylabel('State')
- P.title(imp_mod.name)
+ import pylab as pl
+ pl.figure(1)
+ pl.plot(t,y,linestyle="dashed",marker="o") #Plot the solution
+ pl.xlabel('Time')
+ pl.ylabel('State')
+ pl.title(imp_mod.name)
- P.figure(2)
- P.plot([0] + N.add.accumulate(N.diff(t)).tolist(), order)
- P.title("Used order during the integration")
- P.xlabel("Time")
- P.ylabel("Order")
- P.show()
+ pl.figure(2)
+ pl.plot([0] + np.add.accumulate(np.diff(t)).tolist(), order)
+ pl.title("Used order during the integration")
+ pl.xlabel("Time")
+ pl.ylabel("Order")
+ pl.show()
#Basic tests
nose.tools.assert_almost_equal(y[-1][0],0.9401995, places=4)
diff --git a/examples/kinsol_ors.py b/examples/kinsol_ors.py
index e1744cee..29f263ab 100644
--- a/examples/kinsol_ors.py
+++ b/examples/kinsol_ors.py
@@ -15,19 +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
-import scipy.linalg as LIN
-import scipy.io as IO
-import scipy.sparse as SPARSE
-import scipy.sparse.linalg as LINSP
-import nose
import os
+import nose
+import numpy as np
+import scipy as sp
+import scipy.sparse as sps
from assimulo.solvers import KINSOL
from assimulo.problem import Algebraic_Problem
import warnings
-import scipy.sparse
-warnings.simplefilter("ignore", scipy.sparse.SparseEfficiencyWarning)
+warnings.simplefilter("ignore", sps.SparseEfficiencyWarning)
file_path = os.path.dirname(os.path.realpath(__file__))
@@ -39,25 +36,25 @@ def run_example(with_plots=True):
Iterative Methods for Sparse Linear Systems.
"""
#Read the original matrix
- A_original = IO.mmread(os.path.join(file_path,"kinsol_ors_matrix.mtx"))
+ A_original = sp.io.mmread(os.path.join(file_path,"kinsol_ors_matrix.mtx"))
#Scale the original matrix
- A = SPARSE.spdiags(1.0/A_original.diagonal(), 0, len(A_original.diagonal()), len(A_original.diagonal())) * A_original
+ A = sps.spdiags(1.0/A_original.diagonal(), 0, len(A_original.diagonal()), len(A_original.diagonal())) * A_original
#Preconditioning by Symmetric Gauss Seidel
if True:
- D = SPARSE.spdiags(A.diagonal(), 0, len(A_original.diagonal()), len(A_original.diagonal()))
- Dinv = SPARSE.spdiags(1.0/A.diagonal(), 0, len(A_original.diagonal()), len(A_original.diagonal()))
- E = -SPARSE.tril(A,k=-1)
- F = -SPARSE.triu(A,k=1)
+ D = sps.spdiags(A.diagonal(), 0, len(A_original.diagonal()), len(A_original.diagonal()))
+ Dinv = sps.spdiags(1.0/A.diagonal(), 0, len(A_original.diagonal()), len(A_original.diagonal()))
+ E = -sps.tril(A,k=-1)
+ F = -sps.triu(A,k=1)
L = (D-E).dot(Dinv)
U = D-F
Prec = L.dot(U)
- solvePrec = LINSP.factorized(Prec)
+ solvePrec = sps.linalg.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 +74,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')
@@ -91,7 +88,7 @@ def prec_solve(r):
def setup_param(solver):
solver.linear_solver = "spgmr"
solver.max_dim_krylov_subspace = 10
- solver.ftol = LIN.norm(res(solver.y0))*1e-9
+ solver.ftol = np.linalg.norm(res(solver.y0))*1e-9
solver.max_iter = 300
solver.verbosity = 10
solver.globalization_strategy = "none"
@@ -105,27 +102,27 @@ 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: ", np.linalg.norm(y-np.ones(len(y))))
+ print("Error (preconditioned), in y: ", np.linalg.norm(y_prec-np.ones(len(y_prec))))
if with_plots:
- import pylab as P
- P.figure(4)
- P.semilogy(alg_solver.get_residual_norm_nonlinear_iterations(), label="Original")
- P.semilogy(alg_solver_prec.get_residual_norm_nonlinear_iterations(), label='Preconditioned')
- P.xlabel("Number of Iterations")
- P.ylabel("Residual Norm")
- P.title("Solution Progress")
- P.legend()
- P.grid()
+ import pylab as pl
+ pl.figure(4)
+ pl.semilogy(alg_solver.get_residual_norm_nonlinear_iterations(), label="Original")
+ pl.semilogy(alg_solver_prec.get_residual_norm_nonlinear_iterations(), label='Preconditioned')
+ pl.xlabel("Number of Iterations")
+ pl.ylabel("Residual Norm")
+ pl.title("Solution Progress")
+ pl.legend()
+ pl.grid()
- P.figure(5)
- P.plot(y, label="Original")
- P.plot(y_prec, label="Preconditioned")
- P.legend()
- P.grid()
+ pl.figure(5)
+ pl.plot(y, label="Original")
+ pl.plot(y_prec, label="Preconditioned")
+ pl.legend()
+ pl.grid()
- P.show()
+ pl.show()
#Basic test
for j in range(len(y)):
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..775c7603 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.
@@ -132,23 +131,23 @@ def run_example(with_plots=True):
#Plot
if with_plots:
- import pylab as P
- P.subplot(221)
- P.plot(t,y)
- P.title('LSODAR Bouncing ball (one step mode)')
- P.ylabel('States: $y$ and $\dot y$')
- P.subplot(223)
- P.plot(exp_sim.t_sol,exp_sim.h_sol)
- P.title('LSODAR step size plot')
- P.xlabel('Time')
- P.ylabel('Sepsize')
- P.subplot(224)
- P.plot(exp_sim.t_sol,exp_sim.nq_sol)
- P.title('LSODAR order plot')
- P.xlabel('Time')
- P.ylabel('Order')
- P.suptitle(exp_mod.name)
- P.show()
+ import pylab as pl
+ pl.subplot(221)
+ pl.plot(t,y)
+ pl.title('LSODAR Bouncing ball (one step mode)')
+ pl.ylabel('States: $y$ and $\dot y$')
+ pl.subplot(223)
+ pl.plot(exp_sim.t_sol,exp_sim.h_sol)
+ pl.title('LSODAR step size plot')
+ pl.xlabel('Time')
+ pl.ylabel('Sepsize')
+ pl.subplot(224)
+ pl.plot(exp_sim.t_sol,exp_sim.nq_sol)
+ pl.title('LSODAR order plot')
+ pl.xlabel('Time')
+ pl.ylabel('Order')
+ pl.suptitle(exp_mod.name)
+ pl.show()
return exp_mod, exp_sim
if __name__=="__main__":
diff --git a/examples/lsodar_vanderpol.py b/examples/lsodar_vanderpol.py
index 1b35386d..ee86735d 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
@@ -66,16 +66,16 @@ def f(t,y):
#Plot
if with_plots:
- import pylab as P
- P.plot(t,y[:,0], marker='o')
- P.title(exp_mod.name)
- P.ylabel("State: $y_1$")
- P.xlabel("Time")
- P.show()
+ import pylab as pl
+ pl.plot(t,y[:,0], marker='o')
+ pl.title(exp_mod.name)
+ pl.ylabel("State: $y_1$")
+ pl.xlabel("Time")
+ pl.show()
#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..a2952485 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):
@@ -144,12 +144,12 @@ def run_example(with_plots=True):
#Plot
if with_plots:
- import pylab as P
- P.plot(t,y)
- P.title("Solution of a differential equation with discontinuities")
- P.ylabel('States')
- P.xlabel('Time')
- P.show()
+ import pylab as pl
+ pl.plot(t,y)
+ pl.title("Solution of a differential equation with discontinuities")
+ pl.ylabel('States')
+ pl.xlabel('Time')
+ pl.show()
#Basic test
nose.tools.assert_almost_equal(y[-1][0],8.0)
diff --git a/examples/mech_system_pendulum.py b/examples/mech_system_pendulum.py
index 3a632f70..852b2e11 100644
--- a/examples/mech_system_pendulum.py
+++ b/examples/mech_system_pendulum.py
@@ -15,37 +15,35 @@
# 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 nose
-import scipy.linalg as sl
+import numpy as np
+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()
@@ -59,10 +57,10 @@ def run_example(index="ind1", with_plots=True, with_test=False):
final_residual=my_pend.res(0.,dae_pend.y,dae_pend.yd)
print(my_pend.name+" Residuals after the integration run\n")
- print(final_residual, 'Norm: ', sl.norm(final_residual))
+ print(final_residual, 'Norm: ', np.linalg.norm(final_residual))
if with_test:
- nose.tools.assert_less(sl.norm(final_residual), 1.5e-1)
+ nose.tools.assert_less(np.linalg.norm(final_residual), 1.5e-1)
if with_plots:
dae_pend.plot(mask=[1,1]+(len(my_pend.y0)-2)*[0])
return my_pend, dae_pend
diff --git a/examples/radau5dae_time_events.py b/examples/radau5dae_time_events.py
index c61ee2b9..b4b69dd2 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]
@@ -65,16 +64,16 @@ def run_example(with_plots=True):
#Plot
if with_plots:
- import pylab as P
- P.plot(t,y[:,0], marker='o')
- P.xlabel('Time')
- P.ylabel('State')
- P.title(imp_mod.name)
- P.show()
+ import pylab as pl
+ pl.plot(t,y[:,0], marker='o')
+ pl.xlabel('Time')
+ pl.ylabel('State')
+ pl.title(imp_mod.name)
+ pl.show()
#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..ea5612ce 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.]
@@ -72,21 +72,21 @@ def f(t,y,yd):
#Plot
if with_plots:
- import pylab as P
- P.subplot(211)
- P.plot(t,y[:,0])#, marker='o')
- P.xlabel('Time')
- P.ylabel('State')
- P.subplot(212)
- P.plot(t,yd[:,0]*1.e-5)#, marker='o')
- P.xlabel('Time')
- P.ylabel('State derivatives scaled with $10^{-5}$')
- P.suptitle(imp_mod.name)
- P.show()
+ import pylab as pl
+ pl.subplot(211)
+ pl.plot(t,y[:,0])#, marker='o')
+ pl.xlabel('Time')
+ pl.ylabel('State')
+ pl.subplot(212)
+ pl.plot(t,yd[:,0]*1.e-5)#, marker='o')
+ pl.xlabel('Time')
+ pl.ylabel('State derivatives scaled with $10^{-5}$')
+ pl.suptitle(imp_mod.name)
+ pl.show()
#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..bbc852f9 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
@@ -67,16 +67,16 @@ def f(t,y):
#Plot
if with_plots:
- import pylab as P
- P.plot(t,y[:,0])#, marker='o')
- P.xlabel('Time')
- P.ylabel('State')
- P.title(exp_mod.name)
- P.show()
+ import pylab as pl
+ pl.plot(t,y[:,0])#, marker='o')
+ pl.xlabel('Time')
+ pl.ylabel('State')
+ pl.title(exp_mod.name)
+ pl.show()
#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..544c34f7 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):
@@ -141,12 +140,12 @@ def run_example(with_plots=True):
#Plot
if with_plots:
- import pylab as P
- P.plot(t,y)
- P.title("Solution of a differential equation with discontinuities")
- P.ylabel('States')
- P.xlabel('Time')
- P.show()
+ import pylab as pl
+ pl.plot(t,y)
+ pl.title("Solution of a differential equation with discontinuities")
+ pl.ylabel('States')
+ pl.xlabel('Time')
+ pl.show()
return exp_mod, exp_sim
diff --git a/examples/radau5ode_with_disc_sparse.py b/examples/radau5ode_with_disc_sparse.py
index 3a994040..9ef1d6f3 100644
--- a/examples/radau5ode_with_disc_sparse.py
+++ b/examples/radau5ode_with_disc_sparse.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 scipy.sparse as sp
+import numpy as np
+import scipy.sparse as sps
import nose
from assimulo.solvers import Radau5ODE
from assimulo.problem import Explicit_Problem
@@ -51,10 +51,10 @@ 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')
+ return sps.csc_matrix((len(y), len(y)), dtype = 'float')
jac_nnz = 0
@@ -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.
@@ -148,12 +148,12 @@ def run_example(with_plots=True):
#Plot
if with_plots:
- import pylab as P
- P.plot(t,y)
- P.title("Solution of a differential equation with discontinuities")
- P.ylabel('States')
- P.xlabel('Time')
- P.show()
+ import pylab as pl
+ pl.plot(t,y)
+ pl.title("Solution of a differential equation with discontinuities")
+ pl.ylabel('States')
+ pl.xlabel('Time')
+ pl.show()
return exp_mod, exp_sim
diff --git a/examples/radau5ode_with_jac_sparse.py b/examples/radau5ode_with_jac_sparse.py
index 3fece4d3..633f0535 100644
--- a/examples/radau5ode_with_jac_sparse.py
+++ b/examples/radau5ode_with_jac_sparse.py
@@ -15,9 +15,9 @@
# 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 scipy.sparse as SP
import nose
+import numpy as np
+import scipy.sparse as sps
from assimulo.solvers import Radau5ODE
from assimulo.problem import Explicit_Problem
@@ -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):
@@ -57,7 +57,7 @@ def jac(t,y):
rowvals = [0, 1, 0, 1, 2, 0, 1]
data = [-0.04, 0.04, 1e4*y[2], -1e4*y[2]-6e7*y[1], 6e7*y[1], 1e4*y[1], -1e4*y[1]]
- J = SP.csc_matrix((data, rowvals, colptrs))
+ J = sps.csc_matrix((data, rowvals, colptrs))
return J
#Defines an Assimulo explicit problem
@@ -81,12 +81,12 @@ def jac(t,y):
#Plot
if with_plots:
- import pylab as P
- P.plot(t,y[:,1],linestyle="dashed",marker="o") #Plot the solution
- P.xlabel('Time')
- P.ylabel('State')
- P.title(exp_mod.name)
- P.show()
+ import pylab as pl
+ pl.plot(t,y[:,1],linestyle="dashed",marker="o") #Plot the solution
+ pl.xlabel('Time')
+ pl.ylabel('State')
+ pl.title(exp_mod.name)
+ pl.show()
#Basic tests
nose.tools.assert_almost_equal(y[-1][0], 0.9851, 3)
diff --git a/examples/rodasode_vanderpol.py b/examples/rodasode_vanderpol.py
index ca0e37d5..61da426b 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
@@ -76,17 +76,17 @@ def jac(t,y):
#Plot
if with_plots:
- import pylab as P
- P.plot(t,y[:,0], marker='o')
- P.title(exp_mod.name)
- P.ylabel("State: $y_1$")
- P.xlabel("Time")
- P.show()
+ import pylab as pl
+ pl.plot(t,y[:,0], marker='o')
+ pl.title(exp_mod.name)
+ pl.ylabel("State: $y_1$")
+ pl.xlabel("Time")
+ pl.show()
#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..fea7749f 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,
@@ -53,12 +53,12 @@ def f(t,y):
#Plot
if with_plots:
- import pylab as P
- P.plot(t, y)
- P.title(exp_mod.name)
- P.ylabel('y')
- P.xlabel('Time')
- P.show()
+ import pylab as pl
+ pl.plot(t, y)
+ pl.title(exp_mod.name)
+ pl.ylabel('y')
+ pl.xlabel('Time')
+ pl.show()
return exp_mod, exp_sim
diff --git a/examples/rungekutta34_with_disc.py b/examples/rungekutta34_with_disc.py
index 21bae04f..97e222b7 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.
@@ -142,12 +142,12 @@ def run_example(with_plots=True):
#Plot
if with_plots:
- import pylab as P
- P.plot(t,y)
- P.title(exp_mod.name)
- P.ylabel('States')
- P.xlabel('Time')
- P.show()
+ import pylab as pl
+ pl.plot(t,y)
+ pl.title(exp_mod.name)
+ pl.ylabel('States')
+ pl.xlabel('Time')
+ pl.show()
return exp_mod, exp_sim
diff --git a/examples/rungekutta4_basic.py b/examples/rungekutta4_basic.py
index 4a3a7473..cb009129 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,
@@ -53,12 +53,12 @@ def f(t,y):
#Plot
if with_plots:
- import pylab as P
- P.plot(t, y)
- P.title(exp_mod.name)
- P.ylabel('y')
- P.xlabel('Time')
- P.show()
+ import pylab as pl
+ pl.plot(t, y)
+ pl.title(exp_mod.name)
+ pl.ylabel('y')
+ pl.xlabel('Time')
+ pl.show()
return exp_mod, exp_sim
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..cb274518 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 = (