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 : /// Get the nuumber of atoms in the cell that contains the most atoms 69 : unsigned getMaxInCell() const ; 70 : /// Build the link cell lists 71 : void buildCellLists( const std::vector<Vector>& pos, const std::vector<unsigned>& indices, const Pbc& pbc ); 72 : /// Take three indices and return the index of the corresponding cell 73 : unsigned convertIndicesToIndex( const unsigned& nx, const unsigned& ny, const unsigned& nz ) const ; 74 : /// Find the cell index in which this position is contained 75 : unsigned findCell( const Vector& pos ) const ; 76 : /// Find the cell in which this position is contained 77 : std::array<unsigned,3> findMyCell( const Vector& pos ) const ; 78 : /// Get the list of cells we need to surround the a particular cell 79 : void addRequiredCells( const std::array<unsigned,3>& celn, unsigned& ncells_required, 80 : std::vector<unsigned>& cells_required ) const ; 81 : /// Retrieve the atoms in a list of cells 82 : void retrieveAtomsInCells( const unsigned& ncells_required, 83 : const std::vector<unsigned>& cells_required, 84 : unsigned& natomsper, std::vector<unsigned>& atoms ) const ; 85 : /// Retrieve the atoms we need to consider 86 : void retrieveNeighboringAtoms( const Vector& pos, std::vector<unsigned>& cell_list, unsigned& natomsper, std::vector<unsigned>& atoms ) const ; 87 : }; 88 : 89 : inline 90 : bool LinkCells::enabled() const { 91 : return cutoffwasset; 92 : } 93 : 94 : inline 95 : unsigned LinkCells::getNumberOfCells() const { 96 5295 : return ncells[0]*ncells[1]*ncells[2]; 97 : } 98 : 99 : } 100 : 101 : #endif