Skip to content

Commit 5f19b7a

Browse files
authored
Merge pull request brucefan1983#1400 from luowh35/compute-chunk
Compute chunk
2 parents 17dca37 + 600d9bd commit 5f19b7a

5 files changed

Lines changed: 898 additions & 0 deletions

File tree

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
.. _kw_compute_chunk:
2+
.. index::
3+
single: compute_chunk (keyword in run.in)
4+
5+
:attr:`compute_chunk`
6+
=====================
7+
8+
This keyword computes space- and time-averaged per-chunk quantities based on dynamic spatial binning.
9+
Unlike the :ref:`compute keyword <kw_compute>`, which uses static group assignments defined in the model file, :attr:`compute_chunk` assigns atoms to spatial bins (chunks) based on their real-time coordinates at each sampling step.
10+
This is particularly useful for systems where atoms diffuse across spatial regions during the simulation, such as low-density, porous, or amorphous materials in NEMD simulations.
11+
12+
The results are written to the ``compute_chunk.out`` output file.
13+
14+
15+
Syntax
16+
------
17+
18+
For 1D binning::
19+
20+
compute_chunk <sample_interval> <output_interval> bin/1d <dim> <origin> <delta> {<quantity>}
21+
22+
For 2D binning::
23+
24+
compute_chunk <sample_interval> <output_interval> bin/2d <dim1> <origin1> <delta1> <dim2> <origin2> <delta2> {<quantity>}
25+
26+
For 3D binning::
27+
28+
compute_chunk <sample_interval> <output_interval> bin/3d <dim1> <origin1> <delta1> <dim2> <origin2> <delta2> <dim3> <origin3> <delta3> {<quantity>}
29+
30+
The parameters are defined as follows:
31+
32+
* :attr:`sample_interval`: Sampling interval in time steps. The quantities are sampled every this many steps.
33+
34+
* :attr:`output_interval`: Number of samples to average before producing one output. This is consistent with the :ref:`compute keyword <kw_compute>`: one output is produced every :math:`\text{sample\_interval} \times \text{output\_interval}` time steps.
35+
36+
* :attr:`bin/1d`, :attr:`bin/2d`, :attr:`bin/3d`: The binning style, specifying 1D, 2D, or 3D spatial binning respectively.
37+
38+
* :attr:`dim` (or :attr:`dim1`, :attr:`dim2`, :attr:`dim3`): The axis along which to bin. Must be :attr:`x`, :attr:`y`, or :attr:`z`. For :attr:`bin/2d` and :attr:`bin/3d`, the specified axes must be distinct.
39+
40+
* :attr:`origin` (or :attr:`origin1`, :attr:`origin2`, :attr:`origin3`): The bin origin. Currently only :attr:`lower` is supported, meaning bins start from the lower boundary of the simulation box (coordinate 0).
41+
42+
* :attr:`delta` (or :attr:`delta1`, :attr:`delta2`, :attr:`delta3`): The bin width in Ångströms. The number of bins along each axis is automatically calculated as :math:`\lceil L / \delta \rceil`, where :math:`L` is the box length along that axis. The last bin may be narrower than :math:`\delta` if :math:`L` is not an integer multiple of :math:`\delta`; its volume and center coordinate are computed using the actual width.
43+
44+
Starting after the binning parameters, one can list the quantities to be computed.
45+
The allowed names for :attr:`quantity` are:
46+
47+
* :attr:`temperature`, which yields the temperature of each chunk
48+
* :attr:`density/number`, which yields the number density (atoms per volume) of each chunk
49+
* :attr:`density/mass`, which yields the mass density of each chunk
50+
* :attr:`vx`, which yields the average velocity in the x direction
51+
* :attr:`vy`, which yields the average velocity in the y direction
52+
* :attr:`vz`, which yields the average velocity in the z direction
53+
* :attr:`fx`, which yields the average force in the x direction
54+
* :attr:`fy`, which yields the average force in the y direction
55+
* :attr:`fz`, which yields the average force in the z direction
56+
57+
One can write one or more (distinct) names in any order.
58+
59+
For triclinic (non-orthogonal) simulation boxes, the box length along each axis is computed as the geometric thickness :math:`L = V / A`, where :math:`V` is the box volume and :math:`A` is the cross-sectional area perpendicular to that axis. This is consistent with GPUMD's internal geometry calculations.
60+
61+
62+
Example
63+
-------
64+
65+
Example 1: 1D temperature profile along z
66+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
67+
::
68+
69+
compute_chunk 10 100 bin/1d z lower 1.0 temperature
70+
71+
This means:
72+
73+
* sample the temperature every 10 time steps
74+
* average over 100 samples before writing output (one output every :math:`10 \times 100 = 1000` steps)
75+
* bin atoms along the z axis with 1.0 Å bin width, starting from the lower boundary
76+
* compute the temperature of each bin
77+
78+
Example 2: 1D temperature and density profile
79+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
80+
::
81+
82+
compute_chunk 10 100 bin/1d z lower 1.0 temperature density/number
83+
84+
Same as above, but also computes the number density of each bin.
85+
86+
Example 3: 2D velocity field
87+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
88+
::
89+
90+
compute_chunk 10 100 bin/2d x lower 2.0 z lower 2.0 vx vz
91+
92+
This creates a 2D grid of bins in the x-z plane with 2.0 Å bin width in each direction, and computes the average x and z velocity components in each bin.
93+
94+
Example 4: NEMD temperature profile
95+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
96+
A typical use case for NEMD simulations::
97+
98+
ensemble heat_lan 300 300 50 0 1
99+
compute_chunk 10 100 bin/1d z lower 1.0 temperature density/number
100+
run 1000000
101+
102+
This computes the temperature and density profiles along z during a Langevin heat bath NEMD simulation.
103+
104+
105+
Output file
106+
-----------
107+
108+
The results are written to ``compute_chunk.out``.
109+
The file is appended to if it already exists.
110+
For each output time, there are :math:`N_\text{chunk}` consecutive lines (one per chunk), with the following format per line::
111+
112+
<chunk_id> <coord1> [<coord2>] [<coord3>] <avg_count> <value1> [<value2>] ...
113+
114+
The columns are:
115+
116+
* :attr:`chunk_id`: the zero-based index of the chunk (dimensionless integer).
117+
* :attr:`coord1` (and :attr:`coord2`, :attr:`coord3` for 2D/3D binning): the center coordinates (in units of Å) of the chunk along the corresponding binning axis.
118+
* :attr:`avg_count`: the time-averaged number of atoms in the chunk (dimensionless).
119+
* :attr:`value1`, :attr:`value2`, ...: the time-averaged values of the requested quantities, in the same order as specified in the command. The units for each quantity are:
120+
121+
- :attr:`temperature`: K
122+
- :attr:`density/number`: Å\ :sup:`-3` (number of atoms per volume)
123+
- :attr:`density/mass`: amu/Å\ :sup:`3` (total atomic mass per volume)
124+
- :attr:`vx`, :attr:`vy`, :attr:`vz`: Å/fs
125+
- :attr:`fx`, :attr:`fy`, :attr:`fz`: eV/Å
126+
127+
The temperature is computed from the kinetic energy of the atoms in each chunk as :math:`T = 2 E_\text{k} / (3 k_\text{B} N)`, where :math:`E_\text{k}` is the total kinetic energy, :math:`N` is the atom count, and :math:`k_\text{B}` is the Boltzmann constant.
128+
The velocity and force values are per-atom averages within each chunk.
129+
130+
For example, the command::
131+
132+
compute_chunk 10 100 bin/1d z lower 2.0 temperature density/number
133+
134+
produces output lines of the form::
135+
136+
0 1.000000 52.0 3.0012345678e+02 2.5000000000e-02
137+
1 3.000000 48.0 2.9876543210e+02 2.4000000000e-02
138+
...
139+
140+
Here, each line contains: chunk index, bin center along z (Å), average atom count, temperature (K), and number density (Å\ :sup:`-3`).
141+
The output blocks for successive time points are written consecutively with no blank line separator; each block contains exactly :math:`N_\text{chunk}` lines.
142+
143+
144+
Caveats
145+
-------
146+
147+
* The :attr:`origin` parameter currently only accepts :attr:`lower`. Numeric origin values are not supported.
148+
* This keyword addresses the measurement/analysis side of dynamic spatial binning. The NEMD heat baths (:attr:`ensemble heat_*` source/sink regions) still use static group assignments. Dynamic heat bath regions would require separate modifications to the integrator.
149+
* Multiple :attr:`compute_chunk` commands can be used in the same run.

