LCOV - code coverage report
Current view: top level - core - ActionWithArguments.h (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 18 18 100.0 %
Date: 2025-03-25 09:33:27 Functions: 7 7 100.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             : #ifndef __PLUMED_core_ActionWithArguments_h
      23             : #define __PLUMED_core_ActionWithArguments_h
      24             : 
      25             : #include "Action.h"
      26             : #include "Value.h"
      27             : #include <vector>
      28             : 
      29             : namespace PLMD {
      30             : 
      31             : /**
      32             : \ingroup MULTIINHERIT
      33             : This is used to create PLMD::Action objects that take the output from some other Action as input.
      34             : This is used in PLMD::Function and PLMD::Bias
      35             :  PLMD::Action objects that inherit from PLMD::ActionWithArguments take
      36             :  values and components calculated in other PLMD::Action objects and
      37             :  use this information to calculate some new function.  If you have
      38             :  only one list of arguments you should use the reserved keyword <b> ARG </b>
      39             :  when you use parseArgumentList.
      40             : */
      41             : 
      42             : class ActionSet;
      43             : 
      44             : class ActionWithArguments:
      45             :   public virtual Action {
      46             :   std::vector<Value*> arguments;
      47             :   bool lockRequestArguments;
      48             : protected:
      49             : /// This changes the arg keyword in the pdb file
      50             :   void expandArgKeywordInPDB( const PDB& pdb );
      51             : public:
      52             : /// Get the scalar product between the gradients of two variables
      53             :   double getProjection(unsigned i,unsigned j)const;
      54             : /// Registers the list of keywords
      55             :   static void registerKeywords( Keywords& keys );
      56             : /// Returns the value of an argument
      57             :   double getArgument( const unsigned n ) const;
      58             : /// Return a pointer to specific argument
      59             :   Value* getPntrToArgument( const unsigned n ) const;
      60             : /// Returns the number of arguments
      61             :   virtual unsigned getNumberOfArguments() const ;
      62             : /// Takes the difference taking into account pbc for arg i
      63             :   double difference(int, double, double) const;
      64             : /// Takes one value and brings it back into the pbc of argument i
      65             :   double bringBackInPbc(int i,double d1)const;
      66             : /// Parse a list of arguments
      67             :   void parseArgumentList(const std::string&key,std::vector<Value*>&args);
      68             : /// Parse a numbered list of arguments
      69             :   bool parseArgumentList(const std::string&key,int i,std::vector<Value*>&args);
      70             : /// Setup the dependencies
      71             :   void requestArguments(const std::vector<Value*> &arg);
      72             :   void requestExtraDependencies(const std::vector<Value*> &extra);
      73             : /// Add forces to arguments (used in apply)
      74             :   void addForcesOnArguments( const unsigned& argstart, const std::vector<double>& forces, unsigned& ind, const std::string& c );
      75             : public:
      76             :   explicit ActionWithArguments(const ActionOptions&);
      77       10317 :   virtual ~ActionWithArguments() {}
      78             : /// Calculate the numerical derivatives
      79             : /// N.B. only pass an ActionWithValue to this routine if you know exactly what you
      80             : /// are doing.  The default will be correct for the vast majority of cases
      81             :   void calculateNumericalDerivatives( ActionWithValue* a=NULL ) override;
      82             :   void lockRequests() override;
      83             :   void unlockRequests() override;
      84             : /// Returns an array of pointers to the arguments
      85             :   virtual const std::vector<Value*>    & getArguments() const ;
      86             : /// Convert a list of argument names into a list of pointers to the values
      87             :   static void interpretArgumentList(const std::vector<std::string>& c, const ActionSet& as, Action* action, std::vector<Value*>&arg);
      88             : /// Used to calculate constant values in startup
      89             :   virtual bool calculateConstantValues( const bool& have_atoms );
      90             : /// Get the gradient for this action
      91             :   void setGradients( Value* myval, unsigned& start ) const ;
      92       21362 :   ActionWithArguments* castToActionWithArguments() noexcept final {
      93       21362 :     return this;
      94             :   }
      95             : };
      96             : 
      97             : 
      98             : inline
      99             : Value* ActionWithArguments::getPntrToArgument( const unsigned n ) const {
     100   972102985 :   return arguments[n];
     101             : }
     102             : 
     103             : inline
     104      210398 : double ActionWithArguments::getArgument(const unsigned n) const {
     105      210398 :   return arguments[n]->get();
     106             : }
     107             : 
     108             : inline
     109   619507403 : unsigned ActionWithArguments::getNumberOfArguments()const {
     110   619544361 :   return arguments.size();
     111             : }
     112             : 
     113             : inline
     114             : double ActionWithArguments::difference(int i,double d1,double d2)const {
     115    11462283 :   return arguments[i]->difference(d1,d2);
     116             : }
     117             : 
     118             : inline
     119             : double ActionWithArguments::bringBackInPbc(int i,double d1)const {
     120        1427 :   return arguments[i]->bringBackInPbc(d1);
     121             : }
     122             : 
     123             : inline
     124      682175 : void ActionWithArguments::lockRequests() {
     125      966043 :   lockRequestArguments=true;
     126      682175 : }
     127             : 
     128             : inline
     129      682175 : void ActionWithArguments::unlockRequests() {
     130      966043 :   lockRequestArguments=false;
     131      682175 : }
     132             : 
     133             : inline
     134      186482 : const std::vector<Value*> & ActionWithArguments::getArguments() const {
     135      186913 :   return arguments;
     136             : }
     137             : 
     138             : }
     139             : 
     140             : #endif

Generated by: LCOV version 1.16