OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
SurfaceNormal.hpp
1//
2// Created by jstark on 28.05.21.
3//
4
5#ifndef BOUNDARY_CONDITION_SURFACENORMAL_HPP
6#define BOUNDARY_CONDITION_SURFACENORMAL_HPP
7
8#include "cmath"
9// Include OpenFPM header files
10#include "Vector/vector_dist_subset.hpp"
11
12template <size_t Phi_SDF, size_t Phi_Gradient, size_t Normal, typename vd_type>
13void get_surface_normal_sdf(vd_type & vd, bool unit_vector=false)
14{
15 auto dom = vd.getDomainIterator();
16 while(dom.isNext())
17 {
18 auto key = dom.get();
19
20 // Get the magnitude of the gradient
21 double sum = 0;
22 for(size_t d = 0; d < vd_type::dims; d++)
23 {
24 sum += vd.template getProp<Phi_Gradient>(key)[d] * vd.template getProp<Phi_Gradient>(key)[d];
25 }
26
27 double gradient_magnitude = sqrt(sum);
28 for(size_t d = 0; d < vd_type::dims; d++)
29 {
30 if(unit_vector)
31 {
32 vd.template getProp<Normal>(key)[d] = - vd.template getProp<Phi_Gradient>(key)[d] / gradient_magnitude;
33 }
34 else
35 {
36 vd.template getProp<Normal>(key)[d] =
37 - vd.template getProp<Phi_Gradient>(key)[d] / gradient_magnitude
38 * vd.template getProp<Phi_SDF>(key);
39 }
40 }
41 ++dom;
42 }
43}
44
45template <size_t Phi_SDF, size_t Phi_Gradient, size_t Normal, typename vd_type>
46void get_surface_normal_sdf_subset(vd_type & vd, const openfpm::vector<vect_dist_key_dx> & keys_subset, bool
47unit_vector=false)
48{
49 for (int i = 0; i < keys_subset.size(); i++)
50 {
51 auto key = keys_subset.get(i);
52
53 // Get the magnitude of the gradient
54 double sum = 0;
55 for(size_t d = 0; d < vd_type::dims; d++)
56 {
57 sum += vd.template getProp<Phi_Gradient>(key)[d] * vd.template getProp<Phi_Gradient>(key)[d];
58 }
59
60 double gradient_magnitude = sqrt(sum);
61 for(size_t d = 0; d < vd_type::dims; d++)
62 {
63 vd.template getProp<Normal>(key)[d] = - vd.template getProp<Phi_Gradient>(key)[d] / gradient_magnitude;
64 }
65 if(!unit_vector)
66 {
67 vd.template getProp<Normal>(key) = vd.template getProp<Normal>(key) * vd.template getProp<Phi_SDF>
68 (key);
69 }
70 }
71}
72
73#if 0
74template <typename key_g_type, int dim>
75bool is_corner(key_g_type key_g)
76{
77 bool nodetype = false;
78 switch(dim)
79 {
80 case 1:
81 nodetype = (key_g.get(0) < 1 || key_g.get(0) > grid.size(0) - 1);
82 break;
83 case 2:
84 nodetype = ()
85
86 }
87
88 return nodetype;
89}
90
91template <typename key_g_type, int dim>
92bool is_edge(key_g_type key_g)
93{
94
95}
96
97template <typename key_g_type, int dim>
98bool is_bulk(key_g_type key_g, int border_width_in_nodes)
99{
100 for (int d=0; d<dim; d++)
101 {
102 if (key_g.get(d) < border_width_in_nodes || key_g.get(d) > grid.size(d) - border_width_in_nodes)
103 {return false;}
104 }
105 return true;
106}
107
108template <typename key_g_type, int dim>
109bool is_boundary(key_g_type key_g, int border_width_in_nodes)
110{
111 for (int d=0; d<dim; d++)
112 {
113 if (key_g.get(d) > border_width_in_nodes || key_g.get(d) < grid.size(d) - border_width_in_nodes)
114 {return false;}
115 }
116 return true;
117}
118
119
120
121template <size_t Normal, size_t SDF, typename grid_type>
122void get_surface_normal_box(grid_type & grid, bool unit_vector=false)
123{
124 auto dom = grid.getDomainIterator();
125 while (dom.isNext())
126 {
127 auto key = dom.get();
128 auto key_g = grid.getGKey(key);
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145 if (key_g.get(d) > 0 && key_g.get(d) < grid.size(d) - 1) // if point lays not at the border of the grid
146 {
147 grid.template get<Phi_grad> (key) [d] = upwind_FD<Phi, Phi_0_sign>(grid, key, d);
148 }
149
150 else if (key_g.get(d) == 0) // if point lays at left border, use right sided kernel
151 {
152 grid.template get<Phi_grad> (key) [d] = forward_FD<Phi>(grid, key, d);
153 }
154
155 else if (key_g.get(d) >= grid.size(d) - 1) // if point lays at right border, use left sided kernel
156 {
157 grid.template get<Phi_grad> (key) [d] = backward_FD<Phi>(grid, key, d);
158 }
159
160
161
162
163 ++dom;
164 }
165}
166
167
168#endif
169
170#endif //BOUNDARY_CONDITION_SURFACENORMAL_HPP
This is a distributed grid.
Implementation of 1-D std::vector like structure.
size_t size()
Stub size.
It model an expression expr1 + ... exprn.
Definition sum.hpp:93