Skip to content

Commit d9a5e92

Browse files
author
Fei Yang
committed
fix INPUT problem
1 parent ce6716e commit d9a5e92

File tree

12 files changed

+46
-51
lines changed

12 files changed

+46
-51
lines changed

source/source_io/input_conv.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ 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;
194193
Lattice_Change_Basic::fixed_axes = PARAM.inp.fixed_axes;
195194

196195

source/source_io/module_parameter/input_parameter.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,7 @@ struct Input_para
149149
// int bessel_nao_lmax; ///< lmax used in descriptor
150150

151151
// ============== #Parameters (4.Relaxation) ===========================
152-
std::string relax_method = "cg"; ///< methods to move_ion: sd, bfgs, cg...
153-
std::string relax_method_param = "1";
152+
std::vector<std::string> relax_method = {"cg","1"}; ///< methods to move_ion: sd, bfgs, cg...
154153
bool relax_new = true;
155154
bool relax = false; ///< allow relaxation along the specific direction
156155
double relax_scale_force = 0.5;

source/source_io/read_input_item_relax.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,21 @@ void ReadInput::item_relax()
1212
{
1313
Input_Item item("relax_method");
1414
item.annotation = "cg; bfgs; sd; cg; cg_bfgs;";
15-
read_sync_string(input.relax_method);
1615
item.read_value = [](const Input_Item& item, Parameter& para) {
1716
if(item.get_size()==1)
1817
{
19-
para.input.relax_method = item.str_values[0];
20-
para.input.relax_method_param = "1";
18+
para.input.relax_method[0] = item.str_values[0];
19+
para.input.relax_method[1] = "1";
2120
}
22-
else if(item.get_size()==2)
21+
else if(item.get_size()>=2)
2322
{
24-
para.input.relax_method = item.str_values[0];
25-
para.input.relax_method_param = item.str_values[1];
23+
para.input.relax_method[0] = item.str_values[0];
24+
para.input.relax_method[1] = item.str_values[1];
2625
}
2726
};
2827
item.check_value = [](const Input_Item& item, const Parameter& para) {
2928
const std::vector<std::string> relax_methods = {"cg", "sd", "cg_bfgs","lbfgs","bfgs"};
30-
if (std::find(relax_methods.begin(), relax_methods.end(), para.input.relax_method) == relax_methods.end()) {
29+
if (std::find(relax_methods.begin(), relax_methods.end(), para.input.relax_method[0]) == relax_methods.end()) {
3130
const std::string warningstr = nofound_str(relax_methods, "relax_method");
3231
ModuleBase::WARNING_QUIT("ReadInput", warningstr);
3332
}
@@ -52,7 +51,7 @@ void ReadInput::item_relax()
5251
item.annotation = "whether to use the new relaxation method";
5352
read_sync_bool(input.relax_new);
5453
item.reset_value = [](const Input_Item& item, Parameter& para) {
55-
if (para.input.relax_new && para.input.relax_method != "cg")
54+
if (para.input.relax_new && para.input.relax_method[0] != "cg")
5655
{
5756
para.input.relax_new = false;
5857
}

source/source_io/test/read_input_ptest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ TEST_F(InputParaTest, ParaRead)
114114
EXPECT_EQ(param.inp.fixed_axes, "None");
115115
EXPECT_FALSE(param.inp.fixed_ibrav);
116116
EXPECT_FALSE(param.inp.fixed_atoms);
117-
EXPECT_EQ(param.inp.relax_method, "cg");
117+
EXPECT_EQ(param.inp.relax_method[0], "cg");
118118
EXPECT_DOUBLE_EQ(param.inp.relax_cg_thr, 0.5);
119119
EXPECT_EQ(param.inp.out_level, "ie");
120120
EXPECT_TRUE(param.globalv.out_md_control);

source/source_io/test_serial/read_input_item_test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ TEST_F(InputTest, Item_test)
766766
}
767767
{ // relax_method
768768
auto it = find_label("relax_method", readinput.input_lists);
769-
param.input.relax_method = "none";
769+
param.input.relax_method[0] = "none";
770770
testing::internal::CaptureStdout();
771771
EXPECT_EXIT(it->second.check_value(it->second, param), ::testing::ExitedWithCode(1), "");
772772
output = testing::internal::GetCapturedStdout();
@@ -775,12 +775,12 @@ TEST_F(InputTest, Item_test)
775775
{ //relax_new
776776
auto it = find_label("relax_new", readinput.input_lists);
777777
param.input.relax_new = true;
778-
param.input.relax_method = "cg";
778+
param.input.relax_method[0] = "cg";
779779
it->second.reset_value(it->second, param);
780780
EXPECT_EQ(param.input.relax_new, true);
781781

782782
param.input.relax_new = true;
783-
param.input.relax_method = "none";
783+
param.input.relax_method[0] = "none";
784784
it->second.reset_value(it->second, param);
785785
EXPECT_EQ(param.input.relax_new, false);
786786
}

source/source_relax/ions_move_basic.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ double Ions_Move_Basic::relax_bfgs_init = -1.0; // default is 0.5
2323
double Ions_Move_Basic::best_xxx = 1.0;
2424

2525
int Ions_Move_Basic::out_stru = 0;
26-
std::string Ions_Move_Basic::relax_method = "bfgs";
27-
std::string Ions_Move_Basic::relax_method_param = "1";
26+
std::vector<std::string> Ions_Move_Basic::relax_method = {"bfgs","1"};
2827

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

source/source_relax/ions_move_basic.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ extern double relax_bfgs_rmax; // max value of trust radius,
2121
extern double relax_bfgs_rmin; // min value of trust radius,
2222
extern double relax_bfgs_init; // initial value of trust radius,
2323
extern double best_xxx; // the last step length of cg , we use it as bfgs`s initial step length
24-
extern std::string relax_method; // relaxation method,
24+
extern std::vector<std::string> relax_method; // relaxation method,
2525
extern int out_stru; // output the structure or not
26-
extern std::string relax_method_param;
2726
// funny way to pass this parameter, but nevertheless
2827

2928
//----------------------------------------------------------------------------

source/source_relax/ions_move_cg.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,12 @@ void Ions_Move_CG::start(UnitCell &ucell, const ModuleBase::matrix &force, const
163163
fmax = fa;
164164
sd = false;
165165

166-
if (Ions_Move_Basic::relax_method == "cg_bfgs")
166+
if (Ions_Move_Basic::relax_method[0] == "cg_bfgs")
167167
{
168168
if (Ions_Move_Basic::largest_grad * ModuleBase::Ry_to_eV / 0.529177
169169
< RELAX_CG_THR) // cg to bfgs by pengfei 13-8-8
170170
{
171-
Ions_Move_Basic::relax_method = "bfgs";
171+
Ions_Move_Basic::relax_method[0] = "bfgs";
172172
}
173173
Ions_Move_Basic::best_xxx = steplength;
174174
}

source/source_relax/ions_move_methods.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,28 @@ 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"&&Ions_Move_Basic::relax_method_param != "1")
19+
if (Ions_Move_Basic::relax_method[0] == "bfgs"&&Ions_Move_Basic::relax_method[1] != "1")
2020
{
2121
this->bfgs.allocate();
2222
}
23-
else if (Ions_Move_Basic::relax_method == "sd")
23+
else if (Ions_Move_Basic::relax_method[0] == "sd")
2424
{
2525
this->sd.allocate();
2626
}
27-
else if (Ions_Move_Basic::relax_method == "cg")
27+
else if (Ions_Move_Basic::relax_method[0] == "cg")
2828
{
2929
this->cg.allocate();
3030
}
31-
else if (Ions_Move_Basic::relax_method == "cg_bfgs")
31+
else if (Ions_Move_Basic::relax_method[0] == "cg_bfgs")
3232
{
3333
this->cg.allocate();
3434
this->bfgs.allocate(); // added by pengfei 13-8-8
3535
}
36-
else if(Ions_Move_Basic::relax_method == "bfgs"&&Ions_Move_Basic::relax_method_param == "1")
36+
else if(Ions_Move_Basic::relax_method[0] == "bfgs"&&Ions_Move_Basic::relax_method[1] == "1")
3737
{
3838
this->bfgs_trad.allocate(natom);
3939
}
40-
else if(Ions_Move_Basic::relax_method == "lbfgs")
40+
else if(Ions_Move_Basic::relax_method[0] == "lbfgs")
4141
{
4242
this->lbfgs.allocate(natom);
4343
}
@@ -58,30 +58,30 @@ void Ions_Move_Methods::cal_movement(const int &istep,
5858
ModuleBase::TITLE("Ions_Move_Methods", "init");
5959
// Ions_Move_Basic::istep = istep;
6060
Ions_Move_Basic::istep = force_step;
61-
if (Ions_Move_Basic::relax_method == "bfgs"&&Ions_Move_Basic::relax_method_param != "1")
61+
if (Ions_Move_Basic::relax_method[0] == "bfgs"&&Ions_Move_Basic::relax_method[1] != "1")
6262
{
6363
// move_ions
6464
// output tau
6565
// check all symmery
6666
bfgs.start(ucell, f, etot);
6767
}
68-
else if (Ions_Move_Basic::relax_method == "sd")
68+
else if (Ions_Move_Basic::relax_method[0] == "sd")
6969
{
7070
sd.start(ucell, f, etot);
7171
}
72-
else if (Ions_Move_Basic::relax_method == "cg")
72+
else if (Ions_Move_Basic::relax_method[0] == "cg")
7373
{
7474
cg.start(ucell, f, etot);
7575
}
76-
else if (Ions_Move_Basic::relax_method == "cg_bfgs")
76+
else if (Ions_Move_Basic::relax_method[0] == "cg_bfgs")
7777
{
7878
cg.start(ucell, f, etot); // added by pengfei 13-8-10
7979
}
80-
else if(Ions_Move_Basic::relax_method == "bfgs"&&Ions_Move_Basic::relax_method_param == "1")
80+
else if(Ions_Move_Basic::relax_method[0] == "bfgs"&&Ions_Move_Basic::relax_method[1] == "1")
8181
{
8282
bfgs_trad.relax_step(f,ucell);
8383
}
84-
else if(Ions_Move_Basic::relax_method == "lbfgs")
84+
else if(Ions_Move_Basic::relax_method[0] == "lbfgs")
8585
{
8686
lbfgs.relax_step(f,ucell,etot);
8787
}

source/source_relax/test/ions_move_cg_test.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ TEST_F(IonsMoveCGTest, TestStartSd)
138138
// setup data
139139
Ions_Move_Basic::istep = 1;
140140
Ions_Move_Basic::converged = false;
141-
Ions_Move_Basic::relax_method = "cg_bfgs";
141+
Ions_Move_Basic::relax_method[0] = "cg_bfgs";
142142
Ions_Move_CG::RELAX_CG_THR = 100.0;
143143
UnitCell ucell;
144144
setupucell(ucell);
@@ -162,7 +162,7 @@ TEST_F(IonsMoveCGTest, TestStartSd)
162162
EXPECT_THAT(output, testing::HasSubstr(expected_output));
163163
EXPECT_EQ(Ions_Move_Basic::converged, false);
164164
EXPECT_EQ(Ions_Move_Basic::update_iter, 5);
165-
EXPECT_EQ(Ions_Move_Basic::relax_method, "bfgs");
165+
EXPECT_EQ(Ions_Move_Basic::relax_method[0], "bfgs");
166166
EXPECT_DOUBLE_EQ(Ions_Move_Basic::largest_grad, 0.01);
167167
EXPECT_DOUBLE_EQ(Ions_Move_Basic::best_xxx, -1.0);
168168
EXPECT_DOUBLE_EQ(Ions_Move_Basic::relax_bfgs_init, 1.0);
@@ -201,7 +201,7 @@ TEST_F(IonsMoveCGTest, TestStartTrialGoto)
201201
EXPECT_THAT(output, testing::HasSubstr(expected_output));
202202
EXPECT_EQ(Ions_Move_Basic::converged, false);
203203
EXPECT_EQ(Ions_Move_Basic::update_iter, 5);
204-
EXPECT_EQ(Ions_Move_Basic::relax_method, "bfgs");
204+
EXPECT_EQ(Ions_Move_Basic::relax_method[0], "bfgs");
205205
EXPECT_DOUBLE_EQ(Ions_Move_Basic::largest_grad, 0.001);
206206
EXPECT_DOUBLE_EQ(Ions_Move_Basic::best_xxx, -1.0);
207207
EXPECT_DOUBLE_EQ(Ions_Move_Basic::relax_bfgs_init, 10.0);
@@ -239,7 +239,7 @@ TEST_F(IonsMoveCGTest, TestStartTrial)
239239
EXPECT_THAT(output, testing::HasSubstr(expected_output));
240240
EXPECT_EQ(Ions_Move_Basic::converged, false);
241241
EXPECT_EQ(Ions_Move_Basic::update_iter, 5);
242-
EXPECT_EQ(Ions_Move_Basic::relax_method, "bfgs");
242+
EXPECT_EQ(Ions_Move_Basic::relax_method[0], "bfgs");
243243
EXPECT_DOUBLE_EQ(Ions_Move_Basic::largest_grad, 0.01);
244244
EXPECT_DOUBLE_EQ(Ions_Move_Basic::best_xxx, -1.0);
245245
EXPECT_DOUBLE_EQ(Ions_Move_Basic::relax_bfgs_init, 70.0);
@@ -279,7 +279,7 @@ TEST_F(IonsMoveCGTest, TestStartNoTrialGotoCase1)
279279
EXPECT_THAT(output, testing::HasSubstr(expected_output));
280280
EXPECT_EQ(Ions_Move_Basic::converged, false);
281281
EXPECT_EQ(Ions_Move_Basic::update_iter, 5);
282-
EXPECT_EQ(Ions_Move_Basic::relax_method, "bfgs");
282+
EXPECT_EQ(Ions_Move_Basic::relax_method[0], "bfgs");
283283
EXPECT_DOUBLE_EQ(Ions_Move_Basic::largest_grad, 0.001);
284284
EXPECT_DOUBLE_EQ(Ions_Move_Basic::best_xxx, -1.0);
285285
EXPECT_DOUBLE_EQ(Ions_Move_Basic::relax_bfgs_init, 490.0);
@@ -318,7 +318,7 @@ TEST_F(IonsMoveCGTest, TestStartNoTrialGotoCase2)
318318
EXPECT_THAT(output, testing::HasSubstr(expected_output));
319319
EXPECT_EQ(Ions_Move_Basic::converged, false);
320320
EXPECT_EQ(Ions_Move_Basic::update_iter, 5);
321-
EXPECT_EQ(Ions_Move_Basic::relax_method, "bfgs");
321+
EXPECT_EQ(Ions_Move_Basic::relax_method[0], "bfgs");
322322
EXPECT_DOUBLE_EQ(Ions_Move_Basic::largest_grad, 0.01);
323323
EXPECT_DOUBLE_EQ(Ions_Move_Basic::best_xxx, -1.0);
324324
EXPECT_DOUBLE_EQ(Ions_Move_Basic::relax_bfgs_init, 70.0);
@@ -358,7 +358,7 @@ TEST_F(IonsMoveCGTest, TestStartNoTrial)
358358
EXPECT_THAT(output, testing::HasSubstr(expected_output));
359359
EXPECT_EQ(Ions_Move_Basic::converged, false);
360360
EXPECT_EQ(Ions_Move_Basic::update_iter, 5);
361-
EXPECT_EQ(Ions_Move_Basic::relax_method, "bfgs");
361+
EXPECT_EQ(Ions_Move_Basic::relax_method[0], "bfgs");
362362
EXPECT_DOUBLE_EQ(Ions_Move_Basic::largest_grad, 0.001);
363363
EXPECT_DOUBLE_EQ(Ions_Move_Basic::best_xxx, -1.0);
364364
EXPECT_NEAR(Ions_Move_Basic::relax_bfgs_init, 1.2345679012345678, 1e-12);

0 commit comments

Comments
 (0)