Skip to content

Commit e4fa983

Browse files
author
abacus_fixer
committed
refactor(dftu): convert cal_occ_mat_k/gamma to DFTU_LCAO free functions
Move cal_occ_mat_k and cal_occ_mat_gamma from Plus_U member functions to DFTU_LCAO namespace free functions in dftu_occup.cpp. Changes: - Remove Plus_U::cal_occ_mat_k and Plus_U::cal_occ_mat_gamma member declarations from dftu_lcao.h. - Add DFTU_LCAO::cal_occ_mat_k and DFTU_LCAO::cal_occ_mat_gamma free function declarations at the end of dftu_lcao.h. - Change definitions in dftu_occup.cpp from Plus_U:: to DFTU_LCAO::. - Change occ_mat_initialized parameter from const bool& to bool&. - Replace is_mixing_enabled() with PARAM.inp.mixing_dftu (direct read of input parameter, same semantics). - Replace mark_occ_mat_initialized() with occ_mat_initialized = true (write through reference parameter). - Add Plus_U_Base::set_occ_mat_initialized(bool) setter. - cal_occ_mat specializations call DFTU_LCAO:: free functions, copy occ_mat_initialized in/out via local variable. Governance rules: rule 1 (dependencies passed explicitly), rule 2 (eliminate hidden workflow state from member functions), rule 5 (no default args added). Verification: make -j 30 in build_max_para_test succeeded, target abacus_max_para linked.
1 parent 0cfb33b commit e4fa983

4 files changed

Lines changed: 65 additions & 52 deletions

File tree

source/source_lcao/module_dftu/dftu_lcao.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -291,11 +291,13 @@ void cal_occ_mat(const int iter,
291291
const bool gamma_only_local,
292292
const int nspin)
293293
{
294-
dftu.cal_occ_mat_gamma(dftu.get_paraV(), iter, ucell, dm, mixing_beta, p_ham, nspin,
295-
dftu.get_npol(), dftu.get_nlocal(), dftu.get_iatlnmipol2iwt(),
296-
dftu.get_orbital_corr_vec(),
297-
dftu.get_occ_mat_data(), dftu.get_occ_mat_save_data(),
298-
dftu.get_occ_mat_initialized());
294+
bool occ_mat_initialized = dftu.get_occ_mat_initialized();
295+
DFTU_LCAO::cal_occ_mat_gamma(dftu.get_paraV(), iter, ucell, dm, mixing_beta, p_ham, nspin,
296+
dftu.get_npol(), dftu.get_nlocal(), dftu.get_iatlnmipol2iwt(),
297+
dftu.get_orbital_corr_vec(),
298+
dftu.get_occ_mat_data(), dftu.get_occ_mat_save_data(),
299+
occ_mat_initialized);
300+
dftu.set_occ_mat_initialized(occ_mat_initialized);
299301
}
300302

301303
//! dftu occupation matrix for multiple k-points using dm(complex)
@@ -310,11 +312,13 @@ void cal_occ_mat(const int iter,
310312
const bool gamma_only_local,
311313
const int nspin)
312314
{
313-
dftu.cal_occ_mat_k(dftu.get_paraV(), iter, ucell, dm, kv, mixing_beta, p_ham, gamma_only_local, nspin,
314-
dftu.get_npol(), dftu.get_nlocal(), dftu.get_ks_solver(), dftu.get_iatlnmipol2iwt(),
315-
dftu.get_orbital_corr_vec(),
316-
dftu.get_occ_mat_data(), dftu.get_occ_mat_save_data(),
317-
dftu.get_occ_mat_initialized());
315+
bool occ_mat_initialized = dftu.get_occ_mat_initialized();
316+
DFTU_LCAO::cal_occ_mat_k(dftu.get_paraV(), iter, ucell, dm, kv, mixing_beta, p_ham, gamma_only_local, nspin,
317+
dftu.get_npol(), dftu.get_nlocal(), dftu.get_ks_solver(), dftu.get_iatlnmipol2iwt(),
318+
dftu.get_orbital_corr_vec(),
319+
dftu.get_occ_mat_data(), dftu.get_occ_mat_save_data(),
320+
occ_mat_initialized);
321+
dftu.set_occ_mat_initialized(occ_mat_initialized);
318322
}
319323

320324
} // namespace DFTU_LCAO

