Skip to content

Commit

Permalink
move back Kpoint when basis_type="pw" (#5129)
Browse files Browse the repository at this point in the history
* move back gamma_only and Kpoint

* add gtest in the OFS
  • Loading branch information
A-006 committed Sep 19, 2024
1 parent 7d43917 commit 20d283b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
17 changes: 14 additions & 3 deletions source/module_io/read_input_item_elec_stru.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,10 +451,21 @@ void ReadInput::item_elec_stru()
"set to 1, a fast algorithm is used";
read_sync_bool(input.gamma_only);
item.reset_value = [](const Input_Item& item, Parameter& para) {
if (para.input.gamma_only && para.input.basis_type == "pw")
if (para.input.basis_type == "pw" && para.input.gamma_only)
{
para.input.gamma_only = false;
GlobalV::ofs_warning << "gamma_only is not supported in the pw model" << std::endl;
para.input.gamma_only = false;
GlobalV::ofs_warning << " WARNING : gamma_only has not been implemented for pw yet" << std::endl;
GlobalV::ofs_warning << "gamma_only is not supported in the pw model" << std::endl;
GlobalV::ofs_warning << " the INPUT parameter gamma_only has been reset to 0" << std::endl;
GlobalV::ofs_warning << " and a new KPT is generated with "
"gamma point as the only k point"<< std::endl;
GlobalV::ofs_warning << " Auto generating k-points file: " << para.input.kpoint_file << std::endl;
std::ofstream ofs(para.input.kpoint_file.c_str());
ofs << "K_POINTS" << std::endl;
ofs << "0" << std::endl;
ofs << "Gamma" << std::endl;
ofs << "1 1 1 0 0 0" << std::endl;
ofs.close();
}
};
this->add_item(item);
Expand Down
1 change: 0 additions & 1 deletion source/module_io/test_serial/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ AddTest(
AddTest(
TARGET io_read_item_serial
LIBS parameter ${math_libs} base device io_input_serial
LIBS parameter ${math_libs} base device io_input_serial
SOURCES read_input_item_test.cpp
)

Expand Down
7 changes: 7 additions & 0 deletions source/module_io/test_serial/read_input_item_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -811,8 +811,15 @@ TEST_F(InputTest, Item_test)
auto it = find_label("gamma_only", readinput.input_lists);
param.input.basis_type = "pw";
param.input.gamma_only = true;
std::string filename = param.input.kpoint_file;
it->second.reset_value(it->second, param);
EXPECT_EQ(param.input.gamma_only, false);
std::ifstream ifs(filename);
std::string line;
std::getline(ifs, line);
ifs.close();
EXPECT_EQ(line, "K_POINTS");

}
{ // out_mat_r
auto it = find_label("out_mat_r", readinput.input_lists);
Expand Down

0 comments on commit 20d283b

Please sign in to comment.