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 : /// the vector of the forces 45 : std::vector<double> outputForces; 46 : /// the pointer to the bias component 47 : Value *valueBias; 48 : std::vector<double> f; 49 : std::vector<double> forces; 50 : protected: 51 : /// set the force from the bias on argument i, this automatically set the partial derivative of the bias with respect to i to -f 52 : void setOutputForce(int i,double f); 53 : /// set the value of the bias 54 : void setBias(double bias); 55 : public: 56 : static void registerKeywords(Keywords&); 57 : explicit Bias(const ActionOptions&ao); 58 : void apply() override; 59 : unsigned getNumberOfDerivatives() override; 60 : /// Biases may depend on time/history even when all arguments are constant. 61 : /// Evaluate them during the simulation, after derived-class construction. 62 2666 : bool calculateConstantValues(const bool&) override { 63 2666 : return false; 64 : } 65 : }; 66 : 67 : inline 68 307615 : void Bias::setOutputForce(int i,double f) { 69 307615 : outputForces[i]=f; 70 307615 : valueBias->addDerivative(i,-f); 71 307615 : } 72 : 73 : inline 74 167040 : void Bias::setBias(double bias) { 75 167040 : valueBias->set(bias); 76 167040 : } 77 : 78 : inline 79 1433 : unsigned Bias::getNumberOfDerivatives() { 80 1433 : return getNumberOfArguments(); 81 : } 82 : 83 : } 84 : } 85 : 86 : #endif 87 :