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