Skip to content

Commit 1c30f99

Browse files
authored
Refactor: Remove LCAO_Deepks from GlobalC. (#5844)
* Remove GlobalC::ld. * Fix bug for compling without DeePKS.
1 parent c898e52 commit 1c30f99

32 files changed

+517
-590
lines changed

source/module_elecstate/elecstate.h

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
#ifndef ELECSTATE_H
22
#define ELECSTATE_H
3-
#include "module_parameter/parameter.h"
4-
53
#include "fp_energy.h"
64
#include "module_cell/klist.h"
75
#include "module_elecstate/module_charge/charge.h"
6+
#include "module_parameter/parameter.h"
87
#include "module_psi/psi.h"
98
#include "potentials/potential_new.h"
109

@@ -14,10 +13,10 @@ namespace elecstate
1413
class ElecState
1514
{
1615
public:
17-
ElecState(){}
18-
ElecState(Charge* charge_in,
19-
ModulePW::PW_Basis* rhopw_in,
20-
ModulePW::PW_Basis_Big* bigpw_in)
16+
ElecState()
17+
{
18+
}
19+
ElecState(Charge* charge_in, ModulePW::PW_Basis* rhopw_in, ModulePW::PW_Basis_Big* bigpw_in)
2120
{
2221
this->charge = charge_in;
2322
this->charge->set_rhopw(rhopw_in);
@@ -26,20 +25,20 @@ class ElecState
2625
}
2726
virtual ~ElecState()
2827
{
29-
if(this->pot != nullptr)
28+
if (this->pot != nullptr)
3029
{
3130
delete this->pot;
3231
this->pot = nullptr;
3332
}
3433
}
35-
void init_ks(Charge *chg_in, // pointer for class Charge
36-
const K_Vectors *klist_in,
37-
int nk_in, // number of k points
38-
ModulePW::PW_Basis* rhopw_in,
39-
const ModulePW::PW_Basis_Big* bigpw_in);
34+
void init_ks(Charge* chg_in, // pointer for class Charge
35+
const K_Vectors* klist_in,
36+
int nk_in, // number of k points
37+
ModulePW::PW_Basis* rhopw_in,
38+
const ModulePW::PW_Basis_Big* bigpw_in);
4039

4140
// return current electronic density rho, as a input for constructing Hamiltonian
42-
virtual const double *getRho(int spin) const;
41+
virtual const double* getRho(int spin) const;
4342

4443
// calculate electronic charge density on grid points or density matrix in real space
4544
// the consequence charge density rho saved into rho_out, preparing for charge mixing.
@@ -78,17 +77,14 @@ class ElecState
7877

7978
// use occupied weights from INPUT and skip calculate_weights
8079
// mohan updated on 2024-06-08
81-
void fixed_weights(
82-
const std::vector<double>& ocp_kb,
83-
const int &nbands,
84-
const double &nelec);
80+
void fixed_weights(const std::vector<double>& ocp_kb, const int& nbands, const double& nelec);
8581

86-
// if nupdown is not 0(TWO_EFERMI case),
87-
// nelec_spin will be fixed and weights will be constrained
82+
// if nupdown is not 0(TWO_EFERMI case),
83+
// nelec_spin will be fixed and weights will be constrained
8884
void init_nelec_spin();
89-
//used to record number of electrons per spin index
90-
//for NSPIN=2, it will record number of spin up and number of spin down
91-
//for NSPIN=4, it will record total number, magnetization for x, y, z direction
85+
// used to record number of electrons per spin index
86+
// for NSPIN=2, it will record number of spin up and number of spin down
87+
// for NSPIN=4, it will record total number, magnetization for x, y, z direction
9288
std::vector<double> nelec_spin;
9389

9490
virtual void print_psi(const psi::Psi<double>& psi_in, const int istep = -1)
@@ -102,7 +98,7 @@ class ElecState
10298

10399
/**
104100
* @brief Init rho_core, init rho, renormalize rho, init pot
105-
*
101+
*
106102
* @param istep i-th step
107103
* @param ucell unit cell
108104
* @param strucfac structure factor
@@ -142,28 +138,24 @@ class ElecState
142138
void set_exx(const std::complex<double>& Eexx);
143139
#endif //__LCAO
144140
#endif //__EXX
145-
141+
146142
double get_hartree_energy();
147143
double get_etot_efield();
148144
double get_etot_gatefield();
149145

150146
double get_solvent_model_Ael();
151147
double get_solvent_model_Acav();
152148

153-
virtual double get_spin_constrain_energy() {
149+
virtual double get_spin_constrain_energy()
150+
{
154151
return 0.0;
155152
}
156153

157154
double get_dftu_energy();
158155
double get_local_pp_energy();
159156

160-
#ifdef __DEEPKS
161-
double get_deepks_E_delta();
162-
double get_deepks_E_delta_band();
163-
#endif
164-
165-
fenergy f_en; ///< energies contribute to the total free energy
166-
efermi eferm; ///< fermi energies
157+
fenergy f_en; ///< energies contribute to the total free energy
158+
efermi eferm; ///< fermi energies
167159

168160
// below defines the bandgap:
169161

source/module_elecstate/elecstate_energy.cpp

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
#include <cmath>
2-
31
#include "elecstate.h"
42
#include "elecstate_getters.h"
53
#include "module_base/global_variable.h"
64
#include "module_base/parallel_reduce.h"
75
#include "module_parameter/parameter.h"
6+
7+
#include <cmath>
88
#ifdef USE_PAW
99
#include "module_hamilt_general/module_xc/xc_functional.h"
1010
#include "module_hamilt_pw/hamilt_pwdft/global.h"
@@ -103,10 +103,9 @@ double ElecState::cal_delta_eband(const UnitCell& ucell) const
103103
const double* v_eff = this->pot->get_effective_v(0);
104104
const double* v_fixed = this->pot->get_fixed_v();
105105
const double* v_ofk = nullptr;
106-
const bool v_ofk_flag =(get_xc_func_type() == 3
107-
|| get_xc_func_type() == 5);
106+
const bool v_ofk_flag = (get_xc_func_type() == 3 || get_xc_func_type() == 5);
108107
#ifdef USE_PAW
109-
if(PARAM.inp.use_paw)
108+
if (PARAM.inp.use_paw)
110109
{
111110
ModuleBase::matrix v_xc;
112111
const std::tuple<double, double, ModuleBase::matrix> etxc_vtxc_v
@@ -115,19 +114,19 @@ double ElecState::cal_delta_eband(const UnitCell& ucell) const
115114

116115
for (int ir = 0; ir < this->charge->rhopw->nrxx; ir++)
117116
{
118-
deband_aux -= this->charge->rho[0][ir] * v_xc(0,ir);
117+
deband_aux -= this->charge->rho[0][ir] * v_xc(0, ir);
119118
}
120119
if (PARAM.inp.nspin == 2)
121120
{
122121
for (int ir = 0; ir < this->charge->rhopw->nrxx; ir++)
123122
{
124-
deband_aux -= this->charge->rho[1][ir] * v_xc(1,ir);
123+
deband_aux -= this->charge->rho[1][ir] * v_xc(1, ir);
125124
}
126125
}
127126
}
128127
#endif
129128

130-
if(!PARAM.inp.use_paw)
129+
if (!PARAM.inp.use_paw)
131130
{
132131
for (int ir = 0; ir < this->charge->rhopw->nrxx; ir++)
133132
{
@@ -137,16 +136,16 @@ double ElecState::cal_delta_eband(const UnitCell& ucell) const
137136
{
138137
v_ofk = this->pot->get_effective_vofk(0);
139138
// cause in the get_effective_vofk, the func will return nullptr
140-
if(v_ofk==nullptr && this->charge->rhopw->nrxx>0)
139+
if (v_ofk == nullptr && this->charge->rhopw->nrxx > 0)
141140
{
142-
ModuleBase::WARNING_QUIT("ElecState::cal_delta_eband","v_ofk is nullptr");
141+
ModuleBase::WARNING_QUIT("ElecState::cal_delta_eband", "v_ofk is nullptr");
143142
}
144143
for (int ir = 0; ir < this->charge->rhopw->nrxx; ir++)
145144
{
146145
deband_aux -= this->charge->kin_r[0][ir] * v_ofk[ir];
147146
}
148147
}
149-
148+
150149
if (PARAM.inp.nspin == 2)
151150
{
152151
v_eff = this->pot->get_effective_v(1);
@@ -157,9 +156,9 @@ double ElecState::cal_delta_eband(const UnitCell& ucell) const
157156
if (v_ofk_flag)
158157
{
159158
v_ofk = this->pot->get_effective_vofk(1);
160-
if(v_ofk==nullptr && this->charge->rhopw->nrxx>0)
159+
if (v_ofk == nullptr && this->charge->rhopw->nrxx > 0)
161160
{
162-
ModuleBase::WARNING_QUIT("ElecState::cal_delta_eband","v_ofk is nullptr");
161+
ModuleBase::WARNING_QUIT("ElecState::cal_delta_eband", "v_ofk is nullptr");
163162
}
164163
for (int ir = 0; ir < this->charge->rhopw->nrxx; ir++)
165164
{
@@ -219,7 +218,7 @@ double ElecState::cal_delta_escf() const
219218
if (get_xc_func_type() == 3 || get_xc_func_type() == 5)
220219
{
221220
// cause in the get_effective_vofk, the func will return nullptr
222-
assert(v_ofk!=nullptr);
221+
assert(v_ofk != nullptr);
223222
descf -= (this->charge->kin_r[0][ir] - this->charge->kin_r_save[0][ir]) * v_ofk[ir];
224223
}
225224
}
@@ -278,7 +277,7 @@ void ElecState::cal_converged()
278277
/**
279278
* @brief calculate energies
280279
*
281-
* @param type: 1 means Harris-Foulkes functinoal;
280+
* @param type: 1 means Harris-Foulkes functinoal;
282281
* @param type: 2 means Kohn-Sham functional;
283282
*/
284283
void ElecState::cal_energies(const int type)
@@ -292,7 +291,7 @@ void ElecState::cal_energies(const int type)
292291
//! energy from gate-field
293292
this->f_en.gatefield = get_etot_gatefield();
294293

295-
//! energy from implicit solvation model
294+
//! energy from implicit solvation model
296295
if (PARAM.inp.imp_sol)
297296
{
298297
this->f_en.esol_el = get_solvent_model_Ael();
@@ -305,27 +304,19 @@ void ElecState::cal_energies(const int type)
305304
this->f_en.escon = get_spin_constrain_energy();
306305
}
307306

308-
// energy from DFT+U
307+
// energy from DFT+U
309308
if (PARAM.inp.dft_plus_u)
310309
{
311310
this->f_en.edftu = get_dftu_energy();
312311
}
313312

314313
this->f_en.e_local_pp = get_local_pp_energy();
315314

316-
#ifdef __DEEPKS
317-
// energy from deepks
318-
if (PARAM.inp.deepks_scf)
319-
{
320-
this->f_en.edeepks_scf = get_deepks_E_delta() - get_deepks_E_delta_band();
321-
}
322-
#endif
323-
324315
if (type == 1) // Harris-Foulkes functional
325316
{
326317
this->f_en.calculate_harris();
327318
}
328-
else if (type == 2)// Kohn-Sham functional
319+
else if (type == 2) // Kohn-Sham functional
329320
{
330321
this->f_en.calculate_etot();
331322
}

source/module_elecstate/elecstate_energy_terms.cpp

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
#include "module_elecstate/potentials/efield.h"
44
#include "module_elecstate/potentials/gatefield.h"
55
#include "module_hamilt_lcao/module_deepks/LCAO_deepks.h"
6-
#include "module_hamilt_lcao/module_dftu/dftu.h"
76
#include "module_hamilt_lcao/module_deltaspin/spin_constrain.h"
7+
#include "module_hamilt_lcao/module_dftu/dftu.h"
88

99
namespace elecstate
1010
{
@@ -41,25 +41,15 @@ double ElecState::get_dftu_energy()
4141

4242
double ElecState::get_local_pp_energy()
4343
{
44-
double local_pseudopot_energy = 0.; // electron-ion interaction energy from local pseudopotential
44+
double local_pseudopot_energy = 0.; // electron-ion interaction energy from local pseudopotential
4545
for (int is = 0; is < PARAM.inp.nspin; ++is)
4646
{
47-
local_pseudopot_energy += BlasConnector::dot(this->charge->rhopw->nrxx, this->pot->get_fixed_v(), 1, this->charge->rho[is], 1)
48-
* this->charge->rhopw->omega / this->charge->rhopw->nxyz;
47+
local_pseudopot_energy
48+
+= BlasConnector::dot(this->charge->rhopw->nrxx, this->pot->get_fixed_v(), 1, this->charge->rho[is], 1)
49+
* this->charge->rhopw->omega / this->charge->rhopw->nxyz;
4950
}
5051
Parallel_Reduce::reduce_all(local_pseudopot_energy);
5152
return local_pseudopot_energy;
5253
}
5354

54-
#ifdef __DEEPKS
55-
double ElecState::get_deepks_E_delta()
56-
{
57-
return GlobalC::ld.E_delta;
58-
}
59-
double ElecState::get_deepks_E_delta_band()
60-
{
61-
return GlobalC::ld.e_delta_band;
62-
}
63-
#endif
64-
6555
} // namespace elecstate

source/module_elecstate/elecstate_print.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#include "elecstate.h"
22
#include "elecstate_getters.h"
3-
#include "module_parameter/parameter.h"
43
#include "module_base/formatter.h"
54
#include "module_base/global_variable.h"
65
#include "module_elecstate/potentials/H_Hartree_pw.h"
76
#include "module_elecstate/potentials/efield.h"
87
#include "module_elecstate/potentials/gatefield.h"
98
#include "module_hamilt_general/module_xc/xc_functional.h"
109
#include "module_hamilt_lcao/module_deepks/LCAO_deepks.h"
10+
#include "module_parameter/parameter.h"
1111
#include "occupy.h"
1212
namespace elecstate
1313
{
@@ -311,9 +311,10 @@ void ElecState::print_etot(const Magnetism& magnet,
311311

312312
GlobalV::ofs_running << "\n Density error is " << scf_thr << std::endl;
313313

314-
if (PARAM.inp.basis_type == "pw") {
314+
if (PARAM.inp.basis_type == "pw")
315+
{
315316
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "Error Threshold", pw_diag_thr); // xiaohui add 2013-09-02
316-
}
317+
}
317318

318319
std::vector<std::string> titles;
319320
std::vector<double> energies_Ry;
@@ -378,7 +379,7 @@ void ElecState::print_etot(const Magnetism& magnet,
378379
if (PARAM.inp.deepks_scf) // caoyu add 2021-08-10
379380
{
380381
titles.push_back("E_DeePKS");
381-
energies_Ry.push_back(GlobalC::ld.E_delta);
382+
energies_Ry.push_back(this->f_en.edeepks_delta);
382383
}
383384
#endif
384385
}

source/module_elecstate/fp_energy.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,13 @@ struct fenergy
3939
double esol_el = 0.0; ///< the implicit solvation energy Ael
4040
double esol_cav = 0.0; ///< the implicit solvation energy Acav
4141

42-
double edftu = 0.0; ///< DFT+U energy
43-
double edeepks_scf = 0.0; /// DeePKS energy
42+
double edftu = 0.0; ///< DFT+U energy
43+
double edeepks_scf = 0.0; /// DeePKS energy difference
44+
double edeepks_delta = 0.0; /// DeePKS energy
4445

4546
double escon = 0.0; ///< spin constraint energy
4647

47-
double ekinetic = 0.0; /// kinetic energy, used in OFDFT
48+
double ekinetic = 0.0; /// kinetic energy, used in OFDFT
4849
double e_local_pp = 0.0; /// ion-electron interaction energy contributed by local pp, used in OFDFT
4950

5051
double calculate_etot();

0 commit comments

Comments
 (0)