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

Generated by: LCOV version 1.16