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 462029 : AtomValuePack::AtomValuePack( MultiValue& vals, MultiColvarBase const * mcolv ):
30 : myvals(vals),
31 : mycolv(mcolv),
32 : natoms(0),
33 : indices( vals.getIndices() ),
34 : sort_vector( vals.getSortIndices() ),
35 1848116 : myatoms( vals.getAtomVector() )
36 : {
37 462029 : if( indices.size()!=mcolv->getNumberOfAtoms() ) {
38 23765 : indices.resize( mcolv->getNumberOfAtoms() );
39 47530 : sort_vector.resize( mcolv->getNumberOfAtoms() );
40 47530 : myatoms.resize( mcolv->getNumberOfAtoms() );
41 : }
42 462029 : }
43 :
44 234812 : unsigned AtomValuePack::setupAtomsFromLinkCells( const std::vector<unsigned>& cind, const Vector& cpos, const LinkCells& linkcells ) {
45 234812 : if( cells_required.size()!=linkcells.getNumberOfCells() ) cells_required.resize( linkcells.getNumberOfCells() );
46 : // Build the list of cells that we need
47 469624 : unsigned ncells_required=0; linkcells.addRequiredCells( linkcells.findMyCell( cpos ), ncells_required, cells_required );
48 : // Now build the list of atoms we need
49 875992 : natoms=cind.size(); for(unsigned i=0; i<natoms; ++i) indices[i]=cind[i];
50 234812 : linkcells.retrieveAtomsInCells( ncells_required, cells_required, natoms, indices );
51 : // linkcells.retrieveNeighboringAtoms( cpos, natoms, indices );
52 1203793676 : for(unsigned i=0; i<natoms; ++i) myatoms[i]=mycolv->getPositionOfAtomForLinkCells( indices[i] ) - cpos;
53 469624 : if( mycolv->usesPbc() ) mycolv->applyPbc( myatoms, natoms );
54 234812 : return natoms;
55 : }
56 :
57 530448 : void AtomValuePack::updateUsingIndices() {
58 1262462 : if( myvals.updateComplete() ) return;
59 :
60 : unsigned jactive=0;
61 799436580 : for(unsigned i=0; i<natoms; ++i) {
62 799107698 : unsigned base=3*indices[i];
63 803529679 : if( myvals.isActive( base ) ) { sort_vector[jactive]=indices[i]; jactive++; }
64 : }
65 328882 : std::sort( sort_vector.begin(), sort_vector.begin()+jactive );
66 :
67 328882 : myvals.emptyActiveMembers();
68 9172844 : for(unsigned i=0; i<jactive; ++i) {
69 8843962 : unsigned base=3*sort_vector[i]; // indices[i];
70 4421981 : myvals.putIndexInActiveArray( base );
71 8843962 : myvals.putIndexInActiveArray( base + 1 );
72 8843962 : myvals.putIndexInActiveArray( base + 2 );
73 : }
74 657764 : unsigned nvir=3*mycolv->getNumberOfAtoms();
75 657764 : if( myvals.isActive( nvir ) ) {
76 4313627 : for(unsigned i=0; i<9; ++i) myvals.putIndexInActiveArray( nvir + i );
77 : }
78 328882 : myvals.completeUpdate();
79 : }
80 :
81 905722 : void AtomValuePack::addComDerivatives( const int& ind, const Vector& der, CatomPack& catom_der ) {
82 905722 : if( ind<0 ) {
83 208784 : for(unsigned ider=0; ider<catom_der.getNumberOfAtomsWithDerivatives(); ++ider) {
84 54660 : unsigned jder=3*catom_der.getIndex(ider);
85 109320 : myvals.addTemporyDerivative( jder+0, catom_der.getDerivative(ider,0,der) );
86 109320 : myvals.addTemporyDerivative( jder+1, catom_der.getDerivative(ider,1,der) );
87 109320 : myvals.addTemporyDerivative( jder+2, catom_der.getDerivative(ider,2,der) );
88 : }
89 : } else {
90 3433816 : 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 4839 : }
|