diff --git a/source/driver_run.cpp b/source/driver_run.cpp index e379673e63..371310dbbc 100644 --- a/source/driver_run.cpp +++ b/source/driver_run.cpp @@ -27,9 +27,8 @@ void Driver::driver_run() { ModuleBase::TITLE("Driver", "driver_line"); ModuleBase::timer::tick("Driver", "driver_line"); - //! 1: initialize the ESolver - ModuleESolver::ESolver* p_esolver = nullptr; - ModuleESolver::init_esolver(p_esolver); + //! 1: initialize the ESolver + ModuleESolver::ESolver *p_esolver = ModuleESolver::init_esolver(); //! 2: setup cell and atom information diff --git a/source/module_elecstate/potentials/H_Hartree_pw.cpp b/source/module_elecstate/potentials/H_Hartree_pw.cpp index 055c3f6ade..d7ff3d4cd5 100644 --- a/source/module_elecstate/potentials/H_Hartree_pw.cpp +++ b/source/module_elecstate/potentials/H_Hartree_pw.cpp @@ -100,7 +100,7 @@ PotHartree::PotHartree(const ModulePW::PW_Basis* rho_basis_in) this->fixed_mode = false; } -void PotHartree::cal_v_eff(const Charge* chg, const UnitCell* ucell, ModuleBase::matrix& v_eff) +void PotHartree::cal_v_eff(const Charge*const chg, const UnitCell*const ucell, ModuleBase::matrix& v_eff) { if(GlobalV::use_paw) { diff --git a/source/module_elecstate/potentials/H_Hartree_pw.h b/source/module_elecstate/potentials/H_Hartree_pw.h index ec0685ea67..aed9eced2b 100644 --- a/source/module_elecstate/potentials/H_Hartree_pw.h +++ b/source/module_elecstate/potentials/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* chg, const UnitCell* 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/module_elecstate/potentials/pot_base.h b/source/module_elecstate/potentials/pot_base.h index b55c6f7924..2f91793612 100644 --- a/source/module_elecstate/potentials/pot_base.h +++ b/source/module_elecstate/potentials/pot_base.h @@ -21,18 +21,12 @@ namespace elecstate class PotBase { public: - PotBase(){}; - virtual ~PotBase(){}; - - virtual void cal_v_eff(const Charge* chg, const UnitCell* ucell, ModuleBase::matrix& v_eff) - { - return; - } - - virtual void cal_fixed_v(double* vl_pseudo) - { - return; - } + PotBase(){} + virtual ~PotBase(){} + + 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){} bool fixed_mode = 0; bool dynamic_mode = 0; diff --git a/source/module_elecstate/potentials/pot_surchem.hpp b/source/module_elecstate/potentials/pot_surchem.hpp index f03b2c0d51..f0ff3e1bc2 100644 --- a/source/module_elecstate/potentials/pot_surchem.hpp +++ b/source/module_elecstate/potentials/pot_surchem.hpp @@ -31,7 +31,7 @@ class PotSurChem : public PotBase } } - void cal_v_eff(const Charge* chg, const UnitCell* 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/module_elecstate/potentials/pot_xc.cpp b/source/module_elecstate/potentials/pot_xc.cpp index fdff9edfee..e2df13b7d6 100644 --- a/source/module_elecstate/potentials/pot_xc.cpp +++ b/source/module_elecstate/potentials/pot_xc.cpp @@ -6,7 +6,7 @@ namespace elecstate { -void PotXC::cal_v_eff(const Charge* chg, const UnitCell* 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_v_eff"); ModuleBase::timer::tick("PotXC", "cal_v_eff"); diff --git a/source/module_elecstate/potentials/pot_xc.h b/source/module_elecstate/potentials/pot_xc.h index 70f3bc2eb5..976dcfa58d 100644 --- a/source/module_elecstate/potentials/pot_xc.h +++ b/source/module_elecstate/potentials/pot_xc.h @@ -23,7 +23,7 @@ class PotXC : public PotBase this->fixed_mode = false; } - void cal_v_eff(const Charge* chg, const UnitCell* 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/module_elecstate/potentials/potential_new.cpp b/source/module_elecstate/potentials/potential_new.cpp index 612bed0bb3..38c19dc888 100644 --- a/source/module_elecstate/potentials/potential_new.cpp +++ b/source/module_elecstate/potentials/potential_new.cpp @@ -149,7 +149,7 @@ void Potential::allocate() } } -void Potential::update_from_charge(const Charge* chg, const UnitCell* 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"); @@ -243,11 +243,11 @@ void Potential::cal_fixed_v(double* vl_pseudo) ModuleBase::timer::tick("Potential", "cal_fixed_v"); } -void Potential::cal_v_eff(const Charge* chg, const UnitCell* 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_v_eff"); - int nspin_current = this->v_effective.nr; - int nrxx = this->v_effective.nc; + const int nspin_current = this->v_effective.nr; + const int nrxx = this->v_effective.nc; ModuleBase::timer::tick("Potential", "cal_v_eff"); // first of all, set v_effective to zero. this->v_effective.zero_out(); @@ -275,7 +275,7 @@ void Potential::cal_v_eff(const Charge* chg, const UnitCell* ucell, ModuleBase:: ModuleBase::timer::tick("Potential", "cal_v_eff"); } -void Potential::init_pot(int istep, const Charge* chg) +void Potential::init_pot(int istep, const Charge*const chg) { ModuleBase::TITLE("Potential", "init_pot"); ModuleBase::timer::tick("Potential", "init_pot"); diff --git a/source/module_elecstate/potentials/potential_new.h b/source/module_elecstate/potentials/potential_new.h index 0a44a1fdb1..121ba77130 100644 --- a/source/module_elecstate/potentials/potential_new.h +++ b/source/module_elecstate/potentials/potential_new.h @@ -63,11 +63,11 @@ class Potential : public PotBase ~Potential(); // initialize potential when SCF begin - void init_pot(int istep, const Charge* chg); + void init_pot(int istep, const Charge*const chg); // initialize potential components before SCF void pot_register(std::vector& components_list); // update potential from current charge - void update_from_charge(const Charge* chg, const UnitCell* 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); @@ -170,7 +170,7 @@ class Potential : public PotBase } private: - void cal_v_eff(const Charge* chg, const UnitCell* 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/module_esolver/esolver.cpp b/source/module_esolver/esolver.cpp index 8b5ae5c610..e0199352d7 100644 --- a/source/module_esolver/esolver.cpp +++ b/source/module_esolver/esolver.cpp @@ -10,13 +10,14 @@ #include "esolver_lj.h" #include "esolver_of.h" #include "module_md/md_para.h" +#include namespace ModuleESolver { void ESolver::printname(void) { - std::cout << classname << std::endl; + std::cout << classname << std::endl; } std::string determine_type(void) @@ -85,14 +86,14 @@ std::string determine_type(void) auto device_info = GlobalV::device_flag; - for (char &c : device_info) + for (char &c : device_info) { - if (std::islower(c)) + if (std::islower(c)) { c = std::toupper(c); } } - if (GlobalV::MY_RANK == 0) + if (GlobalV::MY_RANK == 0) { std::cout << " RUNNING WITH DEVICE : " << device_info << " / " << base_device::information::get_device_info(GlobalV::device_flag) << std::endl; @@ -106,74 +107,74 @@ std::string determine_type(void) //Some API to operate E_Solver -void init_esolver(ESolver*& p_esolver) +ESolver* init_esolver() { //determine type of esolver based on INPUT information - std::string esolver_type = determine_type(); + const std::string esolver_type = determine_type(); //initialize the corresponding Esolver child class if (esolver_type == "ksdft_pw") { #if ((defined __CUDA) || (defined __ROCM)) - if (GlobalV::device_flag == "gpu") + if (GlobalV::device_flag == "gpu") { - if (GlobalV::precision_flag == "single") + if (GlobalV::precision_flag == "single") { - p_esolver = new ESolver_KS_PW, base_device::DEVICE_GPU>(); - } - else + return new ESolver_KS_PW, base_device::DEVICE_GPU>(); + } + else { - p_esolver = new ESolver_KS_PW, base_device::DEVICE_GPU>(); - } - return; + return new ESolver_KS_PW, base_device::DEVICE_GPU>(); + } } #endif - if (GlobalV::precision_flag == "single") + if (GlobalV::precision_flag == "single") { - p_esolver = new ESolver_KS_PW, base_device::DEVICE_CPU>(); - } - else + return new ESolver_KS_PW, base_device::DEVICE_CPU>(); + } + else { - p_esolver = new ESolver_KS_PW, base_device::DEVICE_CPU>(); - } - } + return new ESolver_KS_PW, base_device::DEVICE_CPU>(); + } + } #ifdef __LCAO else if (esolver_type == "ksdft_lcao") { if (GlobalV::GAMMA_ONLY_LOCAL) { - p_esolver = new ESolver_KS_LCAO(); + return new ESolver_KS_LCAO(); } else if (GlobalV::NSPIN < 4) { - p_esolver = new ESolver_KS_LCAO, double>(); + return new ESolver_KS_LCAO, double>(); } else { - p_esolver = new ESolver_KS_LCAO, std::complex>(); + return new ESolver_KS_LCAO, std::complex>(); } } else if (esolver_type == "ksdft_lcao_tddft") { - p_esolver = new ESolver_KS_LCAO_TDDFT(); + return new ESolver_KS_LCAO_TDDFT(); } #endif else if (esolver_type == "sdft_pw") { - p_esolver = new ESolver_SDFT_PW(); + return new ESolver_SDFT_PW(); } else if(esolver_type == "ofdft") { - p_esolver = new ESolver_OF(); + return new ESolver_OF(); } else if (esolver_type == "lj_pot") { - p_esolver = new ESolver_LJ(); + return new ESolver_LJ(); } else if (esolver_type == "dp_pot") { - p_esolver = new ESolver_DP(INPUT.mdp.pot_file); + return new ESolver_DP(INPUT.mdp.pot_file); } + throw std::invalid_argument("esolver_type = "+std::string(esolver_type)+". Wrong in "+std::string(__FILE__)+" line "+std::to_string(__LINE__)); } diff --git a/source/module_esolver/esolver.h b/source/module_esolver/esolver.h index af7d870b7e..2895b01be0 100644 --- a/source/module_esolver/esolver.h +++ b/source/module_esolver/esolver.h @@ -82,9 +82,9 @@ std::string determine_type(void); * the corresponding ESolver child class. It supports various ESolver types including ksdft_pw, * ksdft_lcao, ksdft_lcao_tddft, sdft_pw, ofdft, lj_pot, and dp_pot. * - * @param [in, out] p_esolver A pointer to an ESolver object that will be initialized. + * @return [out] A pointer to an ESolver object that will be initialized. */ -void init_esolver(ESolver*& p_esolver); +ESolver* init_esolver(); void clean_esolver(ESolver*& pesolver);