LCOV - code coverage report
Current view: top level - tools - HistogramBead.h (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 9 9 100.0 %
Date: 2026-11-05 10:19:04 Functions: 0 0 -

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2012-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_tools_HistogramBead_h
      23             : #define __PLUMED_tools_HistogramBead_h
      24             : 
      25             : #include <string>
      26             : #include <vector>
      27             : #include "Exception.h"
      28             : #include "Tools.h"
      29             : 
      30             : namespace PLMD {
      31             : 
      32             : class Keywords;
      33             : class Log;
      34             : 
      35             : /**
      36             : \ingroup TOOLBOX
      37             : A class for calculating whether or not values are within a given range using : \f$ \sum_i \int_a^b G( s_i, \sigma*(b-a) ) \f$
      38             : */
      39             : 
      40             : class HistogramBead {
      41             : public:
      42             :   enum class KernelType {gaussian,triangular};
      43             : private:
      44             :   double lowb{0.0};
      45             :   double highb{0.0};
      46             :   double width{0.0};
      47             :   double cutoff{std::numeric_limits<double>::max()};
      48             : 
      49             :   KernelType type{KernelType::gaussian};
      50             :   enum class Periodicity {periodic,notperiodic};
      51             :   Periodicity periodicity{Periodicity::notperiodic};
      52             :   double min{0.0};
      53             :   double max{0.0};
      54             :   double max_minus_min{0.0};
      55             :   double inv_max_minus_min{0.0};
      56             : 
      57             :   double difference(double d1, double d2 ) const ;
      58             : public:
      59             :   static void registerKeywords( Keywords& keys );
      60             :   static void generateBins( const std::string& params, std::vector<std::string>& bins );
      61             :   std::string description() const ;
      62             :   //Non periodic constructor
      63             : #pragma acc routine seq
      64             :   explicit HistogramBead(KernelType, double l, double h, double w);
      65             :   //with period constructor
      66             :   HistogramBead(KernelType, double mlow, double mhigh, double l, double h, double w);
      67             :   HistogramBead(const HistogramBead&);
      68             :   HistogramBead(HistogramBead&&);
      69             :   HistogramBead& operator=(const HistogramBead&);
      70             :   HistogramBead& operator=(HistogramBead&&);
      71             : 
      72             : #pragma acc routine seq
      73             :   void isNotPeriodic();
      74             : #pragma acc routine seq
      75             :   void isPeriodic( double mlow, double mhigh );
      76             :   static KernelType getKernelType( const std::string& ktype );
      77             :   void setKernelType( const std::string& ktype );
      78             : #pragma acc routine seq
      79             :   void setKernelType( KernelType ktype );
      80             :   void set(const std::string& params, std::string& errormsg);
      81             : #pragma acc routine seq
      82             :   void set(double l, double h, double w);
      83             : #pragma acc routine seq
      84             :   double calculate(double x, double&df) const;
      85             : #pragma acc routine seq
      86             :   double calculateWithCutoff( double x, double l, double u, double s, double& df ) const ;
      87             : #pragma acc routine seq
      88             :   double calculateWithCutoff( double x, double& df ) const;
      89             :   double lboundDerivative( double x ) const;
      90             :   double uboundDerivative( double x ) const;
      91             :   double getlowb() const ;
      92             :   double getbigb() const ;
      93             :   double getCutoff() const ;
      94             :   //openacc support functions
      95             :   void toACCDevice() const {
      96             : #pragma acc enter data copyin(this[0:1], lowb, highb, width, cutoff, type, \
      97             :                               periodicity, min, max, max_minus_min, \
      98             :                               inv_max_minus_min)
      99             :   }
     100             :   void removeFromACCDevice() const {
     101             : #pragma acc exit data delete(inv_max_minus_min, max_minus_min, max, min,\
     102             :                              periodicity, type, cutoff, width, highb, lowb,\
     103             :                              this[0:1])
     104             :   }
     105             : };
     106             : 
     107             : inline
     108             : void HistogramBead::isNotPeriodic() {
     109          57 :   periodicity=Periodicity::notperiodic;
     110          57 : }
     111             : 
     112             : inline
     113             : void HistogramBead::isPeriodic( const double mlow, const double mhigh ) {
     114      533619 :   periodicity=Periodicity::periodic;
     115      533619 :   min=mlow;
     116      533619 :   max=mhigh;
     117      533619 :   max_minus_min=max-min;
     118      533619 :   inv_max_minus_min=1.0/max_minus_min;
     119      533618 : }
     120             : 
     121             : inline
     122             : double HistogramBead::getlowb() const {
     123             :   return lowb;
     124             : }
     125             : 
     126             : inline
     127             : double HistogramBead::getbigb() const {
     128             :   return highb;
     129             : }
     130             : 
     131             : inline
     132             : double HistogramBead::getCutoff() const {
     133     2834870 :   return cutoff*width;
     134             : }
     135             : 
     136             : }
     137             : 
     138             : #endif

Generated by: LCOV version 1.16