ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
bfgs.h
Go to the documentation of this file.
1#ifndef BFGS_H
2#define BFGS_H
3
4#include <vector>
5#include <tuple>
6#include<algorithm>
7#include<cmath>
11#include "matrix_methods.h"
12
13class BFGS
14{
15public:
16 std::vector<double> steplength;//the length of atoms displacement
17 std::vector<std::vector<double>> H;//Hessian matrix
18 std::vector<double> force0;//force in previous step
19 std::vector<std::vector<double>> force;
20 std::vector<double> pos0;//atom pos in previous step(cartesian coordinates)
21 std::vector<std::vector<double>> pos;
22 std::vector<double> pos_taud0;//atom pos in previous step(relative coordinates)
23 std::vector<std::vector<double>> pos_taud;
24 std::vector<std::vector<double>> dpos;
25
26 void allocate(const int _size);//initialize parameters
27 void relax_step(const ModuleBase::matrix& _force,UnitCell& ucell);//a full iteration step
28 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);//calculate the atomic displacement in one iteration step
29
30private:
31 bool sign;//check if this is the first iteration
32 double alpha;//initialize H,diagonal element is alpha
33 double maxstep;//every movement smaller than maxstep
34 int size;//number of atoms
35
36 void IsRestrain(std::vector<std::vector<double>>& dpos);//check if converged
37 void CalculateLargestGrad(const ModuleBase::matrix& _force,UnitCell& ucell);
38 void GetPos(UnitCell& ucell,std::vector<std::vector<double>>& pos);
39 void GetPostaud(UnitCell& ucell,std::vector<std::vector<double>>& pos_taud);
40 void Update(std::vector<double>& pos, std::vector<double>& force,std::vector<std::vector<double>>& H,UnitCell& ucell);//update hessian matrix
41 void DetermineStep(std::vector<double>& steplength,std::vector<std::vector<double>>& dpos,double& maxstep);//normalize large atomic displacements based on maxstep
42 void UpdatePos(UnitCell& ucell);//update ucell with the new coordinates
43
44};
45
46#endif // BFGS_H
Definition bfgs.h:14
void GetPos(UnitCell &ucell, std::vector< std::vector< double > > &pos)
Definition bfgs.cpp:77
std::vector< std::vector< double > > dpos
Definition bfgs.h:24
void GetPostaud(UnitCell &ucell, std::vector< std::vector< double > > &pos_taud)
Definition bfgs.cpp:92
double maxstep
Definition bfgs.h:33
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)
Definition bfgs.cpp:108
double alpha
Definition bfgs.h:32
std::vector< double > pos_taud0
Definition bfgs.h:22
void allocate(const int _size)
initialize H0、H、pos0、force0、force
Definition bfgs.cpp:11
void CalculateLargestGrad(const ModuleBase::matrix &_force, UnitCell &ucell)
Definition bfgs.cpp:318
bool sign
Definition bfgs.h:31
std::vector< std::vector< double > > H
Definition bfgs.h:17
void relax_step(const ModuleBase::matrix &_force, UnitCell &ucell)
Definition bfgs.cpp:35
std::vector< double > steplength
Definition bfgs.h:16
std::vector< std::vector< double > > pos_taud
Definition bfgs.h:23
std::vector< double > pos0
Definition bfgs.h:20
void UpdatePos(UnitCell &ucell)
Definition bfgs.cpp:259
int size
Definition bfgs.h:34
void IsRestrain(std::vector< std::vector< double > > &dpos)
Definition bfgs.cpp:312
void DetermineStep(std::vector< double > &steplength, std::vector< std::vector< double > > &dpos, double &maxstep)
Definition bfgs.cpp:240
void Update(std::vector< double > &pos, std::vector< double > &force, std::vector< std::vector< double > > &H, UnitCell &ucell)
Definition bfgs.cpp:165
std::vector< std::vector< double > > force
Definition bfgs.h:19
std::vector< std::vector< double > > pos
Definition bfgs.h:21
std::vector< double > force0
Definition bfgs.h:18
Definition matrix.h:19
Definition unitcell.h:16