Skip to content

Commit 46797ad

Browse files
Refactor: add XC_Functional::get_has_kedf() (#5879)
* Refactor: remove elecstate_getters * Refactor: add XC_Functional::get_has_kedf() * Refactor: update unit tests * [pre-commit.ci lite] apply automatic fixes * Refactor: rename has_kedf to ked_flag --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
1 parent 602ebe5 commit 46797ad

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+234
-287
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_ked_flag());
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_ked_flag())
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_ked_flag())
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_ked_flag())
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_ked_flag())
237237
{
238238
descf -= (this->charge->kin_r[1][ir] - this->charge->kin_r_save[1][ir]) * v_ofk[ir];
239239
}

source/module_elecstate/elecstate_getters.cpp

Lines changed: 0 additions & 17 deletions
This file was deleted.

source/module_elecstate/elecstate_getters.h

Lines changed: 0 additions & 16 deletions
This file was deleted.

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_ked_flag())
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_ked_flag())
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_ked_flag())
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_ked_flag())
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
{

0 commit comments

Comments
 (0)