Commit c8857101 authored by Sebastian J. Mielke's avatar Sebastian J. Mielke
Browse files

Merge remote-tracking branch 'origin/develop' into AdaptiveNN

parents c0192042 efa69251
......@@ -8,7 +8,76 @@
#ifndef ENCAP_HPP_
#define ENCAP_HPP_
//#include "grid_sm.hpp"
#include "util/for_each_ref.hpp"
#include "util/meta_copy.hpp"
#include "boost/mpl/range_c.hpp"
/*! \brief this class is a functor for "for_each" algorithm
*
* This class is a functor for "for_each" algorithm. For each
* element of the boost::vector the operator() is called.
* Is mainly used to copy one encap into another encap object
*
* \tparam encap source
* \tparam encap dst
*
*/
template<typename e_src, typename e_dst>
struct copy_cpu_encap_encap
{
//! object we have to store
const e_src & src;
e_dst & dst;
/*! \brief constructor
*
* It define the copy parameters.
*
* \param key which element we are modifying
* \param grid_dst grid we are updating
* \param obj object we have to set in grid_dst (encapsulated)
*
*/
copy_cpu_encap_encap(const e_src & src, e_dst & dst)
:src(src),dst(dst)
{
#ifdef DEBUG
// e_src and e_dst must have the same number of properties
if (e_src::max_prop != e_dst::max_prop)
std::cerr << "Error " << __FILE__ << ":" << __LINE__ << " the number of properties between src and dst must match";
#endif
};
#ifdef DEBUG
/*! \brief Constructor
*
* Calling this constructor produce an error. This class store the reference of the object,
* this mean that the object passed must not be a temporal object
*
*/
copy_cpu_encap_encap(const e_src && src, const e_dst && dst)
:src(src),dst(dst)
{std::cerr << "Error: " <<__FILE__ << ":" << __LINE__ << " Passing a temporal object";};
#endif
//! 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::fusion::result_of::at_c<typename e_src::type,T::value>::type copy_type;
// Remove the reference from the type to copy
typedef typename boost::remove_reference<copy_type>::type copy_rtype;
meta_copy<copy_rtype> cp(src.template get<T::value>(),dst.template get<T::value>());
}
};
/*! \brief This class is an helper to get the return type for get method for each property
*
......@@ -73,12 +142,14 @@ private:
public:
typedef int yes_i_am_encap;
typedef T T_type;
static const int max_prop = T::max_prop;
// constructor require a key and a memory data
encapc(type & data)
inline encapc(type & data)
:data(data)
{}
......@@ -87,7 +158,7 @@ public:
* \return the address of the data encapsulated
*
*/
type * operator&()
inline type * operator&()
{
return &data;
}
......@@ -97,7 +168,7 @@ public:
* \return the reference
*
*/
template <unsigned int p> typename type_cpu_prop<p,Mem>::type get()
template <unsigned int p> inline typename type_cpu_prop<p,Mem>::type get()
{
#ifdef MEMLEAK_CHECK
check_valid(&boost::fusion::at_c<p>(data),sizeof(typename type_cpu_prop<p,Mem>::type));
......@@ -110,7 +181,7 @@ public:
* \return the reference
*
*/
template <unsigned int p> const typename type_cpu_prop<p,Mem>::type get() const
template <unsigned int p> inline const typename type_cpu_prop<p,Mem>::type get() const
{
#ifdef MEMLEAK_CHECK
check_valid(&boost::fusion::at_c<p>(data),sizeof(typename type_cpu_prop<p,Mem>::type));
......@@ -119,13 +190,27 @@ public:
}
// access the data
template <unsigned int p> void set(typename type_cpu_prop<p,Mem>::type & ele)
template <unsigned int p> inline void set(typename type_cpu_prop<p,Mem>::type & ele)
{
#ifdef MEMLEAK_CHECK
check_valid(&boost::fusion::at_c<p>(data),sizeof(typename type_cpu_prop<p,T>::type));
#endif
return boost::fusion::at_c<p>(data) = ele;
}
/*! \brief Assignment
*
* \param ec encapsulator
*
*/
inline encapc<dim,T,Mem> & operator=(const encapc<dim,T,Mem> & ec)
{
copy_cpu_encap_encap<encapc<dim,T,Mem>,encapc<dim,T,Mem>> cp(ec,*this);
boost::mpl::for_each_ref< boost::mpl::range_c<int,0,T::max_prop> >(cp);
return *this;
}
};
/*! \brief this structure specialize the class for a void object or null
......@@ -173,6 +258,8 @@ class encapg
public:
typedef int yes_i_am_encap;
typedef T T_type;
// constructor require a key and a memory data
......@@ -187,4 +274,23 @@ public:
}
};
#include "util/common.hpp"
template<typename T, typename Sfinae = void>
struct is_encap: std::false_type {};
/*! \brief is_encap check if the type is an encap type
*
* ### Example
*
* \snippet util.hpp Check is_encap
*
* return true if T is an encap
*
*/
template<typename T>
struct is_encap<T, typename Void< typename T::yes_i_am_encap>::type> : std::true_type
{};
#endif /* ENCAP_HPP_ */
......@@ -169,7 +169,7 @@ struct comb
{
int zero = 0;
for (int i = 0 ; i < dim ; i++)
for (size_t i = 0 ; i < dim ; i++)
{
if (c[i] == 0) zero++;
}
......
......@@ -3,7 +3,7 @@
#include "Grid/comb.hpp"
#include "Grid/grid_key_expression.hpp"
#include "Space/Shape/Point.hpp"
/*! \brief grid_key_dx is the key to access any element in the grid
*
......@@ -79,6 +79,20 @@ public:
k[i] = -1;
}
/* \brief sum an a combination to the grid_key
*
* \param comb combination (or relative movement)
*
* \return a grid_key_dx_expression that encapsulate the expression
*
*/
inline grid_key_dx_sum<dim,grid_key_dx<dim>,Point<dim,long int>> operator+(const Point<dim,long int> & p) const
{
grid_key_dx_sum<dim,grid_key_dx<dim>,Point<dim,long int>> exp_sum(*this,p);
return exp_sum;
}
/* \brief sum an a combination to the grid_key
*
* \param comb combination (or relative movement)
......@@ -161,6 +175,41 @@ public:
invert_assign(t...);
}
/*! \brief Convert to a point the grid_key_dx
*
* \see toPoint
*
*/
Point<dim,long int> toPointS() const
{
Point<dim,long int> p;
for (size_t i = 0; i < dim ; i++)
{
p.get(i) = get(i);
}
return p;
}
/*! \brief Convert to a point the grid_key_dx
*
* \see toPointS
*
*/
Point<dim,size_t> toPoint() const
{
Point<dim,size_t> p;
for (size_t i = 0; i < dim ; i++)
{
p.get(i) = get(i);
}
return p;
}
/*! \brief Get the i index
*
* \param i index to get
......
......@@ -31,6 +31,14 @@ BOOST_AUTO_TEST_CASE( grid_expression_use)
BOOST_REQUIRE_EQUAL(res.get(0),0);
BOOST_REQUIRE_EQUAL(res.get(1),0);
BOOST_REQUIRE_EQUAL(res.get(2),0);
const Point<3,long int> p({1,2,3});
res = res + p;
BOOST_REQUIRE_EQUAL(res.get(0),1);
BOOST_REQUIRE_EQUAL(res.get(1),2);
BOOST_REQUIRE_EQUAL(res.get(2),3);
}
BOOST_AUTO_TEST_SUITE_END()
......
#ifndef GRID_KEY_EXPRESSION
#define GRID_KEY_EXPRESSION
#include "util/common.hpp"
template<unsigned int dim> class grid_key_dx;
template<int dim, typename exp1, typename exp2> class grid_key_dx_sum;
......
......@@ -6,7 +6,7 @@
#include <vector>
#include <initializer_list>
#include <array>
#include "memory.hpp"
#include "memory/memory.hpp"
#include "Space/Shape/Box.hpp"
#include "grid_key.hpp"
......@@ -675,11 +675,11 @@ public:
*
*/
grid_key_dx_iterator()
{
{
#ifdef DEBUG
initialized = false;
#endif
}
}
/*! \brief Constructor from a grid_key_dx_iterator<dim>
*
......@@ -705,17 +705,14 @@ public:
* \param g info of the grid on which iterate
*/
template<typename T> grid_key_dx_iterator(const grid_sm<dim,T> & g)
: grid_base(g)
{
//! Initialize to 0 the index
for (size_t i = 0 ; i < dim ; i++)
{gk.set_d(i,0);}
: grid_base(g)
{
reset();
#ifdef DEBUG
initialized = true;
#endif
}
}
/*! \brief Constructor from another grid_key_dx_iterator
*
......@@ -740,7 +737,7 @@ public:
*/
grid_key_dx_iterator<dim> & operator++()
{
{
//! increment the first index
size_t id = gk.get(0);
......@@ -767,7 +764,7 @@ public:
}
return *this;
}
}
/*! \brief Set the dimension
*
......@@ -813,9 +810,9 @@ public:
*
*/
const grid_key_dx<dim> & get()
{
{
return gk;
}
}
/*! \brief Reinitialize the grid_key_dx_iterator
*
......@@ -824,10 +821,11 @@ public:
*/
void reinitialize(const grid_key_dx_iterator<dim> & key)
{
grid_base = key.grid_base;
reset();
}
/*! \brief Reset the counter
/*! \brief Reset the iterator (it restart from the beginning)
*
*/
void reset()
......@@ -1049,8 +1047,8 @@ public:
*
*/
template<typename T> grid_key_dx_iterator_sub(const grid_sm<dim,T> & g, const grid_key_dx<dim> & start, const grid_key_dx<dim> & stop)
: grid_key_dx_iterator<dim>(g),grid_base(g),gk_start(start), gk_stop(stop)
{
: grid_key_dx_iterator<dim>(g),grid_base(g),gk_start(start), gk_stop(stop)
{
#if defined(DEBUG) && !defined(NO_WARNING)
//! If we are on debug check that the stop grid_key id bigger than the start
//! grid_key
......@@ -1065,7 +1063,7 @@ public:
#endif
Initialize();
}
}
/*! \brief Constructor require a grid grid<dim,T>
......@@ -1108,7 +1106,7 @@ public:
template<typename T> grid_key_dx_iterator_sub(const grid_sm<dim,T> & g, const size_t (& start)[dim], const size_t (& stop)[dim])
: grid_key_dx_iterator<dim>(g),grid_base(g),gk_start(start), gk_stop(stop)
{
#ifndef DEBUG
#ifdef DEBUG
//! If we are on debug check that the stop grid_key id bigger than the start
//! grid_key
......@@ -1116,7 +1114,7 @@ public:
{
if (start[i] > stop[i])
{
std::cerr << "Error grid_key_dx_iterator : the starting point of the grid cannot be bigger than the stop point at any coordinate" << "\n";
std::cerr << "Error grid_key_dx_iterator : " << __FILE__ << ":" << __LINE__ << " the starting point of the grid cannot be bigger than the stop point at any coordinate" << "\n";
}
}
#endif
......@@ -1175,7 +1173,7 @@ public:
*
*/
bool isNext()
inline bool isNext()
{
#ifdef DEBUG
if (initialized == false)
......@@ -1196,15 +1194,15 @@ public:
/*! \brief Return the actual grid key iterator
*
*/
grid_key_dx<dim> get()
{
inline grid_key_dx<dim> get()
{
#ifdef DEBUG
if (initialized == false)
{std::cerr << "Error: " << __FILE__ << __LINE__ << " using unitialized iterator" << "\n";}
#endif
return grid_key_dx_iterator<dim>::get();
}
}
/*! \brief Reinitialize the iterator
*
......@@ -1215,7 +1213,7 @@ public:
*
*/
void reinitialize(const grid_key_dx_iterator_sub<dim> & g_s_it)
inline void reinitialize(const grid_key_dx_iterator_sub<dim> & g_s_it)
{
// Reinitialize the iterator
......@@ -1233,7 +1231,7 @@ public:
{
if (gk_start.get(i) > gk_stop.get(i))
{
std::cerr << "Error grid_key_dx_iterator : the starting point of the grid cannot be bigger than the stop point at any coordinate" << "\n";
std::cerr << "Error grid_key_dx_iterator : " << __FILE__ << ":" << __LINE__ << " the starting point of the grid cannot be bigger than the stop point at any coordinate" << "\n";
}
}
......@@ -1242,6 +1240,27 @@ public:
Initialize();
}
/*! \brief Get the volume spanned by this sub-grid iterator
*
* \return the volume
*
*/
inline size_t getVolume()
{
return Box<dim,long int>::getVolumeKey(gk_start.k, gk_stop.k);
}
/*! \brief Reset the iterator (it restart from the beginning)
*
*/
inline void reset()
{
//! Initialize to 0 the index
for (size_t i = 0 ; i < dim ; i++)
{this->gk.set_d(i,gk_start.get(i));}
}
};
......
......@@ -5,6 +5,7 @@
#include "Point_test.hpp"
#include "Space/Shape/HyperCube.hpp"
#include "timer.hpp"
#include "grid_util_test.hpp"
#ifdef TEST_COVERAGE_MODE
#define GS_SIZE 8
......@@ -244,34 +245,8 @@ template<unsigned int dim, typename g> void test_layout_gridObjNd(g & c3, size_t
bool passed = true;
key_it = c3.getIterator();
while (key_it.isNext())
{
grid_key_dx<dim> kk = key_it.get();
c3.template get<P::x>(kk) = c3.getGrid().LinId(kk);
c3.template get<P::y>(kk) = c3.getGrid().LinId(kk)+1;
c3.template get<P::z>(kk) = c3.getGrid().LinId(kk)+2;
c3.template get<P::s>(kk) = c3.getGrid().LinId(kk)+3;
c3.template get<P::v>(kk)[0] = c3.getGrid().LinId(kk)+123;
c3.template get<P::v>(kk)[1] = c3.getGrid().LinId(kk)+124;
c3.template get<P::v>(kk)[2] = c3.getGrid().LinId(kk)+125;
c3.template get<P::t>(kk)[0][0] = c3.getGrid().LinId(kk)+567;
c3.template get<P::t>(kk)[0][1] = c3.getGrid().LinId(kk)+568;
c3.template get<P::t>(kk)[0][2] = c3.getGrid().LinId(kk)+569;
c3.template get<P::t>(kk)[1][0] = c3.getGrid().LinId(kk)+570;
c3.template get<P::t>(kk)[1][1] = c3.getGrid().LinId(kk)+571;
c3.template get<P::t>(kk)[1][2] = c3.getGrid().LinId(kk)+572;
c3.template get<P::t>(kk)[2][0] = c3.getGrid().LinId(kk)+573;
c3.template get<P::t>(kk)[2][1] = c3.getGrid().LinId(kk)+574;
c3.template get<P::t>(kk)[2][2] = c3.getGrid().LinId(kk)+575;
++key_it;
}
//! Fill the grid with some data
fill_grid<dim>(c3);
key_it = c3.getIterator();
......@@ -587,6 +562,13 @@ BOOST_AUTO_TEST_CASE( grid_iterator_test_use)
BOOST_REQUIRE_EQUAL(count, 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);
}
}
......
/*
* grid_util_test.hpp
*
* Created on: Jul 18, 2015
* Author: Pietro Incardona
*/
#ifndef SRC_GRID_GRID_UTIL_TEST_HPP_
#define SRC_GRID_GRID_UTIL_TEST_HPP_
/*! \brief Fill the grid with some data
*
* \param grid to fill
*
*/
template<unsigned int dim, typename T> void fill_grid(T & grid)
{
auto key_it = grid.getIterator();
while (key_it.isNext())
{
grid_key_dx<dim> kk = key_it.get();
grid.template get<P::x>(kk) = grid.getGrid().LinId(kk);
grid.template get<P::y>(kk) = grid.getGrid().LinId(kk)+1;
grid.template get<P::z>(kk) = grid.getGrid().LinId(kk)+2;
grid.template get<P::s>(kk) = grid.getGrid().LinId(kk)+3;
grid.template get<P::v>(kk)[0] = grid.getGrid().LinId(kk)+123;
grid.template get<P::v>(kk)[1] = grid.getGrid().LinId(kk)+124;
grid.template get<P::v>(kk)[2] = grid.getGrid().LinId(kk)+125;
grid.template get<P::t>(kk)[0][0] = grid.getGrid().LinId(kk)+567;
grid.template get<P::t>(kk)[0][1] = grid.getGrid().LinId(kk)+568;
grid.template get<P::t>(kk)[0][2] = grid.getGrid().LinId(kk)+569;
grid.template get<P::t>(kk)[1][0] = grid.getGrid().LinId(kk)+570;
grid.template get<P::t>(kk)[1][1] = grid.getGrid().LinId(kk)+571;
grid.template get<P::t>(kk)[1][2] = grid.getGrid().LinId(kk)+572;
grid.template get<P::t>(kk)[2][0] = grid.getGrid().LinId(kk)+573;
grid.template get<P::t>(kk)[2][1] = grid.getGrid().LinId(kk)+574;
grid.template get<P::t>(kk)[2][2] = grid.getGrid().LinId(kk)+575;
++key_it;
}
}
#endif /* SRC_GRID_GRID_UTIL_TEST_HPP_ */
......@@ -17,16 +17,19 @@
#include <boost/fusion/include/for_each.hpp>
#include <boost/mpl/range_c.hpp>
#include <boost/mpl/for_each.hpp>
#include "memory_conf.hpp"
#include "memory_ly/memory_conf.hpp"
#include "util/meta_copy.hpp"
#include "Memleak_check.hpp"
#include "util/for_each_ref.hpp"
#include "util.hpp"
#include <utility>
#ifdef CUDA_GPU
#include "memory/CudaMemory.cuh"
#endif
#include "grid_sm.hpp"
#include "Encap.hpp"
#include "memory_array.hpp"
#include "memory_c.hpp"
#include "memory_ly/memory_array.hpp"
#include "memory_ly/memory_c.hpp"
#include <vector>
/*! \brief this class is a functor for "for_each" algorithm
......@@ -317,6 +320,8 @@ public:
//! boost::vector that describe the data type
typedef typename T::type T_type;
typedef Mem memory_conf;
private:
//! This is an header that store all information related to the grid
grid_sm<dim,T> g1;
......@@ -347,6 +352,9 @@ private: