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: 2018-12-19 07:49:13 Functions: 9 9 100.0 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2014-2018 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      162397 : ReferenceValuePack::ReferenceValuePack( const unsigned& nargs, const unsigned& natoms, MultiValue& vals ):
      27             :   boxWasSet(false),
      28             :   numberOfArgs(nargs),
      29             :   oind_set(false),
      30             :   myvals(vals),
      31      162397 :   atom_indices(myvals.getIndices()),
      32      325043 :   pca(false)
      33             : {
      34      162894 :   if( atom_indices.size()!=natoms ) { atom_indices.resize( natoms ); myvals.getAtomVector().resize( natoms ); }
      35      162788 :   if( vals.getNumberOfValues()==1 ) { oind=0; oind_set=true; }
      36      162976 : }
      37             : 
      38          87 : void ReferenceValuePack::resize( const unsigned& nargs, const unsigned& natoms ) {
      39          87 :   numberOfArgs=nargs; atom_indices.resize( natoms );
      40          87 :   myvals.getAtomVector().resize( natoms );
      41          87 : }
      42             : 
      43      367600 : void ReferenceValuePack::updateDynamicLists() {
      44      367600 :   myvals.emptyActiveMembers();
      45      367461 :   for(unsigned i=0; i<numberOfArgs; ++i) myvals.putIndexInActiveArray( i );
      46    20859119 :   for(unsigned i=0; i<atom_indices.size(); ++i) {
      47    20489042 :     unsigned nbase = numberOfArgs + 3*atom_indices[i];
      48    20488744 :     if( atom_indices[i]<myvals.getNumberOfDerivatives() && myvals.isActive( nbase ) ) {
      49    17820988 :       myvals.putIndexInActiveArray( nbase+0 ); myvals.putIndexInActiveArray( nbase+1 ); myvals.putIndexInActiveArray( nbase+2 );
      50             :     }
      51             :   }
      52      368391 :   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      368612 :   if( atom_indices.size()>0 ) {
      56     3685765 :     for(unsigned i=0; i<9; ++i) {
      57     3317011 :       myvals.addDerivative( oind, nbase+i, 0.0 );
      58     3314773 :       myvals.putIndexInActiveArray( nbase+i );
      59             :     }
      60             :   }
      61      366174 :   myvals.completeUpdate();
      62      368470 : }
      63             : 
      64      214384 : void ReferenceValuePack::clear() {
      65      214384 :   if( !myvals.updateComplete() ) updateDynamicLists();
      66      214773 :   myvals.clearAll(); boxWasSet=false;
      67      215085 : }
      68             : 
      69      134147 : void ReferenceValuePack::scaleAllDerivatives( const double& scalef ) {
      70      134147 :   if( !myvals.updateComplete() ) updateDynamicLists();
      71             : 
      72     7619331 :   for(unsigned i=0; i<myvals.getNumberActive(); ++i) {
      73     7479284 :     unsigned ider=myvals.getActiveIndex(i);
      74     7461799 :     myvals.setDerivative( oind, ider, scalef*myvals.getDerivative( oind, ider ) );
      75             :   }
      76      135011 : }
      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      866017 :   for(unsigned i=0; i<myvals.getNumberActive(); ++i) {
      90      857204 :     unsigned ider=myvals.getActiveIndex(i);
      91      856902 :     myvals.setDerivative( to, ider, myvals.getDerivative( from, ider ) );
      92             :   }
      93        8661 : }
      94             : 
      95        2523 : }

Generated by: LCOV version 1.13