Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fnal booster input files #408

Open
wants to merge 49 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
369c897
Examples for 3D space charge benchmarking
cemitch99 Jun 7, 2022
d073bcf
Update input_kurth_10nC.in
cemitch99 Dec 5, 2022
a773807
Add MAD-X, SXF input files for Fermilab Booster.
cemitch99 Jul 31, 2023
366be57
Delete input_kurth_10nC.in
cemitch99 Jul 31, 2023
e5960d2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 31, 2023
b8b2369
Write SXF Parser
ax3l Aug 3, 2023
9d3d0e2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 3, 2023
823c4bb
Add F. Schmidt updated SXF file and new Python script.
cemitch99 Dec 21, 2023
920958e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 21, 2023
f8cf0b4
Delete examples/fnal_booster/fermi-booster-madx-sxf
cemitch99 Dec 21, 2023
2d7bffb
Fix merge.
cemitch99 Dec 21, 2023
1260f5b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 21, 2023
0534676
Delete examples/fnal_booster/main_deb_mad_6c.madx
cemitch99 Jan 18, 2024
079687a
Delete examples/fnal_booster/match_chrom.madx
cemitch99 Jan 18, 2024
89a628a
Delete examples/fnal_booster/ring_seq_bb_spch_thin.madx
cemitch99 Jan 18, 2024
c60f529
Delete examples/fnal_booster/match_tunes.madx
cemitch99 Jan 18, 2024
42f7da2
Delete examples/fnal_booster/spcharge_beam_command.madx
cemitch99 Jan 18, 2024
def0096
Update fnal_booster.py
cemitch99 Jan 18, 2024
a5107d1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 18, 2024
a9872b0
Add FNAL Booster execution test.
cemitch99 Jan 18, 2024
16e31cc
Merge branch 'development' into add_fnal_booster
cemitch99 Jan 18, 2024
66d2830
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 18, 2024
66e70f1
Update examples/fnal_booster/fnal_booster.py
cemitch99 Feb 9, 2024
07152fc
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 9, 2024
bc5a380
Update CMakeLists.txt
cemitch99 Feb 9, 2024
5f808dd
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 9, 2024
6da5b0d
Update CMakeLists.txt
cemitch99 Feb 9, 2024
d00b6e4
Update CMakeLists.txt
cemitch99 Feb 9, 2024
38278e2
Update CMakeLists.txt
cemitch99 Feb 10, 2024
cad00e3
Merge remote-tracking branch 'mainline/development' into add_fnal_boo…
ax3l Feb 10, 2024
456bac1
Fix: CMake Copy, Imports, Global Var
ax3l Feb 10, 2024
acfac82
Test: Mark as Slow
ax3l Feb 10, 2024
eae91e5
Update fnal_booster.py
cemitch99 Feb 21, 2024
e2d5589
Update fnal_booster.py
cemitch99 Feb 21, 2024
e8b4e54
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 21, 2024
0f5df30
Update fnal_booster.py
cemitch99 Feb 23, 2024
33fdb84
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 23, 2024
354f9c2
Update fnal_booster.py
cemitch99 Feb 23, 2024
d135246
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 23, 2024
6000f45
Add new SXF input file and corrected Python parsing script.
cemitch99 Jun 13, 2024
538c235
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 13, 2024
a54647d
Update CMakeLists.txt
cemitch99 Jun 13, 2024
909ca2d
Delete examples/fnal_booster/fnal_booster.py
cemitch99 Jun 13, 2024
6f0a3e8
Update CMakeLists.txt
cemitch99 Jun 13, 2024
5484bcc
Update fnal_booster_no-sc.py
cemitch99 Jun 14, 2024
64f1101
Update fnal_booster_no-sc.py
cemitch99 Jun 17, 2024
12ca7f1
Add README and analysis.
cemitch99 Jun 17, 2024
0fcfaf9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 17, 2024
8d68018
Link to documentation.
cemitch99 Jun 17, 2024
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
1 change: 1 addition & 0 deletions docs/source/usage/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ This section allows you to **download input files** that correspond to different
examples/pytorch_surrogate_model/README.rst
examples/apochromatic/README.rst
examples/fodo_tune/README.rst
examples/fnal_booster/README.rst


Unit tests
Expand Down
15 changes: 15 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,21 @@ add_impactx_test(alignment.py
OFF # no plot script yet
)

# Fermilab Booster thin-kick model ################################################
#
# w/o space charge
# copy lattice file & parser
file(COPY ${ImpactX_SOURCE_DIR}/examples/fnal_booster/fermi-booster-madx-3_no-sc.sxf
DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/booster.py)
add_impactx_test(booster.py
examples/fnal_booster/fnal_booster_no-sc.py
OFF # ImpactX MPI-parallel
ON # ImpactX Python interface
examples/fnal_booster/analysis_booster.py
OFF # no plot script yet
)
label_impactx_test(booster.py slow)

# Tune Calculation ###########################################################
#
# w/o space charge
Expand Down
45 changes: 45 additions & 0 deletions examples/fnal_booster/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
.. _examples-booster:

FNAL Booster Model
===================

