Repository navigation
refactor(ofdft): reduce solver global state dependencies #8157
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
Closed
zzlinpku
wants to merge
1
commit into
deepmodeling:develop
from
zzlinpku:ofdft-global-config-refactor
Closed
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| #define ESOLVER_OF_H | ||
|
|
||
| #include <string> | ||
| #include <ostream> | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-blocking: Please use |
||
| #include <vector> | ||
|
|
||
| #include "esolver_fp.h" | ||
|
|
@@ -12,6 +13,22 @@ | |
|
|
||
| namespace ModuleESolver | ||
| { | ||
| /** | ||
| * @brief Runtime settings owned by PARAM but needed by the OFDFT solver. | ||
| * | ||
| * ESolver_OF snapshots these values at its initialization boundary so later | ||
| * OFDFT stages do not read PARAM directly. | ||
| */ | ||
| struct OFDFTRuntimeConfig | ||
| { | ||
| std::string global_readin_dir; | ||
| std::string global_out_dir; | ||
| bool domag = false; | ||
| bool domag_z = false; | ||
| int npol = 1; | ||
| bool gamma_only_pw = false; | ||
| }; | ||
|
|
||
| class ESolver_OF : public ESolver_FP | ||
| { | ||
| public: | ||
|
|
@@ -50,6 +67,7 @@ class ESolver_OF : public ESolver_FP | |
| int max_iter_ = 50; // scf_nmax | ||
|
|
||
| // ------------------ parameters from other module -------------- | ||
| OFDFTRuntimeConfig of_runtime_config_; | ||
| double dV_ = 0; // volume of one grid point in real space | ||
| std::vector<double> nelec_; // number of electrons with each spin | ||
|
|
||
|
|
@@ -83,9 +101,9 @@ class ESolver_OF : public ESolver_FP | |
| // ==================== main process of OFDFT ====================== | ||
| void before_opt(const int istep, UnitCell& ucell); | ||
| void update_potential(UnitCell& ucell); | ||
| void optimize(UnitCell& ucell); | ||
| void optimize(UnitCell& ucell, std::ostream& warning_stream); | ||
| void update_rho(); | ||
| bool check_exit(bool& conv_esolver); | ||
| bool check_exit(bool& conv_esolver, std::ostream& warning_stream); | ||
| void after_opt(const int istep, UnitCell& ucell, const bool conv_esolver); | ||
|
|
||
| // ============================ tools =============================== | ||
|
|
@@ -103,8 +121,8 @@ class ESolver_OF : public ESolver_FP | |
|
|
||
| // --------------------- determine the optimization direction ------- | ||
| void adjust_direction(); | ||
| void check_direction(double* dEdtheta, double** ptemp_phi, UnitCell& ucell); | ||
| void test_direction(double* dEdtheta, double** ptemp_phi, UnitCell& ucell); | ||
| void check_direction(double* dEdtheta, double** ptemp_phi, UnitCell& ucell, std::ostream& warning_stream); | ||
| void test_direction(double* dEdtheta, double** ptemp_phi, UnitCell& ucell, std::ostream& warning_stream); | ||
|
|
||
| // --------------------- interface to blas -------------------------- | ||
| double inner_product(double* pa, double* pb, int length, double dV = 1) const | ||
|
|
@@ -117,7 +135,7 @@ class ESolver_OF : public ESolver_FP | |
| // ---------------------- interfaces to optimization methods -------- | ||
| void init_opt(); | ||
| void get_direction(UnitCell& ucell); | ||
| void get_step_length(double* dEdtheta, double** ptemp_phi, UnitCell& ucell); | ||
| void get_step_length(double* dEdtheta, double** ptemp_phi, UnitCell& ucell, std::ostream& warning_stream); | ||
| }; | ||
| } // namespace ModuleESolver | ||
|
|
||
|
|
||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non-blocking: Could you add a focused regression test for the captured settings and an injected
std::ostringstreamwarning sink?MODULE_PW_OfDFTonly compiles KEDF code, and the calculation cases do not distinguish the supplied sink fromGlobalV::ofs_warningor a retained snapshot from later global reads. The existing integration coverage is useful; this additional coverage can follow after merge.