Skip to content

Commit

Permalink
new test in linear polarization
Browse files Browse the repository at this point in the history
  • Loading branch information
EyaDammak committed Dec 20, 2024
1 parent ca1fda7 commit c44f343
Show file tree
Hide file tree
Showing 6 changed files with 195 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,12 @@ if(BUILD_TESTING)
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
)

add_test(NAME laser_ionization.1Rank
COMMAND bash ${HiPACE_SOURCE_DIR}/tests/laser_ionization.1Rank.sh
$<TARGET_FILE:HiPACE> ${HiPACE_SOURCE_DIR}
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
)

if (NOT HiPACE_COMPUTE STREQUAL CUDA)

# These tests only run on CPU
Expand Down
46 changes: 46 additions & 0 deletions examples/laser_ionization/analysis_laser_ionization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#! /usr/bin/env python3

#
# This file is part of HiPACE++.
#
# Authors:

import numpy as np
import math
from openpmd_viewer import OpenPMDTimeSeries
import statistics

parser = argparse.ArgumentParser(description='Compare with WarpX the fraction of ionization for a specific value of a0 with a linear polarized laser')
parser.add_argument('--output-dir',
dest='output_dir',
default='new',
help='Path to the directory containing output files')
args = parser.parse_args()

ts = OpenPMDTimeSeries(args.output_dir)

lambda0 = 800.e-9
a0 = 0.00885126
nc = 1.75e27
n0 = nc / 10000

me = 9.1093837015e-31
c = 299792458
qe = 1.602176634e-19
C = me * c * c * 2 * math.pi / (lambda0 * qe)

E0 = C * a0

iteration = 0
rho_elec, _ = ts.get_field(field='rho_elec', coord='z', iteration=iteration, plot=False)
rho_elec_mean = np.mean(rho_elec, axis=(1, 2))
rho_average = statistics.mean(rho_elec_mean[0:10])
fraction = rho_average / (-qe) / (n0)

fraction_warpx = 0.41014984 #result from WarpX simulation

relative_diff = np.abs( ( fraction - fraction_warpx ) / fraction_warpx )
tolerance = 0.1
print("percentage error for the fraction of ionization = "+ str(relative_diff *100) + '%')

assert (relative_diff < tolerance), 'Test laser_ionization did not pass'
61 changes: 61 additions & 0 deletions examples/laser_ionization/input_laser_ionization_linear
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
max_step = 0
hipace.dt = 0
hipace.verbose=3

amr.n_cell =32 32 50

my_constants.kp_inv = 10.e-6

my_constants.nc = 1.75e27
my_constants.n0 = nc/10000

my_constants.a0 = 0.00885126

my_constants.w0_um = 1.e8
my_constants.tau_fs = 30/1.17741
my_constants.lambda0_nm = 800

hipace.file_prefix = new
hipace.do_tiling = 0
hipace.deposit_rho_individual = 1

geometry.prob_lo = -10.*kp_inv -10.*kp_inv -15.*kp_inv #box shifted
geometry.prob_hi = 10.*kp_inv 10.*kp_inv 5.*kp_inv

lasers.names = laser
lasers.lambda0 = lambda0_nm * 1.e-9


laser.a0 = a0
laser.position_mean = 0. 0. 0
laser.w0 = w0_um*1.e-6
laser.tau = tau_fs*1.e-15
laser.focal_distance = 50.e-6

plasmas.names = elec ion

elec.density(x,y,z) = n0
elec.ppc = 0 0
elec.u_mean = 0.0 0.0 0.0
elec.element = electron
elec.neutralize_background = false

ion.density(x,y,z) = n0
ion.ppc = 1 1
ion.u_mean = 0.0 0.0 0.0
ion.element = H
ion.mass_Da = 1.008
ion.initial_ion_level = 0
ion.can_laser_ionize = 1
ion.ionization_product = elec

amr.max_level = 0

diagnostic.output_period = 1

hipace.depos_order_xy = 0

boundary.field = Dirichlet
boundary.particle = Periodic

diagnostic.diag_type = xyz
32 changes: 32 additions & 0 deletions tests/checksum/benchmarks_json/laser_ionization.1Rank.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"lev=0": {
"Bx": 2682248.7057786,
"By": 2693948.2733652,
"Bz": 461542.2571099,
"ExmBy": 1615808685829100.0,
"EypBx": 1618198283855800.0,
"Ez": 661283579146520.0,
"Psi": 10769981642.67,
"Sx": 7.6153143423645e+17,
"Sy": 7.6749662052452e+17,
"chi": 2095164846204800.0,
"jx": 5.1803326176917e+17,
"jx_beam": 231581100098160.0,
"jy": 5.1661888254051e+17,
"jy_beam": 230138001520970.0,
"jz_beam": 1.6907142961472e+17,
"rhomjz": 8996307095.7456
},
"beam": {
"charge": 1.127932350336e-16,
"id": 248160,
"mass": 6.413006125856e-28,
"x": 0.00024861156942758,
"y": 0.00024733653871292,
"z": 0.014359549367752,
"ux": 3002.9712584681,
"uy": 3008.1141100408,
"uz": 1386735.4182493,
"w": 825000000.0
}
}
12 changes: 12 additions & 0 deletions tests/checksum/reset_all_benchmarks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -430,3 +430,15 @@ then
--file_name ${build_dir}/bin/transverse_benchmark.1Rank.sh \
--test-name transverse_benchmark.1Rank.sh
fi

# laser_ionization.1Rank.sh
if [[ $all_tests = true ]] || [[ $one_test_name = "laser_ionization.1Rank.sh" ]]
then
cd $build_dir
ctest --output-on-failure -R laser_ionization.1Rank.sh \
|| echo "ctest command failed, maybe just because checksums are different. Keep going"
cd $checksum_dir
./checksumAPI.py --reset-benchmark \
--file_name ${build_dir}/bin/laser_ionization.1Rank \
--test-name laser_ionization.1Rank
fi
38 changes: 38 additions & 0 deletions tests/laser_ionization.1Rank.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#! /usr/bin/env bash

#
# This file is part of HiPACE++.
#
# Authors: EyaDammak


# This file is part of the HiPACE++ test suite.
# It runs a Hipace simulation with in neutral hydrogen that gets ionized by the laser

# abort on first encounted error
set -eu -o pipefail

# Read input parameters
HIPACE_EXECUTABLE=$1
HIPACE_SOURCE_DIR=$2

HIPACE_EXAMPLE_DIR=${HIPACE_SOURCE_DIR}/examples/laser_ionization
HIPACE_TEST_DIR=${HIPACE_SOURCE_DIR}/tests

FILE_NAME=`basename "$0"`
TEST_NAME="${FILE_NAME%.*}"

rm -rf $TEST_NAME

# Run the simulation
mpiexec -n 1 $HIPACE_EXECUTABLE $HIPACE_EXAMPLE_DIR/input_laser_ionization_linear

# Compare the result with theory
$HIPACE_EXAMPLE_DIR/analysis_laser_ionization.py

# Compare the results with checksum benchmark
$HIPACE_TEST_DIR/checksum/checksumAPI.py \
--evaluate \
--file_name $TEST_NAME \
--test-name $TEST_NAME

0 comments on commit c44f343

Please sign in to comment.