Commit 62d76cb0 authored by incardon's avatar incardon

amr_struct

parent 265d602f
openfpm_data @ 1b796172
Subproject commit d125ec9a7a9de358e2fe74e0df55495fd476646e Subproject commit 1b796172ff8fa0a7a4842ce04d12e4d399a58728
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
#define AMR_IMPL_PATCHES 2 #define AMR_IMPL_PATCHES 2
#define AMR_IMPL_OPENVDB 3 #define AMR_IMPL_OPENVDB 3
template<unsigned int dim, typename St, typename T, unsigned int impl=AMR_IMPL_TRIVIAL ,typename Decomposition = CartDecomposition<dim,St>,typename Memory=HeapMemory , typename device_grid=grid_cpu<dim,T> > template<unsigned int dim, typename St, typename T, unsigned int impl=AMR_IMPL_TRIVIAL ,typename Decomposition = CartDecomposition<dim,St>,typename Memory=HeapMemory , typename device_grid=grid_cpu<dim,T> >
class grid_dist_amr class grid_dist_amr
{ {
...@@ -54,8 +56,10 @@ class grid_dist_amr<dim,St,T,AMR_IMPL_TRIVIAL,Decomposition,Memory,device_grid> ...@@ -54,8 +56,10 @@ class grid_dist_amr<dim,St,T,AMR_IMPL_TRIVIAL,Decomposition,Memory,device_grid>
//! array of grids //! array of grids
openfpm::vector<grid_dist_id<dim,St,T,Decomposition,Memory,device_grid>> gd_array; openfpm::vector<grid_dist_id<dim,St,T,Decomposition,Memory,device_grid>> gd_array;
typedef decltype(device_grid::type_of_subiterator()) device_sub_it;
//! Iterator for each distributed grid //! Iterator for each distributed grid
openfpm::vector<grid_dist_iterator<dim,device_grid,FREE>> git; openfpm::vector<grid_dist_iterator<dim,device_grid,device_sub_it,FREE>> git;
//! Iterator for each distributed grid //! Iterator for each distributed grid
openfpm::vector<grid_dist_iterator_sub<dim,device_grid>> git_sub; openfpm::vector<grid_dist_iterator_sub<dim,device_grid>> git_sub;
...@@ -156,7 +160,10 @@ public: ...@@ -156,7 +160,10 @@ public:
} }
grid_dist_amr_key_iterator<dim,device_grid,grid_dist_iterator_sub<dim,device_grid>> getDomainIteratorCells() grid_dist_amr_key_iterator<dim,device_grid,
decltype(grid_dist_id<dim,St,T,Decomposition,Memory,device_grid>::type_of_subiterator()),
decltype(grid_dist_id<dim,St,T,Decomposition,Memory,device_grid>::type_of_subiterator()) >
getDomainIteratorCells()
{ {
git_sub.clear(); git_sub.clear();
...@@ -174,7 +181,9 @@ public: ...@@ -174,7 +181,9 @@ public:
git_sub.add(gd_array.get(i).getSubDomainIterator(start,stop)); git_sub.add(gd_array.get(i).getSubDomainIterator(start,stop));
} }
return grid_dist_amr_key_iterator<dim,device_grid,grid_dist_iterator_sub<dim,device_grid>>(git_sub); return grid_dist_amr_key_iterator<dim,device_grid,
decltype(grid_dist_id<dim,St,T,Decomposition,Memory,device_grid>::type_of_subiterator()),
decltype(grid_dist_id<dim,St,T,Decomposition,Memory,device_grid>::type_of_subiterator())>(git_sub);
} }
grid_dist_iterator_sub<dim,device_grid> getDomainIteratorCells(size_t lvl) grid_dist_iterator_sub<dim,device_grid> getDomainIteratorCells(size_t lvl)
...@@ -191,12 +200,23 @@ public: ...@@ -191,12 +200,23 @@ public:
return gd_array.get(lvl).getSubDomainIterator(start,stop); return gd_array.get(lvl).getSubDomainIterator(start,stop);
} }
/*! \brief Get an iterator to the grid
*
* \return an iterator to the grid
*
*/
auto getGridIterator(size_t lvl) -> decltype(gd_array.get(lvl).getGridIterator())
{
return gd_array.get(lvl).getGridIterator();
}
/*! \brief Get domain iterator /*! \brief Get domain iterator
* *
* \return an iterator over all the grid levels * \return an iterator over all the grid levels
* *
*/ */
grid_dist_amr_key_iterator<dim,device_grid> getDomainIterator() grid_dist_amr_key_iterator<dim,device_grid, decltype(device_grid::type_of_subiterator())>
getDomainIterator()
{ {
git.clear(); git.clear();
...@@ -205,7 +225,7 @@ public: ...@@ -205,7 +225,7 @@ public:
git.add(gd_array.get(i).getDomainIterator()); git.add(gd_array.get(i).getDomainIterator());
} }
return grid_dist_amr_key_iterator<dim,device_grid>(git); return grid_dist_amr_key_iterator<dim,device_grid,decltype(device_grid::type_of_subiterator())>(git);
} }
/*! \brief return an iterator over the level lvl /*! \brief return an iterator over the level lvl
...@@ -215,7 +235,8 @@ public: ...@@ -215,7 +235,8 @@ public:
* \return an iterator over the level lvl selected * \return an iterator over the level lvl selected
* *
*/ */
grid_dist_iterator<dim,device_grid,FREE> getDomainIterator(size_t lvl) const grid_dist_iterator<dim,device_grid,decltype(device_grid::type_of_subiterator()),FREE>
getDomainIterator(size_t lvl) const
{ {
return gd_array.get(lvl).getDomainIterator(); return gd_array.get(lvl).getDomainIterator();
} }
...@@ -285,6 +306,80 @@ public: ...@@ -285,6 +306,80 @@ public:
return gd_array.get(lvl).template get<p>(v1); return gd_array.get(lvl).template get<p>(v1);
} }
//////////////////// Insert functions
/*! \brief Get the reference of the selected element
*
* \tparam p property to get (is an integer)
* \param v1 grid_key that identify the element in the grid
*
* \return the selected element
*
*/
template <unsigned int p>
inline auto insert(const grid_dist_amr_key<dim> & v1)
-> typename std::add_lvalue_reference<decltype(gd_array.get(v1.getLvl()).template insert<p>(v1.getKey()))>::type
{
#ifdef SE_CLASS2
check_valid(this,8);
#endif
return gd_array.get(v1.getLvl()).template insert<p>(v1.getKey());
}
/*! \brief Get the reference of the selected element
*
* \tparam p property to get (is an integer)
* \param v1 grid_key that identify the element in the grid
*
* \return the selected element
*
*/
template <unsigned int p>inline auto insert(size_t lvl, const grid_dist_key_dx<dim> & v1) -> typename std::add_lvalue_reference<decltype(gd_array.get(lvl).template get<p>(v1))>::type
{
#ifdef SE_CLASS2
check_valid(this,8);
#endif
return gd_array.get(lvl).template insert<p>(v1);
}
//////////////////////////////////////
//////////////////// Remove functions
/*! \brief Remove a grid point (this function make sense only in case of
* sparse grid)
*
* \param v1 grid_key that identify the element in the AMR grid to eleminate
*
*/
inline void remove(const grid_dist_amr_key<dim> & v1)
{
#ifdef SE_CLASS2
check_valid(this,8);
#endif
return gd_array.get(v1.getLvl()).remove(v1.getKey());
}
/*! \brief Remove a grid point (this function make sense only in case of
* sparse grid)
*
* \param v1 grid_key that identify the element in the AMR grid to eleminate
*
*/
void remove(size_t lvl, const grid_dist_key_dx<dim> & v1)
{
#ifdef SE_CLASS2
check_valid(this,8);
#endif
return gd_array.get(lvl).remove(v1);
}
//////////////////////////////////////
/*! \brief It synchronize the ghost parts /*! \brief It synchronize the ghost parts
* *
* \tparam prp... Properties to synchronize * \tparam prp... Properties to synchronize
...@@ -358,6 +453,17 @@ public: ...@@ -358,6 +453,17 @@ public:
key.setLvl(lvl+1); key.setLvl(lvl+1);
} }
/*! \brief From a distributed key it return a AMR key that contain also the grid level
*
* \param lvl level
* \param key distributed key
*
*/
inline grid_dist_amr_key<dim> getAMRKey(size_t lvl, grid_dist_key_dx<dim> key)
{
return grid_dist_amr_key<dim>(lvl,key);
}
/*! \brief Move up (to coarser level) the key /*! \brief Move up (to coarser level) the key
* *
* \param key multi-resolution AMR key * \param key multi-resolution AMR key
...@@ -425,5 +531,7 @@ public: ...@@ -425,5 +531,7 @@ public:
} }
}; };
template<unsigned int dim, typename St, typename T>
using sgrid_dist_amr = grid_dist_amr<dim,St,T,AMR_IMPL_TRIVIAL,CartDecomposition<dim,St>,HeapMemory,sgrid_cpu<dim,T,HeapMemory>>;
#endif /* AMR_GRID_AMR_DIST_HPP_ */ #endif /* AMR_GRID_AMR_DIST_HPP_ */
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#include "Grid/Iterators/grid_dist_id_iterator.hpp" #include "Grid/Iterators/grid_dist_id_iterator.hpp"
#include "grid_dist_amr_key.hpp" #include "grid_dist_amr_key.hpp"
template<unsigned int dim, typename device_grid,typename it_type = grid_dist_iterator<dim,device_grid,FREE>> template<unsigned int dim, typename device_grid, typename device_sub_it, typename it_type = grid_dist_iterator<dim,device_grid,device_sub_it,FREE>>
class grid_dist_amr_key_iterator class grid_dist_amr_key_iterator
{ {
//! Array of grid iterators //! Array of grid iterators
...@@ -58,6 +58,8 @@ public: ...@@ -58,6 +58,8 @@ public:
:git(git),g_c(0) :git(git),g_c(0)
{ {
a_it = &git.get(0); a_it = &git.get(0);
selectValidGrid();
} }
...@@ -72,14 +74,14 @@ public: ...@@ -72,14 +74,14 @@ public:
* \return the next grid_key * \return the next grid_key
* *
*/ */
inline grid_dist_amr_key_iterator<dim,device_grid,it_type> & operator++() inline grid_dist_amr_key_iterator<dim,device_grid,device_sub_it,it_type> & operator++()
{ {
++(*a_it); ++(*a_it);
// check if a_it is at the end // check if a_it is at the end
if (a_it->isNext() == true) if (a_it->isNext() == true)
return *this; {return *this;}
else else
{ {
// switch to the new iterator // switch to the new iterator
......
...@@ -20,10 +20,9 @@ BOOST_AUTO_TEST_SUITE( grid_dist_amr_test ) ...@@ -20,10 +20,9 @@ BOOST_AUTO_TEST_SUITE( grid_dist_amr_test )
* \param n_lvl number of levels * \param n_lvl number of levels
* *
*/ */
void Test3D_amr_create_levels(Box<3,float> & domain, size_t coars_g, size_t n_lvl) template<typename grid_amr>
void Test3D_amr_create_levels(grid_amr & amr_g, Box<3,float> & domain, size_t coars_g, size_t n_lvl)
{ {
Ghost<3,float> g(0.05);
size_t g_sz[3] = {coars_g,coars_g,coars_g}; size_t g_sz[3] = {coars_g,coars_g,coars_g};
size_t tot_c = (coars_g - 1)*(coars_g - 1)*(coars_g - 1); size_t tot_c = (coars_g - 1)*(coars_g - 1)*(coars_g - 1);
...@@ -39,10 +38,29 @@ void Test3D_amr_create_levels(Box<3,float> & domain, size_t coars_g, size_t n_lv ...@@ -39,10 +38,29 @@ void Test3D_amr_create_levels(Box<3,float> & domain, size_t coars_g, size_t n_lv
fact *= 8; fact *= 8;
} }
amr_g.initLevels(n_lvl,g_sz);
grid_dist_amr<3,float,aggregate<float>> amr_g(domain,g); for (size_t i = 0 ; i < amr_g.getNLvl() ; i++)
{
// Fill the AMR with something
amr_g.initLevels(n_lvl,g_sz); size_t count = 0;
auto it = amr_g.getGridIterator(i);
while (it.isNext())
{
auto key = it.get_dist();
auto akey = amr_g.getAMRKey(i,key);
amr_g.template insert<0>(akey) = 3.0;
count++;
++it;
}
}
// Iterate across all the levels initialized // Iterate across all the levels initialized
auto it = amr_g.getDomainIterator(); auto it = amr_g.getDomainIterator();
...@@ -91,6 +109,8 @@ void Test3D_amr_create_levels(Box<3,float> & domain, size_t coars_g, size_t n_lv ...@@ -91,6 +109,8 @@ void Test3D_amr_create_levels(Box<3,float> & domain, size_t coars_g, size_t n_lv
BOOST_REQUIRE_EQUAL(count_c,correct_result_cell); BOOST_REQUIRE_EQUAL(count_c,correct_result_cell);
} }
template<unsigned int dim> template<unsigned int dim>
inline bool gr_is_inside(const grid_key_dx<dim> & key, const size_t (& sz)[dim]) inline bool gr_is_inside(const grid_key_dx<dim> & key, const size_t (& sz)[dim])
{ {
...@@ -105,14 +125,13 @@ inline bool gr_is_inside(const grid_key_dx<dim> & key, const size_t (& sz)[dim]) ...@@ -105,14 +125,13 @@ inline bool gr_is_inside(const grid_key_dx<dim> & key, const size_t (& sz)[dim])
return true; return true;
} }
void Test3D_amr_child_parent_get(Box<3,float> & domain, size_t coars_g, size_t n_lvl) template <typename grid>
void Test3D_amr_child_parent_get(grid & amr_g, Box<3,float> & domain, size_t coars_g, size_t n_lvl)
{ {
const int x = 0; const int x = 0;
const int y = 1; const int y = 1;
const int z = 2; const int z = 2;
Ghost<3,long int> g(1);
size_t g_sz[3] = {coars_g,coars_g,coars_g}; size_t g_sz[3] = {coars_g,coars_g,coars_g};
size_t tot = coars_g*coars_g*coars_g; size_t tot = coars_g*coars_g*coars_g;
...@@ -125,10 +144,32 @@ void Test3D_amr_child_parent_get(Box<3,float> & domain, size_t coars_g, size_t n ...@@ -125,10 +144,32 @@ void Test3D_amr_child_parent_get(Box<3,float> & domain, size_t coars_g, size_t n
fact *= 8; fact *= 8;
} }
amr_g.initLevels(n_lvl,g_sz);
grid_dist_amr<3,float,aggregate<long int,long int,long int>> amr_g(domain,g); //////// Add something /////
amr_g.initLevels(n_lvl,g_sz); for (size_t i = 0 ; i < amr_g.getNLvl() ; i++)
{
// Fill the AMR with something
size_t count = 0;
auto it = amr_g.getGridIterator(i);
while (it.isNext())
{
auto key = it.get_dist();
auto akey = amr_g.getAMRKey(i,key);
amr_g.template insert<0>(akey) = 3.0;
count++;
++it;
}
}
////////////////////////////
std::string test = amr_g.getSpacing(0).toString(); std::string test = amr_g.getSpacing(0).toString();
...@@ -140,14 +181,14 @@ void Test3D_amr_child_parent_get(Box<3,float> & domain, size_t coars_g, size_t n ...@@ -140,14 +181,14 @@ void Test3D_amr_child_parent_get(Box<3,float> & domain, size_t coars_g, size_t n
auto key = it.get(); auto key = it.get();
auto gkey = it.getGKey(); auto gkey = it.getGKey();
amr_g.get<0>(key) = gkey.get(0); amr_g.template insert<0>(key) = gkey.get(0);
amr_g.get<1>(key) = gkey.get(1); amr_g.template insert<1>(key) = gkey.get(1);
amr_g.get<2>(key) = gkey.get(2); amr_g.template insert<2>(key) = gkey.get(2);
++it; ++it;
} }
amr_g.ghost_get<0,1,2>(); amr_g.template ghost_get<0,1,2>();
amr_g.write("amr_write_test"); amr_g.write("amr_write_test");
// now we check that move space work // now we check that move space work
...@@ -180,44 +221,44 @@ void Test3D_amr_child_parent_get(Box<3,float> & domain, size_t coars_g, size_t n ...@@ -180,44 +221,44 @@ void Test3D_amr_child_parent_get(Box<3,float> & domain, size_t coars_g, size_t n
if (gr_is_inside(key_gpx,amr_g.getGridInfoVoid(it2.getLvl()).getSize()) == true) if (gr_is_inside(key_gpx,amr_g.getGridInfoVoid(it2.getLvl()).getSize()) == true)
{ {
match &= amr_g.get<0>(key_px) == gkey.get(0) + 1; match &= amr_g.template get<0>(key_px) == gkey.get(0) + 1;
match &= amr_g.get<1>(key_px) == gkey.get(1); match &= amr_g.template get<1>(key_px) == gkey.get(1);
match &= amr_g.get<2>(key_px) == gkey.get(2); match &= amr_g.template get<2>(key_px) == gkey.get(2);
} }
if (gr_is_inside(key_gmx,amr_g.getGridInfoVoid(it2.getLvl()).getSize()) == true) if (gr_is_inside(key_gmx,amr_g.getGridInfoVoid(it2.getLvl()).getSize()) == true)
{ {
match &= amr_g.get<0>(key_mx) == gkey.get(0) - 1; match &= amr_g.template get<0>(key_mx) == gkey.get(0) - 1;
match &= amr_g.get<1>(key_mx) == gkey.get(1); match &= amr_g.template get<1>(key_mx) == gkey.get(1);
match &= amr_g.get<2>(key_mx) == gkey.get(2); match &= amr_g.template get<2>(key_mx) == gkey.get(2);
} }
if (gr_is_inside(key_gpy,amr_g.getGridInfoVoid(it2.getLvl()).getSize()) == true) if (gr_is_inside(key_gpy,amr_g.getGridInfoVoid(it2.getLvl()).getSize()) == true)
{ {
match &= amr_g.get<0>(key_py) == gkey.get(0); match &= amr_g.template get<0>(key_py) == gkey.get(0);
match &= amr_g.get<1>(key_py) == gkey.get(1) + 1; match &= amr_g.template get<1>(key_py) == gkey.get(1) + 1;
match &= amr_g.get<2>(key_py) == gkey.get(2); match &= amr_g.template get<2>(key_py) == gkey.get(2);
} }
if (gr_is_inside(key_gmy,amr_g.getGridInfoVoid(it2.getLvl()).getSize()) == true) if (gr_is_inside(key_gmy,amr_g.getGridInfoVoid(it2.getLvl()).getSize()) == true)
{ {
match &= amr_g.get<0>(key_my) == gkey.get(0); match &= amr_g.template get<0>(key_my) == gkey.get(0);
match &= amr_g.get<1>(key_my) == gkey.get(1) - 1; match &= amr_g.template get<1>(key_my) == gkey.get(1) - 1;
match &= amr_g.get<2>(key_my) == gkey.get(2); match &= amr_g.template get<2>(key_my) == gkey.get(2);
} }
if (gr_is_inside(key_gpz,amr_g.getGridInfoVoid(it2.getLvl()).getSize()) == true) if (gr_is_inside(key_gpz,amr_g.getGridInfoVoid(it2.getLvl()).getSize()) == true)
{ {
match &= amr_g.get<0>(key_pz) == gkey.get(0); match &= amr_g.template get<0>(key_pz) == gkey.get(0);
match &= amr_g.get<1>(key_pz) == gkey.get(1); match &= amr_g.template get<1>(key_pz) == gkey.get(1);
match &= amr_g.get<2>(key_pz) == gkey.get(2) + 1; match &= amr_g.template get<2>(key_pz) == gkey.get(2) + 1;
} }
if (gr_is_inside(key_gmz,amr_g.getGridInfoVoid(it2.getLvl()).getSize()) == true) if (gr_is_inside(key_gmz,amr_g.getGridInfoVoid(it2.getLvl()).getSize()) == true)
{ {
match &= amr_g.get<0>(key_mz) == gkey.get(0); match &= amr_g.template get<0>(key_mz) == gkey.get(0);
match &= amr_g.get<1>(key_mz) == gkey.get(1); match &= amr_g.template get<1>(key_mz) == gkey.get(1);
match &= amr_g.get<2>(key_mz) == gkey.get(2) - 1; match &= amr_g.template get<2>(key_mz) == gkey.get(2) - 1;
} }
// Test to go to all the levels down // Test to go to all the levels down
...@@ -261,6 +302,8 @@ void Test3D_amr_child_parent_get(Box<3,float> & domain, size_t coars_g, size_t n ...@@ -261,6 +302,8 @@ void Test3D_amr_child_parent_get(Box<3,float> & domain, size_t coars_g, size_t n
BOOST_REQUIRE_EQUAL(match,true); BOOST_REQUIRE_EQUAL(match,true);
} }
template <typename> struct Debug;
BOOST_AUTO_TEST_CASE( grid_dist_amr_get_child_test ) BOOST_AUTO_TEST_CASE( grid_dist_amr_get_child_test )
{ {
// Domain // Domain
...@@ -269,7 +312,10 @@ BOOST_AUTO_TEST_CASE( grid_dist_amr_get_child_test ) ...@@ -269,7 +312,10 @@ BOOST_AUTO_TEST_CASE( grid_dist_amr_get_child_test )
long int k = 16*16*16*create_vcluster().getProcessingUnits(); long int k = 16*16*16*create_vcluster().getProcessingUnits();
k = std::pow(k, 1/3.); k = std::pow(k, 1/3.);
Test3D_amr_child_parent_get(domain3,k,4); Ghost<3,long int> g(1);
grid_dist_amr<3,float,aggregate<long int,long int,long int>> amr_g(domain3,g);
Test3D_amr_child_parent_get(amr_g,domain3,k,4);
} }
BOOST_AUTO_TEST_CASE( grid_dist_amr_test ) BOOST_AUTO_TEST_CASE( grid_dist_amr_test )
...@@ -280,9 +326,17 @@ BOOST_AUTO_TEST_CASE( grid_dist_amr_test ) ...@@ -280,9 +326,17 @@ BOOST_AUTO_TEST_CASE( grid_dist_amr_test )
long int k = 16*16*16*create_vcluster().getProcessingUnits(); long int k = 16*16*16*create_vcluster().getProcessingUnits();
k = std::pow(k, 1/3.); k = std::pow(k, 1/3.);
Test3D_amr_create_levels(domain3,k,4); Ghost<3,float> g(0.05);
grid_dist_amr<3,float,aggregate<float>> amr_g(domain3,g);
Test3D_amr_create_levels(amr_g,domain3,k,4);
sgrid_dist_amr<3,float,aggregate<float>> amr_g2(domain3,g);
Test3D_amr_create_levels(amr_g2,domain3,k,4);
} }
BOOST_AUTO_TEST_CASE( grid_dist_amr_get_child_test_low_res ) BOOST_AUTO_TEST_CASE( grid_dist_amr_get_child_test_low_res )
{ {
// Domain // Domain
...@@ -290,7 +344,14 @@ BOOST_AUTO_TEST_CASE( grid_dist_amr_get_child_test_low_res ) ...@@ -290,7 +344,14 @@ BOOST_AUTO_TEST_CASE( grid_dist_amr_get_child_test_low_res )
long int k = 2; long int k = 2;
Test3D_amr_child_parent_get(domain3,k,4); Ghost<3,long int> g(1);
grid_dist_amr<3,float,aggregate<long int,long int,long int>> amr_g(domain3,g);
Test3D_amr_child_parent_get(amr_g,domain3,k,4);
sgrid_dist_amr<3,float,aggregate<long int,long int,long int>> amr_g2(domain3,g);
Test3D_amr_child_parent_get(amr_g2,domain3,k,4);
} }
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()
...@@ -22,10 +22,11 @@ ...@@ -22,10 +22,11 @@
* *
* \tparam dim dimensionality of the grid * \tparam dim dimensionality of the grid
* \tparam device_grid type of basic grid * \tparam device_grid type of basic grid
* \tparam device_sub_it device grid sib-iterator type
* \tparam impl implementation * \tparam impl implementation
* *
*/ */
template<unsigned int dim, typename device_grid, int impl,typename stencil = no_stencil > template<unsigned int dim, typename device_grid, typename device_sub_it, int impl,typename stencil = no_stencil >
class grid_dist_iterator class grid_dist_iterator
{ {
...@@ -38,11 +39,12 @@ class grid_dist_iterator ...@@ -38,11 +39,12 @@ class grid_dist_iterator
* *
* \tparam dim dimensionality of the grid * \tparam dim dimensionality of the grid
* \tparam device_grid type of basic grid * \tparam device_grid type of basic grid
* \tparam impl implementation * \tparam stencil it inject the code to calculate stencil offset
* \tparam sub_iterator it indicate the sub-iterator type of the device_grid
* *
*/ */
template<unsigned int dim, typename device_grid, typename stencil> template<unsigned int dim, typename device_grid, typename device_sub_it, typename stencil>
class grid_dist_iterator<dim,device_grid,FREE,stencil> class grid_dist_iterator<dim,device_grid,device_sub_it,FREE,stencil>
{ {
//! grid list counter //! grid list counter
size_t g_c; size_t g_c;
...@@ -54,7 +56,7 @@ class grid_dist_iterator<dim,device_grid,FREE,stencil> ...@@ -54,7 +56,7 @@ class grid_dist_iterator<dim,device_grid,FREE,stencil>
const openfpm::vector<GBoxes<device_grid::dims>> & gdb_ext; const openfpm::vector<GBoxes<device_grid::dims>> & gdb_ext;
//! Actual iterator //! Actual iterator
grid_key_dx_iterator_sub<dim,stencil> a_it; device_sub_it a_it;
//! stop point (is the grid size) //! stop point (is the grid size)
grid_key_dx<dim> stop; grid_key_dx<dim> stop;
...@@ -83,7 +85,9 @@ class grid_dist_iterator<dim,device_grid,FREE,stencil> ...@@ -83,7 +85,9 @@ class grid_dist_iterator<dim,device_grid,FREE,stencil>
* \param stop end point * \param stop end point
* *
*/ */
grid_dist_iterator(const openfpm::vector<device_grid> & gk, const openfpm::vector<GBoxes<device_grid::dims>> & gdb_ext, const grid_key_dx<dim> & stop) grid_dist_iterator(const openfpm::vector<device_grid> & gk,
const openfpm::vector<GBoxes<device_grid::dims>> & gdb_ext,
const grid_key_dx<dim> & stop)
:g_c(0),gList(gk),gdb_ext(gdb_ext),stop(stop) :g_c(0),gList(gk),gdb_ext(gdb_ext),stop(stop)
{ {
// Initialize the current iterator // Initialize the current iterator
...@@ -112,12 +116,12 @@ class grid_dist_iterator<dim,device_grid,FREE,stencil> ...@@ -112,12 +116,12 @@ class grid_dist_iterator<dim,device_grid,FREE,stencil>
} }
//! Copy constructor //! Copy constructor
grid_dist_iterator(const grid_dist_iterator<dim,device_grid,FREE,stencil> & g) grid_dist_iterator(const grid_dist_iterator<dim,device_grid,device_sub_it,FREE,stencil> & g)
:g_c(g.g_c),gList(g.gList),gdb_ext(g.gdb_ext),a_it(g.a_it),stop(g.stop) :g_c(g.g_c),gList(g.gList),gdb_ext(g.gdb_ext),a_it(g.a_it),stop(g.stop)
{} {}
//! Copy constructor //! Copy constructor
grid_dist_iterator(grid_dist_iterator<dim,device_grid,FREE,stencil> && g) grid_dist_iterator(grid_dist_iterator<dim,device_grid,device_sub_it,FREE,stencil> && g)
:g_c(g.g_c),gList(g.gList),gdb_ext(g.gdb_ext),a_it(g.a_it),stop(g.stop) :g_c(g.g_c),gList(g.gList),gdb_ext(g.gdb_ext),a_it(g.a_it),stop(g.stop)
{} {}
...@@ -131,7 +135,7 @@ class grid_dist_iterator<dim,device_grid,FREE,stencil> ...@@ -131,7 +135,7 @@ class grid_dist_iterator<dim,device_grid,FREE,stencil>
* \return the next grid_key * \return the next grid_key
* *
*/ */
inline grid_dist_iterator<dim,device_grid,FREE,stencil> & operator++() inline grid_dist_iterator<dim,device_grid,device_sub_it,FREE,stencil> & operator++()
{ {
++a_it; ++a_it;
...@@ -170,9 +174,9 @@ class grid_dist_iterator<dim,device_grid,FREE,stencil> ...@@ -170,9 +174,9 @@ class grid_dist_iterator<dim,device_grid,FREE,stencil>
* \return the actual key