Skip to content

Commit

Permalink
Add analysis script for testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
cemitch99 committed Oct 12, 2024
1 parent 3323f51 commit 110e07b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 15 deletions.
16 changes: 16 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -992,3 +992,19 @@ add_impactx_test(coupled-optics.py
examples/coupled_optics/analysis_coupled_optics.py
OFF # no plot script yet
)

# Aperture with Periodic Masking #########################################################
#
# w/o space charge
add_impactx_test(aperture-pepperpot
examples/aperture/input_aperture_pepperpot.in
ON # ImpactX MPI-parallel
examples/aperture/analysis_aperture_pepperpot.py
OFF # no plot script yet
)
add_impactx_test(aperture-pepperpot.py
examples/aperture/run_aperture_pepperpot.py
OFF # ImpactX MPI-parallel
examples/aperture/analysis_aperture_pepperpot.py
OFF # no plot script yet
)
42 changes: 27 additions & 15 deletions examples/aperture/analysis_aperture_pepperpot.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import openpmd_api as io
from scipy.stats import moment


def get_moments(beam):
"""Calculate standard deviations of beam position & momenta
and emittance values
Expand Down Expand Up @@ -80,28 +79,41 @@ def get_moments(beam):
repeat_x = 1.0e-3
repeat_y = 1.0e-3

# kept particles, shifted to the primary
dx = abs(final["position_x"]) - xmax
dy = abs(final["position_y"]) - ymax

# kept particles, shifted to the fundamental domain
xshifted = abs(final["position_x"]) + xmax
yshifted = abs(final["position_y"]) + ymax
u = np.fmod(xshifted,repeat_x) - xmax
v = np.fmod(yshifted,repeat_y) - ymax

# difference from maximum aperture
dx = abs(u) - xmax
dy = abs(v) - ymax

print()
print(f" x_max={final['position_x'].max()}")
print(f" x_min={final['position_x'].min()}")
print(f" fundamental x_max={u.max()}")
print(f" fundamental x_min={u.min()}")
assert np.less_equal(dx.max(), 0.0)

print(f" y_max={final['position_y'].max()}")
print(f" y_min={final['position_y'].min()}")
print(f" fundamental y_max={v.max()}")
print(f" fundamental y_min={v.min()}")
assert np.less_equal(dy.max(), 0.0)

# lost particles
dx = abs(particles_lost["position_x"]) - xmax
dy = abs(particles_lost["position_y"]) - ymax
# lost particles, shifted to the fundamental domain
xshifted = abs(particles_lost["position_x"]) - xmax
yshifted = abs(particles_lost["position_y"]) - ymax
u = np.fmod(xshifted,repeat_x) - xmax
v = np.fmod(yshifted,repeat_y) - ymax

# difference from maximum aperture
dx = abs(u) - xmax
dy = abs(v) - ymax

print()
print(f" x_max={particles_lost['position_x'].max()}")
print(f" x_min={particles_lost['position_x'].min()}")
print(f" fundamental x_max={u.max()}")
print(f" fundamental x_min={u.min()}")
assert np.greater_equal(dx.max(), 0.0)

print(f" y_max={particles_lost['position_y'].max()}")
print(f" y_min={particles_lost['position_y'].min()}")
print(f" fundamental y_max={v.max()}")
print(f" fundamental y_min={v.min()}")
assert np.greater_equal(dy.max(), 0.0)

0 comments on commit 110e07b

Please sign in to comment.