| 1 | /* |
| 2 | * vector_dist_multiphase_functions.hpp |
| 3 | * |
| 4 | * Created on: Oct 14, 2016 |
| 5 | * Author: i-bird |
| 6 | */ |
| 7 | |
| 8 | #ifndef SRC_VECTOR_VECTOR_DIST_MULTIPHASE_FUNCTIONS_HPP_ |
| 9 | #define SRC_VECTOR_VECTOR_DIST_MULTIPHASE_FUNCTIONS_HPP_ |
| 10 | |
| 11 | #include "NN/CellList/CellListM.hpp" |
| 12 | #include "NN/VerletList/VerletListM.hpp" |
| 13 | |
| 14 | template<typename Vector, typename CL, typename T> |
| 15 | VerletList<Vector::dims,typename Vector::stype,Mem_fast<>,shift<Vector::dims,typename Vector::stype>,typename Vector::internal_position_vector_type,CL> |
| 16 | createVerlet(Vector & v, Vector & v1, CL & cl, T r_cut) |
| 17 | { |
| 18 | VerletList<Vector::dims,typename Vector::stype,Mem_fast<>,shift<Vector::dims,typename Vector::stype>,typename Vector::internal_position_vector_type,CL> ver; |
| 19 | |
| 20 | ver.Initialize(cl,r_cut,v.getPosVector(),v1.getPosVector(),v.size_local()); |
| 21 | |
| 22 | return ver; |
| 23 | } |
| 24 | |
| 25 | template<unsigned int sh_byte, typename Vector , typename Vector1,typename CL, typename T> VerletListM<Vector::dims,typename Vector::stype,sh_byte,CL,shift<Vector::dims,typename Vector::stype>,typename Vector::internal_position_vector_type> |
| 26 | createVerletM(size_t pp, Vector & v, Vector1 & phases, CL & cl, T r_cut) |
| 27 | { |
| 28 | VerletListM<Vector::dims,typename Vector::stype,sh_byte,CL,shift<Vector::dims,typename Vector::stype>,typename Vector::internal_position_vector_type> ver; |
| 29 | |
| 30 | openfpm::vector<pos_v<typename Vector::internal_position_vector_type>> v_phases; |
| 31 | |
| 32 | for (size_t i = 0 ; i < phases.size() ; i++) |
| 33 | {v_phases.add(pos_v<typename Vector::internal_position_vector_type>(phases.get(i).getPosVector()));} |
| 34 | |
| 35 | ver.Initialize(cl,pp,r_cut,v.getPosVector(),v_phases,v.size_local()); |
| 36 | |
| 37 | return ver; |
| 38 | } |
| 39 | |
| 40 | template<unsigned int nbit, typename Vector, typename T> |
| 41 | CellListM<Vector::dims,typename Vector::stype,nbit,typename Vector::CellList_type> |
| 42 | createCellListM(openfpm::vector<Vector> & phases, T r_cut) |
| 43 | { |
| 44 | size_t div[3]; |
| 45 | Box<Vector::dims,typename Vector::stype> box_cl; |
| 46 | |
| 47 | CellListM<Vector::dims,typename Vector::stype,nbit,typename Vector::CellList_type> NN; |
| 48 | if (phases.size() == 0) |
| 49 | return NN; |
| 50 | |
| 51 | box_cl = phases.get(0).getDecomposition().getProcessorBounds(); |
| 52 | phases.get(0).getCellListParams(r_cut,div,box_cl); |
| 53 | |
| 54 | NN.Initialize(box_cl,div); |
| 55 | |
| 56 | // for all the phases i |
| 57 | for (size_t i = 0; i < phases.size() ; i++) |
| 58 | { |
| 59 | // iterate across all the particle of the phase i |
| 60 | auto it = phases.get(i).getDomainAndGhostIterator(); |
| 61 | while (it.isNext()) |
| 62 | { |
| 63 | auto key = it.get(); |
| 64 | |
| 65 | Point<Vector::dims,T> xp = phases.get(i).getPos(key); |
| 66 | |
| 67 | // Add the particle of the phase i to the cell list |
| 68 | NN.add(xp, key.getKey(), i); |
| 69 | |
| 70 | ++it; |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | return NN; |
| 75 | } |
| 76 | |
| 77 | |
| 78 | /////// Symmetric version |
| 79 | |
| 80 | template<typename Vector,typename CL, typename T> |
| 81 | VerletList<Vector::dims,typename Vector::stype,Mem_fast<>,shift<Vector::dims,typename Vector::stype>,typename Vector::internal_position_vector_type> |
| 82 | createVerletSym(Vector & v, Vector & v1, CL & cl, T r_cut) |
| 83 | { |
| 84 | VerletList<Vector::dims,typename Vector::stype,Mem_fast<>,shift<Vector::dims,typename Vector::stype>,typename Vector::internal_position_vector_type> ver; |
| 85 | |
| 86 | ver.Initialize(cl,r_cut,v.getPosVector(),v1.getPosVector(),v.size_local()); |
| 87 | |
| 88 | return ver; |
| 89 | } |
| 90 | |
| 91 | template<unsigned int sh_byte, typename Vector, typename Vector1 ,typename CL, typename T> |
| 92 | VerletListM<Vector::dims,typename Vector::stype,sh_byte,CL,shift<Vector::dims,typename Vector::stype>,typename Vector::internal_position_vector_type> |
| 93 | createVerletSymM(size_t pp, Vector & v, Vector1 & phases, CL & cl, T r_cut) |
| 94 | { |
| 95 | VerletListM<Vector::dims,typename Vector::stype,sh_byte,CL,shift<Vector::dims,typename Vector::stype>,typename Vector::internal_position_vector_type> ver; |
| 96 | |
| 97 | openfpm::vector<pos_v<typename CL::internal_vector_pos_type>> v_phases; |
| 98 | |
| 99 | for (size_t i = 0 ; i < phases.size() ; i++) |
| 100 | {v_phases.add(pos_v<typename CL::internal_vector_pos_type>(phases.get(i).getPosVector()));} |
| 101 | |
| 102 | ver.Initialize(cl,pp,r_cut,v.getPosVector(),v_phases,v.size_local(),VL_SYMMETRIC); |
| 103 | |
| 104 | return ver; |
| 105 | } |
| 106 | |
| 107 | template<unsigned int nbit, typename Vector, typename T> |
| 108 | CellListM<Vector::dims,typename Vector::stype,nbit,typename Vector::CellList_type> |
| 109 | createCellListSymM(openfpm::vector<Vector> & phases, T r_cut) |
| 110 | { |
| 111 | Box<Vector::dims,typename Vector::stype> box_cl; |
| 112 | |
| 113 | CellListM<Vector::dims,typename Vector::stype,nbit,typename Vector::CellList_type> NN; |
| 114 | if (phases.size() == 0) |
| 115 | {return NN;} |
| 116 | |
| 117 | // Calculate the Cell list division for this CellList |
| 118 | CellDecomposer_sm<Vector::dims,typename Vector::stype,shift<Vector::dims,typename Vector::stype>> cd_sm; |
| 119 | |
| 120 | size_t pad = 0; |
| 121 | cl_param_calculateSym(phases.get(0).getDecomposition().getDomain(),cd_sm,phases.get(0).getDecomposition().getGhost(),r_cut,pad); |
| 122 | |
| 123 | // Processor bounding box |
| 124 | Box<Vector::dims, typename Vector::stype> pbox = phases.get(0).getDecomposition().getProcessorBounds(); |
| 125 | |
| 126 | // Ghost padding extension |
| 127 | Ghost<Vector::dims,size_t> g_ext(0); |
| 128 | NN.Initialize(cd_sm,pbox,pad); |
| 129 | |
| 130 | // for all the phases i |
| 131 | for (size_t i = 0; i < phases.size() ; i++) |
| 132 | { |
| 133 | // iterate across all the particle of the phase i |
| 134 | auto it = phases.get(i).getDomainAndGhostIterator(); |
| 135 | while (it.isNext()) |
| 136 | { |
| 137 | auto key = it.get(); |
| 138 | |
| 139 | Point<Vector::dims,T> xp = phases.get(i).getPos(key); |
| 140 | |
| 141 | // Add the particle of the phase i to the cell list |
| 142 | NN.add(xp, key.getKey(), i); |
| 143 | |
| 144 | ++it; |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | return NN; |
| 149 | } |
| 150 | |
| 151 | #endif /* SRC_VECTOR_VECTOR_DIST_MULTIPHASE_FUNCTIONS_HPP_ */ |
| 152 | |