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 : #include "Function.h" 23 : #include "tools/OpenMP.h" 24 : #include "tools/Communicator.h" 25 : 26 : namespace PLMD { 27 : namespace function { 28 : 29 3055 : void Function::registerKeywords(Keywords& keys) { 30 3055 : Action::registerKeywords(keys); 31 3055 : ActionWithValue::registerKeywords(keys); 32 3055 : ActionWithArguments::registerKeywords(keys); 33 6110 : keys.reserve("compulsory","PERIODIC","if the output of your function is periodic then you should specify the periodicity of the function. If the output is not periodic you must state this using PERIODIC=NO"); 34 3055 : } 35 : 36 1527 : Function::Function(const ActionOptions&ao): 37 : Action(ao), 38 : ActionWithValue(ao), 39 1527 : ActionWithArguments(ao) { 40 1527 : } 41 : 42 1427 : void Function::addValueWithDerivatives() { 43 1427 : plumed_massert( getNumberOfArguments()!=0, "for functions you must requestArguments before adding values"); 44 2854 : ActionWithValue::addValueWithDerivatives(); 45 1427 : getPntrToValue()->resizeDerivatives(getNumberOfArguments()); 46 1427 : } 47 : 48 3177 : void Function::addComponentWithDerivatives( const std::string& name ) { 49 3177 : plumed_massert( getNumberOfArguments()!=0, "for functions you must requestArguments before adding values"); 50 3177 : ActionWithValue::addComponentWithDerivatives(name); 51 3177 : getPntrToComponent(name)->resizeDerivatives(getNumberOfArguments()); 52 3177 : } 53 : 54 270318 : void Function::apply() { 55 270318 : if( !checkForForces() ) { 56 206482 : return; 57 : } 58 63836 : unsigned ind=0; 59 63836 : addForcesOnArguments( 0, getForcesToApply(), ind, getLabel() ); 60 : } 61 : 62 : } 63 : }