LCOV - code coverage report
Current view: top level - matrixtools - MatrixOperationBase.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 32 36 88.9 %
Date: 2026-11-05 10:19:04 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         429 : void MatrixOperationBase::registerKeywords( Keywords& keys ) {
      28         429 :   Action::registerKeywords( keys );
      29         429 :   ActionWithArguments::registerKeywords( keys );
      30         429 :   ActionWithValue::registerKeywords( keys );
      31         858 :   keys.addInputKeyword("compulsory","ARG","matrix","the input matrix");
      32         429 :   keys.remove("NUMERICAL_DERIVATIVES");
      33         429 :   keys.addDeprecatedKeyword("MATRIX","ARG");
      34         429 : }
      35             : 
      36         244 : MatrixOperationBase::MatrixOperationBase(const ActionOptions&ao):
      37             :   Action(ao),
      38             :   ActionWithArguments(ao),
      39         244 :   ActionWithValue(ao) {
      40         244 :   if( getNumberOfArguments()!=1 ) {
      41           0 :     error("should only be one argument to this action");
      42             :   }
      43         244 :   if( getPntrToArgument(0)->getRank()!=2 || getPntrToArgument(0)->hasDerivatives() ) {
      44          17 :     if( getName()=="TRANSPOSE" ) {
      45          17 :       if (getPntrToArgument(0)->getRank()!=1 || getPntrToArgument(0)->hasDerivatives() ) {
      46           0 :         error("input to this argument should be a matrix or vector");
      47             :       }
      48             :     } else {
      49           0 :       error("input to this argument should be a matrix");
      50             :     }
      51             :   }
      52         244 : }
      53             : 
      54         824 : void MatrixOperationBase::retrieveFullMatrix( Matrix<double>& mymatrix ) {
      55         824 :   if( mymatrix.nrows()!=getPntrToArgument(0)->getShape()[0] || mymatrix.nrows()!=getPntrToArgument(0)->getShape()[1] ) {
      56           0 :     mymatrix.resize( getPntrToArgument(0)->getShape()[0], getPntrToArgument(0)->getShape()[1] );
      57             :   }
      58             :   unsigned nedge;
      59         824 :   getPntrToArgument(0)->retrieveEdgeList( nedge, MOBpairs, MOBvals  );
      60             :   mymatrix=0;
      61             :   bool symmetric = getPntrToArgument(0)->isSymmetric();
      62      389421 :   for(unsigned i=0; i<nedge; ++i ) {
      63      388597 :     mymatrix( MOBpairs[i].first, MOBpairs[i].second ) = MOBvals[i];
      64      388597 :     if( symmetric ) {
      65        6902 :       mymatrix( MOBpairs[i].second, MOBpairs[i].first ) = MOBvals[i];
      66             :     }
      67             :   }
      68         824 : }
      69             : 
      70             : 
      71         796 : void MatrixOperationBase::apply() {
      72         796 :   if( doNotCalculateDerivatives() ) {
      73             :     return;
      74             :   }
      75             : 
      76             :   bool forces=false;
      77         898 :   for(unsigned i=0; i<getNumberOfComponents(); ++i) {
      78         898 :     if( getPntrToComponent(i)->forcesWereAdded() ) {
      79             :       forces=true;
      80             :       break;
      81             :     }
      82             :   }
      83         796 :   if( !forces ) {
      84             :     return;
      85             :   }
      86             : 
      87             :   Value* mat = getPntrToArgument(0);
      88         796 :   unsigned ncols=mat->getNumberOfColumns();
      89        4957 :   for(unsigned i=0; i<mat->getShape()[0]; ++i) {
      90             :     unsigned ncol = mat->getRowLength(i);
      91       38322 :     for(unsigned j=0; j<ncol; ++j) {
      92       34161 :       mat->addForce( i*ncols+j, getForceOnMatrixElement( i, mat->getRowIndex(i,j) ), false );
      93             :     }
      94             :   }
      95             : }
      96             : 
      97             : 
      98             : }
      99             : }

Generated by: LCOV version 1.16