Gyselalib++
jacobian.hpp
1 // SPDX-License-Identifier: MIT
2 #pragma once
3 #include <array>
4 #include <cassert>
5 
6 #include <sll/view.hpp>
7 
14 template <class PositionCoordinate>
15 class Jacobian
16 {
17 public:
26  virtual KOKKOS_FUNCTION double jacobian(PositionCoordinate const& coord) const = 0;
27 
47  virtual KOKKOS_FUNCTION void jacobian_matrix(
48  PositionCoordinate const& coord,
49  Matrix_2x2& matrix) const = 0;
50 
62  virtual KOKKOS_FUNCTION double jacobian_11(PositionCoordinate const& coord) const = 0;
63 
75  virtual KOKKOS_FUNCTION double jacobian_12(PositionCoordinate const& coord) const = 0;
76 
88  virtual KOKKOS_FUNCTION double jacobian_21(PositionCoordinate const& coord) const = 0;
89 
101  virtual KOKKOS_FUNCTION double jacobian_22(PositionCoordinate const& coord) const = 0;
102 
122  virtual KOKKOS_FUNCTION void inv_jacobian_matrix(
123  PositionCoordinate const& coord,
124  Matrix_2x2& matrix) const = 0;
125 
136  virtual KOKKOS_FUNCTION double inv_jacobian_11(PositionCoordinate const& coord) const = 0;
137 
148  virtual KOKKOS_FUNCTION double inv_jacobian_12(PositionCoordinate const& coord) const = 0;
149 
160  virtual KOKKOS_FUNCTION double inv_jacobian_21(PositionCoordinate const& coord) const = 0;
161 
172  virtual KOKKOS_FUNCTION double inv_jacobian_22(PositionCoordinate const& coord) const = 0;
173 };
174 
182 template <class PositionCoordinate>
183 class NonAnalyticalJacobian : public Jacobian<PositionCoordinate>
184 {
185 public:
194  KOKKOS_FUNCTION double jacobian(PositionCoordinate const& coord) const final
195  {
196  const double j_rr = this->jacobian_11(coord);
197  const double j_rp = this->jacobian_12(coord);
198  const double j_pr = this->jacobian_21(coord);
199  const double j_pp = this->jacobian_22(coord);
200  return j_rr * j_pp - j_rp * j_pr;
201  }
202 
222  KOKKOS_FUNCTION void inv_jacobian_matrix(PositionCoordinate const& coord, Matrix_2x2& matrix)
223  const final
224  {
225  double jacob = jacobian(coord);
226  assert(fabs(jacob) > 1e-15);
227  matrix[0][0] = this->jacobian_22(coord) / jacob;
228  matrix[0][1] = -this->jacobian_12(coord) / jacob;
229  matrix[1][0] = -this->jacobian_21(coord) / jacob;
230  matrix[1][1] = this->jacobian_11(coord) / jacob;
231  }
232 
243  KOKKOS_FUNCTION double inv_jacobian_11(PositionCoordinate const& coord) const final
244  {
245  double jacob = jacobian(coord);
246  assert(fabs(jacob) > 1e-15);
247  return this->jacobian_22(coord) / jacob;
248  }
249 
260  KOKKOS_FUNCTION double inv_jacobian_12(PositionCoordinate const& coord) const final
261  {
262  double jacob = jacobian(coord);
263  assert(fabs(jacob) > 1e-15);
264  return -this->jacobian_12(coord) / jacob;
265  }
266 
277  KOKKOS_FUNCTION double inv_jacobian_21(PositionCoordinate const& coord) const final
278  {
279  double jacob = jacobian(coord);
280  assert(fabs(jacob) > 1e-15);
281  return -this->jacobian_21(coord) / jacob;
282  }
283 
294  KOKKOS_FUNCTION double inv_jacobian_22(PositionCoordinate const& coord) const final
295  {
296  double jacob = jacobian(coord);
297  assert(fabs(jacob) > 1e-15);
298  return this->jacobian_11(coord) / jacob;
299  }
300 };
An operator to calculate the Jacobian matrix and its inverse.
Definition: jacobian.hpp:16
virtual KOKKOS_FUNCTION void inv_jacobian_matrix(PositionCoordinate const &coord, Matrix_2x2 &matrix) const =0
Compute full inverse Jacobian matrix.
virtual KOKKOS_FUNCTION double inv_jacobian_22(PositionCoordinate const &coord) const =0
Compute the (2,2) coefficient of the inverse Jacobian matrix.
virtual KOKKOS_FUNCTION void jacobian_matrix(PositionCoordinate const &coord, Matrix_2x2 &matrix) const =0
Compute full Jacobian matrix.
virtual KOKKOS_FUNCTION double jacobian(PositionCoordinate const &coord) const =0
Compute the Jacobian, the determinant of the Jacobian matrix of the mapping.
virtual KOKKOS_FUNCTION double inv_jacobian_11(PositionCoordinate const &coord) const =0
Compute the (1,1) coefficient of the inverse Jacobian matrix.
virtual KOKKOS_FUNCTION double jacobian_21(PositionCoordinate const &coord) const =0
Compute the (2,1) coefficient of the Jacobian matrix.
virtual KOKKOS_FUNCTION double inv_jacobian_12(PositionCoordinate const &coord) const =0
Compute the (1,2) coefficient of the inverse Jacobian matrix.
virtual KOKKOS_FUNCTION double inv_jacobian_21(PositionCoordinate const &coord) const =0
Compute the (2,1) coefficient of the inverse Jacobian matrix.
virtual KOKKOS_FUNCTION double jacobian_22(PositionCoordinate const &coord) const =0
Compute the (2,2) coefficient of the Jacobian matrix.
virtual KOKKOS_FUNCTION double jacobian_12(PositionCoordinate const &coord) const =0
Compute the (1,2) coefficient of the Jacobian matrix.
virtual KOKKOS_FUNCTION double jacobian_11(PositionCoordinate const &coord) const =0
Compute the (1,1) coefficient of the Jacobian matrix.
A specialisation of Jacobian to handle non-analytical terms.
Definition: jacobian.hpp:184
KOKKOS_FUNCTION double inv_jacobian_12(PositionCoordinate const &coord) const final
Compute the (1,2) coefficient of the inverse Jacobian matrix.
Definition: jacobian.hpp:260
KOKKOS_FUNCTION double inv_jacobian_22(PositionCoordinate const &coord) const final
Compute the (2,2) coefficient of the inverse Jacobian matrix.
Definition: jacobian.hpp:294
KOKKOS_FUNCTION double inv_jacobian_21(PositionCoordinate const &coord) const final
Compute the (2,1) coefficient of the inverse Jacobian matrix.
Definition: jacobian.hpp:277
KOKKOS_FUNCTION double jacobian(PositionCoordinate const &coord) const final
Compute the Jacobian, the determinant of the Jacobian matrix of the mapping.
Definition: jacobian.hpp:194
KOKKOS_FUNCTION double inv_jacobian_11(PositionCoordinate const &coord) const final
Compute the (1,1) coefficient of the inverse Jacobian matrix.
Definition: jacobian.hpp:243
KOKKOS_FUNCTION void inv_jacobian_matrix(PositionCoordinate const &coord, Matrix_2x2 &matrix) const final
Compute full inverse Jacobian matrix.
Definition: jacobian.hpp:222