libode
Easy to compile, fast ODE integrators as C++ classes
Loading...
Searching...
No Matches
ode::OdeBase Class Referenceabstract

Lowest base class for all solvers. More...

#include <ode_base.h>

Inheritance diagram for ode::OdeBase:
ode::OdeAdaptive ode::OdeBackwardEuler ode::OdeEmbedded ode::OdeEuler ode::OdeGauss6 ode::OdeGeng5 ode::OdeLobattoIIIC6 ode::OdeRK4 ode::OdeROW6A ode::OdeRadauIIA5 ode::OdeSsp3 ode::OdeTrapz

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
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ OdeBase()

ode::OdeBase::OdeBase ( unsigned long neq,
bool need_jac )

constructs

Parameters
[in]neqnumber of equations in ODE system
[in]need_jacflag 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.

◆ ~OdeBase()

ode::OdeBase::~OdeBase ( )
virtual

destructs

Definition at line 47 of file ode_base.cc.

Member Function Documentation

◆ after_capture()

void ode::OdeBase::after_capture ( double t)
protectedvirtual

does any extra stuff only when a step is captured

Parameters
[in]tcurrent value of ODE system's independent variable

Definition at line 330 of file ode_base.cc.

◆ after_snap()

void ode::OdeBase::after_snap ( std::string dirout,
long isnap,
double t )
protectedvirtual

does any extra stuff after each snap

Parameters
[in]diroutoutput directory (must already exist)
[in]isnapindex of snap being taken (from 0)
[in]tcurrent value of ODE system's independent variable

Definition at line 335 of file ode_base.cc.

◆ after_solve()

void ode::OdeBase::after_solve ( )
protectedvirtual

does any extra stuff after completing a solve

Definition at line 342 of file ode_base.cc.

◆ after_step()

void ode::OdeBase::after_step ( double t)
protectedvirtual

does any extra stuff after each step

Parameters
[in]tcurrent value of ODE system's independent variable

Definition at line 325 of file ode_base.cc.

◆ before_solve()

void ode::OdeBase::before_solve ( )
protectedvirtual

does any extra stuff before starting a solve

Definition at line 323 of file ode_base.cc.

◆ check_pre_snaps()

void ode::OdeBase::check_pre_snaps ( double dt,
double * tsnap,
unsigned long nsnap )
protected

checks that snap times are monotonically increasing and > current time

Parameters
[in]dttime step size
[in]tsnaparray of snapshot times during integration
[in]nsnapnumber of snapshots (length of tsnap)

Definition at line 169 of file ode_base.cc.

◆ check_pre_solve()

void ode::OdeBase::check_pre_solve ( double tint,
double dt )
protected

checks that a solve can be performed with given tend and dt values

Parameters
[in]tintduration of integration
[in]dttime step size

Definition at line 161 of file ode_base.cc.

◆ check_sol_integrity()

void ode::OdeBase::check_sol_integrity ( )
protected

checks solution for nans and infs, exiting the program if they're found

Definition at line 151 of file ode_base.cc.

◆ get_dirout()

const char * ode::OdeBase::get_dirout ( )
inline

gets output directory string if one has been set

Definition at line 204 of file ode_base.h.

◆ get_dt()

double ode::OdeBase::get_dt ( )
inline

gets the most recent or current time step size

Definition at line 217 of file ode_base.h.

◆ get_icheck()

long unsigned ode::OdeBase::get_icheck ( )
inline

gets the number of steps after which the solution is checked for integrity

Definition at line 228 of file ode_base.h.

◆ get_method()

const char * ode::OdeBase::get_method ( )
inline

gets the name of the solver/method

Definition at line 202 of file ode_base.h.

◆ get_name()

const char * ode::OdeBase::get_name ( )
inline

gets the name of the ODE system

Definition at line 200 of file ode_base.h.

◆ get_neq()

unsigned long ode::OdeBase::get_neq ( )
inline

gets the size of the ODE system

Definition at line 210 of file ode_base.h.

◆ get_neval()

long unsigned ode::OdeBase::get_neval ( )
inline

gets the total number of ODE system evaluation

Definition at line 226 of file ode_base.h.

◆ get_nJac()

long unsigned ode::OdeBase::get_nJac ( )
inline

gets the total number of Jacobian evaluations performed

Definition at line 230 of file ode_base.h.

