Commit b0818064 authored by incardon's avatar incardon

Latest modules

parent 254a8598
openfpm_numerics @ 15cfd496
Subproject commit 4e569e3bcec0ac24ebd0b2a30a1b7bf9b602497d
Subproject commit 15cfd496c3c1998d0dae508c044a29aeaba4da02
......@@ -670,7 +670,7 @@ public:
#ifdef SE_CLASS2
check_valid(this,8);
#endif
return gd_array.get(v1.getLvl()).remove(v1.getKey());
gd_array.get(v1.getLvl()).remove(v1.getKey());
}
/*! \brief Remove a grid point (this function make sense only in case of
......@@ -684,7 +684,7 @@ public:
#ifdef SE_CLASS2
check_valid(this,8);
#endif
return gd_array.get(lvl).remove(v1);
gd_array.get(lvl).remove(v1);
}
//////////////////////////////////////
......@@ -776,6 +776,18 @@ public:
return gd_array.get(lvl).getGridInfoVoid();
}
/*! \brief Get an object containing the grid informations for a specific level
*
* \param lvl level
*
* \return an information object about this grid
*
*/
const size_t size(size_t lvl,size_t i) const
{
return gd_array.get(lvl).size(i);
}
/*! \brief Return the maximum number of levels in the AMR struct
*
* \return the number of levels
......
......@@ -10,6 +10,7 @@
#include <boost/test/unit_test.hpp>
#include "grid_dist_amr.hpp"
#include "Point_test.hpp"
BOOST_AUTO_TEST_SUITE( grid_dist_amr_test )
......@@ -301,12 +302,6 @@ void Test3D_amr_child_parent_get_no_periodic(grid & amr_g, Box<3,float> & domain
}
}
if (match == false)
{
int debug = 0;
debug++;
}
++it2;
}
......@@ -990,4 +985,107 @@ BOOST_AUTO_TEST_CASE( grid_dist_amr_ghost_put_create )
Test3D_ghost_put(sg_dist,k);
}
constexpr int x = 0;
constexpr int y = 0;
BOOST_AUTO_TEST_CASE( grid_dist_amr_unperturbed )
{
periodicity<2> bc = {NON_PERIODIC, NON_PERIODIC};
// Domain
Box<2,double> domain({-0.3,-0.3},{1.0,1.0});
// grid size
size_t sz[2];
sz[0] = 2;
sz[1] = 2;
// Ghost
Ghost<2,long int> g(1);
sgrid_dist_amr<2,double,Point_test<float>> sg(domain,g,bc);
sg.initLevels(10,sz);
// create a grid iterator over a bilion point and draw a spere
openfpm::vector<size_t> lvl;
lvl.resize(sg.getNLvl());
for (size_t i = 0 ; i < sg.getNLvl() ; i++)
{lvl.get(i) = 0;}
for (size_t i = 0 ; i < sg.getNLvl() ; i++)
{
auto it = sg.getGridIterator(i);
int radius = sg.size(i,0) * (i + 6)/(sg.getNLvl()+6);
radius /= 2;
while(it.isNext())
{
auto gkey = it.get();
auto key = it.get_dist();
size_t sx = gkey.get(0) - 50;
size_t sy = gkey.get(1) - 50;
if (sx*sx + sy*sy < radius*radius)
{
sg.template insert<0>(i,key) = 1.0;
lvl.get(i)++;
}
++it;
}
}
// Reduce on all processors
Vcluster & v_cl = create_vcluster();
for (size_t i = 0 ; i < sg.getNLvl() ; i++)
{v_cl.sum(lvl.get(i));}
v_cl.execute();
// now we insert point asking for an unperturbed iterator
openfpm::vector<size_t> lvl2;
lvl2.resize(sg.getNLvl());
for (size_t i = 0 ; i < sg.getNLvl() ; i++)
{lvl2.get(i) = 0;}
auto it4 = sg.getDomainIterator();
while (it4.isNext())
{
auto key = it4.get();
sg.template insert<0>(key.moveSpace(x,1)) = 1.0;
sg.template insert<0>(key.moveSpace(x,-1)) = 1.0;
sg.template insert<0>(key.moveSpace(y,1)) = 1.0;
sg.template insert<0>(key.moveSpace(y,-1)) = 1.0;
sg.template insert<0>(key) = 1.0;
lvl2.get(key.getLvl())++;
if (key.getLvl() < sg.getNLvl() - 1 )
{
sg.moveLvlDw(key);
sg.template insert<0>(key) = 1.0;
sg.template insert<0>(key.moveSpace(x,1)) = 1.0;
sg.template insert<0>(key.moveSpace(x,-1)) = 1.0;
sg.template insert<0>(key.moveSpace(y,1)) = 1.0;
sg.template insert<0>(key.moveSpace(y,-1)) = 1.0;
}
++it4;
}
for (size_t i = 0 ; i < sg.getNLvl() ; i++)
{v_cl.sum(lvl2.get(i));}
v_cl.execute();
for (size_t i = 0 ; i < sg.getNLvl() ; i++)
{BOOST_REQUIRE_EQUAL(lvl.get(i),lvl2.get(i));}
}
BOOST_AUTO_TEST_SUITE_END()
......@@ -44,6 +44,9 @@ class grid_dist_iterator
//! stop point (is the grid size)
grid_key_dx<dim> stop;
//! Type of iteration options
iterator_type opt;
/*! \brief from g_c increment g_c until you find a valid grid
*
*/
......@@ -65,7 +68,7 @@ class grid_dist_iterator
// 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()));
a_it.reinitialize(gList.get(g_c).getIterator(gdb_ext.get(g_c).Dbox.getKP1(),gdb_ext.get(g_c).Dbox.getKP2(),opt));
if (a_it.isNext() == false) {g_c++;}
}
} while (g_c < gList.size() && a_it.isNext() == false);
......@@ -83,8 +86,9 @@ class grid_dist_iterator
*/
grid_dist_iterator(const openfpm::vector<device_grid> & gk,
const openfpm::vector<GBoxes<device_grid::dims>> & gdb_ext,
const grid_key_dx<dim> & stop)
:g_c(0),gList(gk),gdb_ext(gdb_ext),stop(stop)
const grid_key_dx<dim> & stop,
iterator_type opt = iterator_type::normal)
:g_c(0),gList(gk),gdb_ext(gdb_ext),stop(stop),opt(opt)
{
// Initialize the current iterator
// with the first grid
......@@ -104,8 +108,9 @@ class grid_dist_iterator
grid_dist_iterator(const openfpm::vector<device_grid> & gk,
const openfpm::vector<GBoxes<device_grid::dims>> & gdb_ext,
const grid_key_dx<dim> & stop,
const grid_key_dx<dim> (& stencil_pnt)[stencil::nsp])
:g_c(0),gList(gk),gdb_ext(gdb_ext),a_it(stencil_pnt),stop(stop)
const grid_key_dx<dim> (& stencil_pnt)[stencil::nsp],
iterator_type opt = iterator_type::normal)
:g_c(0),gList(gk),gdb_ext(gdb_ext),a_it(stencil_pnt),stop(stop),opt(opt)
{
// Initialize the current iterator
// with the first grid
......@@ -114,12 +119,12 @@ class grid_dist_iterator
//! Copy constructor
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)
:g_c(g.g_c),gList(g.gList),gdb_ext(g.gdb_ext),a_it(g.a_it),stop(g.stop),opt(g.opt)
{}
//! Copy constructor
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)
:g_c(g.g_c),gList(g.gList),gdb_ext(g.gdb_ext),a_it(g.a_it),stop(g.stop),opt(g.opt)
{}
//! Destructor
......
......@@ -149,9 +149,13 @@ class grid_dist_iterator_sub
* \param stop position
* \param gk std::vector of the local grid
* \param gdb_ext information about the local grids
* \param opt unused
*
*/
grid_dist_iterator_sub(const grid_key_dx<dim> & start, const grid_key_dx<dim> & stop ,const openfpm::vector<device_grid> & gk, const openfpm::vector<GBoxes<device_grid::dims>> & gdb_ext)
grid_dist_iterator_sub(const grid_key_dx<dim> & start,
const grid_key_dx<dim> & stop,
const openfpm::vector<device_grid> & gk,
const openfpm::vector<GBoxes<device_grid::dims>> & gdb_ext)
:g_c(0),gList(gk),gdb_ext(gdb_ext),start(start),stop(stop)
{
// Initialize the current iterator
......
......@@ -1646,6 +1646,15 @@ public:
v_cl.execute();
}
/*! \brief Save the the headers of each local grids
*
*
*/
void saveHeaders() const
{
for (size_t i = 0 ; i < loc_grid.size(); i++)
{loc_grid.get(i).saveHeaders();}
}
/*! \brief It return an iterator that span the full grid domain (each processor span its local domain)
*
......@@ -1736,7 +1745,7 @@ public:
*/
grid_dist_iterator<dim,device_grid,
decltype(device_grid::type_of_subiterator()),FREE>
getDomainIterator() const
getDomainIterator(iterator_type opt = iterator_type::normal) const
{
#ifdef SE_CLASS2
check_valid(this,8);
......@@ -1747,9 +1756,15 @@ public:
one.one();
stop = stop - one;
if (opt == iterator_type::normal)
{
saveHeaders();
opt = iterator_type::normal_presaved;
}
grid_dist_iterator<dim,device_grid,
decltype(device_grid::type_of_subiterator()),
FREE> it(loc_grid,gdb_ext,stop);
FREE> it(loc_grid,gdb_ext,stop,opt);
return it;
}
......@@ -1766,7 +1781,8 @@ public:
decltype(device_grid::template type_of_subiterator<stencil_offset_compute<dim,Np>>()),
FREE,
stencil_offset_compute<dim,Np> >
getDomainIteratorStencil(const grid_key_dx<dim> (& stencil_pnt)[Np]) const
getDomainIteratorStencil(const grid_key_dx<dim> (& stencil_pnt)[Np],
iterator_type opt = iterator_type::normal) const
{
#ifdef SE_CLASS2
check_valid(this,8);
......@@ -1777,6 +1793,12 @@ public:
one.one();
stop = stop - one;
if (opt == iterator_type::normal)
{
saveHeaders();
opt = iterator_type::normal_presaved;
}
grid_dist_iterator<dim,device_grid,
decltype(device_grid::template type_of_subiterator<stencil_offset_compute<dim,Np>>()),
FREE,
......@@ -1793,7 +1815,7 @@ public:
grid_dist_iterator<dim,device_grid,
decltype(device_grid::type_of_iterator()),
FIXED>
getDomainGhostIterator() const
getDomainGhostIterator(iterator_type opt = iterator_type::normal) const
{
#ifdef SE_CLASS2
check_valid(this,8);
......@@ -1802,6 +1824,12 @@ public:
for (size_t i = 0 ; i < dim ; i++)
{stop.set_d(i,0);}
if (opt == iterator_type::normal)
{
saveHeaders();
opt = iterator_type::normal_presaved;
}
grid_dist_iterator<dim,device_grid,
decltype(device_grid::type_of_iterator()),
FIXED> it(loc_grid,gdb_ext,stop);
......@@ -1823,11 +1851,19 @@ public:
*/
grid_dist_iterator_sub<dim,device_grid>
getSubDomainIterator(const grid_key_dx<dim> & start,
const grid_key_dx<dim> & stop) const
const grid_key_dx<dim> & stop,
iterator_type opt = iterator_type::normal) const
{
#ifdef SE_CLASS2
check_valid(this,8);
#endif
if (opt == iterator_type::normal)
{
saveHeaders();
opt = iterator_type::normal_presaved;
}
grid_dist_iterator_sub<dim,device_grid> it(start,stop,loc_grid,gdb_ext);
return it;
......@@ -1845,8 +1881,21 @@ public:
* \return an iterator on the sub-part of the grid
*
*/
grid_dist_iterator_sub<dim,device_grid> getSubDomainIterator(const long int (& start)[dim], const long int (& stop)[dim]) const
grid_dist_iterator_sub<dim,device_grid>
getSubDomainIterator(const long int (& start)[dim],
const long int (& stop)[dim],
iterator_type opt = iterator_type::normal) const
{
#ifdef SE_CLASS2
check_valid(this,8);
#endif
if (opt == iterator_type::normal)
{
saveHeaders();
opt = iterator_type::normal_presaved;
}
grid_dist_iterator_sub<dim,device_grid> it(grid_key_dx<dim>(start),grid_key_dx<dim>(stop),loc_grid,gdb_ext);
return it;
......
......@@ -105,6 +105,4 @@ static void Test2D_core(grid_dist_id<2, float, scalar<float>> & g_dist, const si
BOOST_REQUIRE_EQUAL(match,true);
}
#endif /* SRC_GRID_TESTS_GRID_DIST_ID_UTIL_TESTS_HPP_ */
......@@ -233,5 +233,71 @@ BOOST_AUTO_TEST_CASE( sgrid_dist_id_basic_test)
BOOST_REQUIRE_EQUAL(match,true);
}
BOOST_AUTO_TEST_CASE( sgrid_dist_id_unpertubed_iterator )
{
periodicity<3> bc = {NON_PERIODIC, NON_PERIODIC, NON_PERIODIC};
// Domain
Box<3,double> domain({-0.3,-0.3,-0.3},{1.0,1.0,1.0});
// grid size
size_t sz[3];
sz[0] = 100;
sz[1] = 100;
sz[2] = 100;
// Ghost
Ghost<3,long int> g(1);
sgrid_dist_id<3,double,Point_test<float>> sg(sz,domain,g,bc);
// create a grid iterator over a bilion point and draw a spere
auto it = sg.getGridIterator();
size_t cnt = 0;
while(it.isNext())
{
auto gkey = it.get();
auto key = it.get_dist();
size_t sx = gkey.get(0) - 50;
size_t sy = gkey.get(1) - 50;
size_t sz = gkey.get(2) - 50;
if (sx*sx + sy*sy + sz*sz < 50*50)
{
sg.template insert<0>(key) = 1.0;
cnt++;
}
++it;
}
// now we insert point asking for an unperturbed iterator
size_t cnt2 = 0;
auto it4 = sg.getDomainIterator();
while (it4.isNext())
{
auto key = it4.get();
sg.template insert<0>(key.move(x,1)) = 1.0;
sg.template insert<0>(key.move(x,-1)) = 1.0;
sg.template insert<0>(key.move(y,1)) = 1.0;
sg.template insert<0>(key.move(y,-1)) = 1.0;
sg.template insert<0>(key.move(z,1)) = 1.0;
sg.template insert<0>(key.move(z,-1)) = 1.0;
sg.template insert<0>(key) = 1.0;
cnt2++;
++it4;
}
BOOST_REQUIRE_EQUAL(cnt,cnt2);
}
BOOST_AUTO_TEST_SUITE_END()
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