1616
1717TEST (GenWfcLcaoFnameTest, OutType1GammaOnlyOutAppFlagTrue)
1818{
19- int out_type = 1 ;
20- bool gamma_only = true ;
21- bool out_app_flag = true ;
22- int ik = 0 ;
23- int istep = 0 ;
24-
25- std::string expected_output = " WFC_NAO_GAMMA1.txt" ;
26- std::string result = ModuleIO::wfc_nao_gen_fname (out_type, gamma_only, out_app_flag, ik, istep);
19+ // output .txt file when out_type=1
20+ const int out_type = 1 ;
21+ const bool gamma_only = true ;
22+ const bool out_app_flag = true ;
23+ const int ik = 0 ;
24+ const std::vector<int > ik2iktot = {0 };
25+ const int nkstot = 1 ;
26+ const int nspin = 1 ;
27+ // if out_app_flag = true, then the 'g' label will not show up
28+ const int istep = 0 ;
29+
30+ std::string expected_output = " wfs1k1_nao.txt" ;
31+ std::string result = ModuleIO::wfc_nao_gen_fname (out_type, gamma_only, out_app_flag, ik,
32+ ik2iktot, nkstot, nspin, istep);
2733
2834 EXPECT_EQ (result, expected_output);
2935}
3036
3137TEST (GenWfcLcaoFnameTest, OutType2GammaOnlyOutAppFlagFalse)
3238{
33- int out_type = 2 ;
34- bool gamma_only = true ;
35- bool out_app_flag = false ;
36- int ik = 1 ;
37- int istep = 2 ;
38-
39- std::string expected_output = " WFC_NAO_GAMMA2_ION3.dat" ;
40- std::string result = ModuleIO::wfc_nao_gen_fname (out_type, gamma_only, out_app_flag, ik, istep);
39+ // output .dat file when out_type=2
40+ const int out_type = 2 ;
41+ const bool gamma_only = true ;
42+ // if out_app_flag = false, then the 'g' label appears
43+ const bool out_app_flag = false ;
44+ const int ik = 1 ;
45+ const std::vector<int > ik2iktot = {0 ,1 };
46+ const int nkstot = 2 ;
47+ const int nspin = 2 ;
48+ const int istep = 2 ;
49+
50+ std::string expected_output = " wfs2g3_nao.dat" ;
51+ std::string result = ModuleIO::wfc_nao_gen_fname (out_type, gamma_only, out_app_flag, ik,
52+ ik2iktot, nkstot, nspin, istep);
4153
4254 EXPECT_EQ (result, expected_output);
4355}
4456
4557TEST (GenWfcLcaoFnameTest, OutTypeInvalid)
4658{
47- int out_type = 3 ;
48- bool gamma_only = false ;
49- bool out_app_flag = true ;
50- int ik = 2 ;
51- int istep = 3 ;
52-
53- std::string expected_output = " WFC_NAO_K3.txt" ;
59+ // a .txt is chosen if out_type is not 1 or 2
60+ const int out_type = 3 ;
61+ const bool gamma_only = false ;
62+ const bool out_app_flag = true ;
63+ const int ik = 2 ;
64+ const std::vector<int > ik2iktot = {0 ,1 ,2 };
65+ const int nkstot = 3 ;
66+ const int nspin = 1 ;
67+ const int istep = 3 ;
68+
69+ std::string expected_output = " wfs1k3_nao.txt" ;
5470 // catch the screen output
5571 testing::internal::CaptureStdout ();
56- std::string result = ModuleIO::wfc_nao_gen_fname (out_type, gamma_only, out_app_flag, ik, istep);
72+ std::string result = ModuleIO::wfc_nao_gen_fname (out_type, gamma_only, out_app_flag, ik,
73+ ik2iktot, nkstot, nspin, istep);
5774 std::string output = testing::internal::GetCapturedStdout ();
5875
5976 EXPECT_EQ (result, expected_output);
@@ -64,7 +81,8 @@ void read_bin(const std::string& name, std::vector<T>& data)
6481{
6582 std::ifstream ifs (name, std::ios::binary);
6683 ifs.seekg (0 , std::ios::beg);
67- int nbands, nbasis;
84+ int nbands=0 ;
85+ int nbasis=0 ;
6886 if (std::is_same<T, std::complex <double >>::value)
6987 {
7088 ifs.ignore (sizeof (int ));
@@ -92,6 +110,7 @@ class WriteWfcLcaoTest : public testing::Test
92110 ModuleBase::matrix ekb;
93111 ModuleBase::matrix wg;
94112 std::vector<ModuleBase::Vector3<double >> kvec_c;
113+
95114 std::vector<double > psi_init_double;
96115 std::vector<std::complex <double >> psi_init_complex;
97116 std::vector<double > psi_local_double;
@@ -100,12 +119,16 @@ class WriteWfcLcaoTest : public testing::Test
100119 int nk = 2 ;
101120 int nbands = 3 ;
102121 int nbasis = 4 ;
103- int nbands_local;
104- int nbasis_local;
122+ int nbands_local = 0 ;
123+ int nbasis_local = 0 ;
124+
125+ // mohan add 2025-05-11
126+ std::vector<int > ik2iktot = {0 ,1 };
127+ int nkstot = 2 ;
128+ bool out_app_flag = true ;
105129
106130 void SetUp () override
107131 {
108- PARAM.input .out_app_flag = true ;
109132 ekb.create (nk, nbands); // in this test the value of ekb and wg is not important and not used.
110133 wg.create (nk, nbands);
111134 kvec_c.resize (nk, ModuleBase::Vector3<double >(0.0 , 0.0 , 0.0 ));
@@ -166,17 +189,26 @@ class WriteWfcLcaoTest : public testing::Test
166189
167190TEST_F (WriteWfcLcaoTest, WriteWfcLcao)
168191{
169- // create a psi object
170- psi::Psi<double > my_psi (psi_local_double.data (), nk, nbands_local, nbasis_local, nbasis_local, true );
171192 PARAM.sys .global_out_dir = " ./" ;
172- ModuleIO::write_wfc_nao (2 , my_psi, ekb, wg, kvec_c, pv, -1 );
173193
174- // check the output
194+ const int out_type = 2 ;
195+ psi::Psi<double > my_psi (psi_local_double.data (), nk, nbands_local, nbasis_local, nbasis_local, true );
196+ const int nspin = 2 ;
197+ const int istep = -1 ;
198+
199+ ModuleIO::write_wfc_nao (out_type, out_app_flag, my_psi, ekb, wg, kvec_c,
200+ ik2iktot, nkstot, pv, nspin, istep);
201+
202+ const bool gamma_only = true ;
203+
204+ // check the output file
175205 if (GlobalV::MY_RANK == 0 )
176206 {
177207 for (int ik = 0 ; ik < nk; ik++)
178208 {
179- std::string fname = ModuleIO::wfc_nao_gen_fname (2 , true , PARAM.input .out_app_flag , ik, -1 );
209+ std::string fname = ModuleIO::wfc_nao_gen_fname (out_type, gamma_only,
210+ out_app_flag, ik, ik2iktot, nkstot, nspin, istep);
211+
180212 std::ifstream file1 (fname);
181213 EXPECT_TRUE (file1.good ());
182214 std::vector<double > data;
@@ -196,16 +228,26 @@ TEST_F(WriteWfcLcaoTest, WriteWfcLcao)
196228
197229TEST_F (WriteWfcLcaoTest, WriteWfcLcaoComplex)
198230{
199- psi::Psi<std::complex <double >> my_psi (psi_local_complex.data (), nk, nbands_local, nbasis_local, true );
200231 PARAM.sys .global_out_dir = " ./" ;
201- ModuleIO::write_wfc_nao (2 , my_psi, ekb, wg, kvec_c, pv, -1 );
232+
233+ const int out_type = 2 ;
234+ psi::Psi<std::complex <double >> my_psi (psi_local_complex.data (), nk, nbands_local, nbasis_local, true );
235+ const int nspin = 1 ;
236+ const int istep = -1 ;
237+
238+ ModuleIO::write_wfc_nao (out_type, out_app_flag, my_psi, ekb, wg, kvec_c,
239+ ik2iktot, nkstot, pv, nspin, istep);
240+
241+ const bool gamma_only = false ;
202242
203243 // check the output file
204244 if (GlobalV::MY_RANK == 0 )
205245 {
206246 for (int ik = 0 ; ik < nk; ik++)
207247 {
208- std::string fname = ModuleIO::wfc_nao_gen_fname (2 , false , PARAM.input .out_app_flag , ik, -1 );
248+ std::string fname = ModuleIO::wfc_nao_gen_fname (out_type, gamma_only,
249+ out_app_flag, ik, ik2iktot, nkstot, nspin, istep);
250+
209251 std::ifstream file1 (fname);
210252 EXPECT_TRUE (file1.good ());
211253 std::vector<std::complex <double >> data;
@@ -231,7 +273,6 @@ TEST(ModuleIOTest, WriteWfcNao)
231273 GlobalV::DRANK = 0 ;
232274 PARAM.input .nbands = 2 ;
233275 PARAM.sys .nlocal = 2 ;
234- PARAM.input .out_app_flag = true ;
235276
236277 // Set up test data
237278 std::string filename = " test_wfc_nao.txt" ;
@@ -278,7 +319,6 @@ TEST(ModuleIOTest, WriteWfcNaoBinary)
278319 GlobalV::DRANK = 0 ;
279320 PARAM.input .nbands = 2 ;
280321 PARAM.sys .nlocal = 2 ;
281- PARAM.input .out_app_flag = true ;
282322
283323 // Set up test data
284324 std::string filename = " test_wfc_nao.dat" ;
@@ -335,7 +375,6 @@ TEST(ModuleIOTest, WriteWfcNaoComplex)
335375 // Set up GlobalV
336376 PARAM.input .nbands = 2 ;
337377 PARAM.sys .nlocal = 3 ;
338- PARAM.input .out_app_flag = true ;
339378 // set up test data
340379 std::string name = " test_wfc_nao_complex.txt" ;
341380 int ik = 0 ;
@@ -379,7 +418,6 @@ TEST(ModuleIOTest, WriteWfcNaoComplexBinary)
379418 // Set up GlobalV
380419 PARAM.input .nbands = 2 ;
381420 PARAM.sys .nlocal = 3 ;
382- PARAM.input .out_app_flag = true ;
383421 // set up test data
384422 std::string name = " test_wfc_nao_complex.dat" ;
385423 int ik = 0 ;
0 commit comments