Object-oriented Scientific Computing Library: Version 0.910
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
ode_iv_solve< func_t, vec_t, alloc_vec_t, alloc_t > Class Template Reference

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

#include <ode_iv_solve.h>

Inheritance diagram for ode_iv_solve< func_t, vec_t, alloc_vec_t, alloc_t >:
ode_iv_table< func_t, vec_t, alloc_vec_t, alloc_t >

Detailed Description

template<class func_t = ode_funct<>, class vec_t = ovector_base, class alloc_vec_t = ovector, class alloc_t = ovector_alloc>
class ode_iv_solve< func_t, vec_t, alloc_vec_t, alloc_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 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 section.

Default template arguments

The default adaptive stepper is an object of type gsl_astep.

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

Definition at line 84 of file ode_iv_solve.h.

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.
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.
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.
template<class mat_t , class mat_row_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.
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.

Data Fields

int verbose
 Set output level.
size_t nsteps_out
 Number of output points if verbose is greater than zero (default 10)
size_t ntrial
 Maximum number of applications of the adaptive stepper (default 1000)
size_t nsteps
 Number of adaptive steps 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

alloc_t ao
 Memory allocator.
size_t mem_size
 Desc.
adapt_step< func_t, vec_t,
alloc_vec_t, alloc_t > * 
astp
 The adaptive stepper.
Desc
alloc_vec_t vtemp
alloc_vec_t vtemp2
alloc_vec_t vtemp3
alloc_vec_t vtemp4

The adaptive stepper

bool exit_on_fail
 If true, stop the solution if the adaptive stepper fails (default true)
gsl_astep< func_t, vec_t,
alloc_vec_t, alloc_t > 
gsl_astp
 The default adaptive stepper.
int set_adapt_step (adapt_step< func_t, vec_t, alloc_vec_t, alloc_t > &as)
 Set the adaptive stepper to use.

Member Function Documentation

template<class func_t = ode_funct<>, class vec_t = ovector_base, class alloc_vec_t = ovector, class alloc_t = ovector_alloc>
int ode_iv_solve< func_t, vec_t, alloc_vec_t, alloc_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 172 of file ode_iv_solve.h.

template<class func_t = ode_funct<>, class vec_t = ovector_base, class alloc_vec_t = ovector, class alloc_t = ovector_alloc>
int ode_iv_solve< func_t, vec_t, alloc_vec_t, alloc_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 195 of file ode_iv_solve.h.

template<class func_t = ode_funct<>, class vec_t = ovector_base, class alloc_vec_t = ovector, class alloc_t = ovector_alloc>
int ode_iv_solve< func_t, vec_t, alloc_vec_t, alloc_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 but h>0.

Definition at line 230 of file ode_iv_solve.h.

template<class func_t = ode_funct<>, class vec_t = ovector_base, class alloc_vec_t = ovector, class alloc_t = ovector_alloc>
template<class mat_t , class mat_row_t >
int ode_iv_solve< func_t, vec_t, alloc_vec_t, alloc_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 425 of file ode_iv_solve.h.

template<class func_t = ode_funct<>, class vec_t = ovector_base, class alloc_vec_t = ovector, class alloc_t = ovector_alloc>
template<class mat_t , class mat_row_t >
int ode_iv_solve< func_t, vec_t, alloc_vec_t, alloc_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 omatrix 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 598 of file ode_iv_solve.h.


Field Documentation

template<class func_t = ode_funct<>, class vec_t = ovector_base, class alloc_vec_t = ovector, class alloc_t = ovector_alloc>
size_t ode_iv_solve< func_t, vec_t, alloc_vec_t, alloc_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 702 of file ode_iv_solve.h.

template<class func_t = ode_funct<>, class vec_t = ovector_base, class alloc_vec_t = ovector, class alloc_t = ovector_alloc>
bool ode_iv_solve< func_t, vec_t, alloc_vec_t, alloc_t >::exit_on_fail

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

Definition at line 724 of file ode_iv_solve.h.


The documentation for this class was generated from the following file:
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

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

Get Object-oriented Scientific Computing
Lib at SourceForge.net. Fast, secure and Free Open Source software
downloads.