Tatooine
boundary_switch.h
Go to the documentation of this file.
1#ifndef TATOOINE_BOUNDARY_SWITCH_H
2#define TATOOINE_BOUNDARY_SWITCH_H
3//==============================================================================
4#include "field.h"
5#include "grid_sampler.h"
6#include "interpolation.h"
7#include "sampled_field.h"
8//==============================================================================
9namespace tatooine {
10//==============================================================================
11template <typename Real>
13 const grid_sampler<Real, 2, vec<Real, 2>, interpolation::linear,
14 interpolation::linear>& sampler) {
15 const size_t left = 0;
16 const size_t right = sampler.size(0) - 1;
17 const size_t bottom = 0;
18 const size_t top = sampler.size(1) - 1;
19 std::vector<vec<Real, 2>> boundary_switch_points;
20
21 // iterate over each boundary grid cell in x-direction
22 for (size_t i = 0; i < sampler.size(0) - 1; ++i) {
23 if ((sampler[i][bottom](1) <= 0 && sampler[i + 1][bottom](1) > 0) ||
24 (sampler[i][bottom](1) >= 0 && sampler[i + 1][bottom](1) < 0)) {
25 const Real t =
26 - sampler[i][bottom](1) / (sampler[i + 1][bottom](1) - sampler[i][bottom](1));
27 boundary_switch_points.emplace_back(
28 sampler.dimension(0)[i] * (1 - t) + sampler.dimension(0)[i + 1] * t,
29 sampler.dimension(1)[bottom]);
30 }
31
32 if ((sampler[i][top](1) <= 0 && sampler[i + 1][top](1) > 0) ||
33 (sampler[i][top](1) >= 0 && sampler[i + 1][top](1) < 0)) {
34 const Real t =
35 - sampler[i][top](1) / (sampler[i + 1][top](1) - sampler[i][top](1));
36 boundary_switch_points.emplace_back(
37 sampler.dimension(0)[i] * (1 - t) + sampler.dimension(0)[i + 1] * t,
38 sampler.dimension(1)[top]);
39 }
40 }
41 // iterate over each boundary grid cell in y-direction
42 for (size_t i = 0; i < sampler.size(1) - 1; ++i) {
43 if ((sampler[left][i](0) <= 0 && sampler[left][i + 1](0) > 0) ||
44 (sampler[left][i](0) >= 0 && sampler[left][i + 1](0) < 0)) {
45 const Real t =
46 - sampler[left][i](0) / (sampler[left][i + 1](0) - sampler[left][i](0));
47 boundary_switch_points.emplace_back(
48 sampler.dimension(0)[left],
49 sampler.dimension(1)[i] * (1 - t) + sampler.dimension(1)[i + 1] * t);
50 }
51 if ((sampler[right][i](0) <= 0 && sampler[right][i + 1](0) > 0) ||
52 (sampler[right][i](0) >= 0 && sampler[right][i + 1](0) < 0)) {
53 const Real t =
54 - sampler[right][i](0) / (sampler[right][i + 1](0) - sampler[right][i](0));
55 boundary_switch_points.emplace_back(
56 sampler.dimension(0)[right],
57 sampler.dimension(1)[i] * (1 - t) + sampler.dimension(1)[i + 1] * t);
58 }
59 }
60 return boundary_switch_points;
61}
62//------------------------------------------------------------------------------
63template <typename Real>
65 const sampled_field<
66 grid_sampler<Real, 2, vec<Real, 2>, interpolation::linear,
68 Real, 2, 2>& v) {
69 return find_boundary_switch_points(v.sampler());
70}
71//==============================================================================
72} // namespace tatooine
73//==============================================================================
74#endif
Definition: algorithm.h:6
auto find_boundary_switch_points(const grid_sampler< Real, 2, vec< Real, 2 >, interpolation::linear, interpolation::linear > &sampler)
Definition: boundary_switch.h:12
Definition: interpolation.h:16
Definition: vec.h:12