Skip to content

Commit 820a367

Browse files
Critsium-xyclaude
andauthored
Refactor: remove source_lcao dependency from source_hsolver (#7683)
HSolverLCAO::solve computed the charge density directly via the source_lcao free function LCAO_domain::dm2rho, making source_hsolver depend on source_lcao. Delegate the charge-density calculation through a new thin ElecStateLCAO::dmToRho wrapper (source_estate, which already depends on source_lcao). This mirrors the existing pexsi branch (_pes->dm2rho) and the plane-wave path (ElecStatePW::psiToRho), and removes the only direct source_lcao include from source_hsolver. No functional change. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 079fd0c commit 820a367

3 files changed

Lines changed: 28 additions & 5 deletions

File tree

source/source_estate/elecstate_lcao.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "source_io/module_parameter/parameter.h"
88

99
#include "source_lcao/module_gint/gint_interface.h"
10+
#include "source_lcao/rho_tau_lcao.h"
1011

1112
#include <vector>
1213

@@ -84,6 +85,15 @@ void ElecStateLCAO<std::complex<double>>::dm2rho(std::vector<std::complex<double
8485
}
8586

8687

88+
template <typename TK>
89+
void ElecStateLCAO<TK>::dmToRho(std::vector<hamilt::HContainer<double>*>& dmr,
90+
int nspin,
91+
Charge* chr,
92+
bool skip_charge)
93+
{
94+
LCAO_domain::dm2rho(dmr, nspin, chr, skip_charge);
95+
}
96+
8797
template class ElecStateLCAO<double>; // Gamma_only case
8898
template class ElecStateLCAO<std::complex<double>>; // multi-k case
8999

source/source_estate/elecstate_lcao.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,23 @@ class ElecStateLCAO : public ElecState
3939
* @param pexsi_EDM: pointers of energy-weighed density matrix (EDMK) calculated by pexsi, needed by MD, will be
4040
* stored in DensityMatrix::pexsi_EDM
4141
*/
42-
void dm2rho(std::vector<TK*> pexsi_DM,
43-
std::vector<TK*> pexsi_EDM,
42+
void dm2rho(std::vector<TK*> pexsi_DM,
43+
std::vector<TK*> pexsi_EDM,
4444
DensityMatrix<TK, double>* dm);
4545

46+
/**
47+
* @brief calculate electronic charge density from the density matrix (DMR)
48+
*
49+
* Thin wrapper over LCAO_domain::dm2rho so that HSolverLCAO delegates the
50+
* charge-density calculation through the ElecState interface, mirroring the
51+
* plane-wave path (ElecStatePW::psiToRho) and the pexsi branch above. This
52+
* keeps the source_lcao dependency out of source_hsolver.
53+
*/
54+
void dmToRho(std::vector<hamilt::HContainer<double>*>& dmr,
55+
int nspin,
56+
Charge* chr,
57+
bool skip_charge = false);
58+
4659
};
4760

4861
template <typename TK>

source/source_hsolver/hsolver_lcao.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@
3535
#include "source_hsolver/parallel_k2d.h"
3636
#include "source_io/module_parameter/parameter.h"
3737

38-
#include "source_lcao/rho_tau_lcao.h" // mohan add 20251024
39-
4038
namespace hsolver
4139
{
4240

@@ -103,7 +101,9 @@ void HSolverLCAO<TK, Device>::solve(hamilt::Hamilt<TK>* pHamilt,
103101
if (!skip_charge)
104102
{
105103
// compute charge density from density matrix, mohan update 20251024
106-
LCAO_domain::dm2rho(dm.get_DMR_vector(), nspin, &chr);
104+
// delegate to ElecStateLCAO to keep the source_lcao dependency out of
105+
// source_hsolver (mirrors the pexsi branch below and the PW psiToRho path)
106+
dynamic_cast<elecstate::ElecStateLCAO<TK>*>(pes)->dmToRho(dm.get_DMR_vector(), nspin, &chr);
107107
}
108108
else
109109
{

0 commit comments

Comments
 (0)