ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
ions_move_bfgs2.h
Go to the documentation of this file.
1#ifndef IONS_MOVE_BFGS2_H
2#define IONS_MOVE_BFGS2_H
3
7
8#include <algorithm>
9#include <cmath>
10#include <fstream>
11#include <tuple>
12#include <vector>
13
14struct Relax_Criteria;
15
17{
18 public:
19 void allocate(const int _size); // initialize parameters
20 void reset();
21 bool relax_step(
22 const ModuleBase::matrix &_force,
23 UnitCell &ucell,
24 std::ofstream &ofs_running,
25 const Relax_Criteria &criteria); // a full iteration step
26
29 bool get_is_initialized() const { return is_initialized; }
30
31 private:
32 // The unit test drives the private step machinery directly (seeding the
33 // Hessian and the previous-step state, then calling one stage at a time).
34 friend class BFGSTest;
35
36 bool sign; // check if this is the first iteration
37 double alpha; // initialize H,diagonal element is alpha
38 double maxstep; // every movement smaller than maxstep
39 int size; // number of atoms
40 bool is_initialized = false;
41
42 std::vector<double> steplength; // the length of atoms displacement
43 std::vector<std::vector<double>> H; // Hessian matrix
44 std::vector<double> force0; // force in previous step
45 std::vector<ModuleBase::Vector3<double>> force;
46 std::vector<double> pos0; // atom pos in previous step(cartesian coordinates)
47 std::vector<ModuleBase::Vector3<double>> pos;
48 std::vector<double> pos_taud0; // atom pos in previous step(relative coordinates)
49 std::vector<ModuleBase::Vector3<double>> pos_taud;
50 std::vector<ModuleBase::Vector3<double>> dpos;
51
52 void PrepareStep(
54 std::vector<ModuleBase::Vector3<double>> &pos,
55 std::vector<std::vector<double>> &H,
56 std::vector<double> &pos0,
57 std::vector<double> &force0,
58 std::vector<double> &steplength,
60 int &size,
61 UnitCell &ucell); // calculate the atomic displacement in one iteration step
62 bool IsRestrain(const double force_thr_ev); // check if converged
63 void CalculateLargestGrad(const ModuleBase::matrix &_force, UnitCell &ucell);
64 void GetPos(UnitCell &ucell, std::vector<ModuleBase::Vector3<double>> &pos);
65 void GetPostaud(UnitCell &ucell, std::vector<ModuleBase::Vector3<double>> &pos_taud);
66 void Update(
67 std::vector<double> &pos,
68 std::vector<double> &force,
69 std::vector<std::vector<double>> &H,
70 UnitCell &ucell); // update hessian matrix
71 void DetermineStep(
72 std::vector<double> &steplength, std::vector<ModuleBase::Vector3<double>> &dpos,
73 double &maxstep); // normalize large atomic displacements based on maxstep
74 void UpdatePos(UnitCell &ucell); // update ucell with the new coordinates
75};
76
77#endif // IONS_MOVE_BFGS2_H
Definition ions_move_bfgs2.h:17
void Update(std::vector< double > &pos, std::vector< double > &force, std::vector< std::vector< double > > &H, UnitCell &ucell)
Definition ions_move_bfgs2.cpp:192
int size
Definition ions_move_bfgs2.h:39
std::vector< ModuleBase::Vector3< double > > pos
Definition ions_move_bfgs2.h:47
void allocate(const int _size)
initialize H0、H、pos0、force0、force
Definition ions_move_bfgs2.cpp:12
std::vector< ModuleBase::Vector3< double > > force
Definition ions_move_bfgs2.h:45
bool is_initialized
Definition ions_move_bfgs2.h:40
std::vector< ModuleBase::Vector3< double > > dpos
Definition ions_move_bfgs2.h:50
void CalculateLargestGrad(const ModuleBase::matrix &_force, UnitCell &ucell)
Definition ions_move_bfgs2.cpp:344
bool IsRestrain(const double force_thr_ev)
Definition ions_move_bfgs2.cpp:380
std::vector< double > pos0
Definition ions_move_bfgs2.h:46
std::vector< double > pos_taud0
Definition ions_move_bfgs2.h:48
bool get_is_initialized() const
whether allocate() has run and the optimiser holds live state. reset() clears it; ions_move_methods_t...
Definition ions_move_bfgs2.h:29
bool relax_step(const ModuleBase::matrix &_force, UnitCell &ucell, std::ofstream &ofs_running, const Relax_Criteria &criteria)
Definition ions_move_bfgs2.cpp:39
void GetPos(UnitCell &ucell, std::vector< ModuleBase::Vector3< double > > &pos)
Definition ions_move_bfgs2.cpp:98
void DetermineStep(std::vector< double > &steplength, std::vector< ModuleBase::Vector3< double > > &dpos, double &maxstep)
Definition ions_move_bfgs2.cpp:274
friend class BFGSTest
Definition ions_move_bfgs2.h:34
std::vector< std::vector< double > > H
Definition ions_move_bfgs2.h:43
std::vector< double > force0
Definition ions_move_bfgs2.h:44
std::vector< ModuleBase::Vector3< double > > pos_taud
Definition ions_move_bfgs2.h:49
bool sign
Definition ions_move_bfgs2.h:36
void PrepareStep(std::vector< ModuleBase::Vector3< double > > &force, std::vector< ModuleBase::Vector3< double > > &pos, std::vector< std::vector< double > > &H, std::vector< double > &pos0, std::vector< double > &force0, std::vector< double > &steplength, std::vector< ModuleBase::Vector3< double > > &dpos, int &size, UnitCell &ucell)
Definition ions_move_bfgs2.cpp:131
void UpdatePos(UnitCell &ucell)
Definition ions_move_bfgs2.cpp:293
double alpha
Definition ions_move_bfgs2.h:37
double maxstep
Definition ions_move_bfgs2.h:38
void GetPostaud(UnitCell &ucell, std::vector< ModuleBase::Vector3< double > > &pos_taud)
Definition ions_move_bfgs2.cpp:115
std::vector< double > steplength
Definition ions_move_bfgs2.h:42
void reset()
Definition ions_move_bfgs2.cpp:37
3 elements vector
Definition vector3.h:21
Definition matrix.h:15
Provide the basic information about unitcell.
Definition unitcell.h:16
INPUT-derived settings that the relaxation algorithms need.
Definition relax_criteria.h:19