diff --git a/src/Grid/grid_key.hpp b/src/Grid/grid_key.hpp index 875f24fb7dd37841b91adbf48265e4b93e71f919..22efe10be2d57b71ecc88c8252ebb231e3e21bba 100644 --- a/src/Grid/grid_key.hpp +++ b/src/Grid/grid_key.hpp @@ -80,7 +80,7 @@ public: inline grid_key_dx(const long int (&k)[dim]) { for (size_t i = 0 ; i < dim ; i++) - this->k[i] = k[i]; + {this->k[i] = k[i];} } /*! \brief Construct a grid key from a list of numbers diff --git a/src/Grid/grid_sm.hpp b/src/Grid/grid_sm.hpp index 8f4494031ae2c3c5736c3f9c089db54c133194ca..8dd4cae011151d76fe6358a91cd1192ab6aeadee 100755 --- a/src/Grid/grid_sm.hpp +++ b/src/Grid/grid_sm.hpp @@ -241,6 +241,10 @@ public: inline grid_sm() :size_tot(0) { + // Initialize sz + for (size_t i = 0 ; i < N ; i++) + {sz[i] = 0;} + Initialize(); } diff --git a/src/Makefile.am b/src/Makefile.am index 9a70c1511210f97a9573d4594757e032b31c65ee..acd38b18c6f8ed189486f276b13346e8e084f699 100755 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -20,7 +20,7 @@ Grid/iterators/grid_key_dx_iterator_sp.hpp Grid/grid_key_dx_iterator_hilbert.hpp Point_test.hpp \ Point_orig.hpp \ memory_ly/memory_array.hpp memory_ly/memory_c.hpp memory_ly/memory_conf.hpp memory_ly/t_to_memory_c.hpp \ -NN/Mem_type/MemBalanced.hpp NN/Mem_type/MemFast.hpp NN/Mem_type/MemMemoryWise.hpp NN/CellList/CellNNIteratorRuntime.hpp NN/CellList/ParticleItCRS_Cells.hpp NN/CellList/ParticleIt_Cells.hpp NN/CellList/CellDecomposer.hpp NN/VerletList/VerletList.hpp NN/VerletList/VerletListFast.hpp NN/VerletList/VerletNNIterator.hpp NN/CellList/CellListNNIteratorRadius.hpp NN/CellList/CellListIterator.hpp NN/CellList/CellListM.hpp NN/CellList/CellNNIteratorM.hpp NN/CellList/CellList.hpp NN/CellList/CellList_test.hpp NN/CellList/CellListFast_gen.hpp NN/CellList/CellNNIterator.hpp NN/CellList/ProcKeys.hpp \ +NN/Mem_type/MemBalanced.hpp NN/Mem_type/MemFast.hpp NN/Mem_type/MemMemoryWise.hpp NN/CellList/CellNNIteratorRuntime.hpp NN/CellList/NNc_array.hpp NN/CellList/ParticleItCRS_Cells.hpp NN/CellList/ParticleIt_Cells.hpp NN/CellList/CellDecomposer.hpp NN/VerletList/VerletList.hpp NN/VerletList/VerletListFast.hpp NN/VerletList/VerletNNIterator.hpp NN/CellList/CellListNNIteratorRadius.hpp NN/CellList/CellListIterator.hpp NN/CellList/CellListM.hpp NN/CellList/CellNNIteratorM.hpp NN/CellList/CellList.hpp NN/CellList/CellList_test.hpp NN/CellList/CellListFast_gen.hpp NN/CellList/CellNNIterator.hpp NN/CellList/ProcKeys.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/Point_operators_functions.hpp Space/Shape/Point_operators.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 \ diff --git a/src/NN/CellList/CellList.hpp b/src/NN/CellList/CellList.hpp index a3fda2e8197efd0d5e2cc77daa707a51bb04578c..9d40e23cc529cb9d0fa7e252630e1e60ac118da3 100644 --- a/src/NN/CellList/CellList.hpp +++ b/src/NN/CellList/CellList.hpp @@ -25,6 +25,7 @@ #include "NN/Mem_type/MemFast.hpp" #include "NN/Mem_type/MemBalanced.hpp" #include "NN/Mem_type/MemMemoryWise.hpp" +#include "NN/CellList/NNc_array.hpp" //! Wrapper of the unordered map template<typename key,typename val> @@ -189,7 +190,7 @@ template<unsigned int dim> void NNcalc_full(openfpm::vector<grid_key_dx<dim>> & // Calculate the divisions for (size_t i = 0 ; i < dim ; i++) - div[i] = 4; + {div[i] = 4;} grid_sm<dim,void> gs(div); grid_key_dx_iterator_sub<dim> gr_sub3(gs,NNzero::data,NNtwo::data); @@ -274,14 +275,17 @@ protected: // * x * // * * * - long int NNc_full[openfpm::math::pow(3,dim)]; + + NNc_array<dim,openfpm::math::pow(3,dim)> NNc_full; +// long int NNc_full[openfpm::math::pow(3,dim)]; //! The array contain the neighborhood of the cell-id in case of symmetric interaction // // * * * // x * // - long int NNc_sym[openfpm::math::pow(3,dim)/2+1]; +// long int NNc_sym[openfpm::math::pow(3,dim)/2+1]; + NNc_array<dim,openfpm::math::pow(3,dim)/2+1> NNc_sym; private: @@ -363,53 +367,11 @@ private: { Mem_type::init_to_zero(slot,tot_n_cell); - // Calculate the NNc_full array, it is a structure to get the neighborhood array - - // compile-time array {0,0,0,....} {2,2,2,...} {1,1,1,...} - - typedef typename generate_array<size_t,dim, Fill_zero>::result NNzero; - typedef typename generate_array<size_t,dim, Fill_two>::result NNtwo; - typedef typename generate_array<size_t,dim, Fill_one>::result NNone; - - // Generate the sub-grid iterator - - grid_sm<dim,void> gs(div); - grid_key_dx_iterator_sub<dim> gr_sub3(gs,NNzero::data,NNtwo::data); - - // Calculate the NNc array - - size_t middle = gs.LinId(NNone::data); - size_t i = 0; - while (gr_sub3.isNext()) - { - NNc_full[i] = (long int)gs.LinId(gr_sub3.get()) - middle; - - ++gr_sub3; - i++; - } - - // Calculate the NNc_sym array - - i = 0; - gr_sub3.reset(); - while (gr_sub3.isNext()) - { - auto key = gr_sub3.get(); - - size_t lin = gs.LinId(key); + NNc_full.set_size(div); + NNc_full.init_full(); - // Only the first half is considered - if (lin < middle) - { - ++gr_sub3; - continue; - } - - NNc_sym[i] = lin - middle; - - ++gr_sub3; - i++; - } + NNc_sym.set_size(div); + NNc_sym.init_sym(); } void setCellDecomposer(CellDecomposer_sm<dim,T,transform> & cd, const CellDecomposer_sm<dim,T,transform> & cd_sm, const Box<dim,T> & dom_box, size_t pad) const @@ -652,8 +614,8 @@ public: */ CellList<dim,T,Mem_type,transform,base> & operator=(const CellList<dim,T,Mem_type,transform,base> & cell) { - std::copy(&cell.NNc_full[0],&cell.NNc_full[openfpm::math::pow(3,dim)],&NNc_full[0]); - std::copy(&cell.NNc_sym[0],&cell.NNc_sym[openfpm::math::pow(3,dim)/2+1],&NNc_sym[0]); + NNc_full = cell.NNc_full; + NNc_sym = cell.NNc_sym; Mem_type::operator=(static_cast<const Mem_type &>(cell)); @@ -854,18 +816,8 @@ public: */ inline void swap(CellList<dim,T,Mem_type,transform,base> & cl) { - long int NNc_full_tmp[openfpm::math::pow(3,dim)]; - long int NNc_sym_tmp[openfpm::math::pow(3,dim)/2+1]; - - std::copy(&cl.NNc_full[0],&cl.NNc_full[openfpm::math::pow(3,dim)],&NNc_full_tmp[0]); - std::copy(&cl.NNc_sym[0],&cl.NNc_sym[openfpm::math::pow(3,dim)/2+1],&NNc_sym_tmp[0]); - - - std::copy(&NNc_full[0],&NNc_full[openfpm::math::pow(3,dim)],&cl.NNc_full[0]); - std::copy(&NNc_sym[0],&NNc_sym[openfpm::math::pow(3,dim)/2+1],&cl.NNc_sym[0]); - - std::copy(&NNc_full_tmp[0],&NNc_full_tmp[openfpm::math::pow(3,dim)],&NNc_full[0]); - std::copy(&NNc_sym_tmp[0],&NNc_sym_tmp[openfpm::math::pow(3,dim)/2+1],&NNc_sym[0]); + NNc_full.swap(cl.NNc_full); + NNc_sym.swap(cl.NNc_sym); Mem_type::swap(static_cast<Mem_type &>(cl)); @@ -969,7 +921,7 @@ public: * \return the symmetric neighborhood * */ - const long int (& getNNc_sym() const)[openfpm::math::pow(3,dim)/2+1] + const NNc_array<dim,openfpm::math::pow(3,dim)/2+1> & getNNc_sym() const { return NNc_sym; } diff --git a/src/NN/CellList/CellListIterator_test.hpp b/src/NN/CellList/CellListIterator_test.hpp index 5e20cb8fe900c82a2c0fcb376b225d883f39f34f..f384c64af2e0f6d6ff8586d5a4af09d258785ec2 100644 --- a/src/NN/CellList/CellListIterator_test.hpp +++ b/src/NN/CellList/CellListIterator_test.hpp @@ -365,7 +365,7 @@ BOOST_AUTO_TEST_CASE( ParticleIt_Cells_NN_iterator ) anom.last().subsub = gs.LinId(key); for(size_t j = 0 ; j < openfpm::math::pow(3,dim)/2+1 ; j++) - anom.last().NN_subsub.add(NN.getNNc_sym()[j]); + {anom.last().NN_subsub.add(NN.getNNc_sym()[j]);} alternate = false; } diff --git a/src/NN/CellList/CellNNIterator.hpp b/src/NN/CellList/CellNNIterator.hpp index 0252eabce23a45c5109d0bf3bb7ba5a143108424..219a7c5bbfb89e9391720e208c19f568614d169b 100644 --- a/src/NN/CellList/CellNNIterator.hpp +++ b/src/NN/CellList/CellNNIterator.hpp @@ -9,6 +9,7 @@ #define CELLNNITERATOR_FULL_HPP_ #include "util/mathutil.hpp" +#include "NN/CellList/NNc_array.hpp" #define FULL openfpm::math::pow(3,dim) #define SYM openfpm::math::pow(3,dim)/2 + 1 @@ -55,7 +56,7 @@ protected: Cell & cl; //! NN cell id - const long int (& NNc)[NNc_size]; + const NNc_array<dim,NNc_size> & NNc; /*! \brief Select non-empty cell * @@ -90,7 +91,7 @@ public: * \param cl Cell structure * */ - inline CellNNIterator(size_t cell, const long int (&NNc)[NNc_size], Cell & cl) + inline CellNNIterator(size_t cell, const NNc_array<dim,NNc_size> &NNc, Cell & cl) :NNc_id(0),cell(cell),cell_id(NNc[NNc_id] + cell),cl(cl),NNc(NNc) { start_id = &cl.getStartId(cell_id); @@ -212,7 +213,7 @@ public: * \param cl Cell structure * */ - inline CellNNIteratorSym(size_t cell, size_t p, const long int (&NNc)[NNc_size], Cell & cl, const openfpm::vector<Point<dim,typename Cell::stype>> & v) + inline CellNNIteratorSym(size_t cell, size_t p, const NNc_array<dim,NNc_size> &NNc, Cell & cl, const openfpm::vector<Point<dim,typename Cell::stype>> & v) :CellNNIterator<dim,Cell,NNc_size,impl>(cell,NNc,cl),p(p),v(v) { selectValid(); diff --git a/src/NN/CellList/CellNNIteratorM.hpp b/src/NN/CellList/CellNNIteratorM.hpp index c3b7608ddfba84793abf18c67de2dee85b1286ff..fa9a57e9ffad0086eaa6cf5c338e28ccd2eddb35 100644 --- a/src/NN/CellList/CellNNIteratorM.hpp +++ b/src/NN/CellList/CellNNIteratorM.hpp @@ -88,7 +88,7 @@ public: CellNNIteratorSymM(size_t cell, size_t pp, size_t p, - const long int (&NNc)[NNc_size], + const NNc_array<dim,NNc_size> & NNc, Cell & cl, const openfpm::vector<Point<dim,typename Cell::stype>> & pos, const openfpm::vector<pos_v<dim,typename Cell::stype>> & ps) @@ -160,7 +160,7 @@ public: * \param cl Cell structure * */ - CellNNIteratorM(size_t cell, const long int (&NNc)[NNc_size], Cell & cl) + CellNNIteratorM(size_t cell, const NNc_array<dim,NNc_size> &NNc, Cell & cl) :CellNNIterator<dim,Cell,NNc_size,impl>(cell,NNc,cl) {} diff --git a/src/NN/CellList/NNc_array.hpp b/src/NN/CellList/NNc_array.hpp new file mode 100644 index 0000000000000000000000000000000000000000..a348aad8dc2c195c44f2b08d37e8fd8b756c5814 --- /dev/null +++ b/src/NN/CellList/NNc_array.hpp @@ -0,0 +1,283 @@ +/* + * NNc_array.hpp + * + * Created on: Feb 6, 2018 + * Author: i-bird + */ + +#ifndef OPENFPM_DATA_SRC_NN_CELLLIST_NNC_ARRAY_HPP_ +#define OPENFPM_DATA_SRC_NN_CELLLIST_NNC_ARRAY_HPP_ + +#include "Grid/grid_sm.hpp" +#include <boost/mpl/bool.hpp> + +/*! \brief Set a dimension threshold + * + * \param dim dimension + * + */ +template<unsigned int dim> +struct as_array_nnc +{ + //! true only if dimension is smaller than 10 + typedef boost::mpl::bool_< dim < 10 > type; +}; + +/* \brief NNc_array + * + * \param size + * + */ +template<unsigned int dim, unsigned int size, bool thr = as_array_nnc<dim>::type::value> +class NNc_array +{ + //! NNc_array + long int NNc_arr[size]; + + //! size of the cell array on each dimension + grid_sm<dim,void> gs; + +public: + + /*! \brief Set the size in each + * + * \param sz size og the cell grid in each dimensions + * + */ + void set_size(const size_t (& sz)[dim]) + { + gs.setDimensions(sz); + } + + /*! \brief return the element i + * + * \return element i + * + */ + inline long int operator[](size_t i) const + { + return NNc_arr[i]; + } + + /*! \brief Initialize the NNc array with full neighborhood cells indexes + * + * + */ + void init_full() + { + typedef typename generate_array<size_t,dim, Fill_zero>::result NNzero; + typedef typename generate_array<size_t,dim, Fill_two>::result NNtwo; + typedef typename generate_array<size_t,dim, Fill_one>::result NNone; + + // Generate the sub-grid iterator + + grid_key_dx_iterator_sub<dim> gr_sub3(gs,NNzero::data,NNtwo::data); + + // Calculate the NNc array + + size_t middle = gs.LinId(NNone::data); + size_t i = 0; + while (gr_sub3.isNext()) + { + NNc_arr[i] = (long int)gs.LinId(gr_sub3.get()) - middle; + + ++gr_sub3; + i++; + } + } + + + /*! \brief Initialize the NNc array with symmetric neighborhood cells indexes + * + * + */ + void init_sym() + { + // compile-time array {0,0,0,....} {2,2,2,...} {1,1,1,...} + + typedef typename generate_array<size_t,dim, Fill_zero>::result NNzero; + typedef typename generate_array<size_t,dim, Fill_two>::result NNtwo; + typedef typename generate_array<size_t,dim, Fill_one>::result NNone; + + size_t middle = gs.LinId(NNone::data); + + // Generate the sub-grid iterator + + grid_key_dx_iterator_sub<dim> gr_sub3(gs,NNzero::data,NNtwo::data); + + // Calculate the NNc_sym array + + size_t i = 0; + while (gr_sub3.isNext()) + { + auto key = gr_sub3.get(); + + size_t lin = gs.LinId(key); + + // Only the first half is considered + if (lin < middle) + { + ++gr_sub3; + continue; + } + + NNc_arr[i] = lin - middle; + + ++gr_sub3; + i++; + } + } + + /*! \brief return the pointer to the array + * + * \return the pointer + * + */ + const long int * getPointer() const + { + return NNc_arr; + } + + /*! \brief Copy the NNc_array + * + * \param nnc NNc_array to copy + * + */ + NNc_array<dim,size,thr> & operator=(const NNc_array<dim,size,thr> & nnc) + { + std::copy(&nnc.NNc_arr[0],&nnc.NNc_arr[size],&NNc_arr[0]); + gs = nnc.gs; + + return *this; + } + + /*! \brief swap NNc_array + * + * \param nnc NNc_array to copy + * + */ + void swap(NNc_array<dim,size,thr> & nnc) + { + gs.swap(nnc.gs); + + long int NNc_full_tmp[openfpm::math::pow(3,dim)]; + + std::copy(&nnc.NNc_arr[0],&nnc.NNc_arr[size],&NNc_full_tmp[0]); + std::copy(&NNc_arr[0],&NNc_arr[size],&nnc.NNc_arr[0]); + std::copy(&NNc_full_tmp[0],&NNc_full_tmp[size],&NNc_arr[0]); + } +}; + +/* \brief NNc_array + * + * \param size + * + */ +template<unsigned int dim, unsigned int size> +class NNc_array<dim,size,false> +{ + grid_sm<dim,void> gs; + grid_sm<dim,void> gs_base; + size_t sub_off; + size_t sym_mid; + + bool full_or_sym; + +public: + + /*! \brief set the size of the cell grid + * + * \param sz[dim] size of the cell grid in each dimension + * + */ + void set_size(const size_t (& sz)[dim]) + { + typedef typename generate_array<size_t,dim, Fill_three>::result NNthree; + + gs.setDimensions(sz); + gs_base.setDimensions(NNthree::data); + + typedef typename generate_array<size_t,dim, Fill_one>::result NNone; + sub_off = gs.LinId(NNone::data); + sym_mid = gs_base.LinId(NNone::data); + } + + /*! \brief return the element i + * + * \return element i + * + */ + long int operator[](size_t i) const + { + if (full_or_sym == true) + { + grid_key_dx<dim> key = gs_base.InvLinId(i); + return gs.LinId(key) - sub_off; + } + + grid_key_dx<dim> key = gs_base.InvLinId(i + sym_mid); + return gs.LinId(key) - sub_off; + } + + void init_full() + { + full_or_sym = true; + } + + void init_sym() + { + full_or_sym = false; + } + + /*! \brief return the pointer to the array + * + * \return the pointer + * + */ + const long int * getPointer() const + { + std::cerr << __FILE__ << ":" << __LINE__ << " error dimension is too high to use this type of neighborhood" << std::endl; + return NULL; + } + + /*! \brief Copy the NNc_array + * + * \param nnc NNc_array to copy + * + */ + NNc_array<dim,size,false> & operator=(const NNc_array<dim,size,false> & nnc) + { + gs = nnc.gs; + gs_base = nnc.gs_base; + sub_off = nnc.sub_off; + sym_mid = nnc.sym_mid; + + bool full_or_sym; + } + + /*! \brief swap the NNc_array + * + * \param nnc NNc_array to copy + * + */ + void swap(NNc_array<dim,size,false> & nnc) + { + gs.swap(nnc.gs); + gs_base.swap(nnc.gs_base); + + size_t sub_off_tmp = sub_off; + sub_off = nnc.sub_off; + nnc.sub_off = sub_off_tmp; + + size_t sym_mid_tmp = sym_mid; + sym_mid = nnc.sym_mid; + nnc.sym_mid = sym_mid_tmp; + + bool full_or_sym_tmp = full_or_sym; + full_or_sym = nnc.full_or_sym; + nnc.full_or_sym = full_or_sym_tmp; + } +}; + + +#endif /* OPENFPM_DATA_SRC_NN_CELLLIST_NNC_ARRAY_HPP_ */ diff --git a/src/NN/CellList/ParticleItCRS_Cells.hpp b/src/NN/CellList/ParticleItCRS_Cells.hpp index 6ce7d4b720598b53ef863fc2437a092d586e26f7..276b466a1a9e4713c2f05dfed7cfcd0eb56fa80a 100644 --- a/src/NN/CellList/ParticleItCRS_Cells.hpp +++ b/src/NN/CellList/ParticleItCRS_Cells.hpp @@ -10,6 +10,7 @@ #include "CellNNIterator.hpp" #include "CellList_util.hpp" +#include "NN/CellList/NNc_array.hpp" /*! \brief sub-sub-domain * @@ -82,7 +83,7 @@ private: // * * * // x * // - const long int (& NNc_sym)[openfpm::math::pow(3,dim)/2+1]; + const NNc_array<dim,openfpm::math::pow(3,dim)/2+1> & NNc_sym; //! Celllist type CellListType & cli; @@ -150,7 +151,7 @@ public: ParticleItCRS_Cells(CellListType & cli, const openfpm::vector<size_t> & dom_cell, const openfpm::vector<subsub_lin<dim>> & anom_dom_cell, - const long int (& NNc_sym)[openfpm::math::pow(3,dim)/2+1]) + const NNc_array<dim,openfpm::math::pow(3,dim)/2+1> & NNc_sym) :cid(0),NNc(NULL),NNc_size(0),dom_or_anom(0),dom_cell(dom_cell),anom_dom_cell(anom_dom_cell),NNc_sym(NNc_sym),cli(cli) { size_t s_cell; @@ -233,7 +234,7 @@ public: typename CellListType::SymNNIterator getNNIteratorCSR(const openfpm::vector<Point<dim,typename CellListType::stype>> & v) const { if (dom_or_anom == 0) - return typename CellListType::SymNNIterator(dom_cell.get(cid),*start,NNc_sym,openfpm::math::pow(3,dim)/2+1,cli,v); + return typename CellListType::SymNNIterator(dom_cell.get(cid),*start,NNc_sym.getPointer(),openfpm::math::pow(3,dim)/2+1,cli,v); else return typename CellListType::SymNNIterator(anom_dom_cell.get(cid).subsub, *start, @@ -261,7 +262,7 @@ public: typename CellListType::SymNNIterator getNNIteratorCSRM(const openfpm::vector<Point<dim,typename CellListType::stype>> & pos ,const openfpm::vector<pos_v<dim,typename CellListType::stype>> & v) const { if (dom_or_anom == 0) - return typename CellListType::SymNNIterator(dom_cell.get(cid),CellListType::getV(*start),CellListType::getP(*start),NNc_sym,openfpm::math::pow(3,dim)/2+1,cli,pos,v); + return typename CellListType::SymNNIterator(dom_cell.get(cid),CellListType::getV(*start),CellListType::getP(*start),NNc_sym.getPointer(),openfpm::math::pow(3,dim)/2+1,cli,pos,v); else return typename CellListType::SymNNIterator(anom_dom_cell.get(cid).subsub,CellListType::getV(*start),CellListType::getP(*start),&anom_dom_cell.get(cid).NN_subsub.get(0),anom_dom_cell.get(cid).NN_subsub.size(),cli,pos,v); } diff --git a/src/NN/CellList/tests/NNc_array_tests.hpp b/src/NN/CellList/tests/NNc_array_tests.hpp new file mode 100644 index 0000000000000000000000000000000000000000..06b93de62fd993960f7fdad2e0fcb5cef6bfea48 --- /dev/null +++ b/src/NN/CellList/tests/NNc_array_tests.hpp @@ -0,0 +1,124 @@ +/* + * NNc_array_tests.hpp + * + * Created on: Feb 6, 2018 + * Author: i-bird + */ + +#ifndef OPENFPM_DATA_SRC_NN_CELLLIST_TESTS_NNC_ARRAY_TESTS_HPP_ +#define OPENFPM_DATA_SRC_NN_CELLLIST_TESTS_NNC_ARRAY_TESTS_HPP_ + +#include "NN/CellList/NNc_array.hpp" + +BOOST_AUTO_TEST_SUITE( NNc_array_tests ) + +BOOST_AUTO_TEST_CASE( NNc_array_tests_use ) +{ + { + NNc_array<2,9,false> nnc; + NNc_array<2,9,true> nnc2; + + size_t sz[2] = {13,17}; + + nnc.set_size(sz); + nnc2.set_size(sz); + nnc.init_full(); + nnc2.init_full(); + + for (size_t i = 0 ; i < 9 ; i++) + { + BOOST_REQUIRE_EQUAL(nnc[i],nnc2[i]); + } + } + + { + NNc_array<3,27,false> nnc; + NNc_array<3,27,true> nnc2; + + size_t sz[3] = {13,17,11}; + + nnc.set_size(sz); + nnc2.set_size(sz); + nnc.init_full(); + nnc2.init_full(); + + for (size_t i = 0 ; i < 27 ; i++) + { + BOOST_REQUIRE_EQUAL(nnc[i],nnc2[i]); + } + } + + { + NNc_array<5,243,false> nnc; + NNc_array<5,243,true> nnc2; + + size_t sz[5] = {13,17,11,7,7}; + + nnc.set_size(sz); + nnc2.set_size(sz); + nnc.init_full(); + nnc2.init_full(); + + for (size_t i = 0 ; i < 243 ; i++) + { + BOOST_REQUIRE_EQUAL(nnc[i],nnc2[i]); + } + } + + + { + NNc_array<2,9,false> nnc; + NNc_array<2,9,true> nnc2; + + size_t sz[2] = {13,17}; + + nnc.set_size(sz); + nnc2.set_size(sz); + nnc.init_sym(); + nnc2.init_sym(); + + for (size_t i = 0 ; i < 5 ; i++) + { + BOOST_REQUIRE_EQUAL(nnc[i],nnc2[i]); + } + } + + { + NNc_array<3,27,false> nnc; + NNc_array<3,27,true> nnc2; + + size_t sz[3] = {13,17,11}; + + nnc.set_size(sz); + nnc2.set_size(sz); + nnc.init_full(); + nnc2.init_full(); + + for (size_t i = 0 ; i < 27 ; i++) + { + BOOST_REQUIRE_EQUAL(nnc[i],nnc2[i]); + } + } + + { + NNc_array<5,243,false> nnc; + NNc_array<5,243,true> nnc2; + + size_t sz[5] = {13,17,11,7,7}; + + nnc.set_size(sz); + nnc2.set_size(sz); + nnc.init_full(); + nnc2.init_full(); + + for (size_t i = 0 ; i < 243 ; i++) + { + BOOST_REQUIRE_EQUAL(nnc[i],nnc2[i]); + } + } +} + +BOOST_AUTO_TEST_SUITE_END() + + +#endif /* OPENFPM_DATA_SRC_NN_CELLLIST_TESTS_NNC_ARRAY_TESTS_HPP_ */ diff --git a/src/Space/Shape/Point.hpp b/src/Space/Shape/Point.hpp index a06d0ece1141e37eba035c5850cd6113d864d261..fc82dcd4e5e3aa54bb6e5ae5711ef0d4a2d29f97 100644 --- a/src/Space/Shape/Point.hpp +++ b/src/Space/Shape/Point.hpp @@ -353,6 +353,16 @@ template<unsigned int dim ,typename T> class Point return true; } + /*! \brief Return the string with the point coordinate + * + * \return the string + * + */ + std::string to_string() const + { + return toString(); + } + /*! \brief Return the string with the point coordinate * * \return the string diff --git a/src/main.cpp b/src/main.cpp index 19f073b345def98dd1fb9144c0eb4ce8685c019f..7885bcda58512eb638e7f5f93d740f4aaf197358 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -44,6 +44,7 @@ int main(int argc, char* argv[]) #include "Grid/grid_sm_unit_tests.hpp" #include "util/mathutil_unit_test.hpp" #include "NN/CellList/CellDecomposer_unit_tests.hpp" +#include "NN/CellList/tests/NNc_array_tests.hpp" #include "NN/CellList/CellListIterator_test.hpp" #include "Vector/map_vector_std_util_unit_test.hpp" #include "NN/VerletList/VerletList_test.hpp"