14#include "spline_boundary_conditions.hpp"
15#include "spline_builder.hpp"
20
21
22
23
24
25
26
43 using exec_space = ExecSpace;
46 using memory_space = MemorySpace;
49 using builder_type1 =
ddc::
50 SplineBuilder<ExecSpace, MemorySpace, BSpline1, DDimI1, BcLower1, BcUpper1, Solver>;
53 using builder_type2 =
ddc::
54 SplineBuilder<ExecSpace, MemorySpace, BSpline2, DDimI2, BcLower2, BcUpper2, Solver>;
57 using builder_deriv_type1 =
ddc::
58 SplineBuilder<ExecSpace, MemorySpace, BSpline1, DDimI1, BcLower1, BcUpper1, Solver>;
61 using continuous_dimension_type1 =
typename builder_type1::continuous_dimension_type;
64 using continuous_dimension_type2 =
typename builder_type2::continuous_dimension_type;
67 using interpolation_discrete_dimension_type1 =
68 typename builder_type1::interpolation_discrete_dimension_type;
71 using interpolation_discrete_dimension_type2 =
72 typename builder_type2::interpolation_discrete_dimension_type;
75 using bsplines_type1 =
typename builder_type1::bsplines_type;
78 using bsplines_type2 =
typename builder_type2::bsplines_type;
81 using deriv_type1 =
typename builder_type1::deriv_type;
84 using deriv_type2 =
typename builder_type2::deriv_type;
87 using interpolation_domain_type1 =
88 typename builder_type1::interpolation_discrete_dimension_type;
91 using interpolation_domain_type2 =
92 typename builder_type2::interpolation_discrete_dimension_type;
96 interpolation_discrete_dimension_type1,
97 interpolation_discrete_dimension_type2>;
100
101
102
103
105 class BatchedInterpolationDDom,
106 class = std::enable_if_t<
ddc::is_discrete_domain_v<BatchedInterpolationDDom>>>
107 using batched_interpolation_domain_type = BatchedInterpolationDDom;
110
111
112
113
114
115
116
117
119 class BatchedInterpolationDDom,
120 class = std::enable_if_t<
ddc::is_discrete_domain_v<BatchedInterpolationDDom>>>
121 using batch_domain_type =
ddc::remove_dims_of_t<
122 BatchedInterpolationDDom,
123 interpolation_discrete_dimension_type1,
124 interpolation_discrete_dimension_type2>;
127
128
129
130
131
132
133
134
136 class BatchedInterpolationDDom,
137 class = std::enable_if_t<
ddc::is_discrete_domain_v<BatchedInterpolationDDom>>>
138 using batched_spline_domain_type
139 =
ddc::detail::convert_type_seq_to_discrete_domain_t<
ddc::type_seq_replace_t<
140 ddc::to_type_seq_t<BatchedInterpolationDDom>,
141 ddc::detail::TypeSeq<
142 interpolation_discrete_dimension_type1,
143 interpolation_discrete_dimension_type2>,
144 ddc::detail::TypeSeq<bsplines_type1, bsplines_type2>>>;
147
148
149
150
151
152
153
154
156 class BatchedInterpolationDDom,
157 class = std::enable_if_t<
ddc::is_discrete_domain_v<BatchedInterpolationDDom>>>
158 using batched_derivs_domain_type1 =
159 typename builder_type1::
template batched_derivs_domain_type<BatchedInterpolationDDom>;
162
163
164
165
166
167
168
169
171 class BatchedInterpolationDDom,
172 class = std::enable_if_t<
ddc::is_discrete_domain_v<BatchedInterpolationDDom>>>
173 using batched_derivs_domain_type2 =
ddc::replace_dim_of_t<
174 BatchedInterpolationDDom,
175 interpolation_discrete_dimension_type2,
179
180
181
182
183
184
185
186
188 class BatchedInterpolationDDom,
189 class = std::enable_if_t<
ddc::is_discrete_domain_v<BatchedInterpolationDDom>>>
190 using batched_derivs_domain_type
191 =
ddc::detail::convert_type_seq_to_discrete_domain_t<
ddc::type_seq_replace_t<
192 ddc::to_type_seq_t<BatchedInterpolationDDom>,
193 ddc::detail::TypeSeq<
194 interpolation_discrete_dimension_type1,
195 interpolation_discrete_dimension_type2>,
196 ddc::detail::TypeSeq<deriv_type1, deriv_type2>>>;
199 builder_type1 m_spline_builder1;
200 builder_deriv_type1 m_spline_builder_deriv1;
201 builder_type2 m_spline_builder2;
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
221 interpolation_domain_type
const& interpolation_domain,
222 std::optional<std::size_t> cols_per_chunk = std::nullopt,
223 std::optional<
unsigned int> preconditioner_max_block_size = std::nullopt)
224 : m_spline_builder1(interpolation_domain, cols_per_chunk, preconditioner_max_block_size)
225 , m_spline_builder_deriv1(interpolation_domain)
226 , m_spline_builder2(interpolation_domain, cols_per_chunk, preconditioner_max_block_size)
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
247 class BatchedInterpolationDDom,
248 class = std::enable_if_t<
ddc::is_discrete_domain_v<BatchedInterpolationDDom>>>
250 BatchedInterpolationDDom
const& batched_interpolation_domain,
251 std::optional<std::size_t> cols_per_chunk = std::nullopt,
252 std::optional<
unsigned int> preconditioner_max_block_size = std::nullopt)
254 interpolation_domain_type(batched_interpolation_domain),
256 preconditioner_max_block_size)
264
265
266
267
277
278
279
280
284
285
286
287
288
289
292 return ddc::
DiscreteDomain<interpolation_domain_type1, interpolation_domain_type2>(
293 m_spline_builder1.interpolation_domain(),
294 m_spline_builder2.interpolation_domain());
298
299
300
301
302
303
304
305
306
308 class BatchedInterpolationDDom,
309 class = std::enable_if_t<
ddc::is_discrete_domain_v<BatchedInterpolationDDom>>>
311 BatchedInterpolationDDom
const& batched_interpolation_domain)
const noexcept
313 assert(interpolation_domain() == interpolation_domain_type(batched_interpolation_domain));
314 return batched_interpolation_domain;
318
319
320
321
322
323
324
325
327 class BatchedInterpolationDDom,
328 class = std::enable_if_t<
ddc::is_discrete_domain_v<BatchedInterpolationDDom>>>
329 batch_domain_type<BatchedInterpolationDDom>
batch_domain(
330 BatchedInterpolationDDom
const& batched_interpolation_domain)
const noexcept
332 assert(interpolation_domain() == interpolation_domain_type(batched_interpolation_domain));
337
338
339
340
341
342
346 ddc::discrete_space<bsplines_type1>().full_domain(),
347 ddc::discrete_space<bsplines_type2>().full_domain());
351
352
353
354
355
356
357
358
360 class BatchedInterpolationDDom,
361 class = std::enable_if_t<
ddc::is_discrete_domain_v<BatchedInterpolationDDom>>>
363 BatchedInterpolationDDom
const& batched_interpolation_domain)
const noexcept
365 assert(interpolation_domain() == interpolation_domain_type(batched_interpolation_domain));
366 return ddc::replace_dim_of<interpolation_discrete_dimension_type1, bsplines_type1>(
368 interpolation_discrete_dimension_type2,
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409 template <
class Layout,
class BatchedInterpolationDDom>
413 batched_spline_domain_type<BatchedInterpolationDDom>,
415 memory_space> spline,
416 ddc::
ChunkSpan<
double const, BatchedInterpolationDDom, Layout, memory_space> vals,
419 batched_derivs_domain_type1<BatchedInterpolationDDom>,
421 memory_space>> derivs_min1
425 batched_derivs_domain_type1<BatchedInterpolationDDom>,
427 memory_space>> derivs_max1
431 batched_derivs_domain_type2<BatchedInterpolationDDom>,
433 memory_space>> derivs_min2
437 batched_derivs_domain_type2<BatchedInterpolationDDom>,
439 memory_space>> derivs_max2
443 batched_derivs_domain_type<BatchedInterpolationDDom>,
445 memory_space>> mixed_derivs_min1_min2
449 batched_derivs_domain_type<BatchedInterpolationDDom>,
451 memory_space>> mixed_derivs_max1_min2
455 batched_derivs_domain_type<BatchedInterpolationDDom>,
457 memory_space>> mixed_derivs_min1_max2
461 batched_derivs_domain_type<BatchedInterpolationDDom>,
463 memory_space>> mixed_derivs_max1_max2
464 = std::nullopt)
const;
480template <
class Layout,
class BatchedInterpolationDDom>
496 batched_spline_domain_type<BatchedInterpolationDDom>,
498 memory_space> spline,
499 ddc::
ChunkSpan<
double const, BatchedInterpolationDDom, Layout, memory_space> vals,
502 batched_derivs_domain_type1<BatchedInterpolationDDom>,
504 memory_space>>
const derivs_min1,
507 batched_derivs_domain_type1<BatchedInterpolationDDom>,
509 memory_space>>
const derivs_max1,
512 batched_derivs_domain_type2<BatchedInterpolationDDom>,
514 memory_space>>
const derivs_min2,
517 batched_derivs_domain_type2<BatchedInterpolationDDom>,
519 memory_space>>
const derivs_max2,
522 batched_derivs_domain_type<BatchedInterpolationDDom>,
524 memory_space>>
const mixed_derivs_min1_min2,
527 batched_derivs_domain_type<BatchedInterpolationDDom>,
529 memory_space>>
const mixed_derivs_max1_min2,
532 batched_derivs_domain_type<BatchedInterpolationDDom>,
534 memory_space>>
const mixed_derivs_min1_max2,
537 batched_derivs_domain_type<BatchedInterpolationDDom>,
539 memory_space>>
const mixed_derivs_max1_max2)
const
541 auto const batched_interpolation_domain = vals.domain();
543 assert(interpolation_domain() == interpolation_domain_type(batched_interpolation_domain));
544 assert(batch_domain_type<BatchedInterpolationDDom>(batched_interpolation_domain)
545 == batch_domain_type<BatchedInterpolationDDom>(spline.domain()));
547 if (batch_domain(batched_interpolation_domain).empty()) {
554 auto const batched_interpolation_deriv_domain
555 =
ddc::replace_dim_of<interpolation_discrete_dimension_type2, deriv_type2>(
556 batched_interpolation_domain,
558 ddc::DiscreteElement<deriv_type2>(builder_type2::s_odd),
562 m_spline_builder_deriv1.batched_spline_domain(batched_interpolation_deriv_domain),
564 auto spline1_deriv_min = spline1_deriv_min_alloc.span_view();
565 auto spline1_deriv_min_opt = std::optional(spline1_deriv_min.span_cview());
567 m_spline_builder_deriv1(
570 mixed_derivs_min1_min2,
571 mixed_derivs_max1_min2);
573 spline1_deriv_min_opt = std::nullopt;
578 m_spline_builder1.batched_spline_domain(batched_interpolation_domain),
580 ddc::
ChunkSpan const spline1 = spline1_alloc.span_view();
582 m_spline_builder1(spline1, vals, derivs_min1, derivs_max1);
586 m_spline_builder_deriv1.batched_spline_domain(batched_interpolation_deriv_domain),
588 auto spline1_deriv_max = spline1_deriv_max_alloc.span_view();
589 auto spline1_deriv_max_opt = std::optional(spline1_deriv_max.span_cview());
591 m_spline_builder_deriv1(
594 mixed_derivs_min1_max2,
595 mixed_derivs_max1_max2);
597 spline1_deriv_max_opt = std::nullopt;
601 m_spline_builder2(spline, spline1.span_cview(), spline1_deriv_min_opt, spline1_deriv_max_opt);
friend class DiscreteDomain
KOKKOS_FUNCTION constexpr bool operator!=(DiscreteVector< OTags... > const &rhs) const noexcept
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.
ddc::DiscreteDomain< bsplines_type1, bsplines_type2 > spline_domain() const noexcept
Get the 2D domain on which spline coefficients are defined.
BatchedInterpolationDDom batched_interpolation_domain(BatchedInterpolationDDom const &batched_interpolation_domain) const noexcept
Get the whole domain representing interpolation points.
SplineBuilder2D(SplineBuilder2D &&x)=default
Move-constructs.
SplineBuilder2D & operator=(SplineBuilder2D &&x)=default
Move-assigns.
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.
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.
batch_domain_type< BatchedInterpolationDDom > batch_domain(BatchedInterpolationDDom const &batched_interpolation_domain) const noexcept
Get the batch 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.
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 & operator=(SplineBuilder2D const &x)=delete
Copy-assignment is deleted.
A class for creating a spline approximation of a function.
The top-level namespace of DDC.
BoundCond
An enum representing a spline boundary condition.
@ HERMITE
Hermite boundary condition.
SplineSolver
An enum determining the backend solver of a SplineBuilder or SplineBuilder2d.