Skip to content

Commit 144c795

Browse files
author
abacus_fixer
committed
refactor(dftu_lcao): extract force/stress as free functions, unify DFTU_LCAO namespace
Extract the 5 force/stress member functions of Plus_U from dftu_force.cpp into free functions declared in a new dftu_force.h header, mirroring the existing dftu_folding pattern. The top-level force_stress takes a Plus_U& parameter because it still calls Plus_U::cal_VU_pot_mat_real/complex (defined in dftu_tools.cpp); the four inner functions (cal_force_k, cal_stress_k, cal_force_gamma, cal_stress_gamma) are fully decoupled and take their dependencies (npol, nlocal, ks_solver, orb_cutoff, iatlnmipol2iwt, orbital_corr) as explicit parameters, so they are unit-testable without a Plus_U instance. Consolidate the two module-local namespaces dftu_force and dftu_folding into a single namespace DFTU_LCAO. The project-wide hamilt:: namespace (used by dftu_lcao_op.h/cpp, dftu_fs.cpp, dftu_lcao_op_legacy.h/cpp for operator classes inheriting from hamilt::OperatorLCAO<T>) is left untouched to avoid breaking the ABACUS hamilt operator framework. All callers updated: dftu_force:: and dftu_folding:: prefixes are replaced by DFTU_LCAO:: in dftu_force.cpp, dftu_occup.cpp, and force_stress_lcao.cpp; TITLE/timer/WARNING_QUIT identifier strings in dftu_force.cpp are renamed accordingly. Plus_U_Base gains two public read-only accessors (get_iatlnmipol2iwt, get_orbital_corr_vec) so the free functions can receive the lookup table and orbital_corr vector as parameters. Plus_U gains 8 public getters (get_paraV, get_npol, get_nlocal, get_ks_solver, get_orb_cutoff, is_gamma_only_local, is_cal_force, is_cal_stress) and cal_VU_pot_mat_real/complex are promoted from private to public so the free function force_stress can call them via the Plus_U& parameter. get_onebody_eff_pot remains private. Verification performed: - cmake --build build_max_para_test -j 4: clean build, no errors, no warnings - ./build_max_para_test/abacus_max_para --version: ABACUS version v3.11.0-beta8 - OMP_NUM_THREADS=1 ctest --test-dir build_max_para_test -R '^dftu_(pw_test|core_test|operator_test|lcao_test)$': 4/4 pass - python3 tools/03_code_analysis/agent_governance_check.py --staged: only warnings (header deps, test evidence, doc sync), all Exception allowed: yes, no blockers - 17_DS_DFTU: 45/50 sub-cases pass; the 5 PW Double-Spin failures are pre-existing baseline (verified via git stash + rerun with identical deviations), unrelated to this refactor - dft_plus_u==2 + force/stress path remains disabled per the existing comment in force_stress_lcao.cpp:429-454; not end-to-end tested.
1 parent c27c60d commit 144c795

8 files changed

Lines changed: 269 additions & 173 deletions

File tree

source/source_lcao/force_stress_lcao.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "source_base/parallel_reduce.h"
44
#include "source_lcao/module_dftu/dftu_lcao.h" //Quxin add for DFT+U on 20201029
5+
#include "source_lcao/module_dftu/dftu_force.h"
56
#include "source_io/module_output/output_log.h"
67
#include "source_io/module_parameter/parameter.h"
78
// new
@@ -456,7 +457,7 @@ void Force_Stress_LCAO<T>::getForceStress(UnitCell& ucell,
456457
std::vector<std::vector<double>>* dmk_d = nullptr;
457458
std::vector<std::vector<std::complex<double>>>* dmk_c = nullptr;
458459
assign_dmk_ptr<T>(dmat.dm, dmk_d, dmk_c, PARAM.globalv.gamma_only_local);
459-
dftu.force_stress(ucell, gd, dmk_d, dmk_c, pv, fsr_dftu, force_u, stress_u, kv, PARAM.globalv.npol);
460+
DFTU_LCAO::force_stress(dftu, ucell, gd, dmk_d, dmk_c, pv, fsr_dftu, force_u, stress_u, kv, PARAM.globalv.npol);
460461
}
461462
else
462463
{

source/source_lcao/module_dftu/dftu_folding.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include "source_hamilt/module_hcontainer/hcontainer.h"
99
#include "source_hamilt/module_hcontainer/hcontainer_funcs.h"
1010

11-
namespace dftu_folding {
11+
namespace DFTU_LCAO {
1212

1313
bool is_adjacent_pair(const std::vector<double>& orb_cutoff,
1414
const UnitCell& ucell,
@@ -296,6 +296,6 @@ void folding_matrix_k_new(const std::string& ks_solver,
296296
ModuleBase::timer::end("Plus_U", "folding_matrix_k_new");
297297
}
298298

299-
} // namespace dftu_folding
299+
} // namespace DFTU_LCAO
300300

301301
#endif // __LCAO

source/source_lcao/module_dftu/dftu_folding.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
#ifdef __LCAO
2121

22-
namespace dftu_folding {
22+
namespace DFTU_LCAO {
2323

2424
/// @brief Judge whether atom pair (T1,I1) and (T2,I2,tau2) are adjacent
2525
/// by direct orbital cutoff overlap or three-body bridging via a
@@ -85,7 +85,7 @@ void folding_matrix_k_new(const std::string& ks_solver,
8585
int ik,
8686
hamilt::Hamilt<std::complex<double>>* p_ham);
8787

88-
} // namespace dftu_folding
88+
} // namespace DFTU_LCAO
8989

9090
#endif // __LCAO
9191

0 commit comments

Comments
 (0)