Skip to content

Commit

Permalink
SUNComm
Browse files Browse the repository at this point in the history
  • Loading branch information
jschueller committed May 15, 2024
1 parent c560c9e commit a76687d
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 16 deletions.
10 changes: 8 additions & 2 deletions src/lib/sundials_callbacks.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ from numpy cimport PyArray_DATA
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
IF SUNDIALS_VERSION >= (7,0,0):
cdef SUNDIALS.SUNComm comm = 0
ELSE:
cdef void* comm = NULL
SUNDIALS.SUNContext_Create(comm, &ctx)
cdef N_Vector v = N_VNew_Serial(n, ctx)
ELSE:
Expand All @@ -39,7 +42,10 @@ cdef inline N_Vector arr2nv(x) noexcept:
cdef void* data_ptr=PyArray_DATA(ndx)
IF SUNDIALS_VERSION >= (6,0,0):
cdef SUNDIALS.SUNContext ctx = NULL
cdef void * comm = NULL
IF SUNDIALS_VERSION >= (7,0,0):
cdef SUNDIALS.SUNComm comm = 0
ELSE:
cdef void* comm = NULL
SUNDIALS.SUNContext_Create(comm, &ctx)
cdef N_Vector v = N_VNew_Serial(n, ctx)
ELSE:
Expand Down
6 changes: 5 additions & 1 deletion src/lib/sundials_includes.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ IF SUNDIALS_VERSION >= (6,0,0):
ctypedef _SUNContext * SUNContext
cdef struct _SUNContext:
pass
int SUNContext_Create(void* comm, SUNContext* ctx) noexcept
IF SUNDIALS_VERSION >= (7,0,0):
ctypedef int SUNComm
int SUNContext_Create(SUNComm comm, SUNContext* ctx) noexcept
ELSE:
int SUNContext_Create(void* comm, SUNContext* ctx) noexcept

IF SUNDIALS_VERSION >= (7,0,0):
cdef extern from "sundials/sundials_context.h":
Expand Down
10 changes: 8 additions & 2 deletions src/solvers/kinsol.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,10 @@ cdef class KINSOL(Algebraic):
cdef int flag #Used for return
IF SUNDIALS_VERSION >= (6,0,0):
cdef SUNDIALS.SUNContext ctx = NULL
cdef void * comm = NULL
IF SUNDIALS_VERSION >= (7,0,0):
cdef SUNDIALS.SUNComm comm = 0
ELSE:
cdef void* comm = NULL
SUNDIALS.SUNContext_Create(comm, &ctx)

self.y_temp = arr2nv(self.y)
Expand Down Expand Up @@ -230,7 +233,10 @@ cdef class KINSOL(Algebraic):
cpdef add_linear_solver(self):
IF SUNDIALS_VERSION >= (6,0,0):
cdef SUNDIALS.SUNContext ctx = NULL
cdef void * comm = NULL
IF SUNDIALS_VERSION >= (7,0,0):
cdef SUNDIALS.SUNComm comm = 0
ELSE:
cdef void* comm = NULL
SUNDIALS.SUNContext_Create(comm, &ctx)
if self.options["linear_solver"] == "DENSE":
IF SUNDIALS_VERSION >= (3,0,0):
Expand Down
52 changes: 41 additions & 11 deletions src/solvers/sundials.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,10 @@ cdef class IDA(Implicit_ODE):
cdef realtype ZERO = 0.0
IF SUNDIALS_VERSION >= (6,0,0):
cdef SUNDIALS.SUNContext ctx = NULL
cdef void * comm = NULL
IF SUNDIALS_VERSION >= (7,0,0):
cdef SUNDIALS.SUNComm comm = 0
ELSE:
cdef void* comm = NULL
SUNDIALS.SUNContext_Create(comm, &ctx)

