From 23f01c589a26d0bdf1ac97ee992ea73db2557271 Mon Sep 17 00:00:00 2001 From: kirk0830 Date: Mon, 15 Jan 2024 13:16:04 +0800 Subject: [PATCH 1/6] add precision control --- source/module_cell/klist.cpp | 4 ++-- source/module_esolver/esolver_ks_lcao.cpp | 14 +++++++++++--- source/module_esolver/esolver_ks_pw.cpp | 5 +++-- source/module_io/input.cpp | 13 ++++++++----- source/module_io/input.h | 2 +- source/module_io/nscf_band.cpp | 23 ++++++++++++++--------- source/module_io/nscf_band.h | 1 + source/module_io/parameter_pool.cpp | 2 +- source/module_io/test/input_test.cpp | 14 ++++++++++---- source/module_io/test/input_test_para.cpp | 4 +++- source/module_io/write_input.cpp | 4 ++-- 11 files changed, 56 insertions(+), 30 deletions(-) diff --git a/source/module_cell/klist.cpp b/source/module_cell/klist.cpp index 52bc42440d..2ace717d4e 100644 --- a/source/module_cell/klist.cpp +++ b/source/module_cell/klist.cpp @@ -444,7 +444,7 @@ bool K_Vectors::read_kpoints(const std::string &fn) ifk >> ksx[iks]; ifk >> ksy[iks]; ifk >> ksz[iks]; - ModuleBase::GlobalFunc::READ_VALUE( ifk, nkl[iks] ); + ModuleBase::GlobalFunc::READ_VALUE( ifk, nkl[iks] ); /* so ifk is ifstream for kpoint, then nkl is number of kpoints on line */ //std::cout << " nkl[" << iks << "]=" << nkl[iks] << std::endl; assert(nkl[iks] >= 0); nkstot += nkl[iks]; @@ -461,7 +461,7 @@ bool K_Vectors::read_kpoints(const std::string &fn) double dy = (ksy[iks] - ksy[iks-1]) / nkl[iks-1]; double dz = (ksz[iks] - ksz[iks-1]) / nkl[iks-1]; // GlobalV::ofs_running << " dx=" << dx << " dy=" << dy << " dz=" << dz << std::endl; - for(int is=0; ispelec->f_en.etot * ModuleBase::Ry_to_eV << " eV" << std::endl; GlobalV::ofs_running << " --------------------------------------------\n\n" << std::endl; - if (INPUT.out_dos != 0 || INPUT.out_band != 0 || INPUT.out_proj_band != 0) + if (INPUT.out_dos != 0 || INPUT.out_band[0] != 0 || INPUT.out_proj_band != 0) { GlobalV::ofs_running << "\n\n\n\n"; GlobalV::ofs_running << " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" << std::endl; @@ -331,7 +331,7 @@ namespace ModuleESolver int nspin0 = (GlobalV::NSPIN == 2) ? 2 : 1; - if (INPUT.out_band) // pengfei 2014-10-13 + if (INPUT.out_band[0]) // pengfei 2014-10-13 { int nks = 0; if (nspin0 == 1) @@ -348,7 +348,15 @@ namespace ModuleESolver std::stringstream ss2; ss2 << GlobalV::global_out_dir << "BANDS_" << is + 1 << ".dat"; GlobalV::ofs_running << "\n Output bands in file: " << ss2.str() << std::endl; - ModuleIO::nscf_band(is, ss2.str(), nks, GlobalV::NBANDS, 0.0, this->pelec->ekb, this->kv, &(GlobalC::Pkpoints)); + ModuleIO::nscf_band(is, + ss2.str(), + nks, + GlobalV::NBANDS, + 0.0, + INPUT.out_band[1], + this->pelec->ekb, + this->kv, + &(GlobalC::Pkpoints)); } } // out_band diff --git a/source/module_esolver/esolver_ks_pw.cpp b/source/module_esolver/esolver_ks_pw.cpp index 294f1636f7..2e81938ae2 100644 --- a/source/module_esolver/esolver_ks_pw.cpp +++ b/source/module_esolver/esolver_ks_pw.cpp @@ -959,7 +959,7 @@ void ESolver_KS_PW::postprocess() GlobalV::ofs_running << " !FINAL_ETOT_IS " << this->pelec->f_en.etot * ModuleBase::Ry_to_eV << " eV" << std::endl; GlobalV::ofs_running << " --------------------------------------------\n\n" << std::endl; - if (INPUT.out_dos != 0 || INPUT.out_band != 0) + if (INPUT.out_dos != 0 || INPUT.out_band[0] != 0) { GlobalV::ofs_running << "\n\n\n\n"; GlobalV::ofs_running << " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" << std::endl; @@ -1001,7 +1001,7 @@ void ESolver_KS_PW::postprocess() } } - if (INPUT.out_band) // pengfei 2014-10-13 + if (INPUT.out_band[0]) // pengfei 2014-10-13 { int nks = 0; if (nspin0 == 1) @@ -1022,6 +1022,7 @@ void ESolver_KS_PW::postprocess() nks, GlobalV::NBANDS, 0.0, + INPUT.out_band[1], this->pelec->ekb, this->kv, &(GlobalC::Pkpoints)); diff --git a/source/module_io/input.cpp b/source/module_io/input.cpp index ece1bfbf5c..a4f1dd8934 100644 --- a/source/module_io/input.cpp +++ b/source/module_io/input.cpp @@ -336,7 +336,7 @@ void Input::Default(void) out_wfc_pw = 0; out_wfc_r = 0; out_dos = 0; - out_band = 0; + out_band = {0, 8}; out_proj_band = 0; out_mat_hs = {0, 8}; out_mat_xc = 0; @@ -1377,7 +1377,8 @@ bool Input::Read(const std::string& fn) } else if (strcmp("out_band", word) == 0) { - read_bool(ifs, out_band); + read_value2stdvector(ifs, out_band); + if(out_band.size() == 1) out_band.push_back(8); } else if (strcmp("out_proj_band", word) == 0) { @@ -2825,7 +2826,7 @@ void Input::Default_2(void) // jiyy add 2019-08-04 this->relax_nmax = 1; out_stru = 0; out_dos = 0; - out_band = 0; + out_band[0] = 0; out_proj_band = 0; cal_force = 0; init_wfc = "file"; @@ -2842,7 +2843,7 @@ void Input::Default_2(void) // jiyy add 2019-08-04 this->relax_nmax = 1; out_stru = 0; out_dos = 0; - out_band = 0; + out_band[0] = 0; out_proj_band = 0; cal_force = 0; init_wfc = "file"; @@ -3305,8 +3306,10 @@ void Input::Bcast() Parallel_Common::bcast_int(out_wfc_pw); Parallel_Common::bcast_bool(out_wfc_r); Parallel_Common::bcast_int(out_dos); - Parallel_Common::bcast_bool(out_band); + if(GlobalV::MY_RANK != 0) out_band.resize(2); /* If this line is absent, will cause segmentation fault in io_input_test_para */ + Parallel_Common::bcast_int(out_band.data(), 2); Parallel_Common::bcast_bool(out_proj_band); + if(GlobalV::MY_RANK != 0) out_mat_hs.resize(2); /* If this line is absent, will cause segmentation fault in io_input_test_para */ Parallel_Common::bcast_int(out_mat_hs.data(), 2); Parallel_Common::bcast_bool(out_mat_hs2); // LiuXh add 2019-07-15 Parallel_Common::bcast_bool(out_mat_t); diff --git a/source/module_io/input.h b/source/module_io/input.h index 66927af591..169d1026e8 100644 --- a/source/module_io/input.h +++ b/source/module_io/input.h @@ -263,7 +263,7 @@ class Input int out_wfc_pw; // 0: no; 1: txt; 2: dat bool out_wfc_r; // 0: no; 1: yes int out_dos; // dos calculation. mohan add 20090909 - bool out_band; // band calculation pengfei 2014-10-13 + std::vector out_band; // band calculation pengfei 2014-10-13 bool out_proj_band; // projected band structure calculation jiyy add 2022-05-11 std::vector out_mat_hs; // output H matrix and S matrix in local basis. bool out_mat_xc; // output exchange-correlation matrix in KS-orbital representation. diff --git a/source/module_io/nscf_band.cpp b/source/module_io/nscf_band.cpp index d8b7b05ca6..850da6f7a3 100644 --- a/source/module_io/nscf_band.cpp +++ b/source/module_io/nscf_band.cpp @@ -3,6 +3,7 @@ #include "module_base/global_variable.h" #include "module_base/timer.h" #include "module_base/tool_title.h" +#include "module_base/formatter_physfmt.h" void ModuleIO::nscf_band( const int &is, @@ -10,6 +11,7 @@ void ModuleIO::nscf_band( const int &nks, const int &nband, const double &fermie, + const int &precision, const ModuleBase::matrix& ekb, const K_Vectors& kv, const Parallel_Kpoints* Pkpoints) @@ -42,14 +44,15 @@ void ModuleIO::nscf_band( { if ( GlobalV::RANK_IN_POOL == 0) { + formatter::PhysicalFmt physfmt; // create a physical formatter temporarily std::ofstream ofs(out_band_dir.c_str(),std::ios::app); - ofs << std::setprecision(8); - //start from 1 - ofs << ik+1; - ofs << " " << klength[ik] << " "; + physfmt.adjust_formatter_flexible(4, 0, false); // for integer + ofs << physfmt.get_p_formatter()->format(ik+1); + physfmt.adjust_formatter_flexible(precision, 4.0/double(precision), false); // for decimal + ofs << physfmt.get_p_formatter()->format(klength[ik]); for(int ib = 0; ib < nband; ib++) { - ofs << " " << (ekb(ik_now+is*nks, ib)-fermie) * ModuleBase::Ry_to_eV; + ofs << physfmt.get_p_formatter()->format((ekb(ik_now+is*nks, ib)-fermie) * ModuleBase::Ry_to_eV); } ofs << std::endl; ofs.close(); @@ -83,18 +86,20 @@ void ModuleIO::nscf_band( #else // std::cout<<"\n nband = "<format(ik+1); + physfmt.adjust_formatter_flexible(precision, 4.0/double(precision), false); // for decimal for(int ibnd = 0; ibnd < nband; ibnd++) { - ofs <format((ekb(ik, ibnd)-fermie) * ModuleBase::Ry_to_eV); } - ofs< input_parameters } else if (input_parameters.count("out_band") != 0) { - INPUT.out_band = *static_cast(input_parameters["out_band"].get()); + INPUT.out_band = *static_cast*>(input_parameters["out_band"].get()); } else if (input_parameters.count("out_proj_band") != 0) { diff --git a/source/module_io/test/input_test.cpp b/source/module_io/test/input_test.cpp index 02a5a19e10..11bce873ab 100644 --- a/source/module_io/test/input_test.cpp +++ b/source/module_io/test/input_test.cpp @@ -176,9 +176,11 @@ TEST_F(InputTest, Default) EXPECT_EQ(INPUT.out_wfc_pw,0); EXPECT_EQ(INPUT.out_wfc_r,0); EXPECT_EQ(INPUT.out_dos,0); - EXPECT_EQ(INPUT.out_band,0); + EXPECT_EQ(INPUT.out_band[0],0); + EXPECT_EQ(INPUT.out_band[1],8); EXPECT_EQ(INPUT.out_proj_band,0); EXPECT_EQ(INPUT.out_mat_hs[0],0); + EXPECT_EQ(INPUT.out_mat_hs[1],8); EXPECT_EQ(INPUT.out_mat_hs2,0); EXPECT_EQ(INPUT.out_mat_xc, 0); EXPECT_EQ(INPUT.out_interval,1); @@ -539,9 +541,11 @@ TEST_F(InputTest, Read) EXPECT_EQ(INPUT.out_wfc_pw,0); EXPECT_EQ(INPUT.out_wfc_r,0); EXPECT_EQ(INPUT.out_dos,0); - EXPECT_EQ(INPUT.out_band,0); + EXPECT_EQ(INPUT.out_band[0],0); + EXPECT_EQ(INPUT.out_band[1],8); EXPECT_EQ(INPUT.out_proj_band,0); EXPECT_EQ(INPUT.out_mat_hs[0],0); + EXPECT_EQ(INPUT.out_mat_hs[1],8); EXPECT_EQ(INPUT.out_mat_hs2,0); EXPECT_EQ(INPUT.out_mat_xc, 0); EXPECT_EQ(INPUT.out_interval,1); @@ -921,7 +925,8 @@ TEST_F(InputTest, Default_2) EXPECT_EQ(INPUT.relax_nmax, 1); EXPECT_EQ(INPUT.out_stru, 0); EXPECT_EQ(INPUT.symmetry, "0"); - EXPECT_EQ(INPUT.out_band,0); + EXPECT_EQ(INPUT.out_band[0],0); + EXPECT_EQ(INPUT.out_band[1],8); EXPECT_EQ(INPUT.out_proj_band,0); EXPECT_EQ(INPUT.cal_force,0); EXPECT_EQ(INPUT.init_wfc,"file"); @@ -943,7 +948,8 @@ TEST_F(InputTest, Default_2) EXPECT_EQ(INPUT.relax_nmax, 1); EXPECT_EQ(INPUT.symmetry, "0"); EXPECT_EQ(INPUT.out_stru, 0); - EXPECT_EQ(INPUT.out_band,0); + EXPECT_EQ(INPUT.out_band[0],0); + EXPECT_EQ(INPUT.out_band[1],8); EXPECT_EQ(INPUT.out_proj_band,0); EXPECT_EQ(INPUT.cal_force,0); EXPECT_EQ(INPUT.init_wfc,"file"); diff --git a/source/module_io/test/input_test_para.cpp b/source/module_io/test/input_test_para.cpp index 444fa1b05a..29f06dd3a6 100644 --- a/source/module_io/test/input_test_para.cpp +++ b/source/module_io/test/input_test_para.cpp @@ -180,9 +180,11 @@ TEST_F(InputParaTest, Bcast) EXPECT_EQ(INPUT.out_wfc_pw, 0); EXPECT_EQ(INPUT.out_wfc_r, 0); EXPECT_EQ(INPUT.out_dos, 0); - EXPECT_EQ(INPUT.out_band, 0); + EXPECT_EQ(INPUT.out_band[0], 0); + EXPECT_EQ(INPUT.out_band[1], 8); EXPECT_EQ(INPUT.out_proj_band, 0); EXPECT_EQ(INPUT.out_mat_hs[0], 0); + EXPECT_EQ(INPUT.out_mat_hs[1], 8); EXPECT_EQ(INPUT.out_mat_hs2, 0); EXPECT_EQ(INPUT.out_mat_xc, 0); EXPECT_EQ(INPUT.out_interval, 1); diff --git a/source/module_io/write_input.cpp b/source/module_io/write_input.cpp index 5c0fc4cada..b7e49901c8 100644 --- a/source/module_io/write_input.cpp +++ b/source/module_io/write_input.cpp @@ -122,7 +122,7 @@ void Input::Print(const std::string &fn) const ModuleBase::GlobalFunc::OUTP(ofs, "out_wfc_pw", out_wfc_pw, "output wave functions"); ModuleBase::GlobalFunc::OUTP(ofs, "out_wfc_r", out_wfc_r, "output wave functions in realspace"); ModuleBase::GlobalFunc::OUTP(ofs, "out_dos", out_dos, "output energy and dos"); - ModuleBase::GlobalFunc::OUTP(ofs, "out_band", out_band, "output energy and band structure"); + ModuleBase::GlobalFunc::OUTP(ofs, "out_band", out_band[0], "output energy and band structure (with precision "+std::to_string(out_band[1])+")"); ModuleBase::GlobalFunc::OUTP(ofs, "out_proj_band", out_proj_band, "output projected band structure"); ModuleBase::GlobalFunc::OUTP(ofs, "restart_save", restart_save, "print to disk every step for restart"); ModuleBase::GlobalFunc::OUTP(ofs, "restart_load", restart_load, "restart from disk"); @@ -222,7 +222,7 @@ ModuleBase::GlobalFunc::OUTP(ofs, "out_bandgap", out_bandgap, "if true, print ou ModuleBase::GlobalFunc::OUTP(ofs, "lcao_dk", lcao_dk, "delta k for 1D integration in LCAO"); ModuleBase::GlobalFunc::OUTP(ofs, "lcao_dr", lcao_dr, "delta r for 1D integration in LCAO"); ModuleBase::GlobalFunc::OUTP(ofs, "lcao_rmax", lcao_rmax, "max R for 1D two-center integration table"); - ModuleBase::GlobalFunc::OUTP(ofs, "out_mat_hs", out_mat_hs[0], "output H and S matrix"); + ModuleBase::GlobalFunc::OUTP(ofs, "out_mat_hs", out_mat_hs[0], "output H and S matrix (with precision "+std::to_string(out_mat_hs[1])+")"); ModuleBase::GlobalFunc::OUTP(ofs, "out_mat_hs2", out_mat_hs2, "output H(R) and S(R) matrix"); ModuleBase::GlobalFunc::OUTP(ofs, "out_mat_dh", out_mat_dh, "output of derivative of H(R) matrix"); ModuleBase::GlobalFunc::OUTP(ofs, "out_mat_xc", out_mat_xc, "output exchange-correlation matrix in KS-orbital representation"); From 1010dffc9e6e3ae578569c63abe40268993ff6f1 Mon Sep 17 00:00:00 2001 From: kirk0830 Date: Mon, 15 Jan 2024 13:17:35 +0800 Subject: [PATCH 2/6] correct serial version of nscf_band function --- source/module_io/nscf_band.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/source/module_io/nscf_band.cpp b/source/module_io/nscf_band.cpp index 850da6f7a3..01102ed19b 100644 --- a/source/module_io/nscf_band.cpp +++ b/source/module_io/nscf_band.cpp @@ -87,14 +87,23 @@ void ModuleIO::nscf_band( // std::cout<<"\n nband = "< klength; + klength.resize(nks); + klength[0] = 0.0; std::ofstream ofs(out_band_dir.c_str()); for(int ik=0;ik0) + { + auto delta=kv.kvec_c[ik]-kv.kvec_c[ik-1]; + klength[ik] = klength[ik-1] + delta.norm(); + } if( kv.isk[ik] == is) { physfmt.adjust_formatter_flexible(4, 0, false); // for integer ofs << physfmt.get_p_formatter()->format(ik+1); physfmt.adjust_formatter_flexible(precision, 4.0/double(precision), false); // for decimal + ofs << physfmt.get_p_formatter()->format(klength[ik]); // add klength, in accordance with the MPI version for(int ibnd = 0; ibnd < nband; ibnd++) { ofs << physfmt.get_p_formatter()->format((ekb(ik, ibnd)-fermie) * ModuleBase::Ry_to_eV); From 284703281438ea7b0c5ad8dd597e663a3fd744e2 Mon Sep 17 00:00:00 2001 From: kirk0830 Date: Mon, 15 Jan 2024 15:09:31 +0800 Subject: [PATCH 3/6] fix issue 3482 --- source/module_cell/klist.cpp | 37 ++++++++++++++++++++++------------ source/module_cell/klist.h | 1 + source/module_io/nscf_band.cpp | 11 +++++++--- 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/source/module_cell/klist.cpp b/source/module_cell/klist.cpp index 2ace717d4e..18116bcf63 100644 --- a/source/module_cell/klist.cpp +++ b/source/module_cell/klist.cpp @@ -362,6 +362,9 @@ bool K_Vectors::read_kpoints(const std::string &fn) //recalculate nkstot. nkstot = 0; + /* ISSUE#3482: to distinguish different kline segments */ + std::vector kpt_segids; + int kpt_segid = 0; for(int iks=0; iks> ksx[iks]; @@ -371,6 +374,9 @@ bool K_Vectors::read_kpoints(const std::string &fn) //std::cout << " nkl[" << iks << "]=" << nkl[iks] << std::endl; assert(nkl[iks] >= 0); nkstot += nkl[iks]; + /* ISSUE#3482: to distinguish different kline segments */ + if((nkl[iks] == 1)&&(iks!=(nks_special-1))) kpt_segid++; + kpt_segids.push_back(kpt_segid); } assert( nkl[nks_special-1] == 1); @@ -389,6 +395,7 @@ bool K_Vectors::read_kpoints(const std::string &fn) kvec_c[count].x = ksx[iks-1] + is*dx; kvec_c[count].y = ksy[iks-1] + is*dy; kvec_c[count].z = ksz[iks-1] + is*dz; + kl_segids.push_back(kpt_segids[iks-1]); /* ISSUE#3482: to distinguish different kline segments */ ++count; } } @@ -397,15 +404,14 @@ bool K_Vectors::read_kpoints(const std::string &fn) kvec_c[count].x = ksx[nks_special-1]; kvec_c[count].y = ksy[nks_special-1]; kvec_c[count].z = ksz[nks_special-1]; + kl_segids.push_back(kpt_segids[nks_special-1]); /* ISSUE#3482: to distinguish different kline segments */ ++count; //std::cout << " count = " << count << std::endl; - assert (count == nkstot ); - - for(int ik=0; ikkc_done = true; @@ -439,6 +445,9 @@ bool K_Vectors::read_kpoints(const std::string &fn) //recalculate nkstot. nkstot = 0; + /* ISSUE#3482: to distinguish different kline segments */ + std::vector kpt_segids; + int kpt_segid = 0; for(int iks=0; iks> ksx[iks]; @@ -448,6 +457,9 @@ bool K_Vectors::read_kpoints(const std::string &fn) //std::cout << " nkl[" << iks << "]=" << nkl[iks] << std::endl; assert(nkl[iks] >= 0); nkstot += nkl[iks]; + /* ISSUE#3482: to distinguish different kline segments */ + if((nkl[iks] == 1)&&(iks!=(nks_special-1))) kpt_segid++; + kpt_segids.push_back(kpt_segid); } assert( nkl[nks_special-1] == 1); @@ -461,11 +473,12 @@ bool K_Vectors::read_kpoints(const std::string &fn) double dy = (ksy[iks] - ksy[iks-1]) / nkl[iks-1]; double dz = (ksz[iks] - ksz[iks-1]) / nkl[iks-1]; // GlobalV::ofs_running << " dx=" << dx << " dy=" << dy << " dz=" << dz << std::endl; - for(int is=0; is Date: Mon, 15 Jan 2024 16:08:12 +0800 Subject: [PATCH 5/6] update document --- docs/advanced/input_files/input-main.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/advanced/input_files/input-main.md b/docs/advanced/input_files/input-main.md index e9debb3632..30192987f6 100644 --- a/docs/advanced/input_files/input-main.md +++ b/docs/advanced/input_files/input-main.md @@ -1494,8 +1494,8 @@ These variables are used to control the output of properties. ### out_band -- **Type**: Boolean -- **Description**: Whether to output the band structure (in eV). For more information, refer to the [band.md](../elec_properties/band.md) +- **Type**: Boolean Integer(optional) +- **Description**: Whether to output the band structure (in eV), optionally output precision can be set by a second parameter, default is 8. For more information, refer to the [band.md](../elec_properties/band.md) - **Default**: False ### out_proj_band From b9d0e56e01e6e0f6aa43d771b3bd623e0f70dd32 Mon Sep 17 00:00:00 2001 From: kirk0830 Date: Tue, 16 Jan 2024 11:37:59 +0800 Subject: [PATCH 6/6] correct unittest and make compatible with false and true --- source/module_io/input.cpp | 1 - source/module_io/input.h | 10 +++++++++- source/module_io/test/support/INPUT | 2 +- source/module_io/test/support/witestfile | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/source/module_io/input.cpp b/source/module_io/input.cpp index f207467af4..abe8f28ebd 100644 --- a/source/module_io/input.cpp +++ b/source/module_io/input.cpp @@ -1385,7 +1385,6 @@ bool Input::Read(const std::string& fn) { read_bool(ifs, out_proj_band); } - else if (strcmp("out_mat_hs", word) == 0) { read_value2stdvector(ifs, out_mat_hs); diff --git a/source/module_io/input.h b/source/module_io/input.h index ef49104cee..6393483cb4 100644 --- a/source/module_io/input.h +++ b/source/module_io/input.h @@ -667,7 +667,15 @@ class Input template typename std::enable_if::value, T>::type cast_string(const std::string& str) { return std::stod(str); } template - typename std::enable_if::value, T>::type cast_string(const std::string& str) { return std::stoi(str); } + typename std::enable_if::value, T>::type cast_string(const std::string& str) + { + if (str == "true" || str == "1") + return 1; + else if (str == "false" || str == "0") + return 0; + else + return std::stoi(str); + } template typename std::enable_if::value, T>::type cast_string(const std::string& str) { return (str == "true" || str == "1"); } template diff --git a/source/module_io/test/support/INPUT b/source/module_io/test/support/INPUT index 469dff2ff4..4fbde867db 100644 --- a/source/module_io/test/support/INPUT +++ b/source/module_io/test/support/INPUT @@ -59,7 +59,7 @@ out_pot 2 #output realspace potential out_wfc_pw 0 #output wave functions out_wfc_r 0 #output wave functions in realspace out_dos 0 #output energy and dos -out_band false #output energy and band structure +out_band 0 #output energy and band structure out_proj_band FaLse #output projected band structure restart_save f #print to disk every step for restart restart_load F #restart from disk diff --git a/source/module_io/test/support/witestfile b/source/module_io/test/support/witestfile index 4043773876..4db819d53f 100644 --- a/source/module_io/test/support/witestfile +++ b/source/module_io/test/support/witestfile @@ -55,7 +55,7 @@ out_pot 2 #output realspace potential out_wfc_pw 0 #output wave functions out_wfc_r 0 #output wave functions in realspace out_dos 0 #output energy and dos -out_band false #output energy and band structure +out_band 0 #output energy and band structure out_proj_band FaLse #output projected band structure restart_save f #print to disk every step for restart restart_load F #restart from disk