DDC 0.5.2
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_Macros.hpp>
14#include <Kokkos_MathematicalFunctions.hpp>
15
16#include "integrals.hpp"
17#include "periodic_extrapolation_rule.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{
42private:
43 /**
44 * @brief Tag to indicate that the value of the spline should be evaluated.
45 */
46 struct eval_type
47 {
48 };
49
50 /**
51 * @brief Tag to indicate that derivative of the spline should be evaluated.
52 */
53 struct eval_deriv_type
54 {
55 };
56
57public:
58 /// @brief The type of the Kokkos execution space used by this class.
59 using exec_space = ExecSpace;
60
61 /// @brief The type of the Kokkos memory space used by this class.
62 using memory_space = MemorySpace;
63
64 /// @brief The type of the evaluation continuous dimension (continuous dimension of interest) used by this class.
65 using continuous_dimension_type = typename BSplines::continuous_dimension_type;
66
67 /// @brief The type of the evaluation discrete dimension (discrete dimension of interest) used by this class.
68 using evaluation_discrete_dimension_type = EvaluationDDim;
69
70 /// @brief The discrete dimension representing the B-splines.
71 using bsplines_type = BSplines;
72
73 /// @brief The type of the domain for the 1D evaluation mesh used by this class.
74 using evaluation_domain_type = ddc::DiscreteDomain<evaluation_discrete_dimension_type>;
75
76 /**
77 * @brief The type of the whole domain representing evaluation points.
78 *
79 * @tparam The batched discrete domain on which the interpolation points are defined.
80 */
81 template <
82 class BatchedInterpolationDDom,
83 class = std::enable_if_t<ddc::is_discrete_domain_v<BatchedInterpolationDDom>>>
84 using batched_evaluation_domain_type = BatchedInterpolationDDom;
85
86 /// @brief The type of the 1D spline domain corresponding to the dimension of interest.
87 using spline_domain_type = ddc::DiscreteDomain<bsplines_type>;
88
89 /**
90 * @brief The type of the batch domain (obtained by removing the dimension of interest
91 * from the whole domain).
92 *
93 * @tparam The batched discrete domain on which the interpolation points are defined.
94 */
95 template <
96 class BatchedInterpolationDDom,
97 class = std::enable_if_t<ddc::is_discrete_domain_v<BatchedInterpolationDDom>>>
98 using batch_domain_type
99 = ddc::remove_dims_of_t<BatchedInterpolationDDom, evaluation_discrete_dimension_type>;
100
101 /**
102 * @brief The type of the whole spline domain (cartesian product of 1D spline domain
103 * and batch domain) preserving the order of dimensions.
104 *
105 * @tparam The batched discrete domain on which the interpolation points are defined.
106 */
107 template <
108 class BatchedInterpolationDDom,
109 class = std::enable_if_t<ddc::is_discrete_domain_v<BatchedInterpolationDDom>>>
110 using batched_spline_domain_type = ddc::replace_dim_of_t<
111 BatchedInterpolationDDom,
112 evaluation_discrete_dimension_type,
113 bsplines_type>;
114
115 /// @brief The type of the extrapolation rule at the lower boundary.
116 using lower_extrapolation_rule_type = LowerExtrapolationRule;
117
118 /// @brief The type of the extrapolation rule at the upper boundary.
119 using upper_extrapolation_rule_type = UpperExtrapolationRule;
120
121
122private:
123 LowerExtrapolationRule m_lower_extrap_rule;
124
125 UpperExtrapolationRule m_upper_extrap_rule;
126
127public:
128 static_assert(
129 std::is_same_v<LowerExtrapolationRule,
130 typename ddc::PeriodicExtrapolationRule<continuous_dimension_type>>
131 == bsplines_type::is_periodic()
132 && std::is_same_v<
133 UpperExtrapolationRule,
134 typename ddc::PeriodicExtrapolationRule<continuous_dimension_type>>
135 == bsplines_type::is_periodic(),
136 "PeriodicExtrapolationRule has to be used if and only if dimension is periodic");
137 static_assert(
138 std::is_invocable_r_v<
139 double,
140 LowerExtrapolationRule,
141 ddc::Coordinate<continuous_dimension_type>,
142 ddc::ChunkSpan<
143 double const,
144 spline_domain_type,
145 Kokkos::layout_right,
146 memory_space>>,
147 "LowerExtrapolationRule::operator() has to be callable with usual arguments.");
148 static_assert(
149 std::is_invocable_r_v<
150 double,
151 UpperExtrapolationRule,
152 ddc::Coordinate<continuous_dimension_type>,
153 ddc::ChunkSpan<
154 double const,
155 spline_domain_type,
156 Kokkos::layout_right,
157 memory_space>>,
158 "UpperExtrapolationRule::operator() has to be callable with usual arguments.");
159
160 /**
161 * @brief Build a SplineEvaluator acting on batched_spline_domain.
162 *
163 * @param lower_extrap_rule The extrapolation rule at the lower boundary.
164 * @param upper_extrap_rule The extrapolation rule at the upper boundary.
165 *
166 * @see NullExtrapolationRule ConstantExtrapolationRule PeriodicExtrapolationRule
167 */
168 explicit SplineEvaluator(
169 LowerExtrapolationRule const& lower_extrap_rule,
170 UpperExtrapolationRule const& upper_extrap_rule)
171 : m_lower_extrap_rule(lower_extrap_rule)
172 , m_upper_extrap_rule(upper_extrap_rule)
173 {
174 }
175
176 /**
177 * @brief Copy-constructs.
178 *
179 * @param x A reference to another SplineEvaluator.
180 */
181 SplineEvaluator(SplineEvaluator const& x) = default;
182
183 /**
184 * @brief Move-constructs.
185 *
186 * @param x An rvalue to another SplineEvaluator.
187 */
188 SplineEvaluator(SplineEvaluator&& x) = default;
189
190 /// @brief Destructs
191 ~SplineEvaluator() = default;
192
193 /**
194 * @brief Copy-assigns.
195 *
196 * @param x A reference to another SplineEvaluator.
197 * @return A reference to this object.
198 */
199 SplineEvaluator& operator=(SplineEvaluator const& x) = default;
200
201 /**
202 * @brief Move-assigns.
203 *
204 * @param x An rvalue to another SplineEvaluator.
205 * @return A reference to this object.
206 */
208
209 /**
210 * @brief Get the lower extrapolation rule.
211 *
212 * 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.
213 *
214 * @return The lower extrapolation rule.
215 *
216 * @see NullExtrapolationRule ConstantExtrapolationRule PeriodicExtrapolationRule
217 */
218 lower_extrapolation_rule_type lower_extrapolation_rule() const
219 {
220 return m_lower_extrap_rule;
221 }
222
223 /**
224 * @brief Get the upper extrapolation rule.
225 *
226 * 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.
227 *
228 * @return The upper extrapolation rule.
229 *
230 * @see NullExtrapolationRule ConstantExtrapolationRule PeriodicExtrapolationRule
231 */
232 upper_extrapolation_rule_type upper_extrapolation_rule() const
233 {
234 return m_upper_extrap_rule;
235 }
236
237 /**
238 * @brief Evaluate 1D spline function (described by its spline coefficients) at a given coordinate.
239 *
240 * 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.
241 *
242 * Remark: calling SplineBuilder then SplineEvaluator corresponds to a spline interpolation.
243 *
244 * @param coord_eval The coordinate where the spline is evaluated. Note that only the component along the dimension of interest is used.
245 * @param spline_coef A ChunkSpan storing the 1D spline coefficients.
246 *
247 * @return The value of the spline function at the desired coordinate.
248 */
249 template <class Layout, class... CoordsDims>
250 KOKKOS_FUNCTION double operator()(
251 ddc::Coordinate<CoordsDims...> const& coord_eval,
252 ddc::ChunkSpan<double const, spline_domain_type, Layout, memory_space> const
253 spline_coef) const
254 {
255 return eval(coord_eval, spline_coef);
256 }
257
258 /**
259 * @brief Evaluate spline function (described by its spline coefficients) on a mesh.
260 *
261 * The spline coefficients represent a spline function defined on a cartesian product of batch_domain and B-splines
262 * (basis splines). They can be obtained via various methods, such as using a SplineBuilder.
263 *
264 * This is not a multidimensional evaluation. This is a batched 1D evaluation. This means that for each slice of coordinates
265 * identified by a batch_domain_type::discrete_element_type, the evaluation is performed with the 1D set of
266 * spline coefficients identified by the same batch_domain_type::discrete_element_type.
267 *
268 * Remark: calling SplineBuilder then SplineEvaluator corresponds to a spline interpolation.
269 *
270 * @param[out] spline_eval The values of the spline function at the desired coordinates. For practical reasons those are
271 * stored in a ChunkSpan defined on a batched_evaluation_domain_type.
272 * @param[in] coords_eval The coordinates where the spline is evaluated. Those are
273 * stored in a ChunkSpan defined on a batched_evaluation_domain_type. Note that the coordinates of the
274 * points represented by this domain are unused and irrelevant (but the points themselves (DiscreteElement) are used to select
275 * the set of 1D spline coefficients retained to perform the evaluation).
276 * @param[in] spline_coef A ChunkSpan storing the spline coefficients.
277 */
278 template <
279 class Layout1,
280 class Layout2,
281 class Layout3,
282 class BatchedInterpolationDDom,
283 class... CoordsDims>
284 void operator()(
285 ddc::ChunkSpan<double, BatchedInterpolationDDom, Layout1, memory_space> const
286 spline_eval,
287 ddc::ChunkSpan<
288 ddc::Coordinate<CoordsDims...> const,
289 BatchedInterpolationDDom,
290 Layout2,
291 memory_space> const coords_eval,
292 ddc::ChunkSpan<
293 double const,
294 batched_spline_domain_type<BatchedInterpolationDDom>,
295 Layout3,
296 memory_space> const spline_coef) const
297 {
298 evaluation_domain_type const evaluation_domain(spline_eval.domain());
299 batch_domain_type<BatchedInterpolationDDom> const batch_domain(spline_eval.domain());
300
301 ddc::parallel_for_each(
302 "ddc_splines_evaluate",
303 exec_space(),
304 batch_domain,
305 KOKKOS_CLASS_LAMBDA(
306 typename batch_domain_type<
307 BatchedInterpolationDDom>::discrete_element_type const j) {
308 const auto spline_eval_1D = spline_eval[j];
309 const auto coords_eval_1D = coords_eval[j];
310 const auto spline_coef_1D = spline_coef[j];
311 for (auto const i : evaluation_domain) {
312 spline_eval_1D(i) = eval(coords_eval_1D(i), spline_coef_1D);
313 }
314 });
315 }
316
317 /**
318 * @brief Evaluate a spline function (described by its spline coefficients) on a mesh.
319 *
320 * The spline coefficients represent a spline function defined on a cartesian
321 * product of batch_domain and B-splines (basis splines). They can be obtained
322 * via various methods, such as using a SplineBuilder.
323 *
324 * This is not a multidimensional evaluation. This is a batched 1D evaluation.
325 * This means that for each slice of spline_eval the evaluation is performed with
326 * the 1D set of spline coefficients identified by the same batch_domain_type::discrete_element_type.
327 *
328 * Remark: calling SplineBuilder then SplineEvaluator corresponds to a spline
329 * interpolation.
330 *
331 * @param[out] spline_eval The values of the spline function at the coordinates
332 * of the mesh.
333 * @param[in] spline_coef A ChunkSpan storing the spline coefficients.
334 */
335 template <class Layout1, class Layout2, class BatchedInterpolationDDom>
336 void operator()(
337 ddc::ChunkSpan<double, BatchedInterpolationDDom, Layout1, memory_space> const
338 spline_eval,
339 ddc::ChunkSpan<
340 double const,
341 batched_spline_domain_type<BatchedInterpolationDDom>,
342 Layout2,
343 memory_space> const spline_coef) const
344 {
345 evaluation_domain_type const evaluation_domain(spline_eval.domain());
346 batch_domain_type<BatchedInterpolationDDom> const batch_domain(spline_eval.domain());
347
348 ddc::parallel_for_each(
349 "ddc_splines_evaluate",
350 exec_space(),
351 batch_domain,
352 KOKKOS_CLASS_LAMBDA(
353 typename batch_domain_type<
354 BatchedInterpolationDDom>::discrete_element_type const j) {
355 const auto spline_eval_1D = spline_eval[j];
356 const auto spline_coef_1D = spline_coef[j];
357 for (auto const i : evaluation_domain) {
358 ddc::Coordinate<continuous_dimension_type> coord_eval_1D
359 = ddc::coordinate(i);
360 spline_eval_1D(i) = eval(coord_eval_1D, spline_coef_1D);
361 }
362 });
363 }
364
365 /**
366 * @brief Differentiate 1D spline function (described by its spline coefficients) at a given coordinate.
367 *
368 * The spline coefficients represent a 1D spline function defined on a B-splines (basis splines). They can be
369 * obtained via various methods, such as using a SplineBuilder.
370 *
371 * @param coord_eval The coordinate where the spline is differentiated. Note that only the component along the dimension of interest is used.
372 * @param spline_coef A ChunkSpan storing the 1D spline coefficients.
373 *
374 * @return The derivative of the spline function at the desired coordinate.
375 */
376 template <class Layout, class... CoordsDims>
377 KOKKOS_FUNCTION double deriv(
378 ddc::Coordinate<CoordsDims...> const& coord_eval,
379 ddc::ChunkSpan<double const, spline_domain_type, Layout, memory_space> const
380 spline_coef) const
381 {
382 return eval_no_bc<eval_deriv_type>(coord_eval, spline_coef);
383 }
384
385 /**
386 * @brief Differentiate spline function (described by its spline coefficients) on a mesh.
387 *
388 * The spline coefficients represent a spline function defined on a cartesian product of batch_domain and B-splines
389 * (basis splines). They can be obtained via various methods, such as using a SplineBuilder.
390 *
391 * The derivation is not performed in a multidimensional way (in any sense). This is a batched 1D derivation.
392 * This means that for each slice of coordinates identified by a batch_domain_type::discrete_element_type,
393 * the derivation is performed with the 1D set of spline coefficients identified by the same batch_domain_type::discrete_element_type.
394 *
395 * @param[out] spline_eval The derivatives of the spline function at the desired coordinates. For practical reasons those are
396 * stored in a ChunkSpan defined on a batched_evaluation_domain_type.
397 * @param[in] coords_eval The coordinates where the spline is differentiated. Those are
398 * stored in a ChunkSpan defined on a batched_evaluation_domain_type. Note that the coordinates of the
399 * points represented by this domain are unused and irrelevant (but the points themselves (DiscreteElement) are used to select
400 * the set of 1D spline coefficients retained to perform the evaluation).
401 * @param[in] spline_coef A ChunkSpan storing the spline coefficients.
402 */
403 template <
404 class Layout1,
405 class Layout2,
406 class Layout3,
407 class BatchedInterpolationDDom,
408 class... CoordsDims>
409 void deriv(
410 ddc::ChunkSpan<double, BatchedInterpolationDDom, Layout1, memory_space> const
411 spline_eval,
412 ddc::ChunkSpan<
413 ddc::Coordinate<CoordsDims...> const,
414 BatchedInterpolationDDom,
415 Layout2,
416 memory_space> const coords_eval,
417 ddc::ChunkSpan<
418 double const,
419 batched_spline_domain_type<BatchedInterpolationDDom>,
420 Layout3,
421 memory_space> const spline_coef) const
422 {
423 evaluation_domain_type const evaluation_domain(spline_eval.domain());
424 batch_domain_type<BatchedInterpolationDDom> const batch_domain(spline_eval.domain());
425
426 ddc::parallel_for_each(
427 "ddc_splines_differentiate",
428 exec_space(),
429 batch_domain,
430 KOKKOS_CLASS_LAMBDA(
431 typename batch_domain_type<
432 BatchedInterpolationDDom>::discrete_element_type const j) {
433 const auto spline_eval_1D = spline_eval[j];
434 const auto coords_eval_1D = coords_eval[j];
435 const auto spline_coef_1D = spline_coef[j];
436 for (auto const i : evaluation_domain) {
437 spline_eval_1D(i)
438 = eval_no_bc<eval_deriv_type>(coords_eval_1D(i), spline_coef_1D);
439 }
440 });
441 }
442
443 /**
444 * @brief Differentiate spline function (described by its spline coefficients) on a mesh.
445 *
446 * The spline coefficients represent a spline function defined on a cartesian product of batch_domain and B-splines
447 * (basis splines). They can be obtained via various methods, such as using a SplineBuilder.
448 *
449 * The derivation is not performed in a multidimensional way (in any sense). This is a batched 1D derivation.
450 * This is not a multidimensional evaluation. This is a batched 1D evaluation.
451 * This means that for each slice of spline_eval the evaluation is performed with
452 * the 1D set of spline coefficients identified by the same batch_domain_type::discrete_element_type.
453 *
454 * @param[out] spline_eval The derivatives of the spline function at the coordinates.
455 * @param[in] spline_coef A ChunkSpan storing the spline coefficients.
456 */
457 template <class Layout1, class Layout2, class BatchedInterpolationDDom>
458 void deriv(
459 ddc::ChunkSpan<double, BatchedInterpolationDDom, Layout1, memory_space> const
460 spline_eval,
461 ddc::ChunkSpan<
462 double const,
463 batched_spline_domain_type<BatchedInterpolationDDom>,
464 Layout2,
465 memory_space> const spline_coef) const
466 {
467 evaluation_domain_type const evaluation_domain(spline_eval.domain());
468 batch_domain_type<BatchedInterpolationDDom> const batch_domain(spline_eval.domain());
469
470 ddc::parallel_for_each(
471 "ddc_splines_differentiate",
472 exec_space(),
473 batch_domain,
474 KOKKOS_CLASS_LAMBDA(
475 typename batch_domain_type<
476 BatchedInterpolationDDom>::discrete_element_type const j) {
477 const auto spline_eval_1D = spline_eval[j];
478 const auto spline_coef_1D = spline_coef[j];
479 for (auto const i : evaluation_domain) {
480 ddc::Coordinate<continuous_dimension_type> coord_eval_1D
481 = ddc::coordinate(i);
482 spline_eval_1D(i)
483 = eval_no_bc<eval_deriv_type>(coord_eval_1D, spline_coef_1D);
484 }
485 });
486 }
487
488 /** @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.
489 *
490 * The spline coefficients represent a spline function defined on a B-splines (basis splines). They can be obtained via the SplineBuilder.
491 *
492 * The integration is not performed in a multidimensional way (in any sense). This is a batched 1D integration.
493 * This means that for each element of integrals, the integration is performed with the 1D set of
494 * spline coefficients identified by the same DiscreteElement.
495 *
496 * @param[out] integrals The integrals of the spline function on the subdomain of batch_domain. For practical reasons those are
497 * stored in a ChunkSpan defined on a batch_domain_type. Note that the coordinates of the
498 * points represented by this domain are unused and irrelevant.
499 * @param[in] spline_coef A ChunkSpan storing the spline coefficients.
500 */
501 template <class Layout1, class Layout2, class BatchedDDom, class BatchedSplineDDom>
502 void integrate(
503 ddc::ChunkSpan<double, BatchedDDom, Layout1, memory_space> const integrals,
504 ddc::ChunkSpan<double const, BatchedSplineDDom, Layout2, memory_space> const
505 spline_coef) const
506 {
507 static_assert(
508 ddc::in_tags_v<bsplines_type, to_type_seq_t<BatchedSplineDDom>>,
509 "The spline coefficients domain must contain the bsplines dimension");
510 using batch_domain_type = ddc::remove_dims_of_t<BatchedSplineDDom, bsplines_type>;
511 static_assert(
512 std::is_same_v<batch_domain_type, BatchedDDom>,
513 "The integrals domain must only contain the batch dimensions");
514
515 BatchedDDom const batch_domain(integrals.domain());
516 ddc::Chunk values_alloc(
517 ddc::DiscreteDomain<bsplines_type>(spline_coef.domain()),
518 ddc::KokkosAllocator<double, memory_space>());
519 ddc::ChunkSpan const values = values_alloc.span_view();
520 ddc::integrals(exec_space(), values);
521
522 ddc::parallel_for_each(
523 "ddc_splines_integrate",
524 exec_space(),
525 batch_domain,
526 KOKKOS_LAMBDA(typename BatchedDDom::discrete_element_type const j) {
527 integrals(j) = 0;
528 for (typename spline_domain_type::discrete_element_type const i :
529 values.domain()) {
530 integrals(j) += spline_coef(i, j) * values(i);
531 }
532 });
533 }
534
535private:
536 template <class Layout, class... CoordsDims>
537 KOKKOS_INLINE_FUNCTION double eval(
538 ddc::Coordinate<CoordsDims...> const& coord_eval,
539 ddc::ChunkSpan<double const, spline_domain_type, Layout, memory_space> const
540 spline_coef) const
541 {
542 ddc::Coordinate<continuous_dimension_type> coord_eval_interest(coord_eval);
543 if constexpr (bsplines_type::is_periodic()) {
544 if (coord_eval_interest < ddc::discrete_space<bsplines_type>().rmin()
545 || coord_eval_interest > ddc::discrete_space<bsplines_type>().rmax()) {
546 coord_eval_interest -= Kokkos::floor(
547 (coord_eval_interest
548 - ddc::discrete_space<bsplines_type>().rmin())
549 / ddc::discrete_space<bsplines_type>().length())
550 * ddc::discrete_space<bsplines_type>().length();
551 }
552 } else {
553 if (coord_eval_interest < ddc::discrete_space<bsplines_type>().rmin()) {
554 return m_lower_extrap_rule(coord_eval_interest, spline_coef);
555 }
556 if (coord_eval_interest > ddc::discrete_space<bsplines_type>().rmax()) {
557 return m_upper_extrap_rule(coord_eval_interest, spline_coef);
558 }
559 }
560 return eval_no_bc<eval_type>(coord_eval_interest, spline_coef);
561 }
562
563 template <class EvalType, class Layout, class... CoordsDims>
564 KOKKOS_INLINE_FUNCTION double eval_no_bc(
565 ddc::Coordinate<CoordsDims...> const& coord_eval,
566 ddc::ChunkSpan<double const, spline_domain_type, Layout, memory_space> const
567 spline_coef) const
568 {
569 static_assert(
570 std::is_same_v<EvalType, eval_type> || std::is_same_v<EvalType, eval_deriv_type>);
571 ddc::DiscreteElement<bsplines_type> jmin;
572 std::array<double, bsplines_type::degree() + 1> vals_ptr;
573 Kokkos::mdspan<double, Kokkos::extents<std::size_t, bsplines_type::degree() + 1>> const
574 vals(vals_ptr.data());
575 ddc::Coordinate<continuous_dimension_type> const coord_eval_interest(coord_eval);
576 if constexpr (std::is_same_v<EvalType, eval_type>) {
577 jmin = ddc::discrete_space<bsplines_type>().eval_basis(vals, coord_eval_interest);
578 } else if constexpr (std::is_same_v<EvalType, eval_deriv_type>) {
579 jmin = ddc::discrete_space<bsplines_type>().eval_deriv(vals, coord_eval_interest);
580 }
581 double y = 0.0;
582 for (std::size_t i = 0; i < bsplines_type::degree() + 1; ++i) {
583 y += spline_coef(ddc::DiscreteElement<bsplines_type>(jmin + i)) * vals[i];
584 }
585 return y;
586 }
587};
588
589} // namespace ddc
friend class DiscreteDomain
A class to evaluate, differentiate or integrate a spline function.
void operator()(ddc::ChunkSpan< double, BatchedInterpolationDDom, Layout1, memory_space > const spline_eval, ddc::ChunkSpan< ddc::Coordinate< CoordsDims... > const, BatchedInterpolationDDom, Layout2, memory_space > const coords_eval, ddc::ChunkSpan< double const, batched_spline_domain_type< BatchedInterpolationDDom >, Layout3, memory_space > const spline_coef) const
Evaluate 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.
SplineEvaluator & operator=(SplineEvaluator &&x)=default
Move-assigns.
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.
KOKKOS_FUNCTION double deriv(ddc::Coordinate< CoordsDims... > const &coord_eval, ddc::ChunkSpan< double 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 deriv(ddc::ChunkSpan< double, BatchedInterpolationDDom, Layout1, memory_space > const spline_eval, ddc::ChunkSpan< double const, batched_spline_domain_type< BatchedInterpolationDDom >, Layout2, memory_space > const spline_coef) const
Differentiate spline function (described by its spline coefficients) on a mesh.
KOKKOS_FUNCTION double operator()(ddc::Coordinate< CoordsDims... > const &coord_eval, ddc::ChunkSpan< double 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(SplineEvaluator const &x)=default
Copy-constructs.
SplineEvaluator(SplineEvaluator &&x)=default
Move-constructs.
void integrate(ddc::ChunkSpan< double, BatchedDDom, Layout1, memory_space > const integrals, ddc::ChunkSpan< double const, BatchedSplineDDom, Layout2, memory_space > const spline_coef) const
Perform batched 1D integrations of a spline function (described by its spline coefficients) along the...
void operator()(ddc::ChunkSpan< double, BatchedInterpolationDDom, Layout1, memory_space > const spline_eval, ddc::ChunkSpan< double 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.
void deriv(ddc::ChunkSpan< double, BatchedInterpolationDDom, Layout1, memory_space > const spline_eval, ddc::ChunkSpan< ddc::Coordinate< CoordsDims... > const, BatchedInterpolationDDom, Layout2, memory_space > const coords_eval, ddc::ChunkSpan< double const, batched_spline_domain_type< BatchedInterpolationDDom >, Layout3, memory_space > const spline_coef) const
Differentiate spline function (described by its spline coefficients) on a mesh.
~SplineEvaluator()=default
Destructs.
The top-level namespace of DDC.