Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace the interface of out_dm by using DensityMatrix.DMK instead of loc.DM #4509

Merged
merged 11 commits into from
Jul 3, 2024
Merged
4 changes: 1 addition & 3 deletions source/Makefile.Objects
Original file line number Diff line number Diff line change
Expand Up @@ -479,16 +479,14 @@ OBJS_IO_LCAO=cal_r_overlap_R.o\
nscf_fermi_surf.o\
istate_charge.o\
istate_envelope.o\
read_dm.o\
io_dmk.o\
unk_overlap_lcao.o\
read_wfc_nao.o\
read_wfc_lcao.o\
write_wfc_nao.o\
write_HS_sparse.o\
single_R_io.o\
write_HS_R.o\
write_dm.o\
output_dm.o\
write_dmr.o\
sparse_matrix.o\
output_mulliken.o\
Expand Down
28 changes: 0 additions & 28 deletions source/module_elecstate/elecstate_lcao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,24 +106,6 @@ void ElecStateLCAO<double>::psiToRho(const psi::Psi<double>& psi)
// cal_dm(this->loc->ParaV, this->wg, psi, this->loc->dm_gamma);
elecstate::cal_dm_psi(this->DM->get_paraV_pointer(), this->wg, psi, *(this->DM));
this->DM->cal_DMR();
if (this->loc->out_dm) // keep interface for old Output_DM until new one is ready
{
this->loc->dm_gamma.resize(GlobalV::NSPIN);
for (int is = 0; is < GlobalV::NSPIN; ++is)
{
this->loc->set_dm_gamma(is, this->DM->get_DMK_pointer(is));
}
}
ModuleBase::timer::tick("ElecStateLCAO", "cal_dm_2d");
for (int ik = 0; ik < psi.get_nk(); ++ik)
{
// for gamma_only case, no convertion occured, just for print.
// old 2D-to-Grid conversion has been replaced by new Gint Refactor 2023/09/25
if (this->loc->out_dm) // keep interface for old Output_DM until new one is ready
{
this->loc->cal_dk_gamma_from_2D_pub();
}
}
}

for (int is = 0; is < GlobalV::NSPIN; is++)
Expand Down Expand Up @@ -191,16 +173,6 @@ void ElecStateLCAO<double>::dmToRho(std::vector<double*> pexsi_DM, std::vector<d
nspin = 1;
}

// old 2D-to-Grid conversion has been replaced by new Gint Refactor 2023/09/25
if (this->loc->out_dm) // keep interface for old Output_DM until new one is ready
{
for (int is = 0; is < nspin; ++is)
{
this->loc->set_dm_gamma(is, pexsi_DM[is]);
}
this->loc->cal_dk_gamma_from_2D_pub();
}

this->get_DM()->pexsi_EDM = pexsi_EDM;

for (int is = 0; is < nspin; is++)
Expand Down
31 changes: 11 additions & 20 deletions source/module_esolver/esolver_ks_lcao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
//---------------------------------------------------

#include "module_hamilt_lcao/module_deltaspin/spin_constrain.h"
#include "module_io/io_dmk.h"
#include "module_io/write_dmr.h"
#include "module_io/write_wfc_nao.h"

Expand Down Expand Up @@ -1000,7 +1001,6 @@ 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();
this->create_Output_DM(is, iter).write();
if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5)
{
this->create_Output_Kin(is, iter, "tmp_").write();
Expand Down Expand Up @@ -1081,12 +1081,19 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(const int istep)
}

// 4) write density matrix
if (this->LOC.out_dm)
if (INPUT.out_dm)
{
for (int is = 0; is < GlobalV::NSPIN; is++)
std::vector<double> efermis(GlobalV::NSPIN == 2 ? 2 : 1);
for (int ispin = 0; ispin < efermis.size(); ispin++)
{
this->create_Output_DM(is, istep).write();
efermis[ispin] = this->pelec->eferm.get_efval(ispin);
}
const int precision = 3;
ModuleIO::write_dmk(dynamic_cast<const elecstate::ElecStateLCAO<TK>*>(this->pelec)->get_DM()->get_DMK_vector(),
precision,
efermis,
&(GlobalC::ucell),
this->orb_con.ParaV);
}

// 5) write Vxc
Expand Down Expand Up @@ -1295,22 +1302,6 @@ bool ESolver_KS_LCAO<TK, TR>::do_after_converge(int& iter)
//! the 16th function of ESolver_KS_LCAO: create_Output_DM
//! mohan add 2024-05-11
//------------------------------------------------------------------------------
template <typename TK, typename TR>
ModuleIO::Output_DM ESolver_KS_LCAO<TK, TR>::create_Output_DM(int is, int iter)
{
const int precision = 3;

return ModuleIO::Output_DM(this->GridT,
is,
iter,
precision,
this->LOC.out_dm,
this->LOC.DM,
this->pelec->eferm.get_efval(is),
&(GlobalC::ucell),
GlobalV::global_out_dir,
GlobalV::GAMMA_ONLY_LOCAL);
}

//------------------------------------------------------------------------------
//! the 17th function of ESolver_KS_LCAO: create_Output_DM1
Expand Down
4 changes: 0 additions & 4 deletions source/module_esolver/esolver_ks_lcao.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "module_ri/Mix_DMk_2D.h"
#endif
#include "module_basis/module_nao/two_center_bundle.h"
#include "module_io/output_dm.h"
#include "module_io/output_mat_sparse.h"

#include <memory>
Expand Down Expand Up @@ -99,9 +98,6 @@ class ESolver_KS_LCAO : public ESolver_KS<TK>
void beforesolver(const int istep);
//----------------------------------------------------------------------

/// @brief create ModuleIO::Output_DM object to output density matrix
ModuleIO::Output_DM create_Output_DM(int is, int iter);

/// @brief create ModuleIO::Output_Mat_Sparse object to output sparse density matrix of H, S, T, r
ModuleIO::Output_Mat_Sparse<TK> create_Output_Mat_Sparse(int istep);

Expand Down
1 change: 0 additions & 1 deletion source/module_esolver/esolver_ks_lcao_elec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include "module_hamilt_lcao/hamilt_lcaodft/operator_lcao/op_exx_lcao.h"
#include "module_hamilt_lcao/hamilt_lcaodft/operator_lcao/operator_lcao.h"
#include "module_hamilt_lcao/module_deltaspin/spin_constrain.h"
#include "module_io/dm_io.h"
#include "module_io/rho_io.h"
#include "module_io/write_pot.h"

Expand Down
1 change: 0 additions & 1 deletion source/module_esolver/esolver_ks_lcao_tddft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include "module_io/cal_r_overlap_R.h"
#include "module_io/dipole_io.h"
#include "module_io/dm_io.h"
#include "module_io/rho_io.h"
#include "module_io/td_current_io.h"
#include "module_io/write_HS.h"
Expand Down
4 changes: 1 addition & 3 deletions source/module_io/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,12 @@ if(ENABLE_LCAO)
nscf_fermi_surf.cpp
istate_charge.cpp
istate_envelope.cpp
read_dm.cpp
read_wfc_nao.cpp
read_wfc_lcao.cpp
write_wfc_nao.cpp
write_dm.cpp
io_dmk.cpp
write_dmr.cpp
dos_nao.cpp
output_dm.cpp
sparse_matrix.cpp
file_reader.cpp
csr_reader.cpp
Expand Down
44 changes: 0 additions & 44 deletions source/module_io/dm_io.h

This file was deleted.

Loading
Loading