Skip to content

Commit 1899f53

Browse files
committed
bfgs_trad
1 parent 8baf4e8 commit 1899f53

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

source/Makefile.Objects

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,8 @@ OBJS_RELAXATION=bfgs_basic.o\
436436
relax_old.o\
437437
relax.o\
438438
line_search.o\
439+
bfgs.o\
440+
439441

440442
OBJS_SURCHEM=surchem.o\
441443
H_correction_pw.o\

source/module_io/read_input_item_relax.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ void ReadInput::item_relax()
1212
item.annotation = "cg; bfgs; sd; cg; cg_bfgs;";
1313
read_sync_string(input.relax_method);
1414
item.check_value = [](const Input_Item& item, const Parameter& para) {
15-
const std::vector<std::string> relax_methods = {"cg", "bfgs", "sd", "cg_bfgs"};
15+
const std::vector<std::string> relax_methods = {"cg", "bfgs", "sd", "cg_bfgs","bfgs_trad"};
1616
if (!find_str(relax_methods, para.input.relax_method))
1717
{
1818
const std::string warningstr = nofound_str(relax_methods, "relax_method");

source/module_relax/relax_driver.cpp

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@ void Relax_Driver::relax_driver(ModuleESolver::ESolver* p_esolver)
1414
ModuleBase::TITLE("Ions", "opt_ions");
1515
ModuleBase::timer::tick("Ions", "opt_ions");
1616

17-
if (PARAM.inp.calculation == "relax" || PARAM.inp.calculation == "cell-relax")
17+
if (PARAM.inp.calculation == "relax" || PARAM.inp.calculation == "cell-relax" )
1818
{
19-
if (!PARAM.inp.relax_new)
19+
if(PARAM.inp.relax_method == "relax_trad")
20+
{
21+
mybfgs.initialize(GlobalC::ucell.nat);
22+
}
23+
else if (!PARAM.inp.relax_new)
2024
{
2125
rl_old.init_relax(GlobalC::ucell.nat);
2226
}
@@ -25,7 +29,7 @@ void Relax_Driver::relax_driver(ModuleESolver::ESolver* p_esolver)
2529
rl.init_relax(GlobalC::ucell.nat);
2630
}
2731
}
28-
mybfgs.initialize(GlobalC::ucell.nat);
32+
2933

3034
this->istep = 1;
3135
int force_step = 1; // pengfei Li 2018-05-14
@@ -78,10 +82,27 @@ void Relax_Driver::relax_driver(ModuleESolver::ESolver* p_esolver)
7882

7983
if (PARAM.inp.calculation == "relax" || PARAM.inp.calculation == "cell-relax")
8084
{
81-
/*if (PARAM.inp.relax_new)
85+
if(PARAM.inp.relax_method == "bfgs_trad")
86+
{
87+
std::vector<std::vector<double>> _force(force.nr,std::vector<double>(force.nc,0));
88+
for(int i = 0; i < force.nr; i++)
89+
{
90+
91+
for(int j=0;j<force.nc;j++)
92+
{
93+
_force[i][j]=force(i,j)*13.605693009/ModuleBase::BOHR_TO_A;
94+
//std::cout<<_force[i][j]<<' ';
95+
}
96+
//std::cout<<std::endl;
97+
}
98+
stop=mybfgs.Step(_force,GlobalC::ucell);
99+
}
100+
101+
else if (PARAM.inp.relax_new)
82102
{
83103
stop = rl.relax_step(force, stress, this->etot);
84104
}
105+
85106
else
86107
{
87108
stop = rl_old.relax_step(istep,
@@ -91,19 +112,8 @@ void Relax_Driver::relax_driver(ModuleESolver::ESolver* p_esolver)
91112
stress,
92113
force_step,
93114
stress_step); // pengfei Li 2018-05-14
94-
}*/
95-
std::vector<std::vector<double>> _force(force.nr,std::vector<double>(force.nc,0));
96-
for(int i = 0; i < force.nr; i++)
97-
{
98-
99-
for(int j=0;j<force.nc;j++)
100-
{
101-
_force[i][j]=force(i,j)*13.605693009/ModuleBase::BOHR_TO_A;
102-
std::cout<<_force[i][j]<<' ';
103-
}
104-
std::cout<<std::endl;
105115
}
106-
stop=mybfgs.Step(_force,GlobalC::ucell);
116+
107117

108118
// print structure
109119
// changelog 20240509

0 commit comments

Comments
 (0)