JDFTx  1.2.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  std::vector<ColumnBundle> C;
34  std::vector<diagMatrix> Haux_eigs;
35  std::vector<diagMatrix> F;
36 
37  std::vector<matrix> Hsub;
38  std::vector<matrix> Hsub_evecs;
39  std::vector<diagMatrix> Hsub_eigs;
40 
41  std::vector< std::vector<matrix> > VdagC; //cached pseudopotential projections (by state and then species)
42 
43  //Densities and potentials:
46  ScalarFieldArray get_nXC() const;
47  ScalarField get_nTot() const { return n.size()==1 ? n[0] : n[0]+n[1]; }
48 
50 
53 
54  ScalarFieldArray Vscloc;
56 
57  std::vector<matrix> rhoAtom, U_rhoAtom;
58 
59  //External interactions:
63  struct BoxPotential
64  { vector3<> min, max;
65  double Vin, Vout, convolve_radius;
66  };
67  std::vector<BoxPotential> boxPot;
68 
69  //Fluid properties
71  std::shared_ptr<struct FluidSolver> fluidSolver;
72  string fluidInitialStateFilename;
73 
74  //Wavefunction initialization:
75  string wfnsFilename;
76  std::shared_ptr<struct ColumnBundleReadConversion> readConversion;
77  bool isRandom;
78  bool initLCAO;
79 
80  string eigsFilename;
81 
82  //Auxiliary hamiltonian initialization
84 
87 
88  ElecVars();
89  void setup(const Everything &everything);
90 
93  void EdensityAndVscloc(Energies& ener, const ExCorr* alternateExCorr=0);
94 
97  double elecEnergyAndGrad(Energies& ener, ElecGradient* grad=0, ElecGradient* Kgrad=0, bool calc_Hsub=false);
98 
100  void setEigenvectors();
101 
103  ScalarFieldArray KEdensity() const;
104 
107 
109  void orthonormalize(int q, const matrix* extraRotation=0);
110 
113  double applyHamiltonian(int q, const diagMatrix& Fq, ColumnBundle& HCq, Energies& ener, bool need_Hsub = false);
114 
115 private:
116  const Everything* e;
117 
118  std::vector<string> VexternalFilename;
119  friend struct CommandVexternal;
120 
121  string rhoExternalFilename;
122  friend struct CommandRhoExternal;
123 
124  int lcaoIter;
125  double lcaoTol;
126  int LCAO();
127  friend struct CommandWavefunction;
128  friend struct CommandLcaoParams;
129  friend class Dump;
130 };
131 #endif // JDFTX_ELECTRONIC_ELECVARS_H
std::shared_ptr< struct ColumnBundleReadConversion > readConversion
ColumnBundle conversion.
Definition: ElecVars.h:76
ScalarFieldArray Vtau
Local part of (optionally spin-dependent) self-consistent potential.
Definition: ElecVars.h:55
std::vector< diagMatrix > Hsub_eigs
eigenvalues of Hsub[q]
Definition: ElecVars.h:39
std::vector< matrix > rhoAtom
Gradient w.r.t kinetic energy density (if meta-GGA)
Definition: ElecVars.h:57
string VFilenamePattern
file pattern to read electron (spin,kinetic) potential from
Definition: ElecVars.h:86
std::vector< ScalarField > ScalarFieldArray
dynamic size collection of real space scalar fields
Definition: ScalarFieldArray.h:32
bool HauxInitialized
whether Haux has been read in/computed
Definition: ElecVars.h:83
std::vector< diagMatrix > F
the fillings (diagonal matrices) for each state
Definition: ElecVars.h:35
ScalarFieldArray tau
kinetic energy density including tauCore, if present (computed if a meta GGA is being used) ...
Definition: ElecVars.h:49
General complex matrix.
Definition: matrix.h:58
ScalarFieldArray Vexternal
external potential
Definition: ElecVars.h:60
Definition: ElecVars.h:63
std::shared_ptr< ScalarFieldTildeData > ScalarFieldTilde
A smart reference-counting pointer to ScalarFieldTildeData.
Definition: ScalarField.h:45
Definition: Energies.h:26
std::vector< diagMatrix > Haux_eigs
auxilliary hamiltonian eigenvalues
Definition: ElecVars.h:34
ScalarFieldArray n
electron density (single ScalarField) or spin density (two ScalarFields [up,dn]) or spin density matr...
Definition: ElecVars.h:44
Real diagonal matrix.
Definition: matrix.h:31
void orthonormalize(int q, const matrix *extraRotation=0)
Orthonormalise wavefunctions, with an optional extra rotation.
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:77
std::vector< matrix > Hsub_evecs
eigenvectors of Hsub[q] in columns
Definition: ElecVars.h:38
ScalarFieldTilde rhoExternal
external charge density
Definition: ElecVars.h:61
std::vector< ColumnBundle > C
orthonormal electronic wavefunctions
Definition: ElecVars.h:33
Definition: ElecMinimizer.h:28
string eigsFilename
file to read eigenvalues from
Definition: ElecVars.h:80
Definition: ExCorr.h:72
std::vector< matrix > U_rhoAtom
Atomic density matrices and gradients w.r.t them (for DFT+U)
Definition: ElecVars.h:57
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:85
ScalarField get_nTot() const
return the total electron density (even in spin polarized situations)
Definition: ElecVars.h:47
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:51
Definition: Everything.h:41
Definition: ElecVars.h:30
classes ScalarFieldArray, ScalarFieldTildeArray and just enough operators to enable CG w...
double applyHamiltonian(int q, const diagMatrix &Fq, ColumnBundle &HCq, Energies &ener, bool need_Hsub=false)
ScalarFieldArray nAccumulated
ElecVars::n accumulated over an MD trajectory.
Definition: ElecVars.h:45
FluidSolverParams fluidParams
parameters for the external box potential
Definition: ElecVars.h:70
void setEigenvectors()
Set C to eigenvectors of the subspace hamiltonian.
std::shared_ptr< ScalarFieldData > ScalarField
A smart reference-counting pointer to ScalarFieldData.
Definition: ScalarField.h:41
Extra parameters for fluids:
Definition: FluidSolverParams.h:93
ScalarFieldTilde V_cavity
non-electrostatic potential on electrons due to fluid
Definition: ElecVars.h:52
std::vector< matrix > Hsub
Subspace Hamiltonian: Hsub[q]=C[q]^H*C[q].
Definition: ElecVars.h:37
string wfnsFilename
file to read wavefunctions from
Definition: ElecVars.h:75
bool initLCAO
initialize wave functions using linear combinations of atomic orbitals
Definition: ElecVars.h:78
ScalarFieldArray KEdensity() const
Compute the kinetic energy density.
Definition: ColumnBundle.h:30
bool rhoExternalSelfEnergy
whether to include self-energy of rhoExternal in output energy
Definition: ElecVars.h:62
Stores the list of what to dump and when, and implements the functions to do so.
Definition: Dump.h:59