diff --git a/docs/advanced/input_files/input-main.md b/docs/advanced/input_files/input-main.md index 4b9790fc27..2b5d1009af 100644 --- a/docs/advanced/input_files/input-main.md +++ b/docs/advanced/input_files/input-main.md @@ -1375,6 +1375,7 @@ These variables are used to control the geometry relaxation. - **Description**: The methods to do geometry optimization. - cg: using the conjugate gradient (CG) algorithm. Note that there are two implementations of the conjugate gradient (CG) method, see [relax_new](#relax_new). - bfgs: using the Broyden–Fletcher–Goldfarb–Shanno (BFGS) algorithm. + - bfgs_trad: using the traditional Broyden–Fletcher–Goldfarb–Shanno (BFGS) algorithm. - 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). - sd: using the steepest descent (SD) algorithm. - 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. diff --git a/docs/advanced/opt.md b/docs/advanced/opt.md index e27800aa4d..9c2023b655 100644 --- a/docs/advanced/opt.md +++ b/docs/advanced/opt.md @@ -22,7 +22,9 @@ In the nested procedure mentioned above, we used CG method to perform cell relax The [BFGS method](https://en.wikipedia.org/wiki/Broyden%E2%80%93Fletcher%E2%80%93Goldfarb%E2%80%93Shanno_algorithm) is a quasi-Newton method for solving nonlinear optimization problem. It belongs to the class of quasi-Newton method where the Hessian matrix is approximated during the optimization process. If the initial point is not far from the extrema, BFGS tends to work better than gradient-based methods. -In ABACUS, we implemented the BFGS method for doing fixed-cell structural relaxation. +There is an alternative traditional BFGS method, which can be called by using the keyword 'bfgs_trad'. The bfgs_trad method is a quasi-Newton method that substitute an approximate matrix B for the Hessian matrix. The main difference between 'bfgs' and 'bfgs_trad' is that 'bfgs' updates the inverse of matrix B while 'bfgs_trad' updates matrix B and obtains the inverse of B by solving the matrix eigenvalues and taking the reciprocal of the eigenvalues. Both methods are mathematically equivalent, but in some cases, 'bfgs_trad' performs better. + +In ABACUS, we implemented the BFGS method for doing fixed-cell structural relaxation. Users can choose which implementation of BFGS to call by adding the 'bfgs_trad' or 'bfgs' parameter. ### SD method diff --git a/source/module_relax/relax_old/bfgs.cpp b/source/module_relax/relax_old/bfgs.cpp index 01f96a7d5c..39bb3c991b 100644 --- a/source/module_relax/relax_old/bfgs.cpp +++ b/source/module_relax/relax_old/bfgs.cpp @@ -7,7 +7,7 @@ //! initialize H0、H、pos0、force0、force void BFGS::allocate(const int _size) { - alpha=70; + alpha=70;//default value in ase is 70 maxstep=PARAM.inp.relax_bfgs_rmax; size=_size; sign =true; @@ -29,8 +29,9 @@ void BFGS::allocate(const int _size) steplength = std::vector(size, 0.0); } -void BFGS::relax_step(ModuleBase::matrix _force, - UnitCell& ucell) + +void BFGS::relax_step(const ModuleBase::matrix& _force,UnitCell& ucell) + { GetPos(ucell,pos); GetPostaud(ucell,pos_taud); @@ -380,7 +381,7 @@ void BFGS::IsRestrain(std::vector>& dpos) * ModuleBase::Ry_to_eV / 0.529177 grad= std::vector(3*size, 0.0); int iat = 0; diff --git a/source/module_relax/relax_old/bfgs.h b/source/module_relax/relax_old/bfgs.h index 5b7ae415c0..fba422c886 100644 --- a/source/module_relax/relax_old/bfgs.h +++ b/source/module_relax/relax_old/bfgs.h @@ -49,14 +49,14 @@ class BFGS * @param _size */ void allocate(const int _size);//initialize parameters - void relax_step(ModuleBase::matrix _force,UnitCell& ucell);// + void relax_step(const ModuleBase::matrix& _force,UnitCell& ucell);// void PrepareStep(std::vector>& force,std::vector>& pos,std::vector>& H,std::vector& pos0,std::vector& force0,std::vector& steplength,std::vector>& dpos,UnitCell& ucell); void IsRestrain(std::vector>& dpos); private: bool sign; - void CalculateLargestGrad(ModuleBase::matrix& _force,UnitCell& ucell); + void CalculateLargestGrad(const ModuleBase::matrix& _force,UnitCell& ucell); void GetPos(UnitCell& ucell,std::vector>& pos); void GetPostaud(UnitCell& ucell,std::vector>& pos_taud); void Update(std::vector& pos, std::vector& force,std::vector>& H,UnitCell& ucell);