Commit 98254b90 authored by incardon's avatar incardon

Adding function isInsideNP_with_border on box

parent e667bae7
......@@ -8,6 +8,9 @@
#include "Grid/Encap.hpp"
#include <sstream>
#define PERIODIC 1
#define NON_PERIODIC 0
/*! \brief It define if we want the upper base or the down base (Lower or upper)
* extreme of the interval
*
......@@ -995,6 +998,37 @@ public:
return true;
}
/*! \brief Check if the point is inside the region excluding the positive part
*
* In periodic boundary conditions the positive border is not included, but match the beginning
*
* \param p point to check
* \return true if the point is inside the space
*
*/
template<typename bc_type>
__device__ __host__ inline bool isInsideNP_with_border(const Point<dim,T> & p, const Box<dim,T> & border, const bc_type (& bc)[dim]) const
{
// check if bound
for (size_t i = 0 ; i < dim ; i++)
{
// if outside the region return false
if ( p.get(i) < this->getLow(i)
|| (bc[i] == NON_PERIODIC && ((this->getHigh(i) != border.getHigh(i) && p.get(i) >= this->getHigh(i)) || (this->getHigh(i) == border.getHigh(i) && p.get(i) > this->getHigh(i)) ) )
|| (bc[i] == PERIODIC && p.get(i) >= this->getHigh(i)))
{
// Out of bound
return false;
}
}
// In bound
return true;
}
/*! \brief Check if the point is inside the region excluding the borders
*
* \param p point to check
......
......@@ -366,6 +366,126 @@ BOOST_AUTO_TEST_CASE( box_min_distance_test )
BOOST_REQUIRE_CLOSE(b1.min_distance(b10),sqrt(0.01 + 0.01),0.01);
}
BOOST_AUTO_TEST_CASE( box_is_inside_with_border )
{
// 2D
size_t bc_nn[] = {NON_PERIODIC,NON_PERIODIC};
size_t bc_pn[] = {PERIODIC,NON_PERIODIC};
size_t bc_np[] = {NON_PERIODIC,PERIODIC};
size_t bc_pp[] = {PERIODIC,PERIODIC};
Box<2,float> border({0.0,0.0},{1.0,1.0});
// non-tounching box
Box<2,float> b2({0.1,0.1},{0.2,0.2});
Box<2,float> b3({0.1,0.1},{1.0,1.0});
Point<2,float> p1({0.15,0.15});
Point<2,float> p2({0.25,0.25});
Point<2,float> p3({0.15,0.2});
Point<2,float> p4({0.1,0.25});
Point<2,float> p5({0.15,1.0});
Point<2,float> p6({0.1,1.0});
////// NON PERIODIC TEST
bool result = b2.isInsideNP_with_border(p1,border,bc_nn);
BOOST_REQUIRE_EQUAL(result,true);
result = b2.isInsideNP_with_border(p2,border,bc_nn);
BOOST_REQUIRE_EQUAL(result,false);
result = b2.isInsideNP_with_border(p3,border,bc_nn);
BOOST_REQUIRE_EQUAL(result,false);
result = b3.isInsideNP_with_border(p1,border,bc_nn);
BOOST_REQUIRE_EQUAL(result,true);
result = b3.isInsideNP_with_border(p4,border,bc_nn);
BOOST_REQUIRE_EQUAL(result,true);
result = b3.isInsideNP_with_border(p5,border,bc_nn);
BOOST_REQUIRE_EQUAL(result,true);
result = b3.isInsideNP_with_border(p6,border,bc_nn);
BOOST_REQUIRE_EQUAL(result,true);
//////////////
result = b2.isInsideNP_with_border(p1,border,bc_pn);
BOOST_REQUIRE_EQUAL(result,true);
result = b2.isInsideNP_with_border(p2,border,bc_pn);
BOOST_REQUIRE_EQUAL(result,false);
result = b2.isInsideNP_with_border(p3,border,bc_pn);
BOOST_REQUIRE_EQUAL(result,false);
result = b3.isInsideNP_with_border(p1,border,bc_pn);
BOOST_REQUIRE_EQUAL(result,true);
result = b3.isInsideNP_with_border(p4,border,bc_pn);
BOOST_REQUIRE_EQUAL(result,true);
result = b3.isInsideNP_with_border(p5,border,bc_pn);
BOOST_REQUIRE_EQUAL(result,true);
result = b3.isInsideNP_with_border(p6,border,bc_pn);
BOOST_REQUIRE_EQUAL(result,true);
////////////
result = b2.isInsideNP_with_border(p1,border,bc_np);
BOOST_REQUIRE_EQUAL(result,true);
result = b2.isInsideNP_with_border(p2,border,bc_np);
BOOST_REQUIRE_EQUAL(result,false);
result = b2.isInsideNP_with_border(p3,border,bc_np);
BOOST_REQUIRE_EQUAL(result,false);
result = b3.isInsideNP_with_border(p1,border,bc_np);
BOOST_REQUIRE_EQUAL(result,true);
result = b3.isInsideNP_with_border(p4,border,bc_np);
BOOST_REQUIRE_EQUAL(result,true);
result = b3.isInsideNP_with_border(p5,border,bc_np);
BOOST_REQUIRE_EQUAL(result,false);
result = b3.isInsideNP_with_border(p6,border,bc_np);
BOOST_REQUIRE_EQUAL(result,false);
////////////
result = b2.isInsideNP_with_border(p1,border,bc_pp);
BOOST_REQUIRE_EQUAL(result,true);
result = b2.isInsideNP_with_border(p2,border,bc_pp);
BOOST_REQUIRE_EQUAL(result,false);
result = b2.isInsideNP_with_border(p3,border,bc_pp);
BOOST_REQUIRE_EQUAL(result,false);
result = b3.isInsideNP_with_border(p1,border,bc_pp);
BOOST_REQUIRE_EQUAL(result,true);
result = b3.isInsideNP_with_border(p4,border,bc_pp);
BOOST_REQUIRE_EQUAL(result,true);
result = b3.isInsideNP_with_border(p5,border,bc_pp);
BOOST_REQUIRE_EQUAL(result,false);
result = b3.isInsideNP_with_border(p6,border,bc_pp);
BOOST_REQUIRE_EQUAL(result,false);
}
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