LCOV - code coverage report
Current view: top level - function - Function.h (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 8 9 88.9 %
Date: 2024-10-18 14:00:25 Functions: 3 3 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_function_Function_h
      23             : #define __PLUMED_function_Function_h
      24             : 
      25             : #include "core/ActionWithValue.h"
      26             : #include "core/ActionWithArguments.h"
      27             : 
      28             : namespace PLMD {
      29             : namespace function {
      30             : 
      31             : /**
      32             : \ingroup INHERIT
      33             : This is the abstract base class to use for implementing new CV function, within it there is
      34             : \ref AddingAFunction "information" as to how to go about implementing a new function.
      35             : */
      36             : 
      37             : class Function:
      38             :   public ActionWithValue,
      39             :   public ActionWithArguments
      40             : {
      41             : protected:
      42             :   void setDerivative(int,double);
      43             :   void setDerivative(Value*,int,double);
      44             :   void addValueWithDerivatives();
      45             :   void addComponentWithDerivatives( const std::string& name );
      46             : public:
      47             :   explicit Function(const ActionOptions&);
      48        1525 :   virtual ~Function() {}
      49             :   double getArgument( const unsigned& iarg );
      50             :   void apply() override;
      51             :   static void registerKeywords(Keywords&);
      52             :   unsigned getNumberOfDerivatives() override;
      53             : };
      54             : 
      55             : inline
      56             : void Function::setDerivative(Value*v,int i,double d) {
      57        2867 :   v->addDerivative(i,d);
      58           0 : }
      59             : 
      60             : inline
      61             : void Function::setDerivative(int i,double d) {
      62             :   setDerivative(getPntrToValue(),i,d);
      63             : }
      64             : 
      65             : inline
      66      278605 : unsigned Function::getNumberOfDerivatives() {
      67             :   unsigned narg=0;
      68     4982503 :   for(unsigned i=0; i<getNumberOfArguments(); ++i) {
      69     4703898 :     if( getPntrToArgument(i)->getRank()==0 ) narg++;
      70             :   }
      71      278605 :   return narg;
      72             : }
      73             : 
      74             : inline
      75       24190 : double Function::getArgument( const unsigned& iarg ) {
      76       24190 :   return getPntrToArgument(iarg)->get();
      77             : }
      78             : 
      79             : }
      80             : }
      81             : 
      82             : #endif
      83             : 

Generated by: LCOV version 1.16