Gyselalib++
 
Loading...
Searching...
No Matches
cartesian_to_circular.hpp
1// SPDX-License-Identifier: MIT
2#pragma once
3
4#include <ddc/ddc.hpp>
5
6#include <sll/view.hpp>
7
8#include "mapping_tools.hpp"
9
10// Pre-declaration of analytical inverse
11template <class R, class Theta, class X, class Y>
13
38template <class X, class Y, class R, class Theta>
40{
41public:
50
52 using CoordArg = ddc::Coordinate<X, Y>;
54 using CoordResult = ddc::Coordinate<R, Theta>;
55
56public:
57 CartesianToCircular() = default;
58
65 KOKKOS_FUNCTION CartesianToCircular(CartesianToCircular const& other) {}
66
74
75 ~CartesianToCircular() = default;
76
86
96
104 KOKKOS_FUNCTION ddc::Coordinate<R, Theta> operator()(ddc::Coordinate<X, Y> const& coord) const
105 {
106 const double x = ddc::get<X>(coord);
107 const double y = ddc::get<Y>(coord);
108 const double r = Kokkos::sqrt(x * x + y * y);
109 const double theta = Kokkos::atan2(y, x);
110 return ddc::Coordinate<R, Theta>(r, theta);
111 }
112
121 KOKKOS_FUNCTION double jacobian(ddc::Coordinate<X, Y> const& coord)
122 {
123 const double x = ddc::get<X>(coord);
124 const double y = ddc::get<Y>(coord);
125 return 2. * (x * x - y * y) / Kokkos::pow(x * x + y * y, 1.5);
126 }
127
147 KOKKOS_FUNCTION void jacobian_matrix(ddc::Coordinate<X, Y> const& coord, Matrix_2x2& matrix)
148
149 {
150 const double x = ddc::get<X>(coord);
151 const double y = ddc::get<Y>(coord);
152 matrix[0][0] = 2 * x / Kokkos::pow(x * x + y * y, 0.5);
153 matrix[0][1] = 2 * y / Kokkos::pow(x * x + y * y, 0.5);
154 matrix[1][0] = -y / Kokkos::pow(x * x + y * y, 2.);
155 matrix[1][1] = x / Kokkos::pow(x * x + y * y, 2.);
156 }
157
169 KOKKOS_FUNCTION double jacobian_11(ddc::Coordinate<X, Y> const& coord)
170 {
171 const double x = ddc::get<X>(coord);
172 const double y = ddc::get<Y>(coord);
173 return 2 * x / Kokkos::pow(x * x + y * y, 0.5);
174 ;
175 }
176
188 KOKKOS_FUNCTION double jacobian_12(ddc::Coordinate<X, Y> const& coord)
189 {
190 const double x = ddc::get<X>(coord);
191 const double y = ddc::get<Y>(coord);
192 return 2 * y / Kokkos::pow(x * x + y * y, 0.5);
193 }
194
206 KOKKOS_FUNCTION double jacobian_21(ddc::Coordinate<X, Y> const& coord)
207 {
208 const double x = ddc::get<X>(coord);
209 const double y = ddc::get<Y>(coord);
210 return -y / Kokkos::pow(x * x + y * y, 2.);
211 }
212
224 KOKKOS_FUNCTION double jacobian_22(ddc::Coordinate<X, Y> const& coord)
225 {
226 const double x = ddc::get<X>(coord);
227 const double y = ddc::get<Y>(coord);
228 return x / Kokkos::pow(x * x + y * y, 2.);
229 }
230
240};
241
242namespace mapping_detail {
243template <class X, class Y, class R, class Theta, class ExecSpace>
244struct MappingAccessibility<ExecSpace, CartesianToCircular<X, Y, R, Theta>> : std::true_type
245{
246};
247} // namespace mapping_detail
A class for describing the circular 2D mapping.
Definition cartesian_to_circular.hpp:40
KOKKOS_FUNCTION double jacobian_22(ddc::Coordinate< X, Y > const &coord)
Compute the (2,2) coefficient of the Jacobian matrix.
Definition cartesian_to_circular.hpp:224
KOKKOS_FUNCTION double jacobian(ddc::Coordinate< X, Y > const &coord)
Compute the Jacobian, the determinant of the Jacobian matrix of the mapping.
Definition cartesian_to_circular.hpp:121
CircularToCartesian< R, Theta, X, Y > get_inverse_mapping() const
Get the inverse mapping.
Definition cartesian_to_circular.hpp:236
KOKKOS_FUNCTION CartesianToCircular(CartesianToCircular const &other)
Instantiate a CartesianToCircular from another CartesianToCircular (lvalue).
Definition cartesian_to_circular.hpp:65
CartesianToCircular & operator=(CartesianToCircular &&x)=default
Assign a CartesianToCircular from another temporary CartesianToCircular (rvalue).
ddc::Coordinate< R, Theta > CoordResult
The type of the result of the function described by this mapping.
Definition cartesian_to_circular.hpp:54
KOKKOS_FUNCTION void jacobian_matrix(ddc::Coordinate< X, Y > const &coord, Matrix_2x2 &matrix)
Compute full Jacobian matrix.
Definition cartesian_to_circular.hpp:147
KOKKOS_FUNCTION ddc::Coordinate< R, Theta > operator()(ddc::Coordinate< X, Y > const &coord) const
Convert the coordinate (x,y) to the equivalent coordinate.
Definition cartesian_to_circular.hpp:104
KOKKOS_FUNCTION double jacobian_11(ddc::Coordinate< X, Y > const &coord)
Compute the (1,1) coefficient of the Jacobian matrix.
Definition cartesian_to_circular.hpp:169
KOKKOS_FUNCTION double jacobian_21(ddc::Coordinate< X, Y > const &coord)
Compute the (2,1) coefficient of the Jacobian matrix.
Definition cartesian_to_circular.hpp:206
KOKKOS_FUNCTION double jacobian_12(ddc::Coordinate< X, Y > const &coord)
Compute the (1,2) coefficient of the Jacobian matrix.
Definition cartesian_to_circular.hpp:188
ddc::Coordinate< X, Y > CoordArg
The type of the argument of the function described by this mapping.
Definition cartesian_to_circular.hpp:52
CartesianToCircular(CartesianToCircular &&x)=default
Instantiate a Curvilinear2DToCartesian from another temporary CartesianToCircular (rvalue).
CartesianToCircular & operator=(CartesianToCircular const &x)=default
Assign a CartesianToCircular from another CartesianToCircular (lvalue).
A class for describing the circular 2D mapping.
Definition circular_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