OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
NarrowBand.hpp
Go to the documentation of this file.
1//
2// Created by jstark on 2020-05-16.
3//
19#ifndef REDISTANCING_SUSSMAN_NARROWBAND_HPP
20#define REDISTANCING_SUSSMAN_NARROWBAND_HPP
21
22// Include standard library header files
23#include <iostream>
24
25// Include OpenFPM header files
26#include "Vector/vector_dist.hpp"
27#include "Grid/grid_dist_id.hpp"
28#include "data_type/aggregate.hpp"
29#include "Decomposition/CartDecomposition.hpp"
30
31// Include level-set-method related header files
32#include "HelpFunctions.hpp"
35
41template <typename grid_in_type, typename phi_type=double>
43{
44public:
51 NarrowBand(const grid_in_type & grid_in,
52 size_t thickness) // thickness in # grid points
53 : g_temp(grid_in.getDecomposition(), grid_in.getGridInfoVoid().getSize(), Ghost<grid_in_type::dims, long int>(3))
54 {
55 set_bounds(thickness, grid_in);
56 }
63 NarrowBand(const grid_in_type & grid_in,
64 double thickness) // thickness as physical width
65 : g_temp(grid_in.getDecomposition(), grid_in.getGridInfoVoid().getSize(), Ghost<grid_in_type::dims, long int>(3))
66 {
67 set_bounds(thickness, grid_in);
68 }
75 NarrowBand(const grid_in_type & grid_in,
76 float thickness) // thickness as physical width
77 : g_temp(grid_in.getDecomposition(), grid_in.getGridInfoVoid().getSize(), Ghost<grid_in_type::dims, long int>(3))
78 {
79 set_bounds(thickness, grid_in);
80 }
88 template<typename width_type>
89 NarrowBand(const grid_in_type & grid_in,
90 width_type width_outside, // physical width of nb inside of object -> Phi > 0
91 width_type width_inside) // physical width nb outside of object -> Phi < 0
92 : g_temp(grid_in.getDecomposition(), grid_in.getGridInfoVoid().getSize(), Ghost<grid_in_type::dims, long int>(3))
93 {
94 set_bounds(width_outside, width_inside, grid_in);
95 }
112
124 template <size_t Phi_SDF_grid, size_t Phi_SDF_vd, typename vector_type, typename grid_type>
126 {
127 auto dom = grid.getDomainIterator();
128 while(dom.isNext())
129 {
130 auto key = dom.get();
131 if(within_narrow_band(grid.template get<Phi_SDF_grid>(key)))
132 {
133 // add particle to vd_narrow_band
134 vd.add();
135 // assign coordinates and properties from respective grid point to particle
136 for(size_t d = 0; d < grid_type::dims; d++)
137 {
138 vd.getLastPos()[d] = grid.getPos(key)[d];
139 }
140 vd.template getLastProp<Phi_SDF_vd>() = grid.template get<Phi_SDF_grid>(key);
141 }
142 ++dom;
143 }
144 vd.map();
145 }
158 template <size_t Phi_SDF_grid, size_t Phi_SDF_vd, size_t Phi_grad, typename vector_type, typename grid_type>
160 {
161 initialize_temporary_grid<Phi_SDF_grid>(grid);
162 auto dom = grid.getDomainIterator();
163 while(dom.isNext())
164 {
165 auto key = dom.get();
166 if(within_narrow_band(grid.template get<Phi_SDF_temp>(key)))
167 {
168 // add particle to vd_narrow_band
169 vd.add();
170 // assign coordinates and properties from respective grid point to particle
171 for(size_t d = 0; d < grid_type::dims; d++)
172 {
173 vd.getLastPos()[d] = grid.getPos(key)[d];
174 vd.template getLastProp<Phi_grad>()[d] = g_temp.template get<Phi_grad_temp>(key)[d];
175 }
176 vd.template getLastProp<Phi_SDF_vd>() = grid.template get<Phi_SDF_temp>(key);
177 }
178 ++dom;
179 }
180 vd.map();
181 }
195 template <size_t Phi_SDF_grid, size_t Phi_SDF_vd, size_t Phi_grad, size_t Phi_magnOfGrad, typename vector_type,
196 typename grid_type>
198 {
199 initialize_temporary_grid<Phi_SDF_grid>(grid);
200 auto dom = grid.getDomainIterator();
201 while(dom.isNext())
202 {
203 auto key = dom.get();
204 if(within_narrow_band(grid.template get<Phi_SDF_grid>(key)))
205 {
206 // add particle to vd_narrow_band
207 vd.add();
208 // assign coordinates and properties from respective grid point to particle
209 for(size_t d = 0; d < grid_type::dims; d++)
210 {
211 vd.getLastPos()[d] = grid.getPos(key)[d];
212 vd.template getLastProp<Phi_grad>()[d] = g_temp.template get<Phi_grad_temp>(key)[d];
213 }
214 vd.template getLastProp<Phi_SDF_vd>() = g_temp.template get<Phi_SDF_temp>(key);
215 vd.template getLastProp<Phi_magnOfGrad>() = get_vector_magnitude<Phi_grad_temp>(g_temp, key);
216 }
217 ++dom;
218 }
219 vd.map(); }
235 template <size_t Phi_SDF_grid, size_t Prop1_grid, size_t Prop1_vd, typename vector_type, typename grid_type>
237 {
238 auto dom = grid.getDomainIterator();
239 while(dom.isNext())
240 {
241 auto key = dom.get();
242 if(within_narrow_band(grid.template get<Phi_SDF_grid>(key)))
243 {
244 // add particle to vd_narrow_band
245 vd.add();
246 // assign coordinates and properties from respective grid point to particle
247 for(size_t d = 0; d < grid_type::dims; d++)
248 {
249 vd.getLastPos()[d] = grid.getPos(key)[d];
250 }
251 vd.template getLastProp<Prop1_vd>() = grid.template get<Prop1_grid>(key);
252 }
253 ++dom;
254 }
255 vd.map();
256 }
273 template <size_t Phi_SDF_grid, size_t Index1Grid, size_t Index2Grid, size_t Index3Grid, size_t Index1Vd, size_t
274 Index2Vd, size_t Index3Vd, typename grid_type, typename vector_type>
276 {
277
278 auto dom = grid.getDomainIterator();
279 while(dom.isNext())
280 {
281 auto key = dom.get();
282 auto key_g = grid.getGKey(key);
283 if(within_narrow_band(grid.template get<Phi_SDF_grid>(key)))
284 {
285 // add particle to vd_narrow_band
286 vd.add();
287 // assign coordinates and properties from respective grid point to particle
288 for(size_t d = 0; d < grid_type::dims; d++)
289 {
290 vd.getLastPos()[d] = key_g.get(d) * grid.getSpacing()[d];
291 }
292 vd.template getLastProp<Index1Vd>() = grid.template get<Index1Grid>(key);
293 vd.template getLastProp<Index2Vd>() = grid.template get<Index2Grid>(key);
294 vd.template getLastProp<Index3Vd>() = grid.template get<Index3Grid>(key);
295 }
296 ++dom;
297 }
298 vd.map();
299 }
300private:
301 // Some indices for better readability
302 static const size_t Phi_SDF_temp = 0;
303 static const size_t Phi_grad_temp = 1;
304 static const size_t Phi_sign_temp = 2;
305
306 phi_type b_low;
307 phi_type b_up;
308
314 void set_bounds(const size_t thickness, const grid_in_type & grid_in)
315 {
316 const phi_type EPSILON = std::numeric_limits<phi_type>::epsilon();
317 b_low = - ceil((phi_type)thickness / 2.0) * get_biggest_spacing(grid_in) - EPSILON;
318 b_up = ceil((phi_type)thickness / 2.0) * get_biggest_spacing(grid_in) + EPSILON;
319 }
325 template<typename thickness_type>
326 void set_bounds(const thickness_type thickness, const grid_in_type & grid_in)
327 {
328 const thickness_type EPSILON = std::numeric_limits<thickness_type>::epsilon();
329 b_low = - thickness / 2.0 - EPSILON;
330 b_up = thickness / 2.0 + EPSILON;
331 }
338 template<typename width_type>
339 void set_bounds(width_type lower_bound, width_type upper_bound, const grid_in_type & grid_in)
340 {
341 const width_type EPSILON = std::numeric_limits<width_type>::epsilon();
342 b_low = lower_bound - EPSILON;
343 b_up = upper_bound + EPSILON;
344 }
345
353 template <size_t Phi_SDF>
354 void initialize_temporary_grid(const grid_in_type & grid_in)
355 {
356 copy_gridTogrid<Phi_SDF, Phi_SDF_temp>(grid_in, g_temp); // Copy Phi_SDF from the input grid to the temorary grid
357 init_sign_prop<Phi_SDF_temp, Phi_sign_temp>(g_temp); // initialize Phi_sign_temp with the sign of the
358 // input Phi_SDF
359 get_upwind_gradient<Phi_SDF_temp, Phi_sign_temp, Phi_grad_temp>(g_temp, 1, true); // Get initial gradients
360 }
367 template<typename T>
369 {
370 return (Phi >= b_low && Phi <= b_up);
371 }
372};
373
374
375#endif //REDISTANCING_SUSSMAN_NARROWBAND_HPP
Header file containing help-functions that perform on OpenFPM-grids.
grid_type::stype get_biggest_spacing(grid_type &grid)
Determines the biggest spacing of a grid which is potentially anisotropic when comparing x,...
Header file containing small mathematical help-functions that are needed e.g. for the Sussman redista...
Approximating upwind gradients on a grid with the following options for the order of accuracy: 1,...
Class for getting the narrow band around the interface.
NarrowBand(const grid_in_type &grid_in, width_type width_outside, width_type width_inside)
Constructor taking the inside and outside physical width of the narrow band in order to initialize th...
phi_type b_up
Narrow band extension towards the object inside.
void set_bounds(const size_t thickness, const grid_in_type &grid_in)
Set the member variable NarrowBand::b_low and NarrowBand::b_up.
void set_bounds(const thickness_type thickness, const grid_in_type &grid_in)
Set the member variable NarrowBand::b_low and NarrowBand::b_up.
NarrowBand(const grid_in_type &grid_in, float thickness)
Constructor taking the thickness of the narrow band as physical width in space in order to initialize...
phi_type b_low
Narrow band extension towards the object outside.
aggregate< phi_type, phi_type[grid_in_type::dims], int > props_temp
Aggregated properties for the temporary grid.
void get_narrow_band(grid_type &grid, vector_type &vd)
Places particles within a narrow band around the interface. SDF and Phi_grad_temp are copied from the...
void initialize_temporary_grid(const grid_in_type &grid_in)
Initialize the internal temporary grid.
bool within_narrow_band(T Phi)
Checks if a value for Phi_SDF lays within the narrow band.
void get_narrow_band_copy_specific_property(grid_type &grid, vector_type &vd)
Places particles within a narrow band around the interface. An arbitrary property is copied from the ...
NarrowBand(const grid_in_type &grid_in, double thickness)
Constructor taking the thickness of the narrow band as physical width in space in order to initialize...
g_temp_type g_temp
Create temporary grid, which is only used inside the class to get the gradients.
static const size_t Phi_grad_temp
Property index of gradient of Phi on the temporary grid.
grid_dist_id< grid_in_type::dims, typename grid_in_type::stype, props_temp > g_temp_type
Type definition for the temporary grid.
void get_narrow_band_copy_three_scalar_properties(grid_type &grid, vector_type &vd)
Places particles within a narrow band around the interface. An arbitrary property is copied from the ...
void get_narrow_band(grid_type &grid, vector_type &vd)
Places particles within a narrow band around the interface. Only the SDF is copied from the grid prop...
NarrowBand(const grid_in_type &grid_in, size_t thickness)
Constructor taking the thickness of the narrow band as grid points in order to initialize the lower a...
static const size_t Phi_sign_temp
Property index of sign of Phi on the temporary grid.
static const size_t Phi_SDF_temp
Property index of Phi_SDF on the temporary grid.
void get_narrow_band(grid_type &grid, vector_type &vd)
Places particles within a narrow band around the interface. SDF and Phi_grad_temp are copied from the...
void set_bounds(width_type lower_bound, width_type upper_bound, const grid_in_type &grid_in)
Set the member variable NarrowBand::b_low and NarrowBand::b_up.
This is a distributed grid.
static const unsigned int dims
Number of dimensions.
Distributed vector.
void map(size_t opt=NONE)
It move all the particles that does not belong to the local processor to the respective processor.
auto getLastPos() -> decltype(v_pos.template get< 0 >(0))
Get the position of the last element.
void add()
Add local particle.
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...