LCOV - code coverage report
Current view: top level - generic - Flush.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 20 20 100.0 %
Date: 2024-10-11 08:09:47 Functions: 8 8 100.0 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2011-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             : #include "core/ActionRegister.h"
      23             : #include "core/ActionPilot.h"
      24             : #include "core/PlumedMain.h"
      25             : #include "core/ActionSet.h"
      26             : 
      27             : namespace PLMD {
      28             : namespace generic {
      29             : 
      30             : //+PLUMEDOC GENERIC FLUSH
      31             : /*
      32             : This command instructs plumed to flush all the open files with a user specified frequency.
      33             : Notice that all files are flushed anyway every 10000 steps.
      34             : 
      35             : This
      36             : is useful for preventing data loss that would otherwise arise as a consequence of the code
      37             : storing data for printing in the buffers. Notice that wherever it is written in the
      38             : plumed input file, it will flush all the open files.
      39             : 
      40             : \par Examples
      41             : 
      42             : A command like this in the input will instruct plumed to flush all the output files every 100 steps
      43             : \plumedfile
      44             : d1: DISTANCE ATOMS=1,10
      45             : PRINT ARG=d1 STRIDE=5 FILE=colvar1
      46             : 
      47             : FLUSH STRIDE=100
      48             : 
      49             : d2: DISTANCE ATOMS=2,11
      50             : # also this print is flushed every 100 steps:
      51             : PRINT ARG=d2 STRIDE=10 FILE=colvar2
      52             : \endplumedfile
      53             : (see also \ref DISTANCE and \ref PRINT).
      54             : */
      55             : //+ENDPLUMEDOC
      56             : 
      57             : class Flush:
      58             :   public ActionPilot
      59             : {
      60             : public:
      61          17 :   explicit Flush(const ActionOptions&ao):
      62             :     Action(ao),
      63          17 :     ActionPilot(ao)
      64             :   {
      65          17 :     checkRead();
      66          17 :   }
      67             :   static void registerKeywords( Keywords& keys );
      68         561 :   void calculate() override {}
      69         561 :   void apply() override {}
      70         561 :   void update() override {
      71         561 :     plumed.fflush();
      72         561 :     log.flush();
      73         561 :     const ActionSet & actionSet(plumed.getActionSet());
      74        3941 :     for(const auto & p : actionSet)
      75        3380 :       p->fflush();
      76         561 :   }
      77             : };
      78             : 
      79       10453 : PLUMED_REGISTER_ACTION(Flush,"FLUSH")
      80             : 
      81          18 : void Flush::registerKeywords( Keywords& keys ) {
      82          18 :   Action::registerKeywords( keys );
      83          18 :   ActionPilot::registerKeywords( keys );
      84          36 :   keys.add("compulsory","STRIDE","the frequency with which all the open files should be flushed");
      85          18 :   keys.remove("LABEL");
      86          18 : }
      87             : 
      88             : }
      89             : }
      90             : 
      91             : 

Generated by: LCOV version 1.15