Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions docs/advanced/input_files/input-main.md
Original file line number Diff line number Diff line change
Expand Up @@ -1561,10 +1561,8 @@ These variables are used to control the output of properties.
### out_freq_elec

- **Type**: Integer
- **Description**: The output frequency of the charge density (controlled by [out_chg](#out_chg)), wavefunction (controlled by [out_wfc_pw](#out_wfc_pw) or [out_wfc_r](#out_wfc_r)), and density matrix of localized orbitals (controlled by [out_dm](#out_dm)).
- \>0: Output them every `out_freq_elec` iteration numbers in electronic iterations.
- 0: Output them when the electronic iteration is converged or reaches the maximal iteration number.
- **Default**: 0
- **Description**: Output the charge density (only binary format, controlled by [out_chg](#out_chg)), wavefunction (controlled by [out_wfc_pw](#out_wfc_pw) or [out_wfc_r](#out_wfc_r)) per `out_freq_elec` electronic iterations. Note that they are always output when converged or reach the maximum iterations [scf_nmax](#scf_nmax).
- **Default**: [scf_nmax](#scf_nmax)

### out_chg

Expand Down
18 changes: 0 additions & 18 deletions source/module_esolver/esolver_fp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,24 +183,6 @@ void ESolver_FP::after_scf(UnitCell& ucell, const int istep)
}
}
}
if (PARAM.inp.out_chg[0] != -1)
{
std::complex<double>** rhog_tot = (PARAM.inp.dm_to_rho)? this->pelec->charge->rhog : this->pelec->charge->rhog_save;
double** rhor_tot = (PARAM.inp.dm_to_rho)? this->pelec->charge->rho : this->pelec->charge->rho_save;
for (int is = 0; is < PARAM.inp.nspin; is++)
{
this->pw_rhod->real2recip(rhor_tot[is], rhog_tot[is]);
}
ModuleIO::write_rhog(PARAM.globalv.global_out_dir + PARAM.inp.suffix + "-CHARGE-DENSITY.restart",
PARAM.globalv.gamma_only_pw || PARAM.globalv.gamma_only_local,
this->pw_rhod,
PARAM.inp.nspin,
ucell.GT,
rhog_tot,
GlobalV::MY_POOL,
GlobalV::RANK_IN_POOL,
GlobalV::NPROC_IN_POOL);
}

// 4) write potential
if (PARAM.inp.out_pot == 1 || PARAM.inp.out_pot == 3)
Expand Down
72 changes: 39 additions & 33 deletions source/module_esolver/esolver_ks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "module_io/json_output/output_info.h"
#include "module_io/output_log.h"
#include "module_io/print_info.h"
#include "module_io/rhog_io.h"
#include "module_io/write_istate_info.h"
#include "module_parameter/parameter.h"

Expand Down Expand Up @@ -46,9 +47,6 @@ ESolver_KS<T, Device>::ESolver_KS()
maxniter = PARAM.inp.scf_nmax;
niter = maxniter;

// should not use GlobalV here, mohan 2024-05-12
out_freq_elec = PARAM.inp.out_freq_elec;

// pw_rho = new ModuleBase::PW_Basis();
// temporary, it will be removed
std::string fft_device = PARAM.inp.device;
Expand Down Expand Up @@ -693,42 +691,50 @@ void ESolver_KS<T, Device>::iter_finish(UnitCell& ucell, const int istep, int& i
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)
//! output charge density
if (PARAM.inp.out_chg[0] != -1)
{
for (int is = 0; is < PARAM.inp.nspin; is++)
if (iter % PARAM.inp.out_freq_elec == 0 || iter == PARAM.inp.scf_nmax || this->conv_esolver)
{
double* data = nullptr;
if (PARAM.inp.dm_to_rho)
{
data = this->pelec->charge->rho[is];
}
else
std::complex<double>** rhog_tot
= (PARAM.inp.dm_to_rho) ? this->pelec->charge->rhog : this->pelec->charge->rhog_save;
double** rhor_tot = (PARAM.inp.dm_to_rho) ? this->pelec->charge->rho : this->pelec->charge->rho_save;
for (int is = 0; is < PARAM.inp.nspin; is++)
{
data = this->pelec->charge->rho_save[is];
this->pw_rhod->real2recip(rhor_tot[is], rhog_tot[is]);
}
std::string fn = PARAM.globalv.global_out_dir + "/tmp_SPIN" + std::to_string(is + 1) + "_CHG.cube";
ModuleIO::write_vdata_palgrid(Pgrid,
data,
is,
PARAM.inp.nspin,
0,
fn,
this->pelec->eferm.get_efval(is),
&(ucell),
3,
1);
ModuleIO::write_rhog(PARAM.globalv.global_out_dir + PARAM.inp.suffix + "-CHARGE-DENSITY.restart",
PARAM.globalv.gamma_only_pw || PARAM.globalv.gamma_only_local,
this->pw_rhod,
PARAM.inp.nspin,
ucell.GT,
rhog_tot,
GlobalV::MY_POOL,
GlobalV::RANK_IN_POOL,
GlobalV::NPROC_IN_POOL);

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(Pgrid,
this->pelec->charge->kin_r_save[is],
is,
PARAM.inp.nspin,
0,
fn,
this->pelec->eferm.get_efval(is),
&(ucell));
std::complex<double>** kin_g = new std::complex<double>*[PARAM.inp.nspin];
for (int is = 0; is < PARAM.inp.nspin; is++)
{
kin_g[is] = new std::complex<double>[this->pelec->charge->ngmc];
this->pw_rhod->real2recip(this->pelec->charge->kin_r_save[is], kin_g[is]);
}
ModuleIO::write_rhog(PARAM.globalv.global_out_dir + PARAM.inp.suffix + "-TAU-DENSITY.restart",
PARAM.globalv.gamma_only_pw || PARAM.globalv.gamma_only_local,
this->pw_rhod,
PARAM.inp.nspin,
ucell.GT,
kin_g,
GlobalV::MY_POOL,
GlobalV::RANK_IN_POOL,
GlobalV::NPROC_IN_POOL);
for (int is = 0; is < PARAM.inp.nspin; is++)
{
delete[] kin_g[is];
}
delete[] kin_g;
}
}
}
Expand Down
1 change: 0 additions & 1 deletion source/module_esolver/esolver_ks.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ class ESolver_KS : public ESolver_FP
double hsolver_error; //! the error of HSolver
int maxniter; //! maximum iter steps for scf
int niter; //! iter steps actually used in scf
int out_freq_elec; //! frequency for output
};
} // namespace ModuleESolver
#endif
6 changes: 3 additions & 3 deletions source/module_esolver/esolver_ks_pw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,10 +617,10 @@ void ESolver_KS_PW<T, Device>::iter_finish(UnitCell& ucell, const int istep, int
this->ppcell.cal_effective_D(veff, this->pw_rhod, ucell);
}

