DDC 0.16.0
Loading...
Searching...
No Matches
spline_evaluator.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
15#include "deriv.hpp"
16#include "integrals.hpp"
18
19namespace ddc {
20
21/**
22 * @brief A class to evaluate, differentiate or integrate a spline function.
23 *
24 * A class which contains an operator () which can be used to evaluate, differentiate or integrate a spline function.
25 *
26 * @tparam ExecSpace The Kokkos execution space on which the spline evaluation is performed.
27 * @tparam MemorySpace The Kokkos memory space on which the data (spline coefficients and evaluation) is stored.
28 * @tparam BSplines The discrete dimension representing the B-splines.
29 * @tparam EvaluationDDim The discrete dimension on which evaluation points are defined.
30 * @tparam LowerExtrapolationRule The lower extrapolation rule type.
31 * @tparam UpperExtrapolationRule The upper extrapolation rule type.
32 */
33template <
34 class ExecSpace,
35 class MemorySpace,
36 class BSplines,
37 class EvaluationDDim,
38 class LowerExtrapolationRule,
39 class UpperExtrapolationRule>
41{
42public:
43 /// @brief The type of the Kokkos execution space used by this class.
44 using exec_space = ExecSpace;
45
46 /// @brief The type of the Kokkos memory space used by this class.
47 using memory_space = MemorySpace;
48
49 /// @brief The type of the evaluation continuous dimension (continuous dimension of interest) used by this class.
50 using continuous_dimension_type = BSplines::continuous_dimension_type;
51
52 /// @brief The type of the evaluation discrete dimension (discrete dimension of interest) used by this class.
53 using evaluation_discrete_dimension_type = EvaluationDDim;
54
55 /// @brief The discrete dimension representing the B-splines.
56 using bsplines_type = BSplines;
57
58 /// @brief The type of the domain for the 1D evaluation mesh used by this class.
59 using evaluation_domain_type = ddc::DiscreteDomain<evaluation_discrete_dimension_type>;
60
61 /**
62 * @brief The type of the whole domain representing evaluation points.
63 *
64 * @tparam The batched discrete domain on which the interpolation points are defined.
65 */
66 template <concepts::discrete_domain BatchedInterpolationDDom>
67 using batched_evaluation_domain_type = BatchedInterpolationDDom;
68
69 /// @brief The type of the 1D spline domain corresponding to the dimension of interest.
70 using spline_domain_type = ddc::DiscreteDomain<bsplines_type>;
71
72 /**
73 * @brief The type of the batch domain (obtained by removing the dimension of interest
74 * from the whole domain).
75 *
76 * @tparam The batched discrete domain on which the interpolation points are defined.
77 */
78 template <concepts::discrete_domain BatchedInterpolationDDom>
79 using batch_domain_type
80 = ddc::remove_dims_of_t<BatchedInterpolationDDom, evaluation_discrete_dimension_type>;
81
82 /**
83 * @brief The type of the whole spline domain (cartesian product of 1D spline domain
84 * and batch domain) preserving the order of dimensions.
85 *
86 * @tparam The batched discrete domain on which the interpolation points are defined.
87 */
88 template <concepts::discrete_domain BatchedInterpolationDDom>
89 using batched_spline_domain_type = ddc::replace_dim_of_t<
90 BatchedInterpolationDDom,
91 evaluation_discrete_dimension_type,
92 bsplines_type>;
93
94 /// @brief The type of the extrapolation rule at the lower boundary.
95 using lower_extrapolation_rule_type = LowerExtrapolationRule;
96
97 /// @brief The type of the extrapolation rule at the upper boundary.
98 using upper_extrapolation_rule_type = UpperExtrapolationRule;
99
100
101private:
102 LowerExtrapolationRule m_lower_extrap_rule;
103
104 UpperExtrapolationRule m_upper_extrap_rule;
105
106public:
107 static_assert(
108 std::is_same_v<LowerExtrapolationRule,
109 typename ddc::PeriodicExtrapolationRule<continuous_dimension_type>>
110 == bsplines_type::is_periodic()
111 && std::is_same_v<
112 UpperExtrapolationRule,
113 typename ddc::PeriodicExtrapolationRule<continuous_dimension_type>>
114 == bsplines_type::is_periodic(),
115 "PeriodicExtrapolationRule has to be used if and only if dimension is periodic");
116 static_assert(
117 std::is_invocable_r_v<
118 Real,
119 LowerExtrapolationRule,
120 ddc::Coordinate<continuous_dimension_type>,
121 ddc::ChunkSpan<
122 Real const,
123 spline_domain_type,
124 Kokkos::layout_right,
125 memory_space>>,
126 "LowerExtrapolationRule::operator() has to be callable with usual arguments.");
127 static_assert(
128 std::is_invocable_r_v<
129 Real,
130 UpperExtrapolationRule,
131 ddc::Coordinate<continuous_dimension_type>,
132 ddc::ChunkSpan<
133 Real const,
134 spline_domain_type,
135 Kokkos::layout_right,
136 memory_space>>,
137 "UpperExtrapolationRule::operator() has to be callable with usual arguments.");
138
139 /**
140 * @brief Build a SplineEvaluator acting on batched_spline_domain.
141 *
142 * @param lower_extrap_rule The extrapolation rule at the lower boundary.
143 * @param upper_extrap_rule The extrapolation rule at the upper boundary.
144 *
145 * @see NullExtrapolationRule ConstantExtrapolationRule PeriodicExtrapolationRule
146 */
147 explicit SplineEvaluator(
148 LowerExtrapolationRule const& lower_extrap_rule,
149 UpperExtrapolationRule const& upper_extrap_rule)
150 : m_lower_extrap_rule(lower_extrap_rule)
151 , m_upper_extrap_rule(upper_extrap_rule)
152 {
153 }
154
155 /**
156 * @brief Copy-constructs.
157 *
158 * @param x A reference to another SplineEvaluator.
159 */
160 SplineEvaluator(SplineEvaluator const& x) = default;
161
162 /**
163 * @brief Move-constructs.
164 *
165 * @param x An rvalue to another SplineEvaluator.
166 */
167 SplineEvaluator(SplineEvaluator&& x) = default;
168
169 /// @brief Destructs
170 ~SplineEvaluator() = default;
171
172 /**
173 * @brief Copy-assigns.
174 *
175 * @param x A reference to another SplineEvaluator.
176 * @return A reference to this object.
177 */
178 SplineEvaluator& operator=(SplineEvaluator const& x) = default;
179
180 /**
181 * @brief Move-assigns.
182 *
183 * @param x An rvalue to another SplineEvaluator.
184 * @return A reference to this object.
185 */
187
188 /**
189 * @brief Get the lower extrapolation rule.
190 *
191 * Extrapolation rules are functors used to define the behavior of the SplineEvaluator out of the domain where the break points of the B-splines are defined.
192 *
193 * @return The lower extrapolation rule.
194 *
195 * @see NullExtrapolationRule ConstantExtrapolationRule PeriodicExtrapolationRule
196 */
197 lower_extrapolation_rule_type lower_extrapolation_rule() const
198 {
199 return m_lower_extrap_rule;
200 }
201
202 /**
203 * @brief Get the upper extrapolation rule.
204 *
205 * Extrapolation rules are functors used to define the behavior of the SplineEvaluator out of the domain where the break points of the B-splines are defined.
206 *
207 * @return The upper extrapolation rule.
208 *
209 * @see NullExtrapolationRule ConstantExtrapolationRule PeriodicExtrapolationRule
210 */
211 upper_extrapolation_rule_type upper_extrapolation_rule() const
212 {
213 return m_upper_extrap_rule;
214 }
215
216 /**
217 * @brief Evaluate 1D spline function (described by its spline coefficients) at a given coordinate.
218 *
219 * The spline coefficients represent a 1D spline function defined on a B-splines (basis splines). They can be obtained via various methods, such as using a SplineBuilder.
220 *
221 * Remark: calling SplineBuilder then SplineEvaluator corresponds to a spline interpolation.
222 *
223 * @param coord_eval The coordinate where the spline is evaluated. Note that only the component along the dimension of interest is used.
224 * @param spline_coef A ChunkSpan storing the 1D spline coefficients.
225 *
226 * @return The value of the spline function at the desired coordinate.
227 */
228 template <class Layout, class... CoordsDims>
229 KOKKOS_FUNCTION Real operator()(
230 ddc::Coordinate<CoordsDims...> const& coord_eval,
231 ddc::ChunkSpan<Real const, spline_domain_type, Layout, memory_space> const spline_coef)
232 const
233 {
234 return eval(coord_eval, spline_coef);
235 }
236
237 /**
238 * @brief Evaluate spline function (described by its spline coefficients) on a mesh.
239 *
240 * The spline coefficients represent a spline function defined on a cartesian product of batch_domain and B-splines
241 * (basis splines). They can be obtained via various methods, such as using a SplineBuilder.
242 *
243 * This is not a multidimensional evaluation. This is a batched 1D evaluation. This means that for each slice of coordinates
244 * identified by a batch_domain_type::discrete_element_type, the evaluation is performed with the 1D set of
245 * spline coefficients identified by the same batch_domain_type::discrete_element_type.
246 *
247 * Remark: calling SplineBuilder then SplineEvaluator corresponds to a spline interpolation.
248 *
249 * @param[out] spline_eval The values of the spline function at the desired coordinates. For practical reasons those are
250 * stored in a ChunkSpan defined on a batched_evaluation_domain_type.
251 * @param[in] coords_eval The coordinates where the spline is evaluated. Those are
252 * stored in a ChunkSpan defined on a batched_evaluation_domain_type. Note that the coordinates of the
253 * points represented by this domain are unused and irrelevant (but the points themselves (DiscreteElement) are used to select
254 * the set of 1D spline coefficients retained to perform the evaluation).
255 * @param[in] spline_coef A ChunkSpan storing the spline coefficients.
256 */
257 template <
258 class Layout1,
259 class Layout2,
260 class Layout3,
261 class BatchedInterpolationDDom,
262 class... CoordsDims>
263 void operator()(
264 ddc::ChunkSpan<Real, BatchedInterpolationDDom, Layout1, memory_space> const spline_eval,
265 ddc::ChunkSpan<
266 ddc::Coordinate<CoordsDims...> const,
267 BatchedInterpolationDDom,
268 Layout2,
269 memory_space> const coords_eval,
270 ddc::ChunkSpan<
271 Real const,
272 batched_spline_domain_type<BatchedInterpolationDDom>,
273 Layout3,
274 memory_space> const spline_coef) const
275 {
276 evaluation_domain_type const evaluation_domain(spline_eval.domain());
277 batch_domain_type<BatchedInterpolationDDom> const batch_domain(spline_eval.domain());
278
279 ddc::parallel_for_each(
280 "ddc_splines_evaluate",
281 exec_space(),
282 batch_domain,
283 KOKKOS_CLASS_LAMBDA(
284 batch_domain_type<BatchedInterpolationDDom>::discrete_element_type const
285 j) {
286 auto const spline_eval_1D = spline_eval[j];
287 auto const coords_eval_1D = coords_eval[j];
288 auto const spline_coef_1D = spline_coef[j];
289 for (auto const i : evaluation_domain) {
290 spline_eval_1D(i) = eval(coords_eval_1D(i), spline_coef_1D);
291 }
292 });
293 }
294
295 /**
296 * @brief Evaluate a spline function (described by its spline coefficients) on a mesh.
297 *
298 * The spline coefficients represent a spline function defined on a cartesian
299 * product of batch_domain and B-splines (basis splines). They can be obtained
300 * via various methods, such as using a SplineBuilder.
301 *
302 * This is not a multidimensional evaluation. This is a batched 1D evaluation.
303 * This means that for each slice of spline_eval the evaluation is performed with
304 * the 1D set of spline coefficients identified by the same batch_domain_type::discrete_element_type.
305 *
306 * Remark: calling SplineBuilder then SplineEvaluator corresponds to a spline
307 * interpolation.
308 *
309 * @param[out] spline_eval The values of the spline function at the coordinates
310 * of the mesh.
311 * @param[in] spline_coef A ChunkSpan storing the spline coefficients.
312 */
313 template <class Layout1, class Layout2, class BatchedInterpolationDDom>
314 void operator()(
315 ddc::ChunkSpan<Real, BatchedInterpolationDDom, Layout1, memory_space> const spline_eval,
316 ddc::ChunkSpan<
317 Real const,
318 batched_spline_domain_type<BatchedInterpolationDDom>,
319 Layout2,
320 memory_space> const spline_coef) const
321 {
322 evaluation_domain_type const evaluation_domain(spline_eval.domain());
323 batch_domain_type<BatchedInterpolationDDom> const batch_domain(spline_eval.domain());
324
325 ddc::parallel_for_each(
326 "ddc_splines_evaluate",
327 exec_space(),
328 batch_domain,
329 KOKKOS_CLASS_LAMBDA(
330 batch_domain_type<BatchedInterpolationDDom>::discrete_element_type const
331 j) {
332 auto const spline_eval_1D = spline_eval[j];
333 auto const spline_coef_1D = spline_coef[j];
334 for (auto const i : evaluation_domain) {
335 ddc::Coordinate<continuous_dimension_type> coord_eval_1D
336 = ddc::coordinate(i);
337 spline_eval_1D(i) = eval(coord_eval_1D, spline_coef_1D);
338 }
339 });
340 }
341
342 /**
343 * @brief Differentiate 1D spline function (described by its spline coefficients) at a given coordinate.
344 *
345 * The spline coefficients represent a 1D spline function defined on a B-splines (basis splines). They can be
346 * obtained via various methods, such as using a SplineBuilder.
347 *
348 * @param deriv_order A DiscreteElement containing the order of derivation for the dimension of interest.
349 * If the dimension is not present, the order of derivation is considered to be 0.
350 * @param coord_eval The coordinate where the spline is differentiated. Note that only the component along the dimension of interest is used.
351 * @param spline_coef A ChunkSpan storing the 1D spline coefficients.
352 *
353 * @return The derivative of the spline function at the desired coordinate.
354 */
355 template <class DElem, class Layout, class... CoordsDims>
356 KOKKOS_FUNCTION Real
357 deriv(DElem const& deriv_order,
358 ddc::Coordinate<CoordsDims...> const& coord_eval,
359 ddc::ChunkSpan<Real const, spline_domain_type, Layout, memory_space> const spline_coef)
360 const
361 {
362 static_assert(is_discrete_element_v<DElem>);
363 return eval_no_bc(deriv_order, coord_eval, spline_coef);
364 }
365
366 /**
367 * @brief Differentiate 1D spline function (described by its spline coefficients) on a mesh.
368 *
369 * The spline coefficients represent a spline function defined on a cartesian product of batch_domain and B-splines
370 * (basis splines). They can be obtained via various methods, such as using a SplineBuilder.
371 *
372 * The derivation is not performed in a multidimensional way (in any sense). This is a batched 1D derivation.
373 * This means that for each slice of coordinates identified by a batch_domain_type::discrete_element_type,
374 * the derivation is performed with the 1D set of spline coefficients identified by the same batch_domain_type::discrete_element_type.
375 *
376 * @param[in] deriv_order A DiscreteElement containing the order of derivation for the dimension of interest.
377 * If the dimension is not present, the order of derivation is considered to be 0.
378 * @param[out] spline_eval The derivatives of the spline function at the desired coordinates. For practical reasons those are
379 * stored in a ChunkSpan defined on a batched_evaluation_domain_type.
380 * @param[in] coords_eval The coordinates where the spline is differentiated. Those are
381 * stored in a ChunkSpan defined on a batched_evaluation_domain_type. Note that the coordinates of the
382 * points represented by this domain are unused and irrelevant (but the points themselves (DiscreteElement) are used to select
383 * the set of 1D spline coefficients retained to perform the evaluation).
384 * @param[in] spline_coef A ChunkSpan storing the spline coefficients.
385 */
386 template <
387 class DElem,
388 class Layout1,
389 class Layout2,
390 class Layout3,
391 class BatchedInterpolationDDom,
392 class... CoordsDims>
393 void deriv(
394 DElem const& deriv_order,
395 ddc::ChunkSpan<Real, BatchedInterpolationDDom, Layout1, memory_space> const spline_eval,
396 ddc::ChunkSpan<
397 ddc::Coordinate<CoordsDims...> const,
398 BatchedInterpolationDDom,
399 Layout2,
400 memory_space> const coords_eval,
401 ddc::ChunkSpan<
402 Real const,
403 batched_spline_domain_type<BatchedInterpolationDDom>,
404 Layout3,
405 memory_space> const spline_coef) const
406 {
407 static_assert(is_discrete_element_v<DElem>);
408
409 evaluation_domain_type const evaluation_domain(spline_eval.domain());
410 batch_domain_type<BatchedInterpolationDDom> const batch_domain(spline_eval.domain());
411
412 ddc::parallel_for_each(
413 "ddc_splines_differentiate",
414 exec_space(),
415 batch_domain,
416 KOKKOS_CLASS_LAMBDA(
417 batch_domain_type<BatchedInterpolationDDom>::discrete_element_type const
418 j) {
419 auto const spline_eval_1D = spline_eval[j];
420 auto const coords_eval_1D = coords_eval[j];
421 auto const spline_coef_1D = spline_coef[j];
422 for (auto const i : evaluation_domain) {
423 spline_eval_1D(i)
424 = eval_no_bc(deriv_order, coords_eval_1D(i), spline_coef_1D);
425 }
426 });
427 }
428
429 /**
430 * @brief Differentiate 1D spline function (described by its spline coefficients) on a mesh.
431 *
432 * The spline coefficients represent a spline function defined on a cartesian product of batch_domain and B-splines
433 * (basis splines). They can be obtained via various methods, such as using a SplineBuilder.
434 *
435 * The derivation is not performed in a multidimensional way (in any sense). This is a batched 1D derivation.
436 * This means that for each slice of spline_eval the evaluation is performed with
437 * the 1D set of spline coefficients identified by the same batch_domain_type::discrete_element_type.
438 *
439 * @param[in] deriv_order A DiscreteElement containing the order of derivation for the dimension of interest.
440 * If the dimension is not present, the order of derivation is considered to be 0.
441 * @param[out] spline_eval The derivatives of the spline function at the coordinates.
442 * @param[in] spline_coef A ChunkSpan storing the spline coefficients.
443 */
444 template <class DElem, class Layout1, class Layout2, class BatchedInterpolationDDom>
445 void deriv(
446 DElem const& deriv_order,
447 ddc::ChunkSpan<Real, BatchedInterpolationDDom, Layout1, memory_space> const spline_eval,
448 ddc::ChunkSpan<
449 Real const,
450 batched_spline_domain_type<BatchedInterpolationDDom>,
451 Layout2,
452 memory_space> const spline_coef) const
453 {
454 static_assert(is_discrete_element_v<DElem>);
455
456 evaluation_domain_type const evaluation_domain(spline_eval.domain());
457 batch_domain_type<BatchedInterpolationDDom> const batch_domain(spline_eval.domain());
458
459 ddc::parallel_for_each(
460 "ddc_splines_differentiate",
461 exec_space(),
462 batch_domain,
463 KOKKOS_CLASS_LAMBDA(
464 batch_domain_type<BatchedInterpolationDDom>::discrete_element_type const
465 j) {
466 auto const spline_eval_1D = spline_eval[j];
467 auto const spline_coef_1D = spline_coef[j];
468 for (auto const i : evaluation_domain) {
469 ddc::Coordinate<continuous_dimension_type> coord_eval_1D
470 = ddc::coordinate(i);
471 spline_eval_1D(i) = eval_no_bc(deriv_order, coord_eval_1D, spline_coef_1D);
472 }
473 });
474 }
475
476 /** @brief Perform batched 1D integrations of a spline function (described by its spline coefficients) along the dimension of interest and store results on a subdomain of batch_domain.
477 *
478 * The spline coefficients represent a spline function defined on a B-splines (basis splines). They can be obtained via the SplineBuilder.
479 *
480 * The integration is not performed in a multidimensional way (in any sense). This is a batched 1D integration.
481 * This means that for each element of integrals, the integration is performed with the 1D set of
482 * spline coefficients identified by the same DiscreteElement.
483 *
484 * @param[out] integrals The integrals of the spline function on the subdomain of batch_domain. For practical reasons those are
485 * stored in a ChunkSpan defined on a batch_domain_type. Note that the coordinates of the
486 * points represented by this domain are unused and irrelevant.
487 * @param[in] spline_coef A ChunkSpan storing the spline coefficients.
488 */
489 template <class Layout1, class Layout2, class BatchedDDom, class BatchedSplineDDom>
490 void integrate(
491 ddc::ChunkSpan<Real, BatchedDDom, Layout1, memory_space> const integrals,
492 ddc::ChunkSpan<Real const, BatchedSplineDDom, Layout2, memory_space> const spline_coef)
493 const
494 {
495 static_assert(
496 ddc::in_tags_v<bsplines_type, to_type_seq_t<BatchedSplineDDom>>,
497 "The spline coefficients domain must contain the bsplines dimension");
498 using batch_domain_type = ddc::remove_dims_of_t<BatchedSplineDDom, bsplines_type>;
499 static_assert(
500 std::is_same_v<batch_domain_type, BatchedDDom>,
501 "The integrals domain must only contain the batch dimensions");
502
503 BatchedDDom const batch_domain(integrals.domain());
504 ddc::Chunk values_alloc(
505 "values (ddc::SplineEvaluator::integrate)",
506 ddc::DiscreteDomain<bsplines_type>(spline_coef.domain()),
507 ddc::KokkosAllocator<Real, memory_space>());
508 ddc::ChunkSpan const values = values_alloc.span_view();
509 ddc::integrals(exec_space(), values);
510
511 ddc::parallel_for_each(
512 "ddc_splines_integrate",
513 exec_space(),
514 batch_domain,
515 KOKKOS_LAMBDA(BatchedDDom::discrete_element_type const j) {
516 integrals(j) = 0;
517 for (typename spline_domain_type::discrete_element_type const i :
518 values.domain()) {
519 integrals(j) += spline_coef(i, j) * values(i);
520 }
521 });
522 }
523
524private:
525 template <class Layout, class... CoordsDims>
526 KOKKOS_INLINE_FUNCTION Real
527 eval(ddc::Coordinate<CoordsDims...> const& coord_eval,
528 ddc::ChunkSpan<Real const, spline_domain_type, Layout, memory_space> const spline_coef)
529 const
530 {
531 ddc::Coordinate<continuous_dimension_type> coord_eval_interest(coord_eval);
532 if constexpr (bsplines_type::is_periodic()) {
533 if (coord_eval_interest < ddc::discrete_space<bsplines_type>().rmin()
534 || coord_eval_interest > ddc::discrete_space<bsplines_type>().rmax()) {
535 coord_eval_interest -= Kokkos::floor(
536 (coord_eval_interest
537 - ddc::discrete_space<bsplines_type>().rmin())
538 / ddc::discrete_space<bsplines_type>().length())
539 * ddc::discrete_space<bsplines_type>().length();
540 }
541 } else {
542 if (coord_eval_interest < ddc::discrete_space<bsplines_type>().rmin()) {
543 return m_lower_extrap_rule(coord_eval_interest, spline_coef);
544 }
545 if (coord_eval_interest > ddc::discrete_space<bsplines_type>().rmax()) {
546 return m_upper_extrap_rule(coord_eval_interest, spline_coef);
547 }
548 }
549 return eval_no_bc(ddc::DiscreteElement<>(), coord_eval_interest, spline_coef);
550 }
551
552 template <class... DerivDims, class Layout, class... CoordsDims>
553 KOKKOS_INLINE_FUNCTION Real eval_no_bc(
554 ddc::DiscreteElement<DerivDims...> const& deriv_order,
555 ddc::Coordinate<CoordsDims...> const& coord_eval,
556 ddc::ChunkSpan<Real const, spline_domain_type, Layout, memory_space> const spline_coef)
557 const
558 {
559 using deriv_dim = ddc::Deriv<continuous_dimension_type>;
560 static_assert(
561 sizeof...(DerivDims) == 0
562 || type_seq_same_v<TypeSeq<DerivDims...>, TypeSeq<deriv_dim>>,
563 "The only valid dimension for deriv_order is Deriv<Dim>");
564
565 ddc::DiscreteElement<bsplines_type> jmin;
566 std::array<Real, bsplines_type::degree() + 1> vals_ptr;
567 Kokkos::mdspan<Real, Kokkos::extents<std::size_t, bsplines_type::degree() + 1>> const vals(
568 vals_ptr.data());
569 ddc::Coordinate<continuous_dimension_type> const coord_eval_interest(coord_eval);
570
571 if constexpr (sizeof...(DerivDims) == 0) {
572 jmin = ddc::discrete_space<bsplines_type>().eval_basis(vals, coord_eval_interest);
573 } else {
574 auto const order = deriv_order.uid();
575 KOKKOS_ASSERT(order > 0 && order <= bsplines_type::degree())
576
577 std::array<Real, (bsplines_type::degree() + 1) * (bsplines_type::degree() + 1)>
578 derivs_ptr;
579 Kokkos::mdspan<
580 Real,
581 Kokkos::extents<
582 std::size_t,
583 bsplines_type::degree() + 1,
584 Kokkos::dynamic_extent>> const derivs(derivs_ptr.data(), order + 1);
585
586 jmin = ddc::discrete_space<bsplines_type>()
587 .eval_basis_and_n_derivs(derivs, coord_eval_interest, order);
588
589 for (std::size_t i = 0; i < bsplines_type::degree() + 1; ++i) {
590 vals[i] = DDC_MDSPAN_ACCESS_OP(derivs, i, order);
591 }
592 }
593
594 Real y = 0.0;
595 for (std::size_t i = 0; i < bsplines_type::degree() + 1; ++i) {
596 y += spline_coef(ddc::DiscreteElement<bsplines_type>(jmin + i)) * vals[i];
597 }
598 return y;
599 }
600};
601
602} // namespace ddc
friend class ChunkSpan
friend class Chunk
Definition chunk.hpp:83
friend class DiscreteDomain
KOKKOS_DEFAULTED_FUNCTION constexpr DiscreteElement()=default
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.
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.
Storage class of the static attributes of the discrete dimension.
KOKKOS_INLINE_FUNCTION std::size_t ncells() const noexcept
Returns the number of cells over which the B-splines are defined.
Impl(Impl &&x)=default
Move-constructs.
KOKKOS_INLINE_FUNCTION std::size_t nbasis() const noexcept
Returns the number of basis functions.
KOKKOS_INLINE_FUNCTION ddc::DiscreteElement< knot_discrete_dimension_type > get_last_support_knot(discrete_element_type const &ix) const
Returns the coordinate of the last support knot associated to a DiscreteElement identifying a B-splin...
KOKKOS_INLINE_FUNCTION discrete_element_type eval_basis_and_n_derivs(Kokkos::mdspan< double, Kokkos::dextents< std::size_t, 2 > > derivs, ddc::Coordinate< CDim > const &x, std::size_t n) const
Evaluates non-zero B-spline values and derivatives at a given coordinate.
Impl(Impl< DDim, OriginMemorySpace > const &impl)
Copy-constructs from another Impl with a different Kokkos memory space.
Impl(Impl const &x)=default
Copy-constructs.
KOKKOS_INLINE_FUNCTION discrete_element_type eval_deriv(Kokkos::mdspan< double, Kokkos::dextents< std::size_t, 1 > > derivs, ddc::Coordinate< CDim > const &x) const
Evaluates non-zero B-spline derivatives at a given coordinate.
KOKKOS_INLINE_FUNCTION ddc::DiscreteDomain< knot_discrete_dimension_type > break_point_domain() const
Returns the discrete domain which describes the break points.
Impl & operator=(Impl const &x)=default
Copy-assigns.
KOKKOS_INLINE_FUNCTION Real length() const noexcept
Returns the length of the domain.
KOKKOS_INLINE_FUNCTION std::size_t npoints() const noexcept
The number of break points.
KOKKOS_INLINE_FUNCTION ddc::DiscreteElement< knot_discrete_dimension_type > get_first_support_knot(discrete_element_type const &ix) const
Returns the coordinate of the first support knot associated to a DiscreteElement identifying a B-spli...
Impl(RandomIt breaks_begin, RandomIt breaks_end)
Constructs an Impl by iterating over a range of break points from begin to end.
KOKKOS_INLINE_FUNCTION discrete_domain_type full_domain() const
Returns the discrete domain including eventual additional B-splines in the periodic case.
KOKKOS_INLINE_FUNCTION std::size_t size() const noexcept
Returns the number of elements necessary to construct a spline representation of a function.
Impl(std::initializer_list< ddc::Coordinate< CDim > > breaks)
Constructs an Impl using a brace-list, i.e.
Impl & operator=(Impl &&x)=default
Move-assigns.
KOKKOS_INLINE_FUNCTION ddc::Coordinate< CDim > rmin() const noexcept
Returns the coordinate of the first break point of the domain on which the B-splines are defined.
KOKKOS_INLINE_FUNCTION discrete_element_type eval_basis(Kokkos::mdspan< double, Kokkos::dextents< std::size_t, 1 > > values, ddc::Coordinate< CDim > const &x) const
Evaluates non-zero B-splines at a given coordinate.
~Impl()=default
Destructs.
KOKKOS_INLINE_FUNCTION ddc::Coordinate< CDim > rmax() const noexcept
Returns the coordinate of the last break point of the domain on which the B-splines are defined.
Impl(std::vector< ddc::Coordinate< CDim > > const &breaks)
Constructs an Impl using a std::vector.
The type of a non-uniform 1D spline basis (B-spline).
static constexpr std::size_t degree() noexcept
The degree of B-splines.
static constexpr bool is_periodic() noexcept
Indicates if the B-splines are periodic or not.
static constexpr bool is_uniform() noexcept
Indicates if the B-splines are uniform or not (this is not the case here).
NonUniformPointSampling models a non-uniform discretization of the CDim segment .
A class for creating a 2D spline approximation of a function.
SplineBuilder2D(BatchedInterpolationDDom const &batched_interpolation_domain, std::optional< std::size_t > cols_per_chunk=std::nullopt, std::optional< unsigned int > preconditioner_max_block_size=std::nullopt)
Build a SplineBuilder2D acting on the interpolation domain contained in batched_interpolation_domain.
void operator()(ddc::ChunkSpan< Real, batched_spline_domain_type< BatchedInterpolationDDom >, Layout, memory_space > spline, ddc::ChunkSpan< Real const, BatchedInterpolationDDom, Layout, memory_space > vals, std::optional< ddc::ChunkSpan< Real const, batched_derivs_domain_type1< BatchedInterpolationDDom >, Layout, memory_space > > derivs_min1=std::nullopt, std::optional< ddc::ChunkSpan< Real const, batched_derivs_domain_type1< BatchedInterpolationDDom >, Layout, memory_space > > derivs_max1=std::nullopt, std::optional< ddc::ChunkSpan< Real const, batched_derivs_domain_type2< BatchedInterpolationDDom >, Layout, memory_space > > derivs_min2=std::nullopt, std::optional< ddc::ChunkSpan< Real const, batched_derivs_domain_type2< BatchedInterpolationDDom >, Layout, memory_space > > derivs_max2=std::nullopt, std::optional< ddc::ChunkSpan< Real const, batched_derivs_domain_type< BatchedInterpolationDDom >, Layout, memory_space > > mixed_derivs_min1_min2=std::nullopt, std::optional< ddc::ChunkSpan< Real const, batched_derivs_domain_type< BatchedInterpolationDDom >, Layout, memory_space > > mixed_derivs_max1_min2=std::nullopt, std::optional< ddc::ChunkSpan< Real const, batched_derivs_domain_type< BatchedInterpolationDDom >, Layout, memory_space > > mixed_derivs_min1_max2=std::nullopt, std::optional< ddc::ChunkSpan< Real const, batched_derivs_domain_type< BatchedInterpolationDDom >, Layout, memory_space > > mixed_derivs_max1_max2=std::nullopt) const
Compute a 2D spline approximation of a function.
SplineBuilder2D & operator=(SplineBuilder2D const &x)=delete
Copy-assignment is deleted.
SplineBuilder2D(std::string const &label, BatchedInterpolationDDom const &batched_interpolation_domain, std::optional< std::size_t > cols_per_chunk=std::nullopt, std::optional< unsigned int > preconditioner_max_block_size=std::nullopt)
Build a SplineBuilder2D acting on the interpolation domain contained in batched_interpolation_domain.
batch_domain_type< BatchedInterpolationDDom > batch_domain(BatchedInterpolationDDom const &batched_interpolation_domain) const noexcept
Get the batch domain.
interpolation_domain_type interpolation_domain() const noexcept
Get the domain for the 2D interpolation mesh used by this class.
SplineBuilder2D(SplineBuilder2D &&x)=default
Move-constructs.
batched_spline_domain_type< BatchedInterpolationDDom > batched_spline_domain(BatchedInterpolationDDom const &batched_interpolation_domain) const noexcept
Get the whole domain on which spline coefficients are defined.
SplineBuilder2D(interpolation_domain_type const &interpolation_domain, std::optional< std::size_t > cols_per_chunk=std::nullopt, std::optional< unsigned int > preconditioner_max_block_size=std::nullopt)
Build a SplineBuilder2D acting on interpolation_domain.
~SplineBuilder2D()=default
Destructs.
SplineBuilder2D(std::string const &label, interpolation_domain_type const &interpolation_domain, std::optional< std::size_t > cols_per_chunk=std::nullopt, std::optional< unsigned int > preconditioner_max_block_size=std::nullopt)
Build a SplineBuilder2D acting on interpolation_domain.
ddc::DiscreteDomain< bsplines_type1, bsplines_type2 > spline_domain() const noexcept
Get the 2D domain on which spline coefficients are defined.
SplineBuilder2D(SplineBuilder2D const &x)=delete
Copy-constructor is deleted.
BatchedInterpolationDDom batched_interpolation_domain(BatchedInterpolationDDom const &batched_interpolation_domain) const noexcept
Get the whole domain representing interpolation points.
SplineBuilder2D & operator=(SplineBuilder2D &&x)=default
Move-assigns.
A class for creating a 3D spline approximation of a function.
BatchedInterpolationDDom batched_interpolation_domain(BatchedInterpolationDDom const &batched_interpolation_domain) const noexcept
Get the whole domain representing interpolation points.
SplineBuilder3D(interpolation_domain_type const &interpolation_domain, std::optional< std::size_t > cols_per_chunk=std::nullopt, std::optional< unsigned int > preconditioner_max_block_size=std::nullopt)
Build a SplineBuilder3D acting on interpolation_domain.
SplineBuilder3D(std::string label, BatchedInterpolationDDom const &batched_interpolation_domain, std::optional< std::size_t > cols_per_chunk=std::nullopt, std::optional< unsigned int > preconditioner_max_block_size=std::nullopt)
Build a SplineBuilder3D acting on the interpolation domain contained in batched_interpolation_domain.
SplineBuilder3D & operator=(SplineBuilder3D &&x)=default
Move-assigns.
batched_spline_domain_type< BatchedInterpolationDDom > batched_spline_domain(BatchedInterpolationDDom const &batched_interpolation_domain) const noexcept
Get the whole domain on which spline coefficients are defined.
ddc::DiscreteDomain< bsplines_type1, bsplines_type2, bsplines_type3 > spline_domain() const noexcept
Get the 3D domain on which spline coefficients are defined.
batch_domain_type< BatchedInterpolationDDom > batch_domain(BatchedInterpolationDDom const &batched_interpolation_domain) const noexcept
Get the batch domain.
interpolation_domain_type interpolation_domain() const noexcept
Get the domain for the 3D interpolation mesh used by this class.
~SplineBuilder3D()=default
Destructs.
SplineBuilder3D & operator=(SplineBuilder3D const &x)=delete
Copy-assignment is deleted.
SplineBuilder3D(BatchedInterpolationDDom const &batched_interpolation_domain, std::optional< std::size_t > cols_per_chunk=std::nullopt, std::optional< unsigned int > preconditioner_max_block_size=std::nullopt)
Build a SplineBuilder3D acting on the interpolation domain contained in batched_interpolation_domain.
void operator()(ddc::ChunkSpan< Real, batched_spline_domain_type< BatchedInterpolationDDom >, Layout, memory_space > spline, ddc::ChunkSpan< Real const, BatchedInterpolationDDom, Layout, memory_space > vals, std::optional< ddc::ChunkSpan< Real const, batched_derivs_domain_type1< BatchedInterpolationDDom >, Layout, memory_space > > derivs_min1=std::nullopt, std::optional< ddc::ChunkSpan< Real const, batched_derivs_domain_type1< BatchedInterpolationDDom >, Layout, memory_space > > derivs_max1=std::nullopt, std::optional< ddc::ChunkSpan< Real const, batched_derivs_domain_type2< BatchedInterpolationDDom >, Layout, memory_space > > derivs_min2=std::nullopt, std::optional< ddc::ChunkSpan< Real const, batched_derivs_domain_type2< BatchedInterpolationDDom >, Layout, memory_space > > derivs_max2=std::nullopt, std::optional< ddc::ChunkSpan< Real const, batched_derivs_domain_type3< BatchedInterpolationDDom >, Layout, memory_space > > derivs_min3=std::nullopt, std::optional< ddc::ChunkSpan< Real const, batched_derivs_domain_type3< BatchedInterpolationDDom >, Layout, memory_space > > derivs_max3=std::nullopt, std::optional< ddc::ChunkSpan< Real const, batched_derivs_domain_type1_2< BatchedInterpolationDDom >, Layout, memory_space > > mixed_derivs_min1_min2=std::nullopt, std::optional< ddc::ChunkSpan< Real const, batched_derivs_domain_type1_2< BatchedInterpolationDDom >, Layout, memory_space > > mixed_derivs_max1_min2=std::nullopt, std::optional< ddc::ChunkSpan< Real const, batched_derivs_domain_type1_2< BatchedInterpolationDDom >, Layout, memory_space > > mixed_derivs_min1_max2=std::nullopt, std::optional< ddc::ChunkSpan< Real const, batched_derivs_domain_type1_2< BatchedInterpolationDDom >, Layout, memory_space > > mixed_derivs_max1_max2=std::nullopt, std::optional< ddc::ChunkSpan< Real const, batched_derivs_domain_type2_3< BatchedInterpolationDDom >, Layout, memory_space > > mixed_derivs_min2_min3=std::nullopt, std::optional< ddc::ChunkSpan< Real const, batched_derivs_domain_type2_3< BatchedInterpolationDDom >, Layout, memory_space > > mixed_derivs_max2_min3=std::nullopt, std::optional< ddc::ChunkSpan< Real const, batched_derivs_domain_type2_3< BatchedInterpolationDDom >, Layout, memory_space > > mixed_derivs_min2_max3=std::nullopt, std::optional< ddc::ChunkSpan< Real const, batched_derivs_domain_type2_3< BatchedInterpolationDDom >, Layout, memory_space > > mixed_derivs_max2_max3=std::nullopt, std::optional< ddc::ChunkSpan< Real const, batched_derivs_domain_type1_3< BatchedInterpolationDDom >, Layout, memory_space > > mixed_derivs_min1_min3=std::nullopt, std::optional< ddc::ChunkSpan< Real const, batched_derivs_domain_type1_3< BatchedInterpolationDDom >, Layout, memory_space > > mixed_derivs_max1_min3=std::nullopt, std::optional< ddc::ChunkSpan< Real const, batched_derivs_domain_type1_3< BatchedInterpolationDDom >, Layout, memory_space > > mixed_derivs_min1_max3=std::nullopt, std::optional< ddc::ChunkSpan< Real const, batched_derivs_domain_type1_3< BatchedInterpolationDDom >, Layout, memory_space > > mixed_derivs_max1_max3=std::nullopt, std::optional< ddc::ChunkSpan< Real const, batched_derivs_domain_type< BatchedInterpolationDDom >, Layout, memory_space > > mixed_derivs_min1_min2_min3=std::nullopt, std::optional< ddc::ChunkSpan< Real const, batched_derivs_domain_type< BatchedInterpolationDDom >, Layout, memory_space > > mixed_derivs_max1_min2_min3=std::nullopt, std::optional< ddc::ChunkSpan< Real const, batched_derivs_domain_type< BatchedInterpolationDDom >, Layout, memory_space > > mixed_derivs_min1_max2_min3=std::nullopt, std::optional< ddc::ChunkSpan< Real const, batched_derivs_domain_type< BatchedInterpolationDDom >, Layout, memory_space > > mixed_derivs_max1_max2_min3=std::nullopt, std::optional< ddc::ChunkSpan< Real const, batched_derivs_domain_type< BatchedInterpolationDDom >, Layout, memory_space > > mixed_derivs_min1_min2_max3=std::nullopt, std::optional< ddc::ChunkSpan< Real const, batched_derivs_domain_type< BatchedInterpolationDDom >, Layout, memory_space > > mixed_derivs_max1_min2_max3=std::nullopt, std::optional< ddc::ChunkSpan< Real const, batched_derivs_domain_type< BatchedInterpolationDDom >, Layout, memory_space > > mixed_derivs_min1_max2_max3=std::nullopt, std::optional< ddc::ChunkSpan< Real const, batched_derivs_domain_type< BatchedInterpolationDDom >, Layout, memory_space > > mixed_derivs_max1_max2_max3=std::nullopt) const
Compute a 3D spline approximation of a function.
SplineBuilder3D(std::string label, interpolation_domain_type const &interpolation_domain, std::optional< std::size_t > cols_per_chunk=std::nullopt, std::optional< unsigned int > preconditioner_max_block_size=std::nullopt)
Build a SplineBuilder3D acting on interpolation_domain.
SplineBuilder3D(SplineBuilder3D const &x)=delete
Copy-constructor is deleted.
SplineBuilder3D(SplineBuilder3D &&x)=default
Move-constructs.
A class for creating a spline approximation of a function.
std::tuple< ddc::Chunk< Real, ddc::DiscreteDomain< ddc::Deriv< typename InterpolationDDim::continuous_dimension_type > >, ddc::KokkosAllocator< Real, OutMemorySpace > >, ddc::Chunk< Real, ddc::DiscreteDomain< InterpolationDDim >, ddc::KokkosAllocator< Real, OutMemorySpace > >, ddc::Chunk< Real, ddc::DiscreteDomain< ddc::Deriv< typename InterpolationDDim::continuous_dimension_type > >, ddc::KokkosAllocator< Real, OutMemorySpace > > > quadrature_coefficients() const
Compute the quadrature coefficients associated to the b-splines used by this SplineBuilder.
ddc::DiscreteDomain< bsplines_type > spline_domain() const noexcept
Get the 1D domain on which spline coefficients are defined.
SplineBuilder(BatchedInterpolationDDom const &batched_interpolation_domain, std::optional< std::size_t > cols_per_chunk=std::nullopt, std::optional< unsigned int > preconditioner_max_block_size=std::nullopt)
Build a SplineBuilder acting on the interpolation domain contained by batched_interpolation_domain.
SplineBuilder(SplineBuilder const &x)=delete
Copy-constructor is deleted.
interpolation_domain_type interpolation_domain() const noexcept
Get the domain for the 1D interpolation mesh used by this class.
batched_derivs_domain_type< BatchedInterpolationDDom > batched_derivs_xmax_domain(BatchedInterpolationDDom const &batched_interpolation_domain) const noexcept
Get the whole domain on which derivatives on upper boundary are defined.
static constexpr int s_nbe_xmin
The number of equations defining the closure relation at the lower bound.
static constexpr ddc::SplineBuilderClosure s_sbc_xmin
The closure relation implemented at the lower bound.
SplineBuilder(std::string label, BatchedInterpolationDDom const &batched_interpolation_domain, std::optional< std::size_t > cols_per_chunk=std::nullopt, std::optional< unsigned int > preconditioner_max_block_size=std::nullopt)
Build a SplineBuilder acting on the interpolation domain contained by batched_interpolation_domain.
batch_domain_type< BatchedInterpolationDDom > batch_domain(BatchedInterpolationDDom const &batched_interpolation_domain) const noexcept
Get the batch domain.
SplineBuilder & operator=(SplineBuilder &&x)=default
Move-assigns.
static constexpr int s_nbe_xmax
The number of equations defining the closure relation at the upper bound.
static constexpr SplineSolver s_spline_solver
The SplineSolver giving the backend used to perform the spline approximation.
static constexpr ddc::SplineBuilderClosure s_sbc_xmax
The closure relation implemented at the upper bound.
BatchedInterpolationDDom batched_interpolation_domain(BatchedInterpolationDDom const &batched_interpolation_domain) const noexcept
Get the whole domain representing interpolation points.
batched_spline_domain_type< BatchedInterpolationDDom > batched_spline_domain(BatchedInterpolationDDom const &batched_interpolation_domain) const noexcept
Get the whole domain on which spline coefficients are defined.
SplineBuilder(interpolation_domain_type const &interpolation_domain, std::optional< std::size_t > cols_per_chunk=std::nullopt, std::optional< unsigned int > preconditioner_max_block_size=std::nullopt)
Build a SplineBuilder acting on interpolation_domain.
static constexpr bool s_odd
Indicates if the degree of the splines is odd or even.
void operator()(ddc::ChunkSpan< Real, batched_spline_domain_type< BatchedInterpolationDDom >, Layout, memory_space > spline, ddc::ChunkSpan< Real const, BatchedInterpolationDDom, Layout, memory_space > vals, std::optional< ddc::ChunkSpan< Real const, batched_derivs_domain_type< BatchedInterpolationDDom >, Layout, memory_space > > derivs_xmin=std::nullopt, std::optional< ddc::ChunkSpan< Real const, batched_derivs_domain_type< BatchedInterpolationDDom >, Layout, memory_space > > derivs_xmax=std::nullopt) const
Compute a spline approximation of a function.
batched_derivs_domain_type< BatchedInterpolationDDom > batched_derivs_xmin_domain(BatchedInterpolationDDom const &batched_interpolation_domain) const noexcept
Get the whole domain on which derivatives on lower boundary are defined.
SplineBuilder(std::string label, interpolation_domain_type const &interpolation_domain, std::optional< std::size_t > cols_per_chunk=std::nullopt, std::optional< unsigned int > preconditioner_max_block_size=std::nullopt)
Build a SplineBuilder acting on interpolation_domain.
SplineBuilder(SplineBuilder &&x)=default
Move-constructs.
static constexpr int s_nbv_xmax
The number of input values defining the closure relation at the upper bound.
~SplineBuilder()=default
Destructs.
static constexpr int s_nbv_xmin
The number of input values defining the closure relation at the lower bound.
SplineBuilder & operator=(SplineBuilder const &x)=delete
Copy-assignment is deleted.
A class to evaluate, differentiate or integrate a spline function.
void deriv(DElem const &deriv_order, ddc::ChunkSpan< Real, BatchedInterpolationDDom, Layout1, memory_space > const spline_eval, ddc::ChunkSpan< ddc::Coordinate< CoordsDims... > const, BatchedInterpolationDDom, Layout2, memory_space > const coords_eval, ddc::ChunkSpan< Real const, batched_spline_domain_type< BatchedInterpolationDDom >, Layout3, memory_space > const spline_coef) const
Differentiate 1D spline function (described by its spline coefficients) on a mesh.
void operator()(ddc::ChunkSpan< Real, BatchedInterpolationDDom, Layout1, memory_space > const spline_eval, ddc::ChunkSpan< Real const, batched_spline_domain_type< BatchedInterpolationDDom >, Layout2, memory_space > const spline_coef) const
Evaluate a spline function (described by its spline coefficients) on a mesh.
upper_extrapolation_rule_type upper_extrapolation_rule() const
Get the upper extrapolation rule.
SplineEvaluator & operator=(SplineEvaluator const &x)=default
Copy-assigns.
void deriv(DElem const &deriv_order, ddc::ChunkSpan< Real, BatchedInterpolationDDom, Layout1, memory_space > const spline_eval, ddc::ChunkSpan< Real const, batched_spline_domain_type< BatchedInterpolationDDom >, Layout2, memory_space > const spline_coef) const
Differentiate 1D spline function (described by its spline coefficients) on a mesh.
SplineEvaluator & operator=(SplineEvaluator &&x)=default
Move-assigns.
void operator()(ddc::ChunkSpan< Real, BatchedInterpolationDDom, Layout1, memory_space > const spline_eval, ddc::ChunkSpan< ddc::Coordinate< CoordsDims... > const, BatchedInterpolationDDom, Layout2, memory_space > const coords_eval, ddc::ChunkSpan< Real const, batched_spline_domain_type< BatchedInterpolationDDom >, Layout3, memory_space > const spline_coef) const
Evaluate spline function (described by its spline coefficients) on a mesh.
KOKKOS_FUNCTION Real operator()(ddc::Coordinate< CoordsDims... > const &coord_eval, ddc::ChunkSpan< Real const, spline_domain_type, Layout, memory_space > const spline_coef) const
Evaluate 1D spline function (described by its spline coefficients) at a given coordinate.
SplineEvaluator(LowerExtrapolationRule const &lower_extrap_rule, UpperExtrapolationRule const &upper_extrap_rule)
Build a SplineEvaluator acting on batched_spline_domain.
lower_extrapolation_rule_type lower_extrapolation_rule() const
Get the lower extrapolation rule.
SplineEvaluator(SplineEvaluator const &x)=default
Copy-constructs.
SplineEvaluator(SplineEvaluator &&x)=default
Move-constructs.
KOKKOS_FUNCTION Real deriv(DElem const &deriv_order, ddc::Coordinate< CoordsDims... > const &coord_eval, ddc::ChunkSpan< Real const, spline_domain_type, Layout, memory_space > const spline_coef) const
Differentiate 1D spline function (described by its spline coefficients) at a given coordinate.
void integrate(ddc::ChunkSpan< Real, BatchedDDom, Layout1, memory_space > const integrals, ddc::ChunkSpan< Real const, BatchedSplineDDom, Layout2, memory_space > const spline_coef) const
Perform batched 1D integrations of a spline function (described by its spline coefficients) along the...
~SplineEvaluator()=default
Destructs.
Storage class of the static attributes of the discrete dimension.
KOKKOS_INLINE_FUNCTION std::size_t ncells() const noexcept
Returns the number of cells over which the B-splines are defined.
KOKKOS_INLINE_FUNCTION Real length() const noexcept
Returns the length of the domain.
KOKKOS_INLINE_FUNCTION ddc::Coordinate< CDim > rmin() const noexcept
Returns the coordinate of the lower bound of the domain on which the B-splines are defined.
Impl(Impl const &x)=default
Copy-constructs.
KOKKOS_INLINE_FUNCTION discrete_domain_type full_domain() const
Returns the discrete domain including eventual additional B-splines in the periodic case.
KOKKOS_INLINE_FUNCTION discrete_element_type eval_deriv(Kokkos::mdspan< double, Kokkos::dextents< std::size_t, 1 > > derivs, ddc::Coordinate< CDim > const &x) const
Evaluates non-zero B-spline derivatives at a given coordinate.
~Impl()=default
Destructs.
Impl(Impl< DDim, OriginMemorySpace > const &impl)
Copy-constructs from another Impl with a different Kokkos memory space.
KOKKOS_INLINE_FUNCTION discrete_element_type eval_basis_and_n_derivs(Kokkos::mdspan< double, Kokkos::dextents< std::size_t, 2 > > derivs, ddc::Coordinate< CDim > const &x, std::size_t n) const
Evaluates non-zero B-spline values and derivatives at a given coordinate.
Impl & operator=(Impl &&x)=default
Move-assigns.
KOKKOS_INLINE_FUNCTION ddc::Coordinate< CDim > rmax() const noexcept
Returns the coordinate of the upper bound of the domain on which the B-splines are defined.
KOKKOS_INLINE_FUNCTION ddc::DiscreteElement< knot_discrete_dimension_type > get_last_support_knot(discrete_element_type const &ix) const
Returns the coordinate of the last support knot associated to a DiscreteElement identifying a B-splin...
KOKKOS_INLINE_FUNCTION ddc::DiscreteDomain< knot_discrete_dimension_type > break_point_domain() const
Returns the discrete domain which describes the break points.
KOKKOS_INLINE_FUNCTION discrete_element_type eval_basis(Kokkos::mdspan< double, Kokkos::dextents< std::size_t, 1 > > values, ddc::Coordinate< CDim > const &x) const
Evaluates non-zero B-splines at a given coordinate.
KOKKOS_INLINE_FUNCTION ddc::DiscreteElement< knot_discrete_dimension_type > get_first_support_knot(discrete_element_type const &ix) const
Returns the coordinate of the first support knot associated to a DiscreteElement identifying a B-spli...
KOKKOS_INLINE_FUNCTION std::size_t nbasis() const noexcept
Returns the number of basis functions.
Impl & operator=(Impl const &x)=default
Copy-assigns.
KOKKOS_INLINE_FUNCTION std::size_t size() const noexcept
Returns the number of elements necessary to construct a spline representation of a function.
Impl(Impl &&x)=default
Move-constructs.
Impl(ddc::Coordinate< CDim > rmin, ddc::Coordinate< CDim > rmax, std::size_t ncells)
Constructs a spline basis (B-splines) with n equidistant knots over .
The type of a uniform 1D spline basis (B-spline).
static constexpr bool is_uniform() noexcept
Indicates if the B-splines are uniform or not (this is the case here).
static constexpr std::size_t degree() noexcept
The degree of B-splines.
static constexpr bool is_periodic() noexcept
Indicates if the B-splines are periodic or not.
UniformPointSampling models a uniform discretization of the provided continuous dimension.
The top-level namespace of DDC.
constexpr bool is_uniform_bsplines_v
Indicates if a tag corresponds to uniform B-splines or not.
SplineSolver
An enum determining the backend solver of a SplineBuilder or SplineBuilder2d.
@ LAPACK
Enum member to identify the LAPACK-based solver (direct method)
@ GINKGO
Enum member to identify the Ginkgo-based solver (iterative method)
constexpr int n_boundary_equations(ddc::SplineBuilderClosure const sbc, std::size_t const degree)
Return the number of equations needed to describe a given closure relation.
ddc::ChunkSpan< Real, ddc::DiscreteDomain< DDim >, Layout, MemorySpace > integrals(ExecSpace const &execution_space, ddc::ChunkSpan< Real, ddc::DiscreteDomain< DDim >, Layout, MemorySpace > int_vals)
Compute the integrals of the B-splines.
constexpr bool is_non_uniform_bsplines_v
Indicates if a tag corresponds to non-uniform B-splines or not.
SplineBuilderClosure
An enum representing a spline closure relation.
@ HOMOGENEOUS_HERMITE
Homogeneous Hermite closure relation (derivatives are 0)
@ GREVILLE
Use Greville points instead of conditions on derivative for B-Spline interpolation.
@ HERMITE
Hermite closure relation.
@ PERIODIC
Periodic closure relation u(1)=u(n)
If the type DDim is a B-spline, defines type to the discrete dimension of the associated knots.
A compile-time sequence of types.
Definition type_seq.hpp:30
A functor for describing a spline boundary value by a constant extrapolation for 2D evaluator.
KOKKOS_FUNCTION Real operator()(CoordType coord_extrap, ddc::ChunkSpan< Real 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.
A templated struct representing a discrete dimension storing the derivatives of a function along a co...
Definition deriv.hpp:17
A functor describing a null extrapolation boundary value for 1D spline evaluator.
KOKKOS_FUNCTION Real operator()(CoordType, ChunkSpan) const
Evaluates the spline at a coordinate outside of the domain.
A functor to represent periodic extrapolation in a 1D spline evaluator.
KOKKOS_FUNCTION Real operator()(CoordType, ChunkSpan) const
This function should never be called.