Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2013-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 "VesselRegister.h" 23 : #include "FunctionVessel.h" 24 : #include "ActionWithVessel.h" 25 : 26 : namespace PLMD { 27 : namespace vesselbase { 28 : 29 : class Min : public FunctionVessel { 30 : private: 31 : double beta; 32 : public: 33 : static void registerKeywords( Keywords& keys ); 34 : static void reserveKeyword( Keywords& keys ); 35 : explicit Min( const VesselOptions& da ); 36 : std::string value_descriptor() override; 37 : double calcTransform( const double& val, double& dv ) const override; 38 : double finalTransform( const double& val, double& dv ) override; 39 : }; 40 : 41 10421 : PLUMED_REGISTER_VESSEL(Min,"MIN") 42 : 43 2 : void Min::registerKeywords( Keywords& keys ) { 44 2 : FunctionVessel::registerKeywords( keys ); 45 4 : keys.add("compulsory","BETA","the value of beta for the equation in the manual"); 46 2 : } 47 : 48 3473 : void Min::reserveKeyword( Keywords& keys ) { 49 6946 : keys.reserve("vessel","MIN","calculate the minimum value. " 50 : "To make this quantity continuous the minimum is calculated using " 51 : "\\f$ \\textrm{min} = \\frac{\\beta}{ \\log \\sum_i \\exp\\left( \\frac{\\beta}{s_i} \\right) } \\f$ " 52 : "The value of \\f$\\beta\\f$ in this function is specified using (BETA=\\f$\\beta\\f$)"); 53 6946 : keys.addOutputComponent("min","MIN","the minimum value. This is calculated using the formula described in the description of the " 54 : "keyword so as to make it continuous."); 55 3473 : } 56 : 57 2 : Min::Min( const VesselOptions& da ) : 58 2 : FunctionVessel(da) 59 : { 60 2 : if( getAction()->isPeriodic() ) error("min is not a meaningful option for periodic variables"); 61 2 : parse("BETA",beta); 62 : 63 2 : if( diffweight ) error("can't calculate min if weight is differentiable"); 64 2 : } 65 : 66 2 : std::string Min::value_descriptor() { 67 2 : std::string str_beta; Tools::convert( beta, str_beta ); 68 4 : return "the minimum value. Beta is equal to " + str_beta; 69 : } 70 : 71 10 : double Min::calcTransform( const double& val, double& dv ) const { 72 10 : double f = exp(beta/val); dv=f/(val*val); 73 10 : return f; 74 : } 75 : 76 5 : double Min::finalTransform( const double& val, double& dv ) { 77 5 : double dist=beta/std::log( val ); 78 5 : dv = dist*dist/val; return dist; 79 : } 80 : 81 : } 82 : }