OpenFPM_data  0.1.0
Project that contain the implementation and interfaces for basic structure like vectors, grids, graph ... .
 All Data Structures Namespaces Functions Variables Typedefs Friends
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 "Grid/Encap.hpp"
9 #include "Ghost.hpp"
10 #include <stdlib.h> /* srand, rand */
11 
25 template<unsigned int dim, typename T>
26 class SpaceBox : public Box<dim,T>
27 {
28  public:
29 
39  inline SpaceBox<dim,T> & operator=(const Box<dim,T> & b)
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  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())/RAND_MAX * (this->getHigh(i) - this->getLow(i)) + this->getLow(i);
215 
216  return p;
217  }
218 
221 };
222 
223 #include "Grid/Encap.hpp"
224 
225 
226 #endif
SpaceBox(const Box< dim, T > &b)
constructor from a box
Definition: SpaceBox.hpp:86
This class represent an N-dimensional box.
Definition: SpaceBox.hpp:26
T getLow(int i) const
get the i-coordinate of the low bound interval of the box
Definition: Box.hpp:484
SpaceBox< dim, T > & operator=(const Box< dim, T > &b)
Define the box from a box shape.
Definition: SpaceBox.hpp:39
void mul(T(&sp)[dim])
multiply the space box with the coefficient defined in sp
Definition: SpaceBox.hpp:178
T getHigh(int i) const
get the high interval of the box
Definition: Box.hpp:495
void setHigh(int i, T val)
set the high interval of the box
Definition: Box.hpp:472
This class implement the point shape in an N-dimensional space.
Definition: Point.hpp:20
SpaceBox(const SpaceBox< dim, T > &b)
constructor from a SpaceBox
Definition: SpaceBox.hpp:73
static const unsigned int p1
Low point.
Definition: Box.hpp:69
T get(int i) const
Get coordinate.
Definition: Point.hpp:42
SpaceBox(std::initializer_list< T > p1, std::initializer_list< T > p2)
Constructor from initializer list.
Definition: SpaceBox.hpp:133
void rescale(T(&sp)[dim])
Re-scale the space box with the coefficient defined in sp.
Definition: SpaceBox.hpp:152
this structure encapsulate an object of the grid
Definition: Encap.hpp:209
void setLow(int i, T val)
set the low interval of the box
Definition: Box.hpp:461
This class represent an N-dimensional box.
Definition: Box.hpp:56
static const unsigned int p2
High point.
Definition: Box.hpp:71
void rescale(S(&sp)[dim])
Re-scale the space box with the coefficient defined in sp.
Definition: SpaceBox.hpp:164
SpaceBox(const encapc< dim_s, Box< dim, T >, Mem > &box)
Constructor from a Box.
Definition: SpaceBox.hpp:97
SpaceBox(const encapc< dim_s, SpaceBox< dim, T >, Mem > &box)
Constructor from a Box.
Definition: SpaceBox.hpp:113
Point< dim, T > rnd()
Generate a random point inside the box.
Definition: SpaceBox.hpp:209
void mul(S(&sp)[dim])
multiply the space box with the coefficient defined in sp
Definition: SpaceBox.hpp:195
SpaceBox(const Box< dim, S > &b)
constructor from a Box of different type
Definition: SpaceBox.hpp:57