doc/gpumd/input_parameters/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ Below you can find a listing of keywords for the ``run.in`` input file.
5050
minimize
5151
run
5252
compute
53+
compute_chunk
5354
compute_adf
5455
compute_cohesive
5556
compute_dos

src/main_gpumd/run.cu

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Run simulation according to the inputs in the run.in file.
3030
#include "measure/adf.cuh"
3131
#include "measure/angular_rdf.cuh"
3232
#include "measure/compute.cuh"
33+
#include "measure/compute_chunk.cuh"
3334
#include "measure/compute_dpdt.cuh"
3435
#include "measure/dos.cuh"
3536
#include "measure/dump_beads.cuh"
@@ -563,6 +564,10 @@ void Run::parse_one_keyword(std::vector<std::string>& tokens)
563564
measure.properties.emplace_back(std::move(property));
564565
} else if (strcmp(param[0], "deform") == 0) {
565566
integrate.parse_deform(param, num_param);
567+
} else if (strcmp(param[0], "compute_chunk") == 0) {
568+
std::unique_ptr<Property> property;
569+
property.reset(new ComputeChunk(param, num_param, box));
570+
measure.properties.emplace_back(std::move(property));
566571
} else if (strcmp(param[0], "compute") == 0) {
567572
std::unique_ptr<Property> property;
568573
property.reset(new Compute(param, num_param, group));

0 commit comments

Comments
 (0)