Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2014-2023 The plumed team 3 : (see the PEOPLE file at the root of the distribution for a list of names) 4 : 5 : See http://www.plumed.org for more information. 6 : 7 : This file is part of plumed, version 2. 8 : 9 : plumed is free software: you can redistribute it and/or modify 10 : it under the terms of the GNU Lesser General Public License as published by 11 : the Free Software Foundation, either version 3 of the License, or 12 : (at your option) any later version. 13 : 14 : plumed is distributed in the hope that it will be useful, 15 : but WITHOUT ANY WARRANTY; without even the implied warranty of 16 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 : GNU Lesser General Public License for more details. 18 : 19 : You should have received a copy of the GNU Lesser General Public License 20 : along with plumed. If not, see <http://www.gnu.org/licenses/>. 21 : +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ 22 : #ifndef __PLUMED_tools_LinkCells_h 23 : #define __PLUMED_tools_LinkCells_h 24 : 25 : #include <vector> 26 : #include "Vector.h" 27 : #include "Pbc.h" 28 : 29 : namespace PLMD { 30 : 31 : class Communicator; 32 : 33 : /// \ingroup TOOLBOX 34 : /// A class for doing link cells 35 : class LinkCells { 36 : private: 37 : /// Symbolic link to plumed communicator 38 : Communicator & comm; 39 : /// Check that the link cells were set up correctly 40 : bool cutoffwasset; 41 : /// The cutoff to use for the sizes of the cells 42 : double link_cutoff; 43 : /// The pbc we are using for link cells 44 : Pbc mypbc; 45 : /// The number of cells in each direction 46 : std::vector<unsigned> ncells; 47 : /// The number of cells to stride through to get the link cells 48 : std::vector<unsigned> nstride; 49 : /// The list of cells each atom is inside 50 : std::vector<unsigned> allcells; 51 : /// The start of each block corresponding to each link cell 52 : std::vector<unsigned> lcell_starts; 53 : /// The number of atoms in each link cell 54 : std::vector<unsigned> lcell_tots; 55 : /// The atoms ordered by link cells 56 : std::vector<unsigned> lcell_lists; 57 : public: 58 : /// 59 : explicit LinkCells( Communicator& comm ); 60 : /// Have the link cells been enabled 61 : bool enabled() const ; 62 : /// Set the value of the cutoff 63 : void setCutoff( const double& lcut ); 64 : /// Get the value of the cutoff 65 : double getCutoff() const ; 66 : /// Get the total number of link cells 67 : unsigned getNumberOfCells() const ; 68 : /// Build the link cell lists 69 : void buildCellLists( const std::vector<Vector>& pos, const std::vector<unsigned>& indices, const Pbc& pbc ); 70 : /// Take three indices and return the index of the corresponding cell 71 : unsigned convertIndicesToIndex( const unsigned& nx, const unsigned& ny, const unsigned& nz ) const ; 72 : /// Find the cell index in which this position is contained 73 : unsigned findCell( const Vector& pos ) const ; 74 : /// Find the cell in which this position is contained 75 : std::array<unsigned,3> findMyCell( const Vector& pos ) const ; 76 : /// Get the list of cells we need to surround the a particular cell 77 : void addRequiredCells( const std::array<unsigned,3>& celn, unsigned& ncells_required, 78 : std::vector<unsigned>& cells_required ) const ; 79 : /// Retrieve the atoms in a list of cells 80 : void retrieveAtomsInCells( const unsigned& ncells_required, 81 : const std::vector<unsigned>& cells_required, 82 : unsigned& natomsper, std::vector<unsigned>& atoms ) const ; 83 : /// Retrieve the atoms we need to consider 84 : void retrieveNeighboringAtoms( const Vector& pos, std::vector<unsigned>& cell_list, unsigned& natomsper, std::vector<unsigned>& atoms ) const ; 85 : }; 86 : 87 : inline 88 : bool LinkCells::enabled() const { 89 1938 : return cutoffwasset; 90 : } 91 : 92 : inline 93 : unsigned LinkCells::getNumberOfCells() const { 94 227143 : return ncells[0]*ncells[1]*ncells[2]; 95 : } 96 : 97 : } 98 : 99 : #endif