DDC 0.16.0
Loading...
Searching...
No Matches
spline_evaluator_2d.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 2D spline function.
23 *
24 * A class which contains an operator () which can be used to evaluate, differentiate or integrate a 2D 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 BSplines1 The discrete dimension representing the B-splines along the first dimension of interest.
29 * @tparam BSplines2 The discrete dimension representing the B-splines along the second dimension of interest.
30 * @tparam EvaluationDDim1 The first discrete dimension on which evaluation points are defined.
31 * @tparam EvaluationDDim2 The second discrete dimension on which evaluation points are defined.
32 * @tparam LowerExtrapolationRule1 The lower extrapolation rule type along first dimension of interest.
33 * @tparam UpperExtrapolationRule1 The upper extrapolation rule type along first dimension of interest.
34 * @tparam LowerExtrapolationRule2 The lower extrapolation rule type along second dimension of interest.
35 * @tparam UpperExtrapolationRule2 The upper extrapolation rule type along second dimension of interest.
36 */
37template <
38 class ExecSpace,
39 class MemorySpace,
40 class BSplines1,
41 class BSplines2,
42 class EvaluationDDim1,
43 class EvaluationDDim2,
44 class LowerExtrapolationRule1,
45 class UpperExtrapolationRule1,
46 class LowerExtrapolationRule2,
47 class UpperExtrapolationRule2>
49{
50public:
51 /// @brief The type of the first evaluation continuous dimension used by this class.
52 using continuous_dimension_type1 = BSplines1::continuous_dimension_type;
53
54 /// @brief The type of the second evaluation continuous dimension used by this class.
55 using continuous_dimension_type2 = BSplines2::continuous_dimension_type;
56
57 /// @brief The type of the Kokkos execution space used by this class.
58 using exec_space = ExecSpace;
59
60 /// @brief The type of the Kokkos memory space used by this class.
61 using memory_space = MemorySpace;
62
63 /// @brief The type of the first discrete dimension of interest used by this class.
64 using evaluation_discrete_dimension_type1 = EvaluationDDim1;
65
66 /// @brief The type of the second discrete dimension of interest used by this class.
67 using evaluation_discrete_dimension_type2 = EvaluationDDim2;
68
69 /// @brief The discrete dimension representing the B-splines along first dimension.
70 using bsplines_type1 = BSplines1;
71
72 /// @brief The discrete dimension representing the B-splines along second dimension.
73 using bsplines_type2 = BSplines2;
74
75 /// @brief The type of the domain for the 1D evaluation mesh along first dimension used by this class.
76 using evaluation_domain_type1 = ddc::DiscreteDomain<evaluation_discrete_dimension_type1>;
77
78 /// @brief The type of the domain for the 1D evaluation mesh along second dimension used by this class.
79 using evaluation_domain_type2 = ddc::DiscreteDomain<evaluation_discrete_dimension_type2>;
80
81 /// @brief The type of the domain for the 2D evaluation mesh used by this class.
82 using evaluation_domain_type = ddc::DiscreteDomain<
83 evaluation_discrete_dimension_type1,
84 evaluation_discrete_dimension_type2>;
85
86 /**
87 * @brief The type of the whole domain representing evaluation points.
88 *
89 * @tparam The batched discrete domain on which the interpolation points are defined.
90 */
91 template <concepts::discrete_domain BatchedInterpolationDDom>
92 using batched_evaluation_domain_type = BatchedInterpolationDDom;
93
94 /// @brief The type of the 1D spline domain corresponding to the first dimension of interest.
95 using spline_domain_type1 = ddc::DiscreteDomain<bsplines_type1>;
96
97 /// @brief The type of the 1D spline domain corresponding to the second dimension of interest.
98 using spline_domain_type2 = ddc::DiscreteDomain<bsplines_type2>;
99
100 /// @brief The type of the 2D spline domain corresponding to the dimensions of interest.
101 using spline_domain_type = ddc::DiscreteDomain<bsplines_type1, bsplines_type2>;
102
103 /**
104 * @brief The type of the batch domain (obtained by removing the dimensions of interest
105 * from the whole domain).
106 *
107 * @tparam The batched discrete domain on which the interpolation points are defined.
108 */
109 template <concepts::discrete_domain BatchedInterpolationDDom>
110 using batch_domain_type = ddc::remove_dims_of_t<
111 BatchedInterpolationDDom,
112 evaluation_discrete_dimension_type1,
113 evaluation_discrete_dimension_type2>;
114
115 /**
116 * @brief The type of the whole spline domain (cartesian product of 2D spline domain
117 * and batch domain) preserving the underlying memory layout (order of dimensions).
118 *
119 * @tparam The batched discrete domain on which the interpolation points are defined.
120 */
121 template <concepts::discrete_domain BatchedInterpolationDDom>
122 using batched_spline_domain_type
123 = ddc::detail::convert_type_seq_to_discrete_domain_t<ddc::type_seq_replace_t<
124 ddc::to_type_seq_t<BatchedInterpolationDDom>,
125 ddc::TypeSeq<
126 evaluation_discrete_dimension_type1,
127 evaluation_discrete_dimension_type2>,
128 ddc::TypeSeq<bsplines_type1, bsplines_type2>>>;
129
130 /// @brief The type of the extrapolation rule at the lower boundary along the first dimension.
131 using lower_extrapolation_rule_1_type = LowerExtrapolationRule1;
132
133 /// @brief The type of the extrapolation rule at the upper boundary along the first dimension.
134 using upper_extrapolation_rule_1_type = UpperExtrapolationRule1;
135
136 /// @brief The type of the extrapolation rule at the lower boundary along the second dimension.
137 using lower_extrapolation_rule_2_type = LowerExtrapolationRule2;
138
139 /// @brief The type of the extrapolation rule at the upper boundary along the second dimension.
140 using upper_extrapolation_rule_2_type = UpperExtrapolationRule2;
141
142private:
143 LowerExtrapolationRule1 m_lower_extrap_rule_1;
144
145 UpperExtrapolationRule1 m_upper_extrap_rule_1;
146
147 LowerExtrapolationRule2 m_lower_extrap_rule_2;
148
149 UpperExtrapolationRule2 m_upper_extrap_rule_2;
150
151public:
152 static_assert(
153 std::is_same_v<LowerExtrapolationRule1,
154 typename ddc::PeriodicExtrapolationRule<continuous_dimension_type1>>
155 == bsplines_type1::is_periodic()
156 && std::is_same_v<
157 UpperExtrapolationRule1,
158 typename ddc::PeriodicExtrapolationRule<continuous_dimension_type1>>
159 == bsplines_type1::is_periodic()
160 && std::is_same_v<
161 LowerExtrapolationRule2,
162 typename ddc::PeriodicExtrapolationRule<continuous_dimension_type2>>
163 == bsplines_type2::is_periodic()
164 && std::is_same_v<
165 UpperExtrapolationRule2,
166 typename ddc::PeriodicExtrapolationRule<continuous_dimension_type2>>
167 == bsplines_type2::is_periodic(),
168 "PeriodicExtrapolationRule has to be used if and only if dimension is periodic");
169 static_assert(
170 std::is_invocable_r_v<
171 Real,
172 LowerExtrapolationRule1,
173 ddc::Coordinate<continuous_dimension_type1>,
174 ddc::ChunkSpan<
175 Real const,
176 spline_domain_type,
177 Kokkos::layout_right,
178 memory_space>>,
179 "LowerExtrapolationRule1::operator() has to be callable "
180 "with usual arguments.");
181 static_assert(
182 std::is_invocable_r_v<
183 Real,
184 UpperExtrapolationRule1,
185 ddc::Coordinate<continuous_dimension_type1>,
186 ddc::ChunkSpan<
187 Real const,
188 spline_domain_type,
189 Kokkos::layout_right,
190 memory_space>>,
191 "UpperExtrapolationRule1::operator() has to be callable "
192 "with usual arguments.");
193 static_assert(
194 std::is_invocable_r_v<
195 Real,
196 LowerExtrapolationRule2,
197 ddc::Coordinate<continuous_dimension_type2>,
198 ddc::ChunkSpan<
199 Real const,
200 spline_domain_type,
201 Kokkos::layout_right,
202 memory_space>>,
203 "LowerExtrapolationRule2::operator() has to be callable "
204 "with usual arguments.");
205 static_assert(
206 std::is_invocable_r_v<
207 Real,
208 UpperExtrapolationRule2,
209 ddc::Coordinate<continuous_dimension_type2>,
210 ddc::ChunkSpan<
211 Real const,
212 spline_domain_type,
213 Kokkos::layout_right,
214 memory_space>>,
215 "UpperExtrapolationRule2::operator() has to be callable "
216 "with usual arguments.");
217
218 /**
219 * @brief Build a SplineEvaluator2D acting on batched_spline_domain.
220 *
221 * @param lower_extrap_rule1 The extrapolation rule at the lower boundary along the first dimension.
222 * @param upper_extrap_rule1 The extrapolation rule at the upper boundary along the first dimension.
223 * @param lower_extrap_rule2 The extrapolation rule at the lower boundary along the second dimension.
224 * @param upper_extrap_rule2 The extrapolation rule at the upper boundary along the second dimension.
225 *
226 * @see NullExtrapolationRule ConstantExtrapolationRule PeriodicExtrapolationRule
227 */
228 explicit SplineEvaluator2D(
229 LowerExtrapolationRule1 const& lower_extrap_rule1,
230 UpperExtrapolationRule1 const& upper_extrap_rule1,
231 LowerExtrapolationRule2 const& lower_extrap_rule2,
232 UpperExtrapolationRule2 const& upper_extrap_rule2)
233 : m_lower_extrap_rule_1(lower_extrap_rule1)
234 , m_upper_extrap_rule_1(upper_extrap_rule1)
235 , m_lower_extrap_rule_2(lower_extrap_rule2)
236 , m_upper_extrap_rule_2(upper_extrap_rule2)
237 {
238 }
239
240 /**
241 * @brief Copy-constructs.
242 *
243 * @param x A reference to another SplineEvaluator.
244 */
245 SplineEvaluator2D(SplineEvaluator2D const& x) = default;
246
247 /**
248 * @brief Move-constructs.
249 *
250 * @param x An rvalue to another SplineEvaluator.
251 */
253
254 /// @brief Destructs.
255 ~SplineEvaluator2D() = default;
256
257 /**
258 * @brief Copy-assigns.
259 *
260 * @param x A reference to another SplineEvaluator.
261 * @return A reference to this object.
262 */
263 SplineEvaluator2D& operator=(SplineEvaluator2D const& x) = default;
264
265 /**
266 * @brief Move-assigns.
267 *
268 * @param x An rvalue to another SplineEvaluator.
269 * @return A reference to this object.
270 */
272
273 /**
274 * @brief Get the lower extrapolation rule along the first dimension.
275 *
276 * 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.
277 *
278 * @return The lower extrapolation rule along the first dimension.
279 *
280 * @see NullExtrapolationRule ConstantExtrapolationRule PeriodicExtrapolationRule
281 */
282 lower_extrapolation_rule_1_type lower_extrapolation_rule_dim_1() const
283 {
284 return m_lower_extrap_rule_1;
285 }
286
287 /**
288 * @brief Get the upper extrapolation rule along the first dimension.
289 *
290 * 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.
291 *
292 * @return The upper extrapolation rule along the first dimension.
293 *
294 * @see NullExtrapolationRule ConstantExtrapolationRule PeriodicExtrapolationRule
295 */
296 upper_extrapolation_rule_1_type upper_extrapolation_rule_dim_1() const
297 {
298 return m_upper_extrap_rule_1;
299 }
300
301 /**
302 * @brief Get the lower extrapolation rule along the second dimension.
303 *
304 * 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.
305 *
306 * @return The lower extrapolation rule along the second dimension.
307 *
308 * @see NullExtrapolationRule ConstantExtrapolationRule PeriodicExtrapolationRule
309 */
310 lower_extrapolation_rule_2_type lower_extrapolation_rule_dim_2() const
311 {
312 return m_lower_extrap_rule_2;
313 }
314
315 /**
316 * @brief Get the upper extrapolation rule along the second dimension.
317 *
318 * 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.
319 *
320 * @return The upper extrapolation rule along the second dimension.
321 *
322 * @see NullExtrapolationRule ConstantExtrapolationRule PeriodicExtrapolationRule
323 */
324 upper_extrapolation_rule_2_type upper_extrapolation_rule_dim_2() const
325 {
326 return m_upper_extrap_rule_2;
327 }
328
329 /**
330 * @brief Evaluate 2D spline function (described by its spline coefficients) at a given coordinate.
331 *
332 * The spline coefficients represent a 2D spline function defined on a B-splines (basis splines). They can be obtained via various methods, such as using a SplineBuilder2D.
333 *
334 * Remark: calling SplineBuilder2D then SplineEvaluator2D corresponds to a 2D spline interpolation.
335 *
336 * @param coord_eval The coordinate where the spline is evaluated. Note that only the components along the dimensions of interest are used.
337 * @param spline_coef A ChunkSpan storing the 2D spline coefficients.
338 *
339 * @return The value of the spline function at the desired coordinate.
340 */
341 template <class Layout, class... CoordsDims>
342 KOKKOS_FUNCTION Real operator()(
343 ddc::Coordinate<CoordsDims...> const& coord_eval,
344 ddc::ChunkSpan<Real const, spline_domain_type, Layout, memory_space> const spline_coef)
345 const
346 {
347 return eval(coord_eval, spline_coef);
348 }
349
350 /**
351 * @brief Evaluate 2D spline function (described by its spline coefficients) on a mesh.
352 *
353 * The spline coefficients represent a 2D spline function defined on a cartesian product of batch_domain and B-splines
354 * (basis splines). They can be obtained via various methods, such as using a SplineBuilder2D.
355 *
356 * This is not a nD evaluation. This is a batched 2D evaluation. This means that for each slice of coordinates
357 * identified by a batch_domain_type::discrete_element_type, the evaluation is performed with the 2D set of
358 * spline coefficients identified by the same batch_domain_type::discrete_element_type.
359 *
360 * Remark: calling SplineBuilder2D then SplineEvaluator2D corresponds to a 2D spline interpolation.
361 *
362 * @param[out] spline_eval The values of the 2D spline function at the desired coordinates. For practical reasons those are
363 * stored in a ChunkSpan defined on a batched_evaluation_domain_type.
364 * @param[in] coords_eval The coordinates where the spline is evaluated. Those are
365 * stored in a ChunkSpan defined on a batched_evaluation_domain_type. Note that the coordinates of the
366 * points represented by this domain are unused and irrelevant (but the points themselves (DiscreteElement) are used to select
367 * the set of 2D spline coefficients retained to perform the evaluation).
368 * @param[in] spline_coef A ChunkSpan storing the 2D spline coefficients.
369 */
370 template <
371 class Layout1,
372 class Layout2,
373 class Layout3,
374 class BatchedInterpolationDDom,
375 class... CoordsDims>
376 void operator()(
377 ddc::ChunkSpan<Real, BatchedInterpolationDDom, Layout1, memory_space> const spline_eval,
378 ddc::ChunkSpan<
379 ddc::Coordinate<CoordsDims...> const,
380 BatchedInterpolationDDom,
381 Layout2,
382 memory_space> const coords_eval,
383 ddc::ChunkSpan<
384 Real const,
385 batched_spline_domain_type<BatchedInterpolationDDom>,
386 Layout3,
387 memory_space> const spline_coef) const
388 {
389 batch_domain_type<BatchedInterpolationDDom> const batch_domain(coords_eval.domain());
390 evaluation_domain_type1 const evaluation_domain1(spline_eval.domain());
391 evaluation_domain_type2 const evaluation_domain2(spline_eval.domain());
392 ddc::parallel_for_each(
393 "ddc_splines_evaluate_2d",
394 exec_space(),
395 batch_domain,
396 KOKKOS_CLASS_LAMBDA(
397 batch_domain_type<BatchedInterpolationDDom>::discrete_element_type const
398 j) {
399 auto const spline_eval_2D = spline_eval[j];
400 auto const coords_eval_2D = coords_eval[j];
401 auto const spline_coef_2D = spline_coef[j];
402 for (auto const i1 : evaluation_domain1) {
403 for (auto const i2 : evaluation_domain2) {
404 spline_eval_2D(i1, i2) = eval(coords_eval_2D(i1, i2), spline_coef_2D);
405 }
406 }
407 });
408 }
409
410 /**
411 * @brief Evaluate 2D spline function (described by its spline coefficients) on a mesh.
412 *
413 * The spline coefficients represent a 2D spline function defined on a cartesian product of batch_domain and B-splines
414 * (basis splines). They can be obtained via various methods, such as using a SplineBuilder2D.
415 *
416 * This is not a multidimensional evaluation. This is a batched 2D evaluation.
417 * This means that for each slice of spline_eval the evaluation is performed with
418 * the 2D set of spline coefficients identified by the same batch_domain_type::discrete_element_type.
419 *
420 * Remark: calling SplineBuilder2D then SplineEvaluator2D corresponds to a 2D spline interpolation.
421 *
422 * @param[out] spline_eval The values of the 2D spline function at their coordinates.
423 * @param[in] spline_coef A ChunkSpan storing the 2D spline coefficients.
424 */
425 template <class Layout1, class Layout2, class BatchedInterpolationDDom>
426 void operator()(
427 ddc::ChunkSpan<Real, BatchedInterpolationDDom, Layout1, memory_space> const spline_eval,
428 ddc::ChunkSpan<
429 Real const,
430 batched_spline_domain_type<BatchedInterpolationDDom>,
431 Layout2,
432 memory_space> const spline_coef) const
433 {
434 batch_domain_type<BatchedInterpolationDDom> const batch_domain(spline_eval.domain());
435 evaluation_domain_type1 const evaluation_domain1(spline_eval.domain());
436 evaluation_domain_type2 const evaluation_domain2(spline_eval.domain());
437 ddc::parallel_for_each(
438 "ddc_splines_evaluate_2d",
439 exec_space(),
440 batch_domain,
441 KOKKOS_CLASS_LAMBDA(
442 batch_domain_type<BatchedInterpolationDDom>::discrete_element_type const
443 j) {
444 auto const spline_eval_2D = spline_eval[j];
445 auto const spline_coef_2D = spline_coef[j];
446 for (auto const i1 : evaluation_domain1) {
447 for (auto const i2 : evaluation_domain2) {
448 ddc::Coordinate<continuous_dimension_type1, continuous_dimension_type2>
449 coord_eval_2D(ddc::coordinate(i1), ddc::coordinate(i2));
450 spline_eval_2D(i1, i2) = eval(coord_eval_2D, spline_coef_2D);
451 }
452 }
453 });
454 }
455
456 /**
457 * @brief Differentiate 2D spline function (described by its spline coefficients) at a given coordinate along the dimensions of interest.
458 *
459 * The spline coefficients represent a 2D spline function defined on a B-splines (basis splines). They can be
460 * obtained via various methods, such as using a SplineBuilder2D.
461 *
462 * @param deriv_order A DiscreteElement containing the orders of derivation for each of the dimensions of interest.
463 * If one of the dimensions is not present, its corresponding order of derivation is considered to be 0.
464 * @param coord_eval The coordinate where the spline is differentiated. Note that only the components along the dimensions of interest are used.
465 * @param spline_coef A ChunkSpan storing the 2D spline coefficients.
466 *
467 * @return The derivative of the spline function at the desired coordinate.
468 */
469 template <class DElem, class Layout, class... CoordsDims>
470 KOKKOS_FUNCTION Real
471 deriv(DElem const& deriv_order,
472 ddc::Coordinate<CoordsDims...> const& coord_eval,
473 ddc::ChunkSpan<Real const, spline_domain_type, Layout, memory_space> const spline_coef)
474 const
475 {
476 return eval_no_bc(deriv_order, coord_eval, spline_coef);
477 }
478
479 /**
480 * @brief Differentiate 2D spline function (described by its spline coefficients) on a mesh along the dimensions of interest.
481 *
482 * The spline coefficients represent a 2D spline function defined on a cartesian product of batch_domain and B-splines
483 * (basis splines). They can be obtained via various methods, such as using a SplineBuilder2D.
484 *
485 * This is not a nD differentiation. This is a batched 2D differentiation.
486 * This means that for each slice of coordinates identified by a batch_domain_type::discrete_element_type,
487 * the differentiation is performed with the 2D set of spline coefficients identified by the same batch_domain_type::discrete_element_type.
488 *
489 * @param[in] deriv_order A DiscreteElement containing the orders of derivation for each of the dimensions of interest.
490 * If one of the dimensions is not present, its corresponding order of derivation is considered to be 0.
491 * @param[out] spline_eval The derivatives of the 2D spline function at the desired coordinates. For practical reasons those are
492 * stored in a ChunkSpan defined on a batched_evaluation_domain_type. Note that the coordinates of the
493 * points represented by this domain are unused and irrelevant (but the points themselves (DiscreteElement) are used to select
494 * the set of 2D spline coefficients retained to perform the evaluation).
495 * @param[in] coords_eval The coordinates where the spline is differentiated. Those are
496 * stored in a ChunkSpan defined on a batched_evaluation_domain_type. Note that the coordinates of the
497 * points represented by this domain are unused and irrelevant (but the points themselves (DiscreteElement) are used to select
498 * the set of 2D spline coefficients retained to perform the evaluation).
499 * @param[in] spline_coef A ChunkSpan storing the 2D spline coefficients.
500 */
501 template <
502 class DElem,
503 class Layout1,
504 class Layout2,
505 class Layout3,
506 class BatchedInterpolationDDom,
507 class... CoordsDims>
508 void deriv(
509 DElem const& deriv_order,
510 ddc::ChunkSpan<Real, BatchedInterpolationDDom, Layout1, memory_space> const spline_eval,
511 ddc::ChunkSpan<
512 ddc::Coordinate<CoordsDims...> const,
513 BatchedInterpolationDDom,
514 Layout2,
515 memory_space> const coords_eval,
516 ddc::ChunkSpan<
517 Real const,
518 batched_spline_domain_type<BatchedInterpolationDDom>,
519 Layout3,
520 memory_space> const spline_coef) const
521 {
522 static_assert(is_discrete_element_v<DElem>);
523
524 batch_domain_type<BatchedInterpolationDDom> const batch_domain(coords_eval.domain());
525 evaluation_domain_type1 const evaluation_domain1(spline_eval.domain());
526 evaluation_domain_type2 const evaluation_domain2(spline_eval.domain());
527 ddc::parallel_for_each(
528 "ddc_splines_differentiate_2d",
529 exec_space(),
530 batch_domain,
531 KOKKOS_CLASS_LAMBDA(
532 batch_domain_type<BatchedInterpolationDDom>::discrete_element_type const
533 j) {
534 auto const spline_eval_2D = spline_eval[j];
535 auto const coords_eval_2D = coords_eval[j];
536 auto const spline_coef_2D = spline_coef[j];
537 for (auto const i1 : evaluation_domain1) {
538 for (auto const i2 : evaluation_domain2) {
539 spline_eval_2D(i1, i2) = eval_no_bc(
540 deriv_order,
541 coords_eval_2D(i1, i2),
542 spline_coef_2D);
543 }
544 }
545 });
546 }
547
548 /**
549 * @brief Differentiate 2D spline function (described by its spline coefficients) on a mesh along the dimensions of interest.
550 *
551 * The spline coefficients represent a 2D spline function defined on a cartesian product of batch_domain and B-splines
552 * (basis splines). They can be obtained via various methods, such as using a SplineBuilder2D.
553 *
554 * This is not a multidimensional differentiation. This is a batched 2D differentiation.
555 * This means that for each slice of spline_eval the differentiation is performed with
556 * the 2D set of spline coefficients identified by the same batch_domain_type::discrete_element_type.
557 *
558 * @param[in] deriv_order A DiscreteElement containing the orders of derivation for each of the dimensions of interest.
559 * If one of the dimensions is not present, its corresponding order of derivation is considered to be 0.
560 * @param[out] spline_eval The derivatives of the 2D spline function at the desired coordinates.
561 * @param[in] spline_coef A ChunkSpan storing the 2D spline coefficients.
562 */
563 template <class DElem, class Layout1, class Layout2, class BatchedInterpolationDDom>
564 void deriv(
565 DElem const& deriv_order,
566 ddc::ChunkSpan<Real, BatchedInterpolationDDom, Layout1, memory_space> const spline_eval,
567 ddc::ChunkSpan<
568 Real const,
569 batched_spline_domain_type<BatchedInterpolationDDom>,
570 Layout2,
571 memory_space> const spline_coef) const
572 {
573 static_assert(is_discrete_element_v<DElem>);
574
575 batch_domain_type<BatchedInterpolationDDom> const batch_domain(spline_eval.domain());
576 evaluation_domain_type1 const evaluation_domain1(spline_eval.domain());
577 evaluation_domain_type2 const evaluation_domain2(spline_eval.domain());
578 ddc::parallel_for_each(
579 "ddc_splines_differentiate_2d",
580 exec_space(),
581 batch_domain,
582 KOKKOS_CLASS_LAMBDA(
583 batch_domain_type<BatchedInterpolationDDom>::discrete_element_type const
584 j) {
585 auto const spline_eval_2D = spline_eval[j];
586 auto const spline_coef_2D = spline_coef[j];
587 for (auto const i1 : evaluation_domain1) {
588 for (auto const i2 : evaluation_domain2) {
589 ddc::Coordinate<continuous_dimension_type1, continuous_dimension_type2>
590 coord_eval_2D(ddc::coordinate(i1), ddc::coordinate(i2));
591 spline_eval_2D(i1, i2)
592 = eval_no_bc(deriv_order, coord_eval_2D, spline_coef_2D);
593 }
594 }
595 });
596 }
597
598 /** @brief Perform batched 2D integrations of a spline function (described by its spline coefficients) along the dimensions of interest and store results on a subdomain of batch_domain.
599 *
600 * The spline coefficients represent a 2D spline function defined on a B-splines (basis splines). They can be obtained via various methods, such as using a SplineBuilder2D.
601 *
602 * This is not a nD integration. This is a batched 2D integration.
603 * This means that for each element of integrals, the integration is performed with the 2D set of
604 * spline coefficients identified by the same DiscreteElement.
605 *
606 * @param[out] integrals The integrals of the 2D spline function on the subdomain of batch_domain. For practical reasons those are
607 * stored in a ChunkSpan defined on a batch_domain_type. Note that the coordinates of the
608 * points represented by this domain are unused and irrelevant.
609 * @param[in] spline_coef A ChunkSpan storing the 2D spline coefficients.
610 */
611 template <class Layout1, class Layout2, class BatchedDDom, class BatchedSplineDDom>
612 void integrate(
613 ddc::ChunkSpan<Real, BatchedDDom, Layout1, memory_space> const integrals,
614 ddc::ChunkSpan<Real const, BatchedSplineDDom, Layout2, memory_space> const spline_coef)
615 const
616 {
617 static_assert(
618 ddc::type_seq_contains_v<
619 ddc::TypeSeq<bsplines_type1, bsplines_type2>,
620 to_type_seq_t<BatchedSplineDDom>>,
621 "The spline coefficients domain must contain the bsplines dimensions");
622 using batch_domain_type
623 = ddc::remove_dims_of_t<BatchedSplineDDom, bsplines_type1, bsplines_type2>;
624 static_assert(
625 std::is_same_v<batch_domain_type, BatchedDDom>,
626 "The integrals domain must only contain the batch dimensions");
627
628 batch_domain_type batch_domain(integrals.domain());
629 ddc::Chunk values1_alloc(
630 "values1 (ddc::SplineEvaluator2D::integrate)",
631 ddc::DiscreteDomain<bsplines_type1>(spline_coef.domain()),
632 ddc::KokkosAllocator<Real, memory_space>());
633 ddc::ChunkSpan values1 = values1_alloc.span_view();
634 ddc::integrals(exec_space(), values1);
635 ddc::Chunk values2_alloc(
636 "values2 (ddc::SplineEvaluator2D::integrate)",
637 ddc::DiscreteDomain<bsplines_type2>(spline_coef.domain()),
638 ddc::KokkosAllocator<Real, memory_space>());
639 ddc::ChunkSpan values2 = values2_alloc.span_view();
640 ddc::integrals(exec_space(), values2);
641
642 ddc::parallel_for_each(
643 "ddc_splines_integrate_bsplines",
644 exec_space(),
645 batch_domain,
646 KOKKOS_LAMBDA(batch_domain_type::discrete_element_type const j) {
647 integrals(j) = 0;
648 for (typename spline_domain_type1::discrete_element_type const i1 :
649 values1.domain()) {
650 for (typename spline_domain_type2::discrete_element_type const i2 :
651 values2.domain()) {
652 integrals(j) += spline_coef(i1, i2, j) * values1(i1) * values2(i2);
653 }
654 }
655 });
656 }
657
658private:
659 /**
660 * @brief Evaluate the function on B-splines at the coordinate given.
661 *
662 * This function firstly deals with the boundary conditions and calls the SplineEvaluator2D::eval_no_bc function
663 * to evaluate.
664 *
665 * @param[in] coord_eval The 2D coordinate where we want to evaluate.
666 * @param[in] spline_coef The B-splines coefficients of the function we want to evaluate.
667 * @param[out] vals1 A ChunkSpan with the not-null values of each function of the spline in the first dimension.
668 * @param[out] vals2 A ChunkSpan with the not-null values of each function of the spline in the second dimension.
669 *
670 * @return A Real with the value of the function at the coordinate given.
671 *
672 * @see SplineBoundaryValue
673 */
674 template <class Layout, class... CoordsDims>
675 KOKKOS_INLINE_FUNCTION Real
676 eval(ddc::Coordinate<CoordsDims...> coord_eval,
677 ddc::ChunkSpan<Real const, spline_domain_type, Layout, memory_space> const spline_coef)
678 const
679 {
680 using Dim1 = continuous_dimension_type1;
681 using Dim2 = continuous_dimension_type2;
682 if constexpr (bsplines_type1::is_periodic()) {
683 if (ddc::get<Dim1>(coord_eval) < ddc::discrete_space<bsplines_type1>().rmin()
684 || ddc::get<Dim1>(coord_eval) > ddc::discrete_space<bsplines_type1>().rmax()) {
685 ddc::get<Dim1>(coord_eval)
686 -= Kokkos::floor(
687 (ddc::get<Dim1>(coord_eval)
688 - ddc::discrete_space<bsplines_type1>().rmin())
689 / ddc::discrete_space<bsplines_type1>().length())
690 * ddc::discrete_space<bsplines_type1>().length();
691 }
692 }
693 if constexpr (bsplines_type2::is_periodic()) {
694 if (ddc::get<Dim2>(coord_eval) < ddc::discrete_space<bsplines_type2>().rmin()
695 || ddc::get<Dim2>(coord_eval) > ddc::discrete_space<bsplines_type2>().rmax()) {
696 ddc::get<Dim2>(coord_eval)
697 -= Kokkos::floor(
698 (ddc::get<Dim2>(coord_eval)
699 - ddc::discrete_space<bsplines_type2>().rmin())
700 / ddc::discrete_space<bsplines_type2>().length())
701 * ddc::discrete_space<bsplines_type2>().length();
702 }
703 }
704 if constexpr (!bsplines_type1::is_periodic()) {
705 if (ddc::get<Dim1>(coord_eval) < ddc::discrete_space<bsplines_type1>().rmin()) {
706 return m_lower_extrap_rule_1(coord_eval, spline_coef);
707 }
708 if (ddc::get<Dim1>(coord_eval) > ddc::discrete_space<bsplines_type1>().rmax()) {
709 return m_upper_extrap_rule_1(coord_eval, spline_coef);
710 }
711 }
712 if constexpr (!bsplines_type2::is_periodic()) {
713 if (ddc::get<Dim2>(coord_eval) < ddc::discrete_space<bsplines_type2>().rmin()) {
714 return m_lower_extrap_rule_2(coord_eval, spline_coef);
715 }
716 if (ddc::get<Dim2>(coord_eval) > ddc::discrete_space<bsplines_type2>().rmax()) {
717 return m_upper_extrap_rule_2(coord_eval, spline_coef);
718 }
719 }
720 return eval_no_bc(
721 ddc::DiscreteElement<>(),
722 ddc::Coordinate<continuous_dimension_type1, continuous_dimension_type2>(
723 ddc::get<Dim1>(coord_eval),
724 ddc::get<Dim2>(coord_eval)),
725 spline_coef);
726 }
727
728 /**
729 * @brief Evaluate the function or its derivative at the coordinate given.
730 *
731 * @param[in] deriv_order A DiscreteElement containing the orders of derivation for each of the dimensions of interest.
732 * If one of the dimensions is not present, its corresponding order of derivation is considered to be 0.
733 * @param[in] coord_eval The coordinate where we want to evaluate.
734 * @param[in] splne_coef The B-splines coefficients of the function we want to evaluate.
735 */
736 template <class... DerivDims, class Layout, class... CoordsDims>
737 KOKKOS_INLINE_FUNCTION Real eval_no_bc(
738 ddc::DiscreteElement<DerivDims...> const& deriv_order,
739 ddc::Coordinate<CoordsDims...> const& coord_eval,
740 ddc::ChunkSpan<Real const, spline_domain_type, Layout, memory_space> const spline_coef)
741 const
742 {
743 using deriv_dim1 = ddc::Deriv<continuous_dimension_type1>;
744 using deriv_dim2 = ddc::Deriv<continuous_dimension_type2>;
745 using deriv_dims = ddc::TypeSeq<DerivDims...>;
746
747 // Check that the tags are valid
748 static_assert(
749 (in_tags_v<DerivDims, ddc::TypeSeq<deriv_dim1, deriv_dim2>> && ...),
750 "The only valid dimensions for deriv_order are Deriv<Dim1> and Deriv<Dim2>");
751
752 ddc::DiscreteElement<bsplines_type1> jmin1;
753 ddc::DiscreteElement<bsplines_type2> jmin2;
754
755 std::array<Real, bsplines_type1::degree() + 1> vals1_ptr;
756 Kokkos::mdspan<Real, Kokkos::extents<std::size_t, bsplines_type1::degree() + 1>> const
757 vals1(vals1_ptr.data());
758 std::array<Real, bsplines_type2::degree() + 1> vals2_ptr;
759 Kokkos::mdspan<Real, Kokkos::extents<std::size_t, bsplines_type2::degree() + 1>> const
760 vals2(vals2_ptr.data());
761 ddc::Coordinate<continuous_dimension_type1> const coord_eval_interest1(coord_eval);
762 ddc::Coordinate<continuous_dimension_type2> const coord_eval_interest2(coord_eval);
763
764 if constexpr (!in_tags_v<deriv_dim1, deriv_dims>) {
765 jmin1 = ddc::discrete_space<bsplines_type1>().eval_basis(vals1, coord_eval_interest1);
766 } else {
767 auto const order1 = deriv_order.template uid<deriv_dim1>();
768 KOKKOS_ASSERT(order1 > 0 && order1 <= bsplines_type1::degree())
769
770 std::array<Real, (bsplines_type1::degree() + 1) * (bsplines_type1::degree() + 1)>
771 derivs1_ptr;
772 Kokkos::mdspan<
773 Real,
774 Kokkos::extents<
775 std::size_t,
776 bsplines_type1::degree() + 1,
777 Kokkos::dynamic_extent>> const derivs1(derivs1_ptr.data(), order1 + 1);
778
779 jmin1 = ddc::discrete_space<bsplines_type1>()
780 .eval_basis_and_n_derivs(derivs1, coord_eval_interest1, order1);
781
782 for (std::size_t i = 0; i < bsplines_type1::degree() + 1; ++i) {
783 vals1[i] = DDC_MDSPAN_ACCESS_OP(derivs1, i, order1);
784 }
785 }
786
787 if constexpr (!in_tags_v<deriv_dim2, deriv_dims>) {
788 jmin2 = ddc::discrete_space<bsplines_type2>().eval_basis(vals2, coord_eval_interest2);
789 } else {
790 auto const order2 = deriv_order.template uid<deriv_dim2>();
791 KOKKOS_ASSERT(order2 > 0 && order2 <= bsplines_type2::degree())
792
793 std::array<Real, (bsplines_type2::degree() + 1) * (bsplines_type2::degree() + 1)>
794 derivs2_ptr;
795 Kokkos::mdspan<
796 Real,
797 Kokkos::extents<
798 std::size_t,
799 bsplines_type2::degree() + 1,
800 Kokkos::dynamic_extent>> const derivs2(derivs2_ptr.data(), order2 + 1);
801
802 jmin2 = ddc::discrete_space<bsplines_type2>()
803 .eval_basis_and_n_derivs(derivs2, coord_eval_interest2, order2);
804
805 for (std::size_t i = 0; i < bsplines_type2::degree() + 1; ++i) {
806 vals2[i] = DDC_MDSPAN_ACCESS_OP(derivs2, i, order2);
807 }
808 }
809
810 Real y = 0.0;
811 for (std::size_t i = 0; i < bsplines_type1::degree() + 1; ++i) {
812 for (std::size_t j = 0; j < bsplines_type2::degree() + 1; ++j) {
813 y += spline_coef(
814 ddc::DiscreteElement<
815 bsplines_type1,
816 bsplines_type2>(jmin1 + i, jmin2 + j))
817 * vals1[i] * vals2[j];
818 }
819 }
820 return y;
821 }
822};
823
824} // 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 2D spline function.
SplineEvaluator2D(SplineEvaluator2D &&x)=default
Move-constructs.
lower_extrapolation_rule_1_type lower_extrapolation_rule_dim_1() const
Get the lower extrapolation rule along the first dimension.
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 2D integrations of a spline function (described by its spline coefficients) along the...
SplineEvaluator2D & operator=(SplineEvaluator2D 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 2D spline function (described by its spline coefficients) on a mesh along the dimension...
SplineEvaluator2D(SplineEvaluator2D const &x)=default
Copy-constructs.
~SplineEvaluator2D()=default
Destructs.
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 2D 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 2D spline function (described by its spline coefficients) on a mesh.
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 2D spline function (described by its spline coefficients) on a mesh along the dimension...
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 2D spline function (described by its spline coefficients) at a given coordinate along t...
upper_extrapolation_rule_2_type upper_extrapolation_rule_dim_2() const
Get the upper extrapolation rule along the second dimension.
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 2D spline function (described by its spline coefficients) at a given coordinate.
upper_extrapolation_rule_1_type upper_extrapolation_rule_dim_1() const
Get the upper extrapolation rule along the first dimension.
lower_extrapolation_rule_2_type lower_extrapolation_rule_dim_2() const
Get the lower extrapolation rule along the second dimension.
SplineEvaluator2D & operator=(SplineEvaluator2D &&x)=default
Move-assigns.
SplineEvaluator2D(LowerExtrapolationRule1 const &lower_extrap_rule1, UpperExtrapolationRule1 const &upper_extrap_rule1, LowerExtrapolationRule2 const &lower_extrap_rule2, UpperExtrapolationRule2 const &upper_extrap_rule2)
Build a SplineEvaluator2D acting on batched_spline_domain.
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.