Skip to content

Commit 4f48af9

Browse files
committed
Fix: using psi rather than evc in out_wfc_r and out_wfc_pw
1 parent 07dc729 commit 4f48af9

File tree

8 files changed

+51
-45
lines changed

8 files changed

+51
-45
lines changed

source/module_esolver/esolver_ks_pw.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ namespace ModuleESolver
392392
//WF_io::write_wfc( ssw.str(), GlobalC::wf.evc );
393393
// mohan update 2011-02-21
394394
//qianrui update 2020-10-17
395-
WF_io::write_wfc2(ssw.str(), GlobalC::wf.evc, GlobalC::pw.gcar);
395+
WF_io::write_wfc2(ssw.str(), GlobalC::wf.psi[0], GlobalC::pw.gcar);
396396
//ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running,"write wave functions into file WAVEFUNC.dat");
397397
}
398398

source/src_io/istate_envelope.cpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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
262263
void 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
}

source/src_io/istate_envelope.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "src_lcao/gint_gamma.h"
55
#include "src_lcao/gint_k.h"
66
#include "src_pw/pw_basis.h"
7+
#include "module_psi/psi.h"
78

89
class IState_Envelope
910
{
@@ -21,9 +22,9 @@ class IState_Envelope
2122

2223
void set_pw_wfc(PW_Basis& pwb,
2324
const int& ik, const int& ib,
24-
const int& nspin, const int& ngk,
25+
const int& nspin,
2526
const double* const* const rho,
26-
ModuleBase::ComplexMatrix& wfc_g);
27+
psi::Psi<std::complex<double>> &wfc_g);
2728

2829
};
2930
#endif

source/src_io/wf_io.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
1919
}*/
2020

