|
7 | 7 | #include "module_io/json_output/output_info.h" |
8 | 8 | #include "module_io/output_log.h" |
9 | 9 | #include "module_io/print_info.h" |
| 10 | +#include "module_io/rhog_io.h" |
10 | 11 | #include "module_io/write_istate_info.h" |
11 | 12 | #include "module_parameter/parameter.h" |
12 | 13 |
|
@@ -46,9 +47,6 @@ ESolver_KS<T, Device>::ESolver_KS() |
46 | 47 | maxniter = PARAM.inp.scf_nmax; |
47 | 48 | niter = maxniter; |
48 | 49 |
|
49 | | - // should not use GlobalV here, mohan 2024-05-12 |
50 | | - out_freq_elec = PARAM.inp.out_freq_elec; |
51 | | - |
52 | 50 | // pw_rho = new ModuleBase::PW_Basis(); |
53 | 51 | // temporary, it will be removed |
54 | 52 | std::string fft_device = PARAM.inp.device; |
@@ -693,42 +691,50 @@ void ESolver_KS<T, Device>::iter_finish(UnitCell& ucell, const int istep, int& i |
693 | 691 | std::cout << " SCF restart after this step!" << std::endl; |
694 | 692 | } |
695 | 693 |
|
696 | | - //! output charge density and density matrix |
697 | | - if (this->out_freq_elec && iter % this->out_freq_elec == 0) |
| 694 | + //! output charge density |
| 695 | + if (PARAM.inp.out_chg[0] != -1) |
698 | 696 | { |
699 | | - for (int is = 0; is < PARAM.inp.nspin; is++) |
| 697 | + if (iter % PARAM.inp.out_freq_elec == 0 || iter == PARAM.inp.scf_nmax || this->conv_esolver) |
700 | 698 | { |
701 | | - double* data = nullptr; |
702 | | - if (PARAM.inp.dm_to_rho) |
703 | | - { |
704 | | - data = this->pelec->charge->rho[is]; |
705 | | - } |
706 | | - else |
| 699 | + std::complex<double>** rhog_tot |
| 700 | + = (PARAM.inp.dm_to_rho) ? this->pelec->charge->rhog : this->pelec->charge->rhog_save; |
| 701 | + double** rhor_tot = (PARAM.inp.dm_to_rho) ? this->pelec->charge->rho : this->pelec->charge->rho_save; |
| 702 | + for (int is = 0; is < PARAM.inp.nspin; is++) |
707 | 703 | { |
708 | | - data = this->pelec->charge->rho_save[is]; |
| 704 | + this->pw_rhod->real2recip(rhor_tot[is], rhog_tot[is]); |
709 | 705 | } |
710 | | - std::string fn = PARAM.globalv.global_out_dir + "/tmp_SPIN" + std::to_string(is + 1) + "_CHG.cube"; |
711 | | - ModuleIO::write_vdata_palgrid(Pgrid, |
712 | | - data, |
713 | | - is, |
714 | | - PARAM.inp.nspin, |
715 | | - 0, |
716 | | - fn, |
717 | | - this->pelec->eferm.get_efval(is), |
718 | | - &(ucell), |
719 | | - 3, |
720 | | - 1); |
| 706 | + ModuleIO::write_rhog(PARAM.globalv.global_out_dir + PARAM.inp.suffix + "-CHARGE-DENSITY.restart", |
| 707 | + PARAM.globalv.gamma_only_pw || PARAM.globalv.gamma_only_local, |
| 708 | + this->pw_rhod, |
| 709 | + PARAM.inp.nspin, |
| 710 | + ucell.GT, |
| 711 | + rhog_tot, |
| 712 | + GlobalV::MY_POOL, |
| 713 | + GlobalV::RANK_IN_POOL, |
| 714 | + GlobalV::NPROC_IN_POOL); |
| 715 | + |
721 | 716 | if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5) |
722 | 717 | { |
723 | | - fn = PARAM.globalv.global_out_dir + "/tmp_SPIN" + std::to_string(is + 1) + "_TAU.cube"; |
724 | | - ModuleIO::write_vdata_palgrid(Pgrid, |
725 | | - this->pelec->charge->kin_r_save[is], |
726 | | - is, |
727 | | - PARAM.inp.nspin, |
728 | | - 0, |
729 | | - fn, |
730 | | - this->pelec->eferm.get_efval(is), |
731 | | - &(ucell)); |
| 718 | + std::complex<double>** kin_g = new std::complex<double>*[PARAM.inp.nspin]; |
| 719 | + for (int is = 0; is < PARAM.inp.nspin; is++) |
| 720 | + { |
| 721 | + kin_g[is] = new std::complex<double>[this->pelec->charge->ngmc]; |
| 722 | + this->pw_rhod->real2recip(this->pelec->charge->kin_r_save[is], kin_g[is]); |
| 723 | + } |
| 724 | + ModuleIO::write_rhog(PARAM.globalv.global_out_dir + PARAM.inp.suffix + "-TAU-DENSITY.restart", |
| 725 | + PARAM.globalv.gamma_only_pw || PARAM.globalv.gamma_only_local, |
| 726 | + this->pw_rhod, |
| 727 | + PARAM.inp.nspin, |
| 728 | + ucell.GT, |
| 729 | + kin_g, |
| 730 | + GlobalV::MY_POOL, |
| 731 | + GlobalV::RANK_IN_POOL, |
| 732 | + GlobalV::NPROC_IN_POOL); |
| 733 | + for (int is = 0; is < PARAM.inp.nspin; is++) |
| 734 | + { |
| 735 | + delete[] kin_g[is]; |
| 736 | + } |
| 737 | + delete[] kin_g; |
732 | 738 | } |
733 | 739 | } |
734 | 740 | } |
|
0 commit comments