Skip to content

refactor esolver_ks_pw#7008

Merged
mohanchen merged 8 commits intodeepmodeling:developfrom
mohanchen:kohn
Mar 10, 2026
Merged

refactor esolver_ks_pw#7008
mohanchen merged 8 commits intodeepmodeling:developfrom
mohanchen:kohn

Conversation

@mohanchen
Copy link
Collaborator

  • 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.

Reminder

  • Have you linked an issue with this pull request?
  • Have you added adequate unit tests and/or case tests for your pull request?
  • Have you noticed possible changes of behavior below or in the linked issue?
  • Have you explained the changes of codes in core modules of ESolver, HSolver, ElecState, Hamilt, Operator or Psi? (ignore if not applicable)

Linked Issue

Fix #...

Unit Tests and/or Case Tests for my changes

  • A unit test is added for each new feature or bug fix.

What's changed?

  • Example: My changes might affect the performance of the application under certain conditions, and I have tested the impact on various scenarios...

Any changes of core modules? (ignore if not applicable)

  • Example: I have added a new virtual function in the esolver base class in order to ...

- 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.
@mohanchen mohanchen requested a review from Cstandardlib March 9, 2026 04:45
@mohanchen mohanchen added Refactor Refactor ABACUS codes The Absolute Zero Reduce the "entropy" of the code to 0 labels Mar 9, 2026
- 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.
abacus_fixer 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.
@mohanchen mohanchen changed the title refactor(esolver): extract update_cell_pw function from esolver_ks_pw refactor esolver_ks_pw Mar 9, 2026
@mohanchen mohanchen requested review from Flying-dragon-boxing and removed request for Cstandardlib March 9, 2026 07:04
abacus_fixer and others added 2 commits March 9, 2026 15:19
…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.
@mohanchen mohanchen merged commit f781fac into deepmodeling:develop Mar 10, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Refactor Refactor ABACUS codes The Absolute Zero Reduce the "entropy" of the code to 0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants