33 #define INCLXX_IN_GEANT4_MODE 1
54 namespace RootFinder {
62 const G4int maxIterations=50;
74 std::pair<G4double,G4double> bracketRoot(RootFunctor
const *
const f,
G4double x0) {
87 return std::make_pair(x0,x1);
89 const G4double scaleFactorMinus1 = 1./scaleFactor;
93 if(iterations > maxIterations) {
94 INCL_DEBUG(
"Could not bracket the root." << std::endl);
102 x0 *= scaleFactorMinus1;
110 return std::make_pair(x0,oldx0);
112 return std::make_pair(oldx1,x1);
120 if( std::abs(y0) < toleranceY ) {
125 std::pair<G4double,G4double> bracket = bracketRoot(f,x0);
132 if(std::abs(y_at_zero)<=toleranceY) {
136 INCL_DEBUG(
"Root-finding algorithm could not bracket the root." << std::endl);
152 G4int lastUpdated = 0;
154 for(
G4int iterations=0; std::abs(y) > toleranceY; iterations++) {
156 if(iterations > maxIterations) {
157 INCL_DEBUG(
"Root-finding algorithm did not converge." << std::endl);
163 x = (y1*x2-y2*
x1)/(y1-y2);
172 if(lastUpdated==-1) y2 *= 0.5;
177 if(lastUpdated==1) y1 *= 0.5;
virtual void cleanUp(const G4bool success) const =0
Solution solve(RootFunctor const *const f, const G4double x0)
Numerically solve a one-dimensional equation.
Static root-finder algorithm.