-
Notifications
You must be signed in to change notification settings - Fork 29
2.5D Gaussian Solver #1166
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
Open
qianglbl
wants to merge
37
commits into
BLAST-ImpactX:development
Choose a base branch
from
qianglbl:topic-gauss2p5dv2
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
2.5D Gaussian Solver #1166
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
8739136
Gauss 3D SC Pusher
qianglbl 5e185f2
add reference for 3D Gaussian SC solver
qianglbl e019105
Fix Compilation Together
ax3l c35918d
fixed a defect in 3D Gaussian SC
qianglbl e953591
added FODO test example with SC from a 3D Gaussian distribution
qianglbl ef44a50
added reference for the 3D SC Gaussian distribution solver.
qianglbl 42e59e7
User-Facing Docs (Manual)
ax3l cdd97d9
Example: README & CMake Update
ax3l d1bee59
Source: Cleaning, Formatting, TODOs
ax3l 75d25a9
Update analysis
ax3l c30c8a4
GPU Support, Performance Opt
ax3l 823a199
Envelope: Abort on Gauss3D
ax3l 8cb841f
Python Bindings: New Allowed Value
ax3l b63339a
Python Example
ax3l b9024b9
Cleanup
ax3l a01d416
Merge remote-tracking branch 'mainline/development' into topic-gauss3d
ax3l ae8b780
GPU Kernel: `AMREX_GPU_DEVICE`
ax3l b7c297a
Apply suggestions from code review
cemitch99 bbc6cb7
fixed the 3D Gaussian distribution pusher
qianglbl 33b30be
added 2.5D SC kicks with transverse Gaussian distribution
qianglbl b865c75
updated Gauss2.5D SC on GPUs
qianglbl af76457
added nint,bins, and delta input parameters and examples for Gaussian…
qianglbl 7ba4b2c
Merge branch 'development' into topic-gauss2p5dv2
qianglbl 2e53ae9
Merge remote-tracking branch 'mainline/development' into topic-gauss2…
ax3l c5f10fb
Cleanup (last commit)
ax3l d13103a
Start Docs
ax3l 3534984
Rename Input Parameters
ax3l 3182852
Update analysis_fodo_Gauss3D_sc.py
qianglbl 3129814
Update parameters.rst
qianglbl d552588
Update python.rst
qianglbl 3875a9c
Update analysis_fodo_Gauss3D_sc.py
qianglbl 6b5caef
Fix analysis_fodo_Gauss3D_sc.py (final moments)
ax3l b9bfb5c
Beam Moments (Final)
ax3l 5dca30c
2.5D Gaussian SC example
qianglbl d49eca4
fixed an error related to 2.5D Gaussian SC
qianglbl fb0e9bb
Fix switched initial/final moments in analysis_fodo_Gauss3D_sc.py
cemitch99 12c2e9c
Relax tolerance slightly.
cemitch99 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,91 @@ | ||
| #!/usr/bin/env python3 | ||
| # | ||
| # Copyright 2022-2023 ImpactX contributors | ||
| # Authors: Axel Huebl, Ji Qiang | ||
| # 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() | ||
| beam_final = series.iterations[last_step].particles["beam"] | ||
| final = beam_final.to_df() | ||
|
|
||
| # compare number of particles | ||
| num_particles = 10000 | ||
| assert num_particles == len(initial) | ||
| assert num_particles == len(final) | ||
|
|
||
| print("Initial Beam:") | ||
| sig_xi, sig_yi, sig_ti, emittance_xi, emittance_yi, emittance_ti = get_moments(initial) | ||
| print(f" sigx={sig_xi:e} sigy={sig_yi:e} sigt={sig_ti:e}") | ||
| print( | ||
| f" emittance_x={emittance_xi:e} emittance_y={emittance_yi:e} emittance_t={emittance_ti: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( | ||
| [sig_xi, sig_yi, sig_ti, emittance_xi, emittance_yi, emittance_ti], | ||
| [7.51e-05, 7.51e-05, 9.99e-4, 1.98e-09, 1.98e-09, 1.97e-06], | ||
| rtol=rtol, | ||
| atol=atol, | ||
| ) | ||
|
|
||
|
|
||
| print("") | ||
| print("Final Beam:") | ||
| sig_xf, sig_yf, sig_tf, emittance_xf, emittance_yf, emittance_tf = get_moments(final) | ||
| print(f" sigx={sig_xf:e} sigy={sig_yf:e} sigt={sig_tf:e}") | ||
| print( | ||
| f" emittance_x={emittance_xf:e} emittance_y={emittance_yf:e} emittance_t={emittance_tf: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( | ||
| [sig_xf, sig_yf, sig_tf, emittance_xf, emittance_yf, emittance_tf], | ||
| [ | ||
| 9.22e-05, | ||
| 8.55e-05, | ||
| 0.000996, | ||
| 2.04e-09, | ||
| 2.01e-09, | ||
| 1.97e-06, | ||
|
Comment on lines
+82
to
+87
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @qianglbl Let's double check these values are correct/converged. |
||
| ], | ||
| rtol=rtol, | ||
| atol=atol, | ||
| ) | ||
This file contains hidden or 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 hidden or 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,60 @@ | ||
| ############################################################################### | ||
| # Particle Beam(s) | ||
| ############################################################################### | ||
| beam.npart = 10000 | ||
| beam.units = static | ||
| beam.kin_energy = 1.0e2 | ||
| beam.charge = 1.0e-9 | ||
| beam.particle = electron | ||
| beam.distribution = gaussian | ||
| beam.lambdaX = 3.9984884770e-5 | ||
| beam.lambdaY = beam.lambdaX | ||
| beam.lambdaT = 1.0e-3 | ||
| beam.lambdaPx = 2.6623538760e-5 | ||
| beam.lambdaPy = beam.lambdaPx | ||
| beam.lambdaPt = 2.0e-3 | ||
| beam.muxpx = -0.846574929020762 | ||
| beam.muypy = -beam.muxpx | ||
| beam.mutpt = 0.0 | ||
|
|
||
|
|
||
| ############################################################################### | ||
| # Beamline: lattice elements and segments | ||
| ############################################################################### | ||
| lattice.elements = monitor drift1 monitor quad1 monitor drift2 monitor quad2 monitor drift3 monitor | ||
| lattice.nslice = 25 | ||
|
|
||
| monitor.type = beam_monitor | ||
| monitor.backend = h5 | ||
|
|
||
| drift1.type = drift | ||
| drift1.ds = 0.25 | ||
|
|
||
| quad1.type = quad | ||
| quad1.ds = 1.0 | ||
| quad1.k = 1.0 | ||
|
|
||
| drift2.type = drift | ||
| drift2.ds = 0.5 | ||
|
|
||
| quad2.type = quad | ||
| quad2.ds = 1.0 | ||
| quad2.k = -1.0 | ||
|
|
||
| drift3.type = drift | ||
| drift3.ds = 0.25 | ||
|
|
||
|
|
||
| ############################################################################### | ||
| # Algorithms | ||
| ############################################################################### | ||
| algo.particle_shape = 2 | ||
| algo.space_charge = Gauss2p5D | ||
| algo.space_charge.gauss_nint = 101 | ||
| algo.space_charge.gauss_charge_z_bins = 129 | ||
| algo.space_charge.gauss_taylor_delta = 0.01 | ||
|
|
||
| ############################################################################### | ||
| # Diagnostics | ||
| ############################################################################### | ||
| diag.slice_step_diagnostics = true |
This file contains hidden or 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 hidden or 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,73 @@ | ||
| #!/usr/bin/env python3 | ||
| # | ||
| # Copyright 2022-2023 ImpactX contributors | ||
| # Authors: Axel Huebl, Chad Mitchell, Ji Qiang | ||
| # License: BSD-3-Clause-LBNL | ||
| # | ||
| # -*- coding: utf-8 -*- | ||
|
|
||
| from impactx import ImpactX, distribution, elements | ||
|
|
||
| sim = ImpactX() | ||
|
|
||
| # set numerical parameters and IO control | ||
| sim.particle_shape = 2 # B-spline order | ||
| sim.space_charge = "Gauss2p5D" | ||
| sim.space_charge_gauss_nint = 101 | ||
| sim.space_charge_gauss_charge_z_bins = 129 | ||
| sim.space_charge_gauss_taylor_delta = 0.01 | ||
| sim.slice_step_diagnostics = True | ||
|
|
||
| # domain decomposition & space charge mesh | ||
| sim.init_grids() | ||
|
|
||
| # load a 2 GeV electron beam with an initial | ||
| # unnormalized rms emittance of 2 nm | ||
| kin_energy_MeV = 100 # reference energy | ||
| bunch_charge_C = 1.0e-9 # used with space charge | ||
| npart = 10000 # number of macro particles | ||
|
|
||
| # reference particle | ||
| ref = sim.particle_container().ref_particle() | ||
| ref.set_charge_qe(-1.0).set_mass_MeV(0.510998950).set_kin_energy_MeV(kin_energy_MeV) | ||
|
|
||
| # particle bunch | ||
| distr = distribution.Gaussian( | ||
| lambdaX=3.9984884770e-5, | ||
| lambdaY=3.9984884770e-5, | ||
| lambdaT=1.0e-3, | ||
| lambdaPx=2.6623538760e-5, | ||
| lambdaPy=2.6623538760e-5, | ||
| lambdaPt=2.0e-3, | ||
| muxpx=-0.846574929020762, | ||
| muypy=0.846574929020762, | ||
| mutpt=0.0, | ||
| ) | ||
| sim.add_particles(bunch_charge_C, distr, npart) | ||
|
|
||
| # add beam diagnostics | ||
| monitor = elements.BeamMonitor("monitor", backend="h5") | ||
|
|
||
| # design the accelerator lattice) | ||
| ns = 25 # number of slices per ds in the element | ||
| fodo = [ | ||
| monitor, | ||
| elements.ChrDrift(name="drift1", ds=0.25, nslice=ns), | ||
| monitor, | ||
| elements.ChrQuad(name="quad1", ds=1.0, k=1.0, nslice=ns), | ||
| monitor, | ||
| elements.ChrDrift(name="drift2", ds=0.5, nslice=ns), | ||
| monitor, | ||
| elements.ChrQuad(name="quad2", ds=1.0, k=-1.0, nslice=ns), | ||
| monitor, | ||
| elements.ChrDrift(name="drift3", ds=0.25, nslice=ns), | ||
| monitor, | ||
| ] | ||
| # assign a fodo segment | ||
| sim.lattice.extend(fodo) | ||
|
|
||
| # run simulation | ||
| sim.track_particles() | ||
|
|
||
| # clean shutdown | ||
| sim.finalize() |
This file contains hidden or 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 hidden or 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 hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.