Chombo + EB + MF  3.2
Classes | Functions
RootSolver Namespace Reference

Classes

struct  RootTr
 
struct  RootTr< double >
 
struct  RootTr< float >
 

Functions

template<typename T , typename Func >
Brent (int &numIter, const Func &f, T aPt, T bPt, T tol=RootTr< T >::tolerance(), const unsigned MAXITER=RootTr< T >::maxIter)
 Brent's root solver. More...
 

Function Documentation

◆ Brent()

template<typename T , typename Func >
T RootSolver::Brent ( int &  numIter,
const Func &  f,
aPt,
bPt,
tol = RootTr<T>::tolerance(),
const unsigned  MAXITER = RootTr<T>::maxIter 
)

Brent's root solver.

Template Parameters
TType for x and f(x) - must be floating point
FuncFunction object describing function to solve where T f(x) = Func::operator()(const T& x)
Parameters
[out]numIterNumber of iterations required for convergence to specified tolerance. If equal to MAXITER, the solution is not within specified tolerance.
[in]fInstance of function to solve
[in]aPtLower bound
[in]bPtUpper bound
[in]tolTolerance for solve - essentially the spread of the bracket. This can be specified in absolute terms, or, if given by an integer cast to T, the number of significant digits to solve for in x. The default is given by the RootTr class. Note that epsilon is also considered for specifying the spread of the bracket.
[in]MAXITERMaximum iterations. Default (100). If reached, a message is written to cerr but the program otherwise completes
Returns
x where f(x) = 0

Example

*     #include <functional>
*     #include "RootSolver.H"
*     // Func is not allowed to be local until the C++0x standard
*     struct Func : public std::unary_function<Real, Real>
*     {
*       Real operator()(const Real& a_x) const
*         {
*           return 5*std::pow(a_x, 5) - 3*std::pow(a_x, 3) + a_x;
*         }
*     };
*     void foo()
*     {
*       int numIter;
*       const Real xmin = -1.;
*       const Real xmax =  1.;
*       const Real x0 = RootSolver::Brent(numIter, Func(), xmin, xmax);
*       if (numIter == RootTr<Real>::maxIter)
*         {
*           std::pout() << "Uh oh\n";
*         }
*     }
*                                                                  

References MayDay::Abort(), Abs(), CH_assert, min(), and pout().