refactor esolver_ks_pw#7008
Merged
mohanchen merged 8 commits intodeepmodeling:developfrom Mar 10, 2026
Merged
Conversation
- Create new files update_cell_pw.h and update_cell_pw.cpp in source_pw/module_pwdft - Extract cell parameter update logic from ESolver_KS_PW::before_scf() - The new function handles: 1. Rescaling non-local pseudopotential (ppcell.rescale_vnl) 2. Reinitializing plane wave basis grids (pw_wfc->initgrids/initparameters/collect_local_pw) - Keep psi initialization (p_psi_init->prepare_init) in esolver to avoid template dependency - Update CMakeLists.txt and Makefile.Objects for new source files This refactoring improves code organization by moving PW-specific cell update logic out of the esolver, making the esolver code cleaner and more focused on high-level workflow control.
- Add init() function to Exx_Helper class for EXX initialization - The init function handles: 1. Check if calculation type is scf/relax/cell-relax/md 2. Check if cal_exx is enabled 3. Set XC first loop if separate_loop is true 4. Set wg pointer for EXX calculation - Simplify ESolver_KS_PW::before_all_runners() by calling exx_helper.init() - Move EXX-specific logic out of esolver, improving code organization This refactoring makes the esolver code cleaner and more focused on high-level workflow control.
added 4 commits
March 9, 2026 13:36
…tu_pw - Create new files dftu_pw.h and dftu_pw.cpp in source_pw/module_pwdft - Extract DFT+U occupation update logic from ESolver_KS_PW::iter_init() - The new function handles: 1. Check if DFT+U is enabled 2. Check iteration and step conditions 3. Call cal_occ_pw for occupation calculation 4. Output DFT+U results - Use void* for psi parameter to avoid template dependency - Update CMakeLists.txt and Makefile.Objects for new source files This refactoring improves code organization by moving DFT+U specific logic out of the esolver, making the esolver code cleaner and more focused on high-level workflow control.
…in_lambda_loop - Create new files deltaspin_pw.h and deltaspin_pw.cpp in source_pw/module_pwdft - Extract DeltaSpin lambda loop logic from ESolver_KS_PW::hamilt2rho_single() - The new function handles: 1. Check if DeltaSpin (sc_mag_switch) is enabled 2. Get SpinConstrain singleton instance 3. Run lambda loop to constrain atomic magnetic moments 4. Return skip_solve flag to control solver execution - Add Doxygen-style comments in English - Update CMakeLists.txt and Makefile.Objects for new source files This refactoring improves code organization by moving DeltaSpin-specific logic out of the esolver, making the esolver code cleaner and more focused on high-level workflow control.
…_deltaspin_oscillation - Add check_deltaspin_oscillation() function to deltaspin_pw.h/cpp - Extract DeltaSpin SCF oscillation check logic from ESolver_KS_PW::iter_finish() - The new function handles: 1. Check if DeltaSpin (sc_mag_switch) is enabled 2. Get SpinConstrain singleton instance 3. Detect SCF oscillation using if_scf_oscillate() 4. Set mixing_restart_step if oscillation detected - Add Doxygen-style comments in English This refactoring consolidates all DeltaSpin-related functions in one place, making the code more modular and easier to maintain.
…re_scf - Add before_scf() function to Exx_Helper class - Extract EXX setup logic from ESolver_KS_PW::before_scf() - The new function handles: 1. Check if calculation type is valid (scf/relax/cell-relax/md) 2. Check if EXX is enabled and basis type is PW 3. Set EXX helper to Hamiltonian 4. Set psi for EXX calculation - Use void* for p_hamilt parameter to avoid circular dependency - Add Doxygen-style comments in English This refactoring consolidates EXX-related setup logic in the Exx_Helper class, making the code more modular and easier to maintain.
…r_finish - Add iter_finish() function to Exx_Helper class - Extract EXX convergence handling logic from ESolver_KS_PW::iter_finish() - The new function handles: 1. Check if EXX is enabled 2. Handle separate_loop mode for EXX convergence 3. Calculate EXX energy difference for energy threshold 4. Update potential if SCF not converged 5. Increment EXX iteration counter - Use Charge* and void* parameters to avoid circular dependency - Add Doxygen-style comments in English This refactoring consolidates all EXX-related functions in the Exx_Helper class, making the code more modular and easier to maintain.
Flying-dragon-boxing
approved these changes
Mar 9, 2026
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.
This refactoring improves code organization by moving PW-specific cell update logic out of the esolver, making the esolver code cleaner and more focused on high-level workflow control.
Reminder
Linked Issue
Fix #...
Unit Tests and/or Case Tests for my changes
What's changed?
Any changes of core modules? (ignore if not applicable)