7 #include <boost/fusion/sequence/intrinsic/at_c.hpp>
8 #include "Grid/grid_key.hpp"
9 #include "memory_ly/Encap.hpp"
13 #define NON_PERIODIC 0
58 template<
unsigned int dim ,
typename T>
64 typedef boost::fusion::vector<T[dim],T[dim]>
type;
75 static const unsigned int p1 = 0;
77 static const unsigned int p2 = 1;
82 static const unsigned int dims = dim;
98 for (
size_t i = 0 ; i < dim ; i++)
100 if (
getLow(i) <= b.getLow(i))
101 b_out.
setLow(i,b.getLow(i));
102 else if (
getLow(i) <= b.getHigh(i))
107 if (
getHigh(i) >= b.getHigh(i))
109 else if (
getHigh(i) >= b.getLow(i))
129 template<
typename Mem>
169 typename distance::ResultType distance_r = 0;
171 for (
size_t i = 0 ; i < dim ; i++)
177 if (boost::fusion::at_c<p1>(
data)[i] < sphere.
center(i))
180 distance_r += dist.accum_dist(sphere.
center(i),boost::fusion::at_c<p1>(
data)[i],i);
182 else if ( boost::fusion::at_c<p2>(
data)[i] <= sphere.
center(i))
185 distance_r += dist.accum_dist(sphere.
center(i),boost::fusion::at_c<p2>(
data)[i],i);
190 return distance_r < sphere.
radius();
226 for (
unsigned int i = 0 ; i < dim ; i++)
229 {dist.get(i) = b.getLow(i) -
getHigh(i);}
230 else if (b.getHigh(i) <=
getLow(i))
231 {dist.get(i) =
getLow(i) - b.getHigh(i);}
234 T d1 = fabs(
getHigh(i) - b.getLow(i) );
235 T d2 = fabs(
getLow(i) - b.getLow(i));
239 T d3 = fabs(
getHigh(i) - b.getHigh(i));
240 dist.get(i) = (d3 < d1)?d3:d1;
244 T d3 = fabs(
getHigh(i) - b.getHigh(i));
245 dist.get(i) = (d3 < d1)?d3:d2;
261 template<
unsigned int b> T
getBase(
const unsigned int i)
const
263 return boost::fusion::at_c<b>(
data)[i];
288 for(
size_t i = 0 ; i < dim ; i++)
322 Box(std::initializer_list<T>
p1, std::initializer_list<T>
p2)
333 inline Box(T * low, T * high)
337 for (
int i = 0 ; i < dim ; i++)
341 boost::fusion::at_c<Box::p1>(
data)[i] = low[i];
342 boost::fusion::at_c<Box::p2>(
data)[i] = high[i];
355 for (
size_t i = 0 ; i < dim ; i++)
357 boost::fusion::at_c<p1>(
data)[i] = boost::fusion::at_c<p1>(box.
data)[i];
358 boost::fusion::at_c<p2>(
data)[i] = boost::fusion::at_c<p2>(box.
data)[i];
371 for (
size_t i = 0 ; i < dim ; i++)
373 boost::fusion::at_c<p1>(
data)[i] = boost::fusion::at_c<p1>(box_data)[i];
374 boost::fusion::at_c<p2>(
data)[i] = boost::fusion::at_c<p2>(box_data)[i];
383 inline Box(T (& box_data)[dim])
387 for (
size_t i = 0 ; i < dim ; i++)
389 boost::fusion::at_c<p1>(
data)[i] = 0;
390 boost::fusion::at_c<p2>(
data)[i] = box_data[i];
402 for (
size_t i = 0 ; i < dim ; i++)
414 template<
unsigned int dimS>
415 __device__ __host__
inline Box(boost::fusion::vector<T[dimS],T[dimS]> & box_data)
419 for (
size_t i = 0 ; i < dim ; i++)
421 boost::fusion::at_c<p1>(
data)[i] = boost::fusion::at_c<p1>(box_data)[i];
422 boost::fusion::at_c<p2>(
data)[i] = boost::fusion::at_c<p2>(box_data)[i];
431 template<
typename Mem>
437 for (
size_t i = 0 ; i < dim ; i++)
439 boost::fusion::at_c<p1>(
data)[i] = b.template get<p1>()[i];
440 boost::fusion::at_c<p2>(
data)[i] = b.template get<p2>()[i];
449 template <
typename S>
453 for (
size_t i = 0 ; i < dim ; i++)
469 for (
size_t i = 0 ; i < dim ; i++)
488 for (
size_t i = 0 ; i < dim ; i++)
505 inline void set(std::initializer_list<T>
p1, std::initializer_list<T>
p2)
532 __device__ __host__
inline void setLow(
int i, T val)
534 boost::fusion::at_c<p1>(
data)[i] = val;
543 __device__ __host__
inline void setHigh(
int i, T val)
545 boost::fusion::at_c<p2>(
data)[i] = val;
555 __device__ __host__
inline T
getLow(
int i)
const
557 return boost::fusion::at_c<p1>(
data)[i];
566 __device__ __host__
inline T
getHigh(
int i)
const
568 return boost::fusion::at_c<p2>(
data)[i];
578 for (
size_t i = 0 ; i < dim ; i++)
589 for (
size_t i = 0 ; i < dim ; i++)
600 for (
size_t i = 0 ; i < dim ; i++)
611 for (
size_t i = 0 ; i < dim ; i++)
738 for (
size_t i = 0 ; i < dim ; i++)
740 boost::fusion::at_c<p2>(
data)[i] -= p.get(i);
741 boost::fusion::at_c<p1>(
data)[i] -= p.get(i);
756 for (
size_t i = 0 ; i < dim ; i++)
758 boost::fusion::at_c<p2>(
data)[i] += p.get(i);
759 boost::fusion::at_c<p1>(
data)[i] += p.get(i);
776 for (
size_t i = 0 ; i < dim ; i++)
778 b.setHigh(i,boost::fusion::at_c<p2>(
data)[i] + p.get(i));
779 b.setLow(i,boost::fusion::at_c<p1>(
data)[i] + p.get(i));
794 for (
size_t i = 0 ; i < dim ; i++)
796 boost::fusion::at_c<p2>(
data)[i] = boost::fusion::at_c<p2>(
data)[i] + exp[i];
824 typedef ::Box<dim,T> g;
826 for (
size_t j = 0 ; j < dim ; j++)
828 setLow(j,this->
template getBase<g::p1>(j) + gh.template getBase<g::p1>(j));
829 setHigh(j,this->
template getBase<g::p2>(j) + gh.template getBase<g::p2>(j));
857 typedef ::Box<dim,T> g;
859 for (
size_t j = 0 ; j < dim ; j++)
861 setHigh(j,this->
template getBase<g::p2>(j) + gh.template getBase<g::p2>(j) - gh.template getBase<g::p1>(j));
872 for (
size_t j = 0 ; j < dim ; j++)
890 typedef ::Box<dim,T> g;
892 for (
size_t j = 0 ; j < dim ; j++)
894 setLow(j,mg * this->
template getBase<g::p1>(j));
895 setHigh(j,mg * this->
template getBase<g::p2>(j));
908 typedef ::Box<dim,T> g;
910 for (
size_t j = 0 ; j < dim ; j++)
912 setHigh(j,this->
template getBase<g::p1>(j) + mg * (this->
template getBase<g::p2>(j) - this->
template getBase<g::p1>(j)));
923 for (
size_t j = 0 ; j < dim ; j++)
936 for (
size_t j = 0 ; j < dim ; j++)
949 for (
size_t j = 0 ; j < dim ; j++)
969 for (
size_t j = 0 ; j < dim ; j++)
974 if (reset_p1 ==
true)
984 for (
size_t j = 0 ; j < dim ; j++)
1020 for (
size_t i = 0 ; i < dim ; i++)
1049 for (
size_t i = 0 ; i < dim ; i++)
1076 template<
typename bc_type>
1081 for (
size_t i = 0 ; i < dim ; i++)
1084 if ( p.get(i) < this->getLow(i)
1085 || (bc[i] == NON_PERIODIC && ((this->getHigh(i) != border.
getHigh(i) && p.get(i) >= this->getHigh(i)) || (this->getHigh(i) == border.
getHigh(i) && p.get(i) > this->getHigh(i)) ) )
1086 || (bc[i] == PERIODIC && p.get(i) >= this->getHigh(i)))
1108 for (
size_t i = 0 ; i < dim ; i++)
1136 for (
size_t i = 0 ; i < dim ; i++)
1159 template<
typename KeyType>
1164 for (
size_t i = 0 ; i < dim ; i++)
1167 if ( k.get(i) < boost::fusion::at_c<
Box<dim,T>::p1>(this->data)[i]
1168 || k.get(i) > boost::fusion::at_c<
Box<dim,T>::p2>(this->data)[i])
1188 for (
size_t i = 0 ; i < dim ; i++)
1204 for (
size_t i = 0 ; i < dim ; i++)
1219 for (
size_t i = 0 ; i < dim ; i++)
1231 for (
size_t i = 0 ; i < dim ; i++)
1243 for (
size_t i = 0 ; i < dim ; i++)
1255 for (
size_t i = 0 ; i < dim ; i++)
1268 for (
size_t i = 0 ; i < dim ; i++)
1279 for (
size_t i = 0 ; i < dim ; i++)
1299 template <
typename Mem>
1304 for (
size_t i = 0 ; i < dim ; i++)
1328 for (
size_t i = 0 ; i < dim ; i++)
1329 r_cut = std::max(r_cut,
getHigh(i));
1343 for (
size_t i = 0 ; i < dim ; i++)
1358 for (
size_t i = 0 ; i < dim ; i++)
1380 for (
size_t i = 0 ; i < dim ; i++)
1381 vol *= (
p2[i] -
p1[i] + 1.0);
1401 for (
size_t i = 0 ; i < dim ; i++)
1414 std::stringstream str;
1416 for (
size_t i = 0 ; i < dim ; i++)
1417 str <<
"x[" << i <<
"]=" <<
getLow(i) <<
" ";
1421 for (
size_t i = 0 ; i < dim ; i++)
1422 str <<
"x[" << i <<
"]=" <<
getHigh(i) <<
" ";
1436 for (
size_t i = 0 ; i < dim ; i++)
1438 if (
getLow(i) != b.getLow(i))
1441 if (
getHigh(i) != b.getHigh(i))
1468 for (
size_t d = 0 ; d < dim ; d++)
1480 for (
size_t d = 0 ; d < dim ; d++)
1492 for (
size_t d = 0 ; d < dim ; d++)
1505 template<
typename S>
void mul(S (& sp)[dim])
1507 for (
size_t d = 0 ; d < dim ; d++)
1523 for (
size_t i = 0 ; i < dim ; i++)
Header file containing functions for creating a filled 3D sphere of defined radius.
This class represent an N-dimensional box.
void enlarge_fix_P1(Box< dim, S > &gh)
Enlarge the box with ghost margin keeping fix the point P1.
bool isInside(const encapc< 1, Point< dim, T >, Mem > &p)
Check if the point is inside the region.
boost::fusion::vector< T[dim], T[dim]> type
boost fusion that store the point
void expand(T(&exp)[dim])
expand the box by a vector
Point< dim, T > getP1() const
Get the point p1.
Box(const grid_key_dx< dim > &key1, const grid_key_dx< dim > &key2)
constructor from 2 grid_key_dx
void mul(T(&sp)[dim])
multiply box p1,p2 points with the coefficients defined in sp
__device__ __host__ T getLow(int i) const
get the i-coordinate of the low bound interval of the box
__device__ __host__ Box(const Box< dim, T > &box)
Box constructor from a box.
static const unsigned int p1
Low point.
void setP2(const Point< dim, T > &p2)
Set the point P2 of the box.
__device__ __host__ bool Intersect(const Box< dim, T > &b, Box< dim, T > &b_out) const
Intersect.
std::string toString() const
Produce a string from the object.
void ceilP1()
Apply the ceil operation to the point P1.
void mul(S(&sp)[dim])
multiply box p1,p2 points with the coefficients defined in sp
Box(type box_data)
Box constructor from vector::fusion.
void zero()
Set p1 and p2 to 0.
Box(std::initializer_list< T > p1, std::initializer_list< T > p2)
Constructor from initializer list.
Box(T *low, T *high)
Box constructor from a box.
__device__ __host__ T getHigh(int i) const
get the high interval of the box
__host__ __device__ bool isInside(const Point< dim, T > &p) const
Check if the point is inside the box.
Box(const Point< dim, T > &p1, const Point< dim, T > &p2)
Constructor from two points.
void setP2(const grid_key_dx< dim > &p2)
Set the point P2 of the box.
Box< dim, T > & operator/=(const Point< dim, T > &p)
Divide component wise each box points with a point.
void ceilP2()
Apply the ceil operation to the point P2.
grid_key_dx< dim > getKP1() const
Get the point p1 as grid_key_dx.
void shrinkP2(T sh)
Shrink moving p2 of sh quantity (on each direction)
void setP1(const Point< dim, T > &p1)
Set the point P1 of the box.
__device__ __host__ Box< dim, T > & operator=(const Box< dim, T > &box)
Operator= between boxes.
void magnify_fix_P1(T mg)
Magnify the box by a factor keeping fix the point P1.
Box< dim, T > & operator-=(const Point< dim, T > &p)
Translate the box.
void shrinkP2(const Point< dim, T > &p)
Shrink the point P2 by one vector.
T getBase(const unsigned int i) const
Get the coordinate of the bounding point.
static T getVolumeKey(const T(&p1)[dim], const T(&p2)[dim])
Get the volume spanned by the Box as grid_key_dx_iterator_sub.
Point< dim, T > getP2() const
Get the point p2.
__device__ __host__ Box(boost::fusion::vector< T[dimS], T[dimS]> &box_data)
Box constructor from vector::fusion of higher dimension.
void rescale(S(&sp)[dim])
Re-scale box with the coefficient defined in sp.
void invalidate()
Invalidate the box.
void set(std::initializer_list< T > p1, std::initializer_list< T > p2)
Constructor from initializer list.
int yes_is_box
Indicate that this is a box.
__device__ __host__ bool isInsideNP(const Point< dim, T > &p) const
Check if the point is inside the region excluding the positive part.
__device__ __host__ Box()
default constructor
grid_key_dx< dim, int > getKP1int() const
Get the point p1 as grid_key_dx.
void enlarge(const Box< dim, T > &gh)
Enlarge the box with ghost margin.
grid_key_dx< dim > getKP2() const
Get the point p12 as grid_key_dx.
grid_key_dx< dim, int > getKP2int() const
Get the point p12 as grid_key_dx.
static const unsigned int dims
dimensionality of the box
bool isValid() const
Check if the Box is a valid box P2 >= P1.
T getVolumeKey() const
Get the volume spanned by the Box P1 and P2 interpreted as grid key.
T getRcut() const
Get the worst extension.
void magnify(T mg)
Magnify the box.
void contained(const Box< dim, T > &en, const bool reset_p1=true)
Refine the box to be contained in the given box and itself.
type data
It store the two point bounding the box.
__device__ __host__ Box(const encapc< 1, Box< dim, T >, Mem > &b)
Box constructor from encapsulated box.
bool isInside(const T(&p)[dim]) const
Check if the point is inside the region (Border included)
Box< dim, T > & operator+=(const Point< dim, T > &p)
Translate the box.
void floorP2()
Apply the ceil operation to the point P2.
__device__ __host__ void setHigh(int i, T val)
set the high interval of the box
Box< dim, T > operator+(const Point< dim, T > &p) const
Translate the box.
static const unsigned int p2
High point.
void enclose(const Box< dim, T > &en)
Refine the box to enclose the given box and itself.
__device__ __host__ bool Intersect(const encapc< 1, Box< dim, T >, Mem > &e_b, Box< dim, T > &b_out) const
Intersect.
Box< dim-1, T > getSubBox()
Get the the box of dimensionality dim-1 (it eliminate the last dimension)
Box< dim, T > operator*(const Point< dim, T > &p)
Multiply component wise each box points with a point.
bool operator==(const Box< dim, T > &b) const
Compare two boxes.
void setP1(const grid_key_dx< dim > &p1)
Set the point P1 of the box.
Point< dim, T > middle() const
Return the middle point of the box.
__device__ __host__ bool isInsideKey(const KeyType &k) const
Check if the point is inside the region (Border included)
type & getVector()
Get the internal boost::fusion::vector that store the data.
__device__ __host__ bool isInsideNP_with_border(const Point< dim, T > &p, const Box< dim, T > &border, const bc_type(&bc)[dim]) const
Check if the point is inside the region excluding the positive part.
bool isInsideNB(const Point< dim, T > &p) const
Check if the point is inside the region excluding the borders.
__device__ __host__ void setLow(int i, T val)
set the low interval of the box
Box(T(&box_data)[dim])
Box constructor from an array reference.
bool operator!=(const Box< dim, T > &b) const
Compare two boxes.
const Box< dim, T > & getBox() const
Get the box enclosing this Box.
Point< dim, T > rnd()
Generates a random point inside the box.
void enlargeP2(T sh)
Shrink moving p2 of sh quantity (on each direction)
void floorP1()
Apply the ceil operation to the point P1.
__device__ __host__ Box(const Box< dim, S > &b)
constructor from a Box of different type
bool Intersect(Sphere< dim, T > &sphere)
Check if the sphere intersect the box.
bool isContained(const Box< dim, T > &b) const
Check if the box is contained.
T getVolume() const
Get the volume of the box.
void swap(Box< dim, T > &b)
exchange the data of two boxes
static bool noPointers()
This structure has no internal pointers.
static const unsigned int max_prop
Maximum number of properties.
bool isValidN() const
Check if the Box is a valid box P2 > P1.
Box< dim, T > & getBox()
Get the box enclosing this Box.
void rescale(T(&sp)[dim])
Re-scale box with the coefficient defined in sp.
This class implement the point shape in an N-dimensional space.
This class implement the Sphere concept in an N-dimensional space.
__device__ __host__ T center(unsigned int i)
Get the component i of the center.
__device__ __host__ T radius() const
Get the radius of the sphere.
__device__ __host__ index_type get(index_type i) const
Get the i index.