Repository navigation
Expand file tree
/
Copy pathdebugE.cpp
More file actions
130 lines (112 loc) · 3.7 KB
/
Copy pathdebugE.cpp
File metadata and controls
130 lines (112 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*-------------------------------------------------------------------
Copyright 2022 Ravishankar Sundararaman
This file is part of JDFTx.
JDFTx is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
JDFTx is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with JDFTx. If not, see <http://www.gnu.org/licenses/>.
-------------------------------------------------------------------*/
#include <core/Util.h>
#include <core/matrix.h>
#include "FeynWann.h"
#include "InputMap.h"
#include <core/Units.h>
//Read a list of k-points from a file
std::vector<vector3<>> readKpointsFile(string fname)
{ std::vector<vector3<>> kArr;
logPrintf("Reading '%s' ... ", fname.c_str()); logFlush();
ifstream ifs(fname); if(!ifs.is_open()) die("could not open file.\n");
while(!ifs.eof())
{ string line; getline(ifs, line);
trim(line);
if(!line.length()) continue;
//Parse line
istringstream iss(line);
string key; iss >> key;
if(key == "kpoint")
{ vector3<> k;
iss >> k[0] >> k[1] >> k[2];
kArr.push_back(k);
}
}
ifs.close();
logPrintf("done.\n");
return kArr;
}
//Write debug code within process() to examine arbitrary electronic properties along a k-path
struct DebugE
{
FeynWann::StateE e; //updated for each k before calling process()
std::vector<diagMatrix> Earr;
std::vector<matrix> Larr;
std::vector<matrix> Qarr;
void process()
{ logPrintf("k: "); e.k.print(globalLog, " %9.6lf ");
Earr.push_back(e.E);
for(int iDir=0; iDir<3; iDir++) Larr.push_back(e.L[iDir]);
for(int iComp=0; iComp<5; iComp++) Qarr.push_back(e.Q[iComp]);
}
void saveOutputs()
{ write(Earr, "debug.E");
write(Larr, "debug.L");
write(Qarr, "debug.Q");
}
static void write(const std::vector<diagMatrix>& Marr, string fname)
{ logPrintf("Dumping '%s' ... ", fname.c_str()); logFlush();
FILE* fp = fopen(fname.c_str(), "w");
for(const diagMatrix& M: Marr)
fwrite(M.data(), sizeof(double), M.nRows(), fp);
fclose(fp);
logPrintf("done.\n"); logFlush();
}
static void write(const std::vector<matrix>& Marr, string fname)
{ logPrintf("Dumping '%s' ... ", fname.c_str()); logFlush();
FILE* fp = fopen(fname.c_str(), "w");
for(const matrix& M: Marr)
M.write(fp);
fclose(fp);
logPrintf("done.\n"); logFlush();
}
};
int main(int argc, char** argv)
{
InitParams ip = FeynWann::initialize(argc, argv, "Debug electronic matrix elements.");
//Get the system parameters (mu, T, lattice vectors etc.)
InputMap inputMap(ip.inputFilename);
string kFile = inputMap.getString("kFile"); //file containing list of k-points (like a bandstruct.kpoints file)
FeynWannParams fwp(&inputMap);
logPrintf("\nInputs after conversion to atomic units:\n");
logPrintf("kFile = %s\n", kFile.c_str());
fwp.printParams();
//Read k-points:
std::vector<vector3<>> kArr = readKpointsFile(kFile);
logPrintf("Read %lu k-points from '%s'\n", kArr.size(), kFile.c_str());
//Initialize FeynWann:
fwp.needL = true;
fwp.needQ = true;
fwp.ePhHeadOnly = true; //so as to debug k-path alone
FeynWann fw(fwp);
if(ip.dryRun)
{ logPrintf("Dry run successful: commands are valid and initialization succeeded.\n");
fw.free();
FeynWann::finalize();
return 0;
}
logPrintf("\n");
DebugE de;
for(vector3<> k: kArr)
{ fw.eCalc(k, de.e);
if(mpiGroup->isHead())
de.process();
}
de.saveOutputs();
fw.free();
FeynWann::finalize();
return 0;
}