OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
SpaceBox.hpp
1
2#ifndef SPACEBOX_HPP_
3#define SPACEBOX_HPP_
4
5#include "Shape/Point.hpp"
6#include "Shape/Box.hpp"
7#include <boost/fusion/include/vector.hpp>
8#include "memory_ly/Encap.hpp"
9#include "Ghost.hpp"
10#include <stdlib.h> /* srand, rand */
11
25template<unsigned int dim, typename T>
26class SpaceBox : public Box<dim,T>
27{
28 public:
29
40 {
41 // for each dimension set high and low
42
43 for (size_t d = 0 ; d < dim ; d++)
44 {this->setLow(d,b.getLow(d));}
45
46 for (size_t d = 0 ; d < dim ; d++)
47 {this->setHigh(d,b.getHigh(d));}
48
49 return *this;
50 }
51
57 template <typename S>inline SpaceBox(const Box<dim,S> & b)
58 {
59 for (size_t d = 0 ; d < dim ; d++)
60 {this->setLow(d,b.getLow(d));}
61
62 for (size_t d = 0 ; d < dim ; d++)
63 {this->setHigh(d,b.getHigh(d));}
64 }
65
74 :Box<dim,T>(b)
75 {
76 }
77
86 explicit SpaceBox(const Box<dim,T> & b)
87 :Box<dim,T>(b)
88 {
89 }
90
97 template<unsigned int dim_s,typename Mem> SpaceBox(const encapc<dim_s,Box<dim,T>,Mem> & box)
98 {
99 // for each dimension set high and low
100
101 for (size_t d = 0 ; d < dim ; d++)
102 {this->setLow(d,box.template get<Box<dim,T>::p1>()[d]);}
103
104 for (size_t d = 0 ; d < dim ; d++)
105 {this->setHigh(d,box.template get<Box<dim,T>::p2>()[d]);}
106 }
107
113 template<unsigned int dim_s,typename Mem> SpaceBox(const encapc<dim_s,SpaceBox<dim,T>,Mem> & box)
114 {
115 // for each dimension set high and low
116
117 for (size_t d = 0 ; d < dim ; d++)
118 {this->setLow(d,box.template get<Box<dim,T>::p1>()[d]);}
119
120 for (size_t d = 0 ; d < dim ; d++)
121 {this->setHigh(d,box.template get<Box<dim,T>::p2>()[d]);}
122 }
123
133 SpaceBox(std::initializer_list<T> p1, std::initializer_list<T> p2)
134 {
135 // for each dimension set high and low
136
137 size_t i = 0;
138 for(T x : p1)
139 {this->setLow(i,x);i++;}
140
141 i = 0;
142 for(T x : p2)
143 {this->setHigh(i,x);i++;}
144 }
145
152 void rescale(T (& sp)[dim])
153 {
154 for (size_t d = 0 ; d < dim ; d++)
155 {this->setHigh(d,this->getLow(d) + (this->getHigh(d) -this->getLow(d)) * sp[d]);}
156 }
157
164 template<typename S> void rescale(S (& sp)[dim])
165 {
166 for (size_t d = 0 ; d < dim ; d++)
167 {this->setHigh(d,this->getLow(d) + (this->getHigh(d) -this->getLow(d)) * sp[d]);}
168 }
169
178 void mul(T (& sp)[dim])
179 {
180 for (size_t d = 0 ; d < dim ; d++)
181 {this->setLow(d,this->getLow(d) * sp[d]);}
182
183 for (size_t d = 0 ; d < dim ; d++)
184 {this->setHigh(d,this->getHigh(d) * sp[d]);}
185 }
186
195 template<typename S> void mul(S (& sp)[dim])
196 {
197 for (size_t d = 0 ; d < dim ; d++)
198 {this->setLow(d,this->getLow(d) * sp[d]);}
199
200 for (size_t d = 0 ; d < dim ; d++)
201 {this->setHigh(d,this->getHigh(d) * sp[d]);}
202 }
203
210 {
211 Point<dim,T> p;
212
213 for (size_t i = 0 ; i < dim ; i++)
214 p.get(i) = ((T)rand())/(T)RAND_MAX * (this->getHigh(i) - this->getLow(i)) + this->getLow(i);
215
216 return p;
217 }
218
220 SpaceBox<dim,T>() {}
221};
222
223
225
226template<unsigned int dim, typename St>
228{
229 enum
230 {
231 value = 1
232 };
233};
234
235
236#endif
This class represent an N-dimensional box.
Definition Box.hpp:61
__device__ __host__ T getLow(int i) const
get the i-coordinate of the low bound interval of the box
Definition Box.hpp:556
static const unsigned int p1
Low point.
Definition Box.hpp:76
__device__ __host__ T getHigh(int i) const
get the high interval of the box
Definition Box.hpp:567
__device__ __host__ void setHigh(int i, T val)
set the high interval of the box
Definition Box.hpp:544
static const unsigned int p2
High point.
Definition Box.hpp:78
__device__ __host__ void setLow(int i, T val)
set the low interval of the box
Definition Box.hpp:533
This class implement the point shape in an N-dimensional space.
Definition Point.hpp:28
__device__ __host__ const T & get(unsigned int i) const
Get coordinate.
Definition Point.hpp:172
This class represent an N-dimensional box.
Definition SpaceBox.hpp:27
void mul(S(&sp)[dim])
multiply the space box with the coefficient defined in sp
Definition SpaceBox.hpp:195
Point< dim, T > rnd()
Generate a random point inside the box.
Definition SpaceBox.hpp:209
SpaceBox(std::initializer_list< T > p1, std::initializer_list< T > p2)
Constructor from initializer list.
Definition SpaceBox.hpp:133
SpaceBox< dim, T > & operator=(const Box< dim, T > &b)
Define the box from a box shape.
Definition SpaceBox.hpp:39
SpaceBox(const encapc< dim_s, Box< dim, T >, Mem > &box)
Constructor from a Box.
Definition SpaceBox.hpp:97
void rescale(S(&sp)[dim])
Re-scale the space box with the coefficient defined in sp.
Definition SpaceBox.hpp:164
void mul(T(&sp)[dim])
multiply the space box with the coefficient defined in sp
Definition SpaceBox.hpp:178
SpaceBox(const Box< dim, T > &b)
constructor from a box
Definition SpaceBox.hpp:86
void rescale(T(&sp)[dim])
Re-scale the space box with the coefficient defined in sp.
Definition SpaceBox.hpp:152
SpaceBox(const Box< dim, S > &b)
constructor from a Box of different type
Definition SpaceBox.hpp:57
SpaceBox(const SpaceBox< dim, T > &b)
constructor from a SpaceBox
Definition SpaceBox.hpp:73
SpaceBox(const encapc< dim_s, SpaceBox< dim, T >, Mem > &box)
Constructor from a Box.
Definition SpaceBox.hpp:113
check if T::type and T.data has the same type
Definition common.hpp:190