Source code for scikits.odes.sundials

#
# odes - Extra ode integrators
#

import inspect

[docs]class CVODESolveException(Exception): """Base class for exceptions raised by ``CVODE.validate_flags``.""" def __init__(self, soln): self.soln = soln self.args = (self._message.format(soln),)
[docs]class CVODESolveFailed(CVODESolveException): """``CVODE.solve`` failed to reach endpoint""" _message = ( "Solver failed with flag {0.flag} and finished at {0.errors.t}" "with values {0.errors.y}." )
[docs]class CVODESolveFoundRoot(CVODESolveException): """``CVODE.solve`` found a root""" _message = "Solver found a root at {0.roots.t[0]}."
[docs]class CVODESolveReachedTSTOP(CVODESolveException): """``CVODE.solve`` reached the endpoint specified by tstop.""" _message = "Solver reached tstop at {0.tstop.t[0]}."
[docs]class IDASolveException(Exception): """Base class for exceptions raised by ``IDA.validate_flags``.""" def __init__(self, soln): self.soln = soln self.args = (self._message.format(soln),)
[docs]class IDASolveFailed(IDASolveException): """``IDA.solve`` failed to reach endpoint""" _message = ( "Solver failed with flag {0.flag} and finished at {0.errors.t}" "with values {0.errors.y} and derivatives {0.errors.ydot}." )
[docs]class IDASolveFoundRoot(IDASolveException): """``IDA.solve`` found a root""" _message = "Solver found a root at {0.roots.t[0]}."
[docs]class IDASolveReachedTSTOP(IDASolveException): """``IDA.solve`` reached the endpoint specified by tstop.""" _message = "Solver reached tstop at {0.tstop.t[0]}."
def _get_num_args(func): """ Python 2/3 compatible method of getting number of args that `func` accepts """ if hasattr(inspect, "signature"): sig = inspect.signature(func) numargs = 0 for param in sig.parameters.values(): if param.kind in ( inspect.Parameter.POSITIONAL_ONLY, inspect.Parameter.POSITIONAL_OR_KEYWORD, inspect.Parameter.VAR_POSITIONAL, ): numargs += 1 return numargs else: return len(inspect.getargspec(func).args)