if (this->out_freq_elec && iter % this->out_freq_elec == 0)
// 4) Print out electronic wavefunctions
if (PARAM.inp.out_wfc_pw == 1 || PARAM.inp.out_wfc_pw == 2)
{
// 4) Print out electronic wavefunctions
if (PARAM.inp.out_wfc_pw == 1 || PARAM.inp.out_wfc_pw == 2)
if (iter % PARAM.inp.out_freq_elec == 0 || iter == PARAM.inp.scf_nmax || this->conv_esolver)
{
std::stringstream ssw;
ssw << PARAM.globalv.global_out_dir << "WAVEFUNC";
Expand Down
10 changes: 7 additions & 3 deletions source/module_io/read_input_item_output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ void ReadInput::item_output()
}
{
Input_Item item("out_freq_elec");
item.annotation = "the frequency ( >= 0) of electronic iter to output "
"charge density and wavefunction. 0: "
"output only when converged";
item.annotation = "the frequency of electronic iter to output charge density and wavefunction ";
item.reset_value = [](const Input_Item& item, Parameter& para) {
if (para.input.out_freq_elec <= 0)
{
para.input.out_freq_elec = para.input.scf_nmax;
}
};
read_sync_int(input.out_freq_elec);
this->add_item(item);
}
Expand Down
2 changes: 1 addition & 1 deletion source/module_io/test/read_input_ptest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ TEST_F(InputParaTest, ParaRead)
EXPECT_EQ(param.inp.printe, 100);
EXPECT_EQ(param.inp.init_chg, "atomic");
EXPECT_EQ(param.inp.chg_extrap, "atomic");
EXPECT_EQ(param.inp.out_freq_elec, 0);
EXPECT_EQ(param.inp.out_freq_elec, 50);
EXPECT_EQ(param.inp.out_freq_ion, 0);
EXPECT_EQ(param.inp.out_chg[0], 0);
EXPECT_EQ(param.inp.out_chg[1], 3);
Expand Down
3 changes: 1 addition & 2 deletions source/module_parameter/input_parameter.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,7 @@ struct Input_para
std::vector<int> aims_nbasis = {}; ///< the number of basis functions for each atom type used in FHI-aims (for benchmark)
// ============== #Parameters (11.Output) ===========================
bool out_stru = false; ///< outut stru file each ion step
int out_freq_elec = 0; ///< the frequency ( >= 0) of electronic iter to output charge
///< 0: output only when converged
int out_freq_elec = 0; ///< the frequency of electronic iter to output charge and wavefunction
int out_freq_ion = 0; ///< the frequency ( >= 0 ) of ionic step to output charge density;
///< 0: output only when ion steps are finished
std::vector<int> out_chg = {0, 3}; ///< output charge density. 0: no; 1: yes
Expand Down
Loading