forked from abacusmodeling/abacus-develop
-
Notifications
You must be signed in to change notification settings - Fork 152
refactor esolver_ks_pw #7008
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
refactor esolver_ks_pw #7008
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7d7a6f4
refactor(esolver): extract update_cell_pw function from esolver_ks_pw
95b3cc0
refactor(esolver): extract EXX initialization into Exx_Helper::init
b5f8ed3
refactor(esolver): extract DFT+U initialization into pw::iter_init_df…
0eb26d6
refactor(esolver): extract DeltaSpin lambda loop into pw::run_deltasp…
2bf6f5d
refactor(esolver): extract DeltaSpin oscillation check into pw::check…
fc3d52f
refactor(esolver): extract EXX before_scf setup into Exx_Helper::befo…
26f2a31
refactor(esolver): extract EXX iter_finish logic into Exx_Helper::ite…
989c3d4
Merge branch 'develop' into kohn
mohanchen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| #include "source_pw/module_pwdft/deltaspin_pw.h" | ||
| #include "source_lcao/module_deltaspin/spin_constrain.h" | ||
| #include "source_estate/module_charge/charge_mixing.h" | ||
|
|
||
| namespace pw | ||
| { | ||
|
|
||
| bool run_deltaspin_lambda_loop(const int iter, | ||
| const double drho, | ||
| const Input_para& inp) | ||
| { | ||
| /// Return false if DeltaSpin is not enabled | ||
| if (!inp.sc_mag_switch) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| /// Get the singleton instance of SpinConstrain | ||
| spinconstrain::SpinConstrain<std::complex<double>>& sc | ||
| = spinconstrain::SpinConstrain<std::complex<double>>::getScInstance(); | ||
|
|
||
| /// Case 1: Magnetic moments not yet converged and SCF is close to convergence. | ||
| /// This is the first time we enter the lambda loop after SCF is nearly converged. | ||
| if (!sc.mag_converged() && drho > 0 && drho < inp.sc_scf_thr) | ||
| { | ||
| /// Optimize lambda to get target magnetic moments | ||
| sc.run_lambda_loop(iter); | ||
| sc.set_mag_converged(true); | ||
| return true; | ||
| } | ||
| /// Case 2: Magnetic moments already converged in previous iteration. | ||
| /// Continue to refine lambda in subsequent SCF iterations. | ||
| else if (sc.mag_converged()) | ||
| { | ||
| sc.run_lambda_loop(iter); | ||
| return true; | ||
| } | ||
|
|
||
| /// Default: run the normal solver | ||
| return false; | ||
| } | ||
|
|
||
| void check_deltaspin_oscillation(const int iter, | ||
| const double drho, | ||
| Charge_Mixing* p_chgmix, | ||
| const Input_para& inp) | ||
| { | ||
| /// Return if DeltaSpin is not enabled | ||
| if (!inp.sc_mag_switch) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| /// Get the singleton instance of SpinConstrain | ||
| spinconstrain::SpinConstrain<std::complex<double>>& sc | ||
| = spinconstrain::SpinConstrain<std::complex<double>>::getScInstance(); | ||
|
|
||
| /// Check if higher magnetization precision is needed | ||
| if (!sc.higher_mag_prec) | ||
| { | ||
| /// Detect SCF oscillation | ||
| sc.higher_mag_prec = p_chgmix->if_scf_oscillate(iter, drho, inp.sc_os_ndim, inp.scf_os_thr); | ||
|
|
||
| /// If oscillation detected, set mixing restart step for next iteration | ||
| if (sc.higher_mag_prec) | ||
| { | ||
| p_chgmix->mixing_restart_step = iter + 1; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| #ifndef DELTASPIN_PW_H | ||
| #define DELTASPIN_PW_H | ||
|
|
||
| #include "source_io/module_parameter/parameter.h" | ||
|
|
||
| class Charge_Mixing; | ||
|
|
||
| namespace pw | ||
| { | ||
|
|
||
| /** | ||
| * @brief Run the inner lambda loop for DeltaSpin method to constrain atomic magnetic moments. | ||
| * | ||
| * This function is used in the PW basis SCF iteration to optimize lambda parameters | ||
| * for constraining atomic magnetic moments to target values using the DeltaSpin method. | ||
| * | ||
| * @param iter The current iteration number (0-indexed). | ||
| * @param drho The current charge density difference. | ||
| * @param inp The input parameters. | ||
| * @return true if the solver should be skipped (lambda loop was executed), | ||
| * false otherwise. | ||
| */ | ||
| bool run_deltaspin_lambda_loop(const int iter, | ||
| const double drho, | ||
| const Input_para& inp); | ||
|
|
||
| /** | ||
| * @brief Check if SCF oscillation occurs for DeltaSpin method. | ||
| * | ||
| * This function checks if the SCF iteration is oscillating and sets the | ||
| * mixing restart step if oscillation is detected. This is used to increase | ||
| * the precision of magnetization calculation. | ||
| * | ||
| * @param iter The current iteration number (1-indexed). | ||
| * @param drho The current charge density difference. | ||
| * @param p_chgmix Pointer to the Charge_Mixing object. | ||
| * @param inp The input parameters. | ||
| */ | ||
| void check_deltaspin_oscillation(const int iter, | ||
| const double drho, | ||
| Charge_Mixing* p_chgmix, | ||
| const Input_para& inp); | ||
|
|
||
| } | ||
|
|
||
| #endif |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| #include "source_pw/module_pwdft/dftu_pw.h" | ||
| #include "source_lcao/module_dftu/dftu.h" | ||
|
|
||
| namespace pw | ||
| { | ||
|
|
||
| void iter_init_dftu_pw(const int iter, | ||
| const int istep, | ||
| Plus_U& dftu, | ||
| const void* psi, | ||
| const ModuleBase::matrix& wg, | ||
| const UnitCell& ucell, | ||
| const Input_para& inp) | ||
| { | ||
| if (!inp.dft_plus_u) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| if (iter == 1 && istep == 0) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| if (dftu.omc != 2) | ||
| { | ||
| dftu.cal_occ_pw(iter, psi, wg, ucell, inp.mixing_beta); | ||
| } | ||
| dftu.output(ucell); | ||
| } | ||
|
|
||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| #ifndef DFTU_PW_H | ||
| #define DFTU_PW_H | ||
|
|
||
| #include "source_io/module_parameter/parameter.h" | ||
| #include "source_cell/unitcell.h" | ||
| #include "source_base/matrix.h" | ||
|
|
||
| class Plus_U; | ||
|
|
||
| namespace pw | ||
| { | ||
|
|
||
| void iter_init_dftu_pw(const int iter, | ||
| const int istep, | ||
| Plus_U& dftu, | ||
| const void* psi, | ||
| const ModuleBase::matrix& wg, | ||
| const UnitCell& ucell, | ||
| const Input_para& inp); | ||
|
|
||
| } | ||
|
|
||
| #endif |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.