OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
RemoveLines.hpp
1//
2// Created by jstark on 07.10.21.
3//
4
5#ifndef SUSSMAN_REDISTANCING_REMOVELINES_HPP
6#define SUSSMAN_REDISTANCING_REMOVELINES_HPP
7
16template <size_t Phi_0_grid, int sign_inside, typename grid_type>
17void removeLines(grid_type & grid)
18{
19 if(sign_inside == 0)
20 {
21 std::cout << "sign_inside was set to 0. However, it must be set to +1 or -1 depending on the level-set "
22 "convention used. Aborting..." << std::endl;
23 abort();
24 }
25 for(int repeat = 0; repeat < 2; ++repeat)
26 {
27 grid.template ghost_get<Phi_0_grid>(KEEP_PROPERTIES);
28 if (sign_inside > 0)
29 {
30 auto dom = grid.getDomainIterator();
31 while(dom.isNext())
32 {
33 auto key = dom.get();
34 if (grid.template getProp<Phi_0_grid>(key) > 0)
35 {
36 for (int d = 0; d < grid_type::dims; ++d)
37 {
38 if (grid.template getProp<Phi_0_grid>(key.move(d, -1)) < 0
39 && grid.template getProp<Phi_0_grid>(key.move(d, +1)) < 0)
40 {
41 grid.template getProp<Phi_0_grid>(key) = grid.template getProp<Phi_0_grid>(key.move(d, +1));
42 break;
43 }
44 }
45 }
46 ++dom;
47 }
48 }
49 if (sign_inside < 0)
50 {
51 auto dom = grid.getDomainIterator();
52 while(dom.isNext())
53 {
54 auto key = dom.get();
55 if (grid.template getProp<Phi_0_grid>(key) < 0)
56 {
57 for (int d = 0; d < grid_type::dims; ++d)
58 {
59 if (grid.template getProp<Phi_0_grid>(key.move(d, -1)) > 0
60 && grid.template getProp<Phi_0_grid>(key.move(d, +1)) > 0)
61 {
62 grid.template getProp<Phi_0_grid>(key) = grid.template getProp<Phi_0_grid>(key.move(d, +1));
63 break;
64 }
65 }
66 }
67 ++dom;
68 }
69 }
70
71 }
72}
73
74template <typename T>
75bool is_inside(T phi)
76{
77 return phi >= 0 - std::numeric_limits<T>::epsilon();
78}
79
80template <typename T>
81bool is_outside(T phi)
82{
83 return phi < 0 + std::numeric_limits<T>::epsilon();
84}
85
93template <size_t Phi_0_grid, typename grid_type>
94void removeLinesAndThinSpaces(grid_type & grid, int repeat=3)
95{
96 for(int k = 0; k < repeat; ++k)
97 {
98 grid.template ghost_get<Phi_0_grid>(KEEP_PROPERTIES);
99 auto dom = grid.getDomainIterator();
100 while(dom.isNext())
101 {
102 auto key = dom.get();
103 for (int d = 0; d < grid_type::dims; ++d)
104 {
105 if (is_inside(grid.template getProp<Phi_0_grid>(key))) // If inside but neighbors are outside
106 {
107 if (is_outside(grid.template getProp<Phi_0_grid>(key.move(d, -1)))
108 && is_outside(grid.template getProp<Phi_0_grid>(key.move(d, +1))))
109 {
110 grid.template getProp<Phi_0_grid>(key) = grid.template getProp<Phi_0_grid>(key.move(d, +1));
111 break;
112 }
113 }
114 else if (is_outside(grid.template getProp<Phi_0_grid>(key))) // If outside but neighbors are inside
115 {
116 if (is_inside(grid.template getProp<Phi_0_grid>(key.move(d, -1)))
117 && is_inside(grid.template getProp<Phi_0_grid>(key.move(d, +1))))
118 {
119 grid.template getProp<Phi_0_grid>(key) = grid.template getProp<Phi_0_grid>(key.move(d, +1));
120 break;
121 }
122 }
123 }
124 ++dom;
125 }
126 }
127}
128#endif //SUSSMAN_REDISTANCING_REMOVELINES_HPP
This is a distributed grid.
static const unsigned int dims
Number of dimensions.