Skip to content

Commit 0ee6b28

Browse files
mohanchenabacus_fixer
andauthored
Refactor the relax module (#7456)
* format update * replace new with vector * format update * update * update * update * move bfgs.h to ions_move_bfgs2.h * fix * add relax_data * update * update * update * fix * fix test of relax module * remove ZEROS function * remove GlobalC, phase 1 * fix bug * remove GlobalV::ofs_running * fix bugs * update * remove esolver_ks.h * fix a bug * delete useless variable * refactor(relax_driver): 重构弛豫驱动模块 主要修改: 1. 移除了 relax_driver.h 中未使用的 Ions_Move_BFGS2 bfgs_trad 成员变量及其头文件包含 2. 将 relax_driver.cpp 中 while 循环内的逻辑拆分为多个独立函数: - init_relax(): 初始化弛豫方法 - iter_info(): 打印迭代信息 - esolve(): 电子结构计算 - relax_step(): 执行单次弛豫步骤 - stru_out(): 输出结构文件 - json_out(): 输出 JSON 结果 - stop_cond(): 检查停止条件 - final_out(): 最终输出 3. 添加了成员变量用于缓存计算结果:force_, stress_, force_step, stress_step 4. 优化了 final_out() 函数,将重复的条件判断合并为早期返回 5. 所有成员变量和成员函数调用都添加了 this-> 前缀,提高代码可读性 * update * change name * update * optimize * update * improve the logic * update * change istep starting from 0 * update istep, should be starting from 0, when output, should be istep+1 * remove class variables * update * update * update * update * update * move istep in ions_move_basic.h * remove converged variable in ions_move_basic * fix test * remove a parameter update_iter in ions_move_basic * remove some variables abot etot and etot_p * update, remove variables * update * remove relax_methods * delete useless variables * update move_cg method * remove static members in lattice_change_cg files --------- Co-authored-by: abacus_fixer <mohanchen@pku.eud.cn>
1 parent 2cdb1f6 commit 0ee6b28

53 files changed

Lines changed: 2386 additions & 2552 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

python/pyabacus/src/ModuleDriver/py_driver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ CalculationResult PyDriver::run(
442442
if (cal == "scf" || cal == "relax" || cal == "cell-relax" || cal == "nscf")
443443
{
444444
Relax_Driver rl_driver;
445-
rl_driver.relax_driver(impl_->p_esolver_, *impl_->ucell_, PARAM.inp);
445+
rl_driver.relax_driver(impl_->p_esolver_, *impl_->ucell_, PARAM.inp, GlobalV::ofs_running);
446446
}
447447
else if (cal == "get_s")
448448
{

source/Makefile.Objects

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -460,10 +460,13 @@ OBJS_PW=fft_bundle.o\
460460
pw_transform.o\
461461
pw_transform_k.o\
462462

463-
OBJS_RELAXATION=bfgs_basic.o\
463+
OBJS_RELAXATION=relax_data.o\
464+
cg_base.o\
465+
bfgs_basic.o\
464466
relax_driver.o\
465467
ions_move_basic.o\
466468
ions_move_bfgs.o\
469+
ions_move_bfgs2.o\
467470
ions_move_cg.o\
468471
ions_move_methods.o\
469472
ions_move_sd.o\
@@ -472,8 +475,7 @@ OBJS_RELAXATION=bfgs_basic.o\
472475
lattice_change_methods.o\
473476
relax_nsync.o\
474477
relax_sync.o\
475-
bfgs.o\
476-
lbfgs.o\
478+
ions_move_lbfgs.o\
477479
matrix_methods.o\
478480
line_search.o\
479481

source/source_io/module_parameter/input_conv.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,6 @@ void Input_Conv::Convert()
190190
Ions_Move_Basic::relax_bfgs_rmax = PARAM.inp.relax_bfgs_rmax;
191191
Ions_Move_Basic::relax_bfgs_rmin = PARAM.inp.relax_bfgs_rmin;
192192
Ions_Move_Basic::relax_bfgs_init = PARAM.inp.relax_bfgs_init;
193-
Ions_Move_Basic::out_stru = PARAM.inp.out_stru; // mohan add 2012-03-23
194-
Ions_Move_Basic::relax_method = PARAM.inp.relax_method;
195193
Lattice_Change_Basic::fixed_axes = PARAM.inp.fixed_axes;
196194

197195

source/source_io/test/for_testing_input_conv.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ double BFGS_Basic::relax_bfgs_w2 = -1.0;
9090
double Ions_Move_Basic::relax_bfgs_rmax = -1.0;
9191
double Ions_Move_Basic::relax_bfgs_rmin = -1.0;
9292
double Ions_Move_Basic::relax_bfgs_init = -1.0;
93-
int Ions_Move_Basic::out_stru = 0;
9493
double Ions_Move_CG::RELAX_CG_THR = -1.0;
9594
std::string Lattice_Change_Basic::fixed_axes = "None";
9695
int ModuleSymmetry::Symmetry::symm_flag = 0;

source/source_main/driver_run.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void Driver::driver_run()
8181
else if (cal == "scf" || cal == "relax" || cal == "cell-relax" || cal == "nscf")
8282
{
8383
Relax_Driver rl_driver;
84-
rl_driver.relax_driver(p_esolver, ucell, PARAM.inp);
84+
rl_driver.relax_driver(p_esolver, ucell, PARAM.inp, GlobalV::ofs_running);
8585
}
8686
else if (cal == "get_s")
8787
{

source/source_relax/CMakeLists.txt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
add_library(
22
relax
33
OBJECT
4-
4+
relax_data.cpp
5+
cg_base.cpp
56
relax_driver.cpp
6-
77
relax_sync.cpp
88
line_search.cpp
9-
10-
bfgs.cpp
11-
lbfgs.cpp
9+
ions_move_lbfgs.cpp
1210
relax_nsync.cpp
1311
bfgs_basic.cpp
1412
ions_move_basic.cpp
1513
ions_move_bfgs.cpp
14+
ions_move_bfgs2.cpp
1615
ions_move_cg.cpp
1716
ions_move_sd.cpp
1817
ions_move_methods.cpp

0 commit comments

Comments
 (0)