Solve an initial-value ODE problems given an adaptive ODE stepper. More...
#include <ode_iv_solve.h>
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
func_t
- ode_functvec_t
- boost::numeric::ublas::vector < double >The default adaptive stepper is an object of type astep_gsl.
Definition at line 91 of file 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 ¥d, 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 ¥d, 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 ¥d, 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 |
The size of the temporary vectors. | |
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. | |
|
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.
Definition at line 179 of file ode_iv_solve.h.
|
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 202 of file ode_iv_solve.h.
|
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 237 of file ode_iv_solve.h.
|
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.
Definition at line 607 of file ode_iv_solve.h.
|
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 solution 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.
Definition at line 433 of file ode_iv_solve.h.
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 731 of file ode_iv_solve.h.
size_t o2scl::ode_iv_solve< func_t, vec_t >::nsteps_out |
This is used in functions solve_store() and solve_final_value() to control how often steps are output when verbose is greater than zero.
Definition at line 709 of file ode_iv_solve.h.
Documentation generated with Doxygen. Provided under the
GNU Free Documentation License (see License Information).