diff --git a/src/core/ActionWithMatrix.cpp b/src/core/ActionWithMatrix.cpp index c67eb136ad..db6112dab0 100644 --- a/src/core/ActionWithMatrix.cpp +++ b/src/core/ActionWithMatrix.cpp @@ -98,20 +98,6 @@ void ActionWithMatrix::setupMatrixStore() { if( next_action_in_chain ) next_action_in_chain->setupMatrixStore(); } -int ActionWithMatrix::checkTaskIsActive( const unsigned& itask ) const { - int nm = getNumberOfMasks(); if( nm<0 ) return 1; - - // This checks for matrices that are masking some elements - unsigned nargs = getNumberOfArguments(); - if( nm==1 && getPntrToArgument(nargs-1)->getRank()==2 ) return 1; - - for(unsigned j=nargs-nm; jgetRank()==1 ); - if( fabs(getPntrToArgument(j)->get(itask))>0 ) return 1; - } - return 0; -} - void ActionWithMatrix::calculate() { if( actionInChain() ) return ; // Update all the neighbour lists diff --git a/src/core/ActionWithMatrix.h b/src/core/ActionWithMatrix.h index 2141187d07..b5a870ba2c 100644 --- a/src/core/ActionWithMatrix.h +++ b/src/core/ActionWithMatrix.h @@ -60,8 +60,6 @@ class ActionWithMatrix : public ActionWithVector { virtual ~ActionWithMatrix(); /// virtual bool isAdjacencyMatrix() const { return false; } -/// - virtual int checkTaskIsActive( const unsigned& itask ) const ; /// void getAllActionLabelsInMatrixChain( std::vector& mylabels ) const override ; /// Get the first matrix in this chain diff --git a/src/core/ActionWithVector.cpp b/src/core/ActionWithVector.cpp index e820f46ec7..a7105c37a9 100644 --- a/src/core/ActionWithVector.cpp +++ b/src/core/ActionWithVector.cpp @@ -436,12 +436,34 @@ void ActionWithVector::prepare() { } int ActionWithVector::checkTaskIsActive( const unsigned& itask ) const { - for(unsigned i=0; igetRank()==0 ) continue; - else if( myarg->getRank()==1 && !myarg->hasDerivatives() ) { - if( fabs(myarg->get(itask))>0 ) return 1; - } else plumed_merror("should not be in action " + getName() ); + unsigned nargs = getNumberOfArguments(); + if( nmask>0 ) { + for(unsigned j=nargs-nmask; jgetRank()==1 && !myarg->hasDerivatives() ) { + if( fabs(myarg->get(itask))>0 ) return 1; + } else if( myarg->getRank()==2 && !myarg->hasDerivatives() ) { + unsigned ncol = myarg->getRowLength(itask); + unsigned base = itask*myarg->getNumberOfColumns(); + for(unsigned k=0; kget(base+k,false))>0 ) return 1; + } + } else plumed_merror("only matrices and vectors should be used as masks"); + } + } else { + for(unsigned i=0; igetRank()==0 ) continue; + else if( myarg->getRank()==1 && !myarg->hasDerivatives() ) { + if( fabs(myarg->get(itask))>0 ) return 1; + } else if( myarg->getRank()==2 && !myarg->hasDerivatives() ) { + unsigned ncol = myarg->getRowLength(itask); + unsigned base = itask*myarg->getNumberOfColumns(); + for(unsigned k=0; kget(base+k,false))>0 ) return 1; + } + } else plumed_merror("should not be in action " + getName() ); + } } return -1; } diff --git a/src/core/ActionWithVector.h b/src/core/ActionWithVector.h index e783dec244..97fc7e17e2 100644 --- a/src/core/ActionWithVector.h +++ b/src/core/ActionWithVector.h @@ -99,6 +99,8 @@ class ActionWithVector: bool atomsWereRetrieved; /// This is used to build the argument store when we cannot use the chain unsigned reallyBuildArgumentStore( const unsigned& argstart ); +/// Determine if a particular task is active based on the values of the input argument + int checkTaskIsActive( const unsigned& itask ) const ; protected: /// A vector that contains the start point for the argument derivatives std::vector arg_deriv_starts; @@ -131,8 +133,6 @@ class ActionWithVector: /// Check if a mask has been set int getNumberOfMasks() const ; void calculateNumericalDerivatives(ActionWithValue* av) override; -/// Determine if a particular task is active based on the values of the input argument - virtual int checkTaskIsActive( const unsigned& itask ) const ; /// Turn off the calculation of the derivatives during the forward pass through a calculation bool doNotCalculateDerivatives() const override ; /// Are we running this command in a chain diff --git a/src/function/FunctionOfMatrix.h b/src/function/FunctionOfMatrix.h index e356eccdde..8050347a5c 100644 --- a/src/function/FunctionOfMatrix.h +++ b/src/function/FunctionOfMatrix.h @@ -56,8 +56,6 @@ class FunctionOfMatrix : public ActionWithMatrix { void turnOnDerivatives() override; /// Get the number of derivatives for this action unsigned getNumberOfDerivatives() override ; -/// Check if the task is active - int checkTaskIsActive( const unsigned& itask ) const override ; /// Resize the matrices void prepare() override ; /// This gets the number of columns @@ -232,17 +230,6 @@ unsigned FunctionOfMatrix::getNumberOfColumns() const { plumed_error(); return 0; } -template -int FunctionOfMatrix::checkTaskIsActive( const unsigned& itask ) const { - const ActionWithVector* av=dynamic_cast( getPntrToArgument(0)->getPntrToAction() ); - unsigned status=1; if( av ) status = av->checkTaskIsActive( itask ); - for(unsigned i=1; i( getPntrToArgument(i)->getPntrToAction() ); - if( av && status!=av->checkTaskIsActive( itask ) ) plumed_merror("this doesn't work"); - } - return status; -} - template void FunctionOfMatrix::setupForTask( const unsigned& task_index, std::vector& indices, MultiValue& myvals ) const { int ncols = -1, basemat=-1; bool redo=false; diff --git a/src/matrixtools/MatrixTimesVector.cpp b/src/matrixtools/MatrixTimesVector.cpp index addabc5a29..dc995f4372 100644 --- a/src/matrixtools/MatrixTimesVector.cpp +++ b/src/matrixtools/MatrixTimesVector.cpp @@ -46,7 +46,6 @@ class MatrixTimesVector : public ActionWithMatrix { unsigned getNumberOfColumns() const override { plumed_error(); } void getNumberOfStreamedDerivatives( unsigned& nderivatives, Value* stopat ) override ; unsigned getNumberOfDerivatives() override ; - int checkTaskIsActive( const unsigned& itask ) const override ; void prepare() override ; void performTask( const unsigned& task_index, MultiValue& myvals ) const override ; bool isInSubChain( unsigned& nder ) override { nder = arg_deriv_starts[0]; return true; } @@ -169,19 +168,6 @@ void MatrixTimesVector::prepare() { std::vector shape(1); shape[0] = getPntrToArgument(0)->getShape()[0]; myval->setShape(shape); } -int MatrixTimesVector::checkTaskIsActive( const unsigned& itask ) const { - if( getPntrToArgument(1)->getRank()==1 ) { - ActionWithMatrix* am=dynamic_cast( getPntrToArgument(0)->getPntrToAction() ); - plumed_assert( am ); return am->checkTaskIsActive(itask); - } else { - unsigned n=getNumberOfArguments()-1; - for(unsigned i=0; i( getPntrToArgument(i)->getPntrToAction() ); - plumed_assert( am ); if( am->checkTaskIsActive(itask)>0 ) return 1; - } - } -} - void MatrixTimesVector::getNumberOfStreamedDerivatives( unsigned& nderivatives, Value* stopat ) { if( actionInChain() ) { ActionWithVector::getNumberOfStreamedDerivatives( nderivatives, stopat ); return; }