1 | /* |
2 | * DrawParticles.hpp |
3 | * |
4 | * Created on: Jan 5, 2017 |
5 | * Author: i-bird |
6 | */ |
7 | |
8 | #ifndef OPENFPM_NUMERICS_SRC_DRAW_DRAWPARTICLES_HPP_ |
9 | #define OPENFPM_NUMERICS_SRC_DRAW_DRAWPARTICLES_HPP_ |
10 | |
11 | #include "PointIterator.hpp" |
12 | #include "PointIteratorSkin.hpp" |
13 | #include "Vector/vector_dist.hpp" |
14 | |
15 | /*! \brief A class to draw/create particles based on simple shaped |
16 | * |
17 | * ## Draw box example |
18 | * |
19 | * \snippet Draw/DrawParticles_unit_tests.hpp DrawBox_example |
20 | * |
21 | */ |
22 | class DrawParticles |
23 | { |
24 | public: |
25 | |
26 | /*! \brief Draw particles in a box B excluding the area of a second box A (B - A) |
27 | * |
28 | * The function return an iterator over particles defined on a virtual grid in the simulation domain. |
29 | * |
30 | * \param vd particles where we are creating the particles |
31 | * \param sz indicate the grid size of the virtual grid. |
32 | * \param domain Domain where the virtual grid is defined (Must match the domain of vd) |
33 | * \param sub_B box contained in domain that define where the particle iterator must iterate, |
34 | * particles are placed strictly inside this box |
35 | * \param sub_A box contained in the domain that define where the particle iterator should not |
36 | * iterate (excluding area) |
37 | * |
38 | * \note Suppose to have a simulation domain of 1.5 on x and we use sz = 16. Consider now |
39 | * to have particles with spacing 0.1 on x. if we define a sub_A that on extend from 0.65 |
40 | * to 0.95 the first fluid particle |
41 | * is at 0.70 and the last is at 0.90 |
42 | * |
43 | * \return an iterator to the selected particles |
44 | * |
45 | */ |
46 | template<unsigned int dim, typename T, typename vd_type> |
47 | static PointIteratorSkin<dim,T,typename vd_type::Decomposition_type> |
48 | DrawSkin(vd_type & vd, |
49 | size_t (& sz)[dim], |
50 | Box<dim,T> & domain, |
51 | Box<dim,T> & sub_A, |
52 | Box<dim,T> & sub_B) |
53 | { |
54 | size_t bc[dim]; |
55 | |
56 | for (size_t i = 0 ; i < dim ; i++) |
57 | bc[i] = NON_PERIODIC; |
58 | |
59 | return PointIteratorSkin<dim,T,typename vd_type::Decomposition_type>(vd.getDecomposition(),sz,vd.getDecomposition().getDomain(),sub_A, sub_B, bc); |
60 | } |
61 | |
62 | |
63 | /*! \brief Draw particles in a box B excluding the areas of an array of boxes A_n |
64 | * |
65 | * The function return an iterator over particles defined on a virtual grid in the simulation domain. |
66 | * |
67 | * \param vd particles where we are creating the particles |
68 | * \param sz indicate the grid size of the virtual grid. |
69 | * \param domain Domain where the virtual grid is defined (Must match the domain of vd) |
70 | * \param sub_B box contained in domain that define where the particle iterator must iterate, |
71 | * particles are placed strictly inside this box |
72 | * \param sub_A array of boxes contained in the domain that define where the particle iterator should not |
73 | * iterate (excluding areas) |
74 | * |
75 | * \note Suppose to have a simulation domain of 1.5 on x and we use sz = 16. Consider now |
76 | * to have particles with spacing 0.1 on x. if we define a sub_A that on extend from 0.65 |
77 | * to 0.95 the first fluid particle |
78 | * is at 0.70 and the last is at 0.90 |
79 | * |
80 | * \return an iterator to the selected particles |
81 | * |
82 | */ |
83 | template<unsigned int dim, typename T, typename vd_type> |
84 | static PointIteratorSkin<dim,T,typename vd_type::Decomposition_type> |
85 | DrawSkin(vd_type & vd, |
86 | size_t (& sz)[dim], |
87 | Box<dim,T> & domain, |
88 | openfpm::vector<Box<dim,T>> & sub_A, |
89 | Box<dim,T> & sub_B) |
90 | { |
91 | size_t bc[dim]; |
92 | |
93 | for (size_t i = 0 ; i < dim ; i++) |
94 | bc[i] = NON_PERIODIC; |
95 | |
96 | PointIteratorSkin<dim,T,typename vd_type::Decomposition_type> it(vd.getDecomposition(),sz,vd.getDecomposition().getDomain(),sub_A.get(0), sub_B, bc); |
97 | |
98 | for (size_t i = 1 ; i < sub_A.size() ; i++) |
99 | it.addBoxA(Box<dim,T>(sub_A.get(i))); |
100 | |
101 | return it; |
102 | } |
103 | |
104 | /*! \brief Draw particles in a box |
105 | * |
106 | * The function return an iterator over particles defined on a virtual grid in the simulation domain. |
107 | * |
108 | * \param vd particles where we are creating the particles |
109 | * \param sz indicate the grid size of the virtual grid. |
110 | * \param domain Domain where the virtual grid is defined (Must match the domain of vd) |
111 | * \param sub box contained in domain that define where the particle iterator must iterate, |
112 | * particles are placed strictly inside this box |
113 | * |
114 | * \note Suppose to have a simulation domain of 1.5 on x and we use sz = 16. Consider now |
115 | * to have particles with spacing 0.1 on x. if we define a sub box that on extend from 0.65 |
116 | * to 0.95 the first fluid particle |
117 | * is at 0.70 and the last is at 0.90 |
118 | * |
119 | * \return an iterator to the selected particles |
120 | * |
121 | */ |
122 | template<unsigned int dim, typename T, typename vd_type> static PointIterator<dim,T,typename vd_type::Decomposition_type> |
123 | DrawBox(vd_type & vd, |
124 | size_t (& sz)[dim], |
125 | Box<dim,T> & domain, |
126 | Box<dim,T> & sub) |
127 | { |
128 | return PointIterator<dim,T,typename vd_type::Decomposition_type>(vd.getDecomposition(),sz,vd.getDecomposition().getDomain(),sub); |
129 | } |
130 | |
131 | }; |
132 | |
133 | |
134 | #endif /* OPENFPM_NUMERICS_SRC_DRAW_DRAWPARTICLES_HPP_ */ |
135 | |