All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Debug.cpp
Go to the documentation of this file.
1 /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2  Copyright (c) 2013 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-code.org for more information.
6 
7  This file is part of plumed, version 2.0.
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 \verbatim
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 \endverbatim
46 
47 */
48 //+ENDPLUMEDOC
49 class Debug:
50  public ActionPilot
51 {
54  bool novirial;
56 public:
57  Debug(const ActionOptions&ao);
58 /// Register all the relevant keywords for the action
59  static void registerKeywords( Keywords& keys );
60  void calculate(){}
61  void apply();
62 };
63 
64 PLUMED_REGISTER_ACTION(Debug,"DEBUG")
65 
66 void Debug::registerKeywords( Keywords& keys ){
67  Action::registerKeywords( keys );
68  ActionPilot::registerKeywords(keys);
69  keys.add("compulsory","STRIDE","1","the frequency with which this action is to be performed");
70  keys.addFlag("logActivity",false,"write in the log which actions are inactive and which are inactive");
71  keys.addFlag("logRequestedAtoms",false,"write in the log which atoms have been requested at a given time");
72  keys.addFlag("NOVIRIAL",false,"switch off the virial contribution for the entirity of the simulation");
73  keys.addFlag("DETAILED_TIMERS",false,"switch on detailed timers");
74 }
75 
76 Debug::Debug(const ActionOptions&ao):
77 Action(ao),
78 ActionPilot(ao),
79 logActivity(false),
80 logRequestedAtoms(false),
81 novirial(false){
82  parseFlag("logActivity",logActivity);
83  if(logActivity) log.printf(" logging activity\n");
84  parseFlag("logRequestedAtoms",logRequestedAtoms);
85  if(logRequestedAtoms) log.printf(" logging requested atoms\n");
86  parseFlag("NOVIRIAL",novirial);
87  if(novirial) log.printf(" Switching off virial contribution\n");
88  if(novirial) plumed.novirial=true;
89  parseFlag("DETAILED_TIMERS",detailedTimers);
90  if(detailedTimers) log.printf(" Detailed timing on\n");
91  plumed.detailedTimers=true;
92  checkRead();
93 }
94 
95 void Debug::apply(){
96  if(logActivity){
97  const ActionSet&actionSet(plumed.getActionSet());
98  int a=0;
99  for(ActionSet::const_iterator p=actionSet.begin();p!=actionSet.end();++p){
100  if(dynamic_cast<Debug*>(*p))continue;
101  if((*p)->isActive()) a++;
102  };
103  if(a>0){
104  log.printf("activity at step %i: ",getStep());
105  for(ActionSet::const_iterator p=actionSet.begin();p!=actionSet.end();++p){
106  if(dynamic_cast<Debug*>(*p))continue;
107  if((*p)->isActive()) log.printf("+");
108  else log.printf("-");
109  };
110  log.printf("\n");
111  };
112  };
113  if(logRequestedAtoms){
114  log.printf("requested atoms at step %i: ",getStep());
115  int* l;
116  int n;
117  plumed.cmd("createFullList",&n);
118  plumed.cmd("getFullList",&l);
119  for(int i=0;i<n;i++) log.printf(" %d",l[i]);
120  log.printf("\n");
121  plumed.cmd("clearFullList");
122  }
123 
124 }
125 
126 }
127 }
128 
void parseFlag(const std::string &key, bool &t)
Parse one keyword as boolean flag.
Definition: Action.cpp:104
Log & log
Reference to the log stream.
Definition: Action.h:93
void calculate()
Calculate an Action.
Definition: Debug.cpp:60
std::vector containing the sequence of Action to be done.
Definition: ActionSet.h:38
This is used to create PLMD::Action objects that are run with some set frequency. ...
Definition: ActionPilot.h:39
void checkRead()
Check if Action was properly read.
Definition: Action.cpp:161
STL namespace.
void const char const char int * n
Definition: Matrix.h:42
This class holds the keywords and their documentation.
Definition: Keywords.h:36
This class is used to bring the relevant information to the Action constructor.
Definition: Action.h:41
int printf(const char *fmt,...)
Formatted output with explicit format - a la printf.
Definition: OFile.cpp:82
Base class for all the input Actions.
Definition: Action.h:60
Provides the keyword DEBUG
Definition: Debug.cpp:49
long int getStep() const
Return the present timestep.
Definition: Action.cpp:169
Main plumed object.
Definition: Plumed.h:201
void const char const char int double * a
Definition: Matrix.h:42
bool logRequestedAtoms
Definition: Debug.cpp:53
void apply()
Apply an Action.
Definition: Debug.cpp:95