Commit 293c299b authored by incardon's avatar incardon
Browse files

Fixing encapg

parent 59ab4036
......@@ -8,7 +8,7 @@
#ifndef ENCAP_HPP_
#define ENCAP_HPP_
#include "grid_sm.hpp"
//#include "grid_sm.hpp"
/*! \brief This class is an helper to get the return type for get method for each property
*
......@@ -164,22 +164,21 @@ class encapg
{
// constructor require a key
Mem & data;
grid_key_dx<dim> & k;
grid_sm<dim,void> & g1;
size_t k;
public:
typedef T T_type;
// constructor require a key and a memory data
encapg(Mem & data, grid_key_dx<dim> & k, grid_sm<dim,void> & g1)
:data(data),k(k),g1(g1)
encapg(Mem & data, size_t k)
:data(data),k(k)
{}
// access the data
template <unsigned int p> typename type_gpu_prop<p,T>::type::reference get()
{
return boost::fusion::at_c<p>(data).mem_r->operator[](g1.LinId(k));
return boost::fusion::at_c<p>(data).mem_r->operator[](k);
}
};
......
......@@ -116,7 +116,7 @@ struct copy_cpu
typedef typename S::type::type ov_seq;
//! object we have to store
obj_type & obj;
const obj_type & obj;
/*! \brief constructor
*
......@@ -127,7 +127,7 @@ struct copy_cpu
* \param obj object we have to set in grid_src
*
*/
copy_cpu(grid_key_dx<dim> & key, S & grid_dst, obj_type & obj)
copy_cpu(grid_key_dx<dim> & key, S & grid_dst, const obj_type & obj)
:key(key),grid_dst(grid_dst),obj(obj){};
//! It call the copy function for each property
......@@ -759,7 +759,7 @@ class grid_cpu
*
*/
inline void set(grid_key_dx<dim> dx, T & obj)
inline void set(grid_key_dx<dim> dx, const T & obj)
{
#ifdef DEBUG
// Check that the element exist
......@@ -1017,7 +1017,7 @@ public:
*/
inline encapg<dim,T,Mem> get_o(grid_key_dx<dim> & v1)
{
return encapg<dim,T,Mem>(data,v1,g1);
return encapg<dim,T,Mem>(data,g1.LinId(v1));
}
inline size_t size()
......
......@@ -5,6 +5,7 @@
#include "Space/Shape/Sphere.hpp"
#include <boost/fusion/sequence/intrinsic/at_c.hpp>
#include "Grid/grid_key.hpp"
#include "Grid/Encap.hpp"
/*! \brief It define if we want the upper base or the down base (Lower or upper)
* extreme of the interval
......@@ -48,6 +49,53 @@ public:
//! Maximum number of properties
static const unsigned int max_prop = 2;
/*! \brief Intersect
*
* Intersect two boxes and return the result boxes, if the boxes does not intersect, return false
*
* \param b box to intersect with
* \param b_out box result of the intersection
*
* \return true if they intersect
*
*/
bool Intersect(const Box<dim,T> & b, Box<dim,T> & b_out)
{
// check if p1 of b is smaller than
for (size_t i ; i < dim ; i++)
{
if (getLow(i) < b.getLow(i))
{
b_out.setLow(i,b.getLow(i));
}
else if (getLow(i) < b.getHigh(i))
{
b_out.setLow(i,getLow(i));
}
else
{
return false;
}
}
return true;
}
/*! \brief Intersect
*
* Intersect two boxes and return the result boxes, if the boxes does not intersect, return false
*
* \param e_b encapsulator box to intersect with
* \param b_out box result of the intersection
*
* \return true if they intersect
*
*/
template<typename Mem> bool Intersect(const encapc<1,Box<dim,T>,Mem> & e_b, Box<dim,T> & b_out)
{
return Intersect(e_b,b_out);
}
/*!
*
* \brief Check if the sphere intersect the box
......
......@@ -104,7 +104,7 @@ class SpaceBox : public Box<dim,T>
*
*/
SpaceBox(Box<dim,T> & b)
SpaceBox(const Box<dim,T> & b)
{
// for each dimension set high and low
......@@ -132,6 +132,23 @@ class SpaceBox : public Box<dim,T>
{this->setHigh(d,box.template get<Box<dim,S>::p2>()[d]);}
}
/*! \brief Constructor from a Box
*
* \param Box
*
*/
template<unsigned int dim_s,typename Mem, typename S>SpaceBox(const encapc<dim_s,SpaceBox<dim,S>,Mem> & box)
{
// for each dimension set high and low
for (size_t d = 0 ; d < dim ; d++)
{this->setLow(d,box.template get<Box<dim,S>::p1>()[d]);}
for (size_t d = 0 ; d < dim ; d++)
{this->setHigh(d,box.template get<Box<dim,S>::p2>()[d]);}
}
/*! \brief Constructor from initializer list
*
* Constructor from initializer list
......
......@@ -393,7 +393,7 @@ namespace openfpm
* reallocation, work only on cpu
*
*/
void add(T & v)
void add(const T & v)
{
//! Check if we have enough space
......@@ -424,7 +424,7 @@ namespace openfpm
*
*
*/
void add(typename grid_cpu<1,T>::container & v)
void add(const typename grid_cpu<1,T>::container & v)
{
//! Check if we have enough space
......
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