-
Notifications
You must be signed in to change notification settings - Fork 200
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
Implementation of Bremsstrahlung collisions #5537
Open
dpgrote
wants to merge
47
commits into
BLAST-WarpX:development
Choose a base branch
from
dpgrote:add_Bremmstrahlung
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
Changes from all commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
c1a5536
Initial implementation of Bremmstrahlung collisions
dpgrote 7f0f53e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 03d96e0
Fix typo
dpgrote edf04f9
Small cleanup
dpgrote e1105c3
Small fixes
dpgrote 2926baa
More cleanup, including const's and prt's
dpgrote 0ab5247
Small fixes
dpgrote 8a147cb
Bug fix
dpgrote d3b22d7
Fix a variable name
dpgrote 2dcd95a
Initialize p_mask to zero
dpgrote c50b855
Fix the energy scaling of the generated photons
dpgrote 1bb5422
Improvements to the algorithm
dpgrote 27fe428
Add CI test
dpgrote 3d26245
Make creation of photons optional
dpgrote 43939ca
Add documentation
dpgrote fd4a0be
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] ed08970
Fix missing semicolon
dpgrote 180a51e
Rewrite the interpolation in Photon_energy
dpgrote 0808815
Fix setting of p_mask when photons are not created
dpgrote 21eaf31
Another small cleanup
dpgrote 2548c27
Small fixes
dpgrote 32a2a2f
Only scale kdsigdk_cut for io_cut == 0
dpgrote bb265a7
Add comment
dpgrote f2f34fc
Fix typo
dpgrote 56d5042
Add precalculated cross section
dpgrote 98bc9e8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] eeadf9a
Clean up in analysis_collision_1d_Bremsstrahlung.py
dpgrote 54ff053
Clean up inputs_test_1d_collision_z_Bremsstrahlung
dpgrote f9756fd
Revert to using the midpoint value of k
dpgrote 7a91252
Fix the sign of the photon energy
dpgrote 2b087e8
Fix const
dpgrote 3267344
Fix CI analysis script
dpgrote d9b05ca
Clean up auto in Bremsstrahlung/PhotonCreationFunc
dpgrote 0f3e881
Ions are updated, now conserving energy and momentum
dpgrote 0e524a3
Rework the collision to conserve energy and momentum
dpgrote 3e356fe
Use const
dpgrote 0ed4e3e
Expanding some expressions allows cancelling of some terms
dpgrote 87107f2
Update CI benchmark after adding conservation of momentum
dpgrote a94241d
Added upper limit of the photon energy
dpgrote 2a1f6a1
Update CI benchmark after change limiting the photon energy
dpgrote 5c1cc70
Now pass in wpe instead of m1 and n1
dpgrote d76a21d
Merge branch 'development' into add_Bremmstrahlung
dpgrote 03aa43e
Fix related to NameComponents change
dpgrote 83896d5
Use better expressions for small and large gamma
dpgrote c15a5d1
Make sure that sqrt is non-negative in energy calculatin
dpgrote 6b59ecb
Merge branch 'development' into add_Bremmstrahlung
dpgrote a10d77c
Merge branch 'development' into add_Bremmstrahlung
dpgrote 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
109 changes: 109 additions & 0 deletions
109
Examples/Tests/collision/analysis_collision_1d_Bremsstrahlung.py
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,109 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Copyright 2025 David Grote | ||
# | ||
# | ||
# This file is part of WarpX. | ||
# | ||
# License: BSD-3-Clause-LBNL | ||
# | ||
# This is a script that analyses the simulation results from the script `inputs_test_1d_collision_z_Bremsstrahlung`. | ||
# run locally: python analysis_collision_1d_Bremsstrahlung.py diags/diag1000600/ | ||
# | ||
# This is a 1D Bremsstrahlung collision of electrons on Borons ions | ||
# producing photons. This checks that the appropriate number of | ||
# photons are created with the correct distribution. | ||
# | ||
import os | ||
import sys | ||
|
||
import numpy as np | ||
from scipy import constants | ||
|
||
# this will be the name of the plot file | ||
last_fn = sys.argv[1] | ||
|
||
particle_energy = np.loadtxt( | ||
os.path.join("diags", "reducedfiles", "particle_energy.txt"), skiprows=1 | ||
) | ||
particle_momentum = np.loadtxt( | ||
os.path.join("diags", "reducedfiles", "particle_momentum.txt"), skiprows=1 | ||
) | ||
particle_number = np.loadtxt( | ||
os.path.join("diags", "reducedfiles", "particle_number.txt"), skiprows=1 | ||
) | ||
|
||
total_energy = particle_energy[:, 2] | ||
electron_energy = particle_energy[:, 3] | ||
ion_energy = particle_energy[:, 4] | ||
photon_energy = particle_energy[:, 5] | ||
|
||
total_momentum = particle_momentum[:, 2] | ||
electron_momentum = particle_momentum[:, 3] | ||
ion_momentum = particle_momentum[:, 4] | ||
photon_momentum = particle_momentum[:, 5] | ||
|
||
energy_tolerance = 1.0e-11 | ||
|
||
print(f"initial total energy = {total_energy[0]}") | ||
print(f"final total energy = {total_energy[-1]}") | ||
|
||
dE_total = np.abs(total_energy[-1] - total_energy[0]) / total_energy[0] | ||
print(f"change in total energy = {dE_total}") | ||
assert dE_total < energy_tolerance | ||
|
||
momentum_tolerance = 1.0e-12 | ||
|
||
print(f"initial total momentum = {total_momentum[0]}") | ||
print(f"final total momentum = {total_momentum[-1]}") | ||
|
||
dP_total = np.abs(total_momentum[-1] - total_momentum[0]) / total_momentum[0] | ||
print(f"change in total momentum = {dP_total}") | ||
assert dP_total < momentum_tolerance | ||
|
||
print() | ||
|
||
dt = 1.0e-2 * 1.0e-15 | ||
Z = 5 | ||
n_i = 5.47e31 | ||
n_e = 5.47e30 | ||
L = 1.0e-6 # 1 micron | ||
T1 = 1.0e6 # 1 MeV | ||
N_e = n_e * L # number of electrons | ||
m_e_eV = constants.m_e * constants.c**2 / constants.e | ||
gamma = T1 / m_e_eV + 1.0 | ||
gamma_beta = np.sqrt(gamma**2 - 1.0) | ||
beta = gamma_beta / gamma | ||
|
||
phirad = 6.761 # from Seltzer and Berger for 1 MeV electron and Boron | ||
|
||
|
||
dEdx_simulation = ( | ||
(particle_energy[0, 3] - particle_energy[1:, 3]) | ||
/ particle_energy[1:, 0] | ||
/ (beta * constants.c * dt) | ||
/ constants.e | ||
/ N_e | ||
) | ||
|
||
Boron_weight = 20065.0 * constants.m_e | ||
r_e = ( | ||
1.0 | ||
/ (4.0 * constants.pi * constants.epsilon_0) | ||
* (constants.e**2 / (constants.m_e * constants.c**2)) | ||
) | ||
dEdx = n_i * constants.alpha * r_e**2 * Z**2 * (T1 + m_e_eV) * phirad | ||
|
||
print(f"dE/dx analytic = {dEdx}") | ||
print(f"dE/dx simulated = {dEdx_simulation[-1]}") | ||
print(f"dE/dx simulated/analytic = {dEdx_simulation[-1] / dEdx}") | ||
assert np.abs(dEdx_simulation[-1] / dEdx - 1.0) < 0.03 | ||
|
||
sigma_total = 1.818e-28 # Calculated from table with k cutoff=1.e-4 | ||
N_photon = n_e * n_i * L * beta * constants.c * sigma_total * dt | ||
print( | ||
f"New photons per step simulated/analytic = {particle_number[-1, -1] / (particle_energy[-1, 0] * N_photon)}" | ||
) | ||
assert ( | ||
np.abs(particle_number[-1, -1] / (particle_energy[-1, 0] * N_photon) - 1.0) < 0.02 | ||
) |
106 changes: 106 additions & 0 deletions
106
Examples/Tests/collision/inputs_test_1d_collision_z_Bremsstrahlung
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,106 @@ | ||
################################# | ||
########## CONSTANTS ############ | ||
################################# | ||
|
||
my_constants.n_e = 5.47e30 # electron density, m^-3 | ||
my_constants.Np_e = 1024 # electrons per cell | ||
my_constants.T1 = 1.e6 # 1 MeV, electron energy | ||
my_constants.m_e_eV = m_e*clight**2/q_e # electron rest mass in eV | ||
my_constants.gamma = T1/m_e_eV + 1. # electron gamma factor | ||
my_constants.gamma_beta = sqrt(gamma**2 - 1.) | ||
|
||
my_constants.n_i = 5.47e31 # ion density, m^-3, for rho = 1000 g/cm^3 | ||
my_constants.Np_i = 1024 # ions per cell | ||
my_constants.T_i = 2.0 # ion temperature, eV | ||
|
||
my_constants.m_B11 = 20065.0*m_e # 11.01*amu/me - 5, Boron | ||
my_constants.q_B11 = 5.*q_e | ||
|
||
################################# | ||
####### GENERAL PARAMETERS ###### | ||
################################# | ||
max_step = 100 | ||
amr.n_cell = 100 | ||
amr.max_level = 0 | ||
amr.blocking_factor = 4 | ||
geometry.dims = 1 | ||
geometry.prob_lo = 0. | ||
geometry.prob_hi = 1.e-6 | ||
|
||
################################# | ||
###### Boundary Condition ####### | ||
################################# | ||
boundary.field_lo = periodic | ||
boundary.field_hi = periodic | ||
|
||
################################# | ||
############ NUMERICS ########### | ||
################################# | ||
warpx.serialize_initial_conditions = 1 | ||
warpx.verbose = 1 | ||
warpx.const_dt = 1.e-2*1.e-15 | ||
warpx.use_filter = 0 | ||
|
||
# Do not evolve the E and B fields | ||
algo.maxwell_solver = none | ||
|
||
# Order of particle shape factors | ||
algo.particle_shape = 1 | ||
|
||
################################# | ||
############ PLASMA ############# | ||
################################# | ||
particles.species_names = electrons ions photons | ||
particles.photon_species = photons | ||
|
||
electrons.species_type = electron | ||
electrons.do_not_deposit = 1 | ||
|
||
electrons.injection_style = "NUniformPerCell" | ||
electrons.num_particles_per_cell_each_dim = Np_e | ||
electrons.profile = "constant" | ||
electrons.density = n_e | ||
electrons.momentum_distribution_type = "constant" | ||
electrons.uz = gamma_beta | ||
|
||
ions.charge = q_B11 | ||
ions.mass = m_B11 | ||
ions.do_not_deposit = 1 | ||
|
||
ions.injection_style = "NUniformPerCell" | ||
ions.num_particles_per_cell_each_dim = Np_i | ||
ions.profile = "constant" | ||
ions.density = n_i | ||
ions.momentum_distribution_type = "gaussian" | ||
ions.ux_th = sqrt(T_i*q_e/m_B11)/clight | ||
ions.uy_th = sqrt(T_i*q_e/m_B11)/clight | ||
ions.uz_th = sqrt(T_i*q_e/m_B11)/clight | ||
|
||
photons.species_type = photon | ||
photons.injection_style = none | ||
|
||
################################# | ||
############ COLLISION ########## | ||
################################# | ||
collisions.collision_names = bremsstrahlung | ||
bremsstrahlung.type = bremsstrahlung | ||
bremsstrahlung.species = electrons ions | ||
bremsstrahlung.Z = 5 | ||
bremsstrahlung.product_species = photons | ||
bremsstrahlung.multiplier = 100. | ||
|
||
# Diagnostics | ||
diagnostics.diags_names = diag1 | ||
diag1.intervals = 100 | ||
diag1.diag_type = Full | ||
|
||
warpx.reduced_diags_names = particle_energy particle_momentum particle_number | ||
particle_energy.type = ParticleEnergy | ||
particle_energy.intervals = 10 | ||
particle_energy.precision = 18 | ||
particle_momentum.type = ParticleMomentum | ||
particle_momentum.intervals = 10 | ||
particle_momentum.precision = 18 | ||
particle_number.type = ParticleNumber | ||
particle_number.intervals = 10 | ||
particle_number.precision = 18 |
34 changes: 34 additions & 0 deletions
34
Regression/Checksum/benchmarks_json/test_1d_collision_z_Bremsstrahlung.json
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,34 @@ | ||
{ | ||
"lev=0": { | ||
"Bx": 0.0, | ||
"By": 0.0, | ||
"Bz": 0.0, | ||
"Ex": 0.0, | ||
"Ey": 0.0, | ||
"Ez": 0.0, | ||
"jx": 0.0, | ||
"jy": 0.0, | ||
"jz": 0.0 | ||
}, | ||
"ions": { | ||
"particle_momentum_x": 6.244058618052987e-18, | ||
"particle_momentum_y": 6.266839026611908e-18, | ||
"particle_momentum_z": 6.237937377390938e-18, | ||
"particle_position_x": 0.05119999887292794, | ||
"particle_weight": 5.470000000000001e+25 | ||
}, | ||
"electrons": { | ||
"particle_momentum_x": 1.7754689380349235e-26, | ||
"particle_momentum_y": 1.8019938095335607e-26, | ||
"particle_momentum_z": 7.780447460289813e-17, | ||
"particle_position_x": 0.05119966127601074, | ||
"particle_weight": 5.470000000000001e+24 | ||
}, | ||
"photons": { | ||
"particle_momentum_x": 8.902000149233514e-25, | ||
"particle_momentum_y": 9.022633314982659e-25, | ||
"particle_momentum_z": 1.271533261332079e-18, | ||
"particle_position_x": 0.014344002048764832, | ||
"particle_weight": 1.5380635742187505e+22 | ||
} | ||
} |
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.
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.
Is this to overwrite the ionization state or, since this is a particle-particle mode, can we also rely on the charge / ionization state of the ion we collide with?
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.
The
Z
is only used to indicate the atomic number, which is used to select which cross section data to use from the tables.