Skip to content

Commit 2a79ecb

Browse files
committed
update bfgs method
1 parent b377902 commit 2a79ecb

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

docs/advanced/input_files/input-main.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,6 +1369,7 @@ These variables are used to control the geometry relaxation.
13691369
- **Description**: The methods to do geometry optimization.
13701370
- cg: using the conjugate gradient (CG) algorithm. Note that there are two implementations of the conjugate gradient (CG) method, see [relax_new](#relax_new).
13711371
- bfgs: using the Broyden–Fletcher–Goldfarb–Shanno (BFGS) algorithm.
1372+
- bfgs_trad: using BFGS algorithm consistent with the BFGS algorithm in ASE.
13721373
- cg_bfgs: using the CG method for the initial steps, and switching to BFGS method when the force convergence is smaller than [relax_cg_thr](#relax_cg_thr).
13731374
- sd: using the steepest descent (SD) algorithm.
13741375
- fire: the Fast Inertial Relaxation Engine method (FIRE), a kind of molecular-dynamics-based relaxation algorithm, is implemented in the molecular dynamics (MD) module. The algorithm can be used by setting [calculation](#calculation) to `md` and [md_type](#md_type) to `fire`. Also ionic velocities should be set in this case. See [fire](../md.md#fire) for more details.

docs/advanced/opt.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ The [BFGS method](https://en.wikipedia.org/wiki/Broyden%E2%80%93Fletcher%E2%80%9
2424

2525
In ABACUS, we implemented the BFGS method for doing fixed-cell structural relaxation.
2626

27+
### BFGS_TRAD method
28+
29+
The BFGS_TRAD method is an algorithm implemented in ABACUS, referencing the BFGS method from ASE. The previous BFGS method in ABACUS did not perform well for some tests and the BFGS_TRAD method now produces results that are consistant with the BFGS method in ASE. In cases where the previous BFGS method could not converge within a limited number of steps, the BFGS_TRAD method can successfully converge.
30+
2731
### SD method
2832

2933
The [SD (steepest descent) method](https://en.wikipedia.org/wiki/Gradient_descent) is one of the simplest first-order optimization methods, where in each step the motion is along the direction of the gradient, where the function descents the fastest.

source/module_relax/relax_old/bfgs.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
void BFGS::allocate(const int _size) // initialize H0、H、pos0、force0、force
88
{
9-
alpha=70;
9+
alpha=70;//default value in ase is 70
1010
maxstep=PARAM.inp.relax_bfgs_rmax;
1111
size=_size;
1212
sign =true;
@@ -24,7 +24,7 @@ void BFGS::allocate(const int _size) // initialize H0、H、pos0、force0、forc
2424
steplength = std::vector<double>(size, 0.0);
2525
}
2626

27-
void BFGS::relax_step(ModuleBase::matrix _force,UnitCell& ucell)
27+
void BFGS::relax_step(const ModuleBase::matrix _force,UnitCell& ucell)
2828
{
2929
GetPos(ucell,pos);
3030
GetPostaud(ucell,pos_taud);
@@ -359,7 +359,7 @@ void BFGS::IsRestrain(std::vector<std::vector<double>>& dpos)
359359
Ions_Move_Basic::converged = Ions_Move_Basic::largest_grad * ModuleBase::Ry_to_eV / 0.529177<PARAM.inp.force_thr_ev;
360360
}
361361

362-
void BFGS::CalculateLargestGrad(ModuleBase::matrix& _force,UnitCell& ucell)
362+
void BFGS::CalculateLargestGrad(const ModuleBase::matrix& _force,UnitCell& ucell)
363363
{
364364
std::vector<double> grad= std::vector<double>(3*size, 0.0);
365365
int iat = 0;

source/module_relax/relax_old/bfgs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ class BFGS
4949
* @param _size
5050
*/
5151
void allocate(const int _size);//initialize parameters
52-
void relax_step(ModuleBase::matrix _force,UnitCell& ucell);//
52+
void relax_step(const ModuleBase::matrix _force,UnitCell& ucell);//
5353
void PrepareStep(std::vector<std::vector<double>>& force,std::vector<std::vector<double>>& pos,std::vector<std::vector<double>>& H,std::vector<double>& pos0,std::vector<double>& force0,std::vector<double>& steplength,std::vector<std::vector<double>>& dpos,UnitCell& ucell);
5454
void IsRestrain(std::vector<std::vector<double>>& dpos);
5555

5656
private:
5757
bool sign;
5858

59-
void CalculateLargestGrad(ModuleBase::matrix& _force,UnitCell& ucell);
59+
void CalculateLargestGrad(const ModuleBase::matrix& _force,UnitCell& ucell);
6060
void GetPos(UnitCell& ucell,std::vector<std::vector<double>>& pos);
6161
void GetPostaud(UnitCell& ucell,std::vector<std::vector<double>>& pos_taud);
6262
void Update(std::vector<double>& pos, std::vector<double>& force,std::vector<std::vector<double>>& H,UnitCell& ucell);

0 commit comments

Comments
 (0)