Gyselalib++
 
Loading...
Searching...
No Matches
circular_to_cartesian.hpp
1// SPDX-License-Identifier: MIT
2#pragma once
3
4#include <cassert>
5#include <cmath>
6
7#include <ddc/ddc.hpp>
8
9#include <sll/view.hpp>
10
11#include "mapping_tools.hpp"
12
13// Pre-declaration of analytical inverse
14template <class X, class Y, class R, class Theta>
16
41template <class R, class Theta, class X, class Y>
43{
44public:
53
55 using CoordArg = ddc::Coordinate<R, Theta>;
57 using CoordResult = ddc::Coordinate<X, Y>;
58
59public:
60 CircularToCartesian() = default;
61
68 KOKKOS_FUNCTION CircularToCartesian(CircularToCartesian const& other) {}
69
77
78 ~CircularToCartesian() = default;
79
89
99
107 KOKKOS_FUNCTION ddc::Coordinate<X, Y> operator()(ddc::Coordinate<R, Theta> const& coord) const
108 {
109 const double r = ddc::get<R>(coord);
110 const double theta = ddc::get<Theta>(coord);
111 const double x = r * Kokkos::cos(theta);
112 const double y = r * Kokkos::sin(theta);
113 return ddc::Coordinate<X, Y>(x, y);
114 }
115
124 KOKKOS_FUNCTION double jacobian(ddc::Coordinate<R, Theta> const& coord) const
125 {
126 double r = ddc::get<R>(coord);
127 return r;
128 }
129
143 KOKKOS_FUNCTION void jacobian_matrix(ddc::Coordinate<R, Theta> const& coord, Matrix_2x2& matrix)
144 const
145 {
146 const double r = ddc::get<R>(coord);
147 const double theta = ddc::get<Theta>(coord);
148 matrix[0][0] = Kokkos::cos(theta);
149 matrix[0][1] = -r * Kokkos::sin(theta);
150 matrix[1][0] = Kokkos::sin(theta);
151 matrix[1][1] = r * Kokkos::cos(theta);
152 }
153
165 KOKKOS_FUNCTION double jacobian_11(ddc::Coordinate<R, Theta> const& coord) const
166 {
167 const double theta = ddc::get<Theta>(coord);
168 return Kokkos::cos(theta);
169 }
170
182 KOKKOS_FUNCTION double jacobian_12(ddc::Coordinate<R, Theta> const& coord) const
183 {
184 const double r = ddc::get<R>(coord);
185 const double theta = ddc::get<Theta>(coord);
186 return -r * Kokkos::sin(theta);
187 }
188
200 KOKKOS_FUNCTION double jacobian_21(ddc::Coordinate<R, Theta> const& coord) const
201 {
202 const double theta = ddc::get<Theta>(coord);
203 return Kokkos::sin(theta);
204 }
205
217 KOKKOS_FUNCTION double jacobian_22(ddc::Coordinate<R, Theta> const& coord) const
218 {
219 const double r = ddc::get<R>(coord);
220 const double theta = ddc::get<Theta>(coord);
221 return r * Kokkos::cos(theta);
222 }
223
224
244 KOKKOS_FUNCTION void inv_jacobian_matrix(
245 ddc::Coordinate<R, Theta> const& coord,
246 Matrix_2x2& matrix) const
247 {
248 const double r = ddc::get<R>(coord);
249 const double theta = ddc::get<Theta>(coord);
250 assert(fabs(r) >= 1e-15);
251 matrix[0][0] = Kokkos::cos(theta);
252 matrix[0][1] = Kokkos::sin(theta);
253 matrix[1][0] = -1 / r * Kokkos::sin(theta);
254 matrix[1][1] = 1 / r * Kokkos::cos(theta);
255 }
256
267 KOKKOS_FUNCTION double inv_jacobian_11(ddc::Coordinate<R, Theta> const& coord) const
268 {
269 const double theta = ddc::get<Theta>(coord);
270 return Kokkos::cos(theta);
271 }
272
283 KOKKOS_FUNCTION double inv_jacobian_12(ddc::Coordinate<R, Theta> const& coord) const
284 {
285 const double theta = ddc::get<Theta>(coord);
286 return Kokkos::sin(theta);
287 }
288
299 KOKKOS_FUNCTION double inv_jacobian_21(ddc::Coordinate<R, Theta> const& coord) const
300 {
301 const double r = ddc::get<R>(coord);
302 const double theta = ddc::get<Theta>(coord);
303 assert(fabs(r) >= 1e-15);
304 return -1 / r * Kokkos::sin(theta);
305 }
306
317 KOKKOS_FUNCTION double inv_jacobian_22(ddc::Coordinate<R, Theta> const& coord) const
318 {
319 const double r = ddc::get<R>(coord);
320 const double theta = ddc::get<Theta>(coord);
321 assert(fabs(r) >= 1e-15);
322 return 1 / r * Kokkos::cos(theta);
323 }
324
334};
335
336namespace mapping_detail {
337template <class X, class Y, class R, class Theta, class ExecSpace>
338struct MappingAccessibility<ExecSpace, CircularToCartesian<R, Theta, X, Y>> : std::true_type
339{
340};
341
342template <class X, class Y, class R, class Theta>
343struct IsCurvilinear2DMapping<CircularToCartesian<R, Theta, X, Y>> : std::true_type
344{
345};
346
347template <class X, class Y, class R, class Theta>
348struct SingularOPointInvJacobian<CircularToCartesian<R, Theta, X, Y>> : std::true_type
349{
350};
351
352} // namespace mapping_detail
A class for describing the circular 2D mapping.
Definition cartesian_to_circular.hpp:40
A class for describing the circular 2D mapping.
Definition circular_to_cartesian.hpp:43
ddc::Coordinate< R, Theta > CoordArg
The type of the argument of the function described by this mapping.
Definition circular_to_cartesian.hpp:55
CircularToCartesian & operator=(CircularToCartesian &&x)=default
Assign a CircularToCartesian from another temporary CircularToCartesian (rvalue).
KOKKOS_FUNCTION double jacobian_12(ddc::Coordinate< R, Theta > const &coord) const
Compute the (1,2) coefficient of the Jacobian matrix.
Definition circular_to_cartesian.hpp:182
KOKKOS_FUNCTION double jacobian_22(ddc::Coordinate< R, Theta > const &coord) const
Compute the (2,2) coefficient of the Jacobian matrix.
Definition circular_to_cartesian.hpp:217
KOKKOS_FUNCTION double inv_jacobian_22(ddc::Coordinate< R, Theta > const &coord) const
Compute the (2,2) coefficient of the inverse Jacobian matrix.
Definition circular_to_cartesian.hpp:317
ddc::Coordinate< X, Y > CoordResult
The type of the result of the function described by this mapping.
Definition circular_to_cartesian.hpp:57
KOKKOS_FUNCTION double jacobian(ddc::Coordinate< R, Theta > const &coord) const
Compute the Jacobian, the determinant of the Jacobian matrix of the mapping.
Definition circular_to_cartesian.hpp:124
CircularToCartesian & operator=(CircularToCartesian const &x)=default
Assign a CircularToCartesian from another CircularToCartesian (lvalue).
KOKKOS_FUNCTION double inv_jacobian_12(ddc::Coordinate< R, Theta > const &coord) const
Compute the (1,2) coefficient of the inverse Jacobian matrix.
Definition circular_to_cartesian.hpp:283
KOKKOS_FUNCTION ddc::Coordinate< X, Y > operator()(ddc::Coordinate< R, Theta > const &coord) const
Convert the coordinate to the equivalent (x,y) coordinate.
Definition circular_to_cartesian.hpp:107
KOKKOS_FUNCTION double jacobian_11(ddc::Coordinate< R, Theta > const &coord) const
Compute the (1,1) coefficient of the Jacobian matrix.
Definition circular_to_cartesian.hpp:165
KOKKOS_FUNCTION double jacobian_21(ddc::Coordinate< R, Theta > const &coord) const
Compute the (2,1) coefficient of the Jacobian matrix.
Definition circular_to_cartesian.hpp:200
CartesianToCircular< X, Y, R, Theta > get_inverse_mapping() const
Get the inverse mapping.
Definition circular_to_cartesian.hpp:330
CircularToCartesian(CircularToCartesian &&x)=default
Instantiate a CircularToCartesian from another temporary CircularToCartesian (rvalue).
KOKKOS_FUNCTION void jacobian_matrix(ddc::Coordinate< R, Theta > const &coord, Matrix_2x2 &matrix) const
Compute full Jacobian matrix.
Definition circular_to_cartesian.hpp:143
KOKKOS_FUNCTION void inv_jacobian_matrix(ddc::Coordinate< R, Theta > const &coord, Matrix_2x2 &matrix) const
Compute full inverse Jacobian matrix.
Definition circular_to_cartesian.hpp:244
KOKKOS_FUNCTION double inv_jacobian_11(ddc::Coordinate< R, Theta > const &coord) const
Compute the (1,1) coefficient of the inverse Jacobian matrix.
Definition circular_to_cartesian.hpp:267
KOKKOS_FUNCTION double inv_jacobian_21(ddc::Coordinate< R, Theta > const &coord) const
Compute the (2,1) coefficient of the inverse Jacobian matrix.
Definition circular_to_cartesian.hpp:299
KOKKOS_FUNCTION CircularToCartesian(CircularToCartesian const &other)
Instantiate a CircularToCartesian from another CircularToCartesian (lvalue).
Definition circular_to_cartesian.hpp:68
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