diff --git a/setup.py b/setup.py index bf61545a..ac18bc73 100644 --- a/setup.py +++ b/setup.py @@ -176,8 +176,8 @@ def fortran_compiler_flags(self): logging.debug('Platform {}'.format(self.platform)) if args[0].sundials_home: - self.incdirs = os.path.join(self.sundialsdir,'include') - self.libdirs = os.path.join(self.sundialsdir,'lib') + self.incdirs = os.path.join(self.sundialsdir, 'include') + self.libdirs = os.path.join(self.sundialsdir, 'lib') elif 'win' in self.platform: self.incdirs = '' self.libdirs = '' @@ -420,7 +420,7 @@ def check_SUNDIALS(self): break if os.path.exists(os.path.join(self.libdirs,'sundials_nvecserial.lib')) and not os.path.exists(os.path.join(self.libdirs,'libsundials_nvecserial.a')): sundials_with_msvc = True - except Exception as e: + except Exception: if os.path.exists(os.path.join(os.path.join(self.incdirs,'arkode'), 'arkode.h')): #This was added in 2.6 sundials_version = (2,6,0) logging.debug('SUNDIALS 2.6 found.') diff --git a/src/algebraic.pyx b/src/algebraic.pyx index e8d33ddf..c0c9dd0f 100644 --- a/src/algebraic.pyx +++ b/src/algebraic.pyx @@ -21,8 +21,8 @@ import numpy as N cimport numpy as N from timeit import default_timer as timer -from exception import Algebraic_Exception, AssimuloException -from problem import Algebraic_Problem +from assimulo.exception import Algebraic_Exception, AssimuloException +from assimulo.problem import Algebraic_Problem include "constants.pxi" #Includes the constants (textual include) diff --git a/src/explicit_ode.pyx b/src/explicit_ode.pyx index 1ddc843d..b2c3c1c4 100644 --- a/src/explicit_ode.pyx +++ b/src/explicit_ode.pyx @@ -25,7 +25,7 @@ import numpy as N cimport numpy as N from timeit import default_timer as timer -from assimulo.ode cimport ODE +from assimulo.ode cimport ODE from assimulo.explicit_ode cimport Explicit_ODE, f_event_locator from assimulo.problem import Explicit_Problem, Delay_Explicit_Problem, SingPerturbed_Problem, cExplicit_Problem diff --git a/src/implicit_ode.pxd b/src/implicit_ode.pxd index 9cdbd392..ccea18ad 100644 --- a/src/implicit_ode.pxd +++ b/src/implicit_ode.pxd @@ -15,12 +15,10 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . - -from ode cimport ODE import numpy as N cimport numpy as N +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) - diff --git a/src/implicit_ode.pyx b/src/implicit_ode.pyx index bfee9af7..b24501bb 100644 --- a/src/implicit_ode.pyx +++ b/src/implicit_ode.pyx @@ -17,18 +17,16 @@ # distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION -from ode cimport ODE -from problem import Implicit_Problem, cImplicit_Problem, Overdetermined_Problem -from problem import cExplicit_Problem - import itertools import sys +import warnings import numpy as N cimport numpy as N - -from exception import TerminateSimulation, TimeLimitExceeded from timeit import default_timer as timer -import warnings + +from assimulo.ode cimport ODE +from assimulo.problem import Implicit_Problem, cExplicit_Problem, cImplicit_Problem, Overdetermined_Problem +from assimulo.exception import TerminateSimulation, TimeLimitExceeded realtype = float diff --git a/src/lib/sundials_callbacks.pxi b/src/lib/sundials_callbacks.pxi index 65ee2aab..7f42ef03 100644 --- a/src/lib/sundials_callbacks.pxi +++ b/src/lib/sundials_callbacks.pxi @@ -21,7 +21,7 @@ import cython # Module functions #================= -cdef N_Vector N_VNewEmpty_Euclidean(long int n): +cdef N_Vector N_VNewEmpty_Euclidean(long int n) noexcept: IF SUNDIALS_VERSION >= (6,0,0): cdef SUNDIALS.SUNContext ctx = NULL cdef void * comm = NULL @@ -32,7 +32,7 @@ cdef N_Vector N_VNewEmpty_Euclidean(long int n): v.ops.nvwrmsnorm = v.ops.nvwl2norm #Overwrite the WRMS norm to the 2-Norm return v -cdef inline N_Vector arr2nv(x): +cdef inline N_Vector arr2nv(x) noexcept: x=N.array(x) cdef long int n = len(x) cdef N.ndarray[realtype, ndim=1,mode='c'] ndx=x @@ -47,7 +47,7 @@ cdef inline N_Vector arr2nv(x): memcpy((v.content).data, data_ptr, n*sizeof(realtype)) return v -cdef inline N_Vector arr2nv_euclidean(x): +cdef inline N_Vector arr2nv_euclidean(x) noexcept: x=N.array(x) cdef long int n = len(x) cdef N.ndarray[realtype, ndim=1,mode='c'] ndx=x @@ -56,33 +56,33 @@ cdef inline N_Vector arr2nv_euclidean(x): memcpy((v.content).data, data_ptr, n*sizeof(realtype)) return v -cdef inline void arr2nv_inplace(x, N_Vector out): +cdef inline void arr2nv_inplace(x, N_Vector out) noexcept: x=N.array(x) cdef long int n = len(x) cdef N.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): +cdef inline N.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) memcpy(PyArray_DATA(x), v_data, n*sizeof(realtype)) return x -cdef inline void nv2arr_inplace(N_Vector v, N.ndarray o): +cdef inline void nv2arr_inplace(N_Vector v, N.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): +cdef inline void nv2mat_inplace(int Ns, N_Vector *v, N.ndarray o) noexcept: cdef long int i,j, Nf for i in range(Ns): Nf = (v[i].content).length for j in range(Nf): o[j,i] = (v[i].content).data[j] -cdef inline realtype2arr(realtype *data, int n): +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) memcpy(PyArray_DATA(x), data, n*sizeof(realtype)) diff --git a/src/lib/sundials_callbacks_ida_cvode.pxi b/src/lib/sundials_callbacks_ida_cvode.pxi index b9a07820..eaa776cb 100644 --- a/src/lib/sundials_callbacks_ida_cvode.pxi +++ b/src/lib/sundials_callbacks_ida_cvode.pxi @@ -19,7 +19,7 @@ import cython import traceback from assimulo.exception import AssimuloRecoverableError -cdef int cv_rhs(realtype t, N_Vector yv, N_Vector yvdot, void* problem_data): +cdef int cv_rhs(realtype t, N_Vector yv, N_Vector yvdot, void* problem_data) noexcept: """ This method is used to connect the Assimulo.Problem.f to the Sundials right-hand-side function. @@ -57,7 +57,7 @@ cdef int cv_rhs(realtype t, N_Vector yv, N_Vector yvdot, void* problem_data): cdef int cv_sens_rhs_all(int Ns, realtype t, N_Vector yv, N_Vector yvdot, N_Vector *yvS, N_Vector *yvSdot, void *problem_data, - N_Vector tmp1, N_Vector tmp2): + N_Vector tmp1, N_Vector tmp2) noexcept: cdef ProblemData pData = problem_data cdef N.ndarray y = pData.work_y @@ -92,7 +92,7 @@ IF SUNDIALS_VERSION >= (3,0,0): @cython.boundscheck(False) @cython.wraparound(False) cdef int cv_jac_sparse(realtype t, N_Vector yv, N_Vector fy, SUNMatrix Jac, - void *problem_data, N_Vector tmp1, N_Vector tmp2, N_Vector tmp3): + void *problem_data, N_Vector tmp1, N_Vector tmp2, N_Vector tmp3) noexcept: """ This method is used to connect the Assimulo.Problem.jac to the Sundials Sparse Jacobian function. @@ -146,7 +146,7 @@ ELSE: @cython.boundscheck(False) @cython.wraparound(False) cdef int cv_jac_sparse(realtype t, N_Vector yv, N_Vector fy, SlsMat Jacobian, - void *problem_data, N_Vector tmp1, N_Vector tmp2, N_Vector tmp3): + void *problem_data, N_Vector tmp1, N_Vector tmp2, N_Vector tmp3) noexcept: """ This method is used to connect the Assimulo.Problem.jac to the Sundials Sparse Jacobian function. @@ -213,7 +213,7 @@ ELSE: IF SUNDIALS_VERSION >= (3,0,0): cdef int cv_jac(realtype t, N_Vector yv, N_Vector fy, SUNMatrix Jac, - void *problem_data, N_Vector tmp1, N_Vector tmp2, N_Vector tmp3): + void *problem_data, N_Vector tmp1, N_Vector tmp2, N_Vector tmp3) noexcept: """ This method is used to connect the Assimulo.Problem.jac to the Sundials Jacobian function. @@ -264,7 +264,7 @@ IF SUNDIALS_VERSION >= (3,0,0): return CVDLS_SUCCESS ELSE: cdef int cv_jac(long int Neq, realtype t, N_Vector yv, N_Vector fy, DlsMat Jacobian, - void *problem_data, N_Vector tmp1, N_Vector tmp2, N_Vector tmp3): + void *problem_data, N_Vector tmp1, N_Vector tmp2, N_Vector tmp3) noexcept: """ This method is used to connect the Assimulo.Problem.jac to the Sundials Jacobian function. @@ -315,7 +315,7 @@ ELSE: cdef int cv_jacv(N_Vector vv, N_Vector Jv, realtype t, N_Vector yv, N_Vector fyv, - void *problem_data, N_Vector tmp): + void *problem_data, N_Vector tmp) noexcept: """ This method is used to connect the Assimulo.Problem.jacv to the Sundials Jacobian times vector function. @@ -365,7 +365,7 @@ cdef int cv_jacv(N_Vector vv, N_Vector Jv, realtype t, N_Vector yv, N_Vector fyv IF SUNDIALS_VERSION >= (3,0,0): cdef int cv_prec_setup(realtype t, N_Vector yy, N_Vector fyy, bint jok, bint *jcurPtr, - realtype gamma, void *problem_data): + realtype gamma, void *problem_data) noexcept: """ For information see CVODES documentation 4.6.9 """ @@ -387,7 +387,7 @@ IF SUNDIALS_VERSION >= (3,0,0): cdef int cv_prec_solve(realtype t, N_Vector yy, N_Vector fyy, N_Vector rr, N_Vector z, realtype gamma, realtype delta, - int lr, void *problem_data): + int lr, void *problem_data) noexcept: """ For information see CVODES documentation 4.6.8 """ @@ -412,7 +412,7 @@ ELSE: bint jok, bint *jcurPtr, realtype gamma, void *problem_data, N_Vector tmp1, N_Vector tmp2, - N_Vector tmp3): + N_Vector tmp3) noexcept: """ For information see CVODES documentation 4.6.9 """ @@ -434,7 +434,7 @@ ELSE: cdef int cv_prec_solve(realtype t, N_Vector yy, N_Vector fyy, N_Vector rr, N_Vector z, realtype gamma, realtype delta, - int lr, void *problem_data, N_Vector tmp): + int lr, void *problem_data, N_Vector tmp) noexcept: """ For information see CVODES documentation 4.6.8 """ @@ -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 y = nv2arr(yv) cdef N.ndarray fy = nv2arr(fyv) - cdef N.ndarray r = nv2arr(rv) + cdef N.ndarray r = nv2arr(rv) cdef int i cdef realtype* zptr=(z.content).data @@ -480,7 +480,7 @@ cdef int cv_prec(realtype t, N Vector yv, N Vector fyv, return SPGMR_PSOLVE_FAIL_UNREC """ -cdef int cv_root(realtype t, N_Vector yv, realtype *gout, void* problem_data): +cdef int cv_root(realtype t, N_Vector yv, realtype *gout, void* problem_data) noexcept: """ This method is used to connect the Assimulo.Problem.state_events to the Sundials Root-finding function. @@ -503,9 +503,9 @@ cdef int cv_root(realtype t, N_Vector yv, realtype *gout, void* problem_data): return CV_SUCCESS except Exception: - return CV_RTFUNC_FAIL # Unrecoverable Error + return CV_RTFUNC_FAIL # Unrecoverable Error -cdef int ida_res(realtype t, N_Vector yv, N_Vector yvdot, N_Vector residual, void* problem_data): +cdef int ida_res(realtype t, N_Vector yv, N_Vector yvdot, N_Vector residual, void* problem_data) noexcept: """ This method is used to connect the Assimulo.Problem.f to the Sundials residual function. @@ -559,7 +559,7 @@ cdef int ida_res(realtype t, N_Vector yv, N_Vector yvdot, N_Vector residual, voi IF SUNDIALS_VERSION >= (3,0,0): cdef int ida_jac(realtype t, realtype c, N_Vector yv, N_Vector yvdot, N_Vector residual, SUNMatrix Jac, - void *problem_data, N_Vector tmp1, N_Vector tmp2, N_Vector tmp3): + void *problem_data, N_Vector tmp1, N_Vector tmp2, N_Vector tmp3) noexcept: """ This method is used to connect the Assimulo.Problem.jac to the Sundials Jacobian function. @@ -612,7 +612,7 @@ IF SUNDIALS_VERSION >= (3,0,0): return IDADLS_JACFUNC_UNRECVR ELSE: cdef int ida_jac(long int Neq, realtype t, realtype c, N_Vector yv, N_Vector yvdot, N_Vector residual, DlsMat Jacobian, - void* problem_data, N_Vector tmp1, N_Vector tmp2, N_Vector tmp3): + void* problem_data, N_Vector tmp1, N_Vector tmp2, N_Vector tmp3) noexcept: """ This method is used to connect the Assimulo.Problem.jac to the Sundials Jacobian function. @@ -664,7 +664,7 @@ ELSE: return IDADLS_JACFUNC_UNRECVR -cdef int ida_root(realtype t, N_Vector yv, N_Vector yvdot, realtype *gout, void* problem_data): +cdef int ida_root(realtype t, N_Vector yv, N_Vector yvdot, realtype *gout, void* problem_data) noexcept: """ This method is used to connect the Assimulo.Problem.state_events to the Sundials root function. @@ -693,7 +693,7 @@ cdef int ida_root(realtype t, N_Vector yv, N_Vector yvdot, realtype *gout, void return IDA_RTFUNC_FAIL # Unrecoverable Error cdef int ida_jacv(realtype t, N_Vector yy, N_Vector yp, N_Vector rr, N_Vector vv, N_Vector Jv, realtype cj, - void *problem_data, N_Vector tmp1, N_Vector tmp2): + void *problem_data, N_Vector tmp1, N_Vector tmp2) noexcept: """ This method is used to connect the Assimulo.Problem.jacv to the Sundials Jacobian times vector function. @@ -744,7 +744,7 @@ cdef int ida_jacv(realtype t, N_Vector yy, N_Vector yp, N_Vector rr, N_Vector vv # Error handling callback functions # ================================= -cdef void cv_err(int error_code, const char *module, const char *function, char *msg, void *problem_data): +cdef void cv_err(int error_code, const char *module, const char *function, char *msg, void *problem_data) noexcept: """ This method overrides the default handling of error messages. """ @@ -757,7 +757,7 @@ cdef void cv_err(int error_code, const char *module, const char *function, char if error_code < 0: #Error print('[CVode Error]', msg) -cdef void ida_err(int error_code, const char *module, const char *function, char *msg, void *problem_data): +cdef void ida_err(int error_code, const char *module, const char *function, char *msg, void *problem_data) noexcept: """ This method overrides the default handling of error messages. """ diff --git a/src/lib/sundials_callbacks_kinsol.pxi b/src/lib/sundials_callbacks_kinsol.pxi index db2a17d1..ab5a497d 100644 --- a/src/lib/sundials_callbacks_kinsol.pxi +++ b/src/lib/sundials_callbacks_kinsol.pxi @@ -21,7 +21,7 @@ from assimulo.exception import AssimuloRecoverableError IF SUNDIALS_VERSION >= (3,0,0): cdef int kin_jac(N_Vector xv, N_Vector fval, SUNMatrix Jac, - void *problem_data, N_Vector tmp1, N_Vector tmp2): + void *problem_data, N_Vector tmp1, N_Vector tmp2) noexcept: """ This method is used to connect the assimulo.Problem.jac to the Sundials Jacobian function. @@ -45,7 +45,7 @@ IF SUNDIALS_VERSION >= (3,0,0): return KINDLS_JACFUNC_RECVR #Recoverable Error (See Sundials description) ELSE: cdef int kin_jac(long int Neq, N_Vector xv, N_Vector fval, DlsMat Jacobian, - void *problem_data, N_Vector tmp1, N_Vector tmp2): + void *problem_data, N_Vector tmp1, N_Vector tmp2) noexcept: """ This method is used to connect the assimulo.Problem.jac to the Sundials Jacobian function. @@ -68,7 +68,7 @@ ELSE: return KINDLS_JACFUNC_RECVR #Recoverable Error (See Sundials description) cdef int kin_jacv(N_Vector vv, N_Vector Jv, N_Vector vx, int* new_u, - void *problem_data): + void *problem_data) noexcept: cdef ProblemDataEquationSolver pData = problem_data cdef N.ndarray x = nv2arr(vx) cdef N.ndarray v = nv2arr(vv) @@ -89,7 +89,7 @@ cdef int kin_jacv(N_Vector vv, N_Vector Jv, N_Vector vx, int* new_u, traceback.print_exc() return SPGMR_PSOLVE_FAIL_UNREC -cdef int kin_res(N_Vector xv, N_Vector fval, void *problem_data): +cdef int kin_res(N_Vector xv, N_Vector fval, void *problem_data) noexcept: """ Residual fct called by KINSOL """ @@ -114,7 +114,7 @@ cdef int kin_res(N_Vector xv, N_Vector fval, void *problem_data): IF SUNDIALS_VERSION >= (3,0,0): cdef int kin_prec_solve(N_Vector u, N_Vector uscaleN, N_Vector fval, - N_Vector fscaleN, N_Vector v, void *problem_data): + N_Vector fscaleN, N_Vector v, void *problem_data) noexcept: """ Preconditioning solve function @@ -144,7 +144,7 @@ IF SUNDIALS_VERSION >= (3,0,0): return KIN_SUCCESS cdef int kin_prec_setup(N_Vector uN, N_Vector uscaleN, N_Vector fvalN, - N_Vector fscaleN, void *problem_data): + N_Vector fscaleN, void *problem_data) noexcept: """ Preconditioning setup function """ @@ -168,7 +168,7 @@ IF SUNDIALS_VERSION >= (3,0,0): ELSE: cdef int kin_prec_solve(N_Vector u, N_Vector uscaleN, N_Vector fval, - N_Vector fscaleN, N_Vector v, void *problem_data, N_Vector tmp): + N_Vector fscaleN, N_Vector v, void *problem_data, N_Vector tmp) noexcept: """ Preconditioning solve function @@ -198,7 +198,7 @@ ELSE: return KIN_SUCCESS cdef int kin_prec_setup(N_Vector uN, N_Vector uscaleN, N_Vector fvalN, - N_Vector fscaleN, void *problem_data, N_Vector tmp1, N_Vector tmp2): + N_Vector fscaleN, void *problem_data, N_Vector tmp1, N_Vector tmp2) noexcept: """ Preconditioning setup function """ @@ -220,7 +220,7 @@ ELSE: return KIN_SUCCESS -cdef void kin_err(int err_code, const char *module, const char *function, char *msg, void *eh_data): +cdef void kin_err(int err_code, const char *module, const char *function, char *msg, void *eh_data) noexcept: cdef ProblemDataEquationSolver pData = eh_data if err_code > 0: #Warning @@ -235,7 +235,7 @@ cdef void kin_err(int err_code, const char *module, const char *function, char * #print(""%(fnorm, snorm, pData.TOL)) -cdef void kin_info(const char *module, const char *function, char *msg, void *eh_data): +cdef void kin_info(const char *module, const char *function, char *msg, void *eh_data) noexcept: cdef ProblemDataEquationSolver pData = eh_data cdef int flag cdef realtype fnorm diff --git a/src/lib/sundials_constants.pxi b/src/lib/sundials_constants.pxi index c5069917..c4820356 100644 --- a/src/lib/sundials_constants.pxi +++ b/src/lib/sundials_constants.pxi @@ -238,4 +238,3 @@ DEF IDA_JAC_IND = 2 # Index to user data jacobian DEF IDA_ROOT_IND = 1 # Index to user data root handling DEF IDA_ROOTF_IND = 0 # Index to user data root function DEF IDA_SW_IND = 1 # Index to user data root switches - diff --git a/src/ode.pxd b/src/ode.pxd index a281cdb7..9d3d43c0 100644 --- a/src/ode.pxd +++ b/src/ode.pxd @@ -17,6 +17,7 @@ import numpy as N cimport numpy as N + from assimulo.support cimport Statistics cdef class ODE: diff --git a/src/ode.pyx b/src/ode.pyx index 3e814a37..75594f7e 100644 --- a/src/ode.pyx +++ b/src/ode.pyx @@ -593,7 +593,7 @@ cdef class ODE: cpdef _chattering_check(self, object event_info): self.chattering_clear_counter = 0 - if event_info[0] is not None and event_info[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])) else: diff --git a/src/problem.pxd b/src/problem.pxd index 36e58281..ef88a0b2 100644 --- a/src/problem.pxd +++ b/src/problem.pxd @@ -41,9 +41,7 @@ cdef class cDelay_Explicit_Problem(cExplicit_Problem): cdef class cSingPerturbed_Problem(cExplicit_Problem): pass - cdef class cAlgebraic_Problem: cpdef initialize(self, solver) cpdef finalize(self,object solver) - diff --git a/src/solvers/glimda.py b/src/solvers/glimda.py index b41372e5..31c72427 100644 --- a/src/solvers/glimda.py +++ b/src/solvers/glimda.py @@ -20,7 +20,6 @@ from assimulo.exception import GLIMDA_Exception from assimulo.ode import ID_PY_COMPLETE, NORMAL - from assimulo.implicit_ode import Implicit_ODE try: diff --git a/src/solvers/kinsol.pyx b/src/solvers/kinsol.pyx index 11bc7c46..a1b1c97a 100644 --- a/src/solvers/kinsol.pyx +++ b/src/solvers/kinsol.pyx @@ -15,9 +15,11 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + import numpy as N cimport numpy as N -from numpy cimport PyArray_DATA +from numpy cimport PyArray_DATA # TODO: Fix? N.import_array() diff --git a/src/solvers/odassl.py b/src/solvers/odassl.py index e997372f..709a7ebb 100644 --- a/src/solvers/odassl.py +++ b/src/solvers/odassl.py @@ -257,9 +257,9 @@ def integrate(self, t, y, yprime, tf, opts): lrw = 40+8*ny + neq**2 + 3*neq rwork = np.zeros((lrw,)) liw = 22+neq - iwork = np.zeros((liw,),np.int) + iwork = np.zeros((liw,),np.intc) jac_dummy = lambda t,x,xp: x - info = np.zeros((15,),np.int) + info = np.zeros((15,),np.intc) info[1] = 1 # Tolerances are vectors info[2] = normal_mode = 1 if opts["output_list"] is None or opts["report_continuously"] else 0 # intermediate output mode info[6] = 1 if self.options["maxh"] > 0.0 else 0 @@ -292,8 +292,8 @@ def integrate(self, t, y, yprime, tf, opts): self._opts = opts - #THIS IS NOT SUPPOSE TO BE NECCESSARY, BUT DUE TO A PROBLEM - #REPORTED IN TICKET:244 THIS IS HOWEVER NECCESSARY AS A + #THIS IS NOT SUPPOSE TO BE NECESSARY, BUT DUE TO A PROBLEM + #REPORTED IN TICKET:244 THIS IS HOWEVER NECESSARY AS A #WORKAROUND FOR NOW... def py_residual(t,y,yd): return self.problem.res(t,y,yd) @@ -367,5 +367,3 @@ def print_statistics(self, verbose=NORMAL): log_message_verbose(' Tolerances (absolute) : ' + str(self._compact_tol(self.options["atol"]))) log_message_verbose(' Tolerances (relative) : ' + str(self.options["rtol"])) log_message_verbose('') - - diff --git a/src/solvers/odepack.py b/src/solvers/odepack.py index ff6c175e..9eb571f8 100644 --- a/src/solvers/odepack.py +++ b/src/solvers/odepack.py @@ -15,14 +15,14 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . +import sys +import logging import numpy as N import scipy.linalg as Sc import scipy.sparse as sp -import sys + from assimulo.exception import ODEPACK_Exception, RKStarter_Exception from assimulo.ode import ID_PY_COMPLETE, ID_PY_EVENT, NORMAL -import logging - from assimulo.explicit_ode import Explicit_ODE try: diff --git a/src/solvers/radar5.py b/src/solvers/radar5.py index 7f2f10e5..1346d09f 100644 --- a/src/solvers/radar5.py +++ b/src/solvers/radar5.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 sys import numpy as N import pylab as P -import sys from assimulo.ode import NORMAL, ID_PY_COMPLETE, ID_PY_EVENT from assimulo.explicit_ode import Explicit_ODE diff --git a/src/solvers/rosenbrock.py b/src/solvers/rosenbrock.py index 7c8d28f2..e32a54cc 100644 --- a/src/solvers/rosenbrock.py +++ b/src/solvers/rosenbrock.py @@ -20,7 +20,6 @@ from assimulo.ode import NORMAL, ID_PY_EVENT, ID_PY_COMPLETE from assimulo.explicit_ode import Explicit_ODE - from assimulo.exception import Rodas_Exception from assimulo.support import set_type_shape_array diff --git a/src/solvers/sdirk_dae.pyx b/src/solvers/sdirk_dae.pyx index 67f6c9ae..f7f1b36d 100644 --- a/src/solvers/sdirk_dae.pyx +++ b/src/solvers/sdirk_dae.pyx @@ -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 sys +import numpy as N from assimulo.exception import ODEPACK_Exception, RKStarter_Exception from assimulo.ode import ID_PY_COMPLETE, ID_PY_EVENT, NORMAL - from assimulo.explicit_ode import Implicit_ODE try: diff --git a/src/special_systems.pyx b/src/special_systems.pyx index 24f52853..8ed7dd2d 100644 --- a/src/special_systems.pyx +++ b/src/special_systems.pyx @@ -17,11 +17,12 @@ # distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION -import assimulo.problem as ap -from assimulo.support import set_type_shape_array import numpy as N cimport numpy as N +from assimulo.problem import Implicit_Problem, Overdetermined_Problem +from assimulo.support import set_type_shape_array + cdef class cMechanical_System: u""" Special problem class for (constrained) mechanical systems: @@ -198,10 +199,10 @@ cdef class cMechanical_System: elif index is None: algvar = (self.pos0.size + self.vel0.size) * [1] if index in ('ovstab2','ovstab1'): - problem=ap.Overdetermined_Problem(self.make_res(index), y0, yd0, self.t0, self.sw0) + problem=Overdetermined_Problem(self.make_res(index), y0, yd0, self.t0, self.sw0) problem.neq=neq else: - problem=ap.Implicit_Problem(self.make_res(index), y0, yd0, self.t0, self.sw0) + problem=Implicit_Problem(self.make_res(index), y0, yd0, self.t0, self.sw0) problem.algvar=algvar return problem diff --git a/src/support.pxd b/src/support.pxd index 8439bb6b..3648edc6 100644 --- a/src/support.pxd +++ b/src/support.pxd @@ -18,7 +18,6 @@ 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 04d20716..214179bb 100644 --- a/src/support.pyx +++ b/src/support.pyx @@ -62,7 +62,7 @@ cdef class Statistics: for k in list(self.statistics.keys()): if self.statistics[k] == -1: continue - print(" %s %s: %d")%(self.statistics_msg[k], " "*(max_len_msg-len(self.statistics_msg[k])+1) ,self.statistics[k]) + print(" {} {}: {}".format(self.statistics_msg[k], " "*(max_len_msg-len(self.statistics_msg[k])+1), self.statistics[k])) def reset(self): """ diff --git a/tests/solvers/test_euler.py b/tests/solvers/test_euler.py index 749b28bc..f7c0547f 100644 --- a/tests/solvers/test_euler.py +++ b/tests/solvers/test_euler.py @@ -78,7 +78,7 @@ def handle_event(self, solver, event_info): event_info = self.check_eIter(b_mode, a_mode) - if not True in event_info: #Breaks the iteration loop + if True not in event_info: #Breaks the iteration loop break #Helper function for handle_event @@ -141,9 +141,9 @@ def test_event_localizer(self): t, y = exp_sim.simulate(10.0,1000) #Simulate 10 seconds with 1000 communications points #Basic test - nose.tools.assert_almost_equal(y[-1][0],8.0) - nose.tools.assert_almost_equal(y[-1][1],3.0) - nose.tools.assert_almost_equal(y[-1][2],2.0) + nose.tools.assert_almost_equal(y[-1][0], 8.0) + nose.tools.assert_almost_equal(y[-1][1], 3.0) + nose.tools.assert_almost_equal(y[-1][2], 2.0) @testattr(stddist = True) def test_h(self): diff --git a/thirdparty/radau5/radau5ode.pyx b/thirdparty/radau5/radau5ode.pyx index 56c90e50..129e9703 100644 --- a/thirdparty/radau5/radau5ode.pyx +++ b/thirdparty/radau5/radau5ode.pyx @@ -17,13 +17,13 @@ # distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION -cimport radau5ode # .pxd cimport cython - import numpy as np cimport numpy as np import scipy.sparse as sps +cimport radau5ode # .pxd + from numpy cimport PyArray_DATA @cython.boundscheck(False)