Skip to content

Commit 0d69273

Browse files
committed
update for 1.3.0
1 parent 7f7fe50 commit 0d69273

File tree

19 files changed

+132
-116
lines changed

19 files changed

+132
-116
lines changed
-547 KB
Binary file not shown.

docs/content/2-code/6-problem_generators.md renamed to docs/content/2-howto/1-problem_generators.md

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ Fields must be returned in the local tetrad (orthonormal) basis, while the passe
154154
155155
Similar to initializing the fields, one can also initialize particles with a given energy or spatial distribution. This is done by providing a custom method of the `PGen` class called `InitPrtls(Domain<S, M>&)` which takes a reference to the local subdomain as a parameter. In principle, one can manually initialize the particles in any way they want, but it is recommended to use the built-in routines from the `arch::` (archetypes) namespace.
156156
157-
For instance, to initialize a uniform Maxwellian of a given temperature, one can use the `arch::Maxwellian` and `arch::UniformInjector` classes together with the `InjectUniform` method:
157+
For instance, to initialize a uniform Maxwellian of a given temperature, one can use the `arch::Maxwellian` class together with the `InjectUniform` method:
158158
159159
```c++
160160
// don't forget to include the proper headers
@@ -171,14 +171,15 @@ struct PGen : public arch::ProblemGenerator<S, M> {
171171
local_domain.mesh.metric,
172172
local_domain.random_pool,
173173
temperature);
174-
const auto injector = arch::UniformInjector<S, M, arch::Maxwellian>(
175-
energy_dist, { 1, 2 });
176-
// ^^^^^
177-
// species to inject
178-
arch::InjectUniform<S, M, arch::UniformInjector<S, M, arch::Maxwellian>>(
174+
arch::InjectUniform<S, M, decltype(energy_dist), decltype(energy_dist)>(
179175
params,
180176
local_domain,
181-
injector,
177+
{ 1, 2 },
178+
// ^^^^^
179+
// species to inject
180+
{ energy_dist, energy_dist },
181+
// ^^^^^ ^^^^^
182+
// energy distributions for each species
182183
1.0); // <-- this is the number density in units of `n0`
183184
}
184185
};
@@ -266,17 +267,15 @@ struct PGen : public arch::ProblemGenerator<S, M> {
266267
x1c,
267268
x2c,
268269
dr);
269-
const auto injector =
270-
arch::NonUniformInjector<S, M, CounterstreamEnergyDist, GaussianDist>(
271-
energy_dist,
272-
spatial_dist,
273-
{ 1, 2 });
274270

275-
arch::InjectNonUniform<S, M, arch::NonUniformInjector<S, M, CounterstreamEnergyDist, GaussianDist>>(
271+
arch::InjectNonUniform<S, M, decltype(energy_dist), decltype(energy_dist), decltype(spatial_dist)>(
276272
params,
277273
domain,
278-
injector,
279-
1.0); // <-- injected density in units of `n0` (2)!
274+
{ 1, 2 },
275+
{ energy_dist, energy_dist },
276+
spatial_dist,
277+
1.0); // <-- injected density in units of `n0`
278+
// (2)!
280279
}
281280

282281
};
@@ -558,7 +557,7 @@ struct PGen : public arch::ProblemGenerator<S, M> {
558557
};
559558
```
560559

561-
Or you may also manually access the fields and particles through the `domain.fields` and `domain.species[...]` objects, respectively, and perform any operations you need. Be mindful, however, that all the raw quantities stored within the `domain` object are in the code units (for more details, see the [fields and particles](./4-fields_particles.md) section; for ways to convert from one system/basis to another, see the [metric](./5-metrics.md) section).
560+
Or you may also manually access the fields and particles through the `domain.fields` and `domain.species[...]` objects, respectively, and perform any operations you need. Be mindful, however, that all the raw quantities stored within the `domain` object are in the code units (for more details, see the [fields and particles](../3-code/4-fields_particles.md) section; for ways to convert from one system/basis to another, see the [metric](../3-code/5-metrics.md) section).
562561

563562
## Particle purging
564563

