DDC 0.11.0
Loading...
Searching...
No Matches
spline_builder_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 <cassert>
8#include <cstddef>
9#include <optional>
10
11#include <ddc/ddc.hpp>
12
15
16namespace ddc {
17
18/**
19 * @brief A class for creating a 2D spline approximation of a function.
20 *
21 * A class which contains an operator () which can be used to build a 2D spline approximation
22 * of a function. A 2D spline approximation uses a cross-product between two 1D SplineBuilder.
23 *
24 * @see SplineBuilder
25 */
26template <
27 class ExecSpace,
28 class MemorySpace,
29 class BSpline1,
30 class BSpline2,
31 class DDimI1,
32 class DDimI2,
33 ddc::BoundCond BcLower1,
34 ddc::BoundCond BcUpper1,
35 ddc::BoundCond BcLower2,
36 ddc::BoundCond BcUpper2,
37 ddc::SplineSolver Solver>
39{
40public:
41 /// @brief The type of the Kokkos execution space used by this class.
42 using exec_space = ExecSpace;
43
44 /// @brief The type of the Kokkos memory space used by this class.
45 using memory_space = MemorySpace;
46
47 /// @brief The type of the SplineBuilder used by this class to spline-approximate along first dimension.
48 using builder_type1 = ddc::
49 SplineBuilder<ExecSpace, MemorySpace, BSpline1, DDimI1, BcLower1, BcUpper1, Solver>;
50
51 /// @brief The type of the SplineBuilder used by this class to spline-approximate along second dimension.
52 using builder_type2 = ddc::
53 SplineBuilder<ExecSpace, MemorySpace, BSpline2, DDimI2, BcLower2, BcUpper2, Solver>;
54
55 /// @brief The type of the SplineBuilder used by this class to spline-approximate the second-dimension-derivatives along first dimension.
56 using builder_deriv_type1 = ddc::
57 SplineBuilder<ExecSpace, MemorySpace, BSpline1, DDimI1, BcLower1, BcUpper1, Solver>;
58
59 /// @brief The type of the first interpolation continuous dimension.
60 using continuous_dimension_type1 = typename builder_type1::continuous_dimension_type;
61
62 /// @brief The type of the second interpolation continuous dimension.
63 using continuous_dimension_type2 = typename builder_type2::continuous_dimension_type;
64
65 /// @brief The type of the first interpolation discrete dimension.
66 using interpolation_discrete_dimension_type1 =
67 typename builder_type1::interpolation_discrete_dimension_type;
68
69 /// @brief The type of the second interpolation discrete dimension.
70 using interpolation_discrete_dimension_type2 =
71 typename builder_type2::interpolation_discrete_dimension_type;
72
73 /// @brief The type of the B-splines in the first dimension.
74 using bsplines_type1 = typename builder_type1::bsplines_type;
75
76 /// @brief The type of the B-splines in the second dimension.
77 using bsplines_type2 = typename builder_type2::bsplines_type;
78
79 /// @brief The type of the Deriv domain on boundaries in the first dimension.
80 using deriv_type1 = typename builder_type1::deriv_type;
81
82 /// @brief The type of the Deriv domain on boundaries in the second dimension.
83 using deriv_type2 = typename builder_type2::deriv_type;
84
85 /// @brief The type of the domain for the interpolation mesh in the first dimension.
86 using interpolation_domain_type1 =
87 typename builder_type1::interpolation_discrete_dimension_type;
88
89 /// @brief The type of the domain for the interpolation mesh in the second dimension.
90 using interpolation_domain_type2 =
91 typename builder_type2::interpolation_discrete_dimension_type;
92
93 /// @brief The type of the domain for the interpolation mesh in the 2D dimension.
94 using interpolation_domain_type = ddc::DiscreteDomain<
95 interpolation_discrete_dimension_type1,
96 interpolation_discrete_dimension_type2>;
97
98 /**
99 * @brief The type of the whole domain representing interpolation points.
100 *
101 * @tparam The batched discrete domain on which the interpolation points are defined.
102 */
103 template <concepts::discrete_domain BatchedInterpolationDDom>
104 using batched_interpolation_domain_type = BatchedInterpolationDDom;
105
106 /**
107 * @brief The type of the batch domain (obtained by removing the dimensions of interest
108 * from the whole domain).
109 *
110 * @tparam The batched discrete domain on which the interpolation points are defined.
111 *
112 * Example: For batched_interpolation_domain_type = DiscreteDomain<X,Y,Z> and dimensions of interest X and Y,
113 * this is DiscreteDomain<Z>.
114 */
115 template <concepts::discrete_domain BatchedInterpolationDDom>
116 using batch_domain_type = ddc::remove_dims_of_t<
117 BatchedInterpolationDDom,
118 interpolation_discrete_dimension_type1,
119 interpolation_discrete_dimension_type2>;
120
121 /**
122 * @brief The type of the whole spline domain (cartesian product of 2D spline domain
123 * and batch domain) preserving the order of dimensions.
124 *
125 * @tparam The batched discrete domain on which the interpolation points are defined.
126 *
127 * Example: For batched_interpolation_domain_type = DiscreteDomain<X,Y,Z> and dimensions of interest X and Y
128 * (associated to B-splines tags BSplinesX and BSplinesY), this is DiscreteDomain<BSplinesX, BSplinesY, Z>
129 */
130 template <concepts::discrete_domain BatchedInterpolationDDom>
131 using batched_spline_domain_type
132 = ddc::detail::convert_type_seq_to_discrete_domain_t<ddc::type_seq_replace_t<
133 ddc::to_type_seq_t<BatchedInterpolationDDom>,
134 ddc::detail::TypeSeq<
135 interpolation_discrete_dimension_type1,
136 interpolation_discrete_dimension_type2>,
137 ddc::detail::TypeSeq<bsplines_type1, bsplines_type2>>>;
138
139 /**
140 * @brief The type of the whole Derivs domain (cartesian product of the 1D Deriv domain
141 * and the associated batch domain) in the first dimension, preserving the order of dimensions.
142 *
143 * @tparam The batched discrete domain on which the interpolation points are defined.
144 *
145 * Example: For batched_interpolation_domain_type = DiscreteDomain<X,Y,Z> and dimensions of interest X and Y,
146 * this is DiscreteDomain<Deriv<X>, Y, Z>.
147 */
148 template <concepts::discrete_domain BatchedInterpolationDDom>
149 using batched_derivs_domain_type1 =
150 typename builder_type1::template batched_derivs_domain_type<BatchedInterpolationDDom>;
151
152 /**
153 * @brief The type of the whole Derivs domain (cartesian product of the 1D Deriv domain
154 * and the associated batch domain) in the second dimension, preserving the order of dimensions.
155 *
156 * @tparam The batched discrete domain on which the interpolation points are defined.
157 *
158 * Example: For batched_interpolation_domain_type = DiscreteDomain<X,Y,Z> and dimensions of interest X and Y,
159 * this is DiscreteDomain<X, Deriv<Y>, Z>.
160 */
161 template <concepts::discrete_domain BatchedInterpolationDDom>
162 using batched_derivs_domain_type2 = ddc::replace_dim_of_t<
163 BatchedInterpolationDDom,
164 interpolation_discrete_dimension_type2,
165 deriv_type2>;
166
167 /**
168 * @brief The type of the whole Derivs domain (cartesian product of the 2D Deriv domain
169 * and the batch domain) in the second dimension, preserving the order of dimensions.
170 *
171 * @tparam The batched discrete domain on which the interpolation points are defined.
172 *
173 * Example: For batched_interpolation_domain_type = DiscreteDomain<X,Y,Z> and dimensions of interest X and Y,
174 * this is DiscreteDomain<Deriv<X>, Deriv<Y>, Z>.
175 */
176 template <concepts::discrete_domain BatchedInterpolationDDom>
177 using batched_derivs_domain_type
178 = ddc::detail::convert_type_seq_to_discrete_domain_t<ddc::type_seq_replace_t<
179 ddc::to_type_seq_t<BatchedInterpolationDDom>,
180 ddc::detail::TypeSeq<
181 interpolation_discrete_dimension_type1,
182 interpolation_discrete_dimension_type2>,
183 ddc::detail::TypeSeq<deriv_type1, deriv_type2>>>;
184
185private:
186 builder_type1 m_spline_builder1;
187 builder_deriv_type1 m_spline_builder_deriv1;
188 builder_type2 m_spline_builder2;
189
190public:
191 /**
192 * @brief Build a SplineBuilder2D acting on interpolation_domain.
193 *
194 * @param interpolation_domain The domain on which the interpolation points are defined, without the batch dimensions.
195 *
196 * @param cols_per_chunk A parameter used by the slicer (internal to the solver) to define the size
197 * of a chunk of right-hand-sides of the linear problem to be computed in parallel (chunks are treated
198 * by the linear solver one-after-the-other).
199 * This value is optional. If no value is provided then the default value is chosen by the requested solver.
200 *
201 * @param preconditioner_max_block_size A parameter used by the slicer (internal to the solver) to
202 * define the size of a block used by the Block-Jacobi preconditioner.
203 * This value is optional. If no value is provided then the default value is chosen by the requested solver.
204 *
205 * @see SplinesLinearProblemSparse
206 */
207 explicit SplineBuilder2D(
208 interpolation_domain_type const& interpolation_domain,
209 std::optional<std::size_t> cols_per_chunk = std::nullopt,
210 std::optional<unsigned int> preconditioner_max_block_size = std::nullopt)
211 : m_spline_builder1(interpolation_domain, cols_per_chunk, preconditioner_max_block_size)
212 , m_spline_builder_deriv1(interpolation_domain)
213 , m_spline_builder2(interpolation_domain, cols_per_chunk, preconditioner_max_block_size)
214 {
215 }
216
217 /**
218 * @brief Build a SplineBuilder2D acting on the interpolation domain contained in batched_interpolation_domain.
219 *
220 * @param batched_interpolation_domain The domain on which the interpolation points are defined.
221 *
222 * @param cols_per_chunk A parameter used by the slicer (internal to the solver) to define the size
223 * of a chunk of right-hand-sides of the linear problem to be computed in parallel (chunks are treated
224 * by the linear solver one-after-the-other).
225 * This value is optional. If no value is provided then the default value is chosen by the requested solver.
226 *
227 * @param preconditioner_max_block_size A parameter used by the slicer (internal to the solver) to
228 * define the size of a block used by the Block-Jacobi preconditioner.
229 * This value is optional. If no value is provided then the default value is chosen by the requested solver.
230 *
231 * @see SplinesLinearProblemSparse
232 */
233 template <concepts::discrete_domain BatchedInterpolationDDom>
234 explicit SplineBuilder2D(
235 BatchedInterpolationDDom const& batched_interpolation_domain,
236 std::optional<std::size_t> cols_per_chunk = std::nullopt,
237 std::optional<unsigned int> preconditioner_max_block_size = std::nullopt)
239 interpolation_domain_type(batched_interpolation_domain),
240 cols_per_chunk,
241 preconditioner_max_block_size)
242 {
243 }
244
245 /// @brief Copy-constructor is deleted.
246 SplineBuilder2D(SplineBuilder2D const& x) = delete;
247
248 /**
249 * @brief Move-constructs.
250 *
251 * @param x An rvalue to another SplineBuilder2D.
252 */
253 SplineBuilder2D(SplineBuilder2D&& x) = default;
254
255 /// @brief Destructs.
256 ~SplineBuilder2D() = default;
257
258 /// @brief Copy-assignment is deleted.
259 SplineBuilder2D& operator=(SplineBuilder2D const& x) = delete;
260
261 /** @brief Move-assigns.
262 *
263 * @param x An rvalue to another SplineBuilder.
264 * @return A reference to this object.
265 */
267
268 /**
269 * @brief Get the domain for the 2D interpolation mesh used by this class.
270 *
271 * This is 2D because it is defined along the dimensions of interest.
272 *
273 * @return The 2D domain for the interpolation mesh.
274 */
275 interpolation_domain_type interpolation_domain() const noexcept
276 {
277 return ddc::DiscreteDomain<interpolation_domain_type1, interpolation_domain_type2>(
278 m_spline_builder1.interpolation_domain(),
279 m_spline_builder2.interpolation_domain());
280 }
281
282 /**
283 * @brief Get the whole domain representing interpolation points.
284 *
285 * Values of the function must be provided on this domain in order
286 * to build a spline representation of the function (cartesian product of 2D interpolation_domain and batch_domain).
287 *
288 * @param batched_interpolation_domain The whole domain on which the interpolation points are defined.
289 *
290 * @return The domain for the interpolation mesh.
291 */
292 template <concepts::discrete_domain BatchedInterpolationDDom>
293 BatchedInterpolationDDom batched_interpolation_domain(
294 BatchedInterpolationDDom const& batched_interpolation_domain) const noexcept
295 {
296 assert(interpolation_domain() == interpolation_domain_type(batched_interpolation_domain));
297 return batched_interpolation_domain;
298 }
299
300 /**
301 * @brief Get the batch domain.
302 *
303 * Obtained by removing the dimensions of interest from the whole interpolation domain.
304 *
305 * @param batched_interpolation_domain The whole domain on which the interpolation points are defined.
306 *
307 * @return The batch domain.
308 */
309 template <concepts::discrete_domain BatchedInterpolationDDom>
310 batch_domain_type<BatchedInterpolationDDom> batch_domain(
311 BatchedInterpolationDDom const& batched_interpolation_domain) const noexcept
312 {
313 assert(interpolation_domain() == interpolation_domain_type(batched_interpolation_domain));
314 return ddc::remove_dims_of(batched_interpolation_domain, interpolation_domain());
315 }
316
317 /**
318 * @brief Get the 2D domain on which spline coefficients are defined.
319 *
320 * The 2D spline domain corresponding to the dimensions of interest.
321 *
322 * @return The 2D domain for the spline coefficients.
323 */
324 ddc::DiscreteDomain<bsplines_type1, bsplines_type2> spline_domain() const noexcept
325 {
326 return ddc::DiscreteDomain<bsplines_type1, bsplines_type2>(
327 ddc::discrete_space<bsplines_type1>().full_domain(),
328 ddc::discrete_space<bsplines_type2>().full_domain());
329 }
330
331 /**
332 * @brief Get the whole domain on which spline coefficients are defined.
333 *
334 * Spline approximations (spline-transformed functions) are computed on this domain.
335 *
336 * @param batched_interpolation_domain The whole domain on which the interpolation points are defined.
337 *
338 * @return The domain for the spline coefficients.
339 */
340 template <concepts::discrete_domain BatchedInterpolationDDom>
341 batched_spline_domain_type<BatchedInterpolationDDom> batched_spline_domain(
342 BatchedInterpolationDDom const& batched_interpolation_domain) const noexcept
343 {
344 assert(interpolation_domain() == interpolation_domain_type(batched_interpolation_domain));
345 return ddc::replace_dim_of<interpolation_discrete_dimension_type1, bsplines_type1>(
346 ddc::replace_dim_of<
347 interpolation_discrete_dimension_type2,
348 bsplines_type2>(batched_interpolation_domain, spline_domain()),
350 }
351
352 /**
353 * @brief Compute a 2D spline approximation of a function.
354 *
355 * Use the values of a function (defined on
356 * SplineBuilder2D::batched_interpolation_domain) and the derivatives of the
357 * function at the boundaries (in the case of BoundCond::HERMITE only)
358 * to calculate a 2D spline approximation of this function.
359 *
360 * The spline approximation is stored as a ChunkSpan of coefficients
361 * associated with B-splines.
362 *
363 * @param[out] spline
364 * The coefficients of the spline computed by this SplineBuilder.
365 * @param[in] vals
366 * The values of the function at the interpolation mesh.
367 * @param[in] derivs_min1
368 * The values of the derivatives at the lower boundary in the first dimension.
369 * @param[in] derivs_max1
370 * The values of the derivatives at the upper boundary in the first dimension.
371 * @param[in] derivs_min2
372 * The values of the derivatives at the lower boundary in the second dimension.
373 * @param[in] derivs_max2
374 * The values of the derivatives at the upper boundary in the second dimension.
375 * @param[in] mixed_derivs_min1_min2
376 * The values of the the cross-derivatives at the lower boundary in the first dimension
377 * and the lower boundary in the second dimension.
378 * @param[in] mixed_derivs_max1_min2
379 * The values of the the cross-derivatives at the upper boundary in the first dimension
380 * and the lower boundary in the second dimension.
381 * @param[in] mixed_derivs_min1_max2
382 * The values of the the cross-derivatives at the lower boundary in the first dimension
383 * and the upper boundary in the second dimension.
384 * @param[in] mixed_derivs_max1_max2
385 * The values of the the cross-derivatives at the upper boundary in the first dimension
386 * and the upper boundary in the second dimension.
387 */
388 template <class Layout, class BatchedInterpolationDDom>
389 void operator()(
390 ddc::ChunkSpan<
391 double,
392 batched_spline_domain_type<BatchedInterpolationDDom>,
393 Layout,
394 memory_space> spline,
395 ddc::ChunkSpan<double const, BatchedInterpolationDDom, Layout, memory_space> vals,
396 std::optional<ddc::ChunkSpan<
397 double const,
398 batched_derivs_domain_type1<BatchedInterpolationDDom>,
399 Layout,
400 memory_space>> derivs_min1
401 = std::nullopt,
402 std::optional<ddc::ChunkSpan<
403 double const,
404 batched_derivs_domain_type1<BatchedInterpolationDDom>,
405 Layout,
406 memory_space>> derivs_max1
407 = std::nullopt,
408 std::optional<ddc::ChunkSpan<
409 double const,
410 batched_derivs_domain_type2<BatchedInterpolationDDom>,
411 Layout,
412 memory_space>> derivs_min2
413 = std::nullopt,
414 std::optional<ddc::ChunkSpan<
415 double const,
416 batched_derivs_domain_type2<BatchedInterpolationDDom>,
417 Layout,
418 memory_space>> derivs_max2
419 = std::nullopt,
420 std::optional<ddc::ChunkSpan<
421 double const,
422 batched_derivs_domain_type<BatchedInterpolationDDom>,
423 Layout,
424 memory_space>> mixed_derivs_min1_min2
425 = std::nullopt,
426 std::optional<ddc::ChunkSpan<
427 double const,
428 batched_derivs_domain_type<BatchedInterpolationDDom>,
429 Layout,
430 memory_space>> mixed_derivs_max1_min2
431 = std::nullopt,
432 std::optional<ddc::ChunkSpan<
433 double const,
434 batched_derivs_domain_type<BatchedInterpolationDDom>,
435 Layout,
436 memory_space>> mixed_derivs_min1_max2
437 = std::nullopt,
438 std::optional<ddc::ChunkSpan<
439 double const,
440 batched_derivs_domain_type<BatchedInterpolationDDom>,
441 Layout,
442 memory_space>> mixed_derivs_max1_max2
443 = std::nullopt) const;
444};
445
446
447template <
448 class ExecSpace,
449 class MemorySpace,
450 class BSpline1,
451 class BSpline2,
452 class DDimI1,
453 class DDimI2,
459template <class Layout, class BatchedInterpolationDDom>
460void SplineBuilder2D<
461 ExecSpace,
462 MemorySpace,
463 BSpline1,
464 BSpline2,
465 DDimI1,
466 DDimI2,
467 BcLower1,
468 BcUpper1,
469 BcLower2,
470 BcUpper2,
471 Solver>::
472operator()(
473 ddc::ChunkSpan<
474 double,
475 batched_spline_domain_type<BatchedInterpolationDDom>,
476 Layout,
477 memory_space> spline,
478 ddc::ChunkSpan<double const, BatchedInterpolationDDom, Layout, memory_space> vals,
479 std::optional<ddc::ChunkSpan<
480 double const,
481 batched_derivs_domain_type1<BatchedInterpolationDDom>,
482 Layout,
483 memory_space>> const derivs_min1,
484 std::optional<ddc::ChunkSpan<
485 double const,
486 batched_derivs_domain_type1<BatchedInterpolationDDom>,
487 Layout,
488 memory_space>> const derivs_max1,
489 std::optional<ddc::ChunkSpan<
490 double const,
491 batched_derivs_domain_type2<BatchedInterpolationDDom>,
492 Layout,
493 memory_space>> const derivs_min2,
494 std::optional<ddc::ChunkSpan<
495 double const,
496 batched_derivs_domain_type2<BatchedInterpolationDDom>,
497 Layout,
498 memory_space>> const derivs_max2,
499 std::optional<ddc::ChunkSpan<
500 double const,
501 batched_derivs_domain_type<BatchedInterpolationDDom>,
502 Layout,
503 memory_space>> const mixed_derivs_min1_min2,
504 std::optional<ddc::ChunkSpan<
505 double const,
506 batched_derivs_domain_type<BatchedInterpolationDDom>,
507 Layout,
508 memory_space>> const mixed_derivs_max1_min2,
509 std::optional<ddc::ChunkSpan<
510 double const,
511 batched_derivs_domain_type<BatchedInterpolationDDom>,
512 Layout,
513 memory_space>> const mixed_derivs_min1_max2,
514 std::optional<ddc::ChunkSpan<
515 double const,
516 batched_derivs_domain_type<BatchedInterpolationDDom>,
517 Layout,
518 memory_space>> const mixed_derivs_max1_max2) const
519{
520 auto const batched_interpolation_domain = vals.domain();
521
522 assert(interpolation_domain() == interpolation_domain_type(batched_interpolation_domain));
523 assert(batch_domain_type<BatchedInterpolationDDom>(batched_interpolation_domain)
524 == batch_domain_type<BatchedInterpolationDDom>(spline.domain()));
525
526 if (batch_domain(batched_interpolation_domain).empty()) {
527 return;
528 }
529
530 // TODO: perform computations along dimension 1 on different streams ?
531 // Spline1-approximate derivs_min2 (to spline1_deriv_min)
532
533 auto const batched_interpolation_deriv_domain
534 = ddc::replace_dim_of<interpolation_discrete_dimension_type2, deriv_type2>(
535 batched_interpolation_domain,
536 ddc::DiscreteDomain<deriv_type2>(
537 ddc::DiscreteElement<deriv_type2>(builder_type2::s_odd),
538 ddc::DiscreteVector<deriv_type2>(bsplines_type2::degree() / 2)));
539
540 ddc::Chunk spline1_deriv_min_alloc(
541 m_spline_builder_deriv1.batched_spline_domain(batched_interpolation_deriv_domain),
542 ddc::KokkosAllocator<double, MemorySpace>());
543 auto spline1_deriv_min = spline1_deriv_min_alloc.span_view();
544 auto spline1_deriv_min_opt = std::optional(spline1_deriv_min.span_cview());
545 if constexpr (BcLower2 == ddc::BoundCond::HERMITE) {
546 m_spline_builder_deriv1(
547 spline1_deriv_min,
548 *derivs_min2,
549 mixed_derivs_min1_min2,
550 mixed_derivs_max1_min2);
551 } else {
552 spline1_deriv_min_opt = std::nullopt;
553 }
554
555 // Spline1-approximate vals (to spline1)
556 ddc::Chunk spline1_alloc(
557 m_spline_builder1.batched_spline_domain(batched_interpolation_domain),
558 ddc::KokkosAllocator<double, MemorySpace>());
559 ddc::ChunkSpan const spline1 = spline1_alloc.span_view();
560
561 m_spline_builder1(spline1, vals, derivs_min1, derivs_max1);
562
563 // Spline1-approximate derivs_max2 (to spline1_deriv_max)
564 ddc::Chunk spline1_deriv_max_alloc(
565 m_spline_builder_deriv1.batched_spline_domain(batched_interpolation_deriv_domain),
566 ddc::KokkosAllocator<double, MemorySpace>());
567 auto spline1_deriv_max = spline1_deriv_max_alloc.span_view();
568 auto spline1_deriv_max_opt = std::optional(spline1_deriv_max.span_cview());
569 if constexpr (BcUpper2 == ddc::BoundCond::HERMITE) {
570 m_spline_builder_deriv1(
571 spline1_deriv_max,
572 *derivs_max2,
573 mixed_derivs_min1_max2,
574 mixed_derivs_max1_max2);
575 } else {
576 spline1_deriv_max_opt = std::nullopt;
577 }
578
579 // Spline2-approximate spline1
580 m_spline_builder2(spline, spline1.span_cview(), spline1_deriv_min_opt, spline1_deriv_max_opt);
581}
582
583} // namespace ddc
friend class ChunkSpan
friend class Chunk
Definition chunk.hpp:81
friend class DiscreteDomain
KOKKOS_FUNCTION constexpr bool operator!=(DiscreteVector< OTags... > const &rhs) const noexcept
A class which provides helper functions to initialise the Greville points from a B-Spline definition.
static ddc::DiscreteDomain< Sampling > get_domain()
Get the domain which gives us access to all of the Greville points.
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.
Impl & operator=(Impl &&x)=default
Move-assigns.
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 ddc::Coordinate< CDim > rmin() const noexcept
Returns the coordinate of the first 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.
KOKKOS_INLINE_FUNCTION discrete_element_type eval_basis(DSpan1D values, ddc::Coordinate< CDim > const &x) const
Evaluates non-zero B-splines at a given coordinate.
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< DDim, OriginMemorySpace > const &impl)
Copy-constructs from another Impl with a different Kokkos memory space.
~Impl()=default
Destructs.
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 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...
Impl(Impl &&x)=default
Move-constructs.
Impl(std::initializer_list< ddc::Coordinate< CDim > > breaks)
Constructs an Impl using a brace-list, i.e.
KOKKOS_INLINE_FUNCTION discrete_element_type eval_basis_and_n_derivs(ddc::DSpan2D derivs, ddc::Coordinate< CDim > const &x, std::size_t n) const
Evaluates non-zero B-spline values and derivatives at a given coordinate.
KOKKOS_INLINE_FUNCTION std::size_t ncells() const noexcept
Returns the number of cells over which the B-splines are defined.
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 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 npoints() const noexcept
The number of break points.
KOKKOS_INLINE_FUNCTION std::size_t nbasis() const noexcept
Returns the number of basis functions.
Impl(Impl const &x)=default
Copy-constructs.
KOKKOS_INLINE_FUNCTION discrete_element_type eval_deriv(DSpan1D derivs, ddc::Coordinate< CDim > const &x) const
Evaluates non-zero B-spline derivatives at a given coordinate.
KOKKOS_INLINE_FUNCTION double length() const noexcept
Returns the length of the domain.
Impl & operator=(Impl const &x)=default
Copy-assigns.
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.
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.
void operator()(ddc::ChunkSpan< double, batched_spline_domain_type< BatchedInterpolationDDom >, Layout, memory_space > spline, ddc::ChunkSpan< double const, BatchedInterpolationDDom, Layout, memory_space > vals, std::optional< ddc::ChunkSpan< double const, batched_derivs_domain_type1< BatchedInterpolationDDom >, Layout, memory_space > > derivs_min1=std::nullopt, std::optional< ddc::ChunkSpan< double const, batched_derivs_domain_type1< BatchedInterpolationDDom >, Layout, memory_space > > derivs_max1=std::nullopt, std::optional< ddc::ChunkSpan< double const, batched_derivs_domain_type2< BatchedInterpolationDDom >, Layout, memory_space > > derivs_min2=std::nullopt, std::optional< ddc::ChunkSpan< double const, batched_derivs_domain_type2< BatchedInterpolationDDom >, Layout, memory_space > > derivs_max2=std::nullopt, std::optional< ddc::ChunkSpan< double const, batched_derivs_domain_type< BatchedInterpolationDDom >, Layout, memory_space > > mixed_derivs_min1_min2=std::nullopt, std::optional< ddc::ChunkSpan< double const, batched_derivs_domain_type< BatchedInterpolationDDom >, Layout, memory_space > > mixed_derivs_max1_min2=std::nullopt, std::optional< ddc::ChunkSpan< double const, batched_derivs_domain_type< BatchedInterpolationDDom >, Layout, memory_space > > mixed_derivs_min1_max2=std::nullopt, std::optional< ddc::ChunkSpan< double const, batched_derivs_domain_type< BatchedInterpolationDDom >, Layout, memory_space > > mixed_derivs_max1_max2=std::nullopt) const
Compute a 2D spline approximation of a function.
BatchedInterpolationDDom batched_interpolation_domain(BatchedInterpolationDDom const &batched_interpolation_domain) const noexcept
Get the whole domain representing interpolation points.
ddc::DiscreteDomain< bsplines_type1, bsplines_type2 > spline_domain() const noexcept
Get the 2D domain on which spline coefficients are defined.
SplineBuilder2D(SplineBuilder2D &&x)=default
Move-constructs.
SplineBuilder2D & operator=(SplineBuilder2D &&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.
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.
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(SplineBuilder2D const &x)=delete
Copy-constructor is deleted.
interpolation_domain_type interpolation_domain() const noexcept
Get the domain for the 2D interpolation mesh used by this class.
batch_domain_type< BatchedInterpolationDDom > batch_domain(BatchedInterpolationDDom const &batched_interpolation_domain) const noexcept
Get the batch domain.
SplineBuilder2D & operator=(SplineBuilder2D const &x)=delete
Copy-assignment is deleted.
A class for creating a spline approximation of a function.
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 SplineSolver s_spline_solver
The SplineSolver giving the backend used to perform the spline approximation.
batch_domain_type< BatchedInterpolationDDom > batch_domain(BatchedInterpolationDDom const &batched_interpolation_domain) const noexcept
Get the batch domain.
std::tuple< ddc::Chunk< double, ddc::DiscreteDomain< ddc::Deriv< typename InterpolationDDim::continuous_dimension_type > >, ddc::KokkosAllocator< double, OutMemorySpace > >, ddc::Chunk< double, ddc::DiscreteDomain< InterpolationDDim >, ddc::KokkosAllocator< double, OutMemorySpace > >, ddc::Chunk< double, ddc::DiscreteDomain< ddc::Deriv< typename InterpolationDDim::continuous_dimension_type > >, ddc::KokkosAllocator< double, OutMemorySpace > > > quadrature_coefficients() const
Compute the quadrature coefficients associated to the b-splines used by this SplineBuilder.
SplineBuilder & operator=(SplineBuilder const &x)=delete
Copy-assignment is deleted.
SplineBuilder(SplineBuilder &&x)=default
Move-constructs.
static constexpr int s_nbe_xmax
The number of equations defining the boundary condition at the upper bound.
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 ddc::BoundCond s_bc_xmin
The boundary condition implemented at the lower bound.
BatchedInterpolationDDom batched_interpolation_domain(BatchedInterpolationDDom const &batched_interpolation_domain) const noexcept
Get the whole domain representing interpolation points.
SplineBuilder & operator=(SplineBuilder &&x)=default
Move-assigns.
SplineBuilder(SplineBuilder const &x)=delete
Copy-constructor is deleted.
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.
static constexpr int s_nbv_xmax
The number of input values defining the boundary condition at the upper bound.
static constexpr bool s_odd
Indicates if the degree of the splines is odd or even.
static constexpr int s_nbv_xmin
The number of input values defining the boundary condition at the lower bound.
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_xmin_domain(BatchedInterpolationDDom const &batched_interpolation_domain) const noexcept
Get the whole domain on which derivatives on lower boundary are defined.
static constexpr ddc::BoundCond s_bc_xmax
The boundary condition implemented at the upper bound.
void operator()(ddc::ChunkSpan< double, batched_spline_domain_type< BatchedInterpolationDDom >, Layout, memory_space > spline, ddc::ChunkSpan< double const, BatchedInterpolationDDom, Layout, memory_space > vals, std::optional< ddc::ChunkSpan< double const, batched_derivs_domain_type< BatchedInterpolationDDom >, Layout, memory_space > > derivs_xmin=std::nullopt, std::optional< ddc::ChunkSpan< double const, batched_derivs_domain_type< BatchedInterpolationDDom >, Layout, memory_space > > derivs_xmax=std::nullopt) const
Compute a spline approximation of a function.
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_type > spline_domain() const noexcept
Get the 1D domain on which spline coefficients are defined.
~SplineBuilder()=default
Destructs.
static constexpr int s_nbe_xmin
The number of equations defining the boundary condition at the lower bound.
Storage class of the static attributes of the discrete dimension.
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...
Impl(ddc::Coordinate< CDim > rmin, ddc::Coordinate< CDim > rmax, std::size_t ncells)
Constructs a spline basis (B-splines) with n equidistant knots over .
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 discrete_element_type eval_basis(DSpan1D values, ddc::Coordinate< CDim > const &x) const
Evaluates non-zero B-splines 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.
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()=default
Destructs.
KOKKOS_INLINE_FUNCTION std::size_t nbasis() const noexcept
Returns the number of basis functions.
Impl(Impl const &x)=default
Copy-constructs.
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.
KOKKOS_INLINE_FUNCTION discrete_element_type eval_basis_and_n_derivs(ddc::DSpan2D derivs, ddc::Coordinate< CDim > const &x, std::size_t n) const
Evaluates non-zero B-spline values and derivatives 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 double length() const noexcept
Returns the length of the domain.
Impl(Impl< DDim, OriginMemorySpace > const &impl)
Copy-constructs from another Impl with a different Kokkos memory space.
KOKKOS_INLINE_FUNCTION std::size_t ncells() const noexcept
Returns the number of cells over which the B-splines are defined.
KOKKOS_INLINE_FUNCTION discrete_element_type eval_deriv(DSpan1D derivs, ddc::Coordinate< CDim > const &x) const
Evaluates non-zero B-spline derivatives at a given coordinate.
Impl & operator=(Impl &&x)=default
Move-assigns.
KOKKOS_INLINE_FUNCTION discrete_domain_type full_domain() const
Returns the discrete domain including eventual additional B-splines in the periodic case.
Impl & operator=(Impl const &x)=default
Copy-assigns.
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 bool is_periodic() noexcept
Indicates if the B-splines are periodic or not.
static constexpr std::size_t degree() noexcept
The degree of B-splines.
UniformPointSampling models a uniform discretization of the provided continuous dimension.
The top-level namespace of DDC.
constexpr int n_boundary_equations(ddc::BoundCond const bc, std::size_t const degree)
Return the number of equations needed to describe a given boundary condition.
constexpr bool is_uniform_bsplines_v
Indicates if a tag corresponds to uniform B-splines or not.
BoundCond
An enum representing a spline boundary condition.
@ HOMOGENEOUS_HERMITE
Homogeneous Hermite boundary condition (derivatives are 0)
@ GREVILLE
Use Greville points instead of conditions on derivative for B-Spline interpolation.
@ HERMITE
Hermite boundary condition.
@ PERIODIC
Periodic boundary condition u(1)=u(n)
ddc::ChunkSpan< double, ddc::DiscreteDomain< DDim >, Layout, MemorySpace > integrals(ExecSpace const &execution_space, ddc::ChunkSpan< double, ddc::DiscreteDomain< DDim >, Layout, MemorySpace > int_vals)
Compute the integrals of the B-splines.
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 bool is_non_uniform_bsplines_v
Indicates if a tag corresponds to non-uniform B-splines or not.
A templated struct representing a discrete dimension storing the derivatives of a function along a co...
Definition deriv.hpp:15
If the type DDim is a B-spline, defines type to the discrete dimension of the associated knots.
ConstantExtrapolationRule(ddc::Coordinate< DimI > eval_pos, ddc::Coordinate< DimNI > eval_pos_not_interest_min, ddc::Coordinate< DimNI > eval_pos_not_interest_max)
Instantiate a ConstantExtrapolationRule.
KOKKOS_FUNCTION double operator()(CoordType coord_extrap, ddc::ChunkSpan< double const, ddc::DiscreteDomain< BSplines1, BSplines2 >, 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.
KOKKOS_FUNCTION double operator()(CoordType pos, ddc::ChunkSpan< double 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 functor describing a null extrapolation boundary value for 1D spline evaluator.
KOKKOS_FUNCTION double operator()(CoordType, ChunkSpan) const
Evaluates the spline at a coordinate outside of the domain.
KOKKOS_FUNCTION double operator()(CoordType, ChunkSpan) const