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

Adding EPAC2004 space charge benchmarks #422

Merged
merged 97 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
8b35f7f
Examples for 3D space charge benchmarking
cemitch99 Jun 7, 2022
0d88ccf
Update input_kurth_10nC.in
cemitch99 Dec 5, 2022
09d153c
Add FODO + RF example w SC
cemitch99 Aug 28, 2023
616d669
Delete input_kurth_10nC.in
cemitch99 Aug 28, 2023
f401805
Correct RF coefficients and add analysis.
cemitch99 Aug 29, 2023
1f8d3dc
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 29, 2023
81cc570
Added analysis script for FODO+RF SC benchmark.
cemitch99 Aug 29, 2023
fae804d
Merge branch 'development' into add_IPAC_3DSC_benchmarks
cemitch99 Aug 29, 2023
ce38921
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 29, 2023
283fc82
Update CMakeLists.txt
cemitch99 Aug 29, 2023
afce9c8
Add FODO+RF+SC Python input.
cemitch99 Aug 30, 2023
859dd34
Remove EOL white spaces.
cemitch99 Aug 30, 2023
4edcc64
Update run_fodo_rf_SC.py
cemitch99 Aug 30, 2023
33665ed
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 30, 2023
4276d05
Update CMakeLists.txt
cemitch99 Aug 30, 2023
da4d743
Update run_fodo_rf_SC.py
cemitch99 Aug 30, 2023
6a77a83
Update run_fodo_rf_SC.py
cemitch99 Aug 30, 2023
3ff638d
Update run_fodo_rf_SC.py
cemitch99 Sep 5, 2023
1416b2a
Update analysis_fodo_rf_SC.py
cemitch99 Sep 5, 2023
c8d87af
Try again.
cemitch99 Aug 31, 2023
587dc9f
Preliminary draft of thermal distribution.
cemitch99 Sep 15, 2023
0781452
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 15, 2023
1c620b8
Added radial sampling.
cemitch99 Sep 16, 2023
b644e95
Modify radial sampling to use AMReX libs.
cemitch99 Sep 16, 2023
05f4d5b
Initializing Rprofile data.
cemitch99 Sep 16, 2023
251073e
Add CDF arrays, fixed shadowed declaration.
cemitch99 Sep 18, 2023
6ef63b3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 18, 2023
e438471
Resolve conflicts.
cemitch99 Sep 18, 2023
3132bf1
Remove comments.
cemitch99 Sep 18, 2023
f2f7707
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 18, 2023
8139e74
Fixed call to generate_radial_dist.
cemitch99 Sep 18, 2023
9f16f05
Added exchange of radial profile data.
cemitch99 Sep 18, 2023
a771e8c
Fix shadowed variables in integrator.
cemitch99 Sep 18, 2023
a535e8b
Support random selection of core or halo based on w.
cemitch99 Sep 19, 2023
d3f8d71
Finalize data exchange with rprofile.
cemitch99 Sep 20, 2023
8517e5e
Allow unused input parameters.
cemitch99 Sep 20, 2023
1037ba0
Add thermal beam example.
cemitch99 Sep 20, 2023
f9824fe
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 20, 2023
d328ab4
Modify to use normalization instead of phi0.
cemitch99 Sep 22, 2023
e6d19f9
Add thermal and bithermal beam examples.
cemitch99 Sep 22, 2023
fc49be2
Update openPMD_to_ASCII.py
cemitch99 Sep 22, 2023
00ab910
Finalize bithermal beam example.
cemitch99 Sep 22, 2023
4a1131c
Finalize thermal beam example.
cemitch99 Sep 22, 2023
097f709
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 22, 2023
d914632
Add Python equivs for thermal tests.
cemitch99 Oct 18, 2023
099c9e5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 18, 2023
128bf9b
Add tests to CI.
cemitch99 Oct 19, 2023
693ab25
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 19, 2023
8e60abc
Reduce resolution for CI.
cemitch99 Oct 19, 2023
1aecfa0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 19, 2023
7bded1f
Update analysis scripts.
cemitch99 Oct 20, 2023
bc10523
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 20, 2023
8db480b
Update Thermal.H
cemitch99 Oct 20, 2023
d7d94fb
Update Thermal.H
cemitch99 Oct 20, 2023
28a9356
Update CMakeLists.txt
cemitch99 Oct 20, 2023
2f39bd4
Eliminate unused variable warnings.
cemitch99 Oct 23, 2023
36c0980
Update CMakeLists.txt
cemitch99 Oct 23, 2023
1eae94c
Update input_thermal.in
cemitch99 Oct 25, 2023
011ecb8
Update input_bithermal.in
cemitch99 Oct 25, 2023
067c2e2
Update input_thermal.in
cemitch99 Oct 25, 2023
93dbb4d
Update input_thermal.in
cemitch99 Oct 26, 2023
3733447
Update input_bithermal.in
cemitch99 Oct 26, 2023
a3ed094
Add tolerance to ToFixedT to avoid pz<=0.
cemitch99 Nov 10, 2023
c0620a5
Update input_thermal.in
cemitch99 Nov 22, 2023
ac699cd
Update input_bithermal.in
cemitch99 Nov 22, 2023
27fc922
Update input_fodo_rf_SC.in
cemitch99 Nov 22, 2023
520ed40
Update run_thermal.py
cemitch99 Nov 22, 2023
8f67db0
Update run_bithermal.py
cemitch99 Nov 22, 2023
f5823c6
Update run_fodo_rf_SC.py
cemitch99 Nov 22, 2023
5ede71d
Update Thermal.H
cemitch99 Nov 22, 2023
2952204
Merge branch 'development' into add_IPAC_3DSC_benchmarks
cemitch99 Nov 22, 2023
0eccfd1
Update CMakeLists.txt
cemitch99 Nov 22, 2023
228fcf0
Merge branch 'development' into add_IPAC_3DSC_benchmarks
cemitch99 Dec 6, 2023
8d57d0c
Update input_thermal.in
cemitch99 Dec 6, 2023
8b71b35
Add README example documentation.
cemitch99 Dec 6, 2023
bec97ce
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 6, 2023
ad47aa0
Add documentation of thermal distribution type.
cemitch99 Dec 6, 2023
c1258a4
Apply suggestions from code review
cemitch99 Dec 9, 2023
114b907
Apply suggestions from code review
ax3l Dec 19, 2023
945a78a
Update src/particles/distribution/Thermal.H
ax3l Dec 19, 2023
c0d19fd
Update src/initialization/InitDistribution.cpp
ax3l Dec 19, 2023
13d77c2
Update src/particles/distribution/Thermal.H
ax3l Dec 19, 2023
18e738b
Comment out PrintToFile Debugging
ax3l Dec 19, 2023
7dcaf8f
Merge remote-tracking branch 'mainline/development' into add_IPAC_3DS…
ax3l Dec 19, 2023
088edb7
Constexpr for length in kernel
ax3l Dec 19, 2023
101fa20
Thermal: Unused Variable
ax3l Jan 2, 2024
c32ea8d
Merge remote-tracking branch 'mainline/development' into add_IPAC_3DS…
ax3l Jan 2, 2024
8a51b5a
Python Thermal Test: `prob_relative` is a list now
ax3l Jan 2, 2024
6ddd678
Bithermal Plot Script: Matplotlib
ax3l Jan 2, 2024
23a24be
Apply suggestions from code review
ax3l Jan 2, 2024
ef62e91
Merge remote-tracking branch 'mainline/development' into add_IPAC_3DS…
ax3l Jan 3, 2024
44ee511
Thermal Distribution: Python
ax3l Jan 3, 2024
56efc2e
Update docs/source/usage/parameters.rst
ax3l Jan 3, 2024
bbfb8fe
Bithermal: slice_step_diagnostics off
ax3l Jan 3, 2024
8347eb9
Python Files: Executable
ax3l Jan 3, 2024
ee6bff7
Bithermal: Update Figure
ax3l Jan 3, 2024
4c2b294
README: New Formatting
ax3l Jan 3, 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
18 changes: 18 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -639,3 +639,21 @@ add_impactx_test(hvkicker_madx.py
examples/kicker/analysis_kicker.py
OFF # no plot script yet
)

