Public Types | Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
o2scl::ode_iv_solve< func_t, vec_t > Class Template Reference

Solve an initial-value ODE problems given an adaptive ODE stepper. More...

#include <ode_iv_solve.h>

Public Types

typedef boost::numeric::ublas::vector< double > ubvector
 

Public Member Functions

virtual const char * type ()
 Return the type, "ode_iv_solve".
 
Main solver functions
int solve_final_value (double x0, double x1, double h, size_t n, vec_t &ystart, vec_t &yend, func_t &derivs)
 Solve the initial-value problem to get the final value. More...
 
int solve_final_value (double x0, double x1, double h, size_t n, vec_t &ystart, vec_t &yend, vec_t &yerr, func_t &derivs)
 Solve the initial-value problem to get the final value with errors. More...
 
int solve_final_value (double x0, double x1, double h, size_t n, vec_t &ystart, vec_t &yend, vec_t &yerr, vec_t &dydx_end, func_t &derivs)
 Solve the initial-value problem to get the final value, derivatives, and errors. More...
 
template<class mat_t >
int solve_store (double x0, double x1, double h, size_t n, size_t &n_sol, vec_t &x_sol, mat_t &y_sol, mat_t &yerr_sol, mat_t &dydx_sol, func_t &derivs, size_t istart=0)
 Solve the initial-value problem and store the associated output. More...
 
template<class mat_t , class mat_row_t >
int solve_grid (double h, size_t n, size_t nsol, vec_t &xsol, mat_t &ysol, mat_t &err_sol, mat_t &dydx_sol, func_t &derivs)
 Solve the initial-value problem from x0 to x1 over a grid storing derivatives and errors. More...
 

Public Attributes

int verbose
 Set output level.
 
size_t nsteps_out
 Number of output points for verbose output (default 10) More...
 
size_t ntrial
 Maximum number of applications of the adaptive stepper (default 1000)
 
size_t nsteps
 Number of adaptive ste!ps employed.
 

Protected Member Functions

virtual int print_iter (double x, size_t nv, vec_t &y)
 Print out iteration information.
 
void free ()
 Free allocated memory.
 
void allocate (size_t n)
 Allocate space for temporary vectors.
 

Protected Attributes

size_t mem_size
 Desc.
 
astep_base< vec_t, vec_t, vec_t, func_t > * astp
 The adaptive stepper.
 
Vectors for temporary storage
vec_t vtemp
 
vec_t vtemp2
 
vec_t vtemp3
 
vec_t vtemp4
 

The adaptive stepper

bool exit_on_fail
 If true, stop the solution if the adaptive stepper fails (default true) More...
 
astep_gsl< vec_t, vec_t, vec_t, func_t > gsl_astp
 The default adaptive stepper.
 
int set_astep (astep_base< vec_t, vec_t, vec_t, func_t > &as)
 Set the adaptive stepper to use.
 

Detailed Description

template<class func_t = ode_funct11, class vec_t = boost::numeric::ublas::vector<double>>
class o2scl::ode_iv_solve< func_t, vec_t >

This class is experimental.

This class gives several functions which solve an initial value ODE problem. The functions solve_final_value() give only the final value of the functions at the end of the ODE integration and are relatively fast.

The function solve_store() stores the solution of the ODE over the full range into a set of vectors and matrices which are allocated and specified by the user. This function is designed to give exactly the same results (though this cannot be guaranteed) as solve_final_value() and additionally records some or all of the results from the adaptive steps which were taken.

The functions solve_grid() works as in solve_store() except that the solution is stored on a grid of points in the independent variable specified by the user, at the cost of taking extra steps to ensure that function values, derivatives, and errors are computed at each grid point.

All of these functions automatically evaluate the derivatives from the specified function at the initial point and user-specified initial derivatives are ignored. The total number of steps taken is limited by ntrial and nsteps stores the number of steps taken by the most recent solution. The variable nsteps_out is the maximum number of points in the interval for which verbose output will be given when o2scl::ode_iv_solve::verbose is greater than zero.

There is an example for the usage of this class in examples/ex_ode.cpp documented in the Ordinary differential equations example section.

Documentation links for default template arguments

The default adaptive stepper is an object of type astep_gsl.

Idea for Future:
The form of solve_final_value() is very similar to that of astep_base::astep_full(), but not quite the same. Maybe should probably be made to be consistent with each other?

Definition at line 91 of file ode_iv_solve.h.

Member Function Documentation

◆ solve_final_value() [1/3]

template<class func_t = ode_funct11, class vec_t = boost::numeric::ublas::vector<double>>
int o2scl::ode_iv_solve< func_t, vec_t >::solve_final_value ( double  x0,
double  x1,
double  h,
size_t  n,
vec_t &  ystart,
vec_t &  yend,
func_t &  derivs 
)
inline

Given the n initial values of the functions in ystart, this function integrates the ODEs specified in derivs over the interval from x0 to x1 with an initial stepsize of h. The final values of the function are given in yend and the initial values of yend are ignored.

If verbose is greater than zero, The solution at less than or approximately equal to nsteps_out points will be written to std::cout. If verbose is greater than one, a character will be required after each selected point.

Todo:
Document if yend can be the same as ystart.

