Skip to content

Commit 6dfd6ee

Browse files
author
abacus_fixer
committed
refactor: eliminate reverse dependency of dftu_lcao.h from PW/base layers
Replace Plus_U (LCAO-derived class) with Plus_U_Base (PW-layer base class) in all non-LCAO interfaces. All DFT+U calls in PW/estate/test layers only use base-class members, so the derived-type reference was unnecessary. Changes: - Remove #include "source_lcao/module_dftu/dftu_lcao.h" from PW/base headers - Use #include "source_pw/module_pwdft/dftu_base.h" instead - Replace Plus_U&/Plus_U* with Plus_U_Base&/Plus_U_Base* in: * source_pw/module_pwdft: force_pw, hamilt_pw, onsite_proj, op_pw_proj, stress_func, stress_onsite, stress_pw (6 headers + 7 impls) * source_estate/module_charge: chgmixing (PW + LCAO mixing functions) * source_pw/module_stodft/test: test_hamilt_sto, test_sto_tool * source_hsolver/test: diago_mock.h (3 explicit specializations) Plus_U (derived) instances held by callers (e.g. ESolver_KS::dftu) continue to work via implicit pointer/reference upcast to Plus_U_Base. No behavioral change.
1 parent cdde2c5 commit 6dfd6ee

18 files changed

Lines changed: 38 additions & 37 deletions

File tree

