Refactor DFT+U codes - #7852
Merged
Merged
Conversation
added 6 commits
August 24, 2026 12:08
- Add empty Plus_U_Base class in source_pw/module_pwdft/ - Wire into CMakeLists.txt and Makefile.Objects - No functional change; dftu.h untouched
…to dftu_base Copy all base-class members (static members, Yukawa members, locale/eff_pot_pw data structures) and non-inline method implementations from dftu.cpp, dftu_io.cpp, dftu_occup.cpp, dftu_pw.cpp into dftu_base.h/.cpp under source_pw/module_pwdft/. The Plus_U_Base class is a standalone duplicate of Plus_U's base portion. Plus_U is not yet modified; both classes coexist independently. init_base has an empty stub body (full implementation deferred to Phase 4). cal_slater_UJ and other Yukawa calculation methods remain in dftu_yukawa.cpp as Plus_U methods for now. Build verified: make -j 30 in build_max_para_test passes with no errors.
…te members - dftu.h: Plus_U now inherits from Plus_U_Base; LCAO-specific members kept - dftu.cpp: remove duplicate static member definitions and method implementations (uramping_update, u_converged) already in dftu_base - dftu_io.cpp: remove duplicate implementations (output, write_occup_m, read_occup_m, local_occup_bcast); keep inline JacobiRotate/ CalculateEigenvalues helpers - dftu_occup.cpp: remove duplicate locale methods (copy_locale, zero_locale, mix_locale, set_locale, get_locale_flat, set_locale_flat); keep LCAO-specific cal_occup_m_k/gamma - dftu_pw.cpp: cal_occ_pw reimplemented as Plus_U_Base::cal_occ_pw (keeps PW-side OnsiteProjector/Charge_Mixing deps out of dftu_base.cpp) - dftu_base.h: change private to protected for accessors used by derived Plus_U; energy_u moved to protected - test_dftu.cpp: remove duplicate static member definitions; rely on dftu_base.cpp for Plus_U_Base symbols - test CMakeLists.txt: add dftu_base.cpp to SOURCES for MODULE_LCAO_operator_dftu_test Verified: make -j 30 in build_max_para_test succeeds; all dftu unit tests pass (dftu_core_test: 10, dftu_pw_test: 11, dftu_operator_test: 15, MODULE_LCAO_operator_dftu_test: 2).
… setup - dftu_base.cpp: implement Plus_U_Base::init_base() containing all base-only initialization (static members, locale/eff_pot_pw/uom_array allocation, Yukawa Fk/U_Yukawa/J_Yukawa setup, dm_onsite file reading) - dftu.cpp: Plus_U::init() now calls init_base() and only retains LCAO-specific setup (paraV, ptr_orb_, orb_cutoff_, ucell pointer, parallel orbital dimension checks) Verified: make -j 30 in build_max_para_test succeeds; all dftu unit tests pass (dftu_core_test: 10, dftu_pw_test: 11, dftu_operator_test: 15, MODULE_LCAO_operator_dftu_test: 2).
- git mv source_lcao/module_dftu/dftu_pw.cpp -> source_pw/module_pwdft/dftu_pw.cpp - dftu_pw.cpp: include dftu_base.h instead of dftu.h (cal_occ_pw is now a Plus_U_Base method, no LCAO types needed) - source_lcao/module_dftu/CMakeLists.txt: remove dftu_pw.cpp from dftu OBJECT library - source_pw/module_pwdft/CMakeLists.txt: add dftu_pw.cpp to module_pwdft OBJECT library - Makefile.Objects: add dftu_pw.o to OBJS_SRCPW (was missing entirely from OBJS_DFTU before) Verified: make -j 30 in build_max_para_test succeeds; all dftu unit tests pass (dftu_core_test: 10, dftu_pw_test: 11, dftu_operator_test: 15, MODULE_LCAO_operator_dftu_test: 2).
dftu_io.cpp only contained inline JacobiRotate/CalculateEigenvalues helpers, which are already duplicated as inline functions in dftu_base.cpp (where write_occup_m uses them). The file had no non-inline symbols, so deleting it is safe. - git rm source_lcao/module_dftu/dftu_io.cpp - source_lcao/module_dftu/CMakeLists.txt: remove dftu_io.cpp from dftu OBJECT library - Makefile.Objects: remove dftu_io.o from OBJS_DFTU Verified: make -j 30 in build_max_para_test succeeds; all dftu unit tests pass (dftu_core_test: 10, dftu_pw_test: 11, dftu_operator_test: 15, MODULE_LCAO_operator_dftu_test: 2).
added 2 commits
August 24, 2026 13:06
- setup_pot.h/cpp: include dftu_base.h instead of dftu.h - setup_pot.cpp: parameter type Plus_U& -> Plus_U_Base& - setup_pot.cpp: call dftu.init_base() instead of dftu.init() with nullptr pv - setup_dftu_pw.h/cpp: forward declare Plus_U_Base, parameter type updated - Callers (esolver_ks_pw.cpp) pass this->dftu (Plus_U), bound to Plus_U_Base& After this phase, the PW path no longer needs LCAO-specific Plus_U headers.
…mespace - New files: source_pw/module_pwdft/dftu_output.h, dftu_output.cpp - declare and implement dftu_io::output and dftu_io::write_occup_m - first parameter is const Plus_U_Base&, accesses state via public getters - JacobiRotate and CalculateEigenvalues inline helpers migrated here - dftu_base.h: added public getters get_U_Yukawa / get_J_Yukawa; removed output/write_occup_m member declarations - dftu_base.cpp: removed output/write_occup_m implementations and the two Jacobi inline helpers (no longer referenced here) - Callers updated: - setup_dftu_pw.cpp: dftu.output(...) -> dftu_io::output(dftu, ...) - setup_dftu_lcao.cpp: dftu_ptr->output(...) -> dftu_io::output(*dftu_ptr, ...) - CMakeLists.txt and Makefile.Objects: added dftu_output.cpp/dftu_output.o All 4 dftu unit tests pass.
lanshuyue
approved these changes
Aug 24, 2026
16 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refactor DFT+U codes