Skip to content

Commit

Permalink
Refactor: remove output_potential
Browse files Browse the repository at this point in the history
  • Loading branch information
YuLiu98 committed Jul 30, 2024
1 parent 06e208a commit b9eb9f8
Show file tree
Hide file tree
Showing 16 changed files with 337 additions and 453 deletions.
1 change: 0 additions & 1 deletion source/Makefile.Objects
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,6 @@ OBJS_IO=input_conv.o\
td_current_io.o\
write_wfc_r.o\
output_log.o\
output_potential.o\
output_mat_sparse.o\
para_json.o\
abacusjson.o\
Expand Down
24 changes: 0 additions & 24 deletions source/module_esolver/esolver_ks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -687,30 +687,6 @@ bool ESolver_KS<T, Device>::get_conv_elec()
return this->conv_elec;
}

//------------------------------------------------------------------------------
//! the 15th function of ESolver_KS: create_Output_Potential
//! mohan add 2024-05-12
//------------------------------------------------------------------------------
template <typename T, typename Device>
ModuleIO::Output_Potential ESolver_KS<T, Device>::create_Output_Potential(int iter, const std::string& prefix)
{
const int precision = 3;
std::string tag = "POT";
return ModuleIO::Output_Potential(this->pw_big,
this->pw_rhod,
GlobalV::NSPIN,
iter,
GlobalV::out_pot,
this->pelec->pot->get_effective_v(),
this->pelec->pot->get_fixed_v(),
&(GlobalC::ucell),
pelec->charge,
precision,
GlobalV::global_out_dir,
tag,
prefix);
}

//------------------------------------------------------------------------------
//! the 16th-20th functions of ESolver_KS
//! mohan add 2024-05-12
Expand Down
4 changes: 0 additions & 4 deletions source/module_esolver/esolver_ks.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "module_hamilt_pw/hamilt_pwdft/wavefunc.h"
#include "module_hsolver/hsolver.h"
#include "module_io/cal_test.h"
#include "module_io/output_potential.h"
#include "module_psi/psi.h"

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

/// @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
43 changes: 42 additions & 1 deletion source/module_esolver/esolver_ks_lcao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "module_io/write_HS.h"
#include "module_io/write_eband_terms.hpp"
#include "module_io/write_istate_info.h"
#include "module_io/write_pot.h"
#include "module_io/write_proj_band_lcao.h"
#include "module_io/write_vxc.hpp"
#include "module_parameter/parameter.h"
Expand Down Expand Up @@ -1186,7 +1187,47 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(const int istep)
#endif

// 6) write potential
this->create_Output_Potential(istep).write();
if (PARAM.inp.out_pot == 1 || PARAM.inp.out_pot == 3)
{
for (int is = 0; is < GlobalV::NSPIN; is++)
{
std::string fn = GlobalV::global_out_dir + "/SPIN" + std::to_string(is + 1) + "_POT.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->pot->get_effective_v(is),
is,
GlobalV::NSPIN,
istep,
fn,
this->pw_rhod->nx,
this->pw_rhod->ny,
this->pw_rhod->nz,
0.0, // efermi
&(GlobalC::ucell),
3, // precision
0); // out_fermi
}
}
else if (PARAM.inp.out_pot == 2)
{
std::string fn = GlobalV::global_out_dir + "/ElecStaticPot.cube";
ModuleIO::write_elecstat_pot(
#ifdef __MPI
this->pw_big->bz,
this->pw_big->nbz,
#endif
fn,
this->pw_rhod,
this->pelec->charge,
&(GlobalC::ucell),
this->pelec->pot->get_fixed_v());
}

// 7) write convergence
ModuleIO::output_convergence_after_scf(this->conv_elec, this->pelec->f_en.etot);
Expand Down
100 changes: 78 additions & 22 deletions source/module_esolver/esolver_ks_pw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ void ESolver_KS_PW<T, Device>::before_scf(const int istep)
//! calculate the total local pseudopotential in real space
this->pelec->init_scf(istep, this->sf.strucFac);