Definition at line 181 of file ode_iv_solve.h.

◆ solve_final_value() [2/3]

template<class func_t = ode_funct11, class vec_t = boost::numeric::ublas::vector<double>>
int o2scl::ode_iv_solve< func_t, vec_t >::solve_final_value ( double  x0,
double  x1,
double  h,
size_t  n,
vec_t &  ystart,
vec_t &  yend,
vec_t &  yerr,
func_t &  derivs 
)
inline

Given the n initial values of the functions in ystart, this function integrates the ODEs specified in derivs over the interval from x0 to x1 with an initial stepsize of h. The final values of the function are given in yend and the associated errors are given in yerr. The initial values of yend and yerr are ignored.

If verbose is greater than zero, The solution at less than or approximately equal to nsteps_out points will be written to std::cout. If verbose is greater than one, a character will be required after each selected point.

Definition at line 204 of file ode_iv_solve.h.

◆ solve_final_value() [3/3]

template<class func_t = ode_funct11, class vec_t = boost::numeric::ublas::vector<double>>
int o2scl::ode_iv_solve< func_t, vec_t >::solve_final_value ( double  x0,
double  x1,
double  h,
size_t  n,
vec_t &  ystart,
vec_t &  yend,
vec_t &  yerr,
vec_t &  dydx_end,
func_t &  derivs 
)
inline

Given the n initial values of the functions in ystart, this function integrates the ODEs specified in derivs over the interval from x0 to x1 with an initial stepsize of h. The final values of the function are given in yend, the derivatives in dydx_end, and the associated errors are given in yerr. The initial values of yend and yerr are ignored.

This function is designed to be relatively fast, avoiding extra copying of vectors back and forth.

If verbose is greater than zero, The solution at less than or approximately equal to nsteps_out points will be written to std::cout. If verbose is greater than one, a character will be required after each selected point.

This function computes dydx_start automatically and the values given by the user are ignored.

The solution fails if more than ntrial steps are required. This function will also fail if x1>x0 and h<0 or if x1-x0 and h>0 do not have the same sign.

Definition at line 239 of file ode_iv_solve.h.

◆ solve_grid()

template<class func_t = ode_funct11, class vec_t = boost::numeric::ublas::vector<double>>
template<class mat_t , class mat_row_t >
int o2scl::ode_iv_solve< func_t, vec_t >::solve_grid ( double  h,
size_t  n,
size_t  nsol,
vec_t &  xsol,
mat_t &  ysol,
mat_t &  err_sol,
mat_t &  dydx_sol,
func_t &  derivs 
)
inline

Initially, xsol should be an array of size nsol, and ysol should be a ubmatrix of size [nsol][n]. This function never takes a step larger than the grid size.

If verbose is greater than zero, The solution at each grid point will be written to std::cout. If verbose is greater than one, a character will be required after each point.

Idea for Future:
Consider making a version of grid which gives the same answers as solve_final_value(). After each proposed step, it would go back and fill in the grid points if the proposed step was past the next grid point.

Definition at line 612 of file ode_iv_solve.h.

◆ solve_store()

template<class func_t = ode_funct11, class vec_t = boost::numeric::ublas::vector<double>>
template<class mat_t >
int o2scl::ode_iv_solve< func_t, vec_t >::solve_store ( double  x0,
double  x1,
double  h,
size_t  n,
size_t &  n_sol,
vec_t &  x_sol,
mat_t &  y_sol,
mat_t &  yerr_sol,
mat_t &  dydx_sol,
func_t &  derivs,
size_t  istart = 0 
)
inline

Initially, x_sol should be a vector of size n_sol, and y_sol, dydx_sol, and yerr_sol should be matrices with size [n_sol][n]. On exit, n_sol will will be number of points store, less than or equal to the original value of n_sol. This function avoids performing extra calls to the adaptive stepper, and the table will be approximately evenly spaced.

This function is also designed to give the exactly the same results as solve_final_value(). This cannot be strictly guaranteed, but will likely hold in most applications.

This template function works with any matrix class mat_t which can be accessed using successive applications of operator[] and which has an associated class mat_row_t which returns a row of a matrix of type mat_t as an object with type vec_t.

If verbose is greater than zero, The solution at each internal point will be written to std::cout. If verbose is greater than one, a character will be required after each point.

Idea for Future:
It might be possible to remove some extra copying by removing the yerrl and dydx vectors

Definition at line 438 of file ode_iv_solve.h.

Member Data Documentation

◆ exit_on_fail

template<class func_t = ode_funct11, class vec_t = boost::numeric::ublas::vector<double>>
bool o2scl::ode_iv_solve< func_t, vec_t >::exit_on_fail

If this is false, then failures in the adaptive stepper are ignored.

Definition at line 738 of file ode_iv_solve.h.

◆ nsteps_out

template<class func_t = ode_funct11, class vec_t = boost::numeric::ublas::vector<double>>
size_t o2scl::ode_iv_solve< func_t, vec_t >::nsteps_out

This is used in functions solve_table() and solve_final_value() to control how often steps are output when verbose is greater than zero.

Definition at line 716 of file ode_iv_solve.h.


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

Documentation generated with Doxygen. Provided under the GNU Free Documentation License (see License Information).