◆ get_nstep()

long unsigned ode::OdeBase::get_nstep ( )
inline

gets the total number of steps taken

Definition at line 224 of file ode_base.h.

◆ get_quiet()

bool ode::OdeBase::get_quiet ( )
inline

gets the boolean determining if updates are printed during solves

Definition at line 206 of file ode_base.h.

◆ get_silent_snap()

bool ode::OdeBase::get_silent_snap ( )
inline

gets whether to skip writing the solution vector to file when snapping

Definition at line 208 of file ode_base.h.

◆ get_sol() [1/2]

double * ode::OdeBase::get_sol ( )
inline

gets a pointer to the whole solution array

Definition at line 219 of file ode_base.h.

◆ get_sol() [2/2]

double ode::OdeBase::get_sol ( unsigned long i)
inline

gets an element of the solution array

Parameters
[in]iindex of element to get (sol[i])

Definition at line 222 of file ode_base.h.

◆ get_t()

double ode::OdeBase::get_t ( )
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.

◆ ode_fun()

virtual void ode::OdeBase::ode_fun ( double * solin,
double * fout )
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.

Parameters
[in]solincurrent solution array
[out]foutevaluation of system of ordinary differential equations

◆ ode_fun_()

void ode::OdeBase::ode_fun_ ( double * solin,
double * fout )
protected

wrapper, calls ode_fun() and increases the neval counter by one

This function should never be called by a top-level integrating class

Parameters
[in]solincurrent solution array
[out]foutJacobian of ode_fun

Definition at line 87 of file ode_base.cc.

◆ ode_jac()

void ode::OdeBase::ode_jac ( double * solin,
double ** Jout )
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.

Parameters
[in]solincurrent solution array
[out]JoutJacobian of ode_fun

Definition at line 60 of file ode_base.cc.

◆ ode_jac_()

void ode::OdeBase::ode_jac_ ( double * solin,
double ** Jout )
protected

wrapper, calls ode_jac() and increments nJac;

This function should never be called by a top-level integrating class

Parameters
[in]solincurrent solution array
[out]JoutJacobian of ode_fun

Definition at line 95 of file ode_base.cc.

◆ reset()

void ode::OdeBase::reset ( double t,
double * sol )

reset to a specified time and initial condition array

Parameters
[in]tnew value of independent variable
[in]solarray of new values for solution array

Definition at line 314 of file ode_base.cc.

◆ set_icheck()

void ode::OdeBase::set_icheck ( unsigned long icheck)
inline

sets the number of steps after which the solution is checked for integrity

Definition at line 253 of file ode_base.h.

◆ set_name() [1/2]

void ode::OdeBase::set_name ( const char * name)
inline

sets the name of the ODE system

Definition at line 247 of file ode_base.h.

◆ set_name() [2/2]

void ode::OdeBase::set_name ( std::string name)
inline

sets the name of the ODE system

Definition at line 245 of file ode_base.h.

◆ set_quiet()

void ode::OdeBase::set_quiet ( bool quiet)
inline

sets the boolean determining if updates are printed during solves

Definition at line 249 of file ode_base.h.

◆ set_silent_snap()

void ode::OdeBase::set_silent_snap ( bool silent_snap)
inline

sets whether to skip writing the solution vector to file when snapping

Definition at line 251 of file ode_base.h.

◆ set_sol() [1/2]

void ode::OdeBase::set_sol ( double * sol)
inline

copies an array into the solution array

Parameters
[in]solan array of length neq to copy into the solution vector

Definition at line 243 of file ode_base.h.

◆ set_sol() [2/2]

void ode::OdeBase::set_sol ( unsigned long i,
double x )
inline

sets an element of the solution array

Parameters
[in]iindex of solution element to set
[in]xvalue to copy into sol[i]

Definition at line 240 of file ode_base.h.

◆ set_t()

void ode::OdeBase::set_t ( double t)
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.

◆ snap()

void ode::OdeBase::snap ( std::string dirout,
long isnap,
double tsnap )
protected

writes the current value of the solution to a binary file

Parameters
[in]diroutoutput directory (must already exist)
[in]isnapthe index of the snap
[in]tsnapindependent variable value for snapshot

Definition at line 122 of file ode_base.cc.

◆ solve_done()

bool ode::OdeBase::solve_done ( double dt,
double tend )
protected

