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 <electronic/Energies.h>
21 #include <electronic/Everything.h>
22 #include <core/matrix.h>
23
Energies()24 Energies::Energies() : TS(0), muN(0), Eband(0)
25 {
26 }
27
28
print(FILE * fp) const29 void Energies::print(FILE* fp) const
30 { if(Eband)
31 fprintf(fp, "Eband = %25.16lf\n\n", Eband);
32 else
33 { E.print(fp, true, "%9s = %25.16lf\n");
34 fprintf(fp, "-------------------------------------\n");
35 fprintf(fp, " Etot = %25.16lf\n", double(E));
36 if(TS)
37 { fprintf(fp, " TS = %25.16lf\n", TS);
38 fprintf(fp, "-------------------------------------\n");
39 fprintf(fp, " F = %25.16lf\n", F());
40 }
41 if(muN)
42 { fprintf(fp, " muN = %25.16lf\n", muN);
43 fprintf(fp, "-------------------------------------\n");
44 fprintf(fp, " G = %25.16lf\n", G());
45 }
46 }
47 fflush(fp);
48 }
49
50
relevantFreeEnergy(const Everything & e)51 double relevantFreeEnergy(const Everything& e)
52 { if(e.cntrl.fixed_H) return e.ener.Eband;
53 else if(e.eInfo.fillingsUpdate==ElecInfo::FillingsConst) return double(e.ener.E);
54 else if(std::isnan(e.eInfo.mu)) return e.ener.F();
55 else return e.ener.G();
56 }
relevantFreeEnergyName(const Everything & e)57 const char* relevantFreeEnergyName(const Everything& e)
58 { if(e.cntrl.fixed_H) return "Eband";
59 else if(e.eInfo.fillingsUpdate==ElecInfo::FillingsConst) return "Etot";
60 else if(std::isnan(e.eInfo.mu)) return "F";
61 else return "G";
62 }
63
64
65
print_Hsub_eigs(const Everything & e)66 void print_Hsub_eigs(const Everything &e)
67 {
68 const ElecInfo &eInfo = e.eInfo;
69 const ElecVars &eVars = e.eVars;
70
71 logPrintf("Band energies:\n"); //TODO: Head process should print all quantum numbers
72 for(int q=eInfo.qStart; q<eInfo.qStop; q++)
73 { logPrintf("\nstate = %d q_k = [ %lg %lg %lg ] w = %lg",
74 q, eInfo.qnums[q].k[0],eInfo.qnums[q].k[1], eInfo.qnums[q].k[2], eInfo.qnums[q].weight);
75 logPrintf(" spin = %d\n",eInfo.qnums[q].spin);
76 logPrintf("%4s %13s %13s %13s\n",
77 "band","filling ","diag(Hsub) ","epsilon ");
78 logPrintf("-------------------------------------------------\n");
79 //NOTE: fillings are always 0 to 1 internally, but read/write 0 to 2 for SpinNone
80 double spinFactor = (eInfo.spinType==SpinNone ? 2 : 1);
81 const diagMatrix diagHsubq = diag(eVars.Hsub[q]);
82 for(int i=0; i < eInfo.nBands; i++)
83 logPrintf("%4d %13.6le %13.6le %13.6le\n",
84 i, spinFactor*eVars.F[q][i], diagHsubq[i], eVars.Hsub_eigs[q][i]);
85 }
86 logFlush();
87 }
88