source/source_lcao/module_dftu/dftu_lcao.h

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -77,40 +77,6 @@ class Plus_U : public Plus_U_Base
7777
std::complex<double>* HR,
7878
const int npol);
7979

80-
// calculate the local occupation number matrix
81-
void cal_occ_mat_k(const Parallel_Orbitals* pv,
82-
const int iter,
83-
const UnitCell& ucell,
84-
const std::vector<std::vector<std::complex<double>>>& dm_k,
85-
const K_Vectors& kv,
86-
const double& mixing_beta,
87-
hamilt::Hamilt<std::complex<double>>* p_ham,
88-
const bool gamma_only_local,
89-
const int nspin,
90-
const int npol,
91-
const int nlocal,
92-
const std::string& ks_solver,
93-
const std::vector<std::vector<std::vector<std::vector<std::vector<int>>>>>& iatlnmipol2iwt,
94-
const std::vector<int>& orbital_corr,
95-
std::vector<std::vector<std::vector<std::vector<ModuleBase::matrix>>>>& occ_mat,
96-
std::vector<std::vector<std::vector<std::vector<ModuleBase::matrix>>>>& occ_mat_save,
97-
const bool& occ_mat_initialized);
98-
99-
void cal_occ_mat_gamma(const Parallel_Orbitals* pv,
100-
const int iter,
101-
const UnitCell& ucell,
102-
const std::vector<std::vector<double>>& dm_gamma,
103-
const double& mixing_beta,
104-
hamilt::Hamilt<double>* p_ham,
105-
const int nspin,
106-
const int npol,
107-
const int nlocal,
108-
const std::vector<std::vector<std::vector<std::vector<std::vector<int>>>>>& iatlnmipol2iwt,
109-
const std::vector<int>& orbital_corr,
110-
std::vector<std::vector<std::vector<std::vector<ModuleBase::matrix>>>>& occ_mat,
111-
std::vector<std::vector<std::vector<std::vector<ModuleBase::matrix>>>>& occ_mat_save,
112-
const bool& occ_mat_initialized);
113-
11480
//=============================================================
11581
// In dftu_tools.cpp
11682
// For calculating onsite potential, which is used
@@ -181,4 +147,45 @@ class Plus_U : public Plus_U_Base
181147
};
182148

183149

150+
151+
// Free functions for occupation matrix calculation in DFTU_LCAO namespace
152+
namespace DFTU_LCAO {
153+
154+
// calculate the local occupation number matrix (k-point version)
155+
void cal_occ_mat_k(const Parallel_Orbitals* pv,
156+
const int iter,
157+
const UnitCell& ucell,
158+
const std::vector<std::vector<std::complex<double>>>& dm_k,
159+
const K_Vectors& kv,
160+
const double& mixing_beta,
161+
hamilt::Hamilt<std::complex<double>>* p_ham,
162+
const bool gamma_only_local,
163+
const int nspin,
164+
const int npol,
165+
const int nlocal,
166+
const std::string& ks_solver,
167+
const std::vector<std::vector<std::vector<std::vector<std::vector<int>>>>>& iatlnmipol2iwt,
168+
const std::vector<int>& orbital_corr,
169+
std::vector<std::vector<std::vector<std::vector<ModuleBase::matrix>>>>& occ_mat,
170+
std::vector<std::vector<std::vector<std::vector<ModuleBase::matrix>>>>& occ_mat_save,
171+
bool& occ_mat_initialized);
172+
173+
// calculate the local occupation number matrix (gamma-point version)
174+
void cal_occ_mat_gamma(const Parallel_Orbitals* pv,
175+
const int iter,
176+
const UnitCell& ucell,
177+
const std::vector<std::vector<double>>& dm_gamma,
178+
const double& mixing_beta,
179+
hamilt::Hamilt<double>* p_ham,
180+
const int nspin,
181+
const int npol,
182+
const int nlocal,
183+
const std::vector<std::vector<std::vector<std::vector<std::vector<int>>>>>& iatlnmipol2iwt,
184+
const std::vector<int>& orbital_corr,
185+
std::vector<std::vector<std::vector<std::vector<ModuleBase::matrix>>>>& occ_mat,
186+
std::vector<std::vector<std::vector<std::vector<ModuleBase::matrix>>>>& occ_mat_save,
187+
bool& occ_mat_initialized);
188+
189+
} // namespace DFTU_LCAO
190+
184191
#endif

