Commit b6254c61 authored by incardon's avatar incardon

Adding CRS example

parent bd5d64d2
......@@ -9,6 +9,7 @@
* \subpage Vector_4_cp
* \subpage Vector_4_mp_cl
* \subpage Vector_5_md_vl_sym
* \subpage Vector_5_md_vl_sym_crs
* \subpage Vector_6_complex_usage
*
*/
......
include ../../example.mk
CC=mpic++
LDIR =
OBJ_DORD = main.o
all: md_sym
%.o: %.cpp
$(CC) -O3 -g -c --std=c++11 $(OPT) -o $@ $< $(INCLUDE_PATH)
md_sym: $(OBJ_DORD)
$(CC) -o $@ $^ $(CFLAGS) $(LIBS_PATH) $(LIBS)
run: md_sym
mpirun -np 3 ./md_sym
.PHONY: clean all run
clean:
rm -f *.o *~ core md_sym
This diff is collapsed.
openfpm_data @ 7e326c01
Subproject commit 155cc3537485efb4993a667330a01a7d2644449a
Subproject commit 7e326c0134dedecc6cf06dfb9e3a466e66280300
......@@ -38,7 +38,7 @@ PROJECT_NAME = "OpenFPM_pdata"
# could be handy for archiving the generated documentation or if some version
# control system is used.
PROJECT_NUMBER = 0.6.0
PROJECT_NUMBER = 0.7.0
# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
......
......@@ -623,7 +623,7 @@ public:
aBC=true;
return add_box_periodic(domain,ghost,bc);
add_box_periodic(domain,ghost,bc);
}
/*! \brief Check if the nn_prcs contain the same information
......
......@@ -6,7 +6,7 @@ pdata_CXXFLAGS = $(OPENMP_CFLAGS) $(AM_CXXFLAGS) $(LIBHILBERT_INCLUDE) $(PETSC_I
pdata_CFLAGS = $(CUDA_CFLAGS)
pdata_LDADD = $(LINKLIBS) -lparmetis -lmetis
nobase_include_HEADERS = Decomposition/CartDecomposition.hpp Decomposition/CartDecomposition_ext.hpp Decomposition/common.hpp Decomposition/Decomposition.hpp Decomposition/ie_ghost.hpp \
Decomposition/nn_processor.hpp Decomposition/ie_loc_ghost.hpp Decomposition/ORB.hpp \
Decomposition/Domain_NN_calculator_cart.hpp Decomposition/nn_processor.hpp Decomposition/ie_loc_ghost.hpp Decomposition/ORB.hpp \
Graph/CartesianGraphFactory.hpp \
Grid/grid_dist_id.hpp Grid/grid_dist_id_iterator_dec.hpp Grid/grid_dist_util.hpp Grid/grid_dist_id_iterator_sub.hpp Grid/grid_dist_id_iterator.hpp Grid/grid_dist_key.hpp Grid/staggered_dist_grid.hpp Grid/staggered_dist_grid_util.hpp Grid/staggered_dist_grid_copy.hpp \
Vector/vector_dist_multiphase_functions.hpp Vector/vector_dist_comm.hpp Vector/vector_dist.hpp Vector/vector_dist_ofb.hpp Vector/vector_dist_iterator.hpp Vector/vector_dist_key.hpp \
......
......@@ -548,6 +548,43 @@ public:
return ver;
}
/*! \brief for each particle get the symmetric verlet list
*
* \param r_cut cut-off radius
*
* \return the verlet list
*
*/
VerletList<dim,St,FAST,shift<dim,St> > getVerletCrs(St r_cut)
{
VerletList<dim,St,FAST,shift<dim,St>> ver;
// Processor bounding box
Box<dim, St> pbox = getDecomposition().getProcessorBounds();
// Initialize the verlet list
ver.InitializeCrs(getDecomposition().getDomain(),pbox,getDecomposition().getGhost(),r_cut,v_pos,g_m);
// Get the internal cell list
auto & NN = ver.getInternalCellList();
// Shift
grid_key_dx<dim> cell_shift = NN.getShift();
// Shift
grid_key_dx<dim> shift = NN.getShift();
// Add padding
for (size_t i = 0 ; i < dim ; i++)
shift.set_d(i,shift.get(i) + NN.getPadding(i));
grid_sm<dim,void> gs = NN.getInternalGrid();
ver.createVerletCrs(r_cut,g_m,v_pos,getDecomposition().getDomainCells(shift,cell_shift,gs),getDecomposition().getAnomDomainCells(shift,cell_shift,gs));
return ver;
}
/*! \brief for each particle get the verlet list
*
* \param r_cut cut-off radius
......@@ -584,7 +621,27 @@ public:
*/
void updateVerlet(VerletList<dim,St,FAST,shift<dim,St> > & ver, St r_cut, size_t opt = VL_NON_SYMMETRIC)
{
ver.update(getDecomposition().getDomain(),r_cut,v_pos,g_m, opt);
if (opt == VL_CRS_SYMMETRIC)
{
// Get the internal cell list
auto & NN = ver.getInternalCellList();
// Shift
grid_key_dx<dim> cell_shift = NN.getShift();
// Shift
grid_key_dx<dim> shift = NN.getShift();
// Add padding
for (size_t i = 0 ; i < dim ; i++)
shift.set_d(i,shift.get(i) + NN.getPadding(i));
grid_sm<dim,void> gs = NN.getInternalGrid();
ver.updateCrs(getDecomposition().getDomain(),r_cut,v_pos,g_m,getDecomposition().getDomainCells(shift,cell_shift,gs),getDecomposition().getAnomDomainCells(shift,cell_shift,gs));
}
else
ver.update(getDecomposition().getDomain(),r_cut,v_pos,g_m, opt);
}
/*! \brief for each particle get the verlet list
......
......@@ -564,6 +564,10 @@ BOOST_AUTO_TEST_CASE( vector_dist_symmetric_crs_cell_list )
// ghost
Ghost<3,float> ghost(r_cut);
Ghost<3,float> ghost2(r_cut);
ghost2.setLow(0,0.0);
ghost2.setLow(1,0.0);
ghost2.setLow(2,0.0);
// Point and global id
struct point_and_gid
......@@ -581,6 +585,7 @@ BOOST_AUTO_TEST_CASE( vector_dist_symmetric_crs_cell_list )
// Distributed vector
vector_dist<3,float, part_prop > vd(k,box,bc,ghost,BIND_DEC_TO_GHOST);
vector_dist<3,float, part_prop > vd2(k,box,bc,ghost2,BIND_DEC_TO_GHOST);
size_t start = vd.init_size_accum(k);
auto it = vd.getIterator();
......@@ -593,19 +598,32 @@ BOOST_AUTO_TEST_CASE( vector_dist_symmetric_crs_cell_list )
vd.getPos(key)[1] = ud(eg);
vd.getPos(key)[2] = ud(eg);
vd2.getPos(key)[0] = vd.getPos(key)[0];
vd2.getPos(key)[1] = vd.getPos(key)[1];
vd2.getPos(key)[2] = vd.getPos(key)[2];
// Fill some properties randomly
vd.getProp<0>(key) = 0;
vd.getProp<1>(key) = 0;
vd.getProp<2>(key) = key.getKey() + start;
vd2.getProp<0>(key) = 0;
vd2.getProp<1>(key) = 0;
vd2.getProp<2>(key) = key.getKey() + start;
++it;
}
vd.map();
vd2.map();
// sync the ghost
vd.ghost_get<0,2>();
vd2.ghost_get<0,2>();
vd2.write("CRS_output");
vd2.getDecomposition().write("CRS_output_dec");
auto NN = vd.getCellList(r_cut);
auto p_it = vd.getDomainIterator();
......@@ -653,20 +671,20 @@ BOOST_AUTO_TEST_CASE( vector_dist_symmetric_crs_cell_list )
// We now try symmetric Cell-list
auto NN2 = vd.getCellListSym(r_cut);
auto NN2 = vd2.getCellListSym(r_cut);
// In case of CRS we have to iterate particles within some cells
// here we define whichone
auto p_it2 = vd.getParticleIteratorCRS(NN2);
auto p_it2 = vd2.getParticleIteratorCRS(NN2);
// For each particle
while (p_it2.isNext())
{
auto p = p_it2.get();
Point<3,float> xp = vd.getPos(p);
Point<3,float> xp = vd2.getPos(p);
auto Np = p_it2.getNNIteratorCSR(vd.getPosVector());
auto Np = p_it2.getNNIteratorCSR(vd2.getPosVector());
while (Np.isNext())
{
......@@ -680,7 +698,7 @@ BOOST_AUTO_TEST_CASE( vector_dist_symmetric_crs_cell_list )
// repulsive
Point<3,float> xq = vd.getPos(q);
Point<3,float> xq = vd2.getPos(q);
Point<3,float> f = (xp - xq);
float distance = f.norm();
......@@ -689,16 +707,16 @@ BOOST_AUTO_TEST_CASE( vector_dist_symmetric_crs_cell_list )
if (distance < r_cut )
{
vd.getProp<1>(p)++;
vd.getProp<1>(q)++;
vd2.getProp<1>(p)++;
vd2.getProp<1>(q)++;
vd.getProp<4>(p).add();
vd.getProp<4>(q).add();
vd2.getProp<4>(p).add();
vd2.getProp<4>(q).add();
vd.getProp<4>(p).last().xq = xq;
vd.getProp<4>(q).last().xq = xp;
vd.getProp<4>(p).last().id = vd.getProp<2>(q);
vd.getProp<4>(q).last().id = vd.getProp<2>(p);
vd2.getProp<4>(p).last().xq = xq;
vd2.getProp<4>(q).last().xq = xp;
vd2.getProp<4>(p).last().id = vd2.getProp<2>(q);
vd2.getProp<4>(q).last().id = vd2.getProp<2>(p);
}
++Np;
......@@ -707,8 +725,8 @@ BOOST_AUTO_TEST_CASE( vector_dist_symmetric_crs_cell_list )
++p_it2;
}
vd.ghost_put<add_,1>();
vd.ghost_put<merge_,4>();
vd2.ghost_put<add_,1>();
vd2.ghost_put<merge_,4>();
auto p_it3 = vd.getDomainIterator();
......@@ -717,25 +735,16 @@ BOOST_AUTO_TEST_CASE( vector_dist_symmetric_crs_cell_list )
{
auto p = p_it3.get();
ret &= vd.getProp<1>(p) == vd.getProp<0>(p);
ret &= vd2.getProp<1>(p) == vd.getProp<0>(p);
vd.getProp<3>(p).sort();
vd.getProp<4>(p).sort();
ret &= vd.getProp<3>(p).size() == vd.getProp<4>(p).size();
// if (v_cl.getProcessUnitID() == 0)
// {
// std::cerr << "Particle: " << p.getKey() << " Position: " << Point<3,float>(vd.getPos(p)).toString() << std::endl;
vd.getProp<3>(p).sort();
vd2.getProp<4>(p).sort();
for (size_t i = 0 ; i < vd.getProp<4>(p).size() ; i++)
{
// std::cerr << "POSITION: " << vd.getProp<3>(p).get(i).xq.toString() << std::endl;
ret &= vd.getProp<3>(p).size() == vd2.getProp<4>(p).size();
// std::cerr << "ID nn " << vd.getProp<3>(p).get(i).id << " " << vd.getProp<4>(p).get(i).id << std::endl;
ret &= vd.getProp<3>(p).get(i).id == vd.getProp<4>(p).get(i).id;
}
// }
for (size_t i = 0 ; i < vd.getProp<3>(p).size() ; i++)
ret &= vd.getProp<3>(p).get(i).id == vd2.getProp<4>(p).get(i).id;
if (ret == false)
break;
......@@ -1169,4 +1178,220 @@ BOOST_AUTO_TEST_CASE( vector_dist_symmetric_verlet_list_no_bottom )
}
BOOST_AUTO_TEST_CASE( vector_dist_symmetric_crs_verlet_list )
{
Vcluster & v_cl = create_vcluster();
if (v_cl.getProcessingUnits() > 24)
return;
float L = 1000.0;
// set the seed
// create the random generator engine
std::srand(0);
std::default_random_engine eg;
std::uniform_real_distribution<float> ud(-L,L);
long int k = 4096 * v_cl.getProcessingUnits();
long int big_step = k / 4;
big_step = (big_step == 0)?1:big_step;
print_test("Testing 3D periodic vector symmetric cell-list k=",k);
BOOST_TEST_CHECKPOINT( "Testing 3D periodic vector symmetric cell-list k=" << k );
Box<3,float> box({-L,-L,-L},{L,L,L});
// Boundary conditions
size_t bc[3]={PERIODIC,PERIODIC,PERIODIC};
float r_cut = 100.0;
// ghost
Ghost<3,float> ghost(r_cut);
Ghost<3,float> ghost2(r_cut);
ghost2.setLow(0,0.0);
ghost2.setLow(1,0.0);
ghost2.setLow(2,0.0);
// Point and global id
struct point_and_gid
{
size_t id;
Point<3,float> xq;
bool operator<(const struct point_and_gid & pag) const
{
return (id < pag.id);
}
};
typedef aggregate<size_t,size_t,size_t,openfpm::vector<point_and_gid>,openfpm::vector<point_and_gid>> part_prop;
// Distributed vector
vector_dist<3,float, part_prop > vd(k,box,bc,ghost,BIND_DEC_TO_GHOST);
vector_dist<3,float, part_prop > vd2(k,box,bc,ghost2,BIND_DEC_TO_GHOST);
size_t start = vd.init_size_accum(k);
auto it = vd.getIterator();
while (it.isNext())
{
auto key = it.get();
vd.getPos(key)[0] = ud(eg);
vd.getPos(key)[1] = ud(eg);
vd.getPos(key)[2] = ud(eg);
vd2.getPos(key)[0] = vd.getPos(key)[0];
vd2.getPos(key)[1] = vd.getPos(key)[1];
vd2.getPos(key)[2] = vd.getPos(key)[2];
// Fill some properties randomly
vd.getProp<0>(key) = 0;
vd.getProp<1>(key) = 0;
vd.getProp<2>(key) = key.getKey() + start;
vd2.getProp<0>(key) = 0;
vd2.getProp<1>(key) = 0;
vd2.getProp<2>(key) = key.getKey() + start;
++it;
}
vd.map();
vd2.map();
// sync the ghost
vd.ghost_get<0,2>();
vd2.ghost_get<0,2>();
auto NN = vd.getVerlet(r_cut);
auto p_it = vd.getDomainIterator();
while (p_it.isNext())
{
auto p = p_it.get();
Point<3,float> xp = vd.getPos(p);
auto Np = NN.getNNIterator(p.getKey());
while (Np.isNext())
{
auto q = Np.get();
if (p.getKey() == q)
{
++Np;
continue;
}
// repulsive
Point<3,float> xq = vd.getPos(q);
Point<3,float> f = (xp - xq);
float distance = f.norm();
// Particle should be inside 2 * r_cut range
if (distance < r_cut )
{
vd.getProp<0>(p)++;
vd.getProp<3>(p).add();
vd.getProp<3>(p).last().xq = xq;
vd.getProp<3>(p).last().id = vd.getProp<2>(q);
}
++Np;
}
++p_it;
}
// We now try symmetric Verlet-list Crs scheme
auto NN2 = vd2.getVerletCrs(r_cut);
// Because iterating across particles in the CSR scheme require a Cell-list
auto p_it2 = vd2.getParticleIteratorCRS(NN2.getInternalCellList());
while (p_it2.isNext())
{
auto p = p_it2.get();
Point<3,float> xp = vd2.getPos(p);
auto Np = NN2.getNNIterator<NO_CHECK>(p);
while (Np.isNext())
{
auto q = Np.get();
if (p == q)
{
++Np;
continue;
}
// repulsive
Point<3,float> xq = vd2.getPos(q);
Point<3,float> f = (xp - xq);
float distance = f.norm();
if (distance < r_cut )
{
vd2.getProp<1>(p)++;
vd2.getProp<1>(q)++;
vd2.getProp<4>(p).add();
vd2.getProp<4>(q).add();
vd2.getProp<4>(p).last().xq = xq;
vd2.getProp<4>(q).last().xq = xp;
vd2.getProp<4>(p).last().id = vd2.getProp<2>(q);
vd2.getProp<4>(q).last().id = vd2.getProp<2>(p);
}
++Np;
}
++p_it2;
}
vd2.ghost_put<add_,1>();
vd2.ghost_put<merge_,4>();
auto p_it3 = vd.getDomainIterator();
bool ret = true;
while (p_it3.isNext())
{
auto p = p_it3.get();
ret &= vd2.getProp<1>(p) == vd.getProp<0>(p);
vd.getProp<3>(p).sort();
vd2.getProp<4>(p).sort();
ret &= vd.getProp<3>(p).size() == vd2.getProp<4>(p).size();
for (size_t i = 0 ; i < vd.getProp<3>(p).size() ; i++)
ret &= vd.getProp<3>(p).get(i).id == vd2.getProp<4>(p).get(i).id;
if (ret == false)
break;
++p_it3;
}
BOOST_REQUIRE_EQUAL(ret,true);
}
#endif /* SRC_VECTOR_VECTOR_DIST_CELL_LIST_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