From ed808e2422cca628918bcdda5f6364ab1c88e38c Mon Sep 17 00:00:00 2001 From: Arianna Formenti Date: Tue, 6 Feb 2024 21:07:11 -0800 Subject: [PATCH] ci test --- Examples/Tests/focusing_beam/plot.py | 61 -------------- .../gaussian_beam/analysis_focusing_beam.py | 83 +++++++++++++++++++ .../inputs_focusing_beam} | 34 ++++---- .../focusing_gaussian_beam.json | 12 +++ Regression/WarpX-tests.ini | 21 +++++ 5 files changed, 132 insertions(+), 79 deletions(-) delete mode 100644 Examples/Tests/focusing_beam/plot.py create mode 100644 Examples/Tests/gaussian_beam/analysis_focusing_beam.py rename Examples/Tests/{focusing_beam/input.txt => gaussian_beam/inputs_focusing_beam} (85%) create mode 100644 Regression/Checksum/benchmarks_json/focusing_gaussian_beam.json diff --git a/Examples/Tests/focusing_beam/plot.py b/Examples/Tests/focusing_beam/plot.py deleted file mode 100644 index ec3624e1c9b..00000000000 --- a/Examples/Tests/focusing_beam/plot.py +++ /dev/null @@ -1,61 +0,0 @@ -import os - -from matplotlib import cm, rcParams, use -from matplotlib.colors import ( - LinearSegmentedColormap, - ListedColormap, - LogNorm, - Normalize, - SymLogNorm, -) -import matplotlib.pyplot as plt -from mpl_toolkits.axes_grid1 import make_axes_locatable -import numpy as np -import openpmd_api as io -from scipy.constants import c -from scipy.constants import e as q_e -from scipy.constants import eV, m_e, micro, milli, nano - -mydir='.' -path=os.path.join(mydir, 'diags/full') -series = io.Series(path+"/openpmd_%T.bp", io.Access.read_only) -iterations = np.asarray(series.iterations) - -my_dpi=300. - - -for n,ts in enumerate(iterations): - - fig, ax = plt.subplots(ncols=1, nrows=3, figsize=(1500./my_dpi, 4500./my_dpi), dpi=my_dpi) - it = series.iterations[ts] - - 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() - print(len(w)) - ax[0].scatter(z,x,color='blue') - ax[1].scatter(z,y,color='blue') - ax[2].scatter(x,y,color='blue') - - it.close() - - for a in ax.reshape(-1): - a.set_aspect('auto') - - ax[0].set_xlabel(r'z') - ax[0].set_ylabel(r'x') - - ax[1].set_xlabel(r'z') - ax[1].set_ylabel(r'y') - - ax[2].set_xlabel(r'x') - ax[2].set_ylabel(r'y') - - - image_file_name =os.path.join('TEST_%04d.png' % n) - plt.tight_layout() - plt.savefig(image_file_name,dpi=my_dpi, bbox_inches='tight') - plt.close("all") diff --git a/Examples/Tests/gaussian_beam/analysis_focusing_beam.py b/Examples/Tests/gaussian_beam/analysis_focusing_beam.py new file mode 100644 index 00000000000..74d54a27095 --- /dev/null +++ b/Examples/Tests/gaussian_beam/analysis_focusing_beam.py @@ -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) + + + + diff --git a/Examples/Tests/focusing_beam/input.txt b/Examples/Tests/gaussian_beam/inputs_focusing_beam similarity index 85% rename from Examples/Tests/focusing_beam/input.txt rename to Examples/Tests/gaussian_beam/inputs_focusing_beam index 3d3d3245ca5..5ba9d20c1fe 100644 --- a/Examples/Tests/focusing_beam/input.txt +++ b/Examples/Tests/gaussian_beam/inputs_focusing_beam @@ -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 @@ -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 @@ -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 + + diff --git a/Regression/Checksum/benchmarks_json/focusing_gaussian_beam.json b/Regression/Checksum/benchmarks_json/focusing_gaussian_beam.json new file mode 100644 index 00000000000..098d18f95ff --- /dev/null +++ b/Regression/Checksum/benchmarks_json/focusing_gaussian_beam.json @@ -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 + }, + +} diff --git a/Regression/WarpX-tests.ini b/Regression/WarpX-tests.ini index 75939c1fd12..427b7a96a73 100644 --- a/Regression/WarpX-tests.ini +++ b/Regression/WarpX-tests.ini @@ -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 + + +