17 #ifndef __CLOSEST_POINT_HPP__ 18 #define __CLOSEST_POINT_HPP__ 20 #include "algoim_hocp.hpp" 23 constexpr
int algoim_padding = 4;
35 template<
typename gr
id_type,
typename gr
id_key_type,
unsigned int dim,
size_t wrapping_field>
43 double operator() (
const blitz::TinyVector<int,dim> idx)
const 45 long int local_key[dim];
49 for (
int d = 0; d < dim; ++d)
50 local_key[d] = idx(d) - algoim_padding;
55 return gd.template get<wrapping_field>(
grid_key);
71 template<
typename gr
id_type,
typename gr
id_key_type,
unsigned int poly_order,
size_t phi_field,
size_t cp_field>
76 using Poly =
typename Algoim::StencilPoly<dim, poly_order>::T_Poly;
79 blitz::TinyVector<double,dim> dx;
80 for(
int d = 0; d < dim; ++d)
88 for(
int i = 0; i < patches.size();i++)
90 for(
int d = 0; d < dim; ++d)
92 p_lo.
set_d(d, patches.get(i).Dbox.getLow(d) + patches.get(i).origin[d]);
93 p_hi.
set_d(d, patches.get(i).Dbox.getHigh(d) + patches.get(i).origin[d]);
99 std::vector<Algoim::detail::CellPoly<dim,Poly>> cells;
101 blitz::TinyVector<int,dim> ext;
103 for(
int d = 0; d < dim; ++d)
104 ext(d) = static_cast<int>(p_hi.
get(d) - p_lo.
get(d) + 1 + 2*algoim_padding);
106 Algoim::detail::createCellPolynomials(ext, phiwrap, dx,
false, cells);
108 std::vector<blitz::TinyVector<double,dim>> points;
109 std::vector<int> pointcells;
110 Algoim::detail::samplePolynomials<dim,Poly>(cells, 2, dx, 0.0, points, pointcells);
112 Algoim::KDTree<double,dim> kdtree(points);
115 Algoim::ComputeHighOrderCP<dim,Poly> hocp(nb_gamma < std::numeric_limits<double>::max() ? nb_gamma*nb_gamma : std::numeric_limits<double>::max(),
117 Algoim::sqr(std::max(1.0e-14, std::pow(blitz::max(dx), Poly::order))),
118 cells, kdtree, points, pointcells, dx, 0.0);
124 if(std::abs(gd.template get<phi_field>(key)) <= nb_gamma)
128 blitz::TinyVector<double,dim> patch_pos, cp;
129 for(
int d = 0; d < dim; ++d)
130 patch_pos(d) = (key_g.get(d) - p_lo.
get(d) + algoim_padding) * dx(d);
132 if (hocp.compute(patch_pos, cp))
134 for(
int d = 0; d < dim; ++d)
135 gd.template get<cp_field>(key)[d] = cp(d);
139 for(
int d = 0; d < dim; ++d)
140 gd.template get<cp_field>(key)[d] = -100.0;
163 template<
typename gr
id_type,
typename gr
id_key_type,
unsigned int poly_order,
size_t phi_field,
size_t cp_field,
size_t extend_field,
size_t extend_field_temp>
168 using Poly =
typename Algoim::StencilPoly<dim, poly_order>::T_Poly;
170 blitz::TinyVector<double,dim> dx;
171 for(
int d = 0; d < dim; ++d)
177 for(
int i = 0; i < patches.size();i++)
179 for(
int d = 0; d < dim; ++d)
181 p_lo.
set_d(d, patches.get(i).Dbox.getLow(d) + patches.get(i).origin[d]);
182 p_hi.
set_d(d, patches.get(i).Dbox.getHigh(d) + patches.get(i).origin[d]);
190 if(std::abs(gd.template get<phi_field>(key)) < nb_gamma)
192 blitz::TinyVector<int,dim> coord;
193 blitz::TinyVector<double,dim> pos;
195 for(
int d = 0; d < dim; ++d)
197 double cp_d = gd.template get<cp_field>(key)[d];
198 coord(d) = static_cast<int>(floor(cp_d / gd.
spacing(d)));
199 pos(d) = cp_d - coord(d)*gd.
spacing(d);
203 Poly field_poly = Poly(coord, fieldwrap, dx);
205 gd.template get<extend_field_temp>(key) = field_poly(pos);
216 if(std::abs(gd.template get<phi_field>(key)) < nb_gamma)
217 gd.template get<extend_field>(key) = gd.template get<extend_field_temp>(key);
234 template<
typename gr
id_type,
typename gr
id_key_type,
unsigned int poly_order,
size_t phi_field,
size_t cp_field>
239 using Poly =
typename Algoim::StencilPoly<dim, poly_order>::T_Poly;
241 blitz::TinyVector<double,dim> dx;
242 for(
int d = 0; d < dim; ++d)
248 for(
int i = 0; i < patches.size();i++)
250 for(
int d = 0; d < dim; ++d)
252 p_lo.
set_d(d, patches.get(i).Dbox.getLow(d) + patches.get(i).origin[d]);
253 p_hi.
set_d(d, patches.get(i).Dbox.getHigh(d) + patches.get(i).origin[d]);
261 if(std::abs(gd.template get<phi_field>(key)) < nb_gamma)
264 double sign_fn = (gd.template get<phi_field>(key) >= 0.0)?1.0:-1.0;
268 double distance = 0.0;
269 for(
int d = 0; d < dim; ++d)
272 double patch_pos = (key_g.get(d) - p_lo.
get(d) + algoim_padding) * gd.
spacing(d);
273 double cp_d = gd.template get<cp_field>(key)[d];
274 distance += ((patch_pos - cp_d)*(patch_pos - cp_d));
276 distance = sqrt(distance);
278 gd.template get<phi_field>(key) = sign_fn*distance;
285 #endif //__CLOSEST_POINT_HPP__ static const unsigned int dims
Number of dimensions.
void extendLSField(grid_type &gd, const double nb_gamma)
Extends a (scalar) field to within nb_gamma from interface. The grid should have level set SDF and cl...
grid_key_dx< dim > getGKey(const grid_dist_key_dx< dim > &k) const
Convert a g_dist_key_dx into a global key.
void estimateClosestPoint(grid_type &gd, const double nb_gamma)
Computes the closest point coordinate for each grid point within nb_gamma from interface.
__device__ __host__ index_type get(index_type i) const
Get the i index.
double operator()(const blitz::TinyVector< int, dim > idx) const
Call operator for the wrapper.
St spacing(size_t i) const
Get the spacing of the grid in direction i.
void reinitializeLS(grid_type &gd, const double nb_gamma)
Reinitializes the level set Phi field on a grid. The grid should have level set SDF and closest point...
grid_dist_iterator_sub< dim, device_grid > getSubDomainIterator(const grid_key_dx< dim > &start, const grid_key_dx< dim > &stop) const
It return an iterator that span the grid domain only in the specified part.
This is a distributed grid.
const openfpm::vector< GBoxes< device_grid::dims > > & getLocalGridsInfo()
It return the informations about the local grids.
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)
__device__ __host__ void set_d(index_type i, index_type id)
Set the i index.