DDC 0.10.0
Loading...
Searching...
No Matches
constant_extrapolation_rule.hpp
1// Copyright (C) The DDC development team, see COPYRIGHT.md file
2//
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
7#include <array>
8#include <cstddef>
9#include <type_traits>
10
11#include <ddc/ddc.hpp>
12
13#include <Kokkos_Core.hpp>
14
15namespace ddc {
16
17template <class DimI, class... Dim>
21
28template <class DimI>
30{
31private:
32 ddc::Coordinate<DimI> m_eval_pos;
33
34public:
43
52 template <class CoordType, class BSplines, class Layout, class MemorySpace>
56 spline_coef) const
57 {
59
60 std::array<double, BSplines::degree() + 1> vals_ptr;
61 Kokkos::mdspan<double, Kokkos::extents<std::size_t, BSplines::degree() + 1>> const vals(
62 vals_ptr.data());
63
65 = ddc::discrete_space<BSplines>().eval_basis(vals, m_eval_pos);
66
67 double y = 0.0;
68 for (std::size_t i = 0; i < BSplines::degree() + 1; ++i) {
69 y += spline_coef(idx + i) * vals[i];
70 }
71 return y;
72 }
73};
74
81template <class DimI, class DimNI>
83{
84private:
85 ddc::Coordinate<DimI> m_eval_pos;
86 ddc::Coordinate<DimNI> m_eval_pos_not_interest_min;
87 ddc::Coordinate<DimNI> m_eval_pos_not_interest_max;
88
89public:
112
123 template <class SFINAEDimNI = DimNI, std::enable_if_t<SFINAEDimNI::PERIODIC, int> = 0>
125 : m_eval_pos(eval_pos)
126 , m_eval_pos_not_interest_min(0.)
127 , m_eval_pos_not_interest_max(0.)
128 {
129 }
130
146 template <class CoordType, class BSplines1, class BSplines2, class Layout, class MemorySpace>
150 double const,
152 Layout,
153 MemorySpace> const spline_coef) const
154 {
155 static_assert(
158
160 if constexpr (DimNI::PERIODIC) {
163 } else {
165 m_eval_pos,
166 Kokkos::
168 m_eval_pos_not_interest_min,
169 m_eval_pos_not_interest_max));
170 }
171
172 std::array<double, BSplines1::degree() + 1> vals1_ptr;
173 Kokkos::mdspan<double, Kokkos::extents<std::size_t, BSplines1::degree() + 1>> const vals1(
174 vals1_ptr.data());
175 std::array<double, BSplines2::degree() + 1> vals2_ptr;
176 Kokkos::mdspan<double, Kokkos::extents<std::size_t, BSplines2::degree() + 1>> const vals2(
177 vals2_ptr.data());
178
180 vals1,
183 vals2,
185
186 double y = 0.0;
187 for (std::size_t i = 0; i < BSplines1::degree() + 1; ++i) {
188 for (std::size_t j = 0; j < BSplines2::degree() + 1; ++j) {
189 y += spline_coef(idx1 + i, idx2 + j) * vals1[i] * vals2[j];
190 }
191 }
192
193 return y;
194 }
195};
196
197} // namespace ddc
A DiscreteElement identifies an element of the discrete dimension.
The top-level namespace of DDC.
constexpr bool enable_chunk
detail::TaggedVector< CoordinateElement, CDims... > Coordinate
A Coordinate represents a coordinate in the continuous space.
ConstantExtrapolationRule(ddc::Coordinate< DimI > eval_pos, ddc::Coordinate< DimNI > eval_pos_not_interest_min, ddc::Coordinate< DimNI > eval_pos_not_interest_max)
Instantiate a ConstantExtrapolationRule.
KOKKOS_FUNCTION double operator()(CoordType coord_extrap, ddc::ChunkSpan< double const, ddc::DiscreteDomain< BSplines1, BSplines2 >, Layout, MemorySpace > const spline_coef) const
Get the value of the function on B-splines at a coordinate outside the domain.
ConstantExtrapolationRule(ddc::Coordinate< DimI > eval_pos)
Instantiate a ConstantExtrapolationRule.
KOKKOS_FUNCTION double operator()(CoordType pos, ddc::ChunkSpan< double const, ddc::DiscreteDomain< BSplines >, Layout, MemorySpace > const spline_coef) const
Get the value of the function on B-splines at a coordinate outside the domain.
ConstantExtrapolationRule(ddc::Coordinate< DimI > eval_pos)
Instantiate a ConstantExtrapolationRule.