Commit 399870e1 authored by incardon's avatar incardon

Last changes

parent 100d9672
openfpm_data @ 20abc8ee
Subproject commit 1a289f3c67d5b567d2edf7328f71892a772191b0
Subproject commit 20abc8eed3bca0ffc5055c7c8fad6c95a484ffc1
......@@ -38,10 +38,10 @@
* \tparam Domain Structure that contain the information of your physical domain
*
* Given an N-dimensional space, this class decompose the space into a Cartesian grid of small
* sub-sub-domain. At each sub-sub-domain is assigned an id that identify which processor is
* going to take care of that part of space (in general the space assigned to a processor is
* simply connected), a second step merge several sub-sub-domain with same id into bigger region
* sub-domain with the id. Each sub-domain has an extended space called ghost part
* sub-sub-domain. To each sub-sub-domain is assigned an id that identify at which processor is
* assigned (in general the union of all the sub-sub-domain assigned to a processor is
* simply connected space), a second step merge several sub-sub-domain with same id into bigger region
* sub-domain. Each sub-domain has an extended space called ghost part
*
* Assuming that VCluster.getProcessUnitID(), equivalent to the MPI processor rank, return the processor local
* processor id, we define
......@@ -405,18 +405,18 @@ public:
+----------------------------------------------------+
| |
| Processor 8 |
| Sub-domain 0 +-----------------------------------+
| Sub+domain 0 +-----------------------------------+
| | |
| | |
++--------------+---+---------------------------+----+ Processor 9 |
| | | B8_0 | | Subdomain 0 |
| +------------------------------------+ |
| | | | | |
| | | XXXXXXXXXXXXX XX |B9_0| |
| | B | X Processor 10 X | | |
| Processor 5 | 5 | X Sub-domain 0 X | | |
| Subdomain 0 | _ | X X +----------------------------------------+
| | 0 | XXXXXXXXXXXXXXXX | | |
| | | |B9_0| |
| | B | Local processor | | |
| Processor 5 | 5 | Subdomain 0 | | |
| Subdomain 0 | _ | +----------------------------------------+
| | 0 | | | |
| | | | | |
| | | | | Processor 9 |
| | | |B9_1| Subdomain 1 |
......@@ -427,35 +427,38 @@ public:
| |
+-----------------------------------+
and also
G8_0 G9_0 G9_1 G5_0 (External ghost boxes)
+----------------------------------------------------+
| |
| Processor 8 |
| Sub-domain 0 +-----------------------------------+
| +---------------------------------------------+ |
| | G8_0 | | |
++--------------+------------------------------------+ | Processor 9 |
| | | | | Subdomain 0 |
| | | |G9_0| |
| | | | | |
| | | XXXXXXXXXXXXX XX | | |
| | | X Processor 10 X | | |
| Processor|5 | X Sub-domain 0 X | | |
| Subdomain|0 | X X +-----------------------------------+
| | | XXXXXXXXXXXXXXXX | | |
| | G | | | |
| | 5 | | | Processor 9 |
| | | | | | Subdomain 1 |
| | 0 | |G9_1| |
| | | | | |
| | | | | |
+--------------+------------------------------------+ | |
+----------------------------------------------------+
| Processor 8 |
| Subdomain 0 +-----------------------------------+
| | |
| +---------------------------------------------+ |
| | G8_0 | | |
+-----+---------------+------------------------------------+ | Processor 9 |
| | | | | Subdomain 0 |
| | | |G9_0| |
| | | | | |
| | | | | |
| | | Local processor | | |
| Processor 5 | | Sub+domain 0 | | |
| Subdomain 0 | | +-----------------------------------+
| | | | | |
| | G | | | |
| | 5 | | | Processor 9 |
| | | | | | Subdomain 1 |
| | 0 | |G9_1| |
| | | | | |
| | | | | |
+---------------------+------------------------------------+ | |
| | | |
+----------------------------------------+----+------------------------------+
*
*
*
......
......@@ -388,45 +388,35 @@ class grid_dist_id
}
}
public:
//! constructor
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)
void write_ie_boxes(std::string output)
{
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;}
// Initialize the cell decomposer
cd_sm.setDimensions(domain,c_g,0);
// fill the global size of the grid
for (int i = 0 ; i < dim ; i++) {this->g_sz[i] = g_sz[i];}
// Write internal ghost box
VTKWriter<openfpm::vector<::Box<dim,size_t>>,VECTOR_BOX> vtk_box1;
// Get the number of processor and calculate the number of sub-domain
// for decomposition
size_t n_proc = v_cl.getProcessingUnits();
size_t n_sub = n_proc * SUB_UNIT_FACTOR;
openfpm::vector< openfpm::vector< ::Box<dim,size_t> > > boxes;
// Calculate the maximum number (before merging) of sub-domain on
// each dimension
size_t div[dim];
for (int i = 0 ; i < dim ; i++)
{div[i] = openfpm::math::round_big_2(pow(n_sub,1.0/dim));}
//! Carefully we have to ensure that boxes does not reallocate inside the for loop
boxes.reserve(ig_box.size());
// Create the sub-domains
dec.setParameters(div);
//! Write internal ghost in grid units (Color encoded)
for (size_t p = 0 ; p < ig_box.size() ; p++)
{
boxes.add();
// Create local grid
Create();
// Create a vector of boxes
for (size_t j = 0 ; j < ig_box.get(p).bid.size() ; j++)
{
boxes.last().add(ig_box.get(p).bid.get(j).box);
}
// Calculate ghost boxes
dec.calculateGhostBoxes(ghost);
vtk_box1.add(boxes.last());
}
vtk_box1.write(output + std::string("internal_ghost_") + std::to_string(v_cl.getProcessUnitID()) + std::string(".vtk"));
}
public:
/*! \brief Constrcuctor
*
* \param g_sz array with the grid size on each dimension
......@@ -901,6 +891,16 @@ public:
}
}
/*! \brief Get the spacing on each dimension
*
* \param get the spacing
*
*/
Point<dim,St> getSpacing()
{
return cd_sm.getCellBox().getP2();
}
/*! \brief Convert a g_dist_key_dx into a global key
*
* \see grid_dist_key_dx
......@@ -924,8 +924,8 @@ public:
/*! \brief Write the distributed grid information
*
* 1) grid_X.vtk Output each local grids for each local processor X
* 2) internal_ghost_X.vtk Internal ghost boxes in grid units for the local processor X
* * grid_X.vtk Output each local grids for each local processor X
* * internal_ghost_X.vtk Internal ghost boxes in grid units for the local processor X
*
* \param output Directory where to put the files
*
......@@ -941,30 +941,33 @@ public:
}
vtk_g.write(output + "/grid_" + std::to_string(v_cl.getProcessUnitID()) + ".vtk");
// Write internal ghost box
VTKWriter<openfpm::vector<::Box<dim,size_t>>,VECTOR_BOX> vtk_box1;
openfpm::vector< openfpm::vector< ::Box<dim,size_t> > > boxes;
write_ie_boxes(output);
//! Carefully we have to ensure that boxes does not reallocate inside the for loop
boxes.reserve(ig_box.size());
return true;
}
//! Write internal ghost in grid units (Color encoded)
for (size_t p = 0 ; p < ig_box.size() ; p++)
/*! \brief Write the distributed grid information, where each properties has a shift
*
* * grid_X.vtk Output each local grids for each local processor X
* * internal_ghost_X.vtk Internal ghost boxes in grid units for the local processor X
*
* \param output Directory where to put the files
* \param c_prp for each property specify a positional vector
* \param sp spacing
*
*/
bool write(std::string output, const openfpm::vector<comb<dim>> (& c_prp)[T::max_prop], const Point<dim,St> & sp)
{
boxes.add();
// Create a vector of boxes
for (size_t j = 0 ; j < ig_box.get(p).bid.size() ; j++)
// Create a writer and write
VTKWriter<boost::mpl::pair<device_grid,float>,VECTOR_GRIDS> vtk_g;
for (size_t i = 0 ; i < loc_grid.size() ; i++)
{
boxes.last().add(ig_box.get(p).bid.get(j).box);
}
vtk_box1.add(boxes.last());
Point<dim,St> offset = Point<dim,St>(gdb_ext.get(i).origin) * cd_sm.getCellBox().getP2();
vtk_g.add(loc_grid.get(i),offset,cd_sm.getCellBox().getP2(),gdb_ext.get(i).Dbox,sp);
}
vtk_box1.write(output + std::string("internal_ghost_") + std::to_string(v_cl.getProcessUnitID()) + std::string(".vtk"));
vtk_g.write(output + "/grid_" + std::to_string(v_cl.getProcessUnitID()) + ".vtk");
vtk_g.write("vtk_grids.vtk");
write_ie_boxes(output);
return true;
}
......
......@@ -10,6 +10,7 @@
#include "Grid/grid_dist_id.hpp"
#include "staggered_dist_grid_util.hpp"
#include "VTKWriter.hpp"
/*! \brief Implementation of the staggered grid
......@@ -60,8 +61,8 @@ class staggered_grid_dist : public grid_dist_id<dim,St,T,Decomposition,Memory,de
public:
staggered_grid_dist(Vcluster & v_cl)
:grid_dist_id<dim,St,T,Decomposition,Memory,device_grid>(v_cl)
staggered_grid_dist(const size_t (& g_sz)[dim], const Box<dim,St> & domain, const Ghost<dim,St> & ghost)
:grid_dist_id<dim,St,T,Decomposition,Memory,device_grid>(g_sz,domain,ghost)
{}
openfpm::vector<comb<dim>> c_prp[T::max_prop];
......@@ -79,15 +80,29 @@ public:
c_prp.get(p) = cmb;
}
/*! \brief It set all the properties on a default location
*
* \return default staggered position
/*! \brief It set all the properties defined to be staggered on the default location
*
*/
openfpm::vector<comb<dim>> getDefaultStagPosition()
void setDefaultStagPosition()
{
// for each properties
stag_set_position<dim,typename T::type> ssp(c_prp);
boost::mpl::for_each_ref< boost::mpl::range_c<int,0,T::max_prop> >(ssp);
}
/*! \brief Write a vtk file with the information of the staggered grid
*
* \param str vtk output file
*
*/
void write(std::string str)
{
// spacing
Point<dim,St> spacing = grid_dist_id<dim,St,T,Decomposition,Memory,device_grid>::getSpacing();
spacing = spacing / 2;
grid_dist_id<dim,St,T,Decomposition,Memory,device_grid>::write(str,c_prp,spacing);
}
};
......
......@@ -8,6 +8,8 @@
#ifndef SRC_GRID_STAGGERED_DIST_GRID_UTIL_HPP_
#define SRC_GRID_STAGGERED_DIST_GRID_UTIL_HPP_
#include "util/common.hpp"
/*! \brief Classes to get the number of components of the properties
*
*/
......@@ -183,15 +185,23 @@ struct extends<T[N1][N2][N3][N4][N5][N6][N7][N8][N9][N10]>
* Is mainly used to produce a default position vector for each
* property
*
* \tparam vector of properties
* \tparam dim dimensionality
* \tparam v boost::fusion::vector of properties
* \tparam has_posMask case when v has a position mask
*
*/
template<unsigned int dim, typename v, bool has_posMask>
struct stag_set_position
template<unsigned int dim, typename v, bool has_pM = has_posMask<v>::value>
class stag_set_position
{
openfpm::vector<comb<dim>> (& pos_prp)[boost::fusion::result_of::size<v>::type::value];
public:
stag_set_position( openfpm::vector<comb<dim>> (& pos_prp)[boost::fusion::result_of::size<v>::type::value])
:pos_prp(pos_prp)
{}
//! It call the copy function for each property
template<typename T>
void operator()(T& t) const
......@@ -223,7 +233,7 @@ struct stag_set_position
{
comb<dim> c;
c.zero();
c.value(i) = 1;
c.value(i) = -1;
pos_prp[T::value].add(c);
}
......@@ -233,22 +243,108 @@ struct stag_set_position
// Create an hypercube object
HyperCube<dim> hyp;
// Diagonal part live in
for (size_t i = 0 ; i < dim ; i++)
{
comb<dim> c1 = pos_prp[T::value-1].get(i);
for (size_t j = 0 ; j < dim ; j++)
{
comb<dim> c2;
c2.zero();
c2.value(i) = -1;
comb<dim> c_res = -c1 + c2;
// Diagonal part live in
pos_prp[T::value].add(c_res);
}
}
}
else if (dim_prp > 2)
{
std::cerr << __FILE__ << ":" << __LINE__ << " Tensor of rank bigger than 2 are not supported";
}
}
};
///////////////////// Staggered default positioning ////////////////////////
/*! \brief this class is a functor for "for_each" algorithm
*
* For each element of the boost::vector the operator() is called.
* Is mainly used to produce a default position vector for each
* property
*
* \tparam vector of properties
*
*/
template<unsigned int dim, typename v>
class stag_set_position<dim,v,false>
{
private:
openfpm::vector<comb<dim>> (& pos_prp)[boost::fusion::result_of::size<v>::type::value];
public:
stag_set_position( openfpm::vector<comb<dim>> (& pos_prp)[boost::fusion::result_of::size<v>::type::value])
:pos_prp(pos_prp)
{}
//! It call the copy function for each property
template<typename T>
void operator()(T& t) const
{
// This is the type of the object we have to copy
typedef typename boost::mpl::at<v,typename boost::mpl::int_<T::value>>::type prop;
// Dimension of the object
size_t dim_prp = extends<prop>::dim();
// It is a scalar
if (dim_prp == 0)
{
comb<dim> c;
c.zero();
// It stay in the center
pos_prp[T::value].add(c);
}
else if (dim_prp == 1)
{
// It stay on the object of dimension dim-1 (Negative part)
for (size_t i = 0 ; i < dim ; i++)
{
comb<dim> c;
c.zero();
c.value(i) = 1;
c.getComb()[i] = -1;
pos_prp[T::value].add(c);
}
}
else if (dim_prp == 2)
{
// Diagonal part live in
for (size_t i = 0 ; i < dim ; i++)
{
comb<dim> c1 = pos_prp[T::value-1].get(i);
for (size_t j = 0 ; j < dim ; j++)
{
comb<dim> c2;
c2.zero();
c2.getComb()[i] = -1;
comb<dim> c_res = c2 - c1;
pos_prp[T::value].add(c_res);
}
}
}
else if (dim_prp > 2)
{
std::cerr << __FILE__ << ":" << __LINE__ << " Tensor of rank bigger than 2 are not supported";
}
}
};
#endif /* SRC_GRID_STAGGERED_DIST_GRID_UTIL_HPP_ */
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