Skip to content

Commit

Permalink
Refactor: remove write_rho and output_rho
Browse files Browse the repository at this point in the history
  • Loading branch information
YuLiu98 committed Jul 30, 2024
1 parent 0f1b2b3 commit 06e208a
Show file tree
Hide file tree
Showing 17 changed files with 258 additions and 332 deletions.
2 changes: 0 additions & 2 deletions source/Makefile.Objects
Original file line number Diff line number Diff line change
Expand Up @@ -491,13 +491,11 @@ OBJS_IO=input_conv.o\
write_wfc_pw.o\
winput.o\
write_cube.o\
write_rho.o\
write_pot.o\
write_dipole.o\
td_current_io.o\
write_wfc_r.o\
output_log.o\
output_rho.o\
output_potential.o\
output_mat_sparse.o\
para_json.o\
Expand Down
61 changes: 0 additions & 61 deletions source/module_esolver/esolver_ks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -687,67 +687,6 @@ bool ESolver_KS<T, Device>::get_conv_elec()
return this->conv_elec;
}

//------------------------------------------------------------------------------
//! the 13th function of ESolver_KS: create_Output_Rho
//! mohan add 2024-05-12
//------------------------------------------------------------------------------
template <typename T, typename Device>
ModuleIO::Output_Rho ESolver_KS<T, Device>::create_Output_Rho(int is, int iter, const std::string& prefix)
{
const int precision = 3;
std::string tag = "CHG";
if (PARAM.inp.dm_to_rho)
{
return ModuleIO::Output_Rho(this->pw_big,
this->pw_rhod,
is,
GlobalV::NSPIN,
pelec->charge->rho[is],
iter,
this->pelec->eferm.get_efval(is),
&(GlobalC::ucell),
GlobalV::global_out_dir,
precision,
tag,
prefix);
}
return ModuleIO::Output_Rho(this->pw_big,
this->pw_rhod,
is,
GlobalV::NSPIN,
pelec->charge->rho_save[is],
iter,
this->pelec->eferm.get_efval(is),
&(GlobalC::ucell),
GlobalV::global_out_dir,
precision,
tag,
prefix);
}

//------------------------------------------------------------------------------
//! the 14th function of ESolver_KS: create_Output_Kin
//! mohan add 2024-05-12
//------------------------------------------------------------------------------
template <typename T, typename Device>
ModuleIO::Output_Rho ESolver_KS<T, Device>::create_Output_Kin(int is, int iter, const std::string& prefix)
{
const int precision = 11;
std::string tag = "TAU";
return ModuleIO::Output_Rho(this->pw_big,
this->pw_rhod,
is,
GlobalV::NSPIN,
pelec->charge->kin_r_save[is],
iter,
this->pelec->eferm.get_efval(is),
&(GlobalC::ucell),
GlobalV::global_out_dir,
precision,
tag,
prefix);
}

//------------------------------------------------------------------------------
//! the 15th function of ESolver_KS: create_Output_Potential
//! mohan add 2024-05-12
Expand Down
11 changes: 2 additions & 9 deletions source/module_esolver/esolver_ks.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "module_hsolver/hsolver.h"
#include "module_io/cal_test.h"
#include "module_io/output_potential.h"
#include "module_io/output_rho.h"
#include "module_psi/psi.h"

#include <fstream>
Expand Down Expand Up @@ -105,14 +104,8 @@ class ESolver_KS : public ESolver_FP
const int istep,
const int iter);

/// @brief create a new ModuleIO::Output_Rho object to output charge density
ModuleIO::Output_Rho create_Output_Rho(int is, int iter, const std::string& prefix="None");

/// @brief create a new ModuleIO::Output_Rho object to print kinetic energy density
ModuleIO::Output_Rho create_Output_Kin(int is, int iter, const std::string& prefix = "None");

/// @brief create a new ModuleIO::Output_Potential object to print potential
ModuleIO::Output_Potential create_Output_Potential(int iter, const std::string& prefix = "None");
/// @brief create a new ModuleIO::Output_Potential object to print potential
ModuleIO::Output_Potential create_Output_Potential(int iter, const std::string& prefix = "None");

