LCOV - code coverage report
Current view: top level - vesselbase - ActionWithAveraging.h (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 11 11 100.0 %
Date: 2020-11-18 11:20:57 Functions: 6 6 100.0 %

          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_ActionWithAveraging_h
      23             : #define __PLUMED_vesselbase_ActionWithAveraging_h
      24             : 
      25             : #include "core/ActionPilot.h"
      26             : #include "core/ActionWithValue.h"
      27             : #include "core/ActionAtomistic.h"
      28             : #include "core/ActionWithValue.h"
      29             : #include "core/ActionWithArguments.h"
      30             : #include "ActionWithVessel.h"
      31             : #include "AveragingVessel.h"
      32             : 
      33             : namespace PLMD {
      34             : namespace vesselbase {
      35             : 
      36             : /**
      37             : \ingroup INHERIT
      38             : This abstract base class should be used if you are writing some method that calculates an "average" from a set of
      39             : trajectory frames.  Notice that we use the word average very broadly here and state that even dimensionality
      40             : reduction algorithms calculate an "average."  In other words, what we mean by average is that the method is going
      41             : to take in data from each trajectory frame and only calculate the final quantity once a certain amount of data has
      42             : been collected.
      43             : */
      44             : 
      45         228 : class ActionWithAveraging :
      46             :   public ActionPilot,
      47             :   public ActionAtomistic,
      48             :   public ActionWithArguments,
      49             :   public ActionWithValue,
      50             :   public ActionWithVessel
      51             : {
      52             :   friend class AveragingVessel;
      53             : private:
      54             : /// The vessel which is used to compute averages
      55             :   AveragingVessel* myaverage;
      56             : /// The weights we are going to use for reweighting
      57             :   std::vector<Value*> weights;
      58             : /// Are we accumulated the unormalized quantity
      59             :   enum {t,f,ndata} normalization;
      60             : protected:
      61             : /// This ensures runAllTasks is used
      62             :   bool useRunAllTasks;
      63             : /// The frequency with which to clear the grid
      64             :   unsigned clearstride;
      65             : /// The current weight and its logarithm
      66             :   double lweight, cweight;
      67             : /// Set the averaging action
      68             :   void setAveragingAction( AveragingVessel* av_vessel, const bool& usetasks );
      69             : /// Check if we are using the normalization condition when calculating this quantity
      70             :   bool noNormalization() const ;
      71             : public:
      72             :   static void registerKeywords( Keywords& keys );
      73             :   explicit ActionWithAveraging( const ActionOptions& );
      74             :   void lockRequests();
      75             :   void unlockRequests();
      76             :   void calculateNumericalDerivatives(PLMD::ActionWithValue*);
      77         212 :   virtual unsigned getNumberOfDerivatives() { return 0; }
      78             :   unsigned getNumberOfArguments() const ;
      79             : /// Overwrite ActionWithArguments getArguments() so that we don't return the bias
      80             :   std::vector<Value*> getArguments();
      81             :   void update();
      82             : /// This does the clearing of the action
      83             :   virtual void clearAverage();
      84             : /// This is done before the averaging comences
      85        1314 :   virtual void prepareForAveraging() {}
      86             : /// This does the averaging operation
      87             :   virtual void performOperations( const bool& from_update );
      88             : /// This is done once the averaging is finished
      89        1356 :   virtual void finishAveraging() {}
      90             : };
      91             : 
      92             : inline
      93      149342 : unsigned ActionWithAveraging::getNumberOfArguments() const {
      94      149441 :   return ActionWithArguments::getNumberOfArguments() - weights.size();
      95             : }
      96             : 
      97             : inline
      98        2238 : std::vector<Value*> ActionWithAveraging::getArguments() {
      99        2238 :   std::vector<Value*> arg_vals( ActionWithArguments::getArguments() );
     100        4482 :   for(unsigned i=0; i<weights.size(); ++i) arg_vals.erase(arg_vals.end()-1);
     101        2238 :   return arg_vals;
     102             : }
     103             : 
     104             : inline
     105             : bool ActionWithAveraging::noNormalization() const {
     106          81 :   return normalization==f;
     107             : }
     108             : 
     109             : }
     110             : }
     111             : #endif

Generated by: LCOV version 1.13