34template < std::
floating_po
int ScalarType >
43 const ScalarType nx = Kokkos::fabs( n( 0 ) );
44 const ScalarType ny = Kokkos::fabs( n( 1 ) );
45 const ScalarType nz = Kokkos::fabs( n( 2 ) );
49 if ( nx <= ny && nx <= nz )
51 ref = { ScalarType( 1 ), ScalarType( 0 ), ScalarType( 0 ) };
53 else if ( ny <= nx && ny <= nz )
55 ref = { ScalarType( 0 ), ScalarType( 1 ), ScalarType( 0 ) };
59 ref = { ScalarType( 0 ), ScalarType( 0 ), ScalarType( 1 ) };
63 Vec3 t1 = ref.cross( n ).normalized();
64 const ScalarType eps = std::is_same_v< ScalarType, double > ? 1e-15 : 1e-6;
65 if ( t1.norm() < eps )
67 t1 = Vec3{ n( 1 ), -n( 0 ), ScalarType( 0 ) }.normalized();
70 const Vec3 t2 = n.cross( t1 ).normalized();
73 Mat3 R = Mat3::from_row_vecs( n, t1, t2 );
94template < std::
floating_po
int ScalarType >
98 return trafo_mat_cartesian_to_normal_tangential< ScalarType >( n_input ).
transposed();
101template < std::
floating_po
int ScalarType, std::
floating_po
int ScalarTypeGr
id, util::FlagLike FlagType >
106 const FlagType& flag )
111 Kokkos::parallel_for(
112 "cartesian_to_normal_tangential_in_place",
113 Kokkos::MDRangePolicy(
114 { 0, 0, 0, 0 }, { data.extent( 0 ), data.extent( 1 ), data.extent( 2 ), data.extent( 3 ) } ),
115 KOKKOS_LAMBDA(
int local_subdomain,
int i,
int j,
int k ) {
116 if ( !
util::has_flag( mask_data( local_subdomain, i, j, k ), flag ) )
122 for (
int d = 0; d < 3; ++d )
124 vec_local_cart( d ) = data( local_subdomain, i, j, k, d );
129 for (
int d = 0; d < 3; ++d )
131 normal( d ) = coords_shell( local_subdomain, i, j, d );
135 const auto vec_local_normal_tangential = R * vec_local_cart;
137 for (
int d = 0; d < 3; ++d )
139 data( local_subdomain, i, j, k, d ) = vec_local_normal_tangential( d );
145template < std::
floating_po
int ScalarType, std::
floating_po
int ScalarTypeGr
id, util::FlagLike FlagType >
150 const FlagType& flag )
152 auto data = vec_normal_tangential.
grid_data();
153 auto mask = vec_normal_tangential.
mask_data();
155 Kokkos::parallel_for(
156 "cartesian_to_normal_tangential_in_place",
157 Kokkos::MDRangePolicy(
158 { 0, 0, 0, 0 }, { data.extent( 0 ), data.extent( 1 ), data.extent( 2 ), data.extent( 3 ) } ),
159 KOKKOS_LAMBDA(
int local_subdomain,
int i,
int j,
int k ) {
160 if ( !
util::has_flag( mask_data( local_subdomain, i, j, k ), flag ) )
166 for (
int d = 0; d < 3; ++d )
168 vec_local_normal_tangential( d ) = data( local_subdomain, i, j, k, d );
172 for (
int d = 0; d < 3; ++d )
174 normal( d ) = coords_shell( local_subdomain, i, j, d );
178 const auto vec_local_cart = Rt * vec_local_normal_tangential;
180 for (
int d = 0; d < 3; ++d )
182 data( local_subdomain, i, j, k, d ) = vec_local_cart( d );
const grid::Grid4DDataScalar< grid::NodeOwnershipFlag > & mask_data() const
Get const reference to mask data.
Definition vector_q1.hpp:285
const grid::Grid4DDataVec< ScalarType, VecDim > & grid_data() const
Get const reference to grid data.
Definition vector_q1.hpp:280
Kokkos::View< ScalarType ***[VecDim], Layout > Grid3DDataVec
Definition grid_types.hpp:40
Kokkos::View< ScalarType ****, Layout > Grid4DDataScalar
Definition grid_types.hpp:25
Definition local_basis_trafo_normal_tangential.hpp:9
void cartesian_to_normal_tangential_in_place(VectorQ1Vec< ScalarType, 3 > &vec_cartesian, const grid::Grid3DDataVec< ScalarTypeGrid, 3 > &coords_shell, const grid::Grid4DDataScalar< FlagType > mask_data, const FlagType &flag)
Definition local_basis_trafo_normal_tangential.hpp:102
dense::Mat< ScalarType, 3, 3 > trafo_mat_normal_tangential_to_cartesian_trafo(const dense::Vec< ScalarType, 3 > &n_input)
Constructs the inverse transformation matrix from (normal–tangential–tangential) to Cartesian coordin...
Definition local_basis_trafo_normal_tangential.hpp:96
void normal_tangential_to_cartesian_in_place(VectorQ1Vec< ScalarType, 3 > &vec_normal_tangential, const grid::Grid3DDataVec< ScalarTypeGrid, 3 > &coords_shell, const grid::Grid4DDataScalar< FlagType > mask_data, const FlagType &flag)
Definition local_basis_trafo_normal_tangential.hpp:146
dense::Mat< ScalarType, 3, 3 > trafo_mat_cartesian_to_normal_tangential(const dense::Vec< ScalarType, 3 > &n_input)
Constructs a robust orthonormal transformation matrix from Cartesian to (normal–tangential–tangential...
Definition local_basis_trafo_normal_tangential.hpp:36
constexpr bool has_flag(E mask_value, E flag) noexcept
Checks if a bitmask value contains a specific flag.
Definition bit_masking.hpp:43
constexpr Mat< T, Cols, Rows > transposed() const
Definition mat.hpp:187
Vec normalized() const
Return a normalized copy of the vector.
Definition vec.hpp:102