docs/content/1-getting-started/5-vis.md renamed to docs/content/2-howto/2-vis.md

Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@ The output is configured using the following configurations in the `input` file:
1313
[simulation]
1414
name = "MySimulation" # (5)!
1515

16+
# ...
17+
[[particles.species]]
18+
tracking = true # (16)!
19+
1620
# ...
1721
[output]
18-
format = "hdf5" # (2)!
22+
format = "BPFile" # (2)!
1923
interval = 100 # (3)!
2024
interval_time = 0.1 # (8)!
2125
separate_files = true # (15)!
@@ -43,7 +47,7 @@ The output is configured using the following configurations in the `input` file:
4347
```
4448

4549
1. fields to write
46-
2. output format (current supported: "HDF5", or "disabled" for no output)
50+
2. output format (current supported: "BPFile"/"HDF5", or "disabled" for no output)
4751
3. output interval (in the number of time steps)
4852
4. smoothing stencil size for moments (in the number of cells) [defaults to 1]
4953
5. title is used for the output filename
@@ -57,8 +61,7 @@ The output is configured using the following configurations in the `input` file:
5761
13. whether to use logarithmic energy bins or linear
5862
14. box reduced quantities to output as stats
5963
15. whether to write in a single file or into separate files
60-
61-
Output is written in the run directory either in a single `hdf5` file, `MySimulation.h5`, or in the directory with the same name `MySimulation`.
64+
16. enable tracking for a given particle species
6265

6366
Following is the list of all supported fields
6467

@@ -87,6 +90,10 @@ and particle quantities
8790
| `X` | Coordinates (all components) | physical |
8891
| `U` | Four-velocities (all components) | dimensionless |
8992
| `W` | Weights | dimensionless |
93+
| `PLDR` &nbsp;<a href="https://github.com/entity-toolkit/entity/pull/144"> <span class="since-version">1.3.0</span> </a> | Real-valued payloads | arbitrary |
94+
| `PLDI` &nbsp;<a href="https://github.com/entity-toolkit/entity/pull/144"> <span class="since-version">1.3.0</span> </a> | Integer-valued payloads | arbitrary |
95+
| `RNK` &nbsp;<a href="https://github.com/entity-toolkit/entity/pull/144"> <span class="since-version">1.3.0</span> </a> | Meshblock rank the particle was created (if MPI is ON) | -- |
96+
| `IDX` &nbsp;<a href="https://github.com/entity-toolkit/entity/pull/144"> <span class="since-version">1.3.0</span> </a> | Index of the particle on the given rank | -- |
9097

9198
<a href="https://github.com/entity-toolkit/entity/pull/69"> <span class="since-version">1.2.0</span> </a> The code also has an output of box-averaged stats into a `.csv` file, which are simply scalars per each output timestep. The following quantities can be computed
9299

@@ -110,11 +117,11 @@ and particle quantities
110117

111118
All of the vector fields are interpolated to cell centers before the output, and converted to orthonormal basis. The particle-based moments are smoothed with a stencil (specified in the input file; `mom_smooth`) for each particle.
112119

113-
In addition, one can write custom user-defined field quantities to the output with the fields or stats. Refer to [the following section](../2-code/6-problem_generators.md#custom-field-output) for more details.
120+
In addition, one can write custom user-defined field quantities to the output with the fields or stats. Refer to [the following section](../2-howto/1-problem_generators.md#custom-field-output) for more details.
114121

115-
!!! warning "Can one track particles at different times?"
122+
!!! success "Can one track particles at different times?"
116123

117-
Particle tracking (outputting the same batch of particles at every timestep) is unfortunately not yet implemented, and will unlikely be available due to limitations imposed by the nature of GPU computations.
124+
Yes! Simply enable particle tracking for a particular species. Then each particle is uniquely identified by a combination of `IDX` and `RNK` (if no MPI is used, then only `IDX` is sufficient). `nt2py` already automatically combines the variables producing a unique `id` for each particle (for the species where tracking is enabled). However, keep in mind, that the simulations are not reproducible and will unfortunately never be due to limitations imposed by the nature of GPU computations.
118125

119126
## [`nt2py`](https://pypi.org/project/nt2py/)
120127

@@ -220,31 +227,32 @@ Particles and spectra can, in turn, be accessed via `data.particles[s]`, where `
220227

