Commit 12066df2 authored by Yaroslav's avatar Yaroslav

Added 'domain' to grid_cpu vectors_util.hpp; reworked algorithm of weight counter

parent d490579d
......@@ -23,7 +23,7 @@ template <unsigned int dim, typename T, typename St>
class weight_counter<dim,T,St,IS_GRID>
{
public:
size_t weight(T & t, Box<dim,St> & b)
size_t weight(T & t, const Box<dim,St> & domain, Box<dim,St> & b)
{
// Grid implementation
// get a size vector
......@@ -31,12 +31,12 @@ public:
size_t res = 1;
//for each dimension
for (int i = 0; i < dim; i++) {
size_t count = 0;
double count = 0;
//rounding coordinates of Low and High up and down
int a1 = (int)(b.getLow(i));
int a2 = (int)(b.getHigh(i) + 0.9999999);
//int a1 = (int)(b.getLow(i));
//int a2 = (int)(b.getHigh(i) + 0.9999999);
//counting points those get into a box, excluding borders
count = a2 - a1 - 1;
count = ceil(b.getHigh(i)) - floor(b.getLow(i)) - 1;
//adding negative borders, if the number was integer
if (b.getLow(i) == ceil(b.getLow(i)))
count++;
......
......@@ -22,16 +22,17 @@ BOOST_AUTO_TEST_CASE( weight_counter_grid )
std::cout << "Grid weight counter test start" << "\n";
grid_cpu<3,Point<3,float>> t({5,5,5});
const SpaceBox<3,float> domain({0.0,0.0,0.0},{5.0,5.0,5.0});
//general case of box, create and check weight
{
SpaceBox<3,float> b({0.5,0.5,0.5},{3.0,3.0,3.0});
SpaceBox<3,float> b({0.5,0.5,0.5},{3.5,3.5,3.5});
weight_counter<3,grid_cpu<3,Point<3,float>>,float,IS_GRID> w;
size_t result = w.weight(t,b);
size_t result = w.weight(t,domain,b);
BOOST_REQUIRE_EQUAL(result,8);
BOOST_REQUIRE_EQUAL(result,27);
}
//case of box with integer Low and High points, create and check weight (positive exclude)
......@@ -40,7 +41,7 @@ BOOST_AUTO_TEST_CASE( weight_counter_grid )
weight_counter<3,grid_cpu<3,Point<3,float>>,float,IS_GRID> w;
size_t result = w.weight(t,b);
size_t result = w.weight(t,domain,b);
BOOST_REQUIRE_EQUAL(result,27);
}
......
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