LCOV - code coverage report
Current view: top level - vesselbase - AveragingVessel.h (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 7 9 77.8 %
Date: 2020-11-18 11:20:57 Functions: 1 3 33.3 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2016-2019 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_vesselbase_AveragingVessel_h
      23             : #define __PLUMED_vesselbase_AveragingVessel_h
      24             : 
      25             : #include "Vessel.h"
      26             : 
      27             : namespace PLMD {
      28             : namespace vesselbase {
      29             : 
      30          98 : class AveragingVessel : public Vessel {
      31             : private:
      32             : /// The grid was recently cleared and bounds can be set
      33             :   bool wascleared;
      34             : /// Are we outputting unormalised data
      35             :   bool unormalised;
      36             : /// The data that is being averaged
      37             :   std::vector<double> data;
      38             : protected:
      39             : /// Set the size of the data vector
      40             :   void setDataSize( const unsigned& size );
      41             : /// Set an element of the data array
      42             :   void setDataElement( const unsigned& myelem, const double& value );
      43             : /// Add some value to an element of the data array
      44             :   void addDataElement( const unsigned& myelem, const double& value );
      45             : /// Get the value of one of the data element
      46             :   double getDataElement( const unsigned& myelem ) const ;
      47             : /// Are we averaging the data
      48      361818 :   bool noAverage() const { return unormalised; }
      49             : public:
      50             : /// keywords
      51             :   static void registerKeywords( Keywords& keys );
      52             : /// Constructor
      53             :   explicit AveragingVessel( const vesselbase::VesselOptions& );
      54             : /// Copy data from an accumulated buffer into the grid
      55             :   virtual void finish( const std::vector<double>& );
      56             : /// Was the grid cleared on the last step
      57             :   bool wasreset() const ;
      58             : /// Clear all the data stored on the grid
      59             :   virtual void clear();
      60             : /// Reset the grid so that it is cleared at start of next time it is calculated
      61             :   virtual void reset();
      62             : /// Functions for dealing with normalisation constant
      63             :   void setNorm( const double& snorm );
      64             :   double getNorm() const ;
      65           0 :   virtual bool applyForce(  std::vector<double>& forces ) { return false; }
      66             : };
      67             : 
      68             : inline
      69             : void AveragingVessel::setDataElement( const unsigned& myelem, const double& value ) {
      70             :   plumed_dbg_assert( myelem<1+data.size() );
      71           0 :   wascleared=false; data[1+myelem]=value;
      72             : }
      73             : 
      74             : inline
      75             : void AveragingVessel::addDataElement( const unsigned& myelem, const double& value ) {
      76             :   plumed_dbg_assert( myelem<1+data.size() );
      77      108280 :   wascleared=false; data[1+myelem]+=value;
      78             : }
      79             : 
      80             : inline
      81             : double AveragingVessel::getDataElement( const unsigned& myelem ) const {
      82             :   plumed_dbg_assert( myelem<data.size()-1 );
      83      324151 :   if( unormalised ) return data[1+myelem];
      84     2876357 :   return data[1+myelem] / data[0];
      85             : }
      86             : 
      87             : inline
      88             : void AveragingVessel::setNorm( const double& snorm ) {
      89             :   plumed_dbg_assert( data.size()>0 );
      90         171 :   data[0]=snorm;
      91             : }
      92             : 
      93             : inline
      94             : double AveragingVessel::getNorm() const {
      95             :   plumed_dbg_assert( data.size()>0 );
      96       90572 :   return data[0];
      97             : }
      98             : 
      99             : }
     100             : }
     101             : #endif

Generated by: LCOV version 1.13