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 5109 : void Function::registerKeywords(Keywords& keys) { 30 5109 : Action::registerKeywords(keys); 31 5109 : ActionWithValue::registerKeywords(keys); 32 5109 : ActionWithArguments::registerKeywords(keys); 33 10218 : keys.addInputKeyword("compulsory","ARG","scalar","the labels of the values from which the function is calculated"); 34 5109 : 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"); 35 5109 : } 36 : 37 2895 : Function::Function(const ActionOptions&ao): 38 : Action(ao), 39 : ActionWithValue(ao), 40 2895 : ActionWithArguments(ao) { 41 2895 : } 42 : 43 2383 : void Function::addValueWithDerivatives(const std::vector<std::size_t>& /* shape */) { 44 : //the shape argument is ignored (shall I put here a warning?) 45 2383 : plumed_massert( getNumberOfArguments()!=0, "for functions you must requestArguments before adding values"); 46 2383 : ActionWithValue::addValueWithDerivatives(); 47 2383 : getPntrToValue()->resizeDerivatives(getNumberOfDerivatives()); 48 2383 : } 49 : 50 3685 : void Function::addComponentWithDerivatives( const std::string& compName, const std::vector<std::size_t>& /* shape */) { 51 : //the shape argument is ignored (shall I put here a warning?) 52 3685 : plumed_massert( getNumberOfArguments()!=0, "for functions you must requestArguments before adding values"); 53 3685 : ActionWithValue::addComponentWithDerivatives(compName); 54 3685 : getPntrToComponent(compName)->resizeDerivatives(getNumberOfDerivatives()); 55 3685 : } 56 : 57 287289 : void Function::apply() { 58 287289 : if( !checkForForces() ) { 59 210123 : return; 60 : } 61 77166 : unsigned ind=0; 62 77166 : addForcesOnArguments( 0, getForcesToApply(), ind ); 63 : } 64 : 65 : } 66 : }