//! Solve Hamitonian
hsolver::HSolver<T, Device>* phsol = nullptr;
Expand Down
101 changes: 96 additions & 5 deletions source/module_esolver/esolver_ks_lcao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "module_base/global_variable.h"
#include "module_base/tool_title.h"
#include "module_io/cube_io.h"
#include "module_io/dos_nao.h"
#include "module_io/nscf_band.h"
#include "module_io/output_dmk.h"
Expand All @@ -10,10 +11,10 @@
#include "module_io/output_sk.h"
#include "module_io/to_qo.h"
#include "module_io/write_HS.h"
#include "module_io/write_vxc.hpp"
#include "module_io/write_eband_terms.hpp"
#include "module_io/write_istate_info.h"
#include "module_io/write_proj_band_lcao.h"
#include "module_io/write_vxc.hpp"
#include "module_parameter/parameter.h"

//--------------temporary----------------------------
Expand Down Expand Up @@ -992,10 +993,55 @@ void ESolver_KS_LCAO<TK, TR>::iter_finish(int iter)
{
for (int is = 0; is < GlobalV::NSPIN; is++)
{
this->create_Output_Rho(is, iter, "tmp_").write();
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 = GlobalV::global_out_dir + "/tmp_SPIN" + std::to_string(is + 1) + "_CHG.cube";
ModuleIO::write_cube(
#ifdef __MPI
this->pw_big->bz,
this->pw_big->nbz,
this->pw_rhod->nplane,
this->pw_rhod->startz_current,
#endif
data,
is,
GlobalV::NSPIN,
iter,
fn,
this->pw_rhod->nx,
this->pw_rhod->ny,
this->pw_rhod->nz,
this->pelec->eferm.get_efval(is),
&(GlobalC::ucell),
3,
1);
if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5)
{
this->create_Output_Kin(is, iter, "tmp_").write();
fn = GlobalV::global_out_dir + "/tmp_SPIN" + std::to_string(is + 1) + "_TAU.cube";
ModuleIO::write_cube(
#ifdef __MPI
this->pw_big->bz,
this->pw_big->nbz,
this->pw_rhod->nplane,
this->pw_rhod->startz_current,
#endif
this->pelec->charge->kin_r_save[is],
is,
GlobalV::NSPIN,
iter,
fn,
this->pw_rhod->nx,
this->pw_rhod->ny,
this->pw_rhod->nz,
this->pelec->eferm.get_efval(is),
&(GlobalC::ucell));
}
}
}
Expand Down Expand Up @@ -1056,10 +1102,55 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(const int istep)
{
for (int is = 0; is < GlobalV::NSPIN; is++)
{
this->create_Output_Rho(is, istep).write();
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 = GlobalV::global_out_dir + "/SPIN" + std::to_string(is + 1) + "_CHG.cube";
ModuleIO::write_cube(
#ifdef __MPI
this->pw_big->bz,
this->pw_big->nbz,
this->pw_rhod->nplane,
this->pw_rhod->startz_current,
#endif
data,
is,
GlobalV::NSPIN,
istep,
fn,
this->pw_rhod->nx,
this->pw_rhod->ny,
this->pw_rhod->nz,
this->pelec->eferm.get_efval(is),
&(GlobalC::ucell),
3,
1);
if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5)
{
this->create_Output_Kin(is, istep).write();
fn = GlobalV::global_out_dir + "/SPIN" + std::to_string(is + 1) + "_TAU.cube";
ModuleIO::write_cube(
#ifdef __MPI
this->pw_big->bz,
this->pw_big->nbz,
this->pw_rhod->nplane,
this->pw_rhod->startz_current,
#endif
this->pelec->charge->kin_r_save[is],
is,
GlobalV::NSPIN,
istep,
fn,
this->pw_rhod->nx,
this->pw_rhod->ny,
this->pw_rhod->nz,
this->pelec->eferm.get_efval(is),
&(GlobalC::ucell));
}
}
}
Expand Down
Loading

0 comments on commit 06e208a

Please sign in to comment.