diff --git a/src/Grid/staggered_grid.hpp b/src/Grid/staggered_dist_grid.hpp similarity index 51% rename from src/Grid/staggered_grid.hpp rename to src/Grid/staggered_dist_grid.hpp index 263c45895480e28f156fdda82ee09707cef7e47e..cef15d141a169870844d0305dead19538b34276b 100644 --- a/src/Grid/staggered_grid.hpp +++ b/src/Grid/staggered_dist_grid.hpp @@ -5,14 +5,16 @@ * Author: i-bird */ -#ifndef SRC_GRID_STAGGERED_GRID_HPP_ -#define SRC_GRID_STAGGERED_GRID_HPP_ +#ifndef SRC_GRID_STAGGERED_DIST_GRID_HPP_ +#define SRC_GRID_STAGGERED_DIST_GRID_HPP_ + +#include "Grid/grid_dist_id.hpp" +#include "staggered_dist_grid_util.hpp" -typedef boost::mpl::vector stag_elements; /*! \brief Implementation of the staggered grid * - * \param dim Dimensionality od the staggered grid + * \param dim Dimensionality of the staggered grid * \param ele elements object on each dimensional objects, must be a stag_elements * * @@ -52,18 +54,41 @@ typedef boost::mpl::vector stag_elements; * * */ -template <unsigned int dim, typename ele> -class staggered_grid +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> { -private: +public: - openfpm::vector< grid_cpu<dim> > + staggered_grid_dist(Vcluster & v_cl) + :grid_dist_id<dim,St,T,Decomposition,Memory,device_grid>(v_cl) + {} -public: + openfpm::vector<comb<dim>> c_prp[T::max_prop]; + /*! \brief Set the staggered positions + * + * + */ + template<unsigned int p> void setStagPosition(openfpm::vector<comb<dim>> & cmb) + { +#ifdef SE_CLASS1 + if (mul_extends< boost::mpl::at<ele::type>::type >::ext() != cmb.size()) + std::cerr << __FILE__ << ":" << __LINE << " error properties has " << mul_extends< boost::mpl::at<ele::type>::type >::ext() << " components, but " << cmb.size() << "has been defined \n"; +#endif + c_prp.get(p) = cmb; + } -}; + /*! \brief It set all the properties on a default location + * + * \return default staggered position + * + */ + openfpm::vector<comb<dim>> getDefaultStagPosition() + { + // for each properties + } +}; -#endif /* SRC_GRID_STAGGERED_GRID_HPP_ */ +#endif /* SRC_GRID_STAGGERED_DIST_GRID_HPP_ */ diff --git a/src/Grid/staggered_dist_grid_util.hpp b/src/Grid/staggered_dist_grid_util.hpp new file mode 100644 index 0000000000000000000000000000000000000000..559a142289de11f028544cc45df1acecb9762144 --- /dev/null +++ b/src/Grid/staggered_dist_grid_util.hpp @@ -0,0 +1,254 @@ +/* + * staggered_util.hpp + * + * Created on: Aug 19, 2015 + * Author: i-bird + */ + +#ifndef SRC_GRID_STAGGERED_DIST_GRID_UTIL_HPP_ +#define SRC_GRID_STAGGERED_DIST_GRID_UTIL_HPP_ + +/*! \brief Classes to get the number of components of the properties + * + */ +template<typename T> +struct extends +{ + static inline size_t mul() + { + return 1; + } + + static inline size_t dim() + { + return 0; + } +}; + +//! Partial specialization for N=1 1D-Array +template<typename T,size_t N1> +struct extends<T[N1]> +{ + static inline size_t mul() + { + return N1; + } + + static inline size_t dim() + { + return 1; + } +}; + +//! Partial specialization for N=2 2D-Array +template<typename T,size_t N1,size_t N2> +struct extends<T[N1][N2]> +{ + static inline size_t mul() + { + return N1 * N2; + } + + static inline size_t dim() + { + return 2; + } +}; + +//! Partial specialization for N=3 +template<typename T,size_t N1,size_t N2,size_t N3> +struct extends<T[N1][N2][N3]> +{ + static inline size_t mul() + { + return N1 * N2 * N3; + } + + static inline size_t dim() + { + return 3; + } +}; + +//! Partial specialization for N=4 +template<typename T,size_t N1,size_t N2,size_t N3,size_t N4> +struct extends<T[N1][N2][N3][N4]> +{ + static inline size_t mul() + { + return N1 * N2 * N3 * N4; + } + + static inline size_t dim() + { + return 4; + } +}; + +//! Partial specialization for N=5 +template<typename T,size_t N1,size_t N2,size_t N3,size_t N4,size_t N5> +struct extends<T[N1][N2][N3][N4][N5]> +{ + static inline size_t mul() + { + return N1 * N2 * N3 * N4 * N5; + } + + static inline size_t dim() + { + return 5; + } +}; + +//! Partial specialization for N=6 +template<typename T,size_t N1,size_t N2,size_t N3,size_t N4,size_t N5, size_t N6> +struct extends<T[N1][N2][N3][N4][N5][N6]> +{ + static inline size_t mul() + { + return N1 * N2 * N3 * N4 * N5 * N6; + } + + static inline size_t dim() + { + return 6; + } +}; + +//! Partial specialization for N=7 +template<typename T,size_t N1,size_t N2,size_t N3,size_t N4,size_t N5, size_t N6, size_t N7> +struct extends<T[N1][N2][N3][N4][N5][N6][N7]> +{ + static inline size_t mul() + { + return N1 * N2 * N3 * N4 * N5 * N6 * N7; + } + + static inline size_t dim() + { + return 7; + } +}; + +//! Partial specialization for N=8 +template<typename T,size_t N1,size_t N2,size_t N3,size_t N4,size_t N5, size_t N6, size_t N7, size_t N8> +struct extends<T[N1][N2][N3][N4][N5][N6][N7][N8]> +{ + static inline size_t mul() + { + return N1 * N2 * N3 * N4 * N5 * N6 * N7 * N8; + } + + static inline size_t dim() + { + return 8; + } +}; + +//! Partial specialization for N=9 +template<typename T,size_t N1,size_t N2,size_t N3,size_t N4,size_t N5, size_t N6, size_t N7, size_t N8, size_t N9> +struct extends<T[N1][N2][N3][N4][N5][N6][N7][N8][N9]> +{ + static inline size_t mul() + { + return N1 * N2 * N3 * N4 * N5 * N6 * N7 * N8 * N9; + } + + static inline size_t dim() + { + return 9; + } +}; + +//! Partial specialization for N=10 +template<typename T,size_t N1,size_t N2,size_t N3,size_t N4,size_t N5, size_t N6, size_t N7, size_t N8, size_t N9, size_t N10> +struct extends<T[N1][N2][N3][N4][N5][N6][N7][N8][N9][N10]> +{ + static inline size_t mul() + { + return N1 * N2 * N3 * N4 * N5 * N6 * N7 * N8 * N9 * N10; + } + + static inline size_t dim() + { + return 10; + } +}; + +///////////////////// Staggered default positioning //////////////////////// + +/*! \brief this class is a functor for "for_each" algorithm + * + * For each element of the boost::vector the operator() is called. + * Is mainly used to produce a default position vector for each + * property + * + * \tparam vector of properties + * + */ + +template<unsigned int dim, typename v, bool has_posMask> +struct stag_set_position +{ + openfpm::vector<comb<dim>> (& pos_prp)[boost::fusion::result_of::size<v>::type::value]; + + //! It call the copy function for each property + template<typename T> + void operator()(T& t) const + { + // This is the type of the object we have to copy + typedef typename boost::mpl::at<v,typename boost::mpl::int_<T::value>>::type prop; + + bool val = prop::stag_pos_mask[T::value]; + + if (val == false) + return; + + // Dimension of the object + size_t dim_prp = extends<prop>::dim(); + + // It is a scalar + if (dim_prp == 0) + { + comb<dim> c; + c.zero(); + + // It stay in the center + pos_prp[T::value].add(c); + } + else if (dim_prp == 1) + { + // It stay on the object of dimension dim-1 (Negative part) + for (size_t i = 0 ; i < dim ; i++) + { + comb<dim> c; + c.zero(); + c.value(i) = 1; + + pos_prp[T::value].add(c); + } + } + else if (dim_prp == 2) + { + // Create an hypercube object + HyperCube<dim> hyp; + + + + // Diagonal part live in + for (size_t i = 0 ; i < dim ; i++) + { + comb<dim> c; + c.zero(); + c.value(i) = 1; + + pos_prp[T::value].add(c); + } + } + + + } +}; + + +#endif /* SRC_GRID_STAGGERED_DIST_GRID_UTIL_HPP_ */ diff --git a/src/Grid/staggered_util.hpp b/src/Grid/staggered_util.hpp deleted file mode 100644 index d29b2e993770a0658fed899f7842fc6f5f56da55..0000000000000000000000000000000000000000 --- a/src/Grid/staggered_util.hpp +++ /dev/null @@ -1,33 +0,0 @@ -/* - * staggered_util.hpp - * - * Created on: Aug 19, 2015 - * Author: i-bird - */ - -#ifndef SRC_GRID_STAGGERED_UTIL_HPP_ -#define SRC_GRID_STAGGERED_UTIL_HPP_ - -#include "variadic_to_vmpl.hpp" - -/*! Meta-function to apply to the vector - * - */ -template<typename arg0, typename T> -struct F -{ - typedef grid_cpu<arg0::value,T> type; -}; - -/*! \brief Create staggered data vector - * - * \param s_ele boost::fusion::vector of elements - * - */ -template <typename s_ele> -struct create_stag_data -{ - typedef v_transform<,s_ele> -}; - -#endif /* SRC_GRID_STAGGERED_UTIL_HPP_ */ diff --git a/src/main.cpp b/src/main.cpp index fe5923ba5cde47805ad87778d49c9de02402728e..ea01000ba4bbc5a9a09dbfc84356a5f9b6f903cc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,6 +18,7 @@ #include "util.hpp" #include "unit_test_init_cleanup.hpp" +#include "Grid/staggered_grid_dist_unit_test.hpp" #include "Decomposition/CartDecomposition_unit_test.hpp" #include "Decomposition/ORB_unit_test.hpp" #include "Graph/CartesianGraphFactory_unit_test.hpp"