Skip to content

Commit acde430

Browse files
committed
fix the bug
1 parent 3132ce7 commit acde430

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/integrate/ensemble_npt_qtb.cu

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ Ensemble_NPT_QTB::Ensemble_NPT_QTB(const char** params, int num_params)
112112

113113
// NPT-QTB: barostat on, NHC thermostat off (QTB replaces it)
114114
ensemble_type = NPH;
115-
use_barostat = true;
115+
use_barostat = false; // will be set true only when a pressure direction is parsed
116116
use_thermostat = false;
117117

118118
// QTB defaults
@@ -125,13 +125,15 @@ Ensemble_NPT_QTB::Ensemble_NPT_QTB(const char** params, int num_params)
125125
while (i < num_params) {
126126
if (strcmp(params[i], "iso") == 0 || strcmp(params[i], "aniso") == 0 ||
127127
strcmp(params[i], "tri") == 0) {
128+
if (i + 2 >= num_params) PRINT_INPUT_ERROR("iso/aniso/tri requires <p_start> <p_stop>.");
128129
if (!is_valid_real(params[i + 1], &p_start[0][0]))
129130
PRINT_INPUT_ERROR("Wrong inputs for p_start.");
130131
p_start[1][1] = p_start[2][2] = p_start[0][0];
131132
if (!is_valid_real(params[i + 2], &p_stop[0][0]))
132133
PRINT_INPUT_ERROR("Wrong inputs for p_stop.");
133134
p_stop[1][1] = p_stop[2][2] = p_stop[0][0];
134135
p_flag[0][0] = p_flag[1][1] = p_flag[2][2] = true;
136+
use_barostat = true;
135137
if (strcmp(params[i], "iso") == 0)
136138
couple_type = XYZ;
137139
if (strcmp(params[i], "tri") == 0) {
@@ -141,18 +143,22 @@ Ensemble_NPT_QTB::Ensemble_NPT_QTB(const char** params, int num_params)
141143
}
142144
i += 3;
143145
} else if (strcmp(params[i], "x") == 0) {
146+
if (i + 2 >= num_params) PRINT_INPUT_ERROR("x requires <p_start> <p_stop>.");
144147
if (!is_valid_real(params[i + 1], &p_start[0][0])) PRINT_INPUT_ERROR("Wrong p_start for x.");
145148
if (!is_valid_real(params[i + 2], &p_stop[0][0])) PRINT_INPUT_ERROR("Wrong p_stop for x.");
146-
p_flag[0][0] = 1; non_hydrostatic = 1; i += 3;
149+
p_flag[0][0] = 1; non_hydrostatic = 1; use_barostat = true; i += 3;
147150
} else if (strcmp(params[i], "y") == 0) {
151+
if (i + 2 >= num_params) PRINT_INPUT_ERROR("y requires <p_start> <p_stop>.");
148152
if (!is_valid_real(params[i + 1], &p_start[1][1])) PRINT_INPUT_ERROR("Wrong p_start for y.");
149153
if (!is_valid_real(params[i + 2], &p_stop[1][1])) PRINT_INPUT_ERROR("Wrong p_stop for y.");
150-
p_flag[1][1] = 1; non_hydrostatic = 1; i += 3;
154+
p_flag[1][1] = 1; non_hydrostatic = 1; use_barostat = true; i += 3;
151155
} else if (strcmp(params[i], "z") == 0) {
156+
if (i + 2 >= num_params) PRINT_INPUT_ERROR("z requires <p_start> <p_stop>.");
152157
if (!is_valid_real(params[i + 1], &p_start[2][2])) PRINT_INPUT_ERROR("Wrong p_start for z.");
153158
if (!is_valid_real(params[i + 2], &p_stop[2][2])) PRINT_INPUT_ERROR("Wrong p_stop for z.");
154-
p_flag[2][2] = 1; non_hydrostatic = 1; i += 3;
159+
p_flag[2][2] = 1; non_hydrostatic = 1; use_barostat = true; i += 3;
155160
} else if (strcmp(params[i], "pperiod") == 0) {
161+
if (i + 1 >= num_params) PRINT_INPUT_ERROR("pperiod requires a value.");
156162
if (!is_valid_real(params[i + 1], &p_period[0][0]))
157163
PRINT_INPUT_ERROR("Wrong inputs for pperiod.");
158164
if (p_period[0][0] < 200)
@@ -162,20 +168,30 @@ Ensemble_NPT_QTB::Ensemble_NPT_QTB(const char** params, int num_params)
162168
p_period[a][b] = p_period[0][0];
163169
i += 2;
164170
} else if (strcmp(params[i], "temp") == 0) {
171+
if (i + 2 >= num_params) PRINT_INPUT_ERROR("temp requires two values: <T_start> <T_stop>.");
165172
if (!is_valid_real(params[i + 1], &t_start)) PRINT_INPUT_ERROR("Wrong t_start.");
166173
if (!is_valid_real(params[i + 2], &t_stop)) PRINT_INPUT_ERROR("Wrong t_stop.");
174+
if (t_start <= 0) PRINT_INPUT_ERROR("t_start should > 0.");
175+
if (t_stop <= 0) PRINT_INPUT_ERROR("t_stop should > 0.");
167176
t_target = t_start;
168177
i += 3;
169178
} else if (strcmp(params[i], "tperiod") == 0) {
179+
if (i + 1 >= num_params) PRINT_INPUT_ERROR("tperiod requires a value.");
170180
if (!is_valid_real(params[i + 1], &t_period)) PRINT_INPUT_ERROR("Wrong tperiod.");
181+
if (t_period <= 0) PRINT_INPUT_ERROR("tperiod should > 0.");
171182
i += 2;
172183
} else if (strcmp(params[i], "f_max") == 0) {
184+
if (i + 1 >= num_params) PRINT_INPUT_ERROR("f_max requires a value.");
173185
if (!is_valid_real(params[i + 1], &qtb_f_max)) PRINT_INPUT_ERROR("f_max should be a number.");
186+
if (qtb_f_max <= 0) PRINT_INPUT_ERROR("f_max should > 0.");
174187
i += 2;
175188
} else if (strcmp(params[i], "N_f") == 0) {
189+
if (i + 1 >= num_params) PRINT_INPUT_ERROR("N_f requires a value.");
176190
if (!is_valid_int(params[i + 1], &qtb_n_f_input)) PRINT_INPUT_ERROR("N_f should be an integer.");
191+
if (qtb_n_f_input <= 0) PRINT_INPUT_ERROR("N_f should > 0.");
177192
i += 2;
178193
} else if (strcmp(params[i], "seed") == 0) {
194+
if (i + 1 >= num_params) PRINT_INPUT_ERROR("seed requires a value.");
179195
if (!is_valid_int(params[i + 1], &qtb_seed)) PRINT_INPUT_ERROR("seed should be an integer.");
180196
i += 2;
181197
} else {

src/integrate/integrate.cu

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,8 @@ void Integrate::parse_ensemble(
978978
break;
979979
case -11:
980980
break;
981+
case -12: // npt_qtb (self-parsed)
982+
break;
981983
case 21:
982984
printf("Integrate with heating and cooling for this run.\n");
983985
printf(" choose the Nose-Hoover chain method.\n");

0 commit comments

Comments
 (0)