Skip to content

Commit a76c946

Browse files
mohanchenabacus_fixer
andauthored
Try removing GlobalC::exx_info (#7575)
* remove some useless codes related to GlobalC * remove some GlobalC::exx_info * remove GlobalC * fix bug * further remove GlobalC::exx * update * update * remove GlobalC::exx_info * remove GlobalC::exx_info * update * remove GlobalC::exx_info * fix bug * fix bug * fix bug in GPU version * remove GlobalC in souce_hamilt module_xc * try to fix bug, * fix bug * fix bug * fix bug * fix bug introduced by Linpeize and Caoyu * fix bug * fix bug * fix bug --------- Co-authored-by: abacus_fixer <mohanchen@pku.eud.cn>
1 parent cf1b47a commit a76c946

65 files changed

Lines changed: 741 additions & 730 deletions

Some content is hidden

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

source/source_cell/sep_cell.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@
99
#include <string>
1010
#include <vector>
1111

12-
// namespace GlobalC
13-
// {
14-
// Sep_Cell sep_cell;
15-
// }
16-
1712
Sep_Cell::Sep_Cell() noexcept : ntype(0), omega(0.0), tpiba2(0.0)
1813
{
1914
}

source/source_cell/sep_cell.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,4 @@ class Sep_Cell
6666
double tpiba2; // tpiba ^ 2
6767
};
6868

69-
// namespace GlobalC
70-
// {
71-
// extern Sep_Cell sep_cell;
72-
// }
73-
7469
#endif // SEP_CEll

source/source_cell/unitcell.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,6 @@ void UnitCell::setup_cell(const std::string& fn, std::ofstream& log)
253253
// readl sep potential, currently using the pseudopotential folder (pseudo_dir in INPUT)
254254
//==========================
255255
if (PARAM.inp.dfthalf_type > 0) {
256-
// GlobalC::sep_cell.init(this->ntype);
257-
// ok3 = GlobalC::sep_cell.read_sep_potentials(ifa, PARAM.inp.pseudo_dir, GlobalV::ofs_warning, this->atom_label);
258-
259256
sep_cell.init(this->ntype);
260257
ok3 = sep_cell.read_sep_potentials(ifa, PARAM.inp.pseudo_dir, GlobalV::ofs_warning, this->atom_label);
261258
}
@@ -285,7 +282,6 @@ void UnitCell::setup_cell(const std::string& fn, std::ofstream& log)
285282

286283
#ifdef __MPI
287284
unitcell::bcast_unitcell(*this);
288-
// GlobalC::sep_cell.bcast_sep_cell();
289285
sep_cell.bcast_sep_cell();
290286
#endif
291287

@@ -350,7 +346,6 @@ void UnitCell::setup_cell(const std::string& fn, std::ofstream& log)
350346
//===================================
351347
this->set_iat2itia();
352348

353-
// GlobalC::sep_cell.set_omega(this->omega, this->tpiba2);
354349
sep_cell.set_omega(this->omega, this->tpiba2);
355350

356351
return;

source/source_esolver/esolver_ks_lcaopw.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#include "esolver_ks_lcaopw.h"
2-
32
#include "source_pw/module_pwdft/elecond.h"
43
#include "source_io/module_parameter/input_conv.h"
5-
64
#include <iostream>
75

86
//--------------temporary----------------------------
@@ -141,9 +139,11 @@ namespace ModuleESolver
141139

142140
// add exx
143141
#ifdef __EXX
144-
if (GlobalC::exx_info.info_global.cal_exx)
142+
bool cal_exx = GlobalC::exx_info.info_global.cal_exx;
143+
double hybrid_alpha = GlobalC::exx_info.info_global.hybrid_alpha;
144+
if (cal_exx)
145145
{
146-
this->pelec->set_exx(this->exx_lip->get_exx_energy()); // Peize Lin add 2019-03-09
146+
this->pelec->set_exx(this->exx_lip->get_exx_energy(), cal_exx, hybrid_alpha); // Peize Lin add 2019-03-09
147147
}
148148
#endif
149149

