Commit 25269e3e authored by incardon's avatar incardon

Fixing iterators

parent cdd40c06
......@@ -3,7 +3,7 @@
AC_PREREQ(2.59)
AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)
AC_INIT(OpenFPM_data, 0.8.0, BUG-REPORT-ADDRESS)
AC_CANONICAL_SYSTEM
AC_CONFIG_SRCDIR([src/main.cpp])
......
......@@ -47,6 +47,41 @@ class grid_key_dx_iterator_sub_bc : public grid_key_dx_iterator_sub<dim,warn>
public:
grid_key_dx_iterator_sub_bc(const grid_key_dx_iterator_sub_bc & tmp)
{
this->operator=(tmp);
}
grid_key_dx_iterator_sub_bc(grid_key_dx_iterator_sub_bc && tmp)
{
this->operator=(tmp);
}
grid_key_dx_iterator_sub_bc & operator=(const grid_key_dx_iterator_sub_bc & tmp)
{
for (size_t i = 0 ; i < dim ; i++)
bc[i] = tmp.bc[i];
act = tmp.act;
boxes = tmp.boxes;
return *this;
}
grid_key_dx_iterator_sub_bc & operator=(grid_key_dx_iterator_sub_bc && tmp)
{
for (size_t i = 0 ; i < dim ; i++)
bc[i] = tmp.bc[i];
act = tmp.act;
boxes.swap(tmp.boxes);
return *this;
}
/*! \brief Constructor
*
*
......
......@@ -38,6 +38,8 @@
\endverbatim
*
* \warning A MUST BE fully contained into B
*
* The skin is the part in between the two boxes A and B
*
......@@ -51,9 +53,12 @@
template<unsigned int dim>
class grid_skin_iterator_bc
{
protected:
//! Internal iterator for each faces
grid_key_dx_iterator_sub_bc<dim> sub_it[2*dim];
private:
//! Actual iterator
size_t act;
......@@ -67,7 +72,7 @@ public:
* \param bc boundary conditions
*
*/
template <typename T> grid_skin_iterator_bc(grid_sm<dim,T> & g_sm, const Box<dim,size_t> & A, const Box<dim,size_t> & B, const size_t (& bc)[dim])
template <typename T> grid_skin_iterator_bc(const grid_sm<dim,T> & g_sm, const Box<dim,size_t> & A, const Box<dim,size_t> & B, const size_t (& bc)[dim])
:act(0)
{
for (size_t i = 0 ; i < dim ; i++)
......
......@@ -18,7 +18,7 @@ struct is_grid: std::false_type {};
*
* ### Example
*
* \snippet util.hpp Check is_grid
* \snippet util_test.hpp Check is_grid
*
* return true if T is a grid
*
......
......@@ -677,6 +677,7 @@ public:
ACTION_ON_ERROR(CELL_DECOMPOSER);
}
#endif
/* coverity[dead_error_line] */
key.set_d(s,ConvertToID(pos,s));
}
......@@ -1298,6 +1299,7 @@ Box "b" <-----------------+ | | | | | | Grid (7, 6)
/////////// Low boundary
// we are at the positive border (We are assuming that there are not rounding error in the decomposition)
/* coverity[copy_paste_error] */
if (b_d.getHigh(i) == box.getLow(i))
g_box.setHigh(i,off[i]);
......@@ -1418,6 +1420,7 @@ Box "b" <-----------------+ | | | | | | Grid (7, 6)
/////////// Low boundary
// we are at the positive border (We are assuming that there are not rounding error in the decomposition)
/* coverity[copy_paste_error] */
if (b_d.getHigh(i) == box.getLow(i))
g_box.setHigh(i,off[i]);
......
......@@ -339,6 +339,8 @@ private:
public:
typedef CellNNIteratorSym<dim,CellList<dim,T,FAST,transform,base>,RUNTIME,NO_CHECK> SymNNIterator;
//! Object type that the structure store
typedef typename base::value_type value_type;
......@@ -434,6 +436,7 @@ public:
// create the array that store the number of particle on each cell and se it to 0
InitializeStructures(this->gr_cell.getSize(),this->gr_cell.size());
from_cd = false;
}
//! Default Constructor
......
......@@ -154,8 +154,6 @@ BOOST_AUTO_TEST_CASE( ParticleIt_Cells_iterator )
while (it_cl.isNext())
{
auto p_key = it_cl.get();
count++;
++it_cl;
}
......@@ -211,8 +209,6 @@ BOOST_AUTO_TEST_CASE( ParticleIt_Cells_iterator )
while (it_cl2.isNext())
{
auto p_key = it_cl2.get();
count++;
++it_cl2;
}
......@@ -247,8 +243,6 @@ BOOST_AUTO_TEST_CASE( ParticleIt_Cells_NN_iterator )
NN.Initialize(box,div,1);
float pos[dim];
grid_key_dx_iterator<3> it(gs2);
float spacing[dim];
......@@ -321,7 +315,6 @@ BOOST_AUTO_TEST_CASE( ParticleIt_Cells_NN_iterator )
while (it_cl.isNext())
{
auto p_key = it_cl.get();
auto NN_it = it_cl.getNNIteratorCSR(vp);
size_t size_NN = 0;
......
......@@ -59,6 +59,8 @@ class CellListM : public CellBase
public:
typedef CellNNIteratorSymM<dim,CellListM<dim,T,sh_byte,CellBase>,sh_byte,RUNTIME,NO_CHECK> SymNNIterator;
//! Default Constructor
CellListM()
{};
......@@ -260,36 +262,9 @@ public:
* \return Cell-list structure
*
*/
template<unsigned int impl> inline CellNNIteratorM<dim,CellListM<dim,T,sh_byte,CellBase>,sh_byte,SYM,impl> getNNIteratorSym(size_t cell)
{
CellNNIteratorM<dim,CellListM<dim,T,sh_byte,CellBase>,sh_byte,SYM,impl> cln(cell,CellListM<dim,T,sh_byte,CellBase>::NNc_sym,*this);
return cln;
}
/*! \brief Get the Neighborhood iterator
*
* It iterate across all the element of the selected cell and the near cells
*
* \verbatim
* *
x *
\endverbatim
*
* * x is the selected cell
* * * are the near cell
*
* \param cell cell id
*
* \return Cell-list structure
*
*/
template<unsigned int impl> inline CellNNIteratorM<dim,CellListM<dim,T,sh_byte,CellBase>,sh_byte,CRS,impl> getNNIteratorCross(size_t cell)
template<unsigned int impl> inline CellNNIteratorSymM<dim,CellListM<dim,T,sh_byte,CellBase>,sh_byte,SYM,impl> getNNIteratorSym(size_t cell,size_t p, const openfpm::vector<Point<dim,typename CellBase::stype>> & v)
{
CellNNIteratorM<dim,CellListM<dim,T,sh_byte,CellBase>,sh_byte,CRS,impl> cln(cell,CellListM<dim,T,sh_byte,CellBase>::NNc_cr,*this);
CellNNIteratorSymM<dim,CellListM<dim,T,sh_byte,CellBase>,sh_byte,SYM,impl> cln(cell,p,CellListM<dim,T,sh_byte,CellBase>::NNc_sym,*this,v);
return cln;
}
......
......@@ -306,7 +306,7 @@ template<unsigned int dim, typename T, typename CellS> void Test_cell_sM(SpaceBo
}
// Create a grid iterator
/* // Create a grid iterator
grid_key_dx<dim> p1(1,1,1);
grid_key_dx<dim> p2(div[0]-2,div[1]-2,div[2]-2);
grid_key_dx_iterator_sub<dim> g_it_s(g_info,p1,p2);
......@@ -336,7 +336,7 @@ template<unsigned int dim, typename T, typename CellS> void Test_cell_sM(SpaceBo
BOOST_REQUIRE_EQUAL(total2,(size_t)openfpm::math::pow(3,dim));
auto NNSym = cl1.template getNNIteratorSym<NO_CHECK>(cl1.getCell(key));
auto NNSym = cl1.template getNNIteratorSym<NO_CHECK>(cl1.getCell(key),);
total1 = 0;
total2 = 0;
......@@ -356,7 +356,7 @@ template<unsigned int dim, typename T, typename CellS> void Test_cell_sM(SpaceBo
BOOST_REQUIRE_EQUAL(total2,(size_t)openfpm::math::pow(3,dim) / 2 + 1);
++g_it_s;
}
}*/
}
template<typename CellList> void Test_CellDecomposer_consistent()
......
......@@ -309,4 +309,6 @@ public:
}
};
#include "CellNNIteratorRuntime.hpp"
#endif /* CELLNNITERATOR_FULL_HPP_ */
......@@ -13,6 +13,61 @@
#include <boost/integer/integer_mask.hpp>
/*! \brief Iterator for the neighborhood of the cell structures
*
* In general you never create it directly but you get it from the CellList structures
*
* It iterate across all the element of the selected cell and the near cells accordingly yo the
* symmetric scheme
*
* \tparam dim dimensionality of the space where the cell live
* \tparam Cell cell type on which the iterator is working
* \tparam NNc_size neighborhood size
* \tparam impl implementation specific options NO_CHECK do not do check on access, SAFE do check on access
*
*/
template<unsigned int dim, typename Cell, unsigned int sh_byte,unsigned int NNc_size, unsigned int impl>
class CellNNIteratorSymM : public CellNNIteratorSym<dim,Cell,NNc_size,impl>
{
typedef boost::low_bits_mask_t<sizeof(size_t)*8-sh_byte> mask_low;
public:
/*! \brief
*
* Cell NN iterator
*
* \param cell Cell id
* \param NNc Cell neighborhood indexes (relative)
* \param cl Cell structure
*
*/
CellNNIteratorSymM(size_t cell, size_t p, const long int (&NNc)[NNc_size], Cell & cl, const openfpm::vector<Point<dim,typename Cell::stype>> & pos)
:CellNNIteratorSym<dim,Cell,NNc_size,impl>(cell,p,NNc,cl,pos)
{}
/*! \brief Get the value of the cell
*
* \return the next element object
*
*/
inline size_t getP()
{
return CellNNIteratorSym<dim,Cell,NNc_size,impl>::get() & mask_low::sig_bits_fast;
}
/*! \brief Get the value of the cell
*
* \return the next element object
*
*/
inline size_t getV()
{
return (CellNNIteratorSym<dim,Cell,NNc_size,impl>::get()) >> (sizeof(size_t)*8-sh_byte);
}
};
/*! \brief Iterator for the neighborhood of the cell structures
*
* In general you never create it directly but you get it from the CellList structures
......@@ -111,5 +166,6 @@ public:
}
};
#include "CellNNIteratorRuntimeM.hpp"
#endif /* OPENFPM_DATA_SRC_NN_CELLLIST_CELLNNITERATORM_HPP_ */
......@@ -163,6 +163,12 @@ public:
else
{
dom_or_anom = 2;
start = NULL;
stop = NULL;
NNc = NULL;
NNc_size = 0;
return;
}
......@@ -224,12 +230,35 @@ public:
* \return Return an iterator over the neighborhood particles
*
*/
CellNNIteratorSym<dim,CellListType,RUNTIME,NO_CHECK> getNNIteratorCSR(const openfpm::vector<Point<dim,typename CellListType::stype>> & v) const
/* CellNNIteratorSym<dim,CellListType,RUNTIME,NO_CHECK> getNNIteratorCSR(const openfpm::vector<Point<dim,typename CellListType::stype>> & v) const
{
if (dom_or_anom == 0)
return CellNNIteratorSym<dim,CellListType,RUNTIME,NO_CHECK>(dom_cell.get(cid),*start,NNc_sym,openfpm::math::pow(3,dim)/2+1,cli,v);
else
return CellNNIteratorSym<dim,CellListType,RUNTIME,NO_CHECK>(anom_dom_cell.get(cid).subsub,*start,&anom_dom_cell.get(cid).NN_subsub.get(0),anom_dom_cell.get(cid).NN_subsub.size(),cli,v);
}*/
/*! \brief Get the neighborhood iterator according to the CRS scheme
*
* The CRS scheme use differen neighborhood based on where the cell
* is positioned in the processor domain
*
*
* * * *
* x * for a cell x in the center of the domain
*
* *
* x for a cell in the outside right
*
* \return Return an iterator over the neighborhood particles
*
*/
typename CellListType::SymNNIterator getNNIteratorCSR(const openfpm::vector<Point<dim,typename CellListType::stype>> & v) const
{
if (dom_or_anom == 0)
return typename CellListType::SymNNIterator(dom_cell.get(cid),*start,NNc_sym,openfpm::math::pow(3,dim)/2+1,cli,v);
else
return typename CellListType::SymNNIterator(anom_dom_cell.get(cid).subsub,*start,&anom_dom_cell.get(cid).NN_subsub.get(0),anom_dom_cell.get(cid).NN_subsub.size(),cli,v);
}
};
......
......@@ -197,9 +197,6 @@ class VerletList<dim,T,FAST,transform,CellListImpl>
{
protected:
private:
//! Number of slot for each particle. Or maximum number of particles for each particle
size_t slot;
......@@ -210,6 +207,9 @@ private:
//! of elements == slot)
openfpm::vector<size_t> cl_base;
private:
//! Interlal cell-list
CellListImpl cli;
......@@ -253,6 +253,7 @@ private:
/*! \brief Create the Verlet list from a given cell-list
*
* \param pos vector of positions
* \param pos2 vector of positions of neighborhood particles
* \param r_cut cut-off radius to get the neighborhood particles
* \param g_m Indicate form which particles to construct the verlet list. For example
* if we have 120 particles and g_m = 100, the Verlet list will be constructed only for the first
......@@ -261,25 +262,26 @@ private:
* \param opt options to create the verlet list like VL_SYMMETRIC or VL_NON_SYMMETRIC
*
*/
inline void create(const openfpm::vector<Point<dim,T>> & pos, const openfpm::vector<size_t> & dom, const openfpm::vector<subsub_lin<dim>> & anom, T r_cut, size_t g_m, CellListImpl & cl, size_t opt)
inline void create(const openfpm::vector<Point<dim,T>> & pos, const openfpm::vector<Point<dim,T>> & pos2, const openfpm::vector<size_t> & dom, const openfpm::vector<subsub_lin<dim>> & anom, T r_cut, size_t g_m, CellListImpl & cl, size_t opt)
{
if (opt == VL_CRS_SYMMETRIC)
{
create_<CellNNIteratorSym<dim,CellListImpl,RUNTIME,NO_CHECK>,VL_CRS_SYMMETRIC>(pos,dom,anom,r_cut,g_m,cl,opt);
create_<CellNNIteratorSym<dim,CellListImpl,RUNTIME,NO_CHECK>,VL_CRS_SYMMETRIC>(pos,pos2,dom,anom,r_cut,g_m,cl,opt);
}
else if (opt == VL_SYMMETRIC)
{
create_<decltype(cl.template getNNIteratorSym<NO_CHECK>(0,0,pos)),VL_SYMMETRIC>(pos,dom,anom,r_cut,g_m,cl,opt);
create_<decltype(cl.template getNNIteratorSym<NO_CHECK>(0,0,pos)),VL_SYMMETRIC>(pos,pos2,dom,anom,r_cut,g_m,cl,opt);
}
else
{
create_<decltype(cl.template getNNIterator<NO_CHECK>(0)),VL_NON_SYMMETRIC>(pos,dom,anom,r_cut,g_m,cl,opt);
create_<decltype(cl.template getNNIterator<NO_CHECK>(0)),VL_NON_SYMMETRIC>(pos,pos2,dom,anom,r_cut,g_m,cl,opt);
}
}
/*! \brief Create the Verlet list from a given cell-list
*
* \param pos vector of positions
* \param pos2 vector of position for the neighborhood
* \param r_cut cut-off radius to get the neighborhood particles
* \param g_m Indicate form which particles to construct the verlet list. For example
* if we have 120 particles and g_m = 100, the Verlet list will be constructed only for the first
......@@ -290,7 +292,7 @@ private:
* \param opt options
*
*/
template<typename NN_type, int type> inline void create_(const openfpm::vector<Point<dim,T>> & pos, const openfpm::vector<size_t> & dom, const openfpm::vector<subsub_lin<dim>> & anom, T r_cut, size_t g_m, CellListImpl & cli, size_t opt)
template<typename NN_type, int type> inline void create_(const openfpm::vector<Point<dim,T>> & pos, const openfpm::vector<Point<dim,T>> & pos2 , const openfpm::vector<size_t> & dom, const openfpm::vector<subsub_lin<dim>> & anom, T r_cut, size_t g_m, CellListImpl & cli, size_t opt)
{
size_t end;
......@@ -316,7 +318,7 @@ private:
{
auto nnp = NN.get();
Point<dim,T> xq = pos.template get<0>(nnp);
Point<dim,T> xq = pos2.template get<0>(nnp);
if (xp.distance2(xq) < r_cut2)
addPart(i,nnp);
......@@ -371,7 +373,25 @@ private:
}
}
/*! \brief Add to the cell
public:
//! Object type that the structure store
typedef size_t value_type;
//! CellList implementation used for Verlet list construction
typedef CellListImpl CellListImpl_;
/*! \brief Return for how many particles has been constructed this verlet list
*
* \return number of particles
*
*/
size_t size()
{
return cl_n.size();
}
/*! \brief Add a neighborhood particle to a particle
*
* \param part_id part id where to add
* \param ele element to add
......@@ -392,22 +412,6 @@ private:
cl_n.get(part_id)++;
}
public:
//! Object type that the structure store
typedef size_t value_type;
/*! \brief Return for how many particles has been constructed this verlet list
*
* \return number of particles
*
*/
size_t size()
{
return cl_n.size();
}
/*! Initialize the verlet list
*
* \param box Domain where this cell list is living
......@@ -439,7 +443,7 @@ public:
openfpm::vector<size_t> dom_c;
// create verlet
create(pos,dom_c,anom_c,r_cut,g_m,cli,opt);
create(pos, pos,dom_c,anom_c,r_cut,g_m,cli,opt);
}
/*! \brief Initialize the symmetric Verlet-list
......@@ -474,7 +478,7 @@ public:
openfpm::vector<size_t> dom_c;
// create verlet
create(pos,dom_c,anom_c,r_cut,g_m,cli,VL_SYMMETRIC);
create(pos, pos,dom_c,anom_c,r_cut,g_m,cli,VL_SYMMETRIC);
}
......@@ -521,7 +525,7 @@ public:
void createVerletCrs(T r_cut, size_t g_m, openfpm::vector<Point<dim,T>> & pos, openfpm::vector<size_t> & dom_c, openfpm::vector<subsub_lin<dim>> & anom_c)
{
// create verlet
create(pos,dom_c,anom_c,r_cut,g_m,cli,VL_CRS_SYMMETRIC);
create(pos, pos,dom_c,anom_c,r_cut,g_m,cli,VL_CRS_SYMMETRIC);
}
/*! \brief update the Verlet list
......@@ -541,7 +545,7 @@ public:
openfpm::vector<subsub_lin<dim>> anom_c;
openfpm::vector<size_t> dom_c;
create(pos,dom_c,anom_c,r_cut,g_m,cli,opt);
create(pos, pos,dom_c,anom_c,r_cut,g_m,cli,opt);
}
/*! \brief update the Verlet list
......@@ -556,7 +560,7 @@ public:
{
initCl(cli,pos,g_m,VL_CRS_SYMMETRIC);
create(pos,dom_c,anom_c,r_cut,g_m,cli,VL_CRS_SYMMETRIC);
create(pos,pos,dom_c,anom_c,r_cut,g_m,cli,VL_CRS_SYMMETRIC);
}
/*! Initialize the verlet list from an already filled cell-list
......@@ -564,13 +568,14 @@ public:
* \param cli external Cell-list
* \param r_cut cutoff-radius
* \param pos vector of particle positions
* \param pos2 vector of particle position for the neighborhood
* \param g_m Indicate form which particles to construct the verlet list. For example
* if we have 120 particles and g_m = 100, the Verlet list will be constructed only for the first
* 100 particles
* \param opt options for the Verlet-list creation
*
*/
void Initialize(CellListImpl & cli, T r_cut, const openfpm::vector<Point<dim,T>> & pos, size_t g_m, size_t opt = VL_NON_SYMMETRIC)
void Initialize(CellListImpl & cli, T r_cut, const openfpm::vector<Point<dim,T>> & pos, const openfpm::vector<Point<dim,T>> & pos2, size_t g_m, size_t opt = VL_NON_SYMMETRIC)
{
cl_n.resize(g_m);
cl_base.resize(g_m*slot);
......@@ -588,14 +593,14 @@ public:
openfpm::vector<subsub_lin<dim>> anom_c;
openfpm::vector<size_t> dom_c;
create(pos,dom_c,anom_c,r_cut,g_m,cli,opt);
create(pos,pos2,dom_c,anom_c,r_cut,g_m,cli,opt);
}
else
{
openfpm::vector<subsub_lin<dim>> anom_c;
openfpm::vector<size_t> dom_c;
create_<decltype(cli.template getNNIteratorRadius<NO_CHECK>(0,0.0)),WITH_RADIUS>(pos,dom_c,anom_c,r_cut,g_m,cli,VL_NON_SYMMETRIC);
create_<decltype(cli.template getNNIteratorRadius<NO_CHECK>(0,0.0)),WITH_RADIUS>(pos,pos2,dom_c,anom_c,r_cut,g_m,cli,VL_NON_SYMMETRIC);
}
}
......
......@@ -10,6 +10,21 @@
#include "NN/VerletList/VerletNNIteratorM.hpp"
/*! \brief Structure that contain a reference to a vector of particles
*
*
*/
template<unsigned int dim, typename T>
struct pos_v
{
const openfpm::vector<Point<dim,T>> & pos;
pos_v(const openfpm::vector<Point<dim,T>> & pos)
:pos(pos)
{}
};
/*! \brief Class for Verlet list implementation with Multiphase
*
* \tparam dim Dimensionality of the space
......@@ -17,7 +32,7 @@
* \tparam CellListImpl Base structure that store the information
*
*/
template<unsigned int dim, typename T, unsigned int sh_byte , typename transform = shift<dim,T>, typename VerletBase=VerletList<dim,T,FAST,transform> >
template<unsigned int dim, typename T, unsigned int sh_byte , typename CellListImpl, typename transform = shift<dim,T>, typename VerletBase=VerletList<dim,T,FAST,transform> >
class VerletListM : public VerletBase
{
......@@ -27,8 +42,143 @@ class VerletListM : public VerletBase
//! Mask to get the low bits of a number
typedef boost::low_bits_mask_t<sizeof(size_t)*8-sh_byte> mask_low;
/*! \brief Create the Verlet list from a given cell-list
*
* \param pos vector of positions
* \param pos2 vector of neighborhood particles position
* \param r_cut cut-off radius to get the neighborhood particles
* \param g_m Indicate form which particles to construct the verlet list. For example
* if we have 120 particles and g_m = 100, the Verlet list will be constructed only for the first
* 100 particles
* \param cl Cell-list elements to use to construct the verlet list
* \param opt options to create the verlet list like VL_SYMMETRIC or VL_NON_SYMMETRIC
*
*/
inline void create(const openfpm::vector<Point<dim,T>> & pos,
const openfpm::vector<pos_v<dim,T>> & pos2 ,
const openfpm::vector<size_t> & dom,
const openfpm::vector<subsub_lin<dim>> & anom,
T r_cut,
size_t g_m,
CellListImpl & cl,
size_t opt)
{
if (opt == VL_CRS_SYMMETRIC)
{
create_<CellNNIteratorSymM<dim,CellListImpl,sh_byte,RUNTIME,NO_CHECK>,VL_CRS_SYMMETRIC>(pos,pos2,dom,anom,r_cut,g_m,cl,opt);
}
else if (opt == VL_SYMMETRIC)
{
create_<decltype(cl.template getNNIteratorSym<NO_CHECK>(0,0,pos)),VL_SYMMETRIC>(pos,pos2,dom,anom,r_cut,g_m,cl,opt);
}
else