Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions packages/scikits-odes-sundials/src/scikits_odes_sundials/c_ida.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,19 @@ cdef extern from "ida/ida.h":
enum: IDA_BAD_T #-26
enum: IDA_BAD_DKY #-27
enum: IDA_VECTOROP_ERR #-28

enum: IDA_UNRECOGNIZED_ERROR #-99

ctypedef int (*IDAResFn)(sunrealtype tt, N_Vector yy, N_Vector yp,
N_Vector rr, void *user_data)
N_Vector rr, void *user_data) except? -1

ctypedef int (*IDARootFn)(sunrealtype t, N_Vector y, N_Vector yp,
sunrealtype *gout, void *user_data)
sunrealtype *gout, void *user_data) except? -1

ctypedef int (*IDAEwtFn)(N_Vector y, N_Vector ewt, void *user_data)

ctypedef void (*IDAErrHandlerFn)(int error_code, const char *module,
const char *function, char *msg,
ctypedef void (*IDAErrHandlerFn)(int error_code, const char *module,
const char *function, char *msg,
void *user_data)

void *IDACreate(SUNContext sunctx)
Expand All @@ -74,15 +74,15 @@ cdef extern from "ida/ida.h":
int IDASVtolerances(void *ida_mem, sunrealtype reltol, N_Vector abstol)
int IDAWFtolerances(void *ida_mem, IDAEwtFn efun)
int IDACalcIC(void *ida_mem, int icopt, sunrealtype tout1)

int IDASetNonlinConvCoefIC(void *ida_mem, sunrealtype epiccon)
int IDASetMaxNumStepsIC(void *ida_mem, int maxnh)
int IDASetMaxNumJacsIC(void *ida_mem, int maxnj)
int IDASetMaxNumItersIC(void *ida_mem, int maxnit)
int IDASetLineSearchOffIC(void *ida_mem, sunbooleantype lsoff)
int IDASetStepToleranceIC(void *ida_mem, sunrealtype steptol)
int IDASetMaxBacksIC(void *ida_mem, int maxbacks)

int IDASetErrHandlerFn(void *ida_mem, IDAErrHandlerFn ehfun, void *eh_data)
int IDASetErrFile(void *ida_mem, FILE *errfp)
int IDASetUserData(void *ida_mem, void *user_data)
Expand All @@ -107,10 +107,10 @@ cdef extern from "ida/ida.h":

int IDASolve(void *ida_mem, sunrealtype tout, sunrealtype *tret,
N_Vector yret, N_Vector ypret, int itask)

int IDAComputeY(void *ida_mem, N_Vector ycor, N_Vector y)
int IDAComputeYp(void *ida_mem, N_Vector ycor, N_Vector yp)

int IDAGetDky(void *ida_mem, sunrealtype t, int k, N_Vector dky)

int IDAGetWorkSpace(void *ida_mem, long int *lenrw, long int *leniw)
Expand Down Expand Up @@ -162,17 +162,17 @@ cdef extern from "ida/ida_ls.h":
ctypedef int (*IDALsJacFn)(sunrealtype t, sunrealtype c_j, N_Vector y,
N_Vector yp, N_Vector r, SUNMatrix Jac,
void *user_data, N_Vector tmp1,
N_Vector tmp2, N_Vector tmp3)
N_Vector tmp2, N_Vector tmp3) except? -1

ctypedef int (*IDALsPrecSetupFn)(sunrealtype tt, N_Vector yy,
N_Vector yp, N_Vector rr,
sunrealtype c_j, void *user_data)
sunrealtype c_j, void *user_data) except? -1

ctypedef int (*IDALsPrecSolveFn)(sunrealtype tt, N_Vector yy,
N_Vector yp, N_Vector rr,
N_Vector rvec, N_Vector zvec,
sunrealtype c_j, sunrealtype delta,
void *user_data)
void *user_data) except? -1

ctypedef int (*IDALsJacTimesSetupFn)(sunrealtype tt, N_Vector yy,
N_Vector yp, N_Vector rr,
Expand All @@ -185,7 +185,7 @@ cdef extern from "ida/ida_ls.h":
N_Vector tmp1, N_Vector tmp2) except? -1

int IDASetLinearSolver(void *ida_mem, SUNLinearSolver LS, SUNMatrix A)

int IDASetJacFn(void *ida_mem, IDALsJacFn jac)
int IDASetPreconditioner(void *ida_mem, IDALsPrecSetupFn pset,
IDALsPrecSolveFn psolve)
Expand All @@ -207,11 +207,11 @@ cdef extern from "ida/ida_ls.h":
char *IDAGetLinReturnFlagName(long int flag)

cdef extern from "ida/ida_direct.h":

ctypedef IDALsJacFn IDAJacFn

int IDASetJacFn(void *ida_mem, IDAJacFn jac)

int IDAGetWorkSpace(void *ida_mem, long int *lenrwLS, long int *leniwLS)
int IDAGetNumJacEvals(void *ida_mem, long int *njevals)
int IDAGetNumResEvals(void *ida_mem, long int *nfevalsLS)
Expand Down
36 changes: 18 additions & 18 deletions packages/scikits-odes-sundials/src/scikits_odes_sundials/cvode.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ cdef class CV_WrapJacRhsFunction(CV_JacRhsFunction):

cdef int _jacdense(sunrealtype tt,
N_Vector yy, N_Vector ff, SUNMatrix Jac,
void *auxiliary_data, N_Vector tmp1, N_Vector tmp2,
void *auxiliary_data, N_Vector tmp1, N_Vector tmp2,
N_Vector tmp3) except? -1:
"""function with the signature of CVodeJacFn that calls python Jac
Note: signature of Jac is SUNMatrix
Expand Down Expand Up @@ -387,8 +387,8 @@ class MutableBool(object):
def __init__(self, value):
self.value = value

cdef int _prec_setupfn(sunrealtype tt, N_Vector yy, N_Vector ff, sunbooleantype jok,
sunbooleantype *jcurPtr, sunrealtype gamma,
cdef int _prec_setupfn(sunrealtype tt, N_Vector yy, N_Vector ff, sunbooleantype jok,
sunbooleantype *jcurPtr, sunrealtype gamma,
void *auxiliary_data) except -1:
""" function with the signature of CVLsPrecSetupFn, that calls python function """
cdef np.ndarray[DTYPE_t, ndim=1] yy_tmp
Expand All @@ -403,7 +403,7 @@ cdef int _prec_setupfn(sunrealtype tt, N_Vector yy, N_Vector ff, sunbooleantype
nv_s2ndarray(yy, yy_tmp)

jcurPtr_tmp = MutableBool(jcurPtr[0])
user_flag = aux_data.prec_setupfn.evaluate(tt, yy_tmp, jok, jcurPtr_tmp,
user_flag = aux_data.prec_setupfn.evaluate(tt, yy_tmp, jok, jcurPtr_tmp,
gamma, aux_data.user_data)
jcurPtr[0] = jcurPtr_tmp.value
return user_flag
Expand Down Expand Up @@ -469,8 +469,8 @@ cdef class CV_WrapPrecSolveFunction(CV_PrecSolveFunction):
user_flag = 0
return user_flag

cdef int _prec_solvefn(sunrealtype tt, N_Vector yy, N_Vector ff, N_Vector r,
N_Vector z, sunrealtype gamma, sunrealtype delta, int lr,
cdef int _prec_solvefn(sunrealtype tt, N_Vector yy, N_Vector ff, N_Vector r,
N_Vector z, sunrealtype gamma, sunrealtype delta, int lr,
void *auxiliary_data) except? -1:
""" function with the signature of CVLsPrecSolveFn, that calls python function """
cdef np.ndarray[DTYPE_t, ndim=1] yy_tmp, r_tmp, z_tmp
Expand Down Expand Up @@ -711,7 +711,7 @@ cdef class CV_WrapErrHandler(CV_ErrHandler):
cdef void _cv_err_handler_fn(
int error_code, const char *module, const char *function, char *msg,
void *eh_data
):
) noexcept:
"""
function with the signature of CVErrHandlerFn, that calls python error
handler
Expand Down Expand Up @@ -871,7 +871,7 @@ cdef class CVODE:
Defines the jacobian function and has to be a subclass
of CV_JacRhsFunction class or python function. This function
takes as input arguments current time t, current value of y,
current value of f(t,y), and
current value of f(t,y), and
a 2D numpy array of returned jacobian and optional userdata.
Return value is 0 if successfull.
Jacobian is only used for dense or lapackdense linear solver
Expand Down Expand Up @@ -923,12 +923,12 @@ cdef class CVODE:
For parallel implementation use_relaxation
use lapackdense or lapackband respectively.
TODO: to add new solvers: pcg, spfgmr, superlumt, klu

