aboutsummaryrefslogtreecommitdiff
path: root/Examples/Physics_applications/laser_acceleration/analysis_refined_injection.py
blob: e7d26d2cb30f1a3673deae74d9200e7220426827 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python3

# Copyright 2019 Andrew Myers
#
#
# This file is part of WarpX.
#
# License: BSD-3-Clause-LBNL

# This script tests the "warpx.refine_plasma=1" option by comparing
# the actual number of electrons at step 200 to the expected value
import os
import sys

import yt

yt.funcs.mylog.setLevel(50)
import numpy as np

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

# this will be the name of the plot file
fn = sys.argv[1]

# Read the file
ds = yt.load(fn)

# count the number of particles
ad = ds.all_data()
np = ad['electrons', 'particle_id'].size

# the number of coarse particle streams
n_coarse = 10

# the number of fine particle streams
n_fine = 64

# num particles per stream at time 0
n_0 = 15

# number of times the moving window moves, calculated as n_move = (c*t)/dz where c  is speed of light, t is physical time (nsteps*dt). dz is dz on level 0
n_move = 192

# ref ratio = 2 1
# Refined only transversly. Longitudinal spacing between particles in each stream is the same in both coarse and fine regions
rr_longitudinal = 1

np_expected = (n_coarse + n_fine*rr_longitudinal)*(n_0 + n_move)

assert( np == np_expected )

# Test uniformity of rho, by taking a slice of rho that
# crosses the edge of the refined injection region
# (but is ahead of the mesh refinement patch)
ds.force_periodicity()
ad = ds.covering_grid(level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions)
rho = ad['rho'].to_ndarray().squeeze()
rho_slice = rho[13:51, 475]
# Test uniformity up to 0.5% relative variation
assert( rho_slice.std() < 0.005*abs(rho_slice.mean()) )

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