Commit d9a88d42 authored by incardon's avatar incardon

AMR latest changes

parent 1373c4e3
/*
* grid_amr_dist.hpp
*
* Created on: Sep 21, 2017
* Author: i-bird
*/
#ifndef AMR_GRID_AMR_DIST_HPP_
#define AMR_GRID_AMR_DIST_HPP_
#endif /* AMR_GRID_AMR_DIST_HPP_ */
/*
* grid_amr_dist.hpp
*
* Created on: Sep 21, 2017
* Author: i-bird
*/
#ifndef AMR_GRID_AMR_DIST_HPP_
#define AMR_GRID_AMR_DIST_HPP_
#include "Grid/grid_dist_id.hpp"
#include "Amr/grid_dist_amr_key_iterator.hpp"
#define AMR_IMPL_TRIVIAL 1
#define AMR_IMPL_PATCHES 2
#define AMR_IMPL_OPENVDB 3
template<unsigned int dim, typename St, typename T, unsigned int impl=AMR_IMPL_TRIVIAL ,typename Decomposition = CartDecomposition<dim,St>,typename Memory=HeapMemory , typename device_grid=grid_cpu<dim,T> >
class grid_dist_amr
{
};
/*! \brief AMR Adaptive Multi Resolution Grid
*
* \tparam dim Dimensionality
* \tparam St type of space
* \tparam T what each point of the grid store
* \tparam Decomposition type of decomposition
*
*/
template<unsigned int dim, typename St, typename T,typename Decomposition,typename Memory, typename device_grid >
class grid_dist_amr<dim,St,T,AMR_IMPL_TRIVIAL,Decomposition,Memory,device_grid>
{
//! Simulation domain
Box<dim,St> domain;
//! Ghost continuos
Ghost<dim,St> g;
//! Ghost integer
Ghost<dim,long int> g_int;
//! array of grids
openfpm::vector<grid_dist_id<dim,St,T,Decomposition,Memory,device_grid>> gd_array;
//! Iterator for each distributed grid
openfpm::vector<grid_dist_iterator<dim,device_grid,FREE>> git;
public:
/*! \brief Constructor
*
* \param domain Simulation domain
* \param g ghost extension
*
*/
grid_dist_amr(const Box<dim,St> & domain)
:domain(domain)
{
}
/*! \brief Constructor
*
* \param domain Simulation domain
* \param g ghost extension
*
*/
grid_dist_amr(const Box<dim,St> & domain, const Ghost<dim,long int> & g)
:domain(domain)
{
}
/*! \brief Initialize the amr grid
*
* \paran n_lvl maximum number of levels (0 mean no additional levels)
* \param g_sz coarsest grid size on each direction
*
*/
void initLevels(size_t n_lvl,const size_t (& g_sz)[dim])
{
size_t g_sz_lvl[dim];
for (size_t i = 0; i < dim ; i++)
{g_sz_lvl[i] = g_sz[i];}
// Add the coarse level
gd_array.add(grid_dist_id<dim,St,T,Decomposition,Memory,device_grid>(g_sz,domain,g_int));
for (size_t i = 0; i < n_lvl - 1 ; i++)
{
for (size_t j = 0 ; j < dim ; j++){g_sz_lvl[j] = g_sz_lvl[j]*2;}
gd_array.add(grid_dist_id<dim,St,T,Decomposition,Memory,device_grid>(g_sz_lvl,domain,g_int));
}
}
/*! \brief Get domain iterator
*
* \return an iterator over all the grid levels
*
*/
grid_dist_amr_key_iterator<dim,device_grid> getDomainIterator()
{
git.clear();
for (size_t i = 0 ; i < gd_array.size() ; i++)
{
git.add(gd_array.get(i).getDomainIterator());
}
return grid_dist_amr_key_iterator<dim,device_grid>(git);
}
};
#endif /* AMR_GRID_AMR_DIST_HPP_ */
/*
* grid_dist_amr_dist_unit_tests.cpp
*
* Created on: Sep 21, 2017
* Author: i-bird
*/
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#include "grid_dist_amr.hpp"
BOOST_AUTO_TEST_SUITE( grid_dist_amr_test )
/*! \brief Coarsest levels of the grid
*
* \param domain Simulation domain
* \param coars_g coarsest grid resolution
* \param n_lvl number of levels
*
*/
void Test3D_amr_create_levels(Box<3,float> & domain, size_t coars_g, size_t n_lvl)
{
Ghost<3,float> g(0.05);
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;
}
grid_dist_amr<3,float,aggregate<float>> amr_g(domain,g);
amr_g.initLevels(n_lvl,g_sz);
// Iterate across all the levels initialized
auto it = amr_g.getDomainIterator();
size_t count = 0;
while (it.isNext())
{
auto key = it.get();
count++;
++it;
}
Vcluster & v_cl = create_vcluster();
v_cl.sum(count);
v_cl.execute();
BOOST_REQUIRE_EQUAL(count,correct_result);
}
BOOST_AUTO_TEST_CASE( grid_dist_amr_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.);
Test3D_amr_create_levels(domain3,k,4);
}
BOOST_AUTO_TEST_SUITE_END()
......@@ -111,7 +111,17 @@ class grid_dist_iterator<dim,device_grid,FREE,stencil>
selectValidGrid();
}
// Destructor
//! Copy constructor
grid_dist_iterator(const grid_dist_iterator<dim,device_grid,FREE,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,FREE,stencil> && g)
:g_c(g.g_c),gList(g.gList),gdb_ext(g.gdb_ext),a_it(g.a_it),stop(g.stop)
{}
//! Destructor
~grid_dist_iterator()
{
}
......@@ -121,7 +131,6 @@ class grid_dist_iterator<dim,device_grid,FREE,stencil>
* \return the next grid_key
*
*/
inline grid_dist_iterator<dim,device_grid,FREE,stencil> & operator++()
{
++a_it;
......@@ -146,7 +155,7 @@ class grid_dist_iterator<dim,device_grid,FREE,stencil>
* \return true if there is the next, false otherwise
*
*/
inline bool isNext()
inline bool isNext() const
{
// If there are no other grid stop
......@@ -161,7 +170,7 @@ class grid_dist_iterator<dim,device_grid,FREE,stencil>
* \return the actual key
*
*/
inline grid_dist_key_dx<dim> get()
inline grid_dist_key_dx<dim> get() const
{
return grid_dist_key_dx<dim>(g_c,a_it.get());
}
......
......@@ -402,15 +402,18 @@ class grid_dist_id : public grid_dist_id_comm<dim,St,T,Decomposition,Memory,devi
}
/*! \brief Create the grids on memory
*
* \param bx_def Where the grid is defined
* \param use_bx_def use the array that define where the grid is defined
*
*/
void Create()
void Create(openfpm::vector<Box<dim,long int>> & bx_def, bool use_bx_def)
{
// Get the number of local grid needed
size_t n_grid = dec.getNSubDomain();
// create gdb
create_gdb_ext<dim,Decomposition>(gdb_ext,dec,cd_sm);
create_gdb_ext<dim,Decomposition>(gdb_ext,dec,cd_sm,bx_def,use_bx_def);
// create local grids for each hyper-cube
loc_grid.resize(n_grid);
......@@ -437,18 +440,6 @@ class grid_dist_id : public grid_dist_id_comm<dim,St,T,Decomposition,Memory,devi
}
}
/*! \brief Default Copy constructor on this class make no sense and is unsafe, this definition disable it
*
* \param g grid to copy
*
*/
grid_dist_id(const grid_dist_id<dim,St,T,Decomposition,Memory,device_grid> & g)
:v_cl(g.v_cl)
{
#ifdef SE_CLASS2
check_new(this,8,GRID_DIST_EVENT,4);
#endif
}
/*! \brief Initialize the Cell decomposer of the grid enforcing perfect overlap of the cells
*
......@@ -643,6 +634,39 @@ public:
return ginfo_v.size(i);
}
/*! \brief Default Copy constructor on this class make no sense and is unsafe, this definition disable it
*
* \param g grid to copy
*
*/
grid_dist_id(const grid_dist_id<dim,St,T,Decomposition,Memory,device_grid> & g)
:grid_dist_id_comm<dim,St,T,Decomposition,Memory,device_grid>(g),
domain(g.domain),
ghost(g.ghost),
loc_grid(g.loc_grid),
loc_grid_old(g.loc_grid_old),
dec(g.dec),
gdb_ext(g.gdb_ext),
gdb_ext_global(g.gdb_ext_global),
gdb_ext_old(g.gdb_ext_old),
cd_sm(g.cd_sm),
v_cl(g.v_cl),
prp_names(g.prp_names),
g_id_to_external_ghost_box(g.g_id_to_external_ghost_box),
g_id_to_internal_ghost_box(g.g_id_to_internal_ghost_box),
ginfo(g.ginfo),
ginfo_v(g.ginfo_v),
init_local_i_g_box(g.init_local_i_g_box),
init_local_e_g_box(g.init_local_e_g_box)
{
#ifdef SE_CLASS2
check_new(this,8,GRID_DIST_EVENT,4);
#endif
for (size_t i = 0 ; i < dim ; i++)
{g_sz[i] = g.g_sz[i];}
}
/*! \brief This constructor is special, it construct an expanded grid that perfectly overlap with the previous
*
* The key-word here is "perfectly overlap". Using the default constructor you could create
......@@ -828,6 +852,36 @@ public:
InitializeStructures(g_sz);
}
/*! \brief It construct a grid on the full domain restricted
* to the set of boxes specified
*
* In particular the grid is defined in the space equal to the
* domain intersected the boxes defined by bx
*
* \param g_sz grid size on each dimension
* \param domain where the grid is constructed
* \param g ghost size
* \param p periodicity of the grid
* \param bx set of boxes where the grid is defined
*
*
*/
grid_dist_id(const size_t (& g_sz)[dim],
const Box<dim,St> & domain,
const Ghost<dim,St> & g,
const periodicity<dim> & p,
openfpm::vector<Box<dim,St>> & bx)
:domain(domain),ghost(g),dec(create_vcluster()),v_cl(create_vcluster()),ginfo(g_sz),ginfo_v(g_sz)
{
#ifdef SE_CLASS2
check_new(this,8,GRID_DIST_EVENT,4);
#endif
InitializeCellDecomposer(g_sz,p.bc);
InitializeDecomposition(g_sz, p.bc);
InitializeStructures(g_sz,bx);
}
/*! It construct a grid of a specified size, defined on a specified Box space, having a specified ghost size and periodicity
*
* \param g_sz grid size on each dimension
......@@ -1597,6 +1651,11 @@ public:
gdb_ext_old.clear();
}
/*! \brief Save the grid state on HDF5
*
* \param filename output filename
*
*/
inline void save(const std::string & filename) const
{
HDF5_writer<GRID_DIST> h5s;
......@@ -1604,6 +1663,11 @@ public:
h5s.save(filename,loc_grid,gdb_ext);
}
/*! \brief Reload the grid from HDF5 file
*
* \param filename output filename
*
*/
inline void load(const std::string & filename)
{
HDF5_reader<GRID_DIST> h5l;
......
......@@ -997,6 +997,18 @@ public:
{
}
/*! \brief Copy constructor
*
* It does not really copy. This structure it suppose to store only
* temporal data
*
*/
grid_dist_id_comm(const grid_dist_id_comm<dim,St,T,Decomposition,Memory,device_grid> & gc)
:v_cl(gc.v_cl)
{
}
};
......
......@@ -107,7 +107,13 @@ template<int dim, typename Decomposition> inline void create_gdb_ext(openfpm::ve
* \param bc boundary conditions
*
*/
template<int dim, typename Decomposition> inline void create_gdb_ext(openfpm::vector<GBoxes<dim>> & gdb_ext, Decomposition & dec, const size_t (& sz)[dim], const Box<Decomposition::dims,typename Decomposition::stype> & domain, typename Decomposition::stype (& spacing)[dim])
template<int dim, typename Decomposition>
inline void create_gdb_ext(openfpm::vector<GBoxes<dim>> & gdb_ext,
Decomposition & dec,
const size_t (& sz)[dim],
const Box<Decomposition::dims,
typename Decomposition::stype> & domain,
typename Decomposition::stype (& spacing)[dim])
{
// Create the cell decomposer
CellDecomposer_sm<Decomposition::dims,typename Decomposition::stype, shift<Decomposition::dims,typename Decomposition::stype>> cd_sm;
......
#ifndef GRID_DIST_UNIT_TEST_HPP
#define GRID_DIST_UNIT_TEST_HPP
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#include "Point_test.hpp"
#include "grid_dist_id.hpp"
#include "Grid/grid_dist_id.hpp"
#include "data_type/scalar.hpp"
#include "data_type/aggregate.hpp"
......@@ -1590,6 +1587,116 @@ void Test_grid_copy(const Box<3,float> & domain, long int k)
}
}
void Test3D_copy(const Box<3,float> & domain, long int k)
{
typedef Point_test<float> p;
Vcluster & v_cl = create_vcluster();
if ( v_cl.getProcessingUnits() > 32 )
return;
long int big_step = k / 30;
big_step = (big_step == 0)?1:big_step;
long int small_step = 21;
print_test( "Testing grid copy k<=",k);
// 3D test
for ( ; k >= 2 ; k-= (k > 2*big_step)?big_step:small_step )
{
BOOST_TEST_CHECKPOINT( "Testing grid periodick<=" << k );
// grid size
size_t sz[3];
sz[0] = k;
sz[1] = k;
sz[2] = k;
// factor
float factor = pow(create_vcluster().getProcessingUnits()/2.0f,1.0f/3.0f);
// Ghost
Ghost<3,float> g(0.01 / factor);
// periodicity
periodicity<3> pr = {{PERIODIC,PERIODIC,PERIODIC}};
// Distributed grid with id decomposition
grid_dist_id<3,float,Point_test<float>> g_dist(sz,domain,g,pr);
// Grid sm
grid_sm<3,void> info(sz);
// Set to zero the full grid
auto dom = g_dist.getDomainIterator();
while (dom.isNext())
{
auto key = dom.get();
auto key_g = g_dist.getGKey(key);
size_t k = info.LinId(key_g);
g_dist.template get<p::x>(key) = 1 + k;
g_dist.template get<p::y>(key) = 567 + k;
g_dist.template get<p::z>(key) = 341 + k;
g_dist.template get<p::s>(key) = 5670 + k;
g_dist.template get<p::v>(key)[0] = 921 + k;
g_dist.template get<p::v>(key)[1] = 5675 + k;
g_dist.template get<p::v>(key)[2] = 117 + k;
g_dist.template get<p::t>(key)[0][0] = 1921 + k;
g_dist.template get<p::t>(key)[0][1] = 25675 + k;
g_dist.template get<p::t>(key)[0][2] = 3117 + k;
g_dist.template get<p::t>(key)[1][0] = 4921 + k;
g_dist.template get<p::t>(key)[1][1] = 55675 + k;
g_dist.template get<p::t>(key)[1][2] = 6117 + k;
g_dist.template get<p::t>(key)[2][0] = 7921 + k;
g_dist.template get<p::t>(key)[2][1] = 85675 + k;
g_dist.template get<p::t>(key)[2][2] = 9117 + k;
++dom;
}
grid_dist_id<3,float,Point_test<float>> g_dist2 = g_dist;
g_dist2.template ghost_get<0>();
auto dom2 = g_dist2.getDomainIterator();
bool match = true;
// check that the grid store the correct information
while (dom2.isNext())
{
auto key = dom2.get();
auto key_g = g_dist.getGKey(key);
size_t k = info.LinId(key_g);
match &= (g_dist2.template get<p::x>(key) == 1 + k)?true:false;
match &= (g_dist2.template get<p::y>(key) == 567 + k)?true:false;
match &= (g_dist2.template get<p::z>(key) == 341 + k)?true:false;
match &= (g_dist2.template get<p::s>(key) == 5670 + k)?true:false;
match &= (g_dist2.template get<p::v>(key)[0] == 921 + k)?true:false;
match &= (g_dist2.template get<p::v>(key)[1] == 5675 + k)?true:false;
match &= (g_dist2.template get<p::v>(key)[2] == 117 + k)?true:false;
match &= (g_dist2.template get<p::t>(key)[0][0] == 1921 + k)?true:false;
match &= (g_dist2.template get<p::t>(key)[0][1] == 25675 + k)?true:false;
match &= (g_dist2.template get<p::t>(key)[0][2] == 3117 + k)?true:false;
match &= (g_dist2.template get<p::t>(key)[1][0] == 4921 + k)?true:false;
match &= (g_dist2.template get<p::t>(key)[1][1] == 55675 + k)?true:false;
match &= (g_dist2.template get<p::t>(key)[1][2] == 6117 + k)?true:false;
match &= (g_dist2.template get<p::t>(key)[2][0] == 7921 + k)?true:false;
match &= (g_dist2.template get<p::t>(key)[2][1] == 85675 + k)?true:false;
match &= (g_dist2.template get<p::t>(key)[2][2] == 9117 + k)?true:false;
++dom2;
}
BOOST_REQUIRE_EQUAL(match,true);
}
}
#include "grid_dist_id_unit_test_ext_dom.hpp"
#include "grid_dist_id_unit_test_unb_ghost.hpp"
......@@ -1756,6 +1863,16 @@ BOOST_AUTO_TEST_CASE( grid_dist_id_periodic_put_test )
Test3D_periodic_put(domain3,k);
}
BOOST_AUTO_TEST_CASE( grid_dist_id_copy_test )
{
// Domain
Box<3,float> domain3({0.0,0.0,0.0},{1.0,1.0,1.0});
long int k = 128*128*128*create_vcluster().getProcessingUnits();
k = std::pow(k, 1/3.);
Test3D_copy(domain3,k);
}
BOOST_AUTO_TEST_SUITE_END()
#endif
......@@ -8,7 +8,7 @@
#ifndef SRC_GRID_STAGGERED_GRID_DIST_UNIT_TEST_HPP_
#define SRC_GRID_STAGGERED_GRID_DIST_UNIT_TEST_HPP_
#include "staggered_dist_grid.hpp"
#include "Grid/staggered_dist_grid.hpp"
#include "Point_test.hpp"
BOOST_AUTO_TEST_SUITE( staggered_grid_dist_id_test )
......
LINKLIBS = $(HDF5_LDFLAGS) $(HDF5_LIBS) $(OPENMP_LDFLAGS) $(LIBHILBERT_LIB) $(METIS_LIB) $(PTHREAD_LIBS) $(OPT_LIBS) $(BOOST_LDFLAGS) $(BOOST_IOSTREAMS_LIB) $(CUDA_LIBS) $(PETSC_LIB) $(PARMETIS_LIB) $(BOOST_UNIT_TEST_FRAMEWORK_LIB) $(BOOST_CHRONO_LIB) $(BOOST_TIMER_LIB) $(BOOST_SYSTEM_LIB) $(LIBIFCORE)
noinst_PROGRAMS = pdata
pdata_SOURCES = main.cpp pdata_performance.cpp Grid/grid_dist_id_unit_test.cpp lib/pdata.cpp test_multiple_o.cpp ../openfpm_devices/src/memory/HeapMemory.cpp ../openfpm_devices/src/memory/PtrMemory.cpp ../openfpm_vcluster/src/VCluster/VCluster.cpp ../openfpm_devices/src/Memleak_check.cpp
pdata_SOURCES = main.cpp pdata_performance.cpp Grid/tests/grid_dist_id_unit_test.cpp Amr/grid_dist_amr_unit_tests.cpp lib/pdata.cpp test_multiple_o.cpp ../openfpm_devices/src/memory/HeapMemory.cpp ../openfpm_devices/src/memory/PtrMemory.cpp ../openfpm_vcluster/src/VCluster/VCluster.cpp ../openfpm_devices/src/Memleak_check.cpp
pdata_CXXFLAGS = $(HDF5_CPPFLAGS) $(OPENMP_CFLAGS) $(AM_CXXFLAGS) $(LIBHILBERT_INCLUDE) $(PETSC_INCLUDE) $(CUDA_CFLAGS) $(INCLUDES_PATH) $(PARMETIS_INCLUDE) $(METIS_INCLUDE) $(BOOST_CPPFLAGS) $(H5PART_INCLUDE) -DPARALLEL_IO -Wno-unused-local-typedefs
pdata_CFLAGS = $(CUDA_CFLAGS)
pdata_LDADD = $(LINKLIBS) -lparmetis -lmetis
......
......@@ -48,14 +48,14 @@ int main(int argc, char* argv[])
#include "Decomposition/dec_optimizer_unit_test.hpp"
#include "Vector/vector_dist_unit_test.hpp"
#include "Vector/vector_dist_HDF5_chckpnt_restart_test.hpp"
#include "Grid/grid_dist_id_HDF5_chckpnt_restart_test.hpp"
#include "Grid/tests/grid_dist_id_HDF5_chckpnt_restart_test.hpp"
#include "Decomposition/Distribution/Distribution_unit_tests.hpp"
#include "Grid/Iterators/grid_dist_id_iterators_unit_tests.hpp"
//#include "DLB/DLB_unit_test.hpp"
#include "Graph/dist_map_graph_unit_test.hpp"
#include "Graph/DistGraphFactory.hpp"
#include "Decomposition/nn_processor_unit_test.hpp"
#include "Grid/staggered_grid_dist_unit_test.hpp"
#include "Grid/tests/staggered_grid_dist_unit_test.hpp"
#include "Vector/vector_dist_MP_unit_tests.hpp"
#include "Vector/se_class3_vector_unit_tests.hpp"
#include "Vector/vector_dist_dlb_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