13#include <Kokkos_Core.hpp>
16#include "integrals.hpp"
17#include "periodic_extrapolation_rule.hpp"
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
42 class EvaluationDDim1,
43 class EvaluationDDim2,
44 class LowerExtrapolationRule1,
45 class UpperExtrapolationRule1,
46 class LowerExtrapolationRule2,
47 class UpperExtrapolationRule2>
52 using continuous_dimension_type1 =
typename BSplines1::continuous_dimension_type;
55 using continuous_dimension_type2 =
typename BSplines2::continuous_dimension_type;
58 using exec_space = ExecSpace;
61 using memory_space = MemorySpace;
64 using evaluation_discrete_dimension_type1 = EvaluationDDim1;
67 using evaluation_discrete_dimension_type2 = EvaluationDDim2;
70 using bsplines_type1 = BSplines1;
73 using bsplines_type2 = BSplines2;
76 using evaluation_domain_type1 =
ddc::
DiscreteDomain<evaluation_discrete_dimension_type1>;
79 using evaluation_domain_type2 =
ddc::
DiscreteDomain<evaluation_discrete_dimension_type2>;
83 evaluation_discrete_dimension_type1,
84 evaluation_discrete_dimension_type2>;
87
88
89
90
92 class BatchedInterpolationDDom,
93 class = std::enable_if_t<
ddc::is_discrete_domain_v<BatchedInterpolationDDom>>>
94 using batched_evaluation_domain_type = BatchedInterpolationDDom;
106
107
108
109
110
112 class BatchedInterpolationDDom,
113 class = std::enable_if_t<
ddc::is_discrete_domain_v<BatchedInterpolationDDom>>>
114 using batch_domain_type =
typename ddc::remove_dims_of_t<
115 BatchedInterpolationDDom,
116 evaluation_discrete_dimension_type1,
117 evaluation_discrete_dimension_type2>;
120
121
122
123
124
126 class BatchedInterpolationDDom,
127 class = std::enable_if_t<
ddc::is_discrete_domain_v<BatchedInterpolationDDom>>>
128 using batched_spline_domain_type =
129 typename ddc::detail::convert_type_seq_to_discrete_domain_t<
ddc::type_seq_replace_t<
130 ddc::to_type_seq_t<BatchedInterpolationDDom>,
131 ddc::detail::TypeSeq<
132 evaluation_discrete_dimension_type1,
133 evaluation_discrete_dimension_type2>,
134 ddc::detail::TypeSeq<bsplines_type1, bsplines_type2>>>;
137 using lower_extrapolation_rule_1_type = LowerExtrapolationRule1;
140 using upper_extrapolation_rule_1_type = UpperExtrapolationRule1;
143 using lower_extrapolation_rule_2_type = LowerExtrapolationRule2;
146 using upper_extrapolation_rule_2_type = UpperExtrapolationRule2;
149 LowerExtrapolationRule1 m_lower_extrap_rule_1;
151 UpperExtrapolationRule1 m_upper_extrap_rule_1;
153 LowerExtrapolationRule2 m_lower_extrap_rule_2;
155 UpperExtrapolationRule2 m_upper_extrap_rule_2;
159 std::is_same_v<LowerExtrapolationRule1,
161 == bsplines_type1::is_periodic()
163 UpperExtrapolationRule1,
165 == bsplines_type1::is_periodic()
167 LowerExtrapolationRule2,
169 == bsplines_type2::is_periodic()
171 UpperExtrapolationRule2,
173 == bsplines_type2::is_periodic(),
174 "PeriodicExtrapolationRule has to be used if and only if dimension is periodic");
176 std::is_invocable_r_v<
178 LowerExtrapolationRule1,
179 ddc::Coordinate<continuous_dimension_type1>,
183 Kokkos::layout_right,
185 "LowerExtrapolationRule1::operator() has to be callable "
186 "with usual arguments.");
188 std::is_invocable_r_v<
190 UpperExtrapolationRule1,
191 ddc::Coordinate<continuous_dimension_type1>,
195 Kokkos::layout_right,
197 "UpperExtrapolationRule1::operator() has to be callable "
198 "with usual arguments.");
200 std::is_invocable_r_v<
202 LowerExtrapolationRule2,
203 ddc::Coordinate<continuous_dimension_type2>,
207 Kokkos::layout_right,
209 "LowerExtrapolationRule2::operator() has to be callable "
210 "with usual arguments.");
212 std::is_invocable_r_v<
214 UpperExtrapolationRule2,
215 ddc::Coordinate<continuous_dimension_type2>,
219 Kokkos::layout_right,
221 "UpperExtrapolationRule2::operator() has to be callable "
222 "with usual arguments.");
225
226
227
228
229
230
231
232
233
235 LowerExtrapolationRule1
const& lower_extrap_rule1,
236 UpperExtrapolationRule1
const& upper_extrap_rule1,
237 LowerExtrapolationRule2
const& lower_extrap_rule2,
238 UpperExtrapolationRule2
const& upper_extrap_rule2)
239 : m_lower_extrap_rule_1(lower_extrap_rule1)
240 , m_upper_extrap_rule_1(upper_extrap_rule1)
241 , m_lower_extrap_rule_2(lower_extrap_rule2)
242 , m_upper_extrap_rule_2(upper_extrap_rule2)
247
248
249
250
254
255
256
257
264
265
266
267
268
272
273
274
275
276
280
281
282
283
284
285
286
287
290 return m_lower_extrap_rule_1;
294
295
296
297
298
299
300
301
304 return m_upper_extrap_rule_1;
308
309
310
311
312
313
314
315
318 return m_lower_extrap_rule_2;
322
323
324
325
326
327
328
329
332 return m_upper_extrap_rule_2;
336
337
338
339
340
341
342
343
344
345
346
347 template <
class Layout,
class... CoordsDims>
349 ddc::Coordinate<CoordsDims...>
const& coord_eval,
350 ddc::
ChunkSpan<
double const, spline_domain_type, Layout, memory_space>
const
353 return eval(coord_eval, spline_coef);
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
380 class BatchedInterpolationDDom,
383 ddc::
ChunkSpan<
double, BatchedInterpolationDDom, Layout1, memory_space>
const
386 ddc::Coordinate<CoordsDims...>
const,
387 BatchedInterpolationDDom,
389 memory_space>
const coords_eval,
392 batched_spline_domain_type<BatchedInterpolationDDom>,
394 memory_space>
const spline_coef)
const
396 batch_domain_type<BatchedInterpolationDDom>
const batch_domain(coords_eval.domain());
397 evaluation_domain_type1
const evaluation_domain1(spline_eval.domain());
398 evaluation_domain_type2
const evaluation_domain2(spline_eval.domain());
399 ddc::parallel_for_each(
400 "ddc_splines_evaluate_2d",
404 typename batch_domain_type<
405 BatchedInterpolationDDom>::discrete_element_type
const j) {
406 auto const spline_eval_2D = spline_eval[j];
407 auto const coords_eval_2D = coords_eval[j];
408 auto const spline_coef_2D = spline_coef[j];
409 for (
auto const i1 : evaluation_domain1) {
410 for (
auto const i2 : evaluation_domain2) {
411 spline_eval_2D(i1, i2) = eval(coords_eval_2D(i1, i2), spline_coef_2D);
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432 template <
class Layout1,
class Layout2,
class BatchedInterpolationDDom>
434 ddc::
ChunkSpan<
double, BatchedInterpolationDDom, Layout1, memory_space>
const
438 batched_spline_domain_type<BatchedInterpolationDDom>,
440 memory_space>
const spline_coef)
const
442 batch_domain_type<BatchedInterpolationDDom>
const batch_domain(spline_eval.domain());
443 evaluation_domain_type1
const evaluation_domain1(spline_eval.domain());
444 evaluation_domain_type2
const evaluation_domain2(spline_eval.domain());
445 ddc::parallel_for_each(
446 "ddc_splines_evaluate_2d",
450 typename batch_domain_type<
451 BatchedInterpolationDDom>::discrete_element_type
const j) {
452 auto const spline_eval_2D = spline_eval[j];
453 auto const spline_coef_2D = spline_coef[j];
454 for (
auto const i1 : evaluation_domain1) {
455 for (
auto const i2 : evaluation_domain2) {
456 ddc::Coordinate<continuous_dimension_type1, continuous_dimension_type2>
457 coord_eval_2D(
ddc::coordinate(i1),
ddc::coordinate(i2));
458 spline_eval_2D(i1, i2) = eval(coord_eval_2D(i1, i2), spline_coef_2D);
464#if defined(DDC_BUILD_DEPRECATED_CODE)
466
467
468
469
470
471
472
473
474
475
476 template <
class Layout,
class... CoordsDims>
478 "Use deriv(DiscreteElement<Deriv<Dim1>>(1), ...) instead)")]] KOKKOS_FUNCTION
double
480 ddc::Coordinate<CoordsDims...>
const& coord_eval,
481 ddc::
ChunkSpan<
double const, spline_domain_type, Layout, memory_space>
const
485 ddc::DiscreteElement<
Deriv<continuous_dimension_type1>>(1),
491
492
493
494
495
496
497
498
499
500
501 template <
class Layout,
class... CoordsDims>
503 "Use deriv(DiscreteElement<Deriv<Dim2>>(1), ...) instead)")]] KOKKOS_FUNCTION
double
505 ddc::Coordinate<CoordsDims...>
const& coord_eval,
506 ddc::
ChunkSpan<
double const, spline_domain_type, Layout, memory_space>
const
510 ddc::DiscreteElement<
Deriv<continuous_dimension_type2>>(1),
516
517
518
519
520
521
522
523
524
525
526 template <
class Layout,
class... CoordsDims>
528 "Use deriv(DiscreteElement<Deriv<Dim1>, Deriv<Dim2>>(1, 1), ...) "
529 "instead)")]] KOKKOS_FUNCTION
double
531 ddc::Coordinate<CoordsDims...>
const& coord_eval,
532 ddc::
ChunkSpan<
double const, spline_domain_type, Layout, memory_space>
const
536 ddc::DiscreteElement<
537 Deriv<continuous_dimension_type1>,
538 Deriv<continuous_dimension_type2>>(1, 1),
544
545
546
547
548
549
550
551
552
553
554
555
556 template <
class InterestDim,
class Layout,
class... CoordsDims>
558 "Use deriv(DiscreteElement<Deriv<InterestDim>>(1), ...) "
559 "instead)")]] KOKKOS_FUNCTION
double
560 deriv(
ddc::Coordinate<CoordsDims...>
const& coord_eval,
561 ddc::
ChunkSpan<
double const, spline_domain_type, Layout, memory_space>
const spline_coef)
564 DDC_DISABLE_DEPRECATED_WARNINGS_PUSH()
566 std::is_same_v<InterestDim, continuous_dimension_type1>
567 || std::is_same_v<InterestDim, continuous_dimension_type2>);
568 if constexpr (std::is_same_v<
570 typename evaluation_discrete_dimension_type1::
571 continuous_dimension_type>) {
572 return deriv_dim_1(coord_eval, spline_coef);
573 }
else if constexpr (std::is_same_v<
575 typename evaluation_discrete_dimension_type2::
576 continuous_dimension_type>) {
577 return deriv_dim_2(coord_eval, spline_coef);
579 DDC_DISABLE_DEPRECATED_WARNINGS_POP()
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598 template <
class InterestDim1,
class InterestDim2,
class Layout,
class... CoordsDims>
600 "Use deriv(DiscreteElement<Deriv<InterestDim1, InterestDim2>>(1, 1), ...) "
601 "instead)")]] KOKKOS_FUNCTION
double
602 deriv2(
ddc::Coordinate<CoordsDims...>
const& coord_eval,
603 ddc::
ChunkSpan<
double const, spline_domain_type, Layout, memory_space>
const spline_coef)
606 DDC_DISABLE_DEPRECATED_WARNINGS_PUSH()
610 typename evaluation_discrete_dimension_type1::continuous_dimension_type>
611 && std::is_same_v<InterestDim2, continuous_dimension_type2>)
614 typename evaluation_discrete_dimension_type1::continuous_dimension_type>
615 && std::is_same_v<InterestDim1, continuous_dimension_type2>));
616 return deriv_1_and_2(coord_eval, spline_coef);
617 DDC_DISABLE_DEPRECATED_WARNINGS_POP()
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
644 class BatchedInterpolationDDom,
646 [[deprecated(
"Use deriv(DiscreteElement<Deriv<Dim1>>(1), ...) instead)")]]
void deriv_dim_1(
647 ddc::
ChunkSpan<
double, BatchedInterpolationDDom, Layout1, memory_space>
const
650 ddc::Coordinate<CoordsDims...>
const,
651 BatchedInterpolationDDom,
653 memory_space>
const coords_eval,
656 batched_spline_domain_type<BatchedInterpolationDDom>,
658 memory_space>
const spline_coef)
const
661 ddc::DiscreteElement<
Deriv<continuous_dimension_type1>>(1),
668
669
670
671
672
673
674
675
676
677
678
679
680 template <
class Layout1,
class Layout2,
class BatchedInterpolationDDom>
681 [[deprecated(
"Use deriv(DiscreteElement<Deriv<Dim1>>(1), ...) instead)")]]
void deriv_dim_1(
682 ddc::
ChunkSpan<
double, BatchedInterpolationDDom, Layout1, memory_space>
const
686 batched_spline_domain_type<BatchedInterpolationDDom>,
688 memory_space>
const spline_coef)
const
691 ddc::DiscreteElement<
Deriv<continuous_dimension_type1>>(1),
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
718 class BatchedInterpolationDDom,
720 [[deprecated(
"Use deriv(DiscreteElement<Deriv<Dim2>>(1), ...) instead)")]]
void deriv_dim_2(
721 ddc::
ChunkSpan<
double, BatchedInterpolationDDom, Layout1, memory_space>
const
724 ddc::Coordinate<CoordsDims...>
const,
725 BatchedInterpolationDDom,
727 memory_space>
const coords_eval,
730 batched_spline_domain_type<BatchedInterpolationDDom>,
732 memory_space>
const spline_coef)
const
735 ddc::DiscreteElement<
Deriv<continuous_dimension_type2>>(1),
742
743
744
745
746
747
748
749
750
751
752
753
754 template <
class Layout1,
class Layout2,
class BatchedInterpolationDDom>
755 [[deprecated(
"Use deriv(DiscreteElement<Deriv<Dim2>>(1), ...) instead)")]]
void deriv_dim_2(
756 ddc::
ChunkSpan<
double, BatchedInterpolationDDom, Layout1, memory_space>
const
760 batched_spline_domain_type<BatchedInterpolationDDom>,
762 memory_space>
const spline_coef)
const
765 ddc::DiscreteElement<
Deriv<continuous_dimension_type2>>(1),
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
792 class BatchedInterpolationDDom,
794 [[deprecated(
"Use deriv(DiscreteElement<Deriv<Dim1>, Deriv<Dim2>>(1, 1), ...) instead)")]]
void
796 ddc::
ChunkSpan<
double, BatchedInterpolationDDom, Layout1, memory_space>
const
799 ddc::Coordinate<CoordsDims...>
const,
800 BatchedInterpolationDDom,
802 memory_space>
const coords_eval,
805 batched_spline_domain_type<BatchedInterpolationDDom>,
807 memory_space>
const spline_coef)
const
810 ddc::DiscreteElement<
811 Deriv<continuous_dimension_type1>,
812 Deriv<continuous_dimension_type2>>(1, 1),
819
820
821
822
823
824
825
826
827
828
829
830
831 template <
class Layout1,
class Layout2,
class BatchedInterpolationDDom>
832 [[deprecated(
"Use deriv(DiscreteElement<Deriv<Dim1>, Deriv<Dim2>>(1, 1), ...) instead)")]]
void
834 ddc::
ChunkSpan<
double, BatchedInterpolationDDom, Layout1, memory_space>
const
838 batched_spline_domain_type<BatchedInterpolationDDom>,
840 memory_space>
const spline_coef)
const
843 ddc::DiscreteElement<
844 Deriv<continuous_dimension_type1>,
845 Deriv<continuous_dimension_type2>>(1, 1),
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
874 class BatchedInterpolationDDom,
876 [[deprecated(
"Use deriv(DiscreteElement<Deriv<InterestDim>>(1), ...) instead)")]]
void deriv(
877 ddc::
ChunkSpan<
double, BatchedInterpolationDDom, Layout1, memory_space>
const
880 ddc::Coordinate<CoordsDims...>
const,
881 BatchedInterpolationDDom,
883 memory_space>
const coords_eval,
886 batched_spline_domain_type<BatchedInterpolationDDom>,
888 memory_space>
const spline_coef)
const
890 DDC_DISABLE_DEPRECATED_WARNINGS_PUSH()
894 typename evaluation_discrete_dimension_type1::continuous_dimension_type>
895 || std::is_same_v<InterestDim, continuous_dimension_type2>);
896 if constexpr (std::is_same_v<
898 typename evaluation_discrete_dimension_type1::
899 continuous_dimension_type>) {
900 return deriv_dim_1(spline_eval, coords_eval, spline_coef);
901 }
else if constexpr (std::is_same_v<
903 typename evaluation_discrete_dimension_type2::
904 continuous_dimension_type>) {
905 return deriv_dim_2(spline_eval, coords_eval, spline_coef);
907 DDC_DISABLE_DEPRECATED_WARNINGS_POP()
911
912
913
914
915
916
917
918
919
920
921
922
923
924 template <
class InterestDim,
class Layout1,
class Layout2,
class BatchedInterpolationDDom>
925 [[deprecated(
"Use deriv(DiscreteElement<Deriv<InterestDim>>(1), ...) instead)")]]
void deriv(
926 ddc::
ChunkSpan<
double, BatchedInterpolationDDom, Layout1, memory_space>
const
930 batched_spline_domain_type<BatchedInterpolationDDom>,
932 memory_space>
const spline_coef)
const
934 DDC_DISABLE_DEPRECATED_WARNINGS_PUSH()
938 typename evaluation_discrete_dimension_type1::continuous_dimension_type>
939 || std::is_same_v<InterestDim, continuous_dimension_type2>);
940 if constexpr (std::is_same_v<
942 typename evaluation_discrete_dimension_type1::
943 continuous_dimension_type>) {
944 return deriv_dim_1(spline_eval, spline_coef);
945 }
else if constexpr (std::is_same_v<
947 typename evaluation_discrete_dimension_type2::
948 continuous_dimension_type>) {
949 return deriv_dim_2(spline_eval, spline_coef);
951 DDC_DISABLE_DEPRECATED_WARNINGS_POP()
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
983 class BatchedInterpolationDDom,
986 "Use deriv(DiscreteElement<Deriv<InterestDim1>, Deriv<InterestDim2>>(1, 1), ...) "
988 deriv2(
ddc::
ChunkSpan<
double, BatchedInterpolationDDom, Layout1, memory_space>
const
991 ddc::Coordinate<CoordsDims...>
const,
992 BatchedInterpolationDDom,
994 memory_space>
const coords_eval,
997 batched_spline_domain_type<BatchedInterpolationDDom>,
999 memory_space>
const spline_coef)
const
1001 DDC_DISABLE_DEPRECATED_WARNINGS_PUSH()
1005 typename evaluation_discrete_dimension_type1::continuous_dimension_type>
1006 && std::is_same_v<InterestDim2, continuous_dimension_type2>)
1009 typename evaluation_discrete_dimension_type1::continuous_dimension_type>
1010 && std::is_same_v<InterestDim1, continuous_dimension_type2>));
1011 return deriv_1_and_2(spline_eval, coords_eval, spline_coef);
1012 DDC_DISABLE_DEPRECATED_WARNINGS_POP()
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1038 class BatchedInterpolationDDom>
1040 "Use deriv(DiscreteElement<Deriv<InterestDim1>, Deriv<InterestDim2>>(1, 1), ...) "
1042 deriv2(
ddc::
ChunkSpan<
double, BatchedInterpolationDDom, Layout1, memory_space>
const
1046 batched_spline_domain_type<BatchedInterpolationDDom>,
1048 memory_space>
const spline_coef)
const
1050 DDC_DISABLE_DEPRECATED_WARNINGS_PUSH()
1054 typename evaluation_discrete_dimension_type1::continuous_dimension_type>
1055 && std::is_same_v<InterestDim2, continuous_dimension_type2>)
1058 typename evaluation_discrete_dimension_type1::continuous_dimension_type>
1059 && std::is_same_v<InterestDim1, continuous_dimension_type2>));
1060 return deriv_1_and_2(spline_eval, spline_coef);
1061 DDC_DISABLE_DEPRECATED_WARNINGS_POP()
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078 template <
class DElem,
class Layout,
class... CoordsDims>
1080 DElem
const& deriv_order,
1081 ddc::Coordinate<CoordsDims...>
const& coord_eval,
1082 ddc::
ChunkSpan<
double const, spline_domain_type, Layout, memory_space>
const
1085 return eval_no_bc(deriv_order, coord_eval, spline_coef);
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1115 class BatchedInterpolationDDom,
1116 class... CoordsDims>
1118 DElem
const& deriv_order,
1119 ddc::
ChunkSpan<
double, BatchedInterpolationDDom, Layout1, memory_space>
const
1122 ddc::Coordinate<CoordsDims...>
const,
1123 BatchedInterpolationDDom,
1125 memory_space>
const coords_eval,
1128 batched_spline_domain_type<BatchedInterpolationDDom>,
1130 memory_space>
const spline_coef)
const
1132 static_assert(is_discrete_element_v<DElem>);
1134 batch_domain_type<BatchedInterpolationDDom>
const batch_domain(coords_eval.domain());
1135 evaluation_domain_type1
const evaluation_domain1(spline_eval.domain());
1136 evaluation_domain_type2
const evaluation_domain2(spline_eval.domain());
1137 ddc::parallel_for_each(
1138 "ddc_splines_differentiate_2d",
1141 KOKKOS_CLASS_LAMBDA(
1142 typename batch_domain_type<
1143 BatchedInterpolationDDom>::discrete_element_type
const j) {
1144 auto const spline_eval_2D = spline_eval[j];
1145 auto const coords_eval_2D = coords_eval[j];
1146 auto const spline_coef_2D = spline_coef[j];
1147 for (
auto const i1 : evaluation_domain1) {
1148 for (
auto const i2 : evaluation_domain2) {
1149 spline_eval_2D(i1, i2) = eval_no_bc(
1151 coords_eval_2D(i1, i2),
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173 template <
class DElem,
class Layout1,
class Layout2,
class BatchedInterpolationDDom>
1175 DElem
const& deriv_order,
1176 ddc::
ChunkSpan<
double, BatchedInterpolationDDom, Layout1, memory_space>
const
1180 batched_spline_domain_type<BatchedInterpolationDDom>,
1182 memory_space>
const spline_coef)
const
1184 static_assert(is_discrete_element_v<DElem>);
1186 batch_domain_type<BatchedInterpolationDDom>
const batch_domain(spline_eval.domain());
1187 evaluation_domain_type1
const evaluation_domain1(spline_eval.domain());
1188 evaluation_domain_type2
const evaluation_domain2(spline_eval.domain());
1189 ddc::parallel_for_each(
1190 "ddc_splines_differentiate_2d",
1193 KOKKOS_CLASS_LAMBDA(
1194 typename batch_domain_type<
1195 BatchedInterpolationDDom>::discrete_element_type
const j) {
1196 auto const spline_eval_2D = spline_eval[j];
1197 auto const spline_coef_2D = spline_coef[j];
1198 for (
auto const i1 : evaluation_domain1) {
1199 for (
auto const i2 : evaluation_domain2) {
1200 ddc::Coordinate<continuous_dimension_type1, continuous_dimension_type2>
1201 coord_eval_2D(
ddc::coordinate(i1),
ddc::coordinate(i2));
1202 spline_eval_2D(i1, i2)
1203 = eval_no_bc(deriv_order, coord_eval_2D, spline_coef_2D);
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222 template <
class Layout1,
class Layout2,
class BatchedDDom,
class BatchedSplineDDom>
1224 ddc::
ChunkSpan<
double, BatchedDDom, Layout1, memory_space>
const integrals,
1225 ddc::
ChunkSpan<
double const, BatchedSplineDDom, Layout2, memory_space>
const
1229 ddc::type_seq_contains_v<
1230 ddc::detail::TypeSeq<bsplines_type1, bsplines_type2>,
1231 to_type_seq_t<BatchedSplineDDom>>,
1232 "The spline coefficients domain must contain the bsplines dimensions");
1233 using batch_domain_type
1234 =
ddc::remove_dims_of_t<BatchedSplineDDom, bsplines_type1, bsplines_type2>;
1236 std::is_same_v<batch_domain_type, BatchedDDom>,
1237 "The integrals domain must only contain the batch dimensions");
1239 batch_domain_type batch_domain(integrals.domain());
1244 ddc::integrals(exec_space(), values1);
1249 ddc::integrals(exec_space(), values2);
1251 ddc::parallel_for_each(
1252 "ddc_splines_integrate_bsplines",
1255 KOKKOS_LAMBDA(
typename batch_domain_type::discrete_element_type
const j) {
1257 for (
typename spline_domain_type1::discrete_element_type
const i1 :
1259 for (
typename spline_domain_type2::discrete_element_type
const i2 :
1261 integrals(j) += spline_coef(i1, i2, j) * values1(i1) * values2(i2);
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283 template <
class Layout,
class... CoordsDims>
1284 KOKKOS_INLINE_FUNCTION
double eval(
1285 ddc::Coordinate<CoordsDims...> coord_eval,
1286 ddc::
ChunkSpan<
double const, spline_domain_type, Layout, memory_space>
const
1289 using Dim1 = continuous_dimension_type1;
1290 using Dim2 = continuous_dimension_type2;
1291 if constexpr (bsplines_type1::is_periodic()) {
1292 if (
ddc::get<Dim1>(coord_eval) <
ddc::discrete_space<bsplines_type1>().rmin()
1293 ||
ddc::get<Dim1>(coord_eval) >
ddc::discrete_space<bsplines_type1>().rmax()) {
1294 ddc::get<Dim1>(coord_eval)
1296 (
ddc::get<Dim1>(coord_eval)
1297 -
ddc::discrete_space<bsplines_type1>().rmin())
1298 /
ddc::discrete_space<bsplines_type1>().length())
1299 *
ddc::discrete_space<bsplines_type1>().length();
1302 if constexpr (bsplines_type2::is_periodic()) {
1303 if (
ddc::get<Dim2>(coord_eval) <
ddc::discrete_space<bsplines_type2>().rmin()
1304 ||
ddc::get<Dim2>(coord_eval) >
ddc::discrete_space<bsplines_type2>().rmax()) {
1305 ddc::get<Dim2>(coord_eval)
1307 (
ddc::get<Dim2>(coord_eval)
1308 -
ddc::discrete_space<bsplines_type2>().rmin())
1309 /
ddc::discrete_space<bsplines_type2>().length())
1310 *
ddc::discrete_space<bsplines_type2>().length();
1313 if constexpr (!bsplines_type1::is_periodic()) {
1314 if (
ddc::get<Dim1>(coord_eval) <
ddc::discrete_space<bsplines_type1>().rmin()) {
1315 return m_lower_extrap_rule_1(coord_eval, spline_coef);
1317 if (
ddc::get<Dim1>(coord_eval) >
ddc::discrete_space<bsplines_type1>().rmax()) {
1318 return m_upper_extrap_rule_1(coord_eval, spline_coef);
1321 if constexpr (!bsplines_type2::is_periodic()) {
1322 if (
ddc::get<Dim2>(coord_eval) <
ddc::discrete_space<bsplines_type2>().rmin()) {
1323 return m_lower_extrap_rule_2(coord_eval, spline_coef);
1325 if (
ddc::get<Dim2>(coord_eval) >
ddc::discrete_space<bsplines_type2>().rmax()) {
1326 return m_upper_extrap_rule_2(coord_eval, spline_coef);
1331 ddc::Coordinate<continuous_dimension_type1, continuous_dimension_type2>(
1332 ddc::get<Dim1>(coord_eval),
1333 ddc::get<Dim2>(coord_eval)),
1338
1339
1340
1341
1342
1343
1344
1345 template <
class... DerivDims,
class Layout,
class... CoordsDims>
1346 KOKKOS_INLINE_FUNCTION
double eval_no_bc(
1347 ddc::DiscreteElement<DerivDims...>
const& deriv_order,
1348 ddc::Coordinate<CoordsDims...>
const& coord_eval,
1349 ddc::
ChunkSpan<
double const, spline_domain_type, Layout, memory_space>
const
1352 using deriv_dim1 =
ddc::
Deriv<continuous_dimension_type1>;
1353 using deriv_dim2 =
ddc::
Deriv<continuous_dimension_type2>;
1354 using deriv_dims =
ddc::detail::TypeSeq<DerivDims...>;
1358 (in_tags_v<DerivDims,
ddc::detail::TypeSeq<deriv_dim1, deriv_dim2>> && ...),
1359 "The only valid dimensions for deriv_order are Deriv<Dim1> and Deriv<Dim2>");
1361 ddc::DiscreteElement<bsplines_type1> jmin1;
1362 ddc::DiscreteElement<bsplines_type2> jmin2;
1364 std::array<
double, bsplines_type1::degree() + 1> vals1_ptr;
1365 Kokkos::mdspan<
double, Kokkos::extents<std::size_t, bsplines_type1::degree() + 1>>
const
1366 vals1(vals1_ptr.data());
1367 std::array<
double, bsplines_type2::degree() + 1> vals2_ptr;
1368 Kokkos::mdspan<
double, Kokkos::extents<std::size_t, bsplines_type2::degree() + 1>>
const
1369 vals2(vals2_ptr.data());
1370 ddc::Coordinate<continuous_dimension_type1>
const coord_eval_interest1(coord_eval);
1371 ddc::Coordinate<continuous_dimension_type2>
const coord_eval_interest2(coord_eval);
1373 if constexpr (!in_tags_v<deriv_dim1, deriv_dims>) {
1374 jmin1 =
ddc::discrete_space<bsplines_type1>().eval_basis(vals1, coord_eval_interest1);
1376 auto const order1 = deriv_order.
template uid<deriv_dim1>();
1377 KOKKOS_ASSERT(order1 > 0 && order1 <= bsplines_type1::degree())
1379 std::array<
double, (bsplines_type1::degree() + 1) * (bsplines_type1::degree() + 1)>
1385 bsplines_type1::degree() + 1,
1386 Kokkos::dynamic_extent>>
const derivs1(derivs1_ptr.data(), order1 + 1);
1388 jmin1 =
ddc::discrete_space<bsplines_type1>()
1389 .eval_basis_and_n_derivs(derivs1, coord_eval_interest1, order1);
1391 for (std::size_t i = 0; i < bsplines_type1::degree() + 1; ++i) {
1392 vals1[i] = DDC_MDSPAN_ACCESS_OP(derivs1, i, order1);
1396 if constexpr (!in_tags_v<deriv_dim2, deriv_dims>) {
1397 jmin2 =
ddc::discrete_space<bsplines_type2>().eval_basis(vals2, coord_eval_interest2);
1399 auto const order2 = deriv_order.
template uid<deriv_dim2>();
1400 KOKKOS_ASSERT(order2 > 0 && order2 <= bsplines_type2::degree())
1402 std::array<
double, (bsplines_type2::degree() + 1) * (bsplines_type2::degree() + 1)>
1408 bsplines_type2::degree() + 1,
1409 Kokkos::dynamic_extent>>
const derivs2(derivs2_ptr.data(), order2 + 1);
1411 jmin2 =
ddc::discrete_space<bsplines_type2>()
1412 .eval_basis_and_n_derivs(derivs2, coord_eval_interest2, order2);
1414 for (std::size_t i = 0; i < bsplines_type2::degree() + 1; ++i) {
1415 vals2[i] = DDC_MDSPAN_ACCESS_OP(derivs2, i, order2);
1420 for (std::size_t i = 0; i < bsplines_type1::degree() + 1; ++i) {
1421 for (std::size_t j = 0; j < bsplines_type2::degree() + 1; ++j) {
1423 ddc::DiscreteElement<
1425 bsplines_type2>(jmin1 + i, jmin2 + j))
1426 * vals1[i] * vals2[j];
friend class DiscreteDomain
KOKKOS_DEFAULTED_FUNCTION constexpr DiscreteElement()=default
A class to evaluate, differentiate or integrate a 2D spline function.
void operator()(ddc::ChunkSpan< double, BatchedInterpolationDDom, Layout1, memory_space > const spline_eval, ddc::ChunkSpan< double const, batched_spline_domain_type< BatchedInterpolationDDom >, Layout2, memory_space > const spline_coef) const
Evaluate 2D spline function (described by its spline coefficients) on a mesh.
SplineEvaluator2D(SplineEvaluator2D &&x)=default
Move-constructs.
lower_extrapolation_rule_1_type lower_extrapolation_rule_dim_1() const
Get the lower extrapolation rule along the first dimension.
SplineEvaluator2D & operator=(SplineEvaluator2D const &x)=default
Copy-assigns.
void deriv(DElem const &deriv_order, ddc::ChunkSpan< double, BatchedInterpolationDDom, Layout1, memory_space > const spline_eval, ddc::ChunkSpan< ddc::Coordinate< CoordsDims... > const, BatchedInterpolationDDom, Layout2, memory_space > const coords_eval, ddc::ChunkSpan< double const, batched_spline_domain_type< BatchedInterpolationDDom >, Layout3, memory_space > const spline_coef) const
Differentiate 2D spline function (described by its spline coefficients) on a mesh along the dimension...
SplineEvaluator2D(SplineEvaluator2D const &x)=default
Copy-constructs.
~SplineEvaluator2D()=default
Destructs.
KOKKOS_FUNCTION double deriv(DElem const &deriv_order, ddc::Coordinate< CoordsDims... > const &coord_eval, ddc::ChunkSpan< double const, spline_domain_type, Layout, memory_space > const spline_coef) const
Differentiate 2D spline function (described by its spline coefficients) at a given coordinate along t...
void deriv(DElem const &deriv_order, ddc::ChunkSpan< double, BatchedInterpolationDDom, Layout1, memory_space > const spline_eval, ddc::ChunkSpan< double const, batched_spline_domain_type< BatchedInterpolationDDom >, Layout2, memory_space > const spline_coef) const
Differentiate 2D spline function (described by its spline coefficients) on a mesh along the dimension...
void integrate(ddc::ChunkSpan< double, BatchedDDom, Layout1, memory_space > const integrals, ddc::ChunkSpan< double const, BatchedSplineDDom, Layout2, memory_space > const spline_coef) const
Perform batched 2D integrations of a spline function (described by its spline coefficients) along the...
upper_extrapolation_rule_2_type upper_extrapolation_rule_dim_2() const
Get the upper extrapolation rule along the second dimension.
upper_extrapolation_rule_1_type upper_extrapolation_rule_dim_1() const
Get the upper extrapolation rule along the first dimension.
lower_extrapolation_rule_2_type lower_extrapolation_rule_dim_2() const
Get the lower extrapolation rule along the second dimension.
SplineEvaluator2D & operator=(SplineEvaluator2D &&x)=default
Move-assigns.
KOKKOS_FUNCTION double operator()(ddc::Coordinate< CoordsDims... > const &coord_eval, ddc::ChunkSpan< double const, spline_domain_type, Layout, memory_space > const spline_coef) const
Evaluate 2D spline function (described by its spline coefficients) at a given coordinate.
void operator()(ddc::ChunkSpan< double, BatchedInterpolationDDom, Layout1, memory_space > const spline_eval, ddc::ChunkSpan< ddc::Coordinate< CoordsDims... > const, BatchedInterpolationDDom, Layout2, memory_space > const coords_eval, ddc::ChunkSpan< double const, batched_spline_domain_type< BatchedInterpolationDDom >, Layout3, memory_space > const spline_coef) const
Evaluate 2D spline function (described by its spline coefficients) on a mesh.
SplineEvaluator2D(LowerExtrapolationRule1 const &lower_extrap_rule1, UpperExtrapolationRule1 const &upper_extrap_rule1, LowerExtrapolationRule2 const &lower_extrap_rule2, UpperExtrapolationRule2 const &upper_extrap_rule2)
Build a SplineEvaluator2D acting on batched_spline_domain.
The top-level namespace of DDC.
A templated struct representing a discrete dimension storing the derivatives of a function along a co...