221228
### Accessing particles
222229

223-
Particles are stored in the same `data` object and are lazily preloaded when one calls `nt2.Data(...)`, as we did above. To access the particle data, use `data.particles`, which returns a python dictionary where the key is particles species index, and the value is an `xarray` Dataset with the particle data. For example, to access the `x` and `y` coordinates of the first species, one can do:
230+
Particles are stored in the same `data` object and are lazily preloaded when one calls `nt2.Data(...)`, as we did above. To access the particle data, use `data.particles`, which returns a custom object which can then be converted into an explicitly populated dataframe using the `load()` method. Selection of particles can be done in a similar way to the fields:
224231

225232
```python
226-
data.particles[1].x
227-
data.particles[1].y
233+
data.particles.sel(t=slice(None, 10)).sel(sp=[1, 3], id=[123, 456, 789]).load()
228234
```
229235

230-
The shape of the returned dataset is number of particles times the number of time steps. To select the data at a specific time step, one can use the same `sel` or `isel` methods mentioned above. For example, to access the 10-th output timestep of the 3-rd species, one can do:
236+
which selects all times before $t<10$, selects species 1 and 3, and picks specific particle id-s (traced along all preselected times). There are two built-in plotting methods: `.spectrum_plot`, and `.phase_plot`, for plotting a 1D energy distribution function of each species, and a 2D phase-space plot (or any 2D binned plot).
231237

232238
```python
233-
data.particles[3].isel(t=10).x
239+
data.particles.sel(t=10, method="nearest").spectrum_plot(
240+
bins=np.logspace(0, 3),
241+
quantity=lambda df: np.sqrt(1 + df.ux**2 + df.uy**2 + df.uz**2),
242+
)
243+
244+
data.particles.sel(t=10, method="nearest").phase_plot(
245+
x_quantity=lambda df: df.x,
246+
y_quantity=lambda df: df.ux,
247+
xy_bins=(np.linspace(-1, 1), np.linspace(0, 2)),
248+
)
234249
```
235250

236-
Scatter plotting the particles on a 2D plane is quite easy, since `xarray` has a built-in `plot.scatter` method:
251+
You may, however, simply use the data from the dataframe to make the plots directly:
237252

238253
```python
239-
species_3 = data.particles[3]
240-
species_4 = data.particles[4]
241-
242-
species_3.isel(t=-1)\
243-
.plot.scatter(x="x", y="y",
244-
label=species_3.attrs["label"])
245-
species_4.isel(t=-1)\
246-
.plot.scatter(x="x", y="y",
247-
label=species_4.attrs["label"])
254+
df = data.particles.sel(t=10, method="nearest").load()
255+
plt.scatter(df.x, df.y, colors=df.sp) # color by species
248256
```
249257

250258
??? showplot "scatter plot $\{x,~y\}$"
@@ -255,22 +263,6 @@ species_4.isel(t=-1)\
255263

256264
`isel(t=-1)` selects the last time step.
257265

258-
Or one can plot the same in phase space:
259-
260-
```python
261-
species_3.isel(t=-1)\
262-
.plot.scatter(x="ux", y="uy",
263-
label=species_3.attrs["label"])
264-
species_4.isel(t=-1)\
265-
.plot.scatter(x="ux", y="uy",
266-
label=species_4.attrs["label"])
267-
```
268-
269-
??? showplot "scatter plot $\{u_x,~u_y\}$"
270-
271-
![nt2demo4](../../assets/images/howto/nt2-demo-4.png)
272-
273-
274266
### Accessing runtime spectra
275267

