Skip to content

Commit 13b70b2

Browse files
committed
fix bug
1 parent fc58546 commit 13b70b2

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

source/module_hamilt_general/module_xc/xc_functional_libxc_vxc.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,14 @@ std::tuple<double,double,ModuleBase::matrix> XC_Functional_Libxc::v_xc_libxc( /
122122
} // end for( xc_func_type &func : funcs )
123123

124124
if(4==PARAM.inp.nspin)
125-
{
126-
v = XC_Functional_Libxc::convert_v_nspin4(nrxx, chr, amag, v);
127-
if(PARAM.inp.multicolin)// added by Xiaoyu Zhang, Peking University, 2024.10.09. multicollinear method
125+
{
126+
if(!PARAM.inp.multicolin) // Kubler's locally collinear method
127+
{
128+
v = XC_Functional_Libxc::convert_v_nspin4(nrxx, chr, amag, v);
129+
}
130+
else // added by Xiaoyu Zhang, Peking University, 2024.10.09. multicollinear method
128131
{
129-
ModuleBase::matrix v_nspin4(PARAM.inp.nspin, nrxx);
132+
v.create(4, nrxx, true);
130133
etxc=0;
131134
vtxc=0;
132135
std::complex<double> twoi(0.0, 2.0);
@@ -142,7 +145,7 @@ std::tuple<double,double,ModuleBase::matrix> XC_Functional_Libxc::v_xc_libxc( /
142145
for(int ir = 0;ir<nrxx; ++ir){
143146
double exc = 0.0;
144147
for(int ipol=0;ipol<4;++ipol){
145-
v_nspin4(ipol, ir) = 0;
148+
v(ipol, ir) = 0;
146149
}
147150
std::vector<double> n = {chr->rho[0][ir] + chr->rho_core[ir]};
148151
std::vector<double> mx = {chr->rho[1][ir]};
@@ -155,15 +158,14 @@ std::tuple<double,double,ModuleBase::matrix> XC_Functional_Libxc::v_xc_libxc( /
155158
std::vector<double> E_MC;
156159
std::vector<Matrix2x2> V_MC;
157160
for(const int &id : func_id){
158-
//auto [E_MC, V_MC] = NCLibxc::lda_mc(id, n, mx, my, mz);
159161
std::tie(E_MC, V_MC) = NCLibxc::lda_mc(id, n, mx, my, mz);
160162
exc = e2*E_MC[0];
161-
v_nspin4(0, ir) += std::real(e2*(V_MC[0][0][0]+V_MC[0][1][1])/two);
162-
v_nspin4(1, ir) += std::real(e2*(V_MC[0][0][1]+V_MC[0][1][0])/two);
163-
v_nspin4(2, ir) += std::real(e2*(V_MC[0][1][0]-V_MC[0][0][1])/twoi);
164-
v_nspin4(3, ir) += std::real(e2*(V_MC[0][0][0]-V_MC[0][1][1])/two);
163+
v(0, ir) += std::real(e2*(V_MC[0][0][0]+V_MC[0][1][1])/two);
164+
v(1, ir) += std::real(e2*(V_MC[0][0][1]+V_MC[0][1][0])/two);
165+
v(2, ir) += std::real(e2*(V_MC[0][1][0]-V_MC[0][0][1])/twoi);
166+
v(3, ir) += std::real(e2*(V_MC[0][0][0]-V_MC[0][1][1])/two);
165167
etxc += exc * n[0];
166-
vtxc += v_nspin4(0, ir) * chr->rho[0][ir] + v_nspin4(1, ir) * mx[0] + v_nspin4(2, ir) * my[0] + v_nspin4(3, ir) * mz[0];// vtxc is used the calculation of the total energy(Ts more specifically), because abacus doesn't directly programme the kinetic operator and instead uses the sum of occupied orbital energy
168+
vtxc += v(0, ir) * chr->rho[0][ir] + v(1, ir) * mx[0] + v(2, ir) * my[0] + v(3, ir) * mz[0];// vtxc is used the calculation of the total energy(Ts more specifically), because abacus doesn't directly programme the kinetic operator and instead uses the sum of occupied orbital energy
167169
// the reason why i use chr->rho here is not clear. It is based on the implementation in v_xc.
168170
}
169171
}
@@ -193,12 +195,12 @@ std::tuple<double,double,ModuleBase::matrix> XC_Functional_Libxc::v_xc_libxc( /
193195
#endif
194196
for (int ir = 0; ir < nrxx; ++ir) {
195197
double exc = e2 * E_MC[ir];
196-
v_nspin4(0, ir) += std::real(e2 * (V_MC[ir][0][0] + V_MC[ir][1][1]) / two);
197-
v_nspin4(1, ir) += std::real(e2 * (V_MC[ir][0][1] + V_MC[ir][1][0]) / two);
198-
v_nspin4(2, ir) += std::real(e2 * (V_MC[ir][1][0] - V_MC[ir][0][1]) / twoi);
199-
v_nspin4(3, ir) += std::real(e2 * (V_MC[ir][0][0] - V_MC[ir][1][1]) / two);
198+
v(0, ir) += std::real(e2 * (V_MC[ir][0][0] + V_MC[ir][1][1]) / two);
199+
v(1, ir) += std::real(e2 * (V_MC[ir][0][1] + V_MC[ir][1][0]) / two);
200+
v(2, ir) += std::real(e2 * (V_MC[ir][1][0] - V_MC[ir][0][1]) / twoi);
201+
v(3, ir) += std::real(e2 * (V_MC[ir][0][0] - V_MC[ir][1][1]) / two);
200202
etxc += exc * n[ir];
201-
vtxc += v_nspin4(0, ir) * chr->rho[0][ir] + v_nspin4(1, ir) * mx[ir] + v_nspin4(2, ir) * my[ir] + v_nspin4(3, ir) * mz[ir];
203+
vtxc += v(0, ir) * chr->rho[0][ir] + v(1, ir) * mx[ir] + v(2, ir) * my[ir] + v(3, ir) * mz[ir];
202204
}
203205
}
204206
}

0 commit comments

Comments
 (0)