From 00df0e27e7ee8da4a838ba13bc58a1dae04bd120 Mon Sep 17 00:00:00 2001 From: liiutao <74701833+A-006@users.noreply.github.com> Date: Thu, 19 Sep 2024 20:07:04 +0800 Subject: [PATCH] Refator:Use PARAM instead of nspin,cal_stress (#5136) * delete parameter in gloablV * change nspin in module_cell * change nspin in module_elecstate * change nspin in module_esolver * change nspin in module_hamilt_lcao * change nspin in module_hamilt_pw * change nspin in module_hamilt_io * change nspin * change nspin in module_cell in test file * change nspin in module_elecstate in test file * change nspin in module_io in test file * change nspin in module_xc in test file * change nspin in module_io in test file * change nspin in module_psi in test file * change nspin in test file * [pre-commit.ci lite] apply automatic fixes * fix bug in two_fermi * fix bug in deepks merge --- source/module_base/global_file.cpp | 2 +- source/module_base/global_variable.cpp | 10 - source/module_base/global_variable.h | 13 - source/module_cell/atom_pseudo.cpp | 3 +- source/module_cell/module_paw/paw_atom.cpp | 25 +- source/module_cell/module_paw/paw_cell.cpp | 4 +- .../module_cell/module_paw/test/test_paw2.cpp | 5 +- .../module_cell/module_symmetry/symmetry.cpp | 4 +- source/module_cell/read_atoms.cpp | 8 +- source/module_cell/test/atom_pseudo_test.cpp | 2 +- source/module_cell/test/klist_test.cpp | 4 +- source/module_cell/test/klist_test_para.cpp | 4 +- source/module_cell/test/unitcell_test.cpp | 26 +- .../module_cell/test/unitcell_test_para.cpp | 4 +- .../module_cell/test/unitcell_test_readpp.cpp | 8 +- .../test/unitcell_test_setupcell.cpp | 11 +- .../module_cell/test_pw/unitcell_test_pw.cpp | 2 +- source/module_cell/unitcell.cpp | 10 +- source/module_cell/unitcell.h | 2 +- source/module_elecstate/elecstate.cpp | 16 +- source/module_elecstate/elecstate.h | 3 +- source/module_elecstate/elecstate_energy.cpp | 10 +- source/module_elecstate/elecstate_lcao.cpp | 16 +- .../module_elecstate/elecstate_lcao_tddft.cpp | 3 +- source/module_elecstate/elecstate_print.cpp | 14 +- source/module_elecstate/elecstate_pw.cpp | 28 +- source/module_elecstate/elecstate_pw_sdft.cpp | 5 +- source/module_elecstate/magnetism.cpp | 7 +- .../module_elecstate/module_charge/charge.cpp | 26 +- .../module_charge/charge_init.cpp | 18 +- .../module_charge/charge_mixing.cpp | 192 +++--- .../module_charge/charge_mpi.cpp | 2 +- .../module_dm/density_matrix.cpp | 7 +- source/module_elecstate/occupy.cpp | 5 +- source/module_elecstate/potentials/efield.h | 4 +- .../potentials/potential_new.cpp | 40 +- .../test/charge_extra_test.cpp | 24 +- .../test/charge_mixing_test.cpp | 146 ++--- source/module_elecstate/test/charge_test.cpp | 24 +- .../test/elecstate_base_test.cpp | 42 +- .../test/elecstate_energy_test.cpp | 4 +- .../test/elecstate_magnetism_test.cpp | 25 +- .../test/elecstate_occupy_test.cpp | 10 +- .../test/elecstate_print_test.cpp | 26 +- .../test/elecstate_pw_test.cpp | 6 +- .../test/potential_new_test.cpp | 32 +- .../test_mpi/charge_mpi_test.cpp | 2 +- source/module_esolver/esolver.cpp | 6 +- source/module_esolver/esolver_fp.cpp | 18 +- source/module_esolver/esolver_ks.cpp | 10 +- source/module_esolver/esolver_ks_lcao.cpp | 40 +- .../module_esolver/esolver_ks_lcao_tddft.cpp | 10 +- source/module_esolver/esolver_ks_lcaopw.cpp | 6 +- source/module_esolver/esolver_ks_pw.cpp | 32 +- source/module_esolver/esolver_of.cpp | 50 +- .../module_esolver/esolver_of_interface.cpp | 31 +- source/module_esolver/esolver_of_tool.cpp | 64 +- source/module_esolver/esolver_sdft_pw.cpp | 6 +- source/module_esolver/lcao_before_scf.cpp | 22 +- source/module_esolver/lcao_fun.cpp | 8 +- source/module_esolver/lcao_init_after_vc.cpp | 4 +- source/module_esolver/lcao_nscf.cpp | 8 +- source/module_esolver/lcao_others.cpp | 8 +- source/module_esolver/pw_fun.cpp | 2 +- source/module_esolver/pw_init_after_vc.cpp | 2 +- source/module_esolver/pw_nscf.cpp | 10 +- .../module_surchem/sol_force.cpp | 3 +- .../module_xc/test/test_xc3.cpp | 9 +- .../module_xc/test/test_xc5.cpp | 15 +- .../module_xc/test/xctest.h | 3 +- .../module_xc/xc_functional.cpp | 6 +- .../module_xc/xc_functional_gradcorr.cpp | 33 +- .../module_xc/xc_functional_vxc.cpp | 30 +- .../hamilt_lcaodft/FORCE_gamma.cpp | 6 +- .../hamilt_lcaodft/FORCE_k.cpp | 7 +- .../hamilt_lcaodft/LCAO_domain.h | 1 + .../hamilt_lcaodft/LCAO_hamilt.hpp | 7 +- .../hamilt_lcaodft/LCAO_init_basis.cpp | 2 +- .../hamilt_lcaodft/LCAO_nl_mu.cpp | 2 +- .../hamilt_lcaodft/LCAO_set_st.cpp | 4 +- .../hamilt_lcaodft/LCAO_set_zero.cpp | 3 +- .../hamilt_lcaodft/fedm_gamma.cpp | 3 +- .../hamilt_lcaodft/fedm_k.cpp | 3 +- .../hamilt_lcaodft/ftvnl_dphi_gamma.cpp | 3 +- .../hamilt_lcaodft/ftvnl_dphi_k.cpp | 3 +- .../hamilt_lcaodft/fvl_dphi_gamma.cpp | 3 +- .../hamilt_lcaodft/fvl_dphi_k.cpp | 3 +- .../hamilt_lcaodft/fvnl_dbeta_gamma.cpp | 3 +- .../hamilt_lcaodft/fvnl_dbeta_k.cpp | 2 +- .../hamilt_lcaodft/hamilt_lcao.cpp | 6 +- .../operator_lcao/dftu_lcao.cpp | 2 +- .../operator_lcao/op_exx_lcao.hpp | 10 +- .../operator_lcao/td_ekinetic_lcao.cpp | 3 +- .../operator_lcao/test/test_dftu.cpp | 7 +- .../operator_lcao/veff_lcao.cpp | 3 +- .../hamilt_lcaodft/spar_dh.cpp | 45 +- .../hamilt_lcaodft/spar_hsr.cpp | 6 +- .../hamilt_lcaodft/spar_st.cpp | 7 +- .../hamilt_lcaodft/wavefunc_in_pw.cpp | 20 +- .../module_deepks/LCAO_deepks_interface.cpp | 4 +- .../module_deepks/LCAO_deepks_odelta.cpp | 3 +- .../module_deepks/LCAO_deepks_vdelta.cpp | 3 +- .../module_deepks/orbital_precalc.cpp | 2 +- .../test/LCAO_deepks_test_prep.cpp | 2 +- .../module_deepks/test/klist_1.cpp | 5 +- .../module_hamilt_lcao/module_dftu/dftu.cpp | 10 +- .../module_dftu/dftu_folding.cpp | 2 +- .../module_dftu/dftu_force.cpp | 8 +- .../module_dftu/dftu_io.cpp | 12 +- .../module_dftu/dftu_occup.cpp | 26 +- .../module_dftu/dftu_yukawa.cpp | 5 +- .../module_hamilt_lcao/module_gint/gint.cpp | 10 +- .../module_gint/gint_gpu_interface.cpp | 2 +- .../module_gint/gint_k_env.cpp | 2 +- .../module_gint/gint_k_pvdpr.cpp | 5 +- .../module_gint/gint_k_pvpr.cpp | 8 +- .../module_gint/gint_k_sparse1.cpp | 4 +- .../module_gint/gint_rho_cpu_interface.cpp | 5 +- .../module_gint/grid_technique.cpp | 4 +- .../hamilt_ofdft/kedf_lkt.cpp | 13 +- .../module_hamilt_pw/hamilt_ofdft/kedf_tf.cpp | 13 +- .../module_hamilt_pw/hamilt_ofdft/kedf_vw.cpp | 65 +- .../module_hamilt_pw/hamilt_ofdft/kedf_wt.cpp | 52 +- .../hamilt_pwdft/VNL_grad_pw.cpp | 15 +- .../hamilt_pwdft/VNL_in_pw.cpp | 100 ++- .../module_hamilt_pw/hamilt_pwdft/forces.cpp | 10 +- .../hamilt_pwdft/forces_cc.cpp | 7 +- .../hamilt_pwdft/forces_us.cpp | 11 +- .../hamilt_pwdft/fs_nonlocal_tools.cpp | 7 +- .../hamilt_pwdft/kernels/vnl_op.h | 2 +- .../hamilt_pwdft/operator_pw/projop_pw.cpp | 9 +- .../hamilt_pwdft/radial_proj.h | 8 +- .../hamilt_pwdft/stress_func_cc.cpp | 5 +- .../hamilt_pwdft/stress_func_har.cpp | 5 +- .../hamilt_pwdft/stress_func_loc.cpp | 5 +- .../hamilt_pwdft/stress_func_mgga.cpp | 11 +- .../hamilt_pwdft/stress_func_nl.cpp | 30 +- .../hamilt_pwdft/stress_func_us.cpp | 26 +- .../hamilt_pwdft/wavefunc.cpp | 18 +- .../hamilt_pwdft/wf_atomic.cpp | 10 +- source/module_hsolver/diago_pexsi.cpp | 9 +- source/module_hsolver/hsolver_lcao.cpp | 3 +- source/module_hsolver/hsolver_pw.cpp | 4 +- .../module_pexsi/simple_pexsi.cpp | 3 +- .../module_hsolver/test/diago_pexsi_test.cpp | 5 +- .../module_hsolver/test/test_hsolver_pw.cpp | 4 +- .../module_hsolver/test/test_hsolver_sdft.cpp | 7 +- source/module_io/berryphase.cpp | 35 +- source/module_io/dos_nao.cpp | 2 +- source/module_io/input_conv.cpp | 11 +- source/module_io/json_output/output_info.cpp | 2 +- source/module_io/numerical_basis.cpp | 5 +- source/module_io/output_log.cpp | 2 +- source/module_io/output_mulliken.cpp | 5 +- source/module_io/print_info.cpp | 2 +- source/module_io/read_set_globalv.cpp | 6 + source/module_io/read_wfc_to_rho.cpp | 2 +- source/module_io/rhog_io.cpp | 7 +- source/module_io/td_current_io.cpp | 12 +- source/module_io/test/outputlog_test.cpp | 2 +- source/module_io/test/read_rhog_test.cpp | 18 +- .../module_io/test/read_wfc_to_rho_test.cpp | 2 +- source/module_io/test/write_dos_pw_test.cpp | 4 +- .../module_io/test/write_istate_info_test.cpp | 8 +- source/module_io/test/write_orb_info_test.cpp | 2 +- source/module_io/to_wannier90.cpp | 20 +- source/module_io/to_wannier90_lcao.cpp | 4 +- source/module_io/to_wannier90_lcao_in_pw.cpp | 6 +- source/module_io/to_wannier90_pw.cpp | 62 +- source/module_io/unk_overlap_pw.cpp | 2 +- source/module_io/write_HS_R.cpp | 4 +- source/module_io/write_HS_sparse.cpp | 26 +- source/module_io/write_cube.cpp | 3 +- source/module_io/write_dos_lcao.cpp | 34 +- source/module_io/write_dos_pw.cpp | 2 +- source/module_io/write_elecstat_pot.cpp | 2 +- source/module_io/write_istate_info.cpp | 2 +- source/module_io/write_proj_band_lcao.cpp | 24 +- source/module_io/write_wfc_r.cpp | 2 +- source/module_lr/dm_trans/dmr_complex.cpp | 5 +- source/module_lr/esolver_lrtd_lcao.cpp | 6 +- source/module_lr/hsolver_lrtd.cpp | 4 +- source/module_lr/lr_spectrum.cpp | 2 +- .../operator_casida/operator_lr_hxc.cpp | 5 +- source/module_lr/potentials/kernel_xc.cpp | 7 +- source/module_lr/potentials/pot_hxc_lrtd.cpp | 2 +- source/module_lr/utils/gint_move.hpp | 11 +- source/module_md/run_md.cpp | 4 +- source/module_md/test/setcell.h | 2 +- source/module_parameter/system_parameter.h | 5 + source/module_psi/psi_initializer_atomic.cpp | 24 +- source/module_psi/psi_initializer_nao.cpp | 24 +- .../test/psi_initializer_unit_test.cpp | 16 +- source/module_relax/relax_driver.cpp | 6 +- .../relax_old/ions_move_basic.cpp | 1 + .../module_relax/relax_old/ions_move_basic.h | 2 +- .../module_relax/relax_old/ions_move_cg.cpp | 4 +- .../relax_old/ions_move_methods.cpp | 20 +- source/module_relax/relax_old/relax_old.cpp | 2 +- .../relax_old/test/ions_move_cg_test.cpp | 14 +- .../relax_old/test/ions_move_methods_test.cpp | 24 +- source/module_ri/Exx_LRI.hpp | 18 +- source/module_ri/Exx_LRI_interface.hpp | 8 +- source/module_ri/RI_2D_Comm.cpp | 143 ++--- source/module_ri/RI_2D_Comm.hpp | 571 +++++++++--------- source/module_ri/RPA_LRI.hpp | 24 +- source/module_ri/exx_lip.cpp | 24 +- .../module_exx_symmetry/symmetry_rotation.cpp | 3 +- 208 files changed, 1711 insertions(+), 1653 deletions(-) diff --git a/source/module_base/global_file.cpp b/source/module_base/global_file.cpp index 80ce3983aa..c2cb6ad0f1 100644 --- a/source/module_base/global_file.cpp +++ b/source/module_base/global_file.cpp @@ -279,7 +279,7 @@ void ModuleBase::Global_File::delete_tmp_files() { if (GlobalV::MY_RANK == 0) { - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { std::string tmp_chg_1 = PARAM.globalv.global_out_dir + "NOW_SPIN" + std::to_string(is + 1) + "_CHG.cube"; std::string tmp_chg_2 = PARAM.globalv.global_out_dir + "OLD1_SPIN" + std::to_string(is + 1) + "_CHG.cube"; diff --git a/source/module_base/global_variable.cpp b/source/module_base/global_variable.cpp index 21c636242e..caa75cee7c 100644 --- a/source/module_base/global_variable.cpp +++ b/source/module_base/global_variable.cpp @@ -22,25 +22,15 @@ int NBANDS = 0; int NLOCAL = 0; // total number of local basis. int NSPIN = 1; // LDA -bool TWO_EFERMI = false; // two fermi energy, exist only magnetization is fixed. double nupdown = 0.0; -bool CAL_STRESS = false; -std::string RELAX_METHOD = "bfgs"; bool use_uspp = false; std::string KS_SOLVER = "cg"; // xiaohui add 2013-09-01 double SEARCH_RADIUS = -1.0; -int PW_DIAG_NDIM = 4; -double PW_DIAG_THR = 1.0e-2; int NB2D = 1; -double DQ = 0.010; // space between Q points of the reciprocal radial tab -int NQX = 10000; // number of points describing reciprocal radial tab -int NQXQ = 10000; // number of points describing reciprocal radial tab for Q - - //---------------------------------------------------------- // EXPLAIN : Parallel information //---------------------------------------------------------- diff --git a/source/module_base/global_variable.h b/source/module_base/global_variable.h index e582478ae8..83b6b3faf9 100644 --- a/source/module_base/global_variable.h +++ b/source/module_base/global_variable.h @@ -22,30 +22,17 @@ extern int NLOCAL; // 1.1 // mohan add 2009-05-29 extern int NSPIN; // 7 -extern bool TWO_EFERMI; // 7.5 two fermi energy, exist if nupdown isn't zero. extern double nupdown; - -extern bool CAL_STRESS; // 8.25 calcualte the stress - -extern std::string RELAX_METHOD; - - 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 -extern int PW_DIAG_NDIM; // 14 -extern double PW_DIAG_THR; // 15 pw_diag_thr extern int NB2D; // 16.5 dividsion of 2D_matrix. // pw, 2: real drho for lcao -extern double DQ; // 19 mohan add 2009-09-10 -extern int NQX; // 20 mohan add 2009-09-10 -extern int NQXQ; // liuyu add 2023-10-03 - //======================================================================== // EXPLAIN : Parallel information diff --git a/source/module_cell/atom_pseudo.cpp b/source/module_cell/atom_pseudo.cpp index 0e4739fb77..0b6767f8ed 100644 --- a/source/module_cell/atom_pseudo.cpp +++ b/source/module_cell/atom_pseudo.cpp @@ -1,4 +1,5 @@ #include "atom_pseudo.h" +#include "module_parameter/parameter.h" #include "module_parameter/parameter.h" Atom_pseudo::Atom_pseudo() @@ -106,7 +107,7 @@ void Atom_pseudo::set_d_so(ModuleBase::ComplexMatrix& d_so_in, { for (int is2 = 0; is2 < 2; is2++) { - if (is >= GlobalV::NSPIN) { + if (is >= PARAM.inp.nspin) { break; } for (int L1 = 0; L1 < nproj_soc; L1++) diff --git a/source/module_cell/module_paw/paw_atom.cpp b/source/module_cell/module_paw/paw_atom.cpp index 9f9fe2b298..49084389f2 100644 --- a/source/module_cell/module_paw/paw_atom.cpp +++ b/source/module_cell/module_paw/paw_atom.cpp @@ -1,5 +1,6 @@ #include "paw_atom.h" #include "module_base/global_variable.h" +#include "module_parameter/parameter.h" void Paw_Atom::init_paw_atom(const int nproj_in) { @@ -8,17 +9,17 @@ void Paw_Atom::init_paw_atom(const int nproj_in) ca.resize(nproj); - rhoij.resize(GlobalV::NSPIN); - for(int is = 0; is < GlobalV::NSPIN; is ++) + rhoij.resize(PARAM.inp.nspin); + for(int is = 0; is < PARAM.inp.nspin; is ++) { rhoij[is].resize(nproj*(nproj + 1) / 2); } - rhoijp.resize(GlobalV::NSPIN * nproj*(nproj + 1) / 2); + rhoijp.resize(PARAM.inp.nspin * nproj*(nproj + 1) / 2); rhoijselect.resize(nproj*(nproj + 1) / 2); - dij.resize(GlobalV::NSPIN); - for(int is = 0; is < GlobalV::NSPIN; is ++) + dij.resize(PARAM.inp.nspin); + for(int is = 0; is < PARAM.inp.nspin; is ++) { dij[is].resize(nproj*nproj); } @@ -45,14 +46,14 @@ void Paw_Atom::reset_rhoij() for(int i = 0; i < nproj*(nproj+1)/2; i ++) { - for(int is = 0; is < GlobalV::NSPIN; is ++) + for(int is = 0; is < PARAM.inp.nspin; is ++) { rhoij[is][i] = 0.0; } rhoijselect[i] = -1; } - for(int i = 0; i < GlobalV::NSPIN * nproj*(nproj + 1) / 2; i ++) + for(int i = 0; i < PARAM.inp.nspin * nproj*(nproj + 1) / 2; i ++) { rhoijp[i] = 0.0; } @@ -75,7 +76,7 @@ void Paw_Atom::set_rhoij(std::vector & rhoij_in) { for(int i = 0; i < nproj*(nproj+1)/2; i ++) { - for(int is = 0; is < GlobalV::NSPIN; is ++) + for(int is = 0; is < PARAM.inp.nspin; is ++) { rhoij[is][i] = rhoij_in[i]; } @@ -88,7 +89,7 @@ void Paw_Atom::convert_rhoij() for(int i = 0; i < rhoij[0].size(); i ++) { bool nonzero = false; - for(int is = 0; is < GlobalV::NSPIN; is ++) + for(int is = 0; is < PARAM.inp.nspin; is ++) { if(std::abs(rhoij[is][i]) > 1e-10) { @@ -100,7 +101,7 @@ void Paw_Atom::convert_rhoij() if(nonzero) { rhoijselect[nrhoijsel] = i+1; //index in fortran - for(int is = 0; is < GlobalV::NSPIN; is ++) + for(int is = 0; is < PARAM.inp.nspin; is ++) { rhoijp[nrhoijsel + is * rhoij[0].size()] = rhoij[is][i]; } @@ -111,7 +112,7 @@ void Paw_Atom::convert_rhoij() void Paw_Atom::reset_dij() { - for(int is = 0; is < GlobalV::NSPIN; is ++) + for(int is = 0; is < PARAM.inp.nspin; is ++) { for(int i = 0; i < nproj*nproj; i ++) { @@ -122,7 +123,7 @@ void Paw_Atom::reset_dij() void Paw_Atom::set_dij(double** dij_in) { - for(int is = 0; is < GlobalV::NSPIN; is ++) + for(int is = 0; is < PARAM.inp.nspin; is ++) { for(int i = 0; i < nproj*nproj; i ++) { diff --git a/source/module_cell/module_paw/paw_cell.cpp b/source/module_cell/module_paw/paw_cell.cpp index 88fad5f70a..7fd6337e15 100644 --- a/source/module_cell/module_paw/paw_cell.cpp +++ b/source/module_cell/module_paw/paw_cell.cpp @@ -125,7 +125,7 @@ void Paw_Cell::init_rhoij() for(int iproj = 0; iproj < nproj; iproj ++) { int i0 = iproj * (iproj + 1) / 2; - rhoij_in[i0 + iproj] = mstate_occ[iproj] / GlobalV::NSPIN; + rhoij_in[i0 + iproj] = mstate_occ[iproj] / PARAM.inp.nspin; } paw_atom_list[iat].set_rhoij(rhoij_in); @@ -215,7 +215,7 @@ void Paw_Cell::set_paw_k( std::complex i_cplx(0.0,1.0); // ig : i(G) - if(PARAM.inp.cal_force || GlobalV::CAL_STRESS) + if(PARAM.inp.cal_force || PARAM.inp.cal_stress) { ig.resize(npw); for(int ipw = 0; ipw < npw; ipw ++) diff --git a/source/module_cell/module_paw/test/test_paw2.cpp b/source/module_cell/module_paw/test/test_paw2.cpp index f0d3da036a..e8e70d6f45 100644 --- a/source/module_cell/module_paw/test/test_paw2.cpp +++ b/source/module_cell/module_paw/test/test_paw2.cpp @@ -1,6 +1,9 @@ #include "gtest/gtest.h" #include #include +#define private public +#include "module_parameter/parameter.h" +#undef private #include "module_base/global_variable.h" #include "../paw_atom.h" @@ -24,7 +27,7 @@ class Test_Paw_Atom : public testing::Test TEST_F(Test_Paw_Atom, test_paw) { - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; paw_atom.init_paw_atom(nproj); paw_atom.reset_rhoij(); diff --git a/source/module_cell/module_symmetry/symmetry.cpp b/source/module_cell/module_symmetry/symmetry.cpp index 79741d9cff..4cc925fedb 100644 --- a/source/module_cell/module_symmetry/symmetry.cpp +++ b/source/module_cell/module_symmetry/symmetry.cpp @@ -119,11 +119,11 @@ void Symmetry::analy_sys(const Lattice& lat, const Statistics& st, Atom* atoms, // which should be loop over all atoms, f.e only loop over spin-up atoms // -------------------------------- // AFM analysis Start - if (GlobalV::NSPIN > 1) { + if (PARAM.inp.nspin > 1) { pricell_loop = this->magmom_same_check(atoms); } - if (!pricell_loop && GlobalV::NSPIN == 2) + if (!pricell_loop && PARAM.inp.nspin == 2) {//analyze symmetry for spin-up atoms only std::vector pos_spinup; for (int it = 0;it < ntype;++it) diff --git a/source/module_cell/read_atoms.cpp b/source/module_cell/read_atoms.cpp index 2ebe9c29fb..043bb0f7b1 100644 --- a/source/module_cell/read_atoms.cpp +++ b/source/module_cell/read_atoms.cpp @@ -626,7 +626,7 @@ bool UnitCell::read_atom_positions(std::ifstream &ifpos, std::ofstream &ofs_runn std::string mags; //cout<<"mag"<0 to avoid too much output @@ -813,7 +813,7 @@ bool UnitCell::read_atom_positions(std::ifstream &ifpos, std::ofstream &ofs_runn } if (autoset_mag) { - if(GlobalV::NSPIN==4) + if(PARAM.inp.nspin==4) { for (int it = 0;it < ntype; it++) { @@ -827,7 +827,7 @@ bool UnitCell::read_atom_positions(std::ifstream &ifpos, std::ofstream &ofs_runn } } } - else if(GlobalV::NSPIN==2) + else if(PARAM.inp.nspin==2) { for (int it = 0;it < ntype; it++) { diff --git a/source/module_cell/test/atom_pseudo_test.cpp b/source/module_cell/test/atom_pseudo_test.cpp index d1efd31295..2bbd43641b 100644 --- a/source/module_cell/test/atom_pseudo_test.cpp +++ b/source/module_cell/test/atom_pseudo_test.cpp @@ -54,7 +54,7 @@ TEST_F(AtomPseudoTest, SetDSo) int nproj = 6; int nproj_soc = 4; bool has_so = true; - GlobalV::NSPIN = 4; + PARAM.input.nspin = 4; 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); diff --git a/source/module_cell/test/klist_test.cpp b/source/module_cell/test/klist_test.cpp index be2b2baad4..ab03d983f4 100644 --- a/source/module_cell/test/klist_test.cpp +++ b/source/module_cell/test/klist_test.cpp @@ -596,7 +596,7 @@ TEST_F(KlistTest, SetAfterVC) kv->kvec_c[0].x = 0; kv->kvec_c[0].y = 0; kv->kvec_c[0].z = 0; - kv->set_after_vc(GlobalV::NSPIN, GlobalC::ucell.G, GlobalC::ucell.latvec); + kv->set_after_vc(PARAM.input.nspin, GlobalC::ucell.G, GlobalC::ucell.latvec); EXPECT_TRUE(kv->kd_done); EXPECT_TRUE(kv->kc_done); EXPECT_DOUBLE_EQ(kv->kvec_d[0].x, 0); @@ -616,7 +616,7 @@ TEST_F(KlistTest, PrintKlists) kv->kvec_c[0].x = 0; kv->kvec_c[0].y = 0; kv->kvec_c[0].z = 0; - kv->set_after_vc(GlobalV::NSPIN, GlobalC::ucell.G, GlobalC::ucell.latvec); + kv->set_after_vc(PARAM.input.nspin, GlobalC::ucell.G, GlobalC::ucell.latvec); EXPECT_TRUE(kv->kd_done); kv->print_klists(GlobalV::ofs_running); GlobalV::ofs_running.close(); diff --git a/source/module_cell/test/klist_test_para.cpp b/source/module_cell/test/klist_test_para.cpp index 1ccea7aa69..a9524e2c12 100644 --- a/source/module_cell/test/klist_test_para.cpp +++ b/source/module_cell/test/klist_test_para.cpp @@ -224,7 +224,7 @@ TEST_F(KlistParaTest, Set) std::string k_file = "./support/KPT1"; // set klist kv->nspin = 1; - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; if (GlobalV::NPROC == 4) { GlobalV::KPAR = 2; @@ -281,7 +281,7 @@ TEST_F(KlistParaTest, SetAfterVC) std::string k_file = "./support/KPT1"; // set klist kv->nspin = 1; - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; if (GlobalV::NPROC == 4) { GlobalV::KPAR = 1; diff --git a/source/module_cell/test/unitcell_test.cpp b/source/module_cell/test/unitcell_test.cpp index c8d1509ce9..a9fb6503eb 100644 --- a/source/module_cell/test/unitcell_test.cpp +++ b/source/module_cell/test/unitcell_test.cpp @@ -1257,7 +1257,7 @@ TEST_F(UcellTest, ReadAtomPositionsS1) PARAM.input.test_pseudo_cell = 2; PARAM.input.basis_type = "lcao"; PARAM.sys.deepks_setorb = true; - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; 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); @@ -1288,7 +1288,7 @@ TEST_F(UcellTest, ReadAtomPositionsS2) PARAM.input.test_pseudo_cell = 2; PARAM.input.basis_type = "lcao"; PARAM.sys.deepks_setorb = true; - GlobalV::NSPIN = 2; + PARAM.input.nspin = 2; 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); @@ -1319,7 +1319,7 @@ TEST_F(UcellTest, ReadAtomPositionsS4Noncolin) PARAM.input.test_pseudo_cell = 2; PARAM.input.basis_type = "lcao"; PARAM.sys.deepks_setorb = true; - GlobalV::NSPIN = 4; + PARAM.input.nspin = 4; PARAM.input.noncolin = true; EXPECT_NO_THROW(ucell->read_atom_species(ifa, ofs_running)); EXPECT_DOUBLE_EQ(ucell->latvec.e11, 4.27957); @@ -1351,7 +1351,7 @@ TEST_F(UcellTest, ReadAtomPositionsS4Colin) PARAM.input.test_pseudo_cell = 2; PARAM.input.basis_type = "lcao"; PARAM.sys.deepks_setorb = true; - GlobalV::NSPIN = 4; + PARAM.input.nspin = 4; PARAM.input.noncolin = false; EXPECT_NO_THROW(ucell->read_atom_species(ifa, ofs_running)); EXPECT_DOUBLE_EQ(ucell->latvec.e11, 4.27957); @@ -1383,7 +1383,7 @@ TEST_F(UcellTest, ReadAtomPositionsC) PARAM.input.test_pseudo_cell = 2; PARAM.input.basis_type = "lcao"; PARAM.sys.deepks_setorb = true; - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; 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); @@ -1414,7 +1414,7 @@ TEST_F(UcellTest, ReadAtomPositionsCA) PARAM.input.test_pseudo_cell = 2; PARAM.input.basis_type = "lcao"; PARAM.sys.deepks_setorb = true; - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; 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); @@ -1445,7 +1445,7 @@ TEST_F(UcellTest, ReadAtomPositionsCACXY) PARAM.input.test_pseudo_cell = 2; PARAM.input.basis_type = "lcao"; PARAM.sys.deepks_setorb = true; - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; 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); @@ -1476,7 +1476,7 @@ TEST_F(UcellTest, ReadAtomPositionsCACXZ) PARAM.input.test_pseudo_cell = 2; PARAM.input.basis_type = "lcao"; PARAM.sys.deepks_setorb = true; - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; 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); @@ -1507,7 +1507,7 @@ TEST_F(UcellTest, ReadAtomPositionsCACYZ) PARAM.input.test_pseudo_cell = 2; PARAM.input.basis_type = "lcao"; PARAM.sys.deepks_setorb = true; - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; 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); @@ -1538,7 +1538,7 @@ TEST_F(UcellTest, ReadAtomPositionsCACXYZ) PARAM.input.test_pseudo_cell = 2; PARAM.input.basis_type = "lcao"; PARAM.sys.deepks_setorb = true; - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; 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); @@ -1569,7 +1569,7 @@ TEST_F(UcellTest, ReadAtomPositionsCAU) PARAM.input.test_pseudo_cell = 2; PARAM.input.basis_type = "lcao"; PARAM.sys.deepks_setorb = true; - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; PARAM.input.fixed_atoms = true; EXPECT_NO_THROW(ucell->read_atom_species(ifa, ofs_running)); EXPECT_DOUBLE_EQ(ucell->latvec.e11, 4.27957); @@ -1601,7 +1601,7 @@ TEST_F(UcellTest, ReadAtomPositionsAutosetMag) PARAM.input.test_pseudo_cell = 2; PARAM.input.basis_type = "lcao"; PARAM.sys.deepks_setorb = true; - GlobalV::NSPIN = 2; + PARAM.input.nspin = 2; 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); @@ -1619,7 +1619,7 @@ TEST_F(UcellTest, ReadAtomPositionsAutosetMag) } } // for nspin == 4 - GlobalV::NSPIN = 4; + PARAM.input.nspin = 4; delete[] ucell->magnet.start_magnetization; ucell->magnet.start_magnetization = new double[ucell->ntype]; ucell->read_atom_positions(ifa, ofs_running, ofs_warning); diff --git a/source/module_cell/test/unitcell_test_para.cpp b/source/module_cell/test/unitcell_test_para.cpp index 76b76a3894..a6a097d9e8 100644 --- a/source/module_cell/test/unitcell_test_para.cpp +++ b/source/module_cell/test/unitcell_test_para.cpp @@ -81,7 +81,7 @@ class UcellTest : public ::testing::Test PARAM.input.pseudo_rcut = 15.0; PARAM.input.dft_functional = "default"; PARAM.input.test_pseudo_cell = 1; - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; PARAM.input.basis_type = "pw"; } void TearDown() @@ -106,7 +106,7 @@ TEST_F(UcellTest, BcastUnitcell2) TEST_F(UcellTest, BcastUnitcell) { - GlobalV::NSPIN = 4; + PARAM.input.nspin = 4; ucell->bcast_unitcell(); if (GlobalV::MY_RANK != 0) { diff --git a/source/module_cell/test/unitcell_test_readpp.cpp b/source/module_cell/test/unitcell_test_readpp.cpp index 782ac08521..b2b01c0559 100644 --- a/source/module_cell/test/unitcell_test_readpp.cpp +++ b/source/module_cell/test/unitcell_test_readpp.cpp @@ -115,7 +115,7 @@ class UcellTest : public ::testing::Test { PARAM.input.pseudo_rcut = 15.0; PARAM.input.dft_functional = "default"; PARAM.input.test_pseudo_cell = true; - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; PARAM.input.basis_type = "pw"; } void TearDown() { ofs.close(); } @@ -225,7 +225,7 @@ TEST_F(UcellTest, CalNatomwfc1) { TEST_F(UcellTest, CalNatomwfc2) { PARAM.input.lspinorb = false; - GlobalV::NSPIN = 4; + PARAM.input.nspin = 4; ucell->read_cell_pseudopots(pp_dir, ofs); EXPECT_FALSE(ucell->atoms[0].ncpp.has_so); EXPECT_FALSE(ucell->atoms[1].ncpp.has_so); @@ -239,7 +239,7 @@ TEST_F(UcellTest, CalNatomwfc2) { TEST_F(UcellTest, CalNatomwfc3) { PARAM.input.lspinorb = true; - GlobalV::NSPIN = 4; + PARAM.input.nspin = 4; ucell->read_cell_pseudopots(pp_dir, ofs); EXPECT_TRUE(ucell->atoms[0].ncpp.has_so); EXPECT_TRUE(ucell->atoms[1].ncpp.has_so); @@ -317,7 +317,7 @@ TEST_F(UcellTest, CalNwfc1) { } TEST_F(UcellTest, CalNwfc2) { - GlobalV::NSPIN = 4; + PARAM.input.nspin = 4; PARAM.input.basis_type = "lcao"; ucell->read_cell_pseudopots(pp_dir, ofs); EXPECT_FALSE(ucell->atoms[0].ncpp.has_so); diff --git a/source/module_cell/test/unitcell_test_setupcell.cpp b/source/module_cell/test/unitcell_test_setupcell.cpp index db5eacbe1c..cda2b115d5 100644 --- a/source/module_cell/test/unitcell_test_setupcell.cpp +++ b/source/module_cell/test/unitcell_test_setupcell.cpp @@ -1,5 +1,8 @@ #include "gtest/gtest.h" #include "gmock/gmock.h" +#define private public +#include "module_parameter/parameter.h" +#undef private #include "memory" #include "module_base/mathzone.h" #include "module_base/global_variable.h" @@ -74,7 +77,7 @@ TEST_F(UcellTest,SetupCellS1) std::string fn = "./support/STRU_MgO"; std::ofstream ofs_running; ofs_running.open("setup_cell.tmp"); - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; ucell->ntype = 2; ucell->setup_cell(fn,ofs_running); ofs_running.close(); @@ -86,7 +89,7 @@ TEST_F(UcellTest,SetupCellS2) std::string fn = "./support/STRU_MgO"; std::ofstream ofs_running; ofs_running.open("setup_cell.tmp"); - GlobalV::NSPIN = 2; + PARAM.input.nspin = 2; ucell->ntype = 2; ucell->setup_cell(fn,ofs_running); ofs_running.close(); @@ -98,7 +101,7 @@ TEST_F(UcellTest,SetupCellS4) std::string fn = "./support/STRU_MgO"; std::ofstream ofs_running; ofs_running.open("setup_cell.tmp"); - GlobalV::NSPIN = 4; + PARAM.input.nspin = 4; ucell->ntype = 2; ucell->setup_cell(fn,ofs_running); ofs_running.close(); @@ -138,7 +141,7 @@ TEST_F(UcellTest,SetupCellAfterVC) std::string fn = "./support/STRU_MgO"; std::ofstream ofs_running; ofs_running.open("setup_cell.tmp"); - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; ucell->ntype = 2; delete[] ucell->magnet.start_magnetization; ucell->magnet.start_magnetization = new double[ucell->ntype]; diff --git a/source/module_cell/test_pw/unitcell_test_pw.cpp b/source/module_cell/test_pw/unitcell_test_pw.cpp index 44ccc876b5..4adf86b6ad 100644 --- a/source/module_cell/test_pw/unitcell_test_pw.cpp +++ b/source/module_cell/test_pw/unitcell_test_pw.cpp @@ -114,7 +114,7 @@ TEST_F(UcellTest,SetupCell) std::string fn = "./support/STRU_MgO"; std::ofstream ofs_running; ofs_running.open("setup_cell.tmp"); - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; ucell->ntype = 2; ucell->setup_cell(fn,ofs_running); ofs_running.close(); diff --git a/source/module_cell/unitcell.cpp b/source/module_cell/unitcell.cpp index bd36b66949..08c68aa259 100644 --- a/source/module_cell/unitcell.cpp +++ b/source/module_cell/unitcell.cpp @@ -142,7 +142,7 @@ void UnitCell::bcast_unitcell() { Parallel_Common::bcast_double(latvec_supercell.e33); Parallel_Common::bcast_double(magnet.start_magnetization, ntype); - if (GlobalV::NSPIN == 4) { + if (PARAM.inp.nspin == 4) { Parallel_Common::bcast_double(magnet.ux_[0]); Parallel_Common::bcast_double(magnet.ux_[1]); Parallel_Common::bcast_double(magnet.ux_[2]); @@ -595,7 +595,7 @@ void UnitCell::setup_cell(const std::string& fn, std::ofstream& log) { #endif // after read STRU, calculate initial total magnetization when NSPIN=2 - if (GlobalV::NSPIN == 2 && !GlobalV::TWO_EFERMI) { + if (PARAM.inp.nspin == 2 && !PARAM.globalv.two_fermi) { for (int it = 0; it < this->ntype; it++) { for (int ia = 0; ia < this->atoms[it].na; ia++) { GlobalV::nupdown += this->atoms[it].mag[ia]; @@ -683,7 +683,7 @@ void UnitCell::setup_cell(const std::string& fn, std::ofstream& log) { GlobalC::paw_cell.set_libpaw_files(); - GlobalC::paw_cell.set_nspin(GlobalV::NSPIN); + GlobalC::paw_cell.set_nspin(PARAM.inp.nspin); } #endif @@ -954,7 +954,7 @@ void UnitCell::cal_nwfc(std::ofstream& log) { for (int it = 0; it < ntype; it++) { atoms[it].stapos_wf = GlobalV::NLOCAL; const int nlocal_it = atoms[it].nw * atoms[it].na; - if (GlobalV::NSPIN != 4) { + if (PARAM.inp.nspin != 4) { GlobalV::NLOCAL += nlocal_it; } else { GlobalV::NLOCAL += nlocal_it * 2; // zhengdy-soc @@ -1124,7 +1124,7 @@ void UnitCell::cal_natomwfc(std::ofstream& log) { int tmp = 0; for (int l = 0; l < atoms[it].ncpp.nchi; l++) { if (atoms[it].ncpp.oc[l] >= 0) { - if (GlobalV::NSPIN == 4) { + if (PARAM.inp.nspin == 4) { if (atoms[it].ncpp.has_so) { tmp += 2 * atoms[it].ncpp.lchi[l]; if (fabs(atoms[it].ncpp.jchi[l] - atoms[it].ncpp.lchi[l] diff --git a/source/module_cell/unitcell.h b/source/module_cell/unitcell.h index e3069df38d..9a8e54ce3d 100644 --- a/source/module_cell/unitcell.h +++ b/source/module_cell/unitcell.h @@ -262,7 +262,7 @@ class UnitCell { * elsewhere. Print STRU file respect to given setting * * @param fn STRU file name - * @param nspin GlobalV::NSPIN feed in + * @param nspin PARAM.inp.nspin feed in * @param direct true for direct coords, false for cartesian coords * @param vol true for printing velocities * @param magmom true for printing Mulliken population analysis produced diff --git a/source/module_elecstate/elecstate.cpp b/source/module_elecstate/elecstate.cpp index b2e0efc4d1..720d920ed5 100644 --- a/source/module_elecstate/elecstate.cpp +++ b/source/module_elecstate/elecstate.cpp @@ -58,8 +58,8 @@ void ElecState::fixed_weights(const std::vector& ocp_kb, const int& nban void ElecState::init_nelec_spin() { - this->nelec_spin.resize(GlobalV::NSPIN); - if (GlobalV::NSPIN == 2) + this->nelec_spin.resize(PARAM.inp.nspin); + if (PARAM.inp.nspin == 2) { // in fact, when TWO_EFERMI(nupdown in INPUT is not 0.0), nelec_spin will be fixed. this->nelec_spin[0] = (GlobalV::nelec + GlobalV::nupdown) / 2.0; @@ -80,7 +80,7 @@ void ElecState::calculate_weights() if (!Occupy::use_gaussian_broadening && !Occupy::fixed_occupations) { - if (GlobalV::TWO_EFERMI) + if (PARAM.globalv.two_fermi) { Occupy::iweights(nks, this->klist->wk, @@ -118,7 +118,7 @@ void ElecState::calculate_weights() } else if (Occupy::use_gaussian_broadening) { - if (GlobalV::TWO_EFERMI) + if (PARAM.globalv.two_fermi) { double demet_up = 0.0; double demet_dw = 0.0; @@ -278,7 +278,7 @@ void ElecState::cal_nbands() if (GlobalV::NBANDS == 0) { - if (GlobalV::NSPIN == 1) + if (PARAM.inp.nspin == 1) { const int nbands1 = static_cast(occupied_bands) + 10; const int nbands2 = static_cast(1.2 * occupied_bands) + 1; @@ -287,7 +287,7 @@ void ElecState::cal_nbands() GlobalV::NBANDS = std::min(GlobalV::NBANDS, GlobalV::NLOCAL); } } - else if (GlobalV::NSPIN == 4) + else if (PARAM.inp.nspin == 4) { const int nbands3 = GlobalV::nelec + 20; const int nbands4 = static_cast(1.2 * GlobalV::nelec) + 1; @@ -296,7 +296,7 @@ void ElecState::cal_nbands() GlobalV::NBANDS = std::min(GlobalV::NBANDS, GlobalV::NLOCAL); } } - else if (GlobalV::NSPIN == 2) + else if (PARAM.inp.nspin == 2) { const double max_occ = std::max(this->nelec_spin[0], this->nelec_spin[1]); const int nbands3 = static_cast(max_occ) + 11; @@ -315,7 +315,7 @@ void ElecState::cal_nbands() if (GlobalV::NBANDS < occupied_bands) { ModuleBase::WARNING_QUIT("unitcell", "Too few bands!"); } - if (GlobalV::NSPIN == 2) + if (PARAM.inp.nspin == 2) { if (GlobalV::NBANDS < this->nelec_spin[0]) { diff --git a/source/module_elecstate/elecstate.h b/source/module_elecstate/elecstate.h index 20a72faae2..023b72b03a 100644 --- a/source/module_elecstate/elecstate.h +++ b/source/module_elecstate/elecstate.h @@ -1,5 +1,6 @@ #ifndef ELECSTATE_H #define ELECSTATE_H +#include "module_parameter/parameter.h" #include "fp_energy.h" #include "module_cell/klist.h" @@ -21,7 +22,7 @@ class ElecState this->charge = charge_in; this->charge->set_rhopw(rhopw_in); this->bigpw = bigpw_in; - this->eferm.two_efermi = GlobalV::TWO_EFERMI; + this->eferm.two_efermi = PARAM.globalv.two_fermi; } virtual ~ElecState() { diff --git a/source/module_elecstate/elecstate_energy.cpp b/source/module_elecstate/elecstate_energy.cpp index 06e5ebbed1..f29e986822 100644 --- a/source/module_elecstate/elecstate_energy.cpp +++ b/source/module_elecstate/elecstate_energy.cpp @@ -116,7 +116,7 @@ double ElecState::cal_delta_eband() const { deband_aux -= this->charge->rho[0][ir] * v_xc(0,ir); } - if (GlobalV::NSPIN == 2) + if (PARAM.inp.nspin == 2) { for (int ir = 0; ir < this->charge->rhopw->nrxx; ir++) { @@ -142,7 +142,7 @@ double ElecState::cal_delta_eband() const } } - if (GlobalV::NSPIN == 2) + if (PARAM.inp.nspin == 2) { v_eff = this->pot->get_effective_v(1); v_ofk = this->pot->get_effective_vofk(1); @@ -155,7 +155,7 @@ double ElecState::cal_delta_eband() const } } } - else if (GlobalV::NSPIN == 4) + else if (PARAM.inp.nspin == 4) { for (int is = 1; is < 4; is++) { @@ -211,7 +211,7 @@ double ElecState::cal_delta_escf() const } } - if (GlobalV::NSPIN == 2) + if (PARAM.inp.nspin == 2) { v_eff = this->pot->get_effective_v(1); if (get_xc_func_type() == 3 || get_xc_func_type() == 5) @@ -227,7 +227,7 @@ double ElecState::cal_delta_escf() const } } } - if (GlobalV::NSPIN == 4) + if (PARAM.inp.nspin == 4) { for (int is = 1; is < 4; is++) { diff --git a/source/module_elecstate/elecstate_lcao.cpp b/source/module_elecstate/elecstate_lcao.cpp index 6745a40dd2..b50c101abc 100644 --- a/source/module_elecstate/elecstate_lcao.cpp +++ b/source/module_elecstate/elecstate_lcao.cpp @@ -50,7 +50,7 @@ void ElecStateLCAO>::psiToRho(const psi::Psicharge->rho[is], this->charge->nrxx); // mohan 2009-11-10 @@ -67,7 +67,7 @@ void ElecStateLCAO>::psiToRho(const psi::Psicharge->kin_r[is], this->charge->nrxx); } @@ -105,7 +105,7 @@ void ElecStateLCAO::psiToRho(const psi::Psi& psi) ModuleBase::timer::tick("ElecStateLCAO", "cal_dm_2d"); } - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { ModuleBase::GlobalFunc::ZEROS(this->charge->rho[is], this->charge->nrxx); // mohan 2009-11-10 @@ -124,7 +124,7 @@ void ElecStateLCAO::psiToRho(const psi::Psi& psi) if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5) { - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { ModuleBase::GlobalFunc::ZEROS(this->charge->kin_r[is], this->charge->nrxx); } @@ -165,8 +165,8 @@ void ElecStateLCAO::dmToRho(std::vector pexsi_DM, std::vector::dmToRho(std::vector pexsi_DM, std::vectorcal_DMR(); - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { ModuleBase::GlobalFunc::ZEROS(this->charge->rho[is], this->charge->nrxx); // mohan 2009-11-10 @@ -191,7 +191,7 @@ void ElecStateLCAO::dmToRho(std::vector pexsi_DM, std::vectorgint_gamma->cal_gint(&inout); if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5) { - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { ModuleBase::GlobalFunc::ZEROS(this->charge->kin_r[0], this->charge->nrxx); } diff --git a/source/module_elecstate/elecstate_lcao_tddft.cpp b/source/module_elecstate/elecstate_lcao_tddft.cpp index cc47f2d182..ec145ca326 100644 --- a/source/module_elecstate/elecstate_lcao_tddft.cpp +++ b/source/module_elecstate/elecstate_lcao_tddft.cpp @@ -1,5 +1,6 @@ #include "elecstate_lcao_tddft.h" +#include "module_parameter/parameter.h" #include "cal_dm.h" #include "module_base/timer.h" #include "module_elecstate/module_dm/cal_dm_psi.h" @@ -29,7 +30,7 @@ void ElecStateLCAO_TDDFT::psiToRho_td(const psi::Psi>& psi) this->DM->cal_DMR(); } - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { ModuleBase::GlobalFunc::ZEROS(this->charge->rho[is], this->charge->nrxx); // mohan 2009-11-10 } diff --git a/source/module_elecstate/elecstate_print.cpp b/source/module_elecstate/elecstate_print.cpp index 7b35029e26..ab4fa47c4d 100644 --- a/source/module_elecstate/elecstate_print.cpp +++ b/source/module_elecstate/elecstate_print.cpp @@ -183,21 +183,21 @@ void ElecState::print_eigenvalue(std::ofstream& ofs) ofs << std::setiosflags(std::ios::showpoint); if (ik == 0) { - ofs << " NSPIN == " << GlobalV::NSPIN << std::endl; - if (GlobalV::NSPIN == 2) + ofs << " NSPIN == " << PARAM.inp.nspin << std::endl; + if (PARAM.inp.nspin == 2) { ofs << "SPIN UP : " << std::endl; } } else if (ik == this->klist->get_nks() / 2) { - if (GlobalV::NSPIN == 2) + if (PARAM.inp.nspin == 2) { ofs << "SPIN DOWN : " << std::endl; } } - if (GlobalV::NSPIN == 2) + if (PARAM.inp.nspin == 2) { if (this->klist->isk[ik] == 0) { @@ -386,7 +386,7 @@ void ElecState::print_etot(const bool converged, energies_Ry.push_back(this->f_en.etot_harris); } - if (GlobalV::TWO_EFERMI) + if (PARAM.globalv.two_fermi) { titles.push_back("E_Fermi_up"); energies_Ry.push_back(this->eferm.ef_up); @@ -400,7 +400,7 @@ void ElecState::print_etot(const bool converged, } if (PARAM.inp.out_bandgap) { - if (!GlobalV::TWO_EFERMI) + if (!PARAM.globalv.two_fermi) { titles.push_back("E_bandgap"); energies_Ry.push_back(this->bandgap); @@ -426,7 +426,7 @@ void ElecState::print_etot(const bool converged, if (PARAM.inp.out_level == "ie" || PARAM.inp.out_level == "m") // xiaohui add 'm' option, 2015-09-16 { std::vector mag; - switch (GlobalV::NSPIN) + switch (PARAM.inp.nspin) { case 2: mag = {get_ucell_tot_magnetization(), get_ucell_abs_magnetization()}; diff --git a/source/module_elecstate/elecstate_pw.cpp b/source/module_elecstate/elecstate_pw.cpp index 78c699f1f3..8fa5ee74b7 100644 --- a/source/module_elecstate/elecstate_pw.cpp +++ b/source/module_elecstate/elecstate_pw.cpp @@ -87,7 +87,7 @@ void ElecStatePW::psiToRho(const psi::Psi& psi) this->calEBand(); - for(int is=0; isrho[is], this->charge->nrxx); @@ -109,7 +109,7 @@ void ElecStatePW::psiToRho(const psi::Psi& psi) this->add_usrho(psi); } if (PARAM.globalv.device_flag == "gpu" || PARAM.inp.precision == "single") { - for (int ii = 0; ii < GlobalV::NSPIN; ii++) { + for (int ii = 0; ii < PARAM.inp.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) { @@ -151,7 +151,7 @@ void ElecStatePW::rhoBandK(const psi::Psi& psi) // wfcr.resize(this->basis->nmaxgr); // used for plane wavefunction FFT3D to real space, non-collinear spin case // static std::vector> wfcr_another_spin; - // if (GlobalV::NSPIN == 4) + // if (PARAM.inp.nspin == 4) // wfcr_another_spin.resize(this->charge->nrxx); if (!this->init_rho) { @@ -160,13 +160,13 @@ void ElecStatePW::rhoBandK(const psi::Psi& psi) int ik = psi.get_current_k(); int npw = psi.get_current_nbas(); int current_spin = 0; - if (GlobalV::NSPIN == 2) + if (PARAM.inp.nspin == 2) { current_spin = this->klist->isk[ik]; } int nbands = psi.get_nbands(); // here we compute the band energy: the sum of the eigenvalues - if (GlobalV::NSPIN == 4) + if (PARAM.inp.nspin == 4) { int npwx = npw / 2; for (int ibnd = 0; ibnd < nbands; ibnd++) @@ -254,8 +254,8 @@ void ElecStatePW::add_usrho(const psi::Psi& psi) T* becp = nullptr; resmem_complex_op()(this->ctx, becp, nbands * nkb, "ElecState::becp"); const int nh_tot = this->ppcell->nhm * (this->ppcell->nhm + 1) / 2; - resmem_var_op()(this->ctx, becsum, nh_tot * ucell->nat * GlobalV::NSPIN, "ElecState::becsum"); - setmem_var_op()(this->ctx, becsum, 0, nh_tot * ucell->nat * GlobalV::NSPIN); + resmem_var_op()(this->ctx, becsum, nh_tot * ucell->nat * PARAM.inp.nspin, "ElecState::becsum"); + setmem_var_op()(this->ctx, becsum, 0, nh_tot * ucell->nat * PARAM.inp.nspin); for (int ik = 0; ik < psi.get_nk(); ++ik) { @@ -399,9 +399,9 @@ void ElecStatePW::add_usrho(const psi::Psi& psi) // transform soft charge to recip space using smooth grids T* rhog = nullptr; - resmem_complex_op()(this->ctx, rhog, this->charge->rhopw->npw * GlobalV::NSPIN, "ElecState::rhog"); - setmem_complex_op()(this->ctx, rhog, 0, this->charge->rhopw->npw * GlobalV::NSPIN); - for (int is = 0; is < GlobalV::NSPIN; is++) + resmem_complex_op()(this->ctx, rhog, this->charge->rhopw->npw * PARAM.inp.nspin, "ElecState::rhog"); + setmem_complex_op()(this->ctx, rhog, 0, this->charge->rhopw->npw * PARAM.inp.nspin); + for (int is = 0; is < PARAM.inp.nspin; is++) { this->rhopw_smooth->real2recip(this->rho[is], &rhog[is * this->charge->rhopw->npw]); } @@ -411,7 +411,7 @@ void ElecStatePW::add_usrho(const psi::Psi& psi) this->addusdens_g(becsum, rhog); // transform back to real space using dense grids - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { this->charge->rhopw->recip2real(&rhog[is * this->charge->rhopw->npw], this->rho[is]); } @@ -456,11 +456,11 @@ void ElecStatePW::addusdens_g(const Real* becsum, T* rhog) T *skk = nullptr, *aux2 = nullptr, *tbecsum = nullptr; resmem_complex_op()(this->ctx, skk, atom->na * npw, "ElecState::skk"); resmem_complex_op()(this->ctx, aux2, nij * npw, "ElecState::aux2"); - resmem_complex_op()(this->ctx, tbecsum, GlobalV::NSPIN * atom->na * nij, "ElecState::tbecsum"); + resmem_complex_op()(this->ctx, tbecsum, PARAM.inp.nspin * atom->na * nij, "ElecState::tbecsum"); for (int ia = 0; ia < atom->na; ia++) { const int iat = ucell->itia2iat(it, ia); - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { for (int ij = 0; ij < nij; ij++) { @@ -475,7 +475,7 @@ void ElecStatePW::addusdens_g(const Real* becsum, T* rhog) } } - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { // sum over atoms char transa = 'N'; diff --git a/source/module_elecstate/elecstate_pw_sdft.cpp b/source/module_elecstate/elecstate_pw_sdft.cpp index 30f4a0312c..bb840b0cfc 100644 --- a/source/module_elecstate/elecstate_pw_sdft.cpp +++ b/source/module_elecstate/elecstate_pw_sdft.cpp @@ -1,5 +1,6 @@ #include "./elecstate_pw_sdft.h" #include "module_base/global_variable.h" +#include "module_parameter/parameter.h" #include "module_base/timer.h" #include "module_base/global_function.h" #include "module_hamilt_general/module_xc/xc_functional.h" @@ -9,7 +10,7 @@ namespace elecstate { ModuleBase::TITLE(this->classname, "psiToRho"); ModuleBase::timer::tick(this->classname, "psiToRho"); - for(int is=0; is < GlobalV::NSPIN; is++) + for(int is=0; is < PARAM.inp.nspin; is++) { ModuleBase::GlobalFunc::ZEROS(this->charge->rho[is], this->charge->nrxx); if (XC_Functional::get_func_type() == 3) @@ -22,7 +23,7 @@ namespace elecstate { this->calEBand(); - for(int is=0; ischarge->rho[is], this->charge->nrxx); } diff --git a/source/module_elecstate/magnetism.cpp b/source/module_elecstate/magnetism.cpp index 5d235f17b2..ee574de604 100644 --- a/source/module_elecstate/magnetism.cpp +++ b/source/module_elecstate/magnetism.cpp @@ -1,5 +1,6 @@ #include "magnetism.h" #include "elecstate_getters.h" +#include "module_parameter/parameter.h" #include "module_base/parallel_reduce.h" Magnetism::Magnetism() @@ -16,7 +17,7 @@ Magnetism::~Magnetism() void Magnetism::compute_magnetization(const int& nrxx, const int& nxyz, const double* const * rho, double* nelec_spin) { - if (GlobalV::NSPIN==2) + if (PARAM.inp.nspin==2) { this->tot_magnetization = 0.00; this->abs_magnetization = 0.00; @@ -39,7 +40,7 @@ void Magnetism::compute_magnetization(const int& nrxx, const int& nxyz, const do //update number of electrons for each spin //if TWO_EFERMI, no need to update - if(!GlobalV::TWO_EFERMI) + if(!PARAM.globalv.two_fermi) { nelec_spin[0] = (GlobalV::nelec + this->tot_magnetization) / 2; nelec_spin[1] = (GlobalV::nelec - this->tot_magnetization) / 2; @@ -49,7 +50,7 @@ void Magnetism::compute_magnetization(const int& nrxx, const int& nxyz, const do } // noncolliear : - else if(GlobalV::NSPIN==4) + else if(PARAM.inp.nspin==4) { for(int i=0;i<3;i++)this->tot_magnetization_nc[i] = 0.00; this->abs_magnetization = 0.00; diff --git a/source/module_elecstate/module_charge/charge.cpp b/source/module_elecstate/module_charge/charge.cpp index 78f653a762..f24d55e96d 100644 --- a/source/module_elecstate/module_charge/charge.cpp +++ b/source/module_elecstate/module_charge/charge.cpp @@ -60,7 +60,7 @@ void Charge::destroy() { if (allocate_rho || allocate_rho_final_scf) // LiuXh add 20180619 { - for (int i = 0; i < GlobalV::NSPIN; i++) + for (int i = 0; i < PARAM.inp.nspin; i++) { if(PARAM.inp.use_paw) { @@ -660,7 +660,7 @@ void Charge::atomic_rho(const int spin_number_need, ima = ima / (double)this->rhopw->nxyz * omega; sumrea = sumrea / (double)this->rhopw->nxyz * omega; - if (((neg < -1.0e-4) && (is == 0 || GlobalV::NSPIN == 2)) || ima > 1.0e-4) + if (((neg < -1.0e-4) && (is == 0 || PARAM.inp.nspin == 2)) || ima > 1.0e-4) { GlobalV::ofs_warning << " Warning: negative or imaginary starting charge : "; GlobalV::ofs_warning << " neg = " << neg << " ima = " << ima << " SPIN = " << is << std::endl; @@ -697,7 +697,7 @@ void Charge::atomic_rho(const int spin_number_need, void Charge::save_rho_before_sum_band() { - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { ModuleBase::GlobalFunc::DCOPY(rho[is], rho_save[is], this->rhopw->nrxx); if (elecstate::get_xc_func_type() == 3 || elecstate::get_xc_func_type() == 5) { @@ -770,16 +770,16 @@ void Charge::init_final_scf() assert(allocate_rho_final_scf == false); if (PARAM.inp.test_charge > 1) { - std::cout << "\n spin_number = " << GlobalV::NSPIN << " real_point_number = " << this->rhopw->nrxx << std::endl; + std::cout << "\n spin_number = " << PARAM.inp.nspin << " real_point_number = " << this->rhopw->nrxx << std::endl; } // allocate memory - rho = new double*[GlobalV::NSPIN]; - rhog = new std::complex*[GlobalV::NSPIN]; - rho_save = new double*[GlobalV::NSPIN]; - rhog_save = new std::complex*[GlobalV::NSPIN]; + rho = new double*[PARAM.inp.nspin]; + rhog = new std::complex*[PARAM.inp.nspin]; + rho_save = new double*[PARAM.inp.nspin]; + rhog_save = new std::complex*[PARAM.inp.nspin]; - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { rho[is] = new double[this->rhopw->nrxx]; rhog[is] = new std::complex[this->rhopw->npw]; @@ -791,10 +791,10 @@ void Charge::init_final_scf() ModuleBase::GlobalFunc::ZEROS(rhog_save[is], this->rhopw->npw); } - ModuleBase::Memory::record("Chg::rho", sizeof(double) * GlobalV::NSPIN * this->rhopw->nrxx); - ModuleBase::Memory::record("Chg::rho_save", sizeof(double) * GlobalV::NSPIN * this->rhopw->nrxx); - ModuleBase::Memory::record("Chg::rhog", sizeof(double) * GlobalV::NSPIN * this->rhopw->npw); - ModuleBase::Memory::record("Chg::rhog_save", sizeof(double) * GlobalV::NSPIN * this->rhopw->npw); + ModuleBase::Memory::record("Chg::rho", sizeof(double) * PARAM.inp.nspin * this->rhopw->nrxx); + ModuleBase::Memory::record("Chg::rho_save", sizeof(double) * PARAM.inp.nspin * this->rhopw->nrxx); + ModuleBase::Memory::record("Chg::rhog", sizeof(double) * PARAM.inp.nspin * this->rhopw->npw); + ModuleBase::Memory::record("Chg::rhog_save", sizeof(double) * PARAM.inp.nspin * this->rhopw->npw); this->rho_core = new double[this->rhopw->nrxx]; // core charge in real space ModuleBase::GlobalFunc::ZEROS(rho_core, this->rhopw->nrxx); diff --git a/source/module_elecstate/module_charge/charge_init.cpp b/source/module_elecstate/module_charge/charge_init.cpp index 4b1da55cb6..fea6955878 100644 --- a/source/module_elecstate/module_charge/charge_init.cpp +++ b/source/module_elecstate/module_charge/charge_init.cpp @@ -42,14 +42,14 @@ void Charge::init_rho(elecstate::efermi& eferm_iout, if (ModuleIO::read_rhog(binary.str(), rhopw, rhog)) { GlobalV::ofs_running << " Read in the charge density: " << binary.str() << std::endl; - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { rhopw->recip2real(rhog[is], rho[is]); } } else { - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { std::stringstream ssc; ssc << PARAM.globalv.global_readin_dir << "SPIN" << is + 1 << "_CHG.cube"; @@ -63,7 +63,7 @@ void Charge::init_rho(elecstate::efermi& eferm_iout, GlobalV::RANK_IN_STOGROUP, is, GlobalV::ofs_running, - GlobalV::NSPIN, + PARAM.inp.nspin, ssc.str(), this->rho[is], this->rhopw->nx, @@ -122,7 +122,7 @@ void Charge::init_rho(elecstate::efermi& eferm_iout, if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5) { - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { std::stringstream ssc; ssc << PARAM.globalv.global_readin_dir << "SPIN" << is + 1 << "_TAU.cube"; @@ -138,7 +138,7 @@ void Charge::init_rho(elecstate::efermi& eferm_iout, GlobalV::RANK_IN_STOGROUP, is, GlobalV::ofs_running, - GlobalV::NSPIN, + PARAM.inp.nspin, ssc.str(), this->kin_r[is], this->rhopw->nx, @@ -172,7 +172,7 @@ void Charge::init_rho(elecstate::efermi& eferm_iout, 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); + this->atomic_rho(PARAM.inp.nspin, GlobalC::ucell.omega, rho, strucFac, GlobalC::ucell); // liuyu 2023-06-29 : move here from atomic_rho(), which will be called several times in charge extrapolation // wenfei 2021-7-29 : initial tau = 3/5 rho^2/3, Thomas-Fermi @@ -180,11 +180,11 @@ void Charge::init_rho(elecstate::efermi& eferm_iout, { const double pi = 3.141592653589790; const double fact = (3.0 / 5.0) * pow(3.0 * pi * pi, 2.0 / 3.0); - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { for (int ir = 0; ir < this->rhopw->nrxx; ++ir) { - kin_r[is][ir] = fact * pow(std::abs(rho[is][ir]) * GlobalV::NSPIN, 5.0 / 3.0) / GlobalV::NSPIN; + kin_r[is][ir] = fact * pow(std::abs(rho[is][ir]) * PARAM.inp.nspin, 5.0 / 3.0) / PARAM.inp.nspin; } } } @@ -193,7 +193,7 @@ void Charge::init_rho(elecstate::efermi& eferm_iout, // Peize Lin add 2020.04.04 if (GlobalC::restart.info_load.load_charge && !GlobalC::restart.info_load.load_charge_finish) { - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { GlobalC::restart.load_disk("charge", is, this->nrxx, rho[is]); } diff --git a/source/module_elecstate/module_charge/charge_mixing.cpp b/source/module_elecstate/module_charge/charge_mixing.cpp index cf6e6df4d5..a139d5dfd1 100644 --- a/source/module_elecstate/module_charge/charge_mixing.cpp +++ b/source/module_elecstate/module_charge/charge_mixing.cpp @@ -48,7 +48,7 @@ void Charge_Mixing::set_mixing(const std::string& mixing_mode_in, { ModuleBase::WARNING_QUIT("Charge_Mixing", "You'd better set mixing_beta to [0.0, 1.0]!"); } - if (GlobalV::NSPIN >= 2 && this->mixing_beta_mag < 0.0) + if (PARAM.inp.nspin >= 2 && this->mixing_beta_mag < 0.0) { ModuleBase::WARNING_QUIT("Charge_Mixing", "You'd better set mixing_beta_mag >= 0.0!"); } @@ -64,7 +64,7 @@ void Charge_Mixing::set_mixing(const std::string& mixing_mode_in, GlobalV::ofs_running<<"mixing_beta: "<< this->mixing_beta <mixing_gg0 <mixing_beta_mag < 0 ) + if (PARAM.inp.nspin == 4 && PARAM.inp.mixing_angle > 0 ) { this->mixing->init_mixing_data(this->rho_mdata, this->rhopw->npw * 2, @@ -128,19 +128,19 @@ void Charge_Mixing::init_mixing() else { this->mixing->init_mixing_data(this->rho_mdata, - this->rhopw->npw * GlobalV::NSPIN, + this->rhopw->npw * PARAM.inp.nspin, sizeof(std::complex)); } } else { - if (GlobalV::NSPIN == 4 && PARAM.inp.mixing_angle > 0 ) + if (PARAM.inp.nspin == 4 && PARAM.inp.mixing_angle > 0 ) { this->mixing->init_mixing_data(this->rho_mdata, this->rhopw->nrxx * 2, sizeof(double)); } else { - this->mixing->init_mixing_data(this->rho_mdata, this->rhopw->nrxx * GlobalV::NSPIN, sizeof(double)); + this->mixing->init_mixing_data(this->rho_mdata, this->rhopw->nrxx * PARAM.inp.nspin, sizeof(double)); } } @@ -150,18 +150,18 @@ void Charge_Mixing::init_mixing() if (PARAM.inp.scf_thr_type == 1) { this->mixing->init_mixing_data(this->tau_mdata, - this->rhopw->npw * GlobalV::NSPIN, + this->rhopw->npw * PARAM.inp.nspin, sizeof(std::complex)); } else { - this->mixing->init_mixing_data(this->tau_mdata, this->rhopw->nrxx * GlobalV::NSPIN, sizeof(double)); + this->mixing->init_mixing_data(this->tau_mdata, this->rhopw->nrxx * PARAM.inp.nspin, sizeof(double)); } } // initailize nhat_mdata #ifdef USE_PAW - if(PARAM.inp.use_paw) { this->mixing->init_mixing_data(this->nhat_mdata, this->rhopw->nrxx * GlobalV::NSPIN, sizeof(double)); + if(PARAM.inp.use_paw) { this->mixing->init_mixing_data(this->nhat_mdata, this->rhopw->nrxx * PARAM.inp.nspin, sizeof(double)); } #endif @@ -178,7 +178,7 @@ void Charge_Mixing::allocate_mixing_dmr(int nnr) ModuleBase::TITLE("Charge_Mixing", "allocate_mixing_dmr"); ModuleBase::timer::tick("Charge_Mixing", "allocate_mixing_dmr"); // - const int dmr_nspin = (GlobalV::NSPIN == 2) ? 2 : 1; + const int dmr_nspin = (PARAM.inp.nspin == 2) ? 2 : 1; // allocate memory for dmr_mdata if (PARAM.inp.scf_thr_type == 1) { @@ -209,7 +209,7 @@ double Charge_Mixing::get_drho(Charge* chr, const double nelec) if (PARAM.inp.scf_thr_type == 1) { - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { ModuleBase::GlobalFunc::NOTE("Perform FFT on rho(r) to obtain rho(G)."); chr->rhopw->real2recip(chr->rho[is], chr->rhog[is]); @@ -219,11 +219,11 @@ double Charge_Mixing::get_drho(Charge* chr, const double nelec) } ModuleBase::GlobalFunc::NOTE("Calculate the charge difference between rho(G) and rho_save(G)"); - std::vector> drhog(GlobalV::NSPIN * this->rhopw->npw); + std::vector> drhog(PARAM.inp.nspin * this->rhopw->npw); #ifdef _OPENMP #pragma omp parallel for collapse(2) schedule(static, 512) #endif - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { for (int ig = 0; ig < this->rhopw->npw; ig++) { @@ -238,7 +238,7 @@ double Charge_Mixing::get_drho(Charge* chr, const double nelec) { // Note: Maybe it is wrong. // The inner_product_real function (L1-norm) is different from that (L2-norm) in mixing. - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { if (is != 0 && is != 3 && PARAM.globalv.domag_z) { @@ -277,7 +277,7 @@ double Charge_Mixing::get_dkin(Charge* chr, const double nelec) double dkin = 0.0; // Get dkin from kin_r and kin_r_save for PW and LCAO both, which is different from drho. - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { if (is != 0 && is != 3 && PARAM.globalv.domag_z) { @@ -327,7 +327,7 @@ void Charge_Mixing::mix_rho_recip(Charge* chr) = std::bind(&Charge_Mixing::inner_product_recip_hartree, this, std::placeholders::_1, std::placeholders::_2); // DIIS Mixing Only for smooth part, while high_frequency part is mixed by plain mixing method. - if (GlobalV::NSPIN == 1) + if (PARAM.inp.nspin == 1) { rhog_in = rhogs_in; rhog_out = rhogs_out; @@ -336,17 +336,17 @@ 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 == 2) + else if (PARAM.inp.nspin == 2) { // magnetic density std::complex *rhog_mag = nullptr; std::complex *rhog_mag_save = nullptr; const int npw = this->rhopw->npw; // allocate rhog_mag[is*ngmc] and rhog_mag_save[is*ngmc] - rhog_mag = new std::complex[npw * GlobalV::NSPIN]; - rhog_mag_save = new std::complex[npw * GlobalV::NSPIN]; - ModuleBase::GlobalFunc::ZEROS(rhog_mag, npw * GlobalV::NSPIN); - ModuleBase::GlobalFunc::ZEROS(rhog_mag_save, npw * GlobalV::NSPIN); + rhog_mag = new std::complex[npw * PARAM.inp.nspin]; + rhog_mag_save = new std::complex[npw * PARAM.inp.nspin]; + ModuleBase::GlobalFunc::ZEROS(rhog_mag, npw * PARAM.inp.nspin); + ModuleBase::GlobalFunc::ZEROS(rhog_mag_save, npw * PARAM.inp.nspin); // get rhog_mag[is*ngmc] and rhog_mag_save[is*ngmc] for (int ig = 0; ig < npw; ig++) { @@ -385,7 +385,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); // get rhog[is][ngmc] from rhog_mag[is*ngmc] - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { ModuleBase::GlobalFunc::ZEROS(chr->rhog[is], npw); } @@ -407,7 +407,7 @@ void Charge_Mixing::mix_rho_recip(Charge* chr) } } } - else if (GlobalV::NSPIN == 4 && PARAM.inp.mixing_angle <= 0) + else if (PARAM.inp.nspin == 4 && PARAM.inp.mixing_angle <= 0) { // normal broyden mixing for {rho, mx, my, mz} rhog_in = rhogs_in; @@ -436,7 +436,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 && PARAM.inp.mixing_angle > 0) + else if (PARAM.inp.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 @@ -523,7 +523,7 @@ void Charge_Mixing::mix_rho_recip(Charge* chr) if ( PARAM.globalv.double_grid) { // plain mixing for high_frequencies - const int ndimhf = (this->rhodpw->npw - this->rhopw->npw) * GlobalV::NSPIN; + const int ndimhf = (this->rhodpw->npw - this->rhopw->npw) * PARAM.inp.nspin; this->mixing_highf->plain_mix(rhoghf_out, rhoghf_in, rhoghf_out, ndimhf, nullptr); // combine smooth part and high_frequency part @@ -532,7 +532,7 @@ void Charge_Mixing::mix_rho_recip(Charge* chr) } // rhog to rho - if (GlobalV::NSPIN == 4 && PARAM.inp.mixing_angle > 0) + if (PARAM.inp.nspin == 4 && PARAM.inp.mixing_angle > 0) { // only tranfer rhog[0] // do not support double_grid, use rhopw directly @@ -540,7 +540,7 @@ void Charge_Mixing::mix_rho_recip(Charge* chr) } else { - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { // use rhodpw for double_grid // rhodpw is the same as rhopw for ! PARAM.globalv.double_grid @@ -551,10 +551,10 @@ void Charge_Mixing::mix_rho_recip(Charge* chr) // For kinetic energy density if ((XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5) && mixing_tau) { - std::vector> kin_g(GlobalV::NSPIN * rhodpw->npw); - std::vector> kin_g_save(GlobalV::NSPIN * rhodpw->npw); + std::vector> kin_g(PARAM.inp.nspin * rhodpw->npw); + std::vector> kin_g_save(PARAM.inp.nspin * rhodpw->npw); // FFT to get kin_g and kin_g_save - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { rhodpw->real2recip(chr->kin_r[is], &kin_g[is * rhodpw->npw]); rhodpw->real2recip(chr->kin_r_save[is], &kin_g_save[is * rhodpw->npw]); @@ -579,7 +579,7 @@ void Charge_Mixing::mix_rho_recip(Charge* chr) if ( PARAM.globalv.double_grid) { // simple mixing for high_frequencies - const int ndimhf = (this->rhodpw->npw - this->rhopw->npw) * GlobalV::NSPIN; + const int ndimhf = (this->rhodpw->npw - this->rhopw->npw) * PARAM.inp.nspin; this->mixing_highf->plain_mix(taughf_out, taughf_in, taughf_out, ndimhf, nullptr); // combine smooth part and high_frequency part @@ -588,7 +588,7 @@ void Charge_Mixing::mix_rho_recip(Charge* chr) } // kin_g to kin_r - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { rhodpw->recip2real(&kin_g[is * rhodpw->npw], chr->kin_r[is]); } @@ -615,7 +615,7 @@ void Charge_Mixing::mix_rho_real(Charge* chr) { double* rhor_in; double* rhor_out; - if (GlobalV::NSPIN == 1) + if (PARAM.inp.nspin == 1) { rhor_in = chr->rho_save[0]; rhor_out = chr->rho[0]; @@ -626,17 +626,17 @@ 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 == 2) + else if (PARAM.inp.nspin == 2) { // magnetic density double *rho_mag = nullptr; double *rho_mag_save = nullptr; const int nrxx = this->rhopw->nrxx; // allocate rho_mag[is*nnrx] and rho_mag_save[is*nnrx] - rho_mag = new double[nrxx * GlobalV::NSPIN]; - rho_mag_save = new double[nrxx * GlobalV::NSPIN]; - ModuleBase::GlobalFunc::ZEROS(rho_mag, nrxx * GlobalV::NSPIN); - ModuleBase::GlobalFunc::ZEROS(rho_mag_save, nrxx * GlobalV::NSPIN); + rho_mag = new double[nrxx * PARAM.inp.nspin]; + rho_mag_save = new double[nrxx * PARAM.inp.nspin]; + ModuleBase::GlobalFunc::ZEROS(rho_mag, nrxx * PARAM.inp.nspin); + ModuleBase::GlobalFunc::ZEROS(rho_mag_save, nrxx * PARAM.inp.nspin); // get rho_mag[is*nnrx] and rho_mag_save[is*nnrx] for (int ir = 0; ir < nrxx; ir++) { @@ -676,7 +676,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); // get new rho[is][nrxx] from rho_mag[is*nrxx] - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { ModuleBase::GlobalFunc::ZEROS(chr->rho[is], nrxx); //ModuleBase::GlobalFunc::ZEROS(rho_save[is], nrxx); @@ -690,7 +690,7 @@ void Charge_Mixing::mix_rho_real(Charge* chr) delete[] rho_mag; delete[] rho_mag_save; } - else if (GlobalV::NSPIN == 4 && PARAM.inp.mixing_angle <= 0) + else if (PARAM.inp.nspin == 4 && PARAM.inp.mixing_angle <= 0) { // normal broyden mixing for {rho, mx, my, mz} rhor_in = chr->rho_save[0]; @@ -721,7 +721,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 && PARAM.inp.mixing_angle > 0) + else if (PARAM.inp.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 @@ -807,27 +807,27 @@ void Charge_Mixing::mix_dmr(elecstate::DensityMatrix* DM) std::vector*> dmr = DM->get_DMR_vector(); std::vector>& dmr_save = DM->get_DMR_save(); // - //const int dmr_nspin = (GlobalV::NSPIN == 2) ? 2 : 1; + //const int dmr_nspin = (PARAM.inp.nspin == 2) ? 2 : 1; double* dmr_in; double* dmr_out; - if (GlobalV::NSPIN == 1 || GlobalV::NSPIN == 4) + if (PARAM.inp.nspin == 1 || PARAM.inp.nspin == 4) { dmr_in = dmr_save[0].data(); dmr_out = dmr[0]->get_wrapper(); this->mixing->push_data(this->dmr_mdata, dmr_in, dmr_out, nullptr, false); this->mixing->mix_data(this->dmr_mdata, dmr_out); } - else if (GlobalV::NSPIN == 2) + else if (PARAM.inp.nspin == 2) { // magnetic density matrix double* dmr_mag = nullptr; double* dmr_mag_save = nullptr; const int nnr = dmr[0]->get_nnr(); // allocate dmr_mag[is*nnrx] and dmr_mag_save[is*nnrx] - dmr_mag = new double[nnr * GlobalV::NSPIN]; - dmr_mag_save = new double[nnr * GlobalV::NSPIN]; - ModuleBase::GlobalFunc::ZEROS(dmr_mag, nnr * GlobalV::NSPIN); - ModuleBase::GlobalFunc::ZEROS(dmr_mag_save, nnr * GlobalV::NSPIN); + dmr_mag = new double[nnr * PARAM.inp.nspin]; + dmr_mag_save = new double[nnr * PARAM.inp.nspin]; + ModuleBase::GlobalFunc::ZEROS(dmr_mag, nnr * PARAM.inp.nspin); + ModuleBase::GlobalFunc::ZEROS(dmr_mag_save, nnr * PARAM.inp.nspin); double* dmr_up; double* dmr_down; // tranfer dmr into dmr_mag @@ -877,7 +877,7 @@ void Charge_Mixing::mix_dmr(elecstate::DensityMatrix* DM) // get new dmr from dmr_mag dmr_up = dmr[0]->get_wrapper(); dmr_down = dmr[1]->get_wrapper(); - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { ModuleBase::GlobalFunc::ZEROS(dmr_up, nnr); ModuleBase::GlobalFunc::ZEROS(dmr_down, nnr); @@ -906,27 +906,27 @@ void Charge_Mixing::mix_dmr(elecstate::DensityMatrix, doubl std::vector*> dmr = DM->get_DMR_vector(); std::vector>& dmr_save = DM->get_DMR_save(); // - //const int dmr_nspin = (GlobalV::NSPIN == 2) ? 2 : 1; + //const int dmr_nspin = (PARAM.inp.nspin == 2) ? 2 : 1; double* dmr_in; double* dmr_out; - if (GlobalV::NSPIN == 1 || GlobalV::NSPIN == 4) + if (PARAM.inp.nspin == 1 || PARAM.inp.nspin == 4) { dmr_in = dmr_save[0].data(); dmr_out = dmr[0]->get_wrapper(); this->mixing->push_data(this->dmr_mdata, dmr_in, dmr_out, nullptr, false); this->mixing->mix_data(this->dmr_mdata, dmr_out); } - else if (GlobalV::NSPIN == 2) + else if (PARAM.inp.nspin == 2) { // magnetic density matrix double* dmr_mag = nullptr; double* dmr_mag_save = nullptr; const int nnr = dmr[0]->get_nnr(); // allocate dmr_mag[is*nnrx] and dmr_mag_save[is*nnrx] - dmr_mag = new double[nnr * GlobalV::NSPIN]; - dmr_mag_save = new double[nnr * GlobalV::NSPIN]; - ModuleBase::GlobalFunc::ZEROS(dmr_mag, nnr * GlobalV::NSPIN); - ModuleBase::GlobalFunc::ZEROS(dmr_mag_save, nnr * GlobalV::NSPIN); + dmr_mag = new double[nnr * PARAM.inp.nspin]; + dmr_mag_save = new double[nnr * PARAM.inp.nspin]; + ModuleBase::GlobalFunc::ZEROS(dmr_mag, nnr * PARAM.inp.nspin); + ModuleBase::GlobalFunc::ZEROS(dmr_mag_save, nnr * PARAM.inp.nspin); double* dmr_up; double* dmr_down; // tranfer dmr into dmr_mag @@ -976,7 +976,7 @@ void Charge_Mixing::mix_dmr(elecstate::DensityMatrix, doubl // get new dmr from dmr_mag dmr_up = dmr[0]->get_wrapper(); dmr_down = dmr[1]->get_wrapper(); - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { ModuleBase::GlobalFunc::ZEROS(dmr_up, nnr); ModuleBase::GlobalFunc::ZEROS(dmr_down, nnr); @@ -1018,8 +1018,8 @@ void Charge_Mixing::mix_rho(Charge* chr) // the charge before mixing. const int nrxx = chr->rhopw->nrxx; - std::vector rho123(GlobalV::NSPIN * nrxx); - for (int is = 0; is < GlobalV::NSPIN; ++is) + std::vector rho123(PARAM.inp.nspin * nrxx); + for (int is = 0; is < PARAM.inp.nspin; ++is) { if (is == 0 || is == 3 || !PARAM.globalv.domag_z) { @@ -1036,8 +1036,8 @@ void Charge_Mixing::mix_rho(Charge* chr) std::vector kin_r123; if ((XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5) && mixing_tau) { - kin_r123.resize(GlobalV::NSPIN * nrxx); - for (int is = 0; is < GlobalV::NSPIN; ++is) + kin_r123.resize(PARAM.inp.nspin * nrxx); + for (int is = 0; is < PARAM.inp.nspin; ++is) { double* kin_r123_is = kin_r123.data() + is * nrxx; #ifdef _OPENMP @@ -1053,13 +1053,13 @@ void Charge_Mixing::mix_rho(Charge* chr) std::vector nhat_r123; if(PARAM.inp.use_paw) { - nhat_r123.resize(GlobalV::NSPIN * nrxx); + nhat_r123.resize(PARAM.inp.nspin * nrxx); #ifdef _OPENMP #pragma omp parallel for schedule(static, 512) #endif for(int ir = 0 ; ir < nrxx ; ++ir) { - for(int is = 0; is < GlobalV::NSPIN; ++is) + for(int is = 0; is < PARAM.inp.nspin; ++is) { nhat_r123[ir+is*nrxx] = chr->nhat[0][ir]; } @@ -1079,7 +1079,7 @@ void Charge_Mixing::mix_rho(Charge* chr) // mohan add 2012-06-05 // rho_save is the charge before mixing - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { if (is == 0 || is == 3 || !PARAM.globalv.domag_z) { @@ -1096,7 +1096,7 @@ void Charge_Mixing::mix_rho(Charge* chr) if ((XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5) && mixing_tau) { - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { double* kin_r123_is = kin_r123.data() + is * nrxx; #ifdef _OPENMP @@ -1117,7 +1117,7 @@ void Charge_Mixing::mix_rho(Charge* chr) #endif for(int ir = 0 ; ir < nrxx ; ++ir) { - for(int is = 0; is < GlobalV::NSPIN; ++is) + for(int is = 0; is < PARAM.inp.nspin; ++is) { chr->nhat_save[is][ir] = nhat_r123[ir+is*nrxx]; } @@ -1141,11 +1141,11 @@ void Charge_Mixing::Kerker_screen_recip(std::complex* drhog) // consider a resize for mixing_angle int resize_tmp = 1; - if (GlobalV::NSPIN == 4 && this->mixing_angle > 0) { resize_tmp = 2; + if (PARAM.inp.nspin == 4 && this->mixing_angle > 0) { resize_tmp = 2; } // implement Kerker for density and magnetization separately - for (int is = 0; is < GlobalV::NSPIN / resize_tmp; ++is) + for (int is = 0; is < PARAM.inp.nspin / resize_tmp; ++is) { // new mixing method only support nspin=2 not nspin=4 if (is >= 1) @@ -1155,7 +1155,7 @@ void Charge_Mixing::Kerker_screen_recip(std::complex* drhog) #ifdef __DEBUG assert(is == 1); // make sure break works #endif - double is_mag = GlobalV::NSPIN - 1; + double is_mag = PARAM.inp.nspin - 1; //for (int ig = 0; ig < this->rhopw->npw * is_mag; ig++) //{ // drhog[is * this->rhopw->npw + ig] *= 1; @@ -1192,12 +1192,12 @@ void Charge_Mixing::Kerker_screen_real(double* drhor) } // consider a resize for mixing_angle int resize_tmp = 1; - if (GlobalV::NSPIN == 4 && this->mixing_angle > 0) { resize_tmp = 2; + if (PARAM.inp.nspin == 4 && this->mixing_angle > 0) { resize_tmp = 2; } // - std::vector> drhog(this->rhopw->npw * GlobalV::NSPIN / resize_tmp); - std::vector drhor_filter(this->rhopw->nrxx * GlobalV::NSPIN / resize_tmp); - for (int is = 0; is < GlobalV::NSPIN / resize_tmp; ++is) + std::vector> drhog(this->rhopw->npw * PARAM.inp.nspin / resize_tmp); + std::vector drhor_filter(this->rhopw->nrxx * PARAM.inp.nspin / resize_tmp); + for (int is = 0; is < PARAM.inp.nspin / resize_tmp; ++is) { // Note after this process some G which is higher than Gmax will be filtered. // Thus we cannot use Kerker_screen_recip(drhog.data()) directly after it. @@ -1205,7 +1205,7 @@ void Charge_Mixing::Kerker_screen_real(double* drhor) } // implement Kerker for density and magnetization separately double fac, gg0, amin; - for (int is = 0; is < GlobalV::NSPIN / resize_tmp; is++) + for (int is = 0; is < PARAM.inp.nspin / resize_tmp; is++) { if (is >= 1) @@ -1215,8 +1215,8 @@ void Charge_Mixing::Kerker_screen_real(double* drhor) #ifdef __DEBUG assert(is == 1); // make sure break works #endif - double is_mag = GlobalV::NSPIN - 1; - if (GlobalV::NSPIN == 4 && this->mixing_angle > 0) { is_mag = 1; + double is_mag = PARAM.inp.nspin - 1; + if (PARAM.inp.nspin == 4 && this->mixing_angle > 0) { is_mag = 1; } for (int ig = 0; ig < this->rhopw->npw * is_mag; ig++) { @@ -1251,7 +1251,7 @@ void Charge_Mixing::Kerker_screen_real(double* drhor) } } // inverse FT - for (int is = 0; is < GlobalV::NSPIN / resize_tmp; ++is) + for (int is = 0; is < PARAM.inp.nspin / resize_tmp; ++is) { this->rhopw->recip2real(drhog.data() + is * this->rhopw->npw, drhor_filter.data() + is * this->rhopw->nrxx); } @@ -1259,7 +1259,7 @@ void Charge_Mixing::Kerker_screen_real(double* drhor) #ifdef _OPENMP #pragma omp parallel for schedule(static, 512) #endif - for (int ir = 0; ir < this->rhopw->nrxx * GlobalV::NSPIN / resize_tmp; ir++) + for (int ir = 0; ir < this->rhopw->nrxx * PARAM.inp.nspin / resize_tmp; ir++) { drhor[ir] -= drhor_filter[ir]; } @@ -1270,9 +1270,9 @@ double Charge_Mixing::inner_product_recip_rho(std::complex* rho1, std::c ModuleBase::TITLE("Charge_Mixing", "inner_product_recip_rho"); ModuleBase::timer::tick("Charge_Mixing", "inner_product_recip_rho"); - std::complex** rhog1 = new std::complex*[GlobalV::NSPIN]; - std::complex** rhog2 = new std::complex*[GlobalV::NSPIN]; - for (int is = 0; is < GlobalV::NSPIN; is++) + std::complex** rhog1 = new std::complex*[PARAM.inp.nspin]; + std::complex** rhog2 = new std::complex*[PARAM.inp.nspin]; + for (int is = 0; is < PARAM.inp.nspin; is++) { rhog1[is] = rho1 + is * this->rhopw->npw; rhog2[is] = rho2 + is * this->rhopw->npw; @@ -1300,7 +1300,7 @@ double Charge_Mixing::inner_product_recip_rho(std::complex* rho1, std::c return sum; }; - switch (GlobalV::NSPIN) + switch (PARAM.inp.nspin) { case 1: sum += part_of_noncolin(); @@ -1418,12 +1418,12 @@ double Charge_Mixing::inner_product_recip_simple(std::complex* rho1, std double rnorm = 0.0; // consider a resize for mixing_angle int resize_tmp = 1; - if (GlobalV::NSPIN == 4 && this->mixing_angle > 0) { resize_tmp = 2; + if (PARAM.inp.nspin == 4 && this->mixing_angle > 0) { resize_tmp = 2; } #ifdef _OPENMP #pragma omp parallel for reduction(+ : rnorm) #endif - for (int ig = 0; ig < this->rhopw->npw * GlobalV::NSPIN / resize_tmp; ++ig) + for (int ig = 0; ig < this->rhopw->npw * PARAM.inp.nspin / resize_tmp; ++ig) { rnorm += (conj(rho1[ig]) * rho2[ig]).real(); } @@ -1466,11 +1466,11 @@ double Charge_Mixing::inner_product_recip_hartree(std::complex* rhog1, s return sum; }; - if (GlobalV::NSPIN==1) + if (PARAM.inp.nspin==1) { sum += part_of_rho(); } - else if (GlobalV::NSPIN==2) + else if (PARAM.inp.nspin==2) { // charge density part #ifdef _OPENMP @@ -1514,7 +1514,7 @@ double Charge_Mixing::inner_product_recip_hartree(std::complex* rhog1, s sum2 += mag; sum += sum2; } - else if (GlobalV::NSPIN==4) + else if (PARAM.inp.nspin==4) { if (!PARAM.globalv.domag && !PARAM.globalv.domag_z) { @@ -1613,13 +1613,13 @@ double Charge_Mixing::inner_product_real(double* rho1, double* rho2) double rnorm = 0.0; // consider a resize for mixing_angle int resize_tmp = 1; - if (GlobalV::NSPIN == 4 && this->mixing_angle > 0) { resize_tmp = 2; + if (PARAM.inp.nspin == 4 && this->mixing_angle > 0) { resize_tmp = 2; } #ifdef _OPENMP #pragma omp parallel for reduction(+ : rnorm) #endif - for (int ir = 0; ir < this->rhopw->nrxx * GlobalV::NSPIN / resize_tmp; ++ir) + for (int ir = 0; ir < this->rhopw->nrxx * PARAM.inp.nspin / resize_tmp; ++ir) { rnorm += rho1[ir] * rho2[ir]; } @@ -1634,7 +1634,7 @@ void Charge_Mixing::divide_data(std::complex* data_d, std::complex*& data_hf) { ModuleBase::TITLE("Charge_Mixing", "divide_data"); - if (GlobalV::NSPIN == 1) + if (PARAM.inp.nspin == 1) { data_s = data_d; data_hf = data_d + this->rhopw->npw; @@ -1644,13 +1644,13 @@ void Charge_Mixing::divide_data(std::complex* data_d, const int ndimd = this->rhodpw->npw; const int ndims = this->rhopw->npw; const int ndimhf = ndimd - ndims; - data_s = new std::complex[GlobalV::NSPIN * ndims]; + data_s = new std::complex[PARAM.inp.nspin * ndims]; data_hf = nullptr; if (ndimhf > 0) { - data_hf = new std::complex[GlobalV::NSPIN * ndimhf]; + data_hf = new std::complex[PARAM.inp.nspin * ndimhf]; } - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { std::memcpy(data_s + is * ndims, data_d + is * ndimd, ndims * sizeof(std::complex)); std::memcpy(data_hf + is * ndimhf, data_d + is * ndimd + ndims, ndimhf * sizeof(std::complex)); @@ -1662,7 +1662,7 @@ void Charge_Mixing::combine_data(std::complex* data_d, std::complex*& data_hf) { ModuleBase::TITLE("Charge_Mixing", "combine_data"); - if (GlobalV::NSPIN == 1) + if (PARAM.inp.nspin == 1) { data_s = nullptr; data_hf = nullptr; @@ -1673,7 +1673,7 @@ void Charge_Mixing::combine_data(std::complex* data_d, const int ndimd = this->rhodpw->npw; const int ndims = this->rhopw->npw; const int ndimhf = ndimd - ndims; - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { std::memcpy(data_d + is * ndimd, data_s + is * ndims, ndims * sizeof(std::complex)); std::memcpy(data_d + is * ndimd + ndims, data_hf + is * ndimhf, ndimhf * sizeof(std::complex)); @@ -1688,7 +1688,7 @@ void Charge_Mixing::combine_data(std::complex* data_d, void Charge_Mixing::clean_data(std::complex*& data_s, std::complex*& data_hf) { ModuleBase::TITLE("Charge_Mixing", "clean_data"); - if (GlobalV::NSPIN == 1) + if (PARAM.inp.nspin == 1) { data_s = nullptr; data_hf = nullptr; diff --git a/source/module_elecstate/module_charge/charge_mpi.cpp b/source/module_elecstate/module_charge/charge_mpi.cpp index ee26d5e7b0..70aae3d9b2 100644 --- a/source/module_elecstate/module_charge/charge_mpi.cpp +++ b/source/module_elecstate/module_charge/charge_mpi.cpp @@ -129,7 +129,7 @@ void Charge::rho_mpi() } ModuleBase::timer::tick("Charge", "rho_mpi"); - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { reduce_diff_pools(this->rho[is]); if (elecstate::get_xc_func_type() == 3 || elecstate::get_xc_func_type() == 5) diff --git a/source/module_elecstate/module_dm/density_matrix.cpp b/source/module_elecstate/module_dm/density_matrix.cpp index aff61c9fda..22152bb093 100644 --- a/source/module_elecstate/module_dm/density_matrix.cpp +++ b/source/module_elecstate/module_dm/density_matrix.cpp @@ -1,5 +1,6 @@ #include "density_matrix.h" +#include "module_parameter/parameter.h" #include "module_base/libm/libm.h" #include "module_base/memory.h" #include "module_base/timer.h" @@ -507,7 +508,7 @@ void DensityMatrix, double>::cal_DMR() } #endif // loop over k-points - if (GlobalV::NSPIN != 4) + if (PARAM.inp.nspin != 4) { for (int ik = 0; ik < this->_nks; ++ik) { @@ -550,7 +551,7 @@ void DensityMatrix, double>::cal_DMR() } // treat DMR as pauli matrix when NSPIN=4 - if (GlobalV::NSPIN == 4) + if (PARAM.inp.nspin == 4) { std::vector> tmp_DMR(this->_paraV->get_col_size() * this->_paraV->get_row_size(), @@ -672,7 +673,7 @@ void DensityMatrix, double>::cal_DMR(const int ik) } #endif // Remove loop over k-points and directly use the provided ik - if (GlobalV::NSPIN != 4) + if (PARAM.inp.nspin != 4) { // cal k_phase // if TK==std::complex, kphase is e^{ikR} diff --git a/source/module_elecstate/occupy.cpp b/source/module_elecstate/occupy.cpp index 26a68122fa..508b72f261 100644 --- a/source/module_elecstate/occupy.cpp +++ b/source/module_elecstate/occupy.cpp @@ -1,5 +1,6 @@ #include "occupy.h" +#include "module_parameter/parameter.h" #include "module_base/constants.h" #include "module_base/mymath.h" #include "module_base/parallel_reduce.h" @@ -141,7 +142,7 @@ void Occupy::iweights( { assert(is < 2); double degspin = 2.0; - if (GlobalV::NSPIN == 4) + if (PARAM.inp.nspin == 4) degspin = 1.0; if (is != -1) degspin = 1.0; @@ -159,7 +160,7 @@ void Occupy::iweights( for (int ik = 0; ik < nks; ++ik) { // when NSPIN=2, only calculate spin up or spin down with TWO_FERMI mode(nupdown != 0) - if (GlobalV::NSPIN == 2 && isk[ik] != is && is != -1) + if (PARAM.inp.nspin == 2 && isk[ik] != is && is != -1) { continue; } diff --git a/source/module_elecstate/potentials/efield.h b/source/module_elecstate/potentials/efield.h index 12d9b37095..79a4860b03 100644 --- a/source/module_elecstate/potentials/efield.h +++ b/source/module_elecstate/potentials/efield.h @@ -76,10 +76,10 @@ class PotEfield : public PotBase void cal_fixed_v(double *vl_pseudo) override { - ModuleBase::matrix v_efield(GlobalV::NSPIN, rho_basis_->nrxx); + ModuleBase::matrix v_efield(PARAM.inp.nspin, rho_basis_->nrxx); v_efield = Efield::add_efield(*ucell_, const_cast(rho_basis_), - GlobalV::NSPIN, + PARAM.inp.nspin, nullptr, GlobalC::solvent_model); for (int ir = 0; ir < rho_basis_->nrxx; ++ir) diff --git a/source/module_elecstate/potentials/potential_new.cpp b/source/module_elecstate/potentials/potential_new.cpp index 6c6270b24e..acf402425f 100644 --- a/source/module_elecstate/potentials/potential_new.cpp +++ b/source/module_elecstate/potentials/potential_new.cpp @@ -109,40 +109,40 @@ void Potential::allocate() this->v_effective_fixed.resize(nrxx); ModuleBase::Memory::record("Pot::veff_fix", sizeof(double) * nrxx); - this->v_effective.create(GlobalV::NSPIN, nrxx); - ModuleBase::Memory::record("Pot::veff", sizeof(double) * GlobalV::NSPIN * nrxx); + this->v_effective.create(PARAM.inp.nspin, nrxx); + ModuleBase::Memory::record("Pot::veff", sizeof(double) * PARAM.inp.nspin * nrxx); - this->veff_smooth.create(GlobalV::NSPIN, nrxx_smooth); - ModuleBase::Memory::record("Pot::veff_smooth", sizeof(double) * GlobalV::NSPIN * nrxx_smooth); + this->veff_smooth.create(PARAM.inp.nspin, nrxx_smooth); + ModuleBase::Memory::record("Pot::veff_smooth", sizeof(double) * PARAM.inp.nspin * nrxx_smooth); if(PARAM.inp.use_paw) { - this->v_xc.create(GlobalV::NSPIN, nrxx); - ModuleBase::Memory::record("Pot::vxc", sizeof(double) * GlobalV::NSPIN * nrxx); + this->v_xc.create(PARAM.inp.nspin, nrxx); + ModuleBase::Memory::record("Pot::vxc", sizeof(double) * PARAM.inp.nspin * nrxx); } if (elecstate::get_xc_func_type() == 3 || elecstate::get_xc_func_type() == 5) { - this->vofk_effective.create(GlobalV::NSPIN, nrxx); - ModuleBase::Memory::record("Pot::vofk", sizeof(double) * GlobalV::NSPIN * nrxx); + this->vofk_effective.create(PARAM.inp.nspin, nrxx); + ModuleBase::Memory::record("Pot::vofk", sizeof(double) * PARAM.inp.nspin * nrxx); - this->vofk_smooth.create(GlobalV::NSPIN, nrxx_smooth); - ModuleBase::Memory::record("Pot::vofk_smooth", sizeof(double) * GlobalV::NSPIN * nrxx_smooth); + this->vofk_smooth.create(PARAM.inp.nspin, nrxx_smooth); + ModuleBase::Memory::record("Pot::vofk_smooth", sizeof(double) * PARAM.inp.nspin * nrxx_smooth); } if (PARAM.globalv.device_flag == "gpu") { if (PARAM.inp.precision == "single") { - resmem_sd_op()(gpu_ctx, s_veff_smooth, GlobalV::NSPIN * nrxx_smooth); - resmem_sd_op()(gpu_ctx, s_vofk_smooth, GlobalV::NSPIN * nrxx_smooth); + resmem_sd_op()(gpu_ctx, s_veff_smooth, PARAM.inp.nspin * nrxx_smooth); + resmem_sd_op()(gpu_ctx, s_vofk_smooth, PARAM.inp.nspin * nrxx_smooth); } else { - resmem_dd_op()(gpu_ctx, d_veff_smooth, GlobalV::NSPIN * nrxx_smooth); - resmem_dd_op()(gpu_ctx, d_vofk_smooth, GlobalV::NSPIN * nrxx_smooth); + resmem_dd_op()(gpu_ctx, d_veff_smooth, PARAM.inp.nspin * nrxx_smooth); + resmem_dd_op()(gpu_ctx, d_vofk_smooth, PARAM.inp.nspin * nrxx_smooth); } } else { if (PARAM.inp.precision == "single") { - resmem_sh_op()(cpu_ctx, s_veff_smooth, GlobalV::NSPIN * nrxx_smooth, "POT::sveff_smooth"); - resmem_sh_op()(cpu_ctx, s_vofk_smooth, GlobalV::NSPIN * nrxx_smooth, "POT::svofk_smooth"); + resmem_sh_op()(cpu_ctx, s_veff_smooth, PARAM.inp.nspin * nrxx_smooth, "POT::sveff_smooth"); + resmem_sh_op()(cpu_ctx, s_vofk_smooth, PARAM.inp.nspin * nrxx_smooth, "POT::svofk_smooth"); } else { this->d_veff_smooth = this->veff_smooth.c; @@ -323,8 +323,8 @@ void Potential::interpolate_vrs() ModuleBase::WARNING_QUIT("Potential::interpolate_vrs", "gamma_only is not consistent"); } - ModuleBase::ComplexMatrix vrs(GlobalV::NSPIN, rho_basis_->npw); - for (int is = 0; is < GlobalV::NSPIN; is++) + ModuleBase::ComplexMatrix vrs(PARAM.inp.nspin, rho_basis_->npw); + for (int is = 0; is < PARAM.inp.nspin; is++) { rho_basis_->real2recip(&v_effective(is, 0), &vrs(is, 0)); rho_basis_smooth_->recip2real(&vrs(is, 0), &veff_smooth(is, 0)); @@ -332,8 +332,8 @@ void Potential::interpolate_vrs() if (elecstate::get_xc_func_type() == 3 || elecstate::get_xc_func_type() == 5) { - ModuleBase::ComplexMatrix vrs_ofk(GlobalV::NSPIN, rho_basis_->npw); - for (int is = 0; is < GlobalV::NSPIN; is++) + ModuleBase::ComplexMatrix vrs_ofk(PARAM.inp.nspin, rho_basis_->npw); + for (int is = 0; is < PARAM.inp.nspin; is++) { rho_basis_->real2recip(&vofk_effective(is, 0), &vrs_ofk(is, 0)); rho_basis_smooth_->recip2real(&vrs_ofk(is, 0), &vofk_smooth(is, 0)); diff --git a/source/module_elecstate/test/charge_extra_test.cpp b/source/module_elecstate/test/charge_extra_test.cpp index 898a0ddf13..fadacdb327 100644 --- a/source/module_elecstate/test/charge_extra_test.cpp +++ b/source/module_elecstate/test/charge_extra_test.cpp @@ -122,7 +122,7 @@ class ChargeExtraTest : public ::testing::Test Structure_Factor sf; void SetUp() override { - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; PARAM.sys.global_out_dir = "./support/"; ucell = utp.SetUcellInfo(); ucell->omega = 1.0; @@ -136,7 +136,7 @@ TEST_F(ChargeExtraTest, InitCEWarningQuit) { PARAM.input.chg_extrap = "wwww"; testing::internal::CaptureStdout(); - EXPECT_EXIT(CE.Init_CE(GlobalV::NSPIN, ucell->nat, charge.rhopw->nrxx, PARAM.input.chg_extrap), + EXPECT_EXIT(CE.Init_CE(PARAM.input.nspin, ucell->nat, charge.rhopw->nrxx, PARAM.input.chg_extrap), ::testing::ExitedWithCode(0), ""); std::string output = testing::internal::GetCapturedStdout(); @@ -146,21 +146,21 @@ TEST_F(ChargeExtraTest, InitCEWarningQuit) TEST_F(ChargeExtraTest, InitCECase1) { PARAM.input.chg_extrap = "none"; - CE.Init_CE(GlobalV::NSPIN, ucell->nat, charge.rhopw->nrxx, PARAM.input.chg_extrap); + CE.Init_CE(PARAM.input.nspin, ucell->nat, charge.rhopw->nrxx, PARAM.input.chg_extrap); EXPECT_EQ(CE.pot_order, 0); } TEST_F(ChargeExtraTest, InitCECase2) { PARAM.input.chg_extrap = "atomic"; - CE.Init_CE(GlobalV::NSPIN, ucell->nat, charge.rhopw->nrxx, PARAM.input.chg_extrap); + CE.Init_CE(PARAM.input.nspin, ucell->nat, charge.rhopw->nrxx, PARAM.input.chg_extrap); EXPECT_EQ(CE.pot_order, 1); } TEST_F(ChargeExtraTest, InitCECase3) { PARAM.input.chg_extrap = "first-order"; - CE.Init_CE(GlobalV::NSPIN, ucell->nat, charge.rhopw->nrxx, PARAM.input.chg_extrap); + CE.Init_CE(PARAM.input.nspin, ucell->nat, charge.rhopw->nrxx, PARAM.input.chg_extrap); EXPECT_EQ(CE.pot_order, 2); EXPECT_NE(CE.delta_rho1.size(), 0); EXPECT_NE(CE.delta_rho2.size(), 0); @@ -169,7 +169,7 @@ TEST_F(ChargeExtraTest, InitCECase3) TEST_F(ChargeExtraTest, InitCECase4) { PARAM.input.chg_extrap = "second-order"; - CE.Init_CE(GlobalV::NSPIN, ucell->nat, charge.rhopw->nrxx, PARAM.input.chg_extrap); + CE.Init_CE(PARAM.input.nspin, ucell->nat, charge.rhopw->nrxx, PARAM.input.chg_extrap); EXPECT_EQ(CE.pot_order, 3); EXPECT_DOUBLE_EQ(CE.alpha, 1.0); EXPECT_DOUBLE_EQ(CE.beta, 0.0); @@ -183,7 +183,7 @@ TEST_F(ChargeExtraTest, InitCECase4) TEST_F(ChargeExtraTest, ExtrapolateChargeCase1) { PARAM.input.chg_extrap = "second-order"; - CE.Init_CE(GlobalV::NSPIN, ucell->nat, charge.rhopw->nrxx, PARAM.input.chg_extrap); + CE.Init_CE(PARAM.input.nspin, ucell->nat, charge.rhopw->nrxx, PARAM.input.chg_extrap); CE.istep = 0; CE.pot_order = 3; @@ -205,7 +205,7 @@ TEST_F(ChargeExtraTest, ExtrapolateChargeCase1) TEST_F(ChargeExtraTest, ExtrapolateChargeCase2) { PARAM.input.chg_extrap = "second-order"; - CE.Init_CE(GlobalV::NSPIN, ucell->nat, charge.rhopw->nrxx, PARAM.input.chg_extrap); + CE.Init_CE(PARAM.input.nspin, ucell->nat, charge.rhopw->nrxx, PARAM.input.chg_extrap); CE.istep = 1; CE.pot_order = 3; @@ -227,7 +227,7 @@ TEST_F(ChargeExtraTest, ExtrapolateChargeCase2) TEST_F(ChargeExtraTest, ExtrapolateChargeCase3) { PARAM.input.chg_extrap = "second-order"; - CE.Init_CE(GlobalV::NSPIN, ucell->nat, charge.rhopw->nrxx, PARAM.input.chg_extrap); + CE.Init_CE(PARAM.input.nspin, ucell->nat, charge.rhopw->nrxx, PARAM.input.chg_extrap); CE.istep = 2; CE.pot_order = 3; @@ -249,7 +249,7 @@ TEST_F(ChargeExtraTest, ExtrapolateChargeCase3) TEST_F(ChargeExtraTest, ExtrapolateChargeCase4) { PARAM.input.chg_extrap = "second-order"; - CE.Init_CE(GlobalV::NSPIN, ucell->nat, charge.rhopw->nrxx, PARAM.input.chg_extrap); + CE.Init_CE(PARAM.input.nspin, ucell->nat, charge.rhopw->nrxx, PARAM.input.chg_extrap); CE.istep = 3; GlobalV::ofs_running.open("log"); @@ -271,7 +271,7 @@ TEST_F(ChargeExtraTest, ExtrapolateChargeCase4) TEST_F(ChargeExtraTest, UpdateAllDis) { PARAM.input.chg_extrap = "second-order"; - CE.Init_CE(GlobalV::NSPIN, ucell->nat, charge.rhopw->nrxx, PARAM.input.chg_extrap); + CE.Init_CE(PARAM.input.nspin, ucell->nat, charge.rhopw->nrxx, PARAM.input.chg_extrap); CE.istep = 3; for (int i = 0; i < ucell->nat; ++i) { @@ -293,7 +293,7 @@ TEST_F(ChargeExtraTest, UpdateAllDis) TEST_F(ChargeExtraTest, FindAlphaAndBeta) { PARAM.input.chg_extrap = "second-order"; - CE.Init_CE(GlobalV::NSPIN, ucell->nat, charge.rhopw->nrxx, PARAM.input.chg_extrap); + CE.Init_CE(PARAM.input.nspin, ucell->nat, charge.rhopw->nrxx, PARAM.input.chg_extrap); CE.istep = 3; for (int i = 0; i < ucell->nat; ++i) { diff --git a/source/module_elecstate/test/charge_mixing_test.cpp b/source/module_elecstate/test/charge_mixing_test.cpp index 210cf922c8..da199d8d10 100644 --- a/source/module_elecstate/test/charge_mixing_test.cpp +++ b/source/module_elecstate/test/charge_mixing_test.cpp @@ -117,7 +117,7 @@ class ChargeMixingTest : public ::testing::Test TEST_F(ChargeMixingTest, SetMixingTest) { omp_set_num_threads(1); - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; Charge_Mixing CMtest; CMtest.set_rhopw(&pw_basis, &pw_basis); PARAM.input.mixing_beta = 1.0; @@ -178,7 +178,7 @@ TEST_F(ChargeMixingTest, SetMixingTest) PARAM.input.mixing_beta = 0.7; PARAM.input.mixing_beta_mag = -0.1; - GlobalV::NSPIN = 2; + PARAM.input.nspin = 2; testing::internal::CaptureStdout(); EXPECT_EXIT(CMtest.set_mixing(PARAM.input.mixing_mode, PARAM.input.mixing_beta, @@ -193,7 +193,7 @@ TEST_F(ChargeMixingTest, SetMixingTest) output = testing::internal::GetCapturedStdout(); EXPECT_THAT(output, testing::HasSubstr("You'd better set mixing_beta_mag >= 0.0!")); - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; PARAM.input.mixing_beta = 0.7; PARAM.input.mixing_beta_mag = 1.6; PARAM.input.mixing_mode = "nothing"; @@ -215,7 +215,7 @@ TEST_F(ChargeMixingTest, SetMixingTest) TEST_F(ChargeMixingTest, InitMixingTest) { omp_set_num_threads(1); - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; FUNC_TYPE = 1; Charge_Mixing CMtest; CMtest.set_rhopw(&pw_basis, &pw_basis); @@ -239,11 +239,11 @@ TEST_F(ChargeMixingTest, InitMixingTest) CMtest.init_mixing(); EXPECT_EQ(CMtest.rho_mdata.length, pw_basis.nrxx); - GlobalV::NSPIN = 4; + PARAM.input.nspin = 4; CMtest.init_mixing(); EXPECT_EQ(CMtest.rho_mdata.length, 4 * pw_basis.nrxx); - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; PARAM.input.mixing_tau = true; CMtest.set_mixing(PARAM.input.mixing_mode, PARAM.input.mixing_beta, @@ -259,7 +259,7 @@ TEST_F(ChargeMixingTest, InitMixingTest) CMtest.init_mixing(); EXPECT_EQ(CMtest.tau_mdata.length, pw_basis.nrxx); - GlobalV::NSPIN = 4; + PARAM.input.nspin = 4; PARAM.input.mixing_angle = 1.0; CMtest.set_mixing(PARAM.input.mixing_mode, PARAM.input.mixing_beta, @@ -290,18 +290,18 @@ TEST_F(ChargeMixingTest, InnerDotRealTest) PARAM.input.mixing_angle, PARAM.input.mixing_dmr); CMtest.set_rhopw(&pw_basis, &pw_basis); - GlobalV::NSPIN = 4; + PARAM.input.nspin = 4; // a simple sum for inner product - std::vector drho1(pw_basis.nrxx * GlobalV::NSPIN); - std::vector drho2(pw_basis.nrxx * GlobalV::NSPIN); - for (int i = 0; i < pw_basis.nrxx * GlobalV::NSPIN; ++i) + std::vector drho1(pw_basis.nrxx * PARAM.input.nspin); + std::vector drho2(pw_basis.nrxx * PARAM.input.nspin); + for (int i = 0; i < pw_basis.nrxx * PARAM.input.nspin; ++i) { drho1[i] = 1.0; drho2[i] = double(i); } double inner = CMtest.inner_product_real(drho1.data(), drho2.data()); - EXPECT_NEAR(inner, 0.5 * pw_basis.nrxx * GlobalV::NSPIN * (pw_basis.nrxx * GlobalV::NSPIN - 1), 1e-8); + EXPECT_NEAR(inner, 0.5 * pw_basis.nrxx * PARAM.input.nspin * (pw_basis.nrxx * PARAM.input.nspin - 1), 1e-8); // mixing angle case PARAM.input.mixing_angle = 1.0; @@ -315,7 +315,7 @@ TEST_F(ChargeMixingTest, InnerDotRealTest) PARAM.input.mixing_gg0_min, PARAM.input.mixing_angle, PARAM.input.mixing_dmr); - GlobalV::NSPIN = 4; + PARAM.input.nspin = 4; // a simple sum for inner product drho1.resize(pw_basis.nrxx * 2); @@ -344,18 +344,18 @@ TEST_F(ChargeMixingTest, InnerDotRecipSimpleTest) PARAM.input.mixing_angle, PARAM.input.mixing_dmr); CMtest.set_rhopw(&pw_basis, &pw_basis); - GlobalV::NSPIN = 2; + PARAM.input.nspin = 2; // a simple sum for inner product - std::vector> drhog1(pw_basis.npw * GlobalV::NSPIN); - std::vector> drhog2(pw_basis.npw * GlobalV::NSPIN); - for (int i = 0; i < pw_basis.npw * GlobalV::NSPIN; ++i) + std::vector> drhog1(pw_basis.npw * PARAM.input.nspin); + std::vector> drhog2(pw_basis.npw * PARAM.input.nspin); + for (int i = 0; i < pw_basis.npw * PARAM.input.nspin; ++i) { drhog1[i] = 1.0; drhog2[i] = double(i); } double inner = CMtest.inner_product_recip_simple(drhog1.data(), drhog2.data()); - EXPECT_NEAR(inner, 0.5 * pw_basis.npw * GlobalV::NSPIN * (pw_basis.npw * GlobalV::NSPIN - 1), 1e-8); + EXPECT_NEAR(inner, 0.5 * pw_basis.npw * PARAM.input.nspin * (pw_basis.npw * PARAM.input.nspin - 1), 1e-8); } TEST_F(ChargeMixingTest, InnerDotRecipHartreeTest) @@ -365,7 +365,7 @@ TEST_F(ChargeMixingTest, InnerDotRecipHartreeTest) CMtest.set_rhopw(&pw_basis, &pw_basis); const int npw = pw_basis.npw; const int nrxx = pw_basis.nrxx; - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; std::vector drhor1(pw_basis.nrxx); std::vector drhor2(pw_basis.nrxx); for (int i = 0; i < pw_basis.nrxx; ++i) @@ -380,7 +380,7 @@ TEST_F(ChargeMixingTest, InnerDotRecipHartreeTest) GlobalC::ucell.tpiba2 = 1.0; GlobalC::ucell.omega = 2.0; - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; std::vector> drhog1(pw_basis.npw); std::vector> drhog2(pw_basis.npw); for (int i = 0; i < pw_basis.nrxx; ++i) @@ -395,12 +395,12 @@ TEST_F(ChargeMixingTest, InnerDotRecipHartreeTest) EXPECT_NEAR(inner, -0.3 * ModuleBase::e2 * ModuleBase::FOUR_PI, 1e-8); // RECIPROCAL NSPIN=2 - GlobalV::NSPIN = 2; - drhog1.resize(pw_basis.npw * GlobalV::NSPIN); - drhog2.resize(pw_basis.npw * GlobalV::NSPIN); - std::vector> drhog1_mag(pw_basis.npw * GlobalV::NSPIN); - std::vector> drhog2_mag(pw_basis.npw * GlobalV::NSPIN); - for (int i = 0; i < pw_basis.npw * GlobalV::NSPIN; ++i) + PARAM.input.nspin = 2; + drhog1.resize(pw_basis.npw * PARAM.input.nspin); + drhog2.resize(pw_basis.npw * PARAM.input.nspin); + std::vector> drhog1_mag(pw_basis.npw * PARAM.input.nspin); + std::vector> drhog2_mag(pw_basis.npw * PARAM.input.nspin); + for (int i = 0; i < pw_basis.npw * PARAM.input.nspin; ++i) { drhog1[i] = std::complex(1.0, double(i)); drhog2[i] = std::complex(1.0, 1.0); @@ -421,10 +421,10 @@ TEST_F(ChargeMixingTest, InnerDotRecipHartreeTest) EXPECT_NEAR(inner, 236763.82650318215 * 2, 1e-8); // RECIPROCAL NSPIN=4 without mixing_angle - GlobalV::NSPIN = 4; - drhog1.resize(pw_basis.npw * GlobalV::NSPIN); - drhog2.resize(pw_basis.npw * GlobalV::NSPIN); - for (int i = 0; i < pw_basis.npw * GlobalV::NSPIN; ++i) + PARAM.input.nspin = 4; + drhog1.resize(pw_basis.npw * PARAM.input.nspin); + drhog2.resize(pw_basis.npw * PARAM.input.nspin); + for (int i = 0; i < pw_basis.npw * PARAM.input.nspin; ++i) { drhog1[i] = std::complex(1.0, double(i)); drhog2[i] = std::complex(1.0, 1.0); @@ -441,7 +441,7 @@ TEST_F(ChargeMixingTest, InnerDotRecipHartreeTest) EXPECT_NEAR(inner, 110668.61166927818, 1e-8); // RECIPROCAL NSPIN=4 with mixing_angle - GlobalV::NSPIN = 4; + PARAM.input.nspin = 4; PARAM.input.mixing_angle = 1.0; CMtest.set_mixing(PARAM.input.mixing_mode, PARAM.input.mixing_beta, @@ -473,7 +473,7 @@ TEST_F(ChargeMixingTest, InnerDotRecipRhoTest) // REAL Charge_Mixing CMtest; CMtest.set_rhopw(&pw_basis, &pw_basis); - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; std::vector drhor1(pw_basis.nrxx); std::vector drhor2(pw_basis.nrxx); for (int i = 0; i < pw_basis.nrxx; ++i) @@ -488,7 +488,7 @@ TEST_F(ChargeMixingTest, InnerDotRecipRhoTest) GlobalC::ucell.tpiba2 = 1.0; GlobalC::ucell.omega = 2.0; - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; std::vector> drhog1(pw_basis.npw); std::vector> drhog2(pw_basis.npw); for (int i = 0; i < pw_basis.nrxx; ++i) @@ -502,10 +502,10 @@ TEST_F(ChargeMixingTest, InnerDotRecipRhoTest) inner = CMtest.inner_product_recip_rho(drhog1.data(), drhog2.data()); EXPECT_NEAR(inner, -0.3 * ModuleBase::e2 * ModuleBase::FOUR_PI, 1e-8); - GlobalV::NSPIN = 2; - drhog1.resize(pw_basis.npw * GlobalV::NSPIN); - drhog2.resize(pw_basis.npw * GlobalV::NSPIN); - for (int i = 0; i < pw_basis.npw * GlobalV::NSPIN; ++i) + PARAM.input.nspin = 2; + drhog1.resize(pw_basis.npw * PARAM.input.nspin); + drhog2.resize(pw_basis.npw * PARAM.input.nspin); + for (int i = 0; i < pw_basis.npw * PARAM.input.nspin; ++i) { drhog1[i] = std::complex(1.0, double(i)); drhog2[i] = std::complex(1.0, 1.0); @@ -517,10 +517,10 @@ TEST_F(ChargeMixingTest, InnerDotRecipRhoTest) inner = CMtest.inner_product_recip_rho(drhog1.data(), drhog2.data()); EXPECT_NEAR(inner, 236763.82650318215 * 2, 1e-8); - GlobalV::NSPIN = 4; - drhog1.resize(pw_basis.npw * GlobalV::NSPIN); - drhog2.resize(pw_basis.npw * GlobalV::NSPIN); - for (int i = 0; i < pw_basis.npw * GlobalV::NSPIN; ++i) + PARAM.input.nspin = 4; + drhog1.resize(pw_basis.npw * PARAM.input.nspin); + drhog2.resize(pw_basis.npw * PARAM.input.nspin); + for (int i = 0; i < pw_basis.npw * PARAM.input.nspin; ++i) { drhog1[i] = std::complex(1.0, double(i)); drhog2[i] = std::complex(1.0, 1.0); @@ -543,17 +543,17 @@ TEST_F(ChargeMixingTest, KerkerScreenRecipTest) CMtest.set_rhopw(&pw_basis, &pw_basis); GlobalC::ucell.tpiba = 1.0; // nspin = 1 - GlobalV::NSPIN = 1; - std::complex* drhog = new std::complex[GlobalV::NSPIN*pw_basis.npw]; - std::complex* drhog_old = new std::complex[GlobalV::NSPIN*pw_basis.npw]; - for (int i = 0; i < GlobalV::NSPIN*pw_basis.npw; ++i) + PARAM.input.nspin = 1; + std::complex* drhog = new std::complex[PARAM.input.nspin*pw_basis.npw]; + std::complex* drhog_old = new std::complex[PARAM.input.nspin*pw_basis.npw]; + for (int i = 0; i < PARAM.input.nspin*pw_basis.npw; ++i) { drhog_old[i] = drhog[i] = std::complex(1.0, 1.0); } // no kerker CMtest.mixing_gg0 = 0.0; CMtest.Kerker_screen_recip(drhog); - for (int i = 0; i < GlobalV::NSPIN*pw_basis.npw; ++i) + for (int i = 0; i < PARAM.input.nspin*pw_basis.npw; ++i) { EXPECT_EQ(drhog[i], drhog_old[i]); } @@ -572,19 +572,19 @@ TEST_F(ChargeMixingTest, KerkerScreenRecipTest) delete[] drhog_old; // nspin = 2 - GlobalV::NSPIN = 2; + PARAM.input.nspin = 2; CMtest.mixing_beta = 0.4; CMtest.mixing_beta_mag = 1.6; - drhog = new std::complex[GlobalV::NSPIN*pw_basis.npw]; - drhog_old = new std::complex[GlobalV::NSPIN*pw_basis.npw]; - for (int i = 0; i < GlobalV::NSPIN*pw_basis.npw; ++i) + drhog = new std::complex[PARAM.input.nspin*pw_basis.npw]; + drhog_old = new std::complex[PARAM.input.nspin*pw_basis.npw]; + for (int i = 0; i < PARAM.input.nspin*pw_basis.npw; ++i) { drhog_old[i] = drhog[i] = std::complex(1.0, 1.0); } // mixing_gg0 = 0.0 CMtest.mixing_gg0 = 0.0; CMtest.Kerker_screen_recip(drhog); - for (int i = 0; i < GlobalV::NSPIN*pw_basis.npw; ++i) + for (int i = 0; i < PARAM.input.nspin*pw_basis.npw; ++i) { EXPECT_EQ(drhog[i], drhog_old[i]); } @@ -607,17 +607,17 @@ TEST_F(ChargeMixingTest, KerkerScreenRecipTest) delete[] drhog_old; // nspin = 4 - GlobalV::NSPIN = 4; - drhog = new std::complex[GlobalV::NSPIN*pw_basis.npw]; - drhog_old = new std::complex[GlobalV::NSPIN*pw_basis.npw]; - for (int i = 0; i < GlobalV::NSPIN*pw_basis.npw; ++i) + PARAM.input.nspin = 4; + drhog = new std::complex[PARAM.input.nspin*pw_basis.npw]; + drhog_old = new std::complex[PARAM.input.nspin*pw_basis.npw]; + for (int i = 0; i < PARAM.input.nspin*pw_basis.npw; ++i) { drhog_old[i] = drhog[i] = std::complex(1.0, 1.0); } // mixing_gg0 = 0.0 CMtest.mixing_gg0 = 0.0; CMtest.Kerker_screen_recip(drhog); - for (int i = 0; i < GlobalV::NSPIN*pw_basis.npw; ++i) + for (int i = 0; i < PARAM.input.nspin*pw_basis.npw; ++i) { EXPECT_EQ(drhog[i], drhog_old[i]); } @@ -657,7 +657,7 @@ TEST_F(ChargeMixingTest, KerkerScreenRecipTest) double gg = this->pw_basis.gg[i]; double ref = std::max(gg / (gg + gg2), 0.1 / CMtest.mixing_beta_mag); // rho - for (int j = 1; j < GlobalV::NSPIN; ++j) + for (int j = 1; j < PARAM.input.nspin; ++j) { EXPECT_NEAR(drhog[i + pw_basis.npw * j].real(), ref, 1e-10); EXPECT_NEAR(drhog[i + pw_basis.npw * j].imag(), ref, 1e-10); @@ -674,17 +674,17 @@ TEST_F(ChargeMixingTest, KerkerScreenRealTest) GlobalC::ucell.tpiba = 1.0; // nspin = 1 - GlobalV::NSPIN = 1; - double* drhor = new double[GlobalV::NSPIN*pw_basis.nrxx]; - double* drhor_ref = new double[GlobalV::NSPIN*pw_basis.nrxx]; - for (int i = 0; i < GlobalV::NSPIN*pw_basis.nrxx; ++i) + PARAM.input.nspin = 1; + double* drhor = new double[PARAM.input.nspin*pw_basis.nrxx]; + double* drhor_ref = new double[PARAM.input.nspin*pw_basis.nrxx]; + for (int i = 0; i < PARAM.input.nspin*pw_basis.nrxx; ++i) { drhor_ref[i] = drhor[i] = 1.0; } // no kerker CMtest.mixing_gg0 = 0.0; CMtest.Kerker_screen_real(drhor); - for (int i = 0; i < GlobalV::NSPIN*pw_basis.nrxx; ++i) + for (int i = 0; i < PARAM.input.nspin*pw_basis.nrxx; ++i) { EXPECT_EQ(drhor[i], drhor_ref[i]); } @@ -692,18 +692,18 @@ TEST_F(ChargeMixingTest, KerkerScreenRealTest) delete[] drhor_ref; // nspin = 2 - GlobalV::NSPIN = 2; + PARAM.input.nspin = 2; CMtest.mixing_gg0 = 0.0; - std::complex* drhog = new std::complex[GlobalV::NSPIN*pw_basis.npw]; - std::complex* drhog_old = new std::complex[GlobalV::NSPIN*pw_basis.npw]; - drhor = new double[GlobalV::NSPIN*pw_basis.nrxx]; - drhor_ref = new double[GlobalV::NSPIN*pw_basis.nrxx]; - for (int i = 0; i < GlobalV::NSPIN*pw_basis.npw; ++i) + std::complex* drhog = new std::complex[PARAM.input.nspin*pw_basis.npw]; + std::complex* drhog_old = new std::complex[PARAM.input.nspin*pw_basis.npw]; + drhor = new double[PARAM.input.nspin*pw_basis.nrxx]; + drhor_ref = new double[PARAM.input.nspin*pw_basis.nrxx]; + for (int i = 0; i < PARAM.input.nspin*pw_basis.npw; ++i) { drhog_old[i] = drhog[i] = std::complex(1.0, 1.0); } CMtest.Kerker_screen_recip(drhog); // no kerker - for (int i = 0; i < GlobalV::NSPIN*pw_basis.npw; ++i) + for (int i = 0; i < PARAM.input.nspin*pw_basis.npw; ++i) { EXPECT_EQ(drhog[i], drhog_old[i]); } @@ -749,7 +749,7 @@ TEST_F(ChargeMixingTest, MixRhoTest) { PARAM.sys.double_grid = false; charge.set_rhopw(&pw_basis); - const int nspin = GlobalV::NSPIN = 1; + const int nspin = PARAM.input.nspin = 1; PARAM.sys.domag_z = false; FUNC_TYPE = 3; PARAM.input.mixing_beta = 0.7; @@ -883,7 +883,7 @@ TEST_F(ChargeMixingTest, MixDoubleGridRhoTest) { PARAM.sys.double_grid = true; charge.set_rhopw(&pw_dbasis); - const int nspin = GlobalV::NSPIN = 1; + const int nspin = PARAM.input.nspin = 1; PARAM.sys.domag_z = false; FUNC_TYPE = 3; PARAM.input.mixing_beta = 0.7; @@ -988,7 +988,7 @@ TEST_F(ChargeMixingTest, MixDoubleGridRhoTest) TEST_F(ChargeMixingTest, MixDivCombTest) { // NSPIN = 1 - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; Charge_Mixing CMtest; CMtest.set_rhopw(&pw_basis, &pw_dbasis); std::vector> data(pw_dbasis.npw, 1.0); @@ -1007,7 +1007,7 @@ TEST_F(ChargeMixingTest, MixDivCombTest) EXPECT_EQ(datahf2, nullptr); // NSPIN = 2 - GlobalV::NSPIN = 2; + PARAM.input.nspin = 2; data.resize(pw_dbasis.npw * 2, 1.0); std::vector> dataout(pw_dbasis.npw * 2, 1.0); CMtest.divide_data(data.data(), datas, datahf); diff --git a/source/module_elecstate/test/charge_test.cpp b/source/module_elecstate/test/charge_test.cpp index 78afaa07a5..91a071b370 100644 --- a/source/module_elecstate/test/charge_test.cpp +++ b/source/module_elecstate/test/charge_test.cpp @@ -46,7 +46,7 @@ double get_ucell_omega() double tmp_gridecut = 80.0; void Set_GlobalV_Default() { - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; PARAM.input.test_charge = 0; GlobalV::nelec = 8; } @@ -62,7 +62,7 @@ void Set_GlobalV_Default() * - this is a trivial test * - Allocate: Charge::set_rhopw(), Charge::allocate(), Charge::destroy() * - allocate rho, rhog, rho_save, rhog_save, kin_r, kin_r_save - * - using rhopw and GlobalV::NSPIN + * - using rhopw and PARAM.input.nspin * - SumRho: Charge::sum_rho() * - calculate \sum_{is}^nspin \sum_{ir}^nrxx rho[is][ir] * - RenormalizeRho: Charge::renormalize_rho() @@ -125,10 +125,10 @@ TEST_F(ChargeTest, Allocate) elecstate::tmp_xc_func_type = 3; charge->set_rhopw(rhopw); EXPECT_FALSE(charge->allocate_rho); - charge->allocate(GlobalV::NSPIN); + charge->allocate(PARAM.input.nspin); EXPECT_TRUE(charge->allocate_rho); // test if Charge::allocate() be called twice - EXPECT_NO_THROW(charge->allocate(GlobalV::NSPIN)); + EXPECT_NO_THROW(charge->allocate(PARAM.input.nspin)); EXPECT_TRUE(charge->allocate_rho); } @@ -136,9 +136,9 @@ TEST_F(ChargeTest, SumRho) { charge->set_rhopw(rhopw); EXPECT_FALSE(charge->allocate_rho); - charge->allocate(GlobalV::NSPIN); + charge->allocate(PARAM.input.nspin); EXPECT_TRUE(charge->allocate_rho); - int nspin = (GlobalV::NSPIN == 2) ? 2 : 1; + int nspin = (PARAM.input.nspin == 2) ? 2 : 1; for (int is = 0; is < nspin; is++) { for (int ir = 0; ir < rhopw->nrxx; ir++) @@ -154,9 +154,9 @@ TEST_F(ChargeTest, RenormalizeRho) { charge->set_rhopw(rhopw); EXPECT_FALSE(charge->allocate_rho); - charge->allocate(GlobalV::NSPIN); + charge->allocate(PARAM.input.nspin); EXPECT_TRUE(charge->allocate_rho); - int nspin = (GlobalV::NSPIN == 2) ? 2 : 1; + int nspin = (PARAM.input.nspin == 2) ? 2 : 1; for (int is = 0; is < nspin; is++) { for (int ir = 0; ir < rhopw->nrxx; ir++) @@ -174,9 +174,9 @@ TEST_F(ChargeTest, CheckNe) { charge->set_rhopw(rhopw); EXPECT_FALSE(charge->allocate_rho); - charge->allocate(GlobalV::NSPIN); + charge->allocate(PARAM.input.nspin); EXPECT_TRUE(charge->allocate_rho); - int nspin = (GlobalV::NSPIN == 2) ? 2 : 1; + int nspin = (PARAM.input.nspin == 2) ? 2 : 1; for (int is = 0; is < nspin; is++) { for (int ir = 0; ir < rhopw->nrxx; ir++) @@ -195,9 +195,9 @@ TEST_F(ChargeTest, SaveRhoBeforeSumBand) { charge->set_rhopw(rhopw); EXPECT_FALSE(charge->allocate_rho); - charge->allocate(GlobalV::NSPIN); + charge->allocate(PARAM.input.nspin); EXPECT_TRUE(charge->allocate_rho); - int nspin = (GlobalV::NSPIN == 2) ? 2 : 1; + int nspin = (PARAM.input.nspin == 2) ? 2 : 1; for (int is = 0; is < nspin; is++) { for (int ir = 0; ir < rhopw->nrxx; ir++) diff --git a/source/module_elecstate/test/elecstate_base_test.cpp b/source/module_elecstate/test/elecstate_base_test.cpp index 984b0a1777..de015315ba 100644 --- a/source/module_elecstate/test/elecstate_base_test.cpp +++ b/source/module_elecstate/test/elecstate_base_test.cpp @@ -127,10 +127,10 @@ class MockElecState : public ElecState public: void Set_GlobalV_Default() { - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; GlobalV::nelec = 10.0; GlobalV::nupdown = 0.0; - GlobalV::TWO_EFERMI = false; + PARAM.sys.two_fermi = false; GlobalV::NBANDS = 6; GlobalV::NLOCAL = 6; PARAM.input.esolver_type = "ksdft"; @@ -162,7 +162,7 @@ using ElecStateDeathTest = ElecStateTest; TEST_F(ElecStateTest, InitNelecSpin) { - GlobalV::NSPIN = 2; + PARAM.input.nspin = 2; elecstate->init_nelec_spin(); EXPECT_EQ(elecstate->nelec_spin[0], 5.0); EXPECT_EQ(elecstate->nelec_spin[1], 5.0); @@ -176,7 +176,7 @@ TEST_F(ElecStateTest, Constructor) elecstate::ElecState* elecstate_new = new elecstate::ElecState(charge, rhopw, bigpw); EXPECT_EQ(elecstate_new->charge, charge); EXPECT_EQ(elecstate_new->bigpw, bigpw); - EXPECT_EQ(elecstate_new->eferm.two_efermi, GlobalV::TWO_EFERMI); + EXPECT_EQ(elecstate_new->eferm.two_efermi, PARAM.sys.two_fermi); delete elecstate_new; delete bigpw; delete rhopw; @@ -237,7 +237,7 @@ TEST_F(ElecStateDeathTest, CalNbandsWarning1) TEST_F(ElecStateDeathTest, CalNbandsWarning2) { - GlobalV::NSPIN = 2; + PARAM.input.nspin = 2; GlobalV::nupdown = 4.0; elecstate->init_nelec_spin(); testing::internal::CaptureStdout(); @@ -248,7 +248,7 @@ TEST_F(ElecStateDeathTest, CalNbandsWarning2) TEST_F(ElecStateDeathTest, CalNbandsWarning3) { - GlobalV::NSPIN = 2; + PARAM.input.nspin = 2; GlobalV::nupdown = -4.0; elecstate->init_nelec_spin(); testing::internal::CaptureStdout(); @@ -259,7 +259,7 @@ TEST_F(ElecStateDeathTest, CalNbandsWarning3) TEST_F(ElecStateTest, CalNbandsSpin1) { - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; GlobalV::NBANDS = 0; elecstate->cal_nbands(); EXPECT_EQ(GlobalV::NBANDS, 15); @@ -267,7 +267,7 @@ TEST_F(ElecStateTest, CalNbandsSpin1) TEST_F(ElecStateTest, CalNbandsSpin1LCAO) { - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; GlobalV::NBANDS = 0; PARAM.input.basis_type = "lcao"; elecstate->cal_nbands(); @@ -276,7 +276,7 @@ TEST_F(ElecStateTest, CalNbandsSpin1LCAO) TEST_F(ElecStateTest, CalNbandsSpin4) { - GlobalV::NSPIN = 4; + PARAM.input.nspin = 4; GlobalV::NBANDS = 0; elecstate->cal_nbands(); EXPECT_EQ(GlobalV::NBANDS, 30); @@ -284,7 +284,7 @@ TEST_F(ElecStateTest, CalNbandsSpin4) TEST_F(ElecStateTest, CalNbandsSpin4LCAO) { - GlobalV::NSPIN = 4; + PARAM.input.nspin = 4; GlobalV::NBANDS = 0; PARAM.input.basis_type = "lcao"; elecstate->cal_nbands(); @@ -293,7 +293,7 @@ TEST_F(ElecStateTest, CalNbandsSpin4LCAO) TEST_F(ElecStateTest, CalNbandsSpin2) { - GlobalV::NSPIN = 2; + PARAM.input.nspin = 2; GlobalV::NBANDS = 0; elecstate->init_nelec_spin(); elecstate->cal_nbands(); @@ -302,7 +302,7 @@ TEST_F(ElecStateTest, CalNbandsSpin2) TEST_F(ElecStateTest, CalNbandsSpin2LCAO) { - GlobalV::NSPIN = 2; + PARAM.input.nspin = 2; GlobalV::NBANDS = 0; PARAM.input.basis_type = "lcao"; elecstate->init_nelec_spin(); @@ -351,8 +351,8 @@ TEST_F(ElecStateTest, GetRho) K_Vectors* klist = new K_Vectors; int nk = 1; int nrxx = 100; - charge->rho = new double*[GlobalV::NSPIN]; - for (int i = 0; i < GlobalV::NSPIN; ++i) + charge->rho = new double*[PARAM.input.nspin]; + for (int i = 0; i < PARAM.input.nspin; ++i) { charge->rho[i] = new double[nrxx]; for (int j = 0; j < nrxx; ++j) @@ -363,7 +363,7 @@ TEST_F(ElecStateTest, GetRho) elecstate->init_ks(charge, klist, nk, rhopw, bigpw); EXPECT_EQ(elecstate->getRho(0), &(charge->rho[0][0])); EXPECT_EQ(elecstate->getRho(0)[nrxx - 1], 1.0); - for (int i = 0; i < GlobalV::NSPIN; ++i) + for (int i = 0; i < PARAM.input.nspin; ++i) { delete[] charge->rho[i]; } @@ -534,14 +534,14 @@ TEST_F(ElecStateTest, CalculateWeightsIWeights) TEST_F(ElecStateTest, CalculateWeightsIWeightsTwoFermi) { // get nelec_spin - GlobalV::TWO_EFERMI = true; - GlobalV::NSPIN = 2; + PARAM.sys.two_fermi = true; + PARAM.input.nspin = 2; elecstate->init_nelec_spin(); EXPECT_EQ(elecstate->nelec_spin[0], 5.0); EXPECT_EQ(elecstate->nelec_spin[1], 5.0); // EXPECT_FALSE(elecstate->skip_weights); - int nks = 5*GlobalV::NSPIN; + int nks = 5*PARAM.input.nspin; K_Vectors* klist = new K_Vectors; klist->set_nks(nks); klist->wk.resize(nks); @@ -641,14 +641,14 @@ TEST_F(ElecStateTest, CalculateWeightsGWeightsTwoFermi) { Occupy::use_gaussian_broadening = true; // get nelec_spin - GlobalV::TWO_EFERMI = true; - GlobalV::NSPIN = 2; + PARAM.sys.two_fermi = true; + PARAM.input.nspin = 2; elecstate->init_nelec_spin(); EXPECT_EQ(elecstate->nelec_spin[0], 5.0); EXPECT_EQ(elecstate->nelec_spin[1], 5.0); // EXPECT_FALSE(elecstate->skip_weights); - int nks = 5*GlobalV::NSPIN; + int nks = 5*PARAM.input.nspin; K_Vectors* klist = new K_Vectors; klist->set_nks(nks); klist->wk.resize(nks); diff --git a/source/module_elecstate/test/elecstate_energy_test.cpp b/source/module_elecstate/test/elecstate_energy_test.cpp index 200220aba7..a9d0c477c5 100644 --- a/source/module_elecstate/test/elecstate_energy_test.cpp +++ b/source/module_elecstate/test/elecstate_energy_test.cpp @@ -76,10 +76,10 @@ class MockElecState : public ElecState PARAM.input.imp_sol = false; PARAM.input.dft_plus_u = 0; // base class - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; GlobalV::nelec = 10.0; GlobalV::nupdown = 0.0; - GlobalV::TWO_EFERMI = false; + PARAM.sys.two_fermi = false; GlobalV::NBANDS = 6; GlobalV::NLOCAL = 6; PARAM.input.esolver_type = "ksdft"; diff --git a/source/module_elecstate/test/elecstate_magnetism_test.cpp b/source/module_elecstate/test/elecstate_magnetism_test.cpp index 77b85ca54a..893ef36c5a 100644 --- a/source/module_elecstate/test/elecstate_magnetism_test.cpp +++ b/source/module_elecstate/test/elecstate_magnetism_test.cpp @@ -2,6 +2,9 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" +#define private public +#include "module_parameter/parameter.h" +#undef private #include "module_elecstate/elecstate_getters.h" /************************************************ @@ -14,8 +17,8 @@ * - Magnetism::~Magnetism() * - Magnetism::judge_parallel() * - Magnetism::compute_magnetization() - * - compute magnetization for spin-polarized system when GlobalV::NSPIN = 2 - * - and non-collinear case with GlobalV::NSPIN = 4 + * - compute magnetization for spin-polarized system when PARAM.input.nspin = 2 + * - and non-collinear case with PARAM.input.nspin = 4 */ #define private public @@ -70,15 +73,15 @@ TEST_F(MagnetismTest, JudgeParallel) TEST_F(MagnetismTest, ComputeMagnetizationS2) { - GlobalV::NSPIN = 2; - GlobalV::TWO_EFERMI = false; + PARAM.input.nspin = 2; + PARAM.sys.two_fermi = false; GlobalV::nelec = 10.0; Charge* chr = new Charge; chr->nrxx = 100; chr->nxyz = 1000; - chr->rho = new double*[GlobalV::NSPIN]; - for (int i=0; i< GlobalV::NSPIN; i++) + chr->rho = new double*[PARAM.input.nspin]; + for (int i=0; i< PARAM.input.nspin; i++) { chr->rho[i] = new double[chr->nrxx]; } @@ -94,7 +97,7 @@ TEST_F(MagnetismTest, ComputeMagnetizationS2) EXPECT_DOUBLE_EQ(4.75, nelec_spin[0]); EXPECT_DOUBLE_EQ(5.25, nelec_spin[1]); delete[] nelec_spin; - for (int i=0; i< GlobalV::NSPIN; i++) + for (int i=0; i< PARAM.input.nspin; i++) { delete[] chr->rho[i]; } @@ -104,13 +107,13 @@ TEST_F(MagnetismTest, ComputeMagnetizationS2) TEST_F(MagnetismTest, ComputeMagnetizationS4) { - GlobalV::NSPIN = 4; + PARAM.input.nspin = 4; Charge* chr = new Charge; - chr->rho = new double*[GlobalV::NSPIN]; + chr->rho = new double*[PARAM.input.nspin]; chr->nrxx = 100; chr->nxyz = 1000; - for (int i=0; i< GlobalV::NSPIN; i++) + for (int i=0; i< PARAM.input.nspin; i++) { chr->rho[i] = new double[chr->nrxx]; } @@ -128,7 +131,7 @@ TEST_F(MagnetismTest, ComputeMagnetizationS4) EXPECT_DOUBLE_EQ(50.0, magnetism->tot_magnetization_nc[1]); EXPECT_DOUBLE_EQ(50.0, magnetism->tot_magnetization_nc[2]); delete[] nelec_spin; - for (int i=0; i< GlobalV::NSPIN; i++) + for (int i=0; i< PARAM.input.nspin; i++) { delete[] chr->rho[i]; } diff --git a/source/module_elecstate/test/elecstate_occupy_test.cpp b/source/module_elecstate/test/elecstate_occupy_test.cpp index a6d8fcd844..f9b18d8b04 100644 --- a/source/module_elecstate/test/elecstate_occupy_test.cpp +++ b/source/module_elecstate/test/elecstate_occupy_test.cpp @@ -1,7 +1,9 @@ #include - #include "gmock/gmock.h" #include "gtest/gtest.h" +#define private public +#include "module_parameter/parameter.h" +#undef private #include "module_elecstate/elecstate_getters.h" /*************************************************************** @@ -181,7 +183,7 @@ TEST_F(OccupyTest, DecisionArbitrary) TEST_F(OccupyTest, IweightsNOSPIN) { - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; double ef = 0.0; ModuleBase::matrix wg(1, 1); std::vector wk(1, 2.0); @@ -195,7 +197,7 @@ TEST_F(OccupyTest, IweightsNOSPIN) TEST_F(OccupyTest, IweightsSPIN) { - GlobalV::NSPIN = 2; + PARAM.input.nspin = 2; double ef_up = 0.0; double ef_dw = 0.0; ModuleBase::matrix wg(2, 1); @@ -216,7 +218,7 @@ TEST_F(OccupyTest, IweightsSPIN) TEST_F(OccupyTest, IweightsWarning) { - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; double ef = 0.0; ModuleBase::matrix wg(1, 1); std::vector wk(1, 2.0); diff --git a/source/module_elecstate/test/elecstate_print_test.cpp b/source/module_elecstate/test/elecstate_print_test.cpp index 44317d4376..748f44c2e9 100644 --- a/source/module_elecstate/test/elecstate_print_test.cpp +++ b/source/module_elecstate/test/elecstate_print_test.cpp @@ -138,7 +138,7 @@ TEST_F(ElecStatePrintTest, PrintFormat) TEST_F(ElecStatePrintTest, PrintEigenvalueS2) { - GlobalV::NSPIN = 2; + PARAM.input.nspin = 2; GlobalV::ofs_running.open("test.dat", std::ios::out); // print eigenvalue elecstate.print_eigenvalue(GlobalV::ofs_running); @@ -161,7 +161,7 @@ TEST_F(ElecStatePrintTest, PrintEigenvalueS2) TEST_F(ElecStatePrintTest, PrintEigenvalueS4) { - GlobalV::NSPIN = 4; + PARAM.input.nspin = 4; GlobalV::ofs_running.open("test.dat", std::ios::out); // print eigenvalue elecstate.print_eigenvalue(GlobalV::ofs_running); @@ -182,7 +182,7 @@ TEST_F(ElecStatePrintTest, PrintEigenvalueS4) TEST_F(ElecStatePrintTest, PrintBand) { - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; GlobalV::NBANDS = 2; GlobalV::MY_RANK = 0; GlobalV::ofs_running.open("test.dat", std::ios::out); @@ -201,7 +201,7 @@ TEST_F(ElecStatePrintTest, PrintBand) TEST_F(ElecStatePrintTest, PrintEigenvalueWarning) { elecstate.ekb(0, 0) = 1.0e11; - GlobalV::NSPIN = 4; + PARAM.input.nspin = 4; GlobalV::ofs_running.open("test.dat", std::ios::out); testing::internal::CaptureStdout(); EXPECT_EXIT(elecstate.print_eigenvalue(GlobalV::ofs_running), ::testing::ExitedWithCode(0), ""); @@ -214,7 +214,7 @@ TEST_F(ElecStatePrintTest, PrintEigenvalueWarning) TEST_F(ElecStatePrintTest, PrintBandWarning) { elecstate.ekb(0, 0) = 1.0e11; - GlobalV::NSPIN = 4; + PARAM.input.nspin = 4; GlobalV::ofs_running.open("test.dat", std::ios::out); testing::internal::CaptureStdout(); EXPECT_EXIT(elecstate.print_band(0, 1, 0), ::testing::ExitedWithCode(0), ""); @@ -242,11 +242,11 @@ TEST_F(ElecStatePrintTest, PrintEtot) PARAM.input.imp_sol = true; PARAM.input.efield_flag = true; PARAM.input.gate_flag = true; - GlobalV::TWO_EFERMI = true; + PARAM.sys.two_fermi = true; PARAM.input.out_bandgap = true; GlobalV::MY_RANK = 0; PARAM.input.basis_type = "pw"; - GlobalV::NSPIN = 2; + PARAM.input.nspin = 2; // iteration of different vdw_method std::vector vdw_methods = {"d2", "d3_0", "d3_bj"}; for (int i = 0; i < vdw_methods.size(); i++) @@ -322,7 +322,7 @@ TEST_F(ElecStatePrintTest, PrintEtot2) PARAM.input.imp_sol = true; PARAM.input.efield_flag = true; PARAM.input.gate_flag = true; - GlobalV::TWO_EFERMI = false; + PARAM.sys.two_fermi = false; PARAM.input.out_bandgap = true; GlobalV::MY_RANK = 0; PARAM.input.basis_type = "pw"; @@ -360,9 +360,9 @@ TEST_F(ElecStatePrintTest, PrintEtotColorS2) PARAM.input.imp_sol = true; PARAM.input.efield_flag = true; PARAM.input.gate_flag = true; - GlobalV::TWO_EFERMI = true; + PARAM.sys.two_fermi = true; PARAM.input.out_bandgap = true; - GlobalV::NSPIN = 2; + PARAM.input.nspin = 2; GlobalV::MY_RANK = 0; elecstate.print_etot(converged, iter, scf_thr, scf_thr_kin, duration, printe, pw_diag_thr, avg_iter, print); } @@ -384,9 +384,9 @@ TEST_F(ElecStatePrintTest, PrintEtotColorS4) PARAM.input.imp_sol = true; PARAM.input.efield_flag = true; PARAM.input.gate_flag = true; - GlobalV::TWO_EFERMI = true; + PARAM.sys.two_fermi = true; PARAM.input.out_bandgap = true; - GlobalV::NSPIN = 4; + PARAM.input.nspin = 4; PARAM.input.noncolin = true; GlobalV::MY_RANK = 0; elecstate.print_etot(converged, iter, scf_thr, scf_thr_kin, duration, printe, pw_diag_thr, avg_iter, print); @@ -410,7 +410,7 @@ TEST_F(ElecStatePrintTest, PrintEtotColorS4) // PARAM.input.imp_sol = true; // PARAM.input.efield_flag = true; // PARAM.input.gate_flag = true; -// GlobalV::TWO_EFERMI = false; +// PARAM.sys.two_fermi = false; // PARAM.input.out_bandgap = true; // GlobalV::MY_RANK = 0; // PARAM.input.basis_type = "pw"; diff --git a/source/module_elecstate/test/elecstate_pw_test.cpp b/source/module_elecstate/test/elecstate_pw_test.cpp index e059518fc8..738af2b044 100644 --- a/source/module_elecstate/test/elecstate_pw_test.cpp +++ b/source/module_elecstate/test/elecstate_pw_test.cpp @@ -169,10 +169,10 @@ void Set_GlobalV_Default() PARAM.sys.domag = false; PARAM.sys.domag_z = false; // Base class dependent - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; GlobalV::nelec = 10.0; GlobalV::nupdown = 0.0; - GlobalV::TWO_EFERMI = false; + PARAM.sys.two_fermi = false; GlobalV::NBANDS = 6; GlobalV::NLOCAL = 6; PARAM.input.esolver_type = "ksdft"; @@ -299,7 +299,7 @@ TEST_F(ElecStatePWTest, InitRhoDataSingle) { PARAM.input.precision = "single"; elecstate::tmp_xc_func_type = 3; - chg->nspin = GlobalV::NSPIN; + chg->nspin = PARAM.input.nspin; chg->nrxx = 1000; elecstate_pw_s = new elecstate::ElecStatePW, base_device::DEVICE_CPU>(wfcpw, chg, diff --git a/source/module_elecstate/test/potential_new_test.cpp b/source/module_elecstate/test/potential_new_test.cpp index 8468f79213..b30a2b21cf 100644 --- a/source/module_elecstate/test/potential_new_test.cpp +++ b/source/module_elecstate/test/potential_new_test.cpp @@ -54,7 +54,7 @@ PotBase* Potential::get_pot_type(const std::string& pot_type) void Set_GlobalV_Default() { - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; PARAM.sys.device_flag = "cpu"; PARAM.input.precision = "double"; } @@ -151,7 +151,7 @@ TEST_F(PotentialNewTest, ConstructorCPUDouble) EXPECT_TRUE(pot->fixed_mode); EXPECT_TRUE(pot->dynamic_mode); EXPECT_EQ(pot->v_effective_fixed.size(), 100); - EXPECT_EQ(pot->v_effective.nr, GlobalV::NSPIN); + EXPECT_EQ(pot->v_effective.nr, PARAM.input.nspin); EXPECT_EQ(pot->v_effective.nc, 100); } @@ -163,7 +163,7 @@ TEST_F(PotentialNewTest, ConstructorCPUSingle) EXPECT_TRUE(pot->fixed_mode); EXPECT_TRUE(pot->dynamic_mode); EXPECT_EQ(pot->v_effective_fixed.size(), 100); - EXPECT_EQ(pot->v_effective.nr, GlobalV::NSPIN); + EXPECT_EQ(pot->v_effective.nr, PARAM.input.nspin); EXPECT_EQ(pot->v_effective.nc, 100); } @@ -183,9 +183,9 @@ TEST_F(PotentialNewTest, ConstructorXC3) EXPECT_TRUE(pot->fixed_mode); EXPECT_TRUE(pot->dynamic_mode); EXPECT_EQ(pot->v_effective_fixed.size(), 100); - EXPECT_EQ(pot->v_effective.nr, GlobalV::NSPIN); + EXPECT_EQ(pot->v_effective.nr, PARAM.input.nspin); EXPECT_EQ(pot->v_effective.nc, 100); - EXPECT_EQ(pot->vofk_effective.nr, GlobalV::NSPIN); + EXPECT_EQ(pot->vofk_effective.nr, PARAM.input.nspin); EXPECT_EQ(pot->vofk_effective.nc, 100); } @@ -198,7 +198,7 @@ TEST_F(PotentialNewTest, ConstructorGPUDouble) EXPECT_TRUE(pot->fixed_mode); EXPECT_TRUE(pot->dynamic_mode); EXPECT_EQ(pot->v_effective_fixed.size(), 100); - EXPECT_EQ(pot->v_effective.nr, GlobalV::NSPIN); + EXPECT_EQ(pot->v_effective.nr, PARAM.input.nspin); EXPECT_EQ(pot->v_effective.nc, 100); } @@ -212,7 +212,7 @@ TEST_F(PotentialNewTest, ConstructorGPUSingle) EXPECT_TRUE(pot->fixed_mode); EXPECT_TRUE(pot->dynamic_mode); EXPECT_EQ(pot->v_effective_fixed.size(), 100); - EXPECT_EQ(pot->v_effective.nr, GlobalV::NSPIN); + EXPECT_EQ(pot->v_effective.nr, PARAM.input.nspin); EXPECT_EQ(pot->v_effective.nc, 100); } @@ -385,7 +385,7 @@ TEST_F(PotentialNewTest, GetVnew) Charge* chg = new Charge; ModuleBase::matrix vnew; pot->get_vnew(chg, vnew); - EXPECT_EQ(vnew.nr, GlobalV::NSPIN); + EXPECT_EQ(vnew.nr, PARAM.input.nspin); EXPECT_EQ(vnew.nc, 100); delete chg; } @@ -398,9 +398,9 @@ TEST_F(PotentialNewTest, GetEffectiveVmatrix) // ModuleBase::matrix v_eff_tmp = pot->get_effective_v(); const ModuleBase::matrix v_eff_tmp_const = pot->get_effective_v(); - EXPECT_EQ(v_eff_tmp.nr, GlobalV::NSPIN); + EXPECT_EQ(v_eff_tmp.nr, PARAM.input.nspin); EXPECT_EQ(v_eff_tmp.nc, 100); - EXPECT_EQ(v_eff_tmp_const.nr, GlobalV::NSPIN); + EXPECT_EQ(v_eff_tmp_const.nr, PARAM.input.nspin); EXPECT_EQ(v_eff_tmp_const.nc, 100); for (int ir = 0; ir < v_eff_tmp.nr; ir++) { @@ -449,9 +449,9 @@ TEST_F(PotentialNewTest, GetEffectiveVofkmatrix) // ModuleBase::matrix vofk_eff_tmp = pot->get_effective_vofk(); const ModuleBase::matrix vofk_eff_tmp_const = pot->get_effective_vofk(); - EXPECT_EQ(vofk_eff_tmp.nr, GlobalV::NSPIN); + EXPECT_EQ(vofk_eff_tmp.nr, PARAM.input.nspin); EXPECT_EQ(vofk_eff_tmp.nc, 100); - EXPECT_EQ(vofk_eff_tmp_const.nr, GlobalV::NSPIN); + EXPECT_EQ(vofk_eff_tmp_const.nr, PARAM.input.nspin); EXPECT_EQ(vofk_eff_tmp_const.nc, 100); for (int ir = 0; ir < vofk_eff_tmp.nr; ir++) { @@ -517,9 +517,9 @@ TEST_F(PotentialNewTest, GetVeffSmooth) // ModuleBase::matrix veff_smooth_tmp = pot->get_veff_smooth(); const ModuleBase::matrix veff_smooth_const_tmp = pot->get_veff_smooth(); - EXPECT_EQ(veff_smooth_tmp.nr, GlobalV::NSPIN); + EXPECT_EQ(veff_smooth_tmp.nr, PARAM.input.nspin); EXPECT_EQ(veff_smooth_tmp.nc, 100); - EXPECT_EQ(veff_smooth_const_tmp.nr, GlobalV::NSPIN); + EXPECT_EQ(veff_smooth_const_tmp.nr, PARAM.input.nspin); EXPECT_EQ(veff_smooth_const_tmp.nc, 100); for (int ir = 0; ir < veff_smooth_tmp.nr; ir++) { @@ -539,9 +539,9 @@ TEST_F(PotentialNewTest, GetVofkSmooth) // ModuleBase::matrix vofk_smooth_tmp = pot->get_veff_smooth(); const ModuleBase::matrix vofk_smooth_const_tmp = pot->get_veff_smooth(); - EXPECT_EQ(vofk_smooth_tmp.nr, GlobalV::NSPIN); + EXPECT_EQ(vofk_smooth_tmp.nr, PARAM.input.nspin); EXPECT_EQ(vofk_smooth_tmp.nc, 100); - EXPECT_EQ(vofk_smooth_const_tmp.nr, GlobalV::NSPIN); + EXPECT_EQ(vofk_smooth_const_tmp.nr, PARAM.input.nspin); EXPECT_EQ(vofk_smooth_const_tmp.nc, 100); for (int ir = 0; ir < vofk_smooth_tmp.nr; ir++) { diff --git a/source/module_elecstate/test_mpi/charge_mpi_test.cpp b/source/module_elecstate/test_mpi/charge_mpi_test.cpp index 606446295f..9e748151eb 100644 --- a/source/module_elecstate/test_mpi/charge_mpi_test.cpp +++ b/source/module_elecstate/test_mpi/charge_mpi_test.cpp @@ -183,7 +183,7 @@ TEST_F(ChargeMpiTest, rho_mpi) rhopw->initparameters(false, 10); rhopw->setuptransform(); charge->rhopw = rhopw; - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; charge->rho = new double*[1]; charge->kin_r = new double*[1]; diff --git a/source/module_esolver/esolver.cpp b/source/module_esolver/esolver.cpp index 67f1b5d95e..28473d1d99 100644 --- a/source/module_esolver/esolver.cpp +++ b/source/module_esolver/esolver.cpp @@ -171,7 +171,7 @@ ESolver* init_esolver(const Input_para& inp, UnitCell& ucell) { return new ESolver_KS_LCAO(); } - else if (GlobalV::NSPIN < 4) + else if (PARAM.inp.nspin < 4) { return new ESolver_KS_LCAO, double>(); } @@ -189,7 +189,7 @@ ESolver* init_esolver(const Input_para& inp, UnitCell& ucell) // use constructor rather than Init function to initialize reference (instead of pointers) to ucell if (PARAM.globalv.gamma_only_local){ return new LR::ESolver_LR(inp, ucell); - } else if (GlobalV::NSPIN < 2) { + } else if (PARAM.inp.nspin < 2) { return new LR::ESolver_LR, double>(inp, ucell); } else { throw std::runtime_error("LR-TDDFT is not implemented for spin polarized case"); @@ -203,7 +203,7 @@ ESolver* init_esolver(const Input_para& inp, UnitCell& ucell) { p_esolver = new ESolver_KS_LCAO(); } - else if (GlobalV::NSPIN < 4) + else if (PARAM.inp.nspin < 4) { p_esolver = new ESolver_KS_LCAO, double>(); } diff --git a/source/module_esolver/esolver_fp.cpp b/source/module_esolver/esolver_fp.cpp index 331192ed85..9eea82454c 100644 --- a/source/module_esolver/esolver_fp.cpp +++ b/source/module_esolver/esolver_fp.cpp @@ -112,7 +112,7 @@ void ESolver_FP::before_all_runners(const Input_para& inp, UnitCell& cell) this->print_rhofft(inp, GlobalV::ofs_running); //! 5) initialize the charge extrapolation method if necessary - this->CE.Init_CE(GlobalV::NSPIN, GlobalC::ucell.nat, this->pw_rhod->nrxx, inp.chg_extrap); + this->CE.Init_CE(PARAM.inp.nspin, GlobalC::ucell.nat, this->pw_rhod->nrxx, inp.chg_extrap); return; } @@ -134,7 +134,7 @@ void ESolver_FP::after_scf(const int istep) // 3) write charge density if (PARAM.inp.out_chg[0] > 0) { - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { double* data = nullptr; if (PARAM.inp.dm_to_rho) @@ -157,7 +157,7 @@ void ESolver_FP::after_scf(const int istep) #endif data, is, - GlobalV::NSPIN, + PARAM.inp.nspin, istep, fn, this->pw_rhod->nx, @@ -179,7 +179,7 @@ void ESolver_FP::after_scf(const int istep) #endif this->pelec->charge->kin_r_save[is], is, - GlobalV::NSPIN, + PARAM.inp.nspin, istep, fn, this->pw_rhod->nx, @@ -194,14 +194,14 @@ void ESolver_FP::after_scf(const int istep) { std::complex** rhog_tot = (PARAM.inp.dm_to_rho)? this->pelec->charge->rhog : this->pelec->charge->rhog_save; double** rhor_tot = (PARAM.inp.dm_to_rho)? this->pelec->charge->rho : this->pelec->charge->rho_save; - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { this->pw_rhod->real2recip(rhor_tot[is], rhog_tot[is]); } ModuleIO::write_rhog(PARAM.globalv.global_out_dir + PARAM.inp.suffix + "-CHARGE-DENSITY.restart", PARAM.globalv.gamma_only_pw || PARAM.globalv.gamma_only_local, this->pw_rhod, - GlobalV::NSPIN, + PARAM.inp.nspin, GlobalC::ucell.GT, rhog_tot, GlobalV::RANK_IN_POOL, @@ -211,7 +211,7 @@ void ESolver_FP::after_scf(const int istep) // 4) write potential if (PARAM.inp.out_pot == 1 || PARAM.inp.out_pot == 3) { - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { std::string fn =PARAM.globalv.global_out_dir + "/SPIN" + std::to_string(is + 1) + "_POT.cube"; @@ -224,7 +224,7 @@ void ESolver_FP::after_scf(const int istep) #endif this->pelec->pot->get_effective_v(is), is, - GlobalV::NSPIN, + PARAM.inp.nspin, istep, fn, this->pw_rhod->nx, @@ -317,7 +317,7 @@ void ESolver_FP::init_after_vc(const Input_para& inp, UnitCell& cell) ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "SYMMETRY"); } - kv.set_after_vc(GlobalV::NSPIN, cell.G, cell.latvec); + kv.set_after_vc(PARAM.inp.nspin, cell.G, cell.latvec); ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "INIT K-POINTS"); return; diff --git a/source/module_esolver/esolver_ks.cpp b/source/module_esolver/esolver_ks.cpp index e71661b00c..0bc5c6ad0d 100644 --- a/source/module_esolver/esolver_ks.cpp +++ b/source/module_esolver/esolver_ks.cpp @@ -216,7 +216,7 @@ void ESolver_KS::before_all_runners(const Input_para& inp, UnitCell& } //! 6) Setup the k points according to symmetry. - this->kv.set(ucell.symm, PARAM.inp.kpoint_file, GlobalV::NSPIN, ucell.G, ucell.latvec, GlobalV::ofs_running); + this->kv.set(ucell.symm, PARAM.inp.kpoint_file, PARAM.inp.nspin, ucell.G, ucell.latvec, GlobalV::ofs_running); ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "INIT K-POINTS"); @@ -423,7 +423,7 @@ void ESolver_KS::runner(const int istep, UnitCell& ucell) this->niter = this->maxniter; // 4) SCF iterations - double diag_ethr = GlobalV::PW_DIAG_THR; + double diag_ethr = PARAM.inp.pw_diag_thr; std::cout << " * * * * * *\n << Start SCF iteration." << std::endl; for (int iter = 1; iter <= this->maxniter; ++iter) @@ -447,7 +447,7 @@ void ESolver_KS::runner(const int istep, UnitCell& ucell) istep, iter, drho, - GlobalV::PW_DIAG_THR, + PARAM.inp.pw_diag_thr, diag_ethr, GlobalV::nelec); } @@ -460,7 +460,7 @@ void ESolver_KS::runner(const int istep, UnitCell& ucell) istep, iter, drho, - GlobalV::PW_DIAG_THR, + PARAM.inp.pw_diag_thr, diag_ethr, GlobalV::NBANDS, esolver_KS_ne); @@ -696,7 +696,7 @@ void ESolver_KS::print_head() { std::cout << " " << std::setw(7) << "ITER"; - if (GlobalV::NSPIN == 2) + if (PARAM.inp.nspin == 2) { std::cout << std::setw(10) << "TMAG"; std::cout << std::setw(10) << "AMAG"; diff --git a/source/module_esolver/esolver_ks_lcao.cpp b/source/module_esolver/esolver_ks_lcao.cpp index 56c564dd97..5bca940644 100644 --- a/source/module_esolver/esolver_ks_lcao.cpp +++ b/source/module_esolver/esolver_ks_lcao.cpp @@ -134,7 +134,7 @@ void ESolver_KS_LCAO::before_all_runners(const Input_para& inp, UnitCell // 1.3) Setup k-points according to symmetry. this->kv - .set(ucell.symm, PARAM.inp.kpoint_file, GlobalV::NSPIN, ucell.G, ucell.latvec, GlobalV::ofs_running); + .set(ucell.symm, PARAM.inp.kpoint_file, PARAM.inp.nspin, ucell.G, ucell.latvec, GlobalV::ofs_running); ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "INIT K-POINTS"); Print_Info::setup_parameters(ucell, this->kv); @@ -179,7 +179,7 @@ void ESolver_KS_LCAO::before_all_runners(const Input_para& inp, UnitCell // DensityMatrix is allocated here, DMK is also initialized here // DMR is not initialized here, it will be constructed in each before_scf dynamic_cast*>(this->pelec) - ->init_DM(&this->kv, &(this->pv), GlobalV::NSPIN); + ->init_DM(&this->kv, &(this->pv), PARAM.inp.nspin); // this function should be removed outside of the function if (PARAM.inp.calculation == "get_S") @@ -219,7 +219,7 @@ void ESolver_KS_LCAO::before_all_runners(const Input_para& inp, UnitCell GlobalC::ppcell.init_vloc(GlobalC::ppcell.vloc, this->pw_rho); // 11) inititlize the charge density - this->pelec->charge->allocate(GlobalV::NSPIN); + this->pelec->charge->allocate(PARAM.inp.nspin); this->pelec->omega = GlobalC::ucell.omega; // 12) initialize the potential @@ -301,7 +301,7 @@ void ESolver_KS_LCAO::cal_force(ModuleBase::matrix& force) Force_Stress_LCAO fsl(this->RA, GlobalC::ucell.nat); fsl.getForceStress(PARAM.inp.cal_force, - GlobalV::CAL_STRESS, + PARAM.inp.cal_stress, PARAM.inp.test_force, PARAM.inp.test_stress, this->pv, @@ -405,7 +405,7 @@ void ESolver_KS_LCAO::after_all_runners() ModuleIO::write_istate_info(this->pelec->ekb, this->pelec->wg, this->kv, &(GlobalC::Pkpoints)); } - const int nspin0 = (GlobalV::NSPIN == 2) ? 2 : 1; + const int nspin0 = (PARAM.inp.nspin == 2) ? 2 : 1; if (PARAM.inp.out_band[0]) { @@ -449,7 +449,7 @@ void ESolver_KS_LCAO::after_all_runners() if (PARAM.inp.out_mat_xc) { - ModuleIO::write_Vxc(GlobalV::NSPIN, + ModuleIO::write_Vxc(PARAM.inp.nspin, GlobalV::NLOCAL, GlobalV::DRANK, &this->pv, @@ -475,7 +475,7 @@ void ESolver_KS_LCAO::after_all_runners() if (PARAM.inp.out_eband_terms) { - ModuleIO::write_eband_terms(GlobalV::NSPIN, + ModuleIO::write_eband_terms(PARAM.inp.nspin, GlobalV::NLOCAL, GlobalV::DRANK, &this->pv, @@ -602,7 +602,7 @@ void ESolver_KS_LCAO::iter_init(const int istep, const int iter) // rho1 and rho2 are the same rho. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - if (GlobalV::NSPIN == 4) + if (PARAM.inp.nspin == 4) { GlobalC::ucell.cal_ux(); } @@ -711,7 +711,7 @@ void ESolver_KS_LCAO::hamilt2density(int istep, int iter, double ethr) if (PARAM.inp.out_bandgap) { - if (!GlobalV::TWO_EFERMI) + if (!PARAM.globalv.two_fermi) { this->pelec->cal_bandgap(); } @@ -782,7 +782,7 @@ void ESolver_KS_LCAO::hamilt2density(int istep, int iter, double ethr) // 10) symmetrize the charge density Symmetry_rho srho; - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { srho.begin(is, *(this->pelec->charge), this->pw_rho, GlobalC::ucell.symm); } @@ -883,7 +883,7 @@ void ESolver_KS_LCAO::update_pot(const int istep, const int iter) if (!this->conv_elec) { - if (GlobalV::NSPIN == 4) + if (PARAM.inp.nspin == 4) { GlobalC::ucell.cal_ux(); } @@ -925,7 +925,7 @@ void ESolver_KS_LCAO::iter_finish(int& iter) // Peize Lin add 2020.04.04 if (GlobalC::restart.info_save.save_charge) { - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { GlobalC::restart.save_disk("charge", is, this->pelec->charge->nrxx, this->pelec->charge->rho[is]); } @@ -1005,7 +1005,7 @@ void ESolver_KS_LCAO::iter_finish(int& iter) // 4) output charge density and density matrix if (this->out_freq_elec && iter % this->out_freq_elec == 0) { - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { double* data = nullptr; if (PARAM.inp.dm_to_rho) @@ -1026,7 +1026,7 @@ void ESolver_KS_LCAO::iter_finish(int& iter) #endif data, is, - GlobalV::NSPIN, + PARAM.inp.nspin, 0, fn, this->pw_rhod->nx, @@ -1048,7 +1048,7 @@ void ESolver_KS_LCAO::iter_finish(int& iter) #endif this->pelec->charge->kin_r_save[is], is, - GlobalV::NSPIN, + PARAM.inp.nspin, 0, fn, this->pw_rhod->nx, @@ -1111,7 +1111,7 @@ void ESolver_KS_LCAO::after_scf(const int istep) // 3) write density matrix if (PARAM.inp.out_dm) { - std::vector efermis(GlobalV::NSPIN == 2 ? 2 : 1); + std::vector efermis(PARAM.inp.nspin == 2 ? 2 : 1); for (int ispin = 0; ispin < efermis.size(); ispin++) { efermis[ispin] = this->pelec->eferm.get_efval(ispin); @@ -1184,7 +1184,7 @@ void ESolver_KS_LCAO::after_scf(const int istep) std::string zipname = "output_HR0.npz"; this->output_mat_npz(zipname, *(p_ham_lcao->getHR())); - if (GlobalV::NSPIN == 2) + if (PARAM.inp.nspin == 2) { this->p_hamilt->updateHk(this->kv.get_nks() / 2); // the other half of k points, down spin hamilt::HamiltLCAO, double>* p_ham_lcao @@ -1202,7 +1202,7 @@ void ESolver_KS_LCAO::after_scf(const int istep) std::string zipname = "output_DM0.npz"; this->output_mat_npz(zipname, *(dm->get_DMR_pointer(1))); - if (GlobalV::NSPIN == 2) + if (PARAM.inp.nspin == 2) { zipname = "output_DM1.npz"; this->output_mat_npz(zipname, *(dm->get_DMR_pointer(2))); @@ -1230,7 +1230,7 @@ void ESolver_KS_LCAO::after_scf(const int istep) } // 16) delete grid - if (!PARAM.inp.cal_force && !GlobalV::CAL_STRESS) + if (!PARAM.inp.cal_force && !PARAM.inp.cal_stress) { RA.delete_grid(); } @@ -1263,7 +1263,7 @@ void ESolver_KS_LCAO::after_scf(const int istep) &GlobalC::GridD, two_center_bundle_.kinetic_orb.get()); - const int nspin_k = (GlobalV::NSPIN == 2 ? 2 : 1); + const int nspin_k = (PARAM.inp.nspin == 2 ? 2 : 1); for (int ik = 0; ik < this->kv.get_nks() / nspin_k; ++ik) { ekinetic->init(ik); diff --git a/source/module_esolver/esolver_ks_lcao_tddft.cpp b/source/module_esolver/esolver_ks_lcao_tddft.cpp index 0d55e8a470..2baa7d713d 100644 --- a/source/module_esolver/esolver_ks_lcao_tddft.cpp +++ b/source/module_esolver/esolver_ks_lcao_tddft.cpp @@ -100,10 +100,10 @@ void ESolver_KS_LCAO_TDDFT::before_all_runners(const Input_para& inp, UnitCell& // 6) initialize Density Matrix - dynamic_cast>*>(this->pelec)->init_DM(&kv, &this->pv, GlobalV::NSPIN); + dynamic_cast>*>(this->pelec)->init_DM(&kv, &this->pv, PARAM.inp.nspin); // 8) initialize the charge density - this->pelec->charge->allocate(GlobalV::NSPIN); + this->pelec->charge->allocate(PARAM.inp.nspin); this->pelec->omega = GlobalC::ucell.omega; // this line is very odd. // 9) initializee the potential @@ -214,7 +214,7 @@ void ESolver_KS_LCAO_TDDFT::hamilt2density(const int istep, const int iter, cons if (istep <= 1) { Symmetry_rho srho; - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { srho.begin(is, *(pelec->charge), pw_rho, GlobalC::ucell.symm); } @@ -297,7 +297,7 @@ void ESolver_KS_LCAO_TDDFT::update_pot(const int istep, const int iter) // Calculate new potential according to new Charge Density if (!this->conv_elec) { - if (GlobalV::NSPIN == 4) + if (PARAM.inp.nspin == 4) { GlobalC::ucell.cal_ux(); } @@ -405,7 +405,7 @@ void ESolver_KS_LCAO_TDDFT::update_pot(const int istep, const int iter) void ESolver_KS_LCAO_TDDFT::after_scf(const int istep) { - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { if (module_tddft::Evolve_elec::out_dipole == 1) { diff --git a/source/module_esolver/esolver_ks_lcaopw.cpp b/source/module_esolver/esolver_ks_lcaopw.cpp index c334f15916..c91e8414a5 100644 --- a/source/module_esolver/esolver_ks_lcaopw.cpp +++ b/source/module_esolver/esolver_ks_lcaopw.cpp @@ -148,7 +148,7 @@ namespace ModuleESolver if (PARAM.inp.out_bandgap) { - if (!GlobalV::TWO_EFERMI) + if (!PARAM.globalv.two_fermi) { this->pelec->cal_bandgap(); } @@ -172,7 +172,7 @@ namespace ModuleESolver this->pelec->cal_energies(1); Symmetry_rho srho; - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { srho.begin(is, *(this->pelec->charge), this->pw_rhod, GlobalC::ucell.symm); } @@ -261,7 +261,7 @@ namespace ModuleESolver #ifdef __LCAO if (PARAM.inp.out_mat_xc) { - ModuleIO::write_Vxc(GlobalV::NSPIN, GlobalV::NLOCAL, + ModuleIO::write_Vxc(PARAM.inp.nspin, GlobalV::NLOCAL, GlobalV::DRANK, *this->kspw_psi, GlobalC::ucell, this->sf, *this->pw_wfc, *this->pw_rho, *this->pw_rhod, GlobalC::ppcell.vloc, *this->pelec->charge, this->kv, this->pelec->wg diff --git a/source/module_esolver/esolver_ks_pw.cpp b/source/module_esolver/esolver_ks_pw.cpp index a5dbacac83..f8d4e512e8 100644 --- a/source/module_esolver/esolver_ks_pw.cpp +++ b/source/module_esolver/esolver_ks_pw.cpp @@ -122,7 +122,7 @@ void ESolver_KS_PW::before_all_runners(const Input_para& inp, UnitCel } //! 4) inititlize the charge density. - this->pelec->charge->allocate(GlobalV::NSPIN); + this->pelec->charge->allocate(PARAM.inp.nspin); //! 5) set the cell volume variable in pelec this->pelec->omega = ucell.omega; @@ -213,7 +213,7 @@ void ESolver_KS_PW::before_scf(const int istep) //! cal_ux should be called before init_scf because //! the direction of ux is used in noncoline_rho - if (GlobalV::NSPIN == 4 && PARAM.globalv.domag) + if (PARAM.inp.nspin == 4 && PARAM.globalv.domag) { GlobalC::ucell.cal_ux(); } @@ -224,7 +224,7 @@ void ESolver_KS_PW::before_scf(const int istep) //! output the initial charge density if (PARAM.inp.out_chg[0] == 2) { - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { std::stringstream ss; ss << PARAM.globalv.global_out_dir << "SPIN" << is + 1 << "_CHG_INI.cube"; @@ -237,7 +237,7 @@ void ESolver_KS_PW::before_scf(const int istep) #endif this->pelec->charge->rho[is], is, - GlobalV::NSPIN, + PARAM.inp.nspin, istep, ss.str(), this->pw_rhod->nx, @@ -251,7 +251,7 @@ void ESolver_KS_PW::before_scf(const int istep) //! output total local potential of the initial charge density if (PARAM.inp.out_pot == 3) { - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { std::stringstream ss; ss << PARAM.globalv.global_out_dir << "SPIN" << is + 1 << "_POT_INI.cube"; @@ -264,7 +264,7 @@ void ESolver_KS_PW::before_scf(const int istep) #endif this->pelec->pot->get_effective_v(is), is, - GlobalV::NSPIN, + PARAM.inp.nspin, istep, ss.str(), this->pw_rhod->nx, @@ -281,7 +281,7 @@ void ESolver_KS_PW::before_scf(const int istep) //! initialized first. liuyu comment: Symmetry_rho should be located between //! init_rho and v_of_rho? Symmetry_rho srho; - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { srho.begin(is, *(this->pelec->charge), this->pw_rhod, GlobalC::ucell.symm); } @@ -370,7 +370,7 @@ void ESolver_KS_PW::hamilt2density(const int istep, const int iter, c PARAM.inp.ks_solver, PARAM.inp.use_paw, GlobalV::use_uspp, - GlobalV::NSPIN, + PARAM.inp.nspin, hsolver::DiagoIterAssist::SCF_ITER, hsolver::DiagoIterAssist::PW_DIAG_NMAX, @@ -392,7 +392,7 @@ void ESolver_KS_PW::hamilt2density(const int istep, const int iter, c if (PARAM.inp.out_bandgap) { - if (!GlobalV::TWO_EFERMI) + if (!PARAM.globalv.two_fermi) { this->pelec->cal_bandgap(); } @@ -409,7 +409,7 @@ void ESolver_KS_PW::hamilt2density(const int istep, const int iter, c this->pelec->cal_energies(1); Symmetry_rho srho; - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { srho.begin(is, *(this->pelec->charge), this->pw_rhod, GlobalC::ucell.symm); } @@ -434,7 +434,7 @@ void ESolver_KS_PW::update_pot(const int istep, const int iter) { if (!this->conv_elec) { - if (GlobalV::NSPIN == 4) + if (PARAM.inp.nspin == 4) { GlobalC::ucell.cal_ux(); } @@ -467,7 +467,7 @@ void ESolver_KS_PW::iter_finish(int& iter) { if (PARAM.inp.out_chg[0] > 0) { - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { double* data = nullptr; if (PARAM.inp.dm_to_rho) @@ -488,7 +488,7 @@ void ESolver_KS_PW::iter_finish(int& iter) #endif data, is, - GlobalV::NSPIN, + PARAM.inp.nspin, 0, fn, this->pw_rhod->nx, @@ -510,7 +510,7 @@ void ESolver_KS_PW::iter_finish(int& iter) #endif this->pelec->charge->kin_r_save[is], is, - GlobalV::NSPIN, + PARAM.inp.nspin, 0, fn, this->pw_rhod->nx, @@ -564,7 +564,7 @@ void ESolver_KS_PW::after_scf(const int istep) { ModuleIO::get_pchg_pw(bands_to_print, this->kspw_psi->get_nbands(), - GlobalV::NSPIN, + PARAM.inp.nspin, this->pw_rhod->nx, this->pw_rhod->ny, this->pw_rhod->nz, @@ -693,7 +693,7 @@ void ESolver_KS_PW::after_all_runners() } int nspin0 = 1; - if (GlobalV::NSPIN == 2) + if (PARAM.inp.nspin == 2) { nspin0 = 2; } diff --git a/source/module_esolver/esolver_of.cpp b/source/module_esolver/esolver_of.cpp index db27c528ec..edd50a6962 100644 --- a/source/module_esolver/esolver_of.cpp +++ b/source/module_esolver/esolver_of.cpp @@ -29,7 +29,7 @@ ESolver_OF::~ESolver_OF() delete psi_; delete[] this->pphi_; - for (int i = 0; i < GlobalV::NSPIN; ++i) + for (int i = 0; i < PARAM.inp.nspin; ++i) { delete[] this->pdirect_[i]; delete[] this->pdLdphi_[i]; @@ -88,7 +88,7 @@ void ESolver_OF::before_all_runners(const Input_para& inp, UnitCell& ucell) } // Setup the k points according to symmetry. - kv.set(ucell.symm, PARAM.inp.kpoint_file, GlobalV::NSPIN, ucell.G, ucell.latvec, GlobalV::ofs_running); + kv.set(ucell.symm, PARAM.inp.kpoint_file, PARAM.inp.nspin, ucell.G, ucell.latvec, GlobalV::ofs_running); ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "INIT K-POINTS"); // print information @@ -132,12 +132,12 @@ void ESolver_OF::before_all_runners(const Input_para& inp, UnitCell& ucell) // Initialize KEDF // Calculate electron numbers, which will be used to initialize WT KEDF - this->nelec_ = new double[GlobalV::NSPIN]; - if (GlobalV::NSPIN == 1) + this->nelec_ = new double[PARAM.inp.nspin]; + if (PARAM.inp.nspin == 1) { this->nelec_[0] = GlobalV::nelec; } - else if (GlobalV::NSPIN == 2) + else if (PARAM.inp.nspin == 2) { // in fact, nelec_spin will not be used anymore this->pelec->init_nelec_spin(); @@ -190,8 +190,8 @@ void ESolver_OF::init_after_vc(const Input_para& inp, UnitCell& ucell) // Refresh the arrays delete this->psi_; - this->psi_ = new psi::Psi(1, GlobalV::NSPIN, this->pw_rho->nrxx); - for (int is = 0; is < GlobalV::NSPIN; ++is) + this->psi_ = new psi::Psi(1, PARAM.inp.nspin, this->pw_rho->nrxx); + for (int is = 0; is < PARAM.inp.nspin; ++is) { this->pphi_[is] = this->psi_->get_pointer(is); } @@ -199,9 +199,9 @@ void ESolver_OF::init_after_vc(const Input_para& inp, UnitCell& ucell) delete this->ptemp_rho_; this->ptemp_rho_ = new Charge(); this->ptemp_rho_->set_rhopw(this->pw_rho); - this->ptemp_rho_->allocate(GlobalV::NSPIN); + this->ptemp_rho_->allocate(PARAM.inp.nspin); - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { delete[] this->pdLdphi_[is]; delete[] this->pdEdphi_[is]; @@ -285,12 +285,12 @@ void ESolver_OF::before_opt(const int istep, UnitCell& ucell) this->pelec->f_en.ewald_energy = H_Ewald_pw::compute_ewald(ucell, this->pw_rho, sf.strucFac); Symmetry_rho srho; - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { srho.begin(is, *(pelec->charge), this->pw_rho, GlobalC::ucell.symm); } - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { if (PARAM.inp.init_chg != "file") { @@ -311,7 +311,7 @@ void ESolver_OF::before_opt(const int istep, UnitCell& ucell) } } - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { this->pelec->eferm.get_ef(is) = 0.; this->theta_[is] = 0.; @@ -319,7 +319,7 @@ void ESolver_OF::before_opt(const int istep, UnitCell& ucell) ModuleBase::GlobalFunc::ZEROS(this->pdEdphi_[is], this->pw_rho->nrxx); ModuleBase::GlobalFunc::ZEROS(this->pdirect_[is], this->pw_rho->nrxx); } - if (GlobalV::NSPIN == 1) + if (PARAM.inp.nspin == 1) { this->theta_[0] = 0.2; } @@ -334,7 +334,7 @@ void ESolver_OF::before_opt(const int istep, UnitCell& ucell) void ESolver_OF::update_potential(UnitCell& ucell) { // (1) get dL/dphi - if (GlobalV::NSPIN == 4) + if (PARAM.inp.nspin == 4) { ucell.cal_ux(); } @@ -343,7 +343,7 @@ void ESolver_OF::update_potential(UnitCell& ucell) this->kinetic_potential(pelec->charge->rho, this->pphi_, this->pelec->pot->get_effective_v()); // (kinetic + Hartree + XC + external) * 2 * phi - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { const double* vr_eff = this->pelec->pot->get_effective_v(is); for (int ir = 0; ir < this->pw_rho->nrxx; ++ir) @@ -366,12 +366,12 @@ void ESolver_OF::update_potential(UnitCell& ucell) // =========================================================================== this->normdLdphi_ = 0.; - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { this->normdLdphi_ += this->inner_product(this->pdLdphi_[is], this->pdLdphi_[is], this->pw_rho->nrxx, 1.0); } Parallel_Reduce::reduce_all(this->normdLdphi_); - this->normdLdphi_ = sqrt(this->normdLdphi_ / this->pw_rho->nxyz / GlobalV::NSPIN); + this->normdLdphi_ = sqrt(this->normdLdphi_ / this->pw_rho->nxyz / PARAM.inp.nspin); } /** @@ -384,8 +384,8 @@ void ESolver_OF::optimize(UnitCell& ucell) // (1) get |d0> with optimization algorithm this->get_direction(); // initialize temp_phi and temp_rho used in line search - double** ptemp_phi = new double*[GlobalV::NSPIN]; - for (int is = 0; is < GlobalV::NSPIN; ++is) + double** ptemp_phi = new double*[PARAM.inp.nspin]; + for (int is = 0; is < PARAM.inp.nspin; ++is) { ptemp_phi[is] = new double[this->pw_rho->nrxx]; for (int ir = 0; ir < this->pw_rho->nrxx; ++ir) @@ -399,8 +399,8 @@ void ESolver_OF::optimize(UnitCell& ucell) this->adjust_direction(); // (3) make sure that dEdtheta<0 at theta = 0 - double* dEdtheta = new double[GlobalV::NSPIN]; // dE/dtheta of tempPhi - ModuleBase::GlobalFunc::ZEROS(dEdtheta, GlobalV::NSPIN); + double* dEdtheta = new double[PARAM.inp.nspin]; // dE/dtheta of tempPhi + ModuleBase::GlobalFunc::ZEROS(dEdtheta, PARAM.inp.nspin); this->check_direction(dEdtheta, ptemp_phi, ucell); // this->test_direction(dEdtheta, ptemp_phi, ucell); @@ -408,7 +408,7 @@ void ESolver_OF::optimize(UnitCell& ucell) // (4) call line search to find the best theta (step length) this->get_step_length(dEdtheta, ptemp_phi, ucell); - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { delete[] ptemp_phi[is]; } @@ -423,7 +423,7 @@ void ESolver_OF::optimize(UnitCell& ucell) */ void ESolver_OF::update_rho() { - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { for (int ir = 0; ir < this->pw_rho->nrxx; ++ir) { @@ -436,7 +436,7 @@ void ESolver_OF::update_rho() // if (ModuleSymmetry::Symmetry::symm_flag == 1) // { // Symmetry_rho srho; - // for (int is = 0; is < GlobalV::NSPIN; is++) + // for (int is = 0; is < PARAM.inp.nspin; is++) // { // srho.begin(is, *(pelec->charge), this->pw_rho, GlobalC::Pgrid, GlobalC::ucell.symm); // for (int ibs = 0; ibs < this->pw_rho->nrxx; ++ibs) @@ -537,7 +537,7 @@ double ESolver_OF::cal_energy() this->pelec->cal_energies(2); double kinetic_energy = this->kinetic_energy(); // kinetic energy double pseudopot_energy = 0.; // electron-ion interaction energy - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { pseudopot_energy += this->inner_product(this->pelec->pot->get_fixed_v(), pelec->charge->rho[is], diff --git a/source/module_esolver/esolver_of_interface.cpp b/source/module_esolver/esolver_of_interface.cpp index 8d766e2f6e..d5d76d9236 100644 --- a/source/module_esolver/esolver_of_interface.cpp +++ b/source/module_esolver/esolver_of_interface.cpp @@ -1,5 +1,6 @@ #include "esolver_of.h" #include "module_hamilt_pw/hamilt_pwdft/global.h" +#include "module_parameter/parameter.h" namespace ModuleESolver { @@ -87,7 +88,7 @@ void ESolver_OF::kinetic_potential(double** prho, double** pphi, ModuleBase::mat } // Before call vw_potential, change rpot to rpot * 2 * pphi - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { for (int ir = 0; ir < this->pw_rho->nrxx; ++ir) { @@ -215,10 +216,10 @@ void ESolver_OF::init_opt() } // optimize theta if nspin=2 - if (GlobalV::NSPIN == 2) + if (PARAM.inp.nspin == 2) { this->opt_cg_mag_ = new ModuleBase::Opt_CG; - this->opt_cg_mag_->allocate(GlobalV::NSPIN); + this->opt_cg_mag_->allocate(PARAM.inp.nspin); } } @@ -228,7 +229,7 @@ void ESolver_OF::init_opt() */ void ESolver_OF::get_direction() { - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { if (this->of_method_ == "tn") { @@ -273,7 +274,7 @@ void ESolver_OF::get_step_length(double* dEdtheta, double** ptemp_phi, UnitCell& double kinetic_energy = 0.0; // kinetic energy double pseudopot_energy = 0.0; // electron-ion interaction energy - if (GlobalV::NSPIN == 1) + if (PARAM.inp.nspin == 1) { int numDC = 0; // iteration number of line search strcpy(this->task_, "START"); @@ -333,16 +334,16 @@ void ESolver_OF::get_step_length(double* dEdtheta, double** ptemp_phi, UnitCell& } } } - else if (GlobalV::NSPIN == 2) + else if (PARAM.inp.nspin == 2) { ModuleBase::WARNING_QUIT("esolver_of", "Sorry, SPIN2 case is not supported by OFDFT for now."); // ========================== Under testing ========================== // this->opt_cg_mag_->refresh(); - // double *pthetaDir = new double[GlobalV::NSPIN]; - // double *temp_theta = new double[GlobalV::NSPIN]; - // ModuleBase::GlobalFunc::ZEROS(pthetaDir, GlobalV::NSPIN); - // ModuleBase::GlobalFunc::ZEROS(temp_theta, GlobalV::NSPIN); + // double *pthetaDir = new double[PARAM.inp.nspin]; + // double *temp_theta = new double[PARAM.inp.nspin]; + // ModuleBase::GlobalFunc::ZEROS(pthetaDir, PARAM.inp.nspin); + // ModuleBase::GlobalFunc::ZEROS(temp_theta, PARAM.inp.nspin); // double thetaAlpha = 0.; // double alphaTol = 1e-4; // double maxThetaDir = 0.; @@ -358,7 +359,7 @@ void ESolver_OF::get_step_length(double* dEdtheta, double** ptemp_phi, UnitCell& // if (dEdalpha >= 0.) // { - // for (int is = 0; is < GlobalV::NSPIN; ++is) + // for (int is = 0; is < PARAM.inp.nspin; ++is) // { // pthetaDir[is] = -dEdtheta[is]; // } @@ -379,7 +380,7 @@ void ESolver_OF::get_step_length(double* dEdtheta, double** ptemp_phi, UnitCell& // this->pw_rho->nxyz); temp_energy = // this->pelec->f_en.etot; kinetic_energy = // this->kinetic_energy(); pseudopot_energy = 0.; for (int - // is = 0; is < GlobalV::NSPIN; ++is) { + // is = 0; is < PARAM.inp.nspin; ++is) { // pseudopot_energy += // this->inner_product(GlobalC::pot.vltot, // ptemp_rho_[is], this->pw_rho->nrxx, this->dV_); @@ -391,7 +392,7 @@ void ESolver_OF::get_step_length(double* dEdtheta, double** ptemp_phi, UnitCell& // if (strncmp(this->task_, "FG", 2) == 0) // { - // for (int is = 0; is < GlobalV::NSPIN; ++is) + // for (int is = 0; is < PARAM.inp.nspin; ++is) // { // temp_theta[is] = this->theta_[is] + thetaAlpha * // pthetaDir[is]; for (int ir = 0; ir < @@ -433,7 +434,7 @@ void ESolver_OF::get_step_length(double* dEdtheta, double** ptemp_phi, UnitCell& // } // } - // for (int is = 0; is < GlobalV::NSPIN; ++is) this->theta_[is] + // for (int is = 0; is < PARAM.inp.nspin; ++is) this->theta_[is] // += thetaAlpha * pthetaDir[is]; if (sqrt(dEdtheta[0] * // dEdtheta[0] + dEdtheta[1] * dEdtheta[1]) < alphaTol) break; // thetaIter++; @@ -443,7 +444,7 @@ void ESolver_OF::get_step_length(double* dEdtheta, double** ptemp_phi, UnitCell& // delete[] pthetaDir; // ========================== Under testing ========================== } - else if (GlobalV::NSPIN == 4) + else if (PARAM.inp.nspin == 4) { ModuleBase::WARNING_QUIT("esolver_of", "Sorry, SPIN4 case is not supported by OFDFT for now."); } diff --git a/source/module_esolver/esolver_of_tool.cpp b/source/module_esolver/esolver_of_tool.cpp index 25922a91fe..5d307bff1f 100644 --- a/source/module_esolver/esolver_of_tool.cpp +++ b/source/module_esolver/esolver_of_tool.cpp @@ -19,7 +19,7 @@ void ESolver_OF::init_elecstate(UnitCell& ucell) if (this->pelec == nullptr) { this->pelec = new elecstate::ElecState((Charge*)(&chr), this->pw_rho, pw_big); - this->pelec->charge->allocate(GlobalV::NSPIN); + this->pelec->charge->allocate(PARAM.inp.nspin); } this->pelec->omega = ucell.omega; @@ -69,10 +69,10 @@ void ESolver_OF::init_elecstate(UnitCell& ucell) void ESolver_OF::allocate_array() { // Initialize the "wavefunction", which is sqrt(rho) - this->psi_ = new psi::Psi(1, GlobalV::NSPIN, this->pw_rho->nrxx); - ModuleBase::Memory::record("OFDFT::Psi", sizeof(double) * GlobalV::NSPIN * this->pw_rho->nrxx); - this->pphi_ = new double*[GlobalV::NSPIN]; - for (int is = 0; is < GlobalV::NSPIN; ++is) + this->psi_ = new psi::Psi(1, PARAM.inp.nspin, this->pw_rho->nrxx); + ModuleBase::Memory::record("OFDFT::Psi", sizeof(double) * PARAM.inp.nspin * this->pw_rho->nrxx); + this->pphi_ = new double*[PARAM.inp.nspin]; + for (int is = 0; is < PARAM.inp.nspin; ++is) { this->pphi_[is] = this->psi_->get_pointer(is); } @@ -82,25 +82,25 @@ void ESolver_OF::allocate_array() delete this->ptemp_rho_; this->ptemp_rho_ = new Charge(); this->ptemp_rho_->set_rhopw(this->pw_rho); - this->ptemp_rho_->allocate(GlobalV::NSPIN); + this->ptemp_rho_->allocate(PARAM.inp.nspin); - this->theta_ = new double[GlobalV::NSPIN]; - this->pdLdphi_ = new double*[GlobalV::NSPIN]; - this->pdEdphi_ = new double*[GlobalV::NSPIN]; - this->pdirect_ = new double*[GlobalV::NSPIN]; - this->precip_dir_ = new std::complex*[GlobalV::NSPIN]; + this->theta_ = new double[PARAM.inp.nspin]; + this->pdLdphi_ = new double*[PARAM.inp.nspin]; + this->pdEdphi_ = new double*[PARAM.inp.nspin]; + this->pdirect_ = new double*[PARAM.inp.nspin]; + this->precip_dir_ = new std::complex*[PARAM.inp.nspin]; - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { this->pdLdphi_[is] = new double[this->pw_rho->nrxx]; this->pdEdphi_[is] = new double[this->pw_rho->nrxx]; this->pdirect_[is] = new double[this->pw_rho->nrxx]; this->precip_dir_[is] = new std::complex[pw_rho->npw]; } - ModuleBase::Memory::record("OFDFT::pdLdphi_", sizeof(double) * GlobalV::NSPIN * this->pw_rho->nrxx); - ModuleBase::Memory::record("OFDFT::pdEdphi_", sizeof(double) * GlobalV::NSPIN * this->pw_rho->nrxx); - ModuleBase::Memory::record("OFDFT::pdirect_", sizeof(double) * GlobalV::NSPIN * this->pw_rho->nrxx); - ModuleBase::Memory::record("OFDFT::precip_dir_", sizeof(std::complex) * GlobalV::NSPIN * this->pw_rho->npw); + ModuleBase::Memory::record("OFDFT::pdLdphi_", sizeof(double) * PARAM.inp.nspin * this->pw_rho->nrxx); + ModuleBase::Memory::record("OFDFT::pdEdphi_", sizeof(double) * PARAM.inp.nspin * this->pw_rho->nrxx); + ModuleBase::Memory::record("OFDFT::pdirect_", sizeof(double) * PARAM.inp.nspin * this->pw_rho->nrxx); + ModuleBase::Memory::record("OFDFT::precip_dir_", sizeof(std::complex) * PARAM.inp.nspin * this->pw_rho->npw); } /** @@ -112,10 +112,10 @@ void ESolver_OF::allocate_array() */ void ESolver_OF::cal_potential(double* ptemp_phi, double* rdLdphi) { - double** dEdtemp_phi = new double*[GlobalV::NSPIN]; - double** temp_phi = new double*[GlobalV::NSPIN]; + double** dEdtemp_phi = new double*[PARAM.inp.nspin]; + double** temp_phi = new double*[PARAM.inp.nspin]; - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { dEdtemp_phi[is] = new double[this->pw_rho->nrxx]; if (is == this->tn_spin_flag_) @@ -132,7 +132,7 @@ void ESolver_OF::cal_potential(double* ptemp_phi, double* rdLdphi) } } - if (GlobalV::NSPIN == 4) + if (PARAM.inp.nspin == 4) { GlobalC::ucell.cal_ux(); } @@ -149,7 +149,7 @@ void ESolver_OF::cal_potential(double* ptemp_phi, double* rdLdphi) { rdLdphi[i] = dEdtemp_phi[this->tn_spin_flag_][i] - 2. * temp_mu * ptemp_phi[i]; } - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { delete[] dEdtemp_phi[is]; } @@ -172,14 +172,14 @@ void ESolver_OF::cal_dEdtheta(double** ptemp_phi, Charge* temp_rho, UnitCell& uc { double* dphi_dtheta = new double[this->pw_rho->nrxx]; - if (GlobalV::NSPIN == 4) { + if (PARAM.inp.nspin == 4) { ucell.cal_ux(); } this->pelec->pot->update_from_charge(temp_rho, &ucell); ModuleBase::matrix& vr_eff = this->pelec->pot->get_effective_v(); this->kinetic_potential(temp_rho->rho, ptemp_phi, vr_eff); - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { for (int ir = 0; ir < this->pw_rho->nrxx; ++ir) { @@ -218,14 +218,14 @@ void ESolver_OF::adjust_direction() // filter the high frequency term in direction if of_full_pw = false if (!PARAM.inp.of_full_pw) { - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { pw_rho->real2recip(this->pdirect_[is], this->precip_dir_[is]); pw_rho->recip2real(this->precip_dir_[is], this->pdirect_[is]); } } - if (GlobalV::NSPIN == 1) + if (PARAM.inp.nspin == 1) { double temp_theta = 0; // temp_theta = |d'|/|d0 + phi|, theta = min(theta, temp_theta) @@ -256,9 +256,9 @@ void ESolver_OF::adjust_direction() temp_theta = norm_direction / temp_theta; this->theta_[0] = std::min(this->theta_[0], temp_theta); } - else if (GlobalV::NSPIN == 2) // theta = 0 + else if (PARAM.inp.nspin == 2) // theta = 0 { - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { // (1) make direction orthogonal to phi // |d'> = |d0> - |phi>/nelec @@ -296,15 +296,15 @@ void ESolver_OF::adjust_direction() */ void ESolver_OF::check_direction(double* dEdtheta, double** ptemp_phi, UnitCell& ucell) { - assert(GlobalV::NSPIN > 0); - double* temp_theta = new double[GlobalV::NSPIN]; - ModuleBase::GlobalFunc::ZEROS(temp_theta, GlobalV::NSPIN); + assert(PARAM.inp.nspin > 0); + double* temp_theta = new double[PARAM.inp.nspin]; + ModuleBase::GlobalFunc::ZEROS(temp_theta, PARAM.inp.nspin); double max_dEdtheta = 1e5; // threshould of dEdtheta, avoid the unstable optimization this->cal_dEdtheta(ptemp_phi, this->ptemp_rho_, ucell, temp_theta, dEdtheta); // Assert dEdtheta(theta = 0) < 0, otherwise line search will not work. - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { if (dEdtheta[is] > max_dEdtheta) { @@ -501,7 +501,7 @@ void ESolver_OF::print_info() energies_Ry.push_back(this->pelec->f_en.etot); } - if (GlobalV::TWO_EFERMI) + if (PARAM.globalv.two_fermi) { titles.push_back("E_Fermi_up"); energies_Ry.push_back(this->pelec->eferm.get_efval(0)); diff --git a/source/module_esolver/esolver_sdft_pw.cpp b/source/module_esolver/esolver_sdft_pw.cpp index ac82ae1a9a..81f487a912 100644 --- a/source/module_esolver/esolver_sdft_pw.cpp +++ b/source/module_esolver/esolver_sdft_pw.cpp @@ -60,7 +60,7 @@ void ESolver_SDFT_PW::before_all_runners(const Input_para& inp, UnitCell& ucell) pw_big); // 4) inititlize the charge density. - this->pelec->charge->allocate(GlobalV::NSPIN); + this->pelec->charge->allocate(PARAM.inp.nspin); this->pelec->omega = ucell.omega; // 5) initialize the potential. @@ -183,7 +183,7 @@ void ESolver_SDFT_PW::hamilt2density(int istep, int iter, double ethr) PARAM.inp.ks_solver, PARAM.inp.use_paw, GlobalV::use_uspp, - GlobalV::NSPIN, + PARAM.inp.nspin, hsolver::DiagoIterAssist>::SCF_ITER, hsolver::DiagoIterAssist>::PW_DIAG_NMAX, hsolver::DiagoIterAssist>::PW_DIAG_THR, @@ -206,7 +206,7 @@ void ESolver_SDFT_PW::hamilt2density(int istep, int iter, double ethr) if (GlobalV::MY_STOGROUP == 0) { Symmetry_rho srho; - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { srho.begin(is, *(this->pelec->charge), pw_rho, GlobalC::ucell.symm); } diff --git a/source/module_esolver/lcao_before_scf.cpp b/source/module_esolver/lcao_before_scf.cpp index 685880699e..4c2ffb4e2f 100644 --- a/source/module_esolver/lcao_before_scf.cpp +++ b/source/module_esolver/lcao_before_scf.cpp @@ -60,7 +60,7 @@ void ESolver_KS_LCAO::beforesolver(const int istep) int ncol = 0; if (PARAM.globalv.gamma_only_local) { - nsk = GlobalV::NSPIN; + nsk = PARAM.inp.nspin; ncol = this->pv.ncol_bands; if (GlobalV::KS_SOLVER == "genelpa" || GlobalV::KS_SOLVER == "elpa" @@ -154,7 +154,7 @@ void ESolver_KS_LCAO::beforesolver(const int istep) PARAM.inp.sc_file, PARAM.globalv.npol, &(this->pv), - GlobalV::NSPIN, + PARAM.inp.nspin, this->kv, GlobalV::KS_SOLVER, this->p_hamilt, @@ -165,7 +165,7 @@ void ESolver_KS_LCAO::beforesolver(const int istep) // cal_ux should be called before init_scf because // the direction of ux is used in noncoline_rho //========================================================= - if (GlobalV::NSPIN == 4 && PARAM.globalv.domag) + if (PARAM.inp.nspin == 4 && PARAM.globalv.domag) { GlobalC::ucell.cal_ux(); } @@ -223,7 +223,7 @@ void ESolver_KS_LCAO::before_scf(const int istep) //! output the initial charge density if (PARAM.inp.out_chg[0] == 2) { - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { std::stringstream ss; ss << PARAM.globalv.global_out_dir << "SPIN" << is + 1 << "_CHG_INI.cube"; @@ -236,7 +236,7 @@ void ESolver_KS_LCAO::before_scf(const int istep) #endif this->pelec->charge->rho[is], is, - GlobalV::NSPIN, + PARAM.inp.nspin, istep, ss.str(), this->pw_rhod->nx, @@ -250,7 +250,7 @@ void ESolver_KS_LCAO::before_scf(const int istep) //! output total local potential of the initial charge density if (PARAM.inp.out_pot == 3) { - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { std::stringstream ss; ss << PARAM.globalv.global_out_dir << "SPIN" << is + 1 << "_POT_INI.cube"; @@ -263,7 +263,7 @@ void ESolver_KS_LCAO::before_scf(const int istep) #endif this->pelec->pot->get_effective_v(is), is, - GlobalV::NSPIN, + PARAM.inp.nspin, istep, ss.str(), this->pw_rhod->nx, @@ -297,7 +297,7 @@ void ESolver_KS_LCAO::before_scf(const int istep) elecstate::DensityMatrix* dm = dynamic_cast*>(this->pelec)->get_DM(); this->read_mat_npz(zipname, *(dm->get_DMR_pointer(1))); - if (GlobalV::NSPIN == 2) + if (PARAM.inp.nspin == 2) { zipname = "output_DM1.npz"; this->read_mat_npz(zipname, *(dm->get_DMR_pointer(2))); @@ -305,7 +305,7 @@ void ESolver_KS_LCAO::before_scf(const int istep) this->pelec->psiToRho(*this->psi); - int nspin0 = GlobalV::NSPIN == 2 ? 2 : 1; + int nspin0 = PARAM.inp.nspin == 2 ? 2 : 1; for (int is = 0; is < nspin0; is++) { std::string fn = PARAM.globalv.global_out_dir + "/SPIN" + std::to_string(is + 1) + "_CHG.cube"; @@ -318,7 +318,7 @@ void ESolver_KS_LCAO::before_scf(const int istep) #endif this->pelec->charge->rho[is], is, - GlobalV::NSPIN, + PARAM.inp.nspin, istep, fn, this->pw_rhod->nx, @@ -336,7 +336,7 @@ void ESolver_KS_LCAO::before_scf(const int istep) // the electron charge density should be symmetrized, // here is the initialization Symmetry_rho srho; - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { srho.begin(is, *(this->pelec->charge), this->pw_rho, GlobalC::ucell.symm); } diff --git a/source/module_esolver/lcao_fun.cpp b/source/module_esolver/lcao_fun.cpp index f3800190dc..10e2ac1374 100644 --- a/source/module_esolver/lcao_fun.cpp +++ b/source/module_esolver/lcao_fun.cpp @@ -90,21 +90,21 @@ void ESolver_KS_LCAO::cal_mag(const int istep, const bool print) auto cell_index = CellIndex(GlobalC::ucell.get_atomLabels(), GlobalC::ucell.get_atomCounts(), GlobalC::ucell.get_lnchiCounts(), - GlobalV::NSPIN); + PARAM.inp.nspin); auto out_sk = ModuleIO::Output_Sk(this->p_hamilt, &(this->pv), - GlobalV::NSPIN, + PARAM.inp.nspin, this->kv.get_nks()); auto out_dmk = ModuleIO::Output_DMK(dynamic_cast*>(this->pelec)->get_DM(), &(this->pv), - GlobalV::NSPIN, + PARAM.inp.nspin, this->kv.get_nks()); auto mulp = ModuleIO::Output_Mulliken(&(out_sk), &(out_dmk), &(this->pv), &cell_index, this->kv.isk, - GlobalV::NSPIN); + PARAM.inp.nspin); auto atom_chg = mulp.get_atom_chg(); /// used in updating mag info in STRU file GlobalC::ucell.atom_mulliken = mulp.get_atom_mulliken(atom_chg); diff --git a/source/module_esolver/lcao_init_after_vc.cpp b/source/module_esolver/lcao_init_after_vc.cpp index 4f7aa982da..3666cdd6ee 100644 --- a/source/module_esolver/lcao_init_after_vc.cpp +++ b/source/module_esolver/lcao_init_after_vc.cpp @@ -48,11 +48,11 @@ void ESolver_KS_LCAO::init_after_vc(const Input_para& inp, UnitCell& uce this->pw_big); dynamic_cast*>(this->pelec) - ->init_DM(&this->kv, &this->pv, GlobalV::NSPIN); + ->init_DM(&this->kv, &this->pv, PARAM.inp.nspin); GlobalC::ppcell.init_vloc(GlobalC::ppcell.vloc, this->pw_rho); - this->pelec->charge->allocate(GlobalV::NSPIN); + this->pelec->charge->allocate(PARAM.inp.nspin); this->pelec->omega = GlobalC::ucell.omega; // Initialize the potential. diff --git a/source/module_esolver/lcao_nscf.cpp b/source/module_esolver/lcao_nscf.cpp index 24bb100953..bca272e1e4 100644 --- a/source/module_esolver/lcao_nscf.cpp +++ b/source/module_esolver/lcao_nscf.cpp @@ -61,7 +61,7 @@ void ESolver_KS_LCAO::nscf() { GlobalV::ofs_running << " end of band structure calculation " << std::endl; GlobalV::ofs_running << " band eigenvalue in this processor (eV) :" << std::endl; - const int nspin = GlobalV::NSPIN; + const int nspin = PARAM.inp.nspin; const int nbands = GlobalV::NBANDS; for (int ik = 0; ik < this->kv.get_nks(); ++ik) @@ -91,7 +91,7 @@ void ESolver_KS_LCAO::nscf() { } if (PARAM.inp.out_bandgap) { std::cout << FmtCore::format("\n * * * * * *\n << Start %s.\n", "band gap calculation"); - if (!GlobalV::TWO_EFERMI) { + if (!PARAM.globalv.two_fermi) { this->pelec->cal_bandgap(); GlobalV::ofs_running << " E_bandgap " << this->pelec->bandgap * ModuleBase::Ry_to_eV << " eV" << std::endl; } @@ -193,7 +193,7 @@ void ESolver_KS_LCAO::nscf() { /// write potential if (PARAM.inp.out_pot == 1 || PARAM.inp.out_pot == 3) { - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { std::string fn = PARAM.globalv.global_out_dir + "/SPIN" + std::to_string(is + 1) + "_POT.cube"; @@ -206,7 +206,7 @@ void ESolver_KS_LCAO::nscf() { #endif this->pelec->pot->get_effective_v(is), is, - GlobalV::NSPIN, + PARAM.inp.nspin, 0, fn, this->pw_rhod->nx, diff --git a/source/module_esolver/lcao_others.cpp b/source/module_esolver/lcao_others.cpp index d89006321e..994e7d7b58 100644 --- a/source/module_esolver/lcao_others.cpp +++ b/source/module_esolver/lcao_others.cpp @@ -118,7 +118,7 @@ void ESolver_KS_LCAO::others(const int istep) PARAM.inp.bands_to_print, GlobalV::NBANDS, GlobalV::nelec, - GlobalV::NSPIN, + PARAM.inp.nspin, GlobalV::NLOCAL, PARAM.globalv.global_out_dir, GlobalV::MY_RANK, @@ -148,7 +148,7 @@ void ESolver_KS_LCAO::others(const int istep) PARAM.inp.bands_to_print, GlobalV::NBANDS, GlobalV::nelec, - GlobalV::NSPIN, + PARAM.inp.nspin, GlobalV::NLOCAL, PARAM.globalv.global_out_dir, GlobalV::MY_RANK, @@ -181,7 +181,7 @@ void ESolver_KS_LCAO::others(const int istep) PARAM.inp.nbands_istate, PARAM.inp.bands_to_print, GlobalV::NBANDS, - GlobalV::NSPIN, + PARAM.inp.nspin, GlobalV::NLOCAL, PARAM.globalv.global_out_dir); } @@ -200,7 +200,7 @@ void ESolver_KS_LCAO::others(const int istep) PARAM.inp.nbands_istate, PARAM.inp.bands_to_print, GlobalV::NBANDS, - GlobalV::NSPIN, + PARAM.inp.nspin, GlobalV::NLOCAL, PARAM.globalv.global_out_dir); } diff --git a/source/module_esolver/pw_fun.cpp b/source/module_esolver/pw_fun.cpp index 7af9734316..dd22724598 100644 --- a/source/module_esolver/pw_fun.cpp +++ b/source/module_esolver/pw_fun.cpp @@ -88,7 +88,7 @@ void ESolver_KS_PW::hamilt2estates(const double ethr) PARAM.inp.ks_solver, PARAM.inp.use_paw, GlobalV::use_uspp, - GlobalV::NSPIN, + PARAM.inp.nspin, hsolver::DiagoIterAssist::SCF_ITER, hsolver::DiagoIterAssist::PW_DIAG_NMAX, diff --git a/source/module_esolver/pw_init_after_vc.cpp b/source/module_esolver/pw_init_after_vc.cpp index 46acc375ec..27632fae36 100644 --- a/source/module_esolver/pw_init_after_vc.cpp +++ b/source/module_esolver/pw_init_after_vc.cpp @@ -103,7 +103,7 @@ void ESolver_KS_PW::init_after_vc(const Input_para& inp, UnitCell& uc this->pw_rho, this->pw_big); - this->pelec->charge->allocate(GlobalV::NSPIN); + this->pelec->charge->allocate(PARAM.inp.nspin); //! setup cell volume this->pelec->omega = ucell.omega; diff --git a/source/module_esolver/pw_nscf.cpp b/source/module_esolver/pw_nscf.cpp index 811c408f54..acc5534be9 100644 --- a/source/module_esolver/pw_nscf.cpp +++ b/source/module_esolver/pw_nscf.cpp @@ -60,7 +60,7 @@ void ESolver_KS_PW::nscf() { this->before_scf(istep_tmp); //! 2) setup the parameters for diagonalization - double diag_ethr = GlobalV::PW_DIAG_THR; + double diag_ethr = PARAM.inp.pw_diag_thr; if (diag_ethr - 1e-2 > -1e-5) { diag_ethr = std::max(1e-13, @@ -78,7 +78,7 @@ void ESolver_KS_PW::nscf() { //! 4) print out band energies and weights std::cout << FmtCore::format("\n * * * * * *\n << Start %s.\n", "writing band energies"); - const int nspin = GlobalV::NSPIN; + const int nspin = PARAM.inp.nspin; const int nbands = GlobalV::NBANDS; for (int ik = 0; ik < this->kv.get_nks(); ik++) { if (nspin == 2) { @@ -108,7 +108,7 @@ void ESolver_KS_PW::nscf() { //! 5) print out band gaps if (PARAM.inp.out_bandgap) { std::cout << FmtCore::format("\n * * * * * *\n << Start %s.\n", "writing band gaps"); - if (!GlobalV::TWO_EFERMI) { + if (!PARAM.globalv.two_fermi) { this->pelec->cal_bandgap(); GlobalV::ofs_running << " E_bandgap " << this->pelec->bandgap * ModuleBase::Ry_to_eV @@ -162,7 +162,7 @@ void ESolver_KS_PW::nscf() { /// write potential if (PARAM.inp.out_pot == 1 || PARAM.inp.out_pot == 3) { - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { std::string fn = PARAM.globalv.global_out_dir + "/SPIN" + std::to_string(is + 1) + "_POT.cube"; @@ -175,7 +175,7 @@ void ESolver_KS_PW::nscf() { #endif this->pelec->pot->get_effective_v(is), is, - GlobalV::NSPIN, + PARAM.inp.nspin, 0, fn, this->pw_rhod->nx, diff --git a/source/module_hamilt_general/module_surchem/sol_force.cpp b/source/module_hamilt_general/module_surchem/sol_force.cpp index 491a9b331b..68ba6613c5 100644 --- a/source/module_hamilt_general/module_surchem/sol_force.cpp +++ b/source/module_hamilt_general/module_surchem/sol_force.cpp @@ -1,5 +1,6 @@ #include "surchem.h" #include "module_base/timer.h" +#include "module_parameter/parameter.h" void force_cor_one(const UnitCell& cell, const ModulePW::PW_Basis* rho_basis, ModuleBase::matrix& forcesol) { @@ -78,7 +79,7 @@ void force_cor_two(const UnitCell& cell, const ModulePW::PW_Basis* rho_basis, Mo std::complex *Vel_g = new complex[rho_basis->npw]; ModuleBase::GlobalFunc::ZEROS(Vcav_g, rho_basis->npw); ModuleBase::GlobalFunc::ZEROS(Vel_g, rho_basis->npw); - for(int is=0; isnrxx; ir++) { diff --git a/source/module_hamilt_general/module_xc/test/test_xc3.cpp b/source/module_hamilt_general/module_xc/test/test_xc3.cpp index 70cfba4d9b..3b859d2969 100644 --- a/source/module_hamilt_general/module_xc/test/test_xc3.cpp +++ b/source/module_hamilt_general/module_xc/test/test_xc3.cpp @@ -84,15 +84,15 @@ class XCTest_GRADCORR : public XCTest XC_Functional::set_xc_type("PBE"); - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; XC_Functional::gradcorr(et1,vt1,v1,&chr,&rhopw,&ucell,stress1,false); XC_Functional::gradcorr(et1,vt1,v1,&chr,&rhopw,&ucell,stress1,true); - GlobalV::NSPIN = 2; + PARAM.input.nspin = 2; XC_Functional::gradcorr(et2,vt2,v2,&chr,&rhopw,&ucell,stress2,false); XC_Functional::gradcorr(et2,vt2,v2,&chr,&rhopw,&ucell,stress2,true); - GlobalV::NSPIN = 4; + PARAM.input.nspin = 4; PARAM.sys.domag = true; XC_Functional::gradcorr(et4,vt4,v4,&chr,&rhopw,&ucell,stress4,false); } @@ -172,8 +172,9 @@ class XCTest_GRADWFC : public XCTest rhopw.nrxx = 5; rhopw.nks = 1; gcar_wrapper = new ModuleBase::Vector3[rhopw.npwk_max]; - for (int ii = 0; ii < rhopw.npwk_max; ii++) + for (int ii = 0; ii < rhopw.npwk_max; ii++) { gcar_wrapper[ii] = ModuleBase::Vector3(0,0,0); +} kvec_c_wrapper = new ModuleBase::Vector3(1,2,3); rhopw.gcar = gcar_wrapper; diff --git a/source/module_hamilt_general/module_xc/test/test_xc5.cpp b/source/module_hamilt_general/module_xc/test/test_xc5.cpp index adfd82ba28..5bc516b72c 100644 --- a/source/module_hamilt_general/module_xc/test/test_xc5.cpp +++ b/source/module_hamilt_general/module_xc/test/test_xc5.cpp @@ -1,5 +1,8 @@ #include "../xc_functional.h" #include "gtest/gtest.h" +#define private public +#include "module_parameter/parameter.h" +#undef private #include "xctest.h" #include "../exx_info.h" #include "xc3_mock.h" @@ -71,14 +74,14 @@ class XCTest_VXC : public XCTest XC_Functional::set_xc_type("PBE"); - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; std::tuple etxc_vtxc_v = XC_Functional::v_xc(rhopw.nrxx,&chr,&ucell); et1 = std::get<0>(etxc_vtxc_v); vt1 = std::get<1>(etxc_vtxc_v); v1 = std::get<2>(etxc_vtxc_v); - GlobalV::NSPIN = 2; + PARAM.input.nspin = 2; etxc_vtxc_v = XC_Functional::v_xc(rhopw.nrxx,&chr,&ucell); et2 = std::get<0>(etxc_vtxc_v); @@ -169,14 +172,14 @@ class XCTest_VXC_Libxc : public XCTest XC_Functional::set_xc_type("GGA_X_PBE+GGA_C_PBE"); - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; std::tuple etxc_vtxc_v = XC_Functional::v_xc(rhopw.nrxx,&chr,&ucell); et1 = std::get<0>(etxc_vtxc_v); vt1 = std::get<1>(etxc_vtxc_v); v1 = std::get<2>(etxc_vtxc_v); - GlobalV::NSPIN = 2; + PARAM.input.nspin = 2; etxc_vtxc_v = XC_Functional::v_xc(rhopw.nrxx,&chr,&ucell); et2 = std::get<0>(etxc_vtxc_v); @@ -277,7 +280,7 @@ class XCTest_VXC_meta : public XCTest XC_Functional::set_xc_type("SCAN"); - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; std::tuple etxc_vtxc_v = XC_Functional::v_xc_meta(rhopw.nrxx,ucell.omega,ucell.tpiba,&chr); et1 = std::get<0>(etxc_vtxc_v); @@ -285,7 +288,7 @@ class XCTest_VXC_meta : public XCTest v1 = std::get<2>(etxc_vtxc_v); vtau1 = std::get<3>(etxc_vtxc_v); - GlobalV::NSPIN = 2; + PARAM.input.nspin = 2; etxc_vtxc_v = XC_Functional::v_xc_meta(rhopw.nrxx,ucell.omega,ucell.tpiba,&chr); et2 = std::get<0>(etxc_vtxc_v); diff --git a/source/module_hamilt_general/module_xc/test/xctest.h b/source/module_hamilt_general/module_xc/test/xctest.h index a179d4b3c8..57294a55bc 100644 --- a/source/module_hamilt_general/module_xc/test/xctest.h +++ b/source/module_hamilt_general/module_xc/test/xctest.h @@ -10,7 +10,8 @@ class XCTest: public testing::Test XCTest() { PARAM.input.basis_type = ""; - PARAM.input.cal_force = 1; + PARAM.input.cal_force = 0; + PARAM.input.cal_stress = 0; } }; #endif \ No newline at end of file diff --git a/source/module_hamilt_general/module_xc/xc_functional.cpp b/source/module_hamilt_general/module_xc/xc_functional.cpp index 3289886936..c3a671d714 100644 --- a/source/module_hamilt_general/module_xc/xc_functional.cpp +++ b/source/module_hamilt_general/module_xc/xc_functional.cpp @@ -63,7 +63,7 @@ void XC_Functional::set_xc_type(const std::string xc_func_in) #ifdef USE_PAW if(PARAM.inp.use_paw) { - if(GlobalV::NSPIN != 1) + if(PARAM.inp.nspin != 1) { ModuleBase::WARNING_QUIT("set_xc_type","paw does not support pz with spin polarization"); } @@ -215,11 +215,11 @@ void XC_Functional::set_xc_type(const std::string xc_func_in) { ModuleBase::WARNING_QUIT("set_xc_type","hybrid functional not realized for planewave yet"); } - if((func_type == 3 || func_type == 5) && GlobalV::NSPIN==4) + if((func_type == 3 || func_type == 5) && PARAM.inp.nspin==4) { ModuleBase::WARNING_QUIT("set_xc_type","meta-GGA has not been implemented for nspin = 4 yet"); } - //if((func_type == 3 || func_type == 5) && GlobalV::CAL_STRESS == 1 && GlobalV::NSPIN!=1) + //if((func_type == 3 || func_type == 5) && PARAM.inp.cal_stress == 1 && PARAM.inp.nspin!=1) //{ // ModuleBase::WARNING_QUIT("set_xc_type","mgga stress not implemented for polarized case yet"); //} diff --git a/source/module_hamilt_general/module_xc/xc_functional_gradcorr.cpp b/source/module_hamilt_general/module_xc/xc_functional_gradcorr.cpp index 68cf4efb3b..4ad50c5905 100644 --- a/source/module_hamilt_general/module_xc/xc_functional_gradcorr.cpp +++ b/source/module_hamilt_general/module_xc/xc_functional_gradcorr.cpp @@ -1,6 +1,5 @@ // This file contains subroutines realted to gradient calculations // it contains 5 subroutines: -#include "module_parameter/parameter.h" // 1. gradcorr, which calculates gradient correction // 2. grad_wfc, which calculates gradient of wavefunction // it is used in stress_func_mgga.cpp @@ -12,7 +11,7 @@ #include "xc_functional.h" #include "module_base/timer.h" #include "module_basis/module_pw/pw_basis_k.h" - +#include "module_parameter/parameter.h" #include #include #include @@ -32,10 +31,10 @@ void XC_Functional::gradcorr(double &etxc, double &vtxc, ModuleBase::matrix &v, if( func_id[1] == XC_GGA_C_LYP) { igcc_is_lyp = true; } - int nspin0 = GlobalV::NSPIN; - if(GlobalV::NSPIN==4) { nspin0 =1; + int nspin0 = PARAM.inp.nspin; + if(PARAM.inp.nspin==4) { nspin0 =1; } - if(GlobalV::NSPIN==4&&(PARAM.globalv.domag||PARAM.globalv.domag_z)) { nspin0 = 2; + if(PARAM.inp.nspin==4&&(PARAM.globalv.domag||PARAM.globalv.domag_z)) { nspin0 = 2; } assert(nspin0>0); @@ -52,7 +51,7 @@ void XC_Functional::gradcorr(double &etxc, double &vtxc, ModuleBase::matrix &v, // doing FFT to get rho in G space: rhog1 rhopw->real2recip(chr->rho[0], chr->rhog[0]); - if(GlobalV::NSPIN==2)//mohan fix bug 2012-05-28 + if(PARAM.inp.nspin==2)//mohan fix bug 2012-05-28 { rhopw->real2recip(chr->rho[1], chr->rhog[1]); } @@ -99,7 +98,7 @@ void XC_Functional::gradcorr(double &etxc, double &vtxc, ModuleBase::matrix &v, // for spin polarized case; // calculate the gradient of (rho_core+rho) in reciprocal space. - if(GlobalV::NSPIN==2) + if(PARAM.inp.nspin==2) { rhotmp2 = new double[rhopw->nrxx]; rhogsum2 = new std::complex[rhopw->npw]; @@ -125,7 +124,7 @@ void XC_Functional::gradcorr(double &etxc, double &vtxc, ModuleBase::matrix &v, XC_Functional::grad_rho( rhogsum2 , gdr2, rhopw, ucell->tpiba); } - if(GlobalV::NSPIN == 4&&(PARAM.globalv.domag||PARAM.globalv.domag_z)) + if(PARAM.inp.nspin == 4&&(PARAM.globalv.domag||PARAM.globalv.domag_z)) { rhotmp2 = new double[rhopw->nrxx]; rhogsum2 = new std::complex[rhopw->npw]; @@ -149,14 +148,14 @@ void XC_Functional::gradcorr(double &etxc, double &vtxc, ModuleBase::matrix &v, } if(!is_stress) { - vsave = new double* [GlobalV::NSPIN]; - for(int is = 0;isnrxx]; } #ifdef _OPENMP #pragma omp parallel for collapse(2) schedule(static, 1024) #endif - for(int is = 0;isnrxx;ir++){ vsave[is][ir] = v(is,ir); v(is,ir) = 0; @@ -390,7 +389,7 @@ void XC_Functional::gradcorr(double &etxc, double &vtxc, ModuleBase::matrix &v, else { double zeta = ( rhotmp1[ir] - rhotmp2[ir] ) / rh; - if(GlobalV::NSPIN==4&&(PARAM.globalv.domag||PARAM.globalv.domag_z)) { zeta = fabs(zeta) * neg[ir]; + if(PARAM.inp.nspin==4&&(PARAM.globalv.domag||PARAM.globalv.domag_z)) { zeta = fabs(zeta) * neg[ir]; } const double grh2 = (gdr1[ir]+gdr2[ir]).norm2(); XC_Functional::gcc_spin(rh, zeta, grh2, sc, v1cup, v1cdw, v2c); @@ -547,12 +546,12 @@ void XC_Functional::gradcorr(double &etxc, double &vtxc, ModuleBase::matrix &v, vtxc += vtxcgc; etxc += etxcgc; - if(GlobalV::NSPIN == 4 && (PARAM.globalv.domag||PARAM.globalv.domag_z)) + if(PARAM.inp.nspin == 4 && (PARAM.globalv.domag||PARAM.globalv.domag_z)) { #ifdef _OPENMP #pragma omp parallel for collapse(2) schedule(static, 1024) #endif - for(int is=0;isnrxx;ir++) { @@ -584,7 +583,7 @@ void XC_Functional::gradcorr(double &etxc, double &vtxc, ModuleBase::matrix &v, if(!is_stress) { delete[] h1; } - if(GlobalV::NSPIN==2) + if(PARAM.inp.nspin==2) { delete[] rhotmp2; delete[] rhogsum2; @@ -592,7 +591,7 @@ void XC_Functional::gradcorr(double &etxc, double &vtxc, ModuleBase::matrix &v, if(!is_stress) { delete[] h2; } } - if(GlobalV::NSPIN == 4 && (PARAM.globalv.domag||PARAM.globalv.domag_z)) + if(PARAM.inp.nspin == 4 && (PARAM.globalv.domag||PARAM.globalv.domag_z)) { delete[] neg; if(!is_stress) @@ -600,7 +599,7 @@ void XC_Functional::gradcorr(double &etxc, double &vtxc, ModuleBase::matrix &v, for(int i=0; i XC_Functional::v_xc( //Exchange-Correlation potential Vxc(r) from n(r) double etxc = 0.0; double vtxc = 0.0; - ModuleBase::matrix v(GlobalV::NSPIN, nrxx); + ModuleBase::matrix v(PARAM.inp.nspin, nrxx); // the square of the e charge // in Rydeberg unit, so * 2.0. @@ -37,7 +37,7 @@ std::tuple XC_Functional::v_xc( double vanishing_charge = 1.0e-10; - if (GlobalV::NSPIN == 1 || ( GlobalV::NSPIN ==4 && !PARAM.globalv.domag && !PARAM.globalv.domag_z)) + if (PARAM.inp.nspin == 1 || ( PARAM.inp.nspin ==4 && !PARAM.globalv.domag && !PARAM.globalv.domag_z)) { // spin-unpolarized case #ifdef _OPENMP @@ -63,7 +63,7 @@ std::tuple XC_Functional::v_xc( } // endif } //enddo } - else if(GlobalV::NSPIN ==2) + else if(PARAM.inp.nspin ==2) { // spin-polarized case #ifdef _OPENMP @@ -89,7 +89,7 @@ std::tuple XC_Functional::v_xc( double vxc[2]; XC_Functional::xc_spin(arhox, zeta, exc, vxc[0], vxc[1]); - for (int is = 0;is < GlobalV::NSPIN;is++) + for (int is = 0;is < PARAM.inp.nspin;is++) { v(is, ir) = e2 * vxc[is]; } @@ -99,7 +99,7 @@ std::tuple XC_Functional::v_xc( } } } - else if(GlobalV::NSPIN == 4)//noncollinear case added by zhengdy + else if(PARAM.inp.nspin == 4)//noncollinear case added by zhengdy { #ifdef _OPENMP #pragma omp parallel for reduction(+:etxc) reduction(+:vtxc) @@ -188,7 +188,7 @@ std::tuple XC_Functional::v_xc_libxc( // Peiz ModuleBase::timer::tick("XC_Functional","v_xc_libxc"); const int nspin = - (GlobalV::NSPIN == 1 || ( GlobalV::NSPIN ==4 && !PARAM.globalv.domag && !PARAM.globalv.domag_z)) + (PARAM.inp.nspin == 1 || ( PARAM.inp.nspin ==4 && !PARAM.globalv.domag && !PARAM.globalv.domag_z)) ? 1 : 2; double etxc = 0.0; @@ -221,7 +221,7 @@ std::tuple XC_Functional::v_xc_libxc( // Peiz // converting rho std::vector rho(nrxx*nspin); std::vector amag; - if(1==nspin || 2==GlobalV::NSPIN) + if(1==nspin || 2==PARAM.inp.nspin) { #ifdef _OPENMP #pragma omp parallel for collapse(2) schedule(static, 1024) @@ -438,15 +438,15 @@ std::tuple XC_Functional::v_xc_libxc( // Peiz finish_func(funcs); - if(1==GlobalV::NSPIN || 2==GlobalV::NSPIN) + if(1==PARAM.inp.nspin || 2==PARAM.inp.nspin) { ModuleBase::timer::tick("XC_Functional","v_xc_libxc"); return std::make_tuple( etxc, vtxc, std::move(v) ); } - else if(4==GlobalV::NSPIN) + else if(4==PARAM.inp.nspin) { constexpr double vanishing_charge = 1.0e-10; - ModuleBase::matrix v_nspin4(GlobalV::NSPIN,nrxx); + ModuleBase::matrix v_nspin4(PARAM.inp.nspin,nrxx); for( int ir=0; ir XC_Functional::v_xc_libxc( // Peiz ModuleBase::timer::tick("XC_Functional","v_xc_libxc"); return std::make_tuple( etxc, vtxc, std::move(v_nspin4) ); - } // end if(4==GlobalV::NSPIN) + } // end if(4==PARAM.inp.nspin) else//NSPIN != 1,2,4 is not supported { - throw std::domain_error("GlobalV::NSPIN ="+std::to_string(GlobalV::NSPIN) + throw std::domain_error("PARAM.inp.nspin ="+std::to_string(PARAM.inp.nspin) +" unfinished in "+std::string(__FILE__)+" line "+std::to_string(__LINE__)); } } @@ -500,8 +500,8 @@ std::tuple XC_Functional::v //output of the subroutine double etxc = 0.0; double vtxc = 0.0; - ModuleBase::matrix v(GlobalV::NSPIN,nrxx); - ModuleBase::matrix vofk(GlobalV::NSPIN,nrxx); + ModuleBase::matrix v(PARAM.inp.nspin,nrxx); + ModuleBase::matrix vofk(PARAM.inp.nspin,nrxx); //---------------------------------------------------------- // xc_func_type is defined in Libxc package @@ -510,7 +510,7 @@ std::tuple XC_Functional::v // https://www.tddft.org/programs/libxc/manual/libxc-5.1.x/ //---------------------------------------------------------- - const int nspin = GlobalV::NSPIN; + const int nspin = PARAM.inp.nspin; std::vector funcs = init_func( ( (1==nspin) ? XC_UNPOLARIZED:XC_POLARIZED ) ); // converting rho diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/FORCE_gamma.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/FORCE_gamma.cpp index ae0c7e7e4d..8fd39e3f0e 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/FORCE_gamma.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/FORCE_gamma.cpp @@ -41,7 +41,7 @@ void Force_LCAO::allocate(const Parallel_Orbitals& pv, ModuleBase::GlobalFunc::ZEROS(fsr.DSloc_z, pv.nloc); ModuleBase::Memory::record("Force::dS_GO", sizeof(double) * pv.nloc * 3); // allocate stress part in gamma_only-line, added by zhengdy-stress - if (GlobalV::CAL_STRESS) + if (PARAM.inp.cal_stress) { fsr.DSloc_11 = new double[pv.nloc]; fsr.DSloc_12 = new double[pv.nloc]; @@ -73,6 +73,7 @@ void Force_LCAO::allocate(const Parallel_Orbitals& pv, LCAO_domain::build_ST_new(fsr, 'S', cal_deri, + PARAM.inp.cal_stress, GlobalC::ucell, orb, pv, @@ -96,6 +97,7 @@ void Force_LCAO::allocate(const Parallel_Orbitals& pv, LCAO_domain::build_ST_new(fsr, 'T', cal_deri, + PARAM.inp.cal_stress, GlobalC::ucell, orb, pv, @@ -133,7 +135,7 @@ void Force_LCAO::finish_ftable(ForceStressArrays& fsr) delete[] fsr.DHloc_fixed_y; delete[] fsr.DHloc_fixed_z; - if (GlobalV::CAL_STRESS) // added by zhengdy-stress + if (PARAM.inp.cal_stress) // added by zhengdy-stress { delete[] fsr.DSloc_11; delete[] fsr.DSloc_12; diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/FORCE_k.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/FORCE_k.cpp index 7c56a222d4..ff11c217c4 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/FORCE_k.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/FORCE_k.cpp @@ -58,7 +58,7 @@ void Force_LCAO>::allocate(const Parallel_Orbitals& pv, ModuleBase::OMP_PARALLEL(init_DSloc_Rxyz); ModuleBase::Memory::record("Force::dS_K", sizeof(double) * nnr * 3); - if (GlobalV::CAL_STRESS) + if (PARAM.inp.cal_stress) { fsr.DH_r = new double[3 * nnr]; fsr.stvnl11 = new double[nnr]; @@ -91,6 +91,7 @@ void Force_LCAO>::allocate(const Parallel_Orbitals& pv, LCAO_domain::build_ST_new(fsr, 'S', cal_deri, + PARAM.inp.cal_stress, GlobalC::ucell, orb, pv, @@ -121,6 +122,7 @@ void Force_LCAO>::allocate(const Parallel_Orbitals& pv, LCAO_domain::build_ST_new(fsr, 'T', cal_deri, + PARAM.inp.cal_stress, GlobalC::ucell, orb, pv, @@ -149,6 +151,7 @@ void Force_LCAO>::allocate(const Parallel_Orbitals& pv, LCAO_domain::build_ST_new(fsr, 'S', cal_deri, + PARAM.inp.cal_stress, GlobalC::ucell, orb, pv, @@ -179,7 +182,7 @@ void Force_LCAO>::finish_ftable(ForceStressArrays& fsr) delete[] fsr.DHloc_fixedR_y; delete[] fsr.DHloc_fixedR_z; - if (GlobalV::CAL_STRESS) + if (PARAM.inp.cal_stress) { delete[] fsr.DH_r; delete[] fsr.stvnl11; diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_domain.h b/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_domain.h index 5fc564d8ae..f98f2433ab 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_domain.h +++ b/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_domain.h @@ -158,6 +158,7 @@ void single_derivative(ForceStressArrays& fsr, void build_ST_new(ForceStressArrays& fsr, const char& dtype, const bool& cal_deri, + const bool& cal_stress, const UnitCell& ucell, const LCAO_Orbitals& orb, const Parallel_Orbitals& pv, diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_hamilt.hpp b/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_hamilt.hpp index bc22a889bf..e3d52324ef 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_hamilt.hpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_hamilt.hpp @@ -1,5 +1,6 @@ //======================= // AUTHOR : Peize Lin +#include "module_parameter/parameter.h" // DATE : 2022-09-13 //======================= @@ -53,7 +54,7 @@ void sparse_format::cal_HR_exx( RI::Cell_Nearest cell_nearest; cell_nearest.init(atoms_pos, latvec, Rs_period); - const std::vector is_list = (GlobalV::NSPIN != 4) + const std::vector is_list = (PARAM.inp.nspin != 4) ? std::vector{current_spin} : std::vector{0, 1, 2, 3}; @@ -97,7 +98,7 @@ void sparse_format::cal_HR_exx( } if (std::abs(Hexx(iw0, iw1)) > sparse_threshold) { - if (GlobalV::NSPIN == 1 || GlobalV::NSPIN == 2) { + if (PARAM.inp.nspin == 1 || PARAM.inp.nspin == 2) { auto& HR_sparse_ptr = HS_Arrays .HR_sparse[current_spin][R][iwt0]; @@ -107,7 +108,7 @@ void sparse_format::cal_HR_exx( if (std::abs(HR_sparse) <= sparse_threshold) { HR_sparse_ptr.erase(iwt1); } - } else if (GlobalV::NSPIN == 4) { + } else if (PARAM.inp.nspin == 4) { auto& HR_sparse_ptr = HS_Arrays.HR_soc_sparse[R][iwt0]; std::complex& HR_sparse diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_init_basis.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_init_basis.cpp index cc069d7896..1ac92ff578 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_init_basis.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_init_basis.cpp @@ -30,7 +30,7 @@ void init_basis_lcao(Parallel_Orbitals& pv, { if (nlocal > 0) { - GlobalV::NB2D = (GlobalV::NSPIN == 4) ? 2 : 1; + GlobalV::NB2D = (PARAM.inp.nspin == 4) ? 2 : 1; } if (nlocal > 500) { diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_nl_mu.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_nl_mu.cpp index a079a16876..ef90927746 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_nl_mu.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_nl_mu.cpp @@ -21,7 +21,7 @@ void build_Nonlocal_mu_new(const Parallel_Orbitals& pv, ModuleBase::TITLE("LCAO_domain", "vnl_mu_new"); ModuleBase::timer::tick("LCAO_domain", "vnl_mu_new"); - const int nspin = GlobalV::NSPIN; + const int nspin = PARAM.inp.nspin; const int npol = PARAM.globalv.npol; const bool gamma_only_local = PARAM.globalv.gamma_only_local; diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_set_st.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_set_st.cpp index cc28a075b0..9d4c06988a 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_set_st.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_set_st.cpp @@ -311,6 +311,7 @@ void single_overlap(const LCAO_Orbitals& orb, void build_ST_new(ForceStressArrays& fsr, const char& dtype, const bool& calc_deri, + const bool& cal_stress, const UnitCell& ucell, const LCAO_Orbitals& orb, const Parallel_Orbitals& pv, @@ -323,9 +324,8 @@ void build_ST_new(ForceStressArrays& fsr, ModuleBase::TITLE("LCAO_domain", "build_ST_new"); ModuleBase::timer::tick("LCAO_domain", "build_ST_new"); - const int nspin = GlobalV::NSPIN; + const int nspin = PARAM.inp.nspin; const int npol = PARAM.globalv.npol; - const bool cal_stress = GlobalV::CAL_STRESS; const bool gamma_only_local = PARAM.globalv.gamma_only_local; int total_nnr = 0; diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_set_zero.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_set_zero.cpp index f154528d4f..039efae65d 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_set_zero.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_set_zero.cpp @@ -1,5 +1,6 @@ #include "module_hamilt_lcao/hamilt_lcaodft/LCAO_domain.h" #include "module_base/global_variable.h" +#include "module_parameter/parameter.h" #include "module_base/timer.h" #include "module_base/tool_threading.h" @@ -11,7 +12,7 @@ void zeros_HSR(const char &mtype, LCAO_HS_Arrays& HS_arrays) auto zeros_HSR_ker = [&](int num_threads, int thread_id) { long long beg, len; - if(GlobalV::NSPIN!=4) + if(PARAM.inp.nspin!=4) { if (mtype=='T') { diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/fedm_gamma.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/fedm_gamma.cpp index 22d1a968a5..6a466c3c59 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/fedm_gamma.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/fedm_gamma.cpp @@ -1,5 +1,6 @@ #include "FORCE.h" #include "module_elecstate/elecstate_lcao.h" +#include "module_parameter/parameter.h" #include "module_hamilt_pw/hamilt_pwdft/global.h" #include "module_base/parallel_reduce.h" #include "module_base/timer.h" @@ -27,7 +28,7 @@ void Force_LCAO::cal_fedm( ModuleBase::TITLE("Force_LCAO","cal_fedm"); ModuleBase::timer::tick("Force_LCAO","cal_fedm"); - const int nspin = GlobalV::NSPIN; + const int nspin = PARAM.inp.nspin; const int nbands = GlobalV::NBANDS; const int nlocal = GlobalV::NLOCAL; diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/fedm_k.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/fedm_k.cpp index 9938489ba6..9eb705d489 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/fedm_k.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/fedm_k.cpp @@ -1,5 +1,6 @@ #include "FORCE.h" #include "module_base/memory.h" +#include "module_parameter/parameter.h" #include "module_base/parallel_reduce.h" #include "module_base/timer.h" #include "module_base/tool_threading.h" @@ -40,7 +41,7 @@ void Force_LCAO>::cal_fedm(const bool isforce, ModuleBase::TITLE("Force_LCAO", "cal_fedm"); ModuleBase::timer::tick("Force_LCAO", "cal_fedm"); - const int nspin = GlobalV::NSPIN; + const int nspin = PARAM.inp.nspin; const int nbands = GlobalV::NBANDS; // construct a DensityMatrix object diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/ftvnl_dphi_gamma.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/ftvnl_dphi_gamma.cpp index 3f25bc8843..ea5ca9ed83 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/ftvnl_dphi_gamma.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/ftvnl_dphi_gamma.cpp @@ -1,5 +1,6 @@ #include "FORCE.h" #include "module_hamilt_pw/hamilt_pwdft/global.h" +#include "module_parameter/parameter.h" #include "module_cell/module_neighbor/sltk_grid_driver.h" #include #include "module_base/timer.h" @@ -20,7 +21,7 @@ void Force_LCAO::cal_ftvnl_dphi( ModuleBase::timer::tick("Force_LCAO","cal_ftvnl_dphi"); const int nlocal = GlobalV::NLOCAL; - const int nspin = GlobalV::NSPIN; + const int nspin = PARAM.inp.nspin; for(int i=0; i #include @@ -38,7 +39,7 @@ void Force_LCAO>::cal_ftvnl_dphi( ModuleBase::TITLE("Force_LCAO", "cal_ftvnl_dphi"); ModuleBase::timer::tick("Force_LCAO", "cal_ftvnl_dphi"); - const int nspin_DMR = (GlobalV::NSPIN == 2) ? 2 : 1; + const int nspin_DMR = (PARAM.inp.nspin == 2) ? 2 : 1; int total_irr = 0; // get the adjacent atom's information. diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/fvl_dphi_gamma.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/fvl_dphi_gamma.cpp index 75d06ce071..5f0c97f63b 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/fvl_dphi_gamma.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/fvl_dphi_gamma.cpp @@ -1,5 +1,6 @@ #include "FORCE.h" #include "module_hamilt_pw/hamilt_pwdft/global.h" +#include "module_parameter/parameter.h" #include "module_base/timer.h" template<> @@ -14,7 +15,7 @@ void Force_LCAO::cal_fvl_dphi( ModuleBase::TITLE("Force_LCAO","cal_fvl_dphi"); ModuleBase::timer::tick("Force_LCAO","cal_fvl_dphi"); - const int nspin = GlobalV::NSPIN; + const int nspin = PARAM.inp.nspin; fvl_dphi.zero_out(); svl_dphi.zero_out(); diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/fvl_dphi_k.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/fvl_dphi_k.cpp index 84e3d025f2..04f4d7b228 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/fvl_dphi_k.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/fvl_dphi_k.cpp @@ -1,5 +1,6 @@ #include "FORCE.h" +#include "module_parameter/parameter.h" #include #include @@ -41,7 +42,7 @@ void Force_LCAO>::cal_fvl_dphi( ModuleBase::timer::tick("Force_LCAO", "cal_fvl_dphi"); - const int nspin = GlobalV::NSPIN; + const int nspin = PARAM.inp.nspin; for (int is = 0; is < nspin; ++is) { diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/fvnl_dbeta_gamma.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/fvnl_dbeta_gamma.cpp index 2594879c22..f387f0f923 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/fvnl_dbeta_gamma.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/fvnl_dbeta_gamma.cpp @@ -1,5 +1,6 @@ #include "FORCE.h" #include "module_base/timer.h" +#include "module_parameter/parameter.h" #include "module_cell/module_neighbor/sltk_grid_driver.h" #include "module_hamilt_pw/hamilt_pwdft/global.h" @@ -192,7 +193,7 @@ void Force_LCAO::cal_fvnl_dbeta(const elecstate::DensityMatrixget_DMK(is + 1, 0, iw2_local, iw1_local); diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/fvnl_dbeta_k.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/fvnl_dbeta_k.cpp index ce7c407446..fe36856c65 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/fvnl_dbeta_k.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/fvnl_dbeta_k.cpp @@ -40,7 +40,7 @@ void Force_LCAO>::cal_fvnl_dbeta(const elecstate::DensityMa ModuleBase::TITLE("Force_LCAO", "cal_fvnl_dbeta"); ModuleBase::timer::tick("Force_LCAO", "cal_fvnl_dbeta"); - const int nspin = GlobalV::NSPIN; + const int nspin = PARAM.inp.nspin; const int nspin_DMR = (nspin == 2) ? 2 : 1; const int npol = PARAM.globalv.npol; diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.cpp index 09a91a0e4b..650532665d 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.cpp @@ -403,7 +403,7 @@ HamiltLCAO::HamiltLCAO(Gint_Gamma* GG_in, #endif // if NSPIN==2, HR should be separated into two parts, save HR into this->hRS2 int memory_fold = 1; - if (GlobalV::NSPIN == 2) + if (PARAM.inp.nspin == 2) { this->hRS2.resize(this->hR->get_nnr() * 2); this->hR->allocate(this->hRS2.data(), 0); @@ -431,7 +431,7 @@ void HamiltLCAO::updateHk(const int ik) ModuleBase::TITLE("HamiltLCAO", "updateHk"); ModuleBase::timer::tick("HamiltLCAO", "updateHk"); // update global spin index - if (GlobalV::NSPIN == 2) + if (PARAM.inp.nspin == 2) { // if Veff is added and current_spin is changed, refresh HR if (PARAM.inp.vl_in_h && this->kv->isk[ik] != this->current_spin) @@ -455,7 +455,7 @@ void HamiltLCAO::refresh() { ModuleBase::TITLE("HamiltLCAO", "refresh"); dynamic_cast*>(this->ops)->set_hr_done(false); - if (GlobalV::NSPIN == 2) + if (PARAM.inp.nspin == 2) { this->refresh_times = 1; this->current_spin = 0; diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/dftu_lcao.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/dftu_lcao.cpp index c1ec37e3b1..3d940ba66d 100755 --- a/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/dftu_lcao.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/dftu_lcao.cpp @@ -31,7 +31,7 @@ hamilt::DFTU>::DFTU(HS_Matrix_K* hsk_in, // initialize HR to allocate sparse Nonlocal matrix memory this->initialize_HR(GridD_in); // set nspin - this->nspin = GlobalV::NSPIN; + this->nspin = PARAM.inp.nspin; } // destructor diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/op_exx_lcao.hpp b/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/op_exx_lcao.hpp index 1b3ad2bc34..06f4e5518a 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/op_exx_lcao.hpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/op_exx_lcao.hpp @@ -104,12 +104,12 @@ OperatorEXX>::OperatorEXX(HS_Matrix_K* hsk_in, const std::string file_name_exx = PARAM.globalv.global_readin_dir + "HexxR" + std::to_string(GlobalV::MY_RANK); if (GlobalC::exx_info.info_ri.real_number) { - ModuleIO::read_Hexxs_csr(file_name_exx, GlobalC::ucell, GlobalV::NSPIN, GlobalV::NLOCAL, *Hexxd); + ModuleIO::read_Hexxs_csr(file_name_exx, GlobalC::ucell, PARAM.inp.nspin, GlobalV::NLOCAL, *Hexxd); if (this->add_hexx_type == Add_Hexx_Type::R) { reallocate_hcontainer(*Hexxd, this->hR); } } else { - ModuleIO::read_Hexxs_csr(file_name_exx, GlobalC::ucell, GlobalV::NSPIN, GlobalV::NLOCAL, *Hexxc); + ModuleIO::read_Hexxs_csr(file_name_exx, GlobalC::ucell, PARAM.inp.nspin, GlobalV::NLOCAL, *Hexxc); if (this->add_hexx_type == Add_Hexx_Type::R) { reallocate_hcontainer(*Hexxc, this->hR); } } this->use_cell_nearest = false; @@ -180,10 +180,10 @@ OperatorEXX>::OperatorEXX(HS_Matrix_K* hsk_in, // read in Hexx(R) const std::string restart_HR_path = GlobalC::restart.folder + "HexxR" + std::to_string(GlobalV::MY_RANK); if (GlobalC::exx_info.info_ri.real_number) { - ModuleIO::read_Hexxs_csr(restart_HR_path, GlobalC::ucell, GlobalV::NSPIN, GlobalV::NLOCAL, *Hexxd); + ModuleIO::read_Hexxs_csr(restart_HR_path, GlobalC::ucell, PARAM.inp.nspin, GlobalV::NLOCAL, *Hexxd); } else { - ModuleIO::read_Hexxs_csr(restart_HR_path, GlobalC::ucell, GlobalV::NSPIN, GlobalV::NLOCAL, *Hexxc); + ModuleIO::read_Hexxs_csr(restart_HR_path, GlobalC::ucell, PARAM.inp.nspin, GlobalV::NLOCAL, *Hexxc); } } @@ -226,7 +226,7 @@ void OperatorEXX>::contributeHR() this->use_cell_nearest ? &this->cell_nearest : nullptr); } } - if (GlobalV::NSPIN == 2) { this->current_spin = 1 - this->current_spin; + if (PARAM.inp.nspin == 2) { this->current_spin = 1 - this->current_spin; } } diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/td_ekinetic_lcao.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/td_ekinetic_lcao.cpp index a3dc0728f8..a41b82c901 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/td_ekinetic_lcao.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/td_ekinetic_lcao.cpp @@ -1,5 +1,6 @@ #include "td_ekinetic_lcao.h" +#include "module_parameter/parameter.h" #include "module_base/global_variable.h" #include "module_base/libm/libm.h" #include "module_base/timer.h" @@ -379,7 +380,7 @@ void TDEkinetic, double>>::contributeHk(int ik ModuleBase::timer::tick("TDEkinetic", "contributeHk"); const Parallel_Orbitals* paraV = this->hR_tmp->get_atom_pair(0).get_paraV(); // save HR data for output - int spin_tot = GlobalV::NSPIN; + int spin_tot = PARAM.inp.nspin; if (spin_tot == 4) ; else if (!output_hR_done && TD_Velocity::out_mat_R) diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/test/test_dftu.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/test/test_dftu.cpp index 7372654a29..51bce2cdd1 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/test/test_dftu.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/test/test_dftu.cpp @@ -1,5 +1,3 @@ -#include "../dftu_lcao.h" - #include "gtest/gtest.h" #include @@ -7,6 +5,7 @@ #define private public #include "module_parameter/parameter.h" #undef private +#include "../dftu_lcao.h" #include "module_hamilt_lcao/module_dftu/dftu.h" ModuleDFTU::DFTU::DFTU(){}; ModuleDFTU::DFTU::~DFTU(){}; @@ -148,7 +147,7 @@ class DFTUTest : public ::testing::Test TEST_F(DFTUTest, constructHRd2d) { // test for nspin=1 - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; std::vector> kvec_d_in(1, ModuleBase::Vector3(0.0, 0.0, 0.0)); hamilt::HS_Matrix_K hsk(paraV, true); hsk.set_zero_hk(); @@ -214,7 +213,7 @@ TEST_F(DFTUTest, constructHRd2d) TEST_F(DFTUTest, constructHRd2cd) { // test for nspin=2 - GlobalV::NSPIN = 2; + PARAM.input.nspin = 2; std::vector> kvec_d_in(2, ModuleBase::Vector3(0.0, 0.0, 0.0)); hamilt::HS_Matrix_K> hsk(paraV, true); hsk.set_zero_hk(); diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.cpp index 23755e497b..a873734946 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.cpp @@ -1,5 +1,6 @@ #include "veff_lcao.h" #include "module_base/timer.h" +#include "module_parameter/parameter.h" #include "module_base/tool_title.h" #include "module_hamilt_general/module_xc/xc_functional.h" #include "module_cell/unitcell.h" @@ -15,7 +16,7 @@ void Veff>::initialize_HR(const UnitCell* ucell_in, ModuleBase::TITLE("Veff", "initialize_HR"); ModuleBase::timer::tick("Veff", "initialize_HR"); - this->nspin = GlobalV::NSPIN; + this->nspin = PARAM.inp.nspin; auto* paraV = this->hR->get_paraV();// get parallel orbitals from HR // TODO: if paraV is nullptr, AtomPair can not use paraV for constructor, I will repair it in the future. diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/spar_dh.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/spar_dh.cpp index 78de11a34e..3487276c5f 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/spar_dh.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/spar_dh.cpp @@ -30,34 +30,19 @@ void sparse_format::cal_dH(const Parallel_Orbitals& pv, ModuleBase::GlobalFunc::ZEROS(fsr_dh.DHloc_fixedR_z, pv.nloc); // cal dT= in LCAO // cal T + VNL(P1) in LCAO basis - if (GlobalV::CAL_STRESS) - { - GlobalV::CAL_STRESS = false; - - LCAO_domain::build_ST_new(fsr_dh, - 'T', - true, - GlobalC::ucell, - orb, - pv, - two_center_bundle, - &GlobalC::GridD, - nullptr); // delete unused parameter lm.Hloc_fixedR - - GlobalV::CAL_STRESS = true; - } - else - { - LCAO_domain::build_ST_new(fsr_dh, - 'T', - true, - GlobalC::ucell, - orb, - pv, - two_center_bundle, - &GlobalC::GridD, - nullptr); // delete unused parameter lm.Hloc_fixedR - } + const bool cal_deri = true; + const bool cal_stress = false; + LCAO_domain::build_ST_new(fsr_dh, + 'T', + cal_deri, + cal_stress, + GlobalC::ucell, + orb, + pv, + two_center_bundle, + &GlobalC::GridD, + nullptr, + false); // delete unused parameter lm.Hloc_fixedR LCAO_domain::build_Nonlocal_mu_new(pv, fsr_dh, @@ -199,7 +184,7 @@ void sparse_format::cal_dSTN_R(const Parallel_Orbitals& pv, continue; } - if (GlobalV::NSPIN != 4) + if (PARAM.inp.nspin != 4) { temp_value_double = fsr.DHloc_fixedR_x[index]; if (std::abs(temp_value_double) > sparse_thr) @@ -236,7 +221,7 @@ void sparse_format::destroy_dH_R_sparse(LCAO_HS_Arrays& HS_Arrays) { ModuleBase::TITLE("LCAO_domain", "destroy_dH_R_sparse"); - if (GlobalV::NSPIN != 4) + if (PARAM.inp.nspin != 4) { std::map, std::map>> empty_dHRx_sparse_up; std::map, std::map>> empty_dHRx_sparse_down; diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/spar_hsr.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/spar_hsr.cpp index 4f1c9e89bc..d845c3c8f2 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/spar_hsr.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/spar_hsr.cpp @@ -23,7 +23,7 @@ void sparse_format::cal_HSR(const Parallel_Orbitals& pv, sparse_format::set_R_range(HS_Arrays.all_R_coor, grid); - const int nspin = GlobalV::NSPIN; + const int nspin = PARAM.inp.nspin; // cal_STN_R_sparse(current_spin, sparse_thr); if (nspin == 1 || nspin == 2) { @@ -250,7 +250,7 @@ void sparse_format::clear_zero_elements(LCAO_HS_Arrays& HS_Arrays, const double& sparse_thr) { ModuleBase::TITLE("sparse_format", "clear_zero_elements"); - if (GlobalV::NSPIN != 4) { + if (PARAM.inp.nspin != 4) { for (auto& R_loop: HS_Arrays.HR_sparse[current_spin]) { for (auto& row_loop: R_loop.second) { auto& col_map = row_loop.second; @@ -330,7 +330,7 @@ void sparse_format::clear_zero_elements(LCAO_HS_Arrays& HS_Arrays, void sparse_format::destroy_HS_R_sparse(LCAO_HS_Arrays& HS_Arrays) { ModuleBase::TITLE("sparse_format", "destroy_HS_R_sparse"); - if (GlobalV::NSPIN != 4) { + if (PARAM.inp.nspin != 4) { std::map, std::map>> empty_HR_sparse_up; diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/spar_st.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/spar_st.cpp index 8070eb2d53..e4fbba3624 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/spar_st.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/spar_st.cpp @@ -24,7 +24,7 @@ void sparse_format::cal_SR( sparse_format::set_R_range(all_R_coor, grid); - const int nspin = GlobalV::NSPIN; + const int nspin = PARAM.inp.nspin; // cal_STN_R_sparse(current_spin, sparse_thr); if (nspin == 1 || nspin == 2) { @@ -74,6 +74,7 @@ void sparse_format::cal_TR(const UnitCell& ucell, LCAO_domain::build_ST_new(fsr_tmp, 'T', false, + PARAM.inp.cal_stress, ucell, orb, pv, @@ -96,7 +97,7 @@ void sparse_format::cal_STN_R_for_T(const UnitCell& ucell, const double& sparse_thr) { ModuleBase::TITLE("sparse_format", "cal_STN_R_for_T"); - const int nspin = GlobalV::NSPIN; + const int nspin = PARAM.inp.nspin; int index = 0; ModuleBase::Vector3 dtau, tau1, tau2; @@ -197,7 +198,7 @@ void sparse_format::cal_STN_R_for_T(const UnitCell& ucell, void sparse_format::destroy_T_R_sparse(LCAO_HS_Arrays& HS_Arrays) { ModuleBase::TITLE("sparse_format", "destroy_T_R_sparse"); - if (GlobalV::NSPIN != 4) { + if (PARAM.inp.nspin != 4) { std::map, std::map>> empty_TR_sparse; diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/wavefunc_in_pw.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/wavefunc_in_pw.cpp index e5776de524..5d4917d9e0 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/wavefunc_in_pw.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/wavefunc_in_pw.cpp @@ -132,11 +132,11 @@ void Wavefunc_in_pw::make_table_q( } } } - double* table = new double[GlobalV::NQX]; + double* table = new double[PARAM.globalv.nqx]; Wavefunc_in_pw::integral(meshr, psir, radial, rab, L, table); - for(int iq=0; iqV(D) //where rho^{hl}_mu,nu = C_{L\mu}C_{L\nu} - C_{H\mu}C_{H\nu}, L for LUMO, H for HOMO @@ -28,7 +29,7 @@ void LCAO_Deepks::cal_o_delta(const std::vector> if (mu >= 0 && nu >= 0) { const int index = nu * pv->nrow + mu; - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { this->o_delta(0,hl) += dm_hl[hl][is](nu, mu) * this->H_V_delta[index]; } diff --git a/source/module_hamilt_lcao/module_deepks/LCAO_deepks_vdelta.cpp b/source/module_hamilt_lcao/module_deepks/LCAO_deepks_vdelta.cpp index 105233f8a4..092ceb50cc 100644 --- a/source/module_hamilt_lcao/module_deepks/LCAO_deepks_vdelta.cpp +++ b/source/module_hamilt_lcao/module_deepks/LCAO_deepks_vdelta.cpp @@ -1,5 +1,6 @@ //This file contains subroutines related to V_delta, which is the deepks contribution to Hamiltonian //defined as |alpha>V(D)>& dm) if (mu >= 0 && nu >= 0) { const int index = nu * pv->nrow + mu; - for (int is = 0; is < dm.size(); ++is) //dm.size() == GlobalV::NSPIN + for (int is = 0; is < dm.size(); ++is) //dm.size() == PARAM.inp.nspin { //this->e_delta_band += dm[is](nu, mu) * this->H_V_delta[index]; this->e_delta_band += dm[is][nu*this->pv->nrow+mu] * this->H_V_delta[index]; diff --git a/source/module_hamilt_lcao/module_deepks/orbital_precalc.cpp b/source/module_hamilt_lcao/module_deepks/orbital_precalc.cpp index 7a4b403605..39fa86150c 100644 --- a/source/module_hamilt_lcao/module_deepks/orbital_precalc.cpp +++ b/source/module_hamilt_lcao/module_deepks/orbital_precalc.cpp @@ -146,7 +146,7 @@ void LCAO_Deepks::cal_orbital_precalc( } std::vector dm_array(row_size * col_size, 0.0); - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { hamilt::AtomPair dm_pair(ibt1, ibt2, diff --git a/source/module_hamilt_lcao/module_deepks/test/LCAO_deepks_test_prep.cpp b/source/module_hamilt_lcao/module_deepks/test/LCAO_deepks_test_prep.cpp index 80aff8d3af..593f628464 100644 --- a/source/module_hamilt_lcao/module_deepks/test/LCAO_deepks_test_prep.cpp +++ b/source/module_hamilt_lcao/module_deepks/test/LCAO_deepks_test_prep.cpp @@ -191,7 +191,7 @@ void test_deepks::set_orbs(const double& lat0_in) void test_deepks::setup_kpt() { this->kv.set("KPT", - GlobalV::NSPIN, + PARAM.input.nspin, ucell.G, ucell.latvec, PARAM.sys.gamma_only_local, diff --git a/source/module_hamilt_lcao/module_deepks/test/klist_1.cpp b/source/module_hamilt_lcao/module_deepks/test/klist_1.cpp index f08ae19065..d1085bd3dd 100644 --- a/source/module_hamilt_lcao/module_deepks/test/klist_1.cpp +++ b/source/module_hamilt_lcao/module_deepks/test/klist_1.cpp @@ -1,5 +1,6 @@ #include "klist.h" +#include "module_parameter/parameter.h" namespace Test_Deepks { K_Vectors::K_Vectors() @@ -67,11 +68,11 @@ namespace Test_Deepks this->set_both_kvec(reciprocal_vec, latvec, ofs_running); int deg = 0; - if(GlobalV::NSPIN == 1) + if(PARAM.input.nspin == 1) { deg = 2; } - else if(GlobalV::NSPIN == 2||GlobalV::NSPIN==4) + else if(PARAM.input.nspin == 2||PARAM.input.nspin==4) { deg = 1; } diff --git a/source/module_hamilt_lcao/module_dftu/dftu.cpp b/source/module_hamilt_lcao/module_dftu/dftu.cpp index f463110d1d..d3a6e09dc0 100644 --- a/source/module_hamilt_lcao/module_dftu/dftu.cpp +++ b/source/module_hamilt_lcao/module_dftu/dftu.cpp @@ -58,7 +58,7 @@ void DFTU::init(UnitCell& cell, // unitcell class // global parameters, need to be removed in future const int npol = PARAM.globalv.npol; // number of polarization directions const int nlocal = GlobalV::NLOCAL; // number of total local orbitals - const int nspin = GlobalV::NSPIN; // number of spins + const int nspin = PARAM.inp.nspin; // number of spins this->EU = 0.0; @@ -254,7 +254,7 @@ void DFTU::cal_energy_correction(const int istep) continue; } - if (GlobalV::NSPIN == 1 || GlobalV::NSPIN == 2) + if (PARAM.inp.nspin == 1 || PARAM.inp.nspin == 2) { for (int spin = 0; spin < 2; spin++) { @@ -281,7 +281,7 @@ void DFTU::cal_energy_correction(const int istep) } } } - else if (GlobalV::NSPIN == 4) // SOC + else if (PARAM.inp.nspin == 4) // SOC { double nm_trace = 0.0; double nm2_trace = 0.0; @@ -328,7 +328,7 @@ void DFTU::cal_energy_correction(const int istep) { const int m2_all = m2 + ipol2 * (2 * l + 1); - if (GlobalV::NSPIN == 1 || GlobalV::NSPIN == 2) + if (PARAM.inp.nspin == 1 || PARAM.inp.nspin == 2) { for (int is = 0; is < 2; is++) { @@ -337,7 +337,7 @@ void DFTU::cal_energy_correction(const int istep) EU_dc += VU * this->locale[iat][l][n][is](m1_all, m2_all); } } - else if (GlobalV::NSPIN == 4) // SOC + else if (PARAM.inp.nspin == 4) // SOC { double VU = 0.0; VU = get_onebody_eff_pot(T, iat, l, n, 0, m1_all, m2_all, false); diff --git a/source/module_hamilt_lcao/module_dftu/dftu_folding.cpp b/source/module_hamilt_lcao/module_dftu/dftu_folding.cpp index ae6e99573b..c973b121d7 100644 --- a/source/module_hamilt_lcao/module_dftu/dftu_folding.cpp +++ b/source/module_hamilt_lcao/module_dftu/dftu_folding.cpp @@ -290,7 +290,7 @@ void DFTU::folding_matrix_k_new(const int ik, } else { - if(GlobalV::NSPIN != 4) + if(PARAM.inp.nspin != 4) { dynamic_cast, double>*>(p_ham)->updateSk(ik, hk_type); } diff --git a/source/module_hamilt_lcao/module_dftu/dftu_force.cpp b/source/module_hamilt_lcao/module_dftu/dftu_force.cpp index 0e19dcc3b5..15d9d02902 100644 --- a/source/module_hamilt_lcao/module_dftu/dftu_force.cpp +++ b/source/module_hamilt_lcao/module_dftu/dftu_force.cpp @@ -87,7 +87,7 @@ void DFTU::force_stress(const elecstate::ElecState* pelec, { force_dftu.zero_out(); } - if (GlobalV::CAL_STRESS) + if (PARAM.inp.cal_stress) { stress_dftu.zero_out(); } @@ -143,7 +143,7 @@ void DFTU::force_stress(const elecstate::ElecState* pelec, this->cal_force_gamma(&rho_VU[0], pv, fsr.DSloc_x, fsr.DSloc_y, fsr.DSloc_z, force_dftu); } - if (GlobalV::CAL_STRESS) + if (PARAM.inp.cal_stress) { this->cal_stress_gamma(GlobalC::ucell, pv, @@ -208,7 +208,7 @@ void DFTU::force_stress(const elecstate::ElecState* pelec, { cal_force_k(fsr, pv, ik, &rho_VU[0], force_dftu, kv.kvec_d); } - if (GlobalV::CAL_STRESS) + if (PARAM.inp.cal_stress) { cal_stress_k(fsr, pv, ik, &rho_VU[0], stress_dftu, kv.kvec_d); } @@ -220,7 +220,7 @@ void DFTU::force_stress(const elecstate::ElecState* pelec, Parallel_Reduce::reduce_pool(force_dftu.c, force_dftu.nr * force_dftu.nc); } - if (GlobalV::CAL_STRESS) + if (PARAM.inp.cal_stress) { Parallel_Reduce::reduce_pool(stress_dftu.c, stress_dftu.nr * stress_dftu.nc); diff --git a/source/module_hamilt_lcao/module_dftu/dftu_io.cpp b/source/module_hamilt_lcao/module_dftu/dftu_io.cpp index 490e5fcbd6..88d72cb94b 100644 --- a/source/module_hamilt_lcao/module_dftu/dftu_io.cpp +++ b/source/module_hamilt_lcao/module_dftu/dftu_io.cpp @@ -114,7 +114,7 @@ void DFTU::write_occup_m(std::ofstream &ofs, bool diag) ofs << "zeta" << " " << n << std::endl; - if (GlobalV::NSPIN == 1 || GlobalV::NSPIN == 2) + if (PARAM.inp.nspin == 1 || PARAM.inp.nspin == 2) { double sum0[2]; for (int is = 0; is < 2; is++) @@ -159,7 +159,7 @@ void DFTU::write_occup_m(std::ofstream &ofs, bool diag) ofs << std::setw(12) << std::setprecision(8) << std::fixed<< "atomic mag: "<> zeta; ifdftu.ignore(150, '\n'); - if (GlobalV::NSPIN == 1 || GlobalV::NSPIN == 2) + if (PARAM.inp.nspin == 1 || PARAM.inp.nspin == 2) { for (int is = 0; is < 2; is++) { @@ -330,7 +330,7 @@ void DFTU::read_occup_m(const std::string &fn) } } } - else if (GlobalV::NSPIN == 4) // SOC + else if (PARAM.inp.nspin == 4) // SOC { double value = 0.0; for (int m0 = 0; m0 < 2 * L + 1; m0++) @@ -412,7 +412,7 @@ void DFTU::local_occup_bcast() continue; } - if (GlobalV::NSPIN == 1 || GlobalV::NSPIN == 2) + if (PARAM.inp.nspin == 1 || PARAM.inp.nspin == 2) { for (int spin = 0; spin < 2; spin++) { @@ -427,7 +427,7 @@ void DFTU::local_occup_bcast() } } } - else if (GlobalV::NSPIN == 4) // SOC + else if (PARAM.inp.nspin == 4) // SOC { for (int m0 = 0; m0 < 2 * L + 1; m0++) { diff --git a/source/module_hamilt_lcao/module_dftu/dftu_occup.cpp b/source/module_hamilt_lcao/module_dftu/dftu_occup.cpp index 656300e9a7..8e3b2ee206 100644 --- a/source/module_hamilt_lcao/module_dftu/dftu_occup.cpp +++ b/source/module_hamilt_lcao/module_dftu/dftu_occup.cpp @@ -49,11 +49,11 @@ void DFTU::copy_locale() for (int n = 0; n < N; n++) { - if (GlobalV::NSPIN == 4) + if (PARAM.inp.nspin == 4) { locale_save[iat][l][n][0] = locale[iat][l][n][0]; } - else if (GlobalV::NSPIN == 1 || GlobalV::NSPIN == 2) + else if (PARAM.inp.nspin == 1 || PARAM.inp.nspin == 2) { locale_save[iat][l][n][0] = locale[iat][l][n][0]; locale_save[iat][l][n][1] = locale[iat][l][n][1]; @@ -84,11 +84,11 @@ void DFTU::zero_locale() for (int n = 0; n < N; n++) { - if (GlobalV::NSPIN == 4) + if (PARAM.inp.nspin == 4) { locale[iat][l][n][0].zero_out(); } - else if (GlobalV::NSPIN == 1 || GlobalV::NSPIN == 2) + else if (PARAM.inp.nspin == 1 || PARAM.inp.nspin == 2) { locale[iat][l][n][0].zero_out(); locale[iat][l][n][1].zero_out(); @@ -122,11 +122,11 @@ void DFTU::mix_locale(const double& mixing_beta) for (int n = 0; n < N; n++) { - if (GlobalV::NSPIN == 4) + if (PARAM.inp.nspin == 4) { locale[iat][l][n][0] = locale[iat][l][n][0]*beta + locale_save[iat][l][n][0]*(1.0-beta); } - else if (GlobalV::NSPIN == 1 || GlobalV::NSPIN == 2) + else if (PARAM.inp.nspin == 1 || PARAM.inp.nspin == 2) { locale[iat][l][n][0] = locale[iat][l][n][0] * beta + locale_save[iat][l][n][0] * (1.0-beta); locale[iat][l][n][1] = locale[iat][l][n][1] * beta + locale_save[iat][l][n][1] * (1.0-beta); @@ -163,7 +163,7 @@ void DFTU::cal_occup_m_k(const int iter, // srho(mu,nu) = \sum_{iw} S(mu,iw)*dm_k(iw,nu) this->folding_matrix_k_new(ik, p_ham); std::complex* s_k_pointer = nullptr; - if(GlobalV::NSPIN != 4) + if(PARAM.inp.nspin != 4) { s_k_pointer = dynamic_cast, double>*>(p_ham)->getSk(); } @@ -287,7 +287,7 @@ void DFTU::cal_occup_m_k(const int iter, // set the local occupation mumber matrix of spin up and down zeros #ifdef __MPI - if (GlobalV::NSPIN == 1 || GlobalV::NSPIN == 4) + if (PARAM.inp.nspin == 1 || PARAM.inp.nspin == 4) { ModuleBase::matrix temp(locale[iat][l][n][0]); MPI_Allreduce(&temp(0, 0), @@ -297,7 +297,7 @@ void DFTU::cal_occup_m_k(const int iter, MPI_SUM, MPI_COMM_WORLD); } - else if (GlobalV::NSPIN == 2) + else if (PARAM.inp.nspin == 2) { ModuleBase::matrix temp0(locale[iat][l][n][0]); MPI_Allreduce(&temp0(0, 0), @@ -318,7 +318,7 @@ void DFTU::cal_occup_m_k(const int iter, #endif // for the case spin independent calculation - switch (GlobalV::NSPIN) + switch (PARAM.inp.nspin) { case 1: locale[iat][l][n][0] += transpose(locale[iat][l][n][0]); @@ -327,7 +327,7 @@ void DFTU::cal_occup_m_k(const int iter, break; case 2: - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) locale[iat][l][n][is] += transpose(locale[iat][l][n][is]); break; @@ -368,7 +368,7 @@ void DFTU::cal_occup_m_gamma(const int iter, const std::vector srho(this->paraV->nloc); - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { // srho(mu,nu) = \sum_{iw} S(mu,iw)*dm_gamma(iw,nu) double* s_gamma_pointer = dynamic_cast*>(p_ham)->getSk(); @@ -469,7 +469,7 @@ void DFTU::cal_occup_m_gamma(const int iter, const std::vector 0) { continue;// for non-collinear spin case, first spin contains the charge density + if(PARAM.inp.nspin == 4 && is > 0) { continue;// for non-collinear spin case, first spin contains the charge density } for (int ir = 0; ir < nrxx; ir++) { diff --git a/source/module_hamilt_lcao/module_gint/gint.cpp b/source/module_hamilt_lcao/module_gint/gint.cpp index ba2e814a23..6c3ec7bd65 100644 --- a/source/module_hamilt_lcao/module_gint/gint.cpp +++ b/source/module_hamilt_lcao/module_gint/gint.cpp @@ -139,9 +139,9 @@ void Gint::initialize_pvpR(const UnitCell& ucell_in, Grid_Driver* gd) { int npol = 1; // there is the only resize code of DMRGint if (this->DMRGint.size() == 0) { - this->DMRGint.resize(GlobalV::NSPIN); + this->DMRGint.resize(PARAM.inp.nspin); } - if (GlobalV::NSPIN != 4) { + if (PARAM.inp.nspin != 4) { if (this->hRGint != nullptr) { delete this->hRGint; } @@ -153,7 +153,7 @@ void Gint::initialize_pvpR(const UnitCell& ucell_in, Grid_Driver* gd) { } this->hRGintCd = new hamilt::HContainer>(ucell_in.nat); - for (int is = 0; is < GlobalV::NSPIN; is++) { + for (int is = 0; is < PARAM.inp.nspin; is++) { if (this->DMRGint[is] != nullptr) { delete this->DMRGint[is]; } @@ -186,7 +186,7 @@ void Gint::initialize_pvpR(const UnitCell& ucell_in, Grid_Driver* gd) { } } - if (PARAM.globalv.gamma_only_local && GlobalV::NSPIN != 4) { + if (PARAM.globalv.gamma_only_local && PARAM.inp.nspin != 4) { this->hRGint->fix_gamma(); } for (int T1 = 0; T1 < ucell_in.ntype; ++T1) { @@ -332,7 +332,7 @@ void Gint::transfer_DM2DtoGrid(std::vector*> DM2D) { #endif ModuleBase::timer::tick("Gint", "transfer_DMR"); - if (GlobalV::NSPIN != 4) { + if (PARAM.inp.nspin != 4) { for (int is = 0; is < this->DMRGint.size(); is++) { #ifdef __MPI hamilt::transferParallels2Serials(*DM2D[is], DMRGint[is]); diff --git a/source/module_hamilt_lcao/module_gint/gint_gpu_interface.cpp b/source/module_hamilt_lcao/module_gint/gint_gpu_interface.cpp index fd01f5cefd..b6511826fc 100644 --- a/source/module_hamilt_lcao/module_gint/gint_gpu_interface.cpp +++ b/source/module_hamilt_lcao/module_gint/gint_gpu_interface.cpp @@ -45,7 +45,7 @@ void Gint::gpu_rho_interface(Gint_inout* inout) { ylmcoef[i] = ModuleBase::Ylm::ylmcoef[i]; } int nrxx = this->gridt->ncx * this->gridt->ncy * this->nplane; - for (int is = 0; is < GlobalV::NSPIN; ++is) { + for (int is = 0; is < PARAM.inp.nspin; ++is) { ModuleBase::GlobalFunc::ZEROS(inout->rho[is], nrxx); GintKernel::gint_rho_gpu(this->DMRGint[is], ylmcoef, diff --git a/source/module_hamilt_lcao/module_gint/gint_k_env.cpp b/source/module_hamilt_lcao/module_gint/gint_k_env.cpp index 023bc71c39..a844205516 100644 --- a/source/module_hamilt_lcao/module_gint/gint_k_env.cpp +++ b/source/module_hamilt_lcao/module_gint/gint_k_env.cpp @@ -110,7 +110,7 @@ void Gint_k::cal_env_k(int ik, int iw1_lo = 0; double* psi1 = &psir_ylm[ib][block_index[ia1]]; std::complex tmp{0.0, 0.0}; - if (GlobalV::NSPIN == 4) // is it a simple add of 2 spins? + if (PARAM.inp.nspin == 4) // is it a simple add of 2 spins? { for (int is = 0; is < 2; ++is) { diff --git a/source/module_hamilt_lcao/module_gint/gint_k_pvdpr.cpp b/source/module_hamilt_lcao/module_gint/gint_k_pvdpr.cpp index 5e9c7e8526..1aea33805b 100644 --- a/source/module_hamilt_lcao/module_gint/gint_k_pvdpr.cpp +++ b/source/module_hamilt_lcao/module_gint/gint_k_pvdpr.cpp @@ -1,5 +1,6 @@ #include "gint_k.h" #include "grid_technique.h" +#include "module_parameter/parameter.h" #include "module_base/global_function.h" #include "module_base/global_variable.h" #include "module_base/memory.h" @@ -14,7 +15,7 @@ void Gint_k::allocate_pvdpR(void) { ModuleBase::TITLE("Gint_k","allocate_pvpR"); - const int nspin = GlobalV::NSPIN; + const int nspin = PARAM.inp.nspin; assert(nspin>0); //xiaohui modify 2015-05-30 @@ -41,7 +42,7 @@ void Gint_k::destroy_pvdpR(void) { ModuleBase::TITLE("Gint_k","destroy_pvpR"); - const int nspin = GlobalV::NSPIN; + const int nspin = PARAM.inp.nspin; assert(nspin>0); for(int is =0;is is nnrg. - this->pvpR_reduced = new double*[GlobalV::NSPIN]; - for (int is = 0; is < GlobalV::NSPIN; is++) + this->pvpR_reduced = new double*[PARAM.inp.nspin]; + for (int is = 0; is < PARAM.inp.nspin; is++) { this->pvpR_reduced[is] = new double[this->gridt->nnrg]; ModuleBase::GlobalFunc::ZEROS(pvpR_reduced[is], this->gridt->nnrg); } - ModuleBase::Memory::record("pvpR_reduced", sizeof(double) * this->gridt->nnrg * GlobalV::NSPIN); + ModuleBase::Memory::record("pvpR_reduced", sizeof(double) * this->gridt->nnrg * PARAM.inp.nspin); this->pvpR_alloc_flag = true; return; @@ -47,7 +47,7 @@ void Gint_k::destroy_pvpR(void) return; } - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { delete[] pvpR_reduced[is]; } diff --git a/source/module_hamilt_lcao/module_gint/gint_k_sparse1.cpp b/source/module_hamilt_lcao/module_gint/gint_k_sparse1.cpp index 0314f83c4f..24caf2e7ba 100644 --- a/source/module_hamilt_lcao/module_gint/gint_k_sparse1.cpp +++ b/source/module_hamilt_lcao/module_gint/gint_k_sparse1.cpp @@ -388,7 +388,7 @@ void Gint_k::cal_dvlocal_R_sparseMatrix(const int& current_spin, const int nug0 = iw2 / PARAM.globalv.npol; const int iw_nowg = ixxx + mug0 * nw + nug0; - if (GlobalV::NSPIN == 4) + if (PARAM.inp.nspin == 4) { // pvp is symmetric, only half is calculated. @@ -557,7 +557,7 @@ void Gint_k::cal_dvlocal_R_sparseMatrix(const int& current_spin, } } - if (GlobalV::NSPIN != 4) + if (PARAM.inp.nspin != 4) { distribute_pvdpR_sparseMatrix(current_spin, 0, sparse_threshold, pvdpRx_sparseMatrix, HS_Arrays, pv); distribute_pvdpR_sparseMatrix(current_spin, 1, sparse_threshold, pvdpRy_sparseMatrix, HS_Arrays, pv); diff --git a/source/module_hamilt_lcao/module_gint/gint_rho_cpu_interface.cpp b/source/module_hamilt_lcao/module_gint/gint_rho_cpu_interface.cpp index f4721cf9af..354de74857 100644 --- a/source/module_hamilt_lcao/module_gint/gint_rho_cpu_interface.cpp +++ b/source/module_hamilt_lcao/module_gint/gint_rho_cpu_interface.cpp @@ -1,5 +1,6 @@ #include "gint.h" #include "module_base/memory.h" +#include "module_parameter/parameter.h" #include "module_base/timer.h" void Gint::gint_kernel_rho(Gint_inout* inout) { @@ -53,7 +54,7 @@ void Gint::gint_kernel_rho(Gint_inout* inout) { cal_flag.get_ptr_2D(), psir_ylm.get_ptr_2D()); - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { ModuleBase::Array_Pool psir_DM(this->bxyz, LD_pool); ModuleBase::GlobalFunc::ZEROS(psir_DM.get_ptr_1D(), this->bxyz * LD_pool); @@ -130,7 +131,7 @@ void Gint::gint_kernel_tau(Gint_inout* inout) { dpsir_ylm_y.get_ptr_2D(), dpsir_ylm_z.get_ptr_2D()); - for(int is=0; is dpsix_DM(this->bxyz, LD_pool); ModuleBase::Array_Pool dpsiy_DM(this->bxyz, LD_pool); diff --git a/source/module_hamilt_lcao/module_gint/grid_technique.cpp b/source/module_hamilt_lcao/module_gint/grid_technique.cpp index d1610639d2..c66c47a24f 100644 --- a/source/module_hamilt_lcao/module_gint/grid_technique.cpp +++ b/source/module_hamilt_lcao/module_gint/grid_technique.cpp @@ -499,7 +499,7 @@ void Grid_Technique::cal_trace_lo(const UnitCell& ucell) { if (this->in_this_processor[iat]) { ++lnat; int nw0 = ucell.atoms[it].nw; - if (GlobalV::NSPIN + if (PARAM.inp.nspin == 4) { // added by zhengdy-soc, need to be double in soc nw0 *= 2; this->lgd += nw0; @@ -515,7 +515,7 @@ void Grid_Technique::cal_trace_lo(const UnitCell& ucell) { } else { // global index of atomic orbitals iw_all += ucell.atoms[it].nw; - if (GlobalV::NSPIN == 4) { + if (PARAM.inp.nspin == 4) { iw_all += ucell.atoms[it].nw; } } diff --git a/source/module_hamilt_pw/hamilt_ofdft/kedf_lkt.cpp b/source/module_hamilt_pw/hamilt_ofdft/kedf_lkt.cpp index d656bd59a1..7ee5d17236 100644 --- a/source/module_hamilt_pw/hamilt_ofdft/kedf_lkt.cpp +++ b/source/module_hamilt_pw/hamilt_ofdft/kedf_lkt.cpp @@ -1,5 +1,6 @@ #include "./kedf_lkt.h" +#include "module_parameter/parameter.h" #include #include "module_base/parallel_reduce.h" @@ -28,7 +29,7 @@ double KEDF_LKT::get_energy(const double* const* prho, ModulePW::PW_Basis* pw_rh nabla_rho[i] = new double[pw_rho->nrxx]; } - if (GlobalV::NSPIN == 1) + if (PARAM.inp.nspin == 1) { this->nabla(prho[0], pw_rho, nabla_rho); this->get_as(prho[0], nabla_rho, pw_rho->nrxx, as); @@ -38,7 +39,7 @@ double KEDF_LKT::get_energy(const double* const* prho, ModulePW::PW_Basis* pw_rh } energy *= this->dV_ * this->c_tf_; } - else if (GlobalV::NSPIN == 2) + else if (PARAM.inp.nspin == 2) { // Waiting for update } @@ -107,7 +108,7 @@ void KEDF_LKT::lkt_potential(const double* const* prho, ModulePW::PW_Basis* pw_r } double* nabla_term = new double[pw_rho->nrxx]; - if (GlobalV::NSPIN == 1) + if (PARAM.inp.nspin == 1) { this->nabla(prho[0], pw_rho, nabla_rho); this->get_as(prho[0], nabla_rho, pw_rho->nrxx, as); @@ -146,7 +147,7 @@ void KEDF_LKT::lkt_potential(const double* const* prho, ModulePW::PW_Basis* pw_r this->lkt_energy *= this->c_tf_ * this->dV_; Parallel_Reduce::reduce_all(this->lkt_energy); } - else if (GlobalV::NSPIN == 2) + else if (PARAM.inp.nspin == 2) { // Waiting for update } @@ -176,7 +177,7 @@ void KEDF_LKT::get_stress(const double* const* prho, ModulePW::PW_Basis* pw_rho) } double* nabla_term = new double[pw_rho->nrxx]; - if (GlobalV::NSPIN == 1) + if (PARAM.inp.nspin == 1) { this->nabla(prho[0], pw_rho, nabla_rho); this->get_as(prho[0], nabla_rho, pw_rho->nrxx, as); @@ -220,7 +221,7 @@ void KEDF_LKT::get_stress(const double* const* prho, ModulePW::PW_Basis* pw_rho) } } } - else if (GlobalV::NSPIN == 2) + else if (PARAM.inp.nspin == 2) { // Waiting for update } diff --git a/source/module_hamilt_pw/hamilt_ofdft/kedf_tf.cpp b/source/module_hamilt_pw/hamilt_ofdft/kedf_tf.cpp index acca258cc2..fa39db5920 100644 --- a/source/module_hamilt_pw/hamilt_ofdft/kedf_tf.cpp +++ b/source/module_hamilt_pw/hamilt_ofdft/kedf_tf.cpp @@ -1,5 +1,6 @@ #include "./kedf_tf.h" +#include "module_parameter/parameter.h" #include #include "module_base/parallel_reduce.h" @@ -21,7 +22,7 @@ void KEDF_TF::set_para(int nx, double dV, double tf_weight) double KEDF_TF::get_energy(const double* const* prho) { double energy = 0.; // in Ry - if (GlobalV::NSPIN == 1) + if (PARAM.inp.nspin == 1) { for (int ir = 0; ir < this->nx_; ++ir) { @@ -29,9 +30,9 @@ double KEDF_TF::get_energy(const double* const* prho) } energy *= this->dV_ * this->c_tf_; } - else if (GlobalV::NSPIN == 2) + else if (PARAM.inp.nspin == 2) { - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { for (int ir = 0; ir < this->nx_; ++ir) { @@ -72,16 +73,16 @@ double KEDF_TF::get_energy_density(const double* const* prho, int is, int ir) void KEDF_TF::tf_potential(const double* const* prho, ModuleBase::matrix& rpotential) { ModuleBase::timer::tick("KEDF_TF", "tf_potential"); - if (GlobalV::NSPIN == 1) + if (PARAM.inp.nspin == 1) { for (int ir = 0; ir < this->nx_; ++ir) { rpotential(0, ir) += 5.0 / 3.0 * this->c_tf_ * std::pow(prho[0][ir], 2. / 3.) * this->tf_weight_; } } - else if (GlobalV::NSPIN == 2) + else if (PARAM.inp.nspin == 2) { - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { for (int ir = 0; ir < this->nx_; ++ir) { diff --git a/source/module_hamilt_pw/hamilt_ofdft/kedf_vw.cpp b/source/module_hamilt_pw/hamilt_ofdft/kedf_vw.cpp index 6117058c83..cc37c73a7c 100644 --- a/source/module_hamilt_pw/hamilt_ofdft/kedf_vw.cpp +++ b/source/module_hamilt_pw/hamilt_ofdft/kedf_vw.cpp @@ -1,5 +1,6 @@ #include "./kedf_vw.h" +#include "module_parameter/parameter.h" #include #include "module_base/parallel_reduce.h" @@ -21,8 +22,8 @@ void KEDF_vW::set_para(double dV, double vw_weight) double KEDF_vW::get_energy(double** pphi, ModulePW::PW_Basis* pw_rho) { // since pphi may contain minus element, we define tempPhi = std::abs(phi), which is true sqrt(rho) - double** tempPhi = new double*[GlobalV::NSPIN]; - for (int is = 0; is < GlobalV::NSPIN; ++is) + double** tempPhi = new double*[PARAM.inp.nspin]; + for (int is = 0; is < PARAM.inp.nspin; ++is) { tempPhi[is] = new double[pw_rho->nrxx]; for (int ir = 0; ir < pw_rho->nrxx; ++ir) @@ -31,13 +32,13 @@ double KEDF_vW::get_energy(double** pphi, ModulePW::PW_Basis* pw_rho) } } - double** LapPhi = new double*[GlobalV::NSPIN]; - for (int is = 0; is < GlobalV::NSPIN; ++is) + double** LapPhi = new double*[PARAM.inp.nspin]; + for (int is = 0; is < PARAM.inp.nspin; ++is) LapPhi[is] = new double[pw_rho->nrxx]; this->laplacian_phi(tempPhi, LapPhi, pw_rho); double energy = 0.; // in Ry - if (GlobalV::NSPIN == 1) + if (PARAM.inp.nspin == 1) { for (int ir = 0; ir < pw_rho->nrxx; ++ir) { @@ -45,9 +46,9 @@ double KEDF_vW::get_energy(double** pphi, ModulePW::PW_Basis* pw_rho) } energy *= this->dV_ * 0.5 * this->vw_weight_ * 2.; // vw_weight * 2 to convert Hartree to Ry } - else if (GlobalV::NSPIN == 2) + else if (PARAM.inp.nspin == 2) { - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { for (int ir = 0; ir < pw_rho->nrxx; ++ir) { @@ -59,7 +60,7 @@ double KEDF_vW::get_energy(double** pphi, ModulePW::PW_Basis* pw_rho) this->vw_energy = energy; Parallel_Reduce::reduce_all(this->vw_energy); - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { delete[] tempPhi[is]; delete[] LapPhi[is]; @@ -83,8 +84,8 @@ double KEDF_vW::get_energy(double** pphi, ModulePW::PW_Basis* pw_rho) double KEDF_vW::get_energy_density(double** pphi, int is, int ir, ModulePW::PW_Basis* pw_rho) { // since pphi may contain minus element, we define tempPhi = std::abs(phi), which is true sqrt(rho) - double** tempPhi = new double*[GlobalV::NSPIN]; - for (int is = 0; is < GlobalV::NSPIN; ++is) + double** tempPhi = new double*[PARAM.inp.nspin]; + for (int is = 0; is < PARAM.inp.nspin; ++is) { tempPhi[is] = new double[pw_rho->nrxx]; for (int ir = 0; ir < pw_rho->nrxx; ++ir) @@ -93,8 +94,8 @@ double KEDF_vW::get_energy_density(double** pphi, int is, int ir, ModulePW::PW_B } } - double** LapPhi = new double*[GlobalV::NSPIN]; - for (int is = 0; is < GlobalV::NSPIN; ++is) + double** LapPhi = new double*[PARAM.inp.nspin]; + for (int is = 0; is < PARAM.inp.nspin; ++is) LapPhi[is] = new double[pw_rho->nrxx]; this->laplacian_phi(tempPhi, LapPhi, pw_rho); @@ -102,7 +103,7 @@ double KEDF_vW::get_energy_density(double** pphi, int is, int ir, ModulePW::PW_B energyDen = 0.5 * tempPhi[is][ir] * LapPhi[is][ir] * this->vw_weight_ * 2.; // vw_weight * 2 to convert Hartree to Ry - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { delete[] tempPhi[is]; delete[] LapPhi[is]; @@ -128,8 +129,8 @@ void KEDF_vW::vw_potential(const double* const* pphi, ModulePW::PW_Basis* pw_rho ModuleBase::timer::tick("KEDF_vW", "vw_potential"); // since pphi may contain minus element, we define tempPhi = std::abs(phi), which is true sqrt(rho) - double** tempPhi = new double*[GlobalV::NSPIN]; - for (int is = 0; is < GlobalV::NSPIN; ++is) + double** tempPhi = new double*[PARAM.inp.nspin]; + for (int is = 0; is < PARAM.inp.nspin; ++is) { tempPhi[is] = new double[pw_rho->nrxx]; for (int ir = 0; ir < pw_rho->nrxx; ++ir) @@ -139,13 +140,13 @@ void KEDF_vW::vw_potential(const double* const* pphi, ModulePW::PW_Basis* pw_rho } // calculate the minus \nabla^2 sqrt(rho) - double** LapPhi = new double*[GlobalV::NSPIN]; - for (int is = 0; is < GlobalV::NSPIN; ++is) + double** LapPhi = new double*[PARAM.inp.nspin]; + for (int is = 0; is < PARAM.inp.nspin; ++is) LapPhi[is] = new double[pw_rho->nrxx]; this->laplacian_phi(tempPhi, LapPhi, pw_rho); // calculate potential - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { for (int ir = 0; ir < pw_rho->nrxx; ++ir) { @@ -162,7 +163,7 @@ void KEDF_vW::vw_potential(const double* const* pphi, ModulePW::PW_Basis* pw_rho // calculate energy double energy = 0.; // in Ry - if (GlobalV::NSPIN == 1) + if (PARAM.inp.nspin == 1) { for (int ir = 0; ir < pw_rho->nrxx; ++ir) { @@ -170,9 +171,9 @@ void KEDF_vW::vw_potential(const double* const* pphi, ModulePW::PW_Basis* pw_rho } energy *= this->dV_ * 0.5 * this->vw_weight_ * 2.; // vw_weight * 2 to convert Hartree to Ry } - else if (GlobalV::NSPIN == 2) + else if (PARAM.inp.nspin == 2) { - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { for (int ir = 0; ir < pw_rho->nrxx; ++ir) { @@ -184,7 +185,7 @@ void KEDF_vW::vw_potential(const double* const* pphi, ModulePW::PW_Basis* pw_rho this->vw_energy = energy; Parallel_Reduce::reduce_all(this->vw_energy); - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { delete[] tempPhi[is]; delete[] LapPhi[is]; @@ -204,8 +205,8 @@ void KEDF_vW::vw_potential(const double* const* pphi, ModulePW::PW_Basis* pw_rho void KEDF_vW::get_stress(const double* const* pphi, ModulePW::PW_Basis* pw_rho) { // since pphi may contain minus element, we define tempPhi = std::abs(phi), which is true sqrt(rho) - double** tempPhi = new double*[GlobalV::NSPIN]; - for (int is = 0; is < GlobalV::NSPIN; ++is) + double** tempPhi = new double*[PARAM.inp.nspin]; + for (int is = 0; is < PARAM.inp.nspin; ++is) { tempPhi[is] = new double[pw_rho->nrxx]; for (int ir = 0; ir < pw_rho->nrxx; ++ir) @@ -214,9 +215,9 @@ void KEDF_vW::get_stress(const double* const* pphi, ModulePW::PW_Basis* pw_rho) } } - std::complex** recipPhi = new std::complex*[GlobalV::NSPIN]; - std::complex** ggrecipPhi = new std::complex*[GlobalV::NSPIN]; - for (int is = 0; is < GlobalV::NSPIN; ++is) + std::complex** recipPhi = new std::complex*[PARAM.inp.nspin]; + std::complex** ggrecipPhi = new std::complex*[PARAM.inp.nspin]; + for (int is = 0; is < PARAM.inp.nspin; ++is) { recipPhi[is] = new std::complex[pw_rho->npw]; ggrecipPhi[is] = new std::complex[pw_rho->npw]; @@ -231,7 +232,7 @@ void KEDF_vW::get_stress(const double* const* pphi, ModulePW::PW_Basis* pw_rho) for (int beta = alpha; beta < 3; ++beta) { this->stress(alpha, beta) = 0; - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { for (int ik = 0; ik < pw_rho->npw; ++ik) { @@ -256,7 +257,7 @@ void KEDF_vW::get_stress(const double* const* pphi, ModulePW::PW_Basis* pw_rho) this->stress(alpha, beta) = this->stress(beta, alpha); } } - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { delete[] tempPhi[is]; delete[] recipPhi[is]; @@ -277,8 +278,8 @@ void KEDF_vW::get_stress(const double* const* pphi, ModulePW::PW_Basis* pw_rho) */ void KEDF_vW::laplacian_phi(const double* const* pphi, double** rLapPhi, ModulePW::PW_Basis* pw_rho) { - std::complex** recipPhi = new std::complex*[GlobalV::NSPIN]; - for (int is = 0; is < GlobalV::NSPIN; ++is) + std::complex** recipPhi = new std::complex*[PARAM.inp.nspin]; + for (int is = 0; is < PARAM.inp.nspin; ++is) { recipPhi[is] = new std::complex[pw_rho->npw]; @@ -290,7 +291,7 @@ void KEDF_vW::laplacian_phi(const double* const* pphi, double** rLapPhi, ModuleP pw_rho->recip2real(recipPhi[is], rLapPhi[is]); } - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { delete[] recipPhi[is]; } diff --git a/source/module_hamilt_pw/hamilt_ofdft/kedf_wt.cpp b/source/module_hamilt_pw/hamilt_ofdft/kedf_wt.cpp index 11002b6e01..2af9e78623 100644 --- a/source/module_hamilt_pw/hamilt_ofdft/kedf_wt.cpp +++ b/source/module_hamilt_pw/hamilt_ofdft/kedf_wt.cpp @@ -74,13 +74,13 @@ void KEDF_WT::set_para(double dV, */ double KEDF_WT::get_energy(const double* const* prho, ModulePW::PW_Basis* pw_rho) { - double** kernelRhoBeta = new double*[GlobalV::NSPIN]; - for (int is = 0; is < GlobalV::NSPIN; ++is) + double** kernelRhoBeta = new double*[PARAM.inp.nspin]; + for (int is = 0; is < PARAM.inp.nspin; ++is) kernelRhoBeta[is] = new double[pw_rho->nrxx]; this->multi_kernel(prho, kernelRhoBeta, this->beta_, pw_rho); double energy = 0.; // in Ry - if (GlobalV::NSPIN == 1) + if (PARAM.inp.nspin == 1) { for (int ir = 0; ir < pw_rho->nrxx; ++ir) { @@ -88,9 +88,9 @@ double KEDF_WT::get_energy(const double* const* prho, ModulePW::PW_Basis* pw_rho } energy *= this->dV_ * this->c_tf_; } - else if (GlobalV::NSPIN == 2) + else if (PARAM.inp.nspin == 2) { - // for (int is = 0; is < GlobalV::NSPIN; ++is) + // for (int is = 0; is < PARAM.inp.nspin; ++is) // { // for (int ir = 0; ir < pw_rho->nrxx; ++ir) // { @@ -102,7 +102,7 @@ double KEDF_WT::get_energy(const double* const* prho, ModulePW::PW_Basis* pw_rho this->wt_energy = energy; Parallel_Reduce::reduce_all(this->wt_energy); - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { delete[] kernelRhoBeta[is]; } @@ -123,14 +123,14 @@ double KEDF_WT::get_energy(const double* const* prho, ModulePW::PW_Basis* pw_rho */ double KEDF_WT::get_energy_density(const double* const* prho, int is, int ir, ModulePW::PW_Basis* pw_rho) { - double** kernelRhoBeta = new double*[GlobalV::NSPIN]; - for (int is = 0; is < GlobalV::NSPIN; ++is) + double** kernelRhoBeta = new double*[PARAM.inp.nspin]; + for (int is = 0; is < PARAM.inp.nspin; ++is) kernelRhoBeta[is] = new double[pw_rho->nrxx]; this->multi_kernel(prho, kernelRhoBeta, this->beta_, pw_rho); double result = this->c_tf_ * std::pow(prho[is][ir], this->alpha_) * kernelRhoBeta[is][ir]; - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { delete[] kernelRhoBeta[is]; } @@ -152,17 +152,17 @@ void KEDF_WT::wt_potential(const double* const* prho, ModulePW::PW_Basis* pw_rho { ModuleBase::timer::tick("KEDF_WT", "wt_potential"); - double** kernelRhoBeta = new double*[GlobalV::NSPIN]; - for (int is = 0; is < GlobalV::NSPIN; ++is) + double** kernelRhoBeta = new double*[PARAM.inp.nspin]; + for (int is = 0; is < PARAM.inp.nspin; ++is) kernelRhoBeta[is] = new double[pw_rho->nrxx]; this->multi_kernel(prho, kernelRhoBeta, this->beta_, pw_rho); - double** kernelRhoAlpha = new double*[GlobalV::NSPIN]; - for (int is = 0; is < GlobalV::NSPIN; ++is) + double** kernelRhoAlpha = new double*[PARAM.inp.nspin]; + for (int is = 0; is < PARAM.inp.nspin; ++is) kernelRhoAlpha[is] = new double[pw_rho->nrxx]; this->multi_kernel(prho, kernelRhoAlpha, this->alpha_, pw_rho); - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { for (int ir = 0; ir < pw_rho->nrxx; ++ir) { @@ -174,7 +174,7 @@ void KEDF_WT::wt_potential(const double* const* prho, ModulePW::PW_Basis* pw_rho // calculate energy double energy = 0.; // in Ry - if (GlobalV::NSPIN == 1) + if (PARAM.inp.nspin == 1) { for (int ir = 0; ir < pw_rho->nrxx; ++ir) { @@ -182,9 +182,9 @@ void KEDF_WT::wt_potential(const double* const* prho, ModulePW::PW_Basis* pw_rho } energy *= this->dV_ * this->c_tf_; } - else if (GlobalV::NSPIN == 2) + else if (PARAM.inp.nspin == 2) { - // for (int is = 0; is < GlobalV::NSPIN; ++is) + // for (int is = 0; is < PARAM.inp.nspin; ++is) // { // for (int ir = 0; ir < pw_rho->nrxx; ++ir) // { @@ -196,7 +196,7 @@ void KEDF_WT::wt_potential(const double* const* prho, ModulePW::PW_Basis* pw_rho this->wt_energy = energy; Parallel_Reduce::reduce_all(this->wt_energy); - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { delete[] kernelRhoBeta[is]; delete[] kernelRhoAlpha[is]; @@ -228,10 +228,10 @@ void KEDF_WT::get_stress(const double* const* prho, ModulePW::PW_Basis* pw_rho, mult = 2. / 3.; } - std::complex** recipRhoAlpha = new std::complex*[GlobalV::NSPIN]; - std::complex** recipRhoBeta = new std::complex*[GlobalV::NSPIN]; + std::complex** recipRhoAlpha = new std::complex*[PARAM.inp.nspin]; + std::complex** recipRhoBeta = new std::complex*[PARAM.inp.nspin]; double* tempRho = new double[pw_rho->nrxx]; - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { recipRhoAlpha[is] = new std::complex[pw_rho->npw]; recipRhoBeta[is] = new std::complex[pw_rho->npw]; @@ -252,7 +252,7 @@ void KEDF_WT::get_stress(const double* const* prho, ModulePW::PW_Basis* pw_rho, double eta = 0.; double diff = 0.; this->stress.zero_out(); - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { for (int ip = 0; ip < pw_rho->npw; ++ip) { @@ -311,7 +311,7 @@ void KEDF_WT::get_stress(const double* const* prho, ModulePW::PW_Basis* pw_rho, } } - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { delete[] recipRhoAlpha[is]; delete[] recipRhoBeta[is]; @@ -416,8 +416,8 @@ double KEDF_WT::diff_linhard(double eta, double vw_weight) */ void KEDF_WT::multi_kernel(const double* const* prho, double** rkernel_rho, double exponent, ModulePW::PW_Basis* pw_rho) { - std::complex** recipkernelRho = new std::complex*[GlobalV::NSPIN]; - for (int is = 0; is < GlobalV::NSPIN; ++is) + std::complex** recipkernelRho = new std::complex*[PARAM.inp.nspin]; + for (int is = 0; is < PARAM.inp.nspin; ++is) { recipkernelRho[is] = new std::complex[pw_rho->npw]; for (int ir = 0; ir < pw_rho->nrxx; ++ir) @@ -432,7 +432,7 @@ void KEDF_WT::multi_kernel(const double* const* prho, double** rkernel_rho, doub pw_rho->recip2real(recipkernelRho[is], rkernel_rho[is]); } - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { delete[] recipkernelRho[is]; } diff --git a/source/module_hamilt_pw/hamilt_pwdft/VNL_grad_pw.cpp b/source/module_hamilt_pw/hamilt_pwdft/VNL_grad_pw.cpp index d58e3f931d..161f72e0f5 100644 --- a/source/module_hamilt_pw/hamilt_pwdft/VNL_grad_pw.cpp +++ b/source/module_hamilt_pw/hamilt_pwdft/VNL_grad_pw.cpp @@ -1,5 +1,6 @@ #include "VNL_in_pw.h" #include "module_base/math_sphbes.h" +#include "module_parameter/parameter.h" #include "module_base/timer.h" #include "module_base/math_ylmreal.h" #include "module_base/math_integral.h" @@ -10,13 +11,13 @@ void pseudopot_cell_vnl::initgradq_vnl(const UnitCell &cell) const int nbrx = 10; const int nbrx_nc = 20; const int ntype = cell.ntype; - if(GlobalV::NSPIN!=4) + if(PARAM.inp.nspin!=4) { - this->tab_dq.create(ntype, nbrx, GlobalV::NQX); + this->tab_dq.create(ntype, nbrx, PARAM.globalv.nqx); } else { - this->tab_dq.create(ntype, nbrx_nc, GlobalV::NQX); + this->tab_dq.create(ntype, nbrx_nc, PARAM.globalv.nqx); } gradvkb.create(3, nkb, this->wfcpw->npwk_max); @@ -36,9 +37,9 @@ void pseudopot_cell_vnl::initgradq_vnl(const UnitCell &cell) for (int ib = 0;ib < nbeta;ib++) { const int l = cell.atoms[it].ncpp.lll[ib]; - for (int iq=0; iqtab, it, nb, GlobalV::NQX, GlobalV::DQ, gnorm ); + this->tab, it, nb, PARAM.globalv.nqx, PARAM.globalv.dq, gnorm ); dvq[ig] =ModuleBase::PolyInt::Polynomial_Interpolation( - this->tab_dq, it, nb, GlobalV::NQX, GlobalV::DQ, gnorm ); + this->tab_dq, it, nb, PARAM.globalv.nqx, PARAM.globalv.dq, gnorm ); } nb0 = nb; } diff --git a/source/module_hamilt_pw/hamilt_pwdft/VNL_in_pw.cpp b/source/module_hamilt_pw/hamilt_pwdft/VNL_in_pw.cpp index 6c8ab20973..b27b62459e 100644 --- a/source/module_hamilt_pw/hamilt_pwdft/VNL_in_pw.cpp +++ b/source/module_hamilt_pw/hamilt_pwdft/VNL_in_pw.cpp @@ -80,7 +80,7 @@ void pseudopot_cell_vnl::release_memory() //----------------------------------- // setup lmaxkb, nhm, nkb, lmaxq -// allocate vkb, GlobalV::NQX, tab, tab_at +// allocate vkb, PARAM.globalv.nqx, tab, tab_at //----------------------------------- void pseudopot_cell_vnl::init(const int ntype, Structure_Factor* psf_in, @@ -149,28 +149,28 @@ void pseudopot_cell_vnl::init(const int ntype, this->nhtol.create(ntype, this->nhm); this->nhtolm.create(ntype, this->nhm); this->nhtoj.create(ntype, this->nhm); - this->deeq.create(GlobalV::NSPIN, GlobalC::ucell.nat, this->nhm, this->nhm); - this->deeq_nc.create(GlobalV::NSPIN, GlobalC::ucell.nat, this->nhm, this->nhm); + this->deeq.create(PARAM.inp.nspin, GlobalC::ucell.nat, this->nhm, this->nhm); + this->deeq_nc.create(PARAM.inp.nspin, GlobalC::ucell.nat, this->nhm, this->nhm); this->qq_nt.create(ntype, this->nhm, this->nhm); this->qq_so.create(ntype, 4, this->nhm, this->nhm); if (PARAM.globalv.device_flag == "gpu") { if (PARAM.inp.precision == "single") { - resmem_sd_op()(gpu_ctx, s_deeq, GlobalV::NSPIN * GlobalC::ucell.nat * this->nhm * this->nhm); + resmem_sd_op()(gpu_ctx, s_deeq, PARAM.inp.nspin * GlobalC::ucell.nat * this->nhm * this->nhm); resmem_sd_op()(gpu_ctx, s_nhtol, ntype * this->nhm); resmem_sd_op()(gpu_ctx, s_nhtolm, ntype * this->nhm); resmem_sd_op()(gpu_ctx, s_indv, ntype * this->nhm); resmem_sd_op()(gpu_ctx, s_qq_nt, ntype * this->nhm * this->nhm); - resmem_cd_op()(gpu_ctx, c_deeq_nc, GlobalV::NSPIN * GlobalC::ucell.nat * this->nhm * this->nhm); + resmem_cd_op()(gpu_ctx, c_deeq_nc, PARAM.inp.nspin * GlobalC::ucell.nat * this->nhm * this->nhm); resmem_cd_op()(gpu_ctx, c_qq_so, ntype * 4 * this->nhm * this->nhm); } else { - resmem_zd_op()(gpu_ctx, z_deeq_nc, GlobalV::NSPIN * GlobalC::ucell.nat * this->nhm * this->nhm); + resmem_zd_op()(gpu_ctx, z_deeq_nc, PARAM.inp.nspin * GlobalC::ucell.nat * this->nhm * this->nhm); resmem_zd_op()(gpu_ctx, z_qq_so, ntype * 4 * this->nhm * this->nhm); } - resmem_dd_op()(gpu_ctx, d_deeq, GlobalV::NSPIN * GlobalC::ucell.nat * this->nhm * this->nhm); + resmem_dd_op()(gpu_ctx, d_deeq, PARAM.inp.nspin * GlobalC::ucell.nat * this->nhm * this->nhm); resmem_dd_op()(gpu_ctx, d_indv, ntype * this->nhm); resmem_dd_op()(gpu_ctx, d_nhtol, ntype * this->nhm); resmem_dd_op()(gpu_ctx, d_nhtolm, ntype * this->nhm); @@ -182,7 +182,7 @@ void pseudopot_cell_vnl::init(const int ntype, { resmem_sh_op()(cpu_ctx, s_deeq, - GlobalV::NSPIN * GlobalC::ucell.nat * this->nhm * this->nhm, + PARAM.inp.nspin * GlobalC::ucell.nat * this->nhm * this->nhm, "VNL::s_deeq"); resmem_sh_op()(cpu_ctx, s_nhtol, ntype * this->nhm, "VNL::s_nhtol"); resmem_sh_op()(cpu_ctx, s_nhtolm, ntype * this->nhm, "VNL::s_nhtolm"); @@ -190,7 +190,7 @@ void pseudopot_cell_vnl::init(const int ntype, resmem_sh_op()(cpu_ctx, s_qq_nt, ntype * this->nhm * this->nhm, "VNL::s_qq_nt"); resmem_ch_op()(cpu_ctx, c_deeq_nc, - GlobalV::NSPIN * GlobalC::ucell.nat * this->nhm * this->nhm, + PARAM.inp.nspin * GlobalC::ucell.nat * this->nhm * this->nhm, "VNL::c_deeq_nc"); resmem_ch_op()(cpu_ctx, c_qq_so, ntype * 4 * this->nhm * this->nhm, "VNL::c_qq_so"); } @@ -207,7 +207,7 @@ void pseudopot_cell_vnl::init(const int ntype, // There's no need to delete double precision pointers while in a CPU environment. } this->dvan.create(ntype, this->nhm, this->nhm); - this->dvan_so.create(GlobalV::NSPIN, ntype, this->nhm, this->nhm); + this->dvan_so.create(PARAM.inp.nspin, ntype, this->nhm, this->nhm); this->ijtoh.create(ntype, this->nhm, this->nhm); this->qq_at.create(GlobalC::ucell.nat, this->nhm, this->nhm); @@ -228,9 +228,7 @@ void pseudopot_cell_vnl::init(const int ntype, } // this->nqx = 10000; // calculted in allocate_nlpot.f90 - GlobalV::NQX = static_cast((sqrt(PARAM.inp.ecutwfc) / GlobalV::DQ + 4.0) * cell_factor); - GlobalV::NQXQ = static_cast((sqrt(PARAM.inp.ecutrho) / GlobalV::DQ + 4.0) * cell_factor); - // GlobalV::NQXQ = static_cast(((sqrt(INPUT.ecutrho) + qnorm) / GlobalV::DQ + 4.0) * cell_factor); + // PARAM.globalv.nqxq = static_cast(((sqrt(INPUT.ecutrho) + qnorm) / PARAM.globalv.dq + 4.0) * cell_factor); // mohan update 2021-02-22 // liuyu update 2023-09-28 @@ -238,20 +236,20 @@ void pseudopot_cell_vnl::init(const int ntype, { const int nbrx_nc = 2 * nbetam; // nbetam: max number of beta functions - if (GlobalV::NSPIN != 4) + if (PARAM.inp.nspin != 4) { - this->tab.create(ntype, nbetam, GlobalV::NQX); - ModuleBase::Memory::record("VNL::tab", ntype * nbetam * GlobalV::NQX * sizeof(double)); + this->tab.create(ntype, nbetam, PARAM.globalv.nqx); + ModuleBase::Memory::record("VNL::tab", ntype * nbetam * PARAM.globalv.nqx * sizeof(double)); } else { - this->tab.create(ntype, nbrx_nc, GlobalV::NQX); - ModuleBase::Memory::record("VNL::tab", ntype * nbrx_nc * GlobalV::NQX * sizeof(double)); + this->tab.create(ntype, nbrx_nc, PARAM.globalv.nqx); + ModuleBase::Memory::record("VNL::tab", ntype * nbrx_nc * PARAM.globalv.nqx * sizeof(double)); } if (lmaxq > 0) { - this->qrad.create(ntype, lmaxq, nbetam * (nbetam + 1) / 2, GlobalV::NQXQ); + this->qrad.create(ntype, lmaxq, nbetam * (nbetam + 1) / 2, PARAM.globalv.nqxq); } } @@ -261,15 +259,15 @@ void pseudopot_cell_vnl::init(const int ntype, { int nchix_nc = 2 * nwfcm; // nwfcm : max number of atomic wavefunctions per atom - if (GlobalV::NSPIN != 4) + if (PARAM.inp.nspin != 4) { - this->tab_at.create(ntype, nwfcm, GlobalV::NQX); - ModuleBase::Memory::record("VNL::tab_at", ntype * nwfcm * GlobalV::NQX * sizeof(double)); + this->tab_at.create(ntype, nwfcm, PARAM.globalv.nqx); + ModuleBase::Memory::record("VNL::tab_at", ntype * nwfcm * PARAM.globalv.nqx * sizeof(double)); } else { - this->tab_at.create(ntype, nchix_nc, GlobalV::NQX); - ModuleBase::Memory::record("VNL::tab_at", ntype * nchix_nc * GlobalV::NQX * sizeof(double)); + this->tab_at.create(ntype, nchix_nc, PARAM.globalv.nqx); + ModuleBase::Memory::record("VNL::tab_at", ntype * nchix_nc * PARAM.globalv.nqx * sizeof(double)); } } if (PARAM.globalv.device_flag == "gpu") @@ -366,8 +364,8 @@ void pseudopot_cell_vnl::getvnl(const int& ik, ModuleBase::ComplexMatrix& vkb_in vq[ig] = ModuleBase::PolyInt::Polynomial_Interpolation(this->tab, it, nb, - GlobalV::NQX, - GlobalV::DQ, + PARAM.globalv.nqx, + PARAM.globalv.dq, gnorm); } @@ -510,7 +508,7 @@ void pseudopot_cell_vnl::getvnl(Device* ctx, const int& ik, std::complex atom_na, atom_nb, atom_nh, - static_cast(GlobalV::DQ), + static_cast(PARAM.globalv.dq), static_cast(GlobalC::ucell.tpiba), static_cast>(ModuleBase::NEG_IMAG_UNIT), gk, @@ -846,9 +844,9 @@ void pseudopot_cell_vnl::init_vnl(UnitCell& cell, const ModulePW::PW_Basis* rho_ for (int ib = 0; ib < nbeta; ib++) { const int l = cell.atoms[it].ncpp.lll[ib]; - for (int iq = 0; iq < GlobalV::NQX; iq++) + for (int iq = 0; iq < PARAM.globalv.nqx; iq++) { - const double q = iq * GlobalV::DQ; + const double q = iq * PARAM.globalv.dq; ModuleBase::Sphbes::Spherical_Bessel(kkbeta, cell.atoms[it].ncpp.r.data(), q, l, jl); for (int ir = 0; ir < kkbeta; ir++) @@ -925,9 +923,9 @@ void pseudopot_cell_vnl::compute_qrad(UnitCell& cell) for (int l = 0; l < upf->nqlc; l++) { - for (int iq = 0; iq < GlobalV::NQXQ; iq++) + for (int iq = 0; iq < PARAM.globalv.nqxq; iq++) { - const double q = iq * GlobalV::DQ; + const double q = iq * PARAM.globalv.dq; // here we compute the spherical bessel function for each q_i ModuleBase::Sphbes::Spherical_Bessel(kkbeta, upf->r.data(), q, l, besr); for (int nb = 0; nb < nbeta; nb++) @@ -1036,8 +1034,8 @@ void pseudopot_cell_vnl::radial_fft_q(const int ng, itype, l, ijv, - GlobalV::NQXQ, - GlobalV::DQ, + PARAM.globalv.nqxq, + PARAM.globalv.dq, qnorm[ig]); qm1 = qnorm[ig]; } @@ -1127,8 +1125,8 @@ void pseudopot_cell_vnl::radial_fft_q(Device* ctx, itype, l, ijv, - GlobalV::NQXQ, - GlobalV::DQ, + PARAM.globalv.nqxq, + PARAM.globalv.dq, qnorm_double[ig]); qm1 = qnorm_double[ig]; } @@ -1248,7 +1246,7 @@ double pseudopot_cell_vnl::CG(int l1, int m1, int l2, int m2, int L, int M) // p // { // const double gnorm = gk[ig].norm() * GlobalC::ucell.tpiba; // vq [ig] = ModuleBase::PolyInt::Polynomial_Interpolation( -// this->tab_alpha, it, nb, L, GlobalV::NQX, GlobalV::DQ, gnorm); +// this->tab_alpha, it, nb, L, PARAM.globalv.nqx, PARAM.globalv.dq, gnorm); // for (int M=0; M<2*L+1; M++) // { @@ -1321,7 +1319,7 @@ void pseudopot_cell_vnl::init_vnl_alpha() // pengfei Li 2018-3-23 const int nbrx = 10; const double pref = ModuleBase::FOUR_PI / sqrt(GlobalC::ucell.omega); - this->tab_alpha.create(GlobalC::ucell.ntype, nbrx, lmaxkb + 2, GlobalV::NQX); + this->tab_alpha.create(GlobalC::ucell.ntype, nbrx, lmaxkb + 2, PARAM.globalv.nqx); this->tab_alpha.zero_out(); GlobalV::ofs_running << "\n Init Non-Local PseudoPotential table( including L index) : "; for (int it = 0; it < GlobalC::ucell.ntype; it++) @@ -1343,9 +1341,9 @@ void pseudopot_cell_vnl::init_vnl_alpha() // pengfei Li 2018-3-23 { for (int L = 0; L <= lmaxkb + 1; L++) { - for (int iq = 0; iq < GlobalV::NQX; iq++) + for (int iq = 0; iq < PARAM.globalv.nqx; iq++) { - const double q = iq * GlobalV::DQ; + const double q = iq * PARAM.globalv.dq; ModuleBase::Sphbes::Spherical_Bessel(kkbeta, GlobalC::ucell.atoms[it].ncpp.r.data(), q, L, jl); for (int ir = 0; ir < kkbeta; ir++) @@ -1396,7 +1394,7 @@ void pseudopot_cell_vnl::cal_effective_D(const ModuleBase::matrix& veff, const int it = cell.iat2it[iat]; const int nht = cell.atoms[it].ncpp.nh; // nht: number of beta functions per atom type - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { for (int ih = 0; ih < nht; ih++) { @@ -1407,7 +1405,7 @@ void pseudopot_cell_vnl::cal_effective_D(const ModuleBase::matrix& veff, this->deeq_nc(is, iat, ih, jh) = this->dvan_so(is, it, ih, jh); this->deeq_nc(is, iat, jh, ih) = this->dvan_so(is, it, jh, ih); } - else if (GlobalV::NSPIN == 4) + else if (PARAM.inp.nspin == 4) { if (is == 0) { @@ -1467,7 +1465,7 @@ void pseudopot_cell_vnl::cal_effective_D(const ModuleBase::matrix& veff, } else { - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { for (int ih = 0; ih < cell.atoms[it].ncpp.nh; ih++) { @@ -1489,12 +1487,12 @@ void pseudopot_cell_vnl::cal_effective_D(const ModuleBase::matrix& veff, cpu_ctx, this->s_deeq, this->deeq.ptr, - GlobalV::NSPIN * cell.nat * this->nhm * this->nhm); + PARAM.inp.nspin * cell.nat * this->nhm * this->nhm); castmem_z2c_h2d_op()(gpu_ctx, cpu_ctx, this->c_deeq_nc, this->deeq_nc.ptr, - GlobalV::NSPIN * cell.nat * this->nhm * this->nhm); + PARAM.inp.nspin * cell.nat * this->nhm * this->nhm); } else { @@ -1502,13 +1500,13 @@ void pseudopot_cell_vnl::cal_effective_D(const ModuleBase::matrix& veff, cpu_ctx, this->z_deeq_nc, this->deeq_nc.ptr, - GlobalV::NSPIN * cell.nat * this->nhm * this->nhm); + PARAM.inp.nspin * cell.nat * this->nhm * this->nhm); } syncmem_d2d_h2d_op()(gpu_ctx, cpu_ctx, this->d_deeq, this->deeq.ptr, - GlobalV::NSPIN * cell.nat * this->nhm * this->nhm); + PARAM.inp.nspin * cell.nat * this->nhm * this->nhm); } else { @@ -1518,12 +1516,12 @@ void pseudopot_cell_vnl::cal_effective_D(const ModuleBase::matrix& veff, cpu_ctx, this->s_deeq, this->deeq.ptr, - GlobalV::NSPIN * cell.nat * this->nhm * this->nhm); + PARAM.inp.nspin * cell.nat * this->nhm * this->nhm); castmem_z2c_h2h_op()(cpu_ctx, cpu_ctx, this->c_deeq_nc, this->deeq_nc.ptr, - GlobalV::NSPIN * cell.nat * this->nhm * this->nhm); + PARAM.inp.nspin * cell.nat * this->nhm * this->nhm); } // There's no need to synchronize double precision pointers while in a CPU environment. } @@ -1551,8 +1549,8 @@ void pseudopot_cell_vnl::newq(const ModuleBase::matrix& veff, const ModulePW::PW } // fourier transform of the total effective potential - ModuleBase::ComplexMatrix vaux(GlobalV::NSPIN, npw); - for (int is = 0; is < GlobalV::NSPIN; is++) + ModuleBase::ComplexMatrix vaux(PARAM.inp.nspin, npw); + for (int is = 0; is < PARAM.inp.nspin; is++) { rho_basis->real2recip(&veff.c[is * veff.nc], &vaux(is, 0)); } @@ -1582,7 +1580,7 @@ void pseudopot_cell_vnl::newq(const ModuleBase::matrix& veff, const ModulePW::PW const int natom = cell.atoms[it].na; ModuleBase::ComplexMatrix aux(natom, npw); ModuleBase::matrix deeaux(natom, nij); - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { for (int ia = 0; ia < natom; ia++) { diff --git a/source/module_hamilt_pw/hamilt_pwdft/forces.cpp b/source/module_hamilt_pw/hamilt_pwdft/forces.cpp index 3373bce73b..0e7ed6b229 100644 --- a/source/module_hamilt_pw/hamilt_pwdft/forces.cpp +++ b/source/module_hamilt_pw/hamilt_pwdft/forces.cpp @@ -238,7 +238,7 @@ void Forces::cal_force(ModuleBase::matrix& force, { rhor[ir] = 0.0; } - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { for (int ir = 0; ir < rho_basis->nrxx; ir++) { @@ -248,12 +248,12 @@ void Forces::cal_force(ModuleBase::matrix& force, force_paw = new double[3 * this->nat]; ModuleBase::matrix v_xc, v_effective; - v_effective.create(GlobalV::NSPIN, rho_basis->nrxx); + v_effective.create(PARAM.inp.nspin, rho_basis->nrxx); v_effective.zero_out(); elec.pot->update_from_charge(elec.charge, &GlobalC::ucell); v_effective = elec.pot->get_effective_v(); - v_xc.create(GlobalV::NSPIN, rho_basis->nrxx); + v_xc.create(PARAM.inp.nspin, rho_basis->nrxx); v_xc.zero_out(); const std::tuple etxc_vtxc_v = XC_Functional::v_xc(rho_basis->nrxx, elec.charge, &GlobalC::ucell); @@ -475,7 +475,7 @@ void Forces::cal_force_loc(ModuleBase::matrix& forcelc, blocking rho_basis->nrxx for data locality. By blocking aux with block size 1024, - we can keep the blocked aux in L1 cache when iterating GlobalV::NSPIN loop + we can keep the blocked aux in L1 cache when iterating PARAM.inp.nspin loop performance will be better when number of atom is quite huge */ const int block_ir = 1024; @@ -493,7 +493,7 @@ void Forces::cal_force_loc(ModuleBase::matrix& forcelc, aux[ir] = std::complex(chr->rho[0][ir], 0.0); } } - if (GlobalV::NSPIN == 2) + if (PARAM.inp.nspin == 2) { for (int ir = irb; ir < ir_end; ++ir) { // accumulate aux diff --git a/source/module_hamilt_pw/hamilt_pwdft/forces_cc.cpp b/source/module_hamilt_pw/hamilt_pwdft/forces_cc.cpp index b4b09c768a..4b5e7a2aff 100644 --- a/source/module_hamilt_pw/hamilt_pwdft/forces_cc.cpp +++ b/source/module_hamilt_pw/hamilt_pwdft/forces_cc.cpp @@ -1,5 +1,6 @@ #include "forces.h" #include "stress_func.h" +#include "module_parameter/parameter.h" #include "module_hamilt_pw/hamilt_pwdft/global.h" #include "module_io/output_log.h" // new @@ -49,7 +50,7 @@ void Forces::cal_force_cc(ModuleBase::matrix& forcecc, return; } - ModuleBase::matrix v(GlobalV::NSPIN, rho_basis->nrxx); + ModuleBase::matrix v(PARAM.inp.nspin, rho_basis->nrxx); if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5) { @@ -66,7 +67,7 @@ void Forces::cal_force_cc(ModuleBase::matrix& forcecc, } else { - if (GlobalV::NSPIN == 4) { + if (PARAM.inp.nspin == 4) { ucell_in.cal_ux(); } const auto etxc_vtxc_v = XC_Functional::v_xc(rho_basis->nrxx, chr, &ucell_in); @@ -78,7 +79,7 @@ void Forces::cal_force_cc(ModuleBase::matrix& forcecc, const ModuleBase::matrix vxc = v; std::complex* psiv = new std::complex[rho_basis->nmaxgr]; - if (GlobalV::NSPIN == 1 || GlobalV::NSPIN == 4) + if (PARAM.inp.nspin == 1 || PARAM.inp.nspin == 4) { #ifdef _OPENMP #pragma omp parallel for schedule(static, 1024) diff --git a/source/module_hamilt_pw/hamilt_pwdft/forces_us.cpp b/source/module_hamilt_pw/hamilt_pwdft/forces_us.cpp index c42fe6322d..aca975431f 100644 --- a/source/module_hamilt_pw/hamilt_pwdft/forces_us.cpp +++ b/source/module_hamilt_pw/hamilt_pwdft/forces_us.cpp @@ -1,5 +1,6 @@ #include "forces.h" #include "module_base/libm/libm.h" +#include "module_parameter/parameter.h" #include "module_base/math_ylmreal.h" #include "module_base/timer.h" #include "module_elecstate/elecstate_pw.h" @@ -31,9 +32,9 @@ void Forces::cal_force_us(ModuleBase::matrix& forcenl, ModuleBase::matrix forceq(ucell.nat, 3); ModuleBase::matrix veff = elec.pot->get_effective_v(); - ModuleBase::ComplexMatrix vg(GlobalV::NSPIN, npw); + ModuleBase::ComplexMatrix vg(PARAM.inp.nspin, npw); // fourier transform of the total effective potential - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { rho_basis->real2recip(&veff.c[is * veff.nc], &vg(is, 0)); } @@ -71,8 +72,8 @@ void Forces::cal_force_us(ModuleBase::matrix& forcenl, double* qgm_data = reinterpret_cast(qgm.c); ModuleBase::ComplexArray aux1(3, atom->na, npw); - ModuleBase::realArray ddeeq(GlobalV::NSPIN, 3, atom->na, nij); - for (int is = 0; is < GlobalV::NSPIN; is++) + ModuleBase::realArray ddeeq(PARAM.inp.nspin, 3, atom->na, nij); + for (int is = 0; is < PARAM.inp.nspin; is++) { for (int ia = 0; ia < atom->na; ia++) { @@ -113,7 +114,7 @@ void Forces::cal_force_us(ModuleBase::matrix& forcenl, } } - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { for (int ia = 0; ia < atom->na; ia++) { diff --git a/source/module_hamilt_pw/hamilt_pwdft/fs_nonlocal_tools.cpp b/source/module_hamilt_pw/hamilt_pwdft/fs_nonlocal_tools.cpp index f6773b3ddb..5e4d54b86f 100644 --- a/source/module_hamilt_pw/hamilt_pwdft/fs_nonlocal_tools.cpp +++ b/source/module_hamilt_pw/hamilt_pwdft/fs_nonlocal_tools.cpp @@ -1,6 +1,7 @@ #include "fs_nonlocal_tools.h" #include "module_base/math_polyint.h" +#include "module_parameter/parameter.h" #include "module_base/math_ylmreal.h" #include "module_base/memory.h" #include "module_base/timer.h" @@ -207,7 +208,7 @@ void FS_Nonlocal_tools::cal_becp(int ik, int npm) npw, this->nlpp_->tab.getBound2(), this->nlpp_->tab.getBound3(), - GlobalV::DQ, + PARAM.globalv.dq, this->ucell_->atoms[it].ncpp.nbeta, hd_vq); @@ -331,7 +332,7 @@ void FS_Nonlocal_tools::cal_dbecp_s(int ik, int npm, int ipol, i npw, this->nlpp_->tab.getBound2(), this->nlpp_->tab.getBound3(), - GlobalV::DQ, + PARAM.globalv.dq, this->ucell_->atoms[it].ncpp.nbeta, hd_vq); cal_vq_deri_op()(this->ctx, @@ -341,7 +342,7 @@ void FS_Nonlocal_tools::cal_dbecp_s(int ik, int npm, int ipol, i npw, this->nlpp_->tab.getBound2(), this->nlpp_->tab.getBound3(), - GlobalV::DQ, + PARAM.globalv.dq, this->ucell_->atoms[it].ncpp.nbeta, hd_vq_deri); diff --git a/source/module_hamilt_pw/hamilt_pwdft/kernels/vnl_op.h b/source/module_hamilt_pw/hamilt_pwdft/kernels/vnl_op.h index 0e346f856e..3e02910abe 100644 --- a/source/module_hamilt_pw/hamilt_pwdft/kernels/vnl_op.h +++ b/source/module_hamilt_pw/hamilt_pwdft/kernels/vnl_op.h @@ -23,7 +23,7 @@ struct cal_vnl_op /// @param atom_nh - GlobalC::ucell.atoms[ii].ncpp.nh /// @param atom_nb - GlobalC::ucell.atoms[it].ncpp.nbeta /// @param atom_na - GlobalC::ucell.atoms[ii].na - /// @param DQ - GlobalV::DQ + /// @param DQ - PARAM.globalv.dq /// @param tpiba - GlobalC::ucell.tpiba /// @param NEG_IMAG_UNIT - ModuleBase::NEG_IMAG_UNIT /// @param gk - GlobalC::wf.get_1qvec_cartesian diff --git a/source/module_hamilt_pw/hamilt_pwdft/operator_pw/projop_pw.cpp b/source/module_hamilt_pw/hamilt_pwdft/operator_pw/projop_pw.cpp index 5c2a4e1bc1..2543f78662 100644 --- a/source/module_hamilt_pw/hamilt_pwdft/operator_pw/projop_pw.cpp +++ b/source/module_hamilt_pw/hamilt_pwdft/operator_pw/projop_pw.cpp @@ -1,5 +1,6 @@ #include #include +#include "module_parameter/parameter.h" #include #include #include @@ -69,8 +70,8 @@ * // the `rgrid` and `projs` are also the output of function `init_proj` * // the `iproj2l` is the angular momentum for each projector, actually you have used it in `init_proj`, it * // is the same as `lproj` - * // the `nq` is the number of G+k vectors, typically it is always GlobalV::NQX - * // the `dq` is the step size of G+k vectors, typically it is always GlobalV::DQ + * // the `nq` is the number of G+k vectors, typically it is always PARAM.globalv.nqx + * // the `dq` is the step size of G+k vectors, typically it is always PARAM.globalv.dq * // the `ik` is the k-point index * // the `pw_basis` is the plane wave basis, need ik * // the `omega` is the cell volume @@ -176,8 +177,8 @@ void cal_becp(const std::vector>& it2ia, // level0: for g const std::vector& rgrid, // level0: the radial grid shared by all projectors const std::vector>& projs, // level0: projectors indexed by `iproj` const std::vector& iproj2l, // level0: for given proj index `iproj`, the angular momentum `l` - const int nq, // level0: GlobalV::NQX - const double& dq, // level0: GlobalV::DQ + const int nq, // level0: PARAM.globalv.nqx + const double& dq, // level0: PARAM.globalv.dq const int ik, // level1: the k-point index const ModulePW::PW_Basis_K& pw_basis, // level1: the plane wave basis, need ik const double& omega, // level1: the cell volume diff --git a/source/module_hamilt_pw/hamilt_pwdft/radial_proj.h b/source/module_hamilt_pw/hamilt_pwdft/radial_proj.h index 1e1e85ac43..2867403b4b 100644 --- a/source/module_hamilt_pw/hamilt_pwdft/radial_proj.h +++ b/source/module_hamilt_pw/hamilt_pwdft/radial_proj.h @@ -155,13 +155,13 @@ namespace RadialProjection const double* r, const std::vector& radials, const std::vector& l, - const int nq, //< GlobalV::DQ - const double& dq); //< GlobalV::NQX + const int nq, //< PARAM.globalv.dq + const double& dq); //< PARAM.globalv.nqx void _build_sbt_tab(const std::vector& r, const std::vector>& radials, const std::vector& l, - const int nq, //< GlobalV::DQ - const double& dq); //< GlobalV::NQX + const int nq, //< PARAM.globalv.dq + const double& dq); //< PARAM.globalv.nqx /** * @brief perform analytical version of the Fourier transform: diff --git a/source/module_hamilt_pw/hamilt_pwdft/stress_func_cc.cpp b/source/module_hamilt_pw/hamilt_pwdft/stress_func_cc.cpp index caa22230ca..2850c58ef7 100644 --- a/source/module_hamilt_pw/hamilt_pwdft/stress_func_cc.cpp +++ b/source/module_hamilt_pw/hamilt_pwdft/stress_func_cc.cpp @@ -1,5 +1,6 @@ #include "stress_func.h" #include "module_hamilt_general/module_xc/xc_functional.h" +#include "module_parameter/parameter.h" #include "module_base/math_integral.h" #include "module_base/timer.h" #include "module_hamilt_pw/hamilt_pwdft/global.h" @@ -57,7 +58,7 @@ void Stress_Func::stress_cc(ModuleBase::matrix& sigma, } else { - if(GlobalV::NSPIN==4) { GlobalC::ucell.cal_ux(); + if(PARAM.inp.nspin==4) { GlobalC::ucell.cal_ux(); } const auto etxc_vtxc_v = XC_Functional::v_xc(rho_basis->nrxx, chr, &GlobalC::ucell); // etxc = std::get<0>(etxc_vtxc_v); // may delete? @@ -67,7 +68,7 @@ void Stress_Func::stress_cc(ModuleBase::matrix& sigma, std::complex* psic = new std::complex[rho_basis->nmaxgr]; - if(GlobalV::NSPIN==1||GlobalV::NSPIN==4) + if(PARAM.inp.nspin==1||PARAM.inp.nspin==4) { #ifdef _OPENMP #pragma omp parallel for schedule(static, 1024) diff --git a/source/module_hamilt_pw/hamilt_pwdft/stress_func_har.cpp b/source/module_hamilt_pw/hamilt_pwdft/stress_func_har.cpp index 131275a223..9858b0186e 100644 --- a/source/module_hamilt_pw/hamilt_pwdft/stress_func_har.cpp +++ b/source/module_hamilt_pw/hamilt_pwdft/stress_func_har.cpp @@ -1,5 +1,6 @@ #include "stress_func.h" #include "module_elecstate/potentials/H_Hartree_pw.h" +#include "module_parameter/parameter.h" #include "module_base/timer.h" #include "module_hamilt_pw/hamilt_pwdft/global.h" @@ -12,14 +13,14 @@ void Stress_Func::stress_har(ModuleBase::matrix& sigma, ModulePW std::complex *aux = new std::complex[rho_basis->nmaxgr]; - const int nspin_rho = (GlobalV::NSPIN == 2) ? 2 : 1; + const int nspin_rho = (PARAM.inp.nspin == 2) ? 2 : 1; // Hartree potential VH(r) from n(r) /* blocking rho_basis->nrxx for data locality. By blocking aux with block size 1024, - we can keep the blocked aux in L1 cache when iterating GlobalV::NSPIN loop + we can keep the blocked aux in L1 cache when iterating PARAM.inp.nspin loop performance will be better when number of atom is quite huge */ const int block_ir = 1024; diff --git a/source/module_hamilt_pw/hamilt_pwdft/stress_func_loc.cpp b/source/module_hamilt_pw/hamilt_pwdft/stress_func_loc.cpp index 7a6b9074be..7a0d614f6f 100644 --- a/source/module_hamilt_pw/hamilt_pwdft/stress_func_loc.cpp +++ b/source/module_hamilt_pw/hamilt_pwdft/stress_func_loc.cpp @@ -1,5 +1,6 @@ #include "stress_func.h" #include "module_base/math_integral.h" +#include "module_parameter/parameter.h" #include "module_base/tool_threading.h" #include "module_base/timer.h" #include "module_base/libm/libm.h" @@ -20,7 +21,7 @@ void Stress_Func::stress_loc(ModuleBase::matrix& sigma, FPTYPE evloc=0.0; FPTYPE fact=1.0; - const int nspin_rho = (GlobalV::NSPIN == 2) ? 2 : 1; + const int nspin_rho = (PARAM.inp.nspin == 2) ? 2 : 1; if (PARAM.globalv.gamma_only_pw && is_pw) { fact=2.0; } @@ -33,7 +34,7 @@ void Stress_Func::stress_loc(ModuleBase::matrix& sigma, blocking rho_basis->nrxx for data locality. By blocking aux with block size 1024, - we can keep the blocked aux in L1 cache when iterating GlobalV::NSPIN loop + we can keep the blocked aux in L1 cache when iterating PARAM.inp.nspin loop performance will be better when number of atom is quite huge */ const int block_ir = 1024; diff --git a/source/module_hamilt_pw/hamilt_pwdft/stress_func_mgga.cpp b/source/module_hamilt_pw/hamilt_pwdft/stress_func_mgga.cpp index bb588a338a..56ef7ebd86 100644 --- a/source/module_hamilt_pw/hamilt_pwdft/stress_func_mgga.cpp +++ b/source/module_hamilt_pw/hamilt_pwdft/stress_func_mgga.cpp @@ -1,5 +1,6 @@ #include "module_base/timer.h" #include "module_hamilt_general/module_xc/xc_functional.h" +#include "module_parameter/parameter.h" #include "module_hamilt_pw/hamilt_pwdft/global.h" #include "stress_func.h" @@ -18,7 +19,7 @@ void Stress_Func::stress_mgga(ModuleBase::matrix& sigma, { ModuleBase::timer::tick("Stress_Func", "stress_mgga"); - if (GlobalV::NSPIN == 4) + if (PARAM.inp.nspin == 4) ModuleBase::WARNING_QUIT("stress_mgga", "noncollinear stress + mGGA not implemented"); int current_spin = 0; @@ -37,13 +38,13 @@ void Stress_Func::stress_mgga(ModuleBase::matrix& sigma, auto crosstaus = ct::Tensor( ct::DataTypeToEnum::value, ct::DeviceTypeToEnum::value, - {GlobalV::NSPIN, nrxx * 6}); + {PARAM.inp.nspin, nrxx * 6}); crosstaus.zero(); // Must be zeroed out auto cal_stress_mgga_solver = hamilt::cal_stress_mgga_op, Device>(); for (int ik = 0; ik < p_kv->get_nks(); ik++) { - if (GlobalV::NSPIN == 2) + if (PARAM.inp.nspin == 2) current_spin = p_kv->isk[ik]; const int npw = p_kv->ngk[ik]; @@ -60,7 +61,7 @@ void Stress_Func::stress_mgga(ModuleBase::matrix& sigma, auto crosstaus_host = crosstaus.to_device(); auto crosstaus_pack = crosstaus_host.accessor(); #ifdef __MPI - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { for (int ipol = 0; ipol < 6; ++ipol) { @@ -77,7 +78,7 @@ void Stress_Func::stress_mgga(ModuleBase::matrix& sigma, } } - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { for (int ix = 0; ix < 3; ix++) { diff --git a/source/module_hamilt_pw/hamilt_pwdft/stress_func_nl.cpp b/source/module_hamilt_pw/hamilt_pwdft/stress_func_nl.cpp index a4771764de..d3cbb06885 100644 --- a/source/module_hamilt_pw/hamilt_pwdft/stress_func_nl.cpp +++ b/source/module_hamilt_pw/hamilt_pwdft/stress_func_nl.cpp @@ -110,8 +110,9 @@ void Stress_Func::get_dvnl1(ModuleBase::ComplexMatrix& vkb, Structure_Factor* p_sf, ModulePW::PW_Basis_K* wfc_basis) { - if (PARAM.inp.test_pp) + if (PARAM.inp.test_pp) { ModuleBase::TITLE("Stress_Func", "get_dvnl1"); +} const int npw = wfc_basis->npwk[ik]; const int lmaxkb = nlpp->lmaxkb; @@ -144,19 +145,22 @@ void Stress_Func::get_dvnl1(ModuleBase::ComplexMatrix& vkb, int jkb = 0; for (int it = 0; it < this->ucell->ntype; it++) { - if (PARAM.inp.test_pp > 1) + if (PARAM.inp.test_pp > 1) { ModuleBase::GlobalFunc::OUT("it", it); +} // calculate beta in G-space using an interpolation table const int nbeta = this->ucell->atoms[it].ncpp.nbeta; const int nh = this->ucell->atoms[it].ncpp.nh; - if (PARAM.inp.test_pp > 1) + if (PARAM.inp.test_pp > 1) { ModuleBase::GlobalFunc::OUT("nbeta", nbeta); +} for (int nb = 0; nb < nbeta; nb++) { - if (PARAM.inp.test_pp > 1) + if (PARAM.inp.test_pp > 1) { ModuleBase::GlobalFunc::OUT("ib", nb); +} #ifdef _OPENMP #pragma omp parallel for #endif @@ -170,8 +174,8 @@ void Stress_Func::get_dvnl1(ModuleBase::ComplexMatrix& vkb, vq[ig] = ModuleBase::PolyInt::Polynomial_Interpolation(nlpp->tab, it, nb, - GlobalV::NQX, - GlobalV::DQ, + PARAM.globalv.nqx, + PARAM.globalv.dq, gnorm); } // enddo @@ -227,8 +231,9 @@ void Stress_Func::get_dvnl2(ModuleBase::ComplexMatrix& vkb, Structure_Factor* p_sf, ModulePW::PW_Basis_K* wfc_basis) { - if (PARAM.inp.test_pp) + if (PARAM.inp.test_pp) { ModuleBase::TITLE("Stress", "get_dvnl2"); +} // ModuleBase::timer::tick("Stress","get_dvnl2"); const int npw = wfc_basis->npwk[ik]; const int lmaxkb = nlpp->lmaxkb; @@ -259,19 +264,22 @@ void Stress_Func::get_dvnl2(ModuleBase::ComplexMatrix& vkb, int jkb = 0; for (int it = 0; it < this->ucell->ntype; it++) { - if (PARAM.inp.test_pp > 1) + if (PARAM.inp.test_pp > 1) { ModuleBase::GlobalFunc::OUT("it", it); +} // calculate beta in G-space using an interpolation table const int nbeta = this->ucell->atoms[it].ncpp.nbeta; const int nh = this->ucell->atoms[it].ncpp.nh; - if (PARAM.inp.test_pp > 1) + if (PARAM.inp.test_pp > 1) { ModuleBase::GlobalFunc::OUT("nbeta", nbeta); +} for (int nb = 0; nb < nbeta; nb++) { - if (PARAM.inp.test_pp > 1) + if (PARAM.inp.test_pp > 1) { ModuleBase::GlobalFunc::OUT("ib", nb); +} #ifdef _OPENMP #pragma omp parallel for #endif @@ -283,7 +291,7 @@ void Stress_Func::get_dvnl2(ModuleBase::ComplexMatrix& vkb, vq[ig] = hamilt::Nonlocal_maths::Polynomial_Interpolation_nl(nlpp->tab, it, nb, - GlobalV::DQ, + PARAM.globalv.dq, gnorm); } // enddo diff --git a/source/module_hamilt_pw/hamilt_pwdft/stress_func_us.cpp b/source/module_hamilt_pw/hamilt_pwdft/stress_func_us.cpp index bb5b583434..1af5e857c4 100644 --- a/source/module_hamilt_pw/hamilt_pwdft/stress_func_us.cpp +++ b/source/module_hamilt_pw/hamilt_pwdft/stress_func_us.cpp @@ -27,9 +27,9 @@ void Stress_PW::stress_us(ModuleBase::matrix& sigma, ModuleBase::matrix stressus(3, 3); ModuleBase::matrix veff = this->pelec->pot->get_effective_v(); - ModuleBase::ComplexMatrix vg(GlobalV::NSPIN, npw); + ModuleBase::ComplexMatrix vg(PARAM.inp.nspin, npw); // fourier transform of the total effective potential - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { rho_basis->real2recip(&veff.c[is * veff.nc], &vg(is, 0)); } @@ -66,7 +66,7 @@ void Stress_PW::stress_us(ModuleBase::matrix& sigma, // qgm contains derivatives of the Fourier transform of the Q function const int nij = atom->ncpp.nh * (atom->ncpp.nh + 1) / 2; ModuleBase::ComplexMatrix qgm(nij, npw); - ModuleBase::matrix tbecsum(GlobalV::NSPIN, nij); + ModuleBase::matrix tbecsum(PARAM.inp.nspin, nij); // Compute and store derivatives of Q(G) for this atomic species // (without structure factor) @@ -95,7 +95,7 @@ void Stress_PW::stress_us(ModuleBase::matrix& sigma, for (int ia = 0; ia < atom->na; ia++) { const int iat = ucell.itia2iat(it, ia); - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { for (int ij = 0; ij < nij; ij++) { @@ -103,7 +103,7 @@ void Stress_PW::stress_us(ModuleBase::matrix& sigma, } } - ModuleBase::ComplexMatrix aux2(GlobalV::NSPIN, npw); + ModuleBase::ComplexMatrix aux2(PARAM.inp.nspin, npw); double* aux2_data = reinterpret_cast(aux2.c); const char transa = 'N'; @@ -114,7 +114,7 @@ void Stress_PW::stress_us(ModuleBase::matrix& sigma, dgemm_(&transa, &transb, &dim, - &GlobalV::NSPIN, + &PARAM.inp.nspin, &nij, &one, qgm_data, @@ -125,7 +125,7 @@ void Stress_PW::stress_us(ModuleBase::matrix& sigma, aux2_data, &dim); - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { for (int ig = 0; ig < npw; ig++) { @@ -145,13 +145,13 @@ void Stress_PW::stress_us(ModuleBase::matrix& sigma, } } - ModuleBase::matrix fac(GlobalV::NSPIN, 3); + ModuleBase::matrix fac(PARAM.inp.nspin, 3); const char transc = 'T'; const int three = 3; dgemm_(&transc, &transb, &three, - &GlobalV::NSPIN, + &PARAM.inp.nspin, &dim, &one, aux1_data, @@ -162,7 +162,7 @@ void Stress_PW::stress_us(ModuleBase::matrix& sigma, fac.c, &three); - for (int is = 0; is < GlobalV::NSPIN; is++) + for (int is = 0; is < PARAM.inp.nspin; is++) { for (int jpol = 0; jpol < 3; jpol++) { @@ -276,10 +276,10 @@ void Stress_Func::dqvan2(const pseudopot_cell_vnl* ppcell_in, itype, l, ijv, - GlobalV::NQXQ, - GlobalV::DQ, + PARAM.globalv.nqxq, + PARAM.globalv.dq, qnorm[ig]); - work1 = this->Polynomial_Interpolation_nl(ppcell_in->qrad, itype, l, ijv, GlobalV::DQ, qnorm[ig]); + work1 = this->Polynomial_Interpolation_nl(ppcell_in->qrad, itype, l, ijv, PARAM.globalv.dq, qnorm[ig]); qm1 = qnorm[ig]; } dqg[ig] += pref * work * dylmk0(lp, ig) / tpiba; diff --git a/source/module_hamilt_pw/hamilt_pwdft/wavefunc.cpp b/source/module_hamilt_pw/hamilt_pwdft/wavefunc.cpp index 96084eda1e..7353ceabde 100644 --- a/source/module_hamilt_pw/hamilt_pwdft/wavefunc.cpp +++ b/source/module_hamilt_pw/hamilt_pwdft/wavefunc.cpp @@ -44,7 +44,7 @@ psi::Psi>* wavefunc::allocate(const int nkstot, const int n // if use spin orbital, do not double nks but double allocate evc and wanf2. int prefactor = 1; - if (GlobalV::NSPIN == 4) + if (PARAM.inp.nspin == 4) { prefactor = PARAM.globalv.npol; // added by zhengdy-soc } @@ -282,8 +282,8 @@ void diago_PAO_in_pw_k2(const int& ik, wfc_basis, wfcatom, GlobalC::ppcell.tab_at, - GlobalV::NQX, - GlobalV::DQ); + PARAM.globalv.nqx, + PARAM.globalv.dq); if (p_wf->init_wfc == "atomic+random" && starting_nw == GlobalC::ucell.natomwfc) // added by qianrui 2021-5-16 { @@ -439,8 +439,8 @@ void diago_PAO_in_pw_k2(const int& ik, wfc_basis, wfcatom, GlobalC::ppcell.tab_at, - GlobalV::NQX, - GlobalV::DQ); + PARAM.globalv.nqx, + PARAM.globalv.dq); if (p_wf->init_wfc == "atomic+random" && starting_nw == GlobalC::ucell.natomwfc) // added by qianrui 2021-5-16 { @@ -547,8 +547,8 @@ void diago_PAO_in_pw_k2(const base_device::DEVICE_GPU* ctx, wfc_basis, wfcatom, GlobalC::ppcell.tab_at, - GlobalV::NQX, - GlobalV::DQ); + PARAM.globalv.nqx, + PARAM.globalv.dq); if (p_wf->init_wfc == "atomic+random" && starting_nw == GlobalC::ucell.natomwfc) // added by qianrui 2021-5-16 { p_wf->atomicrandom(wfcatom, 0, starting_nw, ik, wfc_basis); @@ -650,8 +650,8 @@ void diago_PAO_in_pw_k2(const base_device::DEVICE_GPU* ctx, wfc_basis, wfcatom, GlobalC::ppcell.tab_at, - GlobalV::NQX, - GlobalV::DQ); + PARAM.globalv.nqx, + PARAM.globalv.dq); if (p_wf->init_wfc == "atomic+random" && starting_nw == GlobalC::ucell.natomwfc) // added by qianrui 2021-5-16 { p_wf->atomicrandom(wfcatom, 0, starting_nw, ik, wfc_basis); diff --git a/source/module_hamilt_pw/hamilt_pwdft/wf_atomic.cpp b/source/module_hamilt_pw/hamilt_pwdft/wf_atomic.cpp index 35ca3b564d..89827a5efe 100644 --- a/source/module_hamilt_pw/hamilt_pwdft/wf_atomic.cpp +++ b/source/module_hamilt_pw/hamilt_pwdft/wf_atomic.cpp @@ -74,8 +74,8 @@ void WF_atomic::init_at_1(Structure_Factor *sf_in) double *aux = new double[ndm]; double *vchi = new double[ndm]; - ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"dq(describe PAO in reciprocal space)",GlobalV::DQ); - ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"max q",GlobalV::NQX); + ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"dq(describe PAO in reciprocal space)",PARAM.globalv.dq); + ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"max q",PARAM.globalv.nqx); for (int it=0; itncpp.oc[ic] >= 0.0) { const int l = atom->ncpp.lchi[ic]; - for (int iq=startq; iqncpp.msh, atom->ncpp.r.data(), q, l, aux); for (int ir = 0;ir < atom->ncpp.msh;ir++) { @@ -314,7 +314,7 @@ void WF_atomic::atomic_wfc(const int ik, it, iw, table_dimension, dq, gk[ig].norm() * GlobalC::ucell.tpiba ); } - if(GlobalV::NSPIN==4) + if(PARAM.inp.nspin==4) { if(GlobalC::ucell.atoms[it].ncpp.has_so) { diff --git a/source/module_hsolver/diago_pexsi.cpp b/source/module_hsolver/diago_pexsi.cpp index f7bd881bed..431fe5660f 100644 --- a/source/module_hsolver/diago_pexsi.cpp +++ b/source/module_hsolver/diago_pexsi.cpp @@ -1,5 +1,6 @@ #include #include +#include "module_parameter/parameter.h" #include #ifdef __PEXSI #include "diago_pexsi.h" @@ -19,8 +20,8 @@ std::vector DiagoPexsi::mu_buffer; template DiagoPexsi::DiagoPexsi(const Parallel_Orbitals* ParaV_in) { - int nspin = GlobalV::NSPIN; - if (GlobalV::NSPIN == 4) + int nspin = PARAM.inp.nspin; + if (PARAM.inp.nspin == 4) { nspin = 1; } @@ -46,8 +47,8 @@ DiagoPexsi::DiagoPexsi(const Parallel_Orbitals* ParaV_in) template DiagoPexsi::~DiagoPexsi() { - int nspin = GlobalV::NSPIN; - if (GlobalV::NSPIN == 4) + int nspin = PARAM.inp.nspin; + if (PARAM.inp.nspin == 4) { nspin = 1; } diff --git a/source/module_hsolver/hsolver_lcao.cpp b/source/module_hsolver/hsolver_lcao.cpp index 66818d6eb7..833a26fe18 100644 --- a/source/module_hsolver/hsolver_lcao.cpp +++ b/source/module_hsolver/hsolver_lcao.cpp @@ -1,5 +1,6 @@ #include "hsolver_lcao.h" +#include "module_parameter/parameter.h" #include "diago_cg.h" #ifdef __MPI @@ -324,7 +325,7 @@ void HSolverLCAO::parakSolve(hamilt::Hamilt* pHamilt, nb2d, GlobalV::NPROC, GlobalV::MY_RANK, - GlobalV::NSPIN); + PARAM.inp.nspin); /// set psi_pool const int zero = 0; int ncol_bands_pool = numroc_(&(nbands), &(nb2d), &(k2d.get_p2D_pool()->coord[1]), &zero, &(k2d.get_p2D_pool()->dim1)); diff --git a/source/module_hsolver/hsolver_pw.cpp b/source/module_hsolver/hsolver_pw.cpp index b032215b91..09c8814e9f 100644 --- a/source/module_hsolver/hsolver_pw.cpp +++ b/source/module_hsolver/hsolver_pw.cpp @@ -460,7 +460,7 @@ void HSolverPW::hamiltSolvePsiK(hamilt::Hamilt* hm, psi.get_nbands(), psi.get_k_first() ? psi.get_current_nbas() : psi.get_nk() * psi.get_nbasis(), - GlobalV::PW_DIAG_NDIM, + PARAM.inp.pw_diag_ndim, this->diag_thr, this->diag_iter_max, this->need_subspace, @@ -529,7 +529,7 @@ void HSolverPW::hamiltSolvePsiK(hamilt::Hamilt* hm, DiagoDavid david(pre_condition.data(), nband, dim, - GlobalV::PW_DIAG_NDIM, + PARAM.inp.pw_diag_ndim, this->use_paw, comm_info); // do diag and add davidson iteration counts up to avg_iter diff --git a/source/module_hsolver/module_pexsi/simple_pexsi.cpp b/source/module_hsolver/module_pexsi/simple_pexsi.cpp index d2961c40bd..2eaf215961 100644 --- a/source/module_hsolver/module_pexsi/simple_pexsi.cpp +++ b/source/module_hsolver/module_pexsi/simple_pexsi.cpp @@ -1,5 +1,6 @@ // use PEXSI to solve a Kohn-Sham equation // the H and S matrices are given by 2D block cyclic distribution +#include "module_parameter/parameter.h" // the Density Matrix and Energy Density Matrix calculated by PEXSI are transformed to 2D block cyclic distribution // #include "mpi.h" #ifdef __PEXSI @@ -114,7 +115,7 @@ int loadPEXSIOption(MPI_Comm comm, int_para[15] = 0; int_para[16] = pexsi::PEXSI_Solver::pexsi_nproc_pole; - double_para[0] = 2;//GlobalV::NSPIN; // pexsi::PEXSI_Solver::pexsi_spin; + double_para[0] = 2;//PARAM.inp.nspin; // pexsi::PEXSI_Solver::pexsi_spin; double_para[1] = pexsi::PEXSI_Solver::pexsi_temp; double_para[2] = pexsi::PEXSI_Solver::pexsi_gap; double_para[3] = pexsi::PEXSI_Solver::pexsi_delta_e; diff --git a/source/module_hsolver/test/diago_pexsi_test.cpp b/source/module_hsolver/test/diago_pexsi_test.cpp index 693e84f9bd..1c0f6e08ea 100644 --- a/source/module_hsolver/test/diago_pexsi_test.cpp +++ b/source/module_hsolver/test/diago_pexsi_test.cpp @@ -1,5 +1,8 @@ #ifdef __PEXSI #include "module_hsolver/diago_pexsi.h" +#define private public +#include "module_parameter/parameter.h" +#undef private #include "module_base/global_variable.h" #include "module_base/parallel_global.h" @@ -183,7 +186,7 @@ class PexsiPrepare GlobalV::NLOCAL = nlocal; GlobalV::NBANDS = nbands; GlobalV::DSIZE = dsize; - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; DIAG_WORLD = MPI_COMM_WORLD; GlobalV::NPROC = dsize; diff --git a/source/module_hsolver/test/test_hsolver_pw.cpp b/source/module_hsolver/test/test_hsolver_pw.cpp index 62d49a35d1..2d8d5b4f07 100644 --- a/source/module_hsolver/test/test_hsolver_pw.cpp +++ b/source/module_hsolver/test/test_hsolver_pw.cpp @@ -44,7 +44,7 @@ class TestHSolverPW : public ::testing::Test { "cg", false, GlobalV::use_uspp, - GlobalV::NSPIN, + PARAM.input.nspin, hsolver::DiagoIterAssist, base_device::DEVICE_CPU>::SCF_ITER, hsolver::DiagoIterAssist, base_device::DEVICE_CPU>::PW_DIAG_NMAX, hsolver::DiagoIterAssist, base_device::DEVICE_CPU>::PW_DIAG_THR, @@ -59,7 +59,7 @@ class TestHSolverPW : public ::testing::Test { "cg", false, GlobalV::use_uspp, - GlobalV::NSPIN, + PARAM.input.nspin, hsolver::DiagoIterAssist, base_device::DEVICE_CPU>::SCF_ITER, hsolver::DiagoIterAssist, base_device::DEVICE_CPU>::PW_DIAG_NMAX, hsolver::DiagoIterAssist, base_device::DEVICE_CPU>::PW_DIAG_THR, diff --git a/source/module_hsolver/test/test_hsolver_sdft.cpp b/source/module_hsolver/test/test_hsolver_sdft.cpp index dbeeac396e..1943701078 100644 --- a/source/module_hsolver/test/test_hsolver_sdft.cpp +++ b/source/module_hsolver/test/test_hsolver_sdft.cpp @@ -1,5 +1,8 @@ #include #include +#define private public +#include "module_parameter/parameter.h" +#undef private #include #define private public @@ -144,7 +147,7 @@ class TestHSolverPW_SDFT : public ::testing::Test "cg", false, GlobalV::use_uspp, - GlobalV::NSPIN, + PARAM.input.nspin, hsolver::DiagoIterAssist>::SCF_ITER, hsolver::DiagoIterAssist>::PW_DIAG_NMAX, hsolver::DiagoIterAssist>::PW_DIAG_THR, @@ -220,7 +223,7 @@ TEST_F(TestHSolverPW_SDFT, solve_noband_skipcharge) psi_test_no.nbasis = 0; GlobalV::nelec = 1.0; GlobalV::MY_STOGROUP = 0.0; - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; elecstate_test.charge = new Charge; elecstate_test.charge->rho = new double*[1]; elecstate_test.charge->rho[0] = new double[10]; diff --git a/source/module_io/berryphase.cpp b/source/module_io/berryphase.cpp index 87bb673103..7324a22822 100644 --- a/source/module_io/berryphase.cpp +++ b/source/module_io/berryphase.cpp @@ -1,5 +1,6 @@ #include "berryphase.h" +#include "module_parameter/parameter.h" #include "module_cell/klist.h" #include "module_hamilt_pw/hamilt_pwdft/global.h" @@ -63,12 +64,12 @@ void berryphase::set_kpoints(const K_Vectors& kv, const int direction) { const int num_string = mp_y * mp_z; - if (GlobalV::NSPIN == 1 || GlobalV::NSPIN == 4) + if (PARAM.inp.nspin == 1 || PARAM.inp.nspin == 4) { total_string = num_string; k_index.resize(total_string); } - else if (GlobalV::NSPIN == 2) + else if (PARAM.inp.nspin == 2) { total_string = 2 * num_string; k_index.resize(total_string); @@ -96,7 +97,7 @@ void berryphase::set_kpoints(const K_Vectors& kv, const int direction) } } - if (GlobalV::NSPIN == 2) + if (PARAM.inp.nspin == 2) { for (int istring = num_string; istring < total_string; istring++) { @@ -113,12 +114,12 @@ void berryphase::set_kpoints(const K_Vectors& kv, const int direction) { const int num_string = mp_x * mp_z; - if (GlobalV::NSPIN == 1 || GlobalV::NSPIN == 4) + if (PARAM.inp.nspin == 1 || PARAM.inp.nspin == 4) { total_string = num_string; k_index.resize(total_string); } - else if (GlobalV::NSPIN == 2) + else if (PARAM.inp.nspin == 2) { total_string = 2 * num_string; k_index.resize(total_string); @@ -146,7 +147,7 @@ void berryphase::set_kpoints(const K_Vectors& kv, const int direction) } } - if (GlobalV::NSPIN == 2) + if (PARAM.inp.nspin == 2) { for (int istring = num_string; istring < total_string; istring++) { @@ -163,12 +164,12 @@ void berryphase::set_kpoints(const K_Vectors& kv, const int direction) { const int num_string = mp_x * mp_y; - if (GlobalV::NSPIN == 1 || GlobalV::NSPIN == 4) + if (PARAM.inp.nspin == 1 || PARAM.inp.nspin == 4) { total_string = num_string; k_index.resize(total_string); } - else if (GlobalV::NSPIN == 2) + else if (PARAM.inp.nspin == 2) { total_string = 2 * num_string; k_index.resize(total_string); @@ -196,7 +197,7 @@ void berryphase::set_kpoints(const K_Vectors& kv, const int direction) } } - if (GlobalV::NSPIN == 2) + if (PARAM.inp.nspin == 2) { for (int istring = num_string; istring < total_string; istring++) { @@ -260,7 +261,7 @@ double berryphase::stringPhase(int index_str, for (int nb = 0; nb < nbands; nb++) { - if (GlobalV::NSPIN != 4) + if (PARAM.inp.nspin != 4) { if (k_start == (nppstr - 2)) { @@ -343,7 +344,7 @@ double berryphase::stringPhase(int index_str, #ifdef __LCAO else if (PARAM.inp.basis_type == "lcao") { - if (GlobalV::NSPIN != 4) + if (PARAM.inp.nspin != 4) { // std::complex my_det = lcao_method.det_berryphase(ik_1,ik_2,dk,nbands); zeta = zeta * lcao_method.det_berryphase(ik_1, ik_2, dk, nbands, *(this->paraV), psi_in, kv); @@ -413,7 +414,7 @@ void berryphase::Berry_Phase(int nbands, for (int istring = 0; istring < total_string; istring++) { wistring[istring] = 1.0 / total_string; - if (GlobalV::NSPIN == 2) { + if (PARAM.inp.nspin == 2) { wistring[istring] = wistring[istring] * 2; } } @@ -439,21 +440,21 @@ void berryphase::Berry_Phase(int nbands, // test by jingan } - if (GlobalV::NSPIN == 1) + if (PARAM.inp.nspin == 1) { pdl_elec_tot = 2 * phik_ave; } - else if (GlobalV::NSPIN == 2 || GlobalV::NSPIN == 4) + else if (PARAM.inp.nspin == 2 || PARAM.inp.nspin == 4) { pdl_elec_tot = phik_ave; } - if (GlobalV::NSPIN == 1) // remap to [-1,1] + if (PARAM.inp.nspin == 1) // remap to [-1,1] { pdl_elec_tot = pdl_elec_tot - 2.0 * round(pdl_elec_tot / 2.0); mod_elec_tot = 2; } - else if (GlobalV::NSPIN == 2 || GlobalV::NSPIN == 4) // remap to [-0.5,0.5] + else if (PARAM.inp.nspin == 2 || PARAM.inp.nspin == 4) // remap to [-0.5,0.5] { pdl_elec_tot = pdl_elec_tot - 1.0 * round(pdl_elec_tot / 1.0); mod_elec_tot = 1; @@ -575,7 +576,7 @@ void berryphase::Macroscopic_polarization(const int npwx, // calculate Macroscopic polarization modulus because berry phase int modulus = 0; - if ((!lodd) && (GlobalV::NSPIN == 1)) { + if ((!lodd) && (PARAM.inp.nspin == 1)) { modulus = 2; } else { modulus = 1; diff --git a/source/module_io/dos_nao.cpp b/source/module_io/dos_nao.cpp index 6468b33348..fb993cc201 100644 --- a/source/module_io/dos_nao.cpp +++ b/source/module_io/dos_nao.cpp @@ -38,7 +38,7 @@ namespace ModuleIO write_dos_lcao(psi, pv, ekb, wg, dos_edelta_ev, dos_scale, dos_sigma, kv, p_ham); - int nspin0 = (GlobalV::NSPIN == 2) ? 2 : 1; + int nspin0 = (PARAM.inp.nspin == 2) ? 2 : 1; if (PARAM.inp.out_dos == 3) { for (int i = 0; i < nspin0; i++) diff --git a/source/module_io/input_conv.cpp b/source/module_io/input_conv.cpp index abe21ba929..d4c1398575 100644 --- a/source/module_io/input_conv.cpp +++ b/source/module_io/input_conv.cpp @@ -227,8 +227,6 @@ void Input_Conv::Convert() #endif // __ENABLE_FLOAT_FFTW } - GlobalV::NSPIN = PARAM.inp.nspin; - #ifdef __LCAO Force_Stress_LCAO::force_invalid_threshold_ev = PARAM.inp.force_thr_ev2; @@ -242,13 +240,9 @@ void Input_Conv::Convert() Ions_Move_Basic::relax_bfgs_rmin = PARAM.inp.relax_bfgs_rmin; Ions_Move_Basic::relax_bfgs_init = PARAM.inp.relax_bfgs_init; Ions_Move_Basic::out_stru = PARAM.inp.out_stru; // mohan add 2012-03-23 + Ions_Move_Basic::relax_method = PARAM.inp.relax_method; Lattice_Change_Basic::fixed_axes = PARAM.inp.fixed_axes; - GlobalV::CAL_STRESS = PARAM.inp.cal_stress; - - - GlobalV::RELAX_METHOD = PARAM.inp.relax_method; - Ions_Move_CG::RELAX_CG_THR = PARAM.inp.relax_cg_thr; // pengfei add 2013-09-09 @@ -264,9 +258,7 @@ void Input_Conv::Convert() //---------------------------------------------------------- // diagonalization (5/5) //---------------------------------------------------------- - GlobalV::PW_DIAG_NDIM = PARAM.inp.pw_diag_ndim; - GlobalV::PW_DIAG_THR = PARAM.inp.pw_diag_thr; GlobalV::NB2D = PARAM.inp.nb2d; //---------------------------------------------------------- @@ -304,7 +296,6 @@ void Input_Conv::Convert() GlobalV::nelec = PARAM.inp.nelec; if (PARAM.globalv.two_fermi) { - GlobalV::TWO_EFERMI = true; GlobalV::nupdown = PARAM.inp.nupdown; } elecstate::Gatefield::zgate = PARAM.inp.zgate; diff --git a/source/module_io/json_output/output_info.cpp b/source/module_io/json_output/output_info.cpp index 8e58bf8179..a432ee449f 100644 --- a/source/module_io/json_output/output_info.cpp +++ b/source/module_io/json_output/output_info.cpp @@ -72,7 +72,7 @@ namespace Json // AbacusJson::add_Json(force_array,false,"output",-1,"force"); } - if (GlobalV::CAL_STRESS){ + if (PARAM.inp.cal_stress){ //add stress Json::jsonValue stress_array(JarrayType); for (int i = 0; i < 3; i++) diff --git a/source/module_io/numerical_basis.cpp b/source/module_io/numerical_basis.cpp index f02048990e..4e562f91b8 100644 --- a/source/module_io/numerical_basis.cpp +++ b/source/module_io/numerical_basis.cpp @@ -1,5 +1,6 @@ #include "numerical_basis.h" +#include "module_parameter/parameter.h" #include "module_base/constants.h" #include "module_base/global_variable.h" #include "module_base/intarray.h" @@ -652,7 +653,7 @@ void Numerical_Basis::output_k(std::ofstream& ofs, const K_Vectors& kv) #ifdef __MPI // temprary restrict kpar=1 for NSPIN=2 case for generating_orbitals int pool = 0; - if (GlobalV::NSPIN != 2) { + if (PARAM.inp.nspin != 2) { pool = GlobalC::Pkpoints.whichpool[ik]; } const int iknow = ik - GlobalC::Pkpoints.startk_pool[GlobalV::MY_POOL]; @@ -793,7 +794,7 @@ void Numerical_Basis::output_overlap_Sq(const std::string& name, std::ofstream& // only half of nkstot should be output in "NSPIN == 2" case, k_up and k_down has same k infomation int ispin = 1; - if (GlobalV::NSPIN == 2) { + if (PARAM.inp.nspin == 2) { ispin = 2; } int nkstot = kv.get_nkstot() / ispin; diff --git a/source/module_io/output_log.cpp b/source/module_io/output_log.cpp index b7a70dacab..a940422ea4 100644 --- a/source/module_io/output_log.cpp +++ b/source/module_io/output_log.cpp @@ -140,7 +140,7 @@ void output_vacuum_level(const UnitCell* ucell, { totchg[ir] = rho[0][ir]; } - if (GlobalV::NSPIN == 2) + if (PARAM.inp.nspin == 2) { for (int ir = 0; ir < nrxx; ++ir) { diff --git a/source/module_io/output_mulliken.cpp b/source/module_io/output_mulliken.cpp index 9bf8c70db4..3de113059b 100644 --- a/source/module_io/output_mulliken.cpp +++ b/source/module_io/output_mulliken.cpp @@ -1,5 +1,6 @@ #include "module_io/output_mulliken.h" +#include "module_parameter/parameter.h" #include "module_base/formatter.h" #include "module_base/name_angular.h" #include "module_base/scalapack_connector.h" @@ -568,8 +569,8 @@ void Output_Mulliken::cal_orbMulP() int nw = this->cell_index_->get_nw(); const int nspin = (this->nspin_ == 2) ? 2 : 1; const int nlocal = (this->nspin_ == 4) ? nw / 2 : nw; - // std::vector> MecMulP(GlobalV::NSPIN, std::vector(nlocal, 0)); - // std::vector> orbMulP(GlobalV::NSPIN, std::vector(nlocal, 0)); + // std::vector> MecMulP(PARAM.inp.nspin, std::vector(nlocal, 0)); + // std::vector> orbMulP(PARAM.inp.nspin, std::vector(nlocal, 0)); ModuleBase::matrix MecMulP(this->nspin_, nlocal, true); this->orbMulP_.create(this->nspin_, nlocal, true); diff --git a/source/module_io/print_info.cpp b/source/module_io/print_info.cpp index 2d15c07701..5976cb11ad 100644 --- a/source/module_io/print_info.cpp +++ b/source/module_io/print_info.cpp @@ -79,7 +79,7 @@ void Print_Info::setup_parameters(UnitCell &ucell, K_Vectors &kv) if (orbinfo) { std::cout << std::setw(12) << "NBASE"; } std::cout << std::endl; - std::cout << " " << std::setw(8) << GlobalV::NSPIN; + std::cout << " " << std::setw(8) << PARAM.inp.nspin; if(PARAM.globalv.gamma_only_local) { diff --git a/source/module_io/read_set_globalv.cpp b/source/module_io/read_set_globalv.cpp index 3760cc51fb..9b0ac2af89 100644 --- a/source/module_io/read_set_globalv.cpp +++ b/source/module_io/read_set_globalv.cpp @@ -91,6 +91,9 @@ void ReadInput::set_globalv(Parameter& para) GlobalV::ofs_warning << "Parameter \"device\" can only be set to \"cpu\" or \"gpu\"!" << std::endl; ModuleBase::WARNING_QUIT("device", "Parameter \"device\" can only be set to \"cpu\" or \"gpu\"!"); } + + para.sys.nqx=static_cast((sqrt(para.inp.ecutwfc) / para.sys.dq + 4.0) * para.inp.cell_factor); + para.sys.nqxq=static_cast((sqrt(para.inp.ecutrho) / para.sys.dq + 4.0) * para.inp.cell_factor); } } @@ -125,5 +128,8 @@ void ReadInput::set_globalv_bcast() add_bool_bcast(sys.double_grid); add_double_bcast(sys.uramping); + add_double_bcast(sys.dq); + add_int_bcast(sys.nqx); + add_int_bcast(sys.nqxq); } } // namespace ModuleIO diff --git a/source/module_io/read_wfc_to_rho.cpp b/source/module_io/read_wfc_to_rho.cpp index fb0f3b4929..abd3a3c2b1 100644 --- a/source/module_io/read_wfc_to_rho.cpp +++ b/source/module_io/read_wfc_to_rho.cpp @@ -19,7 +19,7 @@ void ModuleIO::read_wfc_to_rho(const ModulePW::PW_Basis_K* pw_wfc, const int my_pool = GlobalV::MY_POOL; const int my_rank = GlobalV::MY_RANK; const int nbands = GlobalV::NBANDS; - const int nspin = GlobalV::NSPIN; + const int nspin = PARAM.inp.nspin; const int npwk_max = pw_wfc->npwk_max; const int nrxx = pw_wfc->nrxx; diff --git a/source/module_io/rhog_io.cpp b/source/module_io/rhog_io.cpp index 5460aafb12..fba566cc02 100644 --- a/source/module_io/rhog_io.cpp +++ b/source/module_io/rhog_io.cpp @@ -1,5 +1,6 @@ #include "binstream.h" #include "module_base/global_function.h" +#include "module_parameter/parameter.h" #include "module_base/global_variable.h" #include "module_base/parallel_global.h" #include "module_base/timer.h" @@ -63,7 +64,7 @@ bool ModuleIO::read_rhog(const std::string& filename, const ModulePW::PW_Basis* { ModuleBase::WARNING("ModuleIO::read_rhog", "some planewaves in file are missing"); } - if (nspin_in < GlobalV::NSPIN) + if (nspin_in < PARAM.inp.nspin) { ModuleBase::WARNING("ModuleIO::read_rhog", "some spin channels in file are missing"); } @@ -105,7 +106,7 @@ bool ModuleIO::read_rhog(const std::string& filename, const ModulePW::PW_Basis* MPI_Bcast(miller.data(), miller.size(), MPI_INT, 0, POOL_WORLD); #endif // set to zero - for (int is = 0; is < GlobalV::NSPIN; ++is) + for (int is = 0; is < PARAM.inp.nspin; ++is) { ModuleBase::GlobalFunc::ZEROS(rhog[is], pw_rhod->npw); } @@ -164,7 +165,7 @@ bool ModuleIO::read_rhog(const std::string& filename, const ModulePW::PW_Basis* } } - if (nspin_in == 2 && GlobalV::NSPIN == 4 && is == 1) + if (nspin_in == 2 && PARAM.inp.nspin == 4 && is == 1) { for (int ig = 0; ig < pw_rhod->npw; ++ig) { diff --git a/source/module_io/td_current_io.cpp b/source/module_io/td_current_io.cpp index 31bee506a8..bb13b3a9a1 100644 --- a/source/module_io/td_current_io.cpp +++ b/source/module_io/td_current_io.cpp @@ -59,7 +59,7 @@ void ModuleIO::cal_tmp_DM(elecstate::DensityMatrix, double> } #endif // only ik - if (GlobalV::NSPIN != 4) + if (PARAM.inp.nspin != 4) { // cal k_phase // if TK==std::complex, kphase is e^{ikR} @@ -157,8 +157,8 @@ void ModuleIO::write_current(const int istep, // construct a DensityMatrix object // Since the function cal_dm_psi do not suport DMR in complex type, I replace it with two DMR in double type. Should // be refactored in the future. - elecstate::DensityMatrix, double> DM_real(&kv, pv, GlobalV::NSPIN); - elecstate::DensityMatrix, double> DM_imag(&kv, pv, GlobalV::NSPIN); + elecstate::DensityMatrix, double> DM_real(&kv, pv, PARAM.inp.nspin); + elecstate::DensityMatrix, double> DM_imag(&kv, pv, PARAM.inp.nspin); // calculate DMK elecstate::cal_dm_psi(DM_real.get_paraV_pointer(), pelec->wg, psi[0], DM_real); @@ -167,16 +167,16 @@ void ModuleIO::write_current(const int istep, DM_imag.init_DMR(ra, &GlobalC::ucell); int nks = DM_real.get_DMK_nks(); - if (GlobalV::NSPIN == 2) + if (PARAM.inp.nspin == 2) { nks /= 2; } double current_total[3] = {0.0, 0.0, 0.0}; - for (int is = 1; is <= GlobalV::NSPIN; ++is) + for (int is = 1; is <= PARAM.inp.nspin; ++is) { for (int ik = 0; ik < nks; ++ik) { - cal_tmp_DM(DM_real, DM_imag, ik, GlobalV::NSPIN, is); + cal_tmp_DM(DM_real, DM_imag, ik, PARAM.inp.nspin, is); // check later double current_ik[3] = {0.0, 0.0, 0.0}; int total_irr = 0; diff --git a/source/module_io/test/outputlog_test.cpp b/source/module_io/test/outputlog_test.cpp index 56cf4fa81e..1fd15a30ea 100644 --- a/source/module_io/test/outputlog_test.cpp +++ b/source/module_io/test/outputlog_test.cpp @@ -181,7 +181,7 @@ pseudo::~pseudo() TEST(OutputVacuumLevelTest, OutputVacuumLevel) { - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; UnitCell ucell; const int nx = 50, ny = 50, nz = 50, nxyz = 125000, nrxx = 125000, nplane = 50, startz_current = 0; diff --git a/source/module_io/test/read_rhog_test.cpp b/source/module_io/test/read_rhog_test.cpp index fabb5c7ccb..bba037d55c 100644 --- a/source/module_io/test/read_rhog_test.cpp +++ b/source/module_io/test/read_rhog_test.cpp @@ -1,5 +1,8 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" +#define private public +#include "module_parameter/parameter.h" +#undef private #include "module_io/rhog_io.h" #ifdef __MPI #include "module_basis/module_pw/test/test_tool.h" @@ -25,12 +28,15 @@ class ReadRhogTest : public ::testing::Test } virtual void TearDown() { - if (rhopw != nullptr) + if (rhopw != nullptr) { delete rhopw; - if (rhog[0] != nullptr) +} + if (rhog[0] != nullptr) { delete[] rhog[0]; - if (rhog != nullptr) +} + if (rhog != nullptr) { delete[] rhog; +} } }; @@ -38,7 +44,7 @@ class ReadRhogTest : public ::testing::Test TEST_F(ReadRhogTest, ReadRhog) { std::string filename = "./support/charge-density.dat"; - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; #ifdef __MPI rhopw->initmpi(GlobalV::NPROC_IN_POOL, GlobalV::RANK_IN_POOL, MPI_COMM_WORLD); #endif @@ -84,7 +90,7 @@ TEST_F(ReadRhogTest, NotFoundFile) TEST_F(ReadRhogTest, InconsistentGammaOnly) { std::string filename = "./support/charge-density.dat"; - GlobalV::NSPIN = 2; + PARAM.input.nspin = 2; rhopw->gamma_only = true; GlobalV::ofs_warning.open("test_read_rhog.txt"); @@ -111,7 +117,7 @@ TEST_F(ReadRhogTest, InconsistentGammaOnly) TEST_F(ReadRhogTest, SomePWMissing) { std::string filename = "./support/charge-density.dat"; - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; rhopw->npwtot = 2000; GlobalV::ofs_warning.open("test_read_rhog.txt"); diff --git a/source/module_io/test/read_wfc_to_rho_test.cpp b/source/module_io/test/read_wfc_to_rho_test.cpp index 7433e11500..0a1e42e09f 100644 --- a/source/module_io/test/read_wfc_to_rho_test.cpp +++ b/source/module_io/test/read_wfc_to_rho_test.cpp @@ -116,7 +116,7 @@ class ReadWfcRhoTest : public ::testing::Test rhopw = new ModulePW::PW_Basis; kv = new K_Vectors; GlobalV::NBANDS = 4; - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; PARAM.input.out_wfc_pw = 2; } virtual void TearDown() diff --git a/source/module_io/test/write_dos_pw_test.cpp b/source/module_io/test/write_dos_pw_test.cpp index 5aecdc0447..18448958a3 100644 --- a/source/module_io/test/write_dos_pw_test.cpp +++ b/source/module_io/test/write_dos_pw_test.cpp @@ -48,7 +48,7 @@ TEST_F(DosPWTest,Dos1) dosp.read_istate_info(); EXPECT_EQ(dosp.is,0); double dos_scale = 0.01; - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; PARAM.input.dos_emax_ev = dosp.emax_ev; PARAM.sys.dos_setemax = true; PARAM.input.dos_emin_ev = dosp.emin_ev; @@ -98,7 +98,7 @@ TEST_F(DosPWTest,Dos2) dosp.read_istate_info(); EXPECT_EQ(dosp.is,0); double dos_scale = 0.01; - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; PARAM.input.dos_emax_ev = dosp.emax_ev; PARAM.sys.dos_setemax = false; PARAM.input.dos_emin_ev = dosp.emin_ev; diff --git a/source/module_io/test/write_istate_info_test.cpp b/source/module_io/test/write_istate_info_test.cpp index d15ddc8274..43fc87f2b3 100644 --- a/source/module_io/test/write_istate_info_test.cpp +++ b/source/module_io/test/write_istate_info_test.cpp @@ -49,7 +49,7 @@ TEST_F(IstateInfoTest, OutIstateInfoS1) // preconditions GlobalV::KPAR = 1; GlobalV::NBANDS = 4; - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; PARAM.sys.global_out_dir = "./"; // mpi setting Parallel_Global::init_pools(GlobalV::NPROC, @@ -65,7 +65,7 @@ TEST_F(IstateInfoTest, OutIstateInfoS1) kv->set_nkstot(100); int nkstot = kv->get_nkstot(); Pkpoints - ->kinfo(nkstot, GlobalV::KPAR, GlobalV::MY_POOL, GlobalV::RANK_IN_POOL, GlobalV::NPROC_IN_POOL, GlobalV::NSPIN); + ->kinfo(nkstot, GlobalV::KPAR, GlobalV::MY_POOL, GlobalV::RANK_IN_POOL, GlobalV::NPROC_IN_POOL, PARAM.input.nspin); // std::cout<<"my_rank "<set_nkstot(100); int nkstot = kv->get_nkstot(); Pkpoints - ->kinfo(nkstot, GlobalV::KPAR, GlobalV::MY_POOL, GlobalV::RANK_IN_POOL, GlobalV::NPROC_IN_POOL, GlobalV::NSPIN); + ->kinfo(nkstot, GlobalV::KPAR, GlobalV::MY_POOL, GlobalV::RANK_IN_POOL, GlobalV::NPROC_IN_POOL, PARAM.input.nspin); // std::cout<<"my_rank "<read_cell_pseudopots(pp_dir,ofs); diff --git a/source/module_io/to_wannier90.cpp b/source/module_io/to_wannier90.cpp index 95d549d890..207fa4d150 100644 --- a/source/module_io/to_wannier90.cpp +++ b/source/module_io/to_wannier90.cpp @@ -52,7 +52,7 @@ toWannier90::~toWannier90() delete[] x_axis; delete[] alfa; - if (GlobalV::NSPIN == 4) + if (PARAM.inp.nspin == 4) { delete[] spin_eig; delete[] spin_qaxis; @@ -194,22 +194,22 @@ bool toWannier90::try_read_nnkp(const K_Vectors& kv) if (ModuleBase::GlobalFunc::SCAN_BEGIN(nnkp_read, "kpoints")) { num_kpts = kv.get_nkstot(); - if (GlobalV::NSPIN == 1 || GlobalV::NSPIN == 4) + if (PARAM.inp.nspin == 1 || PARAM.inp.nspin == 4) { cal_num_kpts = num_kpts; } - else if (GlobalV::NSPIN == 2) + else if (PARAM.inp.nspin == 2) { cal_num_kpts = num_kpts / 2; } int numkpt_nnkp; ModuleBase::GlobalFunc::READ_VALUE(nnkp_read, numkpt_nnkp); - if ((GlobalV::NSPIN == 1 || GlobalV::NSPIN == 4) && numkpt_nnkp != num_kpts) + if ((PARAM.inp.nspin == 1 || PARAM.inp.nspin == 4) && numkpt_nnkp != num_kpts) { ModuleBase::WARNING_QUIT("toWannier90::read_nnkp", "Error kpoints in *.nnkp file"); } - else if (GlobalV::NSPIN == 2 && numkpt_nnkp != (num_kpts / 2)) + else if (PARAM.inp.nspin == 2 && numkpt_nnkp != (num_kpts / 2)) { ModuleBase::WARNING_QUIT("toWannier90::read_nnkp", "Error kpoints in *.nnkp file"); } @@ -238,7 +238,7 @@ bool toWannier90::try_read_nnkp(const K_Vectors& kv) // read projections if (out_wannier_amn) { - if (GlobalV::NSPIN == 1 || GlobalV::NSPIN == 2) + if (PARAM.inp.nspin == 1 || PARAM.inp.nspin == 2) { if (ModuleBase::GlobalFunc::SCAN_BEGIN(nnkp_read, "projections")) { @@ -272,7 +272,7 @@ bool toWannier90::try_read_nnkp(const K_Vectors& kv) ModuleBase::WARNING_QUIT("toWannier90::read_nnkp", "Cannot find projections in *.nnkp file"); } } - else if (GlobalV::NSPIN == 4) + else if (PARAM.inp.nspin == 4) { if (ModuleBase::GlobalFunc::SCAN_BEGIN(nnkp_read, "spinor_projections")) { @@ -342,7 +342,7 @@ bool toWannier90::try_read_nnkp(const K_Vectors& kv) } // Generate spin-related coefficients - if (GlobalV::NSPIN == 4) + if (PARAM.inp.nspin == 4) { up_con = new std::complex[num_wannier]; dn_con = new std::complex[num_wannier]; @@ -416,11 +416,11 @@ bool toWannier90::try_read_nnkp(const K_Vectors& kv) } int numkpt_nnkp; - if (GlobalV::NSPIN == 1 || GlobalV::NSPIN == 4) + if (PARAM.inp.nspin == 1 || PARAM.inp.nspin == 4) { numkpt_nnkp = kv.get_nkstot(); } - else if (GlobalV::NSPIN == 2) + else if (PARAM.inp.nspin == 2) { numkpt_nnkp = kv.get_nkstot() / 2; } diff --git a/source/module_io/to_wannier90_lcao.cpp b/source/module_io/to_wannier90_lcao.cpp index 1223c86503..3ff2c6ad3f 100644 --- a/source/module_io/to_wannier90_lcao.cpp +++ b/source/module_io/to_wannier90_lcao.cpp @@ -47,7 +47,7 @@ void toWannier90_LCAO::calculate(const ModuleBase::matrix& ekb, read_nnkp(kv); - if (GlobalV::NSPIN == 2) + if (PARAM.inp.nspin == 2) { if (wannier_spin == "up") { @@ -1136,7 +1136,7 @@ void toWannier90_LCAO::unkdotA(const K_Vectors& kv, int row = this->ParaV->get_row_size(); int index_band = -1; int R_num = R_coor_car.size(); - if (GlobalV::NSPIN != 4) + if (PARAM.inp.nspin != 4) { for (int ib = 0; ib < GlobalV::NBANDS; ib++) { diff --git a/source/module_io/to_wannier90_lcao_in_pw.cpp b/source/module_io/to_wannier90_lcao_in_pw.cpp index 9cc6bb9acf..cd962f9678 100644 --- a/source/module_io/to_wannier90_lcao_in_pw.cpp +++ b/source/module_io/to_wannier90_lcao_in_pw.cpp @@ -53,7 +53,7 @@ void toWannier90_LCAO_IN_PW::calculate( this->psi_init_->allocate(true); read_nnkp(kv); - if (GlobalV::NSPIN == 2) + if (PARAM.inp.nspin == 2) { if (wannier_spin == "up") { @@ -118,7 +118,7 @@ psi::Psi>* toWannier90_LCAO_IN_PW::get_unk_from_lcao( unk_inLcao->zero_out(); // Orbital projection to plane wave - ModuleBase::realArray table_local(GlobalC::ucell.ntype, GlobalC::ucell.nmax_total, GlobalV::NQX); + ModuleBase::realArray table_local(GlobalC::ucell.ntype, GlobalC::ucell.nmax_total, PARAM.globalv.nqx); for (int ik = 0; ik < num_kpts; ik++) { @@ -131,7 +131,7 @@ psi::Psi>* toWannier90_LCAO_IN_PW::get_unk_from_lcao( ModuleBase::ComplexMatrix lcao_wfc_global; get_lcao_wfc_global_ik(ik, psi_in, lcao_wfc_global); - if (GlobalV::NSPIN != 4) + if (PARAM.inp.nspin != 4) { for (int ib = 0; ib < num_bands; ib++) { diff --git a/source/module_io/to_wannier90_pw.cpp b/source/module_io/to_wannier90_pw.cpp index 1391391417..9afb105d9d 100644 --- a/source/module_io/to_wannier90_pw.cpp +++ b/source/module_io/to_wannier90_pw.cpp @@ -37,7 +37,7 @@ void toWannier90_PW::calculate( { read_nnkp(kv); - if (GlobalV::NSPIN == 2) + if (PARAM.inp.nspin == 2) { if (wannier_spin == "up") { @@ -216,11 +216,11 @@ void toWannier90_PW::out_unk( { std::stringstream name; - if (GlobalV::NSPIN == 1 || GlobalV::NSPIN == 4) + if (PARAM.inp.nspin == 1 || PARAM.inp.nspin == 4) { name << PARAM.globalv.global_out_dir << "UNK" << std::setw(5) << std::setfill('0') << ik + 1 << ".1"; } - else if (GlobalV::NSPIN == 2) + else if (PARAM.inp.nspin == 2) { if (wannier_spin == "up") name << PARAM.globalv.global_out_dir << "UNK" << std::setw(5) << std::setfill('0') @@ -378,7 +378,7 @@ void toWannier90_PW::unkdotkb( wfcpw->recip2real(phase, phase, cal_ik); - if (GlobalV::NSPIN == 4) + if (PARAM.inp.nspin == 4) { // (1) set value std::complex* psir_up = new std::complex[wfcpw->nmaxgr]; @@ -541,7 +541,7 @@ void toWannier90_PW::gen_radial_function_in_q(std::vector &r auto &tmp_radial = radial_in_q[wannier_index]; if (L[wannier_index] >= 0) { - tmp_radial.create(1, GlobalV::NQX); + tmp_radial.create(1, PARAM.globalv.nqx); integral(mesh_r, psir, r, dr, L[wannier_index], tmp_radial.c); } else @@ -552,11 +552,11 @@ void toWannier90_PW::gen_radial_function_in_q(std::vector &r if (L[wannier_index] == -4 || L[wannier_index] == -5) tmp_size = 3; - tmp_radial.create(tmp_size, GlobalV::NQX); + tmp_radial.create(tmp_size, PARAM.globalv.nqx); for (int tmp_L = 0; tmp_L < tmp_size; tmp_L++) { - integral(mesh_r, psir, r, dr, tmp_L, tmp_radial.c+tmp_L*GlobalV::NQX); + integral(mesh_r, psir, r, dr, tmp_L, tmp_radial.c+tmp_L*PARAM.globalv.nqx); } } @@ -637,7 +637,7 @@ void toWannier90_PW::produce_trial_in_pw( std::complex *orb_px = new std::complex[npw]; get_trial_orbitals_lm_k(0, 0, ylm, gk, npw, radial_in_q[wannier_index].c, orb_s); - get_trial_orbitals_lm_k(1, 1, ylm, gk, npw, radial_in_q[wannier_index].c+GlobalV::NQX, orb_px); + get_trial_orbitals_lm_k(1, 1, ylm, gk, npw, radial_in_q[wannier_index].c+PARAM.globalv.nqx, orb_px); for (int ig = 0; ig < npw; ig++) { @@ -663,8 +663,8 @@ void toWannier90_PW::produce_trial_in_pw( std::complex *orb_py = new std::complex[npw]; get_trial_orbitals_lm_k(0, 0, ylm, gk, npw, radial_in_q[wannier_index].c, orb_s); - get_trial_orbitals_lm_k(1, 1, ylm, gk, npw, radial_in_q[wannier_index].c+GlobalV::NQX, orb_px); - get_trial_orbitals_lm_k(1, 2, ylm, gk, npw, radial_in_q[wannier_index].c+GlobalV::NQX, orb_py); + get_trial_orbitals_lm_k(1, 1, ylm, gk, npw, radial_in_q[wannier_index].c+PARAM.globalv.nqx, orb_px); + get_trial_orbitals_lm_k(1, 2, ylm, gk, npw, radial_in_q[wannier_index].c+PARAM.globalv.nqx, orb_py); for (int ig = 0; ig < npw; ig++) { @@ -683,7 +683,7 @@ void toWannier90_PW::produce_trial_in_pw( std::complex *orb_s = new std::complex[npw]; std::complex *orb_px = new std::complex[npw]; get_trial_orbitals_lm_k(0, 0, ylm, gk, npw, radial_in_q[wannier_index].c, orb_s); - get_trial_orbitals_lm_k(1, 1, ylm, gk, npw, radial_in_q[wannier_index].c+GlobalV::NQX, orb_px); + get_trial_orbitals_lm_k(1, 1, ylm, gk, npw, radial_in_q[wannier_index].c+PARAM.globalv.nqx, orb_px); for (int ig = 0; ig < npw; ig++) { @@ -726,9 +726,9 @@ void toWannier90_PW::produce_trial_in_pw( std::complex *orb_pz = new std::complex[npw]; get_trial_orbitals_lm_k(0, 0, ylm, gk, npw, radial_in_q[wannier_index].c, orb_s); - get_trial_orbitals_lm_k(1, 1, ylm, gk, npw, radial_in_q[wannier_index].c+GlobalV::NQX, orb_px); - get_trial_orbitals_lm_k(1, 2, ylm, gk, npw, radial_in_q[wannier_index].c+GlobalV::NQX, orb_py); - get_trial_orbitals_lm_k(1, 0, ylm, gk, npw, radial_in_q[wannier_index].c+GlobalV::NQX, orb_pz); + get_trial_orbitals_lm_k(1, 1, ylm, gk, npw, radial_in_q[wannier_index].c+PARAM.globalv.nqx, orb_px); + get_trial_orbitals_lm_k(1, 2, ylm, gk, npw, radial_in_q[wannier_index].c+PARAM.globalv.nqx, orb_py); + get_trial_orbitals_lm_k(1, 0, ylm, gk, npw, radial_in_q[wannier_index].c+PARAM.globalv.nqx, orb_pz); for (int ig = 0; ig < npw; ig++) { @@ -756,8 +756,8 @@ void toWannier90_PW::produce_trial_in_pw( std::complex *orb_py = new std::complex[npw]; get_trial_orbitals_lm_k(0, 0, ylm, gk, npw, radial_in_q[wannier_index].c, orb_s); - get_trial_orbitals_lm_k(1, 1, ylm, gk, npw, radial_in_q[wannier_index].c+GlobalV::NQX, orb_px); - get_trial_orbitals_lm_k(1, 2, ylm, gk, npw, radial_in_q[wannier_index].c+GlobalV::NQX, orb_py); + get_trial_orbitals_lm_k(1, 1, ylm, gk, npw, radial_in_q[wannier_index].c+PARAM.globalv.nqx, orb_px); + get_trial_orbitals_lm_k(1, 2, ylm, gk, npw, radial_in_q[wannier_index].c+PARAM.globalv.nqx, orb_py); for (int ig = 0; ig < npw; ig++) { @@ -777,7 +777,7 @@ void toWannier90_PW::produce_trial_in_pw( std::complex *orb_px = new std::complex[npw]; get_trial_orbitals_lm_k(0, 0, ylm, gk, npw, radial_in_q[wannier_index].c, orb_s); - get_trial_orbitals_lm_k(1, 1, ylm, gk, npw, radial_in_q[wannier_index].c+GlobalV::NQX, orb_px); + get_trial_orbitals_lm_k(1, 1, ylm, gk, npw, radial_in_q[wannier_index].c+PARAM.globalv.nqx, orb_px); for (int ig = 0; ig < npw; ig++) { @@ -798,8 +798,8 @@ void toWannier90_PW::produce_trial_in_pw( std::complex *orb_pz = new std::complex[npw]; std::complex *orb_dz2 = new std::complex[npw]; - get_trial_orbitals_lm_k(1, 0, ylm, gk, npw, radial_in_q[wannier_index].c+GlobalV::NQX, orb_pz); - get_trial_orbitals_lm_k(2, 0, ylm, gk, npw, radial_in_q[wannier_index].c+2*GlobalV::NQX, orb_dz2); + get_trial_orbitals_lm_k(1, 0, ylm, gk, npw, radial_in_q[wannier_index].c+PARAM.globalv.nqx, orb_pz); + get_trial_orbitals_lm_k(2, 0, ylm, gk, npw, radial_in_q[wannier_index].c+2*PARAM.globalv.nqx, orb_dz2); for (int ig = 0; ig < npw; ig++) { @@ -833,9 +833,9 @@ void toWannier90_PW::produce_trial_in_pw( std::complex *orb_dx2_y2 = new std::complex[npw]; get_trial_orbitals_lm_k(0, 0, ylm, gk, npw, radial_in_q[wannier_index].c, orb_s); - get_trial_orbitals_lm_k(1, 1, ylm, gk, npw, radial_in_q[wannier_index].c+GlobalV::NQX, orb_px); - get_trial_orbitals_lm_k(2, 0, ylm, gk, npw, radial_in_q[wannier_index].c+2*GlobalV::NQX, orb_dz2); - get_trial_orbitals_lm_k(2, 3, ylm, gk, npw, radial_in_q[wannier_index].c+2*GlobalV::NQX, orb_dx2_y2); + get_trial_orbitals_lm_k(1, 1, ylm, gk, npw, radial_in_q[wannier_index].c+PARAM.globalv.nqx, orb_px); + get_trial_orbitals_lm_k(2, 0, ylm, gk, npw, radial_in_q[wannier_index].c+2*PARAM.globalv.nqx, orb_dz2); + get_trial_orbitals_lm_k(2, 3, ylm, gk, npw, radial_in_q[wannier_index].c+2*PARAM.globalv.nqx, orb_dx2_y2); for (int ig = 0; ig < npw; ig++) { @@ -867,9 +867,9 @@ void toWannier90_PW::produce_trial_in_pw( std::complex *orb_dx2_y2 = new std::complex[npw]; get_trial_orbitals_lm_k(0, 0, ylm, gk, npw, radial_in_q[wannier_index].c, orb_s); - get_trial_orbitals_lm_k(1, 2, ylm, gk, npw, radial_in_q[wannier_index].c+GlobalV::NQX, orb_py); - get_trial_orbitals_lm_k(2, 0, ylm, gk, npw, radial_in_q[wannier_index].c+2*GlobalV::NQX, orb_dz2); - get_trial_orbitals_lm_k(2, 3, ylm, gk, npw, radial_in_q[wannier_index].c+2*GlobalV::NQX, orb_dx2_y2); + get_trial_orbitals_lm_k(1, 2, ylm, gk, npw, radial_in_q[wannier_index].c+PARAM.globalv.nqx, orb_py); + get_trial_orbitals_lm_k(2, 0, ylm, gk, npw, radial_in_q[wannier_index].c+2*PARAM.globalv.nqx, orb_dz2); + get_trial_orbitals_lm_k(2, 3, ylm, gk, npw, radial_in_q[wannier_index].c+2*PARAM.globalv.nqx, orb_dx2_y2); for (int ig = 0; ig < npw; ig++) { @@ -895,8 +895,8 @@ void toWannier90_PW::produce_trial_in_pw( std::complex *orb_dz2 = new std::complex[npw]; get_trial_orbitals_lm_k(0, 0, ylm, gk, npw, radial_in_q[wannier_index].c, orb_s); - get_trial_orbitals_lm_k(1, 0, ylm, gk, npw, radial_in_q[wannier_index].c+GlobalV::NQX, orb_pz); - get_trial_orbitals_lm_k(2, 0, ylm, gk, npw, radial_in_q[wannier_index].c+2*GlobalV::NQX, orb_dz2); + get_trial_orbitals_lm_k(1, 0, ylm, gk, npw, radial_in_q[wannier_index].c+PARAM.globalv.nqx, orb_pz); + get_trial_orbitals_lm_k(2, 0, ylm, gk, npw, radial_in_q[wannier_index].c+2*PARAM.globalv.nqx, orb_dz2); for (int ig = 0; ig < npw; ig++) { @@ -948,7 +948,7 @@ void toWannier90_PW::get_trial_orbitals_lm_k( { for (int ig = 0; ig < npw; ig++) { - orbital_in_G_single[ig] = ModuleBase::PolyInt::Polynomial_Interpolation(radial_in_q_single, GlobalV::NQX, GlobalV::DQ, gk[ig].norm() * GlobalC::ucell.tpiba); + orbital_in_G_single[ig] = ModuleBase::PolyInt::Polynomial_Interpolation(radial_in_q_single, PARAM.globalv.nqx, PARAM.globalv.dq, gk[ig].norm() * GlobalC::ucell.tpiba); } std::complex lphase = pow(ModuleBase::NEG_IMAG_UNIT, orbital_L); @@ -984,9 +984,9 @@ void toWannier90_PW::integral( double *aux = new double[meshr]; double *vchi = new double[meshr]; - for (int iq = 0; iq < GlobalV::NQX; iq++) + for (int iq = 0; iq < PARAM.globalv.nqx; iq++) { - const double q = GlobalV::DQ * iq; + const double q = PARAM.globalv.dq * iq; ModuleBase::Sphbes::Spherical_Bessel(meshr, r, q, l, aux); for (int ir = 0; ir < meshr; ir++) { @@ -1024,7 +1024,7 @@ void toWannier90_PW::unkdotW_A( { int ib = cal_band_index[ib_w]; - if (GlobalV::NSPIN != 4) + if (PARAM.inp.nspin != 4) { for (int ig = 0; ig < npw; ig++) { diff --git a/source/module_io/unk_overlap_pw.cpp b/source/module_io/unk_overlap_pw.cpp index 58dfdd9f97..d0d1d7c706 100644 --- a/source/module_io/unk_overlap_pw.cpp +++ b/source/module_io/unk_overlap_pw.cpp @@ -124,7 +124,7 @@ std::complex unkOverlap_pw::unkdotp_G0(const ModulePW::PW_Basis* rhopw, return result; } -// if noncollinear = 1 or GlobalV::NSPIN = 4 , you need this routine to calculate overlap unk +// if noncollinear = 1 or PARAM.inp.nspin = 4 , you need this routine to calculate overlap unk std::complex unkOverlap_pw::unkdotp_soc_G(const ModulePW::PW_Basis_K* wfcpw, const int ik_L, const int ik_R, diff --git a/source/module_io/write_HS_R.cpp b/source/module_io/write_HS_R.cpp index 2989b9dd5f..0ea348e079 100644 --- a/source/module_io/write_HS_R.cpp +++ b/source/module_io/write_HS_R.cpp @@ -32,7 +32,7 @@ void ModuleIO::output_HSR(const int& istep, ModuleBase::TITLE("ModuleIO", "output_HSR"); ModuleBase::timer::tick("ModuleIO", "output_HSR"); - const int nspin = GlobalV::NSPIN; + const int nspin = PARAM.inp.nspin; if (nspin == 1 || nspin == 4) { const int spin_now = 0; @@ -99,7 +99,7 @@ void ModuleIO::output_dHR(const int& istep, gint_k.allocate_pvdpR(); - const int nspin = GlobalV::NSPIN; + const int nspin = PARAM.inp.nspin; if (nspin == 1 || nspin == 4) { // mohan add 2024-04-01 diff --git a/source/module_io/write_HS_sparse.cpp b/source/module_io/write_HS_sparse.cpp index 6a3b180dcb..7561333a2a 100644 --- a/source/module_io/write_HS_sparse.cpp +++ b/source/module_io/write_HS_sparse.cpp @@ -35,7 +35,7 @@ void ModuleIO::save_HSR_sparse(const int& istep, ModuleBase::GlobalFunc::ZEROS(S_nonzero_num, total_R_num); int spin_loop = 1; - if (GlobalV::NSPIN == 2) { + if (PARAM.inp.nspin == 2) { spin_loop = 2; } @@ -46,7 +46,7 @@ void ModuleIO::save_HSR_sparse(const int& istep, int count = 0; for (auto& R_coor: all_R_coor_ptr) { - if (GlobalV::NSPIN != 4) { + if (PARAM.inp.nspin != 4) { for (int ispin = 0; ispin < spin_loop; ++ispin) { if (TD_Velocity::tddft_velocity) { auto iter @@ -101,7 +101,7 @@ void ModuleIO::save_HSR_sparse(const int& istep, Parallel_Reduce::reduce_all(H_nonzero_num[ispin], total_R_num); } - if (GlobalV::NSPIN == 2) { + if (PARAM.inp.nspin == 2) { for (int index = 0; index < total_R_num; ++index) { if (H_nonzero_num[0][index] != 0 || H_nonzero_num[1][index] != 0 || S_nonzero_num[index] != 0) { @@ -189,7 +189,7 @@ void ModuleIO::save_HSR_sparse(const int& istep, int dRy = R_coor.y; int dRz = R_coor.z; - if (GlobalV::NSPIN == 2) { + if (PARAM.inp.nspin == 2) { if (H_nonzero_num[0][count] == 0 && H_nonzero_num[1][count] == 0 && S_nonzero_num[count] == 0) { count++; @@ -247,7 +247,7 @@ void ModuleIO::save_HSR_sparse(const int& istep, // } // } } else { - if (GlobalV::NSPIN != 4) { + if (PARAM.inp.nspin != 4) { if (TD_Velocity::tddft_velocity) { output_single_R(g1[ispin], TD_Velocity::td_vel_op @@ -287,7 +287,7 @@ void ModuleIO::save_HSR_sparse(const int& istep, // } // } } else { - if (GlobalV::NSPIN != 4) { + if (PARAM.inp.nspin != 4) { output_single_R(g2, SR_sparse_ptr[R_coor], sparse_thr, @@ -348,7 +348,7 @@ void ModuleIO::save_dH_sparse(const int& istep, int step = istep; int spin_loop = 1; - if (GlobalV::NSPIN == 2) { + if (PARAM.inp.nspin == 2) { spin_loop = 2; } @@ -363,7 +363,7 @@ void ModuleIO::save_dH_sparse(const int& istep, int count = 0; for (auto& R_coor: all_R_coor_ptr) { - if (GlobalV::NSPIN != 4) { + if (PARAM.inp.nspin != 4) { for (int ispin = 0; ispin < spin_loop; ++ispin) { auto iter1 = dHRx_sparse_ptr[ispin].find(R_coor); if (iter1 != dHRx_sparse_ptr[ispin].end()) { @@ -404,7 +404,7 @@ void ModuleIO::save_dH_sparse(const int& istep, Parallel_Reduce::reduce_all(dHz_nonzero_num[ispin], total_R_num); } - if (GlobalV::NSPIN == 2) { + if (PARAM.inp.nspin == 2) { for (int index = 0; index < total_R_num; ++index) { if (dHx_nonzero_num[0][index] != 0 || dHx_nonzero_num[1][index] != 0 || dHy_nonzero_num[0][index] != 0 @@ -531,7 +531,7 @@ void ModuleIO::save_dH_sparse(const int& istep, int dRy = R_coor.y; int dRz = R_coor.z; - if (GlobalV::NSPIN == 2) { + if (PARAM.inp.nspin == 2) { if (dHx_nonzero_num[0][count] == 0 && dHx_nonzero_num[1][count] == 0 && dHy_nonzero_num[0][count] == 0 && dHy_nonzero_num[1][count] == 0 @@ -597,7 +597,7 @@ void ModuleIO::save_dH_sparse(const int& istep, for (int ispin = 0; ispin < spin_loop; ++ispin) { if (dHx_nonzero_num[ispin][count] > 0) { - if (GlobalV::NSPIN != 4) { + if (PARAM.inp.nspin != 4) { output_single_R(g1x[ispin], dHRx_sparse_ptr[ispin][R_coor], sparse_thr, @@ -612,7 +612,7 @@ void ModuleIO::save_dH_sparse(const int& istep, } } if (dHy_nonzero_num[ispin][count] > 0) { - if (GlobalV::NSPIN != 4) { + if (PARAM.inp.nspin != 4) { output_single_R(g1y[ispin], dHRy_sparse_ptr[ispin][R_coor], sparse_thr, @@ -627,7 +627,7 @@ void ModuleIO::save_dH_sparse(const int& istep, } } if (dHz_nonzero_num[ispin][count] > 0) { - if (GlobalV::NSPIN != 4) { + if (PARAM.inp.nspin != 4) { output_single_R(g1z[ispin], dHRz_sparse_ptr[ispin][R_coor], sparse_thr, diff --git a/source/module_io/write_cube.cpp b/source/module_io/write_cube.cpp index 8619055e2a..0cc283c6fc 100644 --- a/source/module_io/write_cube.cpp +++ b/source/module_io/write_cube.cpp @@ -1,5 +1,6 @@ #include "module_base/element_name.h" #include "module_io/cube_io.h" +#include "module_parameter/parameter.h" #include void ModuleIO::write_cube( @@ -56,7 +57,7 @@ void ModuleIO::write_cube( ofs_cube << std::setprecision(6); if (out_fermi == 1) { - if (GlobalV::TWO_EFERMI) + if (PARAM.globalv.two_fermi) { if (is == 0) { diff --git a/source/module_io/write_dos_lcao.cpp b/source/module_io/write_dos_lcao.cpp index 5ed0a502bf..cc7a1ec487 100644 --- a/source/module_io/write_dos_lcao.cpp +++ b/source/module_io/write_dos_lcao.cpp @@ -40,7 +40,7 @@ void ModuleIO::write_dos_lcao(const psi::Psi* psi, ModuleBase::TITLE("ModuleIO", "write_dos_lcao"); int nspin0 = 1; - if (GlobalV::NSPIN == 2) + if (PARAM.inp.nspin == 2) { nspin0 = 2; } @@ -197,7 +197,7 @@ void ModuleIO::write_dos_lcao(const psi::Psi* psi, std::stringstream ps; ps << PARAM.globalv.global_out_dir << "TDOS"; std::ofstream out(ps.str().c_str()); - if (GlobalV::NSPIN == 1 || GlobalV::NSPIN == 4) + if (PARAM.inp.nspin == 1 || PARAM.inp.nspin == 4) { for (int n = 0; n < npoints; ++n) @@ -212,7 +212,7 @@ void ModuleIO::write_dos_lcao(const psi::Psi* psi, out << std::setw(20) << en << std::setw(30) << y << std::endl; } } - else if (GlobalV::NSPIN == 2) + else if (PARAM.inp.nspin == 2) { for (int n = 0; n < npoints; ++n) { @@ -239,8 +239,8 @@ void ModuleIO::write_dos_lcao(const psi::Psi* psi, std::ofstream out(as.str().c_str()); out << "" << std::endl; - out << "" << GlobalV::NSPIN << "" << std::endl; - if (GlobalV::NSPIN == 4) { + out << "" << PARAM.inp.nspin << "" << std::endl; + if (PARAM.inp.nspin == 4) { out << "" << std::setw(2) << GlobalV::NLOCAL / 2 << "" << std::endl; } else { out << "" << std::setw(2) << GlobalV::NLOCAL << "" << std::endl; @@ -277,7 +277,7 @@ void ModuleIO::write_dos_lcao(const psi::Psi* psi, out << std::setw(2) << "z=\"" << std::setw(40) << N1 + 1 << "\"" << std::endl; out << ">" << std::endl; out << "" << std::endl; - if (GlobalV::NSPIN == 1) + if (PARAM.inp.nspin == 1) { for (int n = 0; n < npoints; ++n) { @@ -285,14 +285,14 @@ void ModuleIO::write_dos_lcao(const psi::Psi* psi, out << std::setw(13) << pdos[0](w, n) << std::endl; } // n } - else if (GlobalV::NSPIN == 2) + else if (PARAM.inp.nspin == 2) { for (int n = 0; n < npoints; ++n) { out << std::setw(20) << pdos[0](w, n) << std::setw(30) << pdos[1](w, n) << std::endl; } // n } - else if (GlobalV::NSPIN == 4) + else if (PARAM.inp.nspin == 4) { int w0 = w - s0; for (int n = 0; n < npoints; ++n) @@ -354,7 +354,7 @@ void ModuleIO::write_dos_lcao(const psi::Psi>* psi, ModuleBase::TITLE("ModuleIO", "write_dos_lcao"); int nspin0 = 1; - if (GlobalV::NSPIN == 2) + if (PARAM.inp.nspin == 2) { nspin0 = 2; } @@ -447,7 +447,7 @@ void ModuleIO::write_dos_lcao(const psi::Psi>* psi, { // calculate SK for current k point const std::complex* sk = nullptr; - if (GlobalV::NSPIN == 4) + if (PARAM.inp.nspin == 4) { dynamic_cast, std::complex>*>(p_ham)->updateSk(ik, 1); sk = dynamic_cast, std::complex>*>(p_ham)->getSk(); @@ -544,7 +544,7 @@ void ModuleIO::write_dos_lcao(const psi::Psi>* psi, std::stringstream ps; ps << PARAM.globalv.global_out_dir << "TDOS"; std::ofstream out(ps.str().c_str()); - if (GlobalV::NSPIN == 1 || GlobalV::NSPIN == 4) + if (PARAM.inp.nspin == 1 || PARAM.inp.nspin == 4) { for (int n = 0; n < npoints; ++n) @@ -559,7 +559,7 @@ void ModuleIO::write_dos_lcao(const psi::Psi>* psi, out << std::setw(20) << en << std::setw(30) << y << std::endl; } } - else if (GlobalV::NSPIN == 2) + else if (PARAM.inp.nspin == 2) { for (int n = 0; n < npoints; ++n) { @@ -586,8 +586,8 @@ void ModuleIO::write_dos_lcao(const psi::Psi>* psi, std::ofstream out(as.str().c_str()); out << "" << std::endl; - out << "" << GlobalV::NSPIN << "" << std::endl; - if (GlobalV::NSPIN == 4) + out << "" << PARAM.inp.nspin << "" << std::endl; + if (PARAM.inp.nspin == 4) { out << "" << std::setw(2) << GlobalV::NLOCAL / 2 << "" << std::endl; } @@ -627,21 +627,21 @@ void ModuleIO::write_dos_lcao(const psi::Psi>* psi, out << std::setw(2) << "z=\"" << std::setw(40) << N1 + 1 << "\"" << std::endl; out << ">" << std::endl; out << "" << std::endl; - if (GlobalV::NSPIN == 1) + if (PARAM.inp.nspin == 1) { for (int n = 0; n < npoints; ++n) { out << std::setw(13) << pdos[0](w, n) << std::endl; } // n } - else if (GlobalV::NSPIN == 2) + else if (PARAM.inp.nspin == 2) { for (int n = 0; n < npoints; ++n) { out << std::setw(20) << pdos[0](w, n) << std::setw(30) << pdos[1](w, n) << std::endl; } // n } - else if (GlobalV::NSPIN == 4) + else if (PARAM.inp.nspin == 4) { int w0 = w - s0; for (int n = 0; n < npoints; ++n) diff --git a/source/module_io/write_dos_pw.cpp b/source/module_io/write_dos_pw.cpp index 80f984ca44..d6e07d20ed 100644 --- a/source/module_io/write_dos_pw.cpp +++ b/source/module_io/write_dos_pw.cpp @@ -14,7 +14,7 @@ void ModuleIO::write_dos_pw(const ModuleBase::matrix& ekb, ModuleBase::TITLE("ModuleIO", "write_dos_pw"); int nspin0 = 1; - if (GlobalV::NSPIN == 2) + if (PARAM.inp.nspin == 2) nspin0 = 2; // find energy range diff --git a/source/module_io/write_elecstat_pot.cpp b/source/module_io/write_elecstat_pot.cpp index ec582d2551..4a620a3efa 100644 --- a/source/module_io/write_elecstat_pot.cpp +++ b/source/module_io/write_elecstat_pot.cpp @@ -28,7 +28,7 @@ void write_elecstat_pot( std::vector v_elecstat(rho_basis->nrxx, 0.0); - const int nspin = GlobalV::NSPIN; + const int nspin = PARAM.inp.nspin; const int efield = PARAM.inp.efield_flag; const int dip_corr = PARAM.inp.dip_cor_flag; const bool imp_sol = PARAM.inp.imp_sol; diff --git a/source/module_io/write_istate_info.cpp b/source/module_io/write_istate_info.cpp index 321f66727c..5fa53e813e 100644 --- a/source/module_io/write_istate_info.cpp +++ b/source/module_io/write_istate_info.cpp @@ -28,7 +28,7 @@ void ModuleIO::write_istate_info(const ModuleBase::matrix &ekb,const ModuleBase: } #endif std::ofstream ofsi2(ss.str().c_str(), std::ios::app); - if (GlobalV::NSPIN == 1 || GlobalV::NSPIN == 4) + if (PARAM.inp.nspin == 1 || PARAM.inp.nspin == 4) { for (int ik = 0; ik < kv.get_nks(); ik++) { diff --git a/source/module_io/write_proj_band_lcao.cpp b/source/module_io/write_proj_band_lcao.cpp index 109c3a6e5d..c308bc0992 100644 --- a/source/module_io/write_proj_band_lcao.cpp +++ b/source/module_io/write_proj_band_lcao.cpp @@ -25,7 +25,7 @@ void ModuleIO::write_proj_band_lcao( const double* sk = dynamic_cast*>(p_ham)->getSk(); int nspin0 = 1; - if (GlobalV::NSPIN == 2) + if (PARAM.inp.nspin == 2) nspin0 = 2; int nks = 0; if (nspin0 == 1) @@ -102,8 +102,8 @@ void ModuleIO::write_proj_band_lcao( std::ofstream out(ps2.str().c_str()); out << "" << std::endl; - out << "" << GlobalV::NSPIN << "" << std::endl; - if (GlobalV::NSPIN == 4) + out << "" << PARAM.inp.nspin << "" << std::endl; + if (PARAM.inp.nspin == 4) out << "" << std::setw(2) << GlobalV::NLOCAL / 2 << "" << std::endl; else out << "" << std::setw(2) << GlobalV::NLOCAL << "" << std::endl; @@ -139,9 +139,9 @@ void ModuleIO::write_proj_band_lcao( out << "" << std::endl; for (int ib = 0; ib < GlobalV::NBANDS; ib++) { - if (GlobalV::NSPIN == 1 || GlobalV::NSPIN == 2) + if (PARAM.inp.nspin == 1 || PARAM.inp.nspin == 2) out << std::setw(13) << weight(is, ib * GlobalV::NLOCAL + w); - else if (GlobalV::NSPIN == 4) + else if (PARAM.inp.nspin == 4) { int w0 = w - s0; out << std::setw(13) @@ -178,7 +178,7 @@ void ModuleIO::write_proj_band_lcao( ModuleBase::timer::tick("ModuleIO", "write_proj_band_lcao"); int nspin0 = 1; - if (GlobalV::NSPIN == 2) + if (PARAM.inp.nspin == 2) nspin0 = 2; int nks = 0; if (nspin0 == 1) @@ -208,7 +208,7 @@ void ModuleIO::write_proj_band_lcao( { // calculate SK for current k point const std::complex* sk = nullptr; - if (GlobalV::NSPIN == 4) + if (PARAM.inp.nspin == 4) { dynamic_cast, std::complex>*>(p_ham)->updateSk(ik, 1); sk = dynamic_cast, std::complex>*>(p_ham)->getSk(); @@ -286,8 +286,8 @@ void ModuleIO::write_proj_band_lcao( std::ofstream out(ps2.str().c_str()); out << "" << std::endl; - out << "" << GlobalV::NSPIN << "" << std::endl; - if (GlobalV::NSPIN == 4) + out << "" << PARAM.inp.nspin << "" << std::endl; + if (PARAM.inp.nspin == 4) { out << "" << std::setw(2) << GlobalV::NLOCAL / 2 << "" << std::endl; } @@ -334,15 +334,15 @@ void ModuleIO::write_proj_band_lcao( { for (int ib = 0; ib < GlobalV::NBANDS; ib++) { - if (GlobalV::NSPIN == 1) + if (PARAM.inp.nspin == 1) { out << std::setw(13) << weight(ik, ib * GlobalV::NLOCAL + w); } - else if (GlobalV::NSPIN == 2) + else if (PARAM.inp.nspin == 2) { out << std::setw(13) << weight(ik + nks * is, ib * GlobalV::NLOCAL + w); } - else if (GlobalV::NSPIN == 4) + else if (PARAM.inp.nspin == 4) { int w0 = w - s0; out << std::setw(13) diff --git a/source/module_io/write_wfc_r.cpp b/source/module_io/write_wfc_r.cpp index 28914d8da7..f8a15edb4b 100644 --- a/source/module_io/write_wfc_r.cpp +++ b/source/module_io/write_wfc_r.cpp @@ -36,7 +36,7 @@ void write_psi_r_1(const psi::Psi>& wfc_g, for(int ik=0; ik_nks; ++ik) { // cal k_phase @@ -70,7 +71,7 @@ namespace elecstate } } // treat DMR as pauli matrix when NSPIN=4 - if (GlobalV::NSPIN == 4) + if (PARAM.inp.nspin == 4) throw std::runtime_error("complex DM(R) with NSPIN=4 is not implemented yet"); } } diff --git a/source/module_lr/esolver_lrtd_lcao.cpp b/source/module_lr/esolver_lrtd_lcao.cpp index daa1ad59a6..b54a35504c 100644 --- a/source/module_lr/esolver_lrtd_lcao.cpp +++ b/source/module_lr/esolver_lrtd_lcao.cpp @@ -84,7 +84,7 @@ void LR::ESolver_LR::parameter_check()const template void LR::ESolver_LR::set_dimension() { - this->nspin = GlobalV::NSPIN; + this->nspin = PARAM.inp.nspin; if (nspin == 2) { std::cout << "** Assuming the spin-up and spin-down states are degenerate. **" << std::endl; } this->nstates = input.lr_nstates; @@ -242,7 +242,7 @@ LR::ESolver_LR::ESolver_LR(const Input_para& inp, UnitCell& ucell) : inpu GlobalC::ucell.symm.analy_sys(ucell.lat, ucell.st, ucell.atoms, GlobalV::ofs_running); ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "SYMMETRY"); } - this->kv.set(ucell.symm, PARAM.inp.kpoint_file, GlobalV::NSPIN, ucell.G, ucell.latvec, GlobalV::ofs_running); + this->kv.set(ucell.symm, PARAM.inp.kpoint_file, PARAM.inp.nspin, ucell.G, ucell.latvec, GlobalV::ofs_running); ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "INIT K-POINTS"); Print_Info::setup_parameters(ucell, this->kv); @@ -515,7 +515,7 @@ void LR::ESolver_LR::set_X_initial_guess() ix2ioiv = std::move(std::get<1>(indexmap)); // use unit vectors as the initial guess - // for (int i = 0; i < std::min(this->nstates * GlobalV::PW_DIAG_NDIM, nocc * nvirt); i++) + // for (int i = 0; i < std::min(this->nstates * PARAM.inp.pw_diag_ndim, nocc * nvirt); i++) for (int is = 0;is < this->nspin;++is) { for (int s = 0; s < nstates; ++s) diff --git a/source/module_lr/hsolver_lrtd.cpp b/source/module_lr/hsolver_lrtd.cpp index b0a6a9d42e..f3ea744327 100644 --- a/source/module_lr/hsolver_lrtd.cpp +++ b/source/module_lr/hsolver_lrtd.cpp @@ -103,7 +103,7 @@ namespace LR const int& dim = psi_k1_dav.get_nbasis(); //equals to leading dimension here const int& nband = psi_k1_dav.get_nbands(); - hsolver::DiagoDavid david(precondition.data(), nband, dim, GlobalV::PW_DIAG_NDIM, PARAM.inp.use_paw, comm_info); + hsolver::DiagoDavid david(precondition.data(), nband, dim, PARAM.inp.pw_diag_ndim, PARAM.inp.use_paw, comm_info); hsolver::DiagoIterAssist::avg_iter += static_cast(david.diag(hpsi_func, spsi_func, dim, psi_k1_dav.get_pointer(), eigenvalue.data(), this->diag_ethr, david_maxiter, ntry_max, 0)); } @@ -112,7 +112,7 @@ namespace LR hsolver::Diago_DavSubspace dav_subspace(precondition, psi_k1_dav.get_nbands(), psi_k1_dav.get_nbasis(), - GlobalV::PW_DIAG_NDIM, + PARAM.inp.pw_diag_ndim, this->diag_ethr, david_maxiter, false, //always do the subspace diag (check the implementation) diff --git a/source/module_lr/lr_spectrum.cpp b/source/module_lr/lr_spectrum.cpp index c3e3d0f4e5..f39940bc2c 100644 --- a/source/module_lr/lr_spectrum.cpp +++ b/source/module_lr/lr_spectrum.cpp @@ -57,7 +57,7 @@ void LR::LR_Spectrum::oscillator_strength() // 2. transition density double** rho_trans; // LR_Util::new_p2(rho_trans, nspin_solve, this->rho_basis.nrxx); - LR_Util::new_p2(rho_trans, nspin, this->rho_basis.nrxx); // currently gint_kernel_rho uses GlobalV::NSPIN, it needs refactor + LR_Util::new_p2(rho_trans, nspin, this->rho_basis.nrxx); // currently gint_kernel_rho uses PARAM.inp.nspin, it needs refactor this->cal_gint_rho(rho_trans, nspin_solve, this->rho_basis.nrxx); // 3. transition dipole moment diff --git a/source/module_lr/operator_casida/operator_lr_hxc.cpp b/source/module_lr/operator_casida/operator_lr_hxc.cpp index 61f67520a3..edce5a3d51 100644 --- a/source/module_lr/operator_casida/operator_lr_hxc.cpp +++ b/source/module_lr/operator_casida/operator_lr_hxc.cpp @@ -1,5 +1,6 @@ #include "operator_lr_hxc.h" #include +#include "module_parameter/parameter.h" #include "module_base/blas_connector.h" #include "module_base/timer.h" #include "module_lr/utils/lr_util.h" @@ -100,7 +101,7 @@ namespace LR double** rho_trans; const int& nrxx = this->pot.lock()->nrxx; // LR_Util::new_p2(rho_trans, nspin_solve, nrxx); - LR_Util::new_p2(rho_trans, nspin, nrxx); // currently gint_kernel_rho uses GlobalV::NSPIN, it needs refactor + LR_Util::new_p2(rho_trans, nspin, nrxx); // currently gint_kernel_rho uses PARAM.inp.nspin, it needs refactor for (int is = 0;is < nspin_solve;++is)ModuleBase::GlobalFunc::ZEROS(rho_trans[is], nrxx); Gint_inout inout_rho(rho_trans, Gint_Tools::job_type::rho, false); this->gint->cal_gint(&inout_rho); @@ -147,7 +148,7 @@ namespace LR double** rho_trans; const int& nrxx = this->pot.lock()->nrxx; // LR_Util::new_p2(rho_trans, nspin_solve, nrxx); - LR_Util::new_p2(rho_trans, nspin, nrxx); // currently gint_kernel_rho uses GlobalV::NSPIN, it needs refactor + LR_Util::new_p2(rho_trans, nspin, nrxx); // currently gint_kernel_rho uses PARAM.inp.nspin, it needs refactor for (int is = 0;is < nspin_solve;++is)ModuleBase::GlobalFunc::ZEROS(rho_trans[is], nrxx); Gint_inout inout_rho(rho_trans, Gint_Tools::job_type::rho, false); this->gint->cal_gint(&inout_rho); diff --git a/source/module_lr/potentials/kernel_xc.cpp b/source/module_lr/potentials/kernel_xc.cpp index f7ab50ebe1..fad91e0aa4 100644 --- a/source/module_lr/potentials/kernel_xc.cpp +++ b/source/module_lr/potentials/kernel_xc.cpp @@ -1,5 +1,6 @@ #include "kernel.h" #include "module_hamilt_general/module_xc/xc_functional.h" +#include "module_parameter/parameter.h" #include "module_base/timer.h" #include "module_lr/utils/lr_util.h" #ifdef USE_LIBXC @@ -218,11 +219,11 @@ void LR::KernelXC::f_xc_libxc(const int& nspin, const double& omega, const doubl } // end for( xc_func_type &func : funcs ) XC_Functional::finish_func(funcs); - if (1 == GlobalV::NSPIN || 2 == GlobalV::NSPIN) return; - // else if (4 == GlobalV::NSPIN) + if (1 == PARAM.inp.nspin || 2 == PARAM.inp.nspin) return; + // else if (4 == PARAM.inp.nspin) else//NSPIN != 1,2,4 is not supported { - throw std::domain_error("GlobalV::NSPIN =" + std::to_string(GlobalV::NSPIN) + throw std::domain_error("PARAM.inp.nspin =" + std::to_string(PARAM.inp.nspin) + " unfinished in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); } } diff --git a/source/module_lr/potentials/pot_hxc_lrtd.cpp b/source/module_lr/potentials/pot_hxc_lrtd.cpp index c44c3109cc..b2713c8670 100644 --- a/source/module_lr/potentials/pot_hxc_lrtd.cpp +++ b/source/module_lr/potentials/pot_hxc_lrtd.cpp @@ -15,7 +15,7 @@ namespace LR { this->rho_basis_ = rho_basis_in; this->nrxx = chg_gs->nrxx; - this->nspin = (GlobalV::NSPIN == 1 || (GlobalV::NSPIN == 4 && !PARAM.globalv.domag && !PARAM.globalv.domag_z)) ? 1 : 2; + this->nspin = (PARAM.inp.nspin == 1 || (PARAM.inp.nspin == 4 && !PARAM.globalv.domag && !PARAM.globalv.domag_z)) ? 1 : 2; this->pot_hartree = LR_Util::make_unique(this->rho_basis_); std::set local_xc = { "lda", "pbe", "hse" }; diff --git a/source/module_lr/utils/gint_move.hpp b/source/module_lr/utils/gint_move.hpp index a5aff464c2..acdbdad997 100644 --- a/source/module_lr/utils/gint_move.hpp +++ b/source/module_lr/utils/gint_move.hpp @@ -1,5 +1,6 @@ #include "lr_util.h" #include "module_hamilt_lcao/module_gint/gint_gamma.h" +#include "module_parameter/parameter.h" #include "module_hamilt_lcao/module_gint/gint_k.h" #include "module_hamilt_lcao/module_gint/grid_technique.h" @@ -38,13 +39,13 @@ Gint& Gint::operator=(Gint&& rhs) this->nplane = rhs.nplane; this->startz_current = rhs.startz_current; - if (this->pvpR_reduced != nullptr) { d2(this->pvpR_reduced, GlobalV::NSPIN); //nspin*gridt.nnrg + if (this->pvpR_reduced != nullptr) { d2(this->pvpR_reduced, PARAM.inp.nspin); //nspin*gridt.nnrg } - if (this->pvdpRx_reduced != nullptr) { d2(this->pvdpRx_reduced, GlobalV::NSPIN); + if (this->pvdpRx_reduced != nullptr) { d2(this->pvdpRx_reduced, PARAM.inp.nspin); } - if (this->pvdpRy_reduced != nullptr) { d2(this->pvdpRy_reduced, GlobalV::NSPIN); + if (this->pvdpRy_reduced != nullptr) { d2(this->pvdpRy_reduced, PARAM.inp.nspin); } - if (this->pvdpRz_reduced != nullptr) { d2(this->pvdpRz_reduced, GlobalV::NSPIN); + if (this->pvdpRz_reduced != nullptr) { d2(this->pvdpRz_reduced, PARAM.inp.nspin); } this->pvpR_alloc_flag = rhs.pvpR_alloc_flag; rhs.pvpR_alloc_flag = false; @@ -79,7 +80,7 @@ Gint_Gamma& Gint_Gamma::operator=(Gint_Gamma&& rhs) Gint::operator=(std::move(rhs)); // DM may not needed in beyond DFT ESolver - // if (this->DM != nullptr) d3(this->DM, GlobalV::NSPIN, gridt.lgd); + // if (this->DM != nullptr) d3(this->DM, PARAM.inp.nspin, gridt.lgd); assert(this->DM == nullptr); return *this; } diff --git a/source/module_md/run_md.cpp b/source/module_md/run_md.cpp index 5b0e144ac6..35928a9fc3 100644 --- a/source/module_md/run_md.cpp +++ b/source/module_md/run_md.cpp @@ -84,7 +84,7 @@ void md_line(UnitCell& unit_in, ModuleESolver::ESolver* p_esolver, const Paramet if ((mdrun->step_ + mdrun->step_rst_) % param_in.mdp.md_dumpfreq == 0) { - mdrun->print_md(GlobalV::ofs_running, GlobalV::CAL_STRESS); + mdrun->print_md(GlobalV::ofs_running, PARAM.inp.cal_stress); MD_func::dump_info(mdrun->step_ + mdrun->step_rst_, PARAM.globalv.global_out_dir, @@ -109,7 +109,7 @@ void md_line(UnitCell& unit_in, ModuleESolver::ESolver* p_esolver, const Paramet need_orb = need_orb || PARAM.inp.basis_type=="lcao"; need_orb = need_orb || PARAM.inp.basis_type=="lcao_in_pw"; unit_in.print_stru_file(file.str(), - GlobalV::NSPIN, + PARAM.inp.nspin, false, // Cartesian coordinates PARAM.inp.calculation == "md", PARAM.inp.out_mul, diff --git a/source/module_md/test/setcell.h b/source/module_md/test/setcell.h index 1a478fdf9c..e8ccc7e65b 100644 --- a/source/module_md/test/setcell.h +++ b/source/module_md/test/setcell.h @@ -129,7 +129,7 @@ class Setcell PARAM.sys.global_out_dir = "./"; PARAM.sys.global_readin_dir = "./"; GlobalV::SEARCH_RADIUS = 8.5 * ModuleBase::ANGSTROM_AU; - GlobalV::CAL_STRESS = true; + PARAM.input.cal_stress = true; input.mdp.dump_virial = true; input.mdp.dump_force = true; diff --git a/source/module_parameter/system_parameter.h b/source/module_parameter/system_parameter.h index f4a1cac33b..6c0d48fe28 100644 --- a/source/module_parameter/system_parameter.h +++ b/source/module_parameter/system_parameter.h @@ -23,6 +23,11 @@ struct System_para bool dos_setemin = false; ///< true: "dos_emin_ev" is set bool dos_setemax = false; ///< true: "dos_emax_ev" is set + + double dq = 0.010; // space between Q points of the reciprocal radial tab + int nqx = 10000; // number of points describing reciprocal radial tab + int nqxq = 10000; // number of points describing reciprocal radial tab for Q + int ncx = 0, ncy = 0, ncz = 0; ///< three dimension of FFT charge/grid, same as "nx,ny,nz" bool out_md_control = false; ///< true if "out_level" is set diff --git a/source/module_psi/psi_initializer_atomic.cpp b/source/module_psi/psi_initializer_atomic.cpp index 7c19153c7a..0538483cad 100644 --- a/source/module_psi/psi_initializer_atomic.cpp +++ b/source/module_psi/psi_initializer_atomic.cpp @@ -38,7 +38,7 @@ void psi_initializer_atomic::allocate_table() { ModuleBase::WARNING_QUIT("psi_initializer_atomic::allocate_table", "there is not ANY pseudo atomic orbital read in present system, recommand other methods, quit."); } - int dim3 = GlobalV::NQX; + int dim3 = PARAM.globalv.nqx; // allocate memory for ovlp_flzjlq this->ovlp_pswfcjlq_.create(dim1, dim2, dim3); this->ovlp_pswfcjlq_.zero_out(); @@ -110,10 +110,10 @@ void psi_initializer_atomic::tabulate() { ModuleBase::timer::tick("psi_initializer_atomic", "cal_ovlp_pswfcjlq"); int maxn_rgrid = 0; - std::vector qgrid(GlobalV::NQX); - for (int iq = 0; iq < GlobalV::NQX; iq++) + std::vector qgrid(PARAM.globalv.nqx); + for (int iq = 0; iq < PARAM.globalv.nqx; iq++) { - qgrid[iq] = GlobalV::DQ * iq; + qgrid[iq] = PARAM.globalv.dq * iq; } for (int it=0; itp_ucell_->ntype; it++) { @@ -123,8 +123,8 @@ void psi_initializer_atomic::tabulate() const double pref = ModuleBase::FOUR_PI / sqrt(this->p_ucell_->omega); - ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"dq(describe PAO in reciprocal space)",GlobalV::DQ); - ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"max q",GlobalV::NQX); + ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"dq(describe PAO in reciprocal space)",PARAM.globalv.dq); + ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"max q",PARAM.globalv.nqx); for (int it=0; itp_ucell_->ntype; it++) { @@ -141,9 +141,9 @@ void psi_initializer_atomic::tabulate() if (atom->ncpp.oc[ic] >= 0.0) // reasonable occupation number, but is it always true? { const int l = atom->ncpp.lchi[ic]; - std::vector ovlp_pswfcjlq_q(GlobalV::NQX); - this->sbt.direct(l, atom->ncpp.msh, atom->ncpp.r.data(), pswfcr.data(), GlobalV::NQX, qgrid.data(), ovlp_pswfcjlq_q.data(), 1); - for (int iq = 0; iq < GlobalV::NQX; iq++) + std::vector ovlp_pswfcjlq_q(PARAM.globalv.nqx); + this->sbt.direct(l, atom->ncpp.msh, atom->ncpp.r.data(), pswfcr.data(), PARAM.globalv.nqx, qgrid.data(), ovlp_pswfcjlq_q.data(), 1); + for (int iq = 0; iq < PARAM.globalv.nqx; iq++) { this->ovlp_pswfcjlq_(it, ic, iq) = pref * ovlp_pswfcjlq_q[iq]; } @@ -207,10 +207,10 @@ void psi_initializer_atomic::proj_ao_onkG(const int ik) { ovlp_pswfcjlg[ig] = ModuleBase::PolyInt::Polynomial_Interpolation( this->ovlp_pswfcjlq_, it, ipswfc, - GlobalV::NQX, GlobalV::DQ, gk[ig].norm() * this->p_ucell_->tpiba ); + PARAM.globalv.nqx, PARAM.globalv.dq, gk[ig].norm() * this->p_ucell_->tpiba ); } /* NSPIN == 4 */ - if(GlobalV::NSPIN == 4) + if(PARAM.inp.nspin == 4) { if(this->p_ucell_->atoms[it].ncpp.has_so) { @@ -306,7 +306,7 @@ void psi_initializer_atomic::proj_ao_onkG(const int ik) chiaux[ig] = l * ModuleBase::PolyInt::Polynomial_Interpolation( this->ovlp_pswfcjlq_, it, ipswfc_noncolin_soc, - GlobalV::NQX, GlobalV::DQ, gk[ig].norm() * this->p_ucell_->tpiba); + PARAM.globalv.nqx, PARAM.globalv.dq, gk[ig].norm() * this->p_ucell_->tpiba); chiaux[ig] += ovlp_pswfcjlg[ig] * (l + 1.0) ; chiaux[ig] *= 1/(2.0*l+1.0); } diff --git a/source/module_psi/psi_initializer_nao.cpp b/source/module_psi/psi_initializer_nao.cpp index c831b59015..a88b0ed9f8 100644 --- a/source/module_psi/psi_initializer_nao.cpp +++ b/source/module_psi/psi_initializer_nao.cpp @@ -271,7 +271,7 @@ void psi_initializer_nao::allocate_table() ModuleBase::WARNING_QUIT("psi_initializer_nao::psi_initializer_nao", "there is not ANY numerical atomic orbital read in present system, quit."); } - int dim3 = GlobalV::NQX; + int dim3 = PARAM.globalv.nqx; // allocate memory for ovlp_flzjlq this->ovlp_flzjlq_.create(dim1, dim2, dim3); this->ovlp_flzjlq_.zero_out(); @@ -298,7 +298,7 @@ void psi_initializer_nao::initialize(Structure_Factor* sf, // allocate this->allocate_table(); this->read_external_orbs(this->p_ucell_->orbital_fn, rank); - // this->cal_ovlp_flzjlq(); //because GlobalV::NQX will change during vcrelax, so it should be called in both init + // this->cal_ovlp_flzjlq(); //because PARAM.globalv.nqx will change during vcrelax, so it should be called in both init // and init_after_vc // then for generate random number to fill in the wavefunction this->ixy2is_.clear(); @@ -324,7 +324,7 @@ void psi_initializer_nao::initialize(Structure_Factor* sf, // allocate this->allocate_table(); this->read_external_orbs(this->p_ucell_->orbital_fn, 0); - // this->cal_ovlp_flzjlq(); //because GlobalV::NQX will change during vcrelax, so it should be called in both init + // this->cal_ovlp_flzjlq(); //because PARAM.globalv.nqx will change during vcrelax, so it should be called in both init // and init_after_vc // then for generate random number to fill in the wavefunction this->ixy2is_.clear(); @@ -346,20 +346,20 @@ void psi_initializer_nao::tabulate() { for (int izeta = 0; izeta < this->p_ucell_->atoms[it].l_nchi[l]; izeta++) { - std::vector ovlp_flzjlq_q(GlobalV::NQX); - std::vector qgrid(GlobalV::NQX); - for (int iq = 0; iq < GlobalV::NQX; iq++) + std::vector ovlp_flzjlq_q(PARAM.globalv.nqx); + std::vector qgrid(PARAM.globalv.nqx); + for (int iq = 0; iq < PARAM.globalv.nqx; iq++) { - qgrid[iq] = iq * GlobalV::DQ; + qgrid[iq] = iq * PARAM.globalv.dq; } this->sbt.direct(l, this->n_rgrid_[it][ic], this->rgrid_[it][ic].data(), this->rvalue_[it][ic].data(), - GlobalV::NQX, + PARAM.globalv.nqx, qgrid.data(), ovlp_flzjlq_q.data()); - for (int iq = 0; iq < GlobalV::NQX; iq++) + for (int iq = 0; iq < PARAM.globalv.nqx; iq++) { this->ovlp_flzjlq_(it, ic, iq) = ovlp_flzjlq_q[iq]; } @@ -417,13 +417,13 @@ void psi_initializer_nao::proj_ao_onkG(const int ik) this->ovlp_flzjlq_, // the spherical bessel transform of numerical orbital function it, ic, // each (it, ic)-pair defines a unique numerical orbital function - GlobalV::NQX, - GlobalV::DQ, // grid number and grid spacing of q + PARAM.globalv.nqx, + PARAM.globalv.dq, // grid number and grid spacing of q gk[ig].norm() * this->p_ucell_->tpiba // norm of (G+k) = K ); } /* FOR EVERY NAO IN EACH ATOM */ - if (GlobalV::NSPIN == 4) + if (PARAM.inp.nspin == 4) { /* FOR EACH SPIN CHANNEL */ for (int is_N = 0; is_N < 2; is_N++) // rotate base diff --git a/source/module_psi/test/psi_initializer_unit_test.cpp b/source/module_psi/test/psi_initializer_unit_test.cpp index 8dceaa2a8f..3d10cb06d6 100644 --- a/source/module_psi/test/psi_initializer_unit_test.cpp +++ b/source/module_psi/test/psi_initializer_unit_test.cpp @@ -116,7 +116,7 @@ class PsiIntializerUnitTest : public ::testing::Test { #endif // mock GlobalV::NBANDS = 1; - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; PARAM.input.orbital_dir = "./support/"; PARAM.input.pseudo_dir = "./support/"; PARAM.sys.npol = 1; @@ -524,7 +524,7 @@ TEST_F(PsiIntializerUnitTest, CalPsigAtomic) { TEST_F(PsiIntializerUnitTest, CalPsigAtomicSoc) { PARAM.input.init_wfc = "atomic"; - GlobalV::NSPIN = 4; + PARAM.input.nspin = 4; PARAM.sys.npol = 2; this->p_ucell->atoms[0].ncpp.has_so = false; this->p_ucell->natomwfc *= 2; @@ -548,7 +548,7 @@ TEST_F(PsiIntializerUnitTest, CalPsigAtomicSoc) { psi::Psi>* psi = this->psi_init->allocate(); this->psi_init->proj_ao_onkG(0); EXPECT_NEAR(0, psi->operator()(0,0,0).real(), 1e-12); - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; PARAM.sys.npol = 1; this->p_ucell->atoms[0].ncpp.has_so = false; this->p_ucell->natomwfc /= 2; @@ -557,7 +557,7 @@ TEST_F(PsiIntializerUnitTest, CalPsigAtomicSoc) { TEST_F(PsiIntializerUnitTest, CalPsigAtomicSocHasSo) { PARAM.input.init_wfc = "atomic"; - GlobalV::NSPIN = 4; + PARAM.input.nspin = 4; PARAM.sys.npol = 2; this->p_ucell->atoms[0].ncpp.has_so = true; this->p_ucell->natomwfc *= 2; @@ -581,7 +581,7 @@ TEST_F(PsiIntializerUnitTest, CalPsigAtomicSocHasSo) { psi::Psi>* psi = this->psi_init->allocate(); this->psi_init->proj_ao_onkG(0); EXPECT_NEAR(0, psi->operator()(0,0,0).real(), 1e-12); - GlobalV::NSPIN = 1; + PARAM.input.nspin = 1; PARAM.sys.npol = 1; this->p_ucell->atoms[0].ncpp.has_so = false; this->p_ucell->natomwfc /= 2; @@ -665,7 +665,7 @@ TEST_F(PsiIntializerUnitTest, CalPsigNaoRandom) { TEST_F(PsiIntializerUnitTest, CalPsigNaoSoc) { PARAM.input.init_wfc = "nao"; - GlobalV::NSPIN = 4; + PARAM.input.nspin = 4; PARAM.sys.npol = 2; this->p_ucell->atoms[0].ncpp.has_so = false; PARAM.sys.domag = false; @@ -695,7 +695,7 @@ TEST_F(PsiIntializerUnitTest, CalPsigNaoSoc) { TEST_F(PsiIntializerUnitTest, CalPsigNaoSocHasSo) { PARAM.input.init_wfc = "nao"; - GlobalV::NSPIN = 4; + PARAM.input.nspin = 4; PARAM.sys.npol = 2; this->p_ucell->atoms[0].ncpp.has_so = true; PARAM.sys.domag = false; @@ -725,7 +725,7 @@ TEST_F(PsiIntializerUnitTest, CalPsigNaoSocHasSo) { TEST_F(PsiIntializerUnitTest, CalPsigNaoSocHasSoDOMAG) { PARAM.input.init_wfc = "nao"; - GlobalV::NSPIN = 4; + PARAM.input.nspin = 4; PARAM.sys.npol = 2; this->p_ucell->atoms[0].ncpp.has_so = true; PARAM.sys.domag = true; diff --git a/source/module_relax/relax_driver.cpp b/source/module_relax/relax_driver.cpp index 9796811105..c549812f63 100644 --- a/source/module_relax/relax_driver.cpp +++ b/source/module_relax/relax_driver.cpp @@ -69,7 +69,7 @@ void Relax_Driver::relax_driver(ModuleESolver::ESolver* p_esolver) p_esolver->cal_force(force); } // calculate and gather all parts of stress - if (GlobalV::CAL_STRESS) + if (PARAM.inp.cal_stress) { p_esolver->cal_stress(stress); } @@ -102,7 +102,7 @@ void Relax_Driver::relax_driver(ModuleESolver::ESolver* p_esolver) std::stringstream ss, ss1; ss << PARAM.globalv.global_out_dir << "STRU_ION_D"; GlobalC::ucell.print_stru_file(ss.str(), - GlobalV::NSPIN, + PARAM.inp.nspin, true, PARAM.inp.calculation == "md", PARAM.inp.out_mul, @@ -115,7 +115,7 @@ void Relax_Driver::relax_driver(ModuleESolver::ESolver* p_esolver) ss1 << PARAM.globalv.global_out_dir << "STRU_ION"; ss1 << istep << "_D"; GlobalC::ucell.print_stru_file(ss1.str(), - GlobalV::NSPIN, + PARAM.inp.nspin, true, PARAM.inp.calculation == "md", PARAM.inp.out_mul, diff --git a/source/module_relax/relax_old/ions_move_basic.cpp b/source/module_relax/relax_old/ions_move_basic.cpp index f2087ff03d..2215b4daba 100644 --- a/source/module_relax/relax_old/ions_move_basic.cpp +++ b/source/module_relax/relax_old/ions_move_basic.cpp @@ -22,6 +22,7 @@ double Ions_Move_Basic::relax_bfgs_init = -1.0; // default is 0.5 double Ions_Move_Basic::best_xxx = 1.0; int Ions_Move_Basic::out_stru = 0; +std::string Ions_Move_Basic::relax_method = "bfgs"; void Ions_Move_Basic::setup_gradient(const UnitCell &ucell, const ModuleBase::matrix &force, double *pos, double *grad) { diff --git a/source/module_relax/relax_old/ions_move_basic.h b/source/module_relax/relax_old/ions_move_basic.h index 3e2e07983b..9b70117c43 100644 --- a/source/module_relax/relax_old/ions_move_basic.h +++ b/source/module_relax/relax_old/ions_move_basic.h @@ -21,7 +21,7 @@ extern double relax_bfgs_rmax; // max value of trust radius, extern double relax_bfgs_rmin; // min value of trust radius, extern double relax_bfgs_init; // initial value of trust radius, extern double best_xxx; // the last step length of cg , we use it as bfgs`s initial step length - +extern std::string relax_method; // relaxation method, extern int out_stru; // output the structure or not // funny way to pass this parameter, but nevertheless diff --git a/source/module_relax/relax_old/ions_move_cg.cpp b/source/module_relax/relax_old/ions_move_cg.cpp index 110472fb91..6808e19b71 100644 --- a/source/module_relax/relax_old/ions_move_cg.cpp +++ b/source/module_relax/relax_old/ions_move_cg.cpp @@ -172,12 +172,12 @@ void Ions_Move_CG::start(UnitCell &ucell, const ModuleBase::matrix &force, const fmax = fa; sd = false; - if (GlobalV::RELAX_METHOD == "cg_bfgs") + if (Ions_Move_Basic::relax_method == "cg_bfgs") { if (Ions_Move_Basic::largest_grad * ModuleBase::Ry_to_eV / 0.529177 < RELAX_CG_THR) // cg to bfgs by pengfei 13-8-8 { - GlobalV::RELAX_METHOD = "bfgs"; + Ions_Move_Basic::relax_method = "bfgs"; } Ions_Move_Basic::best_xxx = steplength; } diff --git a/source/module_relax/relax_old/ions_move_methods.cpp b/source/module_relax/relax_old/ions_move_methods.cpp index e31470e659..de8b240885 100644 --- a/source/module_relax/relax_old/ions_move_methods.cpp +++ b/source/module_relax/relax_old/ions_move_methods.cpp @@ -15,26 +15,26 @@ void Ions_Move_Methods::allocate(const int &natom) { Ions_Move_Basic::dim = natom * 3; - if (GlobalV::RELAX_METHOD == "bfgs") + if (Ions_Move_Basic::relax_method == "bfgs") { this->bfgs.allocate(); } - else if (GlobalV::RELAX_METHOD == "sd") + else if (Ions_Move_Basic::relax_method == "sd") { this->sd.allocate(); } - else if (GlobalV::RELAX_METHOD == "cg") + else if (Ions_Move_Basic::relax_method == "cg") { this->cg.allocate(); } - else if (GlobalV::RELAX_METHOD == "cg_bfgs") + else if (Ions_Move_Basic::relax_method == "cg_bfgs") { this->cg.allocate(); this->bfgs.allocate(); // added by pengfei 13-8-8 } else { - ModuleBase::WARNING("Ions_Move_Methods::init", "the parameter GlobalV::RELAX_METHOD is not correct."); + ModuleBase::WARNING("Ions_Move_Methods::init", "the parameter Ions_Move_Basic::relax_method is not correct."); } return; } @@ -51,28 +51,28 @@ void Ions_Move_Methods::cal_movement(const int &istep, // Ions_Move_Basic::istep = istep; Ions_Move_Basic::istep = force_step; - if (GlobalV::RELAX_METHOD == "bfgs") + if (Ions_Move_Basic::relax_method == "bfgs") { // move_ions // output tau // check all symmery bfgs.start(ucell, f, etot); } - else if (GlobalV::RELAX_METHOD == "sd") + else if (Ions_Move_Basic::relax_method == "sd") { sd.start(ucell, f, etot); } - else if (GlobalV::RELAX_METHOD == "cg") + else if (Ions_Move_Basic::relax_method == "cg") { cg.start(ucell, f, etot); } - else if (GlobalV::RELAX_METHOD == "cg_bfgs") + else if (Ions_Move_Basic::relax_method == "cg_bfgs") { cg.start(ucell, f, etot); // added by pengfei 13-8-10 } else { - ModuleBase::WARNING("Ions_Move_Methods::init", "the parameter GlobalV::RELAX_METHOD is not correct."); + ModuleBase::WARNING("Ions_Move_Methods::init", "the parameter Ions_Move_Basic::relax_method is not correct."); } return; } diff --git a/source/module_relax/relax_old/relax_old.cpp b/source/module_relax/relax_old/relax_old.cpp index d1781ae7a2..b18219c6a7 100644 --- a/source/module_relax/relax_old/relax_old.cpp +++ b/source/module_relax/relax_old/relax_old.cpp @@ -117,7 +117,7 @@ bool Relax_old::if_do_cellrelax(const UnitCell& ucell) } else { - assert(GlobalV::CAL_STRESS == 1); + assert(PARAM.inp.cal_stress == 1); return true; } } diff --git a/source/module_relax/relax_old/test/ions_move_cg_test.cpp b/source/module_relax/relax_old/test/ions_move_cg_test.cpp index 90909059f1..ce184b410d 100644 --- a/source/module_relax/relax_old/test/ions_move_cg_test.cpp +++ b/source/module_relax/relax_old/test/ions_move_cg_test.cpp @@ -109,7 +109,7 @@ TEST_F(IonsMoveCGTest, TestStartSd) // setup data Ions_Move_Basic::istep = 1; Ions_Move_Basic::converged = false; - GlobalV::RELAX_METHOD = "cg_bfgs"; + Ions_Move_Basic::relax_method = "cg_bfgs"; Ions_Move_CG::RELAX_CG_THR = 100.0; UnitCell ucell; ModuleBase::matrix force(2, 3); @@ -131,7 +131,7 @@ TEST_F(IonsMoveCGTest, TestStartSd) EXPECT_EQ(expected_output, output); EXPECT_EQ(Ions_Move_Basic::converged, false); EXPECT_EQ(Ions_Move_Basic::update_iter, 5); - EXPECT_EQ(GlobalV::RELAX_METHOD, "bfgs"); + EXPECT_EQ(Ions_Move_Basic::relax_method, "bfgs"); EXPECT_DOUBLE_EQ(Ions_Move_Basic::largest_grad, 0.01); EXPECT_DOUBLE_EQ(Ions_Move_Basic::best_xxx, -1.0); EXPECT_DOUBLE_EQ(Ions_Move_Basic::relax_bfgs_init, 1.0); @@ -168,7 +168,7 @@ TEST_F(IonsMoveCGTest, TestStartTrialGoto) EXPECT_EQ(expected_output, output); EXPECT_EQ(Ions_Move_Basic::converged, false); EXPECT_EQ(Ions_Move_Basic::update_iter, 5); - EXPECT_EQ(GlobalV::RELAX_METHOD, "bfgs"); + EXPECT_EQ(Ions_Move_Basic::relax_method, "bfgs"); EXPECT_DOUBLE_EQ(Ions_Move_Basic::largest_grad, 0.001); EXPECT_DOUBLE_EQ(Ions_Move_Basic::best_xxx, -1.0); EXPECT_DOUBLE_EQ(Ions_Move_Basic::relax_bfgs_init, 10.0); @@ -204,7 +204,7 @@ TEST_F(IonsMoveCGTest, TestStartTrial) EXPECT_EQ(expected_output, output); EXPECT_EQ(Ions_Move_Basic::converged, false); EXPECT_EQ(Ions_Move_Basic::update_iter, 5); - EXPECT_EQ(GlobalV::RELAX_METHOD, "bfgs"); + EXPECT_EQ(Ions_Move_Basic::relax_method, "bfgs"); EXPECT_DOUBLE_EQ(Ions_Move_Basic::largest_grad, 0.01); EXPECT_DOUBLE_EQ(Ions_Move_Basic::best_xxx, -1.0); EXPECT_DOUBLE_EQ(Ions_Move_Basic::relax_bfgs_init, 70.0); @@ -242,7 +242,7 @@ TEST_F(IonsMoveCGTest, TestStartNoTrialGotoCase1) EXPECT_EQ(expected_output, output); EXPECT_EQ(Ions_Move_Basic::converged, false); EXPECT_EQ(Ions_Move_Basic::update_iter, 5); - EXPECT_EQ(GlobalV::RELAX_METHOD, "bfgs"); + EXPECT_EQ(Ions_Move_Basic::relax_method, "bfgs"); EXPECT_DOUBLE_EQ(Ions_Move_Basic::largest_grad, 0.001); EXPECT_DOUBLE_EQ(Ions_Move_Basic::best_xxx, -1.0); EXPECT_DOUBLE_EQ(Ions_Move_Basic::relax_bfgs_init, 490.0); @@ -279,7 +279,7 @@ TEST_F(IonsMoveCGTest, TestStartNoTrialGotoCase2) EXPECT_EQ(expected_output, output); EXPECT_EQ(Ions_Move_Basic::converged, false); EXPECT_EQ(Ions_Move_Basic::update_iter, 5); - EXPECT_EQ(GlobalV::RELAX_METHOD, "bfgs"); + EXPECT_EQ(Ions_Move_Basic::relax_method, "bfgs"); EXPECT_DOUBLE_EQ(Ions_Move_Basic::largest_grad, 0.01); EXPECT_DOUBLE_EQ(Ions_Move_Basic::best_xxx, -1.0); EXPECT_DOUBLE_EQ(Ions_Move_Basic::relax_bfgs_init, 70.0); @@ -317,7 +317,7 @@ TEST_F(IonsMoveCGTest, TestStartNoTrial) EXPECT_EQ(expected_output, output); EXPECT_EQ(Ions_Move_Basic::converged, false); EXPECT_EQ(Ions_Move_Basic::update_iter, 5); - EXPECT_EQ(GlobalV::RELAX_METHOD, "bfgs"); + EXPECT_EQ(Ions_Move_Basic::relax_method, "bfgs"); EXPECT_DOUBLE_EQ(Ions_Move_Basic::largest_grad, 0.001); EXPECT_DOUBLE_EQ(Ions_Move_Basic::best_xxx, -1.0); EXPECT_NEAR(Ions_Move_Basic::relax_bfgs_init, 1.2345679012345678, 1e-12); diff --git a/source/module_relax/relax_old/test/ions_move_methods_test.cpp b/source/module_relax/relax_old/test/ions_move_methods_test.cpp index 911ac7fad6..96e448a4f0 100644 --- a/source/module_relax/relax_old/test/ions_move_methods_test.cpp +++ b/source/module_relax/relax_old/test/ions_move_methods_test.cpp @@ -40,19 +40,19 @@ class IonsMoveMethodsTest : public ::testing::Test // Test the allocate() function TEST_F(IonsMoveMethodsTest, Allocate) { - GlobalV::RELAX_METHOD = "bfgs"; + Ions_Move_Basic::relax_method = "bfgs"; imm.allocate(natom); EXPECT_EQ(Ions_Move_Basic::dim, 6); - GlobalV::RELAX_METHOD = "sd"; + Ions_Move_Basic::relax_method = "sd"; imm.allocate(natom); EXPECT_EQ(Ions_Move_Basic::dim, 6); - GlobalV::RELAX_METHOD = "cg"; + Ions_Move_Basic::relax_method = "cg"; imm.allocate(natom); EXPECT_EQ(Ions_Move_Basic::dim, 6); - GlobalV::RELAX_METHOD = "cg_bfgs"; + Ions_Move_Basic::relax_method = "cg_bfgs"; imm.allocate(natom); EXPECT_EQ(Ions_Move_Basic::dim, 6); } @@ -60,14 +60,14 @@ TEST_F(IonsMoveMethodsTest, Allocate) // Test the allocate() function warning quit TEST_F(IonsMoveMethodsTest, AllocateWarningQuit) { - GlobalV::RELAX_METHOD = "none"; + Ions_Move_Basic::relax_method = "none"; GlobalV::ofs_warning.open("log"); imm.allocate(natom); GlobalV::ofs_warning.close(); std::ifstream ifs("log"); std::string output((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); - EXPECT_THAT(output, testing::HasSubstr("the parameter GlobalV::RELAX_METHOD is not correct.")); + EXPECT_THAT(output, testing::HasSubstr("the parameter Ions_Move_Basic::relax_method is not correct.")); ifs.close(); std::remove("log"); } @@ -81,22 +81,22 @@ TEST_F(IonsMoveMethodsTest, CalMovement) const double etot = 0.0; UnitCell ucell; - GlobalV::RELAX_METHOD = "bfgs"; + Ions_Move_Basic::relax_method = "bfgs"; imm.allocate(natom); imm.cal_movement(istep, force_step, f, etot, ucell); EXPECT_EQ(Ions_Move_Basic::istep, force_step); - GlobalV::RELAX_METHOD = "sd"; + Ions_Move_Basic::relax_method = "sd"; imm.allocate(natom); imm.cal_movement(istep, force_step, f, etot, ucell); EXPECT_EQ(Ions_Move_Basic::istep, force_step); - GlobalV::RELAX_METHOD = "cg"; + Ions_Move_Basic::relax_method = "cg"; imm.allocate(natom); imm.cal_movement(istep, force_step, f, etot, ucell); EXPECT_EQ(Ions_Move_Basic::istep, force_step); - GlobalV::RELAX_METHOD = "cg_bfgs"; + Ions_Move_Basic::relax_method = "cg_bfgs"; imm.allocate(natom); imm.cal_movement(istep, force_step, f, etot, ucell); EXPECT_EQ(Ions_Move_Basic::istep, force_step); @@ -110,7 +110,7 @@ TEST_F(IonsMoveMethodsTest, CalMovementWarningQuit) const ModuleBase::matrix f(3, 3); const double etot = 0.0; UnitCell ucell; - GlobalV::RELAX_METHOD = "none"; + Ions_Move_Basic::relax_method = "none"; imm.allocate(natom); GlobalV::ofs_warning.open("log"); @@ -119,7 +119,7 @@ TEST_F(IonsMoveMethodsTest, CalMovementWarningQuit) std::ifstream ifs("log"); std::string output((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); - EXPECT_THAT(output, testing::HasSubstr("the parameter GlobalV::RELAX_METHOD is not correct.")); + EXPECT_THAT(output, testing::HasSubstr("the parameter Ions_Move_Basic::relax_method is not correct.")); ifs.close(); std::remove("log"); } diff --git a/source/module_ri/Exx_LRI.hpp b/source/module_ri/Exx_LRI.hpp index 7d44335949..356cead404 100644 --- a/source/module_ri/Exx_LRI.hpp +++ b/source/module_ri/Exx_LRI.hpp @@ -75,7 +75,7 @@ void Exx_LRI::init(const MPI_Comm &mpi_comm_in, const K_Vectors &kv_in, c case Conv_Coulomb_Pot_K::Ccp_Type::Hf: { // 4/3 * pi * Rcut^3 = V_{supercell} = V_{unitcell} * Nk - const int nspin0 = (GlobalV::NSPIN==2) ? 2 : 1; + const int nspin0 = (PARAM.inp.nspin==2) ? 2 : 1; const double hf_Rcut = std::pow(0.75 * this->p_kv->get_nkstot_full()/nspin0 * GlobalC::ucell.omega / (ModuleBase::PI), 1.0/3.0); return {{"hf_Rcut", hf_Rcut}}; } @@ -192,10 +192,10 @@ void Exx_LRI::cal_exx_elec(const std::vector, std::set>> judge = RI_2D_Comm::get_2D_judge(pv); - this->Hexxs.resize(GlobalV::NSPIN); + this->Hexxs.resize(PARAM.inp.nspin); this->Eexx = 0; (p_symrot) ? this->exx_lri.set_symmetry(true, p_symrot->get_irreducible_sector()) : this->exx_lri.set_symmetry(false, {}); - for(int is=0; is double Exx_LRI::post_process_Eexx(const double& Eexx_in) const { ModuleBase::TITLE("Exx_LRI","post_process_Eexx"); - const double SPIN_multiple = std::map{ {1,2}, {2,1}, {4,1} }.at(GlobalV::NSPIN); // why? + const double SPIN_multiple = std::map{ {1,2}, {2,1}, {4,1} }.at(PARAM.inp.nspin); // why? const double frac = -SPIN_multiple; return frac * Eexx_in; } @@ -261,7 +261,7 @@ post_process_old // E const std::map SPIN_multiple = {{1,2}, {2,1}, {4,1}}; // ??? - energy *= SPIN_multiple.at(GlobalV::NSPIN); // ? + energy *= SPIN_multiple.at(PARAM.inp.nspin); // ? energy /= 2; // /2 for Ry } */ @@ -273,7 +273,7 @@ void Exx_LRI::cal_exx_force() ModuleBase::timer::tick("Exx_LRI", "cal_exx_force"); this->force_exx.create(GlobalC::ucell.nat, Ndim); - for(int is=0; isexx_lri.cal_force({"","",std::to_string(is),"",""}); for(std::size_t idim=0; idim::cal_exx_force() } } - const double SPIN_multiple = std::map{{1,2}, {2,1}, {4,1}}.at(GlobalV::NSPIN); // why? + const double SPIN_multiple = std::map{{1,2}, {2,1}, {4,1}}.at(PARAM.inp.nspin); // why? const double frac = -2 * SPIN_multiple; // why? this->force_exx *= frac; ModuleBase::timer::tick("Exx_LRI", "cal_exx_force"); @@ -297,7 +297,7 @@ void Exx_LRI::cal_exx_stress() ModuleBase::timer::tick("Exx_LRI", "cal_exx_stress"); this->stress_exx.create(Ndim, Ndim); - for(int is=0; isexx_lri.cal_stress({"","",std::to_string(is),"",""}); for(std::size_t idim0=0; idim0::cal_exx_stress() } } - const double SPIN_multiple = std::map{{1,2}, {2,1}, {4,1}}.at(GlobalV::NSPIN); // why? + const double SPIN_multiple = std::map{{1,2}, {2,1}, {4,1}}.at(PARAM.inp.nspin); // why? const double frac = 2 * SPIN_multiple / GlobalC::ucell.omega * GlobalC::ucell.lat0; // why? this->stress_exx *= frac; diff --git a/source/module_ri/Exx_LRI_interface.hpp b/source/module_ri/Exx_LRI_interface.hpp index 079bb40468..8fa6d8b84a 100644 --- a/source/module_ri/Exx_LRI_interface.hpp +++ b/source/module_ri/Exx_LRI_interface.hpp @@ -55,7 +55,7 @@ void Exx_LRI_Interface::exx_beforescf(const K_Vectors& kv, const Charg } } // initialize the rotation matrix in AO representation - this->exx_spacegroup_symmetry = (GlobalV::NSPIN < 4 && ModuleSymmetry::Symmetry::symm_flag == 1); + this->exx_spacegroup_symmetry = (PARAM.inp.nspin < 4 && ModuleSymmetry::Symmetry::symm_flag == 1); if (this->exx_spacegroup_symmetry) { const std::array& period = RI_Util::get_Born_vonKarmen_period(kv); @@ -81,7 +81,7 @@ void Exx_LRI_Interface::exx_beforescf(const K_Vectors& kv, const Charg if(GlobalC::exx_info.info_global.cal_exx) { if (this->exx_spacegroup_symmetry) - {this->mix_DMk_2D.set_nks(kv.get_nkstot_full() * (GlobalV::NSPIN == 2 ? 2 : 1), PARAM.globalv.gamma_only_local);} + {this->mix_DMk_2D.set_nks(kv.get_nkstot_full() * (PARAM.inp.nspin == 2 ? 2 : 1), PARAM.globalv.gamma_only_local);} else {this->mix_DMk_2D.set_nks(kv.get_nks(), PARAM.globalv.gamma_only_local);} if(GlobalC::exx_info.info_global.separate_loop) { @@ -107,8 +107,8 @@ void Exx_LRI_Interface::exx_eachiterinit(const elecstate::DensityMatri else { this->mix_DMk_2D.mix(dm.get_DMK_vector(), flag_restart); } const std::vector>,RI::Tensor>>> Ds = PARAM.globalv.gamma_only_local - ? RI_2D_Comm::split_m2D_ktoR(*this->exx_ptr->p_kv, this->mix_DMk_2D.get_DMk_gamma_out(), *dm.get_paraV_pointer(), GlobalV::NSPIN) - : RI_2D_Comm::split_m2D_ktoR(*this->exx_ptr->p_kv, this->mix_DMk_2D.get_DMk_k_out(), *dm.get_paraV_pointer(), GlobalV::NSPIN, this->exx_spacegroup_symmetry); + ? RI_2D_Comm::split_m2D_ktoR(*this->exx_ptr->p_kv, this->mix_DMk_2D.get_DMk_gamma_out(), *dm.get_paraV_pointer(), PARAM.inp.nspin) + : RI_2D_Comm::split_m2D_ktoR(*this->exx_ptr->p_kv, this->mix_DMk_2D.get_DMk_k_out(), *dm.get_paraV_pointer(), PARAM.inp.nspin, this->exx_spacegroup_symmetry); if (this->exx_spacegroup_symmetry && GlobalC::exx_info.info_global.exx_symmetry_realspace) { this->exx_ptr->cal_exx_elec(Ds, *dm.get_paraV_pointer(), &this->symrot_); } else { this->exx_ptr->cal_exx_elec(Ds, *dm.get_paraV_pointer()); } } diff --git a/source/module_ri/RI_2D_Comm.cpp b/source/module_ri/RI_2D_Comm.cpp index fc7f64ce0d..db6e6d0244 100644 --- a/source/module_ri/RI_2D_Comm.cpp +++ b/source/module_ri/RI_2D_Comm.cpp @@ -1,72 +1,73 @@ -//======================= -// AUTHOR : Peize Lin -// DATE : 2022-08-17 -//======================= - -#include "RI_2D_Comm.h" -#include "module_hamilt_pw/hamilt_pwdft/global.h" -#include "module_cell/klist.h" - -#include -#include - -// judge[is] = {s0, s1} +//======================= +// AUTHOR : Peize Lin +#include "module_parameter/parameter.h" +// DATE : 2022-08-17 +//======================= + +#include "RI_2D_Comm.h" +#include "module_hamilt_pw/hamilt_pwdft/global.h" +#include "module_cell/klist.h" + +#include +#include + +// judge[is] = {s0, s1} auto RI_2D_Comm::get_2D_judge(const Parallel_2D& pv) --> std::vector, std::set>> -{ - ModuleBase::TITLE("RI_2D_Comm","get_2D_judge"); - - const std::map nspin_b = {{1,1}, {2,1}, {4,2}}; - - std::vector> iat0_list(nspin_b.at(GlobalV::NSPIN)); - for (int iwt0_2D = 0; iwt0_2D < pv.nrow; ++iwt0_2D) - { - const int iwt0 = pv.local2global_row(iwt0_2D); - int iat0=0;int iw0_b=0;int is0_b=0; - std::tie(iat0,iw0_b,is0_b) = RI_2D_Comm::get_iat_iw_is_block(iwt0); - iat0_list[is0_b].insert(iat0); - } - - std::vector> iat1_list(nspin_b.at(GlobalV::NSPIN)); - for (int iwt1_2D = 0; iwt1_2D < pv.ncol; ++iwt1_2D) - { - const int iwt1 = pv.local2global_col(iwt1_2D); - int iat1=0;int iw1_b=0;int is1_b=0; - std::tie(iat1,iw1_b,is1_b) = RI_2D_Comm::get_iat_iw_is_block(iwt1); - iat1_list[is1_b].insert(iat1); - } - - std::vector, std::set>> judge(GlobalV::NSPIN); - switch(GlobalV::NSPIN) - { - case 1: - judge[0] = std::make_tuple( std::move(iat0_list[0]), std::move(iat1_list[0]) ); - break; - case 2: - judge[0] = judge[1] = std::make_tuple( std::move(iat0_list[0]), std::move(iat1_list[0]) ); - break; - case 4: - for(int is0_b=0; is0_b<2; ++is0_b) - for(int is1_b=0; is1_b<2; ++is1_b) - { - const int is_b = RI_2D_Comm::get_is_block(-1, is0_b, is1_b); - judge[is_b] = std::make_tuple( iat0_list[is0_b], iat1_list[is1_b] ); - } - break; - default: - throw std::invalid_argument(std::string(__FILE__)+" line "+std::to_string(__LINE__)); - } - return judge; -} - - -std::vector -RI_2D_Comm::get_ik_list(const K_Vectors &kv, const int is_k) -{ - std::vector ik_list; - for(int ik=0; ik std::vector, std::set>> +{ + ModuleBase::TITLE("RI_2D_Comm","get_2D_judge"); + + const std::map nspin_b = {{1,1}, {2,1}, {4,2}}; + + std::vector> iat0_list(nspin_b.at(PARAM.inp.nspin)); + for (int iwt0_2D = 0; iwt0_2D < pv.nrow; ++iwt0_2D) + { + const int iwt0 = pv.local2global_row(iwt0_2D); + int iat0=0;int iw0_b=0;int is0_b=0; + std::tie(iat0,iw0_b,is0_b) = RI_2D_Comm::get_iat_iw_is_block(iwt0); + iat0_list[is0_b].insert(iat0); + } + + std::vector> iat1_list(nspin_b.at(PARAM.inp.nspin)); + for (int iwt1_2D = 0; iwt1_2D < pv.ncol; ++iwt1_2D) + { + const int iwt1 = pv.local2global_col(iwt1_2D); + int iat1=0;int iw1_b=0;int is1_b=0; + std::tie(iat1,iw1_b,is1_b) = RI_2D_Comm::get_iat_iw_is_block(iwt1); + iat1_list[is1_b].insert(iat1); + } + + std::vector, std::set>> judge(PARAM.inp.nspin); + switch(PARAM.inp.nspin) + { + case 1: + judge[0] = std::make_tuple( std::move(iat0_list[0]), std::move(iat1_list[0]) ); + break; + case 2: + judge[0] = judge[1] = std::make_tuple( std::move(iat0_list[0]), std::move(iat1_list[0]) ); + break; + case 4: + for(int is0_b=0; is0_b<2; ++is0_b) + for(int is1_b=0; is1_b<2; ++is1_b) + { + const int is_b = RI_2D_Comm::get_is_block(-1, is0_b, is1_b); + judge[is_b] = std::make_tuple( iat0_list[is0_b], iat1_list[is1_b] ); + } + break; + default: + throw std::invalid_argument(std::string(__FILE__)+" line "+std::to_string(__LINE__)); + } + return judge; +} + + +std::vector +RI_2D_Comm::get_ik_list(const K_Vectors &kv, const int is_k) +{ + std::vector ik_list; + for(int ik=0; ik - -#include -#include -#include - -inline RI::Tensor tensor_conj(const RI::Tensor& t) { return t; } -inline RI::Tensor> tensor_conj(const RI::Tensor>& t) -{ - RI::Tensor> r(t.shape); - for (int i = 0; i < t.data->size(); ++i) { - (*r.data)[i] = std::conj((*t.data)[i]); - } - return r; -} -template -auto RI_2D_Comm::split_m2D_ktoR(const K_Vectors & kv, const std::vector&mks_2D, const Parallel_2D & pv, const int nspin, const bool spgsym) --> std::vector>>> -{ - ModuleBase::TITLE("RI_2D_Comm","split_m2D_ktoR"); - ModuleBase::timer::tick("RI_2D_Comm", "split_m2D_ktoR"); - - const TC period = RI_Util::get_Born_vonKarmen_period(kv); - const std::map nspin_k = {{1,1}, {2,2}, {4,1}}; - const double SPIN_multiple = std::map{ {1,0.5}, {2,1}, {4,1} }.at(nspin); // why? - - std::vector>>> mRs_a2D(nspin); - for (int is_k = 0; is_k < nspin_k.at(nspin); ++is_k) - { - const std::vector ik_list = RI_2D_Comm::get_ik_list(kv, is_k); - for(const TC &cell : RI_Util::get_Born_von_Karmen_cells(period)) - { - RI::Tensor mR_2D; - int ik_full = 0; - for (const int ik : ik_list) - { - auto set_mR_2D = [&mR_2D](auto&& mk_frac) { - if (mR_2D.empty()) { - mR_2D = RI::Global_Func::convert(mk_frac); - } else { - mR_2D - = mR_2D + RI::Global_Func::convert(mk_frac); - } - }; - using Tdata_m = typename Tmatrix::value_type; - if (!spgsym) - { - RI::Tensor mk_2D = RI_Util::Vector_to_Tensor(*mks_2D[ik], pv.get_col_size(), pv.get_row_size()); - const Tdata_m frac = SPIN_multiple - * RI::Global_Func::convert(std::exp( - -ModuleBase::TWO_PI * ModuleBase::IMAG_UNIT * (kv.kvec_c[ik] * (RI_Util::array3_to_Vector3(cell) * GlobalC::ucell.latvec)))); - if (static_cast(std::round(SPIN_multiple * kv.wk[ik] * kv.get_nkstot_full())) == 2) - { set_mR_2D(mk_2D * (frac * 0.5) + tensor_conj(mk_2D * (frac * 0.5))); } - else { set_mR_2D(mk_2D * frac); } - } - else - { // traverse kstar, ik means ik_ibz - for (auto& isym_kvd : kv.kstars[ik % ik_list.size()]) - { - RI::Tensor mk_2D = RI_Util::Vector_to_Tensor(*mks_2D[ik_full + is_k * kv.get_nkstot_full()], pv.get_col_size(), pv.get_row_size()); - const Tdata_m frac = SPIN_multiple - * RI::Global_Func::convert(std::exp( - -ModuleBase::TWO_PI * ModuleBase::IMAG_UNIT * ((isym_kvd.second * GlobalC::ucell.G) * (RI_Util::array3_to_Vector3(cell) * GlobalC::ucell.latvec)))); - set_mR_2D(mk_2D * frac); - ++ik_full; - } - } - } - for(int iwt0_2D=0; iwt0_2D!=mR_2D.shape[0]; ++iwt0_2D) - { - const int iwt0 = - ModuleBase::GlobalFunc::IS_COLUMN_MAJOR_KS_SOLVER() - ? pv.local2global_col(iwt0_2D) - : pv.local2global_row(iwt0_2D); - int iat0, iw0_b, is0_b; - std::tie(iat0,iw0_b,is0_b) = RI_2D_Comm::get_iat_iw_is_block(iwt0); - const int it0 = GlobalC::ucell.iat2it[iat0]; - for(int iwt1_2D=0; iwt1_2D!=mR_2D.shape[1]; ++iwt1_2D) - { - const int iwt1 = - ModuleBase::GlobalFunc::IS_COLUMN_MAJOR_KS_SOLVER() - ? pv.local2global_row(iwt1_2D) - : pv.local2global_col(iwt1_2D); - int iat1, iw1_b, is1_b; - std::tie(iat1,iw1_b,is1_b) = RI_2D_Comm::get_iat_iw_is_block(iwt1); - const int it1 = GlobalC::ucell.iat2it[iat1]; - - const int is_b = RI_2D_Comm::get_is_block(is_k, is0_b, is1_b); - RI::Tensor &mR_a2D = mRs_a2D[is_b][iat0][{iat1,cell}]; - if (mR_a2D.empty()) { - mR_a2D = RI::Tensor( - {static_cast(GlobalC::ucell.atoms[it0].nw), - static_cast( - GlobalC::ucell.atoms[it1].nw)}); - } - mR_a2D(iw0_b,iw1_b) = mR_2D(iwt0_2D, iwt1_2D); - } - } - } - } - ModuleBase::timer::tick("RI_2D_Comm", "split_m2D_ktoR"); - return mRs_a2D; -} - - -template -void RI_2D_Comm::add_Hexx( - const K_Vectors &kv, - const int ik, - const double alpha, - const std::vector>>> &Hs, - const Parallel_Orbitals& pv, - TK* hk) -{ - ModuleBase::TITLE("RI_2D_Comm","add_Hexx"); - ModuleBase::timer::tick("RI_2D_Comm", "add_Hexx"); - - const std::map> is_list = {{1,{0}}, {2,{kv.isk[ik]}}, {4,{0,1,2,3}}}; - for(const int is_b : is_list.at(GlobalV::NSPIN)) - { - int is0_b, is1_b; - std::tie(is0_b,is1_b) = RI_2D_Comm::split_is_block(is_b); - for(const auto &Hs_tmpA : Hs[is_b]) - { - const TA &iat0 = Hs_tmpA.first; - for(const auto &Hs_tmpB : Hs_tmpA.second) - { - const TA &iat1 = Hs_tmpB.first.first; - const TC &cell1 = Hs_tmpB.first.second; - const std::complex frac = alpha - * std::exp( ModuleBase::TWO_PI*ModuleBase::IMAG_UNIT * (kv.kvec_c[ik] * (RI_Util::array3_to_Vector3(cell1)*GlobalC::ucell.latvec)) ); - const RI::Tensor &H = Hs_tmpB.second; - for(size_t iw0_b=0; iw0_b(H(iw0_b, iw1_b)) * RI::Global_Func::convert(frac), pv, hk); - } - } - } - } - } - ModuleBase::timer::tick("RI_2D_Comm", "add_Hexx"); -} - -std::tuple -RI_2D_Comm::get_iat_iw_is_block(const int iwt) -{ - const int iat = GlobalC::ucell.iwt2iat[iwt]; - const int iw = GlobalC::ucell.iwt2iw[iwt]; - switch(GlobalV::NSPIN) - { - case 1: case 2: - return std::make_tuple(iat, iw, 0); - case 4: - return std::make_tuple(iat, iw/2, iw%2); - default: - throw std::invalid_argument(std::string(__FILE__)+" line "+std::to_string(__LINE__)); - } -} - -int RI_2D_Comm::get_is_block(const int is_k, const int is_row_b, const int is_col_b) -{ - switch(GlobalV::NSPIN) - { - case 1: return 0; - case 2: return is_k; - case 4: return is_row_b*2+is_col_b; - default: throw std::invalid_argument(std::string(__FILE__)+" line "+std::to_string(__LINE__)); - } -} - -std::tuple -RI_2D_Comm::split_is_block(const int is_b) -{ - switch(GlobalV::NSPIN) - { - case 1: case 2: - return std::make_tuple(0, 0); - case 4: - return std::make_tuple(is_b/2, is_b%2); - default: - throw std::invalid_argument(std::string(__FILE__)+" line "+std::to_string(__LINE__)); - } -} - - - -int RI_2D_Comm::get_iwt(const int iat, const int iw_b, const int is_b) -{ - const int it = GlobalC::ucell.iat2it[iat]; - const int ia = GlobalC::ucell.iat2ia[iat]; - int iw=-1; - switch(GlobalV::NSPIN) - { - case 1: case 2: - iw = iw_b; break; - case 4: - iw = iw_b*2+is_b; break; - default: - throw std::invalid_argument(std::string(__FILE__)+" line "+std::to_string(__LINE__)); - } - const int iwt = GlobalC::ucell.itiaiw2iwt(it,ia,iw); - return iwt; -} - -template -void RI_2D_Comm::add_HexxR( - const int current_spin, - const double alpha, - const std::vector>>>& Hs, - const Parallel_Orbitals& pv, - const int npol, - hamilt::HContainer& hR, - const RI::Cell_Nearest* const cell_nearest) -{ - ModuleBase::TITLE("RI_2D_Comm", "add_HexxR"); - ModuleBase::timer::tick("RI_2D_Comm", "add_HexxR"); - const std::map> is_list = { {1,{0}}, {2,{current_spin}}, {4,{0,1,2,3}} }; - for (const int is_hs : is_list.at(GlobalV::NSPIN)) - { - int is0_b = 0, is1_b = 0; - std::tie(is0_b, is1_b) = RI_2D_Comm::split_is_block(is_hs); - for (const auto& Hs_tmpA : Hs[is_hs]) - { - const TA& iat0 = Hs_tmpA.first; - for (const auto& Hs_tmpB : Hs_tmpA.second) - { - const TA& iat1 = Hs_tmpB.first.first; - const TC& cell = Hs_tmpB.first.second; - const Abfs::Vector3_Order R = RI_Util::array3_to_Vector3( - (cell_nearest ? - cell_nearest->get_cell_nearest_discrete(iat0, iat1, cell) - : cell)); - hamilt::BaseMatrix* HlocR = hR.find_matrix(iat0, iat1, R.x, R.y, R.z); - if (HlocR == nullptr) - { // add R to HContainer - hamilt::AtomPair tmp(iat0, iat1, R.x, R.y, R.z, &pv); - hR.insert_pair(tmp); - HlocR = hR.find_matrix(iat0, iat1, R.x, R.y, R.z); - } - auto row_indexes = pv.get_indexes_row(iat0); - auto col_indexes = pv.get_indexes_col(iat1); - const RI::Tensor& HexxR = (Tdata)alpha * Hs_tmpB.second; - for (int lw0_b = 0;lw0_b < row_indexes.size();lw0_b += npol) // block - { - const int& gw0 = row_indexes[lw0_b] / npol; - const int& lw0 = (npol == 2) ? (lw0_b + is0_b) : lw0_b; - for (int lw1_b = 0;lw1_b < col_indexes.size();lw1_b += npol) - { - const int& gw1 = col_indexes[lw1_b] / npol; - const int& lw1 = (npol == 2) ? (lw1_b + is1_b) : lw1_b; - HlocR->add_element(lw0, lw1, RI::Global_Func::convert(HexxR(gw0, gw1))); - } - } - } - } - } - - ModuleBase::timer::tick("RI_2D_Comm", "add_HexxR"); -} - +//======================= +// AUTHOR : Peize Lin +#include "module_parameter/parameter.h" +// DATE : 2022-08-17 +//======================= + +#ifndef RI_2D_COMM_HPP +#define RI_2D_COMM_HPP + +#include "RI_2D_Comm.h" +#include "RI_Util.h" +#include "module_hamilt_pw/hamilt_pwdft/global.h" +#include "module_base/tool_title.h" +#include "module_base/timer.h" +#include "module_hamilt_lcao/hamilt_lcaodft/LCAO_domain.h" + +#include + +#include +#include +#include + +inline RI::Tensor tensor_conj(const RI::Tensor& t) { return t; } +inline RI::Tensor> tensor_conj(const RI::Tensor>& t) +{ + RI::Tensor> r(t.shape); + for (int i = 0; i < t.data->size(); ++i) { + (*r.data)[i] = std::conj((*t.data)[i]); + } + return r; +} +template +auto RI_2D_Comm::split_m2D_ktoR(const K_Vectors & kv, const std::vector&mks_2D, const Parallel_2D & pv, const int nspin, const bool spgsym) +-> std::vector>>> +{ + ModuleBase::TITLE("RI_2D_Comm","split_m2D_ktoR"); + ModuleBase::timer::tick("RI_2D_Comm", "split_m2D_ktoR"); + + const TC period = RI_Util::get_Born_vonKarmen_period(kv); + const std::map nspin_k = {{1,1}, {2,2}, {4,1}}; + const double SPIN_multiple = std::map{ {1,0.5}, {2,1}, {4,1} }.at(nspin); // why? + + std::vector>>> mRs_a2D(nspin); + for (int is_k = 0; is_k < nspin_k.at(nspin); ++is_k) + { + const std::vector ik_list = RI_2D_Comm::get_ik_list(kv, is_k); + for(const TC &cell : RI_Util::get_Born_von_Karmen_cells(period)) + { + RI::Tensor mR_2D; + int ik_full = 0; + for (const int ik : ik_list) + { + auto set_mR_2D = [&mR_2D](auto&& mk_frac) { + if (mR_2D.empty()) { + mR_2D = RI::Global_Func::convert(mk_frac); + } else { + mR_2D + = mR_2D + RI::Global_Func::convert(mk_frac); + } + }; + using Tdata_m = typename Tmatrix::value_type; + if (!spgsym) + { + RI::Tensor mk_2D = RI_Util::Vector_to_Tensor(*mks_2D[ik], pv.get_col_size(), pv.get_row_size()); + const Tdata_m frac = SPIN_multiple + * RI::Global_Func::convert(std::exp( + -ModuleBase::TWO_PI * ModuleBase::IMAG_UNIT * (kv.kvec_c[ik] * (RI_Util::array3_to_Vector3(cell) * GlobalC::ucell.latvec)))); + if (static_cast(std::round(SPIN_multiple * kv.wk[ik] * kv.get_nkstot_full())) == 2) + { set_mR_2D(mk_2D * (frac * 0.5) + tensor_conj(mk_2D * (frac * 0.5))); } + else { set_mR_2D(mk_2D * frac); } + } + else + { // traverse kstar, ik means ik_ibz + for (auto& isym_kvd : kv.kstars[ik % ik_list.size()]) + { + RI::Tensor mk_2D = RI_Util::Vector_to_Tensor(*mks_2D[ik_full + is_k * kv.get_nkstot_full()], pv.get_col_size(), pv.get_row_size()); + const Tdata_m frac = SPIN_multiple + * RI::Global_Func::convert(std::exp( + -ModuleBase::TWO_PI * ModuleBase::IMAG_UNIT * ((isym_kvd.second * GlobalC::ucell.G) * (RI_Util::array3_to_Vector3(cell) * GlobalC::ucell.latvec)))); + set_mR_2D(mk_2D * frac); + ++ik_full; + } + } + } + for(int iwt0_2D=0; iwt0_2D!=mR_2D.shape[0]; ++iwt0_2D) + { + const int iwt0 = + ModuleBase::GlobalFunc::IS_COLUMN_MAJOR_KS_SOLVER() + ? pv.local2global_col(iwt0_2D) + : pv.local2global_row(iwt0_2D); + int iat0, iw0_b, is0_b; + std::tie(iat0,iw0_b,is0_b) = RI_2D_Comm::get_iat_iw_is_block(iwt0); + const int it0 = GlobalC::ucell.iat2it[iat0]; + for(int iwt1_2D=0; iwt1_2D!=mR_2D.shape[1]; ++iwt1_2D) + { + const int iwt1 = + ModuleBase::GlobalFunc::IS_COLUMN_MAJOR_KS_SOLVER() + ? pv.local2global_row(iwt1_2D) + : pv.local2global_col(iwt1_2D); + int iat1, iw1_b, is1_b; + std::tie(iat1,iw1_b,is1_b) = RI_2D_Comm::get_iat_iw_is_block(iwt1); + const int it1 = GlobalC::ucell.iat2it[iat1]; + + const int is_b = RI_2D_Comm::get_is_block(is_k, is0_b, is1_b); + RI::Tensor &mR_a2D = mRs_a2D[is_b][iat0][{iat1,cell}]; + if (mR_a2D.empty()) { + mR_a2D = RI::Tensor( + {static_cast(GlobalC::ucell.atoms[it0].nw), + static_cast( + GlobalC::ucell.atoms[it1].nw)}); + } + mR_a2D(iw0_b,iw1_b) = mR_2D(iwt0_2D, iwt1_2D); + } + } + } + } + ModuleBase::timer::tick("RI_2D_Comm", "split_m2D_ktoR"); + return mRs_a2D; +} + + +template +void RI_2D_Comm::add_Hexx( + const K_Vectors &kv, + const int ik, + const double alpha, + const std::vector>>> &Hs, + const Parallel_Orbitals& pv, + TK* hk) +{ + ModuleBase::TITLE("RI_2D_Comm","add_Hexx"); + ModuleBase::timer::tick("RI_2D_Comm", "add_Hexx"); + + const std::map> is_list = {{1,{0}}, {2,{kv.isk[ik]}}, {4,{0,1,2,3}}}; + for(const int is_b : is_list.at(PARAM.inp.nspin)) + { + int is0_b, is1_b; + std::tie(is0_b,is1_b) = RI_2D_Comm::split_is_block(is_b); + for(const auto &Hs_tmpA : Hs[is_b]) + { + const TA &iat0 = Hs_tmpA.first; + for(const auto &Hs_tmpB : Hs_tmpA.second) + { + const TA &iat1 = Hs_tmpB.first.first; + const TC &cell1 = Hs_tmpB.first.second; + const std::complex frac = alpha + * std::exp( ModuleBase::TWO_PI*ModuleBase::IMAG_UNIT * (kv.kvec_c[ik] * (RI_Util::array3_to_Vector3(cell1)*GlobalC::ucell.latvec)) ); + const RI::Tensor &H = Hs_tmpB.second; + for(size_t iw0_b=0; iw0_b(H(iw0_b, iw1_b)) * RI::Global_Func::convert(frac), pv, hk); + } + } + } + } + } + ModuleBase::timer::tick("RI_2D_Comm", "add_Hexx"); +} + +std::tuple +RI_2D_Comm::get_iat_iw_is_block(const int iwt) +{ + const int iat = GlobalC::ucell.iwt2iat[iwt]; + const int iw = GlobalC::ucell.iwt2iw[iwt]; + switch(PARAM.inp.nspin) + { + case 1: case 2: + return std::make_tuple(iat, iw, 0); + case 4: + return std::make_tuple(iat, iw/2, iw%2); + default: + throw std::invalid_argument(std::string(__FILE__)+" line "+std::to_string(__LINE__)); + } +} + +int RI_2D_Comm::get_is_block(const int is_k, const int is_row_b, const int is_col_b) +{ + switch(PARAM.inp.nspin) + { + case 1: return 0; + case 2: return is_k; + case 4: return is_row_b*2+is_col_b; + default: throw std::invalid_argument(std::string(__FILE__)+" line "+std::to_string(__LINE__)); + } +} + +std::tuple +RI_2D_Comm::split_is_block(const int is_b) +{ + switch(PARAM.inp.nspin) + { + case 1: case 2: + return std::make_tuple(0, 0); + case 4: + return std::make_tuple(is_b/2, is_b%2); + default: + throw std::invalid_argument(std::string(__FILE__)+" line "+std::to_string(__LINE__)); + } +} + + + +int RI_2D_Comm::get_iwt(const int iat, const int iw_b, const int is_b) +{ + const int it = GlobalC::ucell.iat2it[iat]; + const int ia = GlobalC::ucell.iat2ia[iat]; + int iw=-1; + switch(PARAM.inp.nspin) + { + case 1: case 2: + iw = iw_b; break; + case 4: + iw = iw_b*2+is_b; break; + default: + throw std::invalid_argument(std::string(__FILE__)+" line "+std::to_string(__LINE__)); + } + const int iwt = GlobalC::ucell.itiaiw2iwt(it,ia,iw); + return iwt; +} + +template +void RI_2D_Comm::add_HexxR( + const int current_spin, + const double alpha, + const std::vector>>>& Hs, + const Parallel_Orbitals& pv, + const int npol, + hamilt::HContainer& hR, + const RI::Cell_Nearest* const cell_nearest) +{ + ModuleBase::TITLE("RI_2D_Comm", "add_HexxR"); + ModuleBase::timer::tick("RI_2D_Comm", "add_HexxR"); + const std::map> is_list = { {1,{0}}, {2,{current_spin}}, {4,{0,1,2,3}} }; + for (const int is_hs : is_list.at(PARAM.inp.nspin)) + { + int is0_b = 0, is1_b = 0; + std::tie(is0_b, is1_b) = RI_2D_Comm::split_is_block(is_hs); + for (const auto& Hs_tmpA : Hs[is_hs]) + { + const TA& iat0 = Hs_tmpA.first; + for (const auto& Hs_tmpB : Hs_tmpA.second) + { + const TA& iat1 = Hs_tmpB.first.first; + const TC& cell = Hs_tmpB.first.second; + const Abfs::Vector3_Order R = RI_Util::array3_to_Vector3( + (cell_nearest ? + cell_nearest->get_cell_nearest_discrete(iat0, iat1, cell) + : cell)); + hamilt::BaseMatrix* HlocR = hR.find_matrix(iat0, iat1, R.x, R.y, R.z); + if (HlocR == nullptr) + { // add R to HContainer + hamilt::AtomPair tmp(iat0, iat1, R.x, R.y, R.z, &pv); + hR.insert_pair(tmp); + HlocR = hR.find_matrix(iat0, iat1, R.x, R.y, R.z); + } + auto row_indexes = pv.get_indexes_row(iat0); + auto col_indexes = pv.get_indexes_col(iat1); + const RI::Tensor& HexxR = (Tdata)alpha * Hs_tmpB.second; + for (int lw0_b = 0;lw0_b < row_indexes.size();lw0_b += npol) // block + { + const int& gw0 = row_indexes[lw0_b] / npol; + const int& lw0 = (npol == 2) ? (lw0_b + is0_b) : lw0_b; + for (int lw1_b = 0;lw1_b < col_indexes.size();lw1_b += npol) + { + const int& gw1 = col_indexes[lw1_b] / npol; + const int& lw1 = (npol == 2) ? (lw1_b + is1_b) : lw1_b; + HlocR->add_element(lw0, lw1, RI::Global_Func::convert(HexxR(gw0, gw1))); + } + } + } + } + } + + ModuleBase::timer::tick("RI_2D_Comm", "add_HexxR"); +} + #endif \ No newline at end of file diff --git a/source/module_ri/RPA_LRI.hpp b/source/module_ri/RPA_LRI.hpp index 8cae321ff0..d60bc87f1d 100644 --- a/source/module_ri/RPA_LRI.hpp +++ b/source/module_ri/RPA_LRI.hpp @@ -77,9 +77,9 @@ void RPA_LRI::cal_postSCF_exx(const elecstate::DensityMatrix const LCAO_Orbitals& orb) { Mix_DMk_2D mix_DMk_2D; - bool exx_spacegroup_symmetry = (GlobalV::NSPIN < 4 && ModuleSymmetry::Symmetry::symm_flag == 1); + bool exx_spacegroup_symmetry = (PARAM.inp.nspin < 4 && ModuleSymmetry::Symmetry::symm_flag == 1); if (exx_spacegroup_symmetry) - {mix_DMk_2D.set_nks(kv.get_nkstot_full() * (GlobalV::NSPIN == 2 ? 2 : 1), PARAM.globalv.gamma_only_local);} + {mix_DMk_2D.set_nks(kv.get_nkstot_full() * (PARAM.inp.nspin == 2 ? 2 : 1), PARAM.globalv.gamma_only_local);} else {mix_DMk_2D.set_nks(kv.get_nks(), PARAM.globalv.gamma_only_local);} @@ -97,8 +97,8 @@ void RPA_LRI::cal_postSCF_exx(const elecstate::DensityMatrix const std::vector>>> Ds = PARAM.globalv.gamma_only_local - ? RI_2D_Comm::split_m2D_ktoR(kv, mix_DMk_2D.get_DMk_gamma_out(), *dm.get_paraV_pointer(), GlobalV::NSPIN) - : RI_2D_Comm::split_m2D_ktoR(kv, mix_DMk_2D.get_DMk_k_out(), *dm.get_paraV_pointer(), GlobalV::NSPIN, exx_spacegroup_symmetry); + ? RI_2D_Comm::split_m2D_ktoR(kv, mix_DMk_2D.get_DMk_gamma_out(), *dm.get_paraV_pointer(), PARAM.inp.nspin) + : RI_2D_Comm::split_m2D_ktoR(kv, mix_DMk_2D.get_DMk_k_out(), *dm.get_paraV_pointer(), PARAM.inp.nspin, exx_spacegroup_symmetry); // set parameters for bare Coulomb potential GlobalC::exx_info.info_global.ccp_type = Conv_Coulomb_Pot_K::Ccp_Type::Hf; @@ -147,8 +147,8 @@ void RPA_LRI::out_eigen_vector(const Parallel_Orbitals& parav, const p ModuleBase::TITLE("DFT_RPA_interface", "out_eigen_vector"); - const int nks_tot = GlobalV::NSPIN == 2 ? p_kv->get_nks() / 2 : p_kv->get_nks(); - const int npsin_tmp = GlobalV::NSPIN == 2 ? 2 : 1; + const int nks_tot = PARAM.inp.nspin == 2 ? p_kv->get_nks() / 2 : p_kv->get_nks(); + const int npsin_tmp = PARAM.inp.nspin == 2 ? 2 : 1; const std::complex zero(0.0, 0.0); for (int ik = 0; ik < nks_tot; ik++) @@ -216,7 +216,7 @@ void RPA_LRI::out_struc() } ModuleBase::TITLE("DFT_RPA_interface", "out_struc"); double TWOPI_Bohr2A = ModuleBase::TWO_PI * ModuleBase::BOHR_TO_A; - const int nks_tot = GlobalV::NSPIN == 2 ? (int)p_kv->get_nks() / 2 : p_kv->get_nks(); + const int nks_tot = PARAM.inp.nspin == 2 ? (int)p_kv->get_nks() / 2 : p_kv->get_nks(); ModuleBase::Matrix3 lat = GlobalC::ucell.latvec / ModuleBase::BOHR_TO_A; ModuleBase::Matrix3 G = GlobalC::ucell.G * TWOPI_Bohr2A; std::stringstream ss; @@ -251,14 +251,14 @@ void RPA_LRI::out_bands(const elecstate::ElecState* pelec) { return; } - const int nks_tot = GlobalV::NSPIN == 2 ? (int)p_kv->get_nks() / 2 : p_kv->get_nks(); - const int nspin_tmp = GlobalV::NSPIN == 2 ? 2 : 1; + const int nks_tot = PARAM.inp.nspin == 2 ? (int)p_kv->get_nks() / 2 : p_kv->get_nks(); + const int nspin_tmp = PARAM.inp.nspin == 2 ? 2 : 1; std::stringstream ss; ss << "band_out"; std::ofstream ofs; ofs.open(ss.str().c_str(), std::ios::out); ofs << nks_tot << std::endl; - ofs << GlobalV::NSPIN << std::endl; + ofs << PARAM.inp.nspin << std::endl; ofs << GlobalV::NBANDS << std::endl; ofs << GlobalV::NLOCAL << std::endl; ofs << (pelec->eferm.ef / 2.0) << std::endl; @@ -329,7 +329,7 @@ void RPA_LRI::out_coulomb_k() mu_shift[I] = all_mu; all_mu += exx_lri_rpa.cv.get_index_abfs_size(GlobalC::ucell.iat2it[I]); } - const int nks_tot = GlobalV::NSPIN == 2 ? (int)p_kv->get_nks() / 2 : p_kv->get_nks(); + const int nks_tot = PARAM.inp.nspin == 2 ? (int)p_kv->get_nks() / 2 : p_kv->get_nks(); std::stringstream ss; ss << "coulomb_mat_" << GlobalV::MY_RANK << ".txt"; @@ -372,7 +372,7 @@ void RPA_LRI::out_coulomb_k() size_t nu_num = exx_lri_rpa.cv.get_index_abfs_size(GlobalC::ucell.iat2it[iJ]); ofs << all_mu << " " << mu_shift[I] + 1 << " " << mu_shift[I] + mu_num << " " << mu_shift[iJ] + 1 << " " << mu_shift[iJ] + nu_num << std::endl; - ofs << ik + 1 << " " << p_kv->wk[ik] / 2.0 * GlobalV::NSPIN << std::endl; + ofs << ik + 1 << " " << p_kv->wk[ik] / 2.0 * PARAM.inp.nspin << std::endl; for (int i = 0; i != vq_J.data->size(); i++) { ofs << std::setw(21) << std::fixed << std::setprecision(12) << (*vq_J.data)[i].real() diff --git a/source/module_ri/exx_lip.cpp b/source/module_ri/exx_lip.cpp index 7c83c191e3..e3a6016e58 100644 --- a/source/module_ri/exx_lip.cpp +++ b/source/module_ri/exx_lip.cpp @@ -47,11 +47,11 @@ void Exx_Lip::cal_exx() } } - for (int iq_tmp = iq_vecik; iq_tmp < iq_vecik + q_pack->kv_ptr->get_nks() / GlobalV::NSPIN; ++iq_tmp) // !!! k_point + for (int iq_tmp = iq_vecik; iq_tmp < iq_vecik + q_pack->kv_ptr->get_nks() / PARAM.inp.nspin; ++iq_tmp) // !!! k_point // parallel incompleted.need to loop iq in other pool { - int iq = (ik < (k_pack->kv_ptr->get_nks() / GlobalV::NSPIN)) ? (iq_tmp % (q_pack->kv_ptr->get_nks() / GlobalV::NSPIN)) : - (iq_tmp % (q_pack->kv_ptr->get_nks() / GlobalV::NSPIN) + (q_pack->kv_ptr->get_nks() / GlobalV::NSPIN)); + int iq = (ik < (k_pack->kv_ptr->get_nks() / PARAM.inp.nspin)) ? (iq_tmp % (q_pack->kv_ptr->get_nks() / PARAM.inp.nspin)) : + (iq_tmp % (q_pack->kv_ptr->get_nks() / PARAM.inp.nspin) + (q_pack->kv_ptr->get_nks() / PARAM.inp.nspin)); qkg2_exp(ik, iq); //t_qkg2_exp += my_time(t); for (int ib = 0; ib < GlobalV::NBANDS; ++ib) @@ -114,9 +114,9 @@ void Exx_Lip::cal_exx() sum3[iw_l][iw_r] = std::complex(0.0,0.0); } - for( int iq_tmp=iq_vecik; iq_tmpkv_ptr->get_nks()/GlobalV::NSPIN; ++iq_tmp) // !!! k_point parallel incompleted. need to loop iq in other pool + for( int iq_tmp=iq_vecik; iq_tmpkv_ptr->get_nks()/PARAM.inp.nspin; ++iq_tmp) // !!! k_point parallel incompleted. need to loop iq in other pool { - int iq = (ik<(k_pack->kv_ptr->get_nks()/GlobalV::NSPIN)) ? (iq_tmp%(q_pack->kv_ptr->get_nks()/GlobalV::NSPIN)) : (iq_tmp%(q_pack->kv_ptr->get_nks()/GlobalV::NSPIN)+(q_pack->kv_ptr->get_nks()/GlobalV::NSPIN)); + int iq = (ik<(k_pack->kv_ptr->get_nks()/PARAM.inp.nspin)) ? (iq_tmp%(q_pack->kv_ptr->get_nks()/PARAM.inp.nspin)) : (iq_tmp%(q_pack->kv_ptr->get_nks()/PARAM.inp.nspin)+(q_pack->kv_ptr->get_nks()/PARAM.inp.nspin)); qkg2_exp(ik, iq); for( int ib=0; ib void Exx_Lip::wf_wg_cal() { ModuleBase::TITLE("Exx_Lip", "wf_wg_cal"); - if (GlobalV::NSPIN == 1) { + if (PARAM.inp.nspin == 1) { for (int ik = 0; ik < k_pack->kv_ptr->get_nks(); ++ik) { for (int ib = 0; ib < GlobalV::NBANDS; ++ib) { k_pack->wf_wg(ik, ib) = k_pack->pelec->wg(ik, ib) / 2; } } - } else if (GlobalV::NSPIN == 2) { + } else if (PARAM.inp.nspin == 2) { for (int ik = 0; ik < k_pack->kv_ptr->get_nks(); ++ik) { for (int ib = 0; ib < GlobalV::NBANDS; ++ib) { k_pack->wf_wg(ik, ib) = k_pack->pelec->wg(ik, ib); @@ -492,7 +492,7 @@ void Exx_Lip::sum_all(int ik) if (gzero_rank_in_pool == GlobalV::RANK_IN_POOL) { exx_matrix[ik][iw_l][iw_r] += spin_fac * (fourpi_div_omega * sum3[iw_l][iw_r] * sum2_factor_g); - exx_matrix[ik][iw_l][iw_r] += spin_fac * (-1 / (Real)sqrt(info.lambda * ModuleBase::PI) * (Real)(q_pack->kv_ptr->get_nks() / GlobalV::NSPIN) * sum3[iw_l][iw_r]); + exx_matrix[ik][iw_l][iw_r] += spin_fac * (-1 / (Real)sqrt(info.lambda * ModuleBase::PI) * (Real)(q_pack->kv_ptr->get_nks() / PARAM.inp.nspin) * sum3[iw_l][iw_r]); } } } @@ -522,7 +522,7 @@ void Exx_Lip::exx_energy_cal() #ifdef __MPI MPI_Allreduce( &exx_energy_tmp, &exx_energy, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); // !!! k_point parallel incompleted. different pools have different kv.set_nks(>) deadlock #endif - exx_energy *= (GlobalV::NSPIN==1) ? 2 : 1; + exx_energy *= (PARAM.inp.nspin==1) ? 2 : 1; exx_energy /= 2; // ETOT = E_band - 1/2 E_exx #if TEST_EXX==1 @@ -635,7 +635,7 @@ void Exx_Lip::write_q_pack() const // q_pack->kv_ptr = new K_Vectors(); // const std::string exx_kpoint_card = PARAM.globalv.global_out_dir + exx_q_pack + PARAM.inp.kpoint_file; -// q_pack->kv_ptr->set( symm, exx_kpoint_card, GlobalV::NSPIN, ucell_ptr->G, ucell_ptr->latvec, GlobalV::ofs_running ); +// q_pack->kv_ptr->set( symm, exx_kpoint_card, PARAM.inp.nspin, ucell_ptr->G, ucell_ptr->latvec, GlobalV::ofs_running ); // q_pack->wf_ptr = new wavefunc(); // q_pack->wf_ptr->allocate(q_pack->kv_ptr->get_nkstot(), @@ -643,8 +643,8 @@ void Exx_Lip::write_q_pack() const // q_pack->kv_ptr->ngk.data(), // wfc_basis->npwk_max); // mohan update 2021-02-25 // // q_pack->wf_ptr->init(q_pack->kv_ptr->get_nks(),q_pack->kv_ptr,ucell_ptr,old_pwptr,&ppcell,&GlobalC::ORB,&hm,&Pkpoints); -// q_pack->wf_ptr->table_local.create(GlobalC::ucell.ntype, GlobalC::ucell.nmax_total, GlobalV::NQX); -// // q_pack->wf_ptr->table_local.create(q_pack->wf_ptr->ucell_ptr->ntype, q_pack->wf_ptr->ucell_ptr->nmax_total, GlobalV::NQX); +// q_pack->wf_ptr->table_local.create(GlobalC::ucell.ntype, GlobalC::ucell.nmax_total, PARAM.globalv.nqx); +// // q_pack->wf_ptr->table_local.create(q_pack->wf_ptr->ucell_ptr->ntype, q_pack->wf_ptr->ucell_ptr->nmax_total, PARAM.globalv.nqx); // #ifdef __LCAO // Wavefunc_in_pw::make_table_q(GlobalC::ORB.orbital_file, q_pack->wf_ptr->table_local); // // Wavefunc_in_pw::make_table_q(q_pack->wf_ptr->ORB_ptr->orbital_file, q_pack->wf_ptr->table_local, q_pack->wf_ptr); diff --git a/source/module_ri/module_exx_symmetry/symmetry_rotation.cpp b/source/module_ri/module_exx_symmetry/symmetry_rotation.cpp index 62661e799d..ab9c7b9756 100644 --- a/source/module_ri/module_exx_symmetry/symmetry_rotation.cpp +++ b/source/module_ri/module_exx_symmetry/symmetry_rotation.cpp @@ -1,5 +1,6 @@ #include "symmetry_rotation.h" #include "module_base/constants.h" +#include "module_parameter/parameter.h" #include #include "module_base/parallel_reduce.h" #include "module_base/scalapack_connector.h" @@ -99,7 +100,7 @@ namespace ModuleSymmetry return z_conj; }; std::vector>> dm_k_full; - int nspin0 = GlobalV::NSPIN == 2 ? 2 : 1; + int nspin0 = PARAM.inp.nspin == 2 ? 2 : 1; dm_k_full.reserve(kv.get_nkstot_full() * nspin0); //nkstot_full didn't doubled by spin int nk = kv.get_nkstot() / nspin0; for (int is = 0;is < nspin0;++is) {