Skip to content
Open
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
4 changes: 4 additions & 0 deletions src/lib/sundials_includes.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ IF SUNDIALS_VERSION >= (6,0,0):
int SUNContext_Create(SUNComm comm, SUNContext* ctx) noexcept
ELSE:
int SUNContext_Create(void* comm, SUNContext* ctx) noexcept
int SUNContext_Free(SUNContext* ctx) noexcept

IF SUNDIALS_VERSION >= (7,0,0):
cdef extern from "sundials/sundials_context.h":
Expand Down Expand Up @@ -294,6 +295,9 @@ ELSE:
cdef inline int with_superlu() noexcept: return 0

IF SUNDIALS_VERSION >= (4,0,0):
cdef extern from "sundials/sundials_nonlinearsolver.h":
int SUNNonlinSolFree(SUNNonlinearSolver NLS) noexcept

cdef extern from "cvodes/cvodes.h":
IF SUNDIALS_VERSION >= (6,0,0):
void* CVodeCreate(int lmm, SUNContext ctx) noexcept
Expand Down
10 changes: 8 additions & 2 deletions src/ode_event_locator.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ int f_event_locator(int n_y, int n_g, double TOL_inp, double t_low, double *t_hi
imax = 0;
for (i = 0; i < n_g; i++){
if ((g_low[i] > 0) != (g_high[i] > 0)){
gfrac = _abs(g_high[i]/(g_low[i] - g_high[i]));
double denom = g_low[i] - g_high[i];
gfrac = (denom != 0.0) ? _abs(g_high[i]/denom) : 0.0;
if (gfrac >= maxfrac){
maxfrac = gfrac;
imax = i;
Expand All @@ -97,7 +98,12 @@ int f_event_locator(int n_y, int n_g, double TOL_inp, double t_low, double *t_hi
if ((g_high[imax] == 0) || (g_low[imax] == 0)){
t_mid = (t_low + *t_high)/2.;
}else{
t_mid = *t_high - (*t_high - t_low)*g_high[imax]/(g_high[imax] - alpha*g_low[imax]);
double denom = g_high[imax] - alpha*g_low[imax];
if (denom != 0.0){
t_mid = *t_high - (*t_high - t_low)*g_high[imax]/denom;
} else {
t_mid = (t_low + *t_high)/2.;
}
}

/* Check if t_mid is to close to current brackets and adjust inwards if so is the case. */
Expand Down
8 changes: 6 additions & 2 deletions src/solvers/kinsol.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,15 @@ cdef class KINSOL(Algebraic):
def __dealloc__(self):

if self.y_temp != NULL:
#Deallocate N_Vector
N_VDestroy(self.y_temp)

if self.y_scale != NULL:
N_VDestroy(self.y_scale)

if self.f_scale != NULL:
N_VDestroy(self.f_scale)

if self.kinsol_mem != NULL:
#Free Memory
SUNDIALS.KINFree(&self.kinsol_mem)

IF SUNDIALS_VERSION >= (3,0,0):
Expand Down
Loading
Loading