Tatooine
regular_flowmap_discretization.h
Go to the documentation of this file.
1#ifndef TATOOINE_REGULAR_FLOWMAP_DISCRETIZATION_H
2#define TATOOINE_REGULAR_FLOWMAP_DISCRETIZATION_H
3//==============================================================================
4#include <tatooine/field.h>
6#include <tatooine/particle.h>
9//==============================================================================
10namespace tatooine {
11//==============================================================================
13template <typename Real, std::size_t NumDimensions>
15 using real_type = Real;
16 static auto constexpr num_dimensions() { return NumDimensions; }
19 template <std::size_t M, typename... Ts>
21 using type = typename grid_type_creator<M - 1, linspace<Real>, Ts...>::type;
22 };
23 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
24 template <typename... Ts>
25 struct grid_type_creator<0, Ts...> {
26 using type = rectilinear_grid<Ts...>;
27 };
28 //----------------------------------------------------------------------------
29 // using forward_grid_type = typename grid_type_creator<NumDimensions>::type;
30 // using forward_grid_vertex_property_type =
31 // detail::rectilinear_grid::typed_vertex_property_interface<
32 // forward_grid_type, pos_type, true>;
34 // template <std::size_t M, template <typename> typename...
35 // InterpolationKernels> struct forward_grid_sampler_type_creator {
36 // using type =
37 // typename forward_grid_sampler_type_creator<M - 1,
38 // interpolation::linear,
39 // InterpolationKernels...>::type;
40 // };
43 // template <template <typename> typename... InterpolationKernels>
44 // struct forward_grid_sampler_type_creator<0, InterpolationKernels...> {
45 // using type = tatooine::detail::rectilinear_grid::vertex_property_sampler<
46 // forward_grid_vertex_property_type, InterpolationKernels...>;
47 // };
48 // using forward_grid_vertex_property_sampler_type =
49 // typename forward_grid_sampler_type_creator<NumDimensions>::type;
50
53 typename forward_grid_type::template typed_vertex_property_type<pos_type>;
54 using forward_grid_vertex_property_sampler_type = typename forward_grid_type::
55 template natural_neighbor_coordinates_sampler_type<pos_type>;
56
59 typename backward_grid_type::template typed_vertex_property_type<
60 pos_type>;
62 typename backward_grid_type::
63 template natural_neighbor_coordinates_sampler_type<pos_type>;
64 //============================================================================
65 private:
66 Real m_t0 = Real{};
67 Real m_t1 = Real{};
68 Real m_tau = Real{};
69
72 std::unique_ptr<forward_grid_vertex_property_sampler_type> m_forward_sampler =
73 nullptr;
74
77 nullptr;
78 std::unique_ptr<backward_grid_vertex_property_sampler_type>
81 //============================================================================
82 template <typename Flowmap, typename ExecutionPolicy, integral Int,
83 std::size_t... Is>
84 regular_flowmap_discretization(std::index_sequence<Is...> seq,
85 Flowmap&& flowmap, arithmetic auto const t0,
86 arithmetic auto const tau, pos_type const& min,
87 pos_type const& max,
88 ExecutionPolicy execution_policy,
89 vec<Int, NumDimensions> const& resolution)
91 std::forward<Flowmap>(flowmap),
92 t0,
93 tau,
94 min,
95 max,
96 execution_policy,
97 resolution(Is)...} {}
98 template <typename Flowmap, typename ExecutionPolicy, std::size_t... Is>
99 regular_flowmap_discretization(std::index_sequence<Is...> /*seq*/,
100 Flowmap&& flowmap, arithmetic auto const t0,
101 arithmetic auto const tau, pos_type const& min,
102 pos_type const& max,
103 ExecutionPolicy /*execution_policy*/,
104 integral auto const... resolution)
105 : m_t0{real_type(t0)},
106 m_t1{real_type(t0 + tau)},
107 m_tau{real_type(tau)},
108
111 &m_forward_grid.template vertex_property<pos_type>(
112 "flowmap_discretization")},
114
117 &m_backward_grid.template vertex_property<pos_type>(
118 "flowmap_discretization")},
120 // fill forward pointset from rectilinear grid
122 min(Is), max(Is), static_cast<std::size_t>(resolution)}...};
123 m_forward_grid.vertices().reserve(grid.vertices().size());
124 grid.vertices().iterate_positions(
125 [this](auto const& p) { m_forward_grid.insert_vertex(p); });
126
127 // equip positions with flow maps
128 m_forward_grid.sample_to_vertex_property(
129 [&](auto const& x) mutable {
130 if constexpr (requires { flowmap.use_caching(false); }) {
131 flowmap.use_caching(false);
132 }
133 return flowmap(x, m_t0, m_tau);
134 },
135 "flowmap_discretization" /*, execution_policy*/);
136
137 // create forward sampler
139 std::make_unique<forward_grid_vertex_property_sampler_type>(
140 m_forward_grid.natural_neighbor_coordinates_sampler(
142
143 m_backward_grid.vertices().resize(m_forward_grid.vertices().size());
144 for (auto const v : m_forward_grid.vertices()) {
146 m_backward_flowmap_discretization->at(v.index()) =
147 m_forward_grid.vertex_at(v);
148 }
150 std::make_unique<backward_grid_vertex_property_sampler_type>(
151 m_backward_grid.natural_neighbor_coordinates_sampler(
153 }
154 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
155 public:
158 .template vertex_property<
159 pos_type>(
160 "flowmap_discretization")},
162 &m_backward_grid.template vertex_property<pos_type>(
163 "flowmap_discretization")} {}
164 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
165 regular_flowmap_discretization(filesystem::path const& p)
167 read(p);
168 }
169 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
170 template <typename Flowmap, typename ExecutionPolicy>
172 ExecutionPolicy execution_policy,
173 arithmetic auto const t0,
174 arithmetic auto const tau, pos_type const& min,
175 pos_type const& max,
176 integral auto const... resolution)
178 std::make_index_sequence<NumDimensions>{},
179 std::forward<Flowmap>(flowmap),
180 t0,
181 tau,
182 min,
183 max,
184 execution_policy,
185 resolution...} {
186 static_assert(
187 sizeof...(resolution) == NumDimensions,
188 "Number of resolution components does not match number of dimensions.");
189 static_assert(
190 std::decay_t<Flowmap>::num_dimensions() == NumDimensions,
191 "Number of dimensions of flowmap does not match number of dimensions.");
192 }
193 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
194 template <typename Flowmap, typename ExecutionPolicy, integral Int>
196 ExecutionPolicy execution_policy,
197 arithmetic auto const t0,
198 arithmetic auto const tau, pos_type const& min,
199 pos_type const& max,
200 vec<Int, NumDimensions> const& resolution)
202 std::make_index_sequence<NumDimensions>{},
203 std::forward<Flowmap>(flowmap),
204 t0,
205 tau,
206 min,
207 max,
208 execution_policy,
209 resolution} {
210 static_assert(
211 std::decay_t<Flowmap>::num_dimensions() == NumDimensions,
212 "Number of dimensions of flowmap does not match number of dimensions.");
213 }
214 //----------------------------------------------------------------------------
215 template <typename Flowmap>
216 regular_flowmap_discretization(Flowmap&& flowmap, arithmetic auto const t0,
217 arithmetic auto const tau, pos_type const& min,
218 pos_type const& max,
219 integral auto const... resolution)
221 std::make_index_sequence<NumDimensions>{},
222 std::forward<Flowmap>(flowmap),
223 t0,
224 tau,
225 min,
226 max,
227 default_execution_policy,
228 resolution...} {
229 static_assert(
230 sizeof...(resolution) == NumDimensions,
231 "Number of resolution components does not match number of dimensions.");
232 static_assert(
233 std::decay_t<Flowmap>::num_dimensions() == NumDimensions,
234 "Number of dimensions of flowmap does not match number of dimensions.");
235 }
236 //----------------------------------------------------------------------------
237 template <typename Flowmap, integral Int>
238 regular_flowmap_discretization(Flowmap&& flowmap, arithmetic auto const t0,
239 arithmetic auto const tau, pos_type const& min,
240 pos_type const& max,
241 vec<Int, NumDimensions> const& resolution)
243 std::make_index_sequence<NumDimensions>{},
244 std::forward<Flowmap>(flowmap),
245 t0,
246 tau,
247 min,
248 max,
249 default_execution_policy,
250 resolution} {
251 static_assert(
252 std::decay_t<Flowmap>::num_dimensions() == NumDimensions,
253 "Number of dimensions of flowmap does not match number of dimensions.");
254 }
255 //----------------------------------------------------------------------------
257 regular_flowmap_discretization&& other) noexcept
258 : m_t0{other.m_t0},
259 m_t1{other.m_t0},
260 m_tau{other.m_t0},
261
262 m_forward_grid{std::move(other.m_forward_grid)},
263 m_forward_flowmap_discretization{
264 &m_forward_grid.template vertex_property<pos_type>(
265 "flowmap_discretization")},
266 m_forward_sampler{std::move(other.m_forward_sampler)},
267
268 m_backward_grid{std::move(other.m_backward_grid)},
269 m_backward_flowmap_discretization{
270 &m_backward_grid.template vertex_property<pos_type>(
271 "flowmap_discretization")},
272 m_backward_sampler{std::move(other.m_backward_sampler)} {}
273 //----------------------------------------------------------------------------
274 auto read(filesystem::path const&) {}
275 auto write(filesystem::path const&) {}
276 //----------------------------------------------------------------------------
278 auto grid(forward_tag const /*direction*/) const -> auto const& {
279 return m_forward_grid;
280 }
281 //----------------------------------------------------------------------------
282 auto grid(forward_tag const /*direction*/) -> auto& { return m_forward_grid; }
283 //----------------------------------------------------------------------------
284 auto grid(backward_tag const /*direction*/) const -> auto const& {
285 return m_backward_grid;
286 }
287 //----------------------------------------------------------------------------
288 auto grid(backward_tag const /*direction*/) -> auto& {
289 return m_backward_grid;
290 }
292 //----------------------------------------------------------------------------
294 auto sampler(forward_tag const /*direction*/) const -> auto const& {
295 return *m_forward_sampler;
296 }
297 //----------------------------------------------------------------------------
298 auto sampler(forward_tag const /*direction*/) -> auto& {
299 return *m_forward_sampler;
300 }
301 //----------------------------------------------------------------------------
302 auto sampler(backward_tag const /*direction*/) const -> auto const& {
303 return *m_backward_sampler;
304 }
305 //----------------------------------------------------------------------------
306 auto sampler(backward_tag const /*direction*/) -> auto& {
307 return *m_backward_sampler;
308 }
310 //----------------------------------------------------------------------------
312 auto flowmap(forward_tag const /*direction*/) -> auto const& {
313 return *m_forward_flowmap_discretization;
314 }
315 //----------------------------------------------------------------------------
316 auto flowmap(backward_tag const /*direction*/) -> auto const& {
317 return *m_backward_flowmap_discretization;
318 }
320 //----------------------------------------------------------------------------
325 auto sample(pos_type const& x,
326 forward_or_backward_tag auto const direction) const {
327 return sampler(direction)(x);
328 }
329};
330//==============================================================================
333//==============================================================================
334} // namespace tatooine
335//==============================================================================
336#endif
Definition: grid_edge.h:16
Definition: rectilinear_grid.h:38
Definition: concepts.h:33
Definition: concepts.h:21
static constexpr parallel_t parallel
Definition: tags.h:60
Definition: algorithm.h:6
auto flowmap(vectorfield< V, Real, NumDimensions > const &v, tag::numerical_t)
Definition: numerical_flowmap.h:412
constexpr auto max(A &&a, B &&b)
Definition: math.h:20
constexpr auto min(A &&a, B &&b)
Definition: math.h:15
static constexpr forward_tag forward
Definition: tags.h:9
Definition: tags.h:10
Definition: tags.h:8
Definition: linspace.h:26
Definition: pointset.h:69
Definition: regular_flowmap_discretization.h:20
typename grid_type_creator< M - 1, linspace< Real >, Ts... >::type type
Definition: regular_flowmap_discretization.h:21
Samples a flow map by advecting particles from a uniform rectilinear grid.
Definition: regular_flowmap_discretization.h:14
vec< Real, NumDimensions > vec_type
Definition: regular_flowmap_discretization.h:17
typename backward_grid_type::template typed_vertex_property_type< pos_type > backward_grid_vertex_property_type
Definition: regular_flowmap_discretization.h:60
auto sampler(forward_tag const) -> auto &
Definition: regular_flowmap_discretization.h:298
auto sampler(forward_tag const) const -> auto const &
Definition: regular_flowmap_discretization.h:294
auto grid(backward_tag const) -> auto &
Definition: regular_flowmap_discretization.h:288
regular_flowmap_discretization(filesystem::path const &p)
Definition: regular_flowmap_discretization.h:165
auto grid(backward_tag const) const -> auto const &
Definition: regular_flowmap_discretization.h:284
auto sample(pos_type const &x, forward_or_backward_tag auto const direction) const
Definition: regular_flowmap_discretization.h:325
auto flowmap(forward_tag const) -> auto const &
Definition: regular_flowmap_discretization.h:312
auto read(filesystem::path const &)
Definition: regular_flowmap_discretization.h:274
regular_flowmap_discretization(Flowmap &&flowmap, arithmetic auto const t0, arithmetic auto const tau, pos_type const &min, pos_type const &max, vec< Int, NumDimensions > const &resolution)
Definition: regular_flowmap_discretization.h:238
Real real_type
Definition: regular_flowmap_discretization.h:15
regular_flowmap_discretization(regular_flowmap_discretization &&other) noexcept
Definition: regular_flowmap_discretization.h:256
regular_flowmap_discretization(std::index_sequence< Is... >, Flowmap &&flowmap, arithmetic auto const t0, arithmetic auto const tau, pos_type const &min, pos_type const &max, ExecutionPolicy, integral auto const ... resolution)
Definition: regular_flowmap_discretization.h:99
pointset< Real, NumDimensions > forward_grid_type
Definition: regular_flowmap_discretization.h:51
Real m_t1
Definition: regular_flowmap_discretization.h:67
auto sampler(backward_tag const) -> auto &
Definition: regular_flowmap_discretization.h:306
regular_flowmap_discretization(Flowmap &&flowmap, arithmetic auto const t0, arithmetic auto const tau, pos_type const &min, pos_type const &max, integral auto const ... resolution)
Definition: regular_flowmap_discretization.h:216
std::unique_ptr< forward_grid_vertex_property_sampler_type > m_forward_sampler
Definition: regular_flowmap_discretization.h:72
auto sampler(backward_tag const) const -> auto const &
Definition: regular_flowmap_discretization.h:302
static auto constexpr num_dimensions()
Definition: regular_flowmap_discretization.h:16
regular_flowmap_discretization(Flowmap &&flowmap, ExecutionPolicy execution_policy, arithmetic auto const t0, arithmetic auto const tau, pos_type const &min, pos_type const &max, vec< Int, NumDimensions > const &resolution)
Definition: regular_flowmap_discretization.h:195
auto flowmap(backward_tag const) -> auto const &
Definition: regular_flowmap_discretization.h:316
auto grid(forward_tag const) -> auto &
Definition: regular_flowmap_discretization.h:282
auto grid(forward_tag const) const -> auto const &
Definition: regular_flowmap_discretization.h:278
forward_grid_vertex_property_type * m_forward_flowmap_discretization
Definition: regular_flowmap_discretization.h:71
regular_flowmap_discretization()
Definition: regular_flowmap_discretization.h:156
pointset< Real, NumDimensions > backward_grid_type
Definition: regular_flowmap_discretization.h:57
backward_grid_vertex_property_type * m_backward_flowmap_discretization
Definition: regular_flowmap_discretization.h:76
typename forward_grid_type::template typed_vertex_property_type< pos_type > forward_grid_vertex_property_type
Definition: regular_flowmap_discretization.h:53
regular_flowmap_discretization(std::index_sequence< Is... > seq, Flowmap &&flowmap, arithmetic auto const t0, arithmetic auto const tau, pos_type const &min, pos_type const &max, ExecutionPolicy execution_policy, vec< Int, NumDimensions > const &resolution)
Definition: regular_flowmap_discretization.h:84
Real m_tau
Definition: regular_flowmap_discretization.h:68
regular_flowmap_discretization(Flowmap &&flowmap, ExecutionPolicy execution_policy, arithmetic auto const t0, arithmetic auto const tau, pos_type const &min, pos_type const &max, integral auto const ... resolution)
Definition: regular_flowmap_discretization.h:171
Real m_t0
Definition: regular_flowmap_discretization.h:66
forward_grid_type m_forward_grid
Definition: regular_flowmap_discretization.h:70
typename forward_grid_type::template natural_neighbor_coordinates_sampler_type< pos_type > forward_grid_vertex_property_sampler_type
Definition: regular_flowmap_discretization.h:55
std::unique_ptr< backward_grid_vertex_property_sampler_type > m_backward_sampler
Definition: regular_flowmap_discretization.h:79
static constexpr auto default_execution_policy
Definition: regular_flowmap_discretization.h:80
backward_grid_type m_backward_grid
Definition: regular_flowmap_discretization.h:75
typename backward_grid_type::template natural_neighbor_coordinates_sampler_type< pos_type > backward_grid_vertex_property_sampler_type
Definition: regular_flowmap_discretization.h:63
auto write(filesystem::path const &)
Definition: regular_flowmap_discretization.h:275