OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
AnalyticalSDF.hpp
Go to the documentation of this file.
1 //
2 // Created by jstark on 27.05.21.
3 //
4 
5 #ifndef OPENFPM_PDATA_ANALYTICALSDF_HPP
6 #define OPENFPM_PDATA_ANALYTICALSDF_HPP
7 
8 //
9 // Created by jstark on 2020-10-05.
10 //
20 #ifndef ANALYTICAL_SDF_HPP
21 #define ANALYTICAL_SDF_HPP
22 
23 #include <iostream>
24 #include "Vector/vector_dist.hpp"
25 #include "Grid/grid_dist_id.hpp"
26 
45 template <typename point_type, typename space_type>
46 space_type get_analytic_sdf_sphere(point_type coords, space_type radius,
47  space_type center_x=0, space_type center_y=0, space_type center_z=0)
48 {
49  typedef typename std::remove_const_t<std::remove_reference_t<decltype(coords.get(0))>> coord_type;
50  if(!(std::is_same<space_type, coord_type>::value))
51  {
52  std::cout << "Radius-, Center- and Space-type of grid must be the same! Aborting..." << std::endl;
53  abort();
54  }
55  const space_type X = coords.get(0), Y = coords.get(1), Z = coords.get(2);
56  return (radius -
57  sqrt((X - center_x) * (X - center_x)
58  + (Y - center_y) * (Y - center_y)
59  + (Z - center_z) * (Z - center_z)));
60 }
61 
76 template <size_t SDF_exact, typename grid_type, typename space_type>
77 void init_analytic_sdf_sphere(grid_type & grid, space_type radius, space_type center_x=0, space_type center_y=0,
78  space_type center_z=0)
79 {
80  if(!(std::is_same<typename grid_type::stype, space_type>::value))
81  {
82  std::cout << "Radius-, Center- and Space-type of grid must be the same! Aborting..." << std::endl;
83  abort();
84  }
85 
86  auto dom = grid.getDomainIterator();
87  while(dom.isNext())
88  {
89  auto key = dom.get();
91  grid.template getProp<SDF_exact>(key) = get_analytic_sdf_sphere(coords, radius, center_x,
92  center_y, center_z);
93  ++dom;
94  }
95 }
96 
115 template <typename point_type, typename space_type>
116 space_type get_analytic_sdf_circle(point_type coords, space_type radius,
117  space_type center_x=0, space_type center_y=0)
118 {
119  typedef typename std::remove_const_t<std::remove_reference_t<decltype(coords.get(0))>> coord_type;
120  if(!(std::is_same<space_type, coord_type>::value))
121  {
122  std::cout << "Radius-, Center- and Space-type of grid must be the same! Aborting..." << std::endl;
123  abort();
124  }
125  const space_type X = coords.get(0), Y = coords.get(1);
126  return (radius -
127  sqrt((X - center_x) * (X - center_x)
128  + (Y - center_y) * (Y - center_y)));
129 }
130 
143 template <size_t SDF_exact, typename grid_type, typename space_type>
144 void init_analytic_sdf_circle(grid_type & grid, space_type radius, space_type center_x=0, space_type center_y=0)
145 {
146  if(!(std::is_same<typename grid_type::stype, space_type>::value))
147  {
148  std::cout << "Radius-, Center- and Space-type of grid must be the same! Aborting..." << std::endl;
149  abort();
150  }
151  auto dom = grid.getDomainIterator();
152  while(dom.isNext())
153  {
154  auto key = dom.get();
156  grid.template getProp<SDF_exact>(key) = get_analytic_sdf_circle(coords, radius, center_x,
157  center_y);
158  ++dom;
159  }
160 }
161 
162 #endif //ANALYTICAL_SDF_HPP
163 
164 
165 #endif //OPENFPM_PDATA_ANALYTICALSDF_HPP
space_type get_analytic_sdf_sphere(point_type coords, space_type radius, space_type center_x=0, space_type center_y=0, space_type center_z=0)
Computes the analytical signed distance function of a sphere for a given point in space.
space_type get_analytic_sdf_circle(point_type coords, space_type radius, space_type center_x=0, space_type center_y=0)
Computes the analytical signed distance function of a circle for a given point in space.
void init_analytic_sdf_circle(grid_type &grid, space_type radius, space_type center_x=0, space_type center_y=0)
Initializes the exact solution of the signed distance function of a circle on an OpenFPM grid.
This class implement the point shape in an N-dimensional space.
Definition: Point.hpp:27
void init_analytic_sdf_sphere(grid_type &grid, space_type radius, space_type center_x=0, space_type center_y=0, space_type center_z=0)
Initializes the exact solution of the signed distance function of a sphere on an OpenFPM grid.
This is a distributed grid.