@@ -64,22 +64,23 @@ void KEDF_XWM::set_para(double dV,
6464 */
6565double KEDF_XWM::get_energy (const double * const * prho, ModulePW::PW_Basis* pw_rho)
6666{
67- double ** w1Rho5_6 = new double *[PARAM .inp .nspin ];
68- for (int is = 0 ; is < PARAM .inp .nspin ; ++is)
67+ const int nspin = PARAM .inp .nspin ;
68+ double ** w1Rho5_6 = new double *[nspin];
69+ for (int is = 0 ; is < nspin; ++is)
6970 {
7071 w1Rho5_6[is] = new double [pw_rho->nrxx ];
7172 }
7273 this ->multi_kernel (prho, this ->kernel1_ .data (), w1Rho5_6, this ->kappa_5_6 , pw_rho);
7374
74- double ** w2Rho5_6 = new double *[PARAM . inp . nspin ];
75- for (int is = 0 ; is < PARAM . inp . nspin ; ++is)
75+ double ** w2Rho5_6 = new double *[nspin];
76+ for (int is = 0 ; is < nspin; ++is)
7677 {
7778 w2Rho5_6[is] = new double [pw_rho->nrxx ];
7879 }
7980 this ->multi_kernel (prho, this ->kernel2_ .data (), w2Rho5_6, this ->kappa_5_6 , pw_rho);
8081
8182 double energy = 0 .; // in Ry
82- if (PARAM . inp . nspin == 1 )
83+ if (nspin == 1 )
8384 {
8485 for (int ir = 0 ; ir < pw_rho->nrxx ; ++ir)
8586 {
@@ -88,14 +89,14 @@ double KEDF_XWM::get_energy(const double* const* prho, ModulePW::PW_Basis* pw_rh
8889 }
8990 energy += this ->dV_ ;
9091 }
91- else if (PARAM . inp . nspin == 2 )
92+ else if (nspin == 2 )
9293 {
9394 // TODO: spin polarized
9495 }
9596 this ->xwm_energy = energy;
9697 Parallel_Reduce::reduce_all (this ->xwm_energy );
9798
98- for (int is = 0 ; is < PARAM . inp . nspin ; ++is)
99+ for (int is = 0 ; is < nspin; ++is)
99100 {
100101 delete[] w1Rho5_6[is];
101102 delete[] w2Rho5_6[is];
@@ -379,4 +380,4 @@ void KEDF_XWM::fill_kernel(double tf_weight, double vw_weight, ModulePW::PW_Basi
379380 this ->kernel1_ [ig] = (this ->c_0 * lindhard + this ->c_2 * diff_lindhard) * this ->c_kernel ;
380381 this ->kernel2_ [ig] = this ->c_1 * diff_lindhard * this ->c_kernel ;
381382 }
382- }
383+ }
0 commit comments