Gyselalib++
 
Loading...
Searching...
No Matches
metric_tensor.hpp
1#pragma once
2#include <type_traits>
3
4#include <sll/view.hpp>
5
6#include "mapping_tools.hpp"
7
13template <class Mapping, class PositionCoordinate>
15{
16 static_assert(is_mapping_v<Mapping>);
17 static_assert(has_2d_jacobian_v<Mapping, PositionCoordinate>);
18
19public:
21 using Matrix_2x2 = std::array<std::array<double, 2>, 2>;
22
23private:
24 Mapping m_mapping;
25
26public:
32 KOKKOS_FUNCTION MetricTensor(Mapping mapping) : m_mapping(mapping) {}
33
46 KOKKOS_FUNCTION void operator()(Matrix_2x2& matrix, PositionCoordinate const& coord) const
47 {
48 const double J_11 = m_mapping.jacobian_11(coord);
49 const double J_12 = m_mapping.jacobian_12(coord);
50 const double J_21 = m_mapping.jacobian_21(coord);
51 const double J_22 = m_mapping.jacobian_22(coord);
52 matrix[0][0] = (J_11 * J_11 + J_21 * J_21);
53 matrix[0][1] = (J_11 * J_12 + J_21 * J_22);
54 matrix[1][0] = (J_11 * J_12 + J_21 * J_22);
55 matrix[1][1] = (J_12 * J_12 + J_22 * J_22);
56 }
57
66 KOKKOS_FUNCTION void inverse(Matrix_2x2& matrix, PositionCoordinate const& coord) const
67 {
68 const double J_11 = m_mapping.jacobian_11(coord);
69 const double J_12 = m_mapping.jacobian_12(coord);
70 const double J_21 = m_mapping.jacobian_21(coord);
71 const double J_22 = m_mapping.jacobian_22(coord);
72 const double jacob_2 = m_mapping.jacobian(coord) * m_mapping.jacobian(coord);
73 matrix[0][0] = (J_12 * J_12 + J_22 * J_22) / jacob_2;
74 matrix[0][1] = (-J_11 * J_12 - J_21 * J_22) / jacob_2;
75 matrix[1][0] = (-J_11 * J_12 - J_21 * J_22) / jacob_2;
76 matrix[1][1] = (J_11 * J_11 + J_21 * J_21) / jacob_2;
77 }
78
89 KOKKOS_FUNCTION std::array<double, 2> to_covariant(
90 std::array<double, 2> const& contravariant_vector,
91 PositionCoordinate const& coord) const
92 {
93 Matrix_2x2 inv_metric_tensor;
94 inverse(inv_metric_tensor, coord);
95 std::array<double, 2> covariant_vector;
96 covariant_vector[0] = inv_metric_tensor[0][0] * contravariant_vector[0]
97 + inv_metric_tensor[0][1] * contravariant_vector[1];
98 covariant_vector[1] = inv_metric_tensor[1][0] * contravariant_vector[0]
99 + inv_metric_tensor[1][1] * contravariant_vector[1];
100 return covariant_vector;
101 }
102};
An operator for calculating the metric tensor.
Definition metric_tensor.hpp:15
KOKKOS_FUNCTION MetricTensor(Mapping mapping)
A constructor for the metric tensor operator.
Definition metric_tensor.hpp:32
std::array< std::array< double, 2 >, 2 > Matrix_2x2
The type of the Jacobian matrix and its inverse.
Definition metric_tensor.hpp:21
KOKKOS_FUNCTION std::array< double, 2 > to_covariant(std::array< double, 2 > const &contravariant_vector, PositionCoordinate const &coord) const
Compute the covariant vector from the contravariant vector.
Definition metric_tensor.hpp:89
KOKKOS_FUNCTION void inverse(Matrix_2x2 &matrix, PositionCoordinate const &coord) const
Compute the inverse metric tensor associated to the mapping.
Definition metric_tensor.hpp:66
KOKKOS_FUNCTION void operator()(Matrix_2x2 &matrix, PositionCoordinate const &coord) const
Compute the metric tensor assignd to the mapping.
Definition metric_tensor.hpp:46