This example is based on a thin-kick model of the Fermilab Booster ring originally created in MAD-X,
and contributed by F. Schmidt (CERN). The lattice file is expressed in SXF format, and it is parsed and
executed in ImpactX using a Python script. A complete set of input and output files can be found on Zenodo:

https://doi.org/10.5281/zenodo.11645618

We use a proton beam with total energy of 1.338272088 GeV and an initial normalized rms emittance of 1.6 microns.

The second moments of the particle distribution after one turn should coincide with the initial second moments of the particle distribution, to within the level expected due to noise due to statistical sampling.

In this test, the initial and final values of :math:`\sigma_x`, :math:`\sigma_y`, :math:`\sigma_t`, :math:`\epsilon_x`, :math:`\epsilon_y`, and :math:`\epsilon_t` must agree with nominal values.


Run
---

This example can be run as:

* **Python** script: ``python3 fnal_booster_no-sc.py`` or

For `MPI-parallel <https://www.mpi-forum.org>`__ runs, prefix these lines with ``mpiexec -n 4 ...`` or ``srun -n 4 ...``, depending on the system.

.. tab-set::

.. tab-item:: Python: Script

.. literalinclude:: fnal_booster_no-sc.py
:language: python3
:caption: You can copy this file from ``examples/fnal_booster/fnal_booster_no-sc.py``.

Analyze
-------

We run the following script to analyze correctness:

.. dropdown:: Script ``analysis_booster.py``

.. literalinclude:: analysis_booster.py
:language: python3
:caption: You can copy this file from ``examples/fnal_booster/analysis_booster.py``.
98 changes: 98 additions & 0 deletions examples/fnal_booster/analysis_booster.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/usr/bin/env python3
#
# Copyright 2022-2023 ImpactX contributors
# Authors: Axel Huebl, Chad Mitchell
# License: BSD-3-Clause-LBNL
#


import numpy as np
import openpmd_api as io
from scipy.stats import moment


def get_moments(beam):
"""Calculate standard deviations of beam position & momenta
and emittance values

Returns
-------
sigx, sigy, sigt, emittance_x, emittance_y, emittance_t
"""
sigx = moment(beam["position_x"], moment=2) ** 0.5 # variance -> std dev.
sigpx = moment(beam["momentum_x"], moment=2) ** 0.5
sigy = moment(beam["position_y"], moment=2) ** 0.5
sigpy = moment(beam["momentum_y"], moment=2) ** 0.5
sigt = moment(beam["position_t"], moment=2) ** 0.5
sigpt = moment(beam["momentum_t"], moment=2) ** 0.5

epstrms = beam.cov(ddof=0)
emittance_x = (sigx**2 * sigpx**2 - epstrms["position_x"]["momentum_x"] ** 2) ** 0.5
emittance_y = (sigy**2 * sigpy**2 - epstrms["position_y"]["momentum_y"] ** 2) ** 0.5
emittance_t = (sigt**2 * sigpt**2 - epstrms["position_t"]["momentum_t"] ** 2) ** 0.5

return (sigx, sigy, sigt, emittance_x, emittance_y, emittance_t)


# initial/final beam
series = io.Series("diags/openPMD/monitor.h5", io.Access.read_only)
last_step = list(series.iterations)[-1]
initial = series.iterations[1].particles["beam"].to_df()
final = series.iterations[last_step].particles["beam"].to_df()

# compare number of particles
num_particles = 10000
assert num_particles == len(initial)
assert num_particles == len(final)

print("Initial Beam:")
sigx, sigy, sigt, emittance_x, emittance_y, emittance_t = get_moments(initial)
print(f" sigx={sigx:e} sigy={sigy:e} sigt={sigt:e}")
print(
f" emittance_x={emittance_x:e} emittance_y={emittance_y:e} emittance_t={emittance_t:e}"
)

atol = 0.0 # ignored
rtol = 1.5 * num_particles**-0.5 # from random sampling of a smooth distribution
print(f" rtol={rtol} (ignored: atol~={atol})")

assert np.allclose(
[sigx, sigy, sigt, emittance_x, emittance_y, emittance_t],
[
7.5519124163421e-3,
2.7653008349980e-3,
1.0000000000000e-6,
1.5731883856314145e-6,
1.5731883856314145e-6,
1.000000000000000e-22,
],
rtol=rtol,
atol=atol,
)


print("")
print("Final Beam:")
sigx, sigy, sigt, emittance_x, emittance_y, emittance_t = get_moments(final)
print(f" sigx={sigx:e} sigy={sigy:e} sigt={sigt:e}")
print(
f" emittance_x={emittance_x:e} emittance_y={emittance_y:e} emittance_t={emittance_t:e}"
)

atol = 0.0 # ignored
rtol = 1.5 * num_particles**-0.5 # from random sampling of a smooth distribution
print(f" rtol={rtol} (ignored: atol~={atol})")

assert np.allclose(
[sigx, sigy, sigt, emittance_x, emittance_y, emittance_t],
[
7.5519124163421e-3,
2.7653008349980e-3,
1.0000000000000e-6,
1.5731883856314145e-6,
1.5731883856314145e-6,
1.000000000000000e-22,
],
rtol=rtol,
atol=atol,
)
Loading
Loading