Skip to content

Commit d5b1c14

Browse files
committed
bfgs_trad
1 parent 4c75875 commit d5b1c14

File tree

4 files changed

+33
-13
lines changed

4 files changed

+33
-13
lines changed

source/module_relax/relax_new/bfgs.cpp

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
void BFGS::init_relax(const int _size,UnitCell& ucell,double _maxstep) // initialize H0、H、pos0、force0、force
77
{
88
alpha=70;//relax_scale_force
9-
maxstep=_maxstep;
9+
maxstep=_maxstep;
10+
if(maxstep==0)
11+
{
12+
maxstep=0.8;
13+
}
1014
size=_size;
1115
sign =true;
1216
H = std::vector<std::vector<double>>(3*size, std::vector<double>(3*size, 0.0));
@@ -40,18 +44,19 @@ bool BFGS::relax_step(ModuleBase::matrix _force,UnitCell& ucell)
4044
//std::cout<<"enter Step0"<<std::endl;
4145
//std::cout<<size<<std::endl;
4246
//GetPos(ucell);
43-
this->PrepareStep(force,pos,H,pos0,force0,steplength);
47+
this->PrepareStep(force,pos,H,pos0,force0,steplength,dpos);
4448
//std::cout<<"enter Step1"<<std::endl;
4549
this->DetermineStep(steplength,dpos,maxstep);
50+
4651
std::cout<<"enter Step2"<<std::endl;
47-
for(int i=0;i<size;i++)
52+
/*for(int i=0;i<size;i++)
4853
{
4954
for(int j=0;j<3;j++)
5055
{
5156
std::cout<<dpos[i][j]<<' ';
5257
}
5358
std::cout<<std::endl;
54-
}
59+
}*/
5560
this->UpdatePos(ucell);
5661
//std::cout<<"enter Step3"<<std::endl;
5762
return this->IsRestrain(dpos);
@@ -73,7 +78,7 @@ void BFGS::GetPos(UnitCell& ucell,std::vector<std::vector<double>>& pos)
7378
}
7479

7580

76-
void BFGS::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)
81+
void BFGS::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)
7782
{
7883
//std::cout<<"enter prepareStep0"<<std::endl;
7984
std::vector<double> changedforce = this->ReshapeMToV(force);
@@ -124,13 +129,29 @@ void BFGS::PrepareStep(std::vector<std::vector<double>>& force,std::vector<std::
124129
std::vector<double> a=this->DotInMAndV2(V, changedforce);
125130
for(int i = 0; i < a.size(); i++)
126131
{
127-
a[i] /= abs(omega[i]);
132+
if(omega[i]>0)
133+
{
134+
a[i] /= omega[i];
135+
}
136+
else if(omega[i]<0)
137+
{
138+
a[i] /= (-omega[i]);
139+
}
140+
128141
}
129142

130143
std::vector<double> tmpdpos = this->DotInMAndV1(V, a);
131144

132145

133146
dpos = this->ReshapeVToM(tmpdpos);
147+
/*for(int i=0;i<size;i++)
148+
{
149+
for(int j=0;j<3;j++)
150+
{
151+
std::cout<<dpos[i][j]<<' ';
152+
}
153+
std::cout<<std::endl;
154+
}*/
134155
for(int i = 0; i < size; i++)
135156
{
136157
double k = 0;
@@ -176,7 +197,7 @@ void BFGS::Update(std::vector<double> pos, std::vector<double> force,std::vector
176197
H = this->MSubM(H, this->MPlus(this->OuterVAndV(dg, dg), b));
177198
}
178199

179-
void BFGS::DetermineStep(std::vector<double> steplength,std::vector<std::vector<double>>& dpos,int maxstep)
200+
void BFGS::DetermineStep(std::vector<double> steplength,std::vector<std::vector<double>>& dpos,double maxstep)
180201
{
181202
auto maxsteplength = max_element(steplength.begin(), steplength.end());
182203
double a = *maxsteplength;

source/module_relax/relax_new/bfgs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class BFGS
3030

3131
void init_relax(const int _size,UnitCell& ucell,double _maxstep);//initialize parameters
3232
bool relax_step(ModuleBase::matrix _force,UnitCell& ucell);//
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);
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);
3434
bool IsRestrain(std::vector<std::vector<double>>& dpos);
3535

3636
private:
@@ -39,7 +39,7 @@ class BFGS
3939

4040
void GetPos(UnitCell& ucell,std::vector<std::vector<double>>& pos);
4141
void Update(std::vector<double> pos, std::vector<double> force,std::vector<std::vector<double>>& H);
42-
void DetermineStep(std::vector<double> steplength,std::vector<std::vector<double>>& dpos,int maxstep);
42+
void DetermineStep(std::vector<double> steplength,std::vector<std::vector<double>>& dpos,double maxstep);
4343
void UpdatePos(UnitCell& ucell);
4444

4545

tests/integrate/109_PW_CR/INPUT

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ suffix autotest
44
pseudo_dir ../../PP_ORB
55

66
nbands 8
7-
calculation cell_relax
7+
calculation cell-relax
88
#Parameters (Accuracy)
99
ecutwfc 20
1010
scf_nmax 20
1111
kpar 2
12-
nspin 1
12+
nspin 2
1313

1414
basis_type pw
1515
relax_nmax 2
@@ -20,7 +20,6 @@ stress_thr 1e-6
2020
cal_force 1
2121
force_thr_ev 1.0e-3
2222

23-
2423
#ks_solver scalapack_gvx
2524
mixing_type broyden
2625
mixing_beta 0.7

tests/integrate/109_PW_CR/KPT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
K_POINTS
22
0
33
Gamma
4-
2 2 2 0 0 0
4+
3 1 2 3 1 2

0 commit comments

Comments
 (0)