//! output the initial charge density
if (PARAM.inp.out_chg == 2)
{
for (int is = 0; is < GlobalV::NSPIN; is++)
Expand All @@ -231,35 +232,50 @@ void ESolver_KS_PW<T, Device>::before_scf(const int istep)
#ifdef __MPI
this->pw_big->bz,
this->pw_big->nbz,
this->pw_rho->nplane,
this->pw_rho->startz_current,
this->pw_rhod->nplane,
this->pw_rhod->startz_current,
#endif
this->pelec->charge->rho[is],
is,
GlobalV::NSPIN,
0,
ss.str(),
this->pw_rho->nx,
this->pw_rho->ny,
this->pw_rho->nz,
this->pw_rhod->nx,
this->pw_rhod->ny,
this->pw_rhod->nz,
this->pelec->eferm.ef,
&(GlobalC::ucell));
}
}

ModuleIO::write_pot(GlobalV::out_pot,
GlobalV::NSPIN,
GlobalV::global_out_dir,
//! output total local potential of the initial charge density
if (PARAM.inp.out_pot == 3)
{
for (int is = 0; is < GlobalV::NSPIN; is++)
{
std::stringstream ss;
ss << GlobalV::global_out_dir << "SPIN" << is + 1 << "_POT_INI.cube";
ModuleIO::write_cube(
#ifdef __MPI
this->pw_big->bz,
this->pw_big->nbz,
this->pw_rho->nplane,
this->pw_rho->startz_current,
this->pw_big->bz,
this->pw_big->nbz,
this->pw_rhod->nplane,
this->pw_rhod->startz_current,
#endif
this->pw_rho->nx,
this->pw_rho->ny,
this->pw_rho->nz,
this->pelec->pot->get_effective_v());
this->pelec->pot->get_effective_v(is),
is,
GlobalV::NSPIN,
0, // iter
ss.str(),
this->pw_rhod->nx,
this->pw_rhod->ny,
this->pw_rhod->nz,
0.0, // efermi
&(GlobalC::ucell),
11, // precsion
0); // out_fermi
}
}

//! Symmetry_rho should behind init_scf, because charge should be
//! initialized first. liuyu comment: Symmetry_rho should be located between
Expand Down Expand Up @@ -518,7 +534,47 @@ void ESolver_KS_PW<T, Device>::after_scf(const int istep)
// 1) call after_scf() of ESolver_FP
ESolver_FP::after_scf(istep);

this->create_Output_Potential(istep).write();
if (PARAM.inp.out_pot == 1 || PARAM.inp.out_pot == 3)
{
for (int is = 0; is < GlobalV::NSPIN; is++)
{
std::string fn = GlobalV::global_out_dir + "/SPIN" + std::to_string(is + 1) + "_POT.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->pot->get_effective_v(is),
is,
GlobalV::NSPIN,
istep,
fn,
this->pw_rhod->nx,
this->pw_rhod->ny,
this->pw_rhod->nz,
0.0, // efermi
&(GlobalC::ucell),
3, // precision
0); // out_fermi
}
}
else if (PARAM.inp.out_pot == 2)
{
std::string fn = GlobalV::global_out_dir + "/ElecStaticPot.cube";
ModuleIO::write_elecstat_pot(
#ifdef __MPI
this->pw_big->bz,
this->pw_big->nbz,
#endif
fn,
this->pw_rhod,
this->pelec->charge,
&(GlobalC::ucell),
this->pelec->pot->get_fixed_v());
}

