Skip to content

Commit b9a78a3

Browse files
atmyersax3l
andauthored
Update particle docs for expanded idcpu range (#4758)
I am making a series of PRs that update the particle documentation. This first one explains the current convention re: particle id and cpu numbers. The proposed changes: - [ ] fix a bug or incorrect behavior in AMReX - [ ] add new capabilities to AMReX - [ ] changes answers in the test suite to more than roundoff level - [ ] are likely to significantly affect the results of downstream AMReX users - [x] include documentation in the code and/or rst files, if appropriate --------- Co-authored-by: Axel Huebl <[email protected]>
1 parent b502b3b commit b9a78a3

File tree

2 files changed

+40
-28
lines changed

2 files changed

+40
-28
lines changed

Docs/sphinx_documentation/source/Particle.rst

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,41 @@ type of components that the particles carry. The first template parameter is the
2424
number of extra :cpp:`Real` variables this particle will have (either single or
2525
double precision [1]_), while the second is the number of extra integer
2626
variables. It is important to note that this is the number of *extra* real and
27-
integer variables; a particle will always have at least :cpp:`BL_SPACEDIM` real
28-
components that store the particle's position and 2 integer components that
29-
store the particle's :cpp:`id` and :cpp:`cpu` numbers. [2]_
30-
31-
The particle struct is designed to store these variables in a way that
32-
minimizes padding, which in practice means that the :cpp:`Real` components
33-
always come first, and the integer components second. Additionally, the
34-
required particle variables are stored before the optional ones, for both the
35-
real and the integer components. For example, say we want to define a particle
36-
type that stores a mass, three velocity components, and two extra integer
37-
flags. Our particle struct would be set up like:
27+
integer variables; a particle will always have at least :cpp:`AMREX_SPACEDIM` real
28+
components that store the particle's position and one 64-bit integer component that
29+
stores a combination of the particle's unique `id` and `cpu` numbers.
30+
31+
The particle struct is stored such that the :cpp:`Real` components come first
32+
and the integer component second. Additionally, the required particle variables
33+
are stored before the optional ones, for both the real and the integer components.
34+
For example, say we want to define a particle type that stores a mass, three velocity
35+
components, and two extra integer flags. Our particle struct would be declared like:
3836

3937
::
4038

4139
Particle<4, 2> p;
4240

43-
and the order of the particle components in would be (assuming :cpp:`BL_SPACEDIM` is 3):
44-
:cpp:`x y z m vx vy vz id cpu flag1 flag2`. [3]_
41+
and the order of the particle components in would be (assuming :cpp:`AMREX_SPACEDIM` is 3):
42+
:cpp:`x y z m vx vy vz idcpu flag1 flag2`. [2]_
43+
44+
The `idcpu` variable stores a combination of the MPI process a particle was generated on
45+
(the `cpu`) and an identification number that is specific to that process (the `id`).
46+
The combination of these numbers is unique across processes. This is done to facilitate
47+
the creation of particle initial conditions in parallel. In storing these
48+
identifying numbers, 39 bits are devoted to the `id`, allowing approximately 550 billion
49+
possible *local* `id` numbers, and 24 bits are used to store the `cpu`, allowing about 16.8 million
50+
unique (MPI) processes.
51+
One bit is devoted to mark a particle valid or invalid.
52+
53+
To pack and unpack these numbers, one uses the following syntax:
54+
55+
::
56+
57+
Particle <0, 0> p;
58+
p.id() = 1;
59+
p.cpu() = 0;
60+
amrex::Print() << p.m_idcpu << "\n"; // 9223372036871553024
61+
amrex::Print() << p.id() << " " << p.cpu() << "\n"; // 1 0
4562

4663
Setting Particle data
4764
---------------------
@@ -440,8 +457,7 @@ example:
440457
real(amrex_particle_real) :: pos(3)
441458
real(amrex_particle_real) :: vel(3)
442459
real(amrex_particle_real) :: acc(3)
443-
integer(c_int) :: id
444-
integer(c_int) :: cpu
460+
integer(c_int64_t) :: idcpu
445461
end type particle_t
446462

447463
is equivalent to a particle struct you get with :cpp:`Particle<6, 0>`. Here,
@@ -793,9 +809,6 @@ The following runtime parameters affect the behavior of virtual particles in Nyx
793809
Particles default to double precision for their real data. To use single precision, compile your code with ``USE_SINGLE_PRECISION_PARTICLES=TRUE``.
794810
795811
.. [2]
796-
Note that :cpp:`cpu` stores the number of the process the particle was *generated* on, not the one it's currently assigned to. This number is set on initialization and never changes, just like the particle :cpp:`id`. In essence, the particles have two integer id numbers, and only the combination of the two is unique. This was done to facilitate the creation of particle initial conditions in parallel.
797-
798-
.. [3]
799812
Note that for the extra particle components, which component refers to which
800813
variable is an application-specific convention - the particles have 4 extra real comps, but which one is "mass" is up
801814
to the user. We suggest using an :cpp:`enum` to keep these indices straight; please

Docs/sphinx_documentation/source/Particle_Chapter.rst

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
Particles
44
=========
55

6-
In addition to the tools for working with mesh data described in previous
7-
chapters, AMReX also provides data structures and iterators for performing
8-
data-parallel particle simulations. Our approach is particularly suited to
9-
particles that interact with data defined on a (possibly adaptive)
10-
block-structured hierarchy of meshes. Example applications include
11-
Particle-in-Cell (PIC) simulations, Lagrangian tracers, or particles that exert
12-
drag forces onto a fluid, such as in multi-phase flow calculations. The overall
13-
goals of AMReX's particle tools are to allow users flexibility in specifying
14-
how the particle data is laid out in memory and to handle the parallel
15-
communication of particle data. In the following sections, we
6+
In addition to the tools for working with mesh data described in previous chapters,
7+
AMReX provides data structures and iterators for performing data-parallel particle simulations.
8+
While these tool can be used to implement pure particle methods, they are particularly
9+
suited for methods in which particles interact with data defined on mesh or
10+
hierarchy of meshes. Example applications include Particle-in-Cell (PIC) simulations,
11+
Lagrangian tracers, and particles that exert drag forces onto a fluid. The overall
12+
goals of AMReX's particle tools are to allow users to express a variety of useful
13+
operations on particle data, including particle-mesh and particle-particle operations,
14+
in a performance-portable and scalable manner. In the following sections, we
1615
give an overview of AMReX's particle classes and how to use them.
1716

1817

0 commit comments

Comments
 (0)