Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2016-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_vesselbase_AveragingVessel_h 23 : #define __PLUMED_vesselbase_AveragingVessel_h 24 : 25 : #include "Vessel.h" 26 : 27 : namespace PLMD { 28 : namespace vesselbase { 29 : 30 : 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 : bool noAverage() const { 49 361754 : return unormalised; 50 : } 51 : public: 52 : /// keywords 53 : static void registerKeywords( Keywords& keys ); 54 : /// Constructor 55 : explicit AveragingVessel( const vesselbase::VesselOptions& ); 56 : /// Copy data from an accumulated buffer into the grid 57 : void finish( const std::vector<double>& ) override; 58 : /// Was the grid cleared on the last step 59 : bool wasreset() const ; 60 : /// Clear all the data stored on the grid 61 : virtual void clear(); 62 : /// Reset the grid so that it is cleared at start of next time it is calculated 63 : virtual void reset(); 64 : /// Functions for dealing with normalisation constant 65 : void setNorm( const double& snorm ); 66 : double getNorm() const ; 67 0 : bool applyForce( std::vector<double>& forces ) override { 68 0 : return false; 69 : } 70 : }; 71 : 72 : inline 73 : void AveragingVessel::setDataElement( const unsigned& myelem, const double& value ) { 74 : plumed_dbg_assert( myelem<1+data.size() ); 75 154208 : wascleared=false; 76 154208 : data[1+myelem]=value; 77 : } 78 : 79 : inline 80 : void AveragingVessel::addDataElement( const unsigned& myelem, const double& value ) { 81 : plumed_dbg_assert( myelem<1+data.size() ); 82 58119 : wascleared=false; 83 58119 : data[1+myelem]+=value; 84 : } 85 : 86 : inline 87 7999243 : double AveragingVessel::getDataElement( const unsigned& myelem ) const { 88 : plumed_dbg_assert( myelem<data.size()-1 ); 89 7999243 : if( unormalised ) { 90 6147888 : return data[1+myelem]; 91 : } 92 1851355 : return data[1+myelem] / data[0]; 93 : } 94 : 95 : inline 96 : void AveragingVessel::setNorm( const double& snorm ) { 97 : plumed_dbg_assert( data.size()>0 ); 98 1389 : data[0]=snorm; 99 27 : } 100 : 101 : inline 102 : double AveragingVessel::getNorm() const { 103 : plumed_dbg_assert( data.size()>0 ); 104 104745 : return data[0]; 105 : } 106 : 107 : } 108 : } 109 : #endif