@@ -103,7 +103,8 @@ double ElecState::cal_delta_eband(const UnitCell& ucell) const
103103 const double * v_eff = this ->pot ->get_effective_v (0 );
104104 const double * v_fixed = this ->pot ->get_fixed_v ();
105105 const double * v_ofk = nullptr ;
106-
106+ const bool v_ofk_flag =(get_xc_func_type () == 3
107+ || get_xc_func_type () == 5 );
107108#ifdef USE_PAW
108109 if (PARAM.inp .use_paw )
109110 {
@@ -128,31 +129,33 @@ double ElecState::cal_delta_eband(const UnitCell& ucell) const
128129
129130 if (!PARAM.inp .use_paw )
130131 {
131- if (get_xc_func_type () == 3 || get_xc_func_type () == 5 )
132- {
133- v_ofk = this ->pot ->get_effective_vofk (0 );
134-
135- }
136-
137132 for (int ir = 0 ; ir < this ->charge ->rhopw ->nrxx ; ir++)
138133 {
139134 deband_aux -= this ->charge ->rho [0 ][ir] * (v_eff[ir] - v_fixed[ir]);
140- if (get_xc_func_type () == 3 || get_xc_func_type () == 5 )
135+ }
136+ if (v_ofk_flag)
137+ {
138+ v_ofk = this ->pot ->get_effective_vofk (0 );
139+ // cause in the get_effective_vofk, the func will return nullptr
140+ assert (v_ofk!=nullptr );
141+ for (int ir = 0 ; ir < this ->charge ->rhopw ->nrxx ; ir++)
141142 {
142- // cause in the get_effective_vofk, the func will return nullptr
143- assert (v_ofk!=nullptr );
144143 deband_aux -= this ->charge ->kin_r [0 ][ir] * v_ofk[ir];
145144 }
146145 }
147-
146+
148147 if (PARAM.inp .nspin == 2 )
149148 {
150149 v_eff = this ->pot ->get_effective_v (1 );
151- v_ofk = this ->pot ->get_effective_vofk (1 );
152150 for (int ir = 0 ; ir < this ->charge ->rhopw ->nrxx ; ir++)
153151 {
154152 deband_aux -= this ->charge ->rho [1 ][ir] * (v_eff[ir] - v_fixed[ir]);
155- if (get_xc_func_type () == 3 || get_xc_func_type () == 5 )
153+ }
154+ if (v_ofk_flag)
155+ {
156+ v_ofk = this ->pot ->get_effective_vofk (1 );
157+ assert (v_ofk!=nullptr );
158+ for (int ir = 0 ; ir < this ->charge ->rhopw ->nrxx ; ir++)
156159 {
157160 deband_aux -= this ->charge ->kin_r [1 ][ir] * v_ofk[ir];
158161 }
0 commit comments