Commit aeab66e0 authored by incardon's avatar incardon
Browse files

Several file movement and refactorization

parent 92aa87ad
......@@ -10,6 +10,7 @@
#include "Grid/iterators/grid_skin_iterator.hpp"
#include "Grid/map_grid.hpp"
#include "data_type/aggregate.hpp"
#include "Grid/iterators/grid_key_dx_iterator_sub_bc.hpp"
BOOST_AUTO_TEST_SUITE( grid_iterators_tests )
......@@ -217,5 +218,132 @@ BOOST_AUTO_TEST_CASE( grid_iterator_sub_stencil_test )
test_stencil_sub_iterator(g_sm);
}
BOOST_AUTO_TEST_CASE( grid_iterator_sub_bc )
{
{
size_t sz[] = {52,52,52};
grid_sm<3,void> g_sm(sz);
grid_key_dx<3> start({51,51,51});
grid_key_dx<3> stop({52,52,52});
size_t bc[3] = {PERIODIC,PERIODIC,PERIODIC};
grid_key_dx_iterator_sub_bc<3> it(g_sm,start,stop,bc);
bool is_ok = true;
size_t cnt = 0;
while (it.isNext())
{
auto p = it.get();
if ((p.get(0) != 51 && p.get(0) != 0) ||
(p.get(1) != 51 && p.get(1) != 0) ||
(p.get(2) != 51 && p.get(2) != 0))
{
is_ok = false;
}
cnt++;
++it;
}
BOOST_REQUIRE_EQUAL(is_ok,true);
BOOST_REQUIRE_EQUAL(cnt,8ul);
}
{
size_t sz[] = {52,52,52};
grid_sm<3,void> g_sm(sz);
grid_key_dx<3> start({-1,-1,-1});
grid_key_dx<3> stop({0,0,0});
size_t bc[3] = {PERIODIC,PERIODIC,PERIODIC};
grid_key_dx_iterator_sub_bc<3> it(g_sm,start,stop,bc);
bool is_ok = true;
size_t cnt = 0;
while (it.isNext())
{
auto p = it.get();
if ((p.get(0) != 51 && p.get(0) != 0) ||
(p.get(1) != 51 && p.get(1) != 0) ||
(p.get(2) != 51 && p.get(2) != 0))
{
is_ok = false;
}
cnt++;
++it;
}
BOOST_REQUIRE_EQUAL(is_ok,true);
BOOST_REQUIRE_EQUAL(cnt,8ul);
}
}
BOOST_AUTO_TEST_CASE( grid_iterator_sub_bc_hd )
{
grid_key_dx<50> start;
grid_key_dx<50> stop;
size_t sz[50];
size_t bc[50];
for (size_t i = 0 ; i < 50 ; i++)
{
sz[i] = 1;
start.set_d(i,0);
stop.set_d(i,0);
bc[i] = NON_PERIODIC;
}
sz[0] = 52;
sz[11] = 52;
sz[23] = 52;
bc[0] = PERIODIC;
bc[11] = PERIODIC;
bc[23] = PERIODIC;
start.set_d(0,51);
start.set_d(11,51);
start.set_d(23,51);
stop.set_d(0,52);
stop.set_d(11,52);
stop.set_d(23,52);
grid_sm<50,void> g_sm(sz);
grid_key_dx_iterator_sub_bc<50> it(g_sm,start,stop,bc);
bool is_ok = true;
size_t cnt = 0;
while (it.isNext())
{
auto p = it.get();
if ((p.get(0) != 51 && p.get(0) != 0) ||
(p.get(11) != 51 && p.get(11) != 0) ||
(p.get(23) != 51 && p.get(23) != 0))
{
is_ok = false;
}
cnt++;
++it;
}
BOOST_REQUIRE_EQUAL(is_ok,true);
BOOST_REQUIRE_EQUAL(cnt,8);
}
BOOST_AUTO_TEST_SUITE_END()
......@@ -120,7 +120,7 @@ public:
// copy the boundary conditions
for (size_t i = 0 ; i < dim ; i++)
this->bc[i] = bc[i];
{this->bc[i] = bc[i];}
// compile-time array {0,0,0,....} {2,2,2,...} {1,1,1,...}
......@@ -128,10 +128,25 @@ public:
typedef typename generate_array<size_t,dim, Fill_two>::result NNtwo;
typedef typename generate_array<size_t,dim, Fill_three>::result NNthree;
// In case of high dimension grid_key_dx_iterator_sub can become exponentially
// expensive, on the other hand we are expecting that some of the dimensions
// are cropped by non periodicity, so we adjust the iteration
size_t end_p[dim];
size_t start_p[dim];
for (size_t i = 0 ; i < dim ; i++)
{
if (this->bc[i] == NON_PERIODIC && g.size(i) == 1)
{start_p[i] = 1; end_p[i] = 1;}
else
{start_p[i] = 0; end_p[i] = 2;}
}
// Generate the sub-grid iterator
grid_sm<dim,void> nn(NNthree::data);
grid_key_dx_iterator_sub<dim,stencil> it(nn,NNzero::data,NNtwo::data);
grid_key_dx_iterator_sub<dim,stencil> it(nn,start_p,end_p);
// Box base
Box<dim,long int> base_b(start,stop);
......@@ -202,7 +217,7 @@ public:
{
act++;
if (act < boxes.size())
grid_key_dx_iterator_sub<dim,stencil,warn>::reinitialize(grid_key_dx_iterator_sub<dim>(this->getGridInfo(),boxes[act].getKP1(),boxes[act].getKP2()));
{grid_key_dx_iterator_sub<dim,stencil,warn>::reinitialize(grid_key_dx_iterator_sub<dim>(this->getGridInfo(),boxes[act].getKP1(),boxes[act].getKP2()));}
}
return *this;
......
......@@ -125,7 +125,7 @@ public:
* \param mem memory object (only used for template deduction)
*
*/
inline grid_cpu(const grid_cpu & g) THROW
inline grid_cpu(const grid_cpu<dim,T,S,typename memory_traits_lin<T>::type> & g) THROW
:grid_base_impl<dim,T,S,layout,memory_traits_lin>(g)
{
}
......
......@@ -8,7 +8,7 @@ else
endif
noinst_PROGRAMS = mem_map
mem_map_SOURCES = ../../openfpm_devices/src/Memleak_check.cpp main.cpp Grid/copy_grid_unit_test.cpp NN/Mem_type/Mem_type_unit_tests.cpp $(CUDA_SOURCES) ../../openfpm_devices/src/memory/HeapMemory.cpp ../../openfpm_devices/src/memory/PtrMemory.cpp
mem_map_SOURCES = ../../openfpm_devices/src/Memleak_check.cpp main.cpp Space/tests/SpaceBox_unit_tests.cpp Grid/copy_grid_unit_test.cpp NN/Mem_type/Mem_type_unit_tests.cpp $(CUDA_SOURCES) ../../openfpm_devices/src/memory/HeapMemory.cpp ../../openfpm_devices/src/memory/PtrMemory.cpp
mem_map_CXXFLAGS = $(AM_CXXFLAGS) $(LIBHILBERT_INCLUDE) $(CUDA_CFLAGS) $(INCLUDES_PATH) $(BOOST_CPPFLAGS) -I/usr/local/include -I/usr/local/libhilbert/include
mem_map_CFLAGS = $(CUDA_CFLAGS)
mem_map_LDADD = $(LINKLIBS)
......@@ -21,7 +21,7 @@ Point_test.hpp \
Point_orig.hpp \
memory_ly/memory_array.hpp memory_ly/memory_c.hpp memory_ly/memory_conf.hpp memory_ly/t_to_memory_c.hpp \
NN/Mem_type/MemBalanced.hpp NN/Mem_type/MemFast.hpp NN/Mem_type/MemMemoryWise.hpp NN/CellList/CellNNIteratorRuntime.hpp NN/CellList/NNc_array.hpp NN/CellList/ParticleItCRS_Cells.hpp NN/CellList/ParticleIt_Cells.hpp NN/CellList/CellDecomposer.hpp NN/VerletList/VerletList.hpp NN/VerletList/VerletListFast.hpp NN/VerletList/VerletNNIterator.hpp NN/CellList/CellListNNIteratorRadius.hpp NN/CellList/CellListIterator.hpp NN/CellList/CellListM.hpp NN/CellList/CellNNIteratorM.hpp NN/CellList/CellList.hpp NN/CellList/CellList_test.hpp NN/CellList/CellListFast_gen.hpp NN/CellList/CellNNIterator.hpp NN/CellList/ProcKeys.hpp \
Space/Ghost.hpp Space/Matrix.hpp Space/SpaceBox.hpp Space/SpaceBox_unit_tests.hpp \
Space/Ghost.hpp Space/Matrix.hpp Space/SpaceBox.hpp \
Space/Shape/AdaptiveCylinderCone.hpp Space/Shape/Box.hpp Space/Shape/Box_unit_tests.hpp Space/Shape/HyperCube.hpp Space/Shape/HyperCube_unit_test.hpp Space/Shape/Point.hpp Space/Shape/Point_unit_test.hpp Space/Shape/Point_operators_functions.hpp Space/Shape/Point_operators.hpp Space/Shape/Sphere.hpp \
util/check_no_pointers.hpp util/common.hpp util/convert.hpp util/create_vmpl_sequence.hpp util/ct_array.hpp util/for_each_ref.hpp util/mathutil.hpp util/object_creator.hpp util/object_s_di.hpp util/object_si_d.hpp util/object_util.hpp util/util_debug.hpp util/util_test.hpp util/variadic_to_vmpl.hpp util/variadic_to_vmpl_unit_test.hpp util/Pack_stat.hpp \
NN/CellList/CellList_util.hpp NN/CellList/CellNNIteratorRuntimeM.hpp NN/VerletList/VerletListM.hpp NN/VerletList/VerletNNIteratorM.hpp Vector/map_vector.hpp Vector/vector_def.hpp Vector/map_vector_std_util.hpp Vector/map_vector_std_ptr.hpp Vector/map_vector_std.hpp Vector/util.hpp Vector/vect_isel.hpp Vector/vector_test_util.hpp Vector/vector_unit_tests.hpp Vector/se_vector.hpp Vector/map_vector_grow_p.hpp Vector/vector_std_pack_unpack.ipp Vector/vector_pack_unpack.ipp Vector/vector_map_iterator.hpp \
......
......@@ -9,7 +9,7 @@
#define OPENFPM_DATA_SRC_NN_CELLLIST_CELLLISTM_HPP_
#include "CellNNIteratorM.hpp"
#include "CellList.hpp"
struct PV_cl
{
......
......@@ -11,6 +11,8 @@
#define CL_SYMMETRIC 1
#define CL_NON_SYMMETRIC 2
#include "Vector/map_vector.hpp"
/*! \brief populate the Cell-list with particles non symmetric case
*
* \tparam dim dimensionality of the space
......
......@@ -12,6 +12,7 @@
#include "util/mathutil.hpp"
#include <boost/integer/integer_mask.hpp>
#include "CellList_util.hpp"
#include "CellNNIterator.hpp"
/*! \brief Iterator for the neighborhood of the cell structures
*
......
......@@ -170,14 +170,23 @@ public:
/* \brief NNc_array
*
* \param size
* It encapsulate a 3^{dim} array containing the neighborhood cells-id
*
* \tparam dim dimensionality
* \tparam size total number of neighborhood cells
*
*/
template<unsigned int dim, unsigned int size>
class NNc_array<dim,size,false>
{
//! NNc_array is a grid in general 3^{dim}, this object contain the information
//! about this grid
grid_sm<dim,void> gs;
//! Information about the grid in the reduced space
grid_sm<dim,void> gs_base;
//!
size_t sub_off;
size_t sym_mid;
......
......@@ -109,7 +109,7 @@ public:
/*! \brief Remove an element from the cell
*
* \param cell_id id of the cell
* \param cell id of the cell
* \param ele element to remove
*
*/
......@@ -168,7 +168,7 @@ public:
/*! \brief Swap two Mem_bal
*
* \param cl element to swap with
* \param cell element to swap with
*
*/
inline void swap(Mem_bal && cell)
......@@ -186,6 +186,11 @@ public:
cl_base.get(i).clear();
}
/*! \brief Get the start index of the selected element
*
* \param part_id element
*
*/
inline const local_index & getStartId(local_index part_id) const
{
if (cl_base.get(part_id).size() == 0)
......@@ -194,6 +199,11 @@ public:
return cl_base.get(part_id).get(0);
}
/*! \brief Get the stop index of the selected element
*
* \param part_id element
*
*/
inline const local_index & getStopId(local_index part_id) const
{
if (cl_base.get(part_id).size() == 0)
......@@ -202,6 +212,15 @@ public:
return *(&cl_base.get(part_id).last() + 1);
}
/*! \brief get_lin
*
* It just return the element pointed by part_id
*
* \param part_id element
*
* \return the element pointed
*
*/
inline const local_index & get_lin(const local_index * part_id) const
{
return *part_id;
......
......@@ -16,9 +16,6 @@
#define VERLET_STARTING_NSLOT 128
#define VL_NON_SYMMETRIC 0
#define VL_SYMMETRIC 1
#define VL_CRS_SYMMETRIC 2
#define WITH_RADIUS 3
......
......@@ -9,7 +9,7 @@
#define OPENFPM_DATA_SRC_NN_VERLETLIST_VERLETLISTM_HPP_
#include "NN/VerletList/VerletNNIteratorM.hpp"
#include "VerletList.hpp"
/*! \brief Get the neighborhood iterator based on type
......
......@@ -12,6 +12,10 @@
#define NO_CHECK 1
#define SAFE 2
#define VL_NON_SYMMETRIC 0
#define VL_SYMMETRIC 1
#define VL_CRS_SYMMETRIC 2
/*! \brief Iterator for the neighborhood of the cell structures
*
* In general you never create it directly but you get it from the CellList structures
......
......@@ -8,6 +8,7 @@
#ifndef OPENFPM_DATA_SRC_NN_VERLETLIST_VERLETNNITERATORM_HPP_
#define OPENFPM_DATA_SRC_NN_VERLETLIST_VERLETNNITERATORM_HPP_
#include "VerletNNIterator.hpp"
/*! \brief Iterator for the neighborhood of the cell structures
*
......
......@@ -14,6 +14,7 @@
#include "Vector/map_vector_grow_p.hpp"
#include "Vector/vect_isel.hpp"
#include "memory_ly/memory_conf.hpp"
#include "util/Pack_stat.hpp"
template<typename T, typename Mem, int pack_type=Pack_selector<T>::value > class Packer;
template<typename T, typename Mem, int pack_type=Pack_selector<T>::value > class Unpacker;
......
......@@ -8,6 +8,8 @@
#ifndef OPENFPM_DATA_SRC_PACKER_UNPACKER_PRP_ALL_ZERO_HPP_
#define OPENFPM_DATA_SRC_PACKER_UNPACKER_PRP_ALL_ZERO_HPP_
#include "util/variadic_to_vmpl.hpp"
//! Structure to convert a variadic template into boost::mpl::vector
template<typename T, bool is_zero, int ... prp>
struct prp_all_zero
......
......@@ -141,6 +141,75 @@ public:
return v;
}
/*! brief Calculate the position (combinations) of all the elements of size d
*
* \param d dimensionality of the object returned in the combinations
* \return all the combinations
*
*/
static std::vector<comb<dim>> getCombinations_R_bc(size_t d, const size_t (& bc)[dim])
{
#ifdef SE_CLASS1
if (d > dim)
std::cerr << "Error: " << __FILE__ << ":" << __LINE__ << " " << d << " must be smaller than " << "\n";
#endif
size_t dg[dim];
size_t k = 0;
// get the indexes of the free degree of freedom
for (size_t i = 0 ; i < dim ; i++)
{
if (bc[i] == PERIODIC)
{
dg[k] = i;
k++;
}
}
// Create an Iterator_g_const
// And a vector that store all the combination
std::vector<comb<dim>> v;
Iterator_g_const it(k-(d-(dim - k)),k);
// for each non-zero elements
// basically the key will store the position of the
// non zero elements, while BinPermutations will
// fill the array of all the permutations
//
while (it.isNext())
{
grid_key_dx_r key = it.get();
// Now we adjust the non zero position
for (size_t i = 0 ; i < key.getDim() ; i++)
{key.set_d(i,dg[key.get(i)]);}
// Calculate the permutation
BinPermutations(key,v);
++it;
}
// case when d == dim
if (d == dim)
{
comb<dim> c;
c.zero();
v.push_back(c);
}
// return the combinations
return v;
}
/*! \brief Binary permutations
*
* Fill v with all the possible binary permutations
......
......@@ -486,6 +486,132 @@ BOOST_AUTO_TEST_CASE( Hyper_cube_use)
BOOST_REQUIRE_EQUAL(isSubdecomposition(combs,sc3_2[i]),true);
}
// High dimension test
size_t bc[50];
for (size_t i = 0 ; i < 50 ; i++)
{bc[i] = NON_PERIODIC;}
bc[0] = PERIODIC;
bc[11] = PERIODIC;
bc[17] = PERIODIC;
std::vector<comb<50>> sc50_2 = HyperCube<50>::getCombinations_R_bc(49,bc);
BOOST_REQUIRE_EQUAL(sc50_2.size(),6ul);
BOOST_REQUIRE_EQUAL(sc50_2[0].c[0],1);
BOOST_REQUIRE_EQUAL(sc50_2[0].c[11],0);
BOOST_REQUIRE_EQUAL(sc50_2[0].c[17],0);
BOOST_REQUIRE_EQUAL(sc50_2[1].c[0],-1);
BOOST_REQUIRE_EQUAL(sc50_2[1].c[11],0);
BOOST_REQUIRE_EQUAL(sc50_2[1].c[17],0);
BOOST_REQUIRE_EQUAL(sc50_2[2].c[0],0);
BOOST_REQUIRE_EQUAL(sc50_2[2].c[11],1);
BOOST_REQUIRE_EQUAL(sc50_2[2].c[17],0);
BOOST_REQUIRE_EQUAL(sc50_2[3].c[0],0);
BOOST_REQUIRE_EQUAL(sc50_2[3].c[11],-1);
BOOST_REQUIRE_EQUAL(sc50_2[3].c[17],0);
BOOST_REQUIRE_EQUAL(sc50_2[4].c[0],0);
BOOST_REQUIRE_EQUAL(sc50_2[4].c[11],0);
BOOST_REQUIRE_EQUAL(sc50_2[4].c[17],1);
BOOST_REQUIRE_EQUAL(sc50_2[5].c[0],0);
BOOST_REQUIRE_EQUAL(sc50_2[5].c[11],0);
BOOST_REQUIRE_EQUAL(sc50_2[5].c[17],-1);
std::vector<comb<50>> sc50_3 = HyperCube<50>::getCombinations_R_bc(48,bc);
BOOST_REQUIRE_EQUAL(sc50_3.size(),12ul);
BOOST_REQUIRE_EQUAL(sc50_3[0].c[0],1);
BOOST_REQUIRE_EQUAL(sc50_3[0].c[11],1);
BOOST_REQUIRE_EQUAL(sc50_3[0].c[17],0);
BOOST_REQUIRE_EQUAL(sc50_3[1].c[0],1);
BOOST_REQUIRE_EQUAL(sc50_3[1].c[11],-1);
BOOST_REQUIRE_EQUAL(sc50_3[1].c[17],0);
BOOST_REQUIRE_EQUAL(sc50_3[2].c[0],-1);
BOOST_REQUIRE_EQUAL(sc50_3[2].c[11],1);
BOOST_REQUIRE_EQUAL(sc50_3[2].c[17],0);
BOOST_REQUIRE_EQUAL(sc50_3[3].c[0],-1);
BOOST_REQUIRE_EQUAL(sc50_3[3].c[11],-1);
BOOST_REQUIRE_EQUAL(sc50_3[3].c[17],0);
BOOST_REQUIRE_EQUAL(sc50_3[4].c[0],1);
BOOST_REQUIRE_EQUAL(sc50_3[4].c[11],0);
BOOST_REQUIRE_EQUAL(sc50_3[4].c[17],1);
BOOST_REQUIRE_EQUAL(sc50_3[5].c[0],1);
BOOST_REQUIRE_EQUAL(sc50_3[5].c[11],0);
BOOST_REQUIRE_EQUAL(sc50_3[5].c[17],-1);
BOOST_REQUIRE_EQUAL(sc50_3[6].c[0],-1);
BOOST_REQUIRE_EQUAL(sc50_3[6].c[11],0);
BOOST_REQUIRE_EQUAL(sc50_3[6].c[17],1);
BOOST_REQUIRE_EQUAL(sc50_3[7].c[0],-1);
BOOST_REQUIRE_EQUAL(sc50_3[7].c[11],0);
BOOST_REQUIRE_EQUAL(sc50_3[7].c[17],-1);
BOOST_REQUIRE_EQUAL(sc50_3[8].c[0],0);
BOOST_REQUIRE_EQUAL(sc50_3[8].c[11],1);
BOOST_REQUIRE_EQUAL(sc50_3[8].c[17],1);
BOOST_REQUIRE_EQUAL(sc50_3[9].c[0],0);
BOOST_REQUIRE_EQUAL(sc50_3[9].c[11],1);
BOOST_REQUIRE_EQUAL(sc50_3[9].c[17],-1);
BOOST_REQUIRE_EQUAL(sc50_3[10].c[0],0);
BOOST_REQUIRE_EQUAL(sc50_3[10].c[11],-1);
BOOST_REQUIRE_EQUAL(sc50_3[10].c[17],1);
BOOST_REQUIRE_EQUAL(sc50_3[11].c[0],0);
BOOST_REQUIRE_EQUAL(sc50_3[11].c[11],-1);
BOOST_REQUIRE_EQUAL(sc50_3[11].c[17],-1);
std::vector<comb<50>> sc50_4 = HyperCube<50>::getCombinations_R_bc(47,bc);
BOOST_REQUIRE_EQUAL(sc50_4.size(),8ul);
BOOST_REQUIRE_EQUAL(sc50_4[0].c[0],1);
BOOST_REQUIRE_EQUAL(sc50_4[0].c[11],1);
BOOST_REQUIRE_EQUAL(sc50_4[0].c[17],1);
BOOST_REQUIRE_EQUAL(sc50_4[1].c[0],1);
BOOST_REQUIRE_EQUAL(sc50_4[1].c[11],1);
BOOST_REQUIRE_EQUAL(sc50_4[1].c[17],-1);
BOOST_REQUIRE_EQUAL(sc50_4[2].c[0],1);
BOOST_REQUIRE_EQUAL(sc50_4[2].c[11],-1);
BOOST_REQUIRE_EQUAL(sc50_4[2].c[17],1);
BOOST_REQUIRE_EQUAL(sc50_4[3].c[0],1);
BOOST_REQUIRE_EQUAL(sc50_4[3].c[11],-1);
BOOST_REQUIRE_EQUAL(sc50_4[3].c[17],-1);
BOOST_REQUIRE_EQUAL(sc50_4[4].c[0],-1);
BOOST_REQUIRE_EQUAL(sc50_4[4].c[11],1);
BOOST_REQUIRE_EQUAL(sc50_4[4].c[17],1);
BOOST_REQUIRE_EQUAL(sc50_4[5].c[0],-1);
BOOST_REQUIRE_EQUAL(sc50_4[5].c[11],1);
BOOST_REQUIRE_EQUAL(sc50_4[5].c[17],-1);
BOOST_REQUIRE_EQUAL(sc50_4[6].c[0],-1);
BOOST_REQUIRE_EQUAL(sc50_4[6].c[11],-1);
BOOST_REQUIRE_EQUAL(sc50_4[6].c[17],1);
BOOST_REQUIRE_EQUAL(sc50_4[7].c[0],-1);
BOOST_REQUIRE_EQUAL(sc50_4[7].c[11],-1);
BOOST_REQUIRE_EQUAL(sc50_4[7].c[17],-1);
std::cout << "Hyper-cube unit test end" << "\n";
}
......