14#include "spline_builder.hpp"
19
20
21
22
23
24
25
42 using exec_space = ExecSpace;
45 using memory_space = MemorySpace;
48 using builder_type1 =
ddc::
49 SplineBuilder<ExecSpace, MemorySpace, BSpline1, DDimI1, BcLower1, BcUpper1, Solver>;
52 using builder_type2 =
ddc::
53 SplineBuilder<ExecSpace, MemorySpace, BSpline2, DDimI2, BcLower2, BcUpper2, Solver>;
56 using builder_deriv_type1 =
ddc::
57 SplineBuilder<ExecSpace, MemorySpace, BSpline1, DDimI1, BcLower1, BcUpper1, Solver>;
60 using continuous_dimension_type1 =
typename builder_type1::continuous_dimension_type;
63 using continuous_dimension_type2 =
typename builder_type2::continuous_dimension_type;
66 using interpolation_discrete_dimension_type1 =
67 typename builder_type1::interpolation_discrete_dimension_type;
70 using interpolation_discrete_dimension_type2 =
71 typename builder_type2::interpolation_discrete_dimension_type;
74 using bsplines_type1 =
typename builder_type1::bsplines_type;
77 using bsplines_type2 =
typename builder_type2::bsplines_type;
80 using deriv_type1 =
typename builder_type1::deriv_type;
83 using deriv_type2 =
typename builder_type2::deriv_type;
86 using interpolation_domain_type1 =
87 typename builder_type1::interpolation_discrete_dimension_type;
90 using interpolation_domain_type2 =
91 typename builder_type2::interpolation_discrete_dimension_type;
95 interpolation_discrete_dimension_type1,
96 interpolation_discrete_dimension_type2>;
99
100
101
102
104 class BatchedInterpolationDDom,
105 class = std::enable_if_t<
ddc::is_discrete_domain_v<BatchedInterpolationDDom>>>
106 using batched_interpolation_domain_type = BatchedInterpolationDDom;
109
110
111
112
113
114
115
116
118 class BatchedInterpolationDDom,
119 class = std::enable_if_t<
ddc::is_discrete_domain_v<BatchedInterpolationDDom>>>
120 using batch_domain_type =
ddc::remove_dims_of_t<
121 BatchedInterpolationDDom,
122 interpolation_discrete_dimension_type1,
123 interpolation_discrete_dimension_type2>;
126
127
128
129
130
131
132
133
135 class BatchedInterpolationDDom,
136 class = std::enable_if_t<
ddc::is_discrete_domain_v<BatchedInterpolationDDom>>>
137 using batched_spline_domain_type
138 =
ddc::detail::convert_type_seq_to_discrete_domain_t<
ddc::type_seq_replace_t<
139 ddc::to_type_seq_t<BatchedInterpolationDDom>,
140 ddc::detail::TypeSeq<
141 interpolation_discrete_dimension_type1,
142 interpolation_discrete_dimension_type2>,
143 ddc::detail::TypeSeq<bsplines_type1, bsplines_type2>>>;
146
147
148
149
150
151
152
153
155 class BatchedInterpolationDDom,
156 class = std::enable_if_t<
ddc::is_discrete_domain_v<BatchedInterpolationDDom>>>
157 using batched_derivs_domain_type1 =
158 typename builder_type1::
template batched_derivs_domain_type<BatchedInterpolationDDom>;
161
162
163
164
165
166
167
168
170 class BatchedInterpolationDDom,
171 class = std::enable_if_t<
ddc::is_discrete_domain_v<BatchedInterpolationDDom>>>
172 using batched_derivs_domain_type2 =
ddc::replace_dim_of_t<
173 BatchedInterpolationDDom,
174 interpolation_discrete_dimension_type2,
178
179
180
181
182
183
184
185
187 class BatchedInterpolationDDom,
188 class = std::enable_if_t<
ddc::is_discrete_domain_v<BatchedInterpolationDDom>>>
189 using batched_derivs_domain_type
190 =
ddc::detail::convert_type_seq_to_discrete_domain_t<
ddc::type_seq_replace_t<
191 ddc::to_type_seq_t<BatchedInterpolationDDom>,
192 ddc::detail::TypeSeq<
193 interpolation_discrete_dimension_type1,
194 interpolation_discrete_dimension_type2>,
195 ddc::detail::TypeSeq<deriv_type1, deriv_type2>>>;
198 builder_type1 m_spline_builder1;
199 builder_deriv_type1 m_spline_builder_deriv1;
200 builder_type2 m_spline_builder2;
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
220 interpolation_domain_type
const& interpolation_domain,
221 std::optional<std::size_t> cols_per_chunk = std::nullopt,
222 std::optional<
unsigned int> preconditioner_max_block_size = std::nullopt)
223 : m_spline_builder1(interpolation_domain, cols_per_chunk, preconditioner_max_block_size)
224 , m_spline_builder_deriv1(interpolation_domain)
225 , m_spline_builder2(interpolation_domain, cols_per_chunk, preconditioner_max_block_size)
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
246 class BatchedInterpolationDDom,
247 class = std::enable_if_t<
ddc::is_discrete_domain_v<BatchedInterpolationDDom>>>
249 BatchedInterpolationDDom
const& batched_interpolation_domain,
250 std::optional<std::size_t> cols_per_chunk = std::nullopt,
251 std::optional<
unsigned int> preconditioner_max_block_size = std::nullopt)
253 interpolation_domain_type(batched_interpolation_domain),
255 preconditioner_max_block_size)
263
264
265
266
276
277
278
279
283
284
285
286
287
288
291 return ddc::
DiscreteDomain<interpolation_domain_type1, interpolation_domain_type2>(
292 m_spline_builder1.interpolation_domain(),
293 m_spline_builder2.interpolation_domain());
297
298
299
300
301
302
303
304
305
307 class BatchedInterpolationDDom,
308 class = std::enable_if_t<
ddc::is_discrete_domain_v<BatchedInterpolationDDom>>>
310 BatchedInterpolationDDom
const& batched_interpolation_domain)
const noexcept
312 assert(interpolation_domain() == interpolation_domain_type(batched_interpolation_domain));
313 return batched_interpolation_domain;
317
318
319
320
321
322
323
324
326 class BatchedInterpolationDDom,
327 class = std::enable_if_t<
ddc::is_discrete_domain_v<BatchedInterpolationDDom>>>
328 batch_domain_type<BatchedInterpolationDDom>
batch_domain(
329 BatchedInterpolationDDom
const& batched_interpolation_domain)
const noexcept
331 assert(interpolation_domain() == interpolation_domain_type(batched_interpolation_domain));
336
337
338
339
340
341
345 ddc::discrete_space<bsplines_type1>().full_domain(),
346 ddc::discrete_space<bsplines_type2>().full_domain());
350
351
352
353
354
355
356
357
359 class BatchedInterpolationDDom,
360 class = std::enable_if_t<
ddc::is_discrete_domain_v<BatchedInterpolationDDom>>>
362 BatchedInterpolationDDom
const& batched_interpolation_domain)
const noexcept
364 assert(interpolation_domain() == interpolation_domain_type(batched_interpolation_domain));
365 return ddc::replace_dim_of<interpolation_discrete_dimension_type1, bsplines_type1>(
367 interpolation_discrete_dimension_type2,
373
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 template <
class Layout,
class BatchedInterpolationDDom>
412 batched_spline_domain_type<BatchedInterpolationDDom>,
414 memory_space> spline,
415 ddc::
ChunkSpan<
double const, BatchedInterpolationDDom, Layout, memory_space> vals,
418 batched_derivs_domain_type1<BatchedInterpolationDDom>,
420 memory_space>> derivs_min1
424 batched_derivs_domain_type1<BatchedInterpolationDDom>,
426 memory_space>> derivs_max1
430 batched_derivs_domain_type2<BatchedInterpolationDDom>,
432 memory_space>> derivs_min2
436 batched_derivs_domain_type2<BatchedInterpolationDDom>,
438 memory_space>> derivs_max2
442 batched_derivs_domain_type<BatchedInterpolationDDom>,
444 memory_space>> mixed_derivs_min1_min2
448 batched_derivs_domain_type<BatchedInterpolationDDom>,
450 memory_space>> mixed_derivs_max1_min2
454 batched_derivs_domain_type<BatchedInterpolationDDom>,
456 memory_space>> mixed_derivs_min1_max2
460 batched_derivs_domain_type<BatchedInterpolationDDom>,
462 memory_space>> mixed_derivs_max1_max2
463 = std::nullopt)
const;
479template <
class Layout,
class BatchedInterpolationDDom>
495 batched_spline_domain_type<BatchedInterpolationDDom>,
497 memory_space> spline,
498 ddc::
ChunkSpan<
double const, BatchedInterpolationDDom, Layout, memory_space> vals,
501 batched_derivs_domain_type1<BatchedInterpolationDDom>,
503 memory_space>>
const derivs_min1,
506 batched_derivs_domain_type1<BatchedInterpolationDDom>,
508 memory_space>>
const derivs_max1,
511 batched_derivs_domain_type2<BatchedInterpolationDDom>,
513 memory_space>>
const derivs_min2,
516 batched_derivs_domain_type2<BatchedInterpolationDDom>,
518 memory_space>>
const derivs_max2,
521 batched_derivs_domain_type<BatchedInterpolationDDom>,
523 memory_space>>
const mixed_derivs_min1_min2,
526 batched_derivs_domain_type<BatchedInterpolationDDom>,
528 memory_space>>
const mixed_derivs_max1_min2,
531 batched_derivs_domain_type<BatchedInterpolationDDom>,
533 memory_space>>
const mixed_derivs_min1_max2,
536 batched_derivs_domain_type<BatchedInterpolationDDom>,
538 memory_space>>
const mixed_derivs_max1_max2)
const
540 auto const batched_interpolation_domain = vals.domain();
542 assert(interpolation_domain() == interpolation_domain_type(batched_interpolation_domain));
547 auto const batched_interpolation_deriv_domain
548 =
ddc::replace_dim_of<interpolation_discrete_dimension_type2, deriv_type2>(
549 batched_interpolation_domain,
551 ddc::DiscreteElement<deriv_type2>(1),
555 m_spline_builder_deriv1.batched_spline_domain(batched_interpolation_deriv_domain),
557 auto spline1_deriv_min = spline1_deriv_min_alloc.span_view();
558 auto spline1_deriv_min_opt = std::optional(spline1_deriv_min.span_cview());
560 m_spline_builder_deriv1(
563 mixed_derivs_min1_min2,
564 mixed_derivs_max1_min2);
566 spline1_deriv_min_opt = std::nullopt;
571 m_spline_builder1.batched_spline_domain(batched_interpolation_domain),
573 ddc::
ChunkSpan const spline1 = spline1_alloc.span_view();
575 m_spline_builder1(spline1, vals, derivs_min1, derivs_max1);
579 m_spline_builder_deriv1.batched_spline_domain(batched_interpolation_deriv_domain),
581 auto spline1_deriv_max = spline1_deriv_max_alloc.span_view();
582 auto spline1_deriv_max_opt = std::optional(spline1_deriv_max.span_cview());
584 m_spline_builder_deriv1(
587 mixed_derivs_min1_max2,
588 mixed_derivs_max1_max2);
590 spline1_deriv_max_opt = std::nullopt;
594 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.