if (PARAM.inp.out_chg)
{
Expand Down Expand Up @@ -707,17 +763,17 @@ void ESolver_KS_PW<T, Device>::after_scf(const int istep)
#ifdef __MPI
this->pw_big->bz,
this->pw_big->nbz,
this->pw_big->nplane,
this->pw_big->startz_current,
this->pw_rhod->nplane,
this->pw_rhod->startz_current,
#endif
rho_band,
0,
GlobalV::NSPIN,
0,
ssc.str(),
this->pw_rho->nx,
this->pw_rho->ny,
this->pw_rho->nz,
this->pw_rhod->nx,
this->pw_rhod->ny,
this->pw_rhod->nz,
0.0,
&(GlobalC::ucell));
}
Expand Down
48 changes: 25 additions & 23 deletions source/module_esolver/esolver_of.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,47 +516,49 @@ void ESolver_OF::after_opt(const int istep, UnitCell& ucell)
#ifdef __MPI
this->pw_big->bz,
this->pw_big->nbz,
this->pw_rho->nplane,
this->pw_rho->startz_current,
this->pw_rhod->nplane,
this->pw_rhod->startz_current,
#endif
this->pelec->charge->rho[is],
is,
GlobalV::NSPIN,
this->iter_,
istep,
ssc.str(),
this->pw_rho->nx,
this->pw_rho->ny,
this->pw_rho->nz,
this->pw_rhod->nx,
this->pw_rhod->ny,
this->pw_rhod->nz,
this->mu_[is],
&(ucell),
3,
1);
}

if (GlobalV::out_pot == 1 || GlobalV::out_pot == 3) // output the effective potential, sunliang 2023-03-16
if (PARAM.inp.out_pot == 1 || PARAM.inp.out_pot == 3) // output the effective potential, sunliang 2023-03-16
{
int precision = 3; // be consistent with esolver_ks_lcao.cpp
std::stringstream ssp;
ssp << GlobalV::global_out_dir << "SPIN" << is + 1 << "_POT.cube";
ModuleIO::write_pot_spin(
GlobalV::out_pot,
std::string fn = GlobalV::global_out_dir + "/SPIN" + std::to_string(is + 1) + "_POT.cube";

ModuleIO::write_cube(
#ifdef __MPI
this->pw_big->bz,
this->pw_big->nbz,
this->pw_rho->nplane,
this->pw_rho->startz_current,
this->pw_rhod->nplane,
this->pw_rhod->startz_current,
#endif
this->pelec->pot->get_effective_v(is),
is,
0,
ssp.str(),
this->pw_rho->nx,
this->pw_rho->ny,
this->pw_rho->nz,
this->pelec->pot->get_effective_v(),
precision);
GlobalV::NSPIN,
istep,
fn,
this->pw_rhod->nx,
this->pw_rhod->ny,
this->pw_rhod->nz,
0.0, // efermi
&(ucell),
3, // precision
0); // out_fermi
}
}
if (GlobalV::out_pot == 2) // output the static electronic potential, sunliang 2023-08-11
if (PARAM.inp.out_pot == 2) // output the static electronic potential, sunliang 2023-08-11
{
int precision = 3;
std::stringstream ssp;
Expand All @@ -567,7 +569,7 @@ void ESolver_OF::after_opt(const int istep, UnitCell& ucell)
this->pw_big->nbz,
#endif
ssp.str(),
this->pw_rho,
this->pw_rhod,
this->pelec->charge,
&(ucell),
this->pelec->pot->get_fixed_v());
Expand Down
10 changes: 5 additions & 5 deletions source/module_esolver/esolver_sdft_pw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,17 +159,17 @@ void ESolver_SDFT_PW::after_scf(const int istep)
#ifdef __MPI
pw_big->bz,
pw_big->nbz,
pw_rho->nplane,
pw_rho->startz_current,
pw_rhod->nplane,
pw_rhod->startz_current,
#endif
pelec->charge->rho_save[is],
is,
GlobalV::NSPIN,
0,
ssc.str(),
pw_rho->nx,
pw_rho->ny,
pw_rho->nz,
pw_rhod->nx,
pw_rhod->ny,
pw_rhod->nz,
ef_tmp,
&(GlobalC::ucell));
}
Expand Down
Loading

0 comments on commit b9eb9f8

Please sign in to comment.