checks if the solution is within a single time step of the end point

Parameters
[in]dttime step duration
[in]tendend time
Returns
true if the solution is within a step of the end, otherwise false

Definition at line 141 of file ode_base.cc.

◆ solve_fixed() [1/4]

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

Parameters
[in]dttime step size
[in]tsnaparray of desired snapshot times
[in]nsnapnumber of snapshots (length of tsnap)
[in]diroutoutput directory (must already exist)

Definition at line 283 of file ode_base.cc.

◆ solve_fixed() [2/4]

void ode::OdeBase::solve_fixed ( double tint,
double dt,
bool extras = true )

integrates for a specified duration of independent variable without output

Parameters
[in]tinttotal integration time
[in]dttime step size
[in]extraswhether to call all the extra functions (before_solve, after_step, ...)

Definition at line 192 of file ode_base.cc.

◆ solve_fixed() [3/4]

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

Parameters
[in]tinttotal integration time
[in]dttime step size
[in]diroutoutput directory (must already exist)
[in]interinterval of steps to store and output

Definition at line 208 of file ode_base.cc.

◆ solve_fixed() [4/4]

void ode::OdeBase::solve_fixed ( double tint,
double dt,
unsigned long nsnap,
const char * dirout )

solves and writes evenly spaced snapshots

Parameters
[in]tinttotal integration time
[in]dttime step size
[in]nsnapnumber of snapshots to output
[in]diroutoutput directory (must already exist)

Definition at line 266 of file ode_base.cc.

◆ solve_fixed_()

void ode::OdeBase::solve_fixed_ ( double tint,
double dt,
bool extra = true )
protected

integrates without output or any counters, trackers, extra functions...

Parameters
[in]tinttotal integration time
[in]dttime step size
[in]extrawhether to call after_step()

Definition at line 182 of file ode_base.cc.

◆ step()

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.

◆ step_()

virtual void ode::OdeBase::step_ ( double dt)
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.

Parameters
[in]dttime step size

Member Data Documentation

◆ absjacdel_

double ode::OdeBase::absjacdel_
protected

absolute adjustment fraction for numerical Jacobian, if needed

Definition at line 345 of file ode_base.h.

◆ dirout_

std::string ode::OdeBase::dirout_
protected

output directory if one is being used by a solver

Definition at line 321 of file ode_base.h.

◆ dt_

double ode::OdeBase::dt_
protected

time step is stored and updated during solves

Definition at line 331 of file ode_base.h.

◆ icheck_

long unsigned ode::OdeBase::icheck_
protected

interval of steps after which to check for nans and infs (zero to ignore)

Definition at line 339 of file ode_base.h.

◆ Jac_

double** ode::OdeBase::Jac_
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.

◆ method_

std::string ode::OdeBase::method_
protected

the "name" of the solver/method, as in "Euler" or "RK4"

Definition at line 319 of file ode_base.h.

◆ name_

std::string ode::OdeBase::name_
protected

the "name" of the system, which is used for output

Definition at line 317 of file ode_base.h.

◆ neq_

unsigned long ode::OdeBase::neq_
protected

number of equations in the system of ODEs

Definition at line 327 of file ode_base.h.

◆ neval_

long unsigned ode::OdeBase::neval_
protected

function evaluation counter, must be incremented in step() when defined

Definition at line 337 of file ode_base.h.

◆ nJac_

long unsigned ode::OdeBase::nJac_
protected

counter for jacobian evaluations

Definition at line 343 of file ode_base.h.

◆ nstep_

long unsigned ode::OdeBase::nstep_
protected

number of time steps

Definition at line 335 of file ode_base.h.

◆ quiet_

bool ode::OdeBase::quiet_
protected

whether stuff should be printed during a solve

Definition at line 323 of file ode_base.h.

◆ reljacdel_

double ode::OdeBase::reljacdel_
protected

relative adjustment fraction for numerical Jacobian, if needed

Definition at line 347 of file ode_base.h.

◆ silent_snap_

bool ode::OdeBase::silent_snap_
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.

◆ sol_

double* ode::OdeBase::sol_
protected

array for the solution, changing over time

Definition at line 333 of file ode_base.h.

◆ t_

double ode::OdeBase::t_
protected

time, initialized to zero

Definition at line 329 of file ode_base.h.


The documentation for this class was generated from the following files: