From ef0d0e6a53b56e495107b24466e8dfbc9a6bcb8e Mon Sep 17 00:00:00 2001 From: linpz Date: Sat, 17 Jan 2026 15:18:20 +0800 Subject: [PATCH 1/2] Refactor class Charge to template --- source/source_esolver/esolver_double_xc.h | 2 +- source/source_esolver/esolver_fp.h | 2 +- source/source_esolver/esolver_of.cpp | 4 +- source/source_esolver/esolver_of.h | 4 +- source/source_esolver/esolver_of_tool.cpp | 6 +- source/source_estate/elecstate.cpp | 2 +- source/source_estate/elecstate.h | 6 +- source/source_estate/elecstate_lcao.h | 2 +- source/source_estate/elecstate_pw.cpp | 2 +- source/source_estate/elecstate_pw.h | 2 +- source/source_estate/elecstate_pw_sdft.h | 2 +- source/source_estate/module_charge/charge.cpp | 221 ++++++++++-------- source/source_estate/module_charge/charge.h | 39 ++-- .../module_charge/charge_extra.cpp | 6 +- .../module_charge/charge_extra.h | 4 +- .../module_charge/charge_init.cpp | 20 +- .../module_charge/charge_mixing.h | 16 +- .../module_charge/charge_mixing_residual.cpp | 4 +- .../module_charge/charge_mixing_rho.cpp | 6 +- .../module_charge/charge_mpi.cpp | 28 ++- .../source_estate/module_charge/chgmixing.cpp | 2 +- .../source_estate/module_charge/chgmixing.h | 2 +- .../module_charge/symmetry_rho.cpp | 2 +- .../module_charge/symmetry_rho.h | 2 +- source/source_estate/module_dm/init_dm.cpp | 6 +- source/source_estate/module_dm/init_dm.h | 2 +- .../source_estate/module_pot/H_Hartree_pw.cpp | 2 +- .../source_estate/module_pot/H_Hartree_pw.h | 2 +- source/source_estate/module_pot/efield.h | 2 +- source/source_estate/module_pot/pot_base.h | 6 +- .../source_estate/module_pot/pot_surchem.hpp | 2 +- source/source_estate/module_pot/pot_xc.cpp | 2 +- source/source_estate/module_pot/pot_xc.h | 2 +- .../module_pot/potential_new.cpp | 8 +- .../source_estate/module_pot/potential_new.h | 12 +- source/source_estate/setup_estate_pw.cpp | 10 +- source/source_estate/setup_estate_pw.h | 2 +- .../source_estate/test/charge_extra_test.cpp | 13 +- .../source_estate/test/charge_mixing_test.cpp | 11 +- source/source_estate/test/charge_test.cpp | 26 +-- .../test/elecstate_base_test.cpp | 26 +-- .../test/elecstate_energy_test.cpp | 2 +- .../test/elecstate_magnetism_test.cpp | 8 +- .../test/elecstate_print_test.cpp | 10 +- .../source_estate/test/elecstate_pw_test.cpp | 22 +- .../source_estate/test/potential_new_test.cpp | 12 +- .../test_mpi/charge_mpi_test.cpp | 8 +- source/source_estate/update_pot.cpp | 2 +- source/source_estate/update_pot.h | 2 +- .../source_hamilt/module_xc/test/test_xc3.cpp | 2 +- .../source_hamilt/module_xc/test/test_xc5.cpp | 6 +- .../source_hamilt/module_xc/test/xc3_mock.h | 4 +- .../source_hamilt/module_xc/xc_functional.h | 4 +- .../module_xc/xc_functional_gradcorr.cpp | 2 +- .../module_xc/xc_functional_libxc.h | 18 +- .../module_xc/xc_functional_libxc_tools.cpp | 12 +- .../module_xc/xc_functional_libxc_vxc.cpp | 4 +- .../module_xc/xc_functional_vxc.cpp | 2 +- source/source_hsolver/hsolver_lcao.cpp | 2 +- source/source_hsolver/hsolver_lcao.h | 2 +- .../test/hsolver_supplementary_mock.h | 6 +- .../source_hsolver/test/test_hsolver_sdft.cpp | 6 +- source/source_io/cal_ldos.cpp | 2 +- source/source_io/cal_ldos.h | 2 +- source/source_io/ctrl_iter_lcao.cpp | 8 +- source/source_io/ctrl_iter_lcao.h | 2 +- source/source_io/ctrl_output_fp.cpp | 2 +- source/source_io/ctrl_output_fp.h | 2 +- source/source_io/ctrl_output_pw.cpp | 20 +- source/source_io/ctrl_output_pw.h | 4 +- source/source_io/ctrl_runner_lcao.cpp | 8 +- source/source_io/ctrl_runner_lcao.h | 2 +- source/source_io/cube_io.h | 3 +- source/source_io/get_pchg_pw.h | 2 +- source/source_io/read_cube.cpp | 15 +- source/source_io/read_wf2rho_pw.cpp | 28 ++- source/source_io/read_wf2rho_pw.h | 3 +- source/source_io/test/read_wf2rho_pw_test.cpp | 10 +- source/source_io/write_eband_terms.hpp | 2 +- source/source_io/write_elecstat_pot.cpp | 2 +- source/source_io/write_elecstat_pot.h | 2 +- source/source_io/write_init.cpp | 2 +- source/source_io/write_init.h | 2 +- source/source_io/write_libxc_r.cpp | 2 +- source/source_io/write_libxc_r.h | 4 +- source/source_io/write_mlkedf_descriptors.cpp | 2 +- source/source_io/write_vxc.hpp | 2 +- source/source_io/write_vxc_lip.hpp | 2 +- source/source_io/write_vxc_r.hpp | 2 +- source/source_lcao/FORCE_STRESS.cpp | 4 +- source/source_lcao/FORCE_STRESS.h | 4 +- source/source_lcao/LCAO_set.cpp | 6 +- source/source_lcao/LCAO_set.h | 2 +- .../module_lr/esolver_lrtd_lcao.cpp | 6 +- .../source_lcao/module_lr/esolver_lrtd_lcao.h | 4 +- .../module_lr/potentials/pot_hxc_lrtd.cpp | 2 +- .../module_lr/potentials/pot_hxc_lrtd.h | 2 +- .../module_lr/potentials/xc_kernel.cpp | 2 +- .../module_lr/potentials/xc_kernel.h | 2 +- source/source_lcao/module_rdmft/rdmft.h | 4 +- source/source_lcao/module_rdmft/rdmft_tools.h | 6 +- .../module_rdmft/update_state_rdmft.cpp | 2 +- source/source_lcao/rho_tau_lcao.cpp | 4 +- source/source_lcao/rho_tau_lcao.h | 4 +- .../source_pw/module_ofdft/evolve_ofdft.cpp | 4 +- source/source_pw/module_ofdft/evolve_ofdft.h | 4 +- source/source_pw/module_pwdft/forces.cpp | 4 +- source/source_pw/module_pwdft/forces.h | 4 +- source/source_pw/module_pwdft/forces_cc.cpp | 2 +- source/source_pw/module_pwdft/setup_pot.cpp | 10 +- source/source_pw/module_pwdft/setup_pot.h | 2 +- source/source_pw/module_pwdft/stress_func.h | 10 +- .../source_pw/module_pwdft/stress_func_cc.cpp | 2 +- .../module_pwdft/stress_func_gga.cpp | 2 +- .../module_pwdft/stress_func_har.cpp | 2 +- .../module_pwdft/stress_func_loc.cpp | 2 +- .../module_pwdft/stress_func_mgga.cpp | 2 +- source/source_pw/module_stodft/sto_forces.cpp | 2 +- .../source_pw/module_stodft/sto_stress_pw.cpp | 2 +- .../source_pw/module_stodft/sto_stress_pw.h | 2 +- .../module_stodft/test/test_hamilt_sto.cpp | 2 +- 121 files changed, 496 insertions(+), 409 deletions(-) diff --git a/source/source_esolver/esolver_double_xc.h b/source/source_esolver/esolver_double_xc.h index bff9e28bc7..ea43543001 100644 --- a/source/source_esolver/esolver_double_xc.h +++ b/source/source_esolver/esolver_double_xc.h @@ -36,7 +36,7 @@ class ESolver_DoubleXC : public ESolver_KS_LCAO LCAO_domain::Setup_DM dmat_base; //! Electorn charge density - Charge chr_base; + Charge chr_base; }; } // namespace ModuleESolver #endif diff --git a/source/source_esolver/esolver_fp.h b/source/source_esolver/esolver_fp.h index b2bb8f065e..fd61f0fdd8 100644 --- a/source/source_esolver/esolver_fp.h +++ b/source/source_esolver/esolver_fp.h @@ -54,7 +54,7 @@ class ESolver_FP: public ESolver K_Vectors kv; //! Electorn charge density - Charge chr; + Charge chr; //! pw_rho: Plane-wave basis set for charge density //! pw_rhod: same as pw_rho for NCPP. Here 'd' stands for 'dense', diff --git a/source/source_esolver/esolver_of.cpp b/source/source_esolver/esolver_of.cpp index 74474d1b7c..c40eef9a48 100644 --- a/source/source_esolver/esolver_of.cpp +++ b/source/source_esolver/esolver_of.cpp @@ -217,7 +217,7 @@ void ESolver_OF::before_opt(const int istep, UnitCell& ucell) } delete this->ptemp_rho_; - this->ptemp_rho_ = new Charge(); + this->ptemp_rho_ = new Charge(); this->ptemp_rho_->set_rhopw(this->pw_rho); const bool kin_den = this->ptemp_rho_->kin_density(); // mohan add 20251202 this->ptemp_rho_->allocate(PARAM.inp.nspin, kin_den); @@ -250,7 +250,7 @@ void ESolver_OF::before_opt(const int istep, UnitCell& ucell) for (int ibs = 0; ibs < this->pw_rho->nrxx; ++ibs) { // Here we initialize rho to be uniform, - // because the rho got by pot.init_pot -> Charge::atomic_rho may contain minus elements. + // because the rho got by pot.init_pot -> Charge::atomic_rho may contain minus elements. this->chr.rho[is][ibs] = this->nelec_[is] / ucell.omega; this->pphi_[is][ibs] = sqrt(this->chr.rho[is][ibs]); } diff --git a/source/source_esolver/esolver_of.h b/source/source_esolver/esolver_of.h index b94019d5fe..921c383908 100644 --- a/source/source_esolver/esolver_of.h +++ b/source/source_esolver/esolver_of.h @@ -62,7 +62,7 @@ class ESolver_OF : public ESolver_FP int tn_spin_flag_ = -1; // spin flag used in cal_potential, which will be called by opt_tn int max_dcsrch_ = 200; // max no. of line search int flag_ = -1; // flag of TN - Charge* ptemp_rho_ = nullptr; // used in line search + Charge* ptemp_rho_ = nullptr; // used in line search psi::Psi* psi_ = nullptr; // sqrt(rho) // ----------------- used for convergence check ------------------- @@ -90,7 +90,7 @@ class ESolver_OF : public ESolver_FP std::function bound_cal_potential_; void cal_potential_wrapper(double* ptemp_phi, double* rdLdphi); void cal_potential(double* ptemp_phi, double* rdLdphi, UnitCell& ucell); - void cal_dEdtheta(double** ptemp_phi, Charge* temp_rho, UnitCell& ucell, double* ptheta, double* rdEdtheta); + void cal_dEdtheta(double** ptemp_phi, Charge* temp_rho, UnitCell& ucell, double* ptheta, double* rdEdtheta); double cal_mu(double* pphi, double* pdEdphi, double nelec); // --------------------- determine the optimization direction ------- diff --git a/source/source_esolver/esolver_of_tool.cpp b/source/source_esolver/esolver_of_tool.cpp index cd29bc448f..0eccb8301b 100644 --- a/source/source_esolver/esolver_of_tool.cpp +++ b/source/source_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 = new elecstate::ElecState((Charge*)(&chr), this->pw_rho, pw_big); } delete this->pelec->pot; @@ -84,7 +84,7 @@ void ESolver_OF::allocate_array() // initialize chemical potential, step length, ... delete this->ptemp_rho_; - this->ptemp_rho_ = new Charge(); + this->ptemp_rho_ = new Charge(); this->ptemp_rho_->set_rhopw(this->pw_rho); const bool kin_den = this->ptemp_rho_->kin_density(); // mohan add 20251202 this->ptemp_rho_->allocate(PARAM.inp.nspin, kin_den); @@ -173,7 +173,7 @@ void ESolver_OF::cal_potential(double* ptemp_phi, double* rdLdphi, UnitCell& uce * @param [in] ptheta * @param [out] rdEdtheta dE/dTheta */ -void ESolver_OF::cal_dEdtheta(double** ptemp_phi, Charge* temp_rho, UnitCell& ucell, double* ptheta, double* rdEdtheta) +void ESolver_OF::cal_dEdtheta(double** ptemp_phi, Charge* temp_rho, UnitCell& ucell, double* ptheta, double* rdEdtheta) { double* dphi_dtheta = new double[this->pw_rho->nrxx]; diff --git a/source/source_estate/elecstate.cpp b/source/source_estate/elecstate.cpp index 5e2c6a8ced..835a50b293 100644 --- a/source/source_estate/elecstate.cpp +++ b/source/source_estate/elecstate.cpp @@ -45,7 +45,7 @@ void ElecState::init_scf(const UnitCell& ucell, } -void ElecState::init_ks(Charge* chr_in, // pointer for class Charge +void ElecState::init_ks(Charge* chr_in, // pointer for class Charge const K_Vectors* klist_in, int nk_in, const ModulePW::PW_Basis_Big* bigpw_in) diff --git a/source/source_estate/elecstate.h b/source/source_estate/elecstate.h index 888b3b95dc..0a63139ef1 100644 --- a/source/source_estate/elecstate.h +++ b/source/source_estate/elecstate.h @@ -17,7 +17,7 @@ class ElecState ElecState() { } - ElecState(Charge* chr_in, ModulePW::PW_Basis* rhopw_in, ModulePW::PW_Basis_Big* bigpw_in) + ElecState(Charge* chr_in, ModulePW::PW_Basis* rhopw_in, ModulePW::PW_Basis_Big* bigpw_in) { this->charge = chr_in; this->charge->set_rhopw(rhopw_in); @@ -32,7 +32,7 @@ class ElecState this->pot = nullptr; } } - void init_ks(Charge* chr_in, // pointer for class Charge + void init_ks(Charge* chr_in, // pointer for class Charge const K_Vectors* klist_in, int nk_in, // number of k points const ModulePW::PW_Basis_Big* bigpw_in); @@ -112,7 +112,7 @@ class ElecState int iter = 0; ///< scf iteration Potential* pot = nullptr; ///< pointer to potential - Charge* charge = nullptr; ///< pointer to charge density + Charge* charge = nullptr; ///< pointer to charge density const K_Vectors* klist = nullptr; ///< pointer to k points lists const ModulePW::PW_Basis_Big* bigpw = nullptr; ///< bigpw will be removed later diff --git a/source/source_estate/elecstate_lcao.h b/source/source_estate/elecstate_lcao.h index bf1f11e1f7..329e4ac6be 100644 --- a/source/source_estate/elecstate_lcao.h +++ b/source/source_estate/elecstate_lcao.h @@ -15,7 +15,7 @@ class ElecStateLCAO : public ElecState ElecStateLCAO() { } // will be called by ElecStateLCAO_TDDFT - ElecStateLCAO(Charge* chr_in, + ElecStateLCAO(Charge* chr_in, const K_Vectors* klist_in, int nks_in, ModulePW::PW_Basis_Big* bigpw_in) diff --git a/source/source_estate/elecstate_pw.cpp b/source/source_estate/elecstate_pw.cpp index 2d24321f2a..094bea99c0 100644 --- a/source/source_estate/elecstate_pw.cpp +++ b/source/source_estate/elecstate_pw.cpp @@ -13,7 +13,7 @@ namespace elecstate { template ElecStatePW::ElecStatePW(ModulePW::PW_Basis_K* wfc_basis_in, - Charge* chr_in, + Charge* chr_in, K_Vectors* pkv_in, UnitCell* ucell_in, pseudopot_cell_vnl* ppcell_in, diff --git a/source/source_estate/elecstate_pw.h b/source/source_estate/elecstate_pw.h index f674beed89..dc55b8cfd7 100644 --- a/source/source_estate/elecstate_pw.h +++ b/source/source_estate/elecstate_pw.h @@ -20,7 +20,7 @@ class ElecStatePW : public ElecState public: ElecStatePW(ModulePW::PW_Basis_K* wfc_basis_in, - Charge* chr_in, + Charge* chr_in, K_Vectors* pkv_in, UnitCell* ucell_in, pseudopot_cell_vnl* ppcell_in, diff --git a/source/source_estate/elecstate_pw_sdft.h b/source/source_estate/elecstate_pw_sdft.h index 0ffa00efc4..347a1f63af 100644 --- a/source/source_estate/elecstate_pw_sdft.h +++ b/source/source_estate/elecstate_pw_sdft.h @@ -8,7 +8,7 @@ class ElecStatePW_SDFT : public ElecStatePW { public: ElecStatePW_SDFT(ModulePW::PW_Basis_K* wfc_basis_in, - Charge* chr_in, + Charge* chr_in, K_Vectors* pkv_in, UnitCell* ucell_in, pseudopot_cell_vnl* ppcell_in, diff --git a/source/source_estate/module_charge/charge.cpp b/source/source_estate/module_charge/charge.cpp index 7c8008c34d..bbc66141d3 100644 --- a/source/source_estate/module_charge/charge.cpp +++ b/source/source_estate/module_charge/charge.cpp @@ -33,13 +33,15 @@ #include -Charge::Charge() +template +Charge::Charge() { allocate_rho = false; allocate_rho_final_scf = false; // LiuXh add 20180619 } -Charge::~Charge() +template +Charge::~Charge() { this->destroy(); #ifdef __MPI @@ -48,13 +50,15 @@ Charge::~Charge() #endif } -void Charge::set_rhopw(ModulePW::PW_Basis* rhopw_in) +template +void Charge::set_rhopw(ModulePW::PW_Basis* rhopw_in) { this->rhopw = rhopw_in; } // mohan add 2025-12-02 -bool Charge::kin_density() +template +bool Charge::kin_density() { if (XC_Functional::get_ked_flag() || PARAM.inp.out_elf[0] > 0) { @@ -66,7 +70,8 @@ bool Charge::kin_density() } } -void Charge::destroy() +template +void Charge::destroy() { if (allocate_rho || allocate_rho_final_scf) // LiuXh add 20180619 { @@ -90,7 +95,8 @@ void Charge::destroy() } } -void Charge::allocate(const int& nspin_in, const bool kin_den) +template +void Charge::allocate(const int& nspin_in, const bool kin_den) { ModuleBase::TITLE("Charge", "allocate"); @@ -121,23 +127,23 @@ void Charge::allocate(const int& nspin_in, const bool kin_den) } // allocate memory - _space_rho = new double[nspin * nrxx]; - _space_rho_save = new double[nspin * nrxx]; - _space_rhog = new std::complex[nspin * ngmc]; - _space_rhog_save = new std::complex[nspin * ngmc]; + _space_rho = new Tr[nspin * nrxx]; + _space_rho_save = new Tr[nspin * nrxx]; + _space_rhog = new Tg[nspin * ngmc]; + _space_rhog_save = new Tg[nspin * ngmc]; if(kin_den) { - _space_kin_r = new double[nspin * nrxx]; - _space_kin_r_save = new double[nspin * nrxx]; + _space_kin_r = new Tr[nspin * nrxx]; + _space_kin_r_save = new Tr[nspin * nrxx]; } - rho = new double*[nspin]; - rhog = new std::complex*[nspin]; - rho_save = new double*[nspin]; - rhog_save = new std::complex*[nspin]; + rho = new Tr*[nspin]; + rhog = new Tg*[nspin]; + rho_save = new Tr*[nspin]; + rhog_save = new Tg*[nspin]; if(kin_den) { - kin_r = new double*[nspin]; - kin_r_save = new double*[nspin]; + kin_r = new Tr*[nspin]; + kin_r_save = new Tr*[nspin]; } for (int is = 0; is < nspin; is++) { @@ -158,34 +164,35 @@ void Charge::allocate(const int& nspin_in, const bool kin_den) } } - ModuleBase::Memory::record("Chg::rho", sizeof(double) * nspin * nrxx); - ModuleBase::Memory::record("Chg::rho_save", sizeof(double) * nspin * nrxx); - ModuleBase::Memory::record("Chg::rhog", sizeof(double) * nspin * ngmc); - ModuleBase::Memory::record("Chg::rhog_save", sizeof(double) * nspin * ngmc); + ModuleBase::Memory::record("Chg::rho", sizeof(Tr) * nspin * nrxx); + ModuleBase::Memory::record("Chg::rho_save", sizeof(Tr) * nspin * nrxx); + ModuleBase::Memory::record("Chg::rhog", sizeof(Tg) * nspin * ngmc); + ModuleBase::Memory::record("Chg::rhog_save", sizeof(Tg) * nspin * ngmc); if(kin_den) { - ModuleBase::Memory::record("Chg::kin_r", sizeof(double) * nspin * ngmc); - ModuleBase::Memory::record("Chg::kin_r_save", sizeof(double) * nspin * ngmc); + ModuleBase::Memory::record("Chg::kin_r", sizeof(Tr) * nspin * ngmc); + ModuleBase::Memory::record("Chg::kin_r_save", sizeof(Tr) * nspin * ngmc); } - this->rho_core = new double[nrxx]; // core charge in real space + this->rho_core = new Tr[nrxx]; // core charge in real space ModuleBase::GlobalFunc::ZEROS(rho_core, nrxx); - this->rhog_core = new std::complex[ngmc]; // reciprocal core charge + this->rhog_core = new Tg[ngmc]; // reciprocal core charge ModuleBase::GlobalFunc::ZEROS(rhog_core, ngmc); - ModuleBase::Memory::record("Chg::rho_core", sizeof(double) * nrxx); - ModuleBase::Memory::record("Chg::rhog_core", sizeof(double) * ngmc); + ModuleBase::Memory::record("Chg::rho_core", sizeof(Tr) * nrxx); + ModuleBase::Memory::record("Chg::rhog_core", sizeof(Tg) * ngmc); this->allocate_rho = true; return; } -double Charge::sum_rho() const +template +Tr Charge::sum_rho() const { ModuleBase::TITLE("Charge", "sum_rho"); - double sum_rho = 0.0; + Tr sum_rho = 0.0; int nspin0 = (nspin == 2) ? 2 : 1; for (int is = 0; is < nspin0; is++) @@ -197,7 +204,7 @@ double Charge::sum_rho() const } // multiply the sum of charge density by a factor - sum_rho *= *this->omega_ / static_cast(this->rhopw->nxyz); + sum_rho *= *this->omega_ / static_cast(this->rhopw->nxyz); #ifdef __MPI Parallel_Reduce::reduce_pool(sum_rho); @@ -205,7 +212,7 @@ double Charge::sum_rho() const // mohan fixed bug 2010-01-18, // sum_rho may be smaller than 1, like Na bcc. - if (sum_rho <= 0.1) + if (std::abs(sum_rho) <= 0.1) { GlobalV::ofs_warning << " sum_rho=" << sum_rho << std::endl; ModuleBase::WARNING_QUIT("Charge::renormalize_rho", "Can't find even an electron!"); @@ -214,14 +221,15 @@ double Charge::sum_rho() const return sum_rho; } -void Charge::renormalize_rho() +template +void Charge::renormalize_rho() { ModuleBase::TITLE("Charge", "renormalize_rho"); - const double sr = this->sum_rho(); + const Tr sr = this->sum_rho(); GlobalV::ofs_warning << std::setprecision(15); ModuleBase::GlobalFunc::OUT(GlobalV::ofs_warning, "charge before normalized", sr); - const double normalize_factor = PARAM.inp.nelec / sr; + const Tr normalize_factor = PARAM.inp.nelec / sr; for (int is = 0; is < nspin; is++) { @@ -242,9 +250,10 @@ void Charge::renormalize_rho() // rho_at (read from pseudopotential files) // allocate work space (psic must already be allocated) //------------------------------------------------------- -void Charge::atomic_rho(const int spin_number_need, +template +void Charge::atomic_rho(const int spin_number_need, const double& omega, - double** rho_in, + Tr** rho_in, const ModuleBase::ComplexMatrix& strucFac, const UnitCell& ucell) const // Peize Lin refactor 2021.04.08 { @@ -366,15 +375,15 @@ void Charge::atomic_rho(const int spin_number_need, // G=0 term only belong to 1 cpu. // Other processors start from '0' //---------------------------------------------------------- - #ifdef _OPENMP - #pragma omp parallel + #ifdef _OPENMP + #pragma omp parallel { - #endif + #endif std::vector rho1d(ucell.meshx); - #ifdef _OPENMP - #pragma omp for - #endif + #ifdef _OPENMP + #pragma omp for + #endif for (int igg = gstart; igg < this->rhopw->ngg; ++igg) { const double gx = sqrt(this->rhopw->gg_uniq[igg]) * ucell.tpiba; @@ -392,9 +401,9 @@ void Charge::atomic_rho(const int spin_number_need, } ModuleBase::Integral::Simpson_Integral(mesh, rho1d.data(), atom->ncpp.rab.data(), rho_lgl[igg]); } - #ifdef _OPENMP - #pragma omp single - #endif + #ifdef _OPENMP + #pragma omp single + #endif { if (PARAM.inp.test_charge > 0) std::cout << " |G|>0 term done." << std::endl; @@ -403,16 +412,16 @@ void Charge::atomic_rho(const int spin_number_need, // EXPLAIN : Complete the transfer of rho from real space to // reciprocal space //---------------------------------------------------------- - #ifdef _OPENMP - #pragma omp for - #endif + #ifdef _OPENMP + #pragma omp for + #endif for (int igg = 0; igg < this->rhopw->ngg; igg++) { rho_lgl[igg] /= omega; } - #ifdef _OPENMP + #ifdef _OPENMP } - #endif + #endif return rho_lgl; }(); //---------------------------------------------------------- @@ -420,9 +429,9 @@ void Charge::atomic_rho(const int spin_number_need, //---------------------------------------------------------- if (spin_number_need == 1) { - #ifdef _OPENMP - #pragma omp parallel for - #endif + #ifdef _OPENMP + #pragma omp parallel for + #endif for (int ig = 0; ig < this->rhopw->npw; ig++) { rho_g3d(0, ig) += strucFac(it, ig) * rho_lgl[this->rhopw->ig2igg[ig]]; @@ -433,9 +442,9 @@ void Charge::atomic_rho(const int spin_number_need, { if (startmag_type == 1) { - #ifdef _OPENMP - #pragma omp parallel for - #endif + #ifdef _OPENMP + #pragma omp parallel for + #endif for (int ig = 0; ig < this->rhopw->npw; ig++) { const std::complex swap = strucFac(it, ig) * rho_lgl[this->rhopw->ig2igg[ig]]; @@ -456,9 +465,9 @@ void Charge::atomic_rho(const int spin_number_need, const double up = 0.5 * (1 + atom->mag[ia] / atom->ncpp.zv); const double dw = 0.5 * (1 - atom->mag[ia] / atom->ncpp.zv); // std::cout << " atom " << ia << " up=" << up << " dw=" << dw << std::endl; - #ifdef _OPENMP - #pragma omp parallel for - #endif + #ifdef _OPENMP + #pragma omp parallel for + #endif for (int ig = 0; ig < this->rhopw->npw; ig++) { const double Gtau = this->rhopw->gcar[ig][0] * atom->tau[ia].x @@ -485,9 +494,9 @@ void Charge::atomic_rho(const int spin_number_need, ModuleBase::libm::sincos(atom->angle1[0], &sin_a1, &cos_a1); ModuleBase::libm::sincos(atom->angle2[0], &sin_a2, &cos_a2); } - #ifdef _OPENMP - #pragma omp parallel for - #endif + #ifdef _OPENMP + #pragma omp parallel for + #endif for (int ig = 0; ig < this->rhopw->npw; ig++) { const std::complex swap = strucFac(it, ig) * rho_lgl[this->rhopw->ig2igg[ig]]; @@ -523,9 +532,9 @@ void Charge::atomic_rho(const int spin_number_need, { ModuleBase::libm::sincos(atom->angle2[ia], &sin_a2, &cos_a2); } - #ifdef _OPENMP - #pragma omp parallel for - #endif + #ifdef _OPENMP + #pragma omp parallel for + #endif for (int ig = 0; ig < this->rhopw->npw; ig++) { const double Gtau = this->rhopw->gcar[ig][0] * atom->tau[ia].x @@ -566,7 +575,7 @@ void Charge::atomic_rho(const int spin_number_need, }(); assert(spin_number_need > 0); - std::vector ne(spin_number_need); + std::vector ne(spin_number_need); for (int is = 0; is < spin_number_need; is++) { this->rhopw->recip2real(&rho_g3d(is, 0), rho_in[is]); @@ -576,10 +585,10 @@ void Charge::atomic_rho(const int spin_number_need, ne[is] += rho_in[is][ir]; } - ne[is] *= omega / (double)this->rhopw->nxyz; - #ifdef __MPI + ne[is] *= omega / (Tr)this->rhopw->nxyz; + #ifdef __MPI Parallel_Reduce::reduce_pool(ne[is]); - #endif + #endif // we check that everything is correct double neg = 0.0; double rea = 0.0; @@ -593,11 +602,11 @@ void Charge::atomic_rho(const int spin_number_need, ima += std::abs(this->rhopw->fft_bundle.get_auxr_data()[ir].imag()); } - #ifdef __MPI + #ifdef __MPI Parallel_Reduce::reduce_pool(neg); Parallel_Reduce::reduce_pool(ima); Parallel_Reduce::reduce_pool(sumrea); - #endif + #endif // mohan fix bug 2011-04-03 neg = neg / (double)this->rhopw->nxyz * omega; ima = ima / (double)this->rhopw->nxyz * omega; @@ -611,7 +620,7 @@ void Charge::atomic_rho(const int spin_number_need, } // end is - double ne_tot = 0.0; + Tr ne_tot = 0.0; int spin0 = 1; if (spin_number_need == 2) { @@ -639,7 +648,8 @@ void Charge::atomic_rho(const int spin_number_need, return; } -void Charge::save_rho_before_sum_band() +template +void Charge::save_rho_before_sum_band() { for (int is = 0; is < PARAM.inp.nspin; is++) { @@ -652,28 +662,30 @@ void Charge::save_rho_before_sum_band() return; } -double Charge::cal_rho2ne(const double* rho_in) const +template +Tr Charge::cal_rho2ne(const Tr* rho_in) const { assert(this->rhopw->nxyz > 0); // mohan add 2025-12-02 - double ne = 0.0; + Tr ne = 0.0; for (int ir = 0; ir < this->rhopw->nrxx; ir++) { ne += rho_in[ir]; } -#ifdef __MPI + #ifdef __MPI Parallel_Reduce::reduce_pool(ne); -#endif - ne = ne * *this->omega_ / (double)this->rhopw->nxyz; + #endif + ne = ne * *this->omega_ / (Tr)this->rhopw->nxyz; return ne; } -void Charge::check_rho() +template +void Charge::check_rho() { if (this->nspin==1 || this->nspin==4) { - double ne = 0.0; + Tr ne = 0.0; ne = this->cal_rho2ne(rho[0]); if (std::abs(ne - PARAM.inp.nelec) > 1.0e-6) { @@ -683,16 +695,16 @@ void Charge::check_rho() else if (this->nspin == 2) { // for spin up - double ne_up = 0.0; + Tr ne_up = 0.0; ne_up = this->cal_rho2ne(rho[0]); - if (ne_up < 0.0) + if (std::real(ne_up) < 0.0) { ModuleBase::WARNING_QUIT("Charge", "Number of spin-down electrons set in starting magnetization exceeds all available."); } // for spin down - double ne_dn = 0.0; + Tr ne_dn = 0.0; ne_dn = this->cal_rho2ne(rho[1]); - if (ne_dn < 0.0) + if (std::real(ne_dn) < 0.0) { ModuleBase::WARNING_QUIT("Charge", "Number of spin-up electrons set in starting magnetization exceeds all available."); } @@ -705,7 +717,8 @@ void Charge::check_rho() } // LiuXh add 20180619 -void Charge::init_final_scf() +template +void Charge::init_final_scf() { ModuleBase::TITLE("Charge", "init_after_scf"); @@ -716,37 +729,41 @@ void Charge::init_final_scf() } // allocate memory - 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]; + rho = new Tr*[PARAM.inp.nspin]; + rhog = new Tg*[PARAM.inp.nspin]; + rho_save = new Tr*[PARAM.inp.nspin]; + rhog_save = new Tg*[PARAM.inp.nspin]; for (int is = 0; is < PARAM.inp.nspin; is++) { - rho[is] = new double[this->rhopw->nrxx]; - rhog[is] = new std::complex[this->rhopw->npw]; - rho_save[is] = new double[this->rhopw->nrxx]; - rhog_save[is] = new std::complex[this->rhopw->npw]; + rho[is] = new Tr[this->rhopw->nrxx]; + rhog[is] = new Tg[this->rhopw->npw]; + rho_save[is] = new Tr[this->rhopw->nrxx]; + rhog_save[is] = new Tg[this->rhopw->npw]; ModuleBase::GlobalFunc::ZEROS(rho[is], this->rhopw->nrxx); ModuleBase::GlobalFunc::ZEROS(rhog[is], this->rhopw->npw); ModuleBase::GlobalFunc::ZEROS(rho_save[is], this->rhopw->nrxx); ModuleBase::GlobalFunc::ZEROS(rhog_save[is], 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); + ModuleBase::Memory::record("Chg::rho", sizeof(Tr) * PARAM.inp.nspin * this->rhopw->nrxx); + ModuleBase::Memory::record("Chg::rho_save", sizeof(Tr) * PARAM.inp.nspin * this->rhopw->nrxx); + ModuleBase::Memory::record("Chg::rhog", sizeof(Tg) * PARAM.inp.nspin * this->rhopw->npw); + ModuleBase::Memory::record("Chg::rhog_save", sizeof(Tg) * PARAM.inp.nspin * this->rhopw->npw); - this->rho_core = new double[this->rhopw->nrxx]; // core charge in real space + this->rho_core = new Tr[this->rhopw->nrxx]; // core charge in real space ModuleBase::GlobalFunc::ZEROS(rho_core, this->rhopw->nrxx); - this->rhog_core = new std::complex[this->rhopw->npw]; // reciprocal core charge + this->rhog_core = new Tg[this->rhopw->npw]; // reciprocal core charge ModuleBase::GlobalFunc::ZEROS(rhog_core, this->rhopw->npw); - ModuleBase::Memory::record("Chg::rho_core", sizeof(double) * this->rhopw->nrxx); - ModuleBase::Memory::record("Chg::rhog_core", sizeof(double) * this->rhopw->npw); + ModuleBase::Memory::record("Chg::rho_core", sizeof(Tr) * this->rhopw->nrxx); + ModuleBase::Memory::record("Chg::rhog_core", sizeof(Tg) * this->rhopw->npw); this->allocate_rho_final_scf = true; return; } + + +template class Charge; +template class Charge>; \ No newline at end of file diff --git a/source/source_estate/module_charge/charge.h b/source/source_estate/module_charge/charge.h index 79a5f5ca9e..d7daf7c6d1 100644 --- a/source/source_estate/module_charge/charge.h +++ b/source/source_estate/module_charge/charge.h @@ -14,9 +14,10 @@ class UnitCell; // Electron Charge Density +template class Charge { - + using Tg = std::complex; public: Charge(); @@ -34,25 +35,25 @@ class Charge // NAME : rhog_core [ngm], the core charge in reciprocal space //========================================================== - double **rho = nullptr; - double **rho_save = nullptr; + Tr **rho = nullptr; + Tr **rho_save = nullptr; - std::complex **rhog = nullptr; - std::complex **rhog_save = nullptr; + Tg **rhog = nullptr; + Tg **rhog_save = nullptr; - double **kin_r = nullptr; // kinetic energy density in real space, for meta-GGA - double **kin_r_save = nullptr; // kinetic energy density in real space, for meta-GGA + Tr **kin_r = nullptr; // kinetic energy density in real space, for meta-GGA + Tr **kin_r_save = nullptr; // kinetic energy density in real space, for meta-GGA const Parallel_Grid* pgrid = nullptr; private: //temporary - double *_space_rho = nullptr; - double *_space_rho_save = nullptr; - std::complex *_space_rhog = nullptr; - std::complex *_space_rhog_save = nullptr; - double *_space_kin_r = nullptr; - double *_space_kin_r_save = nullptr; + Tr *_space_rho = nullptr; + Tr *_space_rho_save = nullptr; + Tg *_space_rhog = nullptr; + Tg *_space_rhog_save = nullptr; + Tr *_space_kin_r = nullptr; + Tr *_space_kin_r_save = nullptr; public: @@ -60,8 +61,8 @@ class Charge double **nhat_save = nullptr; //compensation charge for PAW // wenfei 2023-09-05 - double *rho_core = nullptr; - std::complex *rhog_core = nullptr; + Tr *rho_core = nullptr; + Tg *rhog_core = nullptr; int prenspin = 1; @@ -91,7 +92,7 @@ class Charge void atomic_rho(const int spin_number_need, const double& omega, - double** rho_in, + Tr** rho_in, const ModuleBase::ComplexMatrix& strucFac, const UnitCell& ucell) const; @@ -101,7 +102,7 @@ class Charge void renormalize_rho(); - double sum_rho() const; + Tr sum_rho() const; void save_rho_before_sum_band(); @@ -118,7 +119,7 @@ class Charge double *rhocg ) const; - double cal_rho2ne(const double *rho_in) const; + Tr cal_rho2ne(const Tr *rho_in) const; void check_rho(); // to check whether the charge density is normal @@ -143,7 +144,7 @@ class Charge * * @param array_rho f(rho): an array [nrxx] */ - void reduce_diff_pools(double* array_rho) const; + void reduce_diff_pools(Tr* array_rho) const; void set_omega(double* omega_in){this->omega_ = omega_in;}; diff --git a/source/source_estate/module_charge/charge_extra.cpp b/source/source_estate/module_charge/charge_extra.cpp index dd7bea8344..d1f893d0e1 100644 --- a/source/source_estate/module_charge/charge_extra.cpp +++ b/source/source_estate/module_charge/charge_extra.cpp @@ -77,7 +77,7 @@ void Charge_Extra::Init_CE(const int& nspin, const int& natom, const int& nrxx, void Charge_Extra::extrapolate_charge( Parallel_Grid* Pgrid, UnitCell& ucell, - Charge* chr, + Charge* chr, Structure_Factor* sf, std::ofstream& ofs_running, std::ofstream& ofs_warning) @@ -85,7 +85,7 @@ void Charge_Extra::extrapolate_charge( ModuleBase::TITLE("Charge_Extra","extrapolate_charge"); ModuleBase::timer::tick("Charge_Extra", "extrapolate_charge"); //------------------------------------------------------- - // Charge density extrapolation: + // Charge density extrapolation: // // * pot_order=0 : copy the old potential (nothing is done); // * pot_order=1 : subtract old atomic charge density and sum the new @@ -279,7 +279,7 @@ void Charge_Extra::update_all_dis(const UnitCell& ucell) return; } -void Charge_Extra::update_delta_rho(const UnitCell& ucell, const Charge* chr, const Structure_Factor* sf) +void Charge_Extra::update_delta_rho(const UnitCell& ucell, const Charge* chr, const Structure_Factor* sf) { if (pot_order == 0) { diff --git a/source/source_estate/module_charge/charge_extra.h b/source/source_estate/module_charge/charge_extra.h index 7de11aa0ad..246f03f604 100644 --- a/source/source_estate/module_charge/charge_extra.h +++ b/source/source_estate/module_charge/charge_extra.h @@ -65,7 +65,7 @@ class Charge_Extra void extrapolate_charge( Parallel_Grid* Pgrid, UnitCell& ucell, - Charge* chr, + Charge* chr, Structure_Factor* sf, std::ofstream& ofs_running, std::ofstream& ofs_warning); @@ -87,7 +87,7 @@ class Charge_Extra * @param chr the charge density * @param sf the structure factor */ - void update_delta_rho(const UnitCell& ucell, const Charge* chr, const Structure_Factor* sf); + void update_delta_rho(const UnitCell& ucell, const Charge* chr, const Structure_Factor* sf); private: int istep = 0; ///< the current step diff --git a/source/source_estate/module_charge/charge_init.cpp b/source/source_estate/module_charge/charge_init.cpp index 95f675eb90..d9db22288b 100644 --- a/source/source_estate/module_charge/charge_init.cpp +++ b/source/source_estate/module_charge/charge_init.cpp @@ -18,7 +18,8 @@ #include "source_io/rhog_io.h" #include "source_io/read_wf2rho_pw.h" -void Charge::init_rho(const UnitCell& ucell, +template +void Charge::init_rho(const UnitCell& ucell, const Parallel_Grid& pgrid, const ModuleBase::ComplexMatrix& strucFac, ModuleSymmetry::Symmetry& symm, @@ -134,8 +135,8 @@ void Charge::init_rho(const UnitCell& ucell, { GlobalV::ofs_running << " try to read kinetic energy density from file" << std::endl; // try to read charge from binary file first, which is the same as QE - std::vector> kin_g_space(nspin * this->ngmc, {0.0, 0.0}); - std::vector*> kin_g; + std::vector kin_g_space(nspin * this->ngmc, {0.0, 0.0}); + std::vector kin_g; for (int is = 0; is < nspin; is++) { kin_g.push_back(kin_g_space.data() + is * this->ngmc); @@ -270,7 +271,8 @@ void Charge::init_rho(const UnitCell& ucell, //========================================================== // computes the core charge on the real space 3D mesh. //========================================================== -void Charge::set_rho_core(const UnitCell& ucell, +template +void Charge::set_rho_core(const UnitCell& ucell, const ModuleBase::ComplexMatrix& structure_factor, const bool* numeric) { @@ -298,7 +300,7 @@ void Charge::set_rho_core(const UnitCell& ucell, ModuleBase::GlobalFunc::ZEROS(rhocg, this->rhopw->ngg ); // three dimension. - std::complex *vg = new std::complex[this->rhopw->npw]; + Tg *vg = new Tg[this->rhopw->npw]; for (int it = 0; it < ucell.ntype;it++) { @@ -372,7 +374,8 @@ void Charge::set_rho_core(const UnitCell& ucell, } // end subroutine set_rhoc -void Charge::non_linear_core_correction +template +void Charge::non_linear_core_correction ( const bool &numeric, const double omega, @@ -452,3 +455,8 @@ void Charge::non_linear_core_correction return; } + + + +template class Charge; +template class Charge>; \ No newline at end of file diff --git a/source/source_estate/module_charge/charge_mixing.h b/source/source_estate/module_charge/charge_mixing.h index 3152dc5e20..1bb922ca56 100644 --- a/source/source_estate/module_charge/charge_mixing.h +++ b/source/source_estate/module_charge/charge_mixing.h @@ -64,9 +64,9 @@ class Charge_Mixing /** * @brief charge mixing - * @param chr pointer of Charge object + * @param chr pointer of Charge object */ - void mix_rho(Charge* chr); + void mix_rho(Charge* chr); /** * @brief density matrix mixing, only for LCAO @@ -79,8 +79,8 @@ class Charge_Mixing * @brief Get the drho between rho and rho_save, similar for get_dkin * */ - double get_drho(Charge* chr, const double nelec); - double get_dkin(Charge* chr, const double nelec); + double get_drho(Charge* chr, const double nelec); + double get_dkin(Charge* chr, const double nelec); /** * @brief reset mixing, actually we only call init_mixing() to reset mixing instead of this function @@ -145,15 +145,15 @@ class Charge_Mixing /** * @brief charge mixing for reciprocal space - * @param chr pointer of Charge object + * @param chr pointer of Charge object */ - void mix_rho_recip(Charge* chr); + void mix_rho_recip(Charge* chr); /** * @brief charge mixing for real space - * @param chr pointer of Charge object + * @param chr pointer of Charge object */ - void mix_rho_real(Charge* chr); + void mix_rho_real(Charge* chr); /** * @brief Kerker screen method for reciprocal space diff --git a/source/source_estate/module_charge/charge_mixing_residual.cpp b/source/source_estate/module_charge/charge_mixing_residual.cpp index bbc7c7b6be..932bbcc1e0 100644 --- a/source/source_estate/module_charge/charge_mixing_residual.cpp +++ b/source/source_estate/module_charge/charge_mixing_residual.cpp @@ -5,7 +5,7 @@ #include "source_pw/module_pwdft/global.h" #include "source_base/parallel_reduce.h" -double Charge_Mixing::get_drho(Charge* chr, const double nelec) +double Charge_Mixing::get_drho(Charge* chr, const double nelec) { ModuleBase::TITLE("Charge_Mixing", "get_drho"); ModuleBase::timer::tick("Charge_Mixing", "get_drho"); @@ -72,7 +72,7 @@ double Charge_Mixing::get_drho(Charge* chr, const double nelec) return drho; } -double Charge_Mixing::get_dkin(Charge* chr, const double nelec) +double Charge_Mixing::get_dkin(Charge* chr, const double nelec) { if (!(XC_Functional::get_ked_flag())) { diff --git a/source/source_estate/module_charge/charge_mixing_rho.cpp b/source/source_estate/module_charge/charge_mixing_rho.cpp index 38cd679f94..9ca86fca58 100644 --- a/source/source_estate/module_charge/charge_mixing_rho.cpp +++ b/source/source_estate/module_charge/charge_mixing_rho.cpp @@ -3,7 +3,7 @@ #include "source_base/timer.h" #include "source_pw/module_pwdft/global.h" -void Charge_Mixing::mix_rho_recip(Charge* chr) +void Charge_Mixing::mix_rho_recip(Charge* chr) { ModuleBase::TITLE("Charge_Mixing", "mix_rho_recip"); ModuleBase::timer::tick("Charge_Mixing", "mix_rho_recip"); @@ -310,7 +310,7 @@ void Charge_Mixing::mix_rho_recip(Charge* chr) return; } -void Charge_Mixing::mix_rho_real(Charge* chr) +void Charge_Mixing::mix_rho_real(Charge* chr) { ModuleBase::TITLE("Charge_Mixing", "mix_rho_real"); ModuleBase::timer::tick("Charge_Mixing", "mix_rho_real"); @@ -519,7 +519,7 @@ void Charge_Mixing::mix_rho_real(Charge* chr) } -void Charge_Mixing::mix_rho(Charge* chr) +void Charge_Mixing::mix_rho(Charge* chr) { ModuleBase::TITLE("Charge_Mixing", "mix_rho"); ModuleBase::timer::tick("Charge_Mixing", "mix_rho"); diff --git a/source/source_estate/module_charge/charge_mpi.cpp b/source/source_estate/module_charge/charge_mpi.cpp index 32fc8bc195..05c595066b 100644 --- a/source/source_estate/module_charge/charge_mpi.cpp +++ b/source/source_estate/module_charge/charge_mpi.cpp @@ -6,7 +6,8 @@ #include "source_hamilt/module_xc/xc_functional.h" #include "source_io/module_parameter/parameter.h" #ifdef __MPI -void Charge::init_chgmpi() +template +void Charge::init_chgmpi() { if (KP_WORLD == MPI_COMM_NULL) { @@ -24,8 +25,12 @@ void Charge::init_chgmpi() } } -void Charge::reduce_diff_pools(double* array_rho) const +template<> +void Charge::reduce_diff_pools(double* array_rho) const { + using Tr=double; + // MPI_DOUBLE should change following Tr in the future code + ModuleBase::TITLE("Charge", "reduce_diff_pools"); ModuleBase::timer::tick("Charge", "reduce_diff_pools"); if (KP_WORLD != MPI_COMM_NULL) @@ -34,9 +39,9 @@ void Charge::reduce_diff_pools(double* array_rho) const } else { - double* array_tmp = new double[this->rhopw->nxyz]; - double* array_tot = new double[this->rhopw->nxyz]; - double* array_tot_aux = new double[this->rhopw->nxyz]; + Tr* array_tmp = new Tr[this->rhopw->nxyz]; + Tr* array_tot = new Tr[this->rhopw->nxyz]; + Tr* array_tot_aux = new Tr[this->rhopw->nxyz]; //================================== // Collect the rho in each pool //================================== @@ -116,7 +121,14 @@ void Charge::reduce_diff_pools(double* array_rho) const ModuleBase::timer::tick("Charge", "reduce_diff_pools"); } -void Charge::rho_mpi() +template<> +void Charge>::reduce_diff_pools(std::complex* array_rho) const +{ + ModuleBase::WARNING_QUIT("Charge::reduce_diff_pools", "std::complex unsupported yet."); +} + +template +void Charge::rho_mpi() { ModuleBase::TITLE("Charge", "rho_mpi"); if (GlobalV::KPAR * PARAM.inp.bndpar <= 1) @@ -137,4 +149,8 @@ void Charge::rho_mpi() ModuleBase::timer::tick("Charge", "rho_mpi"); return; } + + +template class Charge; +template class Charge>; #endif diff --git a/source/source_estate/module_charge/chgmixing.cpp b/source/source_estate/module_charge/chgmixing.cpp index 45e5c5b350..b957f1b799 100644 --- a/source/source_estate/module_charge/chgmixing.cpp +++ b/source/source_estate/module_charge/chgmixing.cpp @@ -6,7 +6,7 @@ void module_charge::chgmixing_ks(const int iter, // scf iteration number UnitCell& ucell, elecstate::ElecState* pelec, - Charge &chr, // charge density + Charge &chr, // charge density Charge_Mixing* p_chgmix, // charge mixing class const int nrxx, // charge density double &drho, // charge density deviation diff --git a/source/source_estate/module_charge/chgmixing.h b/source/source_estate/module_charge/chgmixing.h index 4a04a0880d..c859b31ae1 100644 --- a/source/source_estate/module_charge/chgmixing.h +++ b/source/source_estate/module_charge/chgmixing.h @@ -14,7 +14,7 @@ namespace module_charge void chgmixing_ks(const int iter, // scf iteration number UnitCell& ucell, elecstate::ElecState* pelec, - Charge &chr, // charge density + Charge &chr, // charge density Charge_Mixing* p_chgmix, // charge mixing class const int nrxx, // charge density double &drho, // charge density deviation diff --git a/source/source_estate/module_charge/symmetry_rho.cpp b/source/source_estate/module_charge/symmetry_rho.cpp index dbd8a57af1..bd51aa952e 100644 --- a/source/source_estate/module_charge/symmetry_rho.cpp +++ b/source/source_estate/module_charge/symmetry_rho.cpp @@ -11,7 +11,7 @@ Symmetry_rho::~Symmetry_rho() } void Symmetry_rho::begin(const int& spin_now, - const Charge& chr, + const Charge& chr, const ModulePW::PW_Basis* rho_basis, ModuleSymmetry::Symmetry& symm) const { diff --git a/source/source_estate/module_charge/symmetry_rho.h b/source/source_estate/module_charge/symmetry_rho.h index 638903fd93..0c6a4344d4 100644 --- a/source/source_estate/module_charge/symmetry_rho.h +++ b/source/source_estate/module_charge/symmetry_rho.h @@ -12,7 +12,7 @@ class Symmetry_rho ~Symmetry_rho(); void begin(const int& spin_now, - const Charge& CHR, + const Charge& CHR, const ModulePW::PW_Basis* pw, ModuleSymmetry::Symmetry& symm) const; diff --git a/source/source_estate/module_dm/init_dm.cpp b/source/source_estate/module_dm/init_dm.cpp index c45190e01e..b226e303dd 100644 --- a/source/source_estate/module_dm/init_dm.cpp +++ b/source/source_estate/module_dm/init_dm.cpp @@ -9,7 +9,7 @@ void elecstate::init_dm(UnitCell& ucell, elecstate::ElecState* pelec, LCAO_domain::Setup_DM &dmat, psi::Psi* psi, - Charge &chr, + Charge &chr, const int iter, const int exx_two_level_step) { @@ -44,7 +44,7 @@ template void elecstate::init_dm(UnitCell& ucell, elecstate::ElecState* pelec, LCAO_domain::Setup_DM &dmat, psi::Psi* psi, - Charge &chr, + Charge &chr, const int iter, const int exx_two_level_step); @@ -52,7 +52,7 @@ template void elecstate::init_dm>(UnitCell& ucell, elecstate::ElecState* pelec, LCAO_domain::Setup_DM> &dmat, psi::Psi>* psi, - Charge &chr, + Charge &chr, const int iter, const int exx_two_level_step); diff --git a/source/source_estate/module_dm/init_dm.h b/source/source_estate/module_dm/init_dm.h index 2fd969638d..aeb361b42a 100644 --- a/source/source_estate/module_dm/init_dm.h +++ b/source/source_estate/module_dm/init_dm.h @@ -15,7 +15,7 @@ void init_dm(UnitCell& ucell, ElecState* pelec, LCAO_domain::Setup_DM &dmat, psi::Psi* psi, - Charge &chr, + Charge &chr, const int iter, const int exx_two_level_step); diff --git a/source/source_estate/module_pot/H_Hartree_pw.cpp b/source/source_estate/module_pot/H_Hartree_pw.cpp index a9cecd0b64..583216c36d 100644 --- a/source/source_estate/module_pot/H_Hartree_pw.cpp +++ b/source/source_estate/module_pot/H_Hartree_pw.cpp @@ -103,7 +103,7 @@ PotHartree::PotHartree(const ModulePW::PW_Basis* rho_basis_in) this->fixed_mode = false; } -void PotHartree::cal_v_eff(const Charge*const chg, const UnitCell*const ucell, ModuleBase::matrix& v_eff) +void PotHartree::cal_v_eff(const Charge*const chg, const UnitCell*const ucell, ModuleBase::matrix& v_eff) { v_eff += H_Hartree_pw::v_hartree(*ucell, const_cast(this->rho_basis_), v_eff.nr, chg->rho); return; diff --git a/source/source_estate/module_pot/H_Hartree_pw.h b/source/source_estate/module_pot/H_Hartree_pw.h index 7973966033..1662205a6a 100644 --- a/source/source_estate/module_pot/H_Hartree_pw.h +++ b/source/source_estate/module_pot/H_Hartree_pw.h @@ -59,7 +59,7 @@ class PotHartree : public PotBase public: PotHartree(const ModulePW::PW_Basis* rho_basis_in); - void cal_v_eff(const Charge*const chg, const UnitCell*const ucell, ModuleBase::matrix& v_eff); + void cal_v_eff(const Charge*const chg, const UnitCell*const ucell, ModuleBase::matrix& v_eff); }; } // namespace elecstate diff --git a/source/source_estate/module_pot/efield.h b/source/source_estate/module_pot/efield.h index cd829d3be1..86e6863c2c 100644 --- a/source/source_estate/module_pot/efield.h +++ b/source/source_estate/module_pot/efield.h @@ -90,7 +90,7 @@ class PotEfield : public PotBase } } - void cal_v_eff(const Charge *chg, const UnitCell *ucell, ModuleBase::matrix &v_eff) override + void cal_v_eff(const Charge *chg, const UnitCell *ucell, ModuleBase::matrix &v_eff) override { v_eff += Efield::add_efield(*ucell, const_cast(rho_basis_), diff --git a/source/source_estate/module_pot/pot_base.h b/source/source_estate/module_pot/pot_base.h index be47777af4..7dd30b2c18 100644 --- a/source/source_estate/module_pot/pot_base.h +++ b/source/source_estate/module_pot/pot_base.h @@ -12,8 +12,8 @@ namespace elecstate /** This class is the base class of Potential module 1. Main class Potential is derived from it. 2. components of potentials on real space grids can derived from it and will be registered into Potential. - a. cal_fixed_v() is a virtual function, it can be override to contribute potentials which do not change with Charge object. - b. cal_v_eff() is a virtual function, it can be override to contribute potentials which change with Charge object. + a. cal_fixed_v() is a virtual function, it can be override to contribute potentials which do not change with Charge object. + b. cal_v_eff() is a virtual function, it can be override to contribute potentials which change with Charge object. c. fixed_mode should be set "true" if you want Potential class call cal_fixed_v() d. dynamic_mode should be set "true" if you want Potential class call cal_v_eff() e. rho_basis_ is needed to provide number of real space grids(nrxx) and number of spin(nspin) and FFT(real<->recip) interface @@ -24,7 +24,7 @@ class PotBase PotBase(){} virtual ~PotBase(){} - virtual void cal_v_eff(const Charge*const chg, const UnitCell*const ucell, ModuleBase::matrix& v_eff){} + virtual void cal_v_eff(const Charge*const chg, const UnitCell*const ucell, ModuleBase::matrix& v_eff){} virtual void cal_fixed_v(double* vl_pseudo){} diff --git a/source/source_estate/module_pot/pot_surchem.hpp b/source/source_estate/module_pot/pot_surchem.hpp index dc06e60fd4..f69fa8ea8d 100644 --- a/source/source_estate/module_pot/pot_surchem.hpp +++ b/source/source_estate/module_pot/pot_surchem.hpp @@ -32,7 +32,7 @@ class PotSurChem : public PotBase } // Passing an explicit output matrix makes the lifetime and allocation explicit and avoids hidden allocations. - void cal_v_eff(const Charge*const chg, const UnitCell*const ucell, ModuleBase::matrix& v_eff) override + void cal_v_eff(const Charge*const chg, const UnitCell*const ucell, ModuleBase::matrix& v_eff) override { if (!this->allocated) { diff --git a/source/source_estate/module_pot/pot_xc.cpp b/source/source_estate/module_pot/pot_xc.cpp index 09c4719a5c..bcc45c384f 100644 --- a/source/source_estate/module_pot/pot_xc.cpp +++ b/source/source_estate/module_pot/pot_xc.cpp @@ -10,7 +10,7 @@ namespace elecstate { -void PotXC::cal_v_eff(const Charge*const chg, const UnitCell*const ucell, ModuleBase::matrix& v_eff) +void PotXC::cal_v_eff(const Charge*const chg, const UnitCell*const ucell, ModuleBase::matrix& v_eff) { ModuleBase::TITLE("PotXC", "cal_veff"); ModuleBase::timer::tick("PotXC", "cal_veff"); diff --git a/source/source_estate/module_pot/pot_xc.h b/source/source_estate/module_pot/pot_xc.h index bf1cf837d8..6d5534c307 100644 --- a/source/source_estate/module_pot/pot_xc.h +++ b/source/source_estate/module_pot/pot_xc.h @@ -23,7 +23,7 @@ class PotXC : public PotBase this->fixed_mode = false; } - void cal_v_eff(const Charge*const chg, const UnitCell*const ucell, ModuleBase::matrix& v_eff) override; + void cal_v_eff(const Charge*const chg, const UnitCell*const ucell, ModuleBase::matrix& v_eff) override; ModuleBase::matrix* vofk = nullptr; double* etxc_ = nullptr; diff --git a/source/source_estate/module_pot/potential_new.cpp b/source/source_estate/module_pot/potential_new.cpp index 9026cd6b48..ca56c1bfb3 100644 --- a/source/source_estate/module_pot/potential_new.cpp +++ b/source/source_estate/module_pot/potential_new.cpp @@ -155,7 +155,7 @@ void Potential::allocate() } } -void Potential::update_from_charge(const Charge*const chg, const UnitCell*const ucell) +void Potential::update_from_charge(const Charge*const chg, const UnitCell*const ucell) { ModuleBase::TITLE("Potential", "update_from_charge"); //ModuleBase::timer::tick("Potential", "update_from_charge"); @@ -214,7 +214,7 @@ void Potential::cal_fixed_v(double* vl_pseudo) ModuleBase::timer::tick("Potential", "cal_fixed_v"); } -void Potential::cal_v_eff(const Charge*const chg, const UnitCell*const ucell, ModuleBase::matrix& v_eff) +void Potential::cal_v_eff(const Charge*const chg, const UnitCell*const ucell, ModuleBase::matrix& v_eff) { ModuleBase::TITLE("Potential", "cal_veff"); ModuleBase::timer::tick("Potential", "cal_veff"); @@ -247,7 +247,7 @@ void Potential::cal_v_eff(const Charge*const chg, const UnitCell*const ucell, Mo ModuleBase::timer::tick("Potential", "cal_veff"); } -void Potential::init_pot(const Charge*const chg) +void Potential::init_pot(const Charge*const chg) { ModuleBase::TITLE("Potential", "init_pot"); ModuleBase::timer::tick("Potential", "init_pot"); @@ -261,7 +261,7 @@ void Potential::init_pot(const Charge*const chg) return; } -void Potential::get_vnew(const Charge* chg, ModuleBase::matrix& vnew) +void Potential::get_vnew(const Charge* chg, ModuleBase::matrix& vnew) { ModuleBase::TITLE("Potential", "get_vnew"); vnew.create(this->v_eff.nr, this->v_eff.nc); diff --git a/source/source_estate/module_pot/potential_new.h b/source/source_estate/module_pot/potential_new.h index 4aaadf698b..0de9657cca 100644 --- a/source/source_estate/module_pot/potential_new.h +++ b/source/source_estate/module_pot/potential_new.h @@ -17,9 +17,9 @@ namespace elecstate * 1. Constructors and deconstructor * 2. Func init_pot() * a. need istep for update_for_tddft(); - * b. need Charge for update_from_charge(); + * b. need Charge for update_from_charge(); * c. it will reset fixed_done to false, v_eff_fixed will be calculated; - * d. it should be called after Charge is initialized; + * d. it should be called after Charge is initialized; * e. it can only be called once in one SCF loop * 3. Func pot_register() and components * a. need vector for choose target potentials @@ -67,13 +67,13 @@ class Potential : public PotBase ~Potential(); // initialize potential when SCF begin - void init_pot(const Charge*const chg); + void init_pot(const Charge*const chg); // initialize potential components before SCF void pot_register(const std::vector& components_list); // update potential from current charge - void update_from_charge(const Charge*const chg, const UnitCell*const ucell); + void update_from_charge(const Charge*const chg, const UnitCell*const ucell); // interface for SCF-converged, etxc vtxc for Energy, vnew for force_scc - void get_vnew(const Charge* chg, ModuleBase::matrix& vnew); + void get_vnew(const Charge* chg, ModuleBase::matrix& vnew); PotBase* get_pot_type(const std::string& pot_type); @@ -188,7 +188,7 @@ class Potential : public PotBase } private: - void cal_v_eff(const Charge*const chg, const UnitCell*const ucell, ModuleBase::matrix& v_eff) override; + void cal_v_eff(const Charge*const chg, const UnitCell*const ucell, ModuleBase::matrix& v_eff) override; void cal_fixed_v(double* vl_pseudo) override; // interpolate potential on the smooth mesh if necessary void interpolate_vrs(); diff --git a/source/source_estate/setup_estate_pw.cpp b/source/source_estate/setup_estate_pw.cpp index 5daa7be1b5..988d5c18bb 100644 --- a/source/source_estate/setup_estate_pw.cpp +++ b/source/source_estate/setup_estate_pw.cpp @@ -8,7 +8,7 @@ void elecstate::setup_estate_pw(UnitCell& ucell, // unitcell K_Vectors &kv, // kpoints Structure_Factor &sf, // structure factors elecstate::ElecState* &pelec, // pointer of electrons - Charge &chr, // charge density + Charge &chr, // charge density pseudopot_cell_vl &locpp, // local pseudopotentials pseudopot_cell_vnl &ppcell, // non-local pseudopotentials VSep* &vsep_cell, // U-1/2 method @@ -108,7 +108,7 @@ template void elecstate::setup_estate_pw, base_device::DEVIC K_Vectors &kv, // kpoints Structure_Factor &sf, // structure factors elecstate::ElecState* &pelec, // pointer of electrons - Charge &chr, // charge density + Charge &chr, // charge density pseudopot_cell_vl &locpp, // local pseudopotentials pseudopot_cell_vnl &ppcell, // non-local pseudopotentials VSep* &vsep_cell, // U-1/2 method @@ -124,7 +124,7 @@ template void elecstate::setup_estate_pw, base_device::DEVI K_Vectors &kv, // kpoints Structure_Factor &sf, // structure factors elecstate::ElecState* &pelec, // pointer of electrons - Charge &chr, // charge density + Charge &chr, // charge density pseudopot_cell_vl &locpp, // local pseudopotentials pseudopot_cell_vnl &ppcell, // non-local pseudopotentials VSep* &vsep_cell, // U-1/2 method @@ -150,7 +150,7 @@ template void elecstate::setup_estate_pw, base_device::DEVIC K_Vectors &kv, // kpoints Structure_Factor &sf, // structure factors elecstate::ElecState* &pelec, // pointer of electrons - Charge &chr, // charge density + Charge &chr, // charge density pseudopot_cell_vl &locpp, // local pseudopotentials pseudopot_cell_vnl &ppcell, // non-local pseudopotentials VSep* &vsep_cell, // U-1/2 method @@ -166,7 +166,7 @@ template void elecstate::setup_estate_pw, base_device::DEVI K_Vectors &kv, // kpoints Structure_Factor &sf, // structure factors elecstate::ElecState* &pelec, // pointer of electrons - Charge &chr, // charge density + Charge &chr, // charge density pseudopot_cell_vl &locpp, // local pseudopotentials pseudopot_cell_vnl &ppcell, // non-local pseudopotentials VSep* &vsep_cell, // U-1/2 method diff --git a/source/source_estate/setup_estate_pw.h b/source/source_estate/setup_estate_pw.h index 44864ad588..195cf394f4 100644 --- a/source/source_estate/setup_estate_pw.h +++ b/source/source_estate/setup_estate_pw.h @@ -17,7 +17,7 @@ void setup_estate_pw(UnitCell& ucell, // unitcell K_Vectors &kv, // kpoints Structure_Factor &sf, // structure factors elecstate::ElecState* &pelec, // pointer of electrons - Charge &chr, // charge density + Charge &chr, // charge density pseudopot_cell_vl &locpp, // local pseudopotentials pseudopot_cell_vnl &ppcell, // non-local pseudopotentials VSep* &vsep_cell, // U-1/2 method diff --git a/source/source_estate/test/charge_extra_test.cpp b/source/source_estate/test/charge_extra_test.cpp index c2951c1b5a..a918be9ff4 100644 --- a/source/source_estate/test/charge_extra_test.cpp +++ b/source/source_estate/test/charge_extra_test.cpp @@ -28,8 +28,9 @@ Magnetism::~Magnetism() Parallel_Grid::~Parallel_Grid(){}; -// mock functions for Charge -Charge::Charge() +// mock functions for Charge +template<> +Charge::Charge() { rhopw = new ModulePW::PW_Basis; rhopw->nrxx = 8; @@ -44,13 +45,15 @@ Charge::Charge() rho[0][i] = i + 1; } } -Charge::~Charge() +template<> +Charge::~Charge() { delete[] rho[0]; delete[] rho; delete rhopw; } -void Charge::atomic_rho(const int spin_number_need, +template<> +void Charge::atomic_rho(const int spin_number_need, const double& omega, double** rho_in, const ModuleBase::ComplexMatrix& strucFac, @@ -116,7 +119,7 @@ class ChargeExtraTest : public ::testing::Test UcellTestPrepare utp = UcellTestLib["Si"]; std::unique_ptr ucell; Parallel_Grid* pgrid = nullptr; - Charge charge; + Charge charge; Structure_Factor sf; void SetUp() override { diff --git a/source/source_estate/test/charge_mixing_test.cpp b/source/source_estate/test/charge_mixing_test.cpp index a0e03b9911..ca331de8e9 100644 --- a/source/source_estate/test/charge_mixing_test.cpp +++ b/source/source_estate/test/charge_mixing_test.cpp @@ -21,14 +21,17 @@ Magnetism::~Magnetism() Magnetism::Magnetism() { } -Charge::~Charge() +template<> +Charge::~Charge() { } -Charge::Charge() +template<> +Charge::Charge() { } -void Charge::set_rhopw(ModulePW::PW_Basis* rhopw_in) +template<> +void Charge::set_rhopw(ModulePW::PW_Basis* rhopw_in) { this->rhopw = rhopw_in; } @@ -106,7 +109,7 @@ class ChargeMixingTest : public ::testing::Test } ModulePW::PW_Basis pw_basis; ModulePW::PW_Basis_Sup pw_dbasis; - Charge charge; + Charge charge; }; TEST_F(ChargeMixingTest, SetMixingTest) diff --git a/source/source_estate/test/charge_test.cpp b/source/source_estate/test/charge_test.cpp index 261bcc5e3e..9a41a21543 100644 --- a/source/source_estate/test/charge_test.cpp +++ b/source/source_estate/test/charge_test.cpp @@ -28,7 +28,7 @@ Magnetism::~Magnetism() delete[] this->start_mag; } -// mock functions for Charge +// mock functions for Charge int XC_Functional::func_type = 1; bool XC_Functional::ked_flag = false; namespace elecstate @@ -49,21 +49,21 @@ void Set_GlobalV_Default() /** * - Tested Functions: - * - Constructor: Charge::Charge() and Charge::~Charge() + * - Constructor: Charge::Charge() and Charge::~Charge() * - this is a trivial test - * - Allocate: Charge::set_rhopw(), Charge::allocate(), Charge::destroy() + * - Allocate: Charge::set_rhopw(), Charge::allocate(), Charge::destroy() * - allocate rho, rhog, rho_save, rhog_save, kin_r, kin_r_save * - using rhopw and PARAM.input.nspin - * - SumRho: Charge::sum_rho() + * - SumRho: Charge::sum_rho() * - calculate \sum_{is}^nspin \sum_{ir}^nrxx rho[is][ir] - * - RenormalizeRho: Charge::renormalize_rho() + * - RenormalizeRho: Charge::renormalize_rho() * - renormalize rho so as to ensure the sum of rho equals to total number of electrons - * - CheckNe: Charge::cal_rho2ne() + * - CheckNe: Charge::cal_rho2ne() * - check the total number of electrons summed from rho[is] - * - SaveRhoBeforeSumBand: Charge::save_rho_before_sum_band() + * - SaveRhoBeforeSumBand: Charge::save_rho_before_sum_band() * - meaning as the function name - * - InitFinalScf:: Charge::init_final_scf() - * - similar to Charge::allocate(), but for final scf + * - InitFinalScf:: Charge::init_final_scf() + * - similar to Charge::allocate(), but for final scf */ class ChargeTest : public ::testing::Test @@ -71,14 +71,14 @@ class ChargeTest : public ::testing::Test protected: UcellTestPrepare utp = UcellTestLib["Si"]; std::unique_ptr ucell; - Charge* charge; + Charge* charge; ModulePW::PW_Basis* rhopw; std::string output; void SetUp() override { elecstate::Set_GlobalV_Default(); ucell = utp.SetUcellInfo(); - charge = new Charge; + charge = new Charge; rhopw = new ModulePW::PW_Basis; rhopw->initgrids(ucell->lat0, ucell->latvec, elecstate::tmp_gridecut); rhopw->distribute_r(); @@ -111,7 +111,7 @@ TEST_F(ChargeTest, Allocate) EXPECT_EQ(rhopw->nrxx, 13824); EXPECT_EQ(rhopw->npw, 3143); EXPECT_EQ(rhopw->npwtot, 3143); - // call Charge::allocate() + // call Charge::allocate() PARAM.input.test_charge = 2; XC_Functional::func_type = 3; XC_Functional::ked_flag = true; @@ -120,7 +120,7 @@ TEST_F(ChargeTest, Allocate) const bool kin_den = charge->kin_density(); charge->allocate(PARAM.input.nspin, kin_den); EXPECT_TRUE(charge->allocate_rho); - // test if Charge::allocate() be called twice + // test if Charge::allocate() be called twice EXPECT_NO_THROW(charge->allocate(PARAM.input.nspin, kin_den)); EXPECT_TRUE(charge->allocate_rho); } diff --git a/source/source_estate/test/elecstate_base_test.cpp b/source/source_estate/test/elecstate_base_test.cpp index e0d63df822..572cb566e9 100644 --- a/source/source_estate/test/elecstate_base_test.cpp +++ b/source/source_estate/test/elecstate_base_test.cpp @@ -14,10 +14,10 @@ // Mock functions for testing elecstate.cpp namespace elecstate { -void Potential::init_pot(Charge const*) +void Potential::init_pot(Charge const*) { } -void Potential::cal_v_eff(const Charge* chg, const UnitCell* ucell, ModuleBase::matrix& v_eff) +void Potential::cal_v_eff(const Charge* chg, const UnitCell* ucell, ModuleBase::matrix& v_eff) { } void Potential::cal_fixed_v(double* vl_pseudo) @@ -27,10 +27,10 @@ Potential::~Potential() { } } // namespace elecstate -Charge::Charge() +Charge::Charge() { } -Charge::~Charge() +Charge::~Charge() { } UnitCell::UnitCell() @@ -77,10 +77,10 @@ void ModulePW::PW_Basis::initgrids(double, ModuleBase::Matrix3, int, int, int) void ModulePW::PW_Basis::distribute_r() { } -void Charge::set_rho_core(const UnitCell& ucell, ModuleBase::ComplexMatrix const&, const bool*) +void Charge::set_rho_core(const UnitCell& ucell, ModuleBase::ComplexMatrix const&, const bool*) { } -void Charge::init_rho(const UnitCell&, +void Charge::init_rho(const UnitCell&, const Parallel_Grid&, ModuleBase::ComplexMatrix const&, ModuleSymmetry::Symmetry& symm, @@ -88,13 +88,13 @@ void Charge::init_rho(const UnitCell&, const void*) { } -void Charge::set_rhopw(ModulePW::PW_Basis*) +void Charge::set_rhopw(ModulePW::PW_Basis*) { } -void Charge::renormalize_rho() +void Charge::renormalize_rho() { } -void Charge::check_rho() +void Charge::check_rho() { } @@ -181,7 +181,7 @@ TEST_F(ElecStateTest, InitNelecSpin) TEST_F(ElecStateTest, Constructor) { - Charge* charge = new Charge; + Charge* charge = new Charge; ModulePW::PW_Basis* rhopw = new ModulePW::PW_Basis; ModulePW::PW_Basis_Big* bigpw = new ModulePW::PW_Basis_Big; elecstate::ElecState* elecstate_new = new elecstate::ElecState(charge, rhopw, bigpw); @@ -196,7 +196,7 @@ TEST_F(ElecStateTest, Constructor) TEST_F(ElecStateTest, InitKS) { - Charge* charge = new Charge; + Charge* charge = new Charge; ModulePW::PW_Basis_Big* bigpw = new ModulePW::PW_Basis_Big; K_Vectors* klist = new K_Vectors; int nk = 1; @@ -215,7 +215,7 @@ TEST_F(ElecStateTest, InitKS) TEST_F(ElecStateTest, GetRho) { - Charge* charge = new Charge; + Charge* charge = new Charge; ModulePW::PW_Basis_Big* bigpw = new ModulePW::PW_Basis_Big; K_Vectors* klist = new K_Vectors; int nk = 1; @@ -255,7 +255,7 @@ TEST_F(ElecStateTest, VirtualBaseFuncs) TEST_F(ElecStateTest, InitSCF) { - Charge* charge = new Charge; + Charge* charge = new Charge; elecstate->charge = charge; elecstate->pot = new elecstate::Potential; elecstate::Efermi efermi; diff --git a/source/source_estate/test/elecstate_energy_test.cpp b/source/source_estate/test/elecstate_energy_test.cpp index e6d0203b68..ee393bde73 100644 --- a/source/source_estate/test/elecstate_energy_test.cpp +++ b/source/source_estate/test/elecstate_energy_test.cpp @@ -14,7 +14,7 @@ int XC_Functional::func_type = 1; bool XC_Functional::ked_flag = false; namespace elecstate { -void Potential::get_vnew(Charge const*, ModuleBase::matrix&) +void Potential::get_vnew(Charge const*, ModuleBase::matrix&) { return; } diff --git a/source/source_estate/test/elecstate_magnetism_test.cpp b/source/source_estate/test/elecstate_magnetism_test.cpp index 2d92f80ea0..381a17e7f4 100644 --- a/source/source_estate/test/elecstate_magnetism_test.cpp +++ b/source/source_estate/test/elecstate_magnetism_test.cpp @@ -27,10 +27,10 @@ #define private public #include "source_estate/magnetism.h" #undef private -Charge::Charge() +Charge::Charge() { } -Charge::~Charge() +Charge::~Charge() { } @@ -71,7 +71,7 @@ TEST_F(MagnetismTest, ComputeMagnetizationS2) PARAM.sys.two_fermi = false; PARAM.input.nelec = 10.0; - Charge* chr = new Charge; + Charge* chr = new Charge; chr->nrxx = 100; chr->nxyz = 1000; chr->rho = new double*[PARAM.input.nspin]; @@ -103,7 +103,7 @@ TEST_F(MagnetismTest, ComputeMagnetizationS4) { PARAM.input.nspin = 4; - Charge* chr = new Charge; + Charge* chr = new Charge; chr->rho = new double*[PARAM.input.nspin]; chr->nrxx = 100; chr->nxyz = 1000; diff --git a/source/source_estate/test/elecstate_print_test.cpp b/source/source_estate/test/elecstate_print_test.cpp index 53dcbb0c58..20a4dd7c35 100644 --- a/source/source_estate/test/elecstate_print_test.cpp +++ b/source/source_estate/test/elecstate_print_test.cpp @@ -31,10 +31,10 @@ Magnetism::Magnetism(){} Magnetism::~Magnetism(){} InfoNonlocal::InfoNonlocal(){} InfoNonlocal::~InfoNonlocal(){} -Charge::Charge() +Charge::Charge() { } -Charge::~Charge() +Charge::~Charge() { } SepPot::SepPot(){} @@ -127,7 +127,7 @@ TEST_F(ElecStatePrintTest, PrintEtot) double pw_diag_thr = 0.1; int avg_iter = 2; bool print = true; - elecstate.charge = new Charge; + elecstate.charge = new Charge; elecstate.charge->nrxx = 100; elecstate.charge->nxyz = 1000; PARAM.input.out_freq_elec = 1; @@ -211,7 +211,7 @@ TEST_F(ElecStatePrintTest, PrintEtotColorS2) double pw_diag_thr = 0.1; int avg_iter = 2; bool print = true; - elecstate.charge = new Charge; + elecstate.charge = new Charge; elecstate.charge->nrxx = 100; elecstate.charge->nxyz = 1000; @@ -240,7 +240,7 @@ TEST_F(ElecStatePrintTest, PrintEtotColorS4) double pw_diag_thr = 0.1; int avg_iter = 2; bool print = true; - elecstate.charge = new Charge; + elecstate.charge = new Charge; elecstate.charge->nrxx = 100; elecstate.charge->nxyz = 1000; diff --git a/source/source_estate/test/elecstate_pw_test.cpp b/source/source_estate/test/elecstate_pw_test.cpp index 27b9bea73a..714a2feb13 100644 --- a/source/source_estate/test/elecstate_pw_test.cpp +++ b/source/source_estate/test/elecstate_pw_test.cpp @@ -12,10 +12,10 @@ int XC_Functional::func_type = 1; namespace elecstate { -void Potential::init_pot(Charge const*) +void Potential::init_pot(Charge const*) { } -void Potential::cal_v_eff(const Charge* chg, const UnitCell* ucell, ModuleBase::matrix& v_eff) +void Potential::cal_v_eff(const Charge* chg, const UnitCell* ucell, ModuleBase::matrix& v_eff) { } void Potential::cal_fixed_v(double* vl_pseudo) @@ -25,10 +25,10 @@ Potential::~Potential() { } } // namespace elecstate -Charge::Charge() +Charge::Charge() { } -Charge::~Charge() +Charge::~Charge() { } UnitCell::UnitCell() @@ -127,10 +127,10 @@ Fcoef::~Fcoef() } #include "source_cell/klist.h" -void Charge::set_rho_core(const UnitCell& ucell, ModuleBase::ComplexMatrix const&, const bool*) +void Charge::set_rho_core(const UnitCell& ucell, ModuleBase::ComplexMatrix const&, const bool*) { } -void Charge::init_rho(const UnitCell&, +void Charge::init_rho(const UnitCell&, const Parallel_Grid&, ModuleBase::ComplexMatrix const&, ModuleSymmetry::Symmetry& symm, @@ -138,13 +138,13 @@ void Charge::init_rho(const UnitCell&, const void*) { } -void Charge::set_rhopw(ModulePW::PW_Basis*) +void Charge::set_rhopw(ModulePW::PW_Basis*) { } -void Charge::renormalize_rho() +void Charge::renormalize_rho() { } -void Charge::check_rho() +void Charge::check_rho() { } @@ -190,7 +190,7 @@ class ElecStatePWTest : public ::testing::Test elecstate::ElecStatePW, base_device::DEVICE_CPU>* elecstate_pw_d = nullptr; elecstate::ElecStatePW, base_device::DEVICE_CPU>* elecstate_pw_s = nullptr; ModulePW::PW_Basis_K* wfcpw = nullptr; - Charge* chg = nullptr; + Charge* chg = nullptr; K_Vectors* klist = nullptr; UnitCell* ucell = nullptr; pseudopot_cell_vnl* ppcell = nullptr; @@ -201,7 +201,7 @@ class ElecStatePWTest : public ::testing::Test { Set_GlobalV_Default(); wfcpw = new ModulePW::PW_Basis_K; - chg = new Charge; + chg = new Charge; klist = new K_Vectors; klist->set_nks(5); ucell = new UnitCell; diff --git a/source/source_estate/test/potential_new_test.cpp b/source/source_estate/test/potential_new_test.cpp index f91f473efa..8b96466eb0 100644 --- a/source/source_estate/test/potential_new_test.cpp +++ b/source/source_estate/test/potential_new_test.cpp @@ -36,10 +36,10 @@ InfoNonlocal::~InfoNonlocal() { } #endif -Charge::Charge() +Charge::Charge() { } -Charge::~Charge() +Charge::~Charge() { } surchem::surchem() @@ -315,7 +315,7 @@ TEST_F(PotentialNewTest, CalVeff) { pot->components[i]->dynamic_mode = dynamic[i]; } - Charge* chg = new Charge; + Charge* chg = new Charge; ModuleBase::matrix v_eff; v_eff.create(2, 100); pot->cal_v_eff(chg,this->ucell,v_eff); @@ -347,7 +347,7 @@ TEST_F(PotentialNewTest, UpdateFromCharge) pot->components[i]->fixed_mode = fixed[i]; pot->components[i]->dynamic_mode = dynamic[i]; } - Charge* chg = new Charge; + Charge* chg = new Charge; EXPECT_FALSE(pot->fixed_done); pot->update_from_charge(chg, this->ucell); EXPECT_TRUE(pot->fixed_done); @@ -375,7 +375,7 @@ TEST_F(PotentialNewTest, InitPot) pot->components[i]->fixed_mode = fixed[i]; pot->components[i]->dynamic_mode = dynamic[i]; } - Charge* chg = new Charge; + Charge* chg = new Charge; EXPECT_FALSE(pot->fixed_done); pot->init_pot(chg); EXPECT_TRUE(pot->fixed_done); @@ -403,7 +403,7 @@ TEST_F(PotentialNewTest, GetVnew) pot->components[i]->fixed_mode = fixed[i]; pot->components[i]->dynamic_mode = dynamic[i]; } - Charge* chg = new Charge; + Charge* chg = new Charge; ModuleBase::matrix vnew; pot->get_vnew(chg, vnew); EXPECT_EQ(vnew.nr, PARAM.input.nspin); diff --git a/source/source_estate/test_mpi/charge_mpi_test.cpp b/source/source_estate/test_mpi/charge_mpi_test.cpp index 0ddf834690..848b3e12ec 100644 --- a/source/source_estate/test_mpi/charge_mpi_test.cpp +++ b/source/source_estate/test_mpi/charge_mpi_test.cpp @@ -8,10 +8,10 @@ #include "source_io/module_parameter/parameter.h" bool XC_Functional::ked_flag = false; -Charge::Charge() +Charge::Charge() { } -Charge::~Charge() +Charge::~Charge() { delete[] rec; delete[] dis; @@ -40,13 +40,13 @@ auto sum_array = [](const double* v, const int& nv) { class ChargeMpiTest : public ::testing::Test { protected: - Charge* charge; + Charge* charge; std::string output; double lat0 = 4; ModuleBase::Matrix3 latvec; void SetUp() override { - charge = new Charge; + charge = new Charge; } void TearDown() override { diff --git a/source/source_estate/update_pot.cpp b/source/source_estate/update_pot.cpp index f0f0ef861a..56cdf8c14e 100644 --- a/source/source_estate/update_pot.cpp +++ b/source/source_estate/update_pot.cpp @@ -3,7 +3,7 @@ void elecstate::update_pot(UnitCell& ucell, // unitcell elecstate::ElecState* &pelec, // pointer of electrons - const Charge &chr, + const Charge &chr, const bool conv_esolver ) // charge density { diff --git a/source/source_estate/update_pot.h b/source/source_estate/update_pot.h index cce4c42428..671c3af1ee 100644 --- a/source/source_estate/update_pot.h +++ b/source/source_estate/update_pot.h @@ -9,7 +9,7 @@ namespace elecstate void update_pot(UnitCell& ucell, // unitcell elecstate::ElecState* &pelec, // pointer of electrons - const Charge &chr, + const Charge &chr, const bool conv_esolver); // charge density } diff --git a/source/source_hamilt/module_xc/test/test_xc3.cpp b/source/source_hamilt/module_xc/test/test_xc3.cpp index 96a67e785c..fb9ba64e77 100644 --- a/source/source_hamilt/module_xc/test/test_xc3.cpp +++ b/source/source_hamilt/module_xc/test/test_xc3.cpp @@ -39,7 +39,7 @@ class XCTest_GRADCORR : public XCTest { ModulePW::PW_Basis rhopw; UnitCell ucell; - Charge chr; + Charge chr; rhopw.nrxx = 5; rhopw.npw = 5; diff --git a/source/source_hamilt/module_xc/test/test_xc5.cpp b/source/source_hamilt/module_xc/test/test_xc5.cpp index 171e1c263c..eb31ef4495 100644 --- a/source/source_hamilt/module_xc/test/test_xc5.cpp +++ b/source/source_hamilt/module_xc/test/test_xc5.cpp @@ -34,7 +34,7 @@ class XCTest_VXC : public XCTest { ModulePW::PW_Basis rhopw; UnitCell ucell; - Charge chr; + Charge chr; rhopw.nrxx = 5; rhopw.npw = 5; @@ -132,7 +132,7 @@ class XCTest_VXC_Libxc : public XCTest { ModulePW::PW_Basis rhopw; UnitCell ucell; - Charge chr; + Charge chr; rhopw.nrxx = 5; rhopw.npw = 5; @@ -230,7 +230,7 @@ class XCTest_VXC_meta : public XCTest { ModulePW::PW_Basis rhopw; UnitCell ucell; - Charge chr; + Charge chr; rhopw.nrxx = 5; rhopw.npw = 5; diff --git a/source/source_hamilt/module_xc/test/xc3_mock.h b/source/source_hamilt/module_xc/test/xc3_mock.h index 131067c3e9..84486f320d 100644 --- a/source/source_hamilt/module_xc/test/xc3_mock.h +++ b/source/source_hamilt/module_xc/test/xc3_mock.h @@ -181,8 +181,8 @@ namespace GlobalC UnitCell::UnitCell(){}; UnitCell::~UnitCell(){}; -Charge::Charge(){}; -Charge::~Charge(){}; +Charge::Charge(){}; +Charge::~Charge(){}; Magnetism::Magnetism(){}; Magnetism::~Magnetism(){}; diff --git a/source/source_hamilt/module_xc/xc_functional.h b/source/source_hamilt/module_xc/xc_functional.h index 067ceef7cf..4674efd336 100644 --- a/source/source_hamilt/module_xc/xc_functional.h +++ b/source/source_hamilt/module_xc/xc_functional.h @@ -48,7 +48,7 @@ class XC_Functional // [etxc, vtxc, v] = v_xc(...) static std::tuple v_xc( const int &nrxx, // number of real-space grid - const Charge* const chr, + const Charge* const chr, const UnitCell *ucell); // charge density //------------------- @@ -177,7 +177,7 @@ class XC_Functional static void gradcorr(double& etxc, double& vtxc, ModuleBase::matrix& v, - const Charge* const chr, + const Charge* const chr, ModulePW::PW_Basis* rhopw, const UnitCell* ucell, std::vector& stress_gga, diff --git a/source/source_hamilt/module_xc/xc_functional_gradcorr.cpp b/source/source_hamilt/module_xc/xc_functional_gradcorr.cpp index 66b0a4a0d6..af5cf45295 100644 --- a/source/source_hamilt/module_xc/xc_functional_gradcorr.cpp +++ b/source/source_hamilt/module_xc/xc_functional_gradcorr.cpp @@ -23,7 +23,7 @@ // from gradcorr.f90 void XC_Functional::gradcorr(double &etxc, double &vtxc, ModuleBase::matrix &v, - const Charge* const chr, ModulePW::PW_Basis* rhopw, const UnitCell *ucell, + const Charge* const chr, ModulePW::PW_Basis* rhopw, const UnitCell *ucell, std::vector &stress_gga, const bool is_stress) { ModuleBase::TITLE("XC_Functional","gradcorr"); diff --git a/source/source_hamilt/module_xc/xc_functional_libxc.h b/source/source_hamilt/module_xc/xc_functional_libxc.h index defd851faa..582b7a1563 100644 --- a/source/source_hamilt/module_xc/xc_functional_libxc.h +++ b/source/source_hamilt/module_xc/xc_functional_libxc.h @@ -15,7 +15,7 @@ #include // added by jghan, 2024-10-10 #include -class Charge; + template class Charge; namespace XC_Functional_Libxc { @@ -58,7 +58,7 @@ namespace XC_Functional_Libxc const int &nrxx, // number of real-space grid const double &omega, // volume of cell const double tpiba, - const Charge* const chr, // charge density + const Charge* const chr, // charge density const std::map* scaling_factor = nullptr); // added by jghan, 2024-10-10 // for mGGA functional @@ -67,7 +67,7 @@ namespace XC_Functional_Libxc const int &nrxx, // number of real-space grid const double &omega, // volume of cell const double tpiba, - const Charge* const chr); + const Charge* const chr); //------------------- @@ -78,13 +78,13 @@ namespace XC_Functional_Libxc extern std::vector convert_rho( const int nspin, const std::size_t nrxx, - const Charge* const chr); + const Charge* const chr); // converting rho (abacus=>libxc) extern std::tuple, std::vector> convert_rho_amag_nspin4( const int nspin, const std::size_t nrxx, - const Charge* const chr); + const Charge* const chr); // calculating grho extern std::vector>> cal_gdr( @@ -92,7 +92,7 @@ namespace XC_Functional_Libxc const std::size_t nrxx, const std::vector &rho, const double tpiba, - const Charge* const chr); + const Charge* const chr); // converting grho (abacus=>libxc) extern std::vector convert_sigma( @@ -127,7 +127,7 @@ namespace XC_Functional_Libxc const std::vector &vrho, const std::vector &vsigma, const double tpiba, - const Charge* const chr); + const Charge* const chr); // dh for gga v extern std::vector> cal_dh( @@ -137,12 +137,12 @@ namespace XC_Functional_Libxc const std::vector>> &gdr, const std::vector &vsigma, const double tpiba, - const Charge* const chr); + const Charge* const chr); // convert v for NSPIN=4 extern ModuleBase::matrix convert_v_nspin4( const std::size_t nrxx, - const Charge* const chr, + const Charge* const chr, const std::vector &amag, const ModuleBase::matrix &v); diff --git a/source/source_hamilt/module_xc/xc_functional_libxc_tools.cpp b/source/source_hamilt/module_xc/xc_functional_libxc_tools.cpp index 4d4af83a7e..664b099394 100644 --- a/source/source_hamilt/module_xc/xc_functional_libxc_tools.cpp +++ b/source/source_hamilt/module_xc/xc_functional_libxc_tools.cpp @@ -9,7 +9,7 @@ std::vector XC_Functional_Libxc::convert_rho( const int nspin, const std::size_t nrxx, - const Charge* const chr) + const Charge* const chr) { std::vector rho(nrxx*nspin); #ifdef _OPENMP @@ -30,7 +30,7 @@ std::tuple, std::vector> XC_Functional_Libxc::convert_rho_amag_nspin4( const int nspin, const std::size_t nrxx, - const Charge* const chr) + const Charge* const chr) { assert(PARAM.inp.nspin==4); std::vector rho(nrxx*nspin); @@ -58,7 +58,7 @@ XC_Functional_Libxc::cal_gdr( const std::size_t nrxx, const std::vector &rho, const double tpiba, - const Charge* const chr) + const Charge* const chr) { std::vector>> gdr(nspin); for( int is=0; is!=nspin; ++is ) @@ -191,7 +191,7 @@ std::pair XC_Functional_Libxc::convert_vtxc_v( const std::vector &vrho, const std::vector &vsigma, const double tpiba, - const Charge* const chr) + const Charge* const chr) { // assert(nrxx>0); // will cause error double vtxc = 0.0; @@ -243,7 +243,7 @@ std::vector> XC_Functional_Libxc::cal_dh( const std::vector>> &gdr, const std::vector &vsigma, const double tpiba, - const Charge* const chr) + const Charge* const chr) { //assert(nrxx>0); // this line will cause bug std::vector>> h( @@ -288,7 +288,7 @@ std::vector> XC_Functional_Libxc::cal_dh( // convert v for NSPIN=4 ModuleBase::matrix XC_Functional_Libxc::convert_v_nspin4( const std::size_t nrxx, - const Charge* const chr, + const Charge* const chr, const std::vector &amag, const ModuleBase::matrix &v) { diff --git a/source/source_hamilt/module_xc/xc_functional_libxc_vxc.cpp b/source/source_hamilt/module_xc/xc_functional_libxc_vxc.cpp index b4ffb7fcba..d8303ac06c 100644 --- a/source/source_hamilt/module_xc/xc_functional_libxc_vxc.cpp +++ b/source/source_hamilt/module_xc/xc_functional_libxc_vxc.cpp @@ -18,7 +18,7 @@ std::tuple XC_Functional_Libxc::v_xc_libxc( / const int &nrxx, // number of real-space grid const double &omega, // volume of cell const double tpiba, - const Charge* const chr, + const Charge* const chr, const std::map* scaling_factor) { ModuleBase::TITLE("XC_Functional_Libxc","v_xc_libxc"); @@ -173,7 +173,7 @@ std::tuple XC_Functional_Li const int &nrxx, // number of real-space grid const double &omega, // volume of cell const double tpiba, - const Charge* const chr) + const Charge* const chr) { ModuleBase::TITLE("XC_Functional_Libxc","v_xc_meta"); ModuleBase::timer::tick("XC_Functional_Libxc","v_xc_meta"); diff --git a/source/source_hamilt/module_xc/xc_functional_vxc.cpp b/source/source_hamilt/module_xc/xc_functional_vxc.cpp index 0ac1990059..af125fa4ce 100644 --- a/source/source_hamilt/module_xc/xc_functional_vxc.cpp +++ b/source/source_hamilt/module_xc/xc_functional_vxc.cpp @@ -15,7 +15,7 @@ // [etxc, vtxc, v] = XC_Functional::v_xc(...) std::tuple XC_Functional::v_xc(const int& nrxx, // number of real-space grid - const Charge* const chr, + const Charge* const chr, const UnitCell* ucell) // core charge density { ModuleBase::TITLE("XC_Functional", "v_xc"); diff --git a/source/source_hsolver/hsolver_lcao.cpp b/source/source_hsolver/hsolver_lcao.cpp index 413c86777a..df43e1bc51 100644 --- a/source/source_hsolver/hsolver_lcao.cpp +++ b/source/source_hsolver/hsolver_lcao.cpp @@ -44,7 +44,7 @@ void HSolverLCAO::solve(hamilt::Hamilt* pHamilt, psi::Psi& psi, elecstate::ElecState* pes, elecstate::DensityMatrix& dm, // mohan add 2025-11-03 - Charge &chr, + Charge &chr, const int nspin, const bool skip_charge) { diff --git a/source/source_hsolver/hsolver_lcao.h b/source/source_hsolver/hsolver_lcao.h index eebab34208..4799d9623f 100644 --- a/source/source_hsolver/hsolver_lcao.h +++ b/source/source_hsolver/hsolver_lcao.h @@ -21,7 +21,7 @@ class HSolverLCAO psi::Psi& psi, elecstate::ElecState* pes, elecstate::DensityMatrix& dm, // mohan add 2025-11-03 - Charge &chr, // charge density + Charge &chr, // charge density const int nspin, const bool skip_charge); diff --git a/source/source_hsolver/test/hsolver_supplementary_mock.h b/source/source_hsolver/test/hsolver_supplementary_mock.h index 87155ecd5a..a56dc04c85 100644 --- a/source/source_hsolver/test/hsolver_supplementary_mock.h +++ b/source/source_hsolver/test/hsolver_supplementary_mock.h @@ -29,7 +29,7 @@ void ElecState::init_scf(const UnitCell& ucell, return; } -void ElecState::init_ks(Charge* chg_in, // pointer for class Charge +void ElecState::init_ks(Charge* chg_in, // pointer for class Charge const K_Vectors* klist_in, int nk_in, const ModulePW::PW_Basis_Big* bigpw_in) @@ -39,7 +39,7 @@ void ElecState::init_ks(Charge* chg_in, // pointer for class Charge template ElecStatePW::ElecStatePW(ModulePW::PW_Basis_K* wfc_basis_in, - Charge* chg_in, + Charge* chg_in, K_Vectors* pkv_in, UnitCell* ucell_in, pseudopot_cell_vnl* ppcell_in, @@ -80,7 +80,7 @@ Potential::~Potential() { } -void Potential::cal_v_eff(const Charge* const chg, const UnitCell* const ucell, ModuleBase::matrix& v_eff) +void Potential::cal_v_eff(const Charge* const chg, const UnitCell* const ucell, ModuleBase::matrix& v_eff) { } diff --git a/source/source_hsolver/test/test_hsolver_sdft.cpp b/source/source_hsolver/test/test_hsolver_sdft.cpp index 7ab1464195..9d1f70e7e4 100644 --- a/source/source_hsolver/test/test_hsolver_sdft.cpp +++ b/source/source_hsolver/test/test_hsolver_sdft.cpp @@ -183,8 +183,8 @@ void Stochastic_Iter::cal_storho(const UnitCell& ucell, } template class Stochastic_Iter, base_device::DEVICE_CPU>; -Charge::Charge(){}; -Charge::~Charge(){}; +Charge::Charge(){}; +Charge::~Charge(){}; // Mock implementations for the template functions causing linking errors namespace ModulePW { @@ -353,7 +353,7 @@ class TestHSolverPW_SDFT : public ::testing::Test // PARAM.input.nelec = 1.0; // GlobalV::MY_BNDGROUP = 0.0; // PARAM.input.nspin = 1; -// elecstate_test.charge = new Charge; +// elecstate_test.charge = new Charge; // elecstate_test.charge->rho = new double*[1]; // elecstate_test.charge->rho[0] = new double[10]; // elecstate_test.charge->nrxx = 10; diff --git a/source/source_io/cal_ldos.cpp b/source/source_io/cal_ldos.cpp index 009337c254..bc0e4047ad 100644 --- a/source/source_io/cal_ldos.cpp +++ b/source/source_io/cal_ldos.cpp @@ -14,7 +14,7 @@ namespace ModuleIO template void Cal_ldos::cal_ldos_lcao( const elecstate::Efermi &eferm, // mohan add 2025-11-02 - const Charge &chr, // mohan add add 2025-11-02 + const Charge &chr, // mohan add add 2025-11-02 const LCAO_domain::Setup_DM &dmat, // mohan add 2025-11-02 const K_Vectors &kv, // k points, mohan add 2025-11-02 const ModuleBase::matrix &ekb, // mohan add 2025-11-02 diff --git a/source/source_io/cal_ldos.h b/source/source_io/cal_ldos.h index 8a16046b76..ee6892dde5 100644 --- a/source/source_io/cal_ldos.h +++ b/source/source_io/cal_ldos.h @@ -21,7 +21,7 @@ class Cal_ldos static void cal_ldos_lcao( const elecstate::Efermi &eferm, // mohan add 2025-11-02 - const Charge &chr, // mohan add add 2025-11-02 + const Charge &chr, // mohan add add 2025-11-02 const LCAO_domain::Setup_DM &dmat, // mohan add 2025-11-02 const K_Vectors &kv, // k points, mohan add 2025-11-02 const ModuleBase::matrix &ekb, // mohan add 2025-11-02 diff --git a/source/source_io/ctrl_iter_lcao.cpp b/source/source_io/ctrl_iter_lcao.cpp index c772d162e6..b6557c09b7 100644 --- a/source/source_io/ctrl_iter_lcao.cpp +++ b/source/source_io/ctrl_iter_lcao.cpp @@ -18,7 +18,7 @@ void ctrl_iter_lcao(UnitCell& ucell, // unit cell * Parallel_Orbitals& pv, // parallel orbital info * Grid_Driver& gd, // adjacent atom info * psi::Psi* psi, // wave functions * - Charge &chr, // charge density * + Charge &chr, // charge density * Charge_Mixing* p_chgmix, // charge mixing * hamilt::HamiltLCAO* p_hamilt, // hamiltonian * LCAO_Orbitals &orb, // orbital info * @@ -87,7 +87,7 @@ template void ctrl_iter_lcao(UnitCell& ucell, // unit cell * Parallel_Orbitals& pv, // parallel orbital info * Grid_Driver& gd, // adjacent atom info * psi::Psi* psi, // wave functions * - Charge &chr, // charge density * + Charge &chr, // charge density * Charge_Mixing* p_chgmix, // charge mixing * hamilt::HamiltLCAO* p_hamilt, // hamiltonian * LCAO_Orbitals &orb, // orbital info * @@ -107,7 +107,7 @@ template void ctrl_iter_lcao, double>(UnitCell& ucell, // u Parallel_Orbitals& pv, // parallel orbital info * Grid_Driver& gd, // adjacent atom info * psi::Psi>* psi, // wave functions * - Charge &chr, // charge density * + Charge &chr, // charge density * Charge_Mixing* p_chgmix, // charge mixing * hamilt::HamiltLCAO, double>* p_hamilt, // hamiltonian * LCAO_Orbitals &orb, // orbital info * @@ -127,7 +127,7 @@ template void ctrl_iter_lcao, std::complex>(UnitCel Parallel_Orbitals& pv, // parallel orbital info * Grid_Driver& gd, // adjacent atom info * psi::Psi>* psi, // wave functions * - Charge &chr, // charge density * + Charge &chr, // charge density * Charge_Mixing* p_chgmix, // charge mixing * hamilt::HamiltLCAO, std::complex>* p_hamilt, // hamiltonian * LCAO_Orbitals &orb, // orbital info * diff --git a/source/source_io/ctrl_iter_lcao.h b/source/source_io/ctrl_iter_lcao.h index 6297d4f1d0..a41f2cb263 100644 --- a/source/source_io/ctrl_iter_lcao.h +++ b/source/source_io/ctrl_iter_lcao.h @@ -23,7 +23,7 @@ void ctrl_iter_lcao(UnitCell& ucell, // unit cell * Parallel_Orbitals& pv, // parallel orbital info * Grid_Driver& gd, // adjacent atom info * psi::Psi* psi, // wave functions * - Charge &chr, // charge density * + Charge &chr, // charge density * Charge_Mixing* p_chgmix, // charge mixing * hamilt::HamiltLCAO* p_hamilt, // hamiltonian * LCAO_Orbitals &orb, // orbital info * diff --git a/source/source_io/ctrl_output_fp.cpp b/source/source_io/ctrl_output_fp.cpp index e385ddefc9..73258c2bba 100644 --- a/source/source_io/ctrl_output_fp.cpp +++ b/source/source_io/ctrl_output_fp.cpp @@ -17,7 +17,7 @@ void ctrl_output_fp(UnitCell& ucell, elecstate::ElecState* pelec, ModulePW::PW_Basis_Big* pw_big, ModulePW::PW_Basis* pw_rhod, - Charge& chr, + Charge& chr, surchem& solvent, Parallel_Grid& para_grid, const int istep) diff --git a/source/source_io/ctrl_output_fp.h b/source/source_io/ctrl_output_fp.h index ec9f4e20e7..8abc5d3457 100644 --- a/source/source_io/ctrl_output_fp.h +++ b/source/source_io/ctrl_output_fp.h @@ -10,7 +10,7 @@ void ctrl_output_fp(UnitCell& ucell, elecstate::ElecState* pelec, ModulePW::PW_Basis_Big* pw_big, ModulePW::PW_Basis* pw_rhod, - Charge& chr, + Charge& chr, surchem& solvent, Parallel_Grid& para_grid, const int istep); diff --git a/source/source_io/ctrl_output_pw.cpp b/source/source_io/ctrl_output_pw.cpp index decd1f680a..ad80cdade0 100644 --- a/source/source_io/ctrl_output_pw.cpp +++ b/source/source_io/ctrl_output_pw.cpp @@ -84,7 +84,7 @@ template void ModuleIO::ctrl_scf_pw(const int istep, UnitCell& ucell, elecstate::ElecState* pelec, - const Charge &chr, + const Charge &chr, const K_Vectors &kv, const ModulePW::PW_Basis_K *pw_wfc, const ModulePW::PW_Basis *pw_rho, @@ -250,7 +250,7 @@ void ModuleIO::ctrl_runner_pw(UnitCell& ucell, ModulePW::PW_Basis_K* pw_wfc, ModulePW::PW_Basis* pw_rho, ModulePW::PW_Basis* pw_rhod, - Charge &chr, + Charge &chr, K_Vectors &kv, Setup_Psi_pw &stp, Structure_Factor &sf, @@ -378,7 +378,7 @@ template void ModuleIO::ctrl_scf_pw, base_device::DEVICE_CPU const int nstep, UnitCell& ucell, elecstate::ElecState* pelec, - const Charge &chr, + const Charge &chr, const K_Vectors &kv, const ModulePW::PW_Basis_K *pw_wfc, const ModulePW::PW_Basis *pw_rho, @@ -395,7 +395,7 @@ template void ModuleIO::ctrl_scf_pw, base_device::DEVICE_CP const int nstep, UnitCell& ucell, elecstate::ElecState* pelec, - const Charge &chr, + const Charge &chr, const K_Vectors &kv, const ModulePW::PW_Basis_K *pw_wfc, const ModulePW::PW_Basis *pw_rho, @@ -413,7 +413,7 @@ template void ModuleIO::ctrl_scf_pw, base_device::DEVICE_GPU const int nstep, UnitCell& ucell, elecstate::ElecState* pelec, - const Charge &chr, + const Charge &chr, const K_Vectors &kv, const ModulePW::PW_Basis_K *pw_wfc, const ModulePW::PW_Basis *pw_rho, @@ -430,7 +430,7 @@ template void ModuleIO::ctrl_scf_pw, base_device::DEVICE_GP const int nstep, UnitCell& ucell, elecstate::ElecState* pelec, - const Charge &chr, + const Charge &chr, const K_Vectors &kv, const ModulePW::PW_Basis_K *pw_wfc, const ModulePW::PW_Basis *pw_rho, @@ -450,7 +450,7 @@ template void ModuleIO::ctrl_runner_pw, base_device::DEVICE_ ModulePW::PW_Basis_K* pw_wfc, ModulePW::PW_Basis* pw_rho, ModulePW::PW_Basis* pw_rhod, - Charge &chr, + Charge &chr, K_Vectors &kv, Setup_Psi_pw, base_device::DEVICE_CPU> &stp, Structure_Factor &sf, @@ -467,7 +467,7 @@ template void ModuleIO::ctrl_runner_pw, base_device::DEVICE ModulePW::PW_Basis_K* pw_wfc, ModulePW::PW_Basis* pw_rho, ModulePW::PW_Basis* pw_rhod, - Charge &chr, + Charge &chr, K_Vectors &kv, Setup_Psi_pw, base_device::DEVICE_CPU> &stp, Structure_Factor &sf, @@ -485,7 +485,7 @@ template void ModuleIO::ctrl_runner_pw, base_device::DEVICE_ ModulePW::PW_Basis_K* pw_wfc, ModulePW::PW_Basis* pw_rho, ModulePW::PW_Basis* pw_rhod, - Charge &chr, + Charge &chr, K_Vectors &kv, Setup_Psi_pw, base_device::DEVICE_GPU> &stp, Structure_Factor &sf, @@ -502,7 +502,7 @@ template void ModuleIO::ctrl_runner_pw, base_device::DEVICE ModulePW::PW_Basis_K* pw_wfc, ModulePW::PW_Basis* pw_rho, ModulePW::PW_Basis* pw_rhod, - Charge &chr, + Charge &chr, K_Vectors &kv, Setup_Psi_pw, base_device::DEVICE_GPU> &stp, Structure_Factor &sf, diff --git a/source/source_io/ctrl_output_pw.h b/source/source_io/ctrl_output_pw.h index 798629c55e..4af9bd036d 100644 --- a/source/source_io/ctrl_output_pw.h +++ b/source/source_io/ctrl_output_pw.h @@ -23,7 +23,7 @@ template void ctrl_scf_pw(const int istep, UnitCell& ucell, elecstate::ElecState* pelec, - const Charge &chr, + const Charge &chr, const K_Vectors &kv, const ModulePW::PW_Basis_K *pw_wfc, const ModulePW::PW_Basis *pw_rho, @@ -42,7 +42,7 @@ void ctrl_runner_pw(UnitCell& ucell, ModulePW::PW_Basis_K* pw_wfc, ModulePW::PW_Basis* pw_rho, ModulePW::PW_Basis* pw_rhod, - Charge &chr, + Charge &chr, K_Vectors &kv, Setup_Psi_pw &stp, Structure_Factor &sf, diff --git a/source/source_io/ctrl_runner_lcao.cpp b/source/source_io/ctrl_runner_lcao.cpp index dc12ac7d2e..fe4844421b 100644 --- a/source/source_io/ctrl_runner_lcao.cpp +++ b/source/source_io/ctrl_runner_lcao.cpp @@ -22,7 +22,7 @@ void ctrl_runner_lcao(UnitCell& ucell, // unitcell Parallel_Grid &pgrid, // grid info Grid_Driver &gd, // search for adjacent atoms psi::Psi* psi, // wave function - Charge &chr, // charge density + Charge &chr, // charge density hamilt::HamiltLCAO* p_hamilt, // hamiltonian TwoCenterBundle &two_center_bundle, // use two-center integration LCAO_Orbitals &orb, // LCAO orbitals @@ -142,7 +142,7 @@ template void ctrl_runner_lcao(UnitCell& ucell, // unitcell Parallel_Grid &pgrid, // grid info Grid_Driver &gd, // search for adjacent atoms psi::Psi* psi, // wave function - Charge &chr, // charge density + Charge &chr, // charge density hamilt::HamiltLCAO* p_hamilt, // hamiltonian TwoCenterBundle &two_center_bundle, // use two-center integration LCAO_Orbitals &orb, // LCAO orbitals @@ -163,7 +163,7 @@ template void ctrl_runner_lcao, double>(UnitCell& ucell, Parallel_Grid &pgrid, // grid info Grid_Driver &gd, // search for adjacent atoms psi::Psi>* psi, // wave function - Charge &chr, // charge density + Charge &chr, // charge density hamilt::HamiltLCAO, double>* p_hamilt, // hamiltonian TwoCenterBundle &two_center_bundle, // use two-center integration LCAO_Orbitals &orb, // LCAO orbitals @@ -184,7 +184,7 @@ template void ctrl_runner_lcao, std::complex>(UnitC Parallel_Grid &pgrid, // grid info Grid_Driver &gd, // search for adjacent atoms psi::Psi>* psi, // wave function - Charge &chr, // charge density + Charge &chr, // charge density hamilt::HamiltLCAO, std::complex>* p_hamilt, // hamiltonian TwoCenterBundle &two_center_bundle, // use two-center integration LCAO_Orbitals &orb, // LCAO orbitals diff --git a/source/source_io/ctrl_runner_lcao.h b/source/source_io/ctrl_runner_lcao.h index 95c4fe4658..62d9816d54 100644 --- a/source/source_io/ctrl_runner_lcao.h +++ b/source/source_io/ctrl_runner_lcao.h @@ -23,7 +23,7 @@ void ctrl_runner_lcao(UnitCell& ucell, // unitcell Parallel_Grid &pgrid, // grid info Grid_Driver &gd, // search for adjacent atoms psi::Psi* psi, // wave function - Charge &chr, // charge density + Charge &chr, // charge density hamilt::HamiltLCAO* p_hamilt, // hamiltonian TwoCenterBundle &two_center_bundle, // use two-center integration LCAO_Orbitals &orb, // LCAO orbitals diff --git a/source/source_io/cube_io.h b/source/source_io/cube_io.h index ce4fc69f82..d644ec77be 100644 --- a/source/source_io/cube_io.h +++ b/source/source_io/cube_io.h @@ -8,11 +8,12 @@ class Parallel_Grid; namespace ModuleIO { /// read volumetric data from .cube file into the parallel distributed grid. +template bool read_vdata_palgrid(const Parallel_Grid& pgrid, const int my_rank, std::ofstream& ofs_running, const std::string& fn, - double* const data, + T* const data, const int nat); /// write volumetric data on the parallized grid into a .cube file diff --git a/source/source_io/get_pchg_pw.h b/source/source_io/get_pchg_pw.h index 2a61c77aa3..2b65a1354a 100644 --- a/source/source_io/get_pchg_pw.h +++ b/source/source_io/get_pchg_pw.h @@ -23,7 +23,7 @@ void get_pchg_pw(const std::vector& out_pchg, const K_Vectors& kv, const int kpar, const int my_pool, - const Charge* chr) // Charge class is needed for the charge density reduce + const Charge* chr) // Charge class is needed for the charge density reduce { // Get necessary parameters from kv const int nks = kv.get_nks(); // current process pool k-point count diff --git a/source/source_io/read_cube.cpp b/source/source_io/read_cube.cpp index dea1136edd..329e2d0033 100644 --- a/source/source_io/read_cube.cpp +++ b/source/source_io/read_cube.cpp @@ -3,7 +3,8 @@ #include "source_pw/module_pwdft/parallel_grid.h" #include // use std::memcpy -bool ModuleIO::read_vdata_palgrid( +template<> +bool ModuleIO::read_vdata_palgrid( const Parallel_Grid& pgrid, const int my_rank, std::ofstream& ofs_running, @@ -73,6 +74,18 @@ bool ModuleIO::read_vdata_palgrid( return true; } +template<> +bool ModuleIO::read_vdata_palgrid>( + const Parallel_Grid& pgrid, + const int my_rank, + std::ofstream& ofs_running, + const std::string& fn, + std::complex* const data, + const int natom) +{ + ModuleBase::WARNING_QUIT("ModuleIO::read_vdata_palgrid", "std::complex unsupported yet."); +} + void ModuleIO::trilinear_interpolate( const double* const data_in, const int& nx_read, diff --git a/source/source_io/read_wf2rho_pw.cpp b/source/source_io/read_wf2rho_pw.cpp index 1be65a268c..4c921793e0 100644 --- a/source/source_io/read_wf2rho_pw.cpp +++ b/source/source_io/read_wf2rho_pw.cpp @@ -8,10 +8,11 @@ #include "source_estate/kernels/elecstate_op.h" #include "source_io/filename.h" -void ModuleIO::read_wf2rho_pw( +template<> +void ModuleIO::read_wf2rho_pw( const ModulePW::PW_Basis_K* pw_wfc, ModuleSymmetry::Symmetry& symm, - Charge& chg, + Charge& chg, const std::string &readin_dir, const int kpar, const int my_pool, @@ -183,3 +184,26 @@ void ModuleIO::read_wf2rho_pw( ModuleBase::timer::tick("ModuleIO", "read_wf2rho_pw"); } + + +template<> +void ModuleIO::read_wf2rho_pw>( + const ModulePW::PW_Basis_K* pw_wfc, + ModuleSymmetry::Symmetry& symm, + Charge>& chg, + const std::string &readin_dir, + const int kpar, + const int my_pool, + const int my_rank, + const int nproc_in_pool, + const int rank_in_pool, + const int nbands, + const int nspin, + const int npol, + const int nkstot, + const std::vector &ik2iktot, + const std::vector &isk, + std::ofstream &ofs_running) +{ + ModuleBase::WARNING_QUIT("ModuleIO::read_wf2rho_pw", "std::complex unsupported yet."); +} \ No newline at end of file diff --git a/source/source_io/read_wf2rho_pw.h b/source/source_io/read_wf2rho_pw.h index dd3fb72ca1..39f031fc4a 100644 --- a/source/source_io/read_wf2rho_pw.h +++ b/source/source_io/read_wf2rho_pw.h @@ -19,10 +19,11 @@ namespace ModuleIO * @param chg charge density */ +template void read_wf2rho_pw( const ModulePW::PW_Basis_K* pw_wfc, ModuleSymmetry::Symmetry& symm, - Charge& chg, + Charge& chg, const std::string &readin_dir, const int kpar, const int my_pool, diff --git a/source/source_io/test/read_wf2rho_pw_test.cpp b/source/source_io/test/read_wf2rho_pw_test.cpp index 786efd42a4..84e5fa0df5 100644 --- a/source/source_io/test/read_wf2rho_pw_test.cpp +++ b/source/source_io/test/read_wf2rho_pw_test.cpp @@ -28,10 +28,10 @@ Parallel_Grid::Parallel_Grid() Parallel_Grid::~Parallel_Grid() { } -Charge::Charge() +Charge::Charge() { } -Charge::~Charge() +Charge::~Charge() { } UnitCell::UnitCell() @@ -60,7 +60,7 @@ Symmetry_rho::~Symmetry_rho() { } void Symmetry_rho::begin(const int& spin_now, - const Charge& CHR, + const Charge& CHR, const ModulePW::PW_Basis* rho_basis, ModuleSymmetry::Symmetry& symm) const { @@ -113,7 +113,7 @@ class ReadWfcRhoTest : public ::testing::Test ModulePW::PW_Basis* rhopw = nullptr; K_Vectors* kv = nullptr; psi::Psi>* psi = nullptr; - Charge chg; + Charge chg; ModuleSymmetry::Symmetry symm; virtual void SetUp() { @@ -242,7 +242,7 @@ TEST_F(ReadWfcRhoTest, ReadWfcRho) //---------------------------------------- // set charge_ref //---------------------------------------- - Charge chg_ref; + Charge chg_ref; chg_ref.rho = new double*[nspin]; chg_ref._space_rho = new double[rhopw->nrxx]; chg_ref.rho[0] = chg_ref._space_rho; diff --git a/source/source_io/write_eband_terms.hpp b/source/source_io/write_eband_terms.hpp index 701b097b25..5ca3dcfeda 100644 --- a/source/source_io/write_eband_terms.hpp +++ b/source/source_io/write_eband_terms.hpp @@ -20,7 +20,7 @@ void write_eband_terms(const int nspin, const ModulePW::PW_Basis& rho_basis, const ModulePW::PW_Basis& rhod_basis, const ModuleBase::matrix& vloc, - const Charge& chg, + const Charge& chg, const K_Vectors& kv, const ModuleBase::matrix& wg, Grid_Driver& gd, diff --git a/source/source_io/write_elecstat_pot.cpp b/source/source_io/write_elecstat_pot.cpp index e70ba04525..d6eb885f10 100644 --- a/source/source_io/write_elecstat_pot.cpp +++ b/source/source_io/write_elecstat_pot.cpp @@ -19,7 +19,7 @@ void write_elecstat_pot( const std::string& fn, const int& istep, ModulePW::PW_Basis* rho_basis, - const Charge* const chr, + const Charge* const chr, const UnitCell* ucell, const double* v_eff, const surchem& solvent) diff --git a/source/source_io/write_elecstat_pot.h b/source/source_io/write_elecstat_pot.h index bd3f2a8734..2f16829b5f 100644 --- a/source/source_io/write_elecstat_pot.h +++ b/source/source_io/write_elecstat_pot.h @@ -27,7 +27,7 @@ void write_elecstat_pot( const std::string& fn, const int& istep, ModulePW::PW_Basis* rho_basis, - const Charge* const chr, + const Charge* const chr, const UnitCell* ucell_, const double* v_eff_fixed, const surchem& solvent); diff --git a/source/source_io/write_init.cpp b/source/source_io/write_init.cpp index ba435790f6..1012baefa5 100644 --- a/source/source_io/write_init.cpp +++ b/source/source_io/write_init.cpp @@ -7,7 +7,7 @@ void ModuleIO::write_chg_init( const UnitCell& ucell, const Parallel_Grid ¶_grid, - const Charge &chr, + const Charge &chr, const elecstate::Efermi &efermi, const int istep, const Input_para& inp) diff --git a/source/source_io/write_init.h b/source/source_io/write_init.h index 08184931e9..12917d195a 100644 --- a/source/source_io/write_init.h +++ b/source/source_io/write_init.h @@ -13,7 +13,7 @@ namespace ModuleIO void write_chg_init( const UnitCell& ucell, const Parallel_Grid ¶_grid, - const Charge &chr, + const Charge &chr, const elecstate::Efermi &efermi, const int istep, const Input_para& inp); diff --git a/source/source_io/write_libxc_r.cpp b/source/source_io/write_libxc_r.cpp index 744f9f736a..f10c41dc5c 100644 --- a/source/source_io/write_libxc_r.cpp +++ b/source/source_io/write_libxc_r.cpp @@ -29,7 +29,7 @@ void ModuleIO::write_libxc_r( const int &nrxx, // number of real-space grid const double &omega, // volume of cell const double tpiba, - const Charge &chr, + const Charge &chr, const ModulePW::PW_Basis_Big &pw_big, const ModulePW::PW_Basis &pw_rhod) { diff --git a/source/source_io/write_libxc_r.h b/source/source_io/write_libxc_r.h index ad82e68b57..a775af57fe 100644 --- a/source/source_io/write_libxc_r.h +++ b/source/source_io/write_libxc_r.h @@ -11,7 +11,7 @@ #include #include - class Charge; + template class Charge; namespace ModulePW{ class PW_Basis_Big; } namespace ModulePW{ class PW_Basis; } @@ -23,7 +23,7 @@ namespace ModuleIO const int &nrxx, // number of real-space grid const double &omega, // volume of cell const double tpiba, - const Charge &chr, + const Charge &chr, const ModulePW::PW_Basis_Big &pw_big, const ModulePW::PW_Basis &pw_rhod); diff --git a/source/source_io/write_mlkedf_descriptors.cpp b/source/source_io/write_mlkedf_descriptors.cpp index 840adfac7f..2ecda42ae4 100644 --- a/source/source_io/write_mlkedf_descriptors.cpp +++ b/source/source_io/write_mlkedf_descriptors.cpp @@ -30,7 +30,7 @@ void Write_MLKEDF_Descriptors::generateTrainData_KS( Symmetry_rho srho; - Charge* ptempRho = new Charge(); + Charge* ptempRho = new Charge(); ptempRho->nspin = PARAM.inp.nspin; ptempRho->nrxx = this->cal_tool->nx; ptempRho->rho_core = pelec->charge->rho_core; diff --git a/source/source_io/write_vxc.hpp b/source/source_io/write_vxc.hpp index f579fc8b60..fcd901cc65 100644 --- a/source/source_io/write_vxc.hpp +++ b/source/source_io/write_vxc.hpp @@ -145,7 +145,7 @@ void write_Vxc(const int nspin, const ModulePW::PW_Basis& rho_basis, const ModulePW::PW_Basis& rhod_basis, const ModuleBase::matrix& vloc, - const Charge& chg, + const Charge& chg, const K_Vectors& kv, const std::vector& orb_cutoff, const ModuleBase::matrix& wg, diff --git a/source/source_io/write_vxc_lip.hpp b/source/source_io/write_vxc_lip.hpp index 3705993022..92ec781b81 100644 --- a/source/source_io/write_vxc_lip.hpp +++ b/source/source_io/write_vxc_lip.hpp @@ -113,7 +113,7 @@ namespace ModuleIO const ModulePW::PW_Basis& rho_basis, const ModulePW::PW_Basis& rhod_basis, const ModuleBase::matrix& vloc, - const Charge& chg, + const Charge& chg, const K_Vectors& kv, const ModuleBase::matrix& wg #ifdef __EXX diff --git a/source/source_io/write_vxc_r.hpp b/source/source_io/write_vxc_r.hpp index 127f17fde8..802d66555d 100644 --- a/source/source_io/write_vxc_r.hpp +++ b/source/source_io/write_vxc_r.hpp @@ -40,7 +40,7 @@ void write_Vxc_R(const int nspin, const ModulePW::PW_Basis& rho_basis, const ModulePW::PW_Basis& rhod_basis, const ModuleBase::matrix& vloc, - const Charge& chg, + const Charge& chg, const K_Vectors& kv, const std::vector& orb_cutoff, Grid_Driver& gd, diff --git a/source/source_lcao/FORCE_STRESS.cpp b/source/source_lcao/FORCE_STRESS.cpp index 878f54264c..6b21a59553 100644 --- a/source/source_lcao/FORCE_STRESS.cpp +++ b/source/source_lcao/FORCE_STRESS.cpp @@ -713,7 +713,7 @@ void Force_Stress_LCAO::calForcePwPart(UnitCell& ucell, const double& etxc, const ModuleBase::matrix& vnew, const bool vnew_exist, - const Charge* const chr, + const Charge* const chr, ModulePW::PW_Basis* rhopw, const pseudopot_cell_vl& locpp, const Structure_Factor& sf) @@ -819,7 +819,7 @@ void Force_Stress_LCAO::calStressPwPart(UnitCell& ucell, ModuleBase::matrix& sigmacc, ModuleBase::matrix& sigmaxc, const double& etxc, - const Charge* const chr, + const Charge* const chr, ModulePW::PW_Basis* rhopw, const pseudopot_cell_vl& locpp, const Structure_Factor& sf) diff --git a/source/source_lcao/FORCE_STRESS.h b/source/source_lcao/FORCE_STRESS.h index 1c2ebb790e..a7a391c8bb 100644 --- a/source/source_lcao/FORCE_STRESS.h +++ b/source/source_lcao/FORCE_STRESS.h @@ -72,7 +72,7 @@ class Force_Stress_LCAO const double& etxc, const ModuleBase::matrix& vnew, const bool vnew_exist, - const Charge* const chr, + const Charge* const chr, ModulePW::PW_Basis* rhopw, const pseudopot_cell_vl& locpp, const Structure_Factor& sf); @@ -109,7 +109,7 @@ class Force_Stress_LCAO ModuleBase::matrix& sigmacc, ModuleBase::matrix& sigmaxc, const double& etxc, - const Charge* const chr, + const Charge* const chr, ModulePW::PW_Basis* rhopw, const pseudopot_cell_vl& locpp, const Structure_Factor& sf); diff --git a/source/source_lcao/LCAO_set.cpp b/source/source_lcao/LCAO_set.cpp index 2f868dfaa4..12d6195e7f 100644 --- a/source/source_lcao/LCAO_set.cpp +++ b/source/source_lcao/LCAO_set.cpp @@ -12,7 +12,7 @@ void LCAO_domain::set_psi_occ_dm_chg( const Parallel_Orbitals &pv, // parallel scheme of NAO basis elecstate::ElecState* pelec, // eigen values and weights LCAO_domain::Setup_DM &dmat, // density matrix - Charge &chr, // charge density + Charge &chr, // charge density const Input_para &inp) // input parameters { @@ -138,7 +138,7 @@ template void LCAO_domain::set_psi_occ_dm_chg( const Parallel_Orbitals &pv, // parallel scheme of NAO basis elecstate::ElecState* pelec, // eigen values and weights LCAO_domain::Setup_DM &dmat, // density matrix - Charge &chr, // charge density + Charge &chr, // charge density const Input_para &inp); template void LCAO_domain::set_psi_occ_dm_chg>( @@ -147,7 +147,7 @@ template void LCAO_domain::set_psi_occ_dm_chg>( const Parallel_Orbitals &pv, // parallel scheme of NAO basis elecstate::ElecState* pelec, // eigen values and weights LCAO_domain::Setup_DM> &dmat, // density matrix - Charge &chr, // charge density + Charge &chr, // charge density const Input_para &inp); template void LCAO_domain::set_pot( diff --git a/source/source_lcao/LCAO_set.h b/source/source_lcao/LCAO_set.h index 1e1aa6e5a3..aa645c8772 100644 --- a/source/source_lcao/LCAO_set.h +++ b/source/source_lcao/LCAO_set.h @@ -29,7 +29,7 @@ void set_psi_occ_dm_chg( const Parallel_Orbitals &pv, // parallel scheme of NAO basis elecstate::ElecState* pelec, // eigen values and weights LCAO_domain::Setup_DM &dmat, // density matrix - Charge &chr, // charge density + Charge &chr, // charge density const Input_para& inp); // input parameters /** diff --git a/source/source_lcao/module_lr/esolver_lrtd_lcao.cpp b/source/source_lcao/module_lr/esolver_lrtd_lcao.cpp index 16efc5f046..d04887909c 100644 --- a/source/source_lcao/module_lr/esolver_lrtd_lcao.cpp +++ b/source/source_lcao/module_lr/esolver_lrtd_lcao.cpp @@ -359,7 +359,7 @@ LR::ESolver_LR::ESolver_LR(const Input_para& inp, UnitCell& ucell) : inpu this->pw_rho->nrxx, pw_big->nbz, pw_big->bz); - Charge chg_gs; + Charge chg_gs; if (input.ri_hartree_benchmark != "aims") { this->read_ks_chg(chg_gs); } this->init_pot(chg_gs); @@ -629,7 +629,7 @@ void LR::ESolver_LR::set_X_initial_guess() } template -void LR::ESolver_LR::init_pot(const Charge& chg_gs) +void LR::ESolver_LR::init_pot(const Charge& chg_gs) { this->pot.resize(nspin, nullptr); if (this->input.ri_hartree_benchmark != "none") { return; } //no need to initialize potential for Hxc kernel in the RI-benchmark routine @@ -681,7 +681,7 @@ void LR::ESolver_LR::read_ks_wfc() } template -void LR::ESolver_LR::read_ks_chg(Charge& chg_gs) +void LR::ESolver_LR::read_ks_chg(Charge& chg_gs) { chg_gs.set_rhopw(this->pw_rho); const bool kin_den = chg_gs.kin_density(); // mohan add 20251202 diff --git a/source/source_lcao/module_lr/esolver_lrtd_lcao.h b/source/source_lcao/module_lr/esolver_lrtd_lcao.h index 3f2d040501..112e31a54a 100644 --- a/source/source_lcao/module_lr/esolver_lrtd_lcao.h +++ b/source/source_lcao/module_lr/esolver_lrtd_lcao.h @@ -106,9 +106,9 @@ namespace LR /// @brief read in the ground state wave function, band energy and occupation void read_ks_wfc(); /// @brief read in the ground state charge density - void read_ks_chg(Charge& chg); + void read_ks_chg(Charge& chg); - void init_pot(const Charge& chg_gs); + void init_pot(const Charge& chg_gs); /// @brief check the legality of the input parameters void parameter_check() const; diff --git a/source/source_lcao/module_lr/potentials/pot_hxc_lrtd.cpp b/source/source_lcao/module_lr/potentials/pot_hxc_lrtd.cpp index 58febe316e..083c50e6ee 100644 --- a/source/source_lcao/module_lr/potentials/pot_hxc_lrtd.cpp +++ b/source/source_lcao/module_lr/potentials/pot_hxc_lrtd.cpp @@ -12,7 +12,7 @@ namespace LR { // constructor for exchange-correlation kernel PotHxcLR::PotHxcLR(const std::string& xc_kernel, const ModulePW::PW_Basis& rho_basis, const UnitCell& ucell, - const Charge& chg_gs/*ground state*/, const Parallel_Grid& pgrid, + const Charge& chg_gs/*ground state*/, const Parallel_Grid& pgrid, const SpinType& st, const std::vector& lr_init_xc_kernel) :xc_kernel_(xc_kernel), tpiba_(ucell.tpiba), spin_type_(st), rho_basis_(rho_basis), nrxx_(chg_gs.nrxx), nspin_(PARAM.inp.nspin == 1 || (PARAM.inp.nspin == 4 && !PARAM.globalv.domag && !PARAM.globalv.domag_z) ? 1 : 2), diff --git a/source/source_lcao/module_lr/potentials/pot_hxc_lrtd.h b/source/source_lcao/module_lr/potentials/pot_hxc_lrtd.h index 1f3b30fe06..53944a3bb9 100644 --- a/source/source_lcao/module_lr/potentials/pot_hxc_lrtd.h +++ b/source/source_lcao/module_lr/potentials/pot_hxc_lrtd.h @@ -18,7 +18,7 @@ namespace LR enum XCType { None = 0, LDA = 1, GGA = 2, HYB_GGA = 4 }; /// constructor for exchange-correlation kernel PotHxcLR(const std::string& xc_kernel, const ModulePW::PW_Basis& rho_basis, - const UnitCell& ucell, const Charge& chg_gs/*ground state*/, const Parallel_Grid& pgrid, + const UnitCell& ucell, const Charge& chg_gs/*ground state*/, const Parallel_Grid& pgrid, const SpinType& st = SpinType::S1, const std::vector& lr_init_xc_kernel = { "default" }); ~PotHxcLR() {} void cal_v_eff(double** rho, const UnitCell& ucell, ModuleBase::matrix& v_eff, const std::vector& ispin_op = { 0,0 }); diff --git a/source/source_lcao/module_lr/potentials/xc_kernel.cpp b/source/source_lcao/module_lr/potentials/xc_kernel.cpp index 69c37b8de2..7991a7fdd8 100644 --- a/source/source_lcao/module_lr/potentials/xc_kernel.cpp +++ b/source/source_lcao/module_lr/potentials/xc_kernel.cpp @@ -17,7 +17,7 @@ LR::KernelXC::KernelXC(const ModulePW::PW_Basis& rho_basis, const UnitCell& ucell, - const Charge& chg_gs, + const Charge& chg_gs, const Parallel_Grid& pgrid, const int& nspin, const std::string& kernel_name, diff --git a/source/source_lcao/module_lr/potentials/xc_kernel.h b/source/source_lcao/module_lr/potentials/xc_kernel.h index b3be26c58b..f950ca43f5 100644 --- a/source/source_lcao/module_lr/potentials/xc_kernel.h +++ b/source/source_lcao/module_lr/potentials/xc_kernel.h @@ -15,7 +15,7 @@ namespace LR public: KernelXC(const ModulePW::PW_Basis& rho_basis, const UnitCell& ucell, - const Charge& chg_gs, + const Charge& chg_gs, const Parallel_Grid& pgrid, const int& nspin, const std::string& kernel_name, diff --git a/source/source_lcao/module_rdmft/rdmft.h b/source/source_lcao/module_rdmft/rdmft.h index 0e6b532d6e..dffa1392e1 100644 --- a/source/source_lcao/module_rdmft/rdmft.h +++ b/source/source_lcao/module_rdmft/rdmft.h @@ -94,7 +94,7 @@ class RDMFT //! update in elec-step // Or we can use rdmft_solver.wfc/occ_number directly when optimizing, so that the update_elec() function does not require parameters. - void update_elec(UnitCell& ucell, const ModuleBase::matrix& occ_number_in, const psi::Psi& wfc_in, const Charge* charge_in = nullptr); + void update_elec(UnitCell& ucell, const ModuleBase::matrix& occ_number_in, const psi::Psi& wfc_in, const Charge* charge_in = nullptr); //! obtain the gradient of total energy with respect to occupation number and wfc double cal_E_grad_wfc_occ_num(); @@ -186,7 +186,7 @@ class RDMFT const int cal_E_type = 1; // cal_type = 2 just support XC-functional without exx /****** these parameters are passed in from outside, don't need delete ******/ - Charge* charge = nullptr; + Charge* charge = nullptr; // update after ion step const UnitCell* ucell = nullptr; diff --git a/source/source_lcao/module_rdmft/rdmft_tools.h b/source/source_lcao/module_rdmft/rdmft_tools.h index 0a4e28f548..7129047b17 100644 --- a/source/source_lcao/module_rdmft/rdmft_tools.h +++ b/source/source_lcao/module_rdmft/rdmft_tools.h @@ -266,7 +266,7 @@ class Veff_rdmft : public hamilt::OperatorLCAO const std::vector& orb_cutoff, const Grid_Driver* GridD_in, const int& nspin, - const Charge* charge_in, + const Charge* charge_in, const ModulePW::PW_Basis* rho_basis_in, const ModuleBase::matrix* vloc_in, const ModuleBase::ComplexMatrix* sf_in, @@ -300,7 +300,7 @@ class Veff_rdmft : public hamilt::OperatorLCAO std::vector orb_cutoff_; - // Charge calculating method in LCAO base and contained grid base calculation: DM_R, DM, pvpR_reduced + // Charge calculating method in LCAO base and contained grid base calculation: DM_R, DM, pvpR_reduced elecstate::Potential* pot = nullptr; @@ -316,7 +316,7 @@ class Veff_rdmft : public hamilt::OperatorLCAO // added by jghan - const Charge* charge_; + const Charge* charge_; std::string potential_; diff --git a/source/source_lcao/module_rdmft/update_state_rdmft.cpp b/source/source_lcao/module_rdmft/update_state_rdmft.cpp index 7a43c9be91..edfa1663b2 100644 --- a/source/source_lcao/module_rdmft/update_state_rdmft.cpp +++ b/source/source_lcao/module_rdmft/update_state_rdmft.cpp @@ -50,7 +50,7 @@ void RDMFT::update_ion(UnitCell& ucell_in, template void RDMFT::update_elec(UnitCell& ucell, const ModuleBase::matrix& occ_number_in, - const psi::Psi& wfc_in, const Charge* charge_in) + const psi::Psi& wfc_in, const Charge* charge_in) { // update occ_number, wg, wk_fun_occNum occ_number = (occ_number_in); diff --git a/source/source_lcao/rho_tau_lcao.cpp b/source/source_lcao/rho_tau_lcao.cpp index 9fbeb9f1c6..aee2d785dd 100644 --- a/source/source_lcao/rho_tau_lcao.cpp +++ b/source/source_lcao/rho_tau_lcao.cpp @@ -4,7 +4,7 @@ void LCAO_domain::dm2rho(std::vector*> &dmr, const int nspin, - Charge* chr, + Charge* chr, bool skip_normalize) { ModuleBase::TITLE("LCAO_domain", "dm2rho"); @@ -34,7 +34,7 @@ void LCAO_domain::dm2rho(std::vector*> &dmr, void LCAO_domain::dm2tau(std::vector*> &dmr, const int nspin, - Charge* chr) + Charge* chr) { ModuleBase::TITLE("LCAO_domain", "dm2tau"); ModuleBase::timer::tick("LCAO_domain", "dm2tau"); diff --git a/source/source_lcao/rho_tau_lcao.h b/source/source_lcao/rho_tau_lcao.h index b90d23af85..18670cebb3 100644 --- a/source/source_lcao/rho_tau_lcao.h +++ b/source/source_lcao/rho_tau_lcao.h @@ -9,12 +9,12 @@ namespace LCAO_domain { void dm2rho(std::vector*> &dmr, const int nspin, - Charge* chr, + Charge* chr, bool skip_normalize = false); void dm2tau(std::vector*> &dmr, const int nspin, - Charge* chr); + Charge* chr); } #endif diff --git a/source/source_pw/module_ofdft/evolve_ofdft.cpp b/source/source_pw/module_ofdft/evolve_ofdft.cpp index 05a058671d..6a1223986e 100644 --- a/source/source_pw/module_ofdft/evolve_ofdft.cpp +++ b/source/source_pw/module_ofdft/evolve_ofdft.cpp @@ -6,7 +6,7 @@ #include "source_base/parallel_reduce.h" void Evolve_OFDFT::cal_Hpsi(elecstate::ElecState* pelec, - const Charge& chr, + const Charge& chr, UnitCell& ucell, std::vector> psi_, ModulePW::PW_Basis* pw_rho, @@ -221,7 +221,7 @@ void Evolve_OFDFT::cal_CD_potential(std::vector> psi_, } void Evolve_OFDFT::propagate_psi(elecstate::ElecState* pelec, - const Charge& chr, UnitCell& ucell, + const Charge& chr, UnitCell& ucell, std::vector> pphi_, ModulePW::PW_Basis* pw_rho) { diff --git a/source/source_pw/module_ofdft/evolve_ofdft.h b/source/source_pw/module_ofdft/evolve_ofdft.h index 45ffffe7ad..8afe912b17 100644 --- a/source/source_pw/module_ofdft/evolve_ofdft.h +++ b/source/source_pw/module_ofdft/evolve_ofdft.h @@ -25,7 +25,7 @@ class Evolve_OFDFT { } void propagate_psi(elecstate::ElecState* pelec, - const Charge& chr, UnitCell& ucell, + const Charge& chr, UnitCell& ucell, std::vector> pphi_, ModulePW::PW_Basis* pw_rho); @@ -35,7 +35,7 @@ class Evolve_OFDFT * 2; // 10/3*(3*pi^2)^{2/3}, multiply by 2 to convert unit from Hartree to Ry, finally in Ry*Bohr^(-2) void cal_Hpsi(elecstate::ElecState* pelec, - const Charge& chr, + const Charge& chr, UnitCell& ucell, std::vector> psi_, ModulePW::PW_Basis* pw_rho, diff --git a/source/source_pw/module_pwdft/forces.cpp b/source/source_pw/module_pwdft/forces.cpp index 819f0cdf23..eb795d451e 100644 --- a/source/source_pw/module_pwdft/forces.cpp +++ b/source/source_pw/module_pwdft/forces.cpp @@ -41,7 +41,7 @@ void Forces::cal_force(UnitCell& ucell, this->device = base_device::get_device_type(this->ctx); const ModuleBase::matrix& wg = elec.wg; const ModuleBase::matrix& ekb = elec.ekb; - const Charge* const chr = elec.charge; + const Charge* const chr = elec.charge; force.create(nat, 3); ModuleBase::matrix forcelc(nat, 3); @@ -327,7 +327,7 @@ void Forces::cal_force_loc(const UnitCell& ucell, ModuleBase::matrix& forcelc, const ModulePW::PW_Basis* const rho_basis, const ModuleBase::matrix& vloc, - const Charge* const chr) + const Charge* const chr) { ModuleBase::TITLE("Forces", "cal_force_loc"); ModuleBase::timer::tick("Forces", "cal_force_loc"); diff --git a/source/source_pw/module_pwdft/forces.h b/source/source_pw/module_pwdft/forces.h index 61466fcdd6..8d4d1275e6 100644 --- a/source/source_pw/module_pwdft/forces.h +++ b/source/source_pw/module_pwdft/forces.h @@ -57,14 +57,14 @@ class Forces ModuleBase::matrix& forcelc, const ModulePW::PW_Basis* const rho_basis, const ModuleBase::matrix& vloc, - const Charge* const chr); + const Charge* const chr); void cal_force_ew(const UnitCell& ucell, ModuleBase::matrix& forceion, const ModulePW::PW_Basis* const rho_basis, const Structure_Factor* p_sf); void cal_force_cc(ModuleBase::matrix& forcecc, const ModulePW::PW_Basis* const rho_basis, - const Charge* const chr, + const Charge* const chr, const bool* numeric, UnitCell& ucell_in); /** diff --git a/source/source_pw/module_pwdft/forces_cc.cpp b/source/source_pw/module_pwdft/forces_cc.cpp index a03d49964b..b6cc505cb1 100644 --- a/source/source_pw/module_pwdft/forces_cc.cpp +++ b/source/source_pw/module_pwdft/forces_cc.cpp @@ -30,7 +30,7 @@ template void Forces::cal_force_cc(ModuleBase::matrix& forcecc, const ModulePW::PW_Basis* const rho_basis, - const Charge* const chr, + const Charge* const chr, const bool* numeric, UnitCell& ucell_in) { diff --git a/source/source_pw/module_pwdft/setup_pot.cpp b/source/source_pw/module_pwdft/setup_pot.cpp index 5080e265f7..5a82a1f491 100644 --- a/source/source_pw/module_pwdft/setup_pot.cpp +++ b/source/source_pw/module_pwdft/setup_pot.cpp @@ -13,7 +13,7 @@ void pw::setup_pot(const int istep, Structure_Factor &sf, // structure factors elecstate::ElecState *pelec, // pointer of electrons const Parallel_Grid ¶_grid, // parallel of FFT grids - const Charge &chr, // charge density + const Charge &chr, // charge density pseudopot_cell_vl &locpp, // local pseudopotentials pseudopot_cell_vnl &ppcell, // non-local pseudopotentials Plus_U &dftu, // mohan add 2025-11-06 @@ -131,7 +131,7 @@ template void pw::setup_pot, base_device::DEVICE_CPU>( Structure_Factor &sf, // structure factors elecstate::ElecState *pelec, // pointer of electrons const Parallel_Grid ¶_grid, // parallel of FFT grids - const Charge &chr, // charge density + const Charge &chr, // charge density pseudopot_cell_vl &locpp, // local pseudopotentials pseudopot_cell_vnl &ppcell, // non-local pseudopotentials Plus_U &dftu, // mohan add 2025-11-06 @@ -150,7 +150,7 @@ template void pw::setup_pot, base_device::DEVICE_CPU>( Structure_Factor &sf, // structure factors elecstate::ElecState *pelec, // pointer of electrons const Parallel_Grid ¶_grid, // parallel of FFT grids - const Charge &chr, // charge density + const Charge &chr, // charge density pseudopot_cell_vl &locpp, // local pseudopotentials pseudopot_cell_vnl &ppcell, // non-local pseudopotentials Plus_U &dftu, // mohan add 2025-11-06 @@ -170,7 +170,7 @@ template void pw::setup_pot, base_device::DEVICE_GPU>( Structure_Factor &sf, // structure factors elecstate::ElecState *pelec, // pointer of electrons const Parallel_Grid ¶_grid, // parallel of FFT grids - const Charge &chr, // charge density + const Charge &chr, // charge density pseudopot_cell_vl &locpp, // local pseudopotentials pseudopot_cell_vnl &ppcell, // non-local pseudopotentials Plus_U &dftu, // mohan add 2025-11-06 @@ -188,7 +188,7 @@ template void pw::setup_pot, base_device::DEVICE_GPU>( Structure_Factor &sf, // structure factors elecstate::ElecState *pelec, // pointer of electrons const Parallel_Grid ¶_grid, // parallel of FFT grids - const Charge &chr, // charge density + const Charge &chr, // charge density pseudopot_cell_vl &locpp, // local pseudopotentials pseudopot_cell_vnl &ppcell, // non-local pseudopotentials Plus_U &dftu, // mohan add 2025-11-06 diff --git a/source/source_pw/module_pwdft/setup_pot.h b/source/source_pw/module_pwdft/setup_pot.h index 3849ee5087..07b2ac85f3 100644 --- a/source/source_pw/module_pwdft/setup_pot.h +++ b/source/source_pw/module_pwdft/setup_pot.h @@ -20,7 +20,7 @@ void setup_pot(const int istep, Structure_Factor &sf, // structure factors elecstate::ElecState *pelec, // pointer of electrons const Parallel_Grid ¶_grid, // parallel of FFT grids - const Charge &chr, // charge density + const Charge &chr, // charge density pseudopot_cell_vl &locpp, // local pseudopotentials pseudopot_cell_vnl &ppcell, // non-local pseudopotentials Plus_U &dftu, // mohan add 2025-11-06 diff --git a/source/source_pw/module_pwdft/stress_func.h b/source/source_pw/module_pwdft/stress_func.h index 3f0a79b6d3..b5596c0fee 100644 --- a/source/source_pw/module_pwdft/stress_func.h +++ b/source/source_pw/module_pwdft/stress_func.h @@ -75,7 +75,7 @@ class Stress_Func ModuleBase::matrix& sigma, ModulePW::PW_Basis* rho_basis, const bool is_pw, - const Charge* const chr); // hartree part in PW or LCAO basis + const Charge* const chr); // hartree part in PW or LCAO basis // 3) the stress from the ewald term (ion-ion intraction under // periodic boundary conditions). @@ -91,7 +91,7 @@ class Stress_Func const ModuleBase::matrix& vloc, const Structure_Factor* p_sf, const bool is_pw, - const Charge* const chr); // local pseudopotential part in PW or LCAO + const Charge* const chr); // local pseudopotential part in PW or LCAO void dvloc_of_g(const int& msh, const FPTYPE* rab, @@ -119,7 +119,7 @@ class Stress_Func const Structure_Factor* p_sf, const bool is_pw, const bool *numeric, - const Charge* const chr); // nonlinear core correction stress in PW or LCAO basis + const Charge* const chr); // nonlinear core correction stress in PW or LCAO basis void deriv_drhoc(const bool& numeric, const double& omega, @@ -136,12 +136,12 @@ class Stress_Func void stress_gga(const UnitCell& ucell, ModuleBase::matrix& sigma, ModulePW::PW_Basis* rho_basis, - const Charge* const chr); // gga part in both PW and LCAO basis + const Charge* const chr); // gga part in both PW and LCAO basis void stress_mgga(const UnitCell& ucell, ModuleBase::matrix& sigma, const ModuleBase::matrix& wg, const ModuleBase::matrix& v_ofk, - const Charge* const chr, + const Charge* const chr, K_Vectors* p_kv, ModulePW::PW_Basis_K* wfc_basis, const psi::Psi , Device>* psi_in); // gga part in PW basis diff --git a/source/source_pw/module_pwdft/stress_func_cc.cpp b/source/source_pw/module_pwdft/stress_func_cc.cpp index 81b2767d51..85510f1e71 100644 --- a/source/source_pw/module_pwdft/stress_func_cc.cpp +++ b/source/source_pw/module_pwdft/stress_func_cc.cpp @@ -19,7 +19,7 @@ void Stress_Func::stress_cc(ModuleBase::matrix& sigma, const Structure_Factor* p_sf, const bool is_pw, const bool *numeric, - const Charge* const chr) + const Charge* const chr) { ModuleBase::TITLE("Stress","stress_cc"); ModuleBase::timer::tick("Stress","stress_cc"); diff --git a/source/source_pw/module_pwdft/stress_func_gga.cpp b/source/source_pw/module_pwdft/stress_func_gga.cpp index 9d9bbf5ebd..7a8bebf013 100644 --- a/source/source_pw/module_pwdft/stress_func_gga.cpp +++ b/source/source_pw/module_pwdft/stress_func_gga.cpp @@ -8,7 +8,7 @@ template void Stress_Func::stress_gga(const UnitCell& ucell, ModuleBase::matrix& sigma, ModulePW::PW_Basis* rho_basis, - const Charge* const chr) + const Charge* const chr) { ModuleBase::TITLE("Stress","stress_gga"); ModuleBase::timer::tick("Stress","stress_gga"); diff --git a/source/source_pw/module_pwdft/stress_func_har.cpp b/source/source_pw/module_pwdft/stress_func_har.cpp index b99ee7fb04..33f2ae1098 100644 --- a/source/source_pw/module_pwdft/stress_func_har.cpp +++ b/source/source_pw/module_pwdft/stress_func_har.cpp @@ -10,7 +10,7 @@ void Stress_Func::stress_har(const UnitCell& ucell, ModuleBase::matrix& sigma, ModulePW::PW_Basis* rho_basis, const bool is_pw, - const Charge* const chr) + const Charge* const chr) { ModuleBase::TITLE("Stress","stress_har"); ModuleBase::timer::tick("Stress","stress_har"); diff --git a/source/source_pw/module_pwdft/stress_func_loc.cpp b/source/source_pw/module_pwdft/stress_func_loc.cpp index fe4d85e1be..073d7e1c67 100644 --- a/source/source_pw/module_pwdft/stress_func_loc.cpp +++ b/source/source_pw/module_pwdft/stress_func_loc.cpp @@ -14,7 +14,7 @@ void Stress_Func::stress_loc(const UnitCell& ucell, const ModuleBase::matrix& vloc, const Structure_Factor* p_sf, const bool is_pw, - const Charge* const chr) + const Charge* const chr) { ModuleBase::TITLE("Stress","stress_loc"); ModuleBase::timer::tick("Stress","stress_loc"); diff --git a/source/source_pw/module_pwdft/stress_func_mgga.cpp b/source/source_pw/module_pwdft/stress_func_mgga.cpp index b2d9ffe841..eac45c32ea 100644 --- a/source/source_pw/module_pwdft/stress_func_mgga.cpp +++ b/source/source_pw/module_pwdft/stress_func_mgga.cpp @@ -13,7 +13,7 @@ void Stress_Func::stress_mgga(const UnitCell& ucell, ModuleBase::matrix& sigma, const ModuleBase::matrix& wg, const ModuleBase::matrix& v_ofk, - const Charge* const chr, + const Charge* const chr, K_Vectors* p_kv, ModulePW::PW_Basis_K* wfc_basis, const psi::Psi , Device>* psi_in) diff --git a/source/source_pw/module_stodft/sto_forces.cpp b/source/source_pw/module_stodft/sto_forces.cpp index 35ed90a80b..960017c895 100644 --- a/source/source_pw/module_stodft/sto_forces.cpp +++ b/source/source_pw/module_stodft/sto_forces.cpp @@ -34,7 +34,7 @@ void Sto_Forces::cal_stoforce(ModuleBase::matrix& force, ModuleBase::TITLE("Sto_Forces", "init"); this->device = base_device::get_device_type(this->ctx); const ModuleBase::matrix& wg = elec.wg; - const Charge* chr = elec.charge; + const Charge* chr = elec.charge; force.create(this->nat, 3); ModuleBase::matrix forcelc(this->nat, 3); diff --git a/source/source_pw/module_stodft/sto_stress_pw.cpp b/source/source_pw/module_stodft/sto_stress_pw.cpp index d83bd9d441..0c2d3749cb 100644 --- a/source/source_pw/module_stodft/sto_stress_pw.cpp +++ b/source/source_pw/module_stodft/sto_stress_pw.cpp @@ -18,7 +18,7 @@ void Sto_Stress_PW::cal_stress(ModuleBase::matrix& sigmatot, ModulePW::PW_Basis_K* wfc_basis, const psi::Psi , Device>& psi_in, const Stochastic_WF, Device>& stowf, - const Charge* const chr, + const Charge* const chr, const pseudopot_cell_vl* locpp, const pseudopot_cell_vnl* nlpp, UnitCell& ucell_in) diff --git a/source/source_pw/module_stodft/sto_stress_pw.h b/source/source_pw/module_stodft/sto_stress_pw.h index 8dbbc08804..5ab26e8cb0 100644 --- a/source/source_pw/module_stodft/sto_stress_pw.h +++ b/source/source_pw/module_stodft/sto_stress_pw.h @@ -26,7 +26,7 @@ class Sto_Stress_PW : public Stress_Func ModulePW::PW_Basis_K* wfc_basis, const psi::Psi, Device>& psi_in, const Stochastic_WF, Device>& stowf, - const Charge* const chr, + const Charge* const chr, const pseudopot_cell_vl* locpp, const pseudopot_cell_vnl* nlpp, UnitCell& ucell_in); diff --git a/source/source_pw/module_stodft/test/test_hamilt_sto.cpp b/source/source_pw/module_stodft/test/test_hamilt_sto.cpp index a1937caf05..e43dd9b6b2 100644 --- a/source/source_pw/module_stodft/test/test_hamilt_sto.cpp +++ b/source/source_pw/module_stodft/test/test_hamilt_sto.cpp @@ -5,7 +5,7 @@ #include elecstate::Potential::~Potential(){} -void elecstate::Potential::cal_v_eff(Charge const*, UnitCell const*, ModuleBase::matrix&){} +void elecstate::Potential::cal_v_eff(Charge const*, UnitCell const*, ModuleBase::matrix&){} void elecstate::Potential::cal_fixed_v(double*){} template From 1a6a3bc57909c5e9c43ec2a4507646a2f7f8127f Mon Sep 17 00:00:00 2001 From: linpz Date: Sat, 17 Jan 2026 17:03:49 +0800 Subject: [PATCH 2/2] Fix unittests of Charge --- source/source_esolver/esolver_of.cpp | 2 +- source/source_estate/test/CMakeLists.txt | 4 ++-- source/source_estate/test/elecstate_base_test.cpp | 14 +++++++------- .../test/elecstate_magnetism_test.cpp | 4 ++-- .../source_estate/test/elecstate_print_test.cpp | 4 ++-- source/source_estate/test/elecstate_pw_test.cpp | 15 +++++++-------- source/source_estate/test/potential_new_test.cpp | 4 ++-- source/source_estate/test_mpi/charge_mpi_test.cpp | 4 ++-- source/source_hamilt/module_xc/test/xc3_mock.h | 4 ++-- source/source_hsolver/test/test_hsolver_sdft.cpp | 4 ++-- source/source_io/test/read_wf2rho_pw_test.cpp | 4 ++-- 11 files changed, 31 insertions(+), 32 deletions(-) diff --git a/source/source_esolver/esolver_of.cpp b/source/source_esolver/esolver_of.cpp index c40eef9a48..05add90901 100644 --- a/source/source_esolver/esolver_of.cpp +++ b/source/source_esolver/esolver_of.cpp @@ -250,7 +250,7 @@ void ESolver_OF::before_opt(const int istep, UnitCell& ucell) for (int ibs = 0; ibs < this->pw_rho->nrxx; ++ibs) { // Here we initialize rho to be uniform, - // because the rho got by pot.init_pot -> Charge::atomic_rho may contain minus elements. + // because the rho got by pot.init_pot -> Charge::atomic_rho may contain minus elements. this->chr.rho[is][ibs] = this->nelec_[is] / ucell.omega; this->pphi_[is][ibs] = sqrt(this->chr.rho[is][ibs]); } diff --git a/source/source_estate/test/CMakeLists.txt b/source/source_estate/test/CMakeLists.txt index f3eddac1a9..e9260d039f 100644 --- a/source/source_estate/test/CMakeLists.txt +++ b/source/source_estate/test/CMakeLists.txt @@ -38,7 +38,7 @@ AddTest( AddTest( TARGET elecstate_print LIBS parameter ${math_libs} base device - SOURCES elecstate_print_test.cpp ../elecstate_print.cpp ../occupy.cpp + SOURCES elecstate_print_test.cpp ../elecstate_print.cpp ../occupy.cpp ../module_charge/charge.cpp ../module_charge/charge_init.cpp ) AddTest( @@ -81,7 +81,7 @@ AddTest( AddTest( TARGET charge_test LIBS parameter ${math_libs} planewave_serial base device cell_info - SOURCES charge_test.cpp ../module_charge/charge.cpp + SOURCES charge_test.cpp ../module_charge/charge.cpp ../module_charge/charge_init.cpp ../../source_io/output.cpp ) diff --git a/source/source_estate/test/elecstate_base_test.cpp b/source/source_estate/test/elecstate_base_test.cpp index 572cb566e9..f233f43db7 100644 --- a/source/source_estate/test/elecstate_base_test.cpp +++ b/source/source_estate/test/elecstate_base_test.cpp @@ -27,10 +27,10 @@ Potential::~Potential() { } } // namespace elecstate -Charge::Charge() +template Charge::Charge() { } -Charge::~Charge() +template Charge::~Charge() { } UnitCell::UnitCell() @@ -77,10 +77,10 @@ void ModulePW::PW_Basis::initgrids(double, ModuleBase::Matrix3, int, int, int) void ModulePW::PW_Basis::distribute_r() { } -void Charge::set_rho_core(const UnitCell& ucell, ModuleBase::ComplexMatrix const&, const bool*) +template void Charge::set_rho_core(const UnitCell& ucell, ModuleBase::ComplexMatrix const&, const bool*) { } -void Charge::init_rho(const UnitCell&, +template void Charge::init_rho(const UnitCell&, const Parallel_Grid&, ModuleBase::ComplexMatrix const&, ModuleSymmetry::Symmetry& symm, @@ -88,13 +88,13 @@ void Charge::init_rho(const UnitCell&, const void*) { } -void Charge::set_rhopw(ModulePW::PW_Basis*) +template void Charge::set_rhopw(ModulePW::PW_Basis*) { } -void Charge::renormalize_rho() +template void Charge::renormalize_rho() { } -void Charge::check_rho() +template void Charge::check_rho() { } diff --git a/source/source_estate/test/elecstate_magnetism_test.cpp b/source/source_estate/test/elecstate_magnetism_test.cpp index 381a17e7f4..4ed2be8a5f 100644 --- a/source/source_estate/test/elecstate_magnetism_test.cpp +++ b/source/source_estate/test/elecstate_magnetism_test.cpp @@ -27,10 +27,10 @@ #define private public #include "source_estate/magnetism.h" #undef private -Charge::Charge() +template<> Charge::Charge() { } -Charge::~Charge() +template<> Charge::~Charge() { } diff --git a/source/source_estate/test/elecstate_print_test.cpp b/source/source_estate/test/elecstate_print_test.cpp index 20a4dd7c35..8dec790a57 100644 --- a/source/source_estate/test/elecstate_print_test.cpp +++ b/source/source_estate/test/elecstate_print_test.cpp @@ -31,10 +31,10 @@ Magnetism::Magnetism(){} Magnetism::~Magnetism(){} InfoNonlocal::InfoNonlocal(){} InfoNonlocal::~InfoNonlocal(){} -Charge::Charge() +template<> Charge::Charge() { } -Charge::~Charge() +template<> Charge::~Charge() { } SepPot::SepPot(){} diff --git a/source/source_estate/test/elecstate_pw_test.cpp b/source/source_estate/test/elecstate_pw_test.cpp index 714a2feb13..934219187d 100644 --- a/source/source_estate/test/elecstate_pw_test.cpp +++ b/source/source_estate/test/elecstate_pw_test.cpp @@ -25,10 +25,10 @@ Potential::~Potential() { } } // namespace elecstate -Charge::Charge() +template Charge::Charge() { } -Charge::~Charge() +template Charge::~Charge() { } UnitCell::UnitCell() @@ -126,11 +126,10 @@ Fcoef::~Fcoef() { } #include "source_cell/klist.h" - -void Charge::set_rho_core(const UnitCell& ucell, ModuleBase::ComplexMatrix const&, const bool*) +template void Charge::set_rho_core(const UnitCell& ucell, ModuleBase::ComplexMatrix const&, const bool*) { } -void Charge::init_rho(const UnitCell&, +template void Charge::init_rho(const UnitCell&, const Parallel_Grid&, ModuleBase::ComplexMatrix const&, ModuleSymmetry::Symmetry& symm, @@ -138,13 +137,13 @@ void Charge::init_rho(const UnitCell&, const void*) { } -void Charge::set_rhopw(ModulePW::PW_Basis*) +template void Charge::set_rhopw(ModulePW::PW_Basis*) { } -void Charge::renormalize_rho() +template void Charge::renormalize_rho() { } -void Charge::check_rho() +template void Charge::check_rho() { } diff --git a/source/source_estate/test/potential_new_test.cpp b/source/source_estate/test/potential_new_test.cpp index 8b96466eb0..fccaa5c445 100644 --- a/source/source_estate/test/potential_new_test.cpp +++ b/source/source_estate/test/potential_new_test.cpp @@ -36,10 +36,10 @@ InfoNonlocal::~InfoNonlocal() { } #endif -Charge::Charge() +template<> Charge::Charge() { } -Charge::~Charge() +template<> Charge::~Charge() { } surchem::surchem() diff --git a/source/source_estate/test_mpi/charge_mpi_test.cpp b/source/source_estate/test_mpi/charge_mpi_test.cpp index 848b3e12ec..3f20effadc 100644 --- a/source/source_estate/test_mpi/charge_mpi_test.cpp +++ b/source/source_estate/test_mpi/charge_mpi_test.cpp @@ -8,10 +8,10 @@ #include "source_io/module_parameter/parameter.h" bool XC_Functional::ked_flag = false; -Charge::Charge() +template<> Charge::Charge() { } -Charge::~Charge() +template<> Charge::~Charge() { delete[] rec; delete[] dis; diff --git a/source/source_hamilt/module_xc/test/xc3_mock.h b/source/source_hamilt/module_xc/test/xc3_mock.h index 84486f320d..ed91e09287 100644 --- a/source/source_hamilt/module_xc/test/xc3_mock.h +++ b/source/source_hamilt/module_xc/test/xc3_mock.h @@ -181,8 +181,8 @@ namespace GlobalC UnitCell::UnitCell(){}; UnitCell::~UnitCell(){}; -Charge::Charge(){}; -Charge::~Charge(){}; +template<> Charge::Charge(){}; +template<> Charge::~Charge(){}; Magnetism::Magnetism(){}; Magnetism::~Magnetism(){}; diff --git a/source/source_hsolver/test/test_hsolver_sdft.cpp b/source/source_hsolver/test/test_hsolver_sdft.cpp index 9d1f70e7e4..fd7a7b36d4 100644 --- a/source/source_hsolver/test/test_hsolver_sdft.cpp +++ b/source/source_hsolver/test/test_hsolver_sdft.cpp @@ -183,8 +183,8 @@ void Stochastic_Iter::cal_storho(const UnitCell& ucell, } template class Stochastic_Iter, base_device::DEVICE_CPU>; -Charge::Charge(){}; -Charge::~Charge(){}; +template<> Charge::Charge(){}; +template<> Charge::~Charge(){}; // Mock implementations for the template functions causing linking errors namespace ModulePW { diff --git a/source/source_io/test/read_wf2rho_pw_test.cpp b/source/source_io/test/read_wf2rho_pw_test.cpp index 84e5fa0df5..8527f9f03b 100644 --- a/source/source_io/test/read_wf2rho_pw_test.cpp +++ b/source/source_io/test/read_wf2rho_pw_test.cpp @@ -28,10 +28,10 @@ Parallel_Grid::Parallel_Grid() Parallel_Grid::~Parallel_Grid() { } -Charge::Charge() +template<> Charge::Charge() { } -Charge::~Charge() +template<> Charge::~Charge() { } UnitCell::UnitCell()