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_bias_Bias_h 23 : #define __PLUMED_bias_Bias_h 24 : 25 : #include "core/ActionPilot.h" 26 : #include "core/ActionWithValue.h" 27 : #include "core/ActionWithArguments.h" 28 : 29 : #define PLUMED_BIAS_INIT(ao) Action(ao),Bias(ao) 30 : 31 : namespace PLMD { 32 : namespace bias { 33 : 34 : /** 35 : \ingroup INHERIT 36 : This is the abstract base class to use for implementing new simulation biases, within it there is 37 : information as to how to go about implementing a new bias. 38 : */ 39 : 40 : class Bias : 41 : public ActionPilot, 42 : public ActionWithValue, 43 : public ActionWithArguments 44 : { 45 : /// the vector of the forces 46 : std::vector<double> outputForces; 47 : /// the pointer to the bias component 48 : Value *valueBias; 49 : protected: 50 : /// set the force from the bias on argument i, this automatically set the partial derivative of the bias with respect to i to -f 51 : void setOutputForce(int i,double f); 52 : /// set the value of the bias 53 : void setBias(double bias); 54 : public: 55 : static void registerKeywords(Keywords&); 56 : explicit Bias(const ActionOptions&ao); 57 : void apply() override; 58 : unsigned getNumberOfDerivatives() override; 59 : }; 60 : 61 : inline 62 : void Bias::setOutputForce(int i,double f) { 63 141261 : outputForces[i]=f; 64 142327 : valueBias->addDerivative(i,-f); 65 : } 66 : 67 : inline 68 : void Bias::setBias(double bias) { 69 78315 : valueBias->set(bias); 70 38413 : } 71 : 72 : inline 73 790 : unsigned Bias::getNumberOfDerivatives() { 74 790 : return getNumberOfArguments(); 75 : } 76 : 77 : } 78 : } 79 : 80 : #endif 81 :