13#include "bsplines_non_uniform.hpp"
14#include "bsplines_uniform.hpp"
15#include "spline_boundary_conditions.hpp"
20
21
22
23
24
25
29 using continuous_dimension_type =
typename BSplines::continuous_dimension_type;
31 template <
class Sampling>
32 struct IntermediateUniformSampling
37 template <
class Sampling>
38 struct IntermediateNonUniformSampling
43 template <
class Sampling,
typename U = BSplines,
class = std::enable_if_t<U::is_uniform()>>
44 static auto uniform_greville_points()
46 using SamplingImpl =
typename Sampling::
template Impl<Sampling, Kokkos::HostSpace>;
48 double constexpr shift = (BSplines::degree() % 2 == 0) ? 0.5 : 0.0;
50 = (
ddc::discrete_space<BSplines>().rmax() -
ddc::discrete_space<BSplines>().rmin())
51 /
ddc::discrete_space<BSplines>().ncells();
53 ddc::Coordinate<continuous_dimension_type>(
54 ddc::discrete_space<BSplines>().rmin() + shift * dx),
55 ddc::Coordinate<continuous_dimension_type>(dx));
58 template <
class Sampling,
typename U = BSplines,
class = std::enable_if_t<!U::is_uniform()>>
59 static auto non_uniform_greville_points()
61 using SamplingImpl =
typename Sampling::
template Impl<Sampling, Kokkos::HostSpace>;
63 int n_greville_points = 0;
64 if constexpr (U::is_periodic()) {
65 n_greville_points =
ddc::discrete_space<BSplines>().nbasis() + 1;
67 n_greville_points =
ddc::discrete_space<BSplines>().nbasis();
70 std::vector<
double> greville_points(n_greville_points);
72 =
ddc::discrete_space<BSplines>().full_domain().take_first(
78 ddc::DiscreteElement<BSplines> ib0(bspline_domain.front());
80 ddc::for_each(bspline_domain, [&](
ddc::DiscreteElement<BSplines> ib) {
82 greville_points[ib - ib0] = 0.0;
84 ddc::discrete_space<BSplines>().get_first_support_knot(ib) + 1,
86 ddc::for_each(sub_domain, [&](
auto ik) {
87 greville_points[ib - ib0] +=
ddc::coordinate(ik);
89 greville_points[ib - ib0] /= n_points_in_average.value();
93 if constexpr (U::is_periodic()) {
94 std::vector<
double> temp_knots(BSplines::degree());
97 while (greville_points[npoints] <
ddc::discrete_space<BSplines>().rmin()) {
99 = greville_points[npoints] +
ddc::discrete_space<BSplines>().length();
103 for (std::size_t i = 0; i <
ddc::discrete_space<BSplines>().nbasis() - npoints; ++i) {
104 greville_points[i] = greville_points[i + npoints];
106 for (
int i = 0; i < npoints; ++i) {
107 greville_points[
ddc::discrete_space<BSplines>().nbasis() - npoints + i]
112 greville_points[n_greville_points - 1]
113 = greville_points[0] +
ddc::discrete_space<BSplines>().length();
116 return SamplingImpl(greville_points);
119 static constexpr int N_BE_MIN = n_boundary_equations(BcLower, BSplines::degree());
120 static constexpr int N_BE_MAX = n_boundary_equations(BcUpper, BSplines::degree());
122 static constexpr bool is_uniform_discrete_dimension_v
123 = U::is_uniform() && ((N_BE_MIN != 0 && N_BE_MAX != 0) || U::is_periodic());
127
128
129
130
131
132
133
134
135
136
139 typename U = BSplines,
141 is_uniform_discrete_dimension_v<U>,
146 return uniform_greville_points<Sampling>();
150
151
152
153
154
155
158 typename U = BSplines,
160 !is_uniform_discrete_dimension_v<U>,
165 using SamplingImpl =
typename Sampling::
template Impl<Sampling, Kokkos::HostSpace>;
166 if constexpr (U::is_uniform()) {
167 using IntermediateSampling = IntermediateUniformSampling<Sampling>;
168 auto points_wo_bcs = uniform_greville_points<IntermediateSampling>();
169 int const n_break_points =
ddc::discrete_space<BSplines>().ncells() + 1;
170 int const npoints =
ddc::discrete_space<BSplines>().nbasis() - N_BE_MIN - N_BE_MAX;
171 std::vector<
double> points_with_bcs(npoints);
175 for (std::size_t i(0); i < BSplines::degree() / 2 + 1; ++i) {
177 = (BSplines::degree() - i) *
ddc::discrete_space<BSplines>().rmin();
178 ddc::DiscreteElement<BSplines>
const spline_idx(i);
181 ddc::discrete_space<BSplines>().get_last_support_knot(spline_idx)
187 points_with_bcs[i] +=
ddc::coordinate(ik);
189 points_with_bcs[i] /= BSplines::degree();
193 = points_wo_bcs.coordinate(
ddc::DiscreteElement<IntermediateSampling>(0));
198 int const domain_size = n_break_points - 2;
199 ddc::DiscreteElement<IntermediateSampling> domain_start(1);
204 ddc::for_each(domain, [&](
auto ip) {
205 points_with_bcs[ip - domain_start + n_start] = points_wo_bcs.coordinate(ip);
210 for (std::size_t i(0); i < BSplines::degree() / 2 + 1; ++i) {
211 points_with_bcs[npoints - 1 - i]
212 = (BSplines::degree() - i) *
ddc::discrete_space<BSplines>().rmax();
213 ddc::DiscreteElement<BSplines>
const spline_idx(
214 ddc::discrete_space<BSplines>().nbasis() - 1 - i);
217 ddc::discrete_space<BSplines>().get_first_support_knot(spline_idx) + 1,
222 points_with_bcs[npoints - 1 - i] +=
ddc::coordinate(ik);
224 points_with_bcs[npoints - 1 - i] /= BSplines::degree();
227 points_with_bcs[npoints - 1]
228 = points_wo_bcs.coordinate(
ddc::DiscreteElement<IntermediateSampling>(
229 ddc::discrete_space<BSplines>().ncells() - 1
230 + BSplines::degree() % 2));
232 return SamplingImpl(points_with_bcs);
234 using IntermediateSampling = IntermediateNonUniformSampling<Sampling>;
235 if constexpr (N_BE_MIN == 0 && N_BE_MAX == 0) {
236 return non_uniform_greville_points<Sampling>();
238 auto points_wo_bcs = non_uniform_greville_points<IntermediateSampling>();
240 std::vector<
double> points_with_bcs(points_wo_bcs.size() - N_BE_MIN - N_BE_MAX);
241 int constexpr n_start = N_BE_MIN;
245 ddc::DiscreteElement<IntermediateSampling> domain_start(n_start);
247 domain(domain_start, length(points_with_bcs.size()));
249 points_with_bcs[0] = points_wo_bcs.coordinate(domain.front());
250 ddc::for_each(domain.remove(length(1), length(1)), [&](
auto ip) {
251 points_with_bcs[ip - domain_start] = points_wo_bcs.coordinate(ip);
253 points_with_bcs[points_with_bcs.size() - 1]
254 = points_wo_bcs.coordinate(domain.back());
256 return SamplingImpl(points_with_bcs);
262
263
264
265
266 using interpolation_discrete_dimension_type = std::conditional_t<
267 is_uniform_discrete_dimension_v<BSplines>,
272
273
274
275
276
277
278 template <
class Sampling>
281 int const npoints =
ddc::discrete_space<BSplines>().nbasis() - N_BE_MIN - N_BE_MAX;
283 ddc::DiscreteElement<Sampling>(0),
friend class DiscreteDomain
KOKKOS_FUNCTION constexpr bool operator!=(DiscreteVector< OTags... > const &rhs) const noexcept
A class which provides helper functions to initialise the Greville points from a B-Spline definition.
static ddc::DiscreteDomain< Sampling > get_domain()
Get the domain which gives us access to all of the Greville points.
static auto get_sampling()
Get the UniformPointSampling defining the Greville points.
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.