'nonlinsolver':
Values: 'newton' (= default), 'fixedpoint'
Description:
Specifies the used nonlinear solver.

'lband', 'uband':
Values: non-negative integer, 0 = default
Description:
Expand Down Expand Up @@ -1484,7 +1484,7 @@ cdef class CVODE:
if (A == NULL or LS == NULL):
raise ValueError('Could not allocate matrix or linear solver')
flag = CVodeSetLinearSolver(cv_mem, LS, A)

if flag == CVLS_ILL_INPUT:
raise ValueError('CVBand linear solver setting failed, '
'arguments incompatible')
Expand Down Expand Up @@ -1517,7 +1517,7 @@ cdef class CVODE:
else:
raise ValueError('LinSolver::Precondition: Unknown type: %s'
% opts['precond_type'])

if linsolver == 'spgmr':
LS = SUNLinSol_SPGMR(self.y0, pretype, <int> opts['maxl'], self.sunctx);
if LS == NULL:
Expand All @@ -1532,7 +1532,7 @@ cdef class CVODE:
raise ValueError('Could not allocate linear solver')
else:
raise ValueError('Given linsolver {} not implemented in odes'.format(linsolver))

flag = CVodeSetLinearSolver(cv_mem, LS, NULL);
if flag == CVLS_MEM_FAIL:
raise MemoryError('LinSolver:CVode memory allocation '
Expand All @@ -1542,7 +1542,7 @@ cdef class CVODE:
.format(flag))
# TODO: make option for the Gram-Schmidt orthogonalization
#flag = SUNSPGMRSetGSType(LS, gstype);

# TODO make option
#flag = CVodeSetEpsLin(cvode_mem, DELT);
if self.aux_data.prec_solvefn:
Expand All @@ -1558,10 +1558,10 @@ cdef class CVODE:
elif flag != CVLS_SUCCESS:
raise ValueError('CVodeSetPreconditioner failed with code {}'
.format(flag))

if self.aux_data.jac_times_vecfn:
if self.aux_data.jac_times_setupfn:
flag = CVodeSetJacTimes(cv_mem, _jac_times_setupfn,
flag = CVodeSetJacTimes(cv_mem, _jac_times_setupfn,
_jac_times_vecfn)
else:
flag = CVodeSetJacTimes(cv_mem, NULL, _jac_times_vecfn)
Expand Down Expand Up @@ -1615,14 +1615,14 @@ cdef class CVODE:
raise ValueError('LinSolver: Unknown solver type: %s'
% opts['linsolver'])
elif nonlinsolver == 'fixedpoint':
# create fixed point nonlinear solver object
# create fixed point nonlinear solver object
NLS = SUNNonlinSol_FixedPoint(self.y0, 0, self.sunctx);
# attach nonlinear solver object to CVode
flag = CVodeSetNonlinearSolver(cv_mem, NLS)
if flag != CV_SUCCESS:
raise ValueError('CVodeSetNonlinearSolver failed with code {}'
.format(flag))

if (linsolver in ['dense', 'lapackdense', 'lapackband', 'band']
and self.aux_data.jac):
# we need to create the correct shape for jacobian output, here is
Expand Down
20 changes: 10 additions & 10 deletions packages/scikits-odes-sundials/src/scikits_odes_sundials/ida.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ cdef class IDA_WrapJacRhsFunction(IDA_JacRhsFunction):

cdef int _jacdense(sunrealtype tt, sunrealtype cj,
N_Vector yy, N_Vector yp, N_Vector rr, SUNMatrix Jac,
void *auxiliary_data, N_Vector tmp1, N_Vector tmp2, N_Vector tmp3):
void *auxiliary_data, N_Vector tmp1, N_Vector tmp2, N_Vector tmp3) except? -1:
"""function with the signature of IDAJacFn """
cdef np.ndarray[DTYPE_t, ndim=1] yy_tmp, yp_tmp, residual_tmp
cdef np.ndarray jac_tmp
Expand Down Expand Up @@ -413,7 +413,7 @@ cdef class IDA_WrapPrecSetupFunction(IDA_PrecSetupFunction):

