LCOV - code coverage report
Current view: top level - vesselbase - Max.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 25 25 100.0 %
Date: 2018-12-19 07:49:13 Functions: 13 13 100.0 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2013-2018 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           6 : 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();
      37             :   double calcTransform( const double& val, double& dv ) const ;
      38             :   double finalTransform( const double& val, double& dv );
      39             : };
      40             : 
      41        2526 : PLUMED_REGISTER_VESSEL(Max,"MAX")
      42             : 
      43           3 : void Max::registerKeywords( Keywords& keys ) {
      44           3 :   FunctionVessel::registerKeywords( keys );
      45           3 :   keys.add("compulsory","BETA","the value of beta for the equation in the manual");
      46           3 : }
      47             : 
      48         841 : void Max::reserveKeyword( Keywords& keys ) {
      49             :   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         841 :                "The value of \\f$\\beta\\f$ in this function is specified using (BETA=\\f$\\beta\\f$)");
      53             :   keys.addOutputComponent("max","MAX","the maximum value. This is calculated using the formula described in the description of the "
      54         841 :                           "keyword so as to make it continuous.");
      55             : 
      56         841 : }
      57             : 
      58           3 : Max::Max( const VesselOptions& da ) :
      59           3 :   FunctionVessel(da)
      60             : {
      61           3 :   if( getAction()->isPeriodic() ) error("max is not a meaningful option for periodic variables");
      62           3 :   parse("BETA",beta);
      63             : 
      64           3 :   if( diffweight ) error("can't calculate max if weight is differentiable");
      65           3 : }
      66             : 
      67           3 : std::string Max::value_descriptor() {
      68           3 :   std::string str_beta; Tools::convert( beta, str_beta );
      69           3 :   return "the maximum value. Beta is equal to " + str_beta;
      70             : }
      71             : 
      72          13 : double Max::calcTransform( const double& val, double& dv ) const {
      73          13 :   double f = exp(val/beta); dv=f/beta; return f;
      74             : }
      75             : 
      76           6 : double Max::finalTransform( const double& val, double& dv ) {
      77           6 :   double dist=beta*std::log( val );
      78           6 :   dv = beta/val; return dist;
      79             : }
      80             : 
      81             : }
      82        2523 : }

Generated by: LCOV version 1.13