@@ -23,7 +23,8 @@ namespace ModuleIO
2323// write ||wfc_r|| for all k-points and all bands
2424// Input: wfc_g(ik, ib, ig)
2525// loop order is for(z){for(y){for(x)}}
26- void write_psi_r_1 (const psi::Psi<std::complex <double >>& wfc_g,
26+ void write_psi_r_1 (const UnitCell& ucell,
27+ const psi::Psi<std::complex <double >>& wfc_g,
2728 const ModulePW::PW_Basis_K* wfcpw,
2829 const std::string& folder_name,
2930 const bool & square,
@@ -66,18 +67,16 @@ void write_psi_r_1(const psi::Psi<std::complex<double>>& wfc_g,
6667 wfc_imag[ir] = wfc_r[ir].imag ();
6768 }
6869 }
69- const std::string file_name = outdir + " wfc_realspace_" + ModuleBase::GlobalFunc::TO_STRING (ik_out) + " _"
70- + ModuleBase::GlobalFunc::TO_STRING (ib);
70+ std::string file_name_base = outdir + " wfc_realspace_" +
71+ ModuleBase::GlobalFunc::TO_STRING (ik_out) + " _" +
72+ ModuleBase::GlobalFunc::TO_STRING (ib);
73+ const std::string file_name = square ? file_name_base : file_name_base + " _imag" ;
7174#ifdef __MPI
7275 // Use write_chg_r_1 to output the real and imaginary parts of the wave function to file
7376 mpi_requests.push_back ({});
74- write_chg_r_1 (wfcpw, wfc_real, file_name, mpi_requests.back ());
75- if (!square)
76- {
77- write_chg_r_1 (wfcpw, wfc_imag, file_name + " _imag" , mpi_requests.back ());
78- }
77+ write_chg_r_1 (ucell,wfcpw, wfc_real, file_name, mpi_requests.back ());
7978#else
80- write_chg_r_1 (wfcpw, wfc_real, file_name);
79+ write_chg_r_1 (ucell, wfcpw, wfc_real, file_name);
8180 // if (!square)
8281 // write_chg_r_1(wfc_imag, file_name + "_imag", mpi_requests.back());
8382#endif
@@ -115,14 +114,14 @@ std::vector<std::complex<double>> cal_wfc_r(const ModulePW::PW_Basis_K* wfcpw,
115114}
116115
117116// Input: chg_r[ir]
118- # ifdef __MPI
119- void write_chg_r_1 ( const ModulePW::PW_Basis_K* wfcpw,
117+ void write_chg_r_1 ( const UnitCell& ucell,
118+ const ModulePW::PW_Basis_K* wfcpw,
120119 const std::vector<double >& chg_r,
121- const std::string& file_name,
122- MPI_Request& mpi_request)
123- # else
124- void write_chg_r_1 ( const ModulePW::PW_Basis_K* wfcpw, const std::vector< double >& chg_r, const std::string& file_name)
125- # endif
120+ const std::string& file_name
121+ # ifdef __MPI
122+ ,MPI_Request& mpi_request
123+ # endif
124+ )
126125{
127126 ModuleBase::timer::tick (" ModuleIO" , " write_chg_r_1" );
128127 std::ofstream ofs;
@@ -135,32 +134,32 @@ void write_chg_r_1(const ModulePW::PW_Basis_K* wfcpw, const std::vector<double>&
135134 ofs.open (file_name);
136135
137136 ofs << " calculated by ABACUS" << std::endl;
138- ofs << GlobalC:: ucell.lat0_angstrom << std::endl;
139- ofs << GlobalC:: ucell.latvec .e11 << " " << GlobalC:: ucell.latvec .e12 << " " << GlobalC:: ucell.latvec .e13
137+ ofs << ucell.lat0_angstrom << std::endl;
138+ ofs << ucell.latvec .e11 << " " << ucell.latvec .e12 << " " << ucell.latvec .e13
140139 << std::endl
141- << GlobalC:: ucell.latvec .e21 << " " << GlobalC:: ucell.latvec .e22 << " " << GlobalC:: ucell.latvec .e23
140+ << ucell.latvec .e21 << " " << ucell.latvec .e22 << " " << ucell.latvec .e23
142141 << std::endl
143- << GlobalC:: ucell.latvec .e31 << " " << GlobalC:: ucell.latvec .e32 << " " << GlobalC:: ucell.latvec .e33
142+ << ucell.latvec .e31 << " " << ucell.latvec .e32 << " " << ucell.latvec .e33
144143 << std::endl;
145144
146- for (int it = 0 ; it < GlobalC:: ucell.ntype ; ++it)
145+ for (int it = 0 ; it < ucell.ntype ; ++it)
147146 {
148- ofs << GlobalC:: ucell.atoms [it].label << " \t " ;
147+ ofs << ucell.atoms [it].label << " \t " ;
149148 }
150149 ofs << std::endl;
151- for (int it = 0 ; it < GlobalC:: ucell.ntype ; ++it)
150+ for (int it = 0 ; it < ucell.ntype ; ++it)
152151 {
153- ofs << GlobalC:: ucell.atoms [it].na << " \t " ;
152+ ofs << ucell.atoms [it].na << " \t " ;
154153 }
155154 ofs << std::endl;
156155
157156 ofs << " Direct" << std::endl;
158- for (int it = 0 ; it < GlobalC:: ucell.ntype ; ++it)
157+ for (int it = 0 ; it < ucell.ntype ; ++it)
159158 {
160- for (int ia = 0 ; ia < GlobalC:: ucell.atoms [it].na ; ++ia)
159+ for (int ia = 0 ; ia < ucell.atoms [it].na ; ++ia)
161160 {
162- ofs << GlobalC:: ucell.atoms [it].taud [ia].x << " " << GlobalC:: ucell.atoms [it].taud [ia].y << " "
163- << GlobalC:: ucell.atoms [it].taud [ia].z << std::endl;
161+ ofs << ucell.atoms [it].taud [ia].x << " " << ucell.atoms [it].taud [ia].y << " "
162+ << ucell.atoms [it].taud [ia].z << std::endl;
164163 }
165164 }
166165 ofs << std::endl;
0 commit comments