LCOV - code coverage report
Current view: top level - generic - Flush.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 19 19 100.0 %
Date: 2025-03-25 09:33:27 Functions: 5 5 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             : The input below uses the FLUSH command to get PLUMED to flush all the output files every 100 steps
      36             : 
      37             : ```plumed
      38             : d1: DISTANCE ATOMS=1,10
      39             : PRINT ARG=d1 STRIDE=5 FILE=colvar1
      40             : 
      41             : FLUSH STRIDE=100
      42             : 
      43             : d2: DISTANCE ATOMS=2,11
      44             : # also this print is flushed every 100 steps:
      45             : PRINT ARG=d2 STRIDE=10 FILE=colvar2
      46             : ```
      47             : 
      48             : This command is useful for preventing data loss that would otherwise arise as a consequence of the code
      49             : storing data for printing in the buffers. Notice that it will always flush all the open files and that the location
      50             : where put this command in the input does not matter.  In the input above, for example both `colvar1` and `colvar2`
      51             : are flushed every 100 steps.
      52             : 
      53             : */
      54             : //+ENDPLUMEDOC
      55             : 
      56             : class Flush:
      57             :   public ActionPilot {
      58             : public:
      59          17 :   explicit Flush(const ActionOptions&ao):
      60             :     Action(ao),
      61          17 :     ActionPilot(ao) {
      62          17 :     checkRead();
      63          17 :   }
      64             :   static void registerKeywords( Keywords& keys );
      65         561 :   void calculate() override {}
      66         561 :   void apply() override {}
      67         561 :   void update() override {
      68         561 :     plumed.fflush();
      69         561 :     log.flush();
      70         561 :     const ActionSet & actionSet(plumed.getActionSet());
      71        9527 :     for(const auto & p : actionSet) {
      72        8966 :       p->fflush();
      73             :     }
      74         561 :   }
      75             : };
      76             : 
      77             : PLUMED_REGISTER_ACTION(Flush,"FLUSH")
      78             : 
      79          19 : void Flush::registerKeywords( Keywords& keys ) {
      80          19 :   Action::registerKeywords( keys );
      81          19 :   ActionPilot::registerKeywords( keys );
      82          19 :   keys.add("compulsory","STRIDE","the frequency with which all the open files should be flushed");
      83          19 :   keys.remove("LABEL");
      84          19 : }
      85             : 
      86             : }
      87             : }
      88             : 
      89             : 

Generated by: LCOV version 1.16