Commit d1618c56 authored by Pietro Incardona's avatar Pietro Incardona

Small fixes

parent a3893b83
......@@ -17,7 +17,18 @@ m4_ifdef([AX_BOOST_IOSTREAMS],,[m4_include([m4/ax_boost_iostreams.m4])])
m4_ifdef([AX_BOOST_PROGRAM_OPTIONS],,[m4_include([m4/ax_boost_program_options.m4])])
m4_ifdef([AX_BOOST_UNIT_TEST_FRAMEWORK],,[m4_include([m4/ax_boost_unit_test_framework.m4])])
CXXFLAGS+=" --std=c++11 -march=native -mtune=native -Wno-unused-local-typedefs -Wextra -Wno-unused-parameter "
case $host_os in
*cygwin*)
# Do something specific for cygwin
CXXFLAGS+=" --std=gnu++11 "
;;
*)
#Default Case
CXXFLAGS+=" --std=c++11 "
;;
esac
CXXFLAGS+=" -march=native -mtune=native -Wno-unused-local-typedefs -Wextra -Wno-unused-parameter "
NVCCFLAGS=" "
INCLUDES_PATH=" "
......@@ -290,26 +301,6 @@ AC_SUBST(BOOST_CPPFLAGS)
##########################
# Check for which host we are on and setup a few things
# specifically based on the host
case $host_os in
darwin* )
# Do something specific for mac
;;
linux*)
# Do something specific for linux
OPT_LIBS=" -lrt "
;;
*BSD*)
# Do something specific for BSD
;;
*)
#Default Case
AC_MSG_ERROR([Your platform is not currently supported])
;;
esac
AC_SUBST(NVCCFLAGS)
AC_SUBST(INCLUDES_PATH)
AC_SUBST(OPT_LIBS)
......
......@@ -223,6 +223,20 @@ public:
return true;
}
/* \brief Check if two key are the same
*
* \param key_t key to check
*
* \return true if the two key are equal
*
*/
template<unsigned int dim_t> bool operator!=(const grid_key_dx<dim_t> & key_t)
{
return !this->operator==(key_t);
}
//! set the grid key from a list of numbers
template<typename a, typename ...T>void set(a v, T...t)
{
......
......@@ -168,6 +168,144 @@ BOOST_AUTO_TEST_CASE( grid_iterator_sub_p )
BOOST_REQUIRE_EQUAL(cnt,0ul);
}
BOOST_AUTO_TEST_CASE( grid_iterator_sp_test )
{
size_t sz[3] = {16,16,16};
grid_cpu<3, Point_test<float> > c3(sz);
c3.setMemory();
grid_key_dx<3> start(2,2,2);
grid_key_dx<3> stop(10,10,10);
auto info = c3.getGrid();
grid_key_dx_iterator_sp<3> it(info,info.LinId(start),info.LinId(stop));
size_t count = 0;
while (it.isNext())
{
count++;
++it;
}
BOOST_REQUIRE_EQUAL(count,2185ul);
}
BOOST_AUTO_TEST_CASE( grid_iterator_test_use)
{
{
//! [Grid iterator test usage]
size_t count = 0;
// Subdivisions
size_t div[3] = {16,16,16};
// grid info
grid_sm<3,void> g_info(div);
// Create a grid iterator
grid_key_dx_iterator<3> g_it(g_info);
// Iterate on all the elements
while (g_it.isNext())
{
grid_key_dx<3> key = g_it.get();
// set the grid key to zero without any reason ( to avoid warning compilations )
key.zero();
count++;
++g_it;
}
BOOST_REQUIRE_EQUAL(count, (size_t)16*16*16);
//! [Grid iterator test usage]
}
{
size_t count = 0;
// Iterate only on the internal elements
//! [Sub-grid iterator test usage]
// Subdivisions
size_t div[3] = {16,16,16};
// grid info
grid_sm<3,void> g_info(div);
grid_key_dx<3> start(1,1,1);
grid_key_dx<3> stop(14,14,14);
// Create a grid iterator (start and stop included)
grid_key_dx_iterator_sub<3> g_it(g_info,start,stop);
// Iterate on all the elements
while (g_it.isNext())
{
grid_key_dx<3> key = g_it.get();
// set the grid key to zero without any reason ( to avoid warning compilations )
key.zero();
count++;
++g_it;
}
BOOST_REQUIRE_EQUAL(count, (size_t)14*14*14);
//! [Sub-grid iterator test usage]
// reset the iterator and check that it start from gk_start
g_it.reset();
bool val = g_it.get() == start;
BOOST_REQUIRE_EQUAL(val,true);
}
}
BOOST_AUTO_TEST_CASE( grid_sub_iterator_test )
{
//! [Sub-grid iterator test usage]
// Subdivisions
size_t count = 0;
typedef Point_test<float> p;
size_t div[3] = {16,16,16};
// grid info
grid_cpu<3,Point_test<float>> g(div);
g.setMemory();
grid_key_dx<3> start(1,1,1);
grid_key_dx<3> stop(14,14,14);
// Create a grid iterator (start and stop included)
auto g_it = g.getIterator(start,stop);
// Iterate on all the elements
while (g_it.isNext())
{
grid_key_dx<3> key = g_it.get();
// set the x value
g.template get<p::x>(key) = 1.0;
count++;
++g_it;
}
BOOST_REQUIRE_EQUAL(count, (size_t)14*14*14);
//! [Sub-grid iterator test usage]
}
BOOST_AUTO_TEST_SUITE_END()
......
......@@ -515,118 +515,6 @@ template<unsigned int dim, typename g> void test_layout_gridNd(g & c3, size_t sz
BOOST_AUTO_TEST_SUITE( grid_test )
BOOST_AUTO_TEST_CASE( grid_iterator_test_use)
{
{
//! [Grid iterator test usage]
size_t count = 0;
// Subdivisions
size_t div[3] = {16,16,16};
// grid info
grid_sm<3,void> g_info(div);
// Create a grid iterator
grid_key_dx_iterator<3> g_it(g_info);
// Iterate on all the elements
while (g_it.isNext())
{
grid_key_dx<3> key = g_it.get();
// set the grid key to zero without any reason ( to avoid warning compilations )
key.zero();
count++;
++g_it;
}
BOOST_REQUIRE_EQUAL(count, (size_t)16*16*16);
//! [Grid iterator test usage]
}
{
size_t count = 0;
// Iterate only on the internal elements
//! [Sub-grid iterator test usage]
// Subdivisions
size_t div[3] = {16,16,16};
// grid info
grid_sm<3,void> g_info(div);
grid_key_dx<3> start(1,1,1);
grid_key_dx<3> stop(14,14,14);
// Create a grid iterator (start and stop included)
grid_key_dx_iterator_sub<3> g_it(g_info,start,stop);
// Iterate on all the elements
while (g_it.isNext())
{
grid_key_dx<3> key = g_it.get();
// set the grid key to zero without any reason ( to avoid warning compilations )
key.zero();
count++;
++g_it;
}
BOOST_REQUIRE_EQUAL(count, (size_t)14*14*14);
//! [Sub-grid iterator test usage]
// reset the iterator and check that it start from gk_start
g_it.reset();
bool val = g_it.get() == start;
BOOST_REQUIRE_EQUAL(val,true);
}
}
BOOST_AUTO_TEST_CASE( grid_sub_iterator_test )
{
//! [Sub-grid iterator test usage]
// Subdivisions
size_t count = 0;
typedef Point_test<float> p;
size_t div[3] = {16,16,16};
// grid info
grid_cpu<3,Point_test<float>> g(div);
g.setMemory();
grid_key_dx<3> start(1,1,1);
grid_key_dx<3> stop(14,14,14);
// Create a grid iterator (start and stop included)
auto g_it = g.getIterator(start,stop);
// Iterate on all the elements
while (g_it.isNext())
{
grid_key_dx<3> key = g_it.get();
// set the x value
g.template get<p::x>(key) = 1.0;
count++;
++g_it;
}
BOOST_REQUIRE_EQUAL(count, (size_t)14*14*14);
//! [Sub-grid iterator test usage]
}
////////// Test function ///////////
grid_cpu<3,scalar<float>> & test_error()
......@@ -864,32 +752,6 @@ BOOST_AUTO_TEST_CASE( grid_use)
std::cout << "Grid unit test end" << "\n";
}
BOOST_AUTO_TEST_CASE( grid_iterator_sp_test )
{
size_t sz[3] = {16,16,16};
grid_cpu<3, Point_test<float> > c3(sz);
c3.setMemory();
grid_key_dx<3> start(2,2,2);
grid_key_dx<3> stop(10,10,10);
auto info = c3.getGrid();
grid_key_dx_iterator_sp<3> it(info,info.LinId(start),info.LinId(stop));
size_t count = 0;
while (it.isNext())
{
count++;
++it;
}
BOOST_REQUIRE_EQUAL(count,2185ul);
}
/* \brief This is an ordinary test simple 3D with plain C array
*
* This is an ordinary test simple 3D with plain C array
......
......@@ -24,7 +24,7 @@ NN/CellList/CellDecomposer.hpp NN/CellList/CellKey.hpp NN/CellList/CellList.hpp
Space/Ghost.hpp Space/Matrix.hpp Space/SpaceBox.hpp Space/SpaceBox_unit_tests.hpp \
Space/Shape/AdaptiveCylinderCone.hpp Space/Shape/Box.hpp Space/Shape/Box_unit_tests.hpp Space/Shape/HyperCube.hpp Space/Shape/HyperCube_unit_test.hpp Space/Shape/Point.hpp Space/Shape/Point_unit_test.hpp Space/Shape/Sphere.hpp \
util/check_no_pointers.hpp util/common.hpp util/convert.hpp util/create_vmpl_sequence.hpp util/ct_array.hpp util/for_each_ref.hpp util/mathutil.hpp util/object_creator.hpp util/object_s_di.hpp util/object_si_d.hpp util/object_util.hpp util/util_debug.hpp util/util_test.hpp util/variadic_to_vmpl.hpp util/variadic_to_vmpl_unit_test.hpp util/Pack_stat.hpp \
Vector/map_vector.hpp Vector/map_vector_std.hpp Vector/util.hpp Vector/vect_isel.hpp Vector/vector_test_util.hpp Vector/vector_unit_tests.hpp Vector/se_vector.hpp Vector/map_vector_grow_p.hpp Vector/vector_std_pack_unpack.ipp Vector/vector_pack_unpack.ipp \
Vector/map_vector.hpp Vector/map_vector_std_ptr.hpp Vector/map_vector_std.hpp Vector/util.hpp Vector/vect_isel.hpp Vector/vector_test_util.hpp Vector/vector_unit_tests.hpp Vector/se_vector.hpp Vector/map_vector_grow_p.hpp Vector/vector_std_pack_unpack.ipp Vector/vector_pack_unpack.ipp \
timer.hpp \
util/copy_compare/compare_fusion_vector.hpp util/copy_compare/compare_general.hpp util/copy_compare/copy_compare_aggregates.hpp util/copy_compare/copy_fusion_vector.hpp util/copy_compare/copy_general.hpp util/copy_compare/meta_compare.hpp util/copy_compare/meta_copy.hpp \
Packer_Unpacker/Pack_selector.hpp Packer_Unpacker/Packer_nested_tests.hpp Packer_Unpacker/Packer_unit_tests.hpp Packer_Unpacker/Packer.hpp Packer_Unpacker/Unpacker.hpp
......
......@@ -17,6 +17,7 @@ template<unsigned int dim, typename T>
class shift
{
Point<dim,T> sh;
Matrix<dim,T> mat;
public:
......@@ -29,6 +30,7 @@ public:
shift(const Matrix<dim,T> & t, const Point<dim,T> & s)
:sh(s)
{
mat.identity();
}
/*! \brief Shift the point transformation
......@@ -81,12 +83,33 @@ public:
for (size_t i = 0 ; i < dim ; i++)
sh.get(i) = orig.get(i);
}
/*! \brief Get the origin
*
*
*/
inline const Point<dim,T> & getOrig() const
{
return sh;
}
/*! \brief Get the transformation Matrix
*
*
*/
inline const Matrix<dim,T> & getMat() const
{
return mat;
}
};
// No transformation
template<unsigned int dim, typename T>
class no_transform
{
Point<dim,T> orig;
Matrix<dim,T> mat;
public:
/*! \brief Constructor
......@@ -97,6 +120,8 @@ public:
*/
no_transform(const Matrix<dim,T> & t, const Point<dim,T> & s)
{
orig.zero();
mat.identity();
}
/*! \brief Shift the point transformation
......@@ -172,6 +197,24 @@ public:
{
return false;
}
/*! \brief Get the origin
*
*
*/
inline const Point<dim,T> & getOrig() const
{
return orig;
}
/*! \brief Get the transformation Matrix
*
*
*/
inline const Matrix<dim,T> & getMat() const
{
return mat;
}
};
......@@ -208,11 +251,11 @@ public:
* \endverbatim
*
* ### Cell decomposer without shift
* \snippet CellList_test.hpp Cell decomposer use without shift
* \snippet CellDecomposer_unit_tests.hpp Cell decomposer use without shift
* ### Cell decomposer with padding
* \snippet CellList_test.hpp Test Cell decomposer with padding
* \snippet CellDecomposer_unit_tests.hpp Test Cell decomposer with padding
* ### Cell decomposer with shift
* \snippet CellList_test.hpp Test Cell decomposer with shift
* \snippet CellDecompose_unit_tests.hpp Test Cell decomposer with shift
*
*/
template<unsigned int dim,typename T, typename transform = no_transform<dim,T>>
......@@ -399,7 +442,7 @@ public:
* \return the cell-ids ad a grid_key_dx<dim>
*
*/
grid_key_dx<dim> getCellGrid(const Point<dim,T> pos) const
inline grid_key_dx<dim> getCellGrid(const Point<dim,T> & pos) const
{
#ifdef SE_CLASS1
if (tot_n_cell == 0)
......@@ -430,7 +473,7 @@ public:
* \return the cell-id
*
*/
size_t getCell(const T (& pos)[dim]) const
inline size_t getCell(const T (& pos)[dim]) const
{
#ifdef SE_CLASS1
if (tot_n_cell == 0)
......@@ -463,7 +506,7 @@ public:
* \return the cell-id
*
*/
size_t getCell(const Point<dim,T> & pos) const
inline size_t getCell(const Point<dim,T> & pos) const
{
#ifdef SE_CLASS1
if (tot_n_cell == 0)
......@@ -496,7 +539,7 @@ public:
* \return the cell-id
*
*/
template<typename Mem> size_t getCell(const encapc<1,Point<dim,T>,Mem> & pos) const
template<typename Mem> inline size_t getCell(const encapc<1,Point<dim,T>,Mem> & pos) const
{
#ifdef SE_CLASS1
......@@ -553,7 +596,7 @@ public:
* \return the box containing the grid points
*
*/
Box<dim,size_t> getGridPoints(const Box<dim,T> & s_box) const
inline Box<dim,size_t> getGridPoints(const Box<dim,T> & s_box) const
{
// Box with inside grid
Box<dim,size_t> bx;
......@@ -579,10 +622,9 @@ public:
* \param pad padding cell
*
*/
void setDimensions(const Box<dim,T> & box, const size_t (&div)[dim], const size_t pad)
inline void setDimensions(const Box<dim,T> & box, const size_t (&div)[dim], const size_t pad)
{
this->box = box;
this->gr_cell.setDimensions(div);
Initialize(pad,div);
}
......@@ -595,14 +637,56 @@ public:
* \param pad padding cell
*
*/
void setDimensions(const Box<dim,T> & box, const size_t (&div)[dim], const Matrix<dim,T> & mat, const Point<dim,T> & orig, const size_t pad)
inline void setDimensions(const Box<dim,T> & box, const size_t (&div)[dim], const Matrix<dim,T> & mat, const Point<dim,T> & orig, const size_t pad)
{
t.setTransform(mat,orig);
this->box = box;
this->gr_cell.setDimensions(div);
Initialize(pad,div);
}
/*! \brief Set a consistent cell decomposer
*
* When we want to create a new extended CellDecomposer consistent with the old one
* this function can be used to guarantee such costrain.
* With consistent we mean that for each cell of the old CellDecomposer exist
* a Cell in the new CellDecomposer that perfectly overlap
*
* \param cd OLD CellDecomposer
* \param cell_extension extension of the CellDecomposer in term of Cell extesion
*
*/
inline void setDimensions(const CellDecomposer_sm<dim,T,transform> & cd, const Box<dim,size_t> & cell_extension)
{
// Get the space transformation
t.setTransform(cd.getMat(),cd.getOrig());
// The domain is equivalent to the old one
this->box = cd.box;
// The padding must be calculated
size_t pad = 0;
for (size_t i = 0 ; i < dim ; i++)
{
if (pad < cell_extension.getLow(i))
pad = cell_extension.getLow(i);
else if (pad > cell_extension.getHigh(i))
pad = cell_extension.getHigh(i);
}
// We have to give the old division
size_t sz_div[dim];
for (size_t i = 0 ; i < dim ; i++)
sz_div[i] = cd.gr_cell.size(i) - 2*cd.off[i];
Initialize(pad,sz_div);
}
/*! \brief Constructor
*
* \param box Space where is defined the cell list (it is assumed p1 = {0, .... 0})
......@@ -710,6 +794,20 @@ public:
}
/*! \brief Constructor for a consistent CellDecomposer construction
*
* \param cd Old CellDecomposer
* \param ext Extension box
*
*
*/
CellDecomposer_sm(const CellDecomposer_sm<dim,T,transform> & cd, Box<dim,size_t> & ext)
:t(Matrix<dim,T>::identity(),cd.getOrig())
{
setDimensions(cd,ext);
}
//! default constructor
CellDecomposer_sm()
:t(Matrix<dim,T>::identity(),Point<dim,T>::zero_p()),tot_n_cell(0)
......@@ -724,30 +822,35 @@ public:
* \return the box
*
*/
const Box<dim,T> & getCellBox() const
inline const Box<dim,T> & getCellBox() const
{
return box_unit;
}
/*! \brief It fix the boundaries for rounding errors
/*! \brief Get the transformation Matrix of the cell decomposer
*
* Let's consider in floating point units 1.0 / 1011.0 * 1011.0 = 1011.00006
* Let's also consider the case 1.0 / 998 * 998 = 997.99996
* these two are problematic cases because the first
* \return the transformation Matrix
*
*/
/* Box<dim,T> BoundaryFixation()
inline const Matrix<dim,T> & getMat() const
{
return t.getMat();
}
}*/
/*! \brief Get the origin of the cell decomposer
*
* \return the origin
*
*/
inline const Point<dim,T> & getOrig() const
{
return t.getOrig();
}
/*! \brief Convert a Box in the domain space into grid units (Positive countour inclused Negative countour excluded)
/*! \brief Convert a Box in the domain space into grid units (Negative contour included, positive contour excluded)
*
* Given the following
*
* \warning Be carefull the use of this function require boundary fixation
* \see Boundary Fixation