Skip to content

Commit 4d7ef80

Browse files
author
Fei Yang
committed
change input parameters
1 parent 036af83 commit 4d7ef80

File tree

7 files changed

+29
-13
lines changed

7 files changed

+29
-13
lines changed

source/source_io/input_conv.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ void Input_Conv::Convert()
190190
Ions_Move_Basic::relax_bfgs_init = PARAM.inp.relax_bfgs_init;
191191
Ions_Move_Basic::out_stru = PARAM.inp.out_stru; // mohan add 2012-03-23
192192
Ions_Move_Basic::relax_method = PARAM.inp.relax_method;
193+
Ions_Move_Basic::relax_method_param = PARAM.inp.relax_method_param;
193194
Lattice_Change_Basic::fixed_axes = PARAM.inp.fixed_axes;
194195

195196

source/source_io/module_parameter/input_parameter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
struct RelaxMethodParam {
1010
std::string method;
11-
int param = 1;
11+
std::string param;
1212
};
1313

1414
// It stores all input parameters both defined in INPUT file and not defined in

source/source_io/read_input_item_relax.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,36 @@ void ReadInput::item_relax()
1111
{
1212
{
1313
Input_Item item("relax_method");
14-
item.annotation = "cg [param]; bfgs [param]; ...";
14+
item.annotation = "cg; bfgs; sd; cg; cg_bfgs;";
1515
read_sync_string(input.relax_method);
1616
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;
17+
para.input.relax_method_param.method=item.str_values[0];
18+
para.input.relax_method = para.input.relax_method_param.method;
19+
if(item.get_size()==1)
20+
{
21+
para.input.relax_method_param.param = "1";
2122
}
23+
else
24+
{
25+
para.input.relax_method_param.param = item.str_values[1];
26+
}
27+
28+
// std::istringstream iss(item.str_values[0]);
29+
// iss >> para.input.relax_method_param.method;
30+
// if (!(iss >> para.input.relax_method_param.param)) {
31+
// std::cout << "No parameter provided for relax_method_param.param, default to 1" << std::endl;
32+
// para.input.relax_method_param.param = "1";
33+
// }
2234
};
2335
item.check_value = [](const Input_Item& item, const Parameter& para) {
24-
const std::vector<std::string> relax_methods = {"cg", "sd","bfgs_old" "cg_bfgs","bfgs","lbfgs"};
36+
const std::vector<std::string> relax_methods = {"cg", "sd", "cg_bfgs","bfgs","lbfgs"};
2537
if (std::find(relax_methods.begin(), relax_methods.end(), para.input.relax_method_param.method) == relax_methods.end()) {
2638
const std::string warningstr = nofound_str(relax_methods, "relax_method");
2739
ModuleBase::WARNING_QUIT("ReadInput", warningstr);
2840
}
2941
};
3042
this->add_item(item);
43+
3144
// Input_Item item("relax_method");
3245
// item.annotation = "cg; bfgs; sd; cg; cg_bfgs;";
3346
// read_sync_string(input.relax_method);

source/source_relax/ions_move_basic.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ double Ions_Move_Basic::best_xxx = 1.0;
2424

2525
int Ions_Move_Basic::out_stru = 0;
2626
std::string Ions_Move_Basic::relax_method = "bfgs";
27+
RelaxMethodParam Ions_Move_Basic::relax_method_param;
2728

2829
void Ions_Move_Basic::setup_gradient(const UnitCell &ucell, const ModuleBase::matrix &force, double *pos, double *grad)
2930
{

source/source_relax/ions_move_basic.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include "source_base/matrix.h"
55
#include "source_cell/unitcell.h"
6+
#include "source_io/module_parameter/input_parameter.h"
67

78
namespace Ions_Move_Basic
89
{
@@ -23,6 +24,7 @@ extern double relax_bfgs_init; // initial value of trust radius,
2324
extern double best_xxx; // the last step length of cg , we use it as bfgs`s initial step length
2425
extern std::string relax_method; // relaxation method,
2526
extern int out_stru; // output the structure or not
27+
extern RelaxMethodParam relax_method_param;
2628
// funny way to pass this parameter, but nevertheless
2729

2830
//----------------------------------------------------------------------------

source/source_relax/ions_move_methods.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ void Ions_Move_Methods::allocate(const int &natom)
1616
{
1717
Ions_Move_Basic::dim = natom * 3;
1818

19-
if (Ions_Move_Basic::relax_method == "bfgs")
19+
if (Ions_Move_Basic::relax_method_param.method == "bfgs"&&Ions_Move_Basic::relax_method_param.param != "1")
2020
{
2121
this->bfgs.allocate();
2222
}
@@ -33,7 +33,7 @@ void Ions_Move_Methods::allocate(const int &natom)
3333
this->cg.allocate();
3434
this->bfgs.allocate(); // added by pengfei 13-8-8
3535
}
36-
else if(Ions_Move_Basic::relax_method == "bfgs_trad")
36+
else if(Ions_Move_Basic::relax_method_param.method == "bfgs"&&Ions_Move_Basic::relax_method_param.param == "1")
3737
{
3838
this->bfgs_trad.allocate(natom);
3939
}
@@ -59,8 +59,7 @@ void Ions_Move_Methods::cal_movement(const int &istep,
5959

6060
// Ions_Move_Basic::istep = istep;
6161
Ions_Move_Basic::istep = force_step;
62-
63-
if (Ions_Move_Basic::relax_method == "bfgs_old")
62+
if (Ions_Move_Basic::relax_method_param.method == "bfgs"&&Ions_Move_Basic::relax_method_param.param != "1")
6463
{
6564
// move_ions
6665
// output tau
@@ -79,7 +78,7 @@ void Ions_Move_Methods::cal_movement(const int &istep,
7978
{
8079
cg.start(ucell, f, etot); // added by pengfei 13-8-10
8180
}
82-
else if(Ions_Move_Basic::relax_method == "bfgs")
81+
else if(Ions_Move_Basic::relax_method_param.method == "bfgs"&&Ions_Move_Basic::relax_method_param.param == "1")
8382
{
8483
bfgs_trad.relax_step(f,ucell);
8584
}

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_old
11+
relax_method bfgs 2
1212
relax_new 0
1313

1414
# Self-Consistent Field

0 commit comments

Comments
 (0)