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 : protected: 41 : void setDerivative(int,double); 42 : void setDerivative(Value*,int,double); 43 : //overriding explicitly the two functions avoids the [-Woverloaded-virtual] warning 44 : /// the shape argument will be ignored 45 : void addValueWithDerivatives( const std::vector<std::size_t>& =std::vector<std::size_t>() ) override; 46 : /// the shape will be ignored 47 : void addComponentWithDerivatives( const std::string& valname, const std::vector<std::size_t>& =std::vector<std::size_t>() )override; 48 : public: 49 : explicit Function(const ActionOptions&); 50 2887 : virtual ~Function() {} 51 : double getArgument( const unsigned& iarg ); 52 : void apply() override; 53 : static void registerKeywords(Keywords&); 54 : unsigned getNumberOfDerivatives() override; 55 : }; 56 : 57 : inline 58 : void Function::setDerivative(Value*v,int i,double d) { 59 : v->addDerivative(i,d); 60 1152 : } 61 : 62 : inline 63 : void Function::setDerivative(int i,double d) { 64 : setDerivative(getPntrToValue(),i,d); 65 : } 66 : 67 : inline 68 305500 : unsigned Function::getNumberOfDerivatives() { 69 : unsigned narg=0; 70 6799058 : for(unsigned i=0; i<getNumberOfArguments(); ++i) { 71 6493558 : narg += getPntrToArgument(i)->getNumberOfStoredValues(); 72 : } 73 305500 : return narg; 74 : } 75 : 76 : inline 77 30735 : double Function::getArgument( const unsigned& iarg ) { 78 30735 : return getPntrToArgument(iarg)->get(); 79 : } 80 : 81 : } 82 : } 83 : 84 : #endif 85 :