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 Mar 12, 2024
1 parent 57466a9 commit dffe1a7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
6 changes: 6 additions & 0 deletions scikits/odes/ode.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,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
1 change: 1 addition & 0 deletions scikits/odes/sundials/c_cvode.pxd
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
4 changes: 4 additions & 0 deletions scikits/odes/sundials/c_sundials.pxd
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
7 changes: 6 additions & 1 deletion scikits/odes/sundials/cvode.pyx
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 @@ -2046,6 +2048,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

0 comments on commit dffe1a7

Please sign in to comment.