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 : void addValueWithDerivatives(); 44 : void addComponentWithDerivatives( const std::string& name ); 45 : public: 46 : explicit Function(const ActionOptions&); 47 686 : virtual ~Function() {} 48 : void apply() override; 49 : static void registerKeywords(Keywords&); 50 : unsigned getNumberOfDerivatives() override; 51 : }; 52 : 53 : inline 54 : void Function::setDerivative(Value*v,int i,double d) { 55 56539 : v->addDerivative(i,d); 56 0 : } 57 : 58 : inline 59 53629 : void Function::setDerivative(int i,double d) { 60 53629 : setDerivative(getPntrToValue(),i,d); 61 53629 : } 62 : 63 : inline 64 3471329 : unsigned Function::getNumberOfDerivatives() { 65 3471329 : return getNumberOfArguments(); 66 : } 67 : 68 : } 69 : } 70 : 71 : #endif 72 :