Commit d7539e06 authored by incardon's avatar incardon
Browse files

Last stanges to staggered grid

parent 399870e1
openfpm_data @ 0f8108a0
Subproject commit 20abc8eed3bca0ffc5055c7c8fad6c95a484ffc1
Subproject commit 0f8108a0eba32e0249341040a5e127c3f5a7047e
......@@ -415,8 +415,54 @@ class grid_dist_id
vtk_box1.write(output + std::string("internal_ghost_") + std::to_string(v_cl.getProcessUnitID()) + std::string(".vtk"));
}
protected:
/*! \brief Get the i sub-domain grid
*
* \param i sub-domain
*
* \return local grid
*
*/
device_grid & get_loc_grid(size_t i)
{
return loc_grid.get(i);
}
/*! \brief Return the number of local grid
*
* \return the number of local grid
*
*/
size_t getN_loc_grid()
{
return loc_grid.size();
}
/*! \brief Get the point where it start the origin of the grid in the sub-domain i
*
* \return the point
*
*/
Point<dim,St> getOffset(size_t i)
{
return Point<dim,St>(gdb_ext.get(i).origin) * cd_sm.getCellBox().getP2();
}
/*! \brief Given a local sub-domain i with a local grid Domain + ghost return the part of the local grid that is domain
*
* \return the Box defining the domain in the local grid
*
*/
Box<dim,size_t> getDomain(size_t i)
{
return gdb_ext.get(i).Dbox;
}
public:
typedef device_grid loc_grid_type;
/*! \brief Constrcuctor
*
* \param g_sz array with the grid size on each dimension
......@@ -936,7 +982,7 @@ public:
VTKWriter<boost::mpl::pair<device_grid,float>,VECTOR_GRIDS> vtk_g;
for (size_t i = 0 ; i < loc_grid.size() ; i++)
{
Point<dim,St> offset = Point<dim,St>(gdb_ext.get(i).origin) * cd_sm.getCellBox().getP2();
Point<dim,St> offset = getOffset(i);
vtk_g.add(loc_grid.get(i),offset,cd_sm.getCellBox().getP2(),gdb_ext.get(i).Dbox);
}
vtk_g.write(output + "/grid_" + std::to_string(v_cl.getProcessUnitID()) + ".vtk");
......@@ -945,32 +991,6 @@ public:
return true;
}
/*! \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)
{
// 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++)
{
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_g.write(output + "/grid_" + std::to_string(v_cl.getProcessUnitID()) + ".vtk");
write_ie_boxes(output);
return true;
}
};
......
......@@ -18,7 +18,8 @@
* \param dim Dimensionality of the staggered grid
* \param ele elements object on each dimensional objects, must be a stag_elements
*
*
* \verbatim
+--#--+--#--+--#--+--#--+--#--+--#--+
| | | | | | |
# * # * # * # * # * # * #
......@@ -41,6 +42,8 @@
| | | | | | |
+--#--+--#--+--#--+--#--+--#--+--#--+
\endverbatim
In the case of a 2D staggered grid we have 3 (in general dim+1 ) elements
+ = vertex
......@@ -61,6 +64,8 @@ class staggered_grid_dist : public grid_dist_id<dim,St,T,Decomposition,Memory,de
public:
typedef T value_type;
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)
{}
......@@ -99,11 +104,16 @@ public:
*/
void write(std::string str)
{
stag_create_and_add_grid<dim,staggered_grid_dist<dim,St,T,Decomposition,Memory,device_grid>,St> sgw(*this);
boost::mpl::for_each_ref< boost::mpl::range_c<int,0,T::max_prop> >(sgw);
// spacing
Point<dim,St> spacing = grid_dist_id<dim,St,T,Decomposition,Memory,device_grid>::getSpacing();
/* 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);
grid_dist_id<dim,St,T,Decomposition,Memory,device_grid>::write(str,c_prp,spacing);*/
}
friend class stag_create_and_add_grid<dim,staggered_grid_dist<dim,St,T,Decomposition,Memory,device_grid>,St>;
};
#endif /* SRC_GRID_STAGGERED_DIST_GRID_HPP_ */
......@@ -9,6 +9,7 @@
#define SRC_GRID_STAGGERED_DIST_GRID_UTIL_HPP_
#include "util/common.hpp"
#include "VTKWriter.hpp"
/*! \brief Classes to get the number of components of the properties
*
......@@ -266,7 +267,6 @@ public:
}
};
///////////////////// Staggered default positioning ////////////////////////
/*! \brief this class is a functor for "for_each" algorithm
......@@ -347,4 +347,129 @@ public:
}
};
/*! \brief It create separated grid for each properties to write them into a file
*
* \tparam dim dimensionality of the grids
* \tparam obj type object to print, must be in OpenFPM format
*
*/
template<unsigned int dim, typename st_grid, typename St>
class stag_create_and_add_grid
{
// staggered grid to write
st_grid & st_g;
public:
/*! \brief Constructor
*
* \param st_g staggered grid
*
*/
stag_create_and_add_grid(st_grid & st_g)
:st_g(st_g)
{}
template<unsigned int p_val> void out_normal()
{
// property type
typedef typename boost::mpl::at< typename st_grid::value_type::type , typename boost::mpl::int_<p_val> >::type ele;
// create an openfpm format object from the property type
typedef object<typename boost::fusion::vector<ele>> d_object;
VTKWriter<boost::mpl::pair<grid_cpu<dim, d_object >,St>,VECTOR_GRIDS> vtk_w;
// Create a vector of grids
openfpm::vector< grid_cpu<dim, d_object > > vg(st_g.getN_loc_grid());
// for each domain grid
for (size_t i = 0 ; i < vg.size() ; i++)
{
// Set dimansions and memory
vg.get(i).template resize<HeapMemory>(st_g.get_loc_grid(i).getGrid().getSize());
// create the Memory
vg.get(i).template setMemory<HeapMemory>();
auto g_src = st_g.get_loc_grid(i);
auto g_dst = vg.get(i);
auto it = vg.get(i).getIterator();
while(it.isNext())
{
object_si_d< decltype(g_src.get_o(it.get())),decltype(g_dst.get_o(it.get())) ,ENCAP,T::value>(g_src.get_o(it.get()),g_dst.get_o(it.get()));
++it;
}
Point<dim,St> offset = st_g.getOffset(i);
Point<dim,St> spacing = st_g.getSpacing();
Box<dim,size_t> dom = st_g.getDomain(i);
vtk_w.add(g_dst,offset,spacing,dom);
}
vtk_w.write("vtk_grids_st_" + std::to_string(T::value) + ".vtk");
}
template<unsigned int p_val> void out_staggered()
{
// property type
typedef typename boost::mpl::at< typename st_grid::value_type::type , typename boost::mpl::int_<p_val> >::type ele;
// create an openfpm format object from the property type
typedef object<typename boost::fusion::vector<ele>> d_object;
VTKWriter<boost::mpl::pair<grid_cpu<dim, d_object >,St>,VECTOR_GRIDS> vtk_w;
// Create a vector of grids
openfpm::vector< grid_cpu<dim, d_object > > vg(st_g.getN_loc_grid());
// for each domain grid
for (size_t i = 0 ; i < vg.size() ; i++)
{
// Set dimansions and memory
vg.get(i).template resize<HeapMemory>(st_g.get_loc_grid(i).getGrid().getSize());
// create the Memory
vg.get(i).template setMemory<HeapMemory>();
auto g_src = st_g.get_loc_grid(i);
auto g_dst = vg.get(i);
auto it = vg.get(i).getIterator();
while(it.isNext())
{
object_si_d< decltype(g_src.get_o(it.get())),decltype(g_dst.get_o(it.get())) ,ENCAP,T::value>(g_src.get_o(it.get()),g_dst.get_o(it.get()));
++it;
}
Point<dim,St> offset = st_g.getOffset(i);
Point<dim,St> spacing = st_g.getSpacing();
Box<dim,size_t> dom = st_g.getDomain(i);
vtk_w.add(g_dst,offset,spacing,dom);
}
vtk_w.write("vtk_grids_st_" + std::to_string(T::value) + ".vtk");
}
//! It call the copy function for each property
template<typename T>
void operator()(T& t)
{
if (st_g.is_staggered_prop(T::value) == false)
out_normal<T::value>();
else
out_staggered<T::value>();
}
};
#endif /* SRC_GRID_STAGGERED_DIST_GRID_UTIL_HPP_ */
/*
* staggered_grid_unit_test.hpp
*
* Created on: Aug 20, 2015
* Author: i-bird
*/
#ifndef SRC_GRID_STAGGERED_GRID_DIST_UNIT_TEST_HPP_
#define SRC_GRID_STAGGERED_GRID_DIST_UNIT_TEST_HPP_
#include "staggered_dist_grid.hpp"
#include "Point_test.hpp"
BOOST_AUTO_TEST_SUITE( staggered_grid_dist_id_test )
BOOST_AUTO_TEST_CASE( staggered_grid_dist_unit_test)
{
typedef Point2D_test<float> p;
Vcluster & v_cl = *global_v_cluster;
// Domain
Box<2,float> domain({0.0,0.0},{1.0,1.0});
for (size_t k = 1024 ; k >= 2 ; k--)
{
BOOST_TEST_CHECKPOINT( "Testing grid k=" << k );
// grid size
size_t sz[2];
sz[0] = k;
sz[1] = k;
// Ghost
Ghost<2,float> g(0.01);
staggered_grid_dist<2,float,Point2D_test<float>,CartDecomposition<2,float>> sg(sz,domain,g);
sg.setDefaultStagPosition();
auto it = sg.getDomainIterator();
while (it.isNext())
{
auto key = it.get();
grid_key_dx<2> keyg = sg.getGKey(key);
sg.template get<p::s>(key) = keyg.get(0);
sg.template get<p::v>(key)[0] = keyg.get(0);
sg.template get<p::v>(key)[1] = keyg.get(1);
sg.template get<p::t>(key)[0][0] = keyg.get(0);
sg.template get<p::t>(key)[0][1] = keyg.get(1);
sg.template get<p::t>(key)[1][0] = keyg.get(0) + 1.0;
sg.template get<p::t>(key)[1][1] = keyg.get(1) + 7.0;
++it;
}
sg.write("stag_test.vtk");
}
}
BOOST_AUTO_TEST_SUITE_END()
#endif /* SRC_GRID_STAGGERED_GRID_DIST_UNIT_TEST_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