Skip to content

Commit 091edef

Browse files
committed
Refactor: add XC_Functional::get_has_kedf()
1 parent 8232993 commit 091edef

39 files changed

+122
-119
lines changed

source/Makefile.Objects

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,6 @@ OBJS_SRCPW=H_Ewald_pw.o\
651651
vnl_op.o\
652652
global.o\
653653
magnetism.o\
654-
elecstate_getters.o\
655654
occupy.o\
656655
structure_factor.o\
657656
structure_factor_k.o\

source/module_elecstate/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
list(APPEND objects
22
elecstate.cpp
3-
elecstate_getters.cpp
43
elecstate_energy_terms.cpp
54
elecstate_energy.cpp
65
elecstate_exx.cpp

source/module_elecstate/elecstate_energy.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "elecstate.h"
2-
#include "elecstate_getters.h"
32
#include "module_base/global_variable.h"
43
#include "module_base/parallel_reduce.h"
4+
#include "module_hamilt_general/module_xc/xc_functional.h"
55
#include "module_parameter/parameter.h"
66

77
#include <cmath>
@@ -103,7 +103,7 @@ 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 || get_xc_func_type() == 5);
106+
const bool v_ofk_flag = (XC_Functional::get_has_kedf());
107107
#ifdef USE_PAW
108108
if (PARAM.inp.use_paw)
109109
{
@@ -208,14 +208,14 @@ double ElecState::cal_delta_escf() const
208208
const double* v_fixed = this->pot->get_fixed_v();
209209
const double* v_ofk = nullptr;
210210

211-
if (get_xc_func_type() == 3 || get_xc_func_type() == 5)
211+
if (XC_Functional::get_has_kedf())
212212
{
213213
v_ofk = this->pot->get_effective_vofk(0);
214214
}
215215
for (int ir = 0; ir < this->charge->rhopw->nrxx; ir++)
216216
{
217217
descf -= (this->charge->rho[0][ir] - this->charge->rho_save[0][ir]) * (v_eff[ir] - v_fixed[ir]);
218-
if (get_xc_func_type() == 3 || get_xc_func_type() == 5)
218+
if (XC_Functional::get_has_kedf())
219219
{
220220
// cause in the get_effective_vofk, the func will return nullptr
221221
assert(v_ofk != nullptr);
@@ -226,14 +226,14 @@ double ElecState::cal_delta_escf() const
226226
if (PARAM.inp.nspin == 2)
227227
{
228228
v_eff = this->pot->get_effective_v(1);
229-
if (get_xc_func_type() == 3 || get_xc_func_type() == 5)
229+
if (XC_Functional::get_has_kedf())
230230
{
231231
v_ofk = this->pot->get_effective_vofk(1);
232232
}
233233
for (int ir = 0; ir < this->charge->rhopw->nrxx; ir++)
234234
{
235235
descf -= (this->charge->rho[1][ir] - this->charge->rho_save[1][ir]) * (v_eff[ir] - v_fixed[ir]);
236-
if (get_xc_func_type() == 3 || get_xc_func_type() == 5)
236+
if (XC_Functional::get_has_kedf())
237237
{
238238
descf -= (this->charge->kin_r[1][ir] - this->charge->kin_r_save[1][ir]) * v_ofk[ir];
239239
}

source/module_elecstate/elecstate_lcao.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void ElecStateLCAO<std::complex<double>>::psiToRho(const psi::Psi<std::complex<d
6363
Gint_inout inout(this->charge->rho, Gint_Tools::job_type::rho, PARAM.inp.nspin);
6464
this->gint_k->cal_gint(&inout);
6565

66-
if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5)
66+
if (XC_Functional::get_has_kedf())
6767
{
6868
elecstate::lcao_cal_tau_k(gint_k, this->charge);
6969
}
@@ -98,7 +98,7 @@ void ElecStateLCAO<double>::psiToRho(const psi::Psi<double>& psi)
9898

9999
this->gint_gamma->cal_gint(&inout);
100100

101-
if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5)
101+
if (XC_Functional::get_has_kedf())
102102
{
103103
elecstate::lcao_cal_tau_gamma(gint_gamma, this->charge);
104104
}
@@ -161,7 +161,7 @@ void ElecStateLCAO<double>::dmToRho(std::vector<double*> pexsi_DM, std::vector<d
161161
this->gint_gamma->transfer_DM2DtoGrid(this->DM->get_DMR_vector()); // transfer DM2D to DM_grid in gint
162162
Gint_inout inout(this->charge->rho, Gint_Tools::job_type::rho, PARAM.inp.nspin);
163163
this->gint_gamma->cal_gint(&inout);
164-
if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5)
164+
if (XC_Functional::get_has_kedf())
165165
{
166166
for (int is = 0; is < PARAM.inp.nspin; is++)
167167
{

source/module_elecstate/elecstate_print.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include "elecstate.h"
2-
#include "elecstate_getters.h"
32
#include "module_base/formatter.h"
43
#include "module_base/global_variable.h"
54
#include "module_base/parallel_common.h"
@@ -461,7 +460,7 @@ void ElecState::print_etot(const Magnetism& magnet,
461460
break;
462461
}
463462
std::vector<double> drho = {scf_thr};
464-
if (elecstate::get_xc_func_type() == 3 || elecstate::get_xc_func_type() == 5)
463+
if (XC_Functional::get_has_kedf())
465464
{
466465
drho.push_back(scf_thr_kin);
467466
}

source/module_elecstate/elecstate_pw.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
#include "elecstate_pw.h"
2-
#include "module_parameter/parameter.h"
3-
#include "elecstate_getters.h"
2+
43
#include "module_base/constants.h"
54
#include "module_base/libm/libm.h"
65
#include "module_base/math_ylmreal.h"
6+
#include "module_base/module_device/device.h"
77
#include "module_base/parallel_reduce.h"
88
#include "module_base/timer.h"
9-
#include "module_base/module_device/device.h"
9+
#include "module_hamilt_general/module_xc/xc_functional.h"
10+
#include "module_parameter/parameter.h"
1011

1112
namespace elecstate {
1213

@@ -41,7 +42,7 @@ ElecStatePW<T, Device>::~ElecStatePW()
4142
delmem_complex_op()(this->rhog_data);
4243
delete[] this->rhog;
4344
}
44-
if (get_xc_func_type() == 3 || PARAM.inp.out_elf[0] > 0)
45+
if (XC_Functional::get_func_type() == 3 || PARAM.inp.out_elf[0] > 0)
4546
{
4647
delmem_var_op()(this->kin_r_data);
4748
delete[] this->kin_r;
@@ -80,7 +81,7 @@ void ElecStatePW<T, Device>::init_rho_data()
8081
this->rhog[ii] = this->rhog_data + ii * this->charge->rhopw->npw;
8182
}
8283
}
83-
if (get_xc_func_type() == 3 || PARAM.inp.out_elf[0] > 0)
84+
if (XC_Functional::get_func_type() == 3 || PARAM.inp.out_elf[0] > 0)
8485
{
8586
this->kin_r = new Real*[this->charge->nspin];
8687
resmem_var_op()(this->kin_r_data, this->charge->nspin * this->charge->nrxx);
@@ -96,7 +97,7 @@ void ElecStatePW<T, Device>::init_rho_data()
9697
{
9798
this->rhog = reinterpret_cast<T**>(this->charge->rhog);
9899
}
99-
if (get_xc_func_type() == 3 || PARAM.inp.out_elf[0] > 0)
100+
if (XC_Functional::get_func_type() == 3 || PARAM.inp.out_elf[0] > 0)
100101
{
101102
this->kin_r = reinterpret_cast<Real **>(this->charge->kin_r);
102103
}
@@ -119,7 +120,7 @@ void ElecStatePW<T, Device>::psiToRho(const psi::Psi<T, Device>& psi)
119120
// denghui replaced at 20221110
120121
// ModuleBase::GlobalFunc::ZEROS(this->rho[is], this->charge->nrxx);
121122
setmem_var_op()(this->rho[is], 0, this->charge->nrxx);
122-
if (get_xc_func_type() == 3)
123+
if (XC_Functional::get_func_type() == 3)
123124
{
124125
// ModuleBase::GlobalFunc::ZEROS(this->charge->kin_r[is], this->charge->nrxx);
125126
setmem_var_op()(this->kin_r[is], 0, this->charge->nrxx);
@@ -143,7 +144,7 @@ void ElecStatePW<T, Device>::psiToRho(const psi::Psi<T, Device>& psi)
143144
for (int ii = 0; ii < PARAM.inp.nspin; ii++)
144145
{
145146
castmem_var_d2h_op()(this->charge->rho[ii], this->rho[ii], this->charge->nrxx);
146-
if (get_xc_func_type() == 3)
147+
if (XC_Functional::get_func_type() == 3)
147148
{
148149
castmem_var_d2h_op()(this->charge->kin_r[ii], this->kin_r[ii], this->charge->nrxx);
149150
}
@@ -240,7 +241,7 @@ void ElecStatePW<T, Device>::rhoBandK(const psi::Psi<T, Device>& psi)
240241
}
241242

242243
// kinetic energy density
243-
if (get_xc_func_type() == 3)
244+
if (XC_Functional::get_func_type() == 3)
244245
{
245246
for (int j = 0; j < 3; j++)
246247
{

source/module_elecstate/elecstate_pw_cal_tau.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include "elecstate_pw.h"
2-
#include "elecstate_getters.h"
32

43
namespace elecstate {
54

source/module_elecstate/magnetism.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "magnetism.h"
2-
#include "elecstate_getters.h"
3-
#include "module_parameter/parameter.h"
2+
43
#include "module_base/parallel_reduce.h"
4+
#include "module_parameter/parameter.h"
55

66
Magnetism::Magnetism()
77
{

source/module_elecstate/module_charge/charge.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,21 @@
1717
// even in a LSDA calculation.
1818
//----------------------------------------------------------
1919
#include "charge.h"
20-
#include <vector>
21-
#include "module_parameter/parameter.h"
20+
2221
#include "module_base/global_function.h"
2322
#include "module_base/global_variable.h"
24-
#include "module_parameter/parameter.h"
2523
#include "module_base/libm/libm.h"
2624
#include "module_base/math_integral.h"
2725
#include "module_base/memory.h"
2826
#include "module_base/parallel_reduce.h"
2927
#include "module_base/timer.h"
3028
#include "module_base/tool_threading.h"
3129
#include "module_cell/unitcell.h"
32-
#include "module_elecstate/elecstate_getters.h"
3330
#include "module_elecstate/magnetism.h"
31+
#include "module_hamilt_general/module_xc/xc_functional.h"
32+
#include "module_parameter/parameter.h"
33+
34+
#include <vector>
3435

3536
#ifdef USE_PAW
3637
#include "module_cell/module_paw/paw_cell.h"
@@ -80,7 +81,7 @@ void Charge::destroy()
8081
delete[] _space_rhog_save;
8182
delete[] _space_kin_r;
8283
delete[] _space_kin_r_save;
83-
if (elecstate::get_xc_func_type() == 3 || elecstate::get_xc_func_type() == 5 || PARAM.inp.out_elf[0] > 0)
84+
if (XC_Functional::get_has_kedf() || PARAM.inp.out_elf[0] > 0)
8485
{
8586
delete[] kin_r;
8687
delete[] kin_r_save;
@@ -121,7 +122,7 @@ void Charge::allocate(const int& nspin_in)
121122
_space_rho_save = new double[nspin * nrxx];
122123
_space_rhog = new std::complex<double>[nspin * ngmc];
123124
_space_rhog_save = new std::complex<double>[nspin * ngmc];
124-
if (elecstate::get_xc_func_type() == 3 || elecstate::get_xc_func_type() == 5 || PARAM.inp.out_elf[0] > 0)
125+
if (XC_Functional::get_has_kedf() || PARAM.inp.out_elf[0] > 0)
125126
{
126127
_space_kin_r = new double[nspin * nrxx];
127128
_space_kin_r_save = new double[nspin * nrxx];
@@ -130,7 +131,7 @@ void Charge::allocate(const int& nspin_in)
130131
rhog = new std::complex<double>*[nspin];
131132
rho_save = new double*[nspin];
132133
rhog_save = new std::complex<double>*[nspin];
133-
if (elecstate::get_xc_func_type() == 3 || elecstate::get_xc_func_type() == 5 || PARAM.inp.out_elf[0] > 0)
134+
if (XC_Functional::get_has_kedf() || PARAM.inp.out_elf[0] > 0)
134135
{
135136
kin_r = new double*[nspin];
136137
kin_r_save = new double*[nspin];
@@ -151,7 +152,7 @@ void Charge::allocate(const int& nspin_in)
151152
ModuleBase::GlobalFunc::ZEROS(rhog[is], ngmc);
152153
ModuleBase::GlobalFunc::ZEROS(rho_save[is], nrxx);
153154
ModuleBase::GlobalFunc::ZEROS(rhog_save[is], ngmc);
154-
if (elecstate::get_xc_func_type() == 3 || elecstate::get_xc_func_type() == 5 || PARAM.inp.out_elf[0] > 0)
155+
if (XC_Functional::get_has_kedf() || PARAM.inp.out_elf[0] > 0)
155156
{
156157
kin_r[is] = _space_kin_r + is * nrxx;
157158
ModuleBase::GlobalFunc::ZEROS(kin_r[is], nrxx);
@@ -171,7 +172,7 @@ void Charge::allocate(const int& nspin_in)
171172
ModuleBase::Memory::record("Chg::rho_save", sizeof(double) * nspin * nrxx);
172173
ModuleBase::Memory::record("Chg::rhog", sizeof(double) * nspin * ngmc);
173174
ModuleBase::Memory::record("Chg::rhog_save", sizeof(double) * nspin * ngmc);
174-
if (elecstate::get_xc_func_type() == 3 || elecstate::get_xc_func_type() == 5 || PARAM.inp.out_elf[0] > 0)
175+
if (XC_Functional::get_has_kedf() || PARAM.inp.out_elf[0] > 0)
175176
{
176177
ModuleBase::Memory::record("Chg::kin_r", sizeof(double) * nspin * ngmc);
177178
ModuleBase::Memory::record("Chg::kin_r_save", sizeof(double) * nspin * ngmc);
@@ -701,9 +702,10 @@ void Charge::save_rho_before_sum_band()
701702
for (int is = 0; is < PARAM.inp.nspin; is++)
702703
{
703704
ModuleBase::GlobalFunc::DCOPY(rho[is], rho_save[is], this->rhopw->nrxx);
704-
if (elecstate::get_xc_func_type() == 3 || elecstate::get_xc_func_type() == 5) {
705+
if (XC_Functional::get_has_kedf())
706+
{
705707
ModuleBase::GlobalFunc::DCOPY(kin_r[is], kin_r_save[is], this->rhopw->nrxx);
706-
}
708+
}
707709
#ifdef USE_PAW
708710
if(PARAM.inp.use_paw) {
709711
ModuleBase::GlobalFunc::DCOPY(nhat[is], nhat_save[is], this->rhopw->nrxx);

source/module_elecstate/module_charge/charge_init.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ void Charge::init_rho(elecstate::efermi& eferm_iout,
117117
}
118118
}
119119

120-
if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5)
120+
if (XC_Functional::get_has_kedf())
121121
{
122122
// If the charge density is not read in, then the kinetic energy density is not read in either
123123
if (!read_error)
@@ -188,7 +188,7 @@ void Charge::init_rho(elecstate::efermi& eferm_iout,
188188
}
189189

190190
// wenfei 2021-7-29 : initial tau = 3/5 rho^2/3, Thomas-Fermi
191-
if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5)
191+
if (XC_Functional::get_has_kedf())
192192
{
193193
if (PARAM.inp.init_chg == "atomic" || read_kin_error)
194194
{

0 commit comments

Comments
 (0)