Commit 178d18b2 authored by incardon's avatar incardon
Browse files

Change to grid_sm

parent 94af91ba
......@@ -74,7 +74,7 @@ BOOST_AUTO_TEST_CASE( graph_use)
gs.push_back(GS_SIZE);
gs.push_back(GS_SIZE);
grid<2,void> g2(gs);
grid_sm<2,void> g2(gs);
// Create the edge 4 for each vertex
......
......@@ -8,7 +8,7 @@
#ifndef ENCAP_HPP_
#define ENCAP_HPP_
#include "grid.hpp"
#include "grid_sm.hpp"
/*! \brief This class is an helper to get the return type for get method for each property
*
......@@ -168,14 +168,14 @@ class encapg
// constructor require a key
Mem & data;
grid_key_dx<dim> & k;
grid<dim,void> & g1;
grid_sm<dim,void> & g1;
public:
typedef T T_type;
// constructor require a key and a memory data
encapg(Mem & data, grid_key_dx<dim> & k, grid<dim,void> & g1)
encapg(Mem & data, grid_key_dx<dim> & k, grid_sm<dim,void> & g1)
:data(data),k(k),g1(g1)
{}
......
This diff is collapsed.
......@@ -37,28 +37,14 @@ public:
{}
//! Constructor from buffer reference
grid_key_dx(size_t (&k)[dim])
{
for (int i = 0 ; i < dim ; i++)
this->k[i] = k[i];
}
//! Constructor from buffer
grid_key_dx(size_t k[dim])
{
for (int i = 0 ; i < dim ; i++)
this->k[i] = k[i];
}
//! Constructor from buffer
grid_key_dx(const size_t k[dim])
grid_key_dx(const size_t (&k)[dim])
{
for (int i = 0 ; i < dim ; i++)
this->k[i] = k[i];
}
//! Construct a grid key from a list of numbers
template<typename ...T>grid_key_dx(const size_t v,const T...t)
template<typename ...T> grid_key_dx(const size_t v,const T...t)
{
k[dim-1] = v;
invert_assign(t...);
......
......@@ -23,7 +23,7 @@
#include "for_each_ref.hpp"
#include "grid.hpp"
#include "grid_sm.hpp"
#include "Encap.hpp"
#include "memory_array.hpp"
#include "memory_c.hpp"
......@@ -219,7 +219,7 @@ class grid_cpu
typedef typename T::type T_type;
//! This is an header that store all information related to the grid
grid<dim,T> g1;
grid_sm<dim,T> g1;
//! This is the interface to allocate an resize memory
//! and give also a representation to the allocated memory
......@@ -352,7 +352,7 @@ class grid_cpu
*
*/
grid<dim,T> getGrid()
grid_sm<dim,T> getGrid()
{
return g1;
}
......@@ -785,7 +785,7 @@ class grid_gpu
typedef grid_key_dx<dim> access_key;
//! It store all the information regarding the grid
grid<dim,void> g1;
grid_sm<dim,void> g1;
//! This is the interface to allocate,resize ... memory
//! and give also a representation to the allocated memory
......@@ -828,7 +828,7 @@ public:
*
*/
grid<dim,void> getGrid()
grid_sm<dim,void> getGrid()
{
return g1;
}
......
......@@ -27,7 +27,7 @@
#include "Vector/map_vector.hpp"
// Stub implementation
template<unsigned int dim, typename T, unsigned int impl=FAST, typename base=openfpm::vector<size_t>>
template<unsigned int dim, typename T, unsigned int impl=FAST, typename base=openfpm::vector<T>>
class CellList
{
};
......
......@@ -42,7 +42,7 @@ class CellList<dim,T,BALANCED,base>
SpaceBox<dim,T> box_unit;
// Grid structure of the Cell list
grid<dim,void> gr_cell;
grid_sm<dim,void> gr_cell;
public:
......
......@@ -29,6 +29,10 @@
enum { value = 2 };
};
template<size_t index, size_t N> struct Fill_one {
enum { value = 1 };
};
/*! \brief Class for STANDARD cell list implementation
*
* This class implement the STANDARD cell list, fast but memory
......@@ -49,14 +53,27 @@
template<unsigned int dim, typename T, typename base>
class CellList<dim,T,FAST,base>
{
// The array contain the neighborhood of the cell-id
size_t (& NNc_full)[openfpm::math::pow(3,dim)];
// The array contain the neighborhood of the cell-id
size_t (& NNc_sym)[openfpm::math::pow(3,dim)];
// The array contain the neighborhood of the cell-id
size_t (& NNc_cr)[openfpm::math::pow(2,dim)];
// The array contain the neighborhood of the cell-id in case of asymmetric interaction
//
// * * *
// * x *
// * * *
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];
// The array contain the neighborhood of the cell-id in case of symmetric interaction (Optimized)
//
// * *
// x *
//
long int NNc_cr[openfpm::math::pow(2,dim)];
// Total number of cell
size_t tot_n_cell;
......@@ -78,7 +95,7 @@ class CellList<dim,T,FAST,base>
SpaceBox<dim,T> box_unit;
// Grid structure of the Cell list
grid<dim,void> gr_cell;
grid_sm<dim,void> gr_cell;
//Origin point
Point<dim,T> orig;
......@@ -106,6 +123,9 @@ class CellList<dim,T,FAST,base>
public:
// Object type that the structure store
typedef T value_type;
/*! \brief Cell list
*
* \param box Domain where this cell list is living
......@@ -139,20 +159,21 @@ public:
// compile-time array {0,0,0,....} and {3,3,3,...}
typedef generate_array<size_t,dim, Fill_zero>::result NNzero;
typedef generate_array<size_t,dim, Fill_three>::result NNthree;
typedef generate_array<size_t,dim, Fill_two>::result NNtwo;
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(gr_cell,NNzero,NNthree);
grid_key_dx_iterator_sub<dim> gr_sub3(gr_cell,NNzero::data,NNtwo::data);
// Calculate the NNc array
size_t middle = gr_cell.LinId(NNone::data);
size_t i = 0;
while (gr_sub3.isNext())
{
NNc_full[i] = gr_cell.LinId(gr_sub.get()) - openfpm::math::pow(3,dim) / 2;
NNc_full[i] = (long int)gr_cell.LinId(gr_sub3.get()) - middle;
++gr_sub3;
i++;
......@@ -160,7 +181,8 @@ public:
// Calculate the NNc_sym array
size_t i = 0;
i = 0;
gr_sub3.reset();
while (gr_sub3.isNext())
{
auto key = gr_sub3.get();
......@@ -168,10 +190,13 @@ public:
size_t lin = gr_cell.LinId(key);
// Only the first half is considered
if (lin > openfpm::math::pow(3,dim) / 2)
break;
if (lin < middle)
{
++gr_sub3;
continue;
}
NNc_sym[i] = lin;
NNc_sym[i] = lin - middle;
++gr_sub3;
i++;
......@@ -179,15 +204,14 @@ public:
// Calculate the NNc_cross array
grid_key_dx_iterator_sub<dim> gr_sub2(gr_cell,NNzero,NNtwo);
i = 0;
grid_key_dx_iterator_sub<dim> gr_sub2(gr_cell,NNzero::data,NNone::data);
while (gr_sub2.isNext())
{
auto key = gr_sub2.get();
size_t lin = gr_cell.LinId(key);
NNc_cr[i] = lin - openfpm::math::pow(3,dim) / 2;
NNc_cr[i] = (long int)gr_cell.LinId(key);
++gr_sub2;
i++;
......@@ -200,7 +224,7 @@ public:
* \param ele element to store
*
*/
void addElement(const T (& pos)[dim], typename base::value_type ele)
void add(const T (& pos)[dim], typename base::value_type ele)
{
// calculate the Cell id
......@@ -227,7 +251,7 @@ public:
* \param ele element to store
*
*/
void addElement(const Point<dim,T> & pos, typename base::value_type ele)
void add(const Point<dim,T> & pos, typename base::value_type ele)
{
// calculate the Cell id
......@@ -254,9 +278,9 @@ public:
* \param ele element id
*
*/
void removeElement(size_t cell, size_t ele)
void remove(size_t cell, size_t ele)
{
cl_n.get(cell_id)--;
cl_n.get(cell)--;
}
/*! \brief Get the cell-id
......@@ -318,16 +342,35 @@ public:
}
/*! \brief Get an element in the cell
*
* \tparam i property to get
*
* \param cell cell id
* \param ele element id
*
* \return The element value
*
*/
typename base::value_type getElement(size_t cell, size_t ele)
auto get(size_t cell, size_t ele) -> decltype(cl_base.get(cell * slot + ele))
{
return cl_base.get(cell * slot + ele);
}
/*! \brief Get an element in the cell
*
* \tparam i property to get
*
* \param cell cell id
* \param ele element id
*
* \return The element value
*
*/
template<unsigned int i> auto get(size_t cell, size_t ele) -> decltype(cl_base.get(cell * slot + ele))
{
return cl_base.template get<i>(cell * slot + ele);
}
/*! \brief Swap the memory
*
* \param cl Cell list with witch you swap the memory
......@@ -344,21 +387,25 @@ public:
* \param cell cell id
*
*/
CellNNIteratorFull<dim,CellList<dim,T,FAST,base>> getNNIterator(size_t cell)
template<unsigned int impl> CellNNIterator<dim,CellList<dim,T,FAST,base>,FULL,impl> getNNIterator(size_t cell)
{
CellNNIterator<dim,CellList<dim,T,FAST,base>,FULL,impl> cln(cell,NNc_full,*this);
return CellNNIteratorFull(cell,NNc,offset);
return cln;
}
CellNNIteratorSym<dim,CellList<dim,T,FAST,base>> getNNIteratorSym()
template<unsigned int impl> CellNNIterator<dim,CellList<dim,T,FAST,base>,SYM,impl> getNNIteratorSym(size_t cell)
{
CellNNIterator<dim,CellList<dim,T,FAST,base>,SYM,impl> cln(cell,NNc_sym,*this);
return cln;
}
CellNNIteratorCross<dim,CellList<dim,T,FAST,base>> getNNIteratorCross()
template<unsigned int impl> CellNNIterator<dim,CellList<dim,T,FAST,base>,CRS,impl> getNNIteratorCross(size_t cell)
{
CellNNIterator<dim,CellList<dim,T,FAST,base>,CRS,impl> cln(cell,NNc_cr,*this);
return cln;
}
};
......
......@@ -43,7 +43,7 @@ class CellList<dim,T,MEMORY,base>
SpaceBox<dim,T> box_unit;
// Grid structure of the Cell list
grid<dim,void> gr_cell;
grid_sm<dim,void> gr_cell;
public:
......
......@@ -6,23 +6,185 @@
*/
#include "CellList.hpp"
#include "Grid/grid.hpp"
#include "Grid/grid_sm.hpp"
#ifndef CELLLIST_TEST_HPP_
#define CELLLIST_TEST_HPP_
/*! \brief Test cell structure
*
* \tparam CellS
*
*/
template<unsigned int dim, typename T, typename CellS> void Test_cell_s()
{
//Space where is living the Cell list
SpaceBox<dim,T> box({0.0f,0.0f,0.0f},{1.0f,1.0f,1.0f});
// Subdivisions
size_t div[dim] = {16,16,16};
// grid info
grid_sm<dim,void> g_info(div);
// Origin
Point<dim,T> org({0.0,0.0,0.0});
// id Cell list
CellS cl1(box,div,org);
// Create a grid iterator
grid_key_dx_iterator<dim> g_it(g_info);
// Iterate through each element
// Add 1 element for each cell
// Usefull definition of points
Point<dim,T> end = box.getP2();
Point<dim,T> middle = end / div / 2.0;
Point<dim,T> spacing = end / div;
Point<dim,T> offset[dim] = {middle,middle,middle};
// Create offset shift vectors
for (int i = 0 ; i < dim ; i++)
{
offset[i].get(i) += (1.0 / div[i]) / 8.0;
}
size_t id = 0;
while (g_it.isNext())
{
// Add 2 particles on each cell
Point<dim,T> key = g_it.get();
key = key * spacing + offset[0];
cl1.add(key,id);
++id;
key = g_it.get();
key = key * spacing + offset[1];
cl1.add(key,id);
++id;
++g_it;
}
// check the cell are correctly filled
// reset iterator
g_it.reset();
while (g_it.isNext())
{
// Add 2 particles on each cell
Point<dim,T> key = g_it.get();
key = key * spacing + offset[2];
size_t cell = cl1.getCell(key);
size_t n_ele = cl1.getNelements(cell);
BOOST_REQUIRE_EQUAL(n_ele,2);
BOOST_REQUIRE_EQUAL(cl1.get(cell,1) - cl1.get(cell,0),1);
++g_it;
}
// reset itarator
g_it.reset();
// remove one particle from each cell
while (g_it.isNext())
{
// remove 1 particle on each cell
Point<dim,T> key = g_it.get();
key = key * spacing + offset[0];
auto cell = cl1.getCell(key);
// Remove the first particle in the cell
cl1.remove(cell,0);
++g_it;
}
// Check we have 1 object per cell
g_it.reset();
while (g_it.isNext())
{
// remove 1 particle on each cell
Point<dim,T> key = g_it.get();
key = key * spacing + offset[0];
auto cell = cl1.getCell(key);
size_t n_ele = cl1.getNelements(cell);
BOOST_REQUIRE_EQUAL(n_ele,1);
++g_it;
}
// Check the neighborhood iterator on the internal grid (They do not wotk on external grid)
// Check we have 1 object per cell
// Create a grid iterator
grid_key_dx<dim> p1(1,1,1);
grid_key_dx<dim> p2(div[0]-2,div[1]-2,div[2]-2);
grid_key_dx_iterator_sub<dim> g_it_s(g_info,p1,p2);
while (g_it_s.isNext())
{
// remove 1 particle on each cell
Point<dim,T> key = g_it_s.get();
key = key * spacing + offset[0];
auto NN = cl1.template getNNIterator<NO_CHECK>(cl1.getCell(key));
size_t total = 0;
while(NN.isNext())
{
size_t id = NN.get();
// total
total++;
++NN;
}
BOOST_REQUIRE_EQUAL(total,openfpm::math::pow(3,dim));
++g_it_s;
}
}
BOOST_AUTO_TEST_SUITE( CellList_test )
BOOST_AUTO_TEST_CASE( CellList_use)
{
std::cout << "Test cell list" << "\n";
Test_cell_s<3,double,CellList<3,double>>();
std::cout << "End cell list" << "\n";
//Space where is living the Cell list
SpaceBox<3,double> box({0.0f,0.0f,0.0f},{1.0f,1.0f,1.0f});
/* SpaceBox<3,double> box({0.0f,0.0f,0.0f},{1.0f,1.0f,1.0f});
// Subdivisions
size_t div[3] = {16,16,16};
// grid info
grid<3,void> g_info(div);
grid_sm<3,void> g_info(div);
// Origin
Point<3,double> org({0.0,0.0,0.0});
......@@ -57,13 +219,13 @@ BOOST_AUTO_TEST_CASE( CellList_use)
Point<3,double> key = g_it.get();
key = key * spacing + offset[0];
cl1.addElement(key,id);
cl1.add(key,id);
++id;
key = g_it.get();
key = key * spacing + offset[1];
cl1.addElement(key,id);
cl1.add(key,id);
++id;
++g_it;
......@@ -85,7 +247,7 @@ BOOST_AUTO_TEST_CASE( CellList_use)
size_t n_ele = cl1.getNelements(cell);
BOOST_REQUIRE_EQUAL(n_ele,2);
BOOST_REQUIRE_EQUAL(cl1.getElement(cell,1) - cl1.getElement(cell,0),1);
BOOST_REQUIRE_EQUAL(cl1.get(cell,1) - cl1.get(cell,0),1);
++g_it;
}
......@@ -127,19 +289,23 @@ BOOST_AUTO_TEST_CASE( CellList_use)
}
// Check the neighborhood iterator
// Check the neighborhood iterator on the internal grid (They do not wotk on external grid)
// Check we have 1 object per cell
g_it.reset();
while (g_it.isNext())
// Create a grid iterator
grid_key_dx<3> p1(1,1,1);
grid_key_dx<3> p2(div[0]-1,div[1]-1,div[2]-1);
grid_key_dx_iterator_sub<3> g_it_s(g_info,p1,p2);
while (g_it_s.isNext())
{
// remove 1 particle on each cell
Point<3,double> key = g_it.get();
Point<3,double> key = g_it_s.get();
key = key * spacing + offset[0];
auto NN = cl1.getNNIterator();
auto NN = cl1.template getNNIterator<NO_CHECK>(cl1.getCell(key));
size_t total = 0;
while(NN.isNext())
......@@ -153,9 +319,9 @@ BOOST_AUTO_TEST_CASE( CellList_use)
++NN;