LCOV - code coverage report
Current view: top level - reference - ReferenceValuePack.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 60 61 98.4 %
Date: 2026-03-30 13:16:06 Functions: 7 7 100.0 %

          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      519886 : ReferenceValuePack::ReferenceValuePack( const unsigned& nargs, const unsigned& natoms, MultiValue& vals ):
      27      519886 :   boxWasSet(false),
      28      519886 :   numberOfArgs(nargs),
      29      519886 :   oind_set(false),
      30      519886 :   myvals(vals),
      31      519886 :   atom_indices(myvals.getIndices()),
      32      519886 :   pca(false) {
      33      519886 :   if( atom_indices.size()!=natoms ) {
      34       11734 :     atom_indices.resize( natoms );
      35       11734 :     myvals.getAtomVector().resize( natoms );
      36             :   }
      37      519886 :   if( vals.getNumberOfValues()==1 ) {
      38      259844 :     oind=0;
      39      259844 :     oind_set=true;
      40             :   }
      41      519886 : }
      42             : 
      43         104 : void ReferenceValuePack::resize( const unsigned& nargs, const unsigned& natoms ) {
      44         104 :   numberOfArgs=nargs;
      45         104 :   atom_indices.resize( natoms );
      46         104 :   myvals.getAtomVector().resize( natoms );
      47         104 : }
      48             : 
      49      574294 : void ReferenceValuePack::updateDynamicLists() {
      50      574294 :   myvals.emptyActiveMembers();
      51      643854 :   for(unsigned i=0; i<numberOfArgs; ++i) {
      52       69560 :     myvals.putIndexInActiveArray( i );
      53             :   }
      54    25351673 :   for(unsigned i=0; i<atom_indices.size(); ++i) {
      55    24777379 :     unsigned nbase = numberOfArgs + 3*atom_indices[i];
      56    24777379 :     if( atom_indices[i]<myvals.getNumberOfDerivatives() && myvals.isActive( nbase ) ) {
      57    20348746 :       myvals.putIndexInActiveArray( nbase+0 );
      58    20348746 :       myvals.putIndexInActiveArray( nbase+1 );
      59    20348746 :       myvals.putIndexInActiveArray( nbase+2 );
      60             :     }
      61             :   }
      62      574294 :   unsigned nbase = myvals.getNumberOfDerivatives() - 9;
      63             :   // zero is added to all virial components to ensure that these are active in the dynamic list
      64             :   // if this is not done there is a problem with secondary structure variables
      65      574294 :   if( atom_indices.size()>0 ) {
      66     5395140 :     for(unsigned i=0; i<9; ++i) {
      67     4855626 :       myvals.addDerivative( oind, nbase+i, 0.0 );
      68     4855626 :       myvals.putIndexInActiveArray( nbase+i );
      69             :     }
      70             :   }
      71      574294 :   myvals.completeUpdate();
      72      574294 : }
      73             : 
      74      314252 : void ReferenceValuePack::clear() {
      75      314252 :   if( !myvals.updateComplete() ) {
      76      225912 :     updateDynamicLists();
      77             :   }
      78      314252 :   myvals.clearAll();
      79      314252 :   boxWasSet=false;
      80      314252 : }
      81             : 
      82      210969 : void ReferenceValuePack::scaleAllDerivatives( const double& scalef ) {
      83      210969 :   if( !myvals.updateComplete() ) {
      84       38582 :     updateDynamicLists();
      85             :   }
      86             : 
      87    10676993 :   for(unsigned i=0; i<myvals.getNumberActive(); ++i) {
      88    10466024 :     unsigned ider=myvals.getActiveIndex(i);
      89    10466024 :     myvals.setDerivative( oind, ider, scalef*myvals.getDerivative( oind, ider ) );
      90             :   }
      91      210969 : }
      92             : 
      93         162 : void ReferenceValuePack::copyScaledDerivatives( const unsigned& from, const double& scalef, const MultiValue& tvals ) {
      94             :   plumed_dbg_assert( tvals.getNumberOfDerivatives()==myvals.getNumberOfDerivatives() );
      95        3681 :   for(unsigned i=0; i<tvals.getNumberActive(); ++i) {
      96        3519 :     unsigned ider=tvals.getActiveIndex(i);
      97        3519 :     myvals.addDerivative( oind, ider, scalef*tvals.getDerivative( from, ider ) );
      98             :   }
      99         162 : }
     100             : 
     101       19914 : void ReferenceValuePack::moveDerivatives( const unsigned& from, const unsigned& to ) {
     102       19914 :   if( !myvals.updateComplete() ) {
     103           0 :     updateDynamicLists();
     104             :   }
     105             : 
     106     1991400 :   for(unsigned i=0; i<myvals.getNumberActive(); ++i) {
     107     1971486 :     unsigned ider=myvals.getActiveIndex(i);
     108     1971486 :     myvals.setDerivative( to, ider, myvals.getDerivative( from, ider ) );
     109             :   }
     110       19914 : }
     111             : 
     112             : }

Generated by: LCOV version 1.16