DDC 0.0.0

a discrete domain computation library

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 "spline_builder.hpp"
8
9namespace ddc {
10
19template <
20 class ExecSpace,
21 class MemorySpace,
22 class BSpline1,
23 class BSpline2,
24 class IDimI1,
25 class IDimI2,
31 class... IDimX>
33{
34public:
36
38
43 IDimI1,
44 BcXmin1,
45 BcXmax1,
46 Solver,
47 IDimX...>;
52 IDimI2,
53 BcXmin2,
54 BcXmax2,
55 Solver,
56 std::conditional_t<std::is_same_v<IDimX, IDimI1>, BSpline1, IDimX>...>;
61 IDimI1,
62 BcXmin1,
63 BcXmax1,
64 Solver,
65 std::conditional_t<
66 std::is_same_v<IDimX, IDimI2>,
68 IDimX>...>;
69
70private:
74 using tag_type1 = typename builder_type1::bsplines_type::tag_type;
78 using tag_type2 = typename builder_type2::bsplines_type::tag_type;
79
80public:
89
92
101
119 = ddc::detail::convert_type_seq_to_discrete_domain<ddc::type_seq_remove_t<
120 ddc::detail::TypeSeq<IDimX...>,
121 ddc::detail::TypeSeq<interpolation_mesh_type1, interpolation_mesh_type2>>>;
122
124 = ddc::detail::convert_type_seq_to_discrete_domain<ddc::type_seq_replace_t<
125 ddc::detail::TypeSeq<IDimX...>,
126 ddc::detail::TypeSeq<interpolation_mesh_type1, interpolation_mesh_type2>,
127 ddc::detail::TypeSeq<bsplines_type1, bsplines_type2>>>;
128
131 = ddc::detail::convert_type_seq_to_discrete_domain<ddc::type_seq_replace_t<
132 ddc::detail::TypeSeq<IDimX...>,
133 ddc::detail::TypeSeq<interpolation_mesh_type2>,
134 ddc::detail::TypeSeq<deriv_type2>>>;
136 = ddc::detail::convert_type_seq_to_discrete_domain<ddc::type_seq_replace_t<
137 ddc::detail::TypeSeq<IDimX...>,
138 ddc::detail::TypeSeq<interpolation_mesh_type1, interpolation_mesh_type2>,
139 ddc::detail::TypeSeq<deriv_type1, deriv_type2>>>;
140
141private:
142 builder_type1 m_spline_builder1;
143 builder_deriv_type1 m_spline_builder_deriv1;
144 builder_type2 m_spline_builder2;
145
146public:
156 explicit SplineBuilder2D(
158 std::optional<int> cols_per_chunk = std::nullopt,
159 std::optional<unsigned int> preconditionner_max_block_size = std::nullopt)
160 : m_spline_builder1(
164 , m_spline_builder_deriv1(ddc::replace_dim_of<interpolation_mesh_type2, deriv_type2>(
165 m_spline_builder1.batched_interpolation_domain(),
168 ddc::DiscreteVector<deriv_type2>(bsplines_type2::degree() / 2))))
169 , m_spline_builder2(
170 m_spline_builder1.batched_spline_domain(),
173 {
174 }
175
182 SplineBuilder2D(SplineBuilder2D const& x) = delete;
183
190 SplineBuilder2D(SplineBuilder2D&& x) = default;
191
192 ~SplineBuilder2D() = default;
193
194 SplineBuilder2D& operator=(SplineBuilder2D const& x) = delete;
195
196
205
207 {
208 return m_spline_builder1.batched_interpolation_domain();
209 }
210
220 {
225
227 {
229 }
230
240 const noexcept // TODO : clarify name
241 {
253 spline_domain());
254 }
255
292 template <class Layout>
293 void operator()(
296 vals,
297 std::optional<ddc::ChunkSpan<
298 double const,
300 Layout,
302 = std::nullopt,
303 std::optional<ddc::ChunkSpan<
304 double const,
306 Layout,
308 = std::nullopt,
309 std::optional<ddc::ChunkSpan<
310 double const,
312 Layout,
314 = std::nullopt,
315 std::optional<ddc::ChunkSpan<
316 double const,
318 Layout,
320 = std::nullopt,
321 std::optional<ddc::ChunkSpan<
322 double const,
324 Layout,
326 = std::nullopt,
327 std::optional<ddc::ChunkSpan<
328 double const,
330 Layout,
332 = std::nullopt,
333 std::optional<ddc::ChunkSpan<
334 double const,
336 Layout,
338 = std::nullopt,
339 std::optional<ddc::ChunkSpan<
340 double const,
342 Layout,
344 = std::nullopt) const;
345};
346
347
348template <
349 class ExecSpace,
350 class MemorySpace,
351 class BSpline1,
352 class BSpline2,
353 class IDimI1,
354 class IDimI2,
360 class... IDimX>
361template <class Layout>
362void SplineBuilder2D<
363 ExecSpace,
365 BSpline1,
366 BSpline2,
367 IDimI1,
368 IDimI2,
369 BcXmin1,
370 BcXmax1,
371 BcXmin2,
372 BcXmax2,
373 Solver,
375operator()(
378 std::optional<ddc::ChunkSpan<
379 double const,
381 Layout,
383 std::optional<ddc::ChunkSpan<
384 double const,
386 Layout,
388 std::optional<ddc::ChunkSpan<
389 double const,
391 Layout,
393 std::optional<ddc::ChunkSpan<
394 double const,
396 Layout,
398 std::optional<ddc::ChunkSpan<
399 double const,
401 Layout,
403 std::optional<ddc::ChunkSpan<
404 double const,
406 Layout,
408 std::optional<ddc::ChunkSpan<
409 double const,
411 Layout,
413 std::optional<ddc::ChunkSpan<
414 double const,
416 Layout,
418{
419 // TODO: perform computations along dimension 1 on different streams ?
420 // Spline1-transform derivs_min2 (to spline1_deriv_min)
422 m_spline_builder_deriv1.batched_spline_domain(),
425 auto spline1_deriv_min_opt = std::optional(spline1_deriv_min.span_cview());
426 if constexpr (BcXmin2 == ddc::BoundCond::HERMITE) {
427 m_spline_builder_deriv1(
432 } else {
433 spline1_deriv_min_opt = std::nullopt;
434 }
435
436 // Spline1-transform vals (to spline1)
438 m_spline_builder1.batched_spline_domain(),
441
442 m_spline_builder1(spline1, vals, derivs_min1, derivs_max1);
443
444 // Spline1-transform derivs_max2 (to spline1_deriv_max)
446 m_spline_builder_deriv1.batched_spline_domain(),
449 auto spline1_deriv_max_opt = std::optional(spline1_deriv_max.span_cview());
450 if constexpr (BcXmax2 == ddc::BoundCond::HERMITE) {
451 m_spline_builder_deriv1(
456 } else {
457 spline1_deriv_max_opt = std::nullopt;
458 }
459
460 // Spline2-transform spline1
461 m_spline_builder2(spline, spline1.span_cview(), spline1_deriv_min_opt, spline1_deriv_max_opt);
462}
463} // namespace ddc
Definition discrete_domain.hpp:51
A DiscreteElement identifies an element of the discrete dimension.
Definition discrete_element.hpp:146
A DiscreteVector is a vector in the discrete dimension.
Definition discrete_vector.hpp:254
Definition kokkos_allocator.hpp:17
A class for creating a 2D spline approximation of a function.
Definition spline_builder_2d.hpp:33
SplineBuilder2D(batched_interpolation_domain_type const &batched_interpolation_domain, std::optional< int > cols_per_chunk=std::nullopt, std::optional< unsigned int > preconditionner_max_block_size=std::nullopt)
Create a new SplineBuilder2D.
Definition spline_builder_2d.hpp:151
ddc::detail::convert_type_seq_to_discrete_domain< ddc::type_seq_replace_t< ddc::detail::TypeSeq< IDimX... >, ddc::detail::TypeSeq< interpolation_mesh_type1, interpolation_mesh_type2 >, ddc::detail::TypeSeq< deriv_type1, deriv_type2 > > > batched_derivs_domain_type
Definition spline_builder_2d.hpp:131
batched_spline_domain_type batched_spline_domain() const noexcept
Definition spline_builder_2d.hpp:242
interpolation_domain_type interpolation_domain() const noexcept
Get the 2D dimension domain from which the approximation is defined.
Definition spline_builder_2d.hpp:214
batched_interpolation_domain_type batched_interpolation_domain() const noexcept
Definition spline_builder_2d.hpp:201
typename builder_type1::deriv_type deriv_type1
Definition spline_builder_2d.hpp:90
ddc::detail::convert_type_seq_to_discrete_domain< ddc::type_seq_replace_t< ddc::detail::TypeSeq< IDimX... >, ddc::detail::TypeSeq< interpolation_mesh_type1, interpolation_mesh_type2 >, ddc::detail::TypeSeq< bsplines_type1, bsplines_type2 > > > batched_spline_domain_type
Definition spline_builder_2d.hpp:121
typename builder_type2::interpolation_mesh_type interpolation_mesh_type2
The type of the interpolation mesh in the second dimension used by this class.
Definition spline_builder_2d.hpp:100
ExecSpace exec_space
Definition spline_builder_2d.hpp:35
ddc::detail::convert_type_seq_to_discrete_domain< ddc::type_seq_replace_t< ddc::detail::TypeSeq< IDimX... >, ddc::detail::TypeSeq< interpolation_mesh_type2 >, ddc::detail::TypeSeq< deriv_type2 > > > batched_derivs_domain_type2
Definition spline_builder_2d.hpp:127
typename builder_type1::batched_derivs_domain_type batched_derivs_domain_type1
Definition spline_builder_2d.hpp:126
~SplineBuilder2D()=default
void operator()(ddc::ChunkSpan< double, batched_spline_domain_type, Layout, memory_space > spline, ddc::ChunkSpan< double const, batched_interpolation_domain_type, Layout, memory_space > vals, std::optional< ddc::ChunkSpan< double const, batched_derivs_domain_type1, Layout, memory_space > > const derivs_min1=std::nullopt, std::optional< ddc::ChunkSpan< double const, batched_derivs_domain_type1, Layout, memory_space > > const derivs_max1=std::nullopt, std::optional< ddc::ChunkSpan< double const, batched_derivs_domain_type2, Layout, memory_space > > const derivs_min2=std::nullopt, std::optional< ddc::ChunkSpan< double const, batched_derivs_domain_type2, Layout, memory_space > > const derivs_max2=std::nullopt, std::optional< ddc::ChunkSpan< double const, batched_derivs_domain_type, Layout, memory_space > > const mixed_derivs_min1_min2=std::nullopt, std::optional< ddc::ChunkSpan< double const, batched_derivs_domain_type, Layout, memory_space > > const mixed_derivs_max1_min2=std::nullopt, std::optional< ddc::ChunkSpan< double const, batched_derivs_domain_type, Layout, memory_space > > const mixed_derivs_min1_max2=std::nullopt, std::optional< ddc::ChunkSpan< double const, batched_derivs_domain_type, Layout, memory_space > > const mixed_derivs_max1_max2=std::nullopt) const
Build a 2D spline approximation of a function.
Definition spline_builder_2d.hpp:375
ddc::DiscreteDomain< IDimX... > batched_interpolation_domain_type
Definition spline_builder_2d.hpp:115
batch_domain_type batch_domain() const noexcept
Definition spline_builder_2d.hpp:221
typename builder_type2::deriv_type deriv_type2
Definition spline_builder_2d.hpp:91
typename builder_type1::interpolation_mesh_type interpolation_mesh_type1
The type of the interpolation mesh in the first dimension used by this class.
Definition spline_builder_2d.hpp:96
typename builder_type2::interpolation_mesh_type interpolation_domain_type2
The type of the domain for the interpolation mesh is the second dimension used by this class.
Definition spline_builder_2d.hpp:109
typename builder_type2::bsplines_type bsplines_type2
The type of the BSplines in the second dimension which are compatible with this class.
Definition spline_builder_2d.hpp:88
ddc::DiscreteDomain< bsplines_type1, bsplines_type2 > spline_domain() const noexcept
Get the 2D domain on which the approximation is defined.
Definition spline_builder_2d.hpp:234
MemorySpace memory_space
Definition spline_builder_2d.hpp:37
ddc::detail::convert_type_seq_to_discrete_domain< ddc::type_seq_remove_t< ddc::detail::TypeSeq< IDimX... >, ddc::detail::TypeSeq< interpolation_mesh_type1, interpolation_mesh_type2 > > > batch_domain_type
Definition spline_builder_2d.hpp:117
ddc::DiscreteDomain< interpolation_mesh_type1, interpolation_mesh_type2 > interpolation_domain_type
The type of the domain for the interpolation mesh is the 2D dimension used by this class.
Definition spline_builder_2d.hpp:113
SplineBuilder2D & operator=(SplineBuilder2D const &x)=delete
typename builder_type1::bsplines_type bsplines_type1
The type of the BSplines in the first dimension which are compatible with this class.
Definition spline_builder_2d.hpp:84
typename builder_type1::interpolation_mesh_type interpolation_domain_type1
The type of the domain for the interpolation mesh is the first dimension used by this class.
Definition spline_builder_2d.hpp:105
batched_interpolation_domain_type batched_interpolation_domain() const noexcept
Definition spline_builder.hpp:193
interpolation_domain_type interpolation_domain() const noexcept
Get the domain from which the approximation is defined.
Definition spline_builder.hpp:206
batched_spline_domain_type batched_spline_domain() const noexcept
Get the domain on which the approximation is defined.
Definition spline_builder.hpp:229
IDimI1 interpolation_mesh_type
The type of the interpolation mesh used by this class.
Definition spline_builder.hpp:66
typename ddc::detail::convert_type_seq_to_discrete_domain< ddc::type_seq_replace_t< ddc::detail::TypeSeq< IDimX... >, ddc::detail::TypeSeq< interpolation_mesh_type >, ddc::detail::TypeSeq< deriv_type > > > batched_derivs_domain_type
Definition spline_builder.hpp:100
BSpline1 bsplines_type
The type of the BSplines which are compatible with this class.
Definition spline_builder.hpp:71
The top-level namespace of DDC.
Definition aligned_allocator.hpp:11
constexpr bool enable_chunk
Definition chunk_traits.hpp:16
BoundCond
Definition spline_boundary_conditions.hpp:11
SplineSolver
Definition spline_builder.hpp:13
KOKKOS_FUNCTION constexpr auto remove_dims_of(DiscreteDomain< DDimsA... > const &DDom_a, DiscreteDomain< DDimsB... > const &DDom_b) noexcept
Definition discrete_domain.hpp:438
KOKKOS_FUNCTION constexpr auto replace_dim_of(DiscreteDomain< DDimsA... > const &DDom_a, DiscreteDomain< DDimsB... > const &DDom_b) noexcept
Definition discrete_domain.hpp:485
Definition chunk.hpp:21
Definition chunk_span.hpp:30