21-
void WF_io::write_wfc(const std::string &fn, const ModuleBase::ComplexMatrix *psi)
21+
void WF_io::write_wfc(const std::string &fn, const psi::Psi<std::complex<double>> &psi)
2222
{
2323
if (GlobalV::test_wf) ModuleBase::TITLE("WF_io","write_wfc");
2424

@@ -41,8 +41,8 @@ void WF_io::write_wfc(const std::string &fn, const ModuleBase::ComplexMatrix *ps
4141
for (int ig=0; ig<GlobalC::kv.ngk[ik]; ig++)
4242
{
4343
if (ig%4==0) ofs << "\n";
44-
ofs << std::setw(15) << psi[ik](i, ig).real()
45-
<< std::setw(15) << psi[ik](i, ig).imag();
44+
ofs << std::setw(15) << psi(ik, i, ig).real()
45+
<< std::setw(15) << psi(ik, i, ig).imag();
4646
}
4747
ofs << "\n";
4848
}
@@ -53,7 +53,7 @@ void WF_io::write_wfc(const std::string &fn, const ModuleBase::ComplexMatrix *ps
5353
return;
5454
}
5555

56-
void WF_io::write_wfc2(const std::string &fn, const ModuleBase::ComplexMatrix *psi, const ModuleBase::Vector3<double> *gkk)
56+
void WF_io::write_wfc2(const std::string &fn, const psi::Psi<std::complex<double>> &psi, const ModuleBase::Vector3<double> *gkk)
5757
{
5858
if (GlobalV::test_wf) ModuleBase::TITLE("WF_io","write_wfc2");
5959

@@ -96,8 +96,9 @@ void WF_io::write_wfc2(const std::string &fn, const ModuleBase::ComplexMatrix *p
9696
if( GlobalV::MY_POOL == ip )
9797
{
9898
#endif
99-
for(int ik=0; ik<GlobalC::kv.nks; ik++)
99+
for(int ik=0; ik<psi.get_nk(); ik++)
100100
{
101+
psi.fix_k(ik);
101102
int ikngtot=0; //ikngtot: the total number of plane waves of ikpoint
102103
int ikstot=0;//ikstot : the index within all k-points
103104
#ifdef __MPI
@@ -123,8 +124,8 @@ void WF_io::write_wfc2(const std::string &fn, const ModuleBase::ComplexMatrix *p
123124
if(id==0)
124125
{
125126
ofs2<<std::setprecision(6);
126-
ofs2<<std::setw(10)<<"Kpoint"<<std::setw(10)<<"nKpoint"<<std::setw(10)<<"GlobalC::kv.x"<<std::setw(10)
127-
<<"GlobalC::kv.y"<<std::setw(10)<<"GlobalC::kv.z"<<std::setw(10)<<"weight"<<std::setw(10)
127+
ofs2<<std::setw(10)<<"Kpoint"<<std::setw(10)<<"nKpoint"<<std::setw(10)<<"kv.x"<<std::setw(10)
128+
<<"kv.y"<<std::setw(10)<<"kv.z"<<std::setw(10)<<"weight"<<std::setw(10)
128129
<<"ngtot"<<std::setw(10)<<"nband"<<std::setw(10)<<"ecut"<<std::setw(10)<<"lat0"<<std::setw(10)<<"2pi/lat0"<<std::endl;
129130
ofs2<<std::setw(10)<<ikstot+1<<std::setw(10)<<GlobalC::kv.nkstot<<std::setw(10)<<GlobalC::kv.kvec_c[ik].x<<std::setw(10)
130131
<<GlobalC::kv.kvec_c[ik].y<<std::setw(10)<<GlobalC::kv.kvec_c[ik].z<<std::setw(10)<<GlobalC::kv.wk[ik]<<std::setw(10)
@@ -194,11 +195,11 @@ void WF_io::write_wfc2(const std::string &fn, const ModuleBase::ComplexMatrix *p
194195
if(id==0) ofs2 << "\n< Band "<<ib+1 <<" >" <<std::endl;
195196
ofs2 << scientific;
196197

197-
for (int ig=0; ig<GlobalC::kv.ngk[ik]; ig++)
198+
for (int ig=0; ig<psi.get_current_nbas(); ig++)
198199
{
199200
if (ig%4==0&&(ig!=0||id!=0)) ofs2 << "\n";
200-
ofs2 << std::setw(15) << psi[ik](ib, ig).real()
201-
<< std::setw(15) << psi[ik](ib, ig).imag();
201+
ofs2 << std::setw(15) << psi(ib, ig).real()
202+
<< std::setw(15) << psi(ib, ig).imag();
202203
} // end ig
203204
if(id==GlobalV::NPROC_IN_POOL-1) ofs2 << "\n< Band "<<ib+1 <<" >" <<std::endl;
204205
ofs2.close();
@@ -207,9 +208,9 @@ void WF_io::write_wfc2(const std::string &fn, const ModuleBase::ComplexMatrix *p
207208
{
208209
Rwstream wfs2(wfilename[ikstot],"a");
209210
if(id==0) wfs2<<ikngtot*16;
210-
for (int ig=0; ig<GlobalC::kv.ngk[ik]; ig++)
211+
for (int ig=0; ig<psi.get_current_nbas(); ig++)
211212
{
212-
wfs2 << psi[ik](ib, ig).real() << psi[ik](ib, ig).imag();
213+
wfs2 << psi(ib, ig).real() << psi(ib, ig).imag();
213214
}
214215
if(id==GlobalV::NPROC_IN_POOL-1) wfs2<<ikngtot*16;
215216
wfs2.close();

source/src_io/wf_io.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
#include "../module_base/vector3.h"
77
#include "../module_base/complexmatrix.h"
88
#include "rwstream.h"
9+
#include "module_psi/psi.h"
910

1011
namespace WF_io
1112
{
12-
void write_wfc(const std::string &fn, const ModuleBase::ComplexMatrix *psi);
13+
void write_wfc(const std::string &fn, const psi::Psi<std::complex<double>> &psi);
1314

1415
// mohan add 2011-02-21
15-
void write_wfc2(const std::string &fn, const ModuleBase::ComplexMatrix *psi,const ModuleBase::Vector3<double> *gkk);
16-
void read_wfc(const std::string &fn, const ModuleBase::ComplexMatrix *psi);
16+
void write_wfc2(const std::string &fn, const psi::Psi<std::complex<double>> &psi,const ModuleBase::Vector3<double> *gkk);
17+
void read_wfc(const std::string &fn, const psi::Psi<std::complex<double>> &psi);
1718
}
1819

1920
#endif

source/src_io/write_wfc_realspace.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
namespace Write_Wfc_Realspace
1515
{
1616
// write ||wfc_r|| for all k-points and all bands
17-
// Input: wfc_g[ik](ib,ig)
17+
// Input: wfc_g(ik, ib, ig)
1818
// loop order is for(z){for(y){for(x)}}
19-
void write_wfc_realspace_1(const ModuleBase::ComplexMatrix*const wfc_g, const std::string &folder_name, const bool& square)
19+
void write_wfc_realspace_1(const psi::Psi<std::complex<double>> &wfc_g, const std::string &folder_name, const bool& square)
2020
{
2121
ModuleBase::TITLE("Write_Wfc_Realspace", "write_wfc_realspace_1");
2222
ModuleBase::timer::tick("Write_Wfc_Realspace", "write_wfc_realspace_1");
@@ -29,14 +29,15 @@ namespace Write_Wfc_Realspace
2929
#ifdef __MPI
3030
std::vector<MPI_Request> mpi_requests;
3131
#endif
32-
for(int ik=0; ik<GlobalC::kv.nks; ++ik)
32+
for(int ik=0; ik<wfc_g.get_nk(); ++ik)
3333
{
34+
wfc_g.fix_k(ik);
3435
const int ik_out = (GlobalV::NSPIN!=2)
3536
? ik + GlobalC::Pkpoints.startk_pool[GlobalV::MY_POOL]
3637
: ik - GlobalC::kv.nks/2*GlobalC::kv.isk[ik] + GlobalC::kv.nkstot/2*GlobalC::kv.isk[ik] + GlobalC::Pkpoints.startk_pool[GlobalV::MY_POOL];
37-
for(int ib=0; ib<wfc_g[ik].nr; ++ib)
38+
for(int ib=0; ib<wfc_g.get_nbands(); ++ib)
3839
{
39-
const std::vector<std::complex<double>> wfc_r = cal_wfc_r(wfc_g[ik], ik, ib);
40+
const std::vector<std::complex<double>> wfc_r = cal_wfc_r(wfc_g, ik, ib);
4041

4142
std::vector<double> wfc_r2(wfc_r.size());
4243
std::vector<double> wfc_i2;
@@ -86,12 +87,12 @@ namespace Write_Wfc_Realspace
8687

8788
// Input: wfc_g(ib,ig)
8889
// Output: wfc_r[ir]
89-
std::vector<std::complex<double>> cal_wfc_r(const ModuleBase::ComplexMatrix &wfc_g, const int ik, const int ib)
90+
std::vector<std::complex<double>> cal_wfc_r(const psi::Psi<std::complex<double>> &wfc_g, const int ik, const int ib)
9091
{
9192
ModuleBase::timer::tick("Write_Wfc_Realspace", "cal_wfc_r");
9293
ModuleBase::GlobalFunc::ZEROS(GlobalC::UFFT.porter, GlobalC::pw.nrxx);
9394
std::vector<std::complex<double>> wfc_r(GlobalC::pw.nrxx);
94-
for(int ig=0; ig<GlobalC::kv.ngk[ik]; ++ig)
95+
for(int ig=0; ig<wfc_g.get_current_nbas(); ++ig)
9596
GlobalC::UFFT.porter[ GlobalC::pw.ig2fftw[GlobalC::wf.igk(ik,ig)] ] = wfc_g(ib,ig);
9697
GlobalC::pw.FFT_wfc.FFT3D(GlobalC::UFFT.porter,1);
9798
for(int ir=0; ir<GlobalC::pw.nrxx; ++ir)

source/src_io/write_wfc_realspace.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <vector>
1212
#include <complex>
1313
#include <string>
14+
#include "module_psi/psi.h"
1415

1516
#ifdef __MPI
1617
#include "mpi.h"
@@ -21,11 +22,11 @@ namespace Write_Wfc_Realspace
2122
// write ||wfc_r|| for all k-points and all bands
2223
// Input: wfc_g[ik](ib,ig)
2324
// loop order is for(z){for(y){for(x)}}
24-
void write_wfc_realspace_1(const ModuleBase::ComplexMatrix*const wfc_g, const std::string &folder_name, const bool& square);
25+
void write_wfc_realspace_1(const psi::Psi<std::complex<double>> &wfc_g, const std::string &folder_name, const bool& square);
2526

2627
// Input: wfc_g(ib,ig)
2728
// Output: wfc_r[ir]
28-
std::vector<std::complex<double>> cal_wfc_r(const ModuleBase::ComplexMatrix &wfc_g, const int ik, const int ib);
29+
std::vector<std::complex<double>> cal_wfc_r(const psi::Psi<std::complex<double>> &wfc_g, const int ik, const int ib);
2930

3031
// Input: chg_r[ir]
3132
#ifdef __MPI

source/src_ions/ions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ void Ions::opt_ions_pw(ModuleESolver::ESolver *p_esolver)
187187

188188
if(GlobalC::wf.out_wfc_r == 1) // Peize Lin add 2021.11.21
189189
{
190-
Write_Wfc_Realspace::write_wfc_realspace_1(GlobalC::wf.evc, "wfc_realspace", true);
190+
Write_Wfc_Realspace::write_wfc_realspace_1(GlobalC::wf.psi[0], "wfc_realspace", true);
191191
}
192192

193193
ModuleBase::timer::tick("Ions","opt_ions_pw");

0 commit comments

Comments
 (0)