SLBM  3.0
Regional Seismic Travel Time
Public Member Functions | Private Member Functions | Private Attributes | List of all members
util::IntegrateFunction< F > Class Template Reference

Class supports numerical integration of an arbitrary function using a fourth order Simpsons rule for closed intervals. Open intervals at one end-point are handled by using Simpsons rule in a segmented sense to approach the unbounded limit in successive iterations each time dividing the difference to the unbounded limit by 10.0. More...

#include <IntegrateFunction.h>

Public Member Functions

 IntegrateFunction (F &f, double tol)
 Standard Constructor. More...
 
 IntegrateFunction (const IntegrateFunction< F > &ifctn)
 Copy Constructor. More...
 
virtual ~IntegrateFunction ()
 Destructor. More...
 
IntegrateFunction< F > & operator= (const IntegrateFunction< F > &ifctn)
 Assignment Operator. More...
 
double integrateClosed (double a, double b)
 Adaptive closed form numerical integration of the input function over the closed interval a to b. The function is assumed to be defined over the entire interval [a, b]. The function uses the 3 point Simpsons rule to evaluate all sub-intervals. More...
 
double integrateAOpenS (double a, double b)
 Adaptive closed form numerical integration of the input function over the open interval a to b, where the integrand function is undefined at a. The function uses the 3 point Simpsons rule to evaluate all sub-intervals. and slowly encroaches on the limit a until convergence is attained. More...
 
F & getF ()
 Returns a reference to the integrated function. More...
 
const F & getF () const
 Returns a const reference to the integrated function. More...
 
void setTolerance (double tol)
 Sets the integration tolerance value. More...
 
double getTolerance () const
 Returns the integration tolerance value. More...
 

Private Member Functions

double integrateClosedRcrsv (double a, double b, double *fr)
 Returns the test 5 integral value. More...
 
double simpson (double a, double b, double *fa, double &s)
 A 3 point 4th order Simpsons integration rule. More...
 

Private Attributes

double ifTol
 The integration convergence tolerance. More...
 
F & ifF
 The function to be integrated numerically. More...
 

Detailed Description

template<class F>
class util::IntegrateFunction< F >

This object must be instantiated with the function to be integrated. A tolerance may be provided at instantiation or reset to another value at a later time. Both the function to be integrated and the tolerance can be accessed with predefined "get" functions.

The integration functions are integrateClosed(...) and integrateAOpen(...) defined below. The function integrateClosed(...) is a recursively adaptive function that resolves the interval into one or more sub-intervals until the convergence tolerance is met. Unlike their non-adaptive counterparts these functions resolve each region of the function to whatever resolution is required to meet the accuracy requirement. The open interval version uses the closed interval definition for all internal sub-intervals. The closed interval simpson rule is defined by

(h/3)(f0 + 4*f1 + f2)

where h is the interval width, f0 is the function to be integrated defined at the left most range, f2 is defined at the right most range, and f1 is defined at the mid-point of the range.

The simpsons adaptive integration evalutes the integral across a sub- interval range using the rule 3 times, once across the sub-interval, once across the 1st half of the sub-interval and once across the second half of the sub-interval. The split halves are summed to form one result while the entire interval evaluation forms the other. The former has an accuracy that is about 4 times greater than the entire interval evaluation. Convergence is attained when the difference between the two is less than the input tolerance. Five function evaluation are required for each call to the closed form Simpson rule.

The function integrateAOpen(...) solves an improper integral containing an unbounded integrand at the initial limit a (of a,b). This function uses the closed form Simpsons solution to solve the integral from a+e to b where e is some non-zero small number. Then it solves the integral a+e/10 to a+e in a series of consecutive iterations where e is reduced by 10 at each iteration. The results of each solution are summed with the first solution to obtain the final result. The iterations are continued until convergence occurs or an unbounded result terminates the solution with an accuracy less than that which was requested.

Constructor & Destructor Documentation

template<class F>
util::IntegrateFunction< F >::IntegrateFunction ( F &  f,
double  tol 
)

Since IntegrateFunction requires a reference assignment for the function F& ifF, the default constructor is not supported.

template<class F>
util::IntegrateFunction< F >::IntegrateFunction ( const IntegrateFunction< F > &  ifctn)
template<class F>
virtual util::IntegrateFunction< F >::~IntegrateFunction ( )
virtual

Member Function Documentation

template<class F >
F & util::IntegrateFunction< F >::getF ( )
inline
template<class F >
const F & util::IntegrateFunction< F >::getF ( ) const
inline
template<class F >
double util::IntegrateFunction< F >::getTolerance ( ) const
inline
template<class F >
double util::IntegrateFunction< F >::integrateAOpenS ( double  a,
double  b 
)
inline
template<class F >
double util::IntegrateFunction< F >::integrateClosed ( double  a,
double  b 
)
inline
template<class F >
double util::IntegrateFunction< F >::integrateClosedRcrsv ( double  a,
double  b,
double *  fr 
)
inlineprivate

Adaptive closed form numerical integration of the input function over the closed interval a to b. The function is assumed to be defined over the entire interval [a, b]. The function uses the 3 point Simpsons rule to evaluate all sub-intervals. The array fr contains previous function evaluations at ifF(a), ifF((a + b)/2), and ifF(b). This function is only called by the public cover function integrateClosed(a, b).

template<class F>
IntegrateFunction<F>& util::IntegrateFunction< F >::operator= ( const IntegrateFunction< F > &  ifctn)
template<class F >
void util::IntegrateFunction< F >::setTolerance ( double  tol)
inline
template<class F >
double util::IntegrateFunction< F >::simpson ( double  a,
double  b,
double *  fa,
double &  s 
)
inlineprivate

(h/3)(f0 + 4*f1 + f2)

where h is the interval width, f0 is the function to be integrated defined at the left most range, f2 is defined at the right most range, and f1 is defined at the mid-point of the range.

The rule evaluates the integral across a sub-interval range using the rule 3 times, once across the sub-interval, once across the 1st half of the sub-interval and once across the second half of the sub-interval. The split halves are summed to form one result while the entire interval evaluation forms the other. The former has an accuracy that is about 4 times greater than the entire interval evaluation. Convergence is attained when the difference between the two is less than the input tolerance. Five function evaluations are required for the closed form solution. However, 3 evaluations are passed from the previous call so only 2 new function evalutions are required per call to this function. The 3 previous functions evaluations are provided in the array fa at locations fa[0], fa[2], and fa[4]. Evaluations for fa[1] and fa[3] are performed in this function and saved into the array.

Member Data Documentation

template<class F>
F& util::IntegrateFunction< F >::ifF
private
template<class F>
double util::IntegrateFunction< F >::ifTol
private

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