31 static std::size_t max_order()
33 return glc::max_order;
39 assert(n <= glc::max_order);
41 std::size_t
const offset = n * (n - 1) / 2;
43 for (std::size_t i = 0; i < n; ++i) {
44 m_wx[i].first =
static_cast<double>(glc::weight[offset + i]);
45 m_wx[i].second =
static_cast<ddc::Coordinate<Dim>
>(glc::pos[offset + i]);
59 std::size_t order()
const
65 double integrate(F&& f,
double x0,
double x1)
const
67 static_assert(std::is_invocable_r_v<double, F, double>,
"Functor F not handled");
69 double const l = 0.5 * (x1 - x0);
70 double const c = 0.5 * (x0 + x1);
72 for (std::pair<
double, ddc::Coordinate<Dim>>
const& wx : m_wx) {
73 integral += wx.first * f(l * wx.second + c);
78 template <
class Domain>
79 void compute_points(ddc::ChunkSpan<ddc::Coordinate<Dim>, Domain> points,
double x0,
double x1)
83 assert(points.size() == m_wx.size());
85 double const l = 0.5 * (x1 - x0);
86 double const c = 0.5 * (x0 + x1);
87 int const dom_start = points.domain().front().uid();
88 for (
auto i : points.domain()) {
89 points(i) = ddc::Coordinate<Dim>(l * m_wx[i.uid() - dom_start].second + c);
93 template <
class Domain>
94 void compute_points_and_weights(
95 ddc::ChunkSpan<ddc::Coordinate<Dim>, Domain> points,
96 ddc::ChunkSpan<double, Domain> weights,
97 ddc::Coordinate<Dim>
const& x0,
98 ddc::Coordinate<Dim>
const& x1)
const
101 assert(points.size() == m_wx.size());
103 double const l = 0.5 * (ddc::get<Dim>(x1) - ddc::get<Dim>(x0));
104 ddc::Coordinate<Dim>
const c(0.5 * (x0 + x1));
105 int const dom_start = points.domain().front().uid();
106 for (
auto i : points.domain()) {
107 weights(i) = l * m_wx[i.uid() - dom_start].first;
108 points(i) = ddc::Coordinate<Dim>(l * m_wx[i.uid() - dom_start].second + c);
112 template <
class Domain1,
class Domain2>
113 void compute_points_and_weights_on_mesh(
114 ddc::ChunkSpan<ddc::Coordinate<Dim>, Domain1> points,
115 ddc::ChunkSpan<double, Domain1> weights,
116 ddc::ChunkSpan<
const ddc::Coordinate<Dim>, Domain2> mesh_edges)
const
118 [[maybe_unused]]
int const nbcells = mesh_edges.size() - 1;
119 int const npts_gauss = m_wx.size();
120 assert(points.size() == m_wx.size() * nbcells);
121 assert(weights.size() == m_wx.size() * nbcells);
123 typename Domain1::discrete_element_type start = weights.domain().front();
124 typename Domain1::discrete_vector_type step(npts_gauss);
125 typename Domain1::discrete_element_type local_domain_start = start;
127 mesh_edges.domain().remove_last(
typename Domain2::discrete_vector_type(1)),
129 ddc::Coordinate<Dim> const x0 = mesh_edges(icell);
130 ddc::Coordinate<Dim> const x1 = mesh_edges(icell + 1);
132 Domain1 local_domain(local_domain_start, step);
133 local_domain_start += step;
135 compute_points_and_weights(points[local_domain], weights[local_domain], x0, x1);
140 std::vector<std::pair<double, ddc::Coordinate<Dim>>> m_wx;