JDFTx  1.2.0
ElecInfo.h
1 /*-------------------------------------------------------------------
2 Copyright 2011 Ravishankar Sundararaman, Kendra Letchworth Weaver
3 Copyright 1996-2003 Sohrab Ismail-Beigi
4 
5 This file is part of JDFTx.
6 
7 JDFTx is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 JDFTx is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with JDFTx. If not, see <http://www.gnu.org/licenses/>.
19 -------------------------------------------------------------------*/
20 
21 #ifndef JDFTX_ELECTRONIC_ELECINFO_H
22 #define JDFTX_ELECTRONIC_ELECINFO_H
23 
24 #include <electronic/common.h>
25 #include <core/vector3.h>
26 
28 enum SpinType {
29  SpinNone,
30  SpinZ,
31  SpinVector,
32  SpinOrbit
33 };
34 
36 {
37 public:
39  int spin;
40  double weight;
41 
42  QuantumNumber() : spin(0) {}
43  int index() const { return spin<0 ? 1 : 0; }
44 };
45 
47 inline vector3<> getCoord(const QuantumNumber& qnum) { return qnum.k; }
48 
49 class ElecInfo
50 {
51 public:
52  int nBands, nStates;
53  int nDensities, spinWeight, qWeightSum;
54  int qStart, qStop;
55  bool isMine(int q) const { return qDivision.isMine(q); }
56  int whose(int q) const { return qDivision.whose(q); }
57  int qStartOther(int iProc) const { return qDivision.start(iProc); }
58  int qStopOther(int iProc) const { return qDivision.stop(iProc); }
59 
60  SpinType spinType;
61  double nElectrons;
62  std::vector<QuantumNumber> qnums;
63 
64  bool isNoncollinear() const { return spinType==SpinVector || spinType==SpinOrbit; }
65  int spinorLength() const { return isNoncollinear() ? 2 : 1; }
66 
69  FillingsHsub
70  }
71  fillingsUpdate;
73 
74  double kT;
75  double mu;
76 
77  bool hasU;
78 
80 
81  ElecInfo();
82  void setup(const Everything &e, std::vector<diagMatrix>& F, Energies& ener);
83  void printFillings(FILE* fp) const;
84  void printFermi(const double* muOverride=0) const; //Fermi fillings report (compute mu from eigenvalues in eVars if muOverride not provided)
85  void updateFillingsEnergies(const std::vector<diagMatrix>& F, Energies&) const;
86 
87  //Fermi function utilities:
88  inline double muEff(double mu, double Bz, int q) const { return mu + Bz*qnums[q].spin; }
89  double fermi(double mu, double eps) const { return 0.5*(1.-tanh(betaBy2*(eps-mu))); }
90  double fermiPrime(double mu, double eps) const { return -0.5*betaBy2/pow(cosh(betaBy2*(eps-mu)), 2); }
91  diagMatrix fermi(double mu, const diagMatrix& eps) const;
92  diagMatrix fermiPrime(double mu, const diagMatrix& eps) const;
93 
95  matrix fermiGrad(double mu, const diagMatrix& eps, const matrix& gradF) const;
96 
99  double nElectronsFermi(double mu, const std::vector<diagMatrix>& eps, double& Bz) const;
100 
103  double findMu(const std::vector<diagMatrix>& eps, double nElectrons, double& Bz) const;
104 
105  void kpointsPrint(FILE* fp, bool printSpin=false) const;
106  void kpointPrint(FILE* fp, int q, bool printSpin=false) const;
107 
108  int findHOMO(int q) const;
109 
110  //Parallel I/O utilities for diagMatrix/matrix array (one-per-kpoint, with nBands rows and columns unless overridden):
111  void read(std::vector<diagMatrix>&, const char *fname, int nRowsOverride=0) const;
112  void read(std::vector<matrix>&, const char *fname, int nRowsOverride=0, int nColsOverride=0) const;
113  void write(const std::vector<diagMatrix>&, const char *fname, int nRowsOverride=0) const;
114  void write(const std::vector<matrix>&, const char *fname, int nRowsOverride=0, int nColsOverride=0) const;
115  void appendWrite(const std::vector<diagMatrix>&, const char *fname, int nRowsOverride=0) const;
116 
117 private:
118  const Everything* e;
119  double betaBy2;
120  TaskDivision qDivision;
121 
122  //Initial fillings:
123  int nBandsOld;
124  double Qinitial, Minitial;
125  bool Mconstrain;
126  friend struct CommandElecInitialFillings;
127  friend struct CommandElecInitialCharge;
128  friend struct CommandElecInitialMagnetization;
129  friend struct CommandInitialState;
130  friend class ElecVars;
131  friend struct LCAOminimizer;
132 
134  double magnetizationFermi(double mu, double Bz, const std::vector<diagMatrix>& eps, double& nElectrons) const;
135 
136  //k-points:
137  vector3<int> kfold;
138  friend struct CommandKpointFolding;
139  friend class Everything;
140  friend class Phonon;
141  void kpointsFold();
142  void kpointsReduce();
143 };
144 
145 #endif // JDFTX_ELECTRONIC_ELECINFO_H
std::vector< QuantumNumber > qnums
k-points, spins and weights for each state
Definition: ElecInfo.h:62
ScalarField pow(const ScalarField &, double alpha)
Elementwise power (preserve input)
int index() const
return the appropriate index into electron (spin) density/potential arrays
Definition: ElecInfo.h:43
vector3 k
k-point wave vector
Definition: ElecInfo.h:38
bool scalarFillings
whether fillings are scalar (equal for all bands) at all quantum numbers
Definition: ElecInfo.h:72
string initialFillingsFilename
Flag to check whether the calculation has a DFT+U self-interaction correction.
Definition: ElecInfo.h:79
General complex matrix.
Definition: matrix.h:58
int qStop
Range of states handled by current process (= 0 and nStates for non-MPI jobs)
Definition: ElecInfo.h:54
Definition: Energies.h:26
int whose(int q) const
find out which process this state index belongs to
Definition: ElecInfo.h:56
double weight
state weight (= 1x or 2x k-point weight depending on spintype)
Definition: ElecInfo.h:40
Real diagonal matrix.
Definition: matrix.h:31
Definition: ElecInfo.h:35
double fermiPrime(double mu, double eps) const
derivative of fermi function
Definition: ElecInfo.h:90
Calculate phonon dispersion, free energies and electron-phonon matrix elements.
Definition: Phonon.h:47
SpinType spinType
tells us what sort of spins we are using if any
Definition: ElecInfo.h:60
int qStartOther(int iProc) const
find out qStart for another process
Definition: ElecInfo.h:57
int spin
possible spin orientation. up=1, down=-1, none=0
Definition: ElecInfo.h:39
FillingsUpdate
Definition: ElecInfo.h:67
double fermi(double mu, double eps) const
fermi function
Definition: ElecInfo.h:89
bool isMine(int q) const
check if state index is local
Definition: ElecInfo.h:55
double mu
If NaN, fix nElectrons, otherwise fix/target chemical potential to this.
Definition: ElecInfo.h:75
double nElectrons
the number of electrons = Sum w Tr[F]
Definition: ElecInfo.h:61
constant fillings (T=0)
Definition: ElecInfo.h:68
Definition: Everything.h:41
Definition: ElecVars.h:30
Definition: ElecInfo.h:49
int nStates
Number of bands and total number of states.
Definition: ElecInfo.h:52
double kT
Temperature for Fermi distribution of fillings.
Definition: ElecInfo.h:74
int qStopOther(int iProc) const
find out qStop for another process
Definition: ElecInfo.h:58
Definition: MPIUtil.h:87
int qWeightSum
number of density components, spin weight factor (= max occupation per state) and sum of k-point weig...
Definition: ElecInfo.h:53