@@ -71,13 +71,11 @@ void IState_Envelope::begin(Local_Orbital_wfc& lowf, Gint_Gamma& gg, int& out_wf
7171 }
7272
7373 // for pw-wfc in G space
74- ModuleBase::ComplexMatrix* pw_wfc_g;
74+ psi::Psi<std:: complex < double >> pw_wfc_g;
7575
7676 if (out_wfc_pw || out_wfc_r)
7777 {
78- pw_wfc_g = new ModuleBase::ComplexMatrix[GlobalC::kv.nks ];
79- for (int ik = 0 ;ik < GlobalC::kv.nks ;++ik)
80- pw_wfc_g[ik].create (GlobalV::NBANDS, GlobalC::kv.ngk [ik], true );
78+ pw_wfc_g.resize (1 , GlobalV::NBANDS, GlobalC::kv.ngk [0 ]);
8179 }
8280
8381
@@ -115,8 +113,8 @@ void IState_Envelope::begin(Local_Orbital_wfc& lowf, Gint_Gamma& gg, int& out_wf
115113 GlobalC::CHR.write_rho (GlobalC::CHR.rho_save [is], is, 0 , ss.str (), 3 , for_plot);
116114
117115 if (out_wfc_pw || out_wfc_r) // only for gamma_only now
118- this ->set_pw_wfc (GlobalC::pw, 0 , ib, GlobalV::NSPIN, GlobalC::kv. ngk [ 0 ],
119- GlobalC::CHR.rho_save , pw_wfc_g[ 0 ] );
116+ this ->set_pw_wfc (GlobalC::pw, 0 , ib, GlobalV::NSPIN,
117+ GlobalC::CHR.rho_save , pw_wfc_g);
120118 }
121119 }
122120 }
@@ -132,8 +130,9 @@ void IState_Envelope::begin(Local_Orbital_wfc& lowf, Gint_Gamma& gg, int& out_wf
132130 WF_io::write_wfc2 (ssw.str (), pw_wfc_g, GlobalC::pw.gcar );
133131 }
134132 if (out_wfc_r)
133+ {
135134 Write_Wfc_Realspace::write_wfc_realspace_1 (pw_wfc_g, " wfc_realspace" , false );
136- delete[] pw_wfc_g;
135+ }
137136 }
138137
139138 delete[] bands_picked;
@@ -193,13 +192,11 @@ void IState_Envelope::begin(Local_Orbital_wfc& lowf, Gint_k& gk, int& out_wf, in
193192 }
194193
195194 // for pw-wfc in G space
196- ModuleBase::ComplexMatrix* pw_wfc_g;
195+ psi::Psi<std:: complex < double >> pw_wfc_g (GlobalC::kv. ngk . data ()) ;
197196
198197 if (out_wf || out_wf_r)
199198 {
200- pw_wfc_g = new ModuleBase::ComplexMatrix[GlobalC::kv.nks ];
201- for (int ik = 0 ;ik < GlobalC::kv.nks ;++ik)
202- pw_wfc_g[ik].create (GlobalV::NBANDS, GlobalC::kv.ngk [ik], true );
199+ pw_wfc_g.resize (GlobalC::kv.nks , GlobalV::NBANDS, GlobalC::wf.npwx );
203200 }
204201
205202 for (int ib = 0 ; ib < GlobalV::NBANDS; ib++)
@@ -233,8 +230,11 @@ void IState_Envelope::begin(Local_Orbital_wfc& lowf, Gint_k& gk, int& out_wf, in
233230 GlobalC::CHR.write_rho (GlobalC::CHR.rho [ispin], ispin, 0 , ss.str (), 3 , for_plot);
234231
235232 if (out_wf || out_wf_r) // only for gamma_only now
236- this ->set_pw_wfc (GlobalC::pw, ik, ib, GlobalV::NSPIN, GlobalC::kv.ngk [ik],
237- GlobalC::CHR.rho , pw_wfc_g[ik]);
233+ {
234+ pw_wfc_g.fix_k (ik);
235+ this ->set_pw_wfc (GlobalC::pw, ik, ib, GlobalV::NSPIN,
236+ GlobalC::CHR.rho , pw_wfc_g);
237+ }
238238 }
239239 }
240240 }
@@ -250,8 +250,9 @@ void IState_Envelope::begin(Local_Orbital_wfc& lowf, Gint_k& gk, int& out_wf, in
250250 WF_io::write_wfc2 (ssw.str (), pw_wfc_g, GlobalC::pw.gcar );
251251 }
252252 if (out_wf_r)
253+ {
253254 Write_Wfc_Realspace::write_wfc_realspace_1 (pw_wfc_g, " wfc_realspace" , false );
254- delete[] pw_wfc_g;
255+ }
255256 }
256257
257258 delete[] bands_picked;
@@ -260,9 +261,9 @@ void IState_Envelope::begin(Local_Orbital_wfc& lowf, Gint_k& gk, int& out_wf, in
260261
261262// for each band
262263void IState_Envelope::set_pw_wfc (PW_Basis& pwb,
263- const int & ik, const int & ib, const int & nspin, const int & ngk,
264+ const int & ik, const int & ib, const int & nspin,
264265 const double * const * const rho,
265- ModuleBase::ComplexMatrix& wfc_g)
266+ psi::Psi<std:: complex < double >> & wfc_g)
266267{
267268 if (ib == 0 )// once is enough
268269 ModuleBase::TITLE (" IState_Envelope" , " set_pw_wfc" );
@@ -279,6 +280,6 @@ void IState_Envelope::set_pw_wfc(PW_Basis& pwb,
279280
280281 // set pw_wfc_g
281282 // ig2fftw: the index map from i_ngk(local) to i_ngmw(local)
282- for (int ig = 0 ;ig < ngk ;++ig)
283+ for (int ig = 0 ;ig < wfc_g. get_nbasis () ;++ig)
283284 wfc_g (ib, ig) = Porter[pwb.ig2fftw [GlobalC::wf.igk (ik, ig)]];
284285}
0 commit comments