# FODO + RF EPAC2004 ##################################################
#
# with space charge
add_impactx_test(fodo_rf_sc
examples/epac2004_benchmarks/input_fodo_rf_SC.in
ON # ImpactX MPI-parallel
OFF # ImpactX Python interface
examples/epac2004_benchmarks/analysis_fodo_rf_SC.py
OFF # no plot script yet
)
add_impactx_test(fodo_rf_sc.py
examples/epac2004_benchmarks/run_fodo_rf_SC.py
OFF # ImpactX MPI-parallel
ON # ImpactX Python interface
examples/epac2004_benchmarks/analysis_fodo_rf_SC.py
OFF # no plot script yet
)
109 changes: 109 additions & 0 deletions examples/epac2004_benchmarks/analysis_fodo_rf_SC.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#!/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}")

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

assert np.allclose(
[sigx, sigy, sigt],
[9.84722273e-4, 6.96967278e-4, 4.486799242214e-03],
rtol=rtol,
atol=atol,
)

print(
f" emittance_x={emittance_x:e} emittance_y={emittance_y:e} emittance_t={emittance_t:e}"
)

atol = 4.0e-8
print(f" atol={atol}")

assert np.allclose(
[emittance_x, emittance_y, emittance_t],
[0.0, 0.0, 0.0],
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}")

atol = 0.0 # ignored
rtol = 3.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],
[9.84722273e-4, 6.96967278e-4, 4.486799242214e-03],
rtol=rtol,
atol=atol,
)