@@ -227,6 +227,13 @@ namespace ModuleESolver
227227
#ifdef __LCAO
228228
if (PARAM.inp.out_mat_xc)
229229
{
230+
#ifdef __EXX
231+
bool cal_exx = GlobalC::exx_info.info_global.cal_exx;
232+
double hybrid_alpha = GlobalC::exx_info.info_global.hybrid_alpha;
233+
#else
234+
bool cal_exx = false;
235+
double hybrid_alpha = 0.0;
236+
#endif
230237
ModuleIO::write_Vxc(PARAM.inp.nspin,
231238
PARAM.globalv.nlocal,
232239
GlobalV::DRANK,
@@ -240,7 +247,9 @@ namespace ModuleESolver
240247
this->locpp.vloc,
241248
this->chr,
242249
this->kv,
243-
this->pelec->wg
250+
this->pelec->wg,
251+
cal_exx,
252+
hybrid_alpha
244253
#ifdef __EXX
245254
,
246255
*this->exx_lip

source/source_esolver/esolver_ks_pw.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,11 @@ template <typename T, typename Device>
239239
void ESolver_KS_PW<T, Device>::iter_finish(UnitCell& ucell, const int istep, int& iter, bool& conv_esolver)
240240
{
241241
// Related to EXX
242-
if (GlobalC::exx_info.info_global.cal_exx && !exx_helper->get_op_first_iter())
242+
bool cal_exx = GlobalC::exx_info.info_global.cal_exx;
243+
double hybrid_alpha = GlobalC::exx_info.info_global.hybrid_alpha;
244+
if (cal_exx && !exx_helper->get_op_first_iter())
243245
{
244-
this->pelec->set_exx(exx_helper->cal_exx_energy(this->stp.template get_psi_t<T, Device>()));
246+
this->pelec->set_exx(exx_helper->cal_exx_energy(this->stp.template get_psi_t<T, Device>()), cal_exx, hybrid_alpha);
245247
}
246248

247249
// deband is calculated from "output" charge density

source/source_esolver/esolver_of_interface.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -207,19 +207,6 @@ void ESolver_OF::get_step_length(double* dEdtheta, double** ptemp_phi, UnitCell&
207207
// while(true)
208208
// {
209209
// this->pelec->f_en.calculate_etot(this->pw_rho->nrxx,
210-
// this->pw_rho->nxyz); temp_energy =
211-
// this->pelec->f_en.etot; kinetic_energy =
212-
// this->kinetic_energy(); pseudopot_energy = 0.; for (int
213-
// is = 0; is < PARAM.inp.nspin; ++is) {
214-
// pseudopot_energy +=
215-
// this->inner_product(GlobalC::pot.vltot,
216-
// ptemp_rho_[is], this->pw_rho->nrxx, this->dV_);
217-
// }
218-
// Parallel_Reduce::reduce_all(pseudopot_energy);
219-
// temp_energy += kinetic_energy + pseudopot_energy;
220-
// this->opt_dcsrch_->dcSrch(temp_energy, dEdalpha,
221-
// thetaAlpha, this->task_); numDC++;
222-
223210
// if (strncmp(this->task_, "FG", 2) == 0)
224211
// {
225212
// for (int is = 0; is < PARAM.inp.nspin; ++is)

source/source_estate/elecstate.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ class ElecState
115115
bool vnew_exist = false;
116116
void cal_converged();
117117
void cal_energies(const int type);
118-
void set_exx(const double& Eexx);
119-
void set_exx(const std::complex<double>& Eexx);
118+
void set_exx(const double& Eexx, const bool cal_exx, const double hybrid_alpha);
119+
void set_exx(const std::complex<double>& Eexx, const bool cal_exx, const double hybrid_alpha);
120120

121121
double get_hartree_energy();
122122
double get_etot_efield();
Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
#include "source_estate/elecstate.h"
2-
#include "source_hamilt/module_xc/exx_info.h" // use GlobalC::exx_info
2+
#include "source_base/tool_quit.h"
3+
#include <complex> // use std::complex
34

45
namespace elecstate
56
{
67

78
/// @brief calculation if converged
89
/// @date Peize Lin add 2016-12-03
9-
void ElecState::set_exx(const double& Eexx)
10+
void ElecState::set_exx(const double& Eexx, const bool cal_exx, const double hybrid_alpha)
1011
{
1112
ModuleBase::TITLE("energy", "set_exx");
1213

13-
if (GlobalC::exx_info.info_global.cal_exx)
14+
if (cal_exx)
1415
{
15-
this->f_en.exx = GlobalC::exx_info.info_global.hybrid_alpha * Eexx;
16+
this->f_en.exx = hybrid_alpha * Eexx;
1617
}
1718
return;
1819
}
1920

21+
void ElecState::set_exx(const std::complex<double>& Eexx, const bool cal_exx, const double hybrid_alpha)
22+
{
23+
ModuleBase::WARNING_QUIT("ElecState::set_exx",
24+
"std::complex<double> version is not implemented yet");
25+
}
26+
2027
}

source/source_estate/module_pot/pot_sep.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ void PotSep::cal_fixed_v(double* vl_pseudo)
1010
ModuleBase::TITLE("PotSep", "cal_fixed_v");
1111
ModuleBase::timer::start("PotSep", "cal_fixed_v");
1212

13-
// GlobalC::vsep_cell.generate_vsep_r(this->rho_basis_[0], this->sf_[0]);
14-
15-
// const_cast<VSep*>(this->vsep_)->generate_vsep_r(this->rho_basis_[0], this->sf_[0]);
16-
1713
if (vsep_cell != nullptr)
1814
{
1915
for (int ir = 0; ir < this->rho_basis_->nrxx; ++ir)

source/source_estate/module_pot/pot_xc.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,15 @@ void PotXC::cal_v_eff(const Charge*const chg, const UnitCell*const ucell, Module
2424
if (XC_Functional::get_ked_flag())
2525
{
2626
#ifdef USE_LIBXC
27+
const double hybrid_alpha = XC_Functional::get_hybrid_alpha();
28+
#ifdef __EXX
29+
const double hse_omega = XC_Functional::get_hse_omega();
30+
#else
31+
const double hse_omega = 0.0;
32+
#endif
2733
const std::tuple<double, double, ModuleBase::matrix, ModuleBase::matrix> etxc_vtxc_v
2834
= XC_Functional_Libxc::v_xc_meta(XC_Functional::get_func_id(), nrxx_current, ucell->omega, ucell->tpiba, chg,
29-
PARAM.inp.nspin);
35+
PARAM.inp.nspin, hybrid_alpha, hse_omega);
3036
*(this->etxc_) = std::get<0>(etxc_vtxc_v);
3137
*(this->vtxc_) = std::get<1>(etxc_vtxc_v);
3238
v_eff += std::get<2>(etxc_vtxc_v);
@@ -37,11 +43,19 @@ void PotXC::cal_v_eff(const Charge*const chg, const UnitCell*const ucell, Module
3743
}
3844
else
3945
{
46+
const double hybrid_alpha = XC_Functional::get_hybrid_alpha();
47+
#ifdef __EXX
48+
const double hse_omega = XC_Functional::get_hse_omega();
49+
#else
50+
const double hse_omega = 0.0;
51+
#endif
4052
const std::tuple<double, double, ModuleBase::matrix> etxc_vtxc_v
4153
= XC_Functional::v_xc(nrxx_current, chg, ucell,
4254
PARAM.inp.nspin,
4355
PARAM.globalv.domag,
44-
PARAM.globalv.domag_z);
56+
PARAM.globalv.domag_z,
57+
hybrid_alpha,
58+
hse_omega);
4559
*(this->etxc_) = std::get<0>(etxc_vtxc_v);
4660
*(this->vtxc_) = std::get<1>(etxc_vtxc_v);
4761
v_eff += std::get<2>(etxc_vtxc_v);

0 commit comments

Comments
 (0)