1 /*-------------------------------------------------------------------
2 Copyright 2011 Ravishankar Sundararaman
3 
4 This file is part of JDFTx.
5 
6 JDFTx is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10 
11 JDFTx is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15 
16 You should have received a copy of the GNU General Public License
17 along with JDFTx.  If not, see <http://www.gnu.org/licenses/>.
18 -------------------------------------------------------------------*/
19 
20 #ifndef JDFTX_ELECTRONIC_EXCORR_H
21 #define JDFTX_ELECTRONIC_EXCORR_H
22 
23 #include <core/ScalarFieldArray.h>
24 
25 //! @addtogroup ExchangeCorrelation
26 //! @{
27 //! @file ExCorr.h Class ExCorr and helpers
28 
29 //! Types of exchange correlation functionals
30 enum ExCorrType
31 {
32 	ExCorrLDA_PZ, //!< Perdew-Zunger LDA
33 	ExCorrLDA_PW, //!< Perdew-Wang LDA (original version used in PW91)
34 	ExCorrLDA_PW_prec, //!< Perdew-Wang LDA with higher precision constants used in PBE
35 	ExCorrLDA_VWN, //!< Vosko-Wilk-Nusair LDA
36 	ExCorrLDA_Teter, //!< Teter93 LSDA functional
37 	ExCorrGGA_PBE, //!< PBE GGA functional
38 	ExCorrGGA_PBEsol, //!< PBE GGA functional reparametrized for solids
39 	ExCorrGGA_PW91, //!< PW91 GGA functional
40 	ExCorrMGGA_TPSS, //!< TPSS meta-GGA functional
41 	ExCorrMGGA_revTPSS, //!< revised meta-GGA functional
42 #ifdef LIBXC_ENABLED
43 	ExCorrLibXC,
44 #endif
45 	ExCorrORB_GLLBsc, //!< GLLB-sc orbital-dependent potential (no total energy)
46 	ExCorrPOT_LB94, //!< Leeuwen-Baerends potentialfunctional (no total energy)
47 	ExCorrHYB_PBE0, //!< PBE0 Hybrid GGA functional
48 	ExCorrHYB_HSE06, //!< HSE06 Screened Hybrid GGA functional
49 	ExCorrHYB_HSE12, //! Reparametrized screened exchange functional for accuracy
50 	ExCorrHYB_HSE12s, //! Reparametrized screened exchange functional for minimum screening length
51 	ExCorrHF //!< Hartree-Fock
52 };
53 
54 //! Types of kinetic energy functionals
55 enum KineticType
56 {
57 #ifdef LIBXC_ENABLED
58 	KineticLibXC,
59 #endif
60 	KineticNone, //!< No kinetic energy (default)
61 	KineticTF, //!< Thomas-Fermi LDA kinetic energy
62 	KineticVW, //!< von Weisacker GGA kinetic energy
63 	KineticPW91 //!< PW91 GGA kinetic energy
64 };
65 
66 //! Which components to include in the results of ExCorr::operator()
67 struct IncludeTXC
68 {	bool T; //!< kinetic
69 	bool X; //!< exchange
70 	bool C; //!< correlation
71 
TIncludeTXC72 	IncludeTXC(bool T=false, bool X=true, bool C=true) : T(T), X(X), C(C) {} //!< defaults to exchange-correlation without kinetic
73 };
74 
75 //! Exchange-Correlation energy calculator
76 class ExCorr
77 {
78 public:
79 	ExCorr(ExCorrType exCorrType=ExCorrGGA_PBE, KineticType kineticType=KineticNone);
80 	void setup(const Everything&); //!< Initialize
81 	string getName() const; //!< Get a description of the DFT functional
82 
83 	//! Compute the exchange-correlation energy (and optionally gradient) for a (spin) density n.
84 	//! includeTXC selects which components to include in result (XC without kinetic by default).
85 	//! Orbital KE density tau must be provided if needsKEdensity() is true (for meta GGAs)
86 	//! and the corresponding gradient will be returned in Vtau if non-null
87 	//! For metaGGAs, Vtau should be non-null if Vxc is non-null
88 	//! Optionally compute stress due to XC if Exc_RRT is non-null
89 	double operator()(const ScalarFieldArray& n, ScalarFieldArray* Vxc=0, IncludeTXC includeTXC=IncludeTXC(),
90 		const ScalarFieldArray* tau=0, ScalarFieldArray* Vtau=0, matrix3<>* Exc_RRT=0) const;
91 
92 	//! Unpolarized wrapper to above function
93 	double operator()(const ScalarField& n, ScalarField* Vxc=0, IncludeTXC includeTXC=IncludeTXC(),
94 		const ScalarField* tau=0, ScalarField* Vtau=0, matrix3<>* Exc_RRT=0) const;
95 
96 	double exxFactor() const; //!< retrieve the exact exchange scale factor (0 if no exact exchange)
97 	double exxRange() const; //!< range parameter (omega) for screened exchange (0 for long-range exchange)
98 	bool needsKEdensity() const; //!< whether orbital KE density is required as an input (for meta GGAs)
99 	bool hasEnergy() const; //!< whether functional supports a total energy (if not, only usable in SCF, and no forces)
100 
101 	//!Compute second derivatives of energy density w.r.t n and sigma=|grad n|^2
102 	//! by finite difference (supported only for spin-unpolarized internal LDAs and GGAs).
103 	//! All sigma derivatives will be null on output for LDAs.
104 	//! The gradients will be set to zero for regions with n < nCut (useful to reduce numerical sensitivity in systems with empty space)
105 	void getSecondDerivatives(const ScalarField& n, ScalarField& e_nn, ScalarField& e_sigma, ScalarField& e_nsigma, ScalarField& e_sigmasigma, double nCut=1e-4) const;
106 
107 	//! Abstract base class (interface specification) for orbital-dependent potential functionals
108 	struct OrbitalDep
OrbitalDepOrbitalDep109 	{	OrbitalDep(const Everything& e) : e(e) {}
110 		virtual ~OrbitalDep() {}
111 		virtual bool ignore_nCore() const=0; //!< Whether partial cores need to be ignored for this functional
112 		virtual ScalarFieldArray getPotential() const=0; //!< Return orbital-dependent portion of potential (obtains any necessary electronic property directly from ElecVars / ElecInfo)
113 		virtual void dump() const=0; //!< Dump any functional-specific quantities
114 	protected:
115 		const Everything& e;
116 	};
117 	std::shared_ptr<OrbitalDep> orbitalDep; //optional orbital-dependent potential functional
118 
119 private:
120 	const Everything* e;
121 	ExCorrType exCorrType;
122 	KineticType kineticType;
123 	string xcName; // short name of the functional (set by command elec-ex-corr)
124 	friend struct CommandElecExCorr;
125 	friend struct CommandFluidExCorr;
126 
127 	double exxScale; //scale factor for exact exchange
128 	double exxOmega; //Range parameter for exact exchange
129 
130 	double exxScaleOverride, exxOmegaOverride; //override default values of EXX scale and omega
131 	friend struct CommandExchangeParameters; //command that sets the override parameters
132 
133 	std::shared_ptr<struct FunctionalList> functionals; //List of component functionals
134 #ifdef LIBXC_ENABLED
135 	int xcExchange, xcCorr, xcExcorr, xcKinetic; //LibXC codes for various functional components (0 if unused)
136 #endif
137 };
138 
139 //! @}
140 #endif // JDFTX_ELECTRONIC_EXCORR_H
141