Commit f69197c0 authored by incardon's avatar incardon
Browse files

Adding Cell particle iterator

parent b7262515
......@@ -16,8 +16,9 @@
#include "CellListIterator.hpp"
#include "CellListNNIteratorRadius.hpp"
#include <unordered_map>
#include "ParticleItCRS_Cells.hpp"
#include "util/common.hpp"
#include "ParticleIt_Cells.hpp"
//! Wrapper of the unordered map
template<typename key,typename val>
......
......@@ -10,6 +10,29 @@
#include "NN/CellList/CellListIterator.hpp"
#include "NN/CellList/CellListFast_hilb.hpp"
#include "NN/CellList/ParticleIt_Cells.hpp"
/*! \brief Fill the cell-list with particles in the box 0.0,1.0
*
* \param k Number of particles
* \param NN Cell-list
*
*/
template<unsigned int dim, typename CellList> void FillCellList(size_t k, CellList & NN)
{
float pos[dim];
//Fill with particles
for (size_t i = 0; i < k; i++)
{
for (size_t j = 0; j < dim; j++)
{
pos[j] = rand()/double(RAND_MAX);
}
NN.add(pos,i);
}
}
BOOST_AUTO_TEST_SUITE( celllist_hilb_and_iterator_tests )
......@@ -39,17 +62,8 @@ BOOST_AUTO_TEST_CASE( celllist_hilb_and_iterator_test )
NN.Initialize(box,div,k*0.9,1);
float pos[dim];
FillCellList<dim>((size_t)k*0.9,NN);
//Fill with particles
for (size_t i = 0; i < k*0.9; i++)
{
for (size_t j = 0; j < dim; j++)
{
pos[j] = rand()/double(RAND_MAX);
}
NN.add(pos,i);
}
//Test the iterator
auto it_cl = NN.getIterator();
......@@ -88,7 +102,7 @@ BOOST_AUTO_TEST_CASE( celllist_hilb_and_iterator_test )
BOOST_REQUIRE_EQUAL(s1,s2);
}
BOOST_AUTO_TEST_CASE( ParticleIt_Cells_iterator )
BOOST_AUTO_TEST_CASE( ParticleItCRS_Cells_iterator )
{
///////// INPUT DATA //////////
......@@ -117,17 +131,9 @@ BOOST_AUTO_TEST_CASE( ParticleIt_Cells_iterator )
NN.Initialize(box,div,1);
float pos[dim];
FillCellList<dim>(k,NN);
//Fill with particles
for (size_t i = 0; i < k; i++)
{
for (size_t j = 0; j < dim; j++)
{
pos[j] = rand()/double(RAND_MAX);
}
NN.add(pos,i);
}
float pos[dim];
grid_key_dx<3> start(0,0,0);
grid_key_dx<3> stop(div[2]-1+2*NN.getPadding(2),div[1]-1+2*NN.getPadding(1),div[0]-1+2*NN.getPadding(0));
......@@ -335,6 +341,59 @@ BOOST_AUTO_TEST_CASE( ParticleIt_Cells_NN_iterator )
BOOST_REQUIRE_EQUAL(count,(div[0]-2)*(div[1]-2)*(div[2]-2));
}
BOOST_AUTO_TEST_CASE( ParticleIt_Cells_iterator )
{
///////// INPUT DATA //////////
const size_t dim = 3;
size_t div[dim] = {4,5,6};
size_t div_p[dim] = {6,7,8};
grid_sm<3,void> gs(div_p);
//Number of particles
size_t k = 300;
///////////////////////////////
Box<dim,float> box;
for (size_t i = 0; i < dim; i++)
{
box.setLow(i,0.0);
box.setHigh(i,1.0);
}
// Initialize a cell list
CellList<dim,float,FAST,shift<dim,float>> NN;
NN.Initialize(box,div,1);
FillCellList<dim>(k,NN);
grid_key_dx<3> start(0,0,0);
grid_key_dx<3> stop(div[2]-1+2*NN.getPadding(2),div[1]-1+2*NN.getPadding(1),div[0]-1+2*NN.getPadding(0));
// No anomalous cells + all domain cells
grid_key_dx_iterator_sub<dim> it(gs,start,stop);
//Test the iterator
ParticleIt_Cells<dim,CellList<dim,float,FAST,shift<dim,float>>,grid_key_dx_iterator_sub<dim>> it_cl(NN,it);
size_t count = 0;
while (it_cl.isNext())
{
count++;
++it_cl;
}
BOOST_REQUIRE_EQUAL(count,k);
}
BOOST_AUTO_TEST_SUITE_END()
#endif /* OPENFPM_DATA_SRC_NN_CELLLIST_CELLLISTITERATOR_TEST_HPP_ */
/*
* CellListIterator_CRS.hpp
* ParticleIt_Cells.hpp
*
* Created on: Nov 14, 2016
* Created on: Mar 5, 2017
* Author: i-bird
*/
#ifndef OPENFPM_DATA_SRC_NN_CELLLIST_PARTICLEIT_CELLS_HPP_
#define OPENFPM_DATA_SRC_NN_CELLLIST_PARTICLEIT_CELLS_HPP_
#include "CellNNIteratorRuntime.hpp"
#include "CellList_util.hpp"
/*! \brief sub-sub-domain
*
* \tparam dim dimensionality
*
*/
template<unsigned int dim>
struct subsub
{
//! sub-sub-domain
grid_key_dx<dim> subsub;
//! Neighborhood of each sub-sub-domains
openfpm::vector<grid_key_dx<dim>> NN_subsub;
};
/*! \brief Linearized version of subsub
*
* \tparam dim dimensionality
*
*/
template<unsigned int dim>
struct subsub_lin
{
//! sub-sub-domain
size_t subsub;
//! Neighborhood of each sub-sub-domains (indicate the relative position compared to subsub)
openfpm::vector<long int> NN_subsub;
};
/*! \brief This iterator iterate across the particles of a Cell-list following the Cell structure
*
*
* \tparam dim Dimensionality
* \tparam CellListType type of the cell-list
* \tparam CellIterator type of iterator over the cell
*
*/
template<unsigned int dim,typename CellListType> class ParticleItCRS_Cells
template<unsigned int dim,typename CellListType, typename CellIt> class ParticleIt_Cells
{
private:
......@@ -58,81 +26,34 @@ private:
//! stop position
const size_t * stop;
//! Actual cell
size_t cid;
//! Neighborhood
const long int * NNc;
//! Neighborhood size
long int NNc_size;
//! If 0 we are iterating over the domain, if 1 we are iterating over the
//! anomalous neighborhood cells, if 2 we terminate
size_t dom_or_anom;
//! List of all the domain cells
const openfpm::vector<size_t> &dom_cell;
//! List of all anomalous domain cells with neighborhood
const openfpm::vector<subsub_lin<dim>> &anom_dom_cell;
//! The array contain the neighborhood of the cell-id in case of symmetric interaction
//
// * * *
// x *
//
const long int (& NNc_sym)[openfpm::math::pow(3,dim)/2+1];
//! Celllist type
CellListType & cli;
//! grid iterator for cells iteration
CellIt it;
/*! \brief Adjust the counters to reach a valid particle element
*
*
*/
void selectValid()
{
while (start == stop)
while (it.isNext())
{
cid++;
size_t s_cell;
if (dom_or_anom == 0)
{
if (cid >= dom_cell.size())
{
dom_or_anom = 1;
cid = 0;
// Terminate if we do not have anom cell
if (anom_dom_cell.size() == 0)
{
dom_or_anom = 2;
return;
}
s_cell = anom_dom_cell.get(cid).subsub;
}
else
s_cell = dom_cell.get(cid);
}
else
{
if (cid >= anom_dom_cell.size())
{
dom_or_anom = 2;
return;
}
s_cell = anom_dom_cell.get(cid).subsub;
}
auto cell = it.get();
size_t s_cell = cli.getGrid().LinId(cell);
// Get the starting particle
start = &cli.getStartId(s_cell);
// Get the stop particle
stop = &cli.getStopId(s_cell);
if (start == stop)
++it;
else
break;
}
}
......@@ -141,44 +62,13 @@ public:
/*! \brief Initialize the iterator
*
* \param cli Cell-list
* \param dom_cell domain cell
* \param anom_dom_cell anomalous domain cell
* \param NNc_sym symmetric neighborhood
*
* \param size_t internal grid cells
* \param
*
*/
ParticleItCRS_Cells(CellListType & cli,
const openfpm::vector<size_t> & dom_cell,
const openfpm::vector<subsub_lin<dim>> & anom_dom_cell,
const long int (& NNc_sym)[openfpm::math::pow(3,dim)/2+1])
:cid(0),dom_or_anom(0),dom_cell(dom_cell),anom_dom_cell(anom_dom_cell),NNc_sym(NNc_sym),cli(cli)
ParticleIt_Cells(CellListType & cli, CellIt & cit)
:cli(cli),it(cit)
{
size_t s_cell;
if (dom_cell.size() != 0)
s_cell = dom_cell.get(0);
else if (anom_dom_cell.size() != 0)
{
s_cell = anom_dom_cell.get(0).subsub;
dom_or_anom = 1;
}
else
{
dom_or_anom = 2;
start = NULL;
stop = NULL;
NNc = NULL;
NNc_size = 0;
return;
}
// Get the starting particle
start = &cli.getStartId(s_cell);
// Get the stop particle
stop = &cli.getStopId(s_cell);
selectValid();
}
......@@ -187,11 +77,15 @@ public:
* \return The actual particle iterator
*
*/
ParticleItCRS_Cells & operator++()
ParticleIt_Cells & operator++()
{
++start;
selectValid();
if (start == stop)
{
++it;
selectValid();
}
return *this;
}
......@@ -203,7 +97,7 @@ public:
*/
bool isNext()
{
return dom_or_anom != 2;
return it.isNext();
}
/*! \brief Get the actual particle id
......@@ -215,53 +109,6 @@ public:
{
return *start;
}
/*! \brief Get the neighborhood iterator according to the CRS scheme
*
* The CRS scheme use different 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);
}
/*! \brief Get the neighborhood iterator according to the CRS scheme Multi-phase case
*
* The CRS scheme use different 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 getNNIteratorCSRM(const openfpm::vector<Point<dim,typename CellListType::stype>> & pos ,const openfpm::vector<pos_v<dim,typename CellListType::stype>> & v) const
{
if (dom_or_anom == 0)
return typename CellListType::SymNNIterator(dom_cell.get(cid),CellListType::getV(*start),CellListType::getP(*start),NNc_sym,openfpm::math::pow(3,dim)/2+1,cli,pos,v);
else
return typename CellListType::SymNNIterator(anom_dom_cell.get(cid).subsub,CellListType::getV(*start),CellListType::getP(*start),&anom_dom_cell.get(cid).NN_subsub.get(0),anom_dom_cell.get(cid).NN_subsub.size(),cli,pos,v);
}
};
......
......@@ -38,29 +38,6 @@ BOOST_AUTO_TEST_SUITE_END()
#define MEASURE_SET 5
/*! \brief Execute a command getting its output
*
* \param cmd command to execute
*
*
* \return the output string
*
*/
/*std::string exec(const char* cmd)
{
std::shared_ptr<FILE> pipe(popen(cmd, "r"), pclose);
if (!pipe)
return "ERROR";
char buffer[128];
std::string result = "";
while (!feof(pipe.get()))
{
if (fgets(buffer, 128, pipe.get()) != NULL)
result += buffer;
}
return result;
}*/
/*! \brief It store the sha-1 git commit
*
......
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