Skip to content

Commit

Permalink
ci test
Browse files Browse the repository at this point in the history
  • Loading branch information
aeriforme committed Feb 7, 2024
1 parent afa232a commit ed808e2
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 79 deletions.
61 changes: 0 additions & 61 deletions Examples/Tests/focusing_beam/plot.py

This file was deleted.

83 changes: 83 additions & 0 deletions Examples/Tests/gaussian_beam/analysis_focusing_beam.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/usr/bin/env python3

# Copyright 2019 Maxence Thevenet, Revathi Jambunathan, Arianna Formenti
#
# This file is part of WarpX.
#
# License: BSD-3-Clause-LBNL


import os
import sys

import numpy as np
import openpmd_api as io
from scipy.constants import c, e as q_e, eV, m_e, micro, nano

sys.path.insert(1, '../../../../warpx/Regression/Checksum/')
import checksumAPI


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 = 5*micro
emity = 35*nano
focal_distance = 4*sigmaz


def s(z, sigma0, emit):
return np.sqrt(sigma0**2 + emit**2 * (z - focal_distance)**2 / sigma0**2)


filename = sys.argv[1]
series = io.Series("./diags/full/openpmd_%T.bp", io.Access.read_only)


it = series.iterations[0]
ps = it.particles["beam1"]
x = ps["position"]["x"].load_chunk()
y = ps["position"]["y"].load_chunk()
z = ps["position"]["z"].load_chunk()
w = ps["weighting"][io.Mesh_Record_Component.SCALAR].load_chunk()
series.flush()

it.close()
del series

imin = np.argmin(np.sqrt((gridz+focal_distance)**2))
imax = np.argmin(np.sqrt((gridz-focal_distance)**2))


sx, sy = [], []

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])))

sx_theory = s(subgrid, sigmax, emitx/gamma)
sy_theory = s(subgrid, sigmay, emity/gamma)

print('XXXXXXXXXXXXXXXXXXXXXXXX')
assert(np.allclose(sx, sx_theory, rtol=0.12, atol=0))
assert(np.allclose(sy, sy_theory, rtol=0.12, atol=0))


test_name = os.path.split(os.getcwd())[1]
checksumAPI.evaluate_checksum(test_name, filename)




Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
my_constants.mc2 = m_e*clight*clight
my_constants.nano = 1.0e-9
my_constants.micro = 1.e-6
my_constants.milli = 1.e-3
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 = 10000
my_constants.nmacropart = 1000000
my_constants.charge = q_e * npart

my_constants.sigmax = 516.0*nano
Expand Down Expand Up @@ -43,15 +42,13 @@ my_constants.Lz = 20*sigmaz
my_constants.nx = 256
my_constants.ny = 256
my_constants.nz = 256
my_constants.dx = Lx/nx
my_constants.dy = Ly/ny
my_constants.dz = Lz/nz



#################################
####### GENERAL PARAMETERS ######
#################################
max_step = 0
max_step = 2
amr.n_cell = nx ny nz
amr.max_grid_size = 256
amr.blocking_factor = 2
Expand Down Expand Up @@ -102,15 +99,16 @@ beam1.uz_th = duz
######### DIAGNOSTICS ###########
#################################
# FULL
diagnostics.diags_names = full


full.intervals = 1
full.diag_type = Full
full.write_species = 1
full.fields_to_plot = rho_beam1
full.format = openpmd
full.openpmd_backend = bp
full.dump_last_timestep = 1
full.coarsening_ratio = 1 1 1
full.species = beam1
diagnostics.diags_names = diag1

diag1.intervals = 1
diag1.diag_type = Full
diag1.write_species = 1
diag1.species = beam1
diag1.beam1.variables = w
diag1.fields_to_plot = rho_beam1
diag1.format = openpmd
diag1.openpmd_backend = bp
diag1.dump_last_timestep = 1


12 changes: 12 additions & 0 deletions Regression/Checksum/benchmarks_json/focusing_gaussian_beam.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"beam1": {
"particle_momentum_x": 4.178482505909375e-19,
"particle_momentum_y": 4.56492260137707e-19,
"particle_momentum_z": 2.733972888170628e-17,
"particle_position_x": 0.0003995213395426269,
"particle_position_y": 0.0004148795632360405,
"particle_position_z": 1.901942694291968,
"particle_weight": 3120754537.230381
},

}
21 changes: 21 additions & 0 deletions Regression/WarpX-tests.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4531,3 +4531,24 @@ compileTest = 0
doVis = 0
compareParticles = 1
analysisRoutine = Examples/Tests/Implicit/analysis_1d.py

[focusing_gaussian_beam]
buildDir = .
inputFile = Examples/Tests/gaussian_beam/inputs_focusing_beam
runtime_params =
dim = 3
addToCompileString = USE_OPENPMD=TRUE
cmakeSetupOpts = -DWarpX_DIMS=3 -DWarpX_OPENPMD=ON
restartTest = 0
useMPI = 1
numprocs = 2
useOMP = 1
numthreads = 1
compileTest = 0
doVis = 0
compareParticles = 0
doComparison = 0
analysisRoutine = Examples/Tests/gaussian_beam/analysis_focusing_beam.py



0 comments on commit ed808e2

Please sign in to comment.