Skip to content

Commit

Permalink
Refactor:Use PARAM instead of GlobalV::domag* (#5115)
Browse files Browse the repository at this point in the history
* add domag in systyem_parameter

* change paramter noncolin in cpp file

* change paramter noncolin in test file

* change paramter lspinorb in cpp file

* change paramter lspinorb in test file

* change paramter npol in test file

* change paramter npol in test file

* change paramter domag_z in cpp file

* change paramter domag_z in test file

* change paramter domag in cpp file

* change paramter domag in test file

* fix bug

* add unit test

* delete parameter in variable

* delete parameter out_pot in variable

* delete nspin condition

---------

Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
  • Loading branch information
A-006 and pre-commit-ci-lite[bot] authored Sep 18, 2024
1 parent fec3065 commit 7a2e4a8
Show file tree
Hide file tree
Showing 91 changed files with 460 additions and 411 deletions.
11 changes: 0 additions & 11 deletions source/module_base/global_variable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,11 @@ std::ofstream ofs_info; // output math lib info
std::ofstream ofs_device; // output device info


// added by zhengdy-soc
bool NONCOLIN = false;
bool LSPINORB = false;
bool DOMAG = false;
bool DOMAG_Z = false;
int NPOL = 1;

std::vector<std::string> rpa_orbitals;

//==========================================================
// device flags added by denghui
//==========================================================
std::string device_flag = "unknown";

int out_pot = 0;

double nelec = 0;


Expand Down
10 changes: 0 additions & 10 deletions source/module_base/global_variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ extern bool use_uspp;
extern std::string KS_SOLVER; // xiaohui add 2013-09-01
extern double SEARCH_RADIUS; // 11.1 // mohan add 2011-03-10

// added by zhengdy-soc
extern bool NONCOLIN; // 0 : collinear ; 1 : non-collinear
extern bool LSPINORB; // 0 : no soc ; 1 : has soc
extern bool DOMAG; // 1 : calculate the magnetism with x, y, z component
extern bool DOMAG_Z; // 1 : constrain the magnetism to z axis
extern int NPOL; // 1 : no soc; 2 : has soc

extern int PW_DIAG_NDIM; // 14
extern double PW_DIAG_THR; // 15 pw_diag_thr
Expand Down Expand Up @@ -107,8 +101,6 @@ extern std::ofstream ofs_warning;
extern std::ofstream ofs_info;
extern std::ofstream ofs_device;

// rpa related
extern std::vector<std::string> rpa_orbitals;

// mixing parameters

Expand All @@ -120,8 +112,6 @@ extern std::string device_flag;
// precision flags added by denghui
//==========================================================

extern int out_pot;

// "out_chg" elec step.
/// @brief method to initialize wavefunction
/// @author kirk0830, 20230920
Expand Down
2 changes: 1 addition & 1 deletion source/module_base/module_device/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ int get_device_kpar(const int& kpar);

/**
* @brief Get the device flag object
* for module_io GlobalV::device_flag
* for module_io PARAM.globalv.device_flag
*/
std::string get_device_flag(const std::string& device,
const std::string& ks_solver,
Expand Down
7 changes: 4 additions & 3 deletions source/module_basis/module_nao/beta_radials.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "module_basis/module_nao/beta_radials.h"

#include "module_parameter/parameter.h"
#include "module_base/global_variable.h"
#include "module_base/parallel_common.h"
#include "module_base/tool_quit.h"
Expand Down Expand Up @@ -402,7 +403,7 @@ void BetaRadials::build(const Numerical_Nonlocal& nl, const int itype, std::ofst
//#endif
//
// // It is an error if lspinorb is set to true but the pseudopotential file does not contain spin-orbit information
// if (!has_so && GlobalV::LSPINORB)
// if (!has_so && PARAM.inp.lspinorb)
// {
// ModuleBase::WARNING_QUIT("BetaRadials::read_beta_upf201",
// "lspinorb is set to true but the pseudopotential file does not contain spin-orbit information");
Expand Down Expand Up @@ -558,7 +559,7 @@ void BetaRadials::build(const Numerical_Nonlocal& nl, const int itype, std::ofst
// double* rbeta_final = nullptr;
// if (rank == 0)
// {
// if (!GlobalV::LSPINORB && has_so)
// if (!PARAM.inp.lspinorb && has_so)
// {
// /*
// * read the PP_DIJ block for averaging
Expand Down Expand Up @@ -727,7 +728,7 @@ void BetaRadials::build(const Numerical_Nonlocal& nl, const int itype, std::ofst
// delete[] ngrid_final;
// delete[] rbeta_final;
//
// if (rank == 0 && !GlobalV::LSPINORB && has_so)
// if (rank == 0 && !PARAM.inp.lspinorb && has_so)
// {
// delete[] l;
// delete[] ngrid;
Expand Down
3 changes: 2 additions & 1 deletion source/module_cell/atom_pseudo.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "atom_pseudo.h"

#include "module_parameter/parameter.h"
Atom_pseudo::Atom_pseudo()
{
}
Expand Down Expand Up @@ -67,7 +68,7 @@ void Atom_pseudo::set_d_so(ModuleBase::ComplexMatrix& d_so_in,

if (this->lmax > -1)
{
if (GlobalV::LSPINORB)
if (PARAM.inp.lspinorb)
{
int is = 0;
for (int is1 = 0; is1 < 2; is1++)
Expand Down
16 changes: 1 addition & 15 deletions source/module_cell/read_atoms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,6 @@ int UnitCell::read_atom_species(std::ifstream &ifa, std::ofstream &ofs_running)
}
}

if (PARAM.globalv.rpa_setorb)
{
if (ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "ABFS_ORBITAL"))
{
std::cout << "RPA_EXX_LCAO read abfs_orb!!!" << std::endl;
GlobalV::rpa_orbitals.resize(ntype);
for (int i = 0; i < ntype; i++)
{
ifa >> GlobalV::rpa_orbitals[i];
}
}
}
#endif // __EXX
#endif // __MPI
#endif // __LCAO
Expand Down Expand Up @@ -640,11 +628,9 @@ bool UnitCell::read_atom_positions(std::ifstream &ifpos, std::ofstream &ofs_runn

if(GlobalV::NSPIN==4)
{
if(GlobalV::NONCOLIN)
if(PARAM.inp.noncolin)
{
//if magnetization only along z-axis, default settings are DOMAG_Z=true and DOMAG=false
GlobalV::DOMAG_Z = false;
GlobalV::DOMAG = true;
if(input_angle_mag)
{
atoms[it].m_loc_[ia].z = atoms[it].mag[ia] *
Expand Down
9 changes: 5 additions & 4 deletions source/module_cell/read_pp.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "read_pp.h"

#include "module_parameter/parameter.h"
#include <cmath>

#include <cstring> // Peize Lin fix bug about strcpy 2016-08-02
Expand Down Expand Up @@ -123,7 +124,7 @@ int Pseudopot_upf::average_p(const double& lambda, Atom_pseudo& pp)
{
int error = 0;
double lambda_ = lambda;
if(!GlobalV::LSPINORB) { lambda_ = 0.0; }
if(!PARAM.inp.lspinorb) { lambda_ = 0.0; }
if (pp.has_so && pp.tvanp)
{
error++;
Expand All @@ -132,21 +133,21 @@ int Pseudopot_upf::average_p(const double& lambda, Atom_pseudo& pp)
std::cout << "------------------------------------------------------" << std::endl;
return error;
}
if (!pp.has_so && GlobalV::LSPINORB)
if (!pp.has_so && PARAM.inp.lspinorb)
{
error++;
std::cout << "warning_quit! no soc upf used for lspinorb calculation, error!" << std::endl;
return error;
}
// ModuleBase::WARNING_QUIT("average_p", "no soc upf used for lspinorb calculation, error!");

if (!pp.has_so || (GlobalV::LSPINORB && std::abs(lambda_ - 1.0) < 1.0e-8))
if (!pp.has_so || (PARAM.inp.lspinorb && std::abs(lambda_ - 1.0) < 1.0e-8))
{
return error;
}

//if(std::abs(lambda_)<1.0e-8)
if(!GlobalV::LSPINORB)
if(!PARAM.inp.lspinorb)
{
int new_nbeta = 0; //calculate the new nbeta
for(int nb=0; nb< pp.nbeta; nb++)
Expand Down
2 changes: 1 addition & 1 deletion source/module_cell/test/atom_pseudo_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ TEST_F(AtomPseudoTest, SetDSo)
atom_pseudo->set_d_so(d_so_in,nproj,nproj_soc,has_so);
EXPECT_NEAR(atom_pseudo->d_so(0,0,0).real(),1e-8,1e-7);
EXPECT_NEAR(atom_pseudo->d_so(0,0,0).imag(),1e-8,1e-7);
GlobalV::LSPINORB = true;
PARAM.input.lspinorb = true;
atom_pseudo->set_d_so(d_so_in,nproj,nproj_soc,has_so);
EXPECT_NEAR(atom_pseudo->d_so(0,0,0).real(),1e-8,1e-7);
EXPECT_NEAR(atom_pseudo->d_so(0,0,0).imag(),1e-8,1e-7);
Expand Down
8 changes: 4 additions & 4 deletions source/module_cell/test/read_pp_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ TEST_F(ReadPPTest, AverageSimpleReturns)
int ierr;
double lambda = 1.0;
// first return
GlobalV::LSPINORB = 1;
PARAM.input.lspinorb = 1;
upf->has_so = 0;
ierr = read_pp->average_p(lambda, *upf);
EXPECT_EQ(ierr,1);
Expand All @@ -767,7 +767,7 @@ TEST_F(ReadPPTest, AverageErrReturns)
ifs.open("./support/Te.pbe-rrkj.UPF");
read_pp->read_pseudo_upf(ifs, *upf);
EXPECT_TRUE(upf->has_so); // has soc info
GlobalV::LSPINORB = 0;
PARAM.input.lspinorb = 0;
ierr = read_pp->average_p(lambda, *upf);
EXPECT_EQ(upf->nbeta,3);
EXPECT_EQ(ierr,1);
Expand All @@ -787,7 +787,7 @@ TEST_F(ReadPPTest, AverageLSPINORB0)
int ierr;
double lambda = 1.0;
// LSPINORB = 0
GlobalV::LSPINORB = 0;
PARAM.input.lspinorb = 0;
ierr = read_pp->average_p(lambda, *upf);
EXPECT_EQ(ierr,0);
EXPECT_EQ(upf->nbeta,4);
Expand All @@ -804,7 +804,7 @@ TEST_F(ReadPPTest, AverageLSPINORB1)
int ierr;
double lambda = 1.1;
// LSPINORB = 0
GlobalV::LSPINORB = 1;
PARAM.input.lspinorb = 1;
ierr = read_pp->average_p(lambda, *upf);
EXPECT_EQ(ierr,0);
EXPECT_EQ(upf->nbeta,6);
Expand Down
4 changes: 2 additions & 2 deletions source/module_cell/test/unitcell_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1320,7 +1320,7 @@ TEST_F(UcellTest, ReadAtomPositionsS4Noncolin)
PARAM.input.basis_type = "lcao";
PARAM.sys.deepks_setorb = true;
GlobalV::NSPIN = 4;
GlobalV::NONCOLIN = true;
PARAM.input.noncolin = true;
EXPECT_NO_THROW(ucell->read_atom_species(ifa, ofs_running));
EXPECT_DOUBLE_EQ(ucell->latvec.e11, 4.27957);
EXPECT_DOUBLE_EQ(ucell->latvec.e22, 4.27957);
Expand Down Expand Up @@ -1352,7 +1352,7 @@ TEST_F(UcellTest, ReadAtomPositionsS4Colin)
PARAM.input.basis_type = "lcao";
PARAM.sys.deepks_setorb = true;
GlobalV::NSPIN = 4;
GlobalV::NONCOLIN = false;
PARAM.input.noncolin = false;
EXPECT_NO_THROW(ucell->read_atom_species(ifa, ofs_running));
EXPECT_DOUBLE_EQ(ucell->latvec.e11, 4.27957);
EXPECT_DOUBLE_EQ(ucell->latvec.e22, 4.27957);
Expand Down
2 changes: 1 addition & 1 deletion source/module_cell/test/unitcell_test_para.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class UcellTest : public ::testing::Test
PARAM.input.relax_new = utp.relax_new;
PARAM.sys.global_out_dir = "./";
ucell = utp.SetUcellInfo();
GlobalV::LSPINORB = false;
PARAM.input.lspinorb = false;
pp_dir = "./support/";
PARAM.input.pseudo_rcut = 15.0;
PARAM.input.dft_functional = "default";
Expand Down
8 changes: 4 additions & 4 deletions source/module_cell/test/unitcell_test_readpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class UcellTest : public ::testing::Test {
PARAM.input.relax_new = utp.relax_new;
PARAM.sys.global_out_dir = "./";
ucell = utp.SetUcellInfo();
GlobalV::LSPINORB = false;
PARAM.input.lspinorb = false;
pp_dir = "./support/";
PARAM.input.pseudo_rcut = 15.0;
PARAM.input.dft_functional = "default";
Expand All @@ -124,7 +124,7 @@ class UcellTest : public ::testing::Test {
using UcellDeathTest = UcellTest;

TEST_F(UcellDeathTest, ReadCellPPWarning1) {
GlobalV::LSPINORB = true;
PARAM.input.lspinorb = true;
ucell->pseudo_fn[1] = "H_sr.upf";
testing::internal::CaptureStdout();
EXPECT_EXIT(ucell->read_cell_pseudopots(pp_dir, ofs),
Expand Down Expand Up @@ -224,7 +224,7 @@ TEST_F(UcellTest, CalNatomwfc1) {
}

TEST_F(UcellTest, CalNatomwfc2) {
GlobalV::LSPINORB = false;
PARAM.input.lspinorb = false;
GlobalV::NSPIN = 4;
ucell->read_cell_pseudopots(pp_dir, ofs);
EXPECT_FALSE(ucell->atoms[0].ncpp.has_so);
Expand All @@ -238,7 +238,7 @@ TEST_F(UcellTest, CalNatomwfc2) {
}

TEST_F(UcellTest, CalNatomwfc3) {
GlobalV::LSPINORB = true;
PARAM.input.lspinorb = true;
GlobalV::NSPIN = 4;
ucell->read_cell_pseudopots(pp_dir, ofs);
EXPECT_TRUE(ucell->atoms[0].ncpp.has_so);
Expand Down
10 changes: 3 additions & 7 deletions source/module_cell/unitcell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -579,10 +579,6 @@ void UnitCell::setup_cell(const std::string& fn, std::ofstream& log) {
#ifdef __MPI
Parallel_Common::bcast_bool(ok);
Parallel_Common::bcast_bool(ok2);
if (GlobalV::NSPIN == 4) {
Parallel_Common::bcast_bool(GlobalV::DOMAG);
Parallel_Common::bcast_bool(GlobalV::DOMAG_Z);
}
#endif
if (!ok) {
ModuleBase::WARNING_QUIT(
Expand Down Expand Up @@ -985,15 +981,15 @@ void UnitCell::cal_nwfc(std::ofstream& log) {
this->iwt2iw = new int[GlobalV::NLOCAL];

this->itia2iat.create(ntype, namax);
// this->itiaiw2iwt.create(ntype, namax, nwmax*GlobalV::NPOL);
this->set_iat2iwt(GlobalV::NPOL);
// this->itiaiw2iwt.create(ntype, namax, nwmax*PARAM.globalv.npol);
this->set_iat2iwt(PARAM.globalv.npol);
int iat = 0;
int iwt = 0;
for (int it = 0; it < ntype; it++) {
for (int ia = 0; ia < atoms[it].na; ia++) {
this->itia2iat(it, ia) = iat;
// this->iat2ia[iat] = ia;
for (int iw = 0; iw < atoms[it].nw * GlobalV::NPOL; iw++) {
for (int iw = 0; iw < atoms[it].nw * PARAM.globalv.npol; iw++) {
// this->itiaiw2iwt(it, ia, iw) = iwt;
this->iwt2iat[iwt] = iat;
this->iwt2iw[iwt] = iw;
Expand Down
2 changes: 1 addition & 1 deletion source/module_elecstate/elecstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ void ElecState::cal_nbands()
// calculate number of bands (setup.f90)
//=======================================
double occupied_bands = static_cast<double>(GlobalV::nelec / ModuleBase::DEGSPIN);
if (GlobalV::LSPINORB == 1) {
if (PARAM.inp.lspinorb == 1) {
occupied_bands = static_cast<double>(GlobalV::nelec);
}

Expand Down
14 changes: 7 additions & 7 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" || PARAM.inp.precision == "single") {
if (PARAM.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" || PARAM.inp.precision == "single") {
if (PARAM.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 Expand Up @@ -186,8 +186,8 @@ void ElecStatePW<T, Device>::rhoBandK(const psi::Psi<T, Device>& psi)
{
// replaced by denghui at 20221110
elecstate_pw_op()(this->ctx,
GlobalV::DOMAG,
GlobalV::DOMAG_Z,
PARAM.globalv.domag,
PARAM.globalv.domag_z,
this->basis->nrxx,
w1,
this->rho,
Expand Down Expand Up @@ -324,7 +324,7 @@ void ElecStatePW<T, Device>::add_usrho(const psi::Psi<T, Device>& psi)
for (int ia = 0; ia < atom->na; ia++)
{
const int iat = ucell->itia2iat(it, ia);
if (GlobalV::NONCOLIN)
if (PARAM.inp.noncolin)
{
// noncolinear case
}
Expand Down Expand Up @@ -360,10 +360,10 @@ void ElecStatePW<T, Device>::add_usrho(const psi::Psi<T, Device>& psi)
}

// copy output from GEMM into desired format
if (GlobalV::NONCOLIN && !atom->ncpp.has_so)
if (PARAM.inp.noncolin && !atom->ncpp.has_so)
{
}
else if (GlobalV::NONCOLIN && atom->ncpp.has_so)
else if (PARAM.inp.noncolin && atom->ncpp.has_so)
{
}
else
Expand Down
Loading

0 comments on commit 7a2e4a8

Please sign in to comment.