1 /*-------------------------------------------------------------------
2 Copyright 2011 Ravishankar Sundararaman
3 
4 This file is part of JDFTx.
5 
6 JDFTx is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10 
11 JDFTx is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15 
16 You should have received a copy of the GNU General Public License
17 along with JDFTx.  If not, see <http://www.gnu.org/licenses/>.
18 -------------------------------------------------------------------*/
19 
20 #include <commands/command.h>
21 #include <electronic/Everything.h>
22 
23 
24 enum DebugOptions
25 {	DebugEigsFillings,
26 	DebugEcomponents,
27 	DebugMuSearch,
28 	DebugKpointsBasis,
29 	DebugForces,
30 	DebugSymmetries,
31 	DebugFluid,
32 	DebugDelim //delimiter to figure out end of input
33 };
34 
35 EnumStringMap<DebugOptions> debugMap
36 (	DebugEigsFillings, "EigsFillings",
37 	DebugEcomponents, "Ecomponents",
38 	DebugMuSearch, "MuSearch",
39 	DebugKpointsBasis, "KpointsBasis",
40 	DebugForces, "Forces",
41 	DebugSymmetries, "Symmetries",
42 	DebugFluid, "Fluid"
43 );
44 
45 EnumStringMap<DebugOptions> debugDescMap
46 (	DebugEigsFillings, "Print eigenvalues, Hsub and fillings after each iteration",
47 	DebugEcomponents, "Print energy components and after each electronic iteration",
48 	DebugMuSearch, "Print progress of the mu bisect/fit routines",
49 	DebugKpointsBasis, "List details of each k-point and corresponding basis",
50 	DebugForces, "Print each contribution to the force separately (NL, loc etc.)",
51 	DebugSymmetries, "Print various symmetry matrices during start up",
52 	DebugFluid, "Enable verbose logging of fluid (iterations for Linear, even more for others)"
53 );
54 
55 struct CommandDebug : public Command
56 {
CommandDebugCommandDebug57 	CommandDebug() : Command("debug", "jdftx/Output")
58 	{
59 		format = "<option> <option> ...";
60 		comments =
61 			"Each <option> is one of "
62 			+ addDescriptions(debugMap.optionList(), linkDescription(debugMap, debugDescMap))
63 			+ "\n\nDefault: none of the optional outputs";
64 		allowMultiple = true;
65 		hasDefault = false;
66 	}
67 
processCommandDebug68 	void process(ParamList& pl, Everything& e)
69 	{	while(true)
70 		{	DebugOptions option;
71 			pl.get(option, DebugDelim, debugMap, "option");
72 			switch(option)
73 			{	case DebugEigsFillings:
74 					e.cntrl.shouldPrintEigsFillings = true;
75 					break;
76 				case DebugEcomponents:
77 					e.cntrl.shouldPrintEcomponents = true;
78 					break;
79 				case DebugMuSearch:
80 					e.cntrl.shouldPrintMuSearch = true;
81 					break;
82 				case DebugKpointsBasis:
83 					e.cntrl.shouldPrintKpointsBasis = true;
84 					break;
85 				case DebugForces:
86 					e.iInfo.shouldPrintForceComponents = true;
87 					break;
88 				case DebugSymmetries:
89 					e.symm.shouldPrintMatrices = true;
90 					break;
91 				case DebugFluid:
92 					e.eVars.fluidParams.verboseLog = true;
93 					break;
94 				case DebugDelim:
95 					return; //end of input line
96 			}
97 		}
98 	}
99 
printStatusCommandDebug100 	void printStatus(Everything& e, int iRep)
101 	{	//Coalesce all the debug commands into a single one:
102 		if(iRep==0)
103 		{	if(e.cntrl.shouldPrintEigsFillings) logPrintf(" EigsFillings");
104 			if(e.cntrl.shouldPrintEcomponents) logPrintf(" Ecomponents");
105 			if(e.cntrl.shouldPrintMuSearch) logPrintf(" MuSearch");
106 			if(e.cntrl.shouldPrintKpointsBasis) logPrintf(" KpointsBasis");
107 			if(e.iInfo.shouldPrintForceComponents) logPrintf(" Forces");
108 			if(e.symm.shouldPrintMatrices) logPrintf("Symmetries");
109 			if(e.eVars.fluidParams.verboseLog) logPrintf(" Fluid");
110 		}
111 	}
112 }
113 commandDebug;
114 
115 
116 struct CommandForcesOutputCoords : public Command
117 {
CommandForcesOutputCoordsCommandForcesOutputCoords118 	CommandForcesOutputCoords() : Command("forces-output-coords", "jdftx/Output")
119 	{
120 		format = "<coords>=" + forcesOutputCoordsMap.optionList();
121 		comments =
122 			"Coordinate system to use for force output in log file as well as dump:\n"
123 			"+ Positions: Use the same coordinate system as ionic position input (selected by coords-type) [default].\n"
124 			"+ Lattice:   Use (covariant) lattice coordinates\n"
125 			"+ Cartesian: Use cartesian coordinates\n"
126 			"+ Contravariant: Use contravariant lattice coordinates (covariant multiplied by inv(RT.R))";
127 		hasDefault = true;
128 	}
129 
processCommandForcesOutputCoords130 	void process(ParamList& pl, Everything& e)
131 	{	pl.get(e.iInfo.forcesOutputCoords, ForcesCoordsPositions, forcesOutputCoordsMap, "coords");
132 	}
133 
printStatusCommandForcesOutputCoords134 	void printStatus(Everything& e, int iRep)
135 	{	fputs(forcesOutputCoordsMap.getString(e.iInfo.forcesOutputCoords), globalLog);
136 	}
137 }
138 commandForcesOutputCoords;
139