LCOV - code coverage report
Current view: top level - vesselbase - Min.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 26 28 92.9 %
Date: 2026-03-30 13:16:06 Functions: 9 9 100.0 %

          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       13787 : 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        4595 : void Min::reserveKeyword( Keywords& keys ) {
      49        9190 :   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        9190 :   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        4595 : }
      56             : 
      57           2 : Min::Min( const VesselOptions& da ) :
      58           2 :   FunctionVessel(da) {
      59           2 :   if( getAction()->isPeriodic() ) {
      60           0 :     error("min is not a meaningful option for periodic variables");
      61             :   }
      62           2 :   parse("BETA",beta);
      63             : 
      64           2 :   if( diffweight ) {
      65           0 :     error("can't calculate min if weight is differentiable");
      66             :   }
      67           2 : }
      68             : 
      69           2 : std::string Min::value_descriptor() {
      70             :   std::string str_beta;
      71           2 :   Tools::convert( beta, str_beta );
      72           4 :   return "the minimum value. Beta is equal to " + str_beta;
      73             : }
      74             : 
      75          10 : double Min::calcTransform( const double& val, double& dv ) const {
      76          10 :   double f = exp(beta/val);
      77          10 :   dv=f/(val*val);
      78          10 :   return f;
      79             : }
      80             : 
      81           5 : double Min::finalTransform( const double& val, double& dv ) {
      82           5 :   double dist=beta/std::log( val );
      83           5 :   dv = dist*dist/val;
      84           5 :   return dist;
      85             : }
      86             : 
      87             : }
      88             : }

Generated by: LCOV version 1.16