DDC 0.8.0
Loading...
Searching...
No Matches
spline_builder_3d.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#include <type_traits>
11
12#include <ddc/ddc.hpp>
13
14#include "spline_builder.hpp"
15
16namespace ddc {
17
18/**
19 * @brief A class for creating a 3D spline approximation of a function.
20 *
21 * A class which contains an operator () which can be used to build a 3D spline approximation
22 * of a function. A 3D spline approximation uses a cross-product between three 1D SplineBuilder.
23 *
24 * @see SplineBuilder
25 */
26template <
27 class ExecSpace,
28 class MemorySpace,
29 class BSpline1,
30 class BSpline2,
31 class BSpline3,
32 class DDimI1,
33 class DDimI2,
34 class DDimI3,
35 ddc::BoundCond BcLower1,
36 ddc::BoundCond BcUpper1,
37 ddc::BoundCond BcLower2,
38 ddc::BoundCond BcUpper2,
39 ddc::BoundCond BcLower3,
40 ddc::BoundCond BcUpper3,
41 ddc::SplineSolver Solver>
43{
44public:
45 /// @brief The type of the Kokkos execution space used by this class.
46 using exec_space = ExecSpace;
47
48 /// @brief The type of the Kokkos memory space used by this class.
49 using memory_space = MemorySpace;
50
51 /// @brief The type of the SplineBuilder used by this class to spline-approximate along first dimension.
52 using builder_type1 = ddc::
53 SplineBuilder<ExecSpace, MemorySpace, BSpline1, DDimI1, BcLower1, BcUpper1, Solver>;
54
55 /// @brief The type of the SplineBuilder used by this class to spline-approximate along second dimension.
56 using builder_type2 = ddc::
57 SplineBuilder<ExecSpace, MemorySpace, BSpline2, DDimI2, BcLower2, BcUpper2, Solver>;
58
59 /// @brief The type of the SplineBuilder used by this class to spline-approximate along third dimension.
60 using builder_type3 = ddc::
61 SplineBuilder<ExecSpace, MemorySpace, BSpline3, DDimI3, BcLower3, BcUpper3, Solver>;
62
63 /// @brief The type of the SplineBuilder used by this class to spline-approximate the second-dimension-derivatives along first dimension.
64 using builder_deriv_type1 = ddc::
65 SplineBuilder<ExecSpace, MemorySpace, BSpline1, DDimI1, BcLower1, BcUpper1, Solver>;
66
67 /// @brief The type of the SplineBuilder used by this class to spline-approximate the third-dimension-derivatives along second dimension.
68 using builder_deriv_type2 = ddc::
69 SplineBuilder<ExecSpace, MemorySpace, BSpline2, DDimI2, BcLower2, BcUpper2, Solver>;
70
71 /// @brief The type of the first interpolation continuous dimension.
72 using continuous_dimension_type1 = typename builder_type1::continuous_dimension_type;
73
74 /// @brief The type of the second interpolation continuous dimension.
75 using continuous_dimension_type2 = typename builder_type2::continuous_dimension_type;
76
77 /// @brief The type of the third interpolation continuous dimension.
78 using continuous_dimension_type3 = typename builder_type3::continuous_dimension_type;
79
80 /// @brief The type of the first interpolation discrete dimension.
81 using interpolation_discrete_dimension_type1 =
82 typename builder_type1::interpolation_discrete_dimension_type;
83
84 /// @brief The type of the second interpolation discrete dimension.
85 using interpolation_discrete_dimension_type2 =
86 typename builder_type2::interpolation_discrete_dimension_type;
87
88 /// @brief The type of the third interpolation discrete dimension.
89 using interpolation_discrete_dimension_type3 =
90 typename builder_type3::interpolation_discrete_dimension_type;
91
92 /// @brief The type of the B-splines in the first dimension.
93 using bsplines_type1 = typename builder_type1::bsplines_type;
94
95 /// @brief The type of the B-splines in the second dimension.
96 using bsplines_type2 = typename builder_type2::bsplines_type;
97
98 /// @brief The type of the B-splines in the third dimension.
99 using bsplines_type3 = typename builder_type3::bsplines_type;
100
101 /// @brief The type of the Deriv domain on boundaries in the first dimension.
102 using deriv_type1 = typename builder_type1::deriv_type;
103
104 /// @brief The type of the Deriv domain on boundaries in the second dimension.
105 using deriv_type2 = typename builder_type2::deriv_type;
106
107 /// @brief The type of the Deriv domain on boundaries in the third dimension.
108 using deriv_type3 = typename builder_type3::deriv_type;
109
110 /// @brief The type of the domain for the interpolation mesh in the first dimension.
111 using interpolation_domain_type1 =
112 typename builder_type1::interpolation_discrete_dimension_type;
113
114 /// @brief The type of the domain for the interpolation mesh in the second dimension.
115 using interpolation_domain_type2 =
116 typename builder_type2::interpolation_discrete_dimension_type;
117
118 /// @brief The type of the domain for the interpolation mesh in the third dimension.
119 using interpolation_domain_type3 =
120 typename builder_type3::interpolation_discrete_dimension_type;
121
122 /// @brief The type of the domain for the interpolation mesh in the 3D dimension.
123 using interpolation_domain_type = ddc::DiscreteDomain<
124 interpolation_discrete_dimension_type1,
125 interpolation_discrete_dimension_type2,
126 interpolation_discrete_dimension_type3>;
127
128 /**
129 * @brief The type of the whole domain representing interpolation points.
130 *
131 * @tparam The batched discrete domain on which the interpolation points are defined.
132 */
133 template <
134 class BatchedInterpolationDDom,
135 class = std::enable_if_t<ddc::is_discrete_domain_v<BatchedInterpolationDDom>>>
136 using batched_interpolation_domain_type = BatchedInterpolationDDom;
137
138 /**
139 * @brief The type of the batch domain (obtained by removing the dimensions of interest
140 * from the whole domain).
141 *
142 * @tparam The batched discrete domain on which the interpolation points are defined.
143 *
144 * Example: For batched_interpolation_domain_type = DiscreteDomain<X,Y,Z,T> and dimensions of interest X, Y and Z,
145 * this is DiscreteDomain<T>.
146 */
147 template <
148 class BatchedInterpolationDDom,
149 class = std::enable_if_t<ddc::is_discrete_domain_v<BatchedInterpolationDDom>>>
150 using batch_domain_type = ddc::remove_dims_of_t<
151 BatchedInterpolationDDom,
152 interpolation_discrete_dimension_type1,
153 interpolation_discrete_dimension_type2,
154 interpolation_discrete_dimension_type3>;
155
156 /**
157 * @brief The type of the whole spline domain (cartesian product of 3D spline domain
158 * and batch domain) preserving the order of dimensions.
159 *
160 * @tparam The batched discrete domain on which the interpolation points are defined.
161 *
162 * Example: For batched_interpolation_domain_type = DiscreteDomain<X,Y,Z,T> and dimensions of interest X, Y and Z
163 * (associated to B-splines tags BSplinesX, BSplinesY and BSplinesZ), this is DiscreteDomain<BSplinesX, BSplinesY, BSplinesZ, T>
164 */
165 template <
166 class BatchedInterpolationDDom,
167 class = std::enable_if_t<ddc::is_discrete_domain_v<BatchedInterpolationDDom>>>
168 using batched_spline_domain_type
169 = ddc::detail::convert_type_seq_to_discrete_domain_t<ddc::type_seq_replace_t<
170 ddc::to_type_seq_t<BatchedInterpolationDDom>,
171 ddc::detail::TypeSeq<
172 interpolation_discrete_dimension_type1,
173 interpolation_discrete_dimension_type2,
174 interpolation_discrete_dimension_type3>,
175 ddc::detail::TypeSeq<bsplines_type1, bsplines_type2, bsplines_type3>>>;
176
177 /**
178 * @brief The type of the whole Derivs domain (cartesian product of the 1D Deriv domain
179 * and the associated batch domain) in the first dimension, preserving the order of dimensions.
180 *
181 * @tparam The batched discrete domain on which the interpolation points are defined.
182 *
183 * Example: For batched_interpolation_domain_type = DiscreteDomain<X,Y,Z,T> and dimensions of interest X, Y and Z,
184 * this is DiscreteDomain<Deriv<X>, Y, Z, T>.
185 */
186 template <
187 class BatchedInterpolationDDom,
188 class = std::enable_if_t<ddc::is_discrete_domain_v<BatchedInterpolationDDom>>>
189 using batched_derivs_domain_type1 =
190 typename builder_type1::template batched_derivs_domain_type<BatchedInterpolationDDom>;
191
192 /**
193 * @brief The type of the whole Derivs domain (cartesian product of the 1D Deriv domain
194 * and the associated batch domain) in the second dimension, preserving the order of dimensions.
195 *
196 * @tparam The batched discrete domain on which the interpolation points are defined.
197 *
198 * Example: For batched_interpolation_domain_type = DiscreteDomain<X,Y,Z,T> and dimensions of interest X, Y, and Z
199 * this is DiscreteDomain<X, Deriv<Y>, Z, T>.
200 */
201 template <
202 class BatchedInterpolationDDom,
203 class = std::enable_if_t<ddc::is_discrete_domain_v<BatchedInterpolationDDom>>>
204 using batched_derivs_domain_type2 = ddc::replace_dim_of_t<
205 BatchedInterpolationDDom,
206 interpolation_discrete_dimension_type2,
207 deriv_type2>;
208
209 /**
210 * @brief The type of the whole Derivs domain (cartesian product of the 1D Deriv domain
211 * and the associated batch domain) in the third dimension, preserving the order of dimensions.
212 *
213 * @tparam The batched discrete domain on which the interpolation points are defined.
214 *
215 * Example: For batched_interpolation_domain_type = DiscreteDomain<X,Y,Z,T> and dimensions of interest X, Y, and Z
216 * this is DiscreteDomain<X, Y, Deriv<Z>, T>.
217 */
218 template <
219 class BatchedInterpolationDDom,
220 class = std::enable_if_t<ddc::is_discrete_domain_v<BatchedInterpolationDDom>>>
221 using batched_derivs_domain_type3 = ddc::replace_dim_of_t<
222 BatchedInterpolationDDom,
223 interpolation_discrete_dimension_type3,
224 deriv_type3>;
225
226 /**
227 * @brief The type of the whole Derivs domain (cartesian product of the 3D Deriv domain
228 * and the batch domain), preserving the order of dimensions.
229 *
230 * @tparam The batched discrete domain on which the interpolation points are defined.
231 *
232 * Example: For batched_interpolation_domain_type = DiscreteDomain<X,Y,Z,T> and dimensions of interest X, Y and Z,
233 * this is DiscreteDomain<Deriv<X>, Deriv<Y>, Deriv<Z>, T>.
234 */
235 template <
236 class BatchedInterpolationDDom,
237 class = std::enable_if_t<ddc::is_discrete_domain_v<BatchedInterpolationDDom>>>
238 using batched_derivs_domain_type
239 = ddc::detail::convert_type_seq_to_discrete_domain_t<ddc::type_seq_replace_t<
240 ddc::to_type_seq_t<BatchedInterpolationDDom>,
241 ddc::detail::TypeSeq<
242 interpolation_discrete_dimension_type1,
243 interpolation_discrete_dimension_type2,
244 interpolation_discrete_dimension_type3>,
245 ddc::detail::TypeSeq<deriv_type1, deriv_type2, deriv_type3>>>;
246
247private:
248 builder_type1 m_spline_builder1;
249 builder_type2 m_spline_builder2;
250 builder_type3 m_spline_builder3;
251 builder_deriv_type1 m_spline_builder_deriv1;
252 builder_deriv_type2 m_spline_builder_deriv2;
253
254public:
255 /**
256 * @brief Build a SplineBuilder3D acting on interpolation_domain.
257 *
258 * @param interpolation_domain The domain on which the interpolation points are defined, without the batch dimensions.
259 *
260 * @param cols_per_chunk A parameter used by the slicer (internal to the solver) to define the size
261 * of a chunk of right-hand-sides of the linear problem to be computed in parallel (chunks are treated
262 * by the linear solver one-after-the-other).
263 * This value is optional. If no value is provided then the default value is chosen by the requested solver.
264 *
265 * @param preconditioner_max_block_size A parameter used by the slicer (internal to the solver) to
266 * define the size of a block used by the Block-Jacobi preconditioner.
267 * This value is optional. If no value is provided then the default value is chosen by the requested solver.
268 *
269 * @see SplinesLinearProblemSparse
270 */
271 explicit SplineBuilder3D(
272 interpolation_domain_type const& interpolation_domain,
273 std::optional<std::size_t> cols_per_chunk = std::nullopt,
274 std::optional<unsigned int> preconditioner_max_block_size = std::nullopt)
275 : m_spline_builder1(interpolation_domain, cols_per_chunk, preconditioner_max_block_size)
276 , m_spline_builder2(interpolation_domain, cols_per_chunk, preconditioner_max_block_size)
277 , m_spline_builder3(interpolation_domain, cols_per_chunk, preconditioner_max_block_size)
278 , m_spline_builder_deriv1(interpolation_domain)
279 , m_spline_builder_deriv2(interpolation_domain)
280 {
281 }
282
283 /**
284 * @brief Build a SplineBuilder3D acting on the interpolation domain contained in batched_interpolation_domain.
285 *
286 * @param batched_interpolation_domain The domain on which the interpolation points are defined.
287 *
288 * @param cols_per_chunk A parameter used by the slicer (internal to the solver) to define the size
289 * of a chunk of right-hand-sides of the linear problem to be computed in parallel (chunks are treated
290 * by the linear solver one-after-the-other).
291 * This value is optional. If no value is provided then the default value is chosen by the requested solver.
292 *
293 * @param preconditioner_max_block_size A parameter used by the slicer (internal to the solver) to
294 * define the size of a block used by the Block-Jacobi preconditioner.
295 * This value is optional. If no value is provided then the default value is chosen by the requested solver.
296 *
297 * @see SplinesLinearProblemSparse
298 */
299 template <
300 class BatchedInterpolationDDom,
301 class = std::enable_if_t<ddc::is_discrete_domain_v<BatchedInterpolationDDom>>>
302 explicit SplineBuilder3D(
303 BatchedInterpolationDDom const& batched_interpolation_domain,
304 std::optional<std::size_t> cols_per_chunk = std::nullopt,
305 std::optional<unsigned int> preconditioner_max_block_size = std::nullopt)
307 interpolation_domain_type(batched_interpolation_domain),
308 cols_per_chunk,
309 preconditioner_max_block_size)
310 {
311 }
312
313 /// @brief Copy-constructor is deleted.
314 SplineBuilder3D(SplineBuilder3D const& x) = delete;
315
316 /**
317 * @brief Move-constructs.
318 *
319 * @param x An rvalue to another SplineBuilder3D.
320 */
321 SplineBuilder3D(SplineBuilder3D&& x) = default;
322
323 /// @brief Destructs.
324 ~SplineBuilder3D() = default;
325
326 /// @brief Copy-assignment is deleted.
327 SplineBuilder3D& operator=(SplineBuilder3D const& x) = delete;
328
329 /** @brief Move-assigns.
330 *
331 * @param x An rvalue to another SplineBuilder.
332 * @return A reference to this object.
333 */
335
336 /**
337 * @brief Get the domain for the 3D interpolation mesh used by this class.
338 *
339 * This is 3D because it is defined along the dimensions of interest.
340 *
341 * @return The 3D domain for the interpolation mesh.
342 */
343 interpolation_domain_type interpolation_domain() const noexcept
344 {
345 return ddc::DiscreteDomain<
346 interpolation_domain_type1,
347 interpolation_domain_type2,
348 interpolation_domain_type3>(
349 m_spline_builder1.interpolation_domain(),
350 m_spline_builder2.interpolation_domain(),
351 m_spline_builder3.interpolation_domain());
352 }
353
354 /**
355 * @brief Get the whole domain representing interpolation points.
356 *
357 * Values of the function must be provided on this domain in order
358 * to build a spline representation of the function (cartesian product of 3D interpolation_domain and batch_domain).
359 *
360 * @param batched_interpolation_domain The whole domain on which the interpolation points are defined.
361 *
362 * @return The domain for the interpolation mesh.
363 */
364 template <
365 class BatchedInterpolationDDom,
366 class = std::enable_if_t<ddc::is_discrete_domain_v<BatchedInterpolationDDom>>>
367 BatchedInterpolationDDom batched_interpolation_domain(
368 BatchedInterpolationDDom const& batched_interpolation_domain) const noexcept
369 {
370 assert(interpolation_domain() == interpolation_domain_type(batched_interpolation_domain));
371 return batched_interpolation_domain;
372 }
373
374 /**
375 * @brief Get the batch domain.
376 *
377 * Obtained by removing the dimensions of interest from the whole interpolation domain.
378 *
379 * @param batched_interpolation_domain The whole domain on which the interpolation points are defined.
380 *
381 * @return The batch domain.
382 */
383 template <
384 class BatchedInterpolationDDom,
385 class = std::enable_if_t<ddc::is_discrete_domain_v<BatchedInterpolationDDom>>>
386 batch_domain_type<BatchedInterpolationDDom> batch_domain(
387 BatchedInterpolationDDom const& batched_interpolation_domain) const noexcept
388 {
389 assert(interpolation_domain() == interpolation_domain_type(batched_interpolation_domain));
390 return ddc::remove_dims_of(batched_interpolation_domain, interpolation_domain());
391 }
392
393 /**
394 * @brief Get the 3D domain on which spline coefficients are defined.
395 *
396 * The 3D spline domain corresponding to the dimensions of interest.
397 *
398 * @return The 3D domain for the spline coefficients.
399 */
400 ddc::DiscreteDomain<bsplines_type1, bsplines_type2, bsplines_type3> spline_domain()
401 const noexcept
402 {
403 return ddc::DiscreteDomain<bsplines_type1, bsplines_type2, bsplines_type3>(
404 ddc::discrete_space<bsplines_type1>().full_domain(),
405 ddc::discrete_space<bsplines_type2>().full_domain(),
406 ddc::discrete_space<bsplines_type3>().full_domain());
407 }
408
409 /**
410 * @brief Get the whole domain on which spline coefficients are defined.
411 *
412 * Spline approximations (spline-transformed functions) are computed on this domain.
413 *
414 * @param batched_interpolation_domain The whole domain on which the interpolation points are defined.
415 *
416 * @return The domain for the spline coefficients.
417 */
418 template <
419 class BatchedInterpolationDDom,
420 class = std::enable_if_t<ddc::is_discrete_domain_v<BatchedInterpolationDDom>>>
421 batched_spline_domain_type<BatchedInterpolationDDom> batched_spline_domain(
422 BatchedInterpolationDDom const& batched_interpolation_domain) const noexcept
423 {
424 assert(interpolation_domain() == interpolation_domain_type(batched_interpolation_domain));
425 return ddc::replace_dim_of<interpolation_discrete_dimension_type1, bsplines_type1>(
426 ddc::replace_dim_of<interpolation_discrete_dimension_type2, bsplines_type2>(
427 ddc::replace_dim_of<
428 interpolation_discrete_dimension_type3,
429 bsplines_type3>(batched_interpolation_domain, spline_domain()),
432 }
433
434 /**
435 * @brief Compute a 3D spline approximation of a function.
436 *
437 * Use the values of a function (defined on
438 * SplineBuilder3D::batched_interpolation_domain) and the derivatives of the
439 * function at the boundaries (in the case of BoundCond::HERMITE only)
440 * to calculate a 3D spline approximation of this function.
441 *
442 * The spline approximation is stored as a ChunkSpan of coefficients
443 * associated with B-splines.
444 *
445 * @param[out] spline
446 * The coefficients of the spline computed by this SplineBuilder.
447 * @param[in] vals
448 * The values of the function at the interpolation mesh.
449 * @param[in] derivs_min1
450 * The values of the derivatives at the lower boundary in the first dimension.
451 * @param[in] derivs_max1
452 * The values of the derivatives at the upper boundary in the first dimension.
453 * @param[in] derivs_min2
454 * The values of the derivatives at the lower boundary in the second dimension.
455 * @param[in] derivs_max2
456 * The values of the derivatives at the upper boundary in the second dimension.
457 * @param[in] derivs_min3
458 * The values of the derivatives at the lower boundary in the third dimension.
459 * @param[in] derivs_max3
460 * The values of the derivatives at the upper boundary in the third dimension.
461 * @param[in] mixed_derivs_min1_min2_min3
462 * The values of the the cross-derivatives at the lower boundary in the first dimension, the lower boundary in the second dimension and the lower boundary in the third dimension.
463 * @param[in] mixed_derivs_max1_min2_min3
464 * The values of the the cross-derivatives at the upper boundary in the first dimension, the lower boundary in the second dimension and the lower boundary in the third dimension.
465 * @param[in] mixed_derivs_min1_max2_min3
466 * The values of the the cross-derivatives at the lower boundary in the first dimension, the upper boundary in the second dimension and the lower boundary in the third dimension.
467 * @param[in] mixed_derivs_max1_max2_min3
468 * The values of the the cross-derivatives at the upper boundary in the first dimension, the upper boundary in the second dimension and the lower boundary in the third dimension.
469 * @param[in] mixed_derivs_min1_min2_max3
470 * The values of the the cross-derivatives at the lower boundary in the first dimension, the lower boundary in the second dimension and the upper boundary in the third dimension.
471 * @param[in] mixed_derivs_max1_min2_max3
472 * The values of the the cross-derivatives at the upper boundary in the first dimension, the lower boundary in the second dimension and the upper boundary in the third dimension.
473 * @param[in] mixed_derivs_min1_max2_max3
474 * The values of the the cross-derivatives at the lower boundary in the first dimension, the upper boundary in the second dimension and the upper boundary in the third dimension.
475 * @param[in] mixed_derivs_max1_max2_max3
476 * The values of the the cross-derivatives at the upper boundary in the first dimension, the upper boundary in the second dimension and the upper boundary in the third dimension.
477 */
478 template <class Layout, class BatchedInterpolationDDom>
479 void operator()(
480 ddc::ChunkSpan<
481 double,
482 batched_spline_domain_type<BatchedInterpolationDDom>,
483 Layout,
484 memory_space> spline,
485 ddc::ChunkSpan<double const, BatchedInterpolationDDom, Layout, memory_space> vals,
486 std::optional<ddc::ChunkSpan<
487 double const,
488 batched_derivs_domain_type1<BatchedInterpolationDDom>,
489 Layout,
490 memory_space>> derivs_min1
491 = std::nullopt,
492 std::optional<ddc::ChunkSpan<
493 double const,
494 batched_derivs_domain_type1<BatchedInterpolationDDom>,
495 Layout,
496 memory_space>> derivs_max1
497 = std::nullopt,
498 std::optional<ddc::ChunkSpan<
499 double const,
500 batched_derivs_domain_type2<BatchedInterpolationDDom>,
501 Layout,
502 memory_space>> derivs_min2
503 = std::nullopt,
504 std::optional<ddc::ChunkSpan<
505 double const,
506 batched_derivs_domain_type2<BatchedInterpolationDDom>,
507 Layout,
508 memory_space>> derivs_max2
509 = std::nullopt,
510 std::optional<ddc::ChunkSpan<
511 double const,
512 batched_derivs_domain_type3<BatchedInterpolationDDom>,
513 Layout,
514 memory_space>> derivs_min3
515 = std::nullopt,
516 std::optional<ddc::ChunkSpan<
517 double const,
518 batched_derivs_domain_type3<BatchedInterpolationDDom>,
519 Layout,
520 memory_space>> derivs_max3
521 = std::nullopt,
522 std::optional<ddc::ChunkSpan<
523 double const,
524 batched_derivs_domain_type<BatchedInterpolationDDom>,
525 Layout,
526 memory_space>> mixed_derivs_min1_min2_min3
527 = std::nullopt,
528 std::optional<ddc::ChunkSpan<
529 double const,
530 batched_derivs_domain_type<BatchedInterpolationDDom>,
531 Layout,
532 memory_space>> mixed_derivs_max1_min2_min3
533 = std::nullopt,
534 std::optional<ddc::ChunkSpan<
535 double const,
536 batched_derivs_domain_type<BatchedInterpolationDDom>,
537 Layout,
538 memory_space>> mixed_derivs_min1_max2_min3
539 = std::nullopt,
540 std::optional<ddc::ChunkSpan<
541 double const,
542 batched_derivs_domain_type<BatchedInterpolationDDom>,
543 Layout,
544 memory_space>> mixed_derivs_max1_max2_min3
545 = std::nullopt,
546 std::optional<ddc::ChunkSpan<
547 double const,
548 batched_derivs_domain_type<BatchedInterpolationDDom>,
549 Layout,
550 memory_space>> mixed_derivs_min1_min2_max3
551 = std::nullopt,
552 std::optional<ddc::ChunkSpan<
553 double const,
554 batched_derivs_domain_type<BatchedInterpolationDDom>,
555 Layout,
556 memory_space>> mixed_derivs_max1_min2_max3
557 = std::nullopt,
558 std::optional<ddc::ChunkSpan<
559 double const,
560 batched_derivs_domain_type<BatchedInterpolationDDom>,
561 Layout,
562 memory_space>> mixed_derivs_min1_max2_max3
563 = std::nullopt,
564 std::optional<ddc::ChunkSpan<
565 double const,
566 batched_derivs_domain_type<BatchedInterpolationDDom>,
567 Layout,
568 memory_space>> mixed_derivs_max1_max2_max3
569 = std::nullopt) const;
570};
571
572
573template <
574 class ExecSpace,
575 class MemorySpace,
576 class BSpline1,
577 class BSpline2,
578 class BSpline3,
579 class DDimI1,
580 class DDimI2,
581 class DDimI3,
589template <class Layout, class BatchedInterpolationDDom>
590void SplineBuilder3D<
591 ExecSpace,
592 MemorySpace,
593 BSpline1,
594 BSpline2,
595 BSpline3,
596 DDimI1,
597 DDimI2,
598 DDimI3,
599 BcLower1,
600 BcUpper1,
601 BcLower2,
602 BcUpper2,
603 BcLower3,
604 BcUpper3,
605 Solver>::
606operator()(
607 ddc::ChunkSpan<
608 double,
609 batched_spline_domain_type<BatchedInterpolationDDom>,
610 Layout,
611 memory_space> spline,
612 ddc::ChunkSpan<double const, BatchedInterpolationDDom, Layout, memory_space> vals,
613 [[maybe_unused]] std::optional<ddc::ChunkSpan<
614 double const,
615 batched_derivs_domain_type1<BatchedInterpolationDDom>,
616 Layout,
617 memory_space>> derivs_min1,
618 [[maybe_unused]] std::optional<ddc::ChunkSpan<
619 double const,
620 batched_derivs_domain_type1<BatchedInterpolationDDom>,
621 Layout,
622 memory_space>> derivs_max1,
623 [[maybe_unused]] std::optional<ddc::ChunkSpan<
624 double const,
625 batched_derivs_domain_type2<BatchedInterpolationDDom>,
626 Layout,
627 memory_space>> derivs_min2,
628 [[maybe_unused]] std::optional<ddc::ChunkSpan<
629 double const,
630 batched_derivs_domain_type2<BatchedInterpolationDDom>,
631 Layout,
632 memory_space>> derivs_max2,
633 [[maybe_unused]] std::optional<ddc::ChunkSpan<
634 double const,
635 batched_derivs_domain_type3<BatchedInterpolationDDom>,
636 Layout,
637 memory_space>> derivs_min3,
638 [[maybe_unused]] std::optional<ddc::ChunkSpan<
639 double const,
640 batched_derivs_domain_type3<BatchedInterpolationDDom>,
641 Layout,
642 memory_space>> derivs_max3,
643 [[maybe_unused]] std::optional<ddc::ChunkSpan<
644 double const,
645 batched_derivs_domain_type<BatchedInterpolationDDom>,
646 Layout,
647 memory_space>> mixed_derivs_min1_min2_min3,
648 [[maybe_unused]] std::optional<ddc::ChunkSpan<
649 double const,
650 batched_derivs_domain_type<BatchedInterpolationDDom>,
651 Layout,
652 memory_space>> mixed_derivs_max1_min2_min3,
653 [[maybe_unused]] std::optional<ddc::ChunkSpan<
654 double const,
655 batched_derivs_domain_type<BatchedInterpolationDDom>,
656 Layout,
657 memory_space>> mixed_derivs_min1_max2_min3,
658 [[maybe_unused]] std::optional<ddc::ChunkSpan<
659 double const,
660 batched_derivs_domain_type<BatchedInterpolationDDom>,
661 Layout,
662 memory_space>> mixed_derivs_max1_max2_min3,
663 [[maybe_unused]] std::optional<ddc::ChunkSpan<
664 double const,
665 batched_derivs_domain_type<BatchedInterpolationDDom>,
666 Layout,
667 memory_space>> mixed_derivs_min1_min2_max3,
668 [[maybe_unused]] std::optional<ddc::ChunkSpan<
669 double const,
670 batched_derivs_domain_type<BatchedInterpolationDDom>,
671 Layout,
672 memory_space>> mixed_derivs_max1_min2_max3,
673 [[maybe_unused]] std::optional<ddc::ChunkSpan<
674 double const,
675 batched_derivs_domain_type<BatchedInterpolationDDom>,
676 Layout,
677 memory_space>> mixed_derivs_min1_max2_max3,
678 [[maybe_unused]] std::optional<ddc::ChunkSpan<
679 double const,
680 batched_derivs_domain_type<BatchedInterpolationDDom>,
681 Layout,
682 memory_space>> mixed_derivs_max1_max2_max3) const
683{
684 auto const batched_interpolation_domain = vals.domain();
685
686 assert(interpolation_domain() == interpolation_domain_type(batched_interpolation_domain));
687
688 // Spline1-approximate vals (to spline1)
689 ddc::Chunk spline1_alloc(
690 m_spline_builder1.batched_spline_domain(batched_interpolation_domain),
691 ddc::KokkosAllocator<double, MemorySpace>());
692 ddc::ChunkSpan const spline1 = spline1_alloc.span_view();
693
694 m_spline_builder1(spline1, vals);
695
696 // Spline2-approximate spline1 (to spline2)
697 ddc::Chunk spline2_alloc(
698 m_spline_builder2.batched_spline_domain(spline1.domain()),
699 ddc::KokkosAllocator<double, MemorySpace>());
700 ddc::ChunkSpan const spline2 = spline2_alloc.span_view();
701
702 m_spline_builder2(spline2, spline1.span_cview());
703
704 // Spline3-approximate spline2
705 m_spline_builder3(spline, spline2.span_cview());
706}
707
708} // namespace ddc
friend class ChunkSpan
friend class Chunk
Definition chunk.hpp:81
friend class DiscreteDomain
A class for creating a 3D spline approximation of a function.
SplineBuilder3D(SplineBuilder3D const &x)=delete
Copy-constructor is deleted.
~SplineBuilder3D()=default
Destructs.
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.
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.
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 & operator=(SplineBuilder3D const &x)=delete
Copy-assignment is deleted.
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(SplineBuilder3D &&x)=default
Move-constructs.
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_type3< BatchedInterpolationDDom >, Layout, memory_space > > derivs_min3=std::nullopt, std::optional< ddc::ChunkSpan< double const, batched_derivs_domain_type3< BatchedInterpolationDDom >, Layout, memory_space > > derivs_max3=std::nullopt, std::optional< ddc::ChunkSpan< double const, batched_derivs_domain_type< BatchedInterpolationDDom >, Layout, memory_space > > mixed_derivs_min1_min2_min3=std::nullopt, std::optional< ddc::ChunkSpan< double const, batched_derivs_domain_type< BatchedInterpolationDDom >, Layout, memory_space > > mixed_derivs_max1_min2_min3=std::nullopt, std::optional< ddc::ChunkSpan< double const, batched_derivs_domain_type< BatchedInterpolationDDom >, Layout, memory_space > > mixed_derivs_min1_max2_min3=std::nullopt, std::optional< ddc::ChunkSpan< double const, batched_derivs_domain_type< BatchedInterpolationDDom >, Layout, memory_space > > mixed_derivs_max1_max2_min3=std::nullopt, std::optional< ddc::ChunkSpan< double const, batched_derivs_domain_type< BatchedInterpolationDDom >, Layout, memory_space > > mixed_derivs_min1_min2_max3=std::nullopt, std::optional< ddc::ChunkSpan< double const, batched_derivs_domain_type< BatchedInterpolationDDom >, Layout, memory_space > > mixed_derivs_max1_min2_max3=std::nullopt, std::optional< ddc::ChunkSpan< double const, batched_derivs_domain_type< BatchedInterpolationDDom >, Layout, memory_space > > mixed_derivs_min1_max2_max3=std::nullopt, std::optional< ddc::ChunkSpan< double 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.
BatchedInterpolationDDom batched_interpolation_domain(BatchedInterpolationDDom const &batched_interpolation_domain) const noexcept
Get the whole domain representing interpolation points.
SplineBuilder3D & operator=(SplineBuilder3D &&x)=default
Move-assigns.
A class for creating a spline approximation of a function.
The top-level namespace of DDC.
BoundCond
An enum representing a spline boundary condition.
SplineSolver
An enum determining the backend solver of a SplineBuilder or SplineBuilder2d.