Skip to content

Commit 5b01bab

Browse files
committed
move backup charge density output to esolver_fp
1 parent d6d61ed commit 5b01bab

File tree

4 files changed

+53
-48
lines changed

4 files changed

+53
-48
lines changed

source/module_esolver/esolver_fp.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,4 +286,51 @@ void ESolver_FP::before_scf(UnitCell& ucell, const int istep)
286286
return;
287287
}
288288

289+
void ESolver_FP::iter_finish(UnitCell& ucell, const int istep, int& iter)
290+
{
291+
//! output charge density
292+
if (PARAM.inp.out_chg[0] != -1)
293+
{
294+
if (iter % PARAM.inp.out_freq_elec == 0 || iter == PARAM.inp.scf_nmax || this->conv_esolver)
295+
{
296+
std::complex<double>** rhog_tot
297+
= (PARAM.inp.dm_to_rho) ? this->pelec->charge->rhog : this->pelec->charge->rhog_save;
298+
double** rhor_tot = (PARAM.inp.dm_to_rho) ? this->pelec->charge->rho : this->pelec->charge->rho_save;
299+
for (int is = 0; is < PARAM.inp.nspin; is++)
300+
{
301+
this->pw_rhod->real2recip(rhor_tot[is], rhog_tot[is]);
302+
}
303+
ModuleIO::write_rhog(PARAM.globalv.global_out_dir + PARAM.inp.suffix + "-CHARGE-DENSITY.restart",
304+
PARAM.globalv.gamma_only_pw || PARAM.globalv.gamma_only_local,
305+
this->pw_rhod,
306+
PARAM.inp.nspin,
307+
ucell.GT,
308+
rhog_tot,
309+
GlobalV::MY_POOL,
310+
GlobalV::RANK_IN_POOL,
311+
GlobalV::NPROC_IN_POOL);
312+
313+
if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5)
314+
{
315+
std::vector<std::complex<double>> kin_g_space(PARAM.inp.nspin * this->pelec->charge->ngmc, {0.0, 0.0});
316+
std::vector<std::complex<double>*> kin_g;
317+
for (int is = 0; is < PARAM.inp.nspin; is++)
318+
{
319+
kin_g.push_back(kin_g_space.data() + is * this->pelec->charge->ngmc);
320+
this->pw_rhod->real2recip(this->pelec->charge->kin_r_save[is], kin_g[is]);
321+
}
322+
ModuleIO::write_rhog(PARAM.globalv.global_out_dir + PARAM.inp.suffix + "-TAU-DENSITY.restart",
323+
PARAM.globalv.gamma_only_pw || PARAM.globalv.gamma_only_local,
324+
this->pw_rhod,
325+
PARAM.inp.nspin,
326+
ucell.GT,
327+
kin_g.data(),
328+
GlobalV::MY_POOL,
329+
GlobalV::RANK_IN_POOL,
330+
GlobalV::NPROC_IN_POOL);
331+
}
332+
}
333+
}
334+
}
335+
289336
} // namespace ModuleESolver

source/module_esolver/esolver_fp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ class ESolver_FP : public ESolver
4141
//! Something to do after SCF iterations when SCF is converged or comes to the max iter step.
4242
virtual void after_scf(UnitCell& ucell, const int istep);
4343

44+
//! Something to do after hamilt2density function in each iter loop.
45+
virtual void iter_finish(UnitCell& ucell, const int istep, int& iter);
46+
4447
//! ------------------------------------------------------------------------------
4548
//! These pointers will be deleted in the free_pointers() function every ion step.
4649
//! ------------------------------------------------------------------------------

source/module_esolver/esolver_ks.cpp

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include "module_io/json_output/output_info.h"
88
#include "module_io/output_log.h"
99
#include "module_io/print_info.h"
10-
#include "module_io/rhog_io.h"
1110
#include "module_io/write_istate_info.h"
1211
#include "module_parameter/parameter.h"
1312

@@ -691,53 +690,7 @@ void ESolver_KS<T, Device>::iter_finish(UnitCell& ucell, const int istep, int& i
691690
std::cout << " SCF restart after this step!" << std::endl;
692691
}
693692

694-
//! output charge density
695-
if (PARAM.inp.out_chg[0] != -1)
696-
{
697-
if (iter % PARAM.inp.out_freq_elec == 0 || iter == PARAM.inp.scf_nmax || this->conv_esolver)
698-
{
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++)
703-
{
704-
this->pw_rhod->real2recip(rhor_tot[is], rhog_tot[is]);
705-
}
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-
716-
if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5)
717-
{
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;
738-
}
739-
}
740-
}
693+
ESolver_FP::iter_finish(ucell, istep, iter);
741694
}
742695

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

source/module_esolver/esolver_of.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ void ESolver_OF::runner(UnitCell& ucell, const int istep)
182182
this->update_rho();
183183

184184
this->iter_++;
185+
186+
ESolver_FP::iter_finish(ucell, istep, this->iter_);
185187
}
186188

187189
this->after_opt(istep, ucell);

0 commit comments

Comments
 (0)