Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ IncludeCategories:
Priority: 4
- Regex: '^"checkpoint\/.*\.h"'
Priority: 4
- Regex: '^"kernels\/.*\.hpp"'
Priority: 4
- Regex: '^"kernels\/.*\.h"'
Priority: 4
- Regex: '^"output\/.*\.h"'
Priority: 4
- Regex: '^"archetypes\/.*\.h"'
Expand Down
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.mp4 filter=lfs diff=lfs merge=lfs -text
8 changes: 5 additions & 3 deletions .github/workflows/cpuarch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ jobs:
cmake --version
- name: Install OpenMPI 5
run: |
sudo apt-get install -y libopenmpi-dev openmpi-bin
mpirun --version
if [ "${{ matrix.mpi }}" = "ON" ]; then
sudo apt-get install -y libopenmpi-dev openmpi-bin
mpirun --version
fi
- name: Configure
run: |
if [ "${{ matrix.mpi }}" = "ON" ]; then
Expand All @@ -87,7 +89,7 @@ jobs:
strategy:
fail-fast: false
matrix:
pgen: [streaming, turbulence, reconnection, shock, magnetosphere, accretion, wald]
pgen: [streaming, turbulence, reconnection, shock, magnetosphere, accretion, wald, examples/custom_emission]
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ venv/
*.mov
*.mp4
!pgens/**/*.png
!pgens/**/*.mp4

# Accidental files
*.xc
Expand Down
7 changes: 7 additions & 0 deletions pgens/examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Examples

Problem generations in this directory are just examples demonstrating how to use some of the features of the Entity.

- `custom_emission`: simple example where two particles are initialized on gyrating trajectories probabilistically emitting photons while the total energy is conserved.

https://github.com/user-attachments/assets/6c5c399a-bbab-4b93-be5f-35fed1959fcc
3 changes: 3 additions & 0 deletions pgens/examples/custom_emission/custom_emission.mp4
Git LFS file not shown
51 changes: 51 additions & 0 deletions pgens/examples/custom_emission/custom_emission.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import nt2
import matplotlib.pyplot as plt
import numpy as np

plt.rcParams["text.usetex"] = True

data = nt2.Data("custom_emission")


def plot(t, data):
fig = plt.figure(figsize=(8, 4), dpi=150)
ax1 = fig.add_subplot(121)
prtls = data.particles.sel(t=slice(t - 0.5, t)).load()
prtls.plot.scatter(
ax=ax1,
x="x",
y="y",
color=["r" if sp == 1 else "b" for sp in prtls["sp"]],
ec=None,
alpha=(1 - (t - prtls["t"]) / 0.5) ** 2,
s=(1 - (t - prtls["t"]) / 0.5) * 5,
)
ax1.set(xlabel=r"$x$", ylabel=r"$y$", xlim=(-1, 1), ylim=(-1, 1), aspect=1)

ax2 = fig.add_subplot(122)
prtls1 = data.particles.sel(sp=1, t=slice(None, t)).load()
prtls2 = data.particles.sel(sp=2, t=slice(None, t)).load()
e1 = (
prtls1.assign(
e=np.sqrt(1 + prtls1["ux"] ** 2 + prtls1["uy"] ** 2 + prtls1["uz"] ** 2)
)
.groupby("t", as_index=False)["e"]
.sum()
)
e2 = (
prtls2.assign(
e=np.sqrt(prtls2["ux"] ** 2 + prtls2["uy"] ** 2 + prtls2["uz"] ** 2)
)
.groupby("t", as_index=False)["e"]
.sum()
)
e = e1.merge(e2, on="t", how="outer", suffixes=("_1", "_2")).fillna(0)
ax2.plot(e.t, e.e_1, label="emitters", c="r")
ax2.plot(e.t, e.e_2, label="emitted", c="b")
ax2.plot(e.t, e.e_1 + e.e_2, label="total", c="k")
ax2.set(xlabel=r"$t$", ylabel=r"total energy", xlim=(0, 5), ylim=(0, 3))
ax2.axvline(t, color="gray", ls="--")
ax2.legend(loc="center left")


data.makeMovie(plot, framerate=30)
68 changes: 68 additions & 0 deletions pgens/examples/custom_emission/custom_emission.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
[simulation]
name = "custom_emission"
engine = "srpic"
runtime = 5.0

[grid]
resolution = [64, 64]
extent = [[-1.0, 1.0], [-1.0, 1.0]]

[grid.metric]
metric = "minkowski"

[grid.boundaries]
fields = [["PERIODIC"], ["PERIODIC"]]
particles = [["PERIODIC"], ["PERIODIC"]]

[scales]
larmor0 = 0.25
skindepth0 = 1.0

[algorithms]

[algorithms.deposit]
enable = false

[algorithms.timestep]
CFL = 0.5

[particles]
ppc0 = 1.0

[[particles.species]]
label = "p"
mass = 1.0
charge = 1.0
maxnpart = 1e2
emission = "custom"

[[particles.species]]
label = "ph"
mass = 0.0
charge = 0.0
maxnpart = 1e4

[setup]
x1_arr = [0.0, 0.0]
x2_arr = [0.0, 0.0]
x3_arr = [0.0, 0.0]
ux1_arr = [0.0, 0.0]
ux2_arr = [1.0, -1.0]
ux3_arr = [0.0, 0.0]
emission_probability = 0.05

[output]
interval = 1

[output.fields]
quantities = ["N_1", "N_2", "B"]

[output.particles]
enable = true
stride = 1

[output.spectra]
enable = false

[checkpoint]
keep = 0
Loading
Loading