Commit 1a387174 authored by incardon's avatar incardon
Browse files

Fixing symmetric

parent 121d1dfc
......@@ -357,6 +357,31 @@ class CellDecomposer_sm
return id;
}
/*! \brief Convert the coordinates into id without apply shift
*
* \param x coordinate
* \param s dimension
*
*/
inline size_t ConvertToID_ns(const T (&x)[dim] ,size_t s) const
{
size_t id = openfpm::math::size_t_floor(t.transform(x,s) / box_unit.getHigh(s)) + off[s];
id = (id >= gr_cell.size(s))?(gr_cell.size(s)-1):id;
return id;
}
/*! \brief Convert the coordinates into id without apply shift
*
* \param x point
* \param s dimension
*
*/
inline size_t ConvertToID_ns(const Point<dim,T> & x ,size_t s, size_t sc = 0) const
{
size_t id = openfpm::math::size_t_floor(t.transform(x,s) / box_unit.getHigh(s)) + off[s];
id = (id >= gr_cell.size(s))?(gr_cell.size(s)-1):id;
return id;
}
/*! \brief Convert the coordinates into id
*
......@@ -399,18 +424,50 @@ class CellDecomposer_sm
{
check_and_print_error(pos,0);
size_t cell_id = ConvertToID(pos,0);
cell_id = (cell_id == gr_cell2.size(0) - off[0])?gr_cell2.size(0) - off[0] - 1:cell_id;
size_t cell_id = ConvertToID_ns(pos,0);
cell_id = (cell_id == gr_cell.size(0) - off[0])?gr_cell.size(0) - off[0] - 1:cell_id;
cell_id = (cell_id == off[0]-1)?off[0]:cell_id;
cell_id -= cell_shift.get(0);
for (size_t s = 1 ; s < dim ; s++)
{
check_and_print_error(pos,s);
size_t cell_idt = ConvertToID(pos,s);
cell_idt = (cell_idt == gr_cell2.size(s) - off[s])?gr_cell2.size(s) - off[s] - 1:cell_idt;
size_t cell_idt = ConvertToID_ns(pos,s);
cell_idt = (cell_idt == gr_cell.size(s) - off[s])?gr_cell.size(s) - off[s] - 1:cell_idt;
cell_idt = (cell_idt == off[s]-1)?off[s]:cell_idt;
cell_idt -= cell_shift.get(s);
cell_id += gr_cell2.size_s(s-1) * cell_idt;
}
return cell_id;
}
template<typename Ele> inline size_t getCellPad_impl(const Ele & pos) const
{
check_and_print_error(pos,0);
size_t cell_id = ConvertToID_ns(pos,0);
cell_id = (cell_id == off[0])?off[0]-1:cell_id;
cell_id = (cell_id == gr_cell.size(0) - off[0] - 1)?gr_cell.size(0) - off[0]:cell_id;
cell_id -= cell_shift.get(0);
for (size_t s = 1 ; s < dim ; s++)
{
check_and_print_error(pos,s);
size_t cell_idt = ConvertToID_ns(pos,s);
cell_idt = (cell_idt == off[s])?off[s]-1:cell_idt;
cell_idt = (cell_idt == gr_cell.size(s) - off[s] - 1)?gr_cell.size(s) - off[s]:cell_idt;
cell_idt -= cell_shift.get(s);
cell_id += gr_cell2.size_s(s-1) * cell_idt;
}
......@@ -700,6 +757,38 @@ public:
return getCellDom_impl<T[dim]>(pos);
}
/*! \brief Get the cell-id enforcing that is from a padding cell
*
* Convert the point coordinates into the cell id
*
* \note this function is in general used to bypass round-off error
*
* \param pos Point position
*
* \return the cell-id
*
*/
inline size_t getCellPad(const Point<dim,T> & pos) const
{
return getCellPad_impl<Point<dim,T>>(pos);
}
/*! \brief Get the cell-id enforcing that is from a padding cell
*
* Convert the point coordinates into the cell id
*
* \note this function is in general used to bypass round-off error
*
* \param pos Point position
*
* \return the cell-id
*
*/
inline size_t getCellPad(const T (& pos)[dim]) const
{
return getCellPad_impl<T[dim]>(pos);
}
/*! \brief Get the cell-id
*
* Convert the point coordinates into the cell id
......@@ -895,13 +984,13 @@ public:
Initialize(pad,div);
// calculate the box for gr_cell2
Box<dim,T> box_gr_cell2;
/* Box<dim,T> box_gr_cell2;
for (size_t i = 0 ; i < dim ; i++)
{
box_gr_cell2.setLow(i,cell_shift.get(i) * box_unit.getHigh(i));
box_gr_cell2.setHigh(i,(cell_shift.get(i) + div2[i]) * box_unit.getHigh(i));
}
}*/
size_t cells[dim];
......@@ -1179,7 +1268,7 @@ Box "b" <-----------------+ | | | | | | Grid (7, 6)
\verbatim
It return a Box with P1 = (0,2), P2 = (4,5)
It return a Box with P1 = (0,2), P2 = (3,4)
*
* \param b Box in domain space
......@@ -1392,6 +1481,43 @@ Box "b" <-----------------+ | | | | | | Grid (7, 6)
return g_box;
}
inline Box<dim,long int> convertDomainSpaceIntoCellUnitsNear(const Box<dim,T> & b_d) const
{
Box<dim,long int> g_box;
Box<dim,T> b = b_d;
b -= getOrig();
// Convert b into grid units
b /= getCellBox().getP2();
// Considering that we are interested in a box decomposition of the space
// where each box does not intersect any other boxes in the decomposition we include the negative
// countour and exclude the positive one. So ceilP1 do the job for P1 while ceilP2 - 1
// do the job for P2
for (size_t i = 0 ; i < dim ; i++)
{
b.setLow(i,b.getLow(i) + 0.125);
b.setHigh(i,b.getHigh(i) + 0.125);
}
b.floorP1();
b.floorP2();
g_box = b;
// Translate the box by the offset
for (size_t i = 0 ; i < dim ; i++)
{
g_box.setLow(i,g_box.getLow(i) + off[i]);
g_box.setHigh(i,g_box.getHigh(i) + off[i]);
}
return g_box;
}
/*! \brief Convert a Box in grid units into the domain space (Negative contour included, positive contour excluded)
*
* Given the following
......
......@@ -172,8 +172,10 @@ BOOST_AUTO_TEST_CASE( CellDecomposer_use )
{
CellDecomposer_sm<3,double> cd(box,div,1);
size_t cell_cor_dom = cd.getCellDom(Point<3,double>({-0.000001,-0.000001,-0.000001}));
size_t cell_cor_pad = cd.getCellPad(Point<3,double>({0.000001,0.000001,0.000001}));
size_t cell_not_cor_pad1 = cd.getCell(Point<3,double>({-0.000001,-0.000001,-0.000001}));
size_t cell_not_cor_pad2 = cd.getCell(Point<3,double>({0.000001,0.000001,0.000001}));
BOOST_REQUIRE_EQUAL(cell_cor_pad,0ul);
BOOST_REQUIRE_EQUAL(cell_cor_dom,(size_t)(1*18*18 + 1*18 + 1));
BOOST_REQUIRE_EQUAL(cell_not_cor_pad1,0ul);
BOOST_REQUIRE_EQUAL(cell_not_cor_pad2,(size_t)(1*18*18 + 1*18 + 1));
......
......@@ -54,7 +54,6 @@ template<unsigned int dim> void NNcalc_csr(openfpm::vector<std::pair<grid_key_dx
typedef typename generate_array<size_t,dim, Fill_zero>::result NNzero;
typedef typename generate_array<size_t,dim, Fill_two>::result NNtwo;
typedef typename generate_array<size_t,dim, Fill_one>::result NNone;
// Generate the sub-grid iterator
......@@ -121,7 +120,6 @@ template<unsigned int dim> void NNcalc_sym(openfpm::vector<grid_key_dx<dim>> & c
typedef typename generate_array<size_t,dim, Fill_zero>::result NNzero;
typedef typename generate_array<size_t,dim, Fill_two>::result NNtwo;
typedef typename generate_array<size_t,dim, Fill_one>::result NNone;
// Generate the sub-grid iterator
......@@ -173,7 +171,6 @@ template<unsigned int dim> void NNcalc_full(openfpm::vector<grid_key_dx<dim>> &
typedef typename generate_array<size_t,dim, Fill_zero>::result NNzero;
typedef typename generate_array<size_t,dim, Fill_two>::result NNtwo;
typedef typename generate_array<size_t,dim, Fill_one>::result NNone;
// Generate the sub-grid iterator
......@@ -463,12 +460,7 @@ public:
void setCellDecomposer(CellDecomposer_sm<dim,T,transform> & cd, const CellDecomposer_sm<dim,T,transform> & cd_sm, const Box<dim,T> & dom_box, size_t pad) const
{
size_t bc[dim];
for (size_t i = 0 ; i < dim ; i++)
bc[i] = NON_PERIODIC;
Box<dim,long int> bx = cd_sm.convertDomainSpaceIntoCellUnits(dom_box,bc);
Box<dim,long int> bx = cd_sm.convertDomainSpaceIntoCellUnitsNear(dom_box);
size_t div[dim];
size_t div_big[dim];
......@@ -498,10 +490,7 @@ public:
*/
void Initialize(CellDecomposer_sm<dim,T,transform> & cd_sm, const Box<dim,T> & dom_box,const size_t pad = 1, size_t slot=STARTING_NSLOT)
{
size_t bc[dim];
for (size_t i = 0 ; i < dim ; i++) {bc[i] = NON_PERIODIC;}
Box<dim,long int> bx = cd_sm.convertDomainSpaceIntoCellUnits(dom_box,bc);
Box<dim,long int> bx = cd_sm.convertDomainSpaceIntoCellUnitsNear(dom_box);
setCellDecomposer(*this,cd_sm,dom_box,pad);
......@@ -805,6 +794,44 @@ public:
addCell(cell_id,ele);
}
/*! \brief Add an element in the cell list forcing to be in the padding cells
*
* \warning careful is intended to be used ONLY to avoid round-off problems
*
* \param pos array that contain the coordinate
* \param ele element to store
*
*/
inline void addPad(const T (& pos)[dim], typename base::value_type ele)
{
// calculate the Cell id
size_t cell_id = this->getCell(pos);
// add the element to the cell
addCell(cell_id,ele);
}
/*! \brief Add an element in the cell list forcing to be in the padding cells
*
* \warning careful is intended to be used ONLY to avoid round-off problems
*
* \param pos array that contain the coordinate
* \param ele element to store
*
*/
inline void addPad(const Point<dim,T> & pos, typename base::value_type ele)
{
// calculate the Cell id
size_t cell_id = this->getCell(pos);
// add the element to the cell
addCell(cell_id,ele);
}
/*! \brief remove an element from the cell
*
* \param cell cell id
......
......@@ -54,7 +54,7 @@ template<unsigned int dim, typename T, typename CellList> void populate_cell_lis
for (size_t i = g_m; i < pos.size() ; i++)
{
cli.add(pos.get(i), i);
cli.addPad(pos.get(i), i);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment