JDFTx  1.1.0
ElecVars.h
1 /*-------------------------------------------------------------------
2 Copyright 2011 Ravishankar Sundararaman
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_ELECVARS_H
22 #define JDFTX_ELECTRONIC_ELECVARS_H
23 
24 #include <electronic/common.h>
26 #include <core/ScalarFieldArray.h>
27 #include <string>
28 #include <memory>
29 
30 class ElecVars
31 {
32 public:
33  //Independent variables:
34  std::vector<ColumnBundle> Y;
35  std::vector<matrix> B;
37 
38  //Derived quantities:
39  std::vector<matrix> B_evecs;
40  std::vector<diagMatrix> B_eigs;
41 
42  std::vector<matrix> Hsub;
43  std::vector<matrix> Hsub_evecs;
44  std::vector<diagMatrix> Hsub_eigs;
45 
46  std::vector<ColumnBundle> C;
47  std::vector<diagMatrix> F;
48 
49  std::vector< std::vector<matrix> > VdagC; //cached pseudopotential projections (by state and then species)
50  std::vector<matrix> grad_CdagOC;
51 
52  //Densities and potentials:
54  ScalarFieldArray get_nXC() const;
55  ScalarField get_nTot() const { return n.size()==1 ? n[0] : n[0]+n[1]; }
56 
58 
61 
62  ScalarFieldArray Vscloc;
64 
65  std::vector<matrix> rhoAtom, U_rhoAtom;
66 
67  //External interactions:
71  struct BoxPotential
72  { vector3<> min, max;
73  double Vin, Vout, convolve_radius;
74  };
75  std::vector<BoxPotential> boxPot;
76 
77  //Fluid properties
79  std::shared_ptr<struct FluidSolver> fluidSolver;
80  string fluidInitialStateFilename;
81 
82  //Wavefunction initialization:
83  string wfnsFilename;
84  std::shared_ptr<struct ColumnBundleReadConversion> readConversion;
85  bool isRandom;
86  bool initLCAO;
87 
88  string eigsFilename;
89 
90  //Auxiliary hamiltonian initialization
91  string HauxFilename;
93 
95 
98 
99  ElecVars();
100  void setup(const Everything &everything);
101 
104  void EdensityAndVscloc(Energies& ener, const ExCorr* alternateExCorr=0);
105 
108  double elecEnergyAndGrad(Energies& ener, ElecGradient* grad=0, ElecGradient* Kgrad=0, bool calc_Hsub=false);
109 
112  void setEigenvectors(int q=-1);
113 
115  int nOccupiedBands(int q) const;
116 
118  ScalarFieldArray KEdensity() const;
119 
122 
124  void orthonormalize(int q);
125 
131  double applyHamiltonian(int q, const diagMatrix& Fq, ColumnBundle& HCq, Energies& ener, bool need_Hsub=false);
132 
134  void orthonormalizeGrad(int q, const diagMatrix& Fq, const ColumnBundle& HCq, ColumnBundle& gradYq, double KErollover=1., ColumnBundle* KgradYq=0, matrix* gradBq=0, matrix* KgradBq=0);
135 
137  double bandEnergyAndGrad(int q, Energies& ener, ColumnBundle* grad=0, ColumnBundle* Kgrad=0);
138 
139 private:
140  const Everything* e;
141 
142  std::vector<string> VexternalFilename;
143  friend struct CommandVexternal;
144  friend class InverseKohnSham;
145 
146  string rhoExternalFilename;
147  friend struct CommandRhoExternal;
148 
149  int lcaoIter;
150  double lcaoTol;
151  int LCAO();
152  friend struct CommandWavefunction;
153  friend struct CommandLcaoParams;
154  friend class Dump;
155 
157  std::vector<matrix> U; // U[q] = Y[q]^O(Y[q])
158  std::vector<matrix> U_evecs; // eigenvectors of U[q] in columns
159  std::vector<diagMatrix> U_eigs; // eigenvalues of U[q]
160  std::vector<matrix> Umhalf; // Uhmalf[q] = invsqrt(U[q])
161  std::vector<matrix> V; // V=cis(B) or dagger(B_evecs) for subspace rotations / aux hamiltonian respectively
162 };
163 #endif // JDFTX_ELECTRONIC_ELECVARS_H
std::shared_ptr< struct ColumnBundleReadConversion > readConversion
ColumnBundle conversion.
Definition: ElecVars.h:84
ScalarFieldArray Vtau
Local part of (optionally spin-dependent) self-consistent potential.
Definition: ElecVars.h:63
std::vector< diagMatrix > Hsub_eigs
eigenvalues of Hsub[q]
Definition: ElecVars.h:44
std::vector< matrix > rhoAtom
Gradient w.r.t kinetic energy density (if meta-GGA)
Definition: ElecVars.h:65
string VFilenamePattern
file pattern to read electron (spin,kinetic) potential from
Definition: ElecVars.h:97
std::vector< ScalarField > ScalarFieldArray
dynamic size collection of real space scalar fields
Definition: ScalarFieldArray.h:32
std::vector< diagMatrix > B_eigs
eigenvalues of B[q]
Definition: ElecVars.h:40
bool HauxInitialized
whether Haux has been read in/computed
Definition: ElecVars.h:92
std::vector< matrix > B_evecs
eigenvectors of B[q] in columns
Definition: ElecVars.h:39
std::vector< diagMatrix > F
the fillings (diagonal matrices) for each state
Definition: ElecVars.h:47
ScalarFieldArray tau
kinetic energy density including tauCore, if present (computed if a meta GGA is being used) ...
Definition: ElecVars.h:57
string HauxFilename
file to read auxilliary hamiltonian (B) from (used only for FermiFillingsAux mode) ...
Definition: ElecVars.h:91
std::vector< matrix > grad_CdagOC
gradient w.r.t overlap (required for forces when O is atom dependent)
Definition: ElecVars.h:50
General complex matrix.
Definition: matrix.h:57
ScalarFieldArray Vexternal
external potential
Definition: ElecVars.h:68
void setEigenvectors(int q=-1)
Definition: ElecVars.h:71
std::vector< ColumnBundle > Y
unconstrained electronic wavefunctions
Definition: ElecVars.h:34
std::shared_ptr< ScalarFieldTildeData > ScalarFieldTilde
A smart reference-counting pointer to ScalarFieldTildeData.
Definition: ScalarField.h:44
Definition: Energies.h:26
ScalarFieldArray n
electron density (single ScalarField) or spin density (two ScalarFields [up,dn]) or spin density matr...
Definition: ElecVars.h:53
void orthonormalize(int q)
Orthonormalise Y to compute C, U and its cohorts for a quantum number q.
Real diagonal matrix.
Definition: matrix.h:30
double elecEnergyAndGrad(Energies &ener, ElecGradient *grad=0, ElecGradient *Kgrad=0, bool calc_Hsub=false)
bool isRandom
indicates whether the electronic state is random (not yet minimized)
Definition: ElecVars.h:85
std::vector< matrix > Hsub_evecs
eigenvectors of Hsub[q] in columns
Definition: ElecVars.h:43
double subspaceRotationFactor
preconditioning factor for subspace rotations / aux hamiltonian relative to wavefunctions ...
Definition: ElecVars.h:36
ScalarFieldTilde rhoExternal
external charge density
Definition: ElecVars.h:69
std::vector< ColumnBundle > C
orthonormal wavefunctions (after appropriate subspace rotation)
Definition: ElecVars.h:46
std::vector< matrix > B
subspace rotation / auxilliary hamiltonian
Definition: ElecVars.h:35
Definition: ElecMinimizer.h:28
string eigsFilename
file to read eigenvalues from
Definition: ElecVars.h:88
Definition: ExCorr.h:72
std::vector< matrix > U_rhoAtom
Atomic density matrices and gradients w.r.t them (for DFT+U)
Definition: ElecVars.h:65
ScalarFieldArray get_nXC() const
return the total (spin) density including core contributions
string nFilenamePattern
file pattern to read electron (spin,kinetic) density from
Definition: ElecVars.h:96
ScalarField get_nTot() const
return the total electron density (even in spin polarized situations)
Definition: ElecVars.h:55
void EdensityAndVscloc(Energies &ener, const ExCorr *alternateExCorr=0)
ScalarFieldArray calcDensity() const
Calculate density using current orthonormal wavefunctions (C)
ScalarFieldTilde d_fluid
electrostatic potential due to fluid
Definition: ElecVars.h:59
Definition: Everything.h:41
Definition: ElecVars.h:30
classes ScalarFieldArray, ScalarFieldTildeArray and just enough operators to enable CG w...
double bandEnergyAndGrad(int q, Energies &ener, ColumnBundle *grad=0, ColumnBundle *Kgrad=0)
Returns the total single particle energy and gradient of all KS orbitals.
double applyHamiltonian(int q, const diagMatrix &Fq, ColumnBundle &HCq, Energies &ener, bool need_Hsub=false)
FluidSolverParams fluidParams
parameters for the external box potential
Definition: ElecVars.h:78
int nOccupiedBands(int q) const
Return the number of occupied bands (f > occupiedThrehsold) for a given state.
std::shared_ptr< ScalarFieldData > ScalarField
A smart reference-counting pointer to ScalarFieldData.
Definition: ScalarField.h:40
Extra parameters for fluids:
Definition: FluidSolverParams.h:93
ScalarFieldTilde V_cavity
non-electrostatic potential on electrons due to fluid
Definition: ElecVars.h:60
std::vector< matrix > Hsub
Subspace Hamiltonian: Hsub[q]=C[q]^H*C[q].
Definition: ElecVars.h:42
string wfnsFilename
file to read wavefunctions from
Definition: ElecVars.h:83
void orthonormalizeGrad(int q, const diagMatrix &Fq, const ColumnBundle &HCq, ColumnBundle &gradYq, double KErollover=1., ColumnBundle *KgradYq=0, matrix *gradBq=0, matrix *KgradBq=0)
Propagates the gradient wrt orthonormal C (HCq) to gradient wrt Y and B (if given).
bool initLCAO
initialize wave functions using linear combinations of atomic orbitals
Definition: ElecVars.h:86
ScalarFieldArray KEdensity() const
Compute the kinetic energy density.
Definition: ColumnBundle.h:30
double overlapCondition
Current condition number of the orbital overlap matrix (over all states)
Definition: ElecVars.h:94
Definition: InverseKohnSham.h:27
bool rhoExternalSelfEnergy
whether to include self-energy of rhoExternal in output energy
Definition: ElecVars.h:70
Stores the list of what to dump and when, and implements the functions to do so.
Definition: Dump.h:59