Skip to content

Commit e3baf15

Browse files
author
Fei Yang
committed
change input parameters
1 parent 1b2738f commit e3baf15

File tree

4 files changed

+35
-9
lines changed

4 files changed

+35
-9
lines changed

source/source_io/module_parameter/input_parameter.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
#include <string>
77
#include <vector>
88

9+
struct RelaxMethodParam {
10+
std::string method;
11+
int param = 1;
12+
};
13+
914
// It stores all input parameters both defined in INPUT file and not defined in
1015
// INPUT file
1116
struct Input_para
@@ -149,6 +154,7 @@ struct Input_para
149154

150155
// ============== #Parameters (4.Relaxation) ===========================
151156
std::string relax_method = "cg"; ///< methods to move_ion: sd, bfgs, cg...
157+
RelaxMethodParam relax_method_param;
152158
bool relax_new = true;
153159
bool relax = false; ///< allow relaxation along the specific direction
154160
double relax_scale_force = 0.5;

source/source_io/read_input_item_relax.cpp

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,41 @@
55

66
namespace ModuleIO
77
{
8+
9+
810
void ReadInput::item_relax()
911
{
1012
{
1113
Input_Item item("relax_method");
12-
item.annotation = "cg; bfgs; sd; cg; cg_bfgs;";
14+
item.annotation = "cg [param]; bfgs [param]; ...";
1315
read_sync_string(input.relax_method);
16+
item.read_value = [](const Input_Item& item, Parameter& para) {
17+
std::istringstream iss(para.input.relax_method);
18+
iss >> para.input.relax_method_param.method;
19+
if (!(iss >> para.input.relax_method_param.param)) {
20+
para.input.relax_method_param.param = 1;
21+
}
22+
};
1423
item.check_value = [](const Input_Item& item, const Parameter& para) {
15-
const std::vector<std::string> relax_methods = {"cg", "bfgs_old", "sd", "cg_bfgs","bfgs","lbfgs"};
16-
if (std::find(relax_methods.begin(),relax_methods.end(), para.input.relax_method)==relax_methods.end())
17-
{
18-
const std::string warningstr = nofound_str(relax_methods, "relax_method");
19-
ModuleBase::WARNING_QUIT("ReadInput", warningstr);
20-
}
24+
const std::vector<std::string> relax_methods = {"cg", "sd","bfgs_old" "cg_bfgs","bfgs","lbfgs"};
25+
if (std::find(relax_methods.begin(), relax_methods.end(), para.input.relax_method_param.method) == relax_methods.end()) {
26+
const std::string warningstr = nofound_str(relax_methods, "relax_method");
27+
ModuleBase::WARNING_QUIT("ReadInput", warningstr);
28+
}
2129
};
2230
this->add_item(item);
31+
// Input_Item item("relax_method");
32+
// item.annotation = "cg; bfgs; sd; cg; cg_bfgs;";
33+
// read_sync_string(input.relax_method);
34+
// item.check_value = [](const Input_Item& item, const Parameter& para) {
35+
// const std::vector<std::string> relax_methods = {"cg", "bfgs_old", "sd", "cg_bfgs","bfgs","lbfgs"};
36+
// if (std::find(relax_methods.begin(),relax_methods.end(), para.input.relax_method)==relax_methods.end())
37+
// {
38+
// const std::string warningstr = nofound_str(relax_methods, "relax_method");
39+
// ModuleBase::WARNING_QUIT("ReadInput", warningstr);
40+
// }
41+
// };
42+
// this->add_item(item);
2343
}
2444
{
2545
Input_Item item("relax_new");

tests/01_PW/058_PW_RE_MB/INPUT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ calculation relax
88
relax_nmax 2
99
cal_force 1
1010
force_thr_ev 0.01
11-
relax_method bfgs
11+
relax_method bfgs_old
1212
relax_new 0
1313

1414
# Self-Consistent Field

tests/01_PW/059_PW_RE_MB_traj/INPUT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ scf_nmax 100
1616
relax_nmax 2
1717
cal_force 1
1818
force_thr_ev 0.01
19-
relax_method bfgs_trad
19+
relax_method bfgs
2020

2121
#Parameters (4.Basis)
2222
basis_type pw

0 commit comments

Comments
 (0)