-
Notifications
You must be signed in to change notification settings - Fork 31
Add Spin to Particle Container #1226
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
Merged
ax3l
merged 30 commits into
BLAST-ImpactX:development
from
cemitch99:add_spin_container
Dec 16, 2025
Merged
Changes from 20 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
37d09ba
Add spin to particle container.
cemitch99 8602239
Add spin sampling algorithm.
cemitch99 10bd32e
Add citations for documentation
cemitch99 21424ce
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] b1781be
Update citations
cemitch99 90767f5
Spin Distribution Call
ax3l b0d9d1e
Add conditional form of call to AddNParticles.
cemitch99 3361874
Add input for a simple distribution test.
cemitch99 23e3074
[Dependencies] pyAMReX: ax3l branch
ax3l c9a4171
Fix use of optional arguments in AddNParticles call.
cemitch99 88a5695
Formatting
ax3l 6201372
[Dependencies] AMReX: development branch
ax3l c270961
Add P to kappa.
cemitch99 57a2958
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 7c399a1
Add analysis and README for distribution test.
cemitch99 b6d6722
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 172865a
Add app/C++ documentation of distribution.
cemitch99 7561fcb
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 5b37b55
Merge remote-tracking branch 'mainline/development' into add_spin_con…
ax3l 5437431
Test: Update DataFrame Comparison
ax3l 370035d
Fix Init (No-Spin Case)
ax3l 5505632
rst titles
ax3l 562fd6d
Remove todo comment
ax3l dd6a94f
Improve `SpinvMF`
ax3l b6af5c8
NVCC: Work-Around Lambda
ax3l ab8a5e5
pyAMReX: `development`
ax3l f2448dc
Python Test
ax3l 15cbcf9
`Source` Element: Support Spin in Restart
ax3l ce9582e
Merge remote-tracking branch 'mainline/development' into add_spin_con…
ax3l a79aca0
CUDA CI: Lower Build Parallelism
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 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
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,74 @@ | ||
| #!/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 | ||
|
|
||
|
|
||
| def get_polarization(beam): | ||
| """Calculate polarization vector, given by the mean values of spin components. | ||
|
|
||
| Returns | ||
| ------- | ||
| polarization_x, polarization_y, polarization_z | ||
| """ | ||
| polarization_x = np.mean(beam["spin_x"]) | ||
| polarization_y = np.mean(beam["spin_y"]) | ||
| polarization_z = np.mean(beam["spin_z"]) | ||
|
|
||
| return (polarization_x, polarization_y, polarization_z) | ||
|
|
||
|
|
||
| # 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:") | ||
| polarization_x, polarization_y, polarization_z = get_polarization(initial) | ||
| print( | ||
| f" polarization_x={polarization_x:e} polarization_y={polarization_y:e} polarization_z={polarization_z:e}" | ||
| ) | ||
|
|
||
| atol = 1.3 * num_particles**-0.5 # from random sampling of a smooth distribution | ||
| print(f" atol={atol}") | ||
|
|
||
| assert np.allclose( | ||
| [polarization_x, polarization_y, polarization_z], | ||
| [ | ||
| 0.7, | ||
| 0.0, | ||
| 0.0, | ||
| ], | ||
| atol=atol, | ||
| ) | ||
|
|
||
| print("") | ||
| print("Final Beam:") | ||
| polarization_x, polarization_y, polarization_z = get_polarization(final) | ||
| print( | ||
| f" polarization_x={polarization_x:e} polarization_y={polarization_y:e} polarization_z={polarization_z:e}" | ||
| ) | ||
|
|
||
| atol = 1.3 * num_particles**-0.5 # from random sampling of a smooth distribution | ||
| print(f" atol={atol}") | ||
|
|
||
| assert np.allclose( | ||
| [polarization_x, polarization_y, polarization_z], | ||
| [ | ||
| 0.7, | ||
| 0.0, | ||
| 0.0, | ||
| ], | ||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| ############################################################################### | ||
| # Particle Beam(s) | ||
| ############################################################################### | ||
| beam.npart = 10000 | ||
| beam.units = static | ||
| beam.kin_energy = 2.0e3 | ||
| beam.charge = 1.0e-9 | ||
| beam.particle = proton | ||
| beam.distribution = kurth4d | ||
| beam.lambdaX = 1.0e-3 | ||
| beam.lambdaY = beam.lambdaX | ||
| beam.lambdaT = 1.0e-3 | ||
| beam.lambdaPx = 1.0e-3 | ||
| beam.lambdaPy = beam.lambdaPx | ||
| beam.lambdaPt = 2.0e-3 | ||
| beam.muxpx = 0.0 | ||
| beam.muypy = 0.0 | ||
| beam.mutpt = 0.0 | ||
| beam.polarization_x = 0.7 | ||
| beam.polarization_y = 0.0 | ||
| beam.polarization_z = 0.0 | ||
|
|
||
| ############################################################################### | ||
| # Beamline: lattice elements and segments | ||
| ############################################################################### | ||
| lattice.elements = monitor constf1 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.0e-4 | ||
|
|
||
|
|
||
| ############################################################################### | ||
| # Algorithms | ||
| ############################################################################### | ||
| algo.space_charge = false |
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.