LCOV - code coverage report
Current view: top level - matrixtools - MatrixOperationBase.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 33 39 84.6 %
Date: 2025-12-04 11:19:34 Functions: 4 5 80.0 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2011-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 "MatrixOperationBase.h"
      23             : 
      24             : namespace PLMD {
      25             : namespace matrixtools {
      26             : 
      27         368 : void MatrixOperationBase::registerKeywords( Keywords& keys ) {
      28         368 :   Action::registerKeywords( keys );
      29         368 :   ActionWithArguments::registerKeywords( keys );
      30         368 :   ActionWithValue::registerKeywords( keys );
      31         736 :   keys.addInputKeyword("compulsory","ARG","matrix","the input matrix");
      32         368 :   keys.remove("NUMERICAL_DERIVATIVES");
      33         368 :   keys.addDeprecatedKeyword("MATRIX","ARG");
      34         368 : }
      35             : 
      36         214 : MatrixOperationBase::MatrixOperationBase(const ActionOptions&ao):
      37             :   Action(ao),
      38             :   ActionWithArguments(ao),
      39         214 :   ActionWithValue(ao) {
      40         214 :   if( getNumberOfArguments()==0 ) {
      41             :     std::vector<Value*> args;
      42           0 :     parseArgumentList("MATRIX",args);
      43           0 :     requestArguments(args);
      44             :   }
      45         214 :   if( getNumberOfArguments()!=1 ) {
      46           0 :     error("should only be one argument to this action");
      47             :   }
      48         214 :   if( getPntrToArgument(0)->getRank()!=2 || getPntrToArgument(0)->hasDerivatives() ) {
      49          17 :     if( getName()=="TRANSPOSE" ) {
      50          17 :       if (getPntrToArgument(0)->getRank()!=1 || getPntrToArgument(0)->hasDerivatives() ) {
      51           0 :         error("input to this argument should be a matrix or vector");
      52             :       }
      53             :     } else {
      54           0 :       error("input to this argument should be a matrix");
      55             :     }
      56             :   }
      57         214 : }
      58             : 
      59         717 : void MatrixOperationBase::retrieveFullMatrix( Matrix<double>& mymatrix ) {
      60         717 :   if( mymatrix.nrows()!=getPntrToArgument(0)->getShape()[0] || mymatrix.nrows()!=getPntrToArgument(0)->getShape()[1] ) {
      61           0 :     mymatrix.resize( getPntrToArgument(0)->getShape()[0], getPntrToArgument(0)->getShape()[1] );
      62             :   }
      63             :   unsigned nedge;
      64         717 :   getPntrToArgument(0)->retrieveEdgeList( nedge, MOBpairs, MOBvals  );
      65             :   mymatrix=0;
      66             :   bool symmetric = getPntrToArgument(0)->isSymmetric();
      67      379139 :   for(unsigned i=0; i<nedge; ++i ) {
      68      378422 :     mymatrix( MOBpairs[i].first, MOBpairs[i].second ) = MOBvals[i];
      69      378422 :     if( symmetric ) {
      70         714 :       mymatrix( MOBpairs[i].second, MOBpairs[i].first ) = MOBvals[i];
      71             :     }
      72             :   }
      73         717 : }
      74             : 
      75             : 
      76        2601 : void MatrixOperationBase::apply() {
      77        2601 :   if( doNotCalculateDerivatives() ) {
      78             :     return;
      79             :   }
      80             : 
      81             :   bool forces=false;
      82        2700 :   for(unsigned i=0; i<getNumberOfComponents(); ++i) {
      83        2700 :     if( getPntrToComponent(i)->forcesWereAdded() ) {
      84             :       forces=true;
      85             :       break;
      86             :     }
      87             :   }
      88        2598 :   if( !forces ) {
      89             :     return;
      90             :   }
      91             : 
      92             :   Value* mat = getPntrToArgument(0);
      93        2598 :   unsigned ncols=mat->getNumberOfColumns();
      94       65988 :   for(unsigned i=0; i<mat->getShape()[0]; ++i) {
      95             :     unsigned ncol = mat->getRowLength(i);
      96     1961960 :     for(unsigned j=0; j<ncol; ++j) {
      97     1898570 :       mat->addForce( i*ncols+j, getForceOnMatrixElement( i, mat->getRowIndex(i,j) ), false );
      98             :     }
      99             :   }
     100             : }
     101             : 
     102             : 
     103             : }
     104             : }

Generated by: LCOV version 1.16