ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
relax_sync.h
Go to the documentation of this file.
1// Wenfei Li, November 2022
2// A new implementation of CG relaxation
3#ifndef RELAX1_H
4#define RELAX1_H
5
6#include "line_search.h"
10
11class Relax
12{
13 public:
14 Relax() {};
15 ~Relax() {};
16
17 // prepare for relaxation
18 void init_relax(const int nat_in);
19 // perform a single relaxation step
20 bool relax_step(UnitCell& ucell,
21 const ModuleBase::matrix& force,
22 const ModuleBase::matrix& stress,
23 const double etot_in);
24
25 private:
26 int istep = 0; // count ionic step
27
28 // setup gradient based on force and stress
29 // constraints are considered here
30 // also check if relaxation has converged
31 // based on threshold in force & stress
32 bool setup_gradient(const UnitCell& ucell, const ModuleBase::matrix& force, const ModuleBase::matrix& stress);
33
34 // check whether previous line search is done
35 bool check_line_search();
36
37 // if line search not done : perform line search
39
40 // if line search done: find new search direction and make a trial move
41 void new_direction();
42
43 // move ions and lattice vectors
44 void move_cell_ions(UnitCell& ucell, const bool is_new_dir);
45
46 int nat = 0; // number of atoms
47 bool ltrial = false; // if last step is trial step
48
49 double step_size = 0.0;
50
51 // Gradients; _p means previous step
56
57 // Search directions; _p means previous step
62
63 // Used for applyting constraints
64 bool if_cell_moves = false;
65
66 // Keeps track of how many CG trial steps have been performed,
67 // namely the number of CG directions followed
68 // Note : this should not be confused with number of ionic steps
69 // which includes both trial and line search steps
70 int cg_step = 0;
71
72 // in CG, search_dr = search_dr_p + grad * gamma
73 double gamma = 0.0;
74 void calculate_gamma();
75
76 // Intermediate variables
77 // I put them here because they are used across different subroutines
78 double sr_sr = 0.0;
79 double srp_srp = 0.0; // inner/cross products between search directions
80 double gr_gr = 0.0;
81 double gr_grp = 0.0;
82 double grp_grp = 0.0; // inner/cross products between gradients
83 double gr_sr = 0.0; // cross product between search direction and gradient
84 double e1ord1 = 0.0;
85 double e1ord2 = 0.0;
86 double e2ord = 0.0;
87 double e2ord2 = 0.0;
88 double dmove = 0.0;
89 double dmovel = 0.0;
90 double dmoveh = 0.0;
91 double etot = 0.0;
92 double etot_p = 0.0;
93 double force_thr_eva = 0.0;
94
95 bool brent_done = false; // if brent line search is finished
96
97 double fac_force = 0.0;
98 double fac_stress = 0.0;
99
102};
103
104#endif
Definition line_search.h:5
3x3 matrix and related mathamatical operations
Definition matrix3.h:19
Definition matrix.h:19
Definition relax_sync.h:12
void move_cell_ions(UnitCell &ucell, const bool is_new_dir)
Definition relax_sync.cpp:485
ModuleBase::matrix grad_ion_p
Definition relax_sync.h:54
double etot
Definition relax_sync.h:91
void new_direction()
Definition relax_sync.cpp:395
int istep
Definition relax_sync.h:26
int cg_step
Definition relax_sync.h:70
double step_size
Definition relax_sync.h:49
bool relax_step(UnitCell &ucell, const ModuleBase::matrix &force, const ModuleBase::matrix &stress, const double etot_in)
Definition relax_sync.cpp:58
bool setup_gradient(const UnitCell &ucell, const ModuleBase::matrix &force, const ModuleBase::matrix &stress)
Definition relax_sync.cpp:98
double fac_stress
Definition relax_sync.h:98
double gr_sr
Definition relax_sync.h:83
ModuleBase::matrix search_dr_cell
Definition relax_sync.h:59
bool brent_done
Definition relax_sync.h:95
double force_thr_eva
Definition relax_sync.h:93
double e2ord
Definition relax_sync.h:86
double dmoveh
Definition relax_sync.h:90
ModuleBase::matrix grad_cell
Definition relax_sync.h:53
ModuleBase::matrix search_dr_ion_p
Definition relax_sync.h:60
double e2ord2
Definition relax_sync.h:87
ModuleBase::matrix grad_cell_p
Definition relax_sync.h:55
ModuleBase::matrix grad_ion
Definition relax_sync.h:52
~Relax()
Definition relax_sync.h:15
double gr_gr
Definition relax_sync.h:80
double e1ord1
Definition relax_sync.h:84
ModuleBase::matrix search_dr_ion
Definition relax_sync.h:58
void perform_line_search()
Definition relax_sync.cpp:360
ModuleBase::Matrix3 latvec_save
Definition relax_sync.h:100
double dmovel
Definition relax_sync.h:89
ModuleBase::matrix search_dr_cell_p
Definition relax_sync.h:61
bool check_line_search()
Definition relax_sync.cpp:338
double gamma
Definition relax_sync.h:73
double gr_grp
Definition relax_sync.h:81
int nat
Definition relax_sync.h:46
Line_Search ls
Definition relax_sync.h:101
double srp_srp
Definition relax_sync.h:79
void init_relax(const int nat_in)
Definition relax_sync.cpp:15
double e1ord2
Definition relax_sync.h:85
Relax()
Definition relax_sync.h:14
double fac_force
Definition relax_sync.h:97
double dmove
Definition relax_sync.h:88
double grp_grp
Definition relax_sync.h:82
double etot_p
Definition relax_sync.h:92
bool if_cell_moves
Definition relax_sync.h:64
bool ltrial
Definition relax_sync.h:47
double sr_sr
Definition relax_sync.h:78
void calculate_gamma()
Definition relax_sync.cpp:287
Definition unitcell.h:16