42#include "Teuchos_Assert.hpp"
44template <
typename value_type>
51 Teuchos::ParameterList& solverParams) :
56 magnitude_type eps = solverParams.get(
"Bound Perturbation Size", 1e-6);
57 magnitude_type tol = solverParams.get(
"Nonlinear Solver Tolerance", 1e-10);
58 int max_it = solverParams.get(
"Maximum Nonlinear Solver Iterations", 100);
60 value_type aa, alpha, omega, lambda;
62 double pi = 4.0*std::atan(1.0);
70 lambda = 2.0*
L/(
L*
L*omega*omega + 1.0);
78 lambda = 2.0*
L/(
L*
L*omega*omega + 1.0);
89 lambda = 2.0*
L/(
L*
L*omega*omega + 1.0);
96template <
typename value_type>
100newton(
const Func& func,
const value_type& a,
const value_type& b,
103 value_type u = (a+b)/2.0;
104 value_type
f = func.eval(u);
106 while (Teuchos::ScalarTraits<value_type>::magnitude(
f) > tol &&
108 std::cout <<
"u = " << u <<
" f = " <<
f << std::endl;
109 value_type dfdu = func.deriv(u);
114 TEUCHOS_TEST_FOR_EXCEPTION(nit >= max_num_its, std::logic_error,
115 "Nonlinear solver did not converge!" << std::endl);
120template <
typename value_type>
124bisection(
const Func& func,
const value_type& a,
const value_type& b,
128 value_type fa = func.eval(a);
129 value_type fb = func.eval(b);
130 TEUCHOS_TEST_FOR_EXCEPTION(fa*fb > value_type(0.0), std::logic_error,
131 "Bounds [" << a <<
"," << b <<
"] must bracket the root!" << std::endl <<
132 "f(a) = " << fa <<
", f(b) = " << fb << std::endl)
144 value_type u = low + (hi - low)/2.0;
145 value_type
f = func.eval(u);
146 while ((Teuchos::ScalarTraits<value_type>::magnitude(hi - low) > 2.0*tol ||
147 Teuchos::ScalarTraits<value_type>::magnitude(
f) > tol) &&
154 u = low + (hi - low)/2.0;
158 TEUCHOS_TEST_FOR_EXCEPTION(nit >= max_num_its, std::logic_error,
159 "Nonlinear solver did not converge!" << std::endl);
One-dimensional eigenfunction for exponential covariance function.
value_type bisection(const Func &func, const value_type &a, const value_type &b, magnitude_type tol, int max_num_its)
A basic root finder based on bisection.
Teuchos::Array< eigen_pair_type > eig_pair
Eigenpairs.
value_type L
Correlation length.
Teuchos::ScalarTraits< value_type >::magnitudeType magnitude_type
value_type newton(const Func &func, const value_type &a, const value_type &b, magnitude_type tol, int max_num_its)
A basic root finder based on Newton's method.
OneDExponentialCovarianceFunction(int M, const value_type &a, const value_type &b, const value_type &L, const int dim_name, Teuchos::ParameterList &solverParams)
Constructor.
ScalarType f(const Teuchos::Array< ScalarType > &x, double a, double b)
Nonlinear function whose roots define eigenvalues for cos() eigenfunction.
Nonlinear function whose roots define eigenvalues for sin() eigenfunction.