Skip to content

Commit

Permalink
Refactor:Use Param.inp insetead of GlobalV::MIXING* (#5070)
Browse files Browse the repository at this point in the history
* Delete global variable FINAL_SCF in global_variable.cpp and global_variable.h
  • Loading branch information
A-006 authored Sep 10, 2024
1 parent 8661f46 commit 870f01e
Show file tree
Hide file tree
Showing 54 changed files with 575 additions and 636 deletions.
42 changes: 0 additions & 42 deletions source/module_base/global_variable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ bool DOMAG = false;
bool DOMAG_Z = false;
int NPOL = 1;

bool FINAL_SCF = false; // LiuXh add 20180619

bool deepks_out_labels = false; // caoyu add 2021-10-16 for DeePKS, wenfei 2022-1-16
bool deepks_scf = false; // caoyu add 2021-10-16 for DeePKS, wenfei 2022-1-16
Expand All @@ -144,44 +143,13 @@ bool deepks_equiv = false;
bool deepks_setorb = false;


bool imp_sol = false; // implicit solvation. sunml added 2022-04-04
double eb_k = 80.0;

int dft_plus_u = 0; // DFTU control

// Xinyang Dong added for rpa
bool rpa_setorb = false;
std::vector<std::string> rpa_orbitals;

std::string of_kinetic = "wt";
std::string of_method = "tn";
std::string of_conv = "energy";
double of_tole = 2e-6;
double of_tolp = 1e-5;
double of_tf_weight = 1.;
double of_vw_weight = 1.;
double of_wt_alpha = 5. / 6.;
double of_wt_beta = 5. / 6.;
double of_wt_rho0 = 0.;
bool of_hold_rho0 = false;
double of_lkt_a = 1.3;
bool of_full_pw = true;
int of_full_pw_dim = 0;
bool of_read_kernel = false;
std::string of_kernel_file = "WTkernel.txt";

// mixing parameters
std::string MIXING_MODE = "broyden";
double MIXING_BETA = 0.7;
int MIXING_NDIM = 8;
double MIXING_RESTART = 0.0;
double MIXING_GG0 = 1.00;
double MIXING_BETA_MAG = 1.6;
double MIXING_GG0_MAG = 1.00;
double MIXING_GG0_MIN = 0.1;
double MIXING_ANGLE = 0.0;
bool MIXING_TAU = false;
bool MIXING_DMR = false;

//==========================================================
// device flags added by denghui
Expand All @@ -190,30 +158,20 @@ std::string device_flag = "unknown";
//==========================================================
// precision flags added by denghui
//==========================================================
std::string precision_flag = "unknown";

std::string chg_extrap = "";
int out_pot = 0;

std::string init_chg = "";

std::string init_wfc = "atomic";
bool psi_initializer = false;

double nelec = 0;
bool out_bandgap = false; // QO added for bandgap printing

//==========================================================
// Deltaspin related
//==========================================================
double sc_thr = 1.0e-6;

//==========================================================
// Quasiatomic orbital related
//==========================================================
double qo_thr = 1.0e-6;
std::vector<double> qo_screening_coeff = {};

// on-site orbitals
double onsite_radius = 0.0;
} // namespace GlobalV
26 changes: 0 additions & 26 deletions source/module_base/global_variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ extern int test_relax_method;
//==========================================================
extern int test_deconstructor;

extern bool FINAL_SCF; // LiuXh add 20180619

extern bool deepks_out_labels; // (need libnpy) prints energy and force labels
// and descriptors for training, wenfei 2022-1-12
Expand All @@ -180,27 +179,12 @@ extern bool deepks_setorb;


// implicit solvation
extern bool imp_sol; // sunml added 2022-04-04
extern double eb_k;

// DFTU control
extern int dft_plus_u;
// rpa related
extern bool rpa_setorb;
extern std::vector<std::string> rpa_orbitals;

