LCOV - code coverage report
Current view: top level - core - ActionWithArguments.h (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 15 15 100.0 %
Date: 2024-10-11 08:09:47 Functions: 5 5 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 ActionWithArguments:
      43             :   public virtual Action
      44             : {
      45             :   std::vector<Value*> arguments;
      46             :   bool lockRequestArguments;
      47             : protected:
      48             : /// This changes the arg keyword in the pdb file
      49             :   void expandArgKeywordInPDB( const PDB& pdb );
      50             : public:
      51             : /// Get the scalar product between the gradients of two variables
      52             :   double getProjection(unsigned i,unsigned j)const;
      53             : /// Registers the list of keywords
      54             :   static void registerKeywords( Keywords& keys );
      55             : /// Returns the value of an argument
      56             :   double getArgument( const unsigned n ) const;
      57             : /// Return a pointer to specific argument
      58             :   Value* getPntrToArgument( const unsigned n );
      59             : /// Returns the number of arguments
      60             :   virtual unsigned getNumberOfArguments() const ;
      61             : /// Takes the difference taking into account pbc for arg i
      62             :   double difference(int, double, double) const;
      63             : /// Takes one value and brings it back into the pbc of argument i
      64             :   double bringBackInPbc(int i,double d1)const;
      65             : /// Parse a list of arguments
      66             :   void parseArgumentList(const std::string&key,std::vector<Value*>&args);
      67             : /// Parse a numbered list of arguments
      68             :   bool parseArgumentList(const std::string&key,int i,std::vector<Value*>&args);
      69             : /// Setup the dependencies
      70             :   void requestArguments(const std::vector<Value*> &arg);
      71             :   void requestExtraDependencies(const std::vector<Value*> &extra);
      72             : /// Add forces to arguments (used in apply)
      73             :   void addForcesOnArguments( const std::vector<double>& forces );
      74             : public:
      75             :   explicit ActionWithArguments(const ActionOptions&);
      76        2805 :   virtual ~ActionWithArguments() {}
      77             : /// Calculate the numerical derivatives
      78             : /// N.B. only pass an ActionWithValue to this routine if you know exactly what you
      79             : /// are doing.  The default will be correct for the vast majority of cases
      80             :   void calculateNumericalDerivatives( ActionWithValue* a=NULL ) override;
      81             :   void lockRequests() override;
      82             :   void unlockRequests() override;
      83             : /// Returns an array of pointers to the arguments
      84             :   virtual const std::vector<Value*>    & getArguments() const ;
      85             : /// Convert a list of argument names into a list of pointers to the values
      86             :   void interpretArgumentList(const std::vector<std::string>& c, std::vector<Value*>&arg);
      87             : };
      88             : 
      89             : 
      90             : inline
      91             : Value* ActionWithArguments::getPntrToArgument( const unsigned n ) {
      92     4175208 :   return arguments[n];
      93             : }
      94             : 
      95             : inline
      96             : double ActionWithArguments::getArgument(const unsigned n) const {
      97      823666 :   return arguments[n]->get();
      98             : }
      99             : 
     100             : inline
     101  4120418704 : unsigned ActionWithArguments::getNumberOfArguments()const {
     102  4120436323 :   return arguments.size();
     103             : }
     104             : 
     105             : inline
     106             : double ActionWithArguments::difference(int i,double d1,double d2)const {
     107     4858706 :   return arguments[i]->difference(d1,d2);
     108             : }
     109             : 
     110             : inline
     111             : double ActionWithArguments::bringBackInPbc(int i,double d1)const {
     112        1427 :   return arguments[i]->bringBackInPbc(d1);
     113             : }
     114             : 
     115             : inline
     116      538111 : void ActionWithArguments::lockRequests() {
     117      552684 :   lockRequestArguments=true;
     118      538111 : }
     119             : 
     120             : inline
     121      538111 : void ActionWithArguments::unlockRequests() {
     122      552684 :   lockRequestArguments=false;
     123      538111 : }
     124             : 
     125             : inline
     126      458199 : const std::vector<Value*> & ActionWithArguments::getArguments() const {
     127      462012 :   return arguments;
     128             : }
     129             : 
     130             : }
     131             : 
     132             : #endif

Generated by: LCOV version 1.15