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

Fixing staggered grid checking

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