print(
f" emittance_x={emittance_x:e} emittance_y={emittance_y:e} emittance_t={emittance_t:e}"
)

atol = 4.0e-8
print(f" atol={atol}")

assert np.allclose(
[emittance_x, emittance_y, emittance_t],
[0.0, 0.0, 0.0],
atol=atol,
)
128 changes: 128 additions & 0 deletions examples/epac2004_benchmarks/input_fodo_rf_SC.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
###############################################################################
# Particle Beam(s)
###############################################################################
beam.npart = 10000
beam.units = static
beam.energy = 250.0
beam.charge = 1.42857142857142865e-10
beam.particle = proton
beam.distribution = kurth6d
beam.sigmaX = 9.84722273e-4
beam.sigmaY = 6.96967278e-4
beam.sigmaT = 4.486799242214e-03
beam.sigmaPx = 0.0
beam.sigmaPy = 0.0
beam.sigmaPt = 0.0
beam.muxpx = 0.0
beam.muypy = 0.0
beam.mutpt = 0.0


###############################################################################
# Beamline: lattice elements and segments
###############################################################################
lattice.elements = monitor fquad dr gapa1 dr dquad dr gapb1 dr fquad monitor

monitor.type = beam_monitor
monitor.backend = h5

dr.type = drift
dr.ds = 0.1
dr.nslice = 4

fquad.type = quad
fquad.ds = 0.15
fquad.k = 2.4669749766168163
fquad.nslice = 6

dquad.type = quad
dquad.ds = 0.3
dquad.k = -2.4669749766168163
dquad.nslice = 12

gapa1.type = rfcavity
gapa1.ds = 1.0
gapa1.escale = 0.042631556991578
gapa1.freq = 7.0e8
gapa1.phase = 45.0
gapa1.mapsteps = 100
gapa1.nslice = 10
gapa1.cos_coefficients = \
0.120864178375839 \
-0.044057987631337 \
-0.209107290958498 \
-0.019831226655815 \
0.290428111491964 \
0.381974267375227 \
0.276801212694382 \
0.148265085353012 \
0.068569351192205 \
0.0290155855315696 \
0.011281649986680 \
0.004108501632832 \
0.0014277644197320 \
0.000474212125404 \
0.000151675768439 \
0.000047031436898 \
0.000014154595193 \
4.154741658e-6 \
1.191423909e-6 \
3.348293360e-7 \
9.203061700e-8 \
2.515007200e-8 \
6.478108000e-9 \
1.912531000e-9 \
2.925600000e-10
gapa1.sin_coefficients = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \
0 0 0 0 0 0 0

gapb1.type = rfcavity
gapb1.ds = 1.0
gapb1.escale = 0.042631556991578
gapb1.freq = 7.0e8
gapb1.phase = -1.0
gapb1.mapsteps = 100
gapb1.nslice = 10
gapb1.cos_coefficients = \
0.120864178375839 \
-0.044057987631337 \
-0.209107290958498 \
-0.019831226655815 \
0.290428111491964 \
0.381974267375227 \
0.276801212694382 \
0.148265085353012 \
0.068569351192205 \
0.0290155855315696 \
0.011281649986680 \
0.004108501632832 \
0.0014277644197320 \
0.000474212125404 \
0.000151675768439 \
0.000047031436898 \
0.000014154595193 \
4.154741658e-6 \
1.191423909e-6 \
3.348293360e-7 \
9.203061700e-8 \
2.515007200e-8 \
6.478108000e-9 \
1.912531000e-9 \
2.925600000e-10
gapb1.sin_coefficients = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \
0 0 0 0 0 0 0


###############################################################################
# Algorithms
###############################################################################
algo.particle_shape = 2
algo.space_charge = true

amr.n_cell = 56 56 64
geometry.prob_relative = 4.0

###############################################################################
# Diagnostics
###############################################################################
diag.slice_step_diagnostics = true
35 changes: 35 additions & 0 deletions examples/epac2004_benchmarks/input_thermal.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
###############################################################################
# Particle Beam(s)
###############################################################################
beam.npart = 10000
#beam.npart = 2
beam.units = static
beam.energy = 2.0e3
beam.charge = 1.0e-9
beam.particle = proton
beam.distribution = thermal
beam.k = 1.0
beam.kT = 1.0
beam.kT_halo = 1.0
beam.halo = 0.0

###############################################################################
# Beamline: lattice elements and segments
###############################################################################
lattice.elements = monitor

monitor.type = beam_monitor
monitor.backend = h5

constf1.type = constf
constf1.ds = 2.0
constf1.kx = 1.0
constf1.ky = 1.0
constf1.kt = 1.0


###############################################################################
# Algorithms
###############################################################################
algo.particle_shape = 2
algo.space_charge = false
Loading
Loading