Commit e5756fb2 authored by Pietro Incardona's avatar Pietro Incardona

Adding nnprcs test

parent 8fd4e3d4
openfpm_data @ a5ff72b5
Subproject commit 360031739584423b20497b1364d2c3bcf26c5143
Subproject commit a5ff72b524862871657f5769aa4d814c2486df0c
......@@ -89,7 +89,7 @@ BOOST_AUTO_TEST_CASE( nn_processor_np_test)
nn_prcs<2,float> nnp(v_cl);
nnp.create(box_nn_processor, sub_domains);
BOOST_REQUIRE_EQUAL(nnp.getNNProcessors(),3);
BOOST_REQUIRE_EQUAL(nnp.getNNProcessors(),3ul);
if (v_cl.getProcessUnitID() == 0)
{
......@@ -201,67 +201,203 @@ BOOST_AUTO_TEST_CASE( nn_processor_np_test)
BOOST_AUTO_TEST_CASE( nn_processor_box_periodic_test)
{
constexpr unsigned int dim = 3;
typedef float T;
// Vcluster
Vcluster & v_cl = create_vcluster();
Box<dim,T> domain({0.0,0.0,0.0},{1.0,1.0,1.0});
Point<dim,T> middle({0.5,0.5,0.5});
/*!
*
* We test this situation
*
* \verbatim
+-------+-------+
| | |
| 0 | 1 |
| | |
| | |
+---------------+
| | |
| 2 | 3 |
| | |
| | |
+-------+-------+
const size_t bc[dim] = {PERIODIC,PERIODIC,PERIODIC};
* \endverbatim
*
*
*/
// Vcluster
Vcluster & v_cl = create_vcluster();
if (v_cl.getProcessingUnits() != 4)
return;
Ghost<dim,T> ghost(0.01);
Box<2,float> domain({0.0,0.0},{1.0,1.0});
const size_t bc[2] = {PERIODIC,PERIODIC};
//////////////
Ghost<2,float> ghost(0.01);
nn_prcs<dim,T> nnp(v_cl);
openfpm::vector<openfpm::vector<long unsigned int>> box_nn_processor;
openfpm::vector<SpaceBox<2,float>> sub_domains;
/* std::unordered_map<size_t, N_box<dim,T>> & nnp_sub = nnp.get_nn_processor_subdomains();
openfpm::vector<size_t> & nnp_np = nnp.get_nn_processors();
create_decomposition2x2(box_nn_processor,sub_domains);
// we add the boxes
//////////////
size_t tot_n = 0;
HyperCube<dim> hyp;
nn_prcs<2,float> nnp(v_cl);
nnp.create(box_nn_processor, sub_domains);
// check that nn_processor contain the correct boxes
for (long int i = dim-1 ; i >= 0 ; i--)
nnp.applyBC(domain,ghost,bc);
if (v_cl.getProcessUnitID() == 0)
{
std::vector<comb<dim>> cmbs = hyp.getCombinations_R(i);
BOOST_REQUIRE_EQUAL(nnp.getNearSubdomains(1).size(),4);
BOOST_REQUIRE_EQUAL(nnp.getNearSubdomains(2).size(),4);
BOOST_REQUIRE_EQUAL(nnp.getNearSubdomains(3).size(),4);
for (size_t j = 0 ; j < cmbs.size() ; j++)
{
// Create a fake processor number
size_t prc = i;
openfpm::vector<Box<2,float>> bv;
Point<dim,T> p1 = (middle * toPoint<dim,T>::convert(cmbs[j]) + middle)* 1.0/1.1;
Point<dim,T> p2 = p1 + Point<dim,T>({0.1,0.1,0.1}) * 1.0/1.1;
bv.add(Box<2,float>({0.5,0},{1.0,0.5}));
bv.add(Box<2,float>({-0.5,0.0},{0.0,0.5}));
bv.add(Box<2,float>({0.5,1.0},{1.0,1.5}));
bv.add(Box<2,float>({-0.5,1.0},{0.0,1.5}));
Box<dim,T> bx(p1,p2);
nnp_sub[prc+1].id = prc;
nnp_sub[prc+1].bx.add(bx);
bool ret = nnp.getNearSubdomains(1) == bv;
BOOST_REQUIRE_EQUAL(ret,true);
tot_n++;
}
bv.clear();
bv.add(Box<2,float>({0.0,0.5},{0.5,1.0}));
bv.add(Box<2,float>({1.0,0.5},{1.5,1.0}));
bv.add(Box<2,float>({0.0,-0.5},{0.5,0.0}));
bv.add(Box<2,float>({1.0,-0.5},{1.5,0.0}));
ret = nnp.getNearSubdomains(2) == bv;
BOOST_REQUIRE_EQUAL(ret,true);
bv.clear();
bv.add(Box<2,float>({0.5,0.5},{1.0,1.0}));
bv.add(Box<2,float>({-0.5,0.5},{0.0,1.0}));
bv.add(Box<2,float>({0.5,-0.5},{1.0,0.0}));
bv.add(Box<2,float>({-0.5,-0.5},{0.0,0.0}));
ret = nnp.getNearSubdomains(3) == bv;
BOOST_REQUIRE_EQUAL(ret,true);
}
else if (v_cl.getProcessUnitID() == 1)
{
BOOST_REQUIRE_EQUAL(nnp.getNearSubdomains(0).size(),4);
BOOST_REQUIRE_EQUAL(nnp.getNearSubdomains(2).size(),4);
BOOST_REQUIRE_EQUAL(nnp.getNearSubdomains(3).size(),4);
openfpm::vector<Box<2,float>> bv;
bv.add(Box<2,float>({0.0,0},{0.5,0.5}));
bv.add(Box<2,float>({1.0,0.0},{1.5,0.5}));
bv.add(Box<2,float>({0.0,1.0},{0.5,1.5}));
bv.add(Box<2,float>({1.0,1.0},{1.5,1.5}));
bool ret = nnp.getNearSubdomains(0) == bv;
BOOST_REQUIRE_EQUAL(ret,true);
for (size_t i = 0; i < dim; i++)
bv.clear();
bv.add(Box<2,float>({0.0,0.5},{0.5,1.0}));
bv.add(Box<2,float>({1.0,0.5},{1.5,1.0}));
bv.add(Box<2,float>({0.0,-0.5},{0.5,0.0}));
bv.add(Box<2,float>({1.0,-0.5},{1.5,0.0}));
ret = nnp.getNearSubdomains(2) == bv;
BOOST_REQUIRE_EQUAL(ret,true);
bv.clear();
bv.add(Box<2,float>({0.5,0.5},{1.0,1.0}));
bv.add(Box<2,float>({-0.5,0.5},{0.0,1.0}));
bv.add(Box<2,float>({0.5,-0.5},{1.0,0.0}));
bv.add(Box<2,float>({-0.5,-0.5},{0.0,0.0}));
ret = nnp.getNearSubdomains(3) == bv;
BOOST_REQUIRE_EQUAL(ret,true);
}
else if (v_cl.getProcessUnitID() == 2)
{
nnp_np.add(i+1);
}*/
BOOST_REQUIRE_EQUAL(nnp.getNearSubdomains(0).size(),4);
BOOST_REQUIRE_EQUAL(nnp.getNearSubdomains(1).size(),4);
BOOST_REQUIRE_EQUAL(nnp.getNearSubdomains(3).size(),4);
// check that nn_processor contain the correct boxes
openfpm::vector<Box<2,float>> bv;
nnp.applyBC(domain,ghost,bc);
bv.add(Box<2,float>({0.0,0},{0.5,0.5}));
bv.add(Box<2,float>({1.0,0.0},{1.5,0.5}));
bv.add(Box<2,float>({0.0,1.0},{0.5,1.5}));
bv.add(Box<2,float>({1.0,1.0},{1.5,1.5}));
if (v_cl.getProcessUnitID() == 0)
bool ret = nnp.getNearSubdomains(0) == bv;
BOOST_REQUIRE_EQUAL(ret,true);
bv.clear();
bv.add(Box<2,float>({0.5,0},{1.0,0.5}));
bv.add(Box<2,float>({-0.5,0.0},{0.0,0.5}));
bv.add(Box<2,float>({0.5,1.0},{1.0,1.5}));
bv.add(Box<2,float>({-0.5,1.0},{0.0,1.5}));
ret = nnp.getNearSubdomains(1) == bv;
BOOST_REQUIRE_EQUAL(ret,true);
bv.clear();
bv.add(Box<2,float>({0.5,0.5},{1.0,1.0}));
bv.add(Box<2,float>({-0.5,0.5},{0.0,1.0}));
bv.add(Box<2,float>({0.5,-0.5},{1.0,0.0}));
bv.add(Box<2,float>({-0.5,-0.5},{0.0,0.0}));
ret = nnp.getNearSubdomains(3) == bv;
BOOST_REQUIRE_EQUAL(ret,true);
}
else if (v_cl.getProcessUnitID() == 3)
{
BOOST_REQUIRE_EQUAL(nnp.getNearSubdomains(0).size(),4);
BOOST_REQUIRE_EQUAL(nnp.getNearSubdomains(1).size(),4);
BOOST_REQUIRE_EQUAL(nnp.getNearSubdomains(2).size(),4);
openfpm::vector<Box<2,float>> bv;
bv.add(Box<2,float>({0.0,0},{0.5,0.5}));
bv.add(Box<2,float>({1.0,0.0},{1.5,0.5}));
bv.add(Box<2,float>({0.0,1.0},{0.5,1.5}));
bv.add(Box<2,float>({1.0,1.0},{1.5,1.5}));
bool ret = nnp.getNearSubdomains(0) == bv;
BOOST_REQUIRE_EQUAL(ret,true);
bv.clear();
bv.add(Box<2,float>({0.5,0},{1.0,0.5}));
bv.add(Box<2,float>({-0.5,0.0},{0.0,0.5}));
bv.add(Box<2,float>({0.5,1.0},{1.0,1.5}));
bv.add(Box<2,float>({-0.5,1.0},{0.0,1.5}));
ret = nnp.getNearSubdomains(1) == bv;
BOOST_REQUIRE_EQUAL(ret,true);
bv.clear();
bv.add(Box<2,float>({0.0,0.5},{0.5,1.0}));
bv.add(Box<2,float>({1.0,0.5},{1.5,1.0}));
bv.add(Box<2,float>({0.0,-0.5},{0.5,0.0}));
bv.add(Box<2,float>({1.0,-0.5},{1.5,0.0}));
/* for (size_t i = 0 ; i < nnp.getNearSubdomains(2).size() ; i++)
{
Box<2,float> b = nnp.getNearSubdomains(2).get(i);
std::cout << "BOX: " << b.toString() << std::endl;
}*/
ret = nnp.getNearSubdomains(2) == bv;
BOOST_REQUIRE_EQUAL(ret,true);
}
// BOOST_REQUIRE_EQUAL(nnp.getNearSubdomains(nnp.IDtoProc(2)).size(),12ul);
// BOOST_REQUIRE_EQUAL(nnp.getNearSubdomains(nnp.IDtoProc(0)).size(),8ul*8ul);
// BOOST_REQUIRE_EQUAL(nnp.getNearSubdomains(nnp.IDtoProc(1)).size(),12ul*4ul);
}
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