OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
DrawSphere.hpp
1//
2// Created by jstark on 2020-05-17.
3//
12#ifndef ACCURACY_TESTS_SPHERE_HPP
13#define ACCURACY_TESTS_SPHERE_HPP
14
15#include <iostream>
16
17
29template <typename point_type, typename radius_type>
30bool inside_sphere(point_type coords, radius_type radius, double center_x=0, double center_y=0, double center_z=0)
31{
32 typedef typename std::remove_const_t<std::remove_reference_t<decltype(coords.get(0))>> space_type;
33 if(!(std::is_same<space_type, radius_type>::value))
34 {
35 std::cout << "Radius type and space type of grid must be the same! Aborting..." << std::endl;
36 abort();
37 }
38 const space_type EPSILON = std::numeric_limits<space_type>::epsilon();
39 const space_type X = coords.get(0), Y = coords.get(1), Z = coords.get(2);
40 return (X - center_x) * (X - center_x)
41 + (Y - center_y) * (Y - center_y)
42 + (Z - center_z) * (Z - center_z)
43 <= radius * radius + EPSILON;
44}
45
63template <size_t Phi_0, typename grid_type, typename radius_type>
64void init_grid_with_sphere(grid_type & grid, radius_type radius, double center_x=0, double center_y=0, double center_z=0)
65{
66 if(!(std::is_same<typename grid_type::stype, radius_type>::value))
67 {
68 std::cout << "Radius type and space type of grid must be the same! Aborting..." << std::endl;
69 abort();
70 }
71 // assign pixel values to domain. For each pixel get factor_refinement number of grid points with corresponding value
72 auto dom = grid.getDomainIterator();
73 while(dom.isNext())
74 {
75 auto key = dom.get();
76
78
79 if (inside_sphere(coords, radius, center_x, center_y, center_z))
80 {
81 grid.template get<Phi_0> (key) = 1;
82 }
83 else
84 {
85 grid.template get<Phi_0> (key) = -1;
86 }
87 ++dom;
88 }
89}
90
91
92#endif //ACCURACY_TESTS_SPHERE_HPP
This class implement the point shape in an N-dimensional space.
Definition Point.hpp:28
This is a distributed grid.