-
Notifications
You must be signed in to change notification settings - Fork 23
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
Added examples for 3D space charge benchmarking. #141
Merged
ax3l
merged 18 commits into
BLAST-ImpactX:development
from
cemitch99:add_spacecharge_benchmarks
Dec 22, 2022
Merged
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
cd84186
Examples for 3D space charge benchmarking
cemitch99 a3394f2
Update analysis_cfchannel_10nC.py
cemitch99 db77bb9
Update input_cfchannel_10nC.in
cemitch99 6bdaa41
Update input_kurth_periodic.in
cemitch99 4fa0d5e
Update analysis_kurth_periodic.py
cemitch99 688461d
Update input_kurth_10nC_periodic.in
cemitch99 2459e5a
Update analysis_kurth_10nC_periodic.py
cemitch99 9dd7bea
Update analysis_kurth_periodic.py
cemitch99 095bd66
Update input_kurth_10nC.in
cemitch99 cedbfb8
Update analysis_kurth_10nC.py
cemitch99 710eee1
Merge remote-tracking branch 'mainline/development' into add_spacecha…
ax3l 48c9d93
Update analysis_kurth_periodic.py
cemitch99 5c502db
Update input_kurth_periodic.in
cemitch99 2968c59
ConstF Channel: Python 10nC Example
ax3l 0d75550
Python: kurth periodic example
ax3l af13356
Update README.rst
cemitch99 88f6035
Remove Already Covered Scenarios
ax3l d231348
Python: kurth 10nC periodic
ax3l File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
#!/usr/bin/env python3 | ||
# | ||
# Copyright 2022 ImpactX contributors | ||
# Authors: Axel Huebl, Chad Mitchell | ||
# License: BSD-3-Clause-LBNL | ||
# | ||
|
||
import glob | ||
|
||
import numpy as np | ||
import pandas as pd | ||
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["x"], moment=2) ** 0.5 # variance -> std dev. | ||
sigpx = moment(beam["px"], moment=2) ** 0.5 | ||
sigy = moment(beam["y"], moment=2) ** 0.5 | ||
sigpy = moment(beam["py"], moment=2) ** 0.5 | ||
sigt = moment(beam["t"], moment=2) ** 0.5 | ||
sigpt = moment(beam["pt"], moment=2) ** 0.5 | ||
|
||
epstrms = beam.cov(ddof=0) | ||
emittance_x = (sigx**2 * sigpx**2 - epstrms["x"]["px"] ** 2) ** 0.5 | ||
emittance_y = (sigy**2 * sigpy**2 - epstrms["y"]["py"] ** 2) ** 0.5 | ||
emittance_t = (sigt**2 * sigpt**2 - epstrms["t"]["pt"] ** 2) ** 0.5 | ||
|
||
return (sigx, sigy, sigt, emittance_x, emittance_y, emittance_t) | ||
|
||
|
||
def read_all_files(file_pattern): | ||
"""Read in all CSV files from each MPI rank (and potentially OpenMP | ||
thread). Concatenate into one Pandas dataframe. | ||
|
||
Returns | ||
------- | ||
pandas.DataFrame | ||
""" | ||
return pd.concat( | ||
( | ||
pd.read_csv(filename, delimiter=r"\s+") | ||
for filename in glob.glob(file_pattern) | ||
), | ||
axis=0, | ||
ignore_index=True, | ||
).set_index("id") | ||
|
||
|
||
# initial/final beam on rank zero | ||
initial = read_all_files("diags/initial_beam.txt.*") | ||
final = read_all_files("diags/output_beam.txt.*") | ||
|
||
# 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 = 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], | ||
[ | ||
1.2154443728379865788e-003, | ||
1.2154443728379865788e-003, | ||
4.0956844276541331005317e-004, | ||
1.000000000e-006, | ||
1.000000000e-006, | ||
1.000000000e-006, | ||
], | ||
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 = 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], | ||
[ | ||
1.2154443728379865788e-003, | ||
1.2154443728379865788e-003, | ||
4.0956844276541331005317e-004, | ||
1.000000000e-006, | ||
1.000000000e-006, | ||
1.000000000e-006, | ||
], | ||
rtol=rtol, | ||
atol=atol, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
############################################################################### | ||
# Particle Beam(s) | ||
############################################################################### | ||
beam.npart = 10000 | ||
beam.units = static | ||
beam.energy = 2.0e3 | ||
beam.charge = 1.0e-8 | ||
beam.particle = proton | ||
beam.distribution = waterbag | ||
beam.sigmaX = 1.2154443728379865788e-3 | ||
beam.sigmaY = 1.2154443728379865788e-3 | ||
beam.sigmaT = 4.0956844276541331005e-4 | ||
beam.sigmaPx = 8.2274435782286157175e-4 | ||
beam.sigmaPy = 8.2274435782286157175e-4 | ||
beam.sigmaPt = 2.4415943602685364584e-3 | ||
|
||
|
||
############################################################################### | ||
# Beamline: lattice elements and segments | ||
############################################################################### | ||
lattice.elements = constf1 | ||
|
||
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 = true | ||
|
||
amr.n_cell = 40 40 32 | ||
geometry.prob_relative = 1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest that the test here, corresponding to "input_kurth_10nC.in", can be removed since the previous test "input_kurth_10nC_periodic.in" is more comprehensive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks - removed :)