// mixing parameters
extern std::string MIXING_MODE;
extern double MIXING_BETA;
extern int MIXING_NDIM;
extern double MIXING_RESTART;
extern double MIXING_GG0;
extern bool MIXING_TAU;
extern double MIXING_BETA_MAG;
extern double MIXING_GG0_MAG;
extern double MIXING_GG0_MIN;
extern double MIXING_ANGLE;
extern bool MIXING_DMR;

//==========================================================
// device flags added by denghui
Expand All @@ -209,31 +193,21 @@ extern std::string device_flag;
//==========================================================
// precision flags added by denghui
//==========================================================
extern std::string precision_flag;

extern std::string chg_extrap;
extern int out_pot;

extern std::string init_chg; // output charge if out_chg > 0, and output every
// "out_chg" elec step.
/// @brief method to initialize wavefunction
/// @author kirk0830, 20230920
extern std::string init_wfc;
/// @brief whether use the new psi initializer to initialize psi
/// @author ykhuang, 20230920
extern bool psi_initializer;

extern double nelec;
extern bool out_bandgap;

// Deltaspin related
extern double sc_thr;

// Quasiatomic orbital related
extern double qo_thr;
extern std::vector<double> qo_screening_coeff;

// radius of on-site orbitals
extern double onsite_radius;
} // namespace GlobalV
#endif
2 changes: 1 addition & 1 deletion source/module_cell/klist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ void K_Vectors::ibz_kpoint(const ModuleSymmetry::Symmetry& symm,
void K_Vectors::set_both_kvec(const ModuleBase::Matrix3& G, const ModuleBase::Matrix3& R, std::string& skpt)
{

if (GlobalV::FINAL_SCF) // LiuXh add 20180606
if (PARAM.inp.final_scf) // LiuXh add 20180606
{
if (k_nkstot == 0)
{
Expand Down
6 changes: 3 additions & 3 deletions source/module_cell/read_atoms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ int UnitCell::read_atom_species(std::ifstream &ifa, std::ofstream &ofs_running)
||(PARAM.inp.basis_type == "lcao_in_pw")
||(
(PARAM.inp.basis_type == "pw")
&&(GlobalV::psi_initializer)
&&(GlobalV::init_wfc.substr(0, 3) == "nao")
&&(PARAM.inp.psi_initializer)
&&(PARAM.inp.init_wfc.substr(0, 3) == "nao")
)
)
{
Expand Down Expand Up @@ -466,7 +466,7 @@ bool UnitCell::read_atom_positions(std::ifstream &ifpos, std::ofstream &ofs_runn
}
else if(PARAM.inp.basis_type == "pw")
{
if ((GlobalV::psi_initializer)&&(GlobalV::init_wfc.substr(0, 3) == "nao"))
if ((PARAM.inp.psi_initializer)&&(PARAM.inp.init_wfc.substr(0, 3) == "nao"))
{
std::string orbital_file = PARAM.inp.orbital_dir + orbital_fn[it];
this->read_orb_file(it, orbital_file, ofs_running, &(atoms[it]));
Expand Down
6 changes: 3 additions & 3 deletions source/module_cell/test/klist_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ UnitCell ucell;
* according to different spin case
* - set_both_kvec()
* - SetBothKvec: set kvec_c (cartesian coor.) and kvec_d (direct coor.)
* - SetBothKvecFinalSCF: same as above, with GlobalV::FINAL_SCF=1
* - SetBothKvecFinalSCF: same as above, with PARAM.input.final_scf=1
* - print_klists()
* - PrintKlists: print kpoints coordinates
* - PrintKlistsWarningQuit: for nkstot < nks error
Expand Down Expand Up @@ -651,7 +651,7 @@ TEST_F(KlistTest, SetBothKvecFinalSCF)
kv->kvec_c[0].y = 0.0;
kv->kvec_c[0].z = 0.0;
std::string skpt;
GlobalV::FINAL_SCF = true;
PARAM.input.final_scf = true;
kv->kd_done = false;
kv->kc_done = false;
// case 1
Expand Down Expand Up @@ -694,7 +694,7 @@ TEST_F(KlistTest, SetBothKvec)
kv->kc_done = false;
kv->kd_done = true;
std::string skpt;
GlobalV::FINAL_SCF = false;
PARAM.input.final_scf = false;
kv->set_both_kvec(GlobalC::ucell.G, GlobalC::ucell.latvec, skpt);
EXPECT_TRUE(kv->kc_done);
kv->kc_done = true;
Expand Down
4 changes: 2 additions & 2 deletions source/module_cell/unitcell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1050,8 +1050,8 @@ void UnitCell::cal_nwfc(std::ofstream& log) {
// Use localized basis
//=====================
if ((PARAM.inp.basis_type == "lcao") || (PARAM.inp.basis_type == "lcao_in_pw")
|| ((PARAM.inp.basis_type == "pw") && (GlobalV::psi_initializer)
&& (GlobalV::init_wfc.substr(0, 3) == "nao")
|| ((PARAM.inp.basis_type == "pw") && (PARAM.inp.psi_initializer)
&& (PARAM.inp.init_wfc.substr(0, 3) == "nao")
&& (PARAM.inp.esolver_type == "ksdft"))) // xiaohui add 2013-09-02
{
ModuleBase::GlobalFunc::AUTO_SET("NBANDS", GlobalV::NBANDS);
Expand Down
4 changes: 2 additions & 2 deletions source/module_elecstate/elecstate_energy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ void ElecState::cal_energies(const int type)
this->f_en.gatefield = get_etot_gatefield();

//! energy from implicit solvation model
if (GlobalV::imp_sol)
if (PARAM.inp.imp_sol)
{
this->f_en.esol_el = get_solvent_model_Ael();
this->f_en.esol_cav = get_solvent_model_Acav();
Expand All @@ -294,7 +294,7 @@ void ElecState::cal_energies(const int type)
}

// energy from DFT+U
if (GlobalV::dft_plus_u)
if (PARAM.inp.dft_plus_u)
{
this->f_en.edftu = get_dftu_energy();
}
Expand Down
2 changes: 1 addition & 1 deletion source/module_elecstate/elecstate_print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ void ElecState::print_etot(const bool converged,
}
titles.push_back("E_exx");
energies_Ry.push_back(this->f_en.exx);
if (GlobalV::imp_sol)
if (PARAM.inp.imp_sol)
{
titles.push_back("E_sol_el");
energies_Ry.push_back(this->f_en.esol_el);
Expand Down
4 changes: 2 additions & 2 deletions source/module_elecstate/elecstate_pw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ ElecStatePW<T, Device>::~ElecStatePW()
template<typename T, typename Device>
void ElecStatePW<T, Device>::init_rho_data()
{
if (GlobalV::device_flag == "gpu" || GlobalV::precision_flag == "single") {
if (GlobalV::device_flag == "gpu" || PARAM.inp.precision == "single") {
this->rho = new Real*[this->charge->nspin];
resmem_var_op()(this->ctx, this->rho_data, this->charge->nspin * this->charge->nrxx);
for (int ii = 0; ii < this->charge->nspin; ii++) {
Expand Down Expand Up @@ -108,7 +108,7 @@ void ElecStatePW<T, Device>::psiToRho(const psi::Psi<T, Device>& psi)
{
this->add_usrho(psi);
}
if (GlobalV::device_flag == "gpu" || GlobalV::precision_flag == "single") {
if (GlobalV::device_flag == "gpu" || PARAM.inp.precision == "single") {
for (int ii = 0; ii < GlobalV::NSPIN; ii++) {
castmem_var_d2h_op()(cpu_ctx, this->ctx, this->charge->rho[ii], this->rho[ii], this->charge->nrxx);
if (get_xc_func_type() == 3)
Expand Down
14 changes: 7 additions & 7 deletions source/module_elecstate/module_charge/charge_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@

void Charge::init_rho(elecstate::efermi& eferm_iout, const ModuleBase::ComplexMatrix& strucFac, const int& nbz, const int& bz)
{
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "init_chg", GlobalV::init_chg);
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "init_chg", PARAM.inp.init_chg);

std::cout << " START CHARGE : " << GlobalV::init_chg << std::endl;
std::cout << " START CHARGE : " << PARAM.inp.init_chg << std::endl;
bool read_error = false;
if (GlobalV::init_chg == "file" || GlobalV::init_chg == "auto")
if (PARAM.inp.init_chg == "file" || PARAM.inp.init_chg == "auto")
{
GlobalV::ofs_running << " try to read charge from file : " << std::endl;

Expand Down Expand Up @@ -154,18 +154,18 @@ void Charge::init_rho(elecstate::efermi& eferm_iout, const ModuleBase::ComplexMa
const std::string warn_msg = " WARNING: \"init_chg\" is enabled but ABACUS failed to read charge density from file.\n"
" Please check if there is SPINX_CHG.cube (X=1,...) or {suffix}-CHARGE-DENSITY.restart in the directory.\n";
std::cout << std::endl << warn_msg;
if (GlobalV::init_chg == "auto")
if (PARAM.inp.init_chg == "auto")
{
std::cout << " Charge::init_rho: use atomic initialization instead." << std::endl << std::endl;
}
else if (GlobalV::init_chg == "file")
else if (PARAM.inp.init_chg == "file")
{
ModuleBase::WARNING_QUIT("Charge::init_rho", "Failed to read in charge density from file.\nIf you want to use atomic charge initialization, \nplease set init_chg to atomic in INPUT.");
}
}

if (GlobalV::init_chg == "atomic" ||
(GlobalV::init_chg == "auto" && read_error)) // mohan add 2007-10-17
if (PARAM.inp.init_chg == "atomic" ||
(PARAM.inp.init_chg == "auto" && read_error)) // mohan add 2007-10-17
{
this->atomic_rho(GlobalV::NSPIN, GlobalC::ucell.omega, rho, strucFac, GlobalC::ucell);

Expand Down
22 changes: 11 additions & 11 deletions source/module_elecstate/module_charge/charge_mixing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ void Charge_Mixing::set_mixing(const std::string& mixing_mode_in,
GlobalV::ofs_running<<"mixing_type: "<< this->mixing_mode <<std::endl;
GlobalV::ofs_running<<"mixing_beta: "<< this->mixing_beta <<std::endl;
GlobalV::ofs_running<<"mixing_gg0: "<< this->mixing_gg0 <<std::endl;
GlobalV::ofs_running<<"mixing_gg0_min: "<< GlobalV::MIXING_GG0_MIN <<std::endl;
GlobalV::ofs_running<<"mixing_gg0_min: "<< PARAM.inp.mixing_gg0_min <<std::endl;
if (GlobalV::NSPIN==2 || GlobalV::NSPIN==4)
{
GlobalV::ofs_running<<"mixing_beta_mag: "<< this->mixing_beta_mag <<std::endl;
GlobalV::ofs_running<<"mixing_gg0_mag: "<< GlobalV::MIXING_GG0_MAG <<std::endl;
GlobalV::ofs_running<<"mixing_gg0_mag: "<< PARAM.inp.mixing_gg0_mag <<std::endl;
}
if (GlobalV::MIXING_ANGLE > 0)
if (PARAM.inp.mixing_angle > 0)
{
GlobalV::ofs_running<<"mixing_angle: "<< GlobalV::MIXING_ANGLE <<std::endl;
GlobalV::ofs_running<<"mixing_angle: "<< PARAM.inp.mixing_angle <<std::endl;
}
GlobalV::ofs_running<<"mixing_ndim: "<< this->mixing_ndim <<std::endl;
GlobalV::ofs_running<<"----------- Double Check Mixing Parameters End ------------"<<std::endl;
Expand Down Expand Up @@ -119,7 +119,7 @@ void Charge_Mixing::init_mixing()
// initailize rho_mdata
if (PARAM.inp.scf_thr_type == 1)
{
if (GlobalV::NSPIN == 4 && GlobalV::MIXING_ANGLE > 0 )
if (GlobalV::NSPIN == 4 && PARAM.inp.mixing_angle > 0 )
{
this->mixing->init_mixing_data(this->rho_mdata,
this->rhopw->npw * 2,
Expand All @@ -134,7 +134,7 @@ void Charge_Mixing::init_mixing()
}
else
{
if (GlobalV::NSPIN == 4 && GlobalV::MIXING_ANGLE > 0 )
if (GlobalV::NSPIN == 4 && PARAM.inp.mixing_angle > 0 )
{
this->mixing->init_mixing_data(this->rho_mdata, this->rhopw->nrxx * 2, sizeof(double));
}
Expand Down Expand Up @@ -406,7 +406,7 @@ void Charge_Mixing::mix_rho_recip(Charge* chr)
}
}
}
else if (GlobalV::NSPIN == 4 && GlobalV::MIXING_ANGLE <= 0)
else if (GlobalV::NSPIN == 4 && PARAM.inp.mixing_angle <= 0)
{
// normal broyden mixing for {rho, mx, my, mz}
rhog_in = rhogs_in;
Expand Down Expand Up @@ -435,7 +435,7 @@ void Charge_Mixing::mix_rho_recip(Charge* chr)
this->mixing->cal_coef(this->rho_mdata, inner_product);
this->mixing->mix_data(this->rho_mdata, rhog_out);
}
else if (GlobalV::NSPIN == 4 && GlobalV::MIXING_ANGLE > 0)
else if (GlobalV::NSPIN == 4 && PARAM.inp.mixing_angle > 0)
{
// special broyden mixing for {rho, |m|} proposed by J. Phys. Soc. Jpn. 82 (2013) 114706
// here only consider the case of mixing_angle = 1, which mean only change |m| and keep angle fixed
Expand Down Expand Up @@ -530,7 +530,7 @@ void Charge_Mixing::mix_rho_recip(Charge* chr)
}

// rhog to rho
if (GlobalV::NSPIN == 4 && GlobalV::MIXING_ANGLE > 0)
if (GlobalV::NSPIN == 4 && PARAM.inp.mixing_angle > 0)
{
// only tranfer rhog[0]
// do not support double_grid, use rhopw directly
Expand Down Expand Up @@ -688,7 +688,7 @@ void Charge_Mixing::mix_rho_real(Charge* chr)
delete[] rho_mag;
delete[] rho_mag_save;
}
else if (GlobalV::NSPIN == 4 && GlobalV::MIXING_ANGLE <= 0)
else if (GlobalV::NSPIN == 4 && PARAM.inp.mixing_angle <= 0)
{
// normal broyden mixing for {rho, mx, my, mz}
rhor_in = chr->rho_save[0];
Expand Down Expand Up @@ -719,7 +719,7 @@ void Charge_Mixing::mix_rho_real(Charge* chr)
this->mixing->cal_coef(this->rho_mdata, inner_product);
this->mixing->mix_data(this->rho_mdata, rhor_out);
}
else if (GlobalV::NSPIN == 4 && GlobalV::MIXING_ANGLE > 0)
else if (GlobalV::NSPIN == 4 && PARAM.inp.mixing_angle > 0)
{
// special broyden mixing for {rho, |m|} proposed by J. Phys. Soc. Jpn. 82 (2013) 114706
// here only consider the case of mixing_angle = 1, which mean only change |m| and keep angle fixed
Expand Down
Loading

0 comments on commit 870f01e

Please sign in to comment.