cdef int _prec_setupfn(sunrealtype tt, N_Vector yy, N_Vector yp, N_Vector rr,
sunrealtype cj,
void *auxiliary_data):
void *auxiliary_data) except? -1:
""" function with the signature of IDAPrecSetupFn, that calls
the python function """
cdef np.ndarray[DTYPE_t, ndim=1] yy_tmp, rp_tmp, residual_tmp
Expand Down Expand Up @@ -499,7 +499,7 @@ cdef class IDA_WrapPrecSolveFunction(IDA_PrecSolveFunction):

cdef int _prec_solvefn(sunrealtype tt, N_Vector yy, N_Vector yp, N_Vector r,
N_Vector rvec, N_Vector z, sunrealtype cj,
sunrealtype delta, void *auxiliary_data):
sunrealtype delta, void *auxiliary_data) except? -1:
""" function with the signature of CVodePrecSolveFn, that calls python function """
cdef np.ndarray[DTYPE_t, ndim=1] yy_tmp, r_tmp, z_tmp

Expand Down Expand Up @@ -610,7 +610,7 @@ cdef int _jac_times_vecfn(sunrealtype t, N_Vector yy, N_Vector yp, N_Vector rr,

if parallel_implementation:
raise NotImplemented

yy_tmp = aux_data.yy_tmp
yp_tmp = aux_data.yp_tmp
rr_tmp = aux_data.residual_tmp
Expand Down Expand Up @@ -683,7 +683,7 @@ cdef class IDA_WrapJacTimesSetupFunction(IDA_JacTimesSetupFunction):
user_flag = 0
return user_flag

cdef int _jac_times_setupfn(sunrealtype tt, N_Vector yy, N_Vector yp, N_Vector rr,
cdef int _jac_times_setupfn(sunrealtype tt, N_Vector yy, N_Vector yp, N_Vector rr,
sunrealtype cj, void *user_data) except? -1:
""" function with the signature of IDA_JacTimesSetupFunction, that calls python function """
cdef np.ndarray[DTYPE_t, ndim=1] yy_tmp, yp_tmp, rr_tmp
Expand Down Expand Up @@ -758,7 +758,7 @@ cdef class IDA_WrapErrHandler(IDA_ErrHandler):
cdef void _ida_err_handler_fn(
int error_code, const char *module, const char *function, char *msg,
void *eh_data
):
) noexcept:
"""
function with the signature of IDAErrHandlerFn, that calls python error
handler
Expand Down Expand Up @@ -1072,25 +1072,25 @@ cdef class IDA:
yy is the current value of the dependent variable vector, y(t).
yp is the current value of ˙y(t).
rr is the current value of the residual vector F(t, y, y˙).
v is the vector by which the Jacobian must be multiplied to
v is the vector by which the Jacobian must be multiplied to
the right.
Jv is the computed output vector.
cj is the scalar in the system Jacobian, proportional to the
cj is the scalar in the system Jacobian, proportional to the
inverse of the step size.
user data is a pointer to user data (optional)
'jac_times_setupfn':
Values: function of class IDA_JacTimesSetupFunction
Description:
Optional. Default is to internal finite difference with no
extra setup.
Defines a function that preprocesses and/or evaluates
Defines a function that preprocesses and/or evaluates
Jacobian-related data needed by the Jacobiantimes-vector routine
This function takes as input arguments:
tt is the current value of the independent variable.
yy is the current value of the dependent variable vector, y(t).
yp is the current value of ˙y(t).
rr is the current value of the residual vector F(t, y, y˙).
cj is the scalar in the system Jacobian, proportional to the
cj is the scalar in the system Jacobian, proportional to the
inverse of the step size.
user data is a pointer to user data (optional)
'err_handler':
Expand Down