JDFTx  1.2.1
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 
77  SmearingCold
78  }
79  smearingType;
80  double smearingWidth;
81  double mu;
82  bool muLoop;
83 
84  bool hasU;
85 
87 
88  ElecInfo();
89  void setup(const Everything &e, std::vector<diagMatrix>& F, Energies& ener);
90  void printFillings(FILE* fp) const;
91  void smearReport(const double* muOverride=0) const; //Smearing report (compute mu from eigenvalues in eVars if muOverride not provided)
92  void updateFillingsEnergies(const std::vector<diagMatrix>& eps, Energies&) const;
93 
94  //Smearing function utilities:
95  inline double muEff(double mu, double Bz, int q) const { return mu + Bz*qnums[q].spin; }
96  double smear(double mu, double eps) const;
97  double smearPrime(double mu, double eps) const;
98  double smearEntropy(double mu, double eps) const;
99  diagMatrix smear(double mu, const diagMatrix& eps) const;
100  diagMatrix smearPrime(double mu, const diagMatrix& eps) const;
101  diagMatrix smearEntropy(double mu, const diagMatrix& eps) const;
102 
104  matrix smearGrad(double mu, const diagMatrix& eps, const matrix& gradF) const;
105 
108  double nElectronsCalc(double mu, const std::vector<diagMatrix>& eps, double& Bz) const;
109 
112  double findMu(const std::vector<diagMatrix>& eps, double nElectrons, double& Bz) const;
113 
114  void kpointsPrint(FILE* fp, bool printSpin=false) const;
115  void kpointPrint(FILE* fp, int q, bool printSpin=false) const;
116 
117  int findHOMO(int q) const;
118 
119  //Parallel I/O utilities for diagMatrix/matrix array (one-per-kpoint, with nBands rows and columns unless overridden):
120  void read(std::vector<diagMatrix>&, const char *fname, int nRowsOverride=0) const;
121  void read(std::vector<matrix>&, const char *fname, int nRowsOverride=0, int nColsOverride=0) const;
122  void write(const std::vector<diagMatrix>&, const char *fname, int nRowsOverride=0) const;
123  void write(const std::vector<matrix>&, const char *fname, int nRowsOverride=0, int nColsOverride=0) const;
124  void appendWrite(const std::vector<diagMatrix>&, const char *fname, int nRowsOverride=0) const;
125 
126 private:
127  const Everything* e;
128  TaskDivision qDivision;
129 
130  //Initial fillings:
131  int nBandsOld;
132  double Qinitial, Minitial;
133  bool Mconstrain;
134  friend struct CommandElecInitialFillings;
135  friend struct CommandElecInitialCharge;
136  friend struct CommandElecInitialMagnetization;
137  friend struct CommandInitialState;
138  friend class ElecVars;
139  friend struct LCAOminimizer;
140 
142  double magnetizationCalc(double mu, double Bz, const std::vector<diagMatrix>& eps, double& nElectrons) const;
143 
144  //k-points:
145  vector3<int> kfold;
146  friend struct CommandKpointFolding;
147  friend class Everything;
148  friend class Phonon;
149  void kpointsFold();
150  void kpointsReduce();
151 };
152 
153 #endif // JDFTX_ELECTRONIC_ELECINFO_H
std::vector< QuantumNumber > qnums
k-points, spins and weights for each state
Definition: ElecInfo.h:62
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 muLoop
Whether to optimize mu in an outer loop over fixed charge calculations.
Definition: ElecInfo.h:82
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:86
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
Fermi-Dirac smearing.
Definition: ElecInfo.h:75
Real diagonal matrix.
Definition: matrix.h:31
Definition: ElecInfo.h:35
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 smearingWidth
Smearing width (temperature in the Fermi case)
Definition: ElecInfo.h:80
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:81
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
Gaussian smearing.
Definition: ElecInfo.h:76
int nStates
Number of bands and total number of states.
Definition: ElecInfo.h:52
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
SmearingType
Definition: ElecInfo.h:74