Skip to content

Commit b5b292b

Browse files
committed
Feature: support a uniformed alias comprehension manner
1 parent 83f966a commit b5b292b

File tree

1 file changed

+36
-13
lines changed

1 file changed

+36
-13
lines changed

source/module_io/read_input_item_elec_stru.cpp

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,40 @@
33
#include "read_input.h"
44
#include "read_input_tool.h"
55

6+
#include <map>
7+
8+
// next time if there are other keywords need the support of alias, move this function
9+
// to an upper level
10+
std::string alias_to_full_name(const std::map<std::string, std::vector<std::string>>& m,
11+
const std::string& in)
12+
{
13+
for (const auto& key : m)
14+
{
15+
if (std::find(key.second.begin(), key.second.end(), in) != key.second.end())
16+
{
17+
return key.first;
18+
}
19+
}
20+
ModuleBase::WARNING_QUIT("ModuleIO::ReadInput::read_input_item_elec_stru::alias_to_full_name",
21+
"The alias: `" + in + "` is not supported.");
22+
}
23+
24+
// support the alias for keyword `smearing_type`
25+
void alias_update_smearing_method(std::string& in)
26+
{
27+
// once there is new option added, update this map
28+
const std::map<std::string, std::vector<std::string>> alias = {
29+
{"fixed", {"fixed"}},
30+
{"gaussian", {"gaussian", "gauss", "gau"}},
31+
{"fermi-dirac", {"fermi-dirac", "fd", "f-d"}},
32+
{"mp", {"mp", "methfessel-paxton", "m-p"}},
33+
{"mp2", {"mp2", "mp-2"}},
34+
{"mp3", {"mp3", "mp-3"}},
35+
{"marzari-vanderbilt", {"marzari-vanderbilt", "mv", "m-v", "cold"}}
36+
};
37+
in = alias_to_full_name(alias, in);
38+
}
39+
640
namespace ModuleIO
741
{
842
void ReadInput::item_elec_stru()
@@ -335,20 +369,9 @@ void ReadInput::item_elec_stru()
335369
}
336370
{
337371
Input_Item item("smearing_method");
338-
item.annotation = "type of smearing_method: gauss; fd; fixed; mp; mp2; mv";
372+
item.annotation = "type of smearing on electronic occupation";
373+
alias_update_smearing_method(item.str_values[0]); // it might not be the best place
339374
read_sync_string(input.smearing_method);
340-
item.check_value = [](const Input_Item& item, const Parameter& para) {
341-
const std::vector<std::string> methods = {"gauss", "gaussian",
342-
"fd", "fermi-dirac",
343-
"fixed",
344-
"mp", "mp2", "mp3"
345-
"marzari-vanderbilt", "cold", "mv"};
346-
if (std::find(methods.begin(), methods.end(), para.input.smearing_method) == methods.end())
347-
{
348-
const std::string warningstr = nofound_str(methods, "smearing_method");
349-
ModuleBase::WARNING_QUIT("ReadInput", warningstr);
350-
}
351-
};
352375
this->add_item(item);
353376
}
354377
{

0 commit comments

Comments
 (0)