40 template<
typename func_t >
46 int MaximumIterations)
50 double fa = Function(
a);
51 double fb = Function(
b);
55 KRATOS_THROW_ERROR(std::runtime_error,
"Error in BrentIteration::FindRoot: The images of both initial guesses have the same sign.",
"");
60 double p,
q,r,s,tol1,xm;
62 double d = 0.0,
e = 0.0;
63 double eps = (Tolerance < 1
e-8) ? Tolerance : 1
e-8;
65 for(
int iter = 0; iter < MaximumIterations; iter++ )
76 if ( std::fabs(fc) < std::fabs(fb) )
87 tol1 = 2.*eps*std::fabs(
b) + 0.5*Tolerance;
90 if (std::fabs(xm) < tol1 || std::fabs(fb) < eps)
93 if (std::fabs(
e) > tol1 && std::fabs(fa) > std::fabs(fb) )
97 if ( std::fabs(
a-
c) < eps )
106 p = s*( 2.0*xm*
q*(
q-r) - (
b-
a)*(r-1.0) );
107 q = (
q-1.0)*(r-1.0)*(s-1.0);
115 double bound1 = 3.0*xm*
q - std::fabs(tol1*
q);
116 double bound2 = std::fabs(
e*
q);
117 if ( 2.0*
p <
std::min( bound1 , bound2 ) )
142 if (std::abs(
d) > tol1)
148 b += (xm > 0.0) ? std::fabs(tol1) : -std::fabs(tol1);
Definition: brent_iteration.h:30
static double FindRoot(func_t Function, double Guess1, double Guess2, double Tolerance, int MaximumIterations)
Definition: brent_iteration.h:41
#define KRATOS_THROW_ERROR(ExceptionType, ErrorMessage, MoreInfo)
Definition: define.h:77
static double min(double a, double b)
Definition: GeometryFunctions.h:71
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
q
Definition: generate_convection_diffusion_explicit_element.py:109
a
Definition: generate_stokes_twofluid_element.py:77
b
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:31
c
Definition: generate_weakly_compressible_navier_stokes_element.py:108
int d
Definition: ode_solve.py:397
p
Definition: sensitivityMatrix.py:52
e
Definition: run_cpp_mpi_tests.py:31