Skip to content

Commit 03f570e

Browse files
committed
I found read_wfc_lcao code and the corresponding tests are useless
1 parent a5da637 commit 03f570e

File tree

5 files changed

+75
-102
lines changed

5 files changed

+75
-102
lines changed

source/module_io/read_wfc_lcao.cpp

Lines changed: 41 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,23 @@
1212
#include "module_base/parallel_common.h"
1313
#endif
1414

15+
/*
1516
template <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
131128
template <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+
*/

source/module_io/read_wfc_lcao.h

Lines changed: 13 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,31 @@
11
#ifndef READ_WFC_LCAO_H
22
#define READ_WFC_LCAO_H
33

4-
// serial
54
#include "module_base/vector3.h"
6-
75
#include <complex>
86
#include <string>
97
#include <vector>
108

119
#ifdef __MPI
12-
// parallelization
1310
#include "module_base/scalapack_connector.h"
1411
#include "module_base/parallel_2d.h"
1512
#endif
1613

1714
/**
1815
* @brief This class has two functions: restart psi from the previous calculation, and write psi to the disk.
19-
*
2016
*/
17+
2118
namespace ModuleIO
2219
{
2320
// only when you know why you need the T, you can write function with template parameter,
2421
// otherwise, you should overload the function for different types
25-
// For example in this case, ONLY lowf support to be std::complex<double> and std::complex<float>,
22+
// For example in this case, ONLY wfc support to be std::complex<double> and std::complex<float>,
2623
// not ekb, occ, wk and kvec_c.
2724
/**
2825
* @brief Read the wavefunction coefficients from the file (for complex wavefunction coefficients)
2926
*
3027
* @tparam T
31-
* @param flowf [in] file name like "LOWF_K_*.txt", dumped from ABACUS INPUT out_wfc_lcao 1
28+
* @param file [in] file name
3229
* @param ik [out] the index of k points
3330
* @param kvec_c [out] the k vector in Cartesian coordinates
3431
* @param nbands [out] the number of bands
@@ -38,33 +35,21 @@ namespace ModuleIO
3835
* @param occ [out] occupations
3936
* @param wk [out] weight of k points
4037
*/
38+
/*
4139
template <typename T>
42-
void read_abacus_lowf(const std::string& flowf, int& ik, ModuleBase::Vector3<double>& kvec_c, int& nbands, int& nbasis,
40+
void read_wfc_lcao(const std::string& file, int& ik, ModuleBase::Vector3<double>& kvec_c, int& nbands, int& nbasis,
4341
std::vector<std::complex<T>>& lowf, std::vector<double>& ekb, std::vector<double>& occ,
4442
double& wk);
45-
/**
46-
* @brief Read the wavefunction coefficients from the file (for real wavefunction coefficients)
47-
*
48-
* @tparam T
49-
* @param flowf [in] file name like "LOWF_K_*.txt", dumped from ABACUS INPUT out_wfc_lcao 1
50-
* @param ik [out] the index of k points
51-
* @param kvec_c [out] the k vector in Cartesian coordinates
52-
* @param nbands [out] the number of bands
53-
* @param nbasis [out] the number of orbitals
54-
* @param lowf [out] wavefunction coefficients
55-
* @param ekb [out] eigenvalues
56-
* @param occ [out] occupations
57-
* @param wk [out] weight of k points
58-
*/
43+
5944
template <typename T>
60-
void read_abacus_lowf(const std::string& flowf, int& ik, ModuleBase::Vector3<double>& kvec_c, int& nbands, int& nbasis,
45+
void read_wfc_lcao(const std::string& file, int& ik, ModuleBase::Vector3<double>& kvec_c, int& nbands, int& nbasis,
6146
std::vector<T>& lowf, std::vector<double>& ekb, std::vector<double>& occ, double& wk);
47+
*/
6248
// the two functions above will return nbands, nbasis, lowf, ekb, occ and wk.
6349
// the lowf is actually lowf_glb, which means the global matrix (ScaLAPACK convention), need to distribute
6450
// to the local matrix (2D-block-cyclic parallel distribution) in the following function.
6551

66-
// only-MPI-visible function, because the use of comm_world
67-
#ifdef __MPI
52+
//#ifdef __MPI
6853
/**
6954
* @brief Restart the wavefunction coefficients from the file (MPI 2D-BCD version)
7055
*
@@ -83,32 +68,20 @@ void read_abacus_lowf(const std::string& flowf, int& ik, ModuleBase::Vector3<dou
8368
*
8469
* @warning Cpxgemr2d not implemented yet
8570
*/
71+
/*
8672
template <typename T>
8773
void restart_from_file(const std::string& out_dir, // hard-code the file name to be LOWF_K_*.txt?
8874
const Parallel_2D& p2d, const int& nks, int& nbands, int& nbasis, std::vector<T>& lowf_loc,
8975
std::vector<double>& ekb, std::vector<double>& occ,
9076
std::vector<ModuleBase::Vector3<double>>& kvec_c, std::vector<double>& wk);
9177
#endif
78+
9279
// serial version, can always present
93-
/**
94-
* @brief Restart the wavefunction coefficients from the file (serial version)
95-
*
96-
* @tparam T: datatype of the wavefunction coefficients, can be double, float, std::complex<double> or
97-
* std::complex<float>
98-
* @param out_dir [in] the directory where the wavefunction coefficients are stored
99-
* @param nks [in] the number of k points
100-
* @param nbands [out] the number of bands
101-
* @param nbasis [out] the number of orbitals
102-
* @param lowf_loc [out] the local wavefunction coefficients, can be used to construct psi, see constructor No.8
103-
* @param ekb [out] the eigenvalues
104-
* @param occ [out] the occupations
105-
* @param kvec_c [out] the k vectors in Cartesian coordinates
106-
* @param wk [out] the weight of k points
107-
*/
10880
template <typename T>
10981
void restart_from_file(const std::string& out_dir, // hard-code the file name to be LOWF_K_*.txt?
11082
const int& nks, int& nbands, int& nbasis, std::vector<T>& lowf, std::vector<double>& ekb,
11183
std::vector<double>& occ, std::vector<ModuleBase::Vector3<double>>& kvec_c,
11284
std::vector<double>& wk);
113-
} // namespace ModuleIO
85+
*/
86+
}
11487
#endif

