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

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2016-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             : #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          43 : 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             : /// This ensures runAllTasks is used
      57             :   bool useRunAllTasks;
      58             : /// The frequency with which to clear the grid
      59             :   unsigned clearstride;
      60             : /// The weights we are going to use for reweighting
      61             :   std::vector<Value*> weights;
      62             : /// Are we accumulated the unormalized quantity
      63             :   bool unormalised;
      64             : protected:
      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             : public:
      70             :   static void registerKeywords( Keywords& keys );
      71             :   explicit ActionWithAveraging( const ActionOptions& );
      72             :   void lockRequests();
      73             :   void unlockRequests();
      74             :   void calculateNumericalDerivatives(PLMD::ActionWithValue*);
      75         114 :   virtual unsigned getNumberOfDerivatives() { return 0; }
      76             :   unsigned getNumberOfArguments() const ;
      77             : /// Overwrite ActionWithArguments getArguments() so that we don't return the bias
      78             :   std::vector<Value*> getArguments();
      79        1428 :   void calculate() {}
      80        1428 :   void apply() {}
      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        1330 :   virtual void finishAveraging() {}
      90             : };
      91             : 
      92             : inline
      93      119858 : unsigned ActionWithAveraging::getNumberOfArguments() const {
      94      119858 :   return ActionWithArguments::getNumberOfArguments() - weights.size();
      95             : }
      96             : 
      97             : inline
      98        2226 : std::vector<Value*> ActionWithAveraging::getArguments() {
      99        2226 :   std::vector<Value*> arg_vals( ActionWithArguments::getArguments() );
     100        2226 :   for(unsigned i=0; i<weights.size(); ++i) arg_vals.erase(arg_vals.end()-1);
     101        2226 :   return arg_vals;
     102             : }
     103             : 
     104             : }
     105             : }
     106             : #endif

Generated by: LCOV version 1.13