Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2014-2019 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 : #include "AtomValuePack.h" 23 : #include "CatomPack.h" 24 : #include "tools/LinkCells.h" 25 : 26 : namespace PLMD { 27 : namespace multicolvar { 28 : 29 467774 : AtomValuePack::AtomValuePack( MultiValue& vals, MultiColvarBase const * mcolv ): 30 : myvals(vals), 31 : mycolv(mcolv), 32 : natoms(0), 33 467774 : indices( vals.getIndices() ), 34 467774 : sort_vector( vals.getSortIndices() ), 35 1403322 : myatoms( vals.getAtomVector() ) 36 : { 37 467774 : if( indices.size()!=mcolv->getNumberOfAtoms() ) { 38 24201 : indices.resize( mcolv->getNumberOfAtoms() ); 39 24230 : sort_vector.resize( mcolv->getNumberOfAtoms() ); 40 24231 : myatoms.resize( mcolv->getNumberOfAtoms() ); 41 : } 42 467798 : } 43 : 44 240388 : unsigned AtomValuePack::setupAtomsFromLinkCells( const std::vector<unsigned>& cind, const Vector& cpos, const LinkCells& linkcells ) { 45 240388 : if( cells_required.size()!=linkcells.getNumberOfCells() ) cells_required.resize( linkcells.getNumberOfCells() ); 46 : // Build the list of cells that we need 47 240412 : unsigned ncells_required=0; linkcells.addRequiredCells( linkcells.findMyCell( cpos ), ncells_required, cells_required ); 48 : // Now build the list of atoms we need 49 570634 : natoms=cind.size(); for(unsigned i=0; i<natoms; ++i) indices[i]=cind[i]; 50 240412 : linkcells.retrieveAtomsInCells( ncells_required, cells_required, natoms, indices ); 51 : // linkcells.retrieveNeighboringAtoms( cpos, natoms, indices ); 52 1200219333 : for(unsigned i=0; i<natoms; ++i) myatoms[i]=mycolv->getPositionOfAtomForLinkCells( indices[i] ) - cpos; 53 480816 : if( mycolv->usesPbc() ) mycolv->applyPbc( myatoms, natoms ); 54 240421 : return natoms; 55 : } 56 : 57 536000 : void AtomValuePack::updateUsingIndices() { 58 1334416 : if( myvals.updateComplete() ) return; 59 : 60 : unsigned jactive=0; 61 399598607 : for(unsigned i=0; i<natoms; ++i) { 62 799318730 : unsigned base=3*indices[i]; 63 803677397 : if( myvals.isActive( base ) ) { sort_vector[jactive]=indices[i]; jactive++; } 64 : } 65 669000 : std::sort( sort_vector.begin(), sort_vector.begin()+jactive ); 66 : 67 334495 : myvals.emptyActiveMembers(); 68 4755348 : for(unsigned i=0; i<jactive; ++i) { 69 8841728 : unsigned base=3*sort_vector[i]; // indices[i]; 70 4420864 : myvals.putIndexInActiveArray( base ); 71 8841040 : myvals.putIndexInActiveArray( base + 1 ); 72 8841437 : myvals.putIndexInActiveArray( base + 2 ); 73 : } 74 668968 : unsigned nvir=3*mycolv->getNumberOfAtoms(); 75 668982 : if( myvals.isActive( nvir ) ) { 76 4087199 : for(unsigned i=0; i<9; ++i) myvals.putIndexInActiveArray( nvir + i ); 77 : } 78 334463 : myvals.completeUpdate(); 79 : } 80 : 81 905762 : void AtomValuePack::addComDerivatives( const int& ind, const Vector& der, CatomPack& catom_der ) { 82 905762 : if( ind<0 ) { 83 208784 : for(unsigned ider=0; ider<catom_der.getNumberOfAtomsWithDerivatives(); ++ider) { 84 54660 : unsigned jder=3*catom_der.getIndex(ider); 85 54660 : myvals.addTemporyDerivative( jder+0, catom_der.getDerivative(ider,0,der) ); 86 54660 : myvals.addTemporyDerivative( jder+1, catom_der.getDerivative(ider,1,der) ); 87 54660 : myvals.addTemporyDerivative( jder+2, catom_der.getDerivative(ider,2,der) ); 88 : } 89 : } else { 90 3433976 : for(unsigned ider=0; ider<catom_der.getNumberOfAtomsWithDerivatives(); ++ider) { 91 860958 : unsigned jder=3*catom_der.getIndex(ider); 92 860958 : myvals.addDerivative( ind, jder+0, catom_der.getDerivative(ider,0,der) ); 93 860958 : myvals.addDerivative( ind, jder+1, catom_der.getDerivative(ider,1,der) ); 94 860958 : myvals.addDerivative( ind, jder+2, catom_der.getDerivative(ider,2,der) ); 95 : } 96 : } 97 905762 : } 98 : 99 : } 100 5874 : }