Skip to content

Commit 5c1f914

Browse files
committed
gga fixed
1 parent 0482d45 commit 5c1f914

File tree

2 files changed

+30
-55
lines changed

2 files changed

+30
-55
lines changed

source/module_hamilt_general/module_xc/xc_functional_NCLibxc_gga.cpp

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,31 @@ void XC_Functional::postlibxc_gga(int xc_id, const std::vector<double>& rho_up,
167167
XC_Functional::grad_dot( vec_div_H1.data(), div_div_H1.data(), chr->rhopw, tpiba);
168168
XC_Functional::grad_dot( vec_div_H2.data(), div_div_H2.data(), chr->rhopw, tpiba);
169169
XC_Functional::grad_dot( vec_div_H3.data(), div_div_H3.data(), chr->rhopw, tpiba);
170-
171170

172-
171+
std::vector<std::complex<double>> g_vsigma_1(chr->rhopw->npw); // temporary storage for a vector in reciprocal space
172+
std::vector<std::complex<double>> g_vsigma_2(chr->rhopw->npw); // temporary storage for a vector in reciprocal space
173+
std::vector<std::complex<double>> g_vsigma_3(chr->rhopw->npw); // temporary storage for a vector in reciprocal space
174+
175+
std::vector<ModuleBase::Vector3<double>> grad_vsigma_1(nrxx);
176+
std::vector<ModuleBase::Vector3<double>> grad_vsigma_2(nrxx);
177+
std::vector<ModuleBase::Vector3<double>> grad_vsigma_3(nrxx);
178+
179+
chr->rhopw->real2recip(vsigma_1.data(), g_vsigma_1.data());
180+
XC_Functional::grad_rho(g_vsigma_1.data(), grad_vsigma_1.data(), chr->rhopw, tpiba);
181+
chr->rhopw->real2recip(vsigma_2.data(), g_vsigma_2.data());
182+
XC_Functional::grad_rho(g_vsigma_2.data(), grad_vsigma_2.data(), chr->rhopw, tpiba);
183+
chr->rhopw->real2recip(vsigma_3.data(), g_vsigma_3.data());
184+
XC_Functional::grad_rho(g_vsigma_3.data(), grad_vsigma_3.data(), chr->rhopw, tpiba);
185+
186+
std::vector<double> div_grad_vsigma_1(nrxx);
187+
std::vector<double> div_grad_vsigma_2(nrxx);
188+
std::vector<double> div_grad_vsigma_3(nrxx);
189+
190+
XC_Functional::grad_dot( grad_vsigma_1.data(), div_grad_vsigma_1.data(), chr->rhopw, tpiba);
191+
XC_Functional::grad_dot( grad_vsigma_2.data(), div_grad_vsigma_2.data(), chr->rhopw, tpiba);
192+
XC_Functional::grad_dot( grad_vsigma_3.data(), div_grad_vsigma_3.data(), chr->rhopw, tpiba);
193+
194+
173195
e.resize(rho_up.size());
174196
v1.resize(rho_up.size());
175197
v2.resize(rho_down.size());
@@ -183,9 +205,9 @@ void XC_Functional::postlibxc_gga(int xc_id, const std::vector<double>& rho_up,
183205
e[i] = exc[i] ;
184206
v1[i] = vrho_1[i]-div_hup[i] ;
185207
v2[i] = vrho_2[i]-div_hdn[i] ;
186-
f1[i] = v2rho2_1[i]-2.0*div_h1[i]+div_div_H1[i] ;
187-
f2[i] = v2rho2_2[i]-div_h2[i]+div_div_H2[i] ;
188-
f3[i] = v2rho2_3[i]-2.0*div_h3[i]+div_div_H3[i] ;
208+
f1[i] = v2rho2_1[i]-2.0*div_h1[i]+div_div_H1[i]-2.0*div_grad_vsigma_1[i] ;
209+
f2[i] = v2rho2_2[i]-div_h2[i]+div_div_H2[i] - div_grad_vsigma_2[i] ;
210+
f3[i] = v2rho2_3[i]-2.0*div_h3[i]+div_div_H3[i]-2.0*div_grad_vsigma_3[i] ;
189211
}
190212
}
191213

source/module_hamilt_general/module_xc/xc_functional_vxc.cpp

