Gyselalib++
spline_interpolator_2d_rp.hpp
1 // SPDX-License-Identifier: MIT
2 #pragma once
3 #include "ddc_alias_inline_functions.hpp"
4 #include "ddc_aliases.hpp"
5 #include "geometry.hpp"
6 #include "i_interpolator_2d_rp.hpp"
7 
8 
14 template <class RadialExtrapolationRule>
16 {
17 public:
19  using evaluator_type = ddc::SplineEvaluator2D<
20  Kokkos::DefaultHostExecutionSpace,
21  Kokkos::HostSpace,
22  BSplinesR,
24  GridR,
25  GridTheta,
26  RadialExtrapolationRule,
27  RadialExtrapolationRule,
28  ddc::PeriodicExtrapolationRule<Theta>,
29  ddc::PeriodicExtrapolationRule<Theta>,
30  GridR,
31  GridTheta>;
32 
33 private:
34  SplineRThetaBuilder const& m_builder;
35 
36  evaluator_type const& m_evaluator;
37 
38  mutable host_t<DFieldMem<IdxRangeBSRTheta>> m_coefs;
39 
40  using r_deriv_type = host_t<DConstField<SplineRThetaBuilder::batched_derivs_domain_type1>>;
41  using p_deriv_type = host_t<DConstField<SplineRThetaBuilder::batched_derivs_domain_type2>>;
42  using mixed_deriv_type = host_t<DConstField<SplineRThetaBuilder::batched_derivs_domain_type>>;
43 
44 public:
50  SplineInterpolatorRTheta(SplineRThetaBuilder const& builder, evaluator_type const& evaluator)
51  : m_builder(builder)
52  , m_evaluator(evaluator)
53  , m_coefs(get_spline_idx_range(builder))
54  {
55  }
56 
57  ~SplineInterpolatorRTheta() override = default;
58 
71  host_t<DFieldRTheta> operator()(
72  host_t<DFieldRTheta> const inout_data,
73  host_t<Field<CoordRTheta const, IdxRangeRTheta>> const coordinates) const override
74  {
75 #ifndef NDEBUG
76  // To ensure that the interpolator is C0, we ensure that
77  // the value at (r=0,theta) is the same for all theta.
78  IdxRangeR r_idx_range = get_idx_range<GridR>(inout_data);
79  IdxRangeTheta theta_idx_range = get_idx_range<GridTheta>(inout_data);
80  if (ddc::coordinate(r_idx_range.front()) == 0) {
81  ddc::for_each(theta_idx_range, [&](IdxTheta const ip) {
82  bool const unicity_center_point
83  = inout_data(r_idx_range.front(), ip)
84  == inout_data(r_idx_range.front(), theta_idx_range.front());
85  if (!unicity_center_point) {
86  std::printf("Unicity of the value at the center point is not verified.");
87  assert(unicity_center_point);
88  }
89  });
90  }
91 #endif
92 
93  m_builder(get_field(m_coefs), get_const_field(inout_data));
94  m_evaluator(get_field(inout_data), coordinates, get_const_field(m_coefs));
95  return inout_data;
96  }
97 };
98 
99 
100 
108 template <class RadialExtrapolationRule>
110 {
111 public:
113  using evaluator_type = ddc::SplineEvaluator2D<
114  Kokkos::DefaultHostExecutionSpace,
115  Kokkos::HostSpace,
116  BSplinesR,
118  GridR,
119  GridTheta,
120  RadialExtrapolationRule,
121  RadialExtrapolationRule,
122  ddc::PeriodicExtrapolationRule<Theta>,
123  ddc::PeriodicExtrapolationRule<Theta>,
124  GridR,
125  GridTheta>;
126 
127 private:
128  SplineRThetaBuilder const& m_builder;
129 
130  evaluator_type const& m_evaluator;
131 
132 public:
139  SplineRThetaBuilder const& builder,
140  evaluator_type const& evaluator)
141  : m_builder(builder)
142  , m_evaluator(evaluator)
143  {
144  }
145 
146  ~PreallocatableSplineInterpolatorRTheta() override = default;
147 
153  std::unique_ptr<IInterpolatorRTheta> preallocate() const override
154  {
155  return std::make_unique<
156  SplineInterpolatorRTheta<RadialExtrapolationRule>>(m_builder, m_evaluator);
157  }
158 };
A class which provides an interpolating function.
Definition: i_interpolator_2d_rp.hpp:18
A class which provides access to an interpolating function which can be preallocated where useful.
Definition: i_interpolator_2d_rp.hpp:55
A class which stores information necessary to create a pointer to an instance of the SplineInterpolat...
Definition: spline_interpolator_2d_rp.hpp:110
ddc::SplineEvaluator2D< Kokkos::DefaultHostExecutionSpace, Kokkos::HostSpace, BSplinesR, BSplinesTheta, GridR, GridTheta, RadialExtrapolationRule, RadialExtrapolationRule, ddc::PeriodicExtrapolationRule< Theta >, ddc::PeriodicExtrapolationRule< Theta >, GridR, GridTheta > evaluator_type
The type of the 2D Spline Evaluator used by this class.
Definition: spline_interpolator_2d_rp.hpp:125
PreallocatableSplineInterpolatorRTheta(SplineRThetaBuilder const &builder, evaluator_type const &evaluator)
Create an object capable of creating SplineInterpolatorRTheta objects.
Definition: spline_interpolator_2d_rp.hpp:138
std::unique_ptr< IInterpolatorRTheta > preallocate() const override
Create a pointer to an instance of the SplineInterpolatorRTheta class.
Definition: spline_interpolator_2d_rp.hpp:153
A class for interpolating a function using splines in polar coordinates.
Definition: spline_interpolator_2d_rp.hpp:16
SplineInterpolatorRTheta(SplineRThetaBuilder const &builder, evaluator_type const &evaluator)
Create a spline interpolator object.
Definition: spline_interpolator_2d_rp.hpp:50
host_t< DFieldRTheta > operator()(host_t< DFieldRTheta > const inout_data, host_t< Field< CoordRTheta const, IdxRangeRTheta >> const coordinates) const override
Approximate the value of a function at a set of polar coordinates using the current values at a known...
Definition: spline_interpolator_2d_rp.hpp:71
ddc::SplineEvaluator2D< Kokkos::DefaultHostExecutionSpace, Kokkos::HostSpace, BSplinesR, BSplinesTheta, GridR, GridTheta, RadialExtrapolationRule, RadialExtrapolationRule, ddc::PeriodicExtrapolationRule< Theta >, ddc::PeriodicExtrapolationRule< Theta >, GridR, GridTheta > evaluator_type
The type of the 2D Spline Evaluator used by this class.
Definition: spline_interpolator_2d_rp.hpp:31
Definition: geometry.hpp:93
Definition: geometry.hpp:100
Definition: geometry.hpp:116
Definition: geometry.hpp:119