Skip to content

Commit 58cc834

Browse files
mohanchenabacus_fixer
andauthored
Esolver refactor for LCAO and pw (#7012)
* small format changes * refactor(esolver): extract charge density symmetrization to Symmetry_rho::symmetrize_rho - Add static method symmetrize_rho() in Symmetry_rho class - Replace 7 duplicate code blocks with single function call - Simplify code from 35 lines to 7 lines (80% reduction) - Improve code readability and maintainability Modified files: - source_estate/module_charge/symmetry_rho.h: add static method declaration - source_estate/module_charge/symmetry_rho.cpp: implement static method - source_esolver/esolver_ks_lcao.cpp: 2 calls updated - source_esolver/esolver_ks_pw.cpp: 1 call updated - source_esolver/esolver_ks_lcao_tddft.cpp: 1 call updated - source_esolver/esolver_ks_lcaopw.cpp: 1 call updated - source_esolver/esolver_of.cpp: 1 call updated - source_esolver/esolver_sdft_pw.cpp: 1 call updated This refactoring follows the ESolver cleanup principle: keep ESolver focused on high-level workflow control. * refactor(esolver): extract DeltaSpin lambda loop to deltaspin_lcao module - Create new files deltaspin_lcao.h/cpp in module_deltaspin - Extract DeltaSpin lambda loop logic from ESolver_KS_LCAO - Simplify code from 18 lines to 1 line in hamilt2rho_single - Separate LCAO and PW implementations for DeltaSpin Modified files: - source_esolver/esolver_ks_lcao.cpp: replace inline code with function call - source_lcao/module_deltaspin/CMakeLists.txt: add new source file New files: - source_lcao/module_deltaspin/deltaspin_lcao.h: function declaration - source_lcao/module_deltaspin/deltaspin_lcao.cpp: function implementation This refactoring follows the ESolver cleanup principle: keep ESolver focused on high-level workflow control. * refactor(esolver): complete DeltaSpin refactoring in LCAO - Add init_deltaspin_lcao() function for DeltaSpin initialization - Add cal_mi_lcao_wrapper() function for magnetic moment calculation - Refactor all DeltaSpin-related code in esolver_ks_lcao.cpp - Simplify code from 29 lines to 3 lines (90% reduction) Modified files: - source_esolver/esolver_ks_lcao.cpp: replace 3 code blocks with function calls - source_lcao/module_deltaspin/deltaspin_lcao.h: add 2 new function declarations - source_lcao/module_deltaspin/deltaspin_lcao.cpp: implement 2 new functions This completes the DeltaSpin refactoring for LCAO method: 1. init_deltaspin_lcao() - initialize DeltaSpin calculation 2. cal_mi_lcao_wrapper() - calculate magnetic moments 3. run_deltaspin_lambda_loop_lcao() - run lambda loop optimization All functions follow the ESolver cleanup principle: keep ESolver focused on high-level workflow control. * refactor(esolver): extract DFT+U code to dftu_lcao module - Create new files dftu_lcao.h/cpp in source_lcao directory - Add init_dftu_lcao() function for DFT+U initialization - Add finish_dftu_lcao() function for DFT+U finalization - Simplify code from 32 lines to 2 lines in esolver_ks_lcao.cpp - Remove conditional checks from ESolver, move them to functions Modified files: - source_esolver/esolver_ks_lcao.cpp: replace 2 code blocks with function calls - source_lcao/CMakeLists.txt: add new source file New files: - source_lcao/dftu_lcao.h: function declarations - source_lcao/dftu_lcao.cpp: function implementations This refactoring prepares for unifying old and new DFT+U implementations: - Old DFT+U: source_lcao/module_dftu/ - New DFT+U: source_lcao/module_operator_lcao/op_dftu_lcao.cpp All functions follow ESolver cleanup principle: keep ESolver focused on high-level workflow control. * refactor(esolver): extract diagonalization parameters setup to hsolver module - Create new files diago_params.h/cpp in source_hsolver directory - Add setup_diago_params_pw() function for PW diagonalization parameters - Simplify code from 11 lines to 1 line in esolver_ks_pw.cpp - Encapsulate diagonalization parameter setup logic Modified files: - source_esolver/esolver_ks_pw.cpp: replace inline code with function call - source_hsolver/CMakeLists.txt: add new source file New files: - source_hsolver/diago_params.h: function declaration - source_hsolver/diago_params.cpp: function implementation This refactoring follows ESolver cleanup principle: keep ESolver focused on high-level workflow control. * fix(deltaspin): add sc_mag_switch check in cal_mi_lcao_wrapper - Add Input_para parameter to cal_mi_lcao_wrapper function - Add sc_mag_switch check to avoid calling cal_mi_lcao when DeltaSpin is disabled - Fix 'atomCounts is not set' error in non-DeltaSpin calculations - Update function call in esolver_ks_lcao.cpp This fix resolves the CI/CD failure caused by commit 2a520e3. The root cause was that cal_mi_lcao_wrapper was called without checking sc_mag_switch, leading to uninitialized atomCounts error. Modified files: - source_esolver/esolver_ks_lcao.cpp: update function call - source_lcao/module_deltaspin/deltaspin_lcao.h: add parameter - source_lcao/module_deltaspin/deltaspin_lcao.cpp: add check This follows the refactoring principle: preserve original condition checks when extracting code to wrapper functions. * fix(deltaspin): add #ifdef __LCAO for conditional compilation - Add #ifdef __LCAO conditional compilation in init_deltaspin_lcao and cal_mi_lcao_wrapper - Fix parameter order in init_sc call for LCAO and non-LCAO builds - Fix undefined reference to cal_mi_lcao in non-LCAO build This fix resolves CI/CD compilation errors in both build_5pt (with __LCAO) and build_1p (without __LCAO) environments. The The root cause was 1. init_sc has different parameter order in LCAO vs non-LCAO builds - LCAO: psi, dm, pelec - non-LCAO: psi, pelec 2. cal_mi_lcao is only defined in LCAO build Modified files: - source_hsolver/diago_params.h: add setup_diago_params_sdft declaration - source_lcao/module_deltaspin/deltaspin_lcao.cpp: add conditional compilation This follows the refactoring principle: handle conditional compilation properly when code has different implementations for different build configurations. * refactor(esolver): extract SDFT diagonalization parameters setup - Add setup_diago_params_sdft() function for SDFT diagonalization parameters - Simplify code from 11 lines to 1 line in esolver_sdft_pw.cpp - Encapsulate diagonalization parameter setup logic for SDFT Modified files: - source_esolver/esolver_sdft_pw.cpp: replace inline code with function call - source_hsolver/diago_params.cpp: add setup_diago_params_sdft implementation This refactoring follows ESolver cleanup principle: keep ESolver focused on high-level workflow control. Note: SDFT has different parameter setup logic compared to PW: - Different need_subspace condition - No SCF_ITER setting - Always set PW_DIAG_NMAX (no nscf check) --------- Co-authored-by: abacus_fixer <mohanchen@pku.eud.cn>
1 parent b4945b6 commit 58cc834

17 files changed

Lines changed: 569 additions & 128 deletions

source/source_esolver/esolver_ks_lcao.cpp

Lines changed: 9 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "esolver_ks_lcao.h"
22
#include "source_estate/elecstate_tools.h"
33
#include "source_lcao/module_deltaspin/spin_constrain.h"
4+
#include "source_lcao/module_deltaspin/deltaspin_lcao.h"
5+
#include "source_lcao/dftu_lcao.h"
46
#include "source_lcao/hs_matrix_k.hpp" // there may be multiple definitions if using hpp
57
#include "source_estate/module_charge/symmetry_rho.h"
68
#include "source_lcao/LCAO_domain.h" // need DeePKS_init
@@ -149,13 +151,7 @@ void ESolver_KS_LCAO<TK, TR>::before_scf(UnitCell& ucell, const int istep)
149151
this->deepks.build_overlap(ucell, orb_, pv, gd, *(two_center_bundle_.overlap_orb_alpha), PARAM.inp);
150152

151153
// 10) prepare sc calculation
152-
if (PARAM.inp.sc_mag_switch)
153-
{
154-
spinconstrain::SpinConstrain<TK>& sc = spinconstrain::SpinConstrain<TK>::getScInstance();
155-
sc.init_sc(PARAM.inp.sc_thr, PARAM.inp.nsc, PARAM.inp.nsc_min, PARAM.inp.alpha_trial,
156-
PARAM.inp.sccut, PARAM.inp.sc_drop_thr, ucell, &(this->pv),
157-
PARAM.inp.nspin, this->kv, this->p_hamilt, this->psi, this->dmat.dm, this->pelec);
158-
}
154+
init_deltaspin_lcao<TK>(ucell, PARAM.inp, &(this->pv), this->kv, this->p_hamilt, this->psi, this->dmat.dm, this->pelec);
159155

160156
// 11) set xc type before the first cal of xc in pelec->init_scf, Peize Lin add 2016-12-03
161157
this->exx_nao.before_scf(ucell, this->kv, orb_, this->p_chgmix, istep, PARAM.inp);
@@ -203,11 +199,7 @@ void ESolver_KS_LCAO<TK, TR>::before_scf(UnitCell& ucell, const int istep)
203199
#endif
204200

205201
// 16) the electron charge density should be symmetrized,
206-
Symmetry_rho srho;
207-
for (int is = 0; is < PARAM.inp.nspin; is++)
208-
{
209-
srho.begin(is, this->chr, this->pw_rho, ucell.symm);
210-
}
202+
Symmetry_rho::symmetrize_rho(PARAM.inp.nspin, this->chr, this->pw_rho, ucell.symm);
211203

212204
// 17) update of RDMFT, added by jghan
213205
if (PARAM.inp.rdmft == true)
@@ -347,15 +339,7 @@ void ESolver_KS_LCAO<TK, TR>::iter_init(UnitCell& ucell, const int istep, const
347339
}
348340
#endif
349341

350-
if (PARAM.inp.dft_plus_u)
351-
{
352-
if (istep != 0 || iter != 1)
353-
{
354-
this->dftu.set_dmr(this->dmat.dm);
355-
}
356-
// Calculate U and J if Yukawa potential is used
357-
this->dftu.cal_slater_UJ(ucell, this->chr.rho, this->pw_rho->nrxx);
358-
}
342+
init_dftu_lcao<TK>(istep, iter, PARAM.inp, &(this->dftu), this->dmat.dm, ucell, this->chr.rho, this->pw_rho->nrxx);
359343

360344
#ifdef __MLALGO
361345
// the density matrixes of DeePKS have been updated in each iter
@@ -392,24 +376,7 @@ void ESolver_KS_LCAO<TK, TR>::hamilt2rho_single(UnitCell& ucell, int istep, int
392376
bool skip_charge = PARAM.inp.calculation == "nscf" ? true : false;
393377

394378
// 2) run the inner lambda loop to contrain atomic moments with the DeltaSpin method
395-
bool skip_solve = false;
396-
if (PARAM.inp.sc_mag_switch)
397-
{
398-
spinconstrain::SpinConstrain<TK>& sc = spinconstrain::SpinConstrain<TK>::getScInstance();
399-
if (!sc.mag_converged() && this->drho > 0 && this->drho < PARAM.inp.sc_scf_thr)
400-
{
401-
// optimize lambda to get target magnetic moments, but the lambda is not near target
402-
sc.run_lambda_loop(iter - 1);
403-
sc.set_mag_converged(true);
404-
skip_solve = true;
405-
}
406-
else if (sc.mag_converged())
407-
{
408-
// optimize lambda to get target magnetic moments, but the lambda is not near target
409-
sc.run_lambda_loop(iter - 1);
410-
skip_solve = true;
411-
}
412-
}
379+
bool skip_solve = run_deltaspin_lambda_loop_lcao<TK>(iter - 1, this->drho, PARAM.inp);
413380

414381
// 3) run Hsolver
415382
if (!skip_solve)
@@ -435,11 +402,7 @@ void ESolver_KS_LCAO<TK, TR>::hamilt2rho_single(UnitCell& ucell, int istep, int
435402
#endif
436403

437404
// 5) symmetrize the charge density
438-
Symmetry_rho srho;
439-
for (int is = 0; is < PARAM.inp.nspin; is++)
440-
{
441-
srho.begin(is, this->chr, this->pw_rho, ucell.symm);
442-
}
405+
Symmetry_rho::symmetrize_rho(PARAM.inp.nspin, this->chr, this->pw_rho, ucell.symm);
443406

444407
// 6) calculate delta energy
445408
this->pelec->f_en.deband = this->pelec->cal_delta_eband(ucell);
@@ -461,36 +424,13 @@ void ESolver_KS_LCAO<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int&
461424
const std::vector<std::vector<TK>>& dm_vec = this->dmat.dm->get_DMK_vector();
462425

463426
// 1) calculate the local occupation number matrix and energy correction in DFT+U
464-
if (PARAM.inp.dft_plus_u)
465-
{
466-
// old DFT+U method calculates energy correction in esolver,
467-
// new DFT+U method calculates energy in Hamiltonian
468-
if (PARAM.inp.dft_plus_u == 2)
469-
{
470-
if (this->dftu.omc != 2)
471-
{
472-
dftu_cal_occup_m(iter, ucell, dm_vec, this->kv,
473-
this->p_chgmix->get_mixing_beta(), hamilt_lcao, this->dftu);
474-
}
475-
this->dftu.cal_energy_correction(ucell, istep);
476-
}
477-
this->dftu.output(ucell);
478-
// use the converged occupation matrix for next MD/Relax SCF calculation
479-
if (conv_esolver)
480-
{
481-
this->dftu.initialed_locale = true;
482-
}
483-
}
427+
finish_dftu_lcao<TK>(iter, conv_esolver, PARAM.inp, &(this->dftu), ucell, dm_vec, this->kv, this->p_chgmix->get_mixing_beta(), hamilt_lcao);
484428

485429
// 2) for deepks, calculate delta_e, output labels during electronic steps
486430
this->deepks.delta_e(ucell, this->kv, this->orb_, this->pv, this->gd, dm_vec, this->pelec->f_en, PARAM.inp);
487431

488432
// 3) for delta spin
489-
if (PARAM.inp.sc_mag_switch)
490-
{
491-
spinconstrain::SpinConstrain<TK>& sc = spinconstrain::SpinConstrain<TK>::getScInstance();
492-
sc.cal_mi_lcao(iter);
493-
}
433+
cal_mi_lcao_wrapper<TK>(iter, PARAM.inp);
494434

495435
// call iter_finish() of ESolver_KS, where band gap is printed,
496436
// eig and occ are printed, magnetization is calculated,

source/source_esolver/esolver_ks_lcao_tddft.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,7 @@ void ESolver_KS_LCAO_TDDFT<TR, Device>::hamilt2rho_single(UnitCell& ucell,
290290
// Symmetrize the charge density only for ground state
291291
if (istep <= 1)
292292
{
293-
Symmetry_rho srho;
294-
for (int is = 0; is < PARAM.inp.nspin; is++)
295-
{
296-
srho.begin(is, this->chr, this->pw_rho, ucell.symm);
297-
}
293+
Symmetry_rho::symmetrize_rho(PARAM.inp.nspin, this->chr, this->pw_rho, ucell.symm);
298294
}
299295
#ifdef __EXX
300296
if (GlobalC::exx_info.info_ri.real_number)

source/source_esolver/esolver_ks_lcaopw.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,7 @@ namespace ModuleESolver
157157
}
158158
#endif
159159

160-
Symmetry_rho srho;
161-
for (int is = 0; is < PARAM.inp.nspin; is++)
162-
{
163-
srho.begin(is, this->chr, this->pw_rhod, ucell.symm);
164-
}
160+
Symmetry_rho::symmetrize_rho(PARAM.inp.nspin, this->chr, this->pw_rhod, ucell.symm);
165161

166162
// deband is calculated from "output" charge density calculated
167163
// in sum_band

source/source_esolver/esolver_ks_pw.cpp

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include "source_hsolver/diago_iter_assist.h"
88
#include "source_hsolver/hsolver_pw.h"
9+
#include "source_hsolver/diago_params.h"
910

1011
#include "source_hsolver/kernels/hegvd_op.h"
1112
#include "source_io/module_parameter/parameter.h"
@@ -48,10 +49,10 @@ ESolver_KS_PW<T, Device>::ESolver_KS_PW()
4849
template <typename T, typename Device>
4950
ESolver_KS_PW<T, Device>::~ESolver_KS_PW()
5051
{
51-
//****************************************************
52-
// do not add any codes in this deconstructor funcion
53-
//****************************************************
54-
// delete Hamilt
52+
//****************************************************
53+
// do not add any codes in this deconstructor funcion
54+
//****************************************************
55+
// delete Hamilt
5556
this->deallocate_hamilt();
5657

5758
// mohan add 2025-10-12
@@ -83,7 +84,6 @@ void ESolver_KS_PW<T, Device>::deallocate_hamilt()
8384
template <typename T, typename Device>
8485
void ESolver_KS_PW<T, Device>::before_all_runners(UnitCell& ucell, const Input_para& inp)
8586
{
86-
//! Call before_all_runners() of ESolver_KS
8787
ESolver_KS<T, Device>::before_all_runners(ucell, inp);
8888

8989
//! setup and allocation for pelec, potentials, etc.
@@ -105,7 +105,6 @@ void ESolver_KS_PW<T, Device>::before_scf(UnitCell& ucell, const int istep)
105105
ModuleBase::TITLE("ESolver_KS_PW", "before_scf");
106106
ModuleBase::timer::tick("ESolver_KS_PW", "before_scf");
107107

108-
//! Call before_scf() of ESolver_KS
109108
ESolver_KS<T, Device>::before_scf(ucell, istep);
110109

111110
//! Init variables (once the cell has changed)
@@ -143,17 +142,15 @@ void ESolver_KS_PW<T, Device>::before_scf(UnitCell& ucell, const int istep)
143142
template <typename T, typename Device>
144143
void ESolver_KS_PW<T, Device>::iter_init(UnitCell& ucell, const int istep, const int iter)
145144
{
146-
// 1) Call iter_init() of ESolver_KS
147145
ESolver_KS<T, Device>::iter_init(ucell, istep, iter);
148146

149-
// 2) perform charge mixing for KSDFT using pw basis
150147
module_charge::chgmixing_ks_pw(iter, this->p_chgmix, this->dftu, PARAM.inp);
151148

152-
// 3) mohan move harris functional here, 2012-06-05
149+
// mohan move harris functional here, 2012-06-05
153150
// use 'rho(in)' and 'v_h and v_xc'(in)
154151
this->pelec->f_en.deband_harris = this->pelec->cal_delta_eband(ucell);
155152

156-
// 4) update local occupations for DFT+U
153+
// update local occupations for DFT+U
157154
// should before lambda loop in DeltaSpin
158155
pw::iter_init_dftu_pw(iter, istep, this->dftu, this->stp.psi_t, this->pelec->wg, ucell, PARAM.inp);
159156
}
@@ -168,17 +165,8 @@ void ESolver_KS_PW<T, Device>::hamilt2rho_single(UnitCell& ucell, const int iste
168165
this->pelec->f_en.eband = 0.0;
169166
this->pelec->f_en.demet = 0.0;
170167

171-
// choose if psi should be diag in subspace
172-
// be careful that istep start from 0 and iter start from 1
173-
// if (iter == 1)
174-
hsolver::DiagoIterAssist<T, Device>::need_subspace = ((istep == 0 || istep == 1) && iter == 1) ? false : true;
175-
hsolver::DiagoIterAssist<T, Device>::SCF_ITER = iter;
176-
hsolver::DiagoIterAssist<T, Device>::PW_DIAG_THR = ethr;
177-
178-
if (PARAM.inp.calculation != "nscf")
179-
{
180-
hsolver::DiagoIterAssist<T, Device>::PW_DIAG_NMAX = PARAM.inp.pw_diag_nmax;
181-
}
168+
// setup diagonalization parameters
169+
hsolver::setup_diago_params_pw<T, Device>(istep, iter, ethr, PARAM.inp);
182170

183171
bool skip_charge = PARAM.inp.calculation == "nscf" ? true : false;
184172

@@ -205,11 +193,7 @@ void ESolver_KS_PW<T, Device>::hamilt2rho_single(UnitCell& ucell, const int iste
205193
}
206194

207195
// symmetrize the charge density
208-
Symmetry_rho srho;
209-
for (int is = 0; is < PARAM.inp.nspin; is++)
210-
{
211-
srho.begin(is, this->chr, this->pw_rhod, ucell.symm);
212-
}
196+
Symmetry_rho::symmetrize_rho(PARAM.inp.nspin, this->chr, this->pw_rhod, ucell.symm);
213197

214198
ModuleBase::timer::tick("ESolver_KS_PW", "hamilt2rho_single");
215199
}
@@ -265,7 +249,6 @@ void ESolver_KS_PW<T, Device>::after_scf(UnitCell& ucell, const int istep, const
265249
this->pelec->cal_tau(*(this->psi));
266250
}
267251

268-
// Call 'after_scf' of ESolver_KS
269252
ESolver_KS<T, Device>::after_scf(ucell, istep, conv_esolver);
270253

271254
// Output quantities

source/source_esolver/esolver_of.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,7 @@ void ESolver_OF::before_opt(const int istep, UnitCell& ucell)
234234

235235
this->pelec->init_scf(ucell, Pgrid, sf.strucFac, locpp.numeric, ucell.symm);
236236

237-
Symmetry_rho srho;
238-
for (int is = 0; is < PARAM.inp.nspin; is++)
239-
{
240-
srho.begin(is, this->chr, this->pw_rho, ucell.symm);
241-
}
237+
Symmetry_rho::symmetrize_rho(PARAM.inp.nspin, this->chr, this->pw_rho, ucell.symm);
242238

243239
for (int is = 0; is < PARAM.inp.nspin; ++is)
244240
{

source/source_esolver/esolver_sdft_pw.cpp

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "source_pw/module_stodft/sto_forces.h"
99
#include "source_pw/module_stodft/sto_stress_pw.h"
1010
#include "source_hsolver/diago_iter_assist.h"
11+
#include "source_hsolver/diago_params.h"
1112
#include "source_io/module_parameter/parameter.h"
1213

1314
#include <algorithm>
@@ -142,20 +143,11 @@ void ESolver_SDFT_PW<T, Device>::hamilt2rho_single(UnitCell& ucell, int istep, i
142143
// reset energy
143144
this->pelec->f_en.eband = 0.0;
144145
this->pelec->f_en.demet = 0.0;
145-
// choose if psi should be diag in subspace
146-
// be careful that istep start from 0 and iter start from 1
147-
if (istep == 0 && iter == 1 || PARAM.inp.calculation == "nscf")
148-
{
149-
hsolver::DiagoIterAssist<T, Device>::need_subspace = false;
150-
}
151-
else
152-
{
153-
hsolver::DiagoIterAssist<T, Device>::need_subspace = true;
154-
}
146+
147+
// setup diagonalization parameters for SDFT
148+
hsolver::setup_diago_params_sdft<T, Device>(istep, iter, ethr, PARAM.inp);
155149

156150
bool skip_charge = PARAM.inp.calculation == "nscf" ? true : false;
157-
hsolver::DiagoIterAssist<T, Device>::PW_DIAG_THR = ethr;
158-
hsolver::DiagoIterAssist<T, Device>::PW_DIAG_NMAX = PARAM.inp.pw_diag_nmax;
159151

160152
// hsolver only exists in this function
161153
hsolver::HSolverPW_SDFT<T, Device> hsolver_pw_sdft_obj(&this->kv,
@@ -190,11 +182,7 @@ void ESolver_SDFT_PW<T, Device>::hamilt2rho_single(UnitCell& ucell, int istep, i
190182

191183
if (PARAM.globalv.ks_run)
192184
{
193-
Symmetry_rho srho;
194-
for (int is = 0; is < PARAM.inp.nspin; is++)
195-
{
196-
srho.begin(is, this->chr, this->pw_rho, ucell.symm);
197-
}
185+
Symmetry_rho::symmetrize_rho(PARAM.inp.nspin, this->chr, this->pw_rho, ucell.symm);
198186
this->pelec->f_en.deband = this->pelec->cal_delta_eband(ucell);
199187
}
200188
else

source/source_estate/module_charge/symmetry_rho.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@ Symmetry_rho::~Symmetry_rho()
1010
{
1111
}
1212

13+
void Symmetry_rho::symmetrize_rho(const int nspin,
14+
const Charge& chr,
15+
const ModulePW::PW_Basis* pw,
16+
ModuleSymmetry::Symmetry& symm)
17+
{
18+
Symmetry_rho srho;
19+
for (int is = 0; is < nspin; is++)
20+
{
21+
srho.begin(is, chr, pw, symm);
22+
}
23+
}
24+
1325
void Symmetry_rho::begin(const int& spin_now,
1426
const Charge& chr,
1527
const ModulePW::PW_Basis* rho_basis,

source/source_estate/module_charge/symmetry_rho.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,22 @@ class Symmetry_rho
1111
Symmetry_rho();
1212
~Symmetry_rho();
1313

14+
/**
15+
* @brief Symmetrize charge density for all spin channels
16+
*
17+
* This is a static helper function that symmetrizes the charge density
18+
* for all spin channels by calling begin() for each spin.
19+
*
20+
* @param nspin Number of spin channels
21+
* @param chr Charge object containing the density
22+
* @param pw Plane wave basis
23+
* @param symm Symmetry object
24+
*/
25+
static void symmetrize_rho(const int nspin,
26+
const Charge& chr,
27+
const ModulePW::PW_Basis* pw,
28+
ModuleSymmetry::Symmetry& symm);
29+
1430
void begin(const int& spin_now,
1531
const Charge& CHR,
1632
const ModulePW::PW_Basis* pw,

source/source_hsolver/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ list(APPEND objects
1212
hsolver.cpp
1313
diago_pxxxgvx.cpp
1414
diag_hs_para.cpp
15+
diago_params.cpp
1516

1617
)
1718

0 commit comments

Comments
 (0)