@@ -462,32 +462,35 @@ std::tuple<double,double,ModuleBase::matrix,ModuleBase::matrix> XC_Functional_Li
462462 voflapl (is,ir) += vlapl[ir*nspin+is] * sgn[ir*nspin+is];
463463 }
464464 }
465- }
465+ }
466466
467467 // v_xc += nabla^2(vlapl) where vlapl = d(rho*eps_xc)/d(nabla^2 rho)
468468 if (need_laplacian)
469469 {
470470 const int ng = chr->rhopw ->npw ;
471471 const double tpiba2 = tpiba * tpiba;
472- std::vector<std::complex <double >> lapl_tmp (chr->rhopw ->nmaxgr );
473- for (int is = 0 ; is < voflapl.nr ; is++)
472+ std::vector<double > lapl_r (nrxx);
473+ std::vector<std::complex <double >> lapl_g (ng);
474+ for (int is = 0 ; is < voflapl.nr ; is++)
474475 {
475- for (int ir = 0 ; ir < nrxx; ir++)
476- lapl_tmp[ir] = std:: complex < double >( voflapl (is, ir), 0.0 );
477- for ( int ig = ng; ig < chr-> rhopw -> nmaxgr ; ig++)
478- lapl_tmp[ig] = std:: complex < double >( 0.0 , 0.0 );
479- chr->rhopw ->real2recip (lapl_tmp .data (), lapl_tmp .data ());
480- for (int ig = 0 ; ig < ng; ig++)
476+ for (int ir = 0 ; ir < nrxx; ir++)
477+ {
478+ lapl_r[ir] = voflapl (is, ir);
479+ }
480+ chr->rhopw ->real2recip (lapl_r .data (), lapl_g .data ());
481+ for (int ig = 0 ; ig < ng; ig++)
481482 {
482483 double g2 = 0.0 ;
483- for (int i = 0 ; i < 3 ; i++)
484+ for (int i = 0 ; i < 3 ; i++)
485+ {
484486 g2 += chr->rhopw ->gcar [ig][i] * chr->rhopw ->gcar [ig][i];
485- lapl_tmp[ig] *= -g2 * tpiba2;
487+ }
488+ lapl_g[ig] *= -g2 * tpiba2;
486489 }
487- chr->rhopw ->recip2real (lapl_tmp .data (), lapl_tmp .data ());
488- for (int ir = 0 ; ir < nrxx; ir++)
490+ chr->rhopw ->recip2real (lapl_g .data (), lapl_r .data ());
491+ for (int ir = 0 ; ir < nrxx; ir++)
489492 {
490- double vlapl_corr = ModuleBase::e2 * lapl_tmp [ir]. real () ;
493+ double vlapl_corr = ModuleBase::e2 * lapl_r [ir];
491494 v (is, ir) += vlapl_corr;
492495 vtxc += vlapl_corr * chr->rho [is][ir];
493496 }
@@ -511,4 +514,4 @@ std::tuple<double,double,ModuleBase::matrix,ModuleBase::matrix> XC_Functional_Li
511514 return std::make_tuple ( etxc, vtxc, std::move (v), std::move (vofk) );
512515}
513516
514- #endif
517+ #endif
0 commit comments