DDC 0.10.0
Loading...
Searching...
No Matches
knots_as_interpolation_points.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 <tuple>
8#include <type_traits>
9#include <vector>
10
11#include <ddc/ddc.hpp>
12
13#include <Kokkos_Core.hpp>
14
15#include "bsplines_uniform.hpp"
16#include "knot_discrete_dimension_type.hpp"
17#include "spline_boundary_conditions.hpp"
18
19namespace ddc {
20
21/**
22 * @brief Helper class for the initialisation of the mesh of interpolation points.
23 *
24 * A helper class for the initialisation of the mesh of interpolation points. This
25 * class should be used when the interpolation points should be located at the
26 * knots of the spline. This is possible with any kind of boundary condition except
27 * Greville boundary conditions (as there will not be enough interpolation points).
28 * In the case of strongly non-uniform splines this choice may result in a less
29 * well conditioned problem, however most mathematical stability results are proven
30 * with this choice of interpolation points.
31 *
32 * @tparam BSplines The type of the uniform or non-uniform spline basis whose knots are used as interpolation points.
33 * @tparam BcLower The lower boundary condition.
34 * @tparam BcLower The upper boundary condition.
35 */
36template <class BSplines, ddc::BoundCond BcLower, ddc::BoundCond BcUpper>
38{
39 static_assert(BcLower != ddc::BoundCond::GREVILLE);
40 static_assert(BcUpper != ddc::BoundCond::GREVILLE);
41
42 using continuous_dimension_type = typename BSplines::continuous_dimension_type;
43
44public:
45 /**
46 * Get the sampling of interpolation points.
47 *
48 * @return sampling The DDC point sampling of the interpolation points.
49 */
50 template <typename Sampling, typename U = BSplines>
51 static auto get_sampling()
52 {
53 if constexpr (U::is_uniform()) {
54 return std::get<0>(Sampling::
55 init(ddc::discrete_space<BSplines>().rmin(),
56 ddc::discrete_space<BSplines>().rmax(),
57 ddc::DiscreteVector<Sampling>(
58 ddc::discrete_space<BSplines>().ncells() + 1)));
59 } else {
60 using SamplingImpl = typename Sampling::template Impl<Sampling, Kokkos::HostSpace>;
61 std::vector<double> knots(ddc::discrete_space<BSplines>().npoints());
62 ddc::DiscreteDomain<knot_discrete_dimension_t<BSplines>> break_point_domain(
63 ddc::discrete_space<BSplines>().break_point_domain());
64 ddc::host_for_each(
65 break_point_domain,
66 [&](ddc::DiscreteElement<knot_discrete_dimension_t<BSplines>> ik) {
67 knots[ik - break_point_domain.front()] = ddc::coordinate(ik);
68 });
69 return SamplingImpl(knots);
70 }
71 }
72
73 /// The DDC type of the sampling for the interpolation points.
74 using interpolation_discrete_dimension_type = std::conditional_t<
75 is_uniform_bsplines_v<BSplines>,
76 ddc::UniformPointSampling<continuous_dimension_type>,
77 ddc::NonUniformPointSampling<continuous_dimension_type>>;
78
79 /**
80 * Get the domain which can be used to access the interpolation points in the sampling.
81 *
82 * @return domain The discrete domain which maps to the sampling of interpolation points.
83 */
84 template <typename Sampling>
85 static ddc::DiscreteDomain<Sampling> get_domain()
86 {
87 int const npoints = ddc::discrete_space<BSplines>().ncells() + !BSplines::is_periodic();
88 return ddc::DiscreteDomain<Sampling>(
89 ddc::DiscreteElement<Sampling>(0),
90 ddc::DiscreteVector<Sampling>(npoints));
91 }
92};
93
94} // namespace ddc
friend class DiscreteDomain
KOKKOS_FUNCTION constexpr bool operator!=(DiscreteVector< OTags... > const &rhs) const noexcept
Helper class for the initialisation of the mesh of interpolation points.
static auto get_sampling()
Get the sampling of interpolation points.
static ddc::DiscreteDomain< Sampling > get_domain()
Get the domain which can be used to access the interpolation points in the sampling.
NonUniformPointSampling models a non-uniform discretization of the CDim segment .
UniformPointSampling models a uniform discretization of the provided continuous dimension.
The top-level namespace of DDC.
BoundCond
An enum representing a spline boundary condition.
@ GREVILLE
Use Greville points instead of conditions on derivative for B-Spline interpolation.