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

AR list foundation runs and fails more or less successfully.

parent d978b303
......@@ -8,6 +8,17 @@
#ifndef ADAPTIVECELLLIST_HPP_
#define ADAPTIVECELLLIST_HPP_
#include "../CellList/CellList.hpp"
#include "../CellList/CellDecomposer.hpp"
#include "AdaptiveCellListNNIterator.hpp"
#include "Space/SpaceBox.hpp"
// Stub implementation
template<unsigned int dim, typename T, unsigned int impl=BALANCED, typename base=openfpm::vector<size_t>>
class AdaptiveCellList
{
};
/*! \brief Class for Adaptive cell list implementation
*
......@@ -19,9 +30,39 @@
*
*/
template<unsigned int dim, typename T, typename base>
class AdaptiveCellList<dim,T,FAST,base> : public CellDecomposer_sm<dim,T>
class AdaptiveCellList<dim,T,BALANCED,base> : public CellDecomposer_sm<dim,T>
{
// In case you have to store something consider the possibility to re-use openfpm structures
// 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)];
// Number of slot for each cell
size_t slot;
// number of particle in each cell list
openfpm::vector<size_t> cl_n;
// elements that each cell store (each cell can store a number
// of elements == slot )
base cl_base;
//A point
Point<dim,T> orig;
......@@ -31,13 +72,18 @@ public:
// Object type that the structure store
typedef T value_type;
/*! Initialize the adaptive cell list
/*! Initialize the cell list
*
* \param ...
* \param box Domain where this cell list is living
* \param origin of the Cell list
* \param div grid size on each dimension
*
*/
void Initialize(/* Initialize the structure */)
void Initialize(SpaceBox<dim,T> & sbox, size_t (&div)[dim], Point<dim,T> & orig, size_t slot=16)
{
CellDecomposer_sm<dim,T>::setDimensions(sbox,div);
this->slot = slot;
this->orig = orig;
}
/*! \brief Default constructor
......@@ -92,11 +138,13 @@ public:
/*! \brief remove an element from the cell
*
* \param ...
* \param cell cell id
* \param ele element id
*
*/
inline void remove(/* Arguments */)
inline void remove(size_t cell, size_t ele)
{
// i could change params later on
}
/*! \brief Return the number of element in the cell
......@@ -144,7 +192,7 @@ public:
* \param cl Cell list with witch you swap the memory
*
*/
inline void swap(AdaptiveCellList<dim,T,FAST,base> & cl)
inline void swap(AdaptiveCellList<dim,T,BALANCED,base> & cl)
{
cl_n.swap(cl.cl_n);
cl_base.swap(cl.cl_base);
......@@ -155,23 +203,23 @@ public:
* \param cell cell id
*
*/
template<unsigned int impl> inline AdaptiveCellNNIterator getNNIterator(size_t cell)
template<unsigned int impl> inline AdaptiveCellNNIterator<dim,AdaptiveCellList<dim,T,BALANCED,base>,FULL,impl> getNNIterator(size_t cell)
{
AdaptiveCellNNIterator<dim,CellList<dim,T,FAST,base>,FULL,impl> cln(cell,NNc_full,*this);
AdaptiveCellNNIterator<dim,AdaptiveCellList<dim,T,BALANCED,base>,FULL,impl> cln(cell,NNc_full,*this);
return cln;
}
template<unsigned int impl> inline AdaptiveCellNNIterator getNNIteratorSym(size_t cell)
template<unsigned int impl> inline AdaptiveCellNNIterator<dim,AdaptiveCellList<dim,T,BALANCED,base>,SYM,impl> getNNIteratorSym(size_t cell)
{
AdaptiveCellNNIterator<dim,CellList<dim,T,FAST,base>,SYM,impl> cln(cell,NNc_sym,*this);
AdaptiveCellNNIterator<dim,AdaptiveCellList<dim,T,BALANCED,base>,SYM,impl> cln(cell,NNc_sym,*this);
return cln;
}
template<unsigned int impl> inline AdaptiveCellNNIterator getNNIteratorCross(size_t cell)
template<unsigned int impl> inline AdaptiveCellNNIterator<dim,AdaptiveCellList<dim,T,BALANCED,base>,CRS,impl> getNNIteratorCross(size_t cell)
{
AdaptiveCellNNIterator<dim,CellList<dim,T,FAST,base>,CRS,impl> cln(cell,NNc_cr,*this);
AdaptiveCellNNIterator<dim,AdaptiveCellList<dim,T,BALANCED,base>,CRS,impl> cln(cell,NNc_cr,*this);
return cln;
}
......
......@@ -9,7 +9,7 @@
#define ADAPTIVECELLLISTNNITERATOR_HPP_
template<typename Cell> class AdaptiveCellNNIterator
template<unsigned int dim, typename CellS, unsigned int NNc_size, unsigned int impl> class AdaptiveCellNNIterator
{
public:
......@@ -25,6 +25,18 @@ public:
AdaptiveCellNNIterator()
{
}
/*! \brief
*
* Cell NN iterator
*
* \param Cell id
* \param NNc Cell NN id
*
*/
AdaptiveCellNNIterator(size_t cell, long int (&NNc)[NNc_size], CellS & cl)
{
}
/*! \brief
*
......@@ -50,7 +62,7 @@ public:
* \return the actual element
*
*/
typename Cell::value_type & get()
typename CellS::value_type & get()
{
}
};
......
......@@ -8,15 +8,181 @@
#ifndef ADAPTIVECELLLIST_TEST_HPP_
#define ADAPTIVECELLLIST_TEST_HPP_
#include "AdaptiveCellList.hpp"
#include "Grid/grid_sm.hpp"
BOOST_AUTO_TEST_SUITE( AdaptiveCellList_test )
BOOST_AUTO_TEST_CASE( AdaptiveCellList_use)
template<unsigned int dim>
Point<dim+1,double> giveRadius(Point<dim,double> const & p)
{
// Test case for your class
Point<dim+1, double> p_;
for(unsigned int i=0; i<dim; ++i) p_.get(i) = p.get(i);
p_[dim] = 0.5;
return p_;
}
//
/*! \brief Test cell structure
*
* \tparam CellS
*
*/
template<unsigned int dim, typename T, typename CellS> void Test_ar_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
// particle one
Point<dim,T> key = g_it.get();
key = key * spacing + offset[0];
cl1.add(giveRadius(key),id);
++id;
// particle two
key = g_it.get();
key = key * spacing + offset[1];
cl1.add(giveRadius(key),id);
++id;
++g_it;
}
// check the cells 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())
{
// total
total++;
++NN;
}
BOOST_REQUIRE_EQUAL(total,openfpm::math::pow(3,dim));
++g_it_s;
}
}
BOOST_AUTO_TEST_SUITE( AdaptiveCellList_test )
BOOST_AUTO_TEST_CASE( AdaptiveCellList_use)
{
std::cout << "Now testing the AR-List..." << std::endl;
Test_ar_cell_s<3, double, AdaptiveCellList<3, double>>();
std::cout << "Done testing the AR-List." << std::endl;
}
BOOST_AUTO_TEST_CASE( AdaptiveCellList_another_test)
......
......@@ -19,10 +19,10 @@
// Include tests
#include "NN/CellList/CellList_test.hpp"
//#include "NN/CellList/CellList_test.hpp"
#include "NN/AdaptiveCellList/AdaptiveCellList_test.hpp"
#include "Vector/vector_unit_tests.hpp"
#include "hypercube_unit_test.hpp"
#include "Graph/graph_unit_tests.hpp"
#include "Grid/grid_unit_tests.hpp"
//#include "Vector/vector_unit_tests.hpp"
//#include "hypercube_unit_test.hpp"
//#include "Graph/graph_unit_tests.hpp"
//#include "Grid/grid_unit_tests.hpp"
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