Lines changed: 3 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ std::tuple<double,double,ModuleBase::matrix> XC_Functional::v_xc(
116116
}
117117
}
118118
}
119-
else if(PARAM.inp.nspin == 4 && PARAM.inp.multicolin == 0)
119+
else if(PARAM.inp.nspin == 4 && !PARAM.inp.multicolin)
120120
{ //noncollinear case (Kubler's locally collinear) added by zhengdy
121121
#ifdef _OPENMP
122122
#pragma omp parallel for reduction(+:etxc) reduction(+:vtxc)
@@ -176,48 +176,11 @@ std::tuple<double,double,ModuleBase::matrix> XC_Functional::v_xc(
176176
}//end if
177177
// energy terms, local-density contributions
178178

179-
if (PARAM.inp.nspin == 4 && PARAM.inp.multicolin == 1
180-
&& (func_type == 0 || func_type == 1) )
179+
if (PARAM.inp.nspin == 4 && PARAM.inp.multicolin)
181180
{ // noncollinear case added by Xiaoyu Zhang, Peking University, 2024.10.02. multicollinear method for lda Since NCLibxc needs libxc, this part codes will not be used.
182181

183182
std::cerr << "Error: Multi-collinear approach does not support running without Libxc." << std::endl;
184183
std::exit(EXIT_FAILURE);
185-
// NCLibxc::print_NCLibxc();
186-
//#ifdef _OPENMP
187-
//#pragma omp parallel for reduction(+:etxc) reduction(+:vtxc)
188-
//#endif
189-
// for(int ir = 0;ir<nrxx; ir++)
190-
// {
191-
// if(!use_libxc){
192-
// std::cerr << "Error: Multi-collinear approach does not support running without Libxc." << std::endl;
193-
// std::exit(EXIT_FAILURE);
194-
// }
195-
// double exc = 0.0;
196-
// for(int ipol=0;ipol<4;ipol++){
197-
// v(ipol, ir) = 0;
198-
// }
199-
//
200-
// std::vector<double> n = {chr->rho[0][ir] + chr->rho_core[ir]};
201-
// std::vector<double> mx = {chr->rho[1][ir]};
202-
// std::vector<double> my = {chr->rho[2][ir]};
203-
// std::vector<double> mz = {chr->rho[3][ir]};
204-
// double amag = sqrt( pow(chr->rho[1][ir],2) + pow(chr->rho[2][ir],2) + pow(chr->rho[3][ir],2) );
205-
// if (n[0] - amag <= 0.0) { //ensure the rhoup and rhodn to libxc are positive
206-
// continue;
207-
// }
208-
// std::vector<double> E_MC;
209-
// std::vector<Matrix2x2> V_MC;
210-
// for(const int &id : func_id){
211-
// std::tie(E_MC, V_MC) = NCLibxc::lda_mc(id, n, mx, my, mz);
212-
// exc = e2*E_MC[0];
213-
// v(0, ir) += std::real(e2*(V_MC[0][0][0]+V_MC[0][1][1])/two);
214-
// v(1, ir) += std::real(e2*(V_MC[0][0][1]+V_MC[0][1][0])/two);
215-
// v(2, ir) += std::real(e2*(V_MC[0][1][0]-V_MC[0][0][1])/twoi);
216-
// v(3, ir) += std::real(e2*(V_MC[0][0][0]-V_MC[0][1][1])/two);
217-
// etxc += exc * n[0];
218-
// vtxc += v(0, ir) * chr->rho[0][ir] + v(1, ir) * chr->rho[1][ir] + v(2, ir) * chr->rho[2][ir] + v(3, ir) * chr->rho[3][ir];
219-
// }
220-
// }
221184
}
222185

223186

@@ -227,17 +190,7 @@ std::tuple<double,double,ModuleBase::matrix> XC_Functional::v_xc(
227190
// the dummy variable dum contains gradient correction to stress
228191
// which is not used here
229192
std::vector<double> dum;
230-
if(PARAM.inp.nspin == 4 && PARAM.inp.multicolin == 1) {
231-
if(func_type == 2 || func_type == 3) {
232-
//NCLibxc::print_NCLibxc();
233-
}
234-
if(func_type == 4 || func_type == 5) {
235-
std::cerr << "Error: Multi-collinear approach hasn't support hybrid functioanl yet" << std::endl;
236-
std::exit(EXIT_FAILURE);
237-
}
238-
} else {
239-
gradcorr(etxc, vtxc, v, chr, chr->rhopw, ucell, dum);
240-
}
193+
gradcorr(etxc, vtxc, v, chr, chr->rhopw, ucell, dum);
241194

242195
// parallel code : collect vtxc,etxc
243196
// mohan add 2008-06-01

0 commit comments

Comments
 (0)