5#ifndef SPARSEGRID_DIFFUSIONSPACE_SPARSEGRID_HPP
6#define SPARSEGRID_DIFFUSIONSPACE_SPARSEGRID_HPP
11static bool is_diffusionSpace(
const T & phi_sdf,
const T & lower_bound,
const T & upper_bound)
13 const T EPSILON = std::numeric_limits<T>::epsilon();
14 const T _b_low = lower_bound + EPSILON;
15 const T _b_up = upper_bound - EPSILON;
16 return (phi_sdf > _b_low && phi_sdf < _b_up);
19template <
size_t PHI_SDF_ECS_FULL,
size_t PHI_SDF_ECS_SPARSE,
typename gr
id_type,
typename sparse_in_type,
typename T>
21 sparse_in_type & sparse_grid,
25 auto dom =
grid.getDomainIterator();
29 if(is_diffusionSpace(
grid.template get<PHI_SDF_ECS_FULL>(key), b_low, b_up))
31 sparse_grid.template insertFlush<PHI_SDF_ECS_SPARSE>(key) =
grid.template get<PHI_SDF_ECS_FULL>(key);
40template <
size_t PHI_SDF_ECS_FULL,
size_t PHI_SDF_ECS_SPARSE,
typename gr
id_type,
typename gr
id_type_upscale,
typename sparse_in_type,
typename T>
41void get_diffusion_domain_sparse_grid_upscale(
grid_type &
grid,
42 grid_type_upscale & grid_upscale,
43 sparse_in_type & sparse_grid,
44 const int upscale_factor,
48 auto dom =
grid.getDomainIterator();
49 auto dom_upscale = grid_upscale.getDomainIterator();
53 auto key_upscale = dom_upscale.get();
55 for(
int i = 0, i < upscale_factor, ++i)
57 if(is_diffusionSpace(
grid.template get<PHI_SDF_ECS_FULL>(key), b_low, b_up))
59 sparse_grid.template insertFlush<PHI_SDF_ECS_SPARSE>(key_upscale) =
grid.template get<PHI_SDF_ECS_FULL>(key);
72size_t PHI_SDF_ECS_FULL,
73size_t PHI_SDF_SHELL_FULL,
74size_t PHI_SDF_ECS_SPARSE,
75size_t PHI_SDF_SHELL_SPARSE,
77typename sparse_in_type,
79void get_diffusion_domain_sparse_grid_with_shell(
grid_type & grid_ecs,
81 sparse_in_type & sparse_grid,
89 if(is_diffusionSpace(grid_ecs.template get<PHI_SDF_ECS_FULL>(key), b_low, b_up))
91 sparse_grid.template insertFlush<PHI_SDF_ECS_SPARSE>(key) = grid_ecs.template get<PHI_SDF_ECS_FULL>(key);
92 sparse_grid.template insertFlush<PHI_SDF_SHELL_SPARSE>(key) = grid_shell.template get<PHI_SDF_SHELL_FULL>(key);
101 auto dom = g_sparse.getDomainIterator();
104 auto key = dom.get();
105 if (g_sparse.template getProp<PHI_SDF>(key) < 4 * g_sparse.spacing(x))
107 g_sparse.template getProp<CONC_N>(key) =
108 (1 - 0.25 * g_sparse.template getProp<PHI_SDF>(key)) / g_sparse.spacing(x);
112 if(v_cl.rank() == 0) std::cout <<
"Initialized grid with smoothed c0 at the boundary." << std::endl;
113 g_sparse.write(path_output +
"g_init", FORMAT_BINARY);
119template <
typename po
int_type,
typename y_margin_type>
120auto distance_from_margin(point_type & coord, y_margin_type y_margin)
122 return(coord.get(1) - y_margin);
125template <
typename po
int_type,
typename y_margin_type,
typename w
idth_type>
126bool is_source(point_type & coord, y_margin_type y_margin, width_type width_source)
128 return (coord.get(1) >= y_margin
129 && distance_from_margin(coord, y_margin) <= width_source);
133static bool is_inner_surface(
const T & phi_sdf,
const T & lower_bound)
135 const T EPSILON = std::numeric_limits<T>::epsilon();
136 const T _b_low = lower_bound + EPSILON;
137 return (phi_sdf > _b_low);
140template <
size_t PHI_SDF,
size_t K_SOURCE,
size_t K_SINK,
typename gr
id_type,
typename y_margin_type,
typename w
idth_type,
typename k_type>
142 width_type width_source,
143 y_margin_type y_margin,
146 int no_membrane_points=4)
153 auto dom =
grid.getDomainIterator();
156 auto key = dom.get();
159 if(
grid.template get<PHI_SDF>(key) < no_membrane_points *
grid.spacing(0))
161 if(is_source(coord, y_margin, width_source))
163 grid.template insertFlush<K_SOURCE>(key) = k_source;
167 grid.template insertFlush<K_SOURCE>(key) = 0.0;
169 grid.template insertFlush<K_SINK>(key) = k_sink;
175 grid.template insertFlush<K_SOURCE>(key) = 0.0;
176 grid.template insertFlush<K_SINK>(key) = 0.0;
183size_t PHI_SDF_ECS_SPARSE,
184size_t PHI_SDF_SHELL_SPARSE,
188typename y_margin_type,
191typename boundary_type>
193 width_type width_source,
194 y_margin_type y_margin,
197 boundary_type b_low_shell,
198 int no_membrane_points=4)
205 auto dom =
grid.getDomainIterator();
208 auto key = dom.get();
212 grid.template get<PHI_SDF_ECS_SPARSE>(key) < no_membrane_points *
grid.spacing(0)
213 && is_inner_surface(
grid.template get<PHI_SDF_SHELL_SPARSE>(key), b_low_shell)
216 if(is_source(coord, y_margin, width_source))
218 grid.template insertFlush<K_SOURCE>(key) = k_source;
222 grid.template insertFlush<K_SOURCE>(key) = 0.0;
224 grid.template insertFlush<K_SINK>(key) = k_sink;
230 grid.template insertFlush<K_SOURCE>(key) = 0.0;
231 grid.template insertFlush<K_SINK>(key) = 0.0;
238template <
size_t PHI_SDF,
size_t K_SOURCE,
size_t K_SINK,
typename gr
id_type,
typename coord_type,
typename k_type>
245 coord_type no_membrane_points=4,
246 coord_type smoothing=0.25)
256 auto dom =
grid.getDomainIterator();
259 auto key = dom.get();
262 k_type sdf_based_smoothing = 1.0;
263 if(
grid.template get<PHI_SDF>(key) < no_membrane_points *
grid.spacing(0))
267 if (coord[y] > y_start
268 && coord[y] < y_peak + std::numeric_limits<coord_type>::epsilon())
270 grid.template insertFlush<K_SOURCE>(key) = k_source * (coord[y] - y_start) * sdf_based_smoothing;
274 else if (coord[y] >= y_peak - std::numeric_limits<coord_type>::epsilon()
275 && coord[y] < y_stop - std::numeric_limits<coord_type>::epsilon())
277 grid.template insertFlush<K_SOURCE>(key) = k_source * (y_stop - coord[y]) * sdf_based_smoothing;
280 else grid.template insertFlush<K_SOURCE>(key) = 0.0;
281 grid.template insertFlush<K_SINK>(key) = k_sink;
286 grid.template insertFlush<K_SOURCE>(key) = 0.0;
287 grid.template insertFlush<K_SINK>(key) = 0.0;
This class implement the point shape in an N-dimensional space.
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)