1 #define BOOST_TEST_DYN_LINK
2 #include <boost/test/unit_test.hpp>
4 #include "Decomposition/CartDecomposition.hpp"
5 #include "util/mathutil.hpp"
7 BOOST_AUTO_TEST_SUITE (CartDecomposition_test)
9 #define SUB_UNIT_FACTOR 1024
13 float radius2 = pow(radius, 2);
19 for (
size_t i = 0; i < n_v; i++)
23 eq = pow((pos[0] - center.
get(0)), 2) + pow((pos[1] - center.
get(1)), 2);
34 float radius2 = radius * radius;
40 for (
size_t i = 0; i < n_v; i++)
44 eq = pow((pos[0] - center.
get(0)), 2) + pow((pos[1] - center.
get(1)), 2) + pow((pos[2] - center.
get(2)), 2);
55 BOOST_AUTO_TEST_CASE( CartDecomposition_non_periodic_test)
69 size_t n_sub = n_proc * SUB_UNIT_FACTOR;
72 for (
int i = 0; i < 3; i++)
73 { div[i] = openfpm::math::round_big_2(pow(n_sub,1.0/3));}
79 size_t bc[] = { NON_PERIODIC, NON_PERIODIC, NON_PERIODIC };
99 for (
size_t j = 0; j < pr.
size(); j++)
101 if (pr.get(j) == proc)
102 { found =
true;
break;}
110 BOOST_REQUIRE_EQUAL(found,
true);
116 BOOST_REQUIRE_EQUAL(val,
true);
126 BOOST_REQUIRE_EQUAL(ret,
true);
137 BOOST_REQUIRE_EQUAL(ret,
true);
141 BOOST_REQUIRE_EQUAL(ret,
true);
144 BOOST_AUTO_TEST_CASE( CartDecomposition_periodic_test)
159 size_t n_sub = n_proc * SUB_UNIT_FACTOR;
162 for (
int i = 0; i < 3; i++)
163 { div[i] = openfpm::math::round_big_2(pow(n_sub,1.0/3));}
169 size_t bc[] = { PERIODIC, PERIODIC, PERIODIC };
191 for (
size_t j = 0; j < pr.
size(); j++)
193 if (pr.get(j) == proc)
194 { found =
true;
break;}
202 BOOST_REQUIRE_EQUAL(found,
true);
207 BOOST_REQUIRE_EQUAL(val,
true);
216 BOOST_REQUIRE_EQUAL(ret,
true);
229 BOOST_REQUIRE_EQUAL(ret,
true);
233 BOOST_REQUIRE_EQUAL(ret,
true);
239 BOOST_AUTO_TEST_CASE( CartDecomposition_ext_non_periodic_test)
253 size_t n_sub = n_proc * SUB_UNIT_FACTOR;
256 for (
int i = 0 ; i < 3 ; i++)
257 {div[i] = openfpm::math::round_big_2(pow(n_sub,1.0/3));}
263 size_t bc[] = {NON_PERIODIC,NON_PERIODIC,NON_PERIODIC};
276 dec_ext.setParameters(dec,g,box_ext);
283 BOOST_REQUIRE_EQUAL(dec_ext.getNSubDomain(),dec.
getNSubDomain());
286 for (
size_t i = 0; i < dec_ext.getNSubDomain() ; i++)
288 volume += dec_ext.getSubDomain(i).getVolume();
289 BOOST_REQUIRE_EQUAL(dec_ext.getSubDomain(i).isContained(dec.
getSubDomain(i)),
true);
295 BOOST_REQUIRE_CLOSE(volume,1.728,0.0001);
299 double volume_g = 0.0;
300 double volume_ge = 0.0;
307 volume_ge += dec_ext.getProcessorEGhostBox(p,i).getVolume();
309 BOOST_REQUIRE_EQUAL(dec_ext.getProcessorEGhostBox(p,i).isContained(dec_ext.getProcessorEGhostBox(p,i)),
true);
319 BOOST_REQUIRE(volume_ge > volume_g*1.05);
329 volume_ge += dec_ext.getProcessorIGhostBox(p,i).getVolume();
330 BOOST_REQUIRE_EQUAL(dec_ext.getProcessorIGhostBox(p,i).isContained(dec.
getProcessorIGhostBox(p,i)),
true);
340 BOOST_REQUIRE(volume_ge > volume_g*1.05);
345 BOOST_AUTO_TEST_CASE( CartDecomposition_non_periodic_test_dist_grid)
360 size_t n_sub = n_proc * SUB_UNIT_FACTOR*4*4*4;
363 for (
int i = 0; i < 3; i++)
364 {div[i] = openfpm::math::round_big_2(pow(n_sub,1.0/3));}
367 for (
int i = 0; i < 3; i++)
368 {div_sub[i] = div[i] / 4;}
376 size_t bc[] = { NON_PERIODIC, NON_PERIODIC, NON_PERIODIC };
381 dec.
write(
"Test_sub_dist2");
397 for (
size_t j = 0; j < pr.
size(); j++)
399 if (pr.get(j) == proc)
400 { found =
true;
break;}
408 BOOST_REQUIRE_EQUAL(found,
true);
414 BOOST_REQUIRE_EQUAL(val,
true);
417 BOOST_AUTO_TEST_CASE( CartDecomposition_nsub_algo_functions_test)
422 nsub_to_div2<3>(div,n_sub,3);
424 BOOST_REQUIRE_EQUAL(div[0],8ul);
425 BOOST_REQUIRE_EQUAL(div[1],8ul);
426 BOOST_REQUIRE_EQUAL(div[2],8ul);
428 nsub_to_div2<3>(div,n_sub,2);
430 BOOST_REQUIRE_EQUAL(div[0],16ul);
431 BOOST_REQUIRE_EQUAL(div[1],16ul);
432 BOOST_REQUIRE_EQUAL(div[2],1ul);
434 nsub_to_div2<3>(div,n_sub,1);
436 BOOST_REQUIRE_EQUAL(div[0],128ul);
437 BOOST_REQUIRE_EQUAL(div[1],1ul);
438 BOOST_REQUIRE_EQUAL(div[2],1ul);
441 nsub_to_div<3>(div,n_sub,3);
443 BOOST_REQUIRE_EQUAL(div[0],5ul);
444 BOOST_REQUIRE_EQUAL(div[1],5ul);
445 BOOST_REQUIRE_EQUAL(div[2],5ul);
447 nsub_to_div<3>(div,n_sub,2);
449 BOOST_REQUIRE_EQUAL(div[0],13ul);
450 BOOST_REQUIRE_EQUAL(div[1],13ul);
451 BOOST_REQUIRE_EQUAL(div[2],1ul);
453 nsub_to_div<3>(div,n_sub,1);
455 BOOST_REQUIRE_EQUAL(div[0],192ul);
456 BOOST_REQUIRE_EQUAL(div[1],1ul);
457 BOOST_REQUIRE_EQUAL(div[2],1ul);
465 for(
size_t i = 0 ; i < 50 ; i++)
469 bc[i] = NON_PERIODIC;
479 auto & v_cl = create_vcluster();
480 if (v_cl.size() == 1)
482 for (
size_t i = 0 ; i < 50 ; i++)
485 {BOOST_REQUIRE_EQUAL(div2[i],2ul);}
487 {BOOST_REQUIRE_EQUAL(div2[i],1ul);}
491 if (v_cl.size() == 2)
493 for (
size_t i = 0 ; i < 50 ; i++)
496 {BOOST_REQUIRE_EQUAL(div2[i],2ul);}
498 {BOOST_REQUIRE_EQUAL(div2[i],1ul);}
502 if (v_cl.size() == 3)
504 for (
size_t i = 0 ; i < 50 ; i++)
507 {BOOST_REQUIRE_EQUAL(div2[i],13ul);}
509 {BOOST_REQUIRE_EQUAL(div2[i],1ul);}
513 if (v_cl.size() == 4)
515 for (
size_t i = 0 ; i < 50 ; i++)
518 {BOOST_REQUIRE_EQUAL(div2[i],2ul);}
520 {BOOST_REQUIRE_EQUAL(div2[i],1ul);}
524 if (v_cl.size() == 5)
526 for (
size_t i = 0 ; i < 50 ; i++)
529 {BOOST_REQUIRE_EQUAL(div2[i],2ul);}
531 {BOOST_REQUIRE_EQUAL(div2[i],1ul);}
535 if (v_cl.size() == 6)
537 for (
size_t i = 0 ; i < 50 ; i++)
540 {BOOST_REQUIRE_EQUAL(div2[i],7ul);}
542 {BOOST_REQUIRE_EQUAL(div2[i],1ul);}
547 BOOST_AUTO_TEST_SUITE_END()
size_t getNIGhostBox() const
Return the total number of the calculated internal ghost boxes.
void sum(T &num)
Sum the numbers across all processors and get the result.
void setGoodParameters(::Box< dim, T > domain_, const size_t(&bc)[dim], const Ghost< dim, T > &ghost, size_t dec_gran, const grid_sm< dim, void > &sec_dist=grid_sm< dim, void >())
Set the best parameters for the decomposition.
This class represent an N-dimensional box.
bool is_equal(CartDecomposition< dim, T, Memory > &cart)
Check if the CartDecomposition contain the same information.
void getParameters(size_t(&div_)[dim])
return the parameters of the decomposition
This class decompose a space into sub-sub-domains and distribute them across processors.
const ::Box< dim, T > & getProcessorIGhostBox(size_t id, size_t j) const
Get the j Internal ghost box for one processor.
void execute()
Execute all the requests.
size_t getIGhostBoxProcessor(size_t b_id) const
Given the internal ghost box id, it return the near processor at witch belong or the near processor t...
void decompose()
Start decomposition.
void setParameters(const size_t(&div_)[dim],::Box< dim, T > domain_, const size_t(&bc)[dim], const Ghost< dim, T > &ghost, const grid_sm< dim, void > &sec_dist=grid_sm< dim, void >())
Set the parameter of the decomposition.
size_t getNNProcessors() const
Get the number of Near processors.
bool check_consistency()
function to check the consistency of the information of the decomposition
size_t getProcessorNEGhost(size_t id) const
Get the number of External ghost boxes for one processor id.
void setHigh(int i, T val)
set the high interval of the box
This class implement the point shape in an N-dimensional space.
const ::Box< dim, T > & getProcessorEGhostBox(size_t id, size_t j) const
Get the j External ghost box.
const openfpm::vector< size_t > ghost_processorID(const Point< dim, T > &p, const int opt=MULTIPLE)
Given a position it return if the position belong to any neighborhood processor ghost (Internal ghost...
void getSubSubDomainPosition(size_t id, T(&pos)[dim])
function that return the position of the cell in the space
Implementation of VCluster class.
This class decompose a space into sub-sub-domains and distribute them across processors.
size_t getProcessorNIGhost(size_t id) const
Get the number of Internal ghost boxes for one processor.
size_t getNSubDomain()
Get the number of local sub-domains.
SpaceBox< dim, T > getSubDomain(size_t lc)
Get the local sub-domain.
class to select the returned id by ghost_processorID
CartDecomposition< dim, T, Memory, Distribution > duplicate(const Ghost< dim, T > &g) const
It create another object that contain the same decomposition information but with different ghost box...
const T & get(size_t i) const
Get coordinate.
void setLow(int i, T val)
set the low interval of the box
bool write(std::string output) const
Write the decomposition as VTK file.
bool is_equal_ng(CartDecomposition< dim, T, Memory > &cart)
Check if the CartDecomposition contain the same information with the exception of the ghost part It i...
void setSubSubDomainComputationCost(size_t id, size_t weight)
Function that set the computational cost for a of a sub-sub domain.
const ::Box< dim, T > & getIGhostBox(size_t b_id) const
Given the internal ghost box id, it return the internal ghost box.
size_t getProcessingUnits()
Get the total number of processors.
Point< dim, T > rnd()
Generate a random point inside the box.