Skip to content

Commit 6bd4210

Browse files
authored
Merge pull request brucefan1983#1409 from luowh35/expand_group_method
Expand group method
2 parents f797115 + 36e796c commit 6bd4210

21 files changed

Lines changed: 144 additions & 56 deletions

doc/gpumd/input_parameters/fix.rst

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,28 @@ This keyword can be used to fix (freeze) a group of atoms
99

1010
Syntax
1111
------
12-
This keyword requires a single parameter which is the label of the group in which the atoms are to be fixed (velocities and forces are always set to zero such that the atoms in the group do not move).
12+
This keyword accepts 1 or 2 parameters.
13+
The atoms in the specified group will be fixed (velocities and forces are always set to zero such that the atoms do not move).
1314
The full command reads::
1415

1516
fix <group_label>
17+
fix <grouping_method> <group_label>
1618

17-
Here, the :attr:`group_label` refers to the grouping method 0 defined in the :ref:`simulation model file <model_xyz>`.
19+
- If only :attr:`group_label` is given, grouping method 0 is used by default.
20+
- If :attr:`grouping_method` is also specified, the given grouping method defined in the :ref:`simulation model file <model_xyz>` will be used.
21+
22+
Example
23+
-------
24+
25+
Fix group 0 using the default grouping method 0::
26+
27+
fix 0
28+
29+
Fix group 2 using grouping method 1::
30+
31+
fix 1 2
1832

1933
Caveats
2034
-------
21-
This keyword is not propagating, which means that it only affects the simulation within the run it belongs to.
35+
* This keyword is not propagating, which means that it only affects the simulation within the run it belongs to.
36+
* When both :attr:`fix` and :ref:`move <kw_move>` are used, they must use the same grouping method.

doc/gpumd/input_parameters/move.rst

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@ This keyword is used to move part of the system with a constant velocity.
1010
Syntax
1111
------
1212

13-
The :attr:`move` keyword requires 4 parameters::
13+
The :attr:`move` keyword accepts 4 or 5 parameters::
1414

1515
move <moving_group_id> <velocity_x> <velocity_y> <velocity_z>
16+
move <grouping_method> <moving_group_id> <velocity_x> <velocity_y> <velocity_z>
1617

17-
Here, :attr:`moving_group_id` specifies the group id for the moving part, which should be defined in the grouping method 0.
18-
The next three parameters specify the moving velocity vector, in units of Ångstrom/fs.
18+
- If only :attr:`moving_group_id` and velocities are given, grouping method 0 is used by default.
19+
- If :attr:`grouping_method` is also specified, the given grouping method defined in the :ref:`simulation model file <model_xyz>` will be used.
20+
21+
The last three parameters specify the moving velocity vector, in units of Ångstrom/fs.
1922

2023

2124
Example
@@ -28,12 +31,19 @@ One can first equilibrate the system and then move one group of atoms and at the
2831
run 1000000
2932

3033
# production stage
31-
ensemble nvt_scr 300 300 100
32-
fix 0 # fix atoms in group 0
33-
move 1 0.001 0 0 # move atoms in group 1, with a speed of 0.001 Ångstrom/fs in the x direction
34+
ensemble nvt_ber 300 300 100
35+
fix 0 # fix atoms in group 0 (default grouping method 0)
36+
move 1 0.001 0 0 # move atoms in group 1, with a speed of 0.001 Ångstrom/fs in the x direction (default grouping method 0)
37+
run 1000000
38+
39+
Using a specific grouping method::
40+
41+
ensemble nvt_ber 300 300 100
42+
fix 1 0 # fix group 0 in grouping method 1
43+
move 1 1 0.001 0 0 # move group 1 in grouping method 1, with a speed of 0.001 Ångstrom/fs in the x direction
3444
run 1000000
3545

3646
Caveats
3747
-------
38-
* One cannot use NPT when using this keyword.
39-
* Currently, the moving group must be defined in the grouping method 0. This might be extended in a future version.
48+
* One cannot use NPT when using this keyword. Only ``nvt_ber``, ``nvt_nhc``, ``nvt_bdp``, and ``heat_lan`` ensembles are supported.
49+
* When both :ref:`fix <kw_fix>` and :attr:`move` are used, they must use the same grouping method.

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: 67 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ 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 (fixed_grouping_method != move_grouping_method) {
61+
PRINT_INPUT_ERROR("The fixed and moving groups must use the same grouping method.");
62+
}
6063
if (move_group == fixed_group) {
6164
PRINT_INPUT_ERROR("The fixed and moving groups cannot be the same.");
6265
}
@@ -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,

0 commit comments

Comments
 (0)