-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add focusing position to Gaussian beam initialization (#4639)
* add focusing position * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * removed prints * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix stashed * generalized to focal distance * first test * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * ci test * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix formatting in benchmark checksums * updated test and start docs * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * updated test * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * focal distance is optional * updated test * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fixed unused variables vbulk * updated docs * updated test * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * reset benchmark * vx vy mistake * fix conversion error clang tidy * fix clang tidy error * fix typo * Update Docs/source/usage/parameters.rst Co-authored-by: Remi Lehe <remi.lehe@normalesup.org> * Update Examples/Tests/gaussian_beam/analysis_focusing_beam.py Co-authored-by: Remi Lehe <remi.lehe@normalesup.org> * Update Examples/Tests/gaussian_beam/analysis_focusing_beam.py Co-authored-by: Remi Lehe <remi.lehe@normalesup.org> * Update Source/Particles/PhysicalParticleContainer.cpp Co-authored-by: Remi Lehe <remi.lehe@normalesup.org> * Update Examples/Tests/gaussian_beam/analysis_focusing_beam.py Co-authored-by: Remi Lehe <remi.lehe@normalesup.org> * Update Source/Particles/PhysicalParticleContainer.cpp Co-authored-by: Remi Lehe <remi.lehe@normalesup.org> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update Source/Particles/PhysicalParticleContainer.cpp Co-authored-by: Remi Lehe <remi.lehe@normalesup.org> * Update Source/Particles/PhysicalParticleContainer.cpp Co-authored-by: Remi Lehe <remi.lehe@normalesup.org> * integrate comments by remi * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * remove unused variable * reset benchmark * fix v_dot_n * Update Source/Particles/PhysicalParticleContainer.cpp Co-authored-by: Remi Lehe <remi.lehe@normalesup.org> * Update Source/Particles/PhysicalParticleContainer.cpp Co-authored-by: Remi Lehe <remi.lehe@normalesup.org> * Update Source/Particles/PhysicalParticleContainer.cpp Co-authored-by: Remi Lehe <remi.lehe@normalesup.org> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Tools <warpx@lbl.gov> Co-authored-by: Remi Lehe <remi.lehe@normalesup.org>
- Loading branch information
1 parent
07738d3
commit d45d173
Showing
9 changed files
with
282 additions
and
10 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Copyright 2024 Arianna Formenti | ||
# | ||
# This file is part of WarpX. | ||
# | ||
# License: BSD-3-Clause-LBNL | ||
|
||
|
||
import os | ||
import sys | ||
|
||
import numpy as np | ||
from scipy.constants import c, eV, m_e, micro, nano | ||
|
||
sys.path.insert(1, '../../../../warpx/Regression/Checksum/') | ||
|
||
import checksumAPI | ||
from openpmd_viewer import OpenPMDTimeSeries | ||
|
||
GeV=1e9*eV | ||
energy = 125.*GeV | ||
gamma = energy/(m_e*c**2) | ||
sigmax = 516.0*nano | ||
sigmay = 7.7*nano | ||
sigmaz = 300.*micro | ||
nz = 256 | ||
Lz = 20*sigmaz | ||
gridz = np.linspace(-0.5*Lz, 0.5*Lz, nz) | ||
tol = gridz[1] - gridz[0] | ||
emitx = 50*micro | ||
emity = 20*nano | ||
focal_distance = 4*sigmaz | ||
|
||
def s(z, sigma0, emit): | ||
'''The theoretical size of a focusing beam (in the absence of space charge), | ||
at position z, given its emittance and size at focus.''' | ||
return np.sqrt(sigma0**2 + emit**2 * (z - focal_distance)**2 / sigma0**2) | ||
|
||
filename = sys.argv[1] | ||
|
||
ts = OpenPMDTimeSeries('./diags/openpmd/') | ||
|
||
x, y, z, w, = ts.get_particle( ['x', 'y', 'z', 'w'], species='beam1', iteration=0, plot=False) | ||
|
||
imin = np.argmin(np.sqrt((gridz+0.8*focal_distance)**2)) | ||
imax = np.argmin(np.sqrt((gridz-0.8*focal_distance)**2)) | ||
|
||
sx, sy = [], [] | ||
# Compute the size of the beam in each z slice | ||
subgrid = gridz[imin:imax] | ||
for d in subgrid: | ||
i = np.sqrt((z - d)**2) < tol | ||
if (np.sum(i)!=0): | ||
mux = np.average(x[i], weights=w[i]) | ||
muy = np.average(y[i], weights=w[i]) | ||
sx.append(np.sqrt(np.average((x[i]-mux)**2, weights=w[i]))) | ||
sy.append(np.sqrt(np.average((y[i]-muy)**2, weights=w[i]))) | ||
|
||
# Theoretical prediction for the size of the beam in each z slice | ||
sx_theory = s(subgrid, sigmax, emitx/gamma) | ||
sy_theory = s(subgrid, sigmay, emity/gamma) | ||
|
||
assert(np.allclose(sx, sx_theory, rtol=0.051, atol=0)) | ||
assert(np.allclose(sy, sy_theory, rtol=0.038, atol=0)) | ||
|
||
test_name = os.path.split(os.getcwd())[1] | ||
checksumAPI.evaluate_checksum(test_name, filename) |
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,120 @@ | ||
################################# | ||
########## MY CONSTANTS ######### | ||
################################# | ||
my_constants.mc2 = m_e*clight*clight | ||
my_constants.nano = 1.0e-9 | ||
my_constants.micro = 1.e-6 | ||
my_constants.GeV = q_e*1.e9 | ||
|
||
# BEAMS | ||
my_constants.energy = 125.*GeV | ||
my_constants.gamma = energy/mc2 | ||
my_constants.npart = 2.e10 | ||
my_constants.nmacropart = 1000000 | ||
my_constants.charge = q_e * npart | ||
|
||
my_constants.sigmax = 516.0*nano | ||
my_constants.sigmay = 7.7*nano | ||
my_constants.sigmaz = 300.*micro | ||
|
||
my_constants.mux = 0.0 | ||
my_constants.muy = 0.0 | ||
my_constants.muz = 0.0 | ||
|
||
my_constants.ux = 0.0 | ||
my_constants.uy = 0.0 | ||
my_constants.uz = gamma | ||
|
||
my_constants.emitx = 50*micro | ||
my_constants.emity = 20*nano | ||
my_constants.emitz = 0. | ||
|
||
my_constants.dux = emitx / sigmax | ||
my_constants.duy = emity / sigmay | ||
my_constants.duz = emitz / sigmaz | ||
|
||
my_constants.focal_distance = 4*sigmaz | ||
|
||
# BOX | ||
my_constants.Lx = 20*sigmax | ||
my_constants.Ly = 20*sigmay | ||
my_constants.Lz = 20*sigmaz | ||
my_constants.nx = 256 | ||
my_constants.ny = 256 | ||
my_constants.nz = 256 | ||
|
||
|
||
|
||
################################# | ||
####### GENERAL PARAMETERS ###### | ||
################################# | ||
max_step = 0 | ||
amr.n_cell = nx ny nz | ||
amr.max_grid_size = 256 | ||
amr.blocking_factor = 2 | ||
amr.max_level = 0 | ||
geometry.dims = 3 | ||
geometry.prob_lo = -0.5*Lx -0.5*Ly -0.5*Lz | ||
geometry.prob_hi = 0.5*Lx 0.5*Ly 0.5*Lz | ||
|
||
################################# | ||
######## BOUNDARY CONDITION ##### | ||
################################# | ||
boundary.field_lo = PEC PEC PEC | ||
boundary.field_hi = PEC PEC PEC | ||
boundary.particle_lo = Absorbing Absorbing Absorbing | ||
boundary.particle_hi = Absorbing Absorbing Absorbing | ||
|
||
################################# | ||
############ NUMERICS ########### | ||
################################# | ||
algo.particle_shape = 3 | ||
|
||
################################# | ||
########### PARTICLES ########### | ||
################################# | ||
particles.species_names = beam1 | ||
|
||
beam1.species_type = electron | ||
beam1.injection_style = gaussian_beam | ||
beam1.x_rms = sigmax | ||
beam1.y_rms = sigmay | ||
beam1.z_rms = sigmaz | ||
beam1.x_m = muy | ||
beam1.y_m = mux | ||
beam1.z_m = muz | ||
beam1.focal_distance = focal_distance | ||
beam1.npart = nmacropart | ||
beam1.q_tot = -charge | ||
|
||
beam1.momentum_distribution_type = gaussian | ||
beam1.ux_m = ux | ||
beam1.uy_m = uy | ||
beam1.uz_m = uz | ||
beam1.ux_th = dux | ||
beam1.uy_th = duy | ||
beam1.uz_th = duz | ||
|
||
################################# | ||
######### DIAGNOSTICS ########### | ||
################################# | ||
# FULL | ||
diagnostics.diags_names = diag1 openpmd | ||
|
||
diag1.intervals = 1 | ||
diag1.diag_type = Full | ||
diag1.write_species = 1 | ||
diag1.species = beam1 | ||
diag1.fields_to_plot = rho_beam1 | ||
diag1.format = plotfile | ||
diag1.dump_last_timestep = 1 | ||
|
||
|
||
openpmd.intervals = 1 | ||
openpmd.diag_type = Full | ||
openpmd.write_species = 1 | ||
openpmd.species = beam1 | ||
openpmd.beam1.variables = w x y z | ||
openpmd.fields_to_plot = none | ||
openpmd.format = openpmd | ||
openpmd.dump_last_timestep = 1 |
14 changes: 14 additions & 0 deletions
14
Regression/Checksum/benchmarks_json/focusing_gaussian_beam.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,14 @@ | ||
{ | ||
"lev=0": { | ||
"rho_beam1": 5637659324885.731 | ||
}, | ||
"beam1": { | ||
"particle_momentum_x": 2.113335069047891e-14, | ||
"particle_momentum_y": 5.653782702472731e-16, | ||
"particle_momentum_z": 6.68023056405556e-11, | ||
"particle_position_x": 0.5640698094900541, | ||
"particle_position_y": 0.011947117763454793, | ||
"particle_position_z": 239.4325333696459, | ||
"particle_weight": 19999620000.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
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