Gyselalib++
 
Loading...
Searching...
No Matches
spline_quadrature.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2
8#pragma once
9
10#include <cassert>
11
12#include <ddc/ddc.hpp>
13
14#include <sll/matrix.hpp>
15
16#include "ddc_aliases.hpp"
17
18
19
20namespace {
21template <class Grid1D>
22using CoefficientFieldMem1D_host = host_t<DFieldMem<IdxRange<Grid1D>>>;
23}
24
25
59template <class Grid1D, class SplineBuilder>
60host_t<DFieldMem<IdxRange<Grid1D>>> spline_quadrature_coefficients_1d(
61 IdxRange<Grid1D> const& idx_range,
62 SplineBuilder const& builder)
63{
64 static_assert(
65 SplineBuilder::s_nbc_xmin == 0,
66 "The spline quadrature requires a builder which can construct the coefficients using "
67 "only the values at the interpolation points.");
68 static_assert(
69 SplineBuilder::s_nbc_xmax == 0,
70 "The spline quadrature requires a builder which can construct the coefficients using "
71 "only the values at the interpolation points.");
72 // Since spline builder quadrature coeffs are not available on device, need host allocated builder.
73 // See https://github.com/CExA-project/ddc/issues/598
74 static_assert(
75 (std::is_same_v<typename SplineBuilder::memory_space, Kokkos::HostSpace>),
76 "SplineBuilder must be host allocated.");
77
78 DFieldMem<IdxRange<Grid1D>, typename SplineBuilder::memory_space> quadrature_coefficients(
79 builder.interpolation_domain());
80 std::tie(std::ignore, quadrature_coefficients, std::ignore) = builder.quadrature_coefficients();
81 return ddc::create_mirror_and_copy(quadrature_coefficients[idx_range]);
82}
83
84
85
98template <class ExecSpace, class... DDims, class... SplineBuilders>
99DFieldMem<IdxRange<DDims...>, typename ExecSpace::memory_space> spline_quadrature_coefficients(
100 IdxRange<DDims...> const& idx_range,
101 SplineBuilders const&... builders)
102{
103 assert((std::is_same_v<
104 typename DDims::continuous_dimension_type,
105 typename SplineBuilders::continuous_dimension_type> and ...));
106
107 // Get coefficients for each dimension
108 std::tuple<CoefficientFieldMem1D_host<DDims>...> current_dim_coeffs(
109 spline_quadrature_coefficients_1d(ddc::select<DDims>(idx_range), builders)...);
110
111 // Allocate ND coefficients
112 DFieldMem<IdxRange<DDims...>, typename ExecSpace::memory_space> coefficients(idx_range);
113 auto coefficients_host = ddc::create_mirror(get_field(coefficients));
114 // Serial loop is used due to nvcc bug concerning functions with variadic template arguments
115 // (see https://github.com/kokkos/kokkos/pull/7059)
116 ddc::for_each(idx_range, [&](Idx<DDims...> const idim) {
117 // multiply the 1D coefficients by one another
118 coefficients_host(idim)
119 = (std::get<CoefficientFieldMem1D_host<DDims>>(current_dim_coeffs)(
120 ddc::select<DDims>(idim))
121 * ... * 1);
122 });
123 ddc::parallel_deepcopy(coefficients, coefficients_host);
124 return coefficients;
125}
DFieldMem< IdxRange< DDims... >, typename ExecSpace::memory_space > spline_quadrature_coefficients(IdxRange< DDims... > const &idx_range, SplineBuilders const &... builders)
Get the spline quadrature coefficients in ND from N 1D quadrature coefficient.
Definition spline_quadrature.hpp:99
host_t< DFieldMem< IdxRange< Grid1D > > > spline_quadrature_coefficients_1d(IdxRange< Grid1D > const &idx_range, SplineBuilder const &builder)
Get the spline quadrature coefficients.
Definition spline_quadrature.hpp:60