Comment and indent bracketZero().

This commit is contained in:
Atgeirr Flø Rasmussen 2012-06-04 16:54:41 +02:00
parent ed33a780c0
commit 7a31716185

View File

@ -293,37 +293,41 @@ namespace Opm
/// Attempts to find an interval bracketing a zero by successive
template <class Functor> /// enlargement of search interval.
inline void bracketZero(const Functor& f, template <class Functor>
const double x0, inline void bracketZero(const Functor& f,
const double dx, const double x0,
double& a, const double dx,
double& b) double& a,
{ double& b)
const int max_iters = 100; {
double f0 = f(x0); const int max_iters = 100;
double cur_dx = dx; double f0 = f(x0);
int i = 0; double cur_dx = dx;
for (; i < max_iters; ++i) { int i = 0;
double x = x0 + cur_dx; for (; i < max_iters; ++i) {
double f_new = f(x); double x = x0 + cur_dx;
if (f0*f_new <= 0.0) { double f_new = f(x);
break; if (f0*f_new <= 0.0) {
} break;
cur_dx = -2.0*cur_dx;
}
if (i == max_iters) {
THROW("Could not bracket zero in " << max_iters << "iterations.");
}
if (cur_dx < 0.0) {
a = x0 + cur_dx;
b = i < 2 ? x0 : x0 + 0.25*cur_dx;
} else {
a = i < 2 ? x0 : x0 + 0.25*cur_dx;
b = x0 + cur_dx;
} }
cur_dx = -2.0*cur_dx;
} }
if (i == max_iters) {
THROW("Could not bracket zero in " << max_iters << "iterations.");
}
if (cur_dx < 0.0) {
a = x0 + cur_dx;
b = i < 2 ? x0 : x0 + 0.25*cur_dx;
} else {
a = i < 2 ? x0 : x0 + 0.25*cur_dx;
b = x0 + cur_dx;
}
}
} // namespace Opm } // namespace Opm