Gyselalib++
 
Loading...
Searching...
No Matches
vector_mapper.hpp
1// SPDX-License-Identifier: MIT
2#pragma once
3
4#include <sll/view.hpp>
5
6#include "directional_tag.hpp"
7#include "vector_field.hpp"
8#include "vector_field_mem.hpp"
9
13template <class InVectorSpace, class OutVectorSpace, class Mapping, class ExecSpace>
15
26template <class XIn, class YIn, class XOut, class YOut, class Mapping, class ExecSpace>
27class VectorMapper<NDTag<XIn, YIn>, NDTag<XOut, YOut>, Mapping, ExecSpace>
28{
29 static_assert(is_accessible_v<ExecSpace, Mapping>);
30 static_assert(
31 (std::is_same_v<Coord<XIn, YIn>, typename Mapping::CoordArg>)
32 || (std::is_same_v<Coord<XIn, YIn>, typename Mapping::CoordResult>));
33 static_assert(
34 (std::is_same_v<Coord<XOut, YOut>, typename Mapping::CoordArg>)
35 || (std::is_same_v<Coord<XOut, YOut>, typename Mapping::CoordResult>));
36
37public:
39 using memory_space = typename ExecSpace::memory_space;
40
45
46private:
47 Mapping m_mapping;
48
49public:
54 explicit VectorMapper(Mapping mapping) : m_mapping(mapping) {}
55
64 template <class IdxRangeType, class LayoutStridedPolicy1, class LayoutStridedPolicy2>
66 ExecSpace exec_space,
67 VectorField<double, IdxRangeType, NDTag<XOut, YOut>, memory_space, LayoutStridedPolicy1>
68 vector_field_output,
70 double,
71 IdxRangeType,
72 NDTag<XIn, YIn>,
74 LayoutStridedPolicy2> vector_field_input)
75 {
76 using IdxType = typename IdxRangeType::discrete_element_type;
77
78 Mapping mapping_proxy = m_mapping;
79
80 if constexpr (std::is_same_v<Coord<XIn, YIn>, typename Mapping::CoordArg>) {
81 ddc::parallel_for_each(
82 exec_space,
83 get_idx_range(vector_field_input),
84 KOKKOS_LAMBDA(IdxType idx) {
85 Matrix_2x2 map_J;
86 mapping_proxy.jacobian_matrix(ddc::coordinate(idx), map_J);
87
88 vector_element_type_out vector_out;
89 vector_out.array() = mat_vec_mul(map_J, vector_field_input(idx).array());
90 ddcHelper::get<XOut>(vector_field_output)(idx) = ddc::get<XOut>(vector_out);
91 ddcHelper::get<YOut>(vector_field_output)(idx) = ddc::get<YOut>(vector_out);
92 });
93 } else {
95 ddc::parallel_for_each(
96 exec_space,
97 get_idx_range(vector_field_input),
98 KOKKOS_LAMBDA(IdxType idx) {
99 Matrix_2x2 map_J = inv_mapping(ddc::coordinate(idx));
100
101 vector_element_type_out vector_out;
102 vector_out.array() = mat_vec_mul(map_J, vector_field_input(idx).array());
103 ddcHelper::get<XOut>(vector_field_output)(idx) = ddc::get<XOut>(vector_out);
104 ddcHelper::get<YOut>(vector_field_output)(idx) = ddc::get<YOut>(vector_out);
105 });
106 }
107 }
108};
109
110
127template <
128 class ExecSpace,
129 class Mapping,
130 class ElementType,
131 class IdxRangeType,
132 class X,
133 class Y,
134 class LayoutStridedPolicy>
135auto create_geometry_mirror_view(
136 ExecSpace exec_space,
138 ElementType,
139 IdxRangeType,
140 NDTag<X, Y>,
141 typename ExecSpace::memory_space,
142 LayoutStridedPolicy> vector_field,
143 Mapping mapping)
144{
145 using CoordOut = std::conditional_t<
146 std::is_same_v<typename Mapping::CoordArg, Coord<X, Y>>,
147 typename Mapping::CoordResult,
148 typename Mapping::CoordArg>;
149 if constexpr (std::is_same_v<CoordOut, Coord<X, Y>>) {
150 return vector_field;
151 } else {
152 using X_out = ddc::type_seq_element_t<0, ddc::to_type_seq_t<CoordOut>>;
153 using Y_out = ddc::type_seq_element_t<1, ddc::to_type_seq_t<CoordOut>>;
155 std::remove_const_t<ElementType>,
156 IdxRangeType,
157 NDTag<X_out, Y_out>,
158 typename ExecSpace::memory_space>
159 vector_field_out(get_idx_range(vector_field));
160 VectorMapper<NDTag<X, Y>, NDTag<X_out, Y_out>, Mapping, ExecSpace> vector_mapping(mapping);
161 vector_mapping(exec_space, get_field(vector_field_out), get_const_field(vector_field));
162 return vector_field_out;
163 }
164}
A class to calculate the inverse of the Jacobian matrix.
Definition inverse_jacobian_matrix.hpp:18
Pre-declaration of VectorFieldMem.
Definition vector_field_mem.hpp:54
A class which holds multiple (scalar) fields in order to represent a vector field.
Definition vector_field.hpp:64
typename ExecSpace::memory_space memory_space
The type of the memory space where the field is saved (CPU vs GPU).
Definition vector_mapper.hpp:39
void operator()(ExecSpace exec_space, VectorField< double, IdxRangeType, NDTag< XOut, YOut >, memory_space, LayoutStridedPolicy1 > vector_field_output, VectorConstField< double, IdxRangeType, NDTag< XIn, YIn >, memory_space, LayoutStridedPolicy2 > vector_field_input)
Convert vectors defined in the input coordinate system to equivalent vectors in the output coordinate...
Definition vector_mapper.hpp:65
VectorMapper(Mapping mapping)
A constructor for the VectorMapper.
Definition vector_mapper.hpp:54
The general predeclaration of VectorMapper.
Definition vector_mapper.hpp:14
A type describing a vector e.g. (E_x, E_y)
Definition ddc_aliases.hpp:82
Define non periodic real X dimension.
Definition geometry.hpp:278
Define non periodic real Y dimension.
Definition geometry.hpp:289