12#define uint unsigned int
13#define scint static_cast<int>
31 "max_root_finding_iters",
33 "Maximum number of iterations used during root finding");
37 "Root finding iterative tolerance");
51 const int param_count =
52 int(assigned_params.Has(
"order")) + int(assigned_params.Has(
"N"));
54 "Either \"order\" or \"N\" must be specified, not both");
57 const double tol = params.
GetParamValue<
double>(
"root_finding_tol");
59 if (assigned_params.Has(
"order"))
61 const uint N = std::ceil(((
int)
order_ + 1) / 2.0);
66 const uint N = assigned_params.GetParamValue<
uint>(
"N");
81 unsigned int max_iters,
85 const unsigned int N = std::ceil(((
int)
order_ + 1) / 2.0);
95 unsigned int max_iters,
107 unsigned int max_iters,
115 Chi::log.
Log() <<
"Initializing Gauss-Legendre Quadrature "
120 auto roots =
FindRoots(N, max_iters, tol);
126 for (
size_t k = 0; k <
qpoints_.size(); k++)
162 unsigned int max_iters,
169 int num_search_intvls = 1000;
170 if (N > 64) num_search_intvls *= 10;
171 if (N > 256) num_search_intvls *= 10;
172 if (N > 768) num_search_intvls *= 10;
176 num_search_intvls *= 10;
178 <<
"chi_math::QuadratureGaussLegendre::FindRoots: "
179 <<
"The order of the polynomial for which to find the roots is "
180 <<
"greater than 2056. Accuracy of the root finder will be diminished "
181 <<
"along with a reduction in stability.";
186 double delta = 2.0 / num_search_intvls;
187 std::vector<double> xk(N, 0.0);
189 for (
size_t i = 0; i < num_search_intvls; i++)
191 double x_i = -1.0 + i * delta;
192 double x_ip1 = x_i + delta;
195 xk[++counter] = (x_ip1 + x_i) / 2.0;
205 for (
int k = 0; k < N; k++)
207 for (
size_t iteration = 0; iteration < max_iters; iteration++)
216 for (
int i = 0; i <= (k - 1); i++)
217 S1 += 1.0 / (xk[k] - xk[i]);
220 double B_xk = fp - f * S1;
224 for (
int i = 0; i <= (k - 1); i++)
225 S2 += 1.0 / (xk[k] - xk[i]) / (xk[k] - xk[i]);
228 double a = fpp + f * S2;
229 double b = B_xk * B_xk + fp * fp - f * a;
230 double c = 2.0 * f * B_xk / b;
234 if (std::fabs(xk[k] - xold) < tol)
break;
238 std::stable_sort(xk.begin(), xk.end());
#define ChiInvalidArgumentIf(condition, message)
LogStream Log(LOG_LVL level=LOG_0)
T GetParamValue(const std::string ¶m_name) const
void Initialize(unsigned int N, bool verbose, unsigned int max_iters, double tol)
QuadratureGaussLegendre(const chi::InputParameters ¶ms)
static chi::InputParameters GetInputParameters()
static std::vector< double > FindRoots(unsigned int N, unsigned int max_iters=1000, double tol=1.0e-12)
static chi::InputParameters GetInputParameters()
std::vector< chi_math::QuadraturePointXYZ > qpoints_
std::pair< double, double > range_
std::vector< double > weights_
double d2Legendredx2(int N, double x)
double dLegendredx(int N, double x)
RegisterChiObject(chi_math, QuadratureGaussChebyshev)
double Legendre(int N, double x)