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 461915 : AtomValuePack::AtomValuePack( MultiValue& vals, MultiColvarBase const * mcolv ):
30 : myvals(vals),
31 : mycolv(mcolv),
32 : natoms(0),
33 461915 : indices( vals.getIndices() ),
34 461936 : sort_vector( vals.getSortIndices() ),
35 1385830 : myatoms( vals.getAtomVector() )
36 : {
37 461949 : if( indices.size()!=mcolv->getNumberOfAtoms() ) {
38 23782 : indices.resize( mcolv->getNumberOfAtoms() );
39 23777 : sort_vector.resize( mcolv->getNumberOfAtoms() );
40 23786 : myatoms.resize( mcolv->getNumberOfAtoms() );
41 : }
42 461934 : }
43 :
44 234771 : unsigned AtomValuePack::setupAtomsFromLinkCells( const std::vector<unsigned>& cind, const Vector& cpos, const LinkCells& linkcells ) {
45 234771 : if( cells_required.size()!=linkcells.getNumberOfCells() ) cells_required.resize( linkcells.getNumberOfCells() );
46 : // Build the list of cells that we need
47 234825 : unsigned ncells_required=0; linkcells.addRequiredCells( linkcells.findMyCell( cpos ), ncells_required, cells_required );
48 : // Now build the list of atoms we need
49 234812 : natoms=cind.size(); for(unsigned i=0; i<natoms; ++i) indices[i]=cind[i];
50 234803 : linkcells.retrieveAtomsInCells( ncells_required, cells_required, natoms, indices );
51 : // linkcells.retrieveNeighboringAtoms( cpos, natoms, indices );
52 362695 : for(unsigned i=0; i<natoms; ++i) myatoms[i]=mycolv->getPositionOfAtomForLinkCells( indices[i] ) - cpos;
53 234788 : if( mycolv->usesPbc() ) mycolv->applyPbc( myatoms, natoms );
54 234810 : return natoms;
55 : }
56 :
57 530323 : void AtomValuePack::updateUsingIndices() {
58 1060613 : if( myvals.updateComplete() ) return;
59 :
60 476809 : unsigned jactive=0;
61 399878309 : for(unsigned i=0; i<natoms; ++i) {
62 399549468 : unsigned base=3*indices[i];
63 399547302 : if( myvals.isActive( base ) ) { sort_vector[jactive]=indices[i]; jactive++; }
64 : }
65 328841 : std::sort( sort_vector.begin(), sort_vector.begin()+jactive );
66 :
67 328810 : myvals.emptyActiveMembers();
68 4744476 : for(unsigned i=0; i<jactive; ++i) {
69 4415860 : unsigned base=3*sort_vector[i]; // indices[i];
70 4418567 : myvals.putIndexInActiveArray( base );
71 4415271 : myvals.putIndexInActiveArray( base + 1 );
72 4415354 : myvals.putIndexInActiveArray( base + 2 );
73 : }
74 328616 : unsigned nvir=3*mycolv->getNumberOfAtoms();
75 328715 : if( myvals.isActive( nvir ) ) {
76 231013 : for(unsigned i=0; i<9; ++i) myvals.putIndexInActiveArray( nvir + i );
77 : }
78 324735 : myvals.completeUpdate();
79 : }
80 :
81 905722 : void AtomValuePack::addComDerivatives( const int& ind, const Vector& der, CatomPack& catom_der ) {
82 905722 : if( ind<0 ) {
83 104392 : 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 1716908 : for(unsigned ider=0; ider<catom_der.getNumberOfAtomsWithDerivatives(); ++ider) {
91 860918 : unsigned jder=3*catom_der.getIndex(ider);
92 860918 : myvals.addDerivative( ind, jder+0, catom_der.getDerivative(ider,0,der) );
93 860918 : myvals.addDerivative( ind, jder+1, catom_der.getDerivative(ider,1,der) );
94 860918 : myvals.addDerivative( ind, jder+2, catom_der.getDerivative(ider,2,der) );
95 : }
96 : }
97 905722 : }
98 :
99 : }
100 4821 : }
|