Chi-Tech
quadrature_gausschebyshev.cc
Go to the documentation of this file.
2
3#include "ChiObjectFactory.h"
4#include <cmath>
5
6#include "chi_runtime.h"
7#include "chi_log.h"
8
9#define uint unsigned int
10#define scint static_cast<int>
11
12namespace chi_math
13{
14
16
18{
20
21 // clang-format off
23 "Implementation of a Gauss-Chebyshev quadrature");
24 params.SetDocGroup("LuaQuadrature");
25 // clang-format on
26
27 params.ChangeExistingParamToOptional("order", 0);
28
29 params.AddOptionalParameter("N", 1, "Number of quadrature points.");
30
31 return params;
32}
33
35 const chi::InputParameters& params)
36 : chi_math::Quadrature(params)
37{
38 const auto& assigned_params = params.ParametersAtAssignment();
39
40 const int param_count =
41 int(assigned_params.Has("order")) + int(assigned_params.Has("N"));
42 ChiInvalidArgumentIf(param_count == 2,
43 "Either \"order\" or \"N\" must be specified, not both");
44
45 if (assigned_params.Has("order"))
46 {
47 const uint N = static_cast<uint>(order_);
48 Initialize(N);
49 }
50 else
51 {
52 const uint N = assigned_params.GetParamValue<uint>("N");
53 order_ = static_cast<QuadratureOrder>(std::min(scint(N), 43));
54 Initialize(N);
55 }
56}
57
58// ###################################################################
59/**Populates the abscissae and weights for a Gauss-Chebyshev
60 * quadrature given the number of desired quadrature points. The
61 * order of the quadrature will be 2N-1.*/
63 : chi_math::Quadrature((QuadratureOrder)(2 * N - 1))
64{
65 Initialize(N);
66}
67
68// ###################################################################
69/**Populates the abscissae and weights for a Gauss-Chebyshev
70 * quadrature given the number of desired quadrature points.*/
72{
73 if (verbose_)
74 Chi::log.Log() << "Initializing Gauss-Chebyshev Quadrature "
75 "with "
76 << N << " q-points";
77
78 const double pi_N = M_PI / N;
79 for (unsigned int n = 0; n < N; ++n)
80 {
81 const double xn = -std::cos((2 * n + 1) * pi_N / 2.0);
82 const double wn = pi_N;
83
84 qpoints_.emplace_back(xn);
85 weights_.emplace_back(wn);
86
87 if (verbose_)
88 Chi::log.Log() << "root[" << n << "]=" << qpoints_[n][0]
89 << ", weight=" << weights_[n];
90 }
91
92 range_ = {-1, +1};
93}
94
95} // namespace chi_math
#define ChiInvalidArgumentIf(condition, message)
static chi::ChiLog & log
Definition: chi_runtime.h:81
LogStream Log(LOG_LVL level=LOG_0)
Definition: chi_log.cc:35
void SetDocGroup(const std::string &doc_group)
const ParameterBlock & ParametersAtAssignment() const
void AddOptionalParameter(const std::string &name, T value, const std::string &doc_string)
void SetGeneralDescription(const std::string &description)
void ChangeExistingParamToOptional(const std::string &name, T value, const std::string &doc_string="")
static chi::InputParameters GetInputParameters()
QuadratureGaussChebyshev(const chi::InputParameters &params)
static chi::InputParameters GetInputParameters()
Definition: quadrature.cc:66
std::vector< chi_math::QuadraturePointXYZ > qpoints_
Definition: quadrature.h:37
std::pair< double, double > range_
Definition: quadrature.h:45
QuadratureOrder order_
Definition: quadrature.h:36
std::vector< double > weights_
Definition: quadrature.h:38
QuadratureOrder
Definition: quadrature.h:12
RegisterChiObject(chi_math, QuadratureGaussChebyshev)
#define scint
#define uint