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 : #include "ReferenceValuePack.h" 23 : 24 : namespace PLMD { 25 : 26 471328 : ReferenceValuePack::ReferenceValuePack( const unsigned& nargs, const unsigned& natoms, MultiValue& vals ): 27 471328 : boxWasSet(false), 28 471328 : numberOfArgs(nargs), 29 471328 : oind_set(false), 30 471328 : myvals(vals), 31 471328 : atom_indices(myvals.getIndices()), 32 471328 : pca(false) 33 : { 34 471328 : if( atom_indices.size()!=natoms ) { atom_indices.resize( natoms ); myvals.getAtomVector().resize( natoms ); } 35 471328 : if( vals.getNumberOfValues()==1 ) { oind=0; oind_set=true; } 36 471328 : } 37 : 38 98 : void ReferenceValuePack::resize( const unsigned& nargs, const unsigned& natoms ) { 39 98 : numberOfArgs=nargs; atom_indices.resize( natoms ); 40 98 : myvals.getAtomVector().resize( natoms ); 41 98 : } 42 : 43 452938 : void ReferenceValuePack::updateDynamicLists() { 44 452938 : myvals.emptyActiveMembers(); 45 522498 : for(unsigned i=0; i<numberOfArgs; ++i) myvals.putIndexInActiveArray( i ); 46 21588521 : for(unsigned i=0; i<atom_indices.size(); ++i) { 47 21135583 : unsigned nbase = numberOfArgs + 3*atom_indices[i]; 48 21135583 : if( atom_indices[i]<myvals.getNumberOfDerivatives() && myvals.isActive( nbase ) ) { 49 18163510 : myvals.putIndexInActiveArray( nbase+0 ); myvals.putIndexInActiveArray( nbase+1 ); myvals.putIndexInActiveArray( nbase+2 ); 50 : } 51 : } 52 452938 : 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 452938 : if( atom_indices.size()>0 ) { 56 4181580 : for(unsigned i=0; i<9; ++i) { 57 3763422 : myvals.addDerivative( oind, nbase+i, 0.0 ); 58 3763422 : myvals.putIndexInActiveArray( nbase+i ); 59 : } 60 : } 61 452938 : myvals.completeUpdate(); 62 452938 : } 63 : 64 241448 : void ReferenceValuePack::clear() { 65 241448 : if( !myvals.updateComplete() ) updateDynamicLists(); 66 241448 : myvals.clearAll(); boxWasSet=false; 67 241448 : } 68 : 69 192765 : void ReferenceValuePack::scaleAllDerivatives( const double& scalef ) { 70 192765 : if( !myvals.updateComplete() ) updateDynamicLists(); 71 : 72 8856593 : for(unsigned i=0; i<myvals.getNumberActive(); ++i) { 73 8663828 : unsigned ider=myvals.getActiveIndex(i); 74 8663828 : 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 3681 : for(unsigned i=0; i<tvals.getNumberActive(); ++i) { 81 3519 : unsigned ider=tvals.getActiveIndex(i); 82 3519 : 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 8662 : if( !myvals.updateComplete() ) updateDynamicLists(); 88 : 89 866200 : for(unsigned i=0; i<myvals.getNumberActive(); ++i) { 90 857538 : unsigned ider=myvals.getActiveIndex(i); 91 857538 : myvals.setDerivative( to, ider, myvals.getDerivative( from, ider ) ); 92 : } 93 8662 : } 94 : 95 : }