8 #ifndef CELLDECOMPOSER_HPP_
9 #define CELLDECOMPOSER_HPP_
11 #include "Space/SpaceBox.hpp"
12 #include "Space/Matrix.hpp"
13 #include "util/copy_compare/meta_compare.hpp"
16 template<
unsigned int dim,
typename T>
42 inline T
transform(
const T(&s)[dim],
const size_t i)
const
44 return s[i] - sh.get(i);
57 return s.
get(i) - sh.get(i);
70 return s.get(i) - sh.get(i);
81 for (
size_t i = 0 ; i < dim ; i++)
82 sh.get(i) = orig.
get(i);
87 template<
unsigned int dim,
typename T>
110 inline T
transform(
const T(&s)[dim],
const size_t i)
const
138 return s.template get<Point<dim,T>::x>()[i];
218 template<
unsigned int dim,
typename T,
typename transform = no_transform<dim,T>>
219 class CellDecomposer_sm
249 inline size_t ConvertToID(
const T (&x)[dim] ,
size_t s)
const
251 size_t id = (size_t)(t.transform(x,s) / box_unit.getHigh(s)) + off[s];
252 id = (
id >= (gr_cell.size(s) + off[0]))?(gr_cell.size(s)-1):
id;
262 inline size_t ConvertToID(
const Point<dim,T> & x ,
size_t s)
const
264 size_t id = (size_t)(t.transform(x,s) / box_unit.getHigh(s)) + off[s];
265 id = (
id >= (gr_cell.size(s) + off[0]))?(gr_cell.size(s)-1):
id;
275 template <
typename Mem>
inline size_t ConvertToID_(
const encapc<1,
Point<dim,T>,Mem> & x ,
size_t s)
const
277 size_t id = (size_t)(t.transform(x,s) / box_unit.getHigh(s)) + off[s];
278 id = (
id >= (gr_cell.size(s) + off[0]))?(gr_cell.size(s)-1):
id;
303 void Initialize(
const size_t pad,
const size_t (& div)[dim])
306 for (
size_t i = 0 ; i < dim ; i++)
310 std::cerr <<
"Error " << __FILE__ <<
":" << __LINE__ <<
" the number of cells on each dimension must be different from zero\n";
318 for (
size_t i = 0 ; i < dim ; i++)
319 div_p[i] = div[i] + 2*pad;
327 for (
size_t i = 0 ; i < dim ; i++)
329 tot_n_cell *= gr_cell.size(i);
332 box_unit.setHigh(i,box.getHigh(i) / (gr_cell.size(i)- 2*pad) );
335 for (
size_t i = 0; i < dim ; i++)
340 p_middle = box_unit.getP2();
341 p_middle = p_middle / 2;
355 std::cerr <<
"Error: " << __FILE__ <<
":" << __LINE__ <<
" using an uninitialized CellDecomposer";
374 std::cerr <<
"Error: " << __FILE__ <<
":" << __LINE__ <<
" using an uninitialized CellDecomposer";
378 key.
set_d(0,ConvertToID(pos,0));
380 for (
size_t s = 1 ; s < dim ; s++)
383 if ((
size_t)(t.transform(pos,s) / box_unit.getHigh(s)) + off[s] < 0)
384 std::cerr <<
"Error: " << __FILE__ <<
":" << __LINE__ <<
" point is not inside the cell space\n";
386 key.
set_d(s,ConvertToID(pos,s));
406 std::cerr <<
"Error: " << __FILE__ <<
":" << __LINE__ <<
" using an uninitialized CellDecomposer\n";
410 key.
set_d(0,ConvertToID(pos,0));
412 for (
size_t s = 1 ; s < dim ; s++)
415 if ((
size_t)(t.transform(pos,s) / box_unit.getHigh(s)) + off[s] < 0)
416 std::cerr <<
"Error: " << __FILE__ <<
":" << __LINE__ <<
" point is not inside the cell space\n";
418 key.
set_d(s,ConvertToID(pos,s));
433 size_t getCell(
const T (& pos)[dim])
const
437 std::cerr <<
"Error: " << __FILE__ <<
":" << __LINE__ <<
" using an uninitialized CellDecomposer";
439 if (t.transform(pos,0) < box.getLow(0) || t.transform(pos,0) > box.getHigh(0))
440 std::cerr <<
"Error: " << __FILE__ <<
":" << __LINE__ <<
" point " << toPointString(pos) <<
" is not inside the cell space";
443 size_t cell_id = ConvertToID(pos,0);
445 for (
size_t s = 1 ; s < dim ; s++)
448 if (t.transform(pos,s) < box.getLow(s) || t.transform(pos,s) > box.getHigh(s))
449 std::cerr <<
"Error: " << __FILE__ <<
":" << __LINE__ <<
" point " << toPointString(pos) <<
" is not inside the cell space";
451 cell_id += gr_cell.size_s(s-1) * ConvertToID(pos,s);
470 std::cerr <<
"Error: " << __FILE__ <<
":" << __LINE__ <<
" using an uninitialized CellDecomposer";
472 if (t.transform(pos,0) < box.getLow(0) || t.transform(pos,0) > box.getHigh(0))
473 std::cerr <<
"Error: " << __FILE__ <<
":" << __LINE__ <<
" point " << pos.
toPointString() <<
" is not inside the cell space";
476 size_t cell_id = ConvertToID(pos,0);
478 for (
size_t s = 1 ; s < dim ; s++)
481 if (t.transform(pos,s) < box.getLow(s) || t.transform(pos,s) > box.getHigh(s))
482 std::cerr <<
"Error: " << __FILE__ <<
":" << __LINE__ <<
" point " << pos.
toPointString() <<
" is not inside the cell space";
484 cell_id += gr_cell.size_s(s-1) * ConvertToID(pos,s);
504 std::cerr <<
"Error: " << __FILE__ <<
":" << __LINE__ <<
" using an uninitialized CellDecomposer";
506 if (t.transform(pos,0) < box.getLow(0) || t.transform(pos,0) > box.getHigh(0))
507 std::cerr <<
"Error: " << __FILE__ <<
":" << __LINE__ <<
" point " << toPointString(pos) <<
" is not inside the cell space";
510 size_t cell_id = ConvertToID_(pos,0);
512 for (
size_t s = 1 ; s < dim ; s++)
515 if (t.transform(pos,s) < box.getLow(s) || t.transform(pos,s) > box.getHigh(s))
516 std::cerr <<
"Error: " << __FILE__ <<
":" << __LINE__ <<
" point " << toPointString(pos) <<
" is not inside the cell space";
518 cell_id += gr_cell.size_s(s-1) * ConvertToID_(pos,s);
569 bx.
setP2(getCellGrid(p2));
570 bx.
setP1(getCellGrid(p1));
582 void setDimensions(
const Box<dim,T> & box,
const size_t (&div)[dim],
const size_t pad)
585 this->gr_cell.setDimensions(div);
600 t.setTransform(mat,orig);
602 this->gr_cell.setDimensions(div);
637 :t(
Matrix<dim,T>::identity(),
Point<dim,T>::zero()),box(box),gr_cell()
673 :t(
Matrix<dim,T>::identity(),orig),box(box),gr_cell(div)
706 CellDecomposer_sm(
const SpaceBox<dim,T> & box,
const size_t (&div)[dim],
const size_t pad)
707 :t(
Matrix<dim,T>::identity(),
Point<dim,T>::zero_p()),box(box),gr_cell()
715 :t(
Matrix<dim,T>::identity(),
Point<dim,T>::zero_p()),tot_n_cell(0)
794 b /= getCellBox().getP2();
811 for (
size_t i = 0 ; i < dim ; i++)
817 g_box.
setHigh(i,gr_cell.size(i));
835 bool operator==(
const CellDecomposer_sm<dim,T,transform> & cd)
843 if (tot_n_cell != cd.tot_n_cell)
849 if (box_unit != cd.box_unit)
852 if (gr_cell != cd.gr_cell)
855 for (
size_t i = 0 ; i < dim ; i++)
857 if (off[i] != cd.off[i])
871 bool operator!=(
const CellDecomposer_sm<dim,T,transform> & cd)
873 return ! this->operator==(cd);
This class represent an N-dimensional box.
void setP1(const grid_key_dx< dim > &p1)
Set the point P1 of the box.
grid_key_dx is the key to access any element in the grid
T getHigh(int i) const
get the high interval of the box
void setHigh(int i, T val)
set the high interval of the box
shift(const Matrix< dim, T > &t, const Point< dim, T > &s)
Constructor.
This class implement the point shape in an N-dimensional space.
void setTransform(const Matrix< dim, T > &mat, const Point< dim, T > &orig)
Set the transformation Matrix and shift.
T transform(const T(&s)[dim], const size_t i) const
Shift the point transformation.
void setP2(const grid_key_dx< dim > &p2)
Set the point P2 of the box.
void ceilP1()
Translate P1 of a given vector P1.
T get(int i) const
Get coordinate.
void setDimensions(std::vector< size_t > &dims)
Reset the dimension of the grid.
This class implement an NxN (dense) matrix.
this structure encapsulate an object of the grid
This class is a trick to indicate the compiler a specific specialization pattern. ...
T transform(const encapc< 1, Point< dim, T >, Mem > &s, const size_t i) const
Shift the point transformation.
T transform(const Point< dim, T > &s, const size_t i) const
Shift the point transformation.
void ceilP2()
Translate P1 of a unit vector on all directions.
void set_d(size_t i, mem_id id)
Set the i index.
std::string toPointString() const
Convert the point into a string.
void shrinkP2(T sh)
Shrink moving p2 of sh quantity (on each direction)