Commit b958b201 authored by incardon's avatar incardon

Latest version

parent e90b6e45
......@@ -235,6 +235,7 @@ public:
// Add the coarse level
gd_array.add(grid_dist_id<dim,St,T,Decomposition,Memory,device_grid>(dec,g_sz,g_int));
gd_array.last().setBackgroundValue(bck);
initialize_other(n_lvl,g_sz_lvl);
}
......
......@@ -10,29 +10,12 @@
#define FREE 1
#define FIXED 2
#define ITERATION_ISOLATION 4
#include "Grid/grid_dist_key.hpp"
#include "VCluster/VCluster.hpp"
#include "util/GBoxes.hpp"
/*! \brief Distributed grid iterator
*
* Iterator across the local elements of the distributed grid
*
* \tparam dim dimensionality of the grid
* \tparam device_grid type of basic grid
* \tparam device_sub_it device grid sib-iterator type
* \tparam impl implementation
*
*/
template<unsigned int dim, typename device_grid, typename device_sub_it, int impl,typename stencil = no_stencil >
class grid_dist_iterator
{
};
/*! \brief Distributed grid iterator
*
* Iterator across the local elements of the distributed grid
......@@ -43,8 +26,8 @@ class grid_dist_iterator
* \tparam sub_iterator it indicate the sub-iterator type of the device_grid
*
*/
template<unsigned int dim, typename device_grid, typename device_sub_it, typename stencil>
class grid_dist_iterator<dim,device_grid,device_sub_it,FREE,stencil>
template<unsigned int dim, typename device_grid, typename device_sub_it, int impl, typename stencil = no_stencil >
class grid_dist_iterator
{
//! grid list counter
size_t g_c;
......@@ -68,8 +51,16 @@ class grid_dist_iterator<dim,device_grid,device_sub_it,FREE,stencil>
{
do
{
// When the grid has size 0 potentially all the other informations are garbage
while (g_c < gList.size() && (gList.get(g_c).size() == 0 || gdb_ext.get(g_c).Dbox.isValid() == false ) ) g_c++;
if (impl == FREE)
{
// When the grid has size 0 potentially all the other informations are garbage
while (g_c < gList.size() && (gList.get(g_c).size() == 0 || gdb_ext.get(g_c).Dbox.isValid() == false ) ) g_c++;
}
else
{
// When the grid has size 0 potentially all the other informations are garbage
while (g_c < gList.size() && (gList.get(g_c).size() == 0 || gdb_ext.get(g_c).GDbox.isValid() == false) ) g_c++;
}
// get the next grid iterator
if (g_c < gList.size())
......@@ -100,6 +91,7 @@ class grid_dist_iterator<dim,device_grid,device_sub_it,FREE,stencil>
selectValidGrid();
}
/*! \brief Constructor of the distributed grid iterator with
* stencil support
*
......@@ -121,12 +113,12 @@ class grid_dist_iterator<dim,device_grid,device_sub_it,FREE,stencil>
}
//! Copy constructor
grid_dist_iterator(const grid_dist_iterator<dim,device_grid,device_sub_it,FREE,stencil> & g)
grid_dist_iterator(const grid_dist_iterator<dim,device_grid,device_sub_it,impl,stencil> & g)
:g_c(g.g_c),gList(g.gList),gdb_ext(g.gdb_ext),a_it(g.a_it),stop(g.stop)
{}
//! Copy constructor
grid_dist_iterator(grid_dist_iterator<dim,device_grid,device_sub_it,FREE,stencil> && g)
grid_dist_iterator(grid_dist_iterator<dim,device_grid,device_sub_it,impl,stencil> && g)
:g_c(g.g_c),gList(g.gList),gdb_ext(g.gdb_ext),a_it(g.a_it),stop(g.stop)
{}
......@@ -140,7 +132,7 @@ class grid_dist_iterator<dim,device_grid,device_sub_it,FREE,stencil>
* \return the next grid_key
*
*/
inline grid_dist_iterator<dim,device_grid,device_sub_it,FREE,stencil> & operator++()
inline grid_dist_iterator<dim,device_grid,device_sub_it,impl,stencil> & operator++()
{
++a_it;
......@@ -261,184 +253,5 @@ class grid_dist_iterator<dim,device_grid,device_sub_it,FREE,stencil>
};
/*! \brief Distributed grid iterator
*
* Iterator across the local elements of the distributed grid
*
* \tparam dim dimensionality of the grid
* \tparam device_grid type of basic grid
* \tparam impl implementation
*
*/
template<unsigned int dim, typename device_grid, typename device_sub_it,typename stencil>
class grid_dist_iterator<dim,device_grid,device_sub_it,FIXED,stencil>
{
//! grid list counter
size_t g_c;
//! List of the grids we are going to iterate
const openfpm::vector<device_grid> & gList;
//! Extension of each grid: domain and ghost + domain
const openfpm::vector<GBoxes<device_grid::dims>> & gdb_ext;
//! Actual iterator
device_sub_it a_it;
/*! \brief from g_c increment g_c until you find a valid grid
*
*/
void selectValidGrid()
{
do
{
// When the grid has size 0 potentially all the other informations are garbage
while (g_c < gList.size() && (gList.get(g_c).size() == 0 || gdb_ext.get(g_c).GDbox.isValid() == false) ) g_c++;
// get the next grid iterator
if (g_c < gList.size())
{
a_it.reinitialize(gList.get(g_c).getIterator(gdb_ext.get(g_c).Dbox.getKP1(),gdb_ext.get(g_c).Dbox.getKP2()));
if (a_it.isNext() == false) {g_c++;}
}
} while (g_c < gList.size() && a_it.isNext() == false);
}
public:
/*! \brief Copy operator=
*
* \param tmp iterator to copy
*
* \return itself
*
*/
grid_dist_iterator<dim,device_grid,device_sub_it,FIXED> & operator=(const grid_dist_iterator<dim,device_grid,device_sub_it,FIXED> & tmp)
{
g_c = tmp.g_c;
gList = tmp.gList;
gdb_ext = tmp.gdb_ext;
a_it.reinitialize(tmp.a_it);
return *this;
}
/*! \brief Constructor of the distributed grid iterator
*
* \param gk std::vector of the local grid
* \param gdb_ext information about the local grids
*
*/
grid_dist_iterator(const openfpm::vector<device_grid> & gk, const openfpm::vector<GBoxes<device_grid::dims>> & gdb_ext)
:g_c(0),gList(gk),gdb_ext(gdb_ext)
{
// Initialize the current iterator
// with the first grid
selectValidGrid();
}
// Destructor
~grid_dist_iterator()
{
}
/*! \brief Get the next element
*
* \return the next grid_key
*
*/
grid_dist_iterator<dim,device_grid,device_sub_it,FIXED> & operator++()
{
++a_it;
// check if a_it is at the end
if (a_it.isNext() == true)
return *this;
else
{
// switch to the new grid
g_c++;
selectValidGrid();
}
return *this;
}
/*! \brief Check if there is the next element
*
* \return true if there is the next, false otherwise
*
*/
bool isNext()
{
// If there are no other grid stop
if (g_c >= gList.size())
return false;
return true;
}
/*! \brief Get the actual key
*
* \return the actual key
*
*/
grid_dist_key_dx<dim> get()
{
return grid_dist_key_dx<dim>(g_c,a_it.get());
}
/*! \brief Get the boxes
*
* Get the boxes that define the local grids
*
* \return Vector of local boxes
*
*/
inline const openfpm::vector<GBoxes<device_grid::dims>> & getGBoxes()
{
return gdb_ext;
}
/*! \brief Convert a g_dist_key_dx into a global key
*
* \see grid_dist_key_dx
* \see grid_dist_iterator
*
* \param k local coordinates to convert into global
*
* \return the global position in the grid
*
*/
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 = k.getKey();
// shift
k_glob = k_glob + gdb_ext.get(sub_id).origin;
return k_glob;
}
/*! \brief Return the stencil point offset
*
* \tparam id
*
* \return linearized distributed key
*
*/
template<unsigned int id> inline grid_dist_lin_dx getStencil()
{
return grid_dist_lin_dx(g_c,a_it.template getStencil<id>());
}
};
#endif /* GRID_DIST_ID_ITERATOR_SUB_HPP_ */
......@@ -1798,9 +1798,13 @@ public:
#ifdef SE_CLASS2
check_valid(this,8);
#endif
grid_key_dx<dim> stop;
for (size_t i = 0 ; i < dim ; i++)
{stop.set_d(i,0);}
grid_dist_iterator<dim,device_grid,
decltype(device_grid::type_of_iterator()),
FIXED> it(loc_grid,gdb_ext);
FIXED> it(loc_grid,gdb_ext,stop);
return it;
}
......@@ -2399,6 +2403,10 @@ public:
*/
void map(size_t opt = 0)
{
// Save the background values
T bv;
meta_copy<T>::meta_copy_(bv,loc_grid.get(0).getBackgroundValue());
if (!(opt & NO_GDB_EXT_SWITCH))
{
gdb_ext_old = gdb_ext;
......@@ -2417,6 +2425,9 @@ public:
// reset ghost structure to recalculate
reset_ghost_structures();
// Reset the background values
setBackgroundValue(bv);
}
/*! \brief Save the grid state on HDF5
......
......@@ -171,7 +171,7 @@ class grid_dist_id_comm
//! Memory for the ghost sending buffer
Memory g_send_prp_mem;
//! Memory for the ghost sending buffer
//! Memory for the ghost receiving buffer
Memory g_recv_prp_mem;
/*! \brief Sync the local ghost part
......@@ -1014,7 +1014,7 @@ public:
std::vector<size_t> prp_recv;
// Create an object of preallocated memory for properties
ExtPreAlloc<Memory> & prRecv_prp = *(new ExtPreAlloc<Memory>(tot_recv,g_recv_prp_mem));
ExtPreAlloc<Memory> & prRecv_prp = *(new ExtPreAlloc<Memory>(g_recv_prp_mem.size(),g_recv_prp_mem));
prRecv_prp.incRef();
// Before wait for the communication to complete we sync the local ghost
......
......@@ -11,6 +11,9 @@
#include "Grid/grid_dist_id.hpp"
#include "Point_test.hpp"
////////////////////////////////////// THEESE TEST ARE BROKEN TO REMPOVE OR FIX ////
const int x = 0;
const int y = 1;
const int z = 2;
......@@ -34,7 +37,7 @@ BOOST_AUTO_TEST_CASE( sgrid_dist_id_basic_test_2D)
sgrid_dist_id<2,double,Point_test<float>> sg(sz,domain,g,bc);
// create a grid iterator over a bilion point
// create a grid iterator
auto it = sg.getGridIterator();
......
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