Skip to content

Commit 2788887

Browse files
committed
expand the group method
1 parent 5f19b7a commit 2788887

19 files changed

Lines changed: 109 additions & 46 deletions

src/integrate/ensemble.cu

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ void Ensemble::velocity_verlet_v()
299299
int n = atom->number_of_atoms;
300300
const int* group_pointer;
301301
if (group->size())
302-
group_pointer = (*group)[0].label.data();
302+
group_pointer = (*group)[fixed_grouping_method].label.data();
303303
else
304304
group_pointer = 0;
305305

@@ -324,7 +324,7 @@ void Ensemble::velocity_verlet_x()
324324
int n = atom->number_of_atoms;
325325
const int* group_pointer;
326326
if (group->size())
327-
group_pointer = (*group)[0].label.data();
327+
group_pointer = (*group)[fixed_grouping_method].label.data();
328328
else
329329
group_pointer = 0;
330330
gpu_velocity_verlet_x<<<(n - 1) / 128 + 1, 128>>>(
@@ -380,7 +380,7 @@ void Ensemble::velocity_verlet(
380380
move_velocity[0],
381381
move_velocity[1],
382382
move_velocity[2],
383-
group[0].label.data(),
383+
group[fixed_grouping_method].label.data(),
384384
time_step,
385385
mass.data(),
386386
position_per_atom.data(),
@@ -646,10 +646,10 @@ void Ensemble::find_thermo(
646646
const int number_of_atoms = mass.size();
647647
int num_atoms_for_temperature = number_of_atoms;
648648
if (fixed_group >= 0) {
649-
num_atoms_for_temperature -= group[0].cpu_size[fixed_group];
649+
num_atoms_for_temperature -= group[fixed_grouping_method].cpu_size[fixed_group];
650650
}
651651
if (move_group >= 0) {
652-
num_atoms_for_temperature -= group[0].cpu_size[move_group];
652+
num_atoms_for_temperature -= group[move_grouping_method].cpu_size[move_group];
653653
}
654654

655655
gpu_find_thermo_instant_temperature<<<8, 1024>>>(

src/integrate/ensemble.cuh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ public:
7676
int sink;
7777
int fixed_group = -1; // ID of the group in which the atoms will be fixed
7878
int move_group = -1; // ID of the group in which the atoms will move with a constant velocity
79+
int fixed_grouping_method = 0;
80+
int move_grouping_method = 0;
7981
double move_velocity[3];
8082
double temperature; // target temperature at a specific time
8183
double delta_temperature;

src/integrate/ensemble_bao.cu

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ void Ensemble_BAO::operator_A(
278278
gpu_operator_A<<<(number_of_atoms - 1) / 128 + 1, 128>>>(
279279
number_of_atoms,
280280
fixed_group,
281-
group[0].label.data(),
281+
group[fixed_grouping_method].label.data(),
282282
time_step,
283283
mass.data(),
284284
position_per_atom.data(),
@@ -400,7 +400,7 @@ void Ensemble_BAO::operator_B(
400400
gpu_operator_B<<<(number_of_atoms - 1) / 128 + 1, 128>>>(
401401
number_of_atoms,
402402
fixed_group,
403-
group[0].label.data(),
403+
group[fixed_grouping_method].label.data(),
404404
time_step,
405405
mass.data(),
406406
position_per_atom.data(),

src/integrate/ensemble_bdp.cu

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ void Ensemble_BDP::integrate_nvt_bdp_2(
8484
false, time_step, group, mass, force_per_atom, position_per_atom, velocity_per_atom);
8585

8686
// get thermo
87-
int N_fixed = (fixed_group == -1) ? 0 : group[0].cpu_size[fixed_group];
88-
N_fixed += (move_group == -1) ? 0 : group[0].cpu_size[move_group];
87+
int N_fixed = (fixed_group == -1) ? 0 : group[fixed_grouping_method].cpu_size[fixed_group];
88+
N_fixed += (move_group == -1) ? 0 : group[move_grouping_method].cpu_size[move_group];
8989
find_thermo(
9090
true, volume, group, mass, potential_per_atom, velocity_per_atom, virial_per_atom, thermo);
9191

src/integrate/ensemble_npt_scr.cu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ void Ensemble_NPT_SCR::compute2(
239239
atom.position_per_atom,
240240
atom.velocity_per_atom);
241241

242-
int N_fixed = (fixed_group == -1) ? 0 : group[0].cpu_size[fixed_group];
242+
int N_fixed = (fixed_group == -1) ? 0 : group[fixed_grouping_method].cpu_size[fixed_group];
243243
find_thermo(
244244
true,
245245
box.get_volume(),

src/integrate/integrate.cu

Lines changed: 68 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,12 @@ void Integrate::initialize(
5757
if (fixed_group < 0) {
5858
PRINT_INPUT_ERROR("It is not allowed to have moving group but no fixed group.");
5959
}
60-
if (move_group == fixed_group) {
60+
if (move_group == fixed_group && move_grouping_method == fixed_grouping_method) {
6161
PRINT_INPUT_ERROR("The fixed and moving groups cannot be the same.");
6262
}
63+
if (fixed_grouping_method != move_grouping_method) {
64+
PRINT_INPUT_ERROR("The fixed and moving groups must use the same grouping method.");
65+
}
6366
if (type != 1 && type != 2 && type != 4 && type != 22) {
6467
PRINT_INPUT_ERROR(
6568
"It is only allowed to use nvt_ber, nvt_nhc, or nvt_bdp with a moving group.");
@@ -208,12 +211,16 @@ void Integrate::initialize(
208211
ensemble->total_steps = &this->total_steps;
209212
ensemble->thermo = &thermo;
210213
ensemble->fixed_group = fixed_group;
214+
ensemble->fixed_grouping_method = fixed_grouping_method;
215+
ensemble->move_grouping_method = move_grouping_method;
211216
}
212217

213218
void Integrate::finalize()
214219
{
215220
fixed_group = -1; // no group has an index of -1
216221
move_group = -1;
222+
fixed_grouping_method = 0;
223+
move_grouping_method = 0;
217224
deform_x = 0;
218225
deform_y = 0;
219226
deform_z = 0;
@@ -990,64 +997,105 @@ void Integrate::parse_ensemble(
990997

991998
void Integrate::parse_fix(const char** param, int num_param, std::vector<Group>& group)
992999
{
993-
if (num_param != 2) {
994-
PRINT_INPUT_ERROR("Keyword 'fix' should have 1 parameter.");
995-
}
996-
997-
if (!is_valid_int(param[1], &fixed_group)) {
998-
PRINT_INPUT_ERROR("Fixed group ID should be an integer.");
1000+
if (num_param != 2 && num_param != 3) {
1001+
PRINT_INPUT_ERROR("Keyword 'fix' should have 1 or 2 parameters.");
9991002
}
10001003

10011004
if (group.size() < 1) {
10021005
PRINT_INPUT_ERROR("Cannot use 'fix' without grouping method.");
10031006
}
10041007

1008+
if (num_param == 3) {
1009+
// fix grouping_method group_id
1010+
if (!is_valid_int(param[1], &fixed_grouping_method)) {
1011+
PRINT_INPUT_ERROR("Grouping method for 'fix' should be an integer.");
1012+
}
1013+
if (fixed_grouping_method < 0) {
1014+
PRINT_INPUT_ERROR("Grouping method for 'fix' should >= 0.");
1015+
}
1016+
if (fixed_grouping_method >= group.size()) {
1017+
PRINT_INPUT_ERROR("Grouping method for 'fix' should < number of grouping methods.");
1018+
}
1019+
if (!is_valid_int(param[2], &fixed_group)) {
1020+
PRINT_INPUT_ERROR("Fixed group ID should be an integer.");
1021+
}
1022+
} else {
1023+
// fix group_id (default grouping_method = 0)
1024+
fixed_grouping_method = 0;
1025+
if (!is_valid_int(param[1], &fixed_group)) {
1026+
PRINT_INPUT_ERROR("Fixed group ID should be an integer.");
1027+
}
1028+
}
1029+
10051030
if (fixed_group < 0) {
10061031
PRINT_INPUT_ERROR("Fixed group ID should >= 0.");
10071032
}
10081033

1009-
if (fixed_group >= group[0].number) {
1034+
if (fixed_group >= group[fixed_grouping_method].number) {
10101035
PRINT_INPUT_ERROR("Fixed group ID should < number of groups.");
10111036
}
10121037

1013-
printf("Group %d in grouping method 0 will be fixed.\n", fixed_group);
1038+
printf(
1039+
"Group %d in grouping method %d will be fixed.\n", fixed_group, fixed_grouping_method);
10141040
}
10151041

10161042
void Integrate::parse_move(const char** param, int num_param, std::vector<Group>& group)
10171043
{
1018-
if (num_param != 5) {
1019-
PRINT_INPUT_ERROR("Keyword 'move' should have 4 parameters.");
1020-
}
1021-
1022-
if (!is_valid_int(param[1], &move_group)) {
1023-
PRINT_INPUT_ERROR("Moving group ID should be an integer.");
1044+
if (num_param != 5 && num_param != 6) {
1045+
PRINT_INPUT_ERROR("Keyword 'move' should have 4 or 5 parameters.");
10241046
}
10251047

10261048
if (group.size() < 1) {
10271049
PRINT_INPUT_ERROR("Cannot use 'move' without grouping method.");
10281050
}
10291051

1052+
int vid; // index where vx starts
1053+
if (num_param == 6) {
1054+
// move grouping_method group_id vx vy vz
1055+
if (!is_valid_int(param[1], &move_grouping_method)) {
1056+
PRINT_INPUT_ERROR("Grouping method for 'move' should be an integer.");
1057+
}
1058+
if (move_grouping_method < 0) {
1059+
PRINT_INPUT_ERROR("Grouping method for 'move' should >= 0.");
1060+
}
1061+
if (move_grouping_method >= group.size()) {
1062+
PRINT_INPUT_ERROR("Grouping method for 'move' should < number of grouping methods.");
1063+
}
1064+
if (!is_valid_int(param[2], &move_group)) {
1065+
PRINT_INPUT_ERROR("Moving group ID should be an integer.");
1066+
}
1067+
vid = 3;
1068+
} else {
1069+
// move group_id vx vy vz (default grouping_method = 0)
1070+
move_grouping_method = 0;
1071+
if (!is_valid_int(param[1], &move_group)) {
1072+
PRINT_INPUT_ERROR("Moving group ID should be an integer.");
1073+
}
1074+
vid = 2;
1075+
}
1076+
10301077
if (move_group < 0) {
10311078
PRINT_INPUT_ERROR("Moving group ID should >= 0.");
10321079
}
10331080

1034-
if (move_group >= group[0].number) {
1081+
if (move_group >= group[move_grouping_method].number) {
10351082
PRINT_INPUT_ERROR("Moving group ID should < number of groups.");
10361083
}
10371084

1038-
if (!is_valid_real(param[2], &move_velocity[0])) {
1085+
if (!is_valid_real(param[vid], &move_velocity[0])) {
10391086
PRINT_INPUT_ERROR("Moving velocity in x direction should be a number.");
10401087
}
1041-
if (!is_valid_real(param[3], &move_velocity[1])) {
1088+
if (!is_valid_real(param[vid + 1], &move_velocity[1])) {
10421089
PRINT_INPUT_ERROR("Moving velocity in y direction should be a number.");
10431090
}
1044-
if (!is_valid_real(param[4], &move_velocity[2])) {
1091+
if (!is_valid_real(param[vid + 2], &move_velocity[2])) {
10451092
PRINT_INPUT_ERROR("Moving velocity in z direction should be a number.");
10461093
}
10471094

10481095
printf(
1049-
"Group %d in grouping method 0 will move with velocity vector (%g, %g, %g) A/fs.\n",
1096+
"Group %d in grouping method %d will move with velocity vector (%g, %g, %g) A/fs.\n",
10501097
move_group,
1098+
move_grouping_method,
10511099
move_velocity[0],
10521100
move_velocity[1],
10531101
move_velocity[2]);

src/integrate/integrate.cuh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ public:
7474
int sink;
7575
int fixed_group = -1; // ID of the group in which the atoms will be fixed
7676
int move_group = -1; // ID of the group in which the atoms will move with a constant velocity
77+
int fixed_grouping_method = 0;
78+
int move_grouping_method = 0;
7779
double move_velocity[3];
7880

7981
double temperature; // target temperature at a specific time

src/main_gpumd/cohesive.cu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ void Cohesive::compute(
359359
Box new_box;
360360
deform_box(num_atoms, cpu_D[n], box, new_box, position_per_atom, old_box_inv);
361361

362-
Minimizer_SD minimizer(-1, num_atoms, 1000, 1.0e-5);
362+
Minimizer_SD minimizer(-1, 0, num_atoms, 1000, 1.0e-5);
363363
minimizer.compute(
364364
force,
365365
new_box,

src/main_gpumd/run.cu

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ void Run::parse_one_keyword(std::vector<std::string>& tokens)
370370
param,
371371
num_param,
372372
integrate.fixed_group,
373+
integrate.fixed_grouping_method,
373374
force,
374375
box,
375376
atom.position_per_atom,

src/main_mdi/run.cu

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,7 @@ void Run::parse_one_keyword(std::vector<std::string>& tokens)
575575
param,
576576
num_param,
577577
integrate.fixed_group,
578+
integrate.fixed_grouping_method,
578579
force,
579580
box,
580581
atom.position_per_atom,

0 commit comments

Comments
 (0)