Commit 6b1ea580 authored by incardon's avatar incardon

Adding ghost iterator in AMR struct

parent 2922681f
openfpm_data @ 63cf342d
Subproject commit 4094c5a176424df253513deb41021061cdafe9ac
Subproject commit 63cf342df7a5c97e126f2d677c4ffdabbea3d6ae
......@@ -58,9 +58,14 @@ class grid_dist_amr<dim,St,T,AMR_IMPL_TRIVIAL,Decomposition,Memory,device_grid>
typedef decltype(device_grid::type_of_subiterator()) device_sub_it;
//! Iterator for each distributed grid
typedef decltype(device_grid::type_of_iterator()) device_it;
//! Domain iterator for each distributed grid
openfpm::vector<grid_dist_iterator<dim,device_grid,device_sub_it,FREE>> git;
//! Domain and ghost iterator for each distributed grid
openfpm::vector<grid_dist_iterator<dim,device_grid,device_it,FIXED>> git_g;
//! Iterator for each distributed grid
openfpm::vector<grid_dist_iterator_sub<dim,device_grid>> git_sub;
......@@ -303,7 +308,7 @@ public:
*
*/
grid_dist_iterator<dim,device_grid,
grid_key_dx_iterator<dim>,
decltype(device_grid::type_of_iterator()),
FIXED>
getDomainGhostIterator(size_t lvl) const
{
......@@ -333,17 +338,19 @@ public:
* \return an iterator over all the grid levels
*
*/
grid_dist_amr_key_iterator<dim,device_grid, grid_key_dx_iterator<dim>>
grid_dist_amr_key_iterator<dim,device_grid, decltype(device_grid::type_of_iterator()),
grid_dist_iterator<dim,device_grid,decltype(device_grid::type_of_iterator()),FIXED>>
getDomainGhostIterator()
{
git.clear();
git_g.clear();
for (size_t i = 0 ; i < gd_array.size() ; i++)
{
git.add(gd_array.get(i).getDomainIterator());
git_g.add(gd_array.get(i).getDomainGhostIterator());
}
return grid_dist_amr_key_iterator<dim,device_grid,grid_key_dx_iterator<dim>>(git);
return grid_dist_amr_key_iterator<dim,device_grid,decltype(device_grid::type_of_iterator()),
grid_dist_iterator<dim,device_grid,decltype(device_grid::type_of_iterator()),FIXED>>(git_g);
}
/*! \brief Get the reference of the selected element
......
......@@ -414,6 +414,95 @@ void Test3D_amr_ghost_it(grid & amr_g, Box<3,float> & domain, size_t coars_g, si
template <typename grid>
void Test3D_amr_domain_ghost_it(grid & amr_g, Box<3,float> & domain, size_t coars_g, size_t n_lvl)
{
size_t g_sz[3] = {coars_g,coars_g,coars_g};
size_t tot = coars_g*coars_g*coars_g;
size_t correct_result = 0;
size_t fact = 1;
for (size_t i = 0 ; i < n_lvl ; i++)
{
correct_result += tot*fact;
fact *= 8;
}
amr_g.initLevels(n_lvl,g_sz);
size_t total_all_level = 0;
//////// Add something /////
for (size_t i = 0 ; i < amr_g.getNLvl() ; i++)
{
// Fill the AMR with something
size_t count = 0;
auto it = amr_g.getGridGhostIterator(i);
while (it.isNext())
{
auto key = it.get_dist();
auto gkey = it.get();
auto akey = amr_g.getAMRKey(i,key);
amr_g.template insert<0>(akey) = gkey.get(0);
amr_g.template insert<1>(akey) = gkey.get(1);
amr_g.template insert<2>(akey) = gkey.get(2);
count++;
++it;
}
size_t tot = (amr_g.getGridInfoVoid(i).size(0) + 2)*
(amr_g.getGridInfoVoid(i).size(1) + 2)*
(amr_g.getGridInfoVoid(i).size(2) + 2);
auto & v_cl = create_vcluster();
if (v_cl.size() == 1)
{
v_cl.sum(count);
v_cl.execute();
BOOST_REQUIRE_EQUAL(tot,count);
}
bool match = true;
auto it2 = amr_g.getDomainGhostIterator(i);
while (it2.isNext())
{
auto key = it2.get();
auto key_g = it2.getGKey(key);
match &= amr_g.template get<0>(i,key) == key_g.get(0);
total_all_level++;
++it2;
}
BOOST_REQUIRE_EQUAL(match,true);
}
// test the total iterator
size_t gtot_count = 0;
auto tot_it = amr_g.getDomainGhostIterator();
while (tot_it.isNext())
{
gtot_count++;
++tot_it;
}
BOOST_REQUIRE_EQUAL(gtot_count,total_all_level);
}
template <typename> struct Debug;
......@@ -475,6 +564,31 @@ BOOST_AUTO_TEST_CASE( grid_dist_amr_ghost_it_test )
{BOOST_REQUIRE_EQUAL(amr_g2.size_inserted(i),0ul);}
}
BOOST_AUTO_TEST_CASE( grid_dist_amr_domain_ghost_it_test )
{
// Domain
Box<3,float> domain3({0.0,0.0,0.0},{1.0,1.0,1.0});
long int k = 16*16*16*create_vcluster().getProcessingUnits();
k = std::pow(k, 1/3.);
Ghost<3,long int> g(1);
grid_dist_amr<3,float,aggregate<long int,long int,long int>> amr_g(domain3,g);
Test3D_amr_domain_ghost_it(amr_g,domain3,k,4);
sgrid_dist_amr<3,float,aggregate<long int,long int,long int>> amr_g2(domain3,g);
Test3D_amr_domain_ghost_it(amr_g2,domain3,k,4);
for (size_t i = 0 ; i < amr_g2.getNLvl() ; i++)
{BOOST_REQUIRE(amr_g2.size_inserted(i) != 0ul);}
amr_g2.clear();
for (size_t i = 0 ; i < amr_g2.getNLvl() ; i++)
{BOOST_REQUIRE_EQUAL(amr_g2.size_inserted(i),0ul);}
}
BOOST_AUTO_TEST_CASE( grid_dist_amr_get_child_test_low_res )
{
......
......@@ -155,8 +155,6 @@ BOOST_AUTO_TEST_CASE( amr_grid_dist_id_iterator_test_use_2D)
// periodicity
periodicity<2> pr = {{PERIODIC,PERIODIC}};
float factor = pow(create_vcluster().getProcessingUnits()/2.0f,1.0f/2.0f);
// Ghost
Ghost<2,long int> g(1);
......
......@@ -235,7 +235,6 @@ class grid_dist_iterator<dim,device_grid,device_sub_it,FREE,stencil>
size_t sub_id = k.getSub();
grid_key_dx<dim> k_glob = k.getKey();
// gList.get(sub_id).convert_key(k_glob,k.getKey());
// shift
k_glob = k_glob + gdb_ext.get(sub_id).origin;
......@@ -405,13 +404,12 @@ class grid_dist_iterator<dim,device_grid,device_sub_it,FIXED,stencil>
* \return the global position in the grid
*
*/
inline grid_key_dx<dim> getGKey(const grid_dist_key_dx<dim> & k)
inline grid_key_dx<dim> getGKey(const grid_dist_key_dx<dim,typename device_grid::base_key> & k)
{
// Get the sub-domain id
size_t sub_id = k.getSub();
grid_key_dx<dim> k_glob;
gList.get(sub_id).convert_key(k_glob,k.getKey());
grid_key_dx<dim> k_glob = k.getKey();
// shift
k_glob = k_glob + gdb_ext.get(sub_id).origin;
......
......@@ -1734,7 +1734,7 @@ public:
*
*/
grid_dist_iterator<dim,device_grid,
grid_key_dx_iterator<dim>,
decltype(device_grid::type_of_iterator()),
FIXED>
getDomainGhostIterator() const
{
......@@ -1742,7 +1742,7 @@ public:
check_valid(this,8);
#endif
grid_dist_iterator<dim,device_grid,
grid_key_dx_iterator<dim>,
decltype(device_grid::type_of_iterator()),
FIXED> it(loc_grid,gdb_ext);
return it;
......
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