Gyselalib++
 
Loading...
Searching...
No Matches
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
14template <class RadialExtrapolationRule>
16{
17public:
19 using evaluator_type = ddc::SplineEvaluator2D<
20 Kokkos::DefaultHostExecutionSpace,
21 Kokkos::HostSpace,
24 GridR,
26 RadialExtrapolationRule,
27 RadialExtrapolationRule,
28 ddc::PeriodicExtrapolationRule<Theta>,
29 ddc::PeriodicExtrapolationRule<Theta>,
30 GridR,
31 GridTheta>;
32
33private:
34 SplineRThetaBuilder_host 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_host::batched_derivs_domain_type1>>;
41 using p_deriv_type = host_t<DConstField<SplineRThetaBuilder_host::batched_derivs_domain_type2>>;
42 using mixed_deriv_type
43 = host_t<DConstField<SplineRThetaBuilder_host::batched_derivs_domain_type>>;
44
45public:
52 SplineRThetaBuilder_host const& builder,
53 evaluator_type const& evaluator)
54 : m_builder(builder)
55 , m_evaluator(evaluator)
56 , m_coefs(get_spline_idx_range(builder))
57 {
58 }
59
60 ~SplineInterpolatorRTheta() override = default;
61
74 host_t<DFieldRTheta> operator()(
75 host_t<DFieldRTheta> const inout_data,
76 host_t<Field<CoordRTheta const, IdxRangeRTheta>> const coordinates) const override
77 {
78#ifndef NDEBUG
79 // To ensure that the interpolator is C0, we ensure that
80 // the value at (r=0,theta) is the same for all theta.
81 IdxRangeR r_idx_range = get_idx_range<GridR>(inout_data);
82 IdxRangeTheta theta_idx_range = get_idx_range<GridTheta>(inout_data);
83 if (ddc::coordinate(r_idx_range.front()) == 0) {
84 ddc::for_each(theta_idx_range, [&](IdxTheta const ip) {
85 bool const unicity_center_point
86 = inout_data(r_idx_range.front(), ip)
87 == inout_data(r_idx_range.front(), theta_idx_range.front());
88 if (!unicity_center_point) {
89 std::printf("Unicity of the value at the center point is not verified.");
90 assert(unicity_center_point);
91 }
92 });
93 }
94#endif
95
96 m_builder(get_field(m_coefs), get_const_field(inout_data));
97 m_evaluator(get_field(inout_data), coordinates, get_const_field(m_coefs));
98 return inout_data;
99 }
100};
101
102
103
111template <class RadialExtrapolationRule>
113{
114public:
116 using evaluator_type = ddc::SplineEvaluator2D<
117 Kokkos::DefaultHostExecutionSpace,
118 Kokkos::HostSpace,
119 BSplinesR,
121 GridR,
122 GridTheta,
123 RadialExtrapolationRule,
124 RadialExtrapolationRule,
125 ddc::PeriodicExtrapolationRule<Theta>,
126 ddc::PeriodicExtrapolationRule<Theta>,
127 GridR,
128 GridTheta>;
129
130private:
131 SplineRThetaBuilder_host const& m_builder;
132
133 evaluator_type const& m_evaluator;
134
135public:
142 SplineRThetaBuilder_host const& builder,
143 evaluator_type const& evaluator)
144 : m_builder(builder)
145 , m_evaluator(evaluator)
146 {
147 }
148
149 ~PreallocatableSplineInterpolatorRTheta() override = default;
150
156 std::unique_ptr<IInterpolatorRTheta> preallocate() const override
157 {
158 return std::make_unique<
160 }
161};
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:113
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:128
std::unique_ptr< IInterpolatorRTheta > preallocate() const override
Create a pointer to an instance of the SplineInterpolatorRTheta class.
Definition spline_interpolator_2d_rp.hpp:156
PreallocatableSplineInterpolatorRTheta(SplineRThetaBuilder_host const &builder, evaluator_type const &evaluator)
Create an object capable of creating SplineInterpolatorRTheta objects.
Definition spline_interpolator_2d_rp.hpp:141
A class for interpolating a function using splines in polar coordinates.
Definition spline_interpolator_2d_rp.hpp:16
SplineInterpolatorRTheta(SplineRThetaBuilder_host const &builder, evaluator_type const &evaluator)
Create a spline interpolator object.
Definition spline_interpolator_2d_rp.hpp:51
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:74
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