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 "ReferenceValuePack.h"
23 :
24 : namespace PLMD {
25 :
26 221585 : ReferenceValuePack::ReferenceValuePack( const unsigned& nargs, const unsigned& natoms, MultiValue& vals ):
27 : boxWasSet(false),
28 221585 : numberOfArgs(nargs),
29 : oind_set(false),
30 : myvals(vals),
31 : atom_indices(myvals.getIndices()),
32 664755 : pca(false)
33 : {
34 452608 : if( atom_indices.size()!=natoms ) { atom_indices.resize( natoms ); myvals.getAtomVector().resize( natoms ); }
35 221585 : if( vals.getNumberOfValues()==1 ) { oind=0; oind_set=true; }
36 221585 : }
37 :
38 97 : void ReferenceValuePack::resize( const unsigned& nargs, const unsigned& natoms ) {
39 97 : numberOfArgs=nargs; atom_indices.resize( natoms );
40 194 : myvals.getAtomVector().resize( natoms );
41 97 : }
42 :
43 452889 : void ReferenceValuePack::updateDynamicLists() {
44 452889 : myvals.emptyActiveMembers();
45 522449 : for(unsigned i=0; i<numberOfArgs; ++i) myvals.putIndexInActiveArray( i );
46 64311576 : for(unsigned i=0; i<atom_indices.size(); ++i) {
47 42270532 : unsigned nbase = numberOfArgs + 3*atom_indices[i];
48 63405111 : if( atom_indices[i]<myvals.getNumberOfDerivatives() && myvals.isActive( nbase ) ) {
49 72653080 : myvals.putIndexInActiveArray( nbase+0 ); myvals.putIndexInActiveArray( nbase+1 ); myvals.putIndexInActiveArray( nbase+2 );
50 : }
51 : }
52 905778 : unsigned nbase = myvals.getNumberOfDerivatives() - 9;
53 : // zero is added to all virial components to ensure that these are active in the dynamic list
54 : // if this is not done there is a problem with secondary structure variables
55 452889 : if( atom_indices.size()>0 ) {
56 7944071 : for(unsigned i=0; i<9; ++i) {
57 3762981 : myvals.addDerivative( oind, nbase+i, 0.0 );
58 7525962 : myvals.putIndexInActiveArray( nbase+i );
59 : }
60 : }
61 452889 : myvals.completeUpdate();
62 452889 : }
63 :
64 241399 : void ReferenceValuePack::clear() {
65 482798 : if( !myvals.updateComplete() ) updateDynamicLists();
66 241399 : myvals.clearAll(); boxWasSet=false;
67 241399 : }
68 :
69 192765 : void ReferenceValuePack::scaleAllDerivatives( const double& scalef ) {
70 385530 : if( !myvals.updateComplete() ) updateDynamicLists();
71 :
72 26377014 : for(unsigned i=0; i<myvals.getNumberActive(); ++i) {
73 : unsigned ider=myvals.getActiveIndex(i);
74 17327656 : myvals.setDerivative( oind, ider, scalef*myvals.getDerivative( oind, ider ) );
75 : }
76 192765 : }
77 :
78 162 : void ReferenceValuePack::copyScaledDerivatives( const unsigned& from, const double& scalef, const MultiValue& tvals ) {
79 : plumed_dbg_assert( tvals.getNumberOfDerivatives()==myvals.getNumberOfDerivatives() );
80 7200 : for(unsigned i=0; i<tvals.getNumberActive(); ++i) {
81 3519 : unsigned ider=tvals.getActiveIndex(i);
82 7038 : myvals.addDerivative( oind, ider, scalef*tvals.getDerivative( from, ider ) );
83 : }
84 162 : }
85 :
86 8662 : void ReferenceValuePack::moveDerivatives( const unsigned& from, const unsigned& to ) {
87 17324 : if( !myvals.updateComplete() ) updateDynamicLists();
88 :
89 2589938 : for(unsigned i=0; i<myvals.getNumberActive(); ++i) {
90 : unsigned ider=myvals.getActiveIndex(i);
91 : myvals.setDerivative( to, ider, myvals.getDerivative( from, ider ) );
92 : }
93 8662 : }
94 :
95 4839 : }
|