Commit 04778012 authored by Pietro Incardona's avatar Pietro Incardona

Fixing extended domain bug

parent 0bba6b9e
......@@ -152,6 +152,48 @@ protected:
// Receive counter
size_t recv_cnt;
/*! \brief It convert the box from the domain decomposition into sub-domain
*
* The decomposition box from the domain-decomposition contain the box in integer
* coordinates
*
* \param loc_box local box
*
* \return the corresponding sib-domain
*
*/
SpaceBox<dim,T> convertDecBoxIntoSubDomain(const SpaceBox<dim,size_t> & loc_box)
{
// A point with all coordinate to one
size_t one[dim];
for (size_t i = 0 ; i < dim ; i++) {one[i] = 1;}
SpaceBox<dim, size_t> sub_dc = loc_box;
SpaceBox<dim, size_t> sub_dce = sub_dc;
sub_dce.expand(one);
SpaceBox<dim, T> sub_d(sub_dce);
sub_d.mul(spacing);
sub_d += domain.getP1();
// we add the
// Fixing sub-domains to cover all the domain
// Fixing sub_d
// if (loc_box) is at the boundary we have to ensure that the box span the full
// domain (avoiding rounding off error)
for (size_t i = 0; i < dim; i++)
{
if (sub_dc.getHigh(i) == cd.getGrid().size(i) - 1)
sub_d.setHigh(i, domain.getHigh(i));
if (sub_dc.getLow(i) == 0)
sub_d.setLow(i,domain.getLow(i));
}
return sub_d;
}
protected:
......@@ -199,67 +241,18 @@ public:
// optimize the decomposition
d_o.template optimize<nm_v::sub_id, nm_v::proc_id>(dist.getGraph(), p_id, loc_box, box_nn_processor,bc);
// reset ss_box
ss_box = domain;
ss_box -= ss_box.getP1();
// Initialize ss_box and bbox
if (loc_box.size() >= 0)
{
SpaceBox<dim, size_t> sub_dc = loc_box.get(0);
SpaceBox<dim, T> sub_d(sub_dc);
sub_d.mul(spacing);
sub_d.expand(spacing);
sub_d += domain.getP1();
// we add the
// Fixing sub-domains to cover all the domain
// Fixing sub_d
// if (loc_box) is at the boundary we have to ensure that the box span the full
// domain (avoiding rounding off error)
for (size_t i = 0; i < dim; i++)
{
if (sub_dc.getHigh(i) == cd.getGrid().size(i) - 1)
sub_d.setHigh(i, domain.getHigh(i));
if (sub_dc.getLow(i) == 0)
sub_d.setLow(i,domain.getLow(i));
}
// add the sub-domain
sub_domains.add(sub_d);
ss_box = sub_d;
ss_box -= ss_box.getP1();
bbox = sub_d;
}
/* if (loc_box.size())
bbox.zero();
ss_box = domain;*/
bbox = convertDecBoxIntoSubDomain(loc_box.get(0));
// convert into sub-domain
for (size_t s = 1; s < loc_box.size(); s++)
for (size_t s = 0; s < loc_box.size(); s++)
{
SpaceBox<dim, size_t> sub_dc = loc_box.get(s);
SpaceBox<dim, T> sub_d(sub_dc);
// re-scale and add spacing (the end is the starting point of the next domain + spacing)
sub_d.mul(spacing);
sub_d.expand(spacing);
sub_d += domain.getP1();
// Fixing sub-domains to cover all the domain
// Fixing sub_d
// if (loc_box) is a the boundary we have to ensure that the box span the full
// domain (avoiding rounding off error)
for (size_t i = 0; i < dim; i++)
{
if (sub_dc.getHigh(i) == cd.getGrid().size(i) - 1)
sub_d.setHigh(i, domain.getHigh(i));
if (sub_dc.getLow(i) == 0)
sub_d.setLow(i,domain.getLow(i));
}
SpaceBox<dim,T> sub_d = convertDecBoxIntoSubDomain(loc_box.get(s));
// add the sub-domain
sub_domains.add(sub_d);
......
......@@ -14,10 +14,10 @@ void print_test(std::string test, size_t sz)
std::cout << test << " " << sz << "\n";
}
BOOST_AUTO_TEST_CASE( grid_dist_id_domain_grid_unit_converter_test)
BOOST_AUTO_TEST_CASE( grid_dist_id_domain_grid_unit_converter3D_test)
{
// Domain
Box<2,float> domain({0.0,0.0},{1.0,1.0});
Box<3,float> domain({-0.3,-0.3,-0.3},{1.0,1.0,1.0});
// Initialize the global VCluster
init_global_v_cluster(&boost::unit_test::framework::master_test_suite().argc,&boost::unit_test::framework::master_test_suite().argv);
......@@ -30,9 +30,90 @@ BOOST_AUTO_TEST_CASE( grid_dist_id_domain_grid_unit_converter_test)
// Test several grid dimensions
long int k = 293;
long int big_step = k / 30;
big_step = (big_step == 0)?1:big_step;
long int small_step = 21;
print_test( "Testing 3D grid converter k<=",k);
// 3D test
for ( ; k >= 2 ; k-= (k > 2*big_step)?big_step:small_step )
{
BOOST_TEST_CHECKPOINT( "Testing 3D grid converter k=" << k );
// grid size
size_t sz[3];
sz[0] = k;
sz[1] = k;
sz[2] = k;
// Ghost
Ghost<3,float> g(0.01);
// Distributed grid with id decomposition
grid_dist_id<3, float, scalar<float>, CartDecomposition<3,float>> g_dist(sz,domain,g);
// get the decomposition
auto & dec = g_dist.getDecomposition();
// check the consistency of the decomposition
bool val = dec.check_consistency();
BOOST_REQUIRE_EQUAL(val,true);
// for each local volume
// Get the number of local grid needed
size_t n_grid = dec.getNSubDomain();
size_t vol = 0;
// vector of boxes
openfpm::vector<Box<3,size_t>> vb;
// Allocate the grids
for (size_t i = 0 ; i < n_grid ; i++)
{
// Get the local hyper-cube
SpaceBox<3,float> sub = dec.getSubDomain(i);
sub -= domain.getP1();
Box<3,size_t> g_box = g_dist.getCellDecomposer().convertDomainSpaceIntoGridUnits(sub);
vb.add(g_box);
vol += g_box.getVolumeKey();
}
// Create a writer and write
VTKWriter<openfpm::vector<Box<3,size_t>>,VECTOR_BOX> vtk_box2;
vtk_box2.add(vb);
vtk_box2.write(std::to_string(v_cl.getProcessUnitID()) + "vtk_box_3D.vtk");
v_cl.sum(vol);
v_cl.execute();
BOOST_REQUIRE_EQUAL(vol,sz[0]*sz[1]*sz[2]);
}
}
BOOST_AUTO_TEST_CASE( grid_dist_id_domain_grid_unit_converter_test)
{
// Domain
Box<2,float> domain({0.0,0.0},{1.0,1.0});
// Initialize the global VCluster
init_global_v_cluster(&boost::unit_test::framework::master_test_suite().argc,&boost::unit_test::framework::master_test_suite().argv);
Vcluster & v_cl = *global_v_cluster;
// Skip this test on big scale
if (v_cl.getProcessingUnits() >= 32)
return;
for (size_t k = 1024 ; k >= 2 ; k--)
{
BOOST_TEST_CHECKPOINT( "Testing grid k=" << k );
BOOST_TEST_CHECKPOINT( "Testing grid converter 3D k=" << k );
// grid size
size_t sz[2];
......
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