Skip to content

Commit

Permalink
Implement a new BFGS optimizer, used for geometry relaxation (#5467)
Browse files Browse the repository at this point in the history
* bfgs

* bfgs1

* Update bfgs method

* bfgs_trad

* new bfgs method

* new bfgs_trad method

* new bfgs_trad

* bfgs_trad2

* bfgs_trad

* bfgs_trad

* bfgs_trad

* bfgs_trad

* bfgs_trad

* bfgs_trad

* bfgs_trad

* bfgs_trad

* bfgs_trad

* bfgs_trad

* Use force_ev_thr to judge optimization

* remove 108_PW_RE_MB_NEW

* Add determine whether an atom is movable code and modify the value of relax_bfgs_rmax to 0.2

* [pre-commit.ci lite] apply automatic fixes

* bfgs_trad

---------

Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
  • Loading branch information
19hello and pre-commit-ci-lite[bot] authored Dec 1, 2024
1 parent 4a1750a commit 028afb0
Show file tree
Hide file tree
Showing 21 changed files with 791 additions and 21 deletions.
2 changes: 2 additions & 0 deletions source/Makefile.Objects
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,8 @@ OBJS_RELAXATION=bfgs_basic.o\
relax_old.o\
relax.o\
line_search.o\
bfgs.o\


OBJS_SURCHEM=surchem.o\
H_correction_pw.o\
Expand Down
4 changes: 2 additions & 2 deletions source/module_io/read_input_item_relax.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ void ReadInput::item_relax()
item.annotation = "cg; bfgs; sd; cg; cg_bfgs;";
read_sync_string(input.relax_method);
item.check_value = [](const Input_Item& item, const Parameter& para) {
const std::vector<std::string> relax_methods = {"cg", "bfgs", "sd", "cg_bfgs"};
if (std::find(relax_methods.begin(), relax_methods.end(), para.input.relax_method) == relax_methods.end())
const std::vector<std::string> relax_methods = {"cg", "bfgs", "sd", "cg_bfgs","bfgs_trad"};
if (std::find(relax_methods.begin(),relax_methods.end(), para.input.relax_method)==relax_methods.end())
{
const std::string warningstr = nofound_str(relax_methods, "relax_method");
ModuleBase::WARNING_QUIT("ReadInput", warningstr);
Expand Down
2 changes: 1 addition & 1 deletion source/module_parameter/input_parameter.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ struct Input_para
double press3 = 0;
double relax_bfgs_w1 = 0.01; ///< wolfe condition 1
double relax_bfgs_w2 = 0.5; ///< wolfe condition 2
double relax_bfgs_rmax = 0.8; ///< trust radius max
double relax_bfgs_rmax = 0.2; ///< trust radius max
double relax_bfgs_rmin = 1e-05; ///< trust radius min
double relax_bfgs_init = 0.5; ///< initial move
std::string fixed_axes = "None"; ///< which axes are fixed
Expand Down
6 changes: 4 additions & 2 deletions source/module_relax/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ add_library(

relax_new/relax.cpp
relax_new/line_search.cpp


relax_old/bfgs.cpp
relax_old/relax_old.cpp
relax_old/bfgs_basic.cpp
relax_old/ions_move_basic.cpp
Expand All @@ -27,5 +28,6 @@ if(BUILD_TESTING)
if(ENABLE_MPI)
add_subdirectory(relax_new/test)
add_subdirectory(relax_old/test)
endif()
endif()

endif()
6 changes: 3 additions & 3 deletions source/module_relax/relax_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void Relax_Driver::relax_driver(ModuleESolver::ESolver* p_esolver, UnitCell& uce
ModuleBase::TITLE("Ions", "opt_ions");
ModuleBase::timer::tick("Ions", "opt_ions");

if (PARAM.inp.calculation == "relax" || PARAM.inp.calculation == "cell-relax")
if (PARAM.inp.calculation == "relax" || PARAM.inp.calculation == "cell-relax" )
{
if (!PARAM.inp.relax_new)
{
Expand All @@ -25,7 +25,7 @@ void Relax_Driver::relax_driver(ModuleESolver::ESolver* p_esolver, UnitCell& uce
rl.init_relax(ucell.nat);
}
}

this->istep = 1;
int force_step = 1; // pengfei Li 2018-05-14
int stress_step = 1;
Expand Down Expand Up @@ -90,7 +90,7 @@ void Relax_Driver::relax_driver(ModuleESolver::ESolver* p_esolver, UnitCell& uce
stress,
force_step,
stress_step); // pengfei Li 2018-05-14
}
}
// print structure
// changelog 20240509
// because I move out the dependence on GlobalV from UnitCell::print_stru_file
Expand Down
6 changes: 5 additions & 1 deletion source/module_relax/relax_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "module_esolver/esolver_ks.h"
#include "relax_new/relax.h"
#include "relax_old/relax_old.h"

#include "relax_old/bfgs.h"
class Relax_Driver
{

Expand All @@ -27,6 +27,10 @@ class Relax_Driver

// old relaxation method
Relax_old rl_old;

BFGS bfgs_trad;


};

#endif
5 changes: 3 additions & 2 deletions source/module_relax/relax_new/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ AddTest(

AddTest(
TARGET relax_new_relax
SOURCES relax_test.cpp ../relax.cpp ../line_search.cpp ../../../module_base/tool_quit.cpp ../../../module_base/global_variable.cpp ../../../module_base/global_file.cpp ../../../module_base/memory.cpp ../../../module_base/timer.cpp
SOURCES relax_test.cpp ../relax.cpp ../line_search.cpp ../../../module_base/tool_quit.cpp ../../../module_base/global_variable.cpp ../../../module_base/global_file.cpp ../../../module_base/memory.cpp ../../../module_base/timer.cpp
../../../module_base/matrix3.cpp ../../../module_base/intarray.cpp ../../../module_base/tool_title.cpp
../../../module_base/global_function.cpp ../../../module_base/complexmatrix.cpp ../../../module_base/matrix.cpp
../../../module_base/complexarray.cpp ../../../module_base/tool_quit.cpp ../../../module_base/realarray.cpp ../../../module_base/blas_connector.cpp
LIBS parameter ${math_libs}
)
)

Loading

0 comments on commit 028afb0

Please sign in to comment.