OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
HelpFunctionsForGrid.hpp
Go to the documentation of this file.
1//
2// Created by jstark on 2020-05-12.
3//
12#ifndef REDISTANCING_SUSSMAN_HELPFUNCTIONSFORGRID_HPP
13#define REDISTANCING_SUSSMAN_HELPFUNCTIONSFORGRID_HPP
14
15#include <iostream>
16#include <limits>
17
18#include "HelpFunctions.hpp"
19#include "VCluster/VCluster.hpp"
20#include "Grid/grid_dist_id.hpp"
21
22
32template <typename grid_type>
34{
35 typename grid_type::stype sum = 0;
36 for (size_t d = 0; d < grid_type::dims; d++)
37 {
38 sum += abs(u[d]) / grid.spacing(d);
39 }
40 return C / sum;
41}
51template <typename grid_type>
53{
54 typename grid_type::stype sum = 0;
55 for (size_t d = 0; d < grid_type::dims; d++)
56 {
57 sum += abs(u) / grid.spacing(d);
58 }
59 return C / sum;
60}
61
71template <size_t Prop, typename grid_type, typename T>
72void init_grid_and_ghost(grid_type & grid, T init_value)
73{
74 auto dom_ghost = grid.getDomainGhostIterator();
75 while(dom_ghost.isNext())
76 {
77 auto key = dom_ghost.get();
78 grid.template get<Prop>(key) = init_value;
79 ++dom_ghost;
80 }
81}
82
94template <size_t attr_sc, size_t attr_ds, typename grid_source_type, typename grid_dest_type>
95void copy_gridTogrid(const grid_source_type & grid_sc, grid_dest_type & grid_ds, bool include_ghost=false)
96{
97 assert(grid_source_type::dims == grid_dest_type::dims);
98 assert(grid_sc.size() == grid_ds.size());
99 if (include_ghost)
100 {
101 auto dom_sc = grid_sc.getDomainGhostIterator();
102 auto dom_ds = grid_ds.getDomainGhostIterator();
103 while (dom_sc.isNext())
104 {
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);
108 ++dom_sc;
109 ++dom_ds;
110 }
111 }
112 else
113 {
114 auto dom_sc = grid_sc.getDomainIterator();
115 auto dom_ds = grid_ds.getDomainIterator();
116 while (dom_sc.isNext())
117 {
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);
121 ++dom_sc;
122 ++dom_ds;
123 }
124 }
125}
126
134template <typename grid_type>
136{
137 typename grid_type::stype h_max = 0;
138 for (size_t d = 0; d < grid_type::dims; d++)
139 {
140 if (grid.spacing(d) > h_max) h_max = grid.spacing(d);
141 }
142 return h_max;
143}
144
152template <typename grid_type>
154{
155 typename grid_type::stype spacing [grid_type::dims];
156 for (size_t d = 0; d < grid_type::dims; d++)
157 {
158 spacing[d] = grid.spacing(d);
159 }
160 std::sort(std::begin(spacing), std::end(spacing));
161 return spacing[0];
162}
163
174template <size_t Prop1, size_t Prop2, typename grid_type>
176{
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;
180 while (dom.isNext())
181 {
182 auto key = dom.get();
183 total_diff += abs( grid.template get<Prop1>(key) - grid.template get<Prop2>(key) );
184 ++dom;
185 }
186 return total_diff / grid.size();
187}
188
196template <size_t Prop, typename grid_type>
198{
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();
202 while(dom.isNext())
203 {
204 auto key = dom.get();
205 if (grid.template get<Prop>(key) > max_value) max_value = grid.template get<Prop>(key);
206 ++dom;
207 }
208 auto & v_cl = create_vcluster();
209 v_cl.max(max_value);
210 v_cl.execute();
211 return max_value;
212}
213
221template <size_t Prop, typename grid_type>
223{
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();
227 while(dom.isNext())
228 {
229 auto key = dom.get();
230 if (grid.template get<Prop>(key) < min_value) min_value = grid.template get<Prop>(key);
231 ++dom;
232 }
233 auto & v_cl = create_vcluster();
234 v_cl.min(min_value);
235 v_cl.execute();
236 return min_value;
237}
238
246template <size_t Prop_in, size_t Prop_out, typename grid_type>
248{
249 auto dom = grid.getDomainIterator();
250 while(dom.isNext())
251 {
252 auto key = dom.get();
253 grid.template get<Prop_out>(key) = sgn(grid.template get<Prop_in>(key));
254 ++dom;
255 }
256}
257
258
266template <size_t Vector_in, size_t Magnitude_out, typename magnitude_type, typename gridtype>
268{
269 grid.template ghost_get<Vector_in>();
270 auto dom = grid.getDomainGhostIterator();
271 while(dom.isNext())
272 {
273 magnitude_type sum = 0;
274 auto key = dom.get();
275 for(size_t d = 0; d < gridtype::dims; d++)
276 {
277 sum += grid.template get<Vector_in> (key)[d] * grid.template get<Vector_in> (key)[d];
278 }
279 grid.template get<Magnitude_out> (key) = sqrt(sum);
280 ++dom;
281 }
282}
283
290template <size_t Vector_in, typename key_type, typename gridtype>
291auto get_vector_magnitude(gridtype & grid, key_type & key)
292{
293 typedef typename std::remove_const_t<std::remove_reference_t<decltype(grid.template get<Vector_in>(key)[0])>>
294 prop_type;
295 prop_type sum = 0;
296 for(size_t d = 0; d < gridtype::dims; d++)
297 {
298 sum += grid.template get<Vector_in> (key)[d] * grid.template get<Vector_in> (key)[d];
299 }
300 return sqrt(sum);
301}
302
303
304#endif //REDISTANCING_SUSSMAN_HELPFUNCTIONSFORGRID_HPP
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.
St stype
Type of space.
static const unsigned int dims
Number of dimensions.
It model an expression expr1 + ... exprn.
Definition sum.hpp:93