7#include <boost/fusion/sequence/intrinsic/at_c.hpp>
8#include "Grid/grid_key.hpp"
9#include "memory_ly/Encap.hpp"
59template<
unsigned int dim ,
typename T>
65 typedef boost::fusion::vector<T[dim],T[dim]>
type;
76 static const unsigned int p1 = 0;
78 static const unsigned int p2 = 1;
83 static const unsigned int dims = dim;
99 for (
size_t i = 0 ; i < dim ; i++)
101 if (
getLow(i) <= b.getLow(i))
102 b_out.
setLow(i,b.getLow(i));
103 else if (
getLow(i) <= b.getHigh(i))
108 if (
getHigh(i) >= b.getHigh(i))
110 else if (
getHigh(i) >= b.getLow(i))
130 template<
typename Mem>
170 typename distance::ResultType distance_r = 0;
172 for (
size_t i = 0 ; i < dim ; i++)
178 if (boost::fusion::at_c<p1>(
data)[i] < sphere.
center(i))
181 distance_r += dist.accum_dist(sphere.
center(i),boost::fusion::at_c<p1>(
data)[i],i);
183 else if ( boost::fusion::at_c<p2>(
data)[i] <= sphere.
center(i))
186 distance_r += dist.accum_dist(sphere.
center(i),boost::fusion::at_c<p2>(
data)[i],i);
191 return distance_r < sphere.
radius();
227 for (
unsigned int i = 0 ; i < dim ; i++)
230 {dist.get(i) = b.getLow(i) -
getHigh(i);}
231 else if (b.getHigh(i) <=
getLow(i))
232 {dist.get(i) =
getLow(i) - b.getHigh(i);}
235 T d1 = fabs(
getHigh(i) - b.getLow(i) );
236 T d2 = fabs(
getLow(i) - b.getLow(i));
240 T d3 = fabs(
getHigh(i) - b.getHigh(i));
241 dist.get(i) = (d3 < d1)?d3:d1;
245 T d3 = fabs(
getHigh(i) - b.getHigh(i));
246 dist.get(i) = (d3 < d1)?d3:d2;
262 template<
unsigned int b> T
getBase(
const unsigned int i)
const
264 return boost::fusion::at_c<b>(
data)[i];
289 for(
size_t i = 0 ; i < dim ; i++)
292 for(
size_t i = 0 ; i < dim ; i++)
323 Box(std::initializer_list<T>
p1, std::initializer_list<T>
p2)
334 inline Box(T * low, T * high)
338 for (
int i = 0 ; i < dim ; i++)
342 boost::fusion::at_c<Box::p1>(
data)[i] = low[i];
343 boost::fusion::at_c<Box::p2>(
data)[i] = high[i];
356 for (
size_t i = 0 ; i < dim ; i++)
358 boost::fusion::at_c<p1>(
data)[i] = boost::fusion::at_c<p1>(box.
data)[i];
359 boost::fusion::at_c<p2>(
data)[i] = boost::fusion::at_c<p2>(box.
data)[i];
372 for (
size_t i = 0 ; i < dim ; i++)
374 boost::fusion::at_c<p1>(
data)[i] = boost::fusion::at_c<p1>(box_data)[i];
375 boost::fusion::at_c<p2>(
data)[i] = boost::fusion::at_c<p2>(box_data)[i];
384 inline Box(T (& box_data)[dim])
388 for (
size_t i = 0 ; i < dim ; i++)
390 boost::fusion::at_c<p1>(
data)[i] = 0;
391 boost::fusion::at_c<p2>(
data)[i] = box_data[i];
403 for (
size_t i = 0 ; i < dim ; i++)
415 template<
unsigned int dimS>
416 __device__ __host__
inline Box(boost::fusion::vector<T[dimS],T[dimS]> & box_data)
420 for (
size_t i = 0 ; i < dim ; i++)
422 boost::fusion::at_c<p1>(
data)[i] = boost::fusion::at_c<p1>(box_data)[i];
423 boost::fusion::at_c<p2>(
data)[i] = boost::fusion::at_c<p2>(box_data)[i];
432 template<
typename Mem>
438 for (
size_t i = 0 ; i < dim ; i++)
440 boost::fusion::at_c<p1>(
data)[i] = b.template get<p1>()[i];
441 boost::fusion::at_c<p2>(
data)[i] = b.template get<p2>()[i];
450 template <
typename S>
454 for (
size_t d = 0 ; d < dim ; d++)
455 {this->
setLow(d,b.getLow(d));}
457 for (
size_t d = 0 ; d < dim ; d++)
458 {this->
setHigh(d,b.getHigh(d));}
470 for (
size_t i = 0 ; i < dim ; i++)
489 for (
size_t i = 0 ; i < dim ; i++)
506 inline void set(std::initializer_list<T>
p1, std::initializer_list<T>
p2)
533 __device__ __host__
inline void setLow(
int i, T val)
535 boost::fusion::at_c<p1>(
data)[i] = val;
544 __device__ __host__
inline void setHigh(
int i, T val)
546 boost::fusion::at_c<p2>(
data)[i] = val;
556 __device__ __host__
inline T
getLow(
int i)
const
558 return boost::fusion::at_c<p1>(
data)[i];
567 __device__ __host__
inline T
getHigh(
int i)
const
569 return boost::fusion::at_c<p2>(
data)[i];
579 for (
size_t i = 0 ; i < dim ; i++)
590 for (
size_t i = 0 ; i < dim ; i++)
601 for (
size_t i = 0 ; i < dim ; i++)
612 for (
size_t i = 0 ; i < dim ; i++)
739 for (
size_t i = 0 ; i < dim ; i++)
741 boost::fusion::at_c<p2>(
data)[i] -= p.
get(i);
742 boost::fusion::at_c<p1>(
data)[i] -= p.
get(i);
757 for (
size_t i = 0 ; i < dim ; i++)
759 boost::fusion::at_c<p2>(
data)[i] += p.
get(i);
760 boost::fusion::at_c<p1>(
data)[i] += p.
get(i);
777 for (
size_t i = 0 ; i < dim ; i++)
779 b.setHigh(i,boost::fusion::at_c<p2>(
data)[i] + p.
get(i));
780 b.setLow(i,boost::fusion::at_c<p1>(
data)[i] + p.
get(i));
795 for (
size_t i = 0 ; i < dim ; i++)
797 boost::fusion::at_c<p2>(
data)[i] = boost::fusion::at_c<p2>(
data)[i] + exp[i];
825 typedef ::Box<dim,T> g;
827 for (
size_t j = 0 ; j < dim ; j++)
829 this->
setLow(j,this->
template getBase<g::p1>(j) + gh.template getBase<g::p1>(j));
830 this->
setHigh(j,this->
template getBase<g::p2>(j) + gh.template getBase<g::p2>(j));
858 typedef ::Box<dim,T> g;
860 for (
size_t j = 0 ; j < dim ; j++)
862 this->
setHigh(j,this->
template getBase<g::p2>(j) + gh.template getBase<g::p2>(j) - gh.template getBase<g::p1>(j));
873 for (
size_t j = 0 ; j < dim ; j++)
891 typedef ::Box<dim,T> g;
893 for (
size_t j = 0 ; j < dim ; j++)
895 this->
setLow(j,mg * this->
template getBase<g::p1>(j));
896 this->
setHigh(j,mg * this->
template getBase<g::p2>(j));
909 typedef ::Box<dim,T> g;
911 for (
size_t j = 0 ; j < dim ; j++)
913 this->
setHigh(j,this->
template getBase<g::p1>(j) + mg * (this->
template getBase<g::p2>(j) - this->
template getBase<g::p1>(j)));
924 for (
size_t j = 0 ; j < dim ; j++)
937 for (
size_t j = 0 ; j < dim ; j++)
957 for (
size_t j = 0 ; j < dim ; j++)
962 if (reset_p1 ==
true)
972 for (
size_t j = 0 ; j < dim ; j++)
1008 for (
size_t i = 0 ; i < dim ; i++)
1038 for (
size_t i = 0 ; i < dim ; i++)
1066 template<
typename bc_type>
1071 for (
size_t i = 0 ; i < dim ; i++)
1074 if ( p.
get(i) < this->getLow(i)
1075 || (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)) ) )
1076 || (bc[i] == PERIODIC && p.
get(i) >= this->getHigh(i)))
1099 for (
size_t i = 0 ; i < dim ; i++)
1128 for (
size_t i = 0 ; i < dim ; i++)
1152 template<
typename KeyType>
1157 for (
size_t i = 0 ; i < dim ; i++)
1160 if ( k.get(i) < boost::fusion::at_c<
Box<dim,T>::p1>(this->data)[i]
1161 || k.get(i) > boost::fusion::at_c<
Box<dim,T>::p2>(this->data)[i])
1182 for (
size_t i = 0 ; i < dim ; i++)
1198 for (
size_t i = 0 ; i < dim ; i++)
1213 for (
size_t i = 0 ; i < dim ; i++)
1225 for (
size_t i = 0 ; i < dim ; i++)
1237 for (
size_t i = 0 ; i < dim ; i++)
1249 for (
size_t i = 0 ; i < dim ; i++)
1262 for (
size_t i = 0 ; i < dim ; i++)
1275 for (
size_t i = 0 ; i < dim ; i++)
1295 template <
typename Mem>
1300 for (
size_t i = 0 ; i < dim ; i++)
1325 for (
size_t i = 0 ; i < dim ; i++)
1326 {r_cut = std::max(r_cut,
getHigh(i));}
1340 for (
size_t i = 0 ; i < dim ; i++)
1355 for (
size_t i = 0 ; i < dim ; i++)
1377 for (
size_t i = 0 ; i < dim ; i++)
1378 vol *= (
p2[i] -
p1[i] + 1.0);
1398 for (
size_t i = 0 ; i < dim ; i++)
1411 std::stringstream str;
1413 for (
size_t i = 0 ; i < dim ; i++)
1414 str <<
"x[" << i <<
"]=" <<
getLow(i) <<
" ";
1418 for (
size_t i = 0 ; i < dim ; i++)
1419 str <<
"x[" << i <<
"]=" <<
getHigh(i) <<
" ";
1433 for (
size_t i = 0 ; i < dim ; i++)
1435 if (
getLow(i) != b.getLow(i))
1438 if (
getHigh(i) != b.getHigh(i))
Header file containing functions for creating a filled 3D sphere of defined radius.
This class represent an N-dimensional box.
grid_key_dx< dim, int > getKP1int() const
Get the point p1 as grid_key_dx.
type & getVector()
Get the internal boost::fusion::vector that store the data.
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
Box< dim, T > & operator+=(const Point< dim, T > &p)
Translate the box.
grid_key_dx< dim, int > getKP2int() const
Get the point p12 as grid_key_dx.
Point< dim, T > getP2() const
Get the point p2.
Box(const grid_key_dx< dim > &key1, const grid_key_dx< dim > &key2)
constructor from 2 grid_key_dx
Box< dim, T > & operator/=(const Point< dim, T > &p)
Divide component wise each box points with a point.
__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.
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.
const Box< dim, T > & getBox() const
Get the box enclosing this Box.
void ceilP2()
Apply the ceil operation to the point P2.
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.
void magnify_fix_P1(T mg)
Magnify the box by a factor keeping fix the point P1.
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.
__device__ __host__ Box(boost::fusion::vector< T[dimS], T[dimS]> &box_data)
Box constructor from vector::fusion of higher dimension.
__device__ __host__ Box< dim, T > & operator=(const Box< dim, T > &box)
Operator= between boxes.
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
void enlarge(const Box< dim, T > &gh)
Enlarge the box with ghost margin.
static const unsigned int dims
dimensionality of the box
bool isValid() const
Check if the Box is a valid box P2 >= P1.
Box< dim, T > operator+(const Point< dim, T > &p)
Translate the box.
Point< dim, T > middle() const
Return the middle point of the box.
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.
Box< dim, T > & getBox()
Get the box enclosing this 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.
Box< dim, T > operator*(const Point< dim, T > &p)
Multiply component wise each box points with a point.
bool isInside(const T(&p)[dim]) const
Check if the point is inside the region (Border included)
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
static const unsigned int p2
High point.
Point< dim, T > getP1() const
Get the point p1.
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.
bool operator==(const Box< dim, T > &b) const
Compare two boxes.
grid_key_dx< dim > getKP2() const
Get the point p12 as grid_key_dx.
void setP1(const grid_key_dx< dim > &p1)
Set the point P1 of the box.
Box< dim, T > & operator-=(const Point< dim, T > &p)
Translate the box.
__device__ __host__ bool isInsideKey(const KeyType &k) const
Check if the point is inside the region (Border included)
__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.
grid_key_dx< dim > getKP1() const
Get the point p1 as grid_key_dx.
bool operator!=(const Box< dim, T > &b) const
Compare two boxes.
Box< dim-1, T > getSubBox()
Get the the box of dimensionality dim-1 (it eliminate the last dimension)
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.
This class implement the point shape in an N-dimensional space.
__device__ __host__ const T & get(unsigned int i) const
Get coordinate.
type data
structure that store the data of the point
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.
grid_key_dx is the key to access any element in the grid
__device__ __host__ index_type get(index_type i) const
Get the i index.