1212#include " module_base/parallel_common.h"
1313#endif
1414
15+ /*
1516template <typename T>
16- void ModuleIO::read_abacus_lowf (const std::string& flowf ,
17- int & ik,
18- ModuleBase::Vector3<double >& kvec_c,
19- int & nbands,
20- int & nbasis,
21- std::vector<std::complex <T>>& lowf,
22- std::vector<double >& ekb,
23- std::vector<double >& occ,
24- double & wk) // <[out] wavefunction coefficients
17+ void ModuleIO::read_wfc_lcao (const std::string& file ,
18+ int& ik,
19+ ModuleBase::Vector3<double>& kvec_c,
20+ int& nbands,
21+ int& nbasis,
22+ std::vector<std::complex<T>>& lowf,
23+ std::vector<double>& ekb,
24+ std::vector<double>& occ,
25+ double& wk) //<[out] wavefunction coefficients
2526{
2627 // assert the T must be double or float
27- std::ifstream ifs (flowf .c_str ());
28+ std::ifstream ifs(file .c_str());
2829 if (!ifs)
2930 {
30- ModuleBase::WARNING_QUIT (" read_abacus_lowf " , " open file failed: " + flowf );
31+ ModuleBase::WARNING_QUIT("ModuleIO::read_wfc_lcao ", "open file failed: " + file );
3132 }
3233 // will use line-by-line parse
3334 std::string line;
@@ -72,9 +73,7 @@ void ModuleIO::read_abacus_lowf(const std::string& flowf,
7273 else if (FmtCore::endswith(line, "(band)"))
7374 {
7475 std::vector<std::string> result = FmtCore::split(line);
75- #ifdef __DEBUG
7676 assert((ilocal == 0) || (ilocal == nbasis));
77- #endif
7877 iband = std::stoi(result[0]) - 1;
7978 ilocal = 0; // reset ilocal
8079 }
@@ -87,9 +86,7 @@ void ModuleIO::read_abacus_lowf(const std::string& flowf,
8786 {
8887 std::vector<std::string> result = FmtCore::split(line);
8988 occ[iband] = std::stod(result[0]);
90- #ifdef __DEBUG
9189 assert(ilocal == 0);
92- #endif
9390 }
9491 else // read wavefunction coefficients
9592 {
@@ -102,14 +99,13 @@ void ModuleIO::read_abacus_lowf(const std::string& flowf,
10299 }
103100 }
104101 }
105- #ifdef __DEBUG
106102 assert(lowf.size() == nbands * nbasis);
107103 assert(iband == nbands - 1);
108104 assert(ilocal == nbasis);
109- #endif
110105}
106+
111107// instantiate the template function
112- template void ModuleIO::read_abacus_lowf (const std::string& flowf ,
108+ template void ModuleIO::read_wfc_lcao (const std::string& file ,
113109 int& ik,
114110 ModuleBase::Vector3<double>& kvec_c,
115111 int& nbands,
@@ -118,7 +114,8 @@ template void ModuleIO::read_abacus_lowf(const std::string& flowf,
118114 std::vector<double>& ekb,
119115 std::vector<double>& occ,
120116 double& wk);
121- template void ModuleIO::read_abacus_lowf (const std::string& flowf,
117+
118+ template void ModuleIO::read_wfc_lcao(const std::string& file,
122119 int& ik,
123120 ModuleBase::Vector3<double>& kvec_c,
124121 int& nbands,
@@ -129,7 +126,7 @@ template void ModuleIO::read_abacus_lowf(const std::string& flowf,
129126 double& wk);
130127
131128template <typename T>
132- void ModuleIO::read_abacus_lowf (const std::string& flowf ,
129+ void ModuleIO::read_wfc_lcao (const std::string& file ,
133130 int& ik,
134131 ModuleBase::Vector3<double>& kvec_c,
135132 int& nbands,
@@ -139,10 +136,10 @@ void ModuleIO::read_abacus_lowf(const std::string& flowf,
139136 std::vector<double>& occ,
140137 double& wk)
141138{
142- std::ifstream ifs (flowf .c_str ());
139+ std::ifstream ifs(file .c_str());
143140 if (!ifs)
144141 {
145- ModuleBase::WARNING_QUIT (" read_abacus_lowf " , " open file failed: " + flowf );
142+ ModuleBase::WARNING_QUIT("ModuleIO::read_wfc_lcao ", "open file failed: " + file );
146143 }
147144 // will use line-by-line parse
148145 std::string line;
@@ -182,9 +179,7 @@ void ModuleIO::read_abacus_lowf(const std::string& flowf,
182179 else if (FmtCore::endswith(line, "(band)"))
183180 {
184181 std::vector<std::string> result = FmtCore::split(line);
185- #ifdef __DEBUG
186182 assert((ilocal == 0) || (ilocal == nbasis));
187- #endif
188183 iband = std::stoi(result[0]) - 1;
189184 ilocal = 0; // reset ilocal
190185 }
@@ -197,9 +192,7 @@ void ModuleIO::read_abacus_lowf(const std::string& flowf,
197192 {
198193 std::vector<std::string> result = FmtCore::split(line);
199194 occ[iband] = std::stod(result[0]);
200- #ifdef __DEBUG
201195 assert(ilocal == 0);
202- #endif
203196 }
204197 else // read wavefunction coefficients
205198 {
@@ -211,14 +204,13 @@ void ModuleIO::read_abacus_lowf(const std::string& flowf,
211204 }
212205 }
213206 }
214- #ifdef __DEBUG
215207 assert(lowf.size() == nbands * nbasis);
216208 assert(iband == nbands - 1);
217209 assert(ilocal == nbasis);
218- #endif
219210}
211+
220212// instantiate the template function
221- template void ModuleIO::read_abacus_lowf (const std::string& flowf ,
213+ template void ModuleIO::read_wfc_lcao (const std::string& file ,
222214 int& ik,
223215 ModuleBase::Vector3<double>& kvec_c,
224216 int& nbands,
@@ -227,7 +219,8 @@ template void ModuleIO::read_abacus_lowf(const std::string& flowf,
227219 std::vector<double>& ekb,
228220 std::vector<double>& occ,
229221 double& wk);
230- template void ModuleIO::read_abacus_lowf (const std::string& flowf,
222+
223+ template void ModuleIO::read_wfc_lcao(const std::string& file,
231224 int& ik,
232225 ModuleBase::Vector3<double>& kvec_c,
233226 int& nbands,
@@ -259,7 +252,7 @@ void ModuleIO::restart_from_file(const std::string& out_dir, // hard-code the fi
259252 const bool gamma_only = std::is_same<T, double>::value || std::is_same<T, float>::value;
260253 const bool multi_k = std::is_same<T, std::complex<double>>::value || std::is_same<T, std::complex<float>>::value;
261254 assert(gamma_only || multi_k);
262- const std::string flowf_prefix = gamma_only ? " WFC_GAMMA" : " WFC_NAO_K" ;
255+ const std::string file_prefix = gamma_only ? "WFC_GAMMA" : "WFC_NAO_K";
263256 // MPI-related variables init
264257 int iproc=0;
265258
@@ -271,11 +264,11 @@ void ModuleIO::restart_from_file(const std::string& out_dir, // hard-code the fi
271264 for (int ik = 0; ik < nks; ik++)
272265 {
273266 // check existence of file
274- const std::string flowf = out_dir + " /" + flowf_prefix + std::to_string (ik + 1 ) + " .txt" ;
275- std::ifstream ifs (flowf );
267+ const std::string file = out_dir + "/" + file_prefix + std::to_string(ik + 1) + ".txt";
268+ std::ifstream ifs(file );
276269 if (!ifs)
277270 {
278- ModuleBase::WARNING_QUIT (" restart_from_file" , " open file failed: " + flowf );
271+ ModuleBase::WARNING_QUIT("Module_IO:: restart_from_file", "open file failed: " + file );
279272 }
280273
281274 std::vector<T> lowf_glb;
@@ -288,7 +281,7 @@ void ModuleIO::restart_from_file(const std::string& out_dir, // hard-code the fi
288281 if (iproc == 0) // only one rank is needed to read the global lowf, ekb, ...
289282 {
290283 int ik_ = 0;
291- read_abacus_lowf (flowf , ik_, kvec, nbands, nbasis, lowf_glb, ekb_, occ_, wk_);
284+ read_wfc_lcao(file , ik_, kvec, nbands, nbasis, lowf_glb, ekb_, occ_, wk_);
292285
293286 assert(ik_ == ik + 1); // check the consistency of ik
294287 assert(nbands == nbands_ || nbands_ == -1); // check the consistency of nbands
@@ -415,30 +408,35 @@ void ModuleIO::restart_from_file(const std::string& out_dir, // hard-code the fi
415408 const bool gamma_only = std::is_same<T, double>::value || std::is_same<T, float>::value;
416409 const bool multi_k = std::is_same<T, std::complex<double>>::value || std::is_same<T, std::complex<float>>::value;
417410 assert(gamma_only || multi_k);
418- const std::string flowf_prefix = gamma_only ? " WFC_GAMMA" : " WFC_NAO_K" ;
411+ const std::string file_prefix = gamma_only ? "WFC_GAMMA" : "WFC_NAO_K";
419412 int nbands_ = -1, nbasis_ = -1;
420413 for (int ik = 0; ik < nks; ik++)
421414 {
422415 // check existence of file
423- const std::string flowf = out_dir + " /" + flowf_prefix + std::to_string (ik + 1 ) + " .txt" ;
424- const std::ifstream ifs (flowf );
416+ const std::string file = out_dir + "/" + file_prefix + std::to_string(ik + 1) + ".txt";
417+ const std::ifstream ifs(file );
425418 if (!ifs)
426419 {
427- ModuleBase::WARNING_QUIT (" restart_from_file" , " open file failed: " + flowf );
420+ ModuleBase::WARNING_QUIT("restart_from_file", "open file failed: " + file );
428421 }
429422
430423 std::vector<T> lowf_;
431424 std::vector<double> ekb_;
432425 std::vector<double> occ_;
433426 ModuleBase::Vector3<double> kvec_;
434- double wk_;
435- int ik_;
436- read_abacus_lowf (flowf, ik_, kvec_, nbands, nbasis, lowf_, ekb_, occ_, wk_);
427+ double wk_=0.0;
428+ int ik_=0;
429+
430+ read_wfc_lcao(file, ik_, kvec_, nbands, nbasis, lowf_, ekb_, occ_, wk_);
431+
437432 assert(nbands == nbands_ || nbands_ == -1); // check the consistency of nbands
438433 assert(nbasis == nbasis_ || nbasis_ == -1); // check the consistency of nbasis
434+
439435 nbands_ = (nbands_ == -1) ? nbands : nbands_;
440436 nbasis_ = (nbasis_ == -1) ? nbasis : nbasis_;
437+
441438 assert(ik_ == ik + 1); // check the consistency of ik
439+
442440 // append to the global lowf_loc
443441 lowf.insert(lowf.end(), lowf_.begin(), lowf_.end());
444442 ekb.insert(ekb.end(), ekb_.begin(), ekb_.end());
@@ -491,3 +489,4 @@ template void ModuleIO::restart_from_file(const std::string& out_dir,
491489 std::vector<double>& occ,
492490 std::vector<ModuleBase::Vector3<double>>& kvec_c,
493491 std::vector<double>& wk);
492+ */
0 commit comments