source/module_io/restart.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#ifdef __EXX
88
#include <RI/global/Tensor.h>
99
#endif
10+
1011
class Restart
1112
{
1213
public:
@@ -54,4 +55,4 @@ class Restart
5455
bool read_file2(const std::string& file_name, void* const ptr, const size_t size, const bool error_quit = true) const;
5556
};
5657

57-
#endif
58+
#endif

source/module_io/test/CMakeLists.txt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -201,19 +201,19 @@ AddTest(
201201
../orb_io.cpp
202202
)
203203

204-
if(ENABLE_LCAO)
205-
AddTest(
206-
TARGET MODULE_IO_read_wfc_lcao_test
207-
LIBS parameter base ${math_libs} device
208-
SOURCES read_wfc_lcao_test.cpp ../read_wfc_lcao.cpp
209-
)
210-
211-
add_test(NAME MODULE_IO_read_wfc_lcao_test_parallel
212-
COMMAND mpirun -np 4 ./MODULE_IO_read_wfc_lcao_test
213-
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
214-
)
215-
216-
endif()
204+
#if(ENABLE_LCAO)
205+
#AddTest(
206+
# TARGET MODULE_IO_read_wfc_lcao_test
207+
# LIBS parameter base ${math_libs} device
208+
# SOURCES read_wfc_lcao_test.cpp ../read_wfc_lcao.cpp
209+
#)
210+
211+
#add_test(NAME MODULE_IO_read_wfc_lcao_test_parallel
212+
# COMMAND mpirun -np 4 ./MODULE_IO_read_wfc_lcao_test
213+
# WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
214+
#)
215+
216+
#endif()
217217

218218
AddTest(
219219
TARGET MODULE_IO_cif_io_test

0 commit comments

Comments
 (0)