ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
bfgs_basic.h
Go to the documentation of this file.
1#ifndef BFGS_BASIC
2#define BFGS_BASIC
3
5
6#include <fstream>
7#include <iostream>
8#include <vector>
9
10// references
11// 1) Roger Fletcher, Practical Methods of Optimization, John Wiley and
12// Sons, Chichester, 2nd edn, 1987.
13// 2) Salomon R. Billeter, Alexander J. Turner, Walter Thiel,
14// Phys. Chem. Chem. Phys. 2, 2177 (2000).
15// 3) Salomon R. Billeter, Alessandro Curioni, Wanda Andreoni,
16// Comput. Mat. Science 27, 437, (2003).
17// 4) Ren Weiqing, PhD Thesis: Numerical Methods for the Study of Energy
18// Landscapes and Rare Events.
19
21{
22
23 public:
24 BFGS_Basic();
25 ~BFGS_Basic() = default;
26
27 //====================================================================
28 // Test seam.
29 //
30 // The BFGS state below is protected and the update machinery private,
31 // because only Ions_Move_BFGS drives them. The unit tests seed that state
32 // and step the algorithm one stage at a time, so each piece they touch is
33 // reachable through the accessors and wrappers here rather than by
34 // reinterpreting the access specifiers.
35 //
36 // Production code must keep using the protected/private names directly;
37 // nothing outside the tests should call the *_for_testing() wrappers.
38 //====================================================================
39
41 std::vector<double> &get_pos() { return pos; }
43 std::vector<double> &get_grad() { return grad; }
45 std::vector<double> &get_move() { return move; }
47 std::vector<double> &get_pos_p() { return pos_p; }
49 std::vector<double> &get_grad_p() { return grad_p; }
51 std::vector<double> &get_move_p() { return move_p; }
53 bool &get_save_flag() { return save_flag; }
55 bool &get_tr_min_hit() { return tr_min_hit; }
57 bool &get_wolfe_flag() { return wolfe_flag; }
61 int &get_bfgs_ndim() { return bfgs_ndim; }
62
65 const double &lat0,
66 int &update_iter,
67 std::ofstream &ofs,
68 std::vector<double> &etot_info,
69 const int test_relax_method)
70 {
71 new_step(lat0, update_iter, ofs, etot_info, test_relax_method);
72 }
75 void update_inverse_hessian_for_testing(const double &lat0, std::ofstream &ofs)
76 {
77 update_inverse_hessian(lat0, ofs);
78 }
79 void check_wolfe_conditions_for_testing(std::ofstream &ofs, std::vector<double> &etot_info)
80 {
81 check_wolfe_conditions(ofs, etot_info);
82 }
84 std::ofstream &ofs, std::vector<double> &etot_info, const int test_relax_method)
85 {
86 compute_trust_radius(ofs, etot_info, test_relax_method);
87 }
88
89 protected:
90 void allocate_basic(void);
91 void new_step(
92 const double &lat0,
93 int &update_iter,
94 std::ofstream &ofs,
95 std::vector<double> &etot_info,
96 const int test_relax_method);
97 void reset_hessian(void);
98 void save_bfgs(void);
99
100 std::vector<double> pos; // std::vector containing 3N coordinates of the system ( x )
101 std::vector<double> grad; // std::vector containing 3N components of ( grad( V(x) ) )
102 std::vector<double> move; // pos = pos_p + move.
103
104 std::vector<double> pos_p; // p: previous
105 std::vector<double> grad_p; // p: previous
106 std::vector<double> move_p;
107
108 public:
109 static double relax_bfgs_w1; // fixed: parameters for Wolfe conditions.
110 static double relax_bfgs_w2; // fixed: parameters for Wolfe conditions.
111
112 protected:
113 bool save_flag = false;
114 bool tr_min_hit = false; //.TRUE. if the trust_radius has already been set
115 // to the minimum value at the previous step
116
117 // mohan add 2010-07-27
118 double check_move(const double &lat0, const double &pos, const double &pos_p);
119
120 private:
121 bool wolfe_flag = false;
123
125
126 void update_inverse_hessian(const double &lat0, std::ofstream &ofs);
127 void check_wolfe_conditions(std::ofstream &ofs, std::vector<double> &etot_info);
128 void compute_trust_radius(std::ofstream &ofs, std::vector<double> &etot_info, const int test_relax_method);
129};
130
131#endif
void allocate_basic_for_testing()
Definition bfgs_basic.h:63
std::vector< double > & get_grad()
3N components of ( grad( V(x) ) )
Definition bfgs_basic.h:43
int bfgs_ndim
Definition bfgs_basic.h:124
std::vector< double > pos_p
Definition bfgs_basic.h:104
void save_bfgs(void)
Definition bfgs_basic.cpp:148
std::vector< double > & get_grad_p()
gradient of the previous step
Definition bfgs_basic.h:49
std::vector< double > pos
Definition bfgs_basic.h:100
static double relax_bfgs_w1
Definition bfgs_basic.h:109
ModuleBase::matrix inv_hess
Definition bfgs_basic.h:122
bool wolfe_flag
Definition bfgs_basic.h:121
void reset_hessian(void)
Definition bfgs_basic.cpp:129
void check_wolfe_conditions(std::ofstream &ofs, std::vector< double > &etot_info)
Definition bfgs_basic.cpp:97
static double relax_bfgs_w2
Definition bfgs_basic.h:110
std::vector< double > & get_pos_p()
coordinates of the previous step
Definition bfgs_basic.h:47
ModuleBase::matrix & get_inv_hess()
the inverse Hessian of the BFGS update
Definition bfgs_basic.h:59
bool & get_save_flag()
whether a bfgs state has been saved
Definition bfgs_basic.h:53
void compute_trust_radius_for_testing(std::ofstream &ofs, std::vector< double > &etot_info, const int test_relax_method)
Definition bfgs_basic.h:83
std::vector< double > & get_move_p()
step taken at the previous step
Definition bfgs_basic.h:51
void new_step(const double &lat0, int &update_iter, std::ofstream &ofs, std::vector< double > &etot_info, const int test_relax_method)
Definition bfgs_basic.cpp:163
std::vector< double > grad_p
Definition bfgs_basic.h:105
std::vector< double > move_p
Definition bfgs_basic.h:106
bool & get_tr_min_hit()
whether the trust radius already hit its minimum last step
Definition bfgs_basic.h:55
void compute_trust_radius(std::ofstream &ofs, std::vector< double > &etot_info, const int test_relax_method)
Definition bfgs_basic.cpp:266
bool tr_min_hit
Definition bfgs_basic.h:114
void save_bfgs_for_testing()
Definition bfgs_basic.h:74
std::vector< double > & get_move()
the step taken, pos = pos_p + move
Definition bfgs_basic.h:45
~BFGS_Basic()=default
bool & get_wolfe_flag()
whether the Wolfe conditions were satisfied
Definition bfgs_basic.h:57
void new_step_for_testing(const double &lat0, int &update_iter, std::ofstream &ofs, std::vector< double > &etot_info, const int test_relax_method)
Definition bfgs_basic.h:64
bool save_flag
Definition bfgs_basic.h:113
void check_wolfe_conditions_for_testing(std::ofstream &ofs, std::vector< double > &etot_info)
Definition bfgs_basic.h:79
double check_move(const double &lat0, const double &pos, const double &pos_p)
Definition bfgs_basic.cpp:352
std::vector< double > grad
Definition bfgs_basic.h:101
void update_inverse_hessian_for_testing(const double &lat0, std::ofstream &ofs)
Definition bfgs_basic.h:75
std::vector< double > move
Definition bfgs_basic.h:102
void reset_hessian_for_testing()
Definition bfgs_basic.h:73
void update_inverse_hessian(const double &lat0, std::ofstream &ofs)
Definition bfgs_basic.cpp:33
void allocate_basic(void)
Definition bfgs_basic.cpp:16
std::vector< double > & get_pos()
3N coordinates of the system ( x )
Definition bfgs_basic.h:41
int & get_bfgs_ndim()
number of previous steps kept by the BFGS update
Definition bfgs_basic.h:61
BFGS_Basic()
Definition bfgs_basic.cpp:14
Definition matrix.h:15