Skip to content

Commit

Permalink
Add print_stats method to ode and implement for CVODE integrator
Browse files Browse the repository at this point in the history
`CVODE` solver has function `CVodePrintAllStats` that prints statistics about
integrator such as number of right-hand-side function evaluations and number
of nonlinear solves.
  • Loading branch information
dmitry-kabanov committed Jul 19, 2024
1 parent 06cc892 commit 651ef5c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ cdef extern from "cvode/cvode.h":
int CVodeGetNumNonlinSolvConvFails(void *cvode_mem, long int *nncfails)
int CVodeGetNonlinSolvStats(void *cvode_mem, long int *nniters,
long int *nncfails)
int CVodePrintAllStats(void* cvode_mem, FILE* outfile, SUNOutputFormat fmt)
char *CVodeGetReturnFlagName(long int flag)
void CVodeFree(void **cvode_mem)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ cdef extern from "sundials/sundials_types.h":
ctypedef float sunrealtype
ctypedef unsigned int sunbooleantype
ctypedef long sunindextype

cdef enum SUNOutputFormat:
SUN_OUTPUTFORMAT_TABLE,
SUN_OUTPUTFORMAT_CSV

cdef extern from "sundials/sundials_context.h":
struct _SUNContext:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ include "sundials_config.pxi"
import numpy as np
cimport numpy as np

from libc cimport stdio

from . import (
CVODESolveFailed, CVODESolveFoundRoot, CVODESolveReachedTSTOP,
_get_num_args,
)

from .c_sundials cimport (
sunrealtype, N_Vector, SUNContext_Create, SUNContext_Free,
sunrealtype, N_Vector, SUNContext_Create, SUNContext_Free, SUN_OUTPUTFORMAT_TABLE
)
from .c_nvector_serial cimport *
from .c_sunmatrix cimport *
Expand Down Expand Up @@ -2048,6 +2050,9 @@ cdef class CVODE:
'NumRhsEvalsJtimesFD': nfevalsLS})

return info

def print_stats(self):
CVodePrintAllStats(self._cv_mem, stdio.stdout, SUN_OUTPUTFORMAT_TABLE)

def __dealloc__(self):
if self._cv_mem is not NULL: CVodeFree(&self._cv_mem)
Expand Down
6 changes: 6 additions & 0 deletions packages/scikits-odes/src/scikits_odes/ode.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,12 @@ def get_info(self):
else:
return {}

def print_stats(self):
if hasattr(self._integrator, "print_stats"):
self._integrator.print_stats()
else:
print(f"Method `print_stats` is not implemented for integrator {self._integrator}")

#------------------------------------------------------------------------------
# ODE integrators
#------------------------------------------------------------------------------
Expand Down

0 comments on commit 651ef5c

Please sign in to comment.