Gyselalib++
inverse_jacobian_matrix.hpp
1 // SPDX-License-Identifier: MIT
2 #pragma once
3 
4 #include <sll/view.hpp>
5 
6 #include "mapping_tools.hpp"
7 
16 template <class Mapping, class PositionCoordinate = typename Mapping::CoordArg>
18 {
19 private:
20  Mapping m_mapping;
21 
22 public:
27  KOKKOS_FUNCTION explicit InverseJacobianMatrix(Mapping const& mapping) : m_mapping(mapping) {}
28 
45  KOKKOS_INLINE_FUNCTION Matrix_2x2 operator()(PositionCoordinate const& coord) const
46  {
47  Matrix_2x2 matrix;
48  if constexpr (has_2d_inv_jacobian_v<Mapping, PositionCoordinate>) {
49  m_mapping.inv_jacobian_matrix(coord, matrix);
50  } else {
51  static_assert(has_2d_jacobian_v<Mapping, PositionCoordinate>);
52  double jacob = m_mapping.jacobian(coord);
53  assert(fabs(jacob) > 1e-15);
54  matrix[0][0] = m_mapping.jacobian_22(coord) / jacob;
55  matrix[0][1] = -m_mapping.jacobian_12(coord) / jacob;
56  matrix[1][0] = -m_mapping.jacobian_21(coord) / jacob;
57  matrix[1][1] = m_mapping.jacobian_11(coord) / jacob;
58  }
59  return matrix;
60  }
61 
72  KOKKOS_INLINE_FUNCTION double inv_jacobian_11(PositionCoordinate const& coord) const
73  {
74  if constexpr (has_2d_inv_jacobian_v<Mapping, PositionCoordinate>) {
75  return m_mapping.inv_jacobian_11(coord);
76  } else {
77  static_assert(has_2d_jacobian_v<Mapping, PositionCoordinate>);
78  double jacob = m_mapping.jacobian(coord);
79  assert(fabs(jacob) > 1e-15);
80  return m_mapping.jacobian_22(coord) / jacob;
81  }
82  }
83 
94  KOKKOS_INLINE_FUNCTION double inv_jacobian_12(PositionCoordinate const& coord) const
95  {
96  if constexpr (has_2d_inv_jacobian_v<Mapping, PositionCoordinate>) {
97  return m_mapping.inv_jacobian_12(coord);
98  } else {
99  static_assert(has_2d_jacobian_v<Mapping, PositionCoordinate>);
100  double jacob = m_mapping.jacobian(coord);
101  assert(fabs(jacob) > 1e-15);
102  return -m_mapping.jacobian_12(coord) / jacob;
103  }
104  }
115  KOKKOS_INLINE_FUNCTION double inv_jacobian_21(PositionCoordinate const& coord) const
116  {
117  if constexpr (has_2d_inv_jacobian_v<Mapping, PositionCoordinate>) {
118  return m_mapping.inv_jacobian_21(coord);
119  } else {
120  static_assert(has_2d_jacobian_v<Mapping, PositionCoordinate>);
121  double jacob = m_mapping.jacobian(coord);
122  assert(fabs(jacob) > 1e-15);
123  return -m_mapping.jacobian_21(coord) / jacob;
124  }
125  }
126 
137  KOKKOS_INLINE_FUNCTION double inv_jacobian_22(PositionCoordinate const& coord) const
138  {
139  if constexpr (has_2d_inv_jacobian_v<Mapping, PositionCoordinate>) {
140  return m_mapping.inv_jacobian_22(coord);
141  } else {
142  static_assert(has_2d_jacobian_v<Mapping, PositionCoordinate>);
143  double jacob = m_mapping.jacobian(coord);
144  assert(fabs(jacob) > 1e-15);
145  return m_mapping.jacobian_11(coord) / jacob;
146  }
147  }
148 };
A class for describing the circular 2D mapping.
Definition: circular_to_cartesian.hpp:45
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:221
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:238
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:288
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:304
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:186
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:203
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:338
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:265
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:320
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:144
A class to calculate the inverse of the Jacobian matrix.
Definition: inverse_jacobian_matrix.hpp:18
KOKKOS_INLINE_FUNCTION double inv_jacobian_11(PositionCoordinate const &coord) const
Compute the (1,1) coefficient of the inverse Jacobian matrix.
Definition: inverse_jacobian_matrix.hpp:72
KOKKOS_FUNCTION InverseJacobianMatrix(Mapping const &mapping)
A constructor for the InverseJacobianMatrix.
Definition: inverse_jacobian_matrix.hpp:27
KOKKOS_INLINE_FUNCTION double inv_jacobian_21(PositionCoordinate const &coord) const
Compute the (2,1) coefficient of the inverse Jacobian matrix.
Definition: inverse_jacobian_matrix.hpp:115
KOKKOS_INLINE_FUNCTION Matrix_2x2 operator()(PositionCoordinate const &coord) const
Compute full inverse Jacobian matrix.
Definition: inverse_jacobian_matrix.hpp:45
KOKKOS_INLINE_FUNCTION double inv_jacobian_12(PositionCoordinate const &coord) const
Compute the (1,2) coefficient of the inverse Jacobian matrix.
Definition: inverse_jacobian_matrix.hpp:94
KOKKOS_INLINE_FUNCTION double inv_jacobian_22(PositionCoordinate const &coord) const
Compute the (2,2) coefficient of the inverse Jacobian matrix.
Definition: inverse_jacobian_matrix.hpp:137