source/source_lcao/module_dftu/dftu_occup.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
#ifdef __LCAO
1515

16-
void Plus_U::cal_occ_mat_k(const Parallel_Orbitals* pv,
16+
void DFTU_LCAO::cal_occ_mat_k(const Parallel_Orbitals* pv,
1717
const int iter,
1818
const UnitCell& ucell,
1919
const std::vector<std::vector<std::complex<double>>>& dm_k,
@@ -29,7 +29,7 @@ void Plus_U::cal_occ_mat_k(const Parallel_Orbitals* pv,
2929
const std::vector<int>& orbital_corr,
3030
std::vector<std::vector<std::vector<std::vector<ModuleBase::matrix>>>>& occ_mat,
3131
std::vector<std::vector<std::vector<std::vector<ModuleBase::matrix>>>>& occ_mat_save,
32-
const bool& occ_mat_initialized)
32+
bool& occ_mat_initialized)
3333
{
3434
ModuleBase::TITLE("Plus_U", "cal_occ_mat_k");
3535
ModuleBase::timer::start("Plus_U", "cal_occ_mat_k");
@@ -290,7 +290,7 @@ void Plus_U::cal_occ_mat_k(const Parallel_Orbitals* pv,
290290
} // end ia
291291
} // end it
292292

293-
if(is_mixing_enabled() && occ_mat_initialized)
293+
if(PARAM.inp.mixing_dftu && occ_mat_initialized)
294294
{
295295
double beta = mixing_beta;
296296
for (int T = 0; T < ucell.ntype; T++)
@@ -324,12 +324,12 @@ void Plus_U::cal_occ_mat_k(const Parallel_Orbitals* pv,
324324
}
325325
}
326326

327-
mark_occ_mat_initialized();
327+
occ_mat_initialized = true;
328328
ModuleBase::timer::end("Plus_U", "cal_occ_mat_k");
329329
return;
330330
}
331331

332-
void Plus_U::cal_occ_mat_gamma(const Parallel_Orbitals* pv,
332+
void DFTU_LCAO::cal_occ_mat_gamma(const Parallel_Orbitals* pv,
333333
const int iter,
334334
const UnitCell &ucell,
335335
const std::vector<std::vector<double>> &dm_gamma,
@@ -342,7 +342,7 @@ void Plus_U::cal_occ_mat_gamma(const Parallel_Orbitals* pv,
342342
const std::vector<int>& orbital_corr,
343343
std::vector<std::vector<std::vector<std::vector<ModuleBase::matrix>>>>& occ_mat,
344344
std::vector<std::vector<std::vector<std::vector<ModuleBase::matrix>>>>& occ_mat_save,
345-
const bool& occ_mat_initialized)
345+
bool& occ_mat_initialized)
346346
{
347347
ModuleBase::TITLE("Plus_U", "cal_occ_mat_gamma");
348348
ModuleBase::timer::start("Plus_U", "cal_occ_mat_gamma");
@@ -527,7 +527,7 @@ void Plus_U::cal_occ_mat_gamma(const Parallel_Orbitals* pv,
527527
} // it
528528
} // is
529529

530-
if(is_mixing_enabled() && occ_mat_initialized)
530+
if(PARAM.inp.mixing_dftu && occ_mat_initialized)
531531
{
532532
double beta = mixing_beta;
533533
for (int T = 0; T < ucell.ntype; T++)
@@ -561,7 +561,7 @@ void Plus_U::cal_occ_mat_gamma(const Parallel_Orbitals* pv,
561561
}
562562
}
563563

564-
mark_occ_mat_initialized();
564+
occ_mat_initialized = true;
565565
ModuleBase::timer::end("Plus_U", "cal_occ_mat_gamma");
566566
return;
567567
}

source/source_pw/module_pwdft/dftu_base.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ class Plus_U_Base
142142
std::vector<std::vector<std::vector<std::vector<ModuleBase::matrix>>>>& get_occ_mat_save_data() { return occ_mat_save; }
143143
/// get occ_mat_initialized flag
144144
bool get_occ_mat_initialized() const { return occ_mat_initialized; }
145+
/// set occ_mat_initialized flag
146+
void set_occ_mat_initialized(bool val) { occ_mat_initialized = val; }
145147

146148
/// get flat occupation matrix for an atom's correlated orbital.
147149
/// nspin=1: fills occ with occ_mat[iat][l][0][0] data

0 commit comments

Comments
 (0)