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

[WIP]Implementation of Bremsstrahlung collisions #5537

Open
wants to merge 38 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
c1a5536
Initial implementation of Bremmstrahlung collisions
dpgrote Jan 3, 2025
7f0f53e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 3, 2025
03d96e0
Fix typo
dpgrote Jan 3, 2025
edf04f9
Small cleanup
dpgrote Jan 3, 2025
e1105c3
Small fixes
dpgrote Jan 4, 2025
2926baa
More cleanup, including const's and prt's
dpgrote Jan 4, 2025
0ab5247
Small fixes
dpgrote Jan 6, 2025
8a147cb
Bug fix
dpgrote Jan 6, 2025
d3b22d7
Fix a variable name
dpgrote Jan 7, 2025
2dcd95a
Initialize p_mask to zero
dpgrote Jan 7, 2025
c50b855
Fix the energy scaling of the generated photons
dpgrote Jan 8, 2025
1bb5422
Improvements to the algorithm
dpgrote Jan 8, 2025
27fe428
Add CI test
dpgrote Jan 13, 2025
3d26245
Make creation of photons optional
dpgrote Jan 13, 2025
43939ca
Add documentation
dpgrote Jan 13, 2025
fd4a0be
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 13, 2025
ed08970
Fix missing semicolon
dpgrote Jan 13, 2025
180a51e
Rewrite the interpolation in Photon_energy
dpgrote Jan 13, 2025
0808815
Fix setting of p_mask when photons are not created
dpgrote Jan 13, 2025
21eaf31
Another small cleanup
dpgrote Jan 13, 2025
2548c27
Small fixes
dpgrote Jan 14, 2025
32a2a2f
Only scale kdsigdk_cut for io_cut == 0
dpgrote Jan 14, 2025
bb265a7
Add comment
dpgrote Jan 14, 2025
f2f34fc
Fix typo
dpgrote Jan 14, 2025
56d5042
Add precalculated cross section
dpgrote Jan 14, 2025
98bc9e8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 14, 2025
eeadf9a
Clean up in analysis_collision_1d_Bremsstrahlung.py
dpgrote Jan 15, 2025
54ff053
Clean up inputs_test_1d_collision_z_Bremsstrahlung
dpgrote Jan 15, 2025
f9756fd
Revert to using the midpoint value of k
dpgrote Jan 20, 2025
7a91252
Fix the sign of the photon energy
dpgrote Jan 20, 2025
2b087e8
Fix const
dpgrote Jan 20, 2025
3267344
Fix CI analysis script
dpgrote Jan 21, 2025
d9b05ca
Clean up auto in Bremsstrahlung/PhotonCreationFunc
dpgrote Jan 21, 2025
0f3e881
Ions are updated, now conserving energy and momentum
dpgrote Jan 22, 2025
0e524a3
Rework the collision to conserve energy and momentum
dpgrote Jan 25, 2025
3e356fe
Use const
dpgrote Jan 27, 2025
0ed4e3e
Expanding some expressions allows cancelling of some terms
dpgrote Jan 27, 2025
87107f2
Update CI benchmark after adding conservation of momentum
dpgrote Jan 27, 2025
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
24 changes: 22 additions & 2 deletions Docs/source/usage/parameters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2059,17 +2059,21 @@ Details about the collision models can be found in the :ref:`theory section <mul
- ``background_stopping`` for slowing of ions due to collisions with electrons or ions.
This implements the approximate formulae as derived in Introduction to Plasma Physics,
from Goldston and Rutherford, section 14.2.
- ``bremsstrahlung`` for slowing of electrons due to Bremsstrahlung collisions with ions.
This uses the cross sections as given by `Seltzer and Berger <https://doi.org/10.1016/0092-640X(86)90014-8>`__.

* ``<collision_name>.species`` (`strings`)
If using ``dsmc``, ``pairwisecoulomb`` or ``nuclearfusion``, this should be the name(s) of the species,
If using ``dsmc``, ``pairwisecoulomb``, ``nuclearfusion``, or ``bremsstrahlung``, this should be the name(s) of the species,
between which the collision will be considered. (Provide only one name for intra-species collisions.)
With ``bremsstrahlung``, the electron species must be given first, followed by the target species.
If using ``background_mcc`` or ``background_stopping`` type this should be the name of the
species for which collisions with a background will be included.
In this case, only one species name should be given.

* ``<collision_name>.product_species`` (`strings`)
Only for ``nuclearfusion``. The name(s) of the species in which to add
Only for ``nuclearfusion`` and ``bremsstrahlung``. The name(s) of the species in which to add
the new macroparticles created by the reaction.
For ``bremsstrahlung``, the product species must be of type photon.

* ``<collision_name>.ndt`` (`int`) optional
Execute collision every # time steps. The default value is 1.
Expand Down Expand Up @@ -2191,6 +2195,22 @@ Details about the collision models can be found in the :ref:`theory section <mul
produced species must also be given. For example if argon properties is used
for the background gas, a species of argon ions should be specified here.

* ``<collision_name>.Z`` (`integer`)
Only for ``bremsstrahlung``. The atomic number of the target ion species.
Currently, only the values 1, 2, 5, 6 are supported.

* ``<collision_name>.multiplier`` (`float`)
Only for ``bremsstrahlung``. Multiplier for the collision probability.
Any resulting photons will have the electron weight divided the multiplier.
The default is 1. This must be greater than or equal to 1.

* ``<collision_name>.create_photons`` (`integer`)
Only for ``bremsstrahlung``. Whether photons will be created, defaults to 1 (true).

* ``<collision_name>.koT1_cut`` (`float`)
Only for ``bremsstrahlung``. Minimum energy of the photons created.
This is relative to the electron energy, defaulting to 1.e-4.

.. _running-cpp-parameters-numerics:

Numerics and algorithms
Expand Down
10 changes: 10 additions & 0 deletions Examples/Tests/collision/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,13 @@ add_warpx_test(
"analysis_default_regression.py --path diags/diag1000150 --skip-particles" # checksum
OFF # dependency
)

add_warpx_test(
test_1d_collision_z_Bremsstrahlung # name
1 # dims
1 # nprocs
inputs_test_1d_collision_z_Bremsstrahlung # inputs
"analysis_collision_1d_Bremsstrahlung.py diags/diag1000100" # analysis
"analysis_default_regression.py --path diags/diag1000100" # checksum
OFF # dependency
)
109 changes: 109 additions & 0 deletions Examples/Tests/collision/analysis_collision_1d_Bremsstrahlung.py
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 Examples/Tests/collision/inputs_test_1d_collision_z_Bremsstrahlung
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
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
},
"electrons": {
"particle_momentum_x": 1.7754689276894523e-26,
"particle_momentum_y": 1.8019937989491576e-26,
"particle_momentum_z": 7.780447460298363e-17,
"particle_position_x": 0.05119966127601259,
"particle_weight": 5.470000000000001e+24
},
"ions": {
"particle_momentum_x": 6.244058618052987e-18,
"particle_momentum_y": 6.266839026611909e-18,
"particle_momentum_z": 6.237937377390828e-18,
"particle_position_x": 0.051199998872927935,
"particle_weight": 5.470000000000001e+25
},
"photons": {
"particle_momentum_x": 8.902000149229396e-25,
"particle_momentum_y": 9.02263331497841e-25,
"particle_momentum_z": 1.2715332613329798e-18,
"particle_position_x": 0.014344002048765016,
"particle_weight": 1.5380635742187505e+22
}
}
Loading
Loading