7 #include <boost/test/unit_test_log.hpp> 8 #define BOOST_TEST_DYN_LINK 9 #include <boost/test/unit_test.hpp> 11 #include "Grid/grid_dist_id.hpp" 12 #include "data_type/aggregate.hpp" 13 #include "VCluster/VCluster.hpp" 14 #include "Vector/Vector.hpp" 15 #include "FiniteDifference/util/common.hpp" 16 #include "FiniteDifference/eq.hpp" 17 #include "FiniteDifference/FD_op.hpp" 20 constexpr
int narrow_band_half_width = 5;
31 template<
typename gr
id_type,
typename domain_type,
size_t phi_field>
43 double posx = key_g.
get(0)*dx + domain.getLow(0);
44 double posy = key_g.get(1)*dy + domain.getLow(1);
45 double posz = key_g.get(2)*dz + domain.getLow(2);
48 double phi_val = 1.0 - sqrt(((posx - params.origin[0])/params.radiusA)*((posx - params.origin[0])/params.radiusA) + ((posy - params.origin[1])/params.radiusB)*((posy - params.origin[1])/params.radiusB) + ((posz - params.origin[2])/params.radiusC)*((posz - params.origin[2])/params.radiusC));
49 gd.template get<phi_field>(key) = phi_val;
54 BOOST_AUTO_TEST_SUITE( closest_point_test )
57 BOOST_AUTO_TEST_CASE( closest_point_unit_sphere )
60 constexpr
int SIM_DIM = 3;
61 constexpr
int POLY_ORDER = 5;
62 constexpr
int SIM_GRID_SIZE = 128;
69 const long int sz[SIM_DIM] = {SIM_GRID_SIZE, SIM_GRID_SIZE, SIM_GRID_SIZE};
70 const size_t szu[SIM_DIM] = {(size_t) sz[0], (
size_t) sz[1], (size_t) sz[2]};
80 constexpr
int phi = 0;
83 double nb_gamma = 0.0;
88 GridDist gdist(szu, domain, grid_ghost, grid_bc);
92 params.origin[x] = 0.0;
93 params.origin[y] = 0.0;
94 params.origin[z] = 0.0;
100 nb_gamma = narrow_band_half_width * gdist.spacing(0);
103 initializeLSEllipsoid<GridDist, Box<SIM_DIM,double>, phi>(gdist, domain, params);
104 gdist.template ghost_get<phi>();
107 estimateClosestPoint<GridDist, GridKey, POLY_ORDER, phi, cp>(gdist, nb_gamma);
108 gdist.template ghost_get<cp>();
111 auto &patches = gdist.getLocalGridsInfo();
112 double max_error_cp = -1.0;
113 for(
int i = 0; i < patches.size();i++)
116 auto p_xlo = patches.get(i).Dbox.getLow(0) + patches.get(i).origin[0];
117 auto p_xhi = patches.get(i).Dbox.getHigh(0) + patches.get(i).origin[0];
118 auto p_ylo = patches.get(i).Dbox.getLow(1) + patches.get(i).origin[1];
119 auto p_yhi = patches.get(i).Dbox.getHigh(1) + patches.get(i).origin[1];
120 auto p_zlo = patches.get(i).Dbox.getLow(2) + patches.get(i).origin[2];
121 auto p_zhi = patches.get(i).Dbox.getHigh(2) + patches.get(i).origin[2];
123 auto it = gdist.getSubDomainIterator({p_xlo, p_ylo, p_zlo}, {p_xhi, p_yhi, p_zhi});
128 if(std::abs(gdist.template get<phi>(key)) < nb_gamma)
130 auto key_g = gdist.getGKey(key);
133 double cpx = gdist.template get<cp>(key)[x];
134 double cpy = gdist.template get<cp>(key)[y];
135 double cpz = gdist.template get<cp>(key)[z];
137 if(cpx == -100.0 && cpy == -100.0 && cpz == -100.0)
138 std::cout<<
"ERROR: Requesting closest point where it was not computed."<<std::endl;
141 double estim_px = domain.getLow(x) + (p_xlo - algoim_padding)*gdist.spacing(x) + cpx;
142 double estim_py = domain.getLow(y) + (p_ylo - algoim_padding)*gdist.spacing(y) + cpy;
143 double estim_pz = domain.getLow(z) + (p_zlo - algoim_padding)*gdist.spacing(z) + cpz;
146 double posx = key_g.get(0)*gdist.spacing(0) + domain.getLow(0);
147 double posy = key_g.get(1)*gdist.spacing(1) + domain.getLow(1);
148 double posz = key_g.get(2)*gdist.spacing(2) + domain.getLow(2);
150 double norm = sqrt(posx*posx + posy*posy + posz*posz);
152 double exact_px = posx / norm;
153 double exact_py = posy / norm;
154 double exact_pz = posz / norm;
156 max_error_cp = std::max({std::abs(estim_px - exact_px), std::abs(estim_py - exact_py), std::abs(estim_pz - exact_pz), max_error_cp});
161 std::cout<<
"Unit sphere closest_point error : "<<max_error_cp<<std::endl;
162 double tolerance = 1e-5;
164 if (std::abs(max_error_cp) < tolerance)
173 BOOST_AUTO_TEST_CASE( reinitialization_unit_sphere )
176 constexpr
int SIM_DIM = 3;
177 constexpr
int POLY_ORDER = 5;
178 constexpr
int SIM_GRID_SIZE = 128;
185 const long int sz[SIM_DIM] = {SIM_GRID_SIZE, SIM_GRID_SIZE, SIM_GRID_SIZE};
186 const size_t szu[SIM_DIM] = {(size_t) sz[0], (
size_t) sz[1], (size_t) sz[2]};
196 constexpr
int phi = 0;
197 constexpr
int cp = 1;
199 double nb_gamma = 0.0;
204 GridDist gdist(szu, domain, grid_ghost, grid_bc);
207 params.origin[x] = 0.0;
208 params.origin[y] = 0.0;
209 params.origin[z] = 0.0;
210 params.radiusA = 1.0;
211 params.radiusB = 1.0;
212 params.radiusC = 1.0;
214 nb_gamma = narrow_band_half_width * gdist.spacing(0);
216 initializeLSEllipsoid<GridDist, Box<SIM_DIM,double>, phi>(gdist, domain, params);
217 gdist.template ghost_get<phi>();
219 estimateClosestPoint<GridDist, GridKey, POLY_ORDER, phi, cp>(gdist, nb_gamma);
220 gdist.template ghost_get<cp>();
223 reinitializeLS<GridDist, GridKey, POLY_ORDER, phi, cp>(gdist, nb_gamma);
224 gdist.template ghost_get<phi>();
227 auto &patches = gdist.getLocalGridsInfo();
228 double max_error = -1.0;
229 for(
int i = 0; i < patches.size();i++)
231 auto p_xlo = patches.get(i).Dbox.getLow(0) + patches.get(i).origin[0];
232 auto p_xhi = patches.get(i).Dbox.getHigh(0) + patches.get(i).origin[0];
233 auto p_ylo = patches.get(i).Dbox.getLow(1) + patches.get(i).origin[1];
234 auto p_yhi = patches.get(i).Dbox.getHigh(1) + patches.get(i).origin[1];
235 auto p_zlo = patches.get(i).Dbox.getLow(2) + patches.get(i).origin[2];
236 auto p_zhi = patches.get(i).Dbox.getHigh(2) + patches.get(i).origin[2];
238 auto it = gdist.getSubDomainIterator({p_xlo, p_ylo, p_zlo}, {p_xhi, p_yhi, p_zhi});
243 if(std::abs(gdist.template get<phi>(key)) < nb_gamma)
245 auto key_g = gdist.getGKey(key);
247 double posx = key_g.get(0)*gdist.spacing(0) + domain.getLow(0);
248 double posy = key_g.get(1)*gdist.spacing(1) + domain.getLow(1);
249 double posz = key_g.get(2)*gdist.spacing(2) + domain.getLow(2);
253 double distance = 1.0 - sqrt(posx*posx + posy*posy + posz*posz);
255 max_error = std::max({std::abs(distance - gdist.template get<phi>(key)), max_error});
260 std::cout<<
"Reinitialization error : "<<max_error<<std::endl;
261 double tolerance = 1e-5;
263 if (std::abs(max_error) < tolerance)
272 BOOST_AUTO_TEST_SUITE_END()
Point< dim, St > getSpacing()
Get the spacing on each dimension.
grid_key_dx< dim > getGKey(const grid_dist_key_dx< dim > &k) const
Convert a g_dist_key_dx into a global key.
__device__ __host__ index_type get(index_type i) const
Get the i index.
Grid key for a distributed grid.
Functions for level set reinitialization and extension on OpenFPM grids based on closest point method...
This is a distributed grid.
grid_dist_iterator< dim, device_grid, decltype(device_grid::type_of_subiterator()), FREE > getDomainIterator() const
It return an iterator that span the full grid domain (each processor span its local domain)
This class represent an N-dimensional box.