12#ifndef REDISTANCING_SUSSMAN_HELPFUNCTIONSFORGRID_HPP
13#define REDISTANCING_SUSSMAN_HELPFUNCTIONSFORGRID_HPP
19#include "VCluster/VCluster.hpp"
20#include "Grid/grid_dist_id.hpp"
32template <
typename gr
id_type>
38 sum += abs(u[d]) /
grid.spacing(d);
51template <
typename gr
id_type>
57 sum += abs(u) /
grid.spacing(d);
71template <
size_t Prop,
typename gr
id_type,
typename T>
74 auto dom_ghost =
grid.getDomainGhostIterator();
75 while(dom_ghost.isNext())
77 auto key = dom_ghost.get();
78 grid.template get<Prop>(key) = init_value;
94template <
size_t attr_sc,
size_t attr_ds,
typename gr
id_source_type,
typename gr
id_dest_type>
95void copy_gridTogrid(
const grid_source_type & grid_sc, grid_dest_type & grid_ds,
bool include_ghost=
false)
97 assert(grid_source_type::dims == grid_dest_type::dims);
98 assert(grid_sc.size() == grid_ds.size());
101 auto dom_sc = grid_sc.getDomainGhostIterator();
102 auto dom_ds = grid_ds.getDomainGhostIterator();
103 while (dom_sc.isNext())
105 auto key_sc = dom_sc.get();
106 auto key_ds = dom_ds.get();
107 grid_ds.template get<attr_ds>(key_ds) = grid_sc.template get<attr_sc>(key_sc);
114 auto dom_sc = grid_sc.getDomainIterator();
115 auto dom_ds = grid_ds.getDomainIterator();
116 while (dom_sc.isNext())
118 auto key_sc = dom_sc.get();
119 auto key_ds = dom_ds.get();
120 grid_ds.template get<attr_ds>(key_ds) = grid_sc.template get<attr_sc>(key_sc);
134template <
typename gr
id_type>
140 if (
grid.spacing(d) > h_max) h_max =
grid.spacing(d);
152template <
typename gr
id_type>
158 spacing[d] =
grid.spacing(d);
160 std::sort(std::begin(spacing), std::end(spacing));
174template <
size_t Prop1,
size_t Prop2,
typename gr
id_type>
177 auto dom =
grid.getDomainIterator();
178 typedef typename std::decay_t<
decltype(
grid.template get<Prop1>(dom.get()))> prop_type;
179 prop_type total_diff = 0;
182 auto key = dom.get();
183 total_diff += abs(
grid.template get<Prop1>(key) -
grid.template get<Prop2>(key) );
186 return total_diff /
grid.size();
196template <
size_t Prop,
typename gr
id_type>
199 auto dom =
grid.getDomainIterator();
200 typedef typename std::decay_t<
decltype(
grid.template get<Prop>(dom.get()))> prop_type;
201 prop_type max_value = std::numeric_limits<prop_type>::lowest();
204 auto key = dom.get();
205 if (
grid.template get<Prop>(key) > max_value) max_value =
grid.template get<Prop>(key);
208 auto & v_cl = create_vcluster();
221template <
size_t Prop,
typename gr
id_type>
224 auto dom =
grid.getDomainIterator();
225 typedef typename std::decay_t<
decltype(
grid.template get<Prop>(dom.get()))> prop_type;
226 prop_type min_value = std::numeric_limits<prop_type>::max();
229 auto key = dom.get();
230 if (
grid.template get<Prop>(key) < min_value) min_value =
grid.template get<Prop>(key);
233 auto & v_cl = create_vcluster();
246template <
size_t Prop_in,
size_t Prop_out,
typename gr
id_type>
249 auto dom =
grid.getDomainIterator();
252 auto key = dom.get();
253 grid.template get<Prop_out>(key) =
sgn(
grid.template get<Prop_in>(key));
266template <
size_t Vector_in,
size_t Magnitude_out,
typename magnitude_type,
typename gr
idtype>
269 grid.template ghost_get<Vector_in>();
270 auto dom =
grid.getDomainGhostIterator();
273 magnitude_type
sum = 0;
274 auto key = dom.get();
275 for(
size_t d = 0; d < gridtype::dims; d++)
277 sum +=
grid.template get<Vector_in> (key)[d] *
grid.template get<Vector_in> (key)[d];
279 grid.template get<Magnitude_out> (key) = sqrt(
sum);
290template <
size_t Vector_in,
typename key_type,
typename gr
idtype>
293 typedef typename std::remove_const_t<std::remove_reference_t<
decltype(
grid.template get<Vector_in>(key)[0])>>
296 for(
size_t d = 0; d < gridtype::dims; d++)
298 sum +=
grid.template get<Vector_in> (key)[d] *
grid.template get<Vector_in> (key)[d];
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_time_step_CFL(grid_type &grid, typename grid_type::stype u[grid_type::dims], typename grid_type::stype C)
Computes the time step size fulfilling CFL condition according to https://www.cfd-online ....
void get_vector_magnitude(gridtype &grid)
Computes the magnitude of the gradient (L2-norm of gradient vector).
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_max_val(grid_type &grid)
Determines the maximum value stored on a given grid at a given property.
void init_sign_prop(grid_type &grid)
Determines the sign of a value stored at a given property and stores it in another property.
auto average_difference(grid_type &grid)
Computes the average difference between the values stored at two different properties of the same gri...
grid_type::stype get_smallest_spacing(grid_type &grid)
Determines the smallest spacing of a grid which is potentially anisotropic when comparing x,...
grid_type::stype get_biggest_spacing(grid_type &grid)
Determines the biggest spacing of a grid which is potentially anisotropic when comparing x,...
auto get_min_val(grid_type &grid)
Determines the minimum value stored on a given grid at a given property.
Header file containing small mathematical help-functions that are needed e.g. for the Sussman redista...
int sgn(T val)
Gets the sign of a variable.
This is a distributed grid.
static const unsigned int dims
Number of dimensions.
It model an expression expr1 + ... exprn.