11 #ifndef _ROOTSOLVER_H_ 12 #define _ROOTSOLVER_H_ 128 template <
typename T,
typename Func>
139 const int prec = (int)tol;
140 if (((T)prec) == tol)
142 tol = std::pow(10., -std::abs(prec));
164 for (i = 0; i < MAXITER; i++)
175 if (std::fabs(fc) < std::fabs(fb))
186 const T tol1 = 2.0 * eps * std::fabs(bPt) + 0.5 * tol;
187 const T xm = 0.5 * (c - bPt);
189 if (std::fabs(xm) <= tol1 || fb == 0.0)
194 if (std::fabs(e) >= tol1 && std::fabs(fa) > std::fabs(fb))
207 p = s * (2.0 * xm * q * (q-r) - (bPt-aPt) * (r-1.0));
208 q = (q-1.0) * (r-1.0) * (s-1.0);
216 if (2.0 * p <
std::min(((
float)3.0)*xm*q-std::fabs(tol1*q),
242 if (std::fabs(d) > tol1)
248 if (xm < 0) bPt = bPt - tol1;
249 else bPt = bPt + tol1;
257 std::cerr <<
"RootSolver::Brent: exceeded maximum iterations: " 258 << MAXITER << std::endl;
Definition: RootSolver.H:33
#define CH_assert(cond)
Definition: CHArray.H:37
IndexTM< T, N > min(const IndexTM< T, N > &a_p1, const IndexTM< T, N > &a_p2)
Definition: IndexTMI.H:396
T 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.
Definition: RootSolver.H:129
static double eps()
Definition: RootSolver.H:64
Definition: RootSolver.H:30
static double tolerance()
Definition: RootSolver.H:69
static float tolerance()
Definition: RootSolver.H:50
static float eps()
Definition: RootSolver.H:45
static void Abort(const char *const a_msg=m_nullString)
Print out message to cerr and exit via abort() (if serial) or MPI_Abort() (if parallel).