OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
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
45template <typename point_type, typename space_type>
46space_type get_analytic_sdf_sphere(const point_type coords, const space_type radius,
47 const space_type center_x=0, const space_type center_y=0, const 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
71template <typename point_type, typename space_type>
72space_type get_analytic_sdf_sphere(const point_type coords, const space_type radius, const space_type center[point_type::dims])
73{
74 size_t x = 0, y = 1, z = 2;
75 typedef typename std::remove_const_t<std::remove_reference_t<decltype(coords.get(0))>> coord_type;
76 if(!(std::is_same<space_type, coord_type>::value))
77 {
78 std::cout << "Radius-, Center- and Space-type of grid must be the same! Aborting..." << std::endl;
79 abort();
80 }
81 const space_type X = coords.get(0), Y = coords.get(1), Z = coords.get(2);
82 return (radius -
83 sqrt((X - center[x]) * (X - center[x])
84 + (Y - center[y]) * (Y - center[y])
85 + (Z - center[z]) * (Z - center[z])));
86}
87
101template <size_t SDF_exact, typename grid_type, typename space_type>
102void init_analytic_sdf_sphere(grid_type & grid, const space_type radius, const space_type center_x=0, const space_type center_y=0,
103 const space_type center_z=0)
104{
105 if(!(std::is_same<typename grid_type::stype, space_type>::value))
106 {
107 std::cout << "Radius-, Center- and Space-type of grid must be the same! Aborting..." << std::endl;
108 abort();
109 }
110
111 auto dom = grid.getDomainIterator();
112 while(dom.isNext())
113 {
114 auto key = dom.get();
116 grid.template getProp<SDF_exact>(key) = get_analytic_sdf_sphere(coords, radius, center_x,
117 center_y, center_z);
118 ++dom;
119 }
120}
121
137template <size_t SDF_exact, typename grid_type, typename space_type>
138void init_analytic_sdf_sphere(grid_type & grid, const space_type radius, const space_type center[grid_type::dims])
139{
140 if(!(std::is_same<typename grid_type::stype, space_type>::value))
141 {
142 std::cout << "Radius-, Center- and Space-type of grid must be the same! Aborting..." << std::endl;
143 abort();
144 }
145
146 auto dom = grid.getDomainIterator();
147 while(dom.isNext())
148 {
149 auto key = dom.get();
151 grid.template getProp<SDF_exact>(key) = get_analytic_sdf_sphere(coords, radius, center);
152 ++dom;
153 }
154}
155
156
157
158
160
161
162
180template <typename point_type, typename space_type>
181space_type get_analytic_sdf_circle(point_type coords, const space_type radius,
182 const space_type center_x=0, const space_type center_y=0)
183{
184 typedef typename std::remove_const_t<std::remove_reference_t<decltype(coords.get(0))>> coord_type;
185 if(!(std::is_same<space_type, coord_type>::value))
186 {
187 std::cout << "Radius-, Center- and Space-type of grid must be the same! Aborting..." << std::endl;
188 abort();
189 }
190 const space_type X = coords.get(0), Y = coords.get(1);
191 return (radius -
192 sqrt((X - center_x) * (X - center_x)
193 + (Y - center_y) * (Y - center_y)));
194}
195
205template <typename point_type, typename space_type>
206space_type get_analytic_sdf_circle(const point_type coords, const space_type radius, const space_type center[point_type::dims])
207{
208 size_t x = 0, y = 1;
209 typedef typename std::remove_const_t<std::remove_reference_t<decltype(coords.get(0))>> coord_type;
210 if(!(std::is_same<space_type, coord_type>::value))
211 {
212 std::cout << "Radius-, Center- and Space-type of grid must be the same! Aborting..." << std::endl;
213 abort();
214 }
215 const space_type X = coords.get(0), Y = coords.get(1);
216 return (radius -
217 sqrt((X - center[x]) * (X - center[x])
218 + (Y - center[y]) * (Y - center[y])));
219}
220
233template <size_t SDF_exact, typename grid_type, typename space_type>
234void init_analytic_sdf_circle(grid_type & grid, const space_type radius, const space_type center_x=0, const space_type center_y=0)
235{
236 if(!(std::is_same<typename grid_type::stype, space_type>::value))
237 {
238 std::cout << "Radius-, Center- and Space-type of grid must be the same! Aborting..." << std::endl;
239 abort();
240 }
241 auto dom = grid.getDomainIterator();
242 while(dom.isNext())
243 {
244 auto key = dom.get();
246 grid.template getProp<SDF_exact>(key) = get_analytic_sdf_circle(coords, radius, center_x,
247 center_y);
248 ++dom;
249 }
250}
251
267template <size_t SDF_exact, typename grid_type, typename space_type>
268void init_analytic_sdf_circle(grid_type & grid, const space_type radius, const space_type center[grid_type::dims])
269{
270 if(!(std::is_same<typename grid_type::stype, space_type>::value))
271 {
272 std::cout << "Radius-, Center- and Space-type of grid must be the same! Aborting..." << std::endl;
273 abort();
274 }
275
276 auto dom = grid.getDomainIterator();
277 while(dom.isNext())
278 {
279 auto key = dom.get();
281 grid.template getProp<SDF_exact>(key) = get_analytic_sdf_circle(coords, radius, center);
282 ++dom;
283 }
284}
285
286#endif //ANALYTICAL_SDF_HPP
287
288
289#endif //OPENFPM_PDATA_ANALYTICALSDF_HPP
space_type get_analytic_sdf_circle(point_type coords, const space_type radius, const space_type center_x=0, const 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, const space_type radius, const space_type center_x=0, const space_type center_y=0)
Initializes the exact solution of the signed distance function of a circle on an OpenFPM grid.
space_type get_analytic_sdf_sphere(const point_type coords, const space_type radius, const space_type center_x=0, const space_type center_y=0, const space_type center_z=0)
Computes the analytical signed distance function of a sphere for a given point in space.
void init_analytic_sdf_sphere(grid_type &grid, const space_type radius, const space_type center_x=0, const space_type center_y=0, const space_type center_z=0)
Initializes the exact solution of the signed distance function of a sphere on an OpenFPM grid.
This class implement the point shape in an N-dimensional space.
Definition Point.hpp:28
This is a distributed grid.
static const unsigned int dims
Number of dimensions.