Gyselalib++
 
Loading...
Searching...
No Matches
inv_jacobian_o_point.hpp
1// SPDX-License-Identifier: MIT
2#pragma once
3
4#include <sll/view.hpp>
5
6#include "cartesian_to_circular.hpp"
7#include "circular_to_cartesian.hpp"
8#include "czarny_to_cartesian.hpp"
9#include "discrete_to_cartesian.hpp"
10#include "mapping_tools.hpp"
11
26template <class Mapping, class CoordRTheta>
28
29// Pre-declaration of CombinedMapping.
30template <class Mapping1, class Mapping2>
31class CombinedMapping;
32
40template <class X, class Y, class R, class Theta, class Xpc, class Ypc>
44 CartesianToCircular<Xpc, Ypc, R, Theta>>,
45 ddc::Coordinate<R, Theta>>
46{
48 using CoordRTheta = ddc::Coordinate<R, Theta>;
49
50private:
54
55private:
56 Mapping m_mapping;
57
58public:
63 KOKKOS_FUNCTION explicit InvJacobianOPoint(Mapping const& mapping) : m_mapping(mapping) {}
64
79 KOKKOS_INLINE_FUNCTION Matrix_2x2 operator()() const
80 {
81 Matrix_2x2 J;
82 J[0][0] = 1.;
83 J[0][1] = 0.;
84 J[1][0] = 0.;
85 J[1][1] = 1.;
86 return J;
87 }
88};
89
96template <class X, class Y, class R, class Theta, class Xpc, class Ypc>
99 ddc::Coordinate<R, Theta>>
100{
102 using CoordRTheta = ddc::Coordinate<R, Theta>;
103
104private:
105 using Mapping = CombinedMapping<
108
109private:
110 Mapping m_mapping;
111
112public:
117 KOKKOS_FUNCTION explicit InvJacobianOPoint(Mapping const& mapping) : m_mapping(mapping) {}
118
131 KOKKOS_INLINE_FUNCTION Matrix_2x2 operator()() const
132 {
133 Matrix_2x2 J;
134 const double epsilon
135 = m_mapping.template get<CzarnyToCartesian<R, Theta, X, Y>>().epsilon();
136 const double e = m_mapping.template get<CzarnyToCartesian<R, Theta, X, Y>>().e();
137 const double xi = Kokkos::sqrt(1. / (1. - epsilon * epsilon * 0.25));
138 const double sqrt_eps_2 = Kokkos::sqrt(1. + epsilon * epsilon);
139 J[0][0] = -sqrt_eps_2;
140 J[0][1] = 0.;
141 J[1][0] = 0.;
142 J[1][1] = (2 - sqrt_eps_2) / e / xi;
143 return J;
144 }
145};
146
153template <
154 class X,
155 class Y,
156 class SplineEvaluator,
157 class R,
158 class Theta,
159 class MemorySpace,
160 class Xpc,
161 class Ypc>
164 DiscreteToCartesian<X, Y, SplineEvaluator, R, Theta, MemorySpace>,
165 CartesianToCircular<Xpc, Ypc, R, Theta>>,
166 ddc::Coordinate<R, Theta>>
167{
169 using CoordRTheta = ddc::Coordinate<R, Theta>;
170
171private:
172 using Mapping = CombinedMapping<
175
176 using IdxRangeR = typename SplineEvaluator::evaluation_domain_type1;
177 using IdxRangeTheta = typename SplineEvaluator::evaluation_domain_type2;
178 using IdxR = typename IdxRangeR::discrete_element_type;
179 using IdxTheta = typename IdxRangeTheta::discrete_element_type;
180
181private:
182 Mapping m_mapping;
183
184public:
189 KOKKOS_FUNCTION explicit InvJacobianOPoint(Mapping const& mapping) : m_mapping(mapping) {}
190
229 KOKKOS_FUNCTION Matrix_2x2 operator()() const
230 {
232 = m_mapping.template get<
234 Matrix_2x2 J;
235 J[0][0] = 0;
236 J[0][1] = 0;
237 J[1][0] = 0;
238 J[1][1] = 0;
239 ddc::DiscreteDomain idx_range_singular_point = discrete_mapping.idx_range_singular_point();
240 // Average the values at (r = 0, theta):
241 IdxR ir(idx_range_singular_point.front());
242 for (IdxTheta ip : IdxRangeTheta(idx_range_singular_point)) {
243 ddc::Coordinate<R, Theta> coord(ddc::coordinate(ir), ddc::coordinate(ip));
244 Matrix_2x2 J_first_order = discrete_mapping.first_order_jacobian_matrix_r_rtheta(coord);
245
246 double th = ddc::get<Theta>(coord);
247 Matrix_2x2 J_circ_r_rtheta;
248 J_circ_r_rtheta[0][0] = Kokkos::cos(th);
249 J_circ_r_rtheta[0][1] = Kokkos::sin(th);
250 J_circ_r_rtheta[1][0] = -Kokkos::sin(th);
251 J_circ_r_rtheta[1][1] = Kokkos::cos(th);
252
253 Matrix_2x2 J_theta;
254 J_theta = inverse(mat_mul(J_first_order, J_circ_r_rtheta));
255
256 J[0][0] += J_theta[0][0];
257 J[0][1] += J_theta[0][1];
258 J[1][0] += J_theta[1][0];
259 J[1][1] += J_theta[1][1];
260 }
261
262 int const theta_size = idx_range_singular_point.size();
263 J[0][0] /= theta_size;
264 J[0][1] /= theta_size;
265 J[1][0] /= theta_size;
266 J[1][1] /= theta_size;
267 return J;
268 }
269};
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
A class which describes a mapping which is constructed by combining two mappings.
Definition combined_mapping.hpp:26
A class for describing the Czarny 2D mapping.
Definition czarny_to_cartesian.hpp:50
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_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
KOKKOS_INLINE_FUNCTION Matrix_2x2 operator()() const
Compute the full inverse Jacobian matrix from a coordinate system (x_pc, y_pc) to a coordinate system...
Definition inv_jacobian_o_point.hpp:79
KOKKOS_FUNCTION InvJacobianOPoint(Mapping const &mapping)
The constructor of InvJacobianOPoint.
Definition inv_jacobian_o_point.hpp:63
KOKKOS_INLINE_FUNCTION Matrix_2x2 operator()() const
Compute the full inverse Jacobian matrix from a coordinate system (x_pc, y_pc) to a coordinate system...
Definition inv_jacobian_o_point.hpp:131
KOKKOS_FUNCTION InvJacobianOPoint(Mapping const &mapping)
The constructor of InvJacobianOPoint.
Definition inv_jacobian_o_point.hpp:117
KOKKOS_FUNCTION InvJacobianOPoint(Mapping const &mapping)
The constructor of InvJacobianOPoint.
Definition inv_jacobian_o_point.hpp:189
KOKKOS_FUNCTION Matrix_2x2 operator()() const
Compute the full inverse Jacobian matrix from a coordinate system (x_pc, y_pc) to a coordinate system...
Definition inv_jacobian_o_point.hpp:229
An operator for calculating the inverse of the Jacobian at an O-point.
Definition inv_jacobian_o_point.hpp:27
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