LCOV - code coverage report
Current view: top level - generic - Debug.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 57 57 100.0 %
Date: 2019-08-13 10:15:31 Functions: 11 12 91.7 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2011-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             : #include "core/ActionRegister.h"
      23             : #include "core/ActionPilot.h"
      24             : #include "core/ActionSet.h"
      25             : #include "core/PlumedMain.h"
      26             : 
      27             : using namespace std;
      28             : 
      29             : namespace PLMD {
      30             : namespace generic {
      31             : 
      32             : //+PLUMEDOC GENERIC DEBUG
      33             : /*
      34             : Set some debug options.
      35             : 
      36             : Can be used while debugging or optimizing plumed.
      37             : 
      38             : \par Examples
      39             : 
      40             : \plumedfile
      41             : # print detailed (action-by-action) timers at the end of simulation
      42             : DEBUG DETAILED_TIMERS
      43             : # dump every two steps which are the atoms required from the MD code
      44             : DEBUG logRequestedAtoms STRIDE=2
      45             : \endplumedfile
      46             : 
      47             : */
      48             : //+ENDPLUMEDOC
      49          18 : class Debug:
      50             :   public ActionPilot
      51             : {
      52             :   OFile ofile;
      53             :   bool logActivity;
      54             :   bool logRequestedAtoms;
      55             :   bool novirial;
      56             :   bool detailedTimers;
      57             : public:
      58             :   explicit Debug(const ActionOptions&ao);
      59             : /// Register all the relevant keywords for the action
      60             :   static void registerKeywords( Keywords& keys );
      61         140 :   void calculate() override {}
      62             :   void apply() override;
      63             : };
      64             : 
      65        7844 : PLUMED_REGISTER_ACTION(Debug,"DEBUG")
      66             : 
      67           7 : void Debug::registerKeywords( Keywords& keys ) {
      68           7 :   Action::registerKeywords( keys );
      69           7 :   ActionPilot::registerKeywords(keys);
      70          35 :   keys.add("compulsory","STRIDE","1","the frequency with which this action is to be performed");
      71          21 :   keys.addFlag("logActivity",false,"write in the log which actions are inactive and which are inactive");
      72          21 :   keys.addFlag("logRequestedAtoms",false,"write in the log which atoms have been requested at a given time");
      73          21 :   keys.addFlag("NOVIRIAL",false,"switch off the virial contribution for the entirety of the simulation");
      74          21 :   keys.addFlag("DETAILED_TIMERS",false,"switch on detailed timers");
      75          28 :   keys.add("optional","FILE","the name of the file on which to output these quantities");
      76           7 : }
      77             : 
      78           6 : Debug::Debug(const ActionOptions&ao):
      79             :   Action(ao),
      80             :   ActionPilot(ao),
      81             :   logActivity(false),
      82             :   logRequestedAtoms(false),
      83           6 :   novirial(false) {
      84          12 :   parseFlag("logActivity",logActivity);
      85           6 :   if(logActivity) log.printf("  logging activity\n");
      86          12 :   parseFlag("logRequestedAtoms",logRequestedAtoms);
      87           6 :   if(logRequestedAtoms) log.printf("  logging requested atoms\n");
      88          12 :   parseFlag("NOVIRIAL",novirial);
      89           6 :   if(novirial) log.printf("  Switching off virial contribution\n");
      90           6 :   if(novirial) plumed.novirial=true;
      91          12 :   parseFlag("DETAILED_TIMERS",detailedTimers);
      92           6 :   if(detailedTimers) {
      93           2 :     log.printf("  Detailed timing on\n");
      94           2 :     plumed.detailedTimers=true;
      95             :   }
      96           6 :   ofile.link(*this);
      97             :   std::string file;
      98          12 :   parse("FILE",file);
      99           6 :   if(file.length()>0) {
     100           2 :     ofile.open(file);
     101           2 :     log.printf("  on file %s\n",file.c_str());
     102             :   } else {
     103           4 :     log.printf("  on plumed log file\n");
     104           4 :     ofile.link(log);
     105             :   }
     106           6 :   checkRead();
     107           6 : }
     108             : 
     109         140 : void Debug::apply() {
     110         140 :   if(logActivity) {
     111          10 :     const ActionSet&actionSet(plumed.getActionSet());
     112             :     int a=0;
     113         125 :     for(const auto & p : actionSet) {
     114         105 :       if(dynamic_cast<Debug*>(p.get()))continue;
     115          90 :       if(p->isActive()) a++;
     116             :     };
     117          10 :     if(a>0) {
     118           9 :       ofile<<"activity at step "<<getStep()<<": ";
     119         116 :       for(const auto & p : actionSet) {
     120          98 :         if(dynamic_cast<Debug*>(p.get()))continue;
     121          85 :         if(p->isActive()) ofile.printf("+");
     122          27 :         else                 ofile.printf("-");
     123             :       };
     124           9 :       ofile.printf("\n");
     125             :     };
     126             :   };
     127         140 :   if(logRequestedAtoms) {
     128          17 :     ofile<<"requested atoms at step "<<getStep()<<": ";
     129             :     int* l;
     130             :     int n;
     131          34 :     plumed.cmd("createFullList",&n);
     132          34 :     plumed.cmd("getFullList",&l);
     133          17 :     for(int i=0; i<n; i++) ofile.printf(" %d",l[i]);
     134          17 :     ofile.printf("\n");
     135          34 :     plumed.cmd("clearFullList");
     136             :   }
     137             : 
     138         140 : }
     139             : 
     140             : }
     141        5874 : }
     142             : 

Generated by: LCOV version 1.14