Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions source/source_io/module_parameter/read_input_item_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,15 @@ void ReadInput::item_system()
ModuleBase::WARNING_QUIT("ReadInput", "Can not find `pot_file` !");
}
}
};
item.reset_value = [](const Input_Item& item, Parameter& para) {
// LR reads the ground state wave function from a separate SCF run,
// so it cannot be combined with a self-consistent calculation.
if (para.input.esolver_type == "lr" && para.input.calculation == "scf")
{ // for LR-only calculation based on the ground-state, set calculation to "nscf"
para.input.calculation = "nscf";
{
ModuleBase::WARNING_QUIT("ReadInput",
"esolver_type=lr requires calculation=nscf (it reads the ground state "
"wave function computed by a separate SCF run); please set calculation=nscf.");
}
};
};
this->add_item(item);
}
{
Expand Down
6 changes: 4 additions & 2 deletions source/source_io/test_serial/read_input_item_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,10 @@ TEST_F(InputTest, Item_test)
param.input.esolver_type = "lr";
param.input.calculation = "scf";
it = find_label("esolver_type", readinput.input_lists);
it->second.reset_value(it->second, param);
EXPECT_EQ(param.input.calculation, "nscf");
testing::internal::CaptureStdout();
EXPECT_EXIT(it->second.check_value(it->second, param), ::testing::ExitedWithCode(1), "");
output = testing::internal::GetCapturedStdout();
EXPECT_THAT(output, testing::HasSubstr("esolver_type=lr requires calculation=nscf"));
}
{ // nspin
auto it = find_label("nspin", readinput.input_lists);
Expand Down
19 changes: 19 additions & 0 deletions source/source_io/test_serial/read_input_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,25 @@ TEST_F(InputTest, ValidateBandParallelization)
"bndpar can not exceed the number of MPI processes");
}

TEST_F(InputTest, ValidateLrRequiresNscf)
{
// esolver_type=lr reads the ground state wave function from a separate SCF run,
// so it cannot be combined with a self-consistent calculation.
expect_invalid_input("lr_scf_INPUT",
"esolver_type lr\n",
"esolver_type=lr requires calculation=nscf");
expect_invalid_input("lr_explicit_scf_INPUT",
"esolver_type lr\ncalculation scf\n",
"esolver_type=lr requires calculation=nscf");

Parameter valid_param;
EXPECT_NO_THROW(read_parameters("lr_nscf_INPUT",
"esolver_type lr\ncalculation nscf\n",
valid_param));
EXPECT_EQ(valid_param.inp.esolver_type, "lr");
EXPECT_EQ(valid_param.inp.calculation, "nscf");
}

TEST_F(InputTest, ValidateDeepksOutputFrequency)
{
Parameter default_param;
Expand Down
Loading