19#include <Kokkos_Core.hpp>
32
33
34
35
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
61 class InterpolationDDim,
75 using exec_space = ExecSpace;
78 using memory_space = MemorySpace;
81 using continuous_dimension_type = InterpolationDDim::continuous_dimension_type;
84 using interpolation_discrete_dimension_type = InterpolationDDim;
87 using bsplines_type = BSplines;
90 using deriv_type =
ddc::
Deriv<continuous_dimension_type>;
93 using interpolation_domain_type =
ddc::
DiscreteDomain<interpolation_discrete_dimension_type>;
96
97
98
99
100 template <concepts::discrete_domain BatchedInterpolationDDom>
101 using batched_interpolation_domain_type = BatchedInterpolationDDom;
104
105
106
107
108
109
110
111
112 template <concepts::discrete_domain BatchedInterpolationDDom>
113 using batch_domain_type =
ddc::
114 remove_dims_of_t<BatchedInterpolationDDom, interpolation_discrete_dimension_type>;
117
118
119
120
121
122
123
124
125 template <concepts::discrete_domain BatchedInterpolationDDom>
126 using batched_spline_domain_type =
ddc::replace_dim_of_t<
127 BatchedInterpolationDDom,
128 interpolation_discrete_dimension_type,
133
134
135
136
137
138
139
140
141 template <concepts::discrete_domain BatchedInterpolationDDom>
142 using batched_spline_tr_domain_type
143 =
ddc::detail::convert_type_seq_to_discrete_domain_t<
ddc::type_seq_merge_t<
144 ddc::detail::TypeSeq<bsplines_type>,
145 ddc::type_seq_remove_t<
146 ddc::to_type_seq_t<BatchedInterpolationDDom>,
147 ddc::detail::TypeSeq<interpolation_discrete_dimension_type>>>>;
151
152
153
154
155
156
157
158
159 template <concepts::discrete_domain BatchedInterpolationDDom>
160 using batched_derivs_domain_type =
ddc::replace_dim_of_t<
161 BatchedInterpolationDDom,
162 interpolation_discrete_dimension_type,
166 static constexpr bool s_odd = BSplines::degree() % 2;
169 static constexpr int s_nbe_xmin = n_boundary_equations(SBCLower, BSplines::degree());
172 static constexpr int s_nbe_xmax = n_boundary_equations(SBCUpper, BSplines::degree());
177 : n_boundary_equations(SBCLower, BSplines::degree());
182 : n_boundary_equations(SBCUpper, BSplines::degree());
194 interpolation_domain_type m_interpolation_domain;
201 std::unique_ptr<
ddc::detail::SplinesLinearProblem<exec_space>> m_matrix;
206 void compute_offset(interpolation_domain_type
const& interpolation_domain,
int& offset);
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
229 interpolation_domain_type
const& interpolation_domain,
230 std::optional<std::size_t> cols_per_chunk = std::nullopt,
231 std::optional<
unsigned int> preconditioner_max_block_size = std::nullopt)
232 : m_interpolation_domain(interpolation_domain)
233 , m_dx((
ddc::discrete_space<BSplines>().rmax() -
ddc::discrete_space<BSplines>().rmin())
234 /
ddc::discrete_space<BSplines>().ncells())
235 , m_label(std::move(label))
240 "Incompatible closure relations");
243 compute_offset(
this->interpolation_domain(), m_offset);
246 int lower_block_size;
247 int upper_block_size;
248 if constexpr (bsplines_type::is_uniform()) {
249 upper_block_size = compute_block_sizes_uniform(SBCLower,
s_nbe_xmin);
250 lower_block_size = compute_block_sizes_uniform(SBCUpper,
s_nbe_xmax);
252 upper_block_size = compute_block_sizes_non_uniform(SBCLower,
s_nbe_xmin);
253 lower_block_size = compute_block_sizes_non_uniform(SBCUpper,
s_nbe_xmax);
259 preconditioner_max_block_size);
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
279 interpolation_domain_type
const& interpolation_domain,
280 std::optional<std::size_t> cols_per_chunk = std::nullopt,
281 std::optional<
unsigned int> preconditioner_max_block_size = std::nullopt)
284 interpolation_domain,
286 preconditioner_max_block_size)
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308 template <
concepts::discrete_domain BatchedInterpolationDDom>
311 BatchedInterpolationDDom
const& batched_interpolation_domain,
312 std::optional<std::size_t> cols_per_chunk = std::nullopt,
313 std::optional<
unsigned int> preconditioner_max_block_size = std::nullopt)
316 interpolation_domain_type(batched_interpolation_domain),
318 preconditioner_max_block_size)
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338 template <
concepts::discrete_domain BatchedInterpolationDDom>
340 BatchedInterpolationDDom
const& batched_interpolation_domain,
341 std::optional<std::size_t> cols_per_chunk = std::nullopt,
342 std::optional<
unsigned int> preconditioner_max_block_size = std::nullopt)
345 interpolation_domain_type(batched_interpolation_domain),
347 preconditioner_max_block_size)
356
357
358
368
369
370
371
375
376
377
378
379
380
383 return m_interpolation_domain;
387
388
389
390
391
392
393
394
395
396 template <
concepts::discrete_domain BatchedInterpolationDDom>
398 BatchedInterpolationDDom
const& batched_interpolation_domain)
const noexcept
401 return batched_interpolation_domain;
405
406
407
408
409
410
411
412
413 template <
class BatchedInterpolationDDom>
414 batch_domain_type<BatchedInterpolationDDom>
batch_domain(
415 BatchedInterpolationDDom
const& batched_interpolation_domain)
const noexcept
422
423
424
425
426
427
430 return ddc::discrete_space<bsplines_type>().full_domain();
434
435
436
437
438
439
440
441
442 template <
class BatchedInterpolationDDom>
444 BatchedInterpolationDDom
const& batched_interpolation_domain)
const noexcept
447 return ddc::replace_dim_of<
448 interpolation_discrete_dimension_type,
454
455
456
457
458
459
460
461
462 template <
class BatchedInterpolationDDom>
463 batched_spline_tr_domain_type<BatchedInterpolationDDom> batched_spline_tr_domain(
464 BatchedInterpolationDDom
const& batched_interpolation_domain)
const noexcept
467 return batched_spline_tr_domain_type<BatchedInterpolationDDom>(
468 ddc::replace_dim_of<bsplines_type, bsplines_type>(
469 batched_spline_domain(batched_interpolation_domain),
471 ddc::DiscreteElement<bsplines_type>(0),
473 m_matrix->required_number_of_rhs_rows()))));
478
479
480
481
482
483
484
485
486 template <
class BatchedInterpolationDDom>
488 BatchedInterpolationDDom
const& batched_interpolation_domain)
const noexcept
491 return ddc::replace_dim_of<interpolation_discrete_dimension_type, deriv_type>(
492 batched_interpolation_domain,
494 ddc::DiscreteElement<deriv_type>(1),
499
500
501
502
503
504
505
506
507 template <
class BatchedInterpolationDDom>
509 BatchedInterpolationDDom
const& batched_interpolation_domain)
const noexcept
512 return ddc::replace_dim_of<interpolation_discrete_dimension_type, deriv_type>(
513 batched_interpolation_domain,
515 ddc::DiscreteElement<deriv_type>(1),
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538 template <
class Layout,
class BatchedInterpolationDDom>
542 batched_spline_domain_type<BatchedInterpolationDDom>,
544 memory_space> spline,
545 ddc::
ChunkSpan<
double const, BatchedInterpolationDDom, Layout, memory_space> vals,
548 batched_derivs_domain_type<BatchedInterpolationDDom>,
550 memory_space>> derivs_xmin
554 batched_derivs_domain_type<BatchedInterpolationDDom>,
556 memory_space>> derivs_xmax
557 = std::nullopt)
const;
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582 template <
class OutMemorySpace = MemorySpace>
605 void allocate_matrix(
606 int lower_block_size,
607 int upper_block_size,
608 std::optional<std::size_t> cols_per_chunk = std::nullopt,
609 std::optional<
unsigned int> preconditioner_max_block_size = std::nullopt);
611 void build_matrix_system();
613 void check_valid_grid();
615 template <
class KnotElement>
616 static void check_n_points_in_cell(
int n_points_in_cell, KnotElement current_cell_end_idx);
623 class InterpolationDDim,
634 Solver>::compute_offset(interpolation_domain_type
const& interpolation_domain,
int& offset)
636 if constexpr (bsplines_type::is_periodic()) {
638 std::array<
double, bsplines_type::degree() + 1> values_ptr;
639 Kokkos::mdspan<
double, Kokkos::extents<std::size_t, bsplines_type::degree() + 1>>
const
640 values(values_ptr.data());
641 ddc::DiscreteElement<interpolation_discrete_dimension_type> start(
642 interpolation_domain.front());
643 auto jmin =
ddc::discrete_space<BSplines>()
644 .eval_basis(values,
ddc::coordinate(start + BSplines::degree()));
645 if constexpr (bsplines_type::degree() % 2 == 0) {
646 offset = jmin.uid() - start.uid() + bsplines_type::degree() / 2 - BSplines::degree();
648 int const mid = bsplines_type::degree() / 2;
649 offset = jmin.uid() - start.uid()
650 + (DDC_MDSPAN_ACCESS_OP(values, mid) > DDC_MDSPAN_ACCESS_OP(values, mid + 1)
653 - BSplines::degree();
664 class InterpolationDDim,
668int SplineBuilder<ExecSpace, MemorySpace, BSplines, InterpolationDDim, SBCLower, SBCUpper, Solver>::
672 return static_cast<
int>(bsplines_type::degree()) / 2;
681 return static_cast<
int>(bsplines_type::degree()) - 1;
684 throw std::runtime_error(
"ddc::SplineBuilderClosure not handled");
691 class InterpolationDDim,
695int SplineBuilder<ExecSpace, MemorySpace, BSplines, InterpolationDDim, SBCLower, SBCUpper, Solver>::
700 return static_cast<
int>(bsplines_type::degree()) - 1;
708 throw std::runtime_error(
"ddc::SplineBuilderClosure not handled");
715 class InterpolationDDim,
728 [[maybe_unused]]
int lower_block_size,
729 [[maybe_unused]]
int upper_block_size,
730 std::optional<std::size_t> cols_per_chunk,
731 std::optional<
unsigned int> preconditioner_max_block_size)
741 int upper_band_width;
742 if (bsplines_type::is_uniform()) {
743 upper_band_width = bsplines_type::degree() / 2;
745 upper_band_width = bsplines_type::degree() - 1;
747 if constexpr (bsplines_type::is_periodic()) {
748 m_matrix =
ddc::detail::SplinesLinearProblemMaker::make_new_periodic_band_matrix<
750 ddc::discrete_space<BSplines>().nbasis(),
753 bsplines_type::is_uniform());
755 m_matrix =
ddc::detail::SplinesLinearProblemMaker::
756 make_new_block_matrix_with_band_main_block<ExecSpace>(
757 ddc::discrete_space<BSplines>().nbasis(),
760 bsplines_type::is_uniform(),
765 m_matrix =
ddc::detail::SplinesLinearProblemMaker::make_new_sparse<ExecSpace>(
766 ddc::discrete_space<BSplines>().nbasis(),
768 preconditioner_max_block_size);
771 build_matrix_system();
773 m_matrix->setup_solver();
780 class InterpolationDDim,
791 Solver>::build_matrix_system()
797 std::array<
double, (bsplines_type::degree() / 2 + 1) * (bsplines_type::degree() + 1)>
800 derivs(derivs_ptr.data(),
801 bsplines_type::degree() + 1,
802 bsplines_type::degree() / 2 + 1);
803 ddc::discrete_space<BSplines>().eval_basis_and_n_derivs(
805 ddc::discrete_space<BSplines>().rmin(),
810 for (std::size_t i = 0; i < bsplines_type::degree() + 1; ++i) {
811 for (std::size_t j = 1; j < bsplines_type::degree() / 2 + 1; ++j) {
812 DDC_MDSPAN_ACCESS_OP(derivs, i, j) *=
ddc::detail::ipow(m_dx, j);
818 for (std::size_t i = 0; i <
s_nbe_xmin; ++i) {
819 for (std::size_t j = 0; j < bsplines_type::degree(); ++j) {
820 m_matrix->set_element(i, j, DDC_MDSPAN_ACCESS_OP(derivs, j, i + s_odd));
827 std::array<
double, bsplines_type::degree() + 1> values_ptr;
828 Kokkos::mdspan<
double, Kokkos::extents<std::size_t, bsplines_type::degree() + 1>>
const values(
833 auto jmin =
ddc::discrete_space<BSplines>().eval_basis(
835 ddc::coordinate(
ddc::DiscreteElement<interpolation_discrete_dimension_type>(ix)));
836 for (std::size_t s = 0; s < bsplines_type::degree() + 1; ++s) {
837 int const j =
ddc::detail::
838 modulo(
int(jmin.uid() - m_offset + s),
839 static_cast<
int>(
ddc::discrete_space<BSplines>().nbasis()));
840 m_matrix->set_element(
843 DDC_MDSPAN_ACCESS_OP(values, s));
851 std::array<
double, (bsplines_type::degree() / 2 + 1) * (bsplines_type::degree() + 1)>
857 bsplines_type::degree() + 1,
858 bsplines_type::degree() / 2 + 1>>
const derivs(derivs_ptr.data());
860 ddc::discrete_space<BSplines>().eval_basis_and_n_derivs(
862 ddc::discrete_space<BSplines>().rmax(),
867 for (std::size_t i = 0; i < bsplines_type::degree() + 1; ++i) {
868 for (std::size_t j = 1; j < bsplines_type::degree() / 2 + 1; ++j) {
869 DDC_MDSPAN_ACCESS_OP(derivs, i, j) *=
ddc::detail::ipow(m_dx, j);
874 int const i0 =
ddc::discrete_space<BSplines>().nbasis() -
s_nbe_xmax;
875 int const j0 =
ddc::discrete_space<BSplines>().nbasis() - bsplines_type::degree();
876 for (std::size_t j = 0; j < bsplines_type::degree(); ++j) {
877 for (std::size_t i = 0; i <
s_nbe_xmax; ++i) {
878 m_matrix->set_element(
881 DDC_MDSPAN_ACCESS_OP(derivs, j + 1, i +
s_odd));
896template <
class Layout,
class BatchedInterpolationDDom>
908 batched_spline_domain_type<BatchedInterpolationDDom>,
910 memory_space> spline,
911 ddc::
ChunkSpan<
double const, BatchedInterpolationDDom, Layout, memory_space> vals,
914 batched_derivs_domain_type<BatchedInterpolationDDom>,
916 memory_space>>
const derivs_xmin,
919 batched_derivs_domain_type<BatchedInterpolationDDom>,
921 memory_space>>
const derivs_xmax)
const
923 auto const batched_interpolation_domain = vals.domain();
926 assert(batch_domain_type<BatchedInterpolationDDom>(batched_interpolation_domain)
927 == batch_domain_type<BatchedInterpolationDDom>(spline.domain()));
929 if (batch_domain(batched_interpolation_domain).empty()) {
933 assert(vals.
template extent<interpolation_discrete_dimension_type>()
937 assert(
ddc::DiscreteElement<deriv_type>(derivs_xmin->domain().front()).uid() ==
s_odd);
938 assert(derivs_xmin.has_value() ||
s_nbe_xmin == 0);
940 assert(!derivs_xmin.has_value() || derivs_xmin->
template extent<deriv_type>() == 0);
943 assert(
ddc::DiscreteElement<deriv_type>(derivs_xmax->domain().front()).uid() ==
s_odd);
944 assert(derivs_xmax.has_value() ||
s_nbe_xmax == 0);
946 assert(!derivs_xmax.has_value() || derivs_xmax->
template extent<deriv_type>() == 0);
953 assert(derivs_xmin->
template extent<deriv_type>() ==
s_nbe_xmin);
954 auto derivs_xmin_values = *derivs_xmin;
955 auto const dx_proxy = m_dx;
956 auto const odd_proxy =
s_odd;
957 ddc::parallel_for_each(
958 "ddc_splines_hermite_compute_lower_coefficients",
960 batch_domain(batched_interpolation_domain),
962 batch_domain_type<BatchedInterpolationDDom>::discrete_element_type j) {
964 spline(
ddc::DiscreteElement<bsplines_type>(i), j)
965 = derivs_xmin_values(
966 ddc::DiscreteElement<deriv_type>(i + odd_proxy),
968 *
ddc::detail::ipow(dx_proxy, i + odd_proxy);
973 ddc::DiscreteElement<bsplines_type>(0),
975 batched_spline_domain_type<BatchedInterpolationDDom>
const
976 dx_spline_domain(dx_splines, batch_domain(batched_interpolation_domain));
977 ddc::parallel_fill(exec_space(), spline[dx_spline_domain], 0.0);
996 interpolation_discrete_dimension_type>())))]
997 .allocation_kokkos_view(),
998 vals.allocation_kokkos_view());
1005 auto const& nbasis_proxy =
ddc::discrete_space<bsplines_type>().nbasis();
1007 assert(derivs_xmax->
template extent<deriv_type>() ==
s_nbe_xmax);
1008 auto derivs_xmax_values = *derivs_xmax;
1009 auto const dx_proxy = m_dx;
1010 auto const odd_proxy =
s_odd;
1011 ddc::parallel_for_each(
1012 "ddc_splines_hermite_compute_upper_coefficients",
1014 batch_domain(batched_interpolation_domain),
1016 batch_domain_type<BatchedInterpolationDDom>::discrete_element_type j) {
1018 spline(
ddc::DiscreteElement<bsplines_type>(nbasis_proxy -
s_nbe_xmax + i),
1020 = derivs_xmax_values(
1021 ddc::DiscreteElement<deriv_type>(i + odd_proxy),
1023 *
ddc::detail::ipow(dx_proxy, i + odd_proxy);
1028 ddc::DiscreteElement<bsplines_type>(nbasis_proxy -
s_nbe_xmax),
1030 batched_spline_domain_type<BatchedInterpolationDDom>
const
1031 dx_spline_domain(dx_splines, batch_domain(batched_interpolation_domain));
1032 ddc::parallel_fill(exec_space(), spline[dx_spline_domain], 0.0);
1036 auto const& offset_proxy = m_offset;
1038 m_label +
" > spline_tr (ddc::SplineBuilder::operator())",
1039 batched_spline_tr_domain(batched_interpolation_domain),
1041 ddc::
ChunkSpan const spline_tr = spline_tr_alloc.span_view();
1042 ddc::parallel_for_each(
1043 m_label +
" > ddc_splines_transpose_rhs",
1045 batch_domain(batched_interpolation_domain),
1047 batch_domain_type<BatchedInterpolationDDom>::discrete_element_type
const j) {
1048 for (std::size_t i = 0; i < nbasis_proxy; ++i) {
1049 spline_tr(
ddc::DiscreteElement<bsplines_type>(i), j)
1050 = spline(
ddc::DiscreteElement<bsplines_type>(i + offset_proxy), j);
1054 Kokkos::View<
double**, Kokkos::LayoutRight, exec_space>
const bcoef_section(
1055 spline_tr.data_handle(),
1056 static_cast<std::size_t>(spline_tr.
template extent<bsplines_type>()),
1057 batch_domain(batched_interpolation_domain).size());
1059 m_matrix->solve(bcoef_section,
false);
1061 ddc::parallel_for_each(
1062 m_label +
" > ddc_splines_transpose_back_rhs",
1064 batch_domain(batched_interpolation_domain),
1066 batch_domain_type<BatchedInterpolationDDom>::discrete_element_type
const j) {
1067 for (std::size_t i = 0; i < nbasis_proxy; ++i) {
1068 spline(
ddc::DiscreteElement<bsplines_type>(i + offset_proxy), j)
1069 = spline_tr(
ddc::DiscreteElement<bsplines_type>(i), j);
1074 if (bsplines_type::is_periodic()) {
1075 ddc::parallel_for_each(
1076 m_label +
" > ddc_splines_periodic_rows_duplicate_rhs",
1078 batch_domain(batched_interpolation_domain),
1080 batch_domain_type<BatchedInterpolationDDom>::discrete_element_type
const
1082 if (offset_proxy != 0) {
1083 for (
int i = 0; i < offset_proxy; ++i) {
1084 spline(
ddc::DiscreteElement<bsplines_type>(i), j) = spline(
1085 ddc::DiscreteElement<bsplines_type>(nbasis_proxy + i),
1088 for (std::size_t i = offset_proxy; i < bsplines_type::degree(); ++i) {
1089 spline(
ddc::DiscreteElement<bsplines_type>(nbasis_proxy + i), j)
1090 = spline(
ddc::DiscreteElement<bsplines_type>(i), j);
1093 for (std::size_t i(0); i < bsplines_type::degree(); ++i) {
1094 ddc::DiscreteElement<bsplines_type>
const i_start(i);
1095 ddc::DiscreteElement<bsplines_type>
const i_end(nbasis_proxy + i);
1097 spline(i_end, j) = spline(i_start, j);
1111template <
class OutMemorySpace>
1127SplineBuilder<ExecSpace, MemorySpace, BSplines, InterpolationDDim, SBCLower, SBCUpper, Solver>::
1132 ddc::integrals(ExecSpace(), integral_bsplines.span_view());
1135 ddc::
ChunkSpan const integral_bsplines_without_periodic_additional_bsplines
1140 Kokkos::View<
double**, Kokkos::LayoutRight, MemorySpace>
const
1141 integral_bsplines_mirror_with_additional_allocation(
1142 m_label +
" > integral_bsplines_mirror_with_additional_allocation",
1143 m_matrix->required_number_of_rhs_rows(),
1147 Kokkos::View<
double*, Kokkos::LayoutRight, MemorySpace>
const integral_bsplines_mirror
1149 subview(integral_bsplines_mirror_with_additional_allocation,
1151 pair {
static_cast<std::size_t>(0),
1152 integral_bsplines_without_periodic_additional_bsplines
1158 integral_bsplines_mirror,
1159 integral_bsplines_without_periodic_additional_bsplines.allocation_kokkos_view());
1160 m_matrix->solve(integral_bsplines_mirror_with_additional_allocation,
true);
1162 integral_bsplines_without_periodic_additional_bsplines.allocation_kokkos_view(),
1163 integral_bsplines_mirror);
1167 = integral_bsplines_without_periodic_additional_bsplines[
spline_domain().take_first(
1169 ddc::
ChunkSpan const coefficients = integral_bsplines_without_periodic_additional_bsplines
1177 = integral_bsplines_without_periodic_additional_bsplines
1185 auto const dx_proxy = m_dx;
1186 auto const odd_proxy =
s_odd;
1187 ddc::parallel_for_each(
1189 coefficients_derivs_xmin.domain(),
1190 KOKKOS_LAMBDA(
ddc::DiscreteElement<bsplines_type> i) {
1191 coefficients_derivs_xmin(i) *=
ddc::detail::
1193 static_cast<std::size_t>(get<bsplines_type>(
1194 (i - coefficients_derivs_xmin.domain().front()) + odd_proxy)));
1196 ddc::parallel_for_each(
1198 coefficients_derivs_xmax.domain(),
1199 KOKKOS_LAMBDA(
ddc::DiscreteElement<bsplines_type> i) {
1200 coefficients_derivs_xmax(i) *=
ddc::detail::
1202 static_cast<std::size_t>(get<bsplines_type>(
1203 (i - coefficients_derivs_xmax.domain().front()) + odd_proxy)));
1206 ddc::DiscreteElement<deriv_type>
const first_deriv(
s_odd);
1208 ddc::
Chunk coefficients_derivs_xmin_out(
1215 coefficients.size())),
1217 ddc::
Chunk coefficients_derivs_xmax_out(
1222 coefficients_derivs_xmin_out.allocation_kokkos_view(),
1223 coefficients_derivs_xmin.allocation_kokkos_view());
1225 coefficients_out.allocation_kokkos_view(),
1226 coefficients.allocation_kokkos_view());
1228 coefficients_derivs_xmax_out.allocation_kokkos_view(),
1229 coefficients_derivs_xmax.allocation_kokkos_view());
1230 return std::make_tuple(
1231 std::move(coefficients_derivs_xmin_out),
1232 std::move(coefficients_out),
1233 std::move(coefficients_derivs_xmax_out));
1244template <
class KnotElement>
1253 check_n_points_in_cell(
int const n_points_in_cell, KnotElement
const current_cell_end_idx)
1255 if (n_points_in_cell > BSplines::degree() + 1) {
1256 KnotElement
const rmin_idx =
ddc::discrete_space<BSplines>().break_point_domain().front();
1257 int const failed_cell = (current_cell_end_idx - rmin_idx).value();
1258 throw std::runtime_error(
1259 "The spline problem is overconstrained. There are "
1260 + std::to_string(n_points_in_cell) +
" points in the " + std::to_string(failed_cell)
1269 class InterpolationDDim,
1280 Solver>::check_valid_grid()
1283 std::size_t
const expected_npoints
1285 if (n_interp_points != expected_npoints) {
1286 throw std::runtime_error(
1287 "Incorrect number of points supplied to NonUniformInterpolationPoints. "
1289 + std::to_string(n_interp_points)
1290 +
", expected : " + std::to_string(expected_npoints));
1292 int n_points_in_cell = 0;
1293 auto current_cell_end_idx =
ddc::discrete_space<BSplines>().break_point_domain().front() + 1;
1295 ddc::Coordinate<continuous_dimension_type>
const point =
ddc::coordinate(idx);
1296 if (point >
ddc::coordinate(current_cell_end_idx)) {
1298 check_n_points_in_cell(n_points_in_cell, current_cell_end_idx);
1300 n_points_in_cell = 1;
1302 current_cell_end_idx += 1;
1303 }
else if (point ==
ddc::coordinate(current_cell_end_idx)) {
1305 check_n_points_in_cell(n_points_in_cell + 1, current_cell_end_idx);
1307 n_points_in_cell = 1;
1309 current_cell_end_idx += 1;
1312 n_points_in_cell += 1;
1316 check_n_points_in_cell(n_points_in_cell, current_cell_end_idx);
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.
A class for creating a spline approximation of a function.
ddc::DiscreteDomain< bsplines_type > spline_domain() const noexcept
Get the 1D domain on which spline coefficients are defined.
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.
SplineBuilder(SplineBuilder const &x)=delete
Copy-constructor is deleted.
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_xmax_domain(BatchedInterpolationDDom const &batched_interpolation_domain) const noexcept
Get the whole domain on which derivatives on upper boundary are defined.
static constexpr int s_nbe_xmin
The number of equations defining the closure relation at the lower bound.
static constexpr ddc::SplineBuilderClosure s_sbc_xmin
The closure relation implemented at the lower bound.
SplineBuilder(std::string label, 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.
batch_domain_type< BatchedInterpolationDDom > batch_domain(BatchedInterpolationDDom const &batched_interpolation_domain) const noexcept
Get the batch domain.
SplineBuilder & operator=(SplineBuilder &&x)=default
Move-assigns.
static constexpr int s_nbe_xmax
The number of equations defining the closure relation at the upper bound.
static constexpr SplineSolver s_spline_solver
The SplineSolver giving the backend used to perform the spline approximation.
static constexpr ddc::SplineBuilderClosure s_sbc_xmax
The closure relation implemented at the upper bound.
BatchedInterpolationDDom batched_interpolation_domain(BatchedInterpolationDDom const &batched_interpolation_domain) const noexcept
Get the whole domain representing interpolation points.
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.
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.
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 bool s_odd
Indicates if the degree of the splines is odd or even.
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.
SplineBuilder(std::string label, 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.
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.
SplineBuilder(SplineBuilder &&x)=default
Move-constructs.
static constexpr int s_nbv_xmax
The number of input values defining the closure relation at the upper bound.
~SplineBuilder()=default
Destructs.
static constexpr int s_nbv_xmin
The number of input values defining the closure relation at the lower bound.
SplineBuilder & operator=(SplineBuilder const &x)=delete
Copy-assignment is deleted.
The top-level namespace of DDC.
constexpr bool is_uniform_bsplines_v
Indicates if a tag corresponds to uniform B-splines or not.
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 int n_boundary_equations(ddc::SplineBuilderClosure const sbc, std::size_t const degree)
Return the number of equations needed to describe a given closure relation.
constexpr bool is_non_uniform_bsplines_v
Indicates if a tag corresponds to non-uniform B-splines or not.
SplineBuilderClosure
An enum representing a spline closure relation.
@ HOMOGENEOUS_HERMITE
Homogeneous Hermite closure relation (derivatives are 0)
@ GREVILLE
Use Greville points instead of conditions on derivative for B-Spline interpolation.
@ HERMITE
Hermite closure relation.
@ PERIODIC
Periodic closure relation u(1)=u(n)
A templated struct representing a discrete dimension storing the derivatives of a function along a co...
If the type DDim is a B-spline, defines type to the discrete dimension of the associated knots.