LCOV - code coverage report
Current view: top level - vesselbase - Max.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 Max : public FunctionVessel {
      30             : private:
      31             :   double beta;
      32             : public:
      33             :   static void registerKeywords( Keywords& keys );
      34             :   static void reserveKeyword( Keywords& keys );
      35             :   explicit Max( 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       13788 : PLUMED_REGISTER_VESSEL(Max,"MAX")
      42             : 
      43           3 : void Max::registerKeywords( Keywords& keys ) {
      44           3 :   FunctionVessel::registerKeywords( keys );
      45           6 :   keys.add("compulsory","BETA","the value of beta for the equation in the manual");
      46           3 : }
      47             : 
      48        4595 : void Max::reserveKeyword( Keywords& keys ) {
      49        9190 :   keys.reserve("vessel","MAX","calculate the maximum value. "
      50             :                "To make this quantity continuous the maximum is calculated using "
      51             :                "\\f$ \\textrm{max} = \\beta \\log \\sum_i \\exp\\left( \\frac{s_i}{\\beta}\\right) \\f$ "
      52             :                "The value of \\f$\\beta\\f$ in this function is specified using (BETA=\\f$\\beta\\f$)");
      53        9190 :   keys.addOutputComponent("max","MAX","the maximum value. This is calculated using the formula described in the description of the "
      54             :                           "keyword so as to make it continuous.");
      55             : 
      56        4595 : }
      57             : 
      58           3 : Max::Max( const VesselOptions& da ) :
      59           3 :   FunctionVessel(da) {
      60           3 :   if( getAction()->isPeriodic() ) {
      61           0 :     error("max is not a meaningful option for periodic variables");
      62             :   }
      63           3 :   parse("BETA",beta);
      64             : 
      65           3 :   if( diffweight ) {
      66           0 :     error("can't calculate max if weight is differentiable");
      67             :   }
      68           3 : }
      69             : 
      70           3 : std::string Max::value_descriptor() {
      71             :   std::string str_beta;
      72           3 :   Tools::convert( beta, str_beta );
      73           6 :   return "the maximum value. Beta is equal to " + str_beta;
      74             : }
      75             : 
      76          13 : double Max::calcTransform( const double& val, double& dv ) const {
      77          13 :   double f = exp(val/beta);
      78          13 :   dv=f/beta;
      79          13 :   return f;
      80             : }
      81             : 
      82           6 : double Max::finalTransform( const double& val, double& dv ) {
      83           6 :   double dist=beta*std::log( val );
      84           6 :   dv = beta/val;
      85           6 :   return dist;
      86             : }
      87             : 
      88             : }
      89             : }

Generated by: LCOV version 1.16