LCOV - code coverage report
Current view: top level - reference - ReferenceValuePack.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 46 46 100.0 %
Date: 2019-08-13 10:15:31 Functions: 9 9 100.0 %

          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      471250 : ReferenceValuePack::ReferenceValuePack( const unsigned& nargs, const unsigned& natoms, MultiValue& vals ):
      27             :   boxWasSet(false),
      28             :   numberOfArgs(nargs),
      29             :   oind_set(false),
      30             :   myvals(vals),
      31      471250 :   atom_indices(myvals.getIndices()),
      32      942500 :   pca(false)
      33             : {
      34      942510 :   if( atom_indices.size()!=natoms ) { atom_indices.resize( natoms ); myvals.getAtomVector().resize( natoms ); }
      35      471304 :   if( vals.getNumberOfValues()==1 ) { oind=0; oind_set=true; }
      36      471304 : }
      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      452798 : void ReferenceValuePack::updateDynamicLists() {
      44      452798 :   myvals.emptyActiveMembers();
      45      524892 :   for(unsigned i=0; i<numberOfArgs; ++i) myvals.putIndexInActiveArray( i );
      46    43150912 :   for(unsigned i=0; i<atom_indices.size(); ++i) {
      47    42245320 :     unsigned nbase = numberOfArgs + 3*atom_indices[i];
      48    63348542 :     if( atom_indices[i]<myvals.getNumberOfDerivatives() && myvals.isActive( nbase ) ) {
      49    72623881 :       myvals.putIndexInActiveArray( nbase+0 ); myvals.putIndexInActiveArray( nbase+1 ); myvals.putIndexInActiveArray( nbase+2 );
      50             :     }
      51             :   }
      52      905592 :   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      452796 :   if( atom_indices.size()>0 ) {
      56     3758973 :     for(unsigned i=0; i<9; ++i) {
      57     3759440 :       myvals.addDerivative( oind, nbase+i, 0.0 );
      58     7516155 :       myvals.putIndexInActiveArray( nbase+i );
      59             :     }
      60             :   }
      61      452329 :   myvals.completeUpdate();
      62      452855 : }
      63             : 
      64      241334 : void ReferenceValuePack::clear() {
      65      482743 :   if( !myvals.updateComplete() ) updateDynamicLists();
      66      241413 :   myvals.clearAll(); boxWasSet=false;
      67      241424 : }
      68             : 
      69      192613 : void ReferenceValuePack::scaleAllDerivatives( const double& scalef ) {
      70      385269 :   if( !myvals.updateComplete() ) updateDynamicLists();
      71             : 
      72    17488441 :   for(unsigned i=0; i<myvals.getNumberActive(); ++i) {
      73     8646558 :     unsigned ider=myvals.getActiveIndex(i);
      74    17293116 :     myvals.setDerivative( oind, ider, scalef*myvals.getDerivative( oind, ider ) );
      75             :   }
      76      192737 : }
      77             : 
      78         162 : void ReferenceValuePack::copyScaledDerivatives( const unsigned& from, const double& scalef, const MultiValue& tvals ) {
      79             :   plumed_dbg_assert( tvals.getNumberOfDerivatives()==myvals.getNumberOfDerivatives() );
      80        7362 :   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        8660 : void ReferenceValuePack::moveDerivatives( const unsigned& from, const unsigned& to ) {
      87       17320 :   if( !myvals.updateComplete() ) updateDynamicLists();
      88             : 
      89     1723005 :   for(unsigned i=0; i<myvals.getNumberActive(); ++i) {
      90      857218 :     unsigned ider=myvals.getActiveIndex(i);
      91      857218 :     myvals.setDerivative( to, ider, myvals.getDerivative( from, ider ) );
      92             :   }
      93        8661 : }
      94             : 
      95        5874 : }

Generated by: LCOV version 1.14