source/source_estate/module_charge/chgmixing.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ void module_charge::chgmixing_ks(const int iter, // scf iteration number
119119

120120
void module_charge::chgmixing_ks_pw(const int iter, // scf iteration number
121121
Charge_Mixing* p_chgmix, // charge mixing class
122-
Plus_U &dftu, // mohan add 2025-11-06
122+
Plus_U_Base& dftu,
123123
const Input_para& inp) // input parameters
124124
{
125125
ModuleBase::TITLE("module_charge", "chgmixing_ks_pw");
@@ -180,7 +180,7 @@ void module_charge::chgmixing_ks_pw(const int iter, // scf iteration number
180180

181181
void module_charge::chgmixing_ks_lcao(const int iter, // scf iteration number
182182
Charge_Mixing* p_chgmix, // charge mixing class
183-
Plus_U &dftu, // mohan add 2025-11-06
183+
Plus_U_Base& dftu,
184184
const int nnr, // dimension of density matrix
185185
const Input_para& inp) // input parameters
186186
{

source/source_estate/module_charge/chgmixing.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "source_estate/module_charge/charge_mixing.h" // use p_chgmix
77
#include "source_io/module_parameter/input_parameter.h" // use Input_para
88
#include "source_cell/unitcell.h"
9-
#include "source_lcao/module_dftu/dftu_lcao.h" // mohan add 2025-11-06
9+
#include "source_pw/module_pwdft/dftu_base.h"
1010

1111
namespace module_charge
1212
{
@@ -28,12 +28,12 @@ void chgmixing_ks(const int iter, // scf iteration number
2828

2929
void chgmixing_ks_pw(const int iter,
3030
Charge_Mixing* p_chgmix,
31-
Plus_U &dftu, // mohan add 2025-11-06
31+
Plus_U_Base& dftu,
3232
const Input_para& inp); // input parameters
3333

3434
void chgmixing_ks_lcao(const int iter, // scf iteration number
3535
Charge_Mixing* p_chgmix, // charge mixing class
36-
Plus_U &dftu, // mohan add 2025-11-06
36+
Plus_U_Base& dftu,
3737
const int nnr, // dimension of density matrix
3838
const Input_para& inp); // input parameters
3939

source/source_hsolver/test/diago_mock.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ template<> hamilt::HamiltPW<double>::HamiltPW(
577577
ModulePW::PW_Basis_K* wfc_basis,
578578
K_Vectors* pkv,
579579
pseudopot_cell_vnl* ppcell,
580-
Plus_U* p_dftu, // mohan add 20251108
580+
Plus_U_Base* p_dftu,
581581
const UnitCell* ucell,
582582
const General_Exx_Info* exx_info)
583583
{
@@ -599,7 +599,7 @@ template<> hamilt::HamiltPW<std::complex<double>>::HamiltPW(
599599
ModulePW::PW_Basis_K* wfc_basis,
600600
K_Vectors* pkv,
601601
pseudopot_cell_vnl* ppcell,
602-
Plus_U* p_dftu, // mohan add 20251108
602+
Plus_U_Base* p_dftu,
603603
const UnitCell* ucell,
604604
const General_Exx_Info* exx_info)
605605
{
@@ -621,7 +621,7 @@ template<> hamilt::HamiltPW<std::complex<float>>::HamiltPW(
621621
ModulePW::PW_Basis_K* wfc_basis,
622622
K_Vectors* pkv,
623623
pseudopot_cell_vnl* ppcell,
624-
Plus_U* p_dftu, // mohan add 20251108
624+
Plus_U_Base* p_dftu,
625625
const UnitCell* ucell,
626626
const General_Exx_Info* exx_info)
627627
{

source/source_pw/module_pwdft/force_pw.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void Forces<FPTYPE, Device>::cal_force(UnitCell& ucell,
3434
ModuleSymmetry::Symmetry* p_symm,
3535
Structure_Factor* p_sf,
3636
surchem& solvent,
37-
const Plus_U *p_dftu, //mohan add 2025-11-06
37+
const Plus_U_Base* p_dftu,
3838
const pseudopot_cell_vl* locpp,
3939
const pseudopot_cell_vnl* p_nlpp,
4040
K_Vectors* pkv,

source/source_pw/module_pwdft/force_pw.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "source_base/kernels/math_kernel_op.h"
1313
#include "source_psi/psi.h"
1414
#include "stru_fac.h"
15-
#include "source_lcao/module_dftu/dftu_lcao.h" // mohan add 2025-11-06
15+
#include "source_pw/module_pwdft/dftu_base.h"
1616

1717
class pseudopot_cell_vnl;
1818

@@ -53,7 +53,7 @@ class Forces
5353
ModuleSymmetry::Symmetry* p_symm,
5454
Structure_Factor* p_sf,
5555
surchem& solvent,
56-
const Plus_U *p_dftu, //mohan add 2025-11-06
56+
const Plus_U_Base* p_dftu,
5757
const pseudopot_cell_vl* locpp,
5858
const pseudopot_cell_vnl* nlpp = nullptr,
5959
K_Vectors* pkv = nullptr,
@@ -107,7 +107,7 @@ class Forces
107107
const ModuleBase::matrix& wg,
108108
const ModulePW::PW_Basis_K* wfc_basis,
109109
const UnitCell& ucell_in,
110-
const Plus_U &dftu, // mohan add 2025-11-06
110+
const Plus_U_Base& dftu,
111111
const psi::Psi <std::complex<FPTYPE>, Device>* psi_in = nullptr);
112112

113113
void cal_force_scc(ModuleBase::matrix& forcescc,

source/source_pw/module_pwdft/force_pw_onsite.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
#include "source_pw/module_pwdft/onsite_proj.h"
66
#include "source_pw/module_pwdft/kernels/force_op.h"
77
#include "source_io/module_parameter/parameter.h"
8-
#include "source_lcao/module_dftu/dftu_lcao.h"
8+
#include "source_pw/module_pwdft/dftu_base.h"
99
#include "source_lcao/module_deltaspin/spin_constrain.h"
1010

1111
template <typename FPTYPE, typename Device>
1212
void Forces<FPTYPE, Device>::cal_force_onsite(ModuleBase::matrix& force_onsite,
1313
const ModuleBase::matrix& wg,
1414
const ModulePW::PW_Basis_K* wfc_basis,
1515
const UnitCell& ucell_in,
16-
const Plus_U &dftu,
16+
const Plus_U_Base& dftu,
1717
const psi::Psi <std::complex<FPTYPE>, Device>* psi_in)
1818
{
1919
ModuleBase::TITLE("Forces", "cal_force_onsite");

source/source_pw/module_pwdft/hamilt_pw.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ HamiltPW<T, Device>::HamiltPW(elecstate::Potential* pot_in,
2020
ModulePW::PW_Basis_K* wfc_basis,
2121
K_Vectors* pkv,
2222
pseudopot_cell_vnl* nlpp,
23-
Plus_U* p_dftu, // mohan add 2025-11-06
23+
Plus_U_Base* p_dftu,
2424
const UnitCell* ucell,
2525
const General_Exx_Info* exx_info)
2626
: ucell(ucell)

source/source_pw/module_pwdft/hamilt_pw.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "source_cell/klist.h"
77
#include "source_estate/module_pot/potential_new.h"
88
#include "source_hamilt/hamilt.h"
9-
#include "source_lcao/module_dftu/dftu_lcao.h" // mohan add 2025-11-06
9+
#include "source_pw/module_pwdft/dftu_base.h"
1010
#include "source_pw/module_pwdft/exx_helper.h"
1111
#include "source_pw/module_pwdft/vnl_pw.h"
1212

@@ -31,7 +31,7 @@ class HamiltPW : public Hamilt<T, Device>
3131
ModulePW::PW_Basis_K* wfc_basis,
3232
K_Vectors* p_kv,
3333
pseudopot_cell_vnl* nlpp,
34-
Plus_U* p_dftu, // mohan add 2025-11-06
34+
Plus_U_Base* p_dftu,
3535
const UnitCell* ucell,
3636
const General_Exx_Info* exx_info);
3737

source/source_pw/module_pwdft/onsite_proj.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <tuple>
77
#include "source_pw/module_pwdft/onsite_proj.h"
88
#include "source_pw/module_pwdft/onsite_proj_print.h"
9-
#include "source_lcao/module_dftu/dftu_lcao.h"
9+
#include "source_pw/module_pwdft/dftu_base.h"
1010
#include "source_lcao/module_deltaspin/spin_constrain.h"
1111
#include "source_cell/cell_tools.h"
1212
#include "source_io/module_parameter/parameter.h"
@@ -590,7 +590,7 @@ void projectors::OnsiteProjector<T, Device>::cal_occupations(
590590

591591
template <typename T, typename Device>
592592
void projectors::OnsiteProjector<T, Device>::cal_force_onsite_dftu(int ik, int npm, T* force,
593-
const Plus_U& dftu, int nks,
593+
const Plus_U_Base& dftu, int nks,
594594
const double* wg_ik) const
595595
{
596596
const int isk_val = this->isk_ ? this->isk_[ik] : 0;
@@ -602,7 +602,7 @@ void projectors::OnsiteProjector<T, Device>::cal_force_onsite_dftu(int ik, int n
602602

603603
template <typename T, typename Device>
604604
double projectors::OnsiteProjector<T, Device>::cal_stress_onsite_dftu(int ik, int npm,
605-
const Plus_U& dftu, int nks,
605+
const Plus_U_Base& dftu, int nks,
606606
const double* wg_ik) const
607607
{
608608
const int isk_val = this->isk_ ? this->isk_[ik] : 0;

source/source_pw/module_pwdft/onsite_proj.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include "source_pw/module_pwdft/radial_proj.h"
88
#include "source_psi/psi.h"
99
#include "source_pw/module_pwdft/onsite_proj_tools.h"
10-
#include "source_lcao/module_dftu/dftu_lcao.h"
10+
#include "source_pw/module_pwdft/dftu_base.h"
1111

1212
#include <string>
1313
#include <vector>
@@ -90,12 +90,12 @@ namespace projectors
9090

9191
/// high-level: compute DFT+U force contribution for one k-point
9292
void cal_force_onsite_dftu(int ik, int npm, T* force,
93-
const Plus_U& dftu, int nks,
93+
const Plus_U_Base& dftu, int nks,
9494
const double* wg_ik) const;
9595

9696
/// high-level: compute DFT+U stress contribution for one k-point
9797
double cal_stress_onsite_dftu(int ik, int npm,
98-
const Plus_U& dftu, int nks,
98+
const Plus_U_Base& dftu, int nks,
9999
const double* wg_ik) const;
100100

101101
/// high-level: compute DeltaSpin force contribution for one k-point

0 commit comments

Comments
 (0)