libode
Easy to compile, fast ODE integrators as C++ classes
|
Lowest base class for all solvers. More...
#include <ode_base.h>
Public Member Functions | |
OdeBase (unsigned long neq, bool need_jac) | |
constructs | |
virtual | ~OdeBase () |
destructs | |
const char * | get_name () |
gets the name of the ODE system | |
const char * | get_method () |
gets the name of the solver/method | |
const char * | get_dirout () |
gets output directory string if one has been set | |
bool | get_quiet () |
gets the boolean determining if updates are printed during solves | |
bool | get_silent_snap () |
gets whether to skip writing the solution vector to file when snapping | |
unsigned long | get_neq () |
gets the size of the ODE system | |
double | get_t () |
gets the current value of the independent variable | |
double | get_dt () |
gets the most recent or current time step size | |
double * | get_sol () |
gets a pointer to the whole solution array | |
double | get_sol (unsigned long i) |
gets an element of the solution array | |
long unsigned | get_nstep () |
gets the total number of steps taken | |
long unsigned | get_neval () |
gets the total number of ODE system evaluation | |
long unsigned | get_icheck () |
gets the number of steps after which the solution is checked for integrity | |
long unsigned | get_nJac () |
gets the total number of Jacobian evaluations performed | |
void | set_t (double t) |
sets the "time," or independent variable used to track progress | |
void | set_sol (unsigned long i, double x) |
sets an element of the solution array | |
void | set_sol (double *sol) |
copies an array into the solution array | |
void | set_name (std::string name) |
sets the name of the ODE system | |
void | set_name (const char *name) |
sets the name of the ODE system | |
void | set_quiet (bool quiet) |
sets the boolean determining if updates are printed during solves | |
void | set_silent_snap (bool silent_snap) |
sets whether to skip writing the solution vector to file when snapping | |
void | set_icheck (unsigned long icheck) |
sets the number of steps after which the solution is checked for integrity | |
void | step (double dt, bool extra=true) |
increments the step counter and the time, checks the solution integrity if needed, stores the time step in the object, and executes after_step() if extra is true | |
void | solve_fixed (double tint, double dt, bool extras=true) |
integrates for a specified duration of independent variable without output | |
void | solve_fixed (double tint, double dt, const char *dirout, int inter=1) |
lots of output, solves and stores every "inter" point along the way | |
void | solve_fixed (double tint, double dt, unsigned long nsnap, const char *dirout) |
solves and writes evenly spaced snapshots | |
void | solve_fixed (double dt, double *tsnap, unsigned long nsnap, const char *dirout) |
solves and writes snapshots at times specified in the tsnap array | |
void | reset (double t, double *sol) |
reset to a specified time and initial condition array | |
Protected Member Functions | |
void | solve_fixed_ (double tint, double dt, bool extra=true) |
integrates without output or any counters, trackers, extra functions... | |
virtual void | ode_fun (double *solin, double *fout)=0 |
evaluates the system of ODEs in autonomous form and must be defined by a derived class | |
virtual void | ode_jac (double *solin, double **Jout) |
evaluates the system's Jacobian matrix, also in autonomous form, and can either be defined in a derived class or left to numerical approximation | |
virtual void | step_ (double dt)=0 |
advances a single time step (without changing counters or the time) and must be defined in the derived class implementing the solver/method | |
void | ode_fun_ (double *solin, double *fout) |
wrapper, calls ode_fun() and increases the neval counter by one | |
void | ode_jac_ (double *solin, double **Jout) |
wrapper, calls ode_jac() and increments nJac; | |
virtual void | before_solve () |
does any extra stuff before starting a solve | |
virtual void | after_step (double t) |
does any extra stuff after each step | |
virtual void | after_capture (double t) |
does any extra stuff only when a step is captured | |
virtual void | after_snap (std::string dirout, long isnap, double t) |
does any extra stuff after each snap | |
virtual void | after_solve () |
does any extra stuff after completing a solve | |
void | snap (std::string dirout, long isnap, double tsnap) |
writes the current value of the solution to a binary file | |
bool | solve_done (double dt, double tend) |
checks if the solution is within a single time step of the end point | |
void | check_sol_integrity () |
checks solution for nans and infs, exiting the program if they're found | |
void | check_pre_solve (double tint, double dt) |
checks that a solve can be performed with given tend and dt values | |
void | check_pre_snaps (double dt, double *tsnap, unsigned long nsnap) |
checks that snap times are monotonically increasing and > current time | |
Protected Attributes | |
std::string | name_ |
the "name" of the system, which is used for output | |
std::string | method_ |
the "name" of the solver/method, as in "Euler" or "RK4" | |
std::string | dirout_ |
output directory if one is being used by a solver | |
bool | quiet_ |
whether stuff should be printed during a solve | |
bool | silent_snap_ |
whether to skip writing the solution vector to file when snapping but still execute after_snap() | |
unsigned long | neq_ |
number of equations in the system of ODEs | |
double | t_ |
time, initialized to zero | |
double | dt_ |
time step is stored and updated during solves | |
double * | sol_ |
array for the solution, changing over time | |
long unsigned | nstep_ |
number of time steps | |
long unsigned | neval_ |
function evaluation counter, must be incremented in step() when defined | |
long unsigned | icheck_ |
interval of steps after which to check for nans and infs (zero to ignore) | |
double ** | Jac_ |
storage for the ODE system's Jacobian matrix, only allocated for the methods that need it | |
long unsigned | nJac_ |
counter for jacobian evaluations | |
double | absjacdel_ |
absolute adjustment fraction for numerical Jacobian, if needed | |
double | reljacdel_ |
relative adjustment fraction for numerical Jacobian, if needed | |
Lowest base class for all solvers.
This is the deepest base class, upon which all integrators and other base classes are built. It provides basic variables like the solution array, the independent variable, and a string defining the integrator's name. It implements the solve_fixed function for integrating with a fixed time step. When constructing, it will allocate space for a Jacobian matrix if the need_jac flag is true.
Definition at line 184 of file ode_base.h.
ode::OdeBase::OdeBase | ( | unsigned long | neq, |
bool | need_jac ) |
constructs
[in] | neq | number of equations in ODE system |
[in] | need_jac | flag signaling whether the Jacobian of the system is needed |
whether to skip writing the solution vector to file when snapping
Definition at line 7 of file ode_base.cc.
|
virtual |
destructs
Definition at line 47 of file ode_base.cc.
|
protectedvirtual |
does any extra stuff only when a step is captured
[in] | t | current value of ODE system's independent variable |
Definition at line 330 of file ode_base.cc.
|
protectedvirtual |
does any extra stuff after each snap
[in] | dirout | output directory (must already exist) |
[in] | isnap | index of snap being taken (from 0) |
[in] | t | current value of ODE system's independent variable |
Definition at line 335 of file ode_base.cc.
|
protectedvirtual |
does any extra stuff after completing a solve
Definition at line 342 of file ode_base.cc.
|
protectedvirtual |
does any extra stuff after each step
[in] | t | current value of ODE system's independent variable |
Definition at line 325 of file ode_base.cc.
|
protectedvirtual |
does any extra stuff before starting a solve
Definition at line 323 of file ode_base.cc.
|
protected |
checks that snap times are monotonically increasing and > current time
[in] | dt | time step size |
[in] | tsnap | array of snapshot times during integration |
[in] | nsnap | number of snapshots (length of tsnap) |
Definition at line 169 of file ode_base.cc.
|
protected |
checks that a solve can be performed with given tend and dt values
[in] | tint | duration of integration |
[in] | dt | time step size |
Definition at line 161 of file ode_base.cc.
|
protected |
checks solution for nans and infs, exiting the program if they're found
Definition at line 151 of file ode_base.cc.
|
inline |
gets output directory string if one has been set
Definition at line 204 of file ode_base.h.
|
inline |
gets the most recent or current time step size
Definition at line 217 of file ode_base.h.
|
inline |
gets the number of steps after which the solution is checked for integrity
Definition at line 228 of file ode_base.h.
|
inline |
gets the name of the solver/method
Definition at line 202 of file ode_base.h.
|
inline |
gets the name of the ODE system
Definition at line 200 of file ode_base.h.
|
inline |
gets the size of the ODE system
Definition at line 210 of file ode_base.h.
|
inline |
gets the total number of ODE system evaluation
Definition at line 226 of file ode_base.h.
|
inline |
gets the total number of Jacobian evaluations performed
Definition at line 230 of file ode_base.h.
|
inline |
gets the total number of steps taken
Definition at line 224 of file ode_base.h.
|
inline |
gets the boolean determining if updates are printed during solves
Definition at line 206 of file ode_base.h.
|
inline |
gets whether to skip writing the solution vector to file when snapping
Definition at line 208 of file ode_base.h.
|
inline |
gets a pointer to the whole solution array
Definition at line 219 of file ode_base.h.
|
inline |
gets an element of the solution array
[in] | i | index of element to get (sol[i]) |
Definition at line 222 of file ode_base.h.
|
inline |
gets the current value of the independent variable
The value of the independent variable is provided as a convenience and is used internally to track integration progress, but is not precisely accurate during steps. Libode solves systems in autonomous form. If the independent variable is needed during a step, an extra variable must be added to the system of ODEs to represent it. The corresponding extra ODE is always one. For example, if the independent variable is t for time, the extra ODE states dt/dt = 1.
Definition at line 215 of file ode_base.h.
|
protectedpure virtual |
evaluates the system of ODEs in autonomous form and must be defined by a derived class
The incoming solin
vector contains the current values of all solution variables and has length neq
. The output vector should be filled with the time derivatives for each variable in solin
. All elements of fout
should be set, even if they're zero, because the fout
array isn't cleared before it's reused.
[in] | solin | current solution array |
[out] | fout | evaluation of system of ordinary differential equations |
|
protected |
wrapper, calls ode_fun() and increases the neval counter by one
This function should never be called by a top-level integrating class
[in] | solin | current solution array |
[out] | fout | Jacobian of ode_fun |
Definition at line 87 of file ode_base.cc.
|
protectedvirtual |
evaluates the system's Jacobian matrix, also in autonomous form, and can either be defined in a derived class or left to numerical approximation
The incoming solin
vector contains the current values of all solution variables and has length neq
. The output array Jout
is a 2D array with size neq
x neq
. All elements of Jout
should be set, even if they're zero, because the Jout
array isn't cleared before it's reused. If the Jacobian is needed and there is no overriding definition of this function, a finite differences approximation is used.
[in] | solin | current solution array |
[out] | Jout | Jacobian of ode_fun |
Definition at line 60 of file ode_base.cc.
|
protected |
wrapper, calls ode_jac() and increments nJac;
This function should never be called by a top-level integrating class
[in] | solin | current solution array |
[out] | Jout | Jacobian of ode_fun |
Definition at line 95 of file ode_base.cc.
void ode::OdeBase::reset | ( | double | t, |
double * | sol ) |
reset to a specified time and initial condition array
[in] | t | new value of independent variable |
[in] | sol | array of new values for solution array |
Definition at line 314 of file ode_base.cc.
|
inline |
sets the number of steps after which the solution is checked for integrity
Definition at line 253 of file ode_base.h.
|
inline |
sets the name of the ODE system
Definition at line 247 of file ode_base.h.
|
inline |
sets the name of the ODE system
Definition at line 245 of file ode_base.h.
|
inline |
sets the boolean determining if updates are printed during solves
Definition at line 249 of file ode_base.h.
|
inline |
sets whether to skip writing the solution vector to file when snapping
Definition at line 251 of file ode_base.h.
|
inline |
copies an array into the solution array
[in] | sol | an array of length neq to copy into the solution vector |
Definition at line 243 of file ode_base.h.
|
inline |
sets an element of the solution array
[in] | i | index of solution element to set |
[in] | x | value to copy into sol[i] |
Definition at line 240 of file ode_base.h.
|
inline |
sets the "time," or independent variable used to track progress
Because libode solves system in autonomous form, the "time" t
is just an internal tracker for the integrating functions. See get_t()
. Nevertheless, this function will set the internal value of the integrator's t
variable.
Definition at line 234 of file ode_base.h.
|
protected |
writes the current value of the solution to a binary file
[in] | dirout | output directory (must already exist) |
[in] | isnap | the index of the snap |
[in] | tsnap | independent variable value for snapshot |
Definition at line 122 of file ode_base.cc.
|
protected |
checks if the solution is within a single time step of the end point
[in] | dt | time step duration |
[in] | tend | end time |
Definition at line 141 of file ode_base.cc.
void ode::OdeBase::solve_fixed | ( | double | dt, |
double * | tsnap, | ||
unsigned long | nsnap, | ||
const char * | dirout ) |
solves and writes snapshots at times specified in the tsnap array
[in] | dt | time step size |
[in] | tsnap | array of desired snapshot times |
[in] | nsnap | number of snapshots (length of tsnap) |
[in] | dirout | output directory (must already exist) |
Definition at line 283 of file ode_base.cc.
void ode::OdeBase::solve_fixed | ( | double | tint, |
double | dt, | ||
bool | extras = true ) |
integrates for a specified duration of independent variable without output
[in] | tint | total integration time |
[in] | dt | time step size |
[in] | extras | whether to call all the extra functions (before_solve, after_step, ...) |
Definition at line 192 of file ode_base.cc.
void ode::OdeBase::solve_fixed | ( | double | tint, |
double | dt, | ||
const char * | dirout, | ||
int | inter = 1 ) |
lots of output, solves and stores every "inter" point along the way
[in] | tint | total integration time |
[in] | dt | time step size |
[in] | dirout | output directory (must already exist) |
[in] | inter | interval of steps to store and output |
Definition at line 208 of file ode_base.cc.
void ode::OdeBase::solve_fixed | ( | double | tint, |
double | dt, | ||
unsigned long | nsnap, | ||
const char * | dirout ) |
solves and writes evenly spaced snapshots
[in] | tint | total integration time |
[in] | dt | time step size |
[in] | nsnap | number of snapshots to output |
[in] | dirout | output directory (must already exist) |
Definition at line 266 of file ode_base.cc.
|
protected |
integrates without output or any counters, trackers, extra functions...
[in] | tint | total integration time |
[in] | dt | time step size |
[in] | extra | whether to call after_step() |
Definition at line 182 of file ode_base.cc.
void ode::OdeBase::step | ( | double | dt, |
bool | extra = true ) |
increments the step counter and the time, checks the solution integrity if needed, stores the time step in the object, and executes after_step() if extra is true
Definition at line 103 of file ode_base.cc.
|
protectedpure virtual |
advances a single time step (without changing counters or the time) and must be defined in the derived class implementing the solver/method
This is a virtual function overridden by the class which implements the stepping algorightm. It should never be used outside of the wrapper step() function, and this wrapper should always be used instead.
[in] | dt | time step size |
|
protected |
absolute adjustment fraction for numerical Jacobian, if needed
Definition at line 345 of file ode_base.h.
|
protected |
output directory if one is being used by a solver
Definition at line 321 of file ode_base.h.
|
protected |
time step is stored and updated during solves
Definition at line 331 of file ode_base.h.
|
protected |
interval of steps after which to check for nans and infs (zero to ignore)
Definition at line 339 of file ode_base.h.
|
protected |
storage for the ODE system's Jacobian matrix, only allocated for the methods that need it
Definition at line 341 of file ode_base.h.
|
protected |
the "name" of the solver/method, as in "Euler" or "RK4"
Definition at line 319 of file ode_base.h.
|
protected |
the "name" of the system, which is used for output
Definition at line 317 of file ode_base.h.
|
protected |
number of equations in the system of ODEs
Definition at line 327 of file ode_base.h.
|
protected |
function evaluation counter, must be incremented in step() when defined
Definition at line 337 of file ode_base.h.
|
protected |
counter for jacobian evaluations
Definition at line 343 of file ode_base.h.
|
protected |
number of time steps
Definition at line 335 of file ode_base.h.
|
protected |
whether stuff should be printed during a solve
Definition at line 323 of file ode_base.h.
|
protected |
relative adjustment fraction for numerical Jacobian, if needed
Definition at line 347 of file ode_base.h.
|
protected |
whether to skip writing the solution vector to file when snapping but still execute after_snap()
Definition at line 325 of file ode_base.h.
|
protected |
array for the solution, changing over time
Definition at line 333 of file ode_base.h.
|
protected |
time, initialized to zero
Definition at line 329 of file ode_base.h.