Gyselalib++
 
Loading...
Searching...
No Matches
discrete_to_cartesian.hpp
1// SPDX-License-Identifier: MIT
2#pragma once
3#include <iostream>
4
5#include <ddc/ddc.hpp>
6
7#include <sll/math_tools.hpp>
8#include <sll/view.hpp>
9
10#include "mapping_tools.hpp"
11
24template <
25 class X,
26 class Y,
27 class SplineEvaluator,
28 class R = typename SplineEvaluator::continuous_dimension_type1,
29 class Theta = typename SplineEvaluator::continuous_dimension_type2,
30 class MemorySpace = typename SplineEvaluator::memory_space>
32{
33 static_assert(std::is_same_v<MemorySpace, typename SplineEvaluator::memory_space>);
34
35public:
39 using BSplineR = typename SplineEvaluator::bsplines_type1;
43 using BSplineTheta = typename SplineEvaluator::bsplines_type2;
44
53
55 using CoordArg = ddc::Coordinate<R, Theta>;
57 using CoordResult = ddc::Coordinate<X, Y>;
58
59private:
60 using spline_idx_range = ddc::DiscreteDomain<BSplineR, BSplineTheta>;
61
62 using SplineType = ddc::ChunkView<double, spline_idx_range, Kokkos::layout_right, MemorySpace>;
63
64 using IdxRangeRTheta = typename SplineEvaluator::evaluation_domain_type;
65 using IdxRangeTheta = typename SplineEvaluator::evaluation_domain_type2;
66 using IdxTheta = typename IdxRangeTheta::discrete_element_type;
67
68private:
69 SplineType m_x_spline_representation;
70 SplineType m_y_spline_representation;
71 SplineEvaluator m_spline_evaluator;
72 IdxRangeRTheta m_idx_range_singular_point;
73
74public:
105 KOKKOS_FUNCTION DiscreteToCartesian(
106 SplineType curvilinear_to_x,
107 SplineType curvilinear_to_y,
108 SplineEvaluator const& evaluator,
109 IdxRangeRTheta idx_range_singular_point)
110 : m_x_spline_representation(curvilinear_to_x)
111 , m_y_spline_representation(curvilinear_to_y)
112 , m_spline_evaluator(evaluator)
113 , m_idx_range_singular_point(idx_range_singular_point)
114 {
115 }
116
130 KOKKOS_FUNCTION ddc::Coordinate<X, Y> operator()(
131 ddc::Coordinate<curvilinear_tag_r, curvilinear_tag_theta> const& coord) const
132 {
133 const double x = m_spline_evaluator(coord, m_x_spline_representation.span_cview());
134 const double y = m_spline_evaluator(coord, m_y_spline_representation.span_cview());
135 return ddc::Coordinate<X, Y>(x, y);
136 }
137
151 KOKKOS_FUNCTION void jacobian_matrix(
152 ddc::Coordinate<curvilinear_tag_r, curvilinear_tag_theta> const& coord,
153 Matrix_2x2& matrix) const
154 {
155 matrix[0][0]
156 = m_spline_evaluator.deriv_dim_1(coord, m_x_spline_representation.span_cview());
157 matrix[0][1]
158 = m_spline_evaluator.deriv_dim_2(coord, m_x_spline_representation.span_cview());
159 matrix[1][0]
160 = m_spline_evaluator.deriv_dim_1(coord, m_y_spline_representation.span_cview());
161 matrix[1][1]
162 = m_spline_evaluator.deriv_dim_2(coord, m_y_spline_representation.span_cview());
163 }
164
181 KOKKOS_FUNCTION double jacobian_11(
182 ddc::Coordinate<curvilinear_tag_r, curvilinear_tag_theta> const& coord) const
183 {
184 return m_spline_evaluator.deriv_dim_1(coord, m_x_spline_representation.span_cview());
185 }
186
203 KOKKOS_FUNCTION double jacobian_12(
204 ddc::Coordinate<curvilinear_tag_r, curvilinear_tag_theta> const& coord) const
205 {
206 return m_spline_evaluator.deriv_dim_2(coord, m_x_spline_representation.span_cview());
207 }
208
225 KOKKOS_FUNCTION double jacobian_21(
226 ddc::Coordinate<curvilinear_tag_r, curvilinear_tag_theta> const& coord) const
227 {
228 return m_spline_evaluator.deriv_dim_1(coord, m_y_spline_representation.span_cview());
229 }
230
247 KOKKOS_FUNCTION double jacobian_22(
248 ddc::Coordinate<curvilinear_tag_r, curvilinear_tag_theta> const& coord) const
249 {
250 return m_spline_evaluator.deriv_dim_2(coord, m_y_spline_representation.span_cview());
251 }
252
261 KOKKOS_FUNCTION double jacobian(
262 ddc::Coordinate<curvilinear_tag_r, curvilinear_tag_theta> const& coord) const
263 {
264 Matrix_2x2 J;
265 jacobian_matrix(coord, J);
266 return determinant(J);
267 }
268
283 KOKKOS_INLINE_FUNCTION Matrix_2x2 first_order_jacobian_matrix_r_rtheta(
284 ddc::Coordinate<curvilinear_tag_r, curvilinear_tag_theta> const& coord) const
285 {
286 Matrix_2x2 matrix;
287 matrix[0][0]
288 = m_spline_evaluator.deriv_dim_1(coord, m_x_spline_representation.span_cview());
289 matrix[0][1]
290 = m_spline_evaluator.deriv_1_and_2(coord, m_x_spline_representation.span_cview());
291 matrix[1][0]
292 = m_spline_evaluator.deriv_dim_1(coord, m_y_spline_representation.span_cview());
293 matrix[1][1]
294 = m_spline_evaluator.deriv_1_and_2(coord, m_y_spline_representation.span_cview());
295 return matrix;
296 }
297
303 KOKKOS_INLINE_FUNCTION IdxRangeRTheta idx_range_singular_point() const
304 {
305 return m_idx_range_singular_point;
306 }
307
336 KOKKOS_INLINE_FUNCTION const ddc::Coordinate<X, Y> control_point(
337 ddc::DiscreteElement<BSplineR, BSplineTheta> const& el) const
338 {
339 return ddc::Coordinate<X, Y>(m_x_spline_representation(el), m_y_spline_representation(el));
340 }
341};
342
343
344namespace mapping_detail {
345template <
346 class X,
347 class Y,
348 class SplineEvaluator,
349 class R,
350 class Theta,
351 class MemorySpace,
352 class ExecSpace>
353struct MappingAccessibility<
354 ExecSpace,
355 DiscreteToCartesian<X, Y, SplineEvaluator, R, Theta, MemorySpace>>
356{
357 static constexpr bool value = Kokkos::SpaceAccessibility<ExecSpace, MemorySpace>::accessible;
358};
359
360template <class X, class Y, class SplineEvaluator, class R, class Theta, class MemorySpace>
361struct IsCurvilinear2DMapping<DiscreteToCartesian<X, Y, SplineEvaluator, R, Theta, MemorySpace>>
362 : std::true_type
363{
364};
365
366template <class X, class Y, class SplineEvaluator, class R, class Theta, class MemorySpace>
367struct SingularOPointInvJacobian<DiscreteToCartesian<X, Y, SplineEvaluator, R, Theta, MemorySpace>>
368 : std::true_type
369{
370};
371
372} // namespace mapping_detail
A class for describing discrete 2D mappings from the logical domain to the physical domain.
Definition discrete_to_cartesian.hpp:32
KOKKOS_INLINE_FUNCTION Matrix_2x2 first_order_jacobian_matrix_r_rtheta(ddc::Coordinate< curvilinear_tag_r, curvilinear_tag_theta > const &coord) const
Get the first order expansion of the Jacobian matrix with the theta component divided by r.
Definition discrete_to_cartesian.hpp:283
KOKKOS_FUNCTION DiscreteToCartesian(SplineType curvilinear_to_x, SplineType curvilinear_to_y, SplineEvaluator const &evaluator, IdxRangeRTheta idx_range_singular_point)
Instantiate a DiscreteToCartesian from the coefficients of 2D splines approximating the mapping.
Definition discrete_to_cartesian.hpp:105
KOKKOS_FUNCTION double jacobian_11(ddc::Coordinate< curvilinear_tag_r, curvilinear_tag_theta > const &coord) const
Compute the (1,1) coefficient of the Jacobian matrix.
Definition discrete_to_cartesian.hpp:181
KOKKOS_FUNCTION ddc::Coordinate< X, Y > operator()(ddc::Coordinate< curvilinear_tag_r, curvilinear_tag_theta > const &coord) const
Compute the physical coordinates from the logical coordinates.
Definition discrete_to_cartesian.hpp:130
ddc::Coordinate< X, Y > CoordResult
The type of the result of the function described by this mapping.
Definition discrete_to_cartesian.hpp:57
KOKKOS_FUNCTION void jacobian_matrix(ddc::Coordinate< curvilinear_tag_r, curvilinear_tag_theta > const &coord, Matrix_2x2 &matrix) const
Compute full Jacobian matrix.
Definition discrete_to_cartesian.hpp:151
typename SplineEvaluator::bsplines_type1 BSplineR
Indicate the bspline type of the first logical dimension.
Definition discrete_to_cartesian.hpp:39
KOKKOS_FUNCTION double jacobian(ddc::Coordinate< curvilinear_tag_r, curvilinear_tag_theta > const &coord) const
Compute the Jacobian, the determinant of the Jacobian matrix of the mapping.
Definition discrete_to_cartesian.hpp:261
KOKKOS_FUNCTION double jacobian_12(ddc::Coordinate< curvilinear_tag_r, curvilinear_tag_theta > const &coord) const
Compute the (1,2) coefficient of the Jacobian matrix.
Definition discrete_to_cartesian.hpp:203
KOKKOS_FUNCTION double jacobian_22(ddc::Coordinate< curvilinear_tag_r, curvilinear_tag_theta > const &coord) const
Compute the (2,2) coefficient of the Jacobian matrix.
Definition discrete_to_cartesian.hpp:247
KOKKOS_INLINE_FUNCTION const ddc::Coordinate< X, Y > control_point(ddc::DiscreteElement< BSplineR, BSplineTheta > const &el) const
Get a control point of the mapping on B-splines.
Definition discrete_to_cartesian.hpp:336
KOKKOS_FUNCTION double jacobian_21(ddc::Coordinate< curvilinear_tag_r, curvilinear_tag_theta > const &coord) const
Compute the (2,1) coefficient of the Jacobian matrix.
Definition discrete_to_cartesian.hpp:225
ddc::Coordinate< R, Theta > CoordArg
The type of the argument of the function described by this mapping.
Definition discrete_to_cartesian.hpp:55
KOKKOS_INLINE_FUNCTION IdxRangeRTheta idx_range_singular_point() const
Get the index range describing the points which should be used to evaluate functions at the central p...
Definition discrete_to_cartesian.hpp:303
typename SplineEvaluator::bsplines_type2 BSplineTheta
Indicate the bspline type of the second logical dimension.
Definition discrete_to_cartesian.hpp:43
Define non periodic real R dimension.
Definition geometry.hpp:31
Define periodic real Theta dimension.
Definition geometry.hpp:42
Define non periodic real X dimension.
Definition geometry.hpp:278
Define non periodic real Y dimension.
Definition geometry.hpp:289