LCOV - code coverage report
Current view: top level - generic - Debug.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 55 57 96.5 %
Date: 2020-11-18 11:20:57 Functions: 10 12 83.3 %

          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           6 : 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          15 :   void calculate() {}
      62             :   void apply();
      63             : };
      64             : 
      65        6455 : PLUMED_REGISTER_ACTION(Debug,"DEBUG")
      66             : 
      67           4 : void Debug::registerKeywords( Keywords& keys ) {
      68           4 :   Action::registerKeywords( keys );
      69           4 :   ActionPilot::registerKeywords(keys);
      70          20 :   keys.add("compulsory","STRIDE","1","the frequency with which this action is to be performed");
      71          12 :   keys.addFlag("logActivity",false,"write in the log which actions are inactive and which are inactive");
      72          12 :   keys.addFlag("logRequestedAtoms",false,"write in the log which atoms have been requested at a given time");
      73          12 :   keys.addFlag("NOVIRIAL",false,"switch off the virial contribution for the entirity of the simulation");
      74          12 :   keys.addFlag("DETAILED_TIMERS",false,"switch on detailed timers");
      75          16 :   keys.add("optional","FILE","the name of the file on which to output these quantities");
      76           4 : }
      77             : 
      78           3 : Debug::Debug(const ActionOptions&ao):
      79             :   Action(ao),
      80             :   ActionPilot(ao),
      81             :   logActivity(false),
      82             :   logRequestedAtoms(false),
      83           3 :   novirial(false) {
      84           6 :   parseFlag("logActivity",logActivity);
      85           3 :   if(logActivity) log.printf("  logging activity\n");
      86           6 :   parseFlag("logRequestedAtoms",logRequestedAtoms);
      87           3 :   if(logRequestedAtoms) log.printf("  logging requested atoms\n");
      88           6 :   parseFlag("NOVIRIAL",novirial);
      89           3 :   if(novirial) log.printf("  Switching off virial contribution\n");
      90           3 :   if(novirial) plumed.novirial=true;
      91           6 :   parseFlag("DETAILED_TIMERS",detailedTimers);
      92           3 :   if(detailedTimers) {
      93           0 :     log.printf("  Detailed timing on\n");
      94           0 :     plumed.detailedTimers=true;
      95             :   }
      96           3 :   ofile.link(*this);
      97             :   std::string file;
      98           6 :   parse("FILE",file);
      99           3 :   if(file.length()>0) {
     100           2 :     ofile.open(file);
     101           4 :     log.printf("  on file %s\n",file.c_str());
     102             :   } else {
     103           1 :     log.printf("  on plumed log file\n");
     104           1 :     ofile.link(log);
     105             :   }
     106           3 :   checkRead();
     107           3 : }
     108             : 
     109          15 : void Debug::apply() {
     110          15 :   if(logActivity) {
     111          10 :     const ActionSet&actionSet(plumed.getActionSet());
     112             :     int a=0;
     113         115 :     for(const auto & p : actionSet) {
     114         105 :       if(dynamic_cast<Debug*>(p))continue;
     115          90 :       if(p->isActive()) a++;
     116             :     };
     117          10 :     if(a>0) {
     118           9 :       ofile.printf("activity at step %i: ",getStep());
     119         107 :       for(const auto & p : actionSet) {
     120          98 :         if(dynamic_cast<Debug*>(p))continue;
     121          85 :         if(p->isActive()) ofile.printf("+");
     122          27 :         else                 ofile.printf("-");
     123             :       };
     124           9 :       ofile.printf("\n");
     125             :     };
     126             :   };
     127          15 :   if(logRequestedAtoms) {
     128           5 :     ofile.printf("requested atoms at step %i: ",getStep());
     129             :     int* l;
     130             :     int n;
     131          10 :     plumed.cmd("createFullList",&n);
     132          10 :     plumed.cmd("getFullList",&l);
     133          15 :     for(int i=0; i<n; i++) ofile.printf(" %d",l[i]);
     134           5 :     ofile.printf("\n");
     135          10 :     plumed.cmd("clearFullList");
     136             :   }
     137             : 
     138          15 : }
     139             : 
     140             : }
     141        4839 : }
     142             : 

Generated by: LCOV version 1.13