12 #ifndef REDISTANCING_SUSSMAN_HELPFUNCTIONSFORGRID_HPP 13 #define REDISTANCING_SUSSMAN_HELPFUNCTIONSFORGRID_HPP 19 #include "VCluster/VCluster.hpp" 20 #include "Grid/grid_dist_id.hpp" 28 template <
typename gr
id_type>
49 template <
typename gr
id_type>
68 template <
typename gr
id_type>
88 template <
size_t Prop,
typename gr
id_type,
typename T>
91 auto dom_ghost =
grid.getDomainGhostIterator();
92 while(dom_ghost.isNext())
94 auto key = dom_ghost.get();
111 template <
size_t attr_sc,
size_t attr_ds,
typename gr
id_source_type,
typename gr
id_dest_type>
112 void copy_gridTogrid(
const grid_source_type & grid_sc, grid_dest_type & grid_ds,
bool include_ghost=
false)
114 assert(grid_source_type::dims == grid_dest_type::dims);
115 assert(grid_sc.size() == grid_ds.size());
118 auto dom_sc = grid_sc.getDomainGhostIterator();
119 auto dom_ds = grid_ds.getDomainGhostIterator();
120 while (dom_sc.isNext())
122 auto key_sc = dom_sc.get();
123 auto key_ds = dom_ds.get();
124 grid_ds.template get<attr_ds>(key_ds) = grid_sc.template get<attr_sc>(key_sc);
131 auto dom_sc = grid_sc.getDomainIterator();
132 auto dom_ds = grid_ds.getDomainIterator();
133 while (dom_sc.isNext())
135 auto key_sc = dom_sc.get();
136 auto key_ds = dom_ds.get();
137 grid_ds.template get<attr_ds>(key_ds) = grid_sc.template get<attr_sc>(key_sc);
151 template <
typename gr
id_type>
157 if (
grid.spacing(d) > h_max) h_max =
grid.spacing(d);
169 template <
typename gr
id_type>
175 spacing[d] =
grid.spacing(d);
177 std::sort(std::begin(spacing), std::end(spacing));
191 template <
size_t Prop1,
size_t Prop2,
typename gr
id_type>
194 auto dom =
grid.getDomainIterator();
195 typedef typename std::decay_t<decltype(
grid.template get<Prop1>(dom.get()))> prop_type;
196 prop_type total_diff = 0;
199 auto key = dom.get();
200 total_diff += abs(
grid.template get<Prop1>(key) -
grid.template get<Prop2>(key) );
203 return total_diff /
grid.size();
213 template <
size_t Prop,
typename gr
id_type>
216 auto dom =
grid.getDomainIterator();
217 typedef typename std::decay_t<decltype(
grid.template get<Prop>(dom.get()))> prop_type;
218 prop_type max_value = std::numeric_limits<prop_type>::lowest();
221 auto key = dom.get();
222 if (
grid.template get<Prop>(key) > max_value) max_value =
grid.template get<Prop>(key);
225 auto & v_cl = create_vcluster();
238 template <
size_t Prop,
typename gr
id_type>
241 auto dom =
grid.getDomainIterator();
242 typedef typename std::decay_t<decltype(
grid.template get<Prop>(dom.get()))> prop_type;
243 prop_type min_value = std::numeric_limits<prop_type>::max();
246 auto key = dom.get();
247 if (
grid.template get<Prop>(key) < min_value) min_value =
grid.template get<Prop>(key);
250 auto & v_cl = create_vcluster();
263 template <
size_t Prop_in,
size_t Prop_out,
typename gr
id_type>
266 auto dom =
grid.getDomainIterator();
269 auto key = dom.get();
270 grid.template get<Prop_out>(key) =
sgn(
grid.template get<Prop_in>(key));
283 template <
size_t Vector_in,
size_t Magnitude_out,
typename magnitude_type,
typename gr
idtype>
286 grid.template ghost_get<Vector_in>();
287 auto dom =
grid.getDomainGhostIterator();
290 magnitude_type
sum = 0;
291 auto key = dom.get();
292 for(
size_t d = 0; d < gridtype::dims; d++)
294 sum +=
grid.template get<Vector_in> (key)[d] *
grid.template get<Vector_in> (key)[d];
296 grid.template get<Magnitude_out> (key) = sqrt(
sum);
307 template <
size_t Vector_in,
typename key_type,
typename gr
idtype>
310 typedef typename std::remove_const_t<std::remove_reference_t<decltype(
grid.template get<Vector_in>(key)[0])>>
313 for(
size_t d = 0; d < gridtype::dims; d++)
315 sum +=
grid.template get<Vector_in> (key)[d] *
grid.template get<Vector_in> (key)[d];
321 #endif //REDISTANCING_SUSSMAN_HELPFUNCTIONSFORGRID_HPP static const unsigned int dims
Number of dimensions.
auto get_max_val(grid_type &grid)
Determines the maximum value stored on a given grid at a given property.
void init_grid_and_ghost(grid_type &grid, T init_value)
Initializes given property Prop of an OpenFPM grid including ghost layer with a given value from init...
auto get_min_val(grid_type &grid)
Determines the minimum value stored on a given grid at a given property.
grid_type::stype get_smallest_spacing(grid_type &grid)
Determines the smallest spacing of a grid which is potentially anisotropic when comparing x,...
int sgn(T val)
Gets the sign of a variable.
auto average_difference(grid_type &grid)
Computes the average difference between the values stored at two different properties of the same gri...
This is a distributed grid.
void get_vector_magnitude(gridtype &grid)
Computes the magnitude of the gradient (L2-norm of gradient vector).
void copy_gridTogrid(const grid_source_type &grid_sc, grid_dest_type &grid_ds, bool include_ghost=false)
Copies the value stored in a given property from a given source grid to a given destination grid.
grid_type::stype get_biggest_spacing(grid_type &grid)
Determines the biggest spacing of a grid which is potentially anisotropic when comparing x,...
OutputIteratorT ScanTileStateT int ScanOpT InitValueT init_value
Initial value to seed the exclusive scan.
void init_sign_prop(grid_type &grid)
Determines the sign of a value stored at a given property and stores it in another property.
It model an expression expr1 + ... exprn.
grid_type::stype get_time_step_CFL(grid_type &grid)
Computes the time step for the iterative re-distancing fulfilling CFL condition.
Header file containing small mathematical help-functions that are needed e.g. for the Sussman redista...