Commit 66377ea5 authored by Pietro Incardona's avatar Pietro Incardona

Added grid iterator from decomposition

parent 5449ffff
openfpm_data @ 17662fd3
Subproject commit 6897f78253e1b1926f0c290ad7d70603614a75f4
Subproject commit 17662fd368e0b2e8f16143cd4ccea2125ad0d72e
openfpm_devices @ e79687e8
Subproject commit 52aa2cffd29ad7e4fc306e4f58fd2be2e596fd81
Subproject commit e79687e8594b0761330a34a0f3eecf514f9f9290
openfpm_numerics @ 0c51112a
Subproject commit a9ea8f7d598d205d3deae6aaf9f4ac59354befaf
Subproject commit 0c51112a6a0808e7209329de9d4639c1e440a815
openfpm_vcluster @ 6e360fcb
Subproject commit 9803a7ad4f9fb08c23f624e6ed43e32e0430eabb
Subproject commit 6e360fcbf118277ca59b2709eb2ffa0661c677a8
......@@ -887,6 +887,18 @@ p1[0]<-----+ +----> p2[0]
return ss_box;
}
/*! \brief Get the periodicity on i dimension
*
* \param i dimension
*
* \return the periodicity in direction i
*
*/
size_t isPeriodic(size_t i)
{
return bc[i];
}
/*! \brief Set the parameter of the decomposition
*
* \param div_ storing into how many domain to decompose on each dimension
......
......@@ -1011,76 +1011,141 @@ void Test3D_dup(const Box<3,float> & domain, long int k)
void Test3D_decit(const Box<3,float> & domain, long int k)
{
typedef Point_test<float> p;
size_t k_bck = k;
{
typedef Point_test<float> p;
Vcluster & v_cl = *global_v_cluster;
Vcluster & v_cl = *global_v_cluster;
if ( v_cl.getProcessingUnits() > 32 )
return;
if ( v_cl.getProcessingUnits() > 32 )
return;
long int big_step = k / 30;
big_step = (big_step == 0)?1:big_step;
long int small_step = 21;
long int big_step = k / 30;
big_step = (big_step == 0)?1:big_step;
long int small_step = 21;
print_test( "Testing grid iterator from decomposition k<=",k);
print_test( "Testing grid iterator from decomposition k<=",k);
// 3D test
for ( ; k >= 2 ; k-= (k > 2*big_step)?big_step:small_step )
{
BOOST_TEST_CHECKPOINT( "Testing grid iterator from decomposition k<=" << k );
// 3D test
for ( ; k >= 2 ; k-= (k > 2*big_step)?big_step:small_step )
{
BOOST_TEST_CHECKPOINT( "Testing grid iterator from decomposition k<=" << k );
// grid size
size_t sz[3];
sz[0] = k;
sz[1] = k;
sz[2] = k;
// grid size
size_t sz[3];
sz[0] = k;
sz[1] = k;
sz[2] = k;
// factor
float factor = pow(global_v_cluster->getProcessingUnits()/2.0f,1.0f/3.0f);
// factor
float factor = pow(global_v_cluster->getProcessingUnits()/2.0f,1.0f/3.0f);
// Ghost
Ghost<3,float> g(0.01 / factor);
// Ghost
Ghost<3,float> g(0.01 / factor);
// Distributed grid with id decomposition
grid_dist_id<3, float, Point_test<float>, CartDecomposition<3,float>> g_dist(sz,domain,g);
// Distributed grid with id decomposition
grid_dist_id<3, float, Point_test<float>, CartDecomposition<3,float>> g_dist(sz,domain,g);
// check the consistency of the decomposition
bool val = g_dist.getDecomposition().check_consistency();
BOOST_REQUIRE_EQUAL(val,true);
// check the consistency of the decomposition
bool val = g_dist.getDecomposition().check_consistency();
BOOST_REQUIRE_EQUAL(val,true);
// Grid sm
grid_sm<3,void> info(sz);
// Grid sm
grid_sm<3,void> info(sz);
auto dom = g_dist.getSubDomainIterator({0,0,0},{sz[0]-1,sz[1]-1,sz[2]-1});
auto dom = g_dist.getDomainIterator();
bool match = true;
bool match = true;
// create a grid iterator from the decomposition
// create a grid iterator from the decomposition
grid_dist_id_iterator_dec<CartDecomposition<3,float>> it_dec(g_dist.getDecomposition(),g_dist.getGridInfoVoid().getSize());
grid_dist_id_iterator_dec<CartDecomposition<3,float>> it_dec(g_dist.getDecomposition(),g_dist.getGridInfoVoid().getSize());
while (dom.isNext())
while (dom.isNext())
{
auto key = dom.get();
auto key_g = g_dist.getGKey(key);
auto key_dec = it_dec.get();
// Check if the two keys match
match &= (key_dec == key_g);
++dom;
++it_dec;
}
BOOST_REQUIRE_EQUAL(match,true);
}
}
k = k_bck;
{
typedef Point_test<float> p;
Vcluster & v_cl = *global_v_cluster;
if ( v_cl.getProcessingUnits() > 32 )
return;
long int big_step = k / 30;
big_step = (big_step == 0)?1:big_step;
long int small_step = 21;
print_test( "Testing grid iterator from decomposition k<=",k);
// 3D test
for ( ; k >= 2 ; k-= (k > 2*big_step)?big_step:small_step )
{
auto key = dom.get();
auto key_g = g_dist.getGKey(key);
BOOST_TEST_CHECKPOINT( "Testing grid iterator from decomposition k<=" << k );
// grid size
size_t sz[3];
sz[0] = k;
sz[1] = k;
sz[2] = k;
// factor
float factor = pow(global_v_cluster->getProcessingUnits()/2.0f,1.0f/3.0f);
// Ghost
Ghost<3,float> g(0.01 / factor);
// Distributed grid with id decomposition
grid_dist_id<3, float, Point_test<float>, CartDecomposition<3,float>> g_dist(sz,domain,g);
// check the consistency of the decomposition
bool val = g_dist.getDecomposition().check_consistency();
BOOST_REQUIRE_EQUAL(val,true);
// Grid sm
grid_sm<3,void> info(sz);
auto key_dec = it_dec.get();
auto dom = g_dist.getSubDomainIterator({0,0,0},{sz[0]-2,sz[1]-2,sz[2]-2});
// Check if the two keys match
match &= key_dec == key_g;
bool match = true;
// create a grid iterator from the decomposition
if (match == false)
grid_dist_id_iterator_dec<CartDecomposition<3,float>> it_dec(g_dist.getDecomposition(),sz,{0,0,0},{sz[0]-2,sz[1]-2,sz[2]-2});
while (dom.isNext())
{
int debug = 0;
debug++;
auto key = dom.get();
auto key_g = g_dist.getGKey(key);
auto key_dec = it_dec.get();
// Check if the two keys match
match &= (key_dec == key_g);
++dom;
++it_dec;
}
++dom;
++it_dec;
BOOST_REQUIRE_EQUAL(match,true);
}
BOOST_REQUIRE_EQUAL(match,true);
}
}
......@@ -1159,7 +1224,7 @@ BOOST_AUTO_TEST_CASE( grid_dist_id_with_grid_unit_ghost )
Test3D_gg(domain3,k,1);
}
BOOST_AUTO_TEST_CASE( grid_dist_id_decomposition )
BOOST_AUTO_TEST_CASE( grid_dist_id_decomposition_iterator )
{
// Domain
Box<2,float> domain({0.0,0.0},{1.0,1.0});
......
......@@ -55,17 +55,29 @@ template<int dim, typename Decomposition> inline void create_gdb_ext(openfpm::ve
*
* \param gdb_ext Vector of Boxes that define the local grids extension
* \param dec Decomposition
* \param Global grid grid size
* \param sz Global grid grid size
* \param domain Domain where the grid is defined
* \param spacing Define the spacing of the grid
*
*/
template<int dim, typename Decomposition> inline void create_gdb_ext(openfpm::vector<GBoxes<dim>> & gdb_ext, Decomposition & dec, const size_t (& sz)[dim], const Box<Decomposition::dims,typename Decomposition::stype> & domain)
template<int dim, typename Decomposition> inline void create_gdb_ext(openfpm::vector<GBoxes<dim>> & gdb_ext, Decomposition & dec, const size_t (& sz)[dim], const Box<Decomposition::dims,typename Decomposition::stype> & domain, typename Decomposition::stype (& spacing)[dim])
{
// Create the cell decomposer
CellDecomposer_sm<Decomposition::dims,typename Decomposition::stype> cd_sm;
cd_sm.setDimensions(domain,sz,0);
size_t sz_cell[Decomposition::dims];
for (size_t i = 0 ; i < dim ; i++)
sz_cell[i] = sz[i] - 1;
// Careful cd_sm require the number of cell
cd_sm.setDimensions(domain,sz_cell,0);
create_gdb_ext<dim,Decomposition>(gdb_ext,dec,cd_sm);
// fill the spacing
for (size_t i = 0 ; i < dim ; i++)
spacing[i] = cd_sm.getCellBox().getP2()[i];
}
#endif /* SRC_GRID_GRID_DIST_UTIL_HPP_ */
......@@ -21,6 +21,7 @@
#include "memory/ExtPreAlloc.hpp"
#include "CSVWriter.hpp"
#include "Decomposition/common.hpp"
#include "Grid/grid_dist_id_iterator_dec.hpp"
#define V_SUB_UNIT_FACTOR 64
......@@ -918,6 +919,37 @@ public:
return vector_dist_iterator(0,v_pos.size());
}
/*! /brief Get a grid Iterator
*
* Usefull function to place particles on a grid or grid-like (grid + noise)
*
* \return a Grid iterator
*
*/
inline grid_dist_id_iterator_dec<Decomposition> getGridIterator(const size_t (& sz)[dim])
{
size_t sz_g[dim];
grid_key_dx<dim> start;
grid_key_dx<dim> stop;
for (size_t i = 0 ; i < dim ; i++)
{
start.set_d(i,0);
if (dec.isPeriodic(i) == PERIODIC)
{
sz_g[i] = sz[i]-1;
stop.set_d(i,sz_g[i]-1);
}
else
{
sz_g[i] = sz[i];
stop.set_d(i,sz_g[i]-1);
}
}
grid_dist_id_iterator_dec<Decomposition> it_dec(dec,sz_g,start,stop);
return it_dec;
}
/*! \brief Get the iterator across the position of the ghost particles
*
* \return an iterator
......
......@@ -825,7 +825,11 @@ BOOST_AUTO_TEST_CASE( vector_dist_not_periodic_map )
BOOST_AUTO_TEST_CASE( vector_dist_cell_verlet_test )
{
/* typedef Point<3,float> s;
typedef Point<3,float> s;
// we create a 128x128x128 Grid iterator
size_t sz[3] = {128,128,128};
size_t total = sz[0]*sz[1]*sz[2];
Box<3,float> box({0.0,0.0,0.0},{1.0,1.0,1.0});
......@@ -839,23 +843,82 @@ BOOST_AUTO_TEST_CASE( vector_dist_cell_verlet_test )
Ghost<3,float> ghost(0.05 / factor);
// Distributed vector
vector_dist<3,float, Point_test<float>, CartDecomposition<3,float> > vd(1,box,bc,ghost);
vector_dist<3,float, Point_test<float>, CartDecomposition<3,float> > vd(total,box,bc,ghost);
// Put particles on a grid creating a Grid iterator
auto it = vd.getGridIterator(sz);
auto it_p = vd.getDomainIterator();
while (it.isNext())
while (it_p.isNext())
{
auto key_p = it_p.get();
auto key = it.get();
vd.template getPos<s::x>(key)[0] = key.get(0);
vd.template getPos<s::x>(key)[1] = key.get(1);
vd.template getPos<s::x>(key)[2] = key.get(2);
vd.template getPos<s::x>(key_p)[0] = key.get(0) * it.getSpacing(0);
vd.template getPos<s::x>(key_p)[1] = key.get(1) * it.getSpacing(1);
vd.template getPos<s::x>(key_p)[2] = key.get(2) * it.getSpacing(2);
++it;
++it_p;
}
vd.map();
// calculate the distance of the first, second and third neighborhood particle
// Consider that they are on a regular grid
float spacing = it.getSpacing(0);
float first_dist = spacing;
float second_dist = sqrt(2.0*spacing*spacing);
float third_dist = sqrt(3.0 * spacing*spacing);
// add a 5% to dist
first_dist += first_dist * 0.05;
second_dist += second_dist * 0.05;
third_dist += third_dist * 0.05;
// Create a verlet list for each particle
openfpm::vector<openfpm::vector<size_t>> verlet;
vd.getVerlet(verlet);
bool correct = true;
// for each particle
for (size_t i = 0 ; i < verlet.size() ; i++)
{
// first NN
size_t first_NN = 0;
size_t second_NN = 0;
size_t third_NN = 0;
Point<3,float> p = vd.getPos<0>(i);
// for each neighborhood particle
for (size_t j = 0 ; j < verlet.get(i).size() ; j++)
{
auto & NN = verlet.get(i);
Point<3,float> q = vc.getPos<0>(NN.get(j));
float dist = p.distance(q);
if (dist <= first_dist)
first_NN++;
else if (dist <= second_dist)
second_NN++;
else
third_NN++;
}
correct &= (first_NN == 6);
correct &= (second_NN == 12);
correct &= (third_NN = 8);
}
vd.map();*/
BOOST_REQUIRE_EQUAL(correct,true);
}
......
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