self.yTemp = arr2nv(self.y)
Expand Down Expand Up @@ -739,7 +742,10 @@ cdef class IDA(Implicit_ODE):
cdef np.ndarray err, pyweight, pyele
IF SUNDIALS_VERSION >= (6,0,0):
cdef SUNDIALS.SUNContext ctx = NULL
cdef void* comm = NULL
IF SUNDIALS_VERSION >= (7,0,0):
cdef SUNDIALS.SUNComm comm = 0
ELSE:
cdef void* comm = NULL
SUNDIALS.SUNContext_Create(comm, &ctx)
cdef N_Vector ele = N_VNew_Serial(self.pData.dim, ctx)
cdef N_Vector eweight = N_VNew_Serial(self.pData.dim, ctx)
Expand Down Expand Up @@ -774,7 +780,10 @@ cdef class IDA(Implicit_ODE):
cdef np.ndarray res
IF SUNDIALS_VERSION >= (6,0,0):
cdef SUNDIALS.SUNContext ctx = NULL
cdef void* comm = NULL
IF SUNDIALS_VERSION >= (7,0,0):
cdef SUNDIALS.SUNComm comm = 0
ELSE:
cdef void* comm = NULL
SUNDIALS.SUNContext_Create(comm, &ctx)
cdef N_Vector dky=N_VNew_Serial(self.pData.dim, ctx)
ELSE:
Expand Down Expand Up @@ -815,7 +824,10 @@ cdef class IDA(Implicit_ODE):
"""
IF SUNDIALS_VERSION >= (6,0,0):
cdef SUNDIALS.SUNContext ctx = NULL
cdef void* comm = NULL
IF SUNDIALS_VERSION >= (7,0,0):
cdef SUNDIALS.SUNComm comm = 0
ELSE:
cdef void* comm = NULL
SUNDIALS.SUNContext_Create(comm, &ctx)
cdef N_Vector dkyS=N_VNew_Serial(self.pData.dim, ctx)
ELSE:
Expand Down Expand Up @@ -1614,7 +1626,10 @@ cdef class CVode(Explicit_ODE):
cdef int flag
IF SUNDIALS_VERSION >= (6,0,0):
cdef SUNDIALS.SUNContext ctx = NULL
cdef void* comm = NULL
IF SUNDIALS_VERSION >= (7,0,0):
cdef SUNDIALS.SUNComm comm = 0
ELSE:
cdef void* comm = NULL
SUNDIALS.SUNContext_Create(comm, &ctx)
cdef N_Vector ele=N_VNew_Serial(self.pData.dim, ctx)
ELSE:
Expand Down Expand Up @@ -1696,7 +1711,10 @@ cdef class CVode(Explicit_ODE):
cdef int flag
IF SUNDIALS_VERSION >= (6,0,0):
cdef SUNDIALS.SUNContext ctx = NULL
cdef void* comm = NULL
IF SUNDIALS_VERSION >= (7,0,0):
cdef SUNDIALS.SUNComm comm = 0
ELSE:
cdef void* comm = NULL
SUNDIALS.SUNContext_Create(comm, &ctx)
cdef N_Vector eweight=N_VNew_Serial(self.pData.dim, ctx)
ELSE:
Expand Down Expand Up @@ -1770,7 +1788,10 @@ cdef class CVode(Explicit_ODE):
cdef realtype ZERO = 0.0
IF SUNDIALS_VERSION >= (6,0,0):
cdef SUNDIALS.SUNContext ctx = NULL
cdef void * comm = NULL
IF SUNDIALS_VERSION >= (7,0,0):
cdef SUNDIALS.SUNComm comm = 0
ELSE:
cdef void* comm = NULL
SUNDIALS.SUNContext_Create(comm, &ctx)

if self.options["norm"] == "EUCLIDEAN":
Expand Down Expand Up @@ -1930,7 +1951,10 @@ cdef class CVode(Explicit_ODE):
cdef np.ndarray res
IF SUNDIALS_VERSION >= (6,0,0):
cdef SUNDIALS.SUNContext ctx = NULL
cdef void* comm = NULL
IF SUNDIALS_VERSION >= (7,0,0):
cdef SUNDIALS.SUNComm comm = 0
ELSE:
cdef void* comm = NULL
SUNDIALS.SUNContext_Create(comm, &ctx)
cdef N_Vector dky=N_VNew_Serial(self.pData.dim, ctx)
ELSE:
Expand Down Expand Up @@ -1972,7 +1996,10 @@ cdef class CVode(Explicit_ODE):
"""
IF SUNDIALS_VERSION >= (6,0,0):
cdef SUNDIALS.SUNContext ctx = NULL
cdef void* comm = NULL
IF SUNDIALS_VERSION >= (7,0,0):
cdef SUNDIALS.SUNComm comm = 0
ELSE:
cdef void* comm = NULL
SUNDIALS.SUNContext_Create(comm, &ctx)
cdef N_Vector dkyS=N_VNew_Serial(self.pData.dim, ctx)
ELSE:
Expand Down Expand Up @@ -2251,8 +2278,11 @@ cdef class CVode(Explicit_ODE):
"""
cdef flag
IF SUNDIALS_VERSION >= (6,0,0):
cdef SUNDIALS.SUNContext ctx
cdef void* comm = NULL
cdef SUNDIALS.SUNContext ctx = NULL
IF SUNDIALS_VERSION >= (7,0,0):
cdef SUNDIALS.SUNComm comm = 0
ELSE:
cdef void* comm = NULL
SUNDIALS.SUNContext_Create(comm, &ctx)

#Choose a linear solver if and only if NEWTON is choosen
Expand Down

0 comments on commit a76687d

Please sign in to comment.