diff --git a/src/Grid/grid_dist_id.hpp b/src/Grid/grid_dist_id.hpp index d5ea40d1f5d3aee766cc19f68c0d2431cc60dcfc..6c4400c940bba3efb8362edd13a32dbf8f9c6dc5 100644 --- a/src/Grid/grid_dist_id.hpp +++ b/src/Grid/grid_dist_id.hpp @@ -374,6 +374,19 @@ class grid_dist_id } } + /*! \brief Check the the grid has valid size + * + * Distributed grids with size < 2 on each dimension are not supported + * + */ + inline void check_size(const size_t (& g_sz)[dim]) + { + for (size_t i = 0 ; i < dim ; i++) + { + if (g_sz[i] < 2) + std::cerr << "Error: " << __FILE__ << ":" << __LINE__ << " distrobuted grids with size smaller than 2 are not supported\n"; + } + } public: @@ -381,6 +394,8 @@ public: grid_dist_id(Vcluster v_cl, Decomposition & dec, const size_t (& g_sz)[dim], const Box<dim,St> & domain, const Ghost<dim,T> & ghost) :domain(domain),ghost(ghost),loc_grid(NULL),v_cl(v_cl),dec(dec) { + check_size(g_sz); + // For a 5x5 grid you have 4x4 Cell size_t c_g[dim]; for (size_t i = 0 ; i < dim ; i++) {c_g[i] = g_sz[i]-1;} @@ -421,9 +436,12 @@ public: grid_dist_id(const size_t (& g_sz)[dim],const Box<dim,St> & domain, const Ghost<dim,St> & g) :domain(domain),ghost(g),dec(Decomposition(*global_v_cluster)),v_cl(*global_v_cluster) { + // check that the grid has valid size + check_size(g_sz); + // For a 5x5 grid you have 4x4 Cell size_t c_g[dim]; - for (size_t i = 0 ; i < dim ; i++) {c_g[i] = g_sz[i]-1;} + for (size_t i = 0 ; i < dim ; i++) {c_g[i] = (g_sz[i]-1 > 0)?(g_sz[i]-1):1;} // Initialize the cell decomposer cd_sm.setDimensions(domain,c_g,0); diff --git a/src/Grid/grid_dist_id_iterator.hpp b/src/Grid/grid_dist_id_iterator.hpp index 0ae0639577d6b2dea038b263d084215ff85646ac..63a45ab2c4f6d55ff49b189a26b5067e8e4492b9 100644 --- a/src/Grid/grid_dist_id_iterator.hpp +++ b/src/Grid/grid_dist_id_iterator.hpp @@ -96,6 +96,21 @@ class grid_dist_iterator<dim,device_grid,FREE> //! margin of the grid iterator size_t m; + /*! \brief from g_c increment g_c until you find a valid grid + * + */ + void selectValidGrid() + { + // When the grid has size 0 potentially all the other informations are garbage + while (g_c < gList.size() && (gList[g_c].size() == 0 || gdb_ext.get(g_c).Dbox.isValid() == false ) ) g_c++; + + // get the next grid iterator + if (g_c < gList.size()) + { + a_it.reinitialize(gList[g_c].getIterator(gdb_ext.get(g_c).Dbox.getKP1(),gdb_ext.get(g_c).Dbox.getKP2())); + } + } + public: /*! \brief Constructor of the distributed grid @@ -108,7 +123,7 @@ class grid_dist_iterator<dim,device_grid,FREE> { // Initialize the current iterator // with the first grid - a_it.reinitialize(gList[0].getIterator(gdb_ext.get(0).Dbox.getKP1(),gdb_ext.get(0).Dbox.getKP2())); + selectValidGrid(); } // Destructor @@ -135,14 +150,7 @@ class grid_dist_iterator<dim,device_grid,FREE> // switch to the new grid g_c++; - // When the grid has size 0 potentially all the other informations are garbage - while (g_c < gList.size() && (gList[g_c].size() == 0 || gdb_ext.get(g_c).Dbox.isValid() == false ) ) g_c++; - - // get the next grid iterator - if (g_c < gList.size()) - { - a_it.reinitialize(gList[g_c].getIterator(gdb_ext.get(g_c).Dbox.getKP1(),gdb_ext.get(g_c).Dbox.getKP2())); - } + selectValidGrid(); } return *this; @@ -239,7 +247,7 @@ class grid_dist_iterator<dim,device_grid,FIXED> g_c++; // When the grid has size 0 potentially all the other informations are garbage - while (g_c < gList.size() && gList[g_c].size() == 0 ) g_c++; + while (g_c < gList.size() && gdb_ext.get(g_c).Dbox.getVolumeKey() == 0 ) g_c++; // get the next grid iterator if (g_c < gList.size()) diff --git a/src/Grid/grid_dist_id_unit_test.hpp b/src/Grid/grid_dist_id_unit_test.hpp index 0264ef1acf2c59a0d9671518674ee87cbf826fcb..6c1c9f84dd489988b25358e393fbbe572bdf5dca 100644 --- a/src/Grid/grid_dist_id_unit_test.hpp +++ b/src/Grid/grid_dist_id_unit_test.hpp @@ -40,7 +40,7 @@ BOOST_AUTO_TEST_CASE( grid_dist_id_domain_grid_unit_converter_test) // Test several grid dimensions - for (size_t k = 1024 ; k >= 1 ; k--) + for (size_t k = 1024 ; k >= 2 ; k--) { std::cout << "Testing: " << k << "\n"; @@ -94,7 +94,7 @@ BOOST_AUTO_TEST_CASE( grid_dist_id_iterator_test_use) // Initialize the global VCluster init_global_v_cluster(&boost::unit_test::framework::master_test_suite().argc,&boost::unit_test::framework::master_test_suite().argv); - for (long int k = 1024 ; k >= 1 ; k-= (k >= 66)?33:1 ) + for (long int k = 8 ; k >= 2 ; k-= (k >= 66)?33:1 ) { std::cout << "Testing: " << k << "\n";