5#ifndef BOUNDARY_CONDITION_SURFACENORMAL_HPP
6#define BOUNDARY_CONDITION_SURFACENORMAL_HPP
10#include "Vector/vector_dist_subset.hpp"
12template <
size_t Phi_SDF,
size_t Phi_Gradient,
size_t Normal,
typename vd_type>
13void get_surface_normal_sdf(vd_type & vd,
bool unit_vector=
false)
15 auto dom = vd.getDomainIterator();
22 for(
size_t d = 0; d < vd_type::dims; d++)
24 sum += vd.template getProp<Phi_Gradient>(key)[d] * vd.template getProp<Phi_Gradient>(key)[d];
27 double gradient_magnitude = sqrt(
sum);
28 for(
size_t d = 0; d < vd_type::dims; d++)
32 vd.template getProp<Normal>(key)[d] = - vd.template getProp<Phi_Gradient>(key)[d] / gradient_magnitude;
36 vd.template getProp<Normal>(key)[d] =
37 - vd.template getProp<Phi_Gradient>(key)[d] / gradient_magnitude
38 * vd.template getProp<Phi_SDF>(key);
45template <
size_t Phi_SDF,
size_t Phi_Gradient,
size_t Normal,
typename vd_type>
49 for (
int i = 0; i < keys_subset.
size(); i++)
51 auto key = keys_subset.get(i);
55 for(
size_t d = 0; d < vd_type::dims; d++)
57 sum += vd.template getProp<Phi_Gradient>(key)[d] * vd.template getProp<Phi_Gradient>(key)[d];
60 double gradient_magnitude = sqrt(
sum);
61 for(
size_t d = 0; d < vd_type::dims; d++)
63 vd.template getProp<Normal>(key)[d] = - vd.template getProp<Phi_Gradient>(key)[d] / gradient_magnitude;
67 vd.template getProp<Normal>(key) = vd.template getProp<Normal>(key) * vd.template getProp<Phi_SDF>
74template <
typename key_g_type,
int dim>
75bool is_corner(key_g_type key_g)
77 bool nodetype =
false;
81 nodetype = (key_g.get(0) < 1 || key_g.get(0) >
grid.size(0) - 1);
91template <
typename key_g_type,
int dim>
92bool is_edge(key_g_type key_g)
97template <
typename key_g_type,
int dim>
98bool is_bulk(key_g_type key_g,
int border_width_in_nodes)
100 for (
int d=0; d<dim; d++)
102 if (key_g.get(d) < border_width_in_nodes || key_g.get(d) >
grid.size(d) - border_width_in_nodes)
108template <
typename key_g_type,
int dim>
109bool is_boundary(key_g_type key_g,
int border_width_in_nodes)
111 for (
int d=0; d<dim; d++)
113 if (key_g.get(d) > border_width_in_nodes || key_g.get(d) <
grid.size(d) - border_width_in_nodes)
121template <
size_t Normal,
size_t SDF,
typename gr
id_type>
122void get_surface_normal_box(
grid_type &
grid,
bool unit_vector=
false)
124 auto dom =
grid.getDomainIterator();
127 auto key = dom.get();
128 auto key_g =
grid.getGKey(key);
145 if (key_g.get(d) > 0 && key_g.get(d) <
grid.size(d) - 1)
147 grid.template get<Phi_grad> (key) [d] = upwind_FD<Phi, Phi_0_sign>(
grid, key, d);
150 else if (key_g.get(d) == 0)
152 grid.template get<Phi_grad> (key) [d] = forward_FD<Phi>(
grid, key, d);
155 else if (key_g.get(d) >=
grid.size(d) - 1)
157 grid.template get<Phi_grad> (key) [d] = backward_FD<Phi>(
grid, key, d);
This is a distributed grid.
Implementation of 1-D std::vector like structure.
It model an expression expr1 + ... exprn.