6#include "ddc_aliases.hpp"
7#include "geometry_descriptors.hpp"
22template <
class ExecSpace,
class Gr
id1D>
23void fill_simpson_quadrature_coefficients_1d(
24 DField<IdxRange<Grid1D>,
typename ExecSpace::memory_space> coefficients)
26 IdxRange<Grid1D> idx_range = get_idx_range(coefficients);
27 if constexpr (Grid1D::continuous_dimension_type::PERIODIC) {
28 if (idx_range.size() % 2 != 0) {
29 throw std::runtime_error(
30 "Simpson quadrature requires 2n quadrature points for a periodic direction.");
33 if (idx_range.size() % 2 == 0) {
34 throw std::runtime_error(
"Simpson quadrature requires 2n+1 quadrature points for a "
35 "non-periodic direction.");
41 Kokkos::RangePolicy<ExecSpace>(
43 idx_range.size() / 2 -
int(Grid1D::continuous_dimension_type::PERIODIC)),
44 KOKKOS_LAMBDA(
const int i) {
45 Idx<Grid1D> idx_c = idx_range.front() + i * 2 + 1;
46 double const dx_l = distance_at_left(idx_c);
47 double const dx_r = distance_at_right(idx_c);
48 double const dx_sum = dx_l + dx_r;
49 coefficients(idx_c - 1) = dx_sum * (2. * dx_l - dx_r) / (6. * dx_l);
50 coefficients(idx_c) = dx_sum * dx_sum * dx_sum / (6. * dx_l * dx_r);
56 Kokkos::RangePolicy<ExecSpace>(
58 idx_range.size() / 2 -
int(Grid1D::continuous_dimension_type::PERIODIC) - 1),
59 KOKKOS_LAMBDA(
const int i) {
60 Idx<Grid1D> idx_c = idx_range.front() + i * 2 + 1;
61 double const dx_l = distance_at_left(idx_c);
62 double const dx_r = distance_at_right(idx_c);
63 double const dx_sum = dx_l + dx_r;
64 coefficients(idx_c + 1) += dx_sum * (2. * dx_r - dx_l) / (6. * dx_r);
69 Kokkos::RangePolicy<ExecSpace>(0, 1),
70 KOKKOS_LAMBDA(
const int i) {
72 = idx_range.back() - 1 -
int(Grid1D::continuous_dimension_type::PERIODIC);
73 double const dx_l = distance_at_left(idx_c);
74 double const dx_r = distance_at_right(idx_c);
75 double const dx_sum = dx_l + dx_r;
76 coefficients(idx_c + 1) = dx_sum * (2. * dx_r - dx_l) / (6. * dx_r);
79 if constexpr (Grid1D::continuous_dimension_type::PERIODIC) {
82 Kokkos::RangePolicy<ExecSpace>(0, 1),
83 KOKKOS_LAMBDA(
const int i) {
84 Idx<Grid1D> idx_c = idx_range.back();
85 double const dx_l = distance_at_left(idx_c);
86 double const dx_r = distance_at_right(idx_c);
87 double const dx_sum = dx_l + dx_r;
88 coefficients(idx_c - 1) += dx_sum * (2. * dx_l - dx_r) / (6. * dx_l);
89 coefficients(idx_c) = dx_sum * dx_sum * dx_sum / (6. * dx_l * dx_r);
90 coefficients(idx_range.front()) += dx_sum * (2. * dx_r - dx_l) / (6. * dx_r);
108template <
class ExecSpace,
class Gr
id1D>
109DFieldMem<IdxRange<Grid1D>,
typename ExecSpace::memory_space> simpson_quadrature_coefficients_1d(
110 IdxRange<Grid1D>
const& idx_range)
112 DFieldMem<IdxRange<Grid1D>,
typename ExecSpace::memory_space> coefficients_alloc(idx_range);
113 fill_simpson_quadrature_coefficients_1d<ExecSpace>(get_field(coefficients_alloc));
114 return coefficients_alloc;
130template <
class ExecSpace,
class Gr
id1D>
131DFieldMem<IdxRange<Grid1D>,
typename ExecSpace::memory_space>
132simpson_trapezoid_quadrature_coefficients_1d(
133 IdxRange<Grid1D>
const& idx_range,
134 Extremity trapezoid_extremity)
137 !Grid1D::continuous_dimension_type::PERIODIC,
138 "The extremity is non-sensical in a Periodic dimension");
140 return simpson_quadrature_coefficients_1d<ExecSpace>(idx_range);
141 }
catch (
const std::runtime_error& error) {
142 DFieldMem<IdxRange<Grid1D>,
typename ExecSpace::memory_space> coefficients_alloc(idx_range);
143 DField<IdxRange<Grid1D>,
typename ExecSpace::memory_space> coefficients(
144 get_field(coefficients_alloc));
145 IdxStep<Grid1D> npts_to_remove(1);
146 if (trapezoid_extremity == Extremity::FRONT) {
147 fill_simpson_quadrature_coefficients_1d<ExecSpace>(
148 coefficients_alloc[idx_range.remove_first(npts_to_remove)]);
149 Kokkos::parallel_for(
151 Kokkos::RangePolicy<ExecSpace>(0, 1),
152 KOKKOS_LAMBDA(
const int i) {
153 Idx<Grid1D> idx_l = idx_range.front();
154 double dx_cell = 0.5 * distance_at_right(idx_l);
155 coefficients(idx_l) = dx_cell;
156 coefficients(idx_l + 1) += dx_cell;
159 fill_simpson_quadrature_coefficients_1d<ExecSpace>(
160 coefficients_alloc[idx_range.remove_last(npts_to_remove)]);
161 Kokkos::parallel_for(
163 Kokkos::RangePolicy<ExecSpace>(0, 1),
164 KOKKOS_LAMBDA(
const int i) {
165 Idx<Grid1D> idx_r = idx_range.back();
166 double dx_cell = 0.5 * distance_at_left(idx_r);
167 coefficients(idx_r) = dx_cell;
168 coefficients(idx_r - 1) += dx_cell;
171 return coefficients_alloc;
188template <
class ExecSpace,
class... ODims>
189DFieldMem<IdxRange<ODims...>,
typename ExecSpace::memory_space> simpson_quadrature_coefficients(
190 IdxRange<ODims...>
const& idx_range)
194 (std::function<DFieldMem<IdxRange<ODims>,
typename ExecSpace::memory_space>(
195 IdxRange<ODims>)>(simpson_quadrature_coefficients_1d<ExecSpace, ODims>))...);
File providing helper functions for defining multi-dimensional quadrature methods.
DFieldMem< IdxRange< DDims... >, typename ExecSpace::memory_space > quadrature_coeffs_nd(IdxRange< DDims... > const &idx_range, std::function< DFieldMem< IdxRange< DDims >, typename ExecSpace::memory_space >(IdxRange< DDims >)>... funcs)
Helper function which creates ND dimensions from N 1D quadrature coefficient functions.
Definition quadrature_coeffs_nd.hpp:31
File providing quadrature coefficients via the trapezoidal method.