diff --git a/source/module_esolver/esolver_ks.cpp b/source/module_esolver/esolver_ks.cpp index a3f9d91710..65d2796d48 100644 --- a/source/module_esolver/esolver_ks.cpp +++ b/source/module_esolver/esolver_ks.cpp @@ -2,6 +2,7 @@ #include "module_base/timer.h" #include "module_cell/cal_atoms_info.h" +#include "module_io/cube_io.h" #include "module_io/json_output/init_info.h" #include "module_io/json_output/output_info.h" #include "module_io/output_log.h" @@ -679,6 +680,46 @@ void ESolver_KS::iter_finish(UnitCell& ucell, const int istep, int& i this->p_chgmix->mixing_restart_last = iter; std::cout << " SCF restart after this step!" << std::endl; } + + //! output charge density and density matrix + if (this->out_freq_elec && iter % this->out_freq_elec == 0) + { + for (int is = 0; is < PARAM.inp.nspin; is++) + { + double* data = nullptr; + if (PARAM.inp.dm_to_rho) + { + data = this->pelec->charge->rho[is]; + } + else + { + data = this->pelec->charge->rho_save[is]; + } + std::string fn = PARAM.globalv.global_out_dir + "/tmp_SPIN" + std::to_string(is + 1) + "_CHG.cube"; + ModuleIO::write_vdata_palgrid(GlobalC::Pgrid, + data, + is, + PARAM.inp.nspin, + 0, + fn, + this->pelec->eferm.get_efval(is), + &(ucell), + 3, + 1); + if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5) + { + fn = PARAM.globalv.global_out_dir + "/tmp_SPIN" + std::to_string(is + 1) + "_TAU.cube"; + ModuleIO::write_vdata_palgrid(GlobalC::Pgrid, + this->pelec->charge->kin_r_save[is], + is, + PARAM.inp.nspin, + 0, + fn, + this->pelec->eferm.get_efval(is), + &(ucell)); + } + } + } } //! Something to do after SCF iterations when SCF is converged or comes to the max iter step. diff --git a/source/module_esolver/esolver_ks_lcao.cpp b/source/module_esolver/esolver_ks_lcao.cpp index ef884e1c5b..f18957c01c 100644 --- a/source/module_esolver/esolver_ks_lcao.cpp +++ b/source/module_esolver/esolver_ks_lcao.cpp @@ -939,46 +939,6 @@ void ESolver_KS_LCAO::iter_finish(UnitCell& ucell, const int istep, int& } #endif - // 4) output charge density and density matrix - if (this->out_freq_elec && iter % this->out_freq_elec == 0) - { - for (int is = 0; is < PARAM.inp.nspin; is++) - { - double* data = nullptr; - if (PARAM.inp.dm_to_rho) - { - data = this->pelec->charge->rho[is]; - } - else - { - data = this->pelec->charge->rho_save[is]; - } - std::string fn = PARAM.globalv.global_out_dir + "/tmp_SPIN" + std::to_string(is + 1) + "_CHG.cube"; - ModuleIO::write_vdata_palgrid(GlobalC::Pgrid, - data, - is, - PARAM.inp.nspin, - 0, - fn, - this->pelec->eferm.get_efval(is), - &(ucell), - 3, - 1); - if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5) - { - fn = PARAM.globalv.global_out_dir + "/tmp_SPIN" + std::to_string(is + 1) + "_TAU.cube"; - ModuleIO::write_vdata_palgrid(GlobalC::Pgrid, - this->pelec->charge->kin_r_save[is], - is, - PARAM.inp.nspin, - 0, - fn, - this->pelec->eferm.get_efval(is), - &(ucell)); - } - } - } - // 6) use the converged occupation matrix for next MD/Relax SCF calculation if (PARAM.inp.dft_plus_u && this->conv_esolver) { diff --git a/source/module_esolver/esolver_ks_pw.cpp b/source/module_esolver/esolver_ks_pw.cpp index 30b1507265..d32c4790f9 100644 --- a/source/module_esolver/esolver_ks_pw.cpp +++ b/source/module_esolver/esolver_ks_pw.cpp @@ -502,48 +502,8 @@ void ESolver_KS_PW::iter_finish(UnitCell& ucell, const int istep, int GlobalC::ppcell.cal_effective_D(veff, this->pw_rhod, ucell); } - // 3) Print out charge density if (this->out_freq_elec && iter % this->out_freq_elec == 0) { - if (PARAM.inp.out_chg[0] > 0) - { - for (int is = 0; is < PARAM.inp.nspin; is++) - { - double* data = nullptr; - if (PARAM.inp.dm_to_rho) - { - data = this->pelec->charge->rho[is]; - } - else - { - data = this->pelec->charge->rho_save[is]; - } - std::string fn = PARAM.globalv.global_out_dir + "/tmp_SPIN" + std::to_string(is + 1) + "_CHG.cube"; - ModuleIO::write_vdata_palgrid(GlobalC::Pgrid, - data, - is, - PARAM.inp.nspin, - 0, - fn, - this->pelec->eferm.get_efval(is), - &(ucell), - 3, - 1); - if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5) - { - fn = PARAM.globalv.global_out_dir + "/tmp_SPIN" + std::to_string(is + 1) + "_TAU.cube"; - ModuleIO::write_vdata_palgrid(GlobalC::Pgrid, - this->pelec->charge->kin_r_save[is], - is, - PARAM.inp.nspin, - 0, - fn, - this->pelec->eferm.get_efval(is), - &(ucell)); - } - } - } - // 4) Print out electronic wavefunctions if (PARAM.inp.out_wfc_pw == 1 || PARAM.inp.out_wfc_pw == 2) {