Commit 44232a31 authored by Pietro Incardona's avatar Pietro Incardona
Browse files

Fixing staggered grid checking

parent 237fef5f
......@@ -61,6 +61,7 @@
template<unsigned int dim, typename St, typename T, typename Decomposition,typename Memory=HeapMemory , typename device_grid=grid_cpu<dim,T>>
class staggered_grid_dist : public grid_dist_id<dim,St,T,Decomposition,Memory,device_grid>
{
openfpm::vector<comb<dim>> c_prp[T::max_prop];
public:
......@@ -70,10 +71,9 @@ public:
:grid_dist_id<dim,St,T,Decomposition,Memory,device_grid>(g_sz,domain,ghost)
{}
openfpm::vector<comb<dim>> c_prp[T::max_prop];
/*! \brief Set the staggered positions
/*! \brief Get the staggered positions
*
* \return a vector of combination
*
*/
template<unsigned int p> void setStagPosition(openfpm::vector<comb<dim>> & cmb)
......@@ -97,6 +97,16 @@ public:
boost::mpl::for_each_ref< boost::mpl::range_c<int,0,T::max_prop> >(ssp);
}
/*! \brief Get the staggered positions
*
* \return The vector of the staggered positions
*
*/
const openfpm::vector<comb<dim>> (& getStagPositions()) [T::max_prop]
{
return c_prp;
}
/*! \brief Write a vtk file with the information of the staggered grid
*
* \param str vtk output file
......
......@@ -23,42 +23,36 @@ BOOST_AUTO_TEST_CASE( staggered_grid_dist_unit_test)
size_t k = 1024;
/* for (size_t k = 1024 ; k >= 2 ; k--)
{*/
BOOST_TEST_CHECKPOINT( "Testing grid k=" << k );
// grid size
size_t sz[2];
sz[0] = k;
sz[1] = k;
size_t sz[2] = {k,k};
// Ghost
Ghost<2,float> g(0.01);
Ghost<2,float> g(0.0);
staggered_grid_dist<2,float,Point2D_test<float>,CartDecomposition<2,float>> sg(sz,domain,g);
sg.setDefaultStagPosition();
auto it = sg.getDomainIterator();
while (it.isNext())
{
auto key = it.get();
sg.template get<p::s>(key) = 1;
sg.template get<p::v>(key)[0] = 0;
sg.template get<p::v>(key)[1] = 1;
sg.template get<p::t>(key)[0][0] = 0;
sg.template get<p::t>(key)[0][1] = 1;
sg.template get<p::t>(key)[1][0] = 2;
sg.template get<p::t>(key)[1][1] = 3;
++it;
}
/* }*/
// We check that the staggered position is correct
const openfpm::vector<comb<2>> (& cmbs)[6] = sg.getStagPositions();
BOOST_REQUIRE_EQUAL(cmbs[0].size(),1ul);
BOOST_REQUIRE_EQUAL(cmbs[1].size(),1ul);
BOOST_REQUIRE_EQUAL(cmbs[2].size(),1ul);
BOOST_REQUIRE_EQUAL(cmbs[3].size(),1ul);
BOOST_REQUIRE_EQUAL(cmbs[4].size(),2ul);
BOOST_REQUIRE_EQUAL(cmbs[5].size(),4ul);
BOOST_REQUIRE(cmbs[0].get(0) == comb<2>({0,0}));
BOOST_REQUIRE(cmbs[1].get(0) == comb<2>({0,0}));
BOOST_REQUIRE(cmbs[2].get(0) == comb<2>({0,0}));
BOOST_REQUIRE(cmbs[3].get(0) == comb<2>({0,0}));
BOOST_REQUIRE(cmbs[4].get(0) == comb<2>({0,-1}));
BOOST_REQUIRE(cmbs[4].get(1) == comb<2>({-1,0}));
BOOST_REQUIRE(cmbs[5].get(0) == comb<2>({0,0}));
BOOST_REQUIRE(cmbs[5].get(1) == comb<2>({-1,-1}));
BOOST_REQUIRE(cmbs[5].get(2) == comb<2>({-1,-1}));
BOOST_REQUIRE(cmbs[5].get(3) == comb<2>({0,0}));
}
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