LCOV - code coverage report
Current view: top level - tools - MultiValue.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 46 46 100.0 %
Date: 2024-10-18 14:00:25 Functions: 4 4 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 "MultiValue.h"
      23             : #include "Tools.h"
      24             : 
      25             : namespace PLMD {
      26             : 
      27      344869 : MultiValue::MultiValue( const size_t& nvals, const size_t& nder, const size_t& nmat, const size_t& maxcol, const size_t& nbook ):
      28      344869 :   task_index(0),
      29      344869 :   task2_index(0),
      30      344869 :   values(nvals),
      31      344869 :   nderivatives(nder),
      32      344869 :   derivatives(nvals*nder),
      33      344869 :   hasderiv(nvals*nder,false),
      34      344869 :   tmpval(0),
      35      344869 :   nactive(nvals),
      36      344869 :   active_list(nvals*nder),
      37      344869 :   tmpder(nder),
      38      344869 :   atLeastOneSet(false),
      39      344869 :   vector_call(false),
      40      344869 :   nindices(0),
      41      344869 :   nsplit(0),
      42      344869 :   nmatrix_cols(maxcol),
      43      344869 :   matrix_row_stash(nmat*maxcol,0),
      44      344869 :   matrix_force_stash(nder*nmat),
      45      344869 :   matrix_bookeeping(nbook,0),
      46      344869 :   matrix_row_nderivatives(nmat,0),
      47      344869 :   matrix_row_derivative_indices(nmat)
      48             : {
      49      388633 :   for(unsigned i=0; i<nmat; ++i) matrix_row_derivative_indices[i].resize( nder );
      50             :   // This is crap that will be deleted in future
      51      344869 :   std::vector<unsigned> myind( nder );
      52    99768807 :   for(unsigned i=0; i<nder; ++i) myind[i]=i;
      53      344869 : }
      54             : 
      55          36 : void MultiValue::resize( const size_t& nvals, const size_t& nder, const size_t& nmat, const size_t& maxcol, const size_t& nbook ) {
      56          36 :   values.resize(nvals); nderivatives=nder; derivatives.resize( nvals*nder );
      57          36 :   hasderiv.resize(nvals*nder,false); nactive.resize(nvals); active_list.resize(nvals*nder);
      58          36 :   nmatrix_cols=maxcol; matrix_row_stash.resize(nmat*maxcol,0); matrix_force_stash.resize(nmat*nder,0); matrix_bookeeping.resize(nbook, 0);
      59          36 :   matrix_row_nderivatives.resize(nmat,0); matrix_row_derivative_indices.resize(nmat); atLeastOneSet=false;
      60          36 :   for(unsigned i=0; i<nmat; ++i) matrix_row_derivative_indices[i].resize( nder );
      61             :   // All crap from here onwards
      62          36 :   tmpder.resize( nder ); std::vector<unsigned> myind( nder );
      63        6840 :   for(unsigned i=0; i<nder; ++i) myind[i]=i;
      64          36 : }
      65             : 
      66     6810512 : void MultiValue::clearAll() {
      67    36576302 :   for(unsigned i=0; i<values.size(); ++i) values[i]=0;
      68             :   // Clear matrix row
      69             :   std::fill( matrix_row_stash.begin(), matrix_row_stash.end(), 0 );
      70             :   // Clear matrix derivative indices
      71             :   std::fill( matrix_row_nderivatives.begin(), matrix_row_nderivatives.end(), 0 );
      72             :   // Clear matrix forces
      73             :   std::fill(matrix_force_stash.begin(),matrix_force_stash.end(),0);
      74     6810512 :   if( !atLeastOneSet ) return;
      75    29403410 :   for(unsigned i=0; i<values.size(); ++i) clearDerivatives(i);
      76     5521277 :   atLeastOneSet=false;
      77             : }
      78             : 
      79   128147747 : void MultiValue::clearDerivatives( const unsigned& ival ) {
      80   128147747 :   values[ival]=0;
      81   128147747 :   if( !atLeastOneSet ) return;
      82    69072184 :   unsigned base=ival*nderivatives;
      83   626107740 :   for(unsigned i=0; i<nactive[ival]; ++i) {
      84   557035556 :     unsigned k = base+active_list[base+i]; derivatives[k]=0.; hasderiv[k]=false;
      85             :   }
      86    69072184 :   nactive[ival]=0;
      87             : #ifndef NDEBUG
      88             :   for(unsigned i=0; i<nderivatives; ++i) {
      89             :     if( hasderiv[base+i] ) {
      90             :       std::string num1, num2;
      91             :       Tools::convert(ival,num1); Tools::convert(i,num2);
      92             :       plumed_merror("FAILING TO CLEAR VALUE " + num1 + " DERIVATIVE " + num2 + " IS PROBLEMATIC");
      93             :     }
      94             :     // As this is debugging code we hard code an escape here otherwise this check is really expensive
      95             :     if( i>1000 ) return;
      96             :   }
      97             : #endif
      98             : }
      99             : 
     100             : }

Generated by: LCOV version 1.16