Skip to content

Commit 64e3118

Browse files
authored
Merge pull request #1214 from wenfei-li/develop
perf: allow soc in the accelerated vnl which also fixes a bug in the old vnl
2 parents f73db98 + b9e6b3f commit 64e3118

File tree

9 files changed

+148
-48
lines changed

9 files changed

+148
-48
lines changed

source/src_lcao/LCAO_gen_fixedH.cpp

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,6 @@ LCAO_gen_fixedH::~LCAO_gen_fixedH()
2424
void LCAO_gen_fixedH::calculate_NL_no(double* HlocR)
2525
{
2626
ModuleBase::TITLE("LCAO_gen_fixedH","calculate_NL_no");
27-
if(GlobalV::NSPIN==4)
28-
{
29-
this->build_Nonlocal_mu(HlocR, false);
30-
return;
31-
//ModuleBase::WARNING_QUIT("LCAO_gen_fixedH::calculate_NL_no","noncollinear case shoule be complex<double>* type");
32-
}
33-
3427
if(GlobalV::GAMMA_ONLY_LOCAL)
3528
{
3629
//for gamma only.
@@ -64,16 +57,6 @@ void LCAO_gen_fixedH::calculate_NL_no(double* HlocR)
6457
return;
6558
}
6659

67-
/*void LCAO_gen_fixedH::calculate_NL_no(std::complex<double>* HlocR)
68-
{
69-
ModuleBase::TITLE("LCAO_gen_fixedH","calculate_NL_no");
70-
if(GlobalV::NSPIN!=4) ModuleBase::WARNING_QUIT("LCAO_gen_fixedH::calculate_NL_no","complex<double>* type shoule be noncollinear case");
71-
72-
this->build_Nonlocal_mu(HlocR, false);
73-
74-
return;
75-
}*/
76-
7760
void LCAO_gen_fixedH::calculate_T_no(double* HlocR)
7861
{
7962
ModuleBase::TITLE("LCAO_gen_fixedH","calculate_T_no");
@@ -733,39 +716,51 @@ void LCAO_gen_fixedH::build_Nonlocal_mu_new(double* NLloc, const bool &calc_deri
733716
{
734717
std::vector<double> nlm_1=(*nlm_cur1_e)[iw1_all];
735718
std::vector<double> nlm_2=(*nlm_cur2_e)[iw2_all];
736-
double nlm_tmp = 0.0;
737-
738-
const int nproj = GlobalC::ucell.infoNL.nproj[T0];
739-
int ib = 0;
740-
for (int nb = 0; nb < nproj; nb++)
719+
if(GlobalV::NSPIN==4)
741720
{
742-
const int L0 = GlobalC::ucell.infoNL.Beta[T0].Proj[nb].getL();
743-
for(int m=0;m<2*L0+1;m++)
721+
std::complex<double> nlm_tmp = ModuleBase::ZERO;
722+
int is0 = (j-j0*GlobalV::NPOL) + (k-k0*GlobalV::NPOL)*2;
723+
for (int no = 0; no < GlobalC::ucell.atoms[T0].non_zero_count_soc[is0]; no++)
744724
{
745-
if(nlm_1[ib]!=0.0 && nlm_2[ib]!=0.0)
725+
const int p1 = GlobalC::ucell.atoms[T0].index1_soc[is0][no];
726+
const int p2 = GlobalC::ucell.atoms[T0].index2_soc[is0][no];
727+
nlm_tmp += nlm_1[p1] * nlm_2[p2] * GlobalC::ucell.atoms[T0].d_so(is0, p2, p1);
728+
}
729+
this->LM->Hloc_fixedR_soc[nnr+nnr_inner] += nlm_tmp;
730+
}
731+
else
732+
{
733+
double nlm_tmp = 0.0;
734+
const int nproj = GlobalC::ucell.infoNL.nproj[T0];
735+
int ib = 0;
736+
for (int nb = 0; nb < nproj; nb++)
737+
{
738+
const int L0 = GlobalC::ucell.infoNL.Beta[T0].Proj[nb].getL();
739+
for(int m=0;m<2*L0+1;m++)
746740
{
747-
nlm_tmp += nlm_1[ib]*nlm_2[ib]*GlobalC::ucell.atoms[T0].dion(nb,nb);
741+
if(nlm_1[ib]!=0.0 && nlm_2[ib]!=0.0)
742+
{
743+
nlm_tmp += nlm_1[ib]*nlm_2[ib]*GlobalC::ucell.atoms[T0].dion(nb,nb);
744+
}
745+
ib+=1;
748746
}
749-
ib+=1;
750747
}
751-
}
752-
assert(ib==nlm_1.size());
748+
assert(ib==nlm_1.size());
753749

754-
if(GlobalV::GAMMA_ONLY_LOCAL)
755-
{
756-
// mohan add 2010-12-20
757-
if( nlm_tmp!=0.0 )
750+
if(GlobalV::GAMMA_ONLY_LOCAL)
758751
{
759-
// GlobalV::ofs_running << std::setw(10) << iw1_all << std::setw(10)
760-
// << iw2_all << std::setw(20) << nlm[0] << std::endl;
761-
this->LM->set_HSgamma(iw1_all,iw2_all,nlm_tmp,'N', NLloc);//N stands for nonlocal.
752+
// mohan add 2010-12-20
753+
if( nlm_tmp!=0.0 )
754+
{
755+
this->LM->set_HSgamma(iw1_all,iw2_all,nlm_tmp,'N', NLloc);//N stands for nonlocal.
756+
}
762757
}
763-
}
764-
else
765-
{
766-
if( nlm_tmp!=0.0 )
758+
else
767759
{
768-
NLloc[nnr+nnr_inner] += nlm_tmp;
760+
if( nlm_tmp!=0.0 )
761+
{
762+
NLloc[nnr+nnr_inner] += nlm_tmp;
763+
}
769764
}
770765
}
771766
}// calc_deri
@@ -874,12 +869,10 @@ void LCAO_gen_fixedH::build_Nonlocal_mu_new(double* NLloc, const bool &calc_deri
874869

875870
if(!GlobalV::GAMMA_ONLY_LOCAL)
876871
{
877-
// std::cout << " nr=" << nnr << std::endl;
878-
// std::cout << " pv->nnr=" << pv->nnr << std::endl;
879-
// GlobalV::ofs_running << " nr=" << nnr << std::endl;
880-
// GlobalV::ofs_running << " pv->nnr=" << pv->nnr << std::endl;
881872
if( nnr!=pv->nnr)
882873
{
874+
GlobalV::ofs_running << " nr=" << nnr << std::endl;
875+
GlobalV::ofs_running << " pv->nnr=" << pv->nnr << std::endl;
883876
ModuleBase::WARNING_QUIT("LCAO_gen_fixedH::build_Nonlocal_mu_new","nnr!=LNNR.nnr");
884877
}
885878
}
@@ -1025,6 +1018,13 @@ void LCAO_gen_fixedH::build_Nonlocal_mu(double* NLloc, const bool &calc_deri)
10251018
if(!calc_deri)
10261019
{
10271020
int is0 = (j-j0*GlobalV::NPOL) + (k-k0*GlobalV::NPOL)*2;
1021+
//Note : there was a bug in the old implementation
1022+
//of soc nonlocal PP, which does not seem to affect the
1023+
//converged results though.
1024+
//However, there is a discrepancy in the integrate test case
1025+
//240*soc, when checked against the new method.
1026+
//The origin of the bug is the mismatch between the indexes
1027+
//of <psi|beta> and d_so
10281028
GlobalC::UOT.snap_psibeta(
10291029
GlobalC::ORB,
10301030
GlobalC::ucell.infoNL,
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
etotref -1870.568879523735
2-
etotperatomref -935.2844397619
3-
totaltimeref 16.605
1+
etotref -1870.520882454763
2+
etotperatomref -935.2604412274
3+
totaltimeref 8.5263
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
INPUT_PARAMETERS
2+
#Parameters (General)
3+
suffix autotest
4+
pseudo_dir ../tools/PP_ORB/
5+
ntype 2
6+
#nbands 40
7+
pseudo_type upf201
8+
gamma_only 0
9+
10+
11+
calculation scf
12+
symmetry 1
13+
14+
#test_force 1
15+
relax_nmax 1
16+
force_thr_ev 0.001
17+
out_level ie
18+
relax_method cg
19+
out_chg 1
20+
#out_band 1
21+
#init_chg file
22+
23+
smearing_method gaussian
24+
smearing_sigma 0.001
25+
#Parameters (3.PW)
26+
ecutwfc 20
27+
scf_thr 1e-6
28+
scf_nmax 100
29+
30+
31+
#cal_stress 1
32+
#noncolin 1
33+
lspinorb 1
34+
35+
#Parameters (LCAO)
36+
basis_type lcao
37+
ks_solver genelpa
38+
chg_extrap second-order
39+
out_dm 0
40+
pw_diag_thr 0.00001
41+
42+
43+
mixing_type pulay
44+
mixing_beta 0.4
45+
mixing_gg0 1.5
46+
47+
soc_lambda 0.0
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
K_POINTS
2+
0
3+
Gamma
4+
2 2 2 0 0 0
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
This test for:
2+
*GaAs-soc
3+
*LCAO
4+
*kpoints 2*2*2
5+
*sg15 pseudopotential
6+
*smearing_method gauss
7+
*ks_solver genelpa
8+
*mixing_type pulay-kerker
9+
*mixing_beta 0.4
10+
11+
Compared with 240*SO, I added parameter soc_lambda = 0 to this test case,
12+
which means I am performing the calculation in a nspin = 4 manner
13+
but with soc strength = 0
14+
Therefore, the result should be consistent with the calculation by turning off
15+
soc (i.e., set lspinorb to be 0 in the INPUT file)
16+
This is not the case for the old implementation of soc nonlocal PP (build_Nonlocal_mu)
17+
but the new implementation (build_Nonlocal_mu_new) fixed it
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
ATOMIC_SPECIES
2+
As 1 As_ONCV_PBE_FR-1.1.upf
3+
Ga 1 Ga_ONCV_PBE_FR-1.0.upf.txt
4+
5+
LATTICE_CONSTANT
6+
1 // add lattice constant, 10.58 ang
7+
8+
NUMERICAL_ORBITAL
9+
../tools/PP_ORB/As_gga_8au_60Ry_2s2p1d.orb
10+
../tools/PP_ORB/Ga_gga_9au_60Ry_2s2p2d.orb
11+
12+
LATTICE_VECTORS
13+
5.34197 5.34197 0.0
14+
0.0 5.34197 5.34197
15+
5.34197 0.0 5.34197
16+
ATOMIC_POSITIONS
17+
Direct //Cartesian or Direct coordinate.
18+
19+
As
20+
0
21+
1
22+
0.2500000 0.2500000 0.25000000 0 0 0
23+
24+
Ga //Element Label
25+
0
26+
1 //number of atom
27+
0.00000 0.00000 0.000000 0 0 0
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Func:LCAO/SOC(lspinorb=1); Sys:AsGa; Ref:energy
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
etotref -1870.759635935754
2+
etotperatomref -935.3798179679
3+
totaltimeref 8.4023

tests/integrate/CASES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@
144144
220_NO_KP_MD_NVE
145145
#230_NO_KP_MD_TD
146146
240_NO_KP_15_SO
147+
240_NO_KP_15_SO_average
147148
250_NO_KP_CR_VDW2
148149
250_NO_KP_CR_VDW3
149150
260_NO_15_PK_PU_AF

0 commit comments

Comments
 (0)