Skip to content

Commit 7e9d081

Browse files
authored
Refactor: move tmp charge density output to esolver_ks (#5592)
1 parent 0f37fe5 commit 7e9d081

File tree

3 files changed

+41
-80
lines changed

3 files changed

+41
-80
lines changed

source/module_esolver/esolver_ks.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "module_base/timer.h"
44
#include "module_cell/cal_atoms_info.h"
5+
#include "module_io/cube_io.h"
56
#include "module_io/json_output/init_info.h"
67
#include "module_io/json_output/output_info.h"
78
#include "module_io/output_log.h"
@@ -679,6 +680,46 @@ void ESolver_KS<T, Device>::iter_finish(UnitCell& ucell, const int istep, int& i
679680
this->p_chgmix->mixing_restart_last = iter;
680681
std::cout << " SCF restart after this step!" << std::endl;
681682
}
683+
684+
//! output charge density and density matrix
685+
if (this->out_freq_elec && iter % this->out_freq_elec == 0)
686+
{
687+
for (int is = 0; is < PARAM.inp.nspin; is++)
688+
{
689+
double* data = nullptr;
690+
if (PARAM.inp.dm_to_rho)
691+
{
692+
data = this->pelec->charge->rho[is];
693+
}
694+
else
695+
{
696+
data = this->pelec->charge->rho_save[is];
697+
}
698+
std::string fn = PARAM.globalv.global_out_dir + "/tmp_SPIN" + std::to_string(is + 1) + "_CHG.cube";
699+
ModuleIO::write_vdata_palgrid(GlobalC::Pgrid,
700+
data,
701+
is,
702+
PARAM.inp.nspin,
703+
0,
704+
fn,
705+
this->pelec->eferm.get_efval(is),
706+
&(ucell),
707+
3,
708+
1);
709+
if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5)
710+
{
711+
fn = PARAM.globalv.global_out_dir + "/tmp_SPIN" + std::to_string(is + 1) + "_TAU.cube";
712+
ModuleIO::write_vdata_palgrid(GlobalC::Pgrid,
713+
this->pelec->charge->kin_r_save[is],
714+
is,
715+
PARAM.inp.nspin,
716+
0,
717+
fn,
718+
this->pelec->eferm.get_efval(is),
719+
&(ucell));
720+
}
721+
}
722+
}
682723
}
683724

684725
//! Something to do after SCF iterations when SCF is converged or comes to the max iter step.

source/module_esolver/esolver_ks_lcao.cpp

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -939,46 +939,6 @@ void ESolver_KS_LCAO<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int&
939939
}
940940
#endif
941941

942-
// 4) output charge density and density matrix
943-
if (this->out_freq_elec && iter % this->out_freq_elec == 0)
944-
{
945-
for (int is = 0; is < PARAM.inp.nspin; is++)
946-
{
947-
double* data = nullptr;
948-
if (PARAM.inp.dm_to_rho)
949-
{
950-
data = this->pelec->charge->rho[is];
951-
}
952-
else
953-
{
954-
data = this->pelec->charge->rho_save[is];
955-
}
956-
std::string fn = PARAM.globalv.global_out_dir + "/tmp_SPIN" + std::to_string(is + 1) + "_CHG.cube";
957-
ModuleIO::write_vdata_palgrid(GlobalC::Pgrid,
958-
data,
959-
is,
960-
PARAM.inp.nspin,
961-
0,
962-
fn,
963-
this->pelec->eferm.get_efval(is),
964-
&(ucell),
965-
3,
966-
1);
967-
if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5)
968-
{
969-
fn = PARAM.globalv.global_out_dir + "/tmp_SPIN" + std::to_string(is + 1) + "_TAU.cube";
970-
ModuleIO::write_vdata_palgrid(GlobalC::Pgrid,
971-
this->pelec->charge->kin_r_save[is],
972-
is,
973-
PARAM.inp.nspin,
974-
0,
975-
fn,
976-
this->pelec->eferm.get_efval(is),
977-
&(ucell));
978-
}
979-
}
980-
}
981-
982942
// 6) use the converged occupation matrix for next MD/Relax SCF calculation
983943
if (PARAM.inp.dft_plus_u && this->conv_esolver)
984944
{

source/module_esolver/esolver_ks_pw.cpp

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -502,48 +502,8 @@ void ESolver_KS_PW<T, Device>::iter_finish(UnitCell& ucell, const int istep, int
502502
GlobalC::ppcell.cal_effective_D(veff, this->pw_rhod, ucell);
503503
}
504504

505-
// 3) Print out charge density
506505
if (this->out_freq_elec && iter % this->out_freq_elec == 0)
507506
{
508-
if (PARAM.inp.out_chg[0] > 0)
509-
{
510-
for (int is = 0; is < PARAM.inp.nspin; is++)
511-
{
512-
double* data = nullptr;
513-
if (PARAM.inp.dm_to_rho)
514-
{
515-
data = this->pelec->charge->rho[is];
516-
}
517-
else
518-
{
519-
data = this->pelec->charge->rho_save[is];
520-
}
521-
std::string fn = PARAM.globalv.global_out_dir + "/tmp_SPIN" + std::to_string(is + 1) + "_CHG.cube";
522-
ModuleIO::write_vdata_palgrid(GlobalC::Pgrid,
523-
data,
524-
is,
525-
PARAM.inp.nspin,
526-
0,
527-
fn,
528-
this->pelec->eferm.get_efval(is),
529-
&(ucell),
530-
3,
531-
1);
532-
if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5)
533-
{
534-
fn = PARAM.globalv.global_out_dir + "/tmp_SPIN" + std::to_string(is + 1) + "_TAU.cube";
535-
ModuleIO::write_vdata_palgrid(GlobalC::Pgrid,
536-
this->pelec->charge->kin_r_save[is],
537-
is,
538-
PARAM.inp.nspin,
539-
0,
540-
fn,
541-
this->pelec->eferm.get_efval(is),
542-
&(ucell));
543-
}
544-
}
545-
}
546-
547507
// 4) Print out electronic wavefunctions
548508
if (PARAM.inp.out_wfc_pw == 1 || PARAM.inp.out_wfc_pw == 2)
549509
{

0 commit comments

Comments
 (0)