276268
Distribution functions for all particle species in the box are also written with the data at specified timesteps. These can be accessed via `data.spectra`, which has several different fields. As in particles & fields, you can access the data at different times using `data.spectra.isel(t=...)` or `data.spectra.sel(t=...)`. The energy bins are written into `data.spectra.e`; by default, the binning is done logarithmically in $\gamma - 1$ for massive particles and energy, $E$, for the photons. Below is an example script to build a distribution function of electron-positron pairs at output step `t=450`:
@@ -307,9 +299,9 @@ def plot_frame(ti, data):
307299
# e.g.
308300
fig = plt.figure()
309301
ax = fig.add_subplot(111)
310-
(data.N_1 + data.N_2).isel(t=ti).plot(ax=ax, cmap="viridis")
311-
# ^
312-
# selecting timestep by index
302+
(data.fields.N_1 + data.fields.N_2).isel(t=ti).plot(ax=ax, cmap="viridis")
303+
# ^
304+
# selecting timestep by index
313305

314306
# then simply pass this function to the routine:
315307
data.makeMovie(plot_frame, num_cpus=8, framerate="10", ...)
File renamed without changes.

docs/content/1-getting-started/6-checkpoints.md renamed to docs/content/2-howto/4-checkpoints.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Oftentimes, large simulations cannot be run on a single go. For these cases, Ent
1313

1414
## Writing checkpoints
1515

16-
Since the checkpoint writing relies on the `ADIOS2` library, to be able to use checkpointing, the code has to be compiled with the `-D output=ON` flag (enabled by default). Configurations for the checkpoint writing are done via the `.toml` input file under the block named `[checkpoint]` (also see the [input file documentation](3-inputfile.md)). The following parameters control how often the checkpoint is written, as well as how many snapshots are preserved as the simulation runs.
16+
Since the checkpoint writing relies on the `ADIOS2` library, to be able to use checkpointing, the code has to be compiled with the `-D output=ON` flag (enabled by default). Configurations for the checkpoint writing are done via the `.toml` input file under the block named `[checkpoint]` (also see the [input file documentation](../1-getting-started/3-inputfile.md)). The following parameters control how often the checkpoint is written, as well as how many snapshots are preserved as the simulation runs.
1717

1818
| parameter | description | default |
1919
| ---- | ---- | ---- |
File renamed without changes.
File renamed without changes.

docs/content/1-getting-started/9-faq.md renamed to docs/content/2-howto/7-faq.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ hide:
1313

1414
!!! faq "I want to have a custom boundary/injection/driving/distribution function/output."
1515

16-
All of that *can* be done via the tools provided by the problem generator. Please inspect carefully the [section dedicated to that](../2-code/6-problem_generators.md). Also have a look at the set of officially supported problem generators some of which might implement a variation of what your original intent is.
16+
All of that *can* be done via the tools provided by the problem generator. Please inspect carefully the [section dedicated to that](../2-howto/1-problem_generators.md). Also have a look at the set of officially supported problem generators some of which might implement a variation of what your original intent is.
1717

1818
## Technical
1919

@@ -29,7 +29,7 @@ hide:
2929

3030
- CUDA @ NVIDIA GPUs: make sure you have a version of `gcc` which is supported by the version of CUDA you are using; check out [this unofficial compatibility matrix](https://gist.github.com/ax3l/9489132#nvcc). In particular, Intel compilers are not very compatible with CUDA, and it is recommended to use `gcc` instead (you won't gain much by using Intel anyway, since CUDA will be doing the heavy-lifting).
3131

32-
- HIP/ROCm @ AMD GPUs: ROCm library is a headache. The documentation is even more so. We have a [dedicated section](./1-compile-run.md#hiprocm-amd-gpus) specifically discussing compilation with HIP. Make sure to check it before opening an issue.
32+
- HIP/ROCm @ AMD GPUs: ROCm library is a headache. The documentation is even more so. We have a [dedicated section](../1-getting-started/1-compile-run.md#hiprocm-amd-gpus) specifically discussing compilation with HIP. Make sure to check it before opening an issue.
3333

3434

3535
!!! faq "If the code gives an error, how do I know whether the problem is with the Entity itself or with the other libraries it depends on (e.g., `Kokkos`, `ADIOS2`, `MPI`)?"
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)