Skip to content

Commit 819cf12

Browse files
committed
Fix: SDFT bug after merge
1 parent e97a39e commit 819cf12

File tree

5 files changed

+63
-5
lines changed

5 files changed

+63
-5
lines changed

source/src_pw/stress_func_kin.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,15 @@ void Stress_Func::stress_kin(ModuleBase::matrix& sigma)
5151
{
5252
for(int ibnd=0;ibnd<GlobalV::NBANDS;ibnd++)
5353
{
54-
const std::complex<double>* ppsi = &(GlobalC::wf.psi[0](ik, ibnd, 0));
54+
const std::complex<double>* ppsi=nullptr;
55+
if(GlobalC::wf.psi!=nullptr)
56+
{
57+
ppsi = &(GlobalC::wf.psi[0](ik, ibnd, 0));
58+
}
59+
else
60+
{
61+
ppsi = &(GlobalC::wf.evc[ik](ibnd, 0));
62+
}
5563
for(int i=0;i<npw;i++)
5664
{
5765
s_kin[l][m] +=

source/src_pw/stress_func_mgga.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,18 @@ void Stress_Func::stress_mgga(ModuleBase::matrix& sigma)
4444
for (int ibnd = 0; ibnd < GlobalV::NBANDS; ibnd++)
4545
{
4646
const double w1 = GlobalC::wf.wg(ik, ibnd) / GlobalC::ucell.omega;
47+
const std::complex<double>* ppsi=nullptr;
48+
if(GlobalC::wf.psi!=nullptr)
49+
{
50+
ppsi = &(GlobalC::wf.psi[0](ik, ibnd, 0));
51+
}
52+
else
53+
{
54+
ppsi = &(GlobalC::wf.evc[ik](ibnd, 0));
55+
}
4756
for(int ig = 0; ig<npw; ig++)
4857
{
49-
psi[ig]=GlobalC::wf.psi[0](ik, ibnd, ig);
58+
psi[ig] = ppsi[ig];
5059
}
5160
XC_Functional::grad_wfc(psi, ik, gradwfc, npw);
5261

source/src_pw/stress_func_nl.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,15 @@ void Stress_Func::stress_nl(ModuleBase::matrix& sigma)
6060
if(GlobalC::wf.wg(ik, ib) < ModuleBase::threshold_wg) continue;
6161
for (int i = 0; i < nkb; i++)
6262
{
63-
const std::complex<double>* ppsi = &(GlobalC::wf.psi[0](ik, ib, 0));
63+
const std::complex<double>* ppsi=nullptr;
64+
if(GlobalC::wf.psi!=nullptr)
65+
{
66+
ppsi = &(GlobalC::wf.psi[0](ik, ib, 0));
67+
}
68+
else
69+
{
70+
ppsi = &(GlobalC::wf.evc[ik](ib, 0));
71+
}
6472
const std::complex<double>* pvkb = &(GlobalC::ppcell.vkb(i, 0));
6573
for (int ig = 0; ig < GlobalC::wf.npw; ig++)
6674
{
@@ -146,7 +154,15 @@ void Stress_Func::stress_nl(ModuleBase::matrix& sigma)
146154
if(GlobalC::wf.wg(ik, ib) < ModuleBase::threshold_wg) continue;
147155
for (int i=0; i<nkb; i++)
148156
{
149-
const std::complex<double>* ppsi = &(GlobalC::wf.psi[0](ik, ib, 0));
157+
const std::complex<double>* ppsi=nullptr;
158+
if(GlobalC::wf.psi!=nullptr)
159+
{
160+
ppsi = &(GlobalC::wf.psi[0](ik, ib, 0));
161+
}
162+
else
163+
{
164+
ppsi = &(GlobalC::wf.evc[ik](ib, 0));
165+
}
150166
const std::complex<double>* pdbecp_noevc = &(dbecp_noevc(i, 0));
151167
for (int ig=0; ig<GlobalC::wf.npw; ig++)
152168
{

source/src_pw/wavefunc.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,14 @@ void wavefunc::allocate(const int nks)
128128
std::cout << " MEMORY FOR PSI (MB) : " <<
129129
ModuleBase::Memory::record("wavefunc","evc",nks2*GlobalV::NBANDS*(prefactor*npwx),"complexmatrix") << std::endl;
130130
}
131+
else if(GlobalV::CALCULATION.substr(0,3) == "sto")
132+
{
133+
this->evc = new ModuleBase::ComplexMatrix [nks2];
134+
for (int ik = 0; ik < nks2; ik++)
135+
{
136+
this->evc[ik].create(GlobalV::NBANDS, npwx * GlobalV::NPOL);//added by zhengdy-soc
137+
}
138+
}
131139
else
132140
{
133141
//initial psi rather than evc
@@ -359,7 +367,14 @@ void wavefunc::wfcinit_k(void)
359367
// get the wave functions
360368
// by first diagolize PAO
361369
// wave functions.
362-
this->diago_PAO_in_pw_k(ik, this->psi[0]);
370+
if(GlobalV::CALCULATION.substr(0,3) == "sto")
371+
{
372+
this->diago_PAO_in_pw_k(ik, this->evc[ik]);
373+
}
374+
else
375+
{
376+
this->diago_PAO_in_pw_k(ik, this->psi[0]);
377+
}
363378
}
364379
#ifdef __LCAO
365380
else if(GlobalV::BASIS_TYPE=="lcao_in_pw")
@@ -823,6 +838,15 @@ void wavefunc::init_after_vc(const int nks)
823838
}
824839

825840
//temporary function for nscf
841+
void wavefunc::diago_PAO_in_pw_k(const int &ik, ModuleBase::ComplexMatrix &wvf)
842+
{
843+
ModuleBase::TITLE("wavefunc","diago_PAO_in_pw_k");
844+
845+
GlobalC::hm.hpw.init_k(ik);
846+
this->diago_PAO_in_pw_k2(ik, wvf);
847+
848+
return;
849+
}
826850
void wavefunc::diago_PAO_in_pw_k2(const int &ik, ModuleBase::ComplexMatrix &wvf)
827851
{
828852
ModuleBase::TITLE("wavefunc","diago_PAO_in_pw_k2");

source/src_pw/wavefunc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class wavefunc : public WF_atomic
4545
// evc: get the initial wave functions from diagnalized the PAO
4646
// orbitals first.
4747
void diago_PAO_in_pw_k(const int &ik, psi::Psi<std::complex<double>> &wvf);
48+
void diago_PAO_in_pw_k(const int &ik, ModuleBase::ComplexMatrix &wvf);
4849

4950
// used if k dependent staff is ready.
5051
void prepare_k(void);

0 commit comments

Comments
 (0)