aboutsummaryrefslogtreecommitdiff
path: root/Examples/Modules/ionization/analysis_ionization.py
blob: d81e04345fb740e29561b97b767a89329062a96b (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env python3

# Copyright 2019-2020 Luca Fedeli, Maxence Thevenet
#
# This file is part of WarpX.
#
# License: BSD-3-Clause-LBNL


"""
This script tests the result of the ionization module in WarpX.

Input files inputs.rt and inputs.bf.rt are used to reproduce the test from
Chen, JCP, 2013, figure 2 (in the lab frame and in a boosted frame,
respectively): a plane-wave laser pulse propagates through a
uniform N2+ neutral plasma and further ionizes the Nitrogen atoms. This test
checks that, after the laser went through the plasma, ~32% of Nitrogen
ions are N5+, in agreement with theory from Chen's article.
"""

import os
import sys

import numpy as np
import yt

yt.funcs.mylog.setLevel(0)
sys.path.insert(1, '../../../../warpx/Regression/Checksum/')
import checksumAPI

# Open plotfile specified in command line, and get ion's ionization level.
filename = sys.argv[1]
ds = yt.load( filename )
ad = ds.all_data()
ilev = ad['ions', 'particle_ionization_level'].v

# Fraction of Nitrogen ions that are N5+.
N5_fraction = ilev[ilev == 5].size/float(ilev.size)

print("Number of ions: " + str(ilev.size))
print("Number of N5+ : " + str(ilev[ilev == 5].size))
print("N5_fraction   : " + str(N5_fraction))

do_plot = False
if do_plot:
    import matplotlib.pyplot as plt
    all_data_level_0 = ds.covering_grid(level=0,left_edge=ds.domain_left_edge,
                                        dims=ds.domain_dimensions)
    F = all_data_level_0['boxlib', 'Ex'].v.squeeze()
    extent = [ ds.domain_left_edge[1], ds.domain_right_edge[1],
               ds.domain_left_edge[0], ds.domain_right_edge[0] ]
    ad = ds.all_data()

    # Plot ions with ionization levels
    species = 'ions';
    xi = ad[species, 'particle_position_x'].v
    zi = ad[species, 'particle_position_y'].v
    ii = ad[species, 'particle_ionization_level'].v
    plt.figure(figsize=(10,10))
    plt.subplot(211)
    plt.imshow(np.abs(F), extent=extent, aspect='auto',
               cmap='magma', origin='default')
    plt.colorbar()
    for lev in range(int(np.max(ii)+1)):
        select = (ii == lev)
        plt.scatter(zi[select],xi[select],s=.2,
                    label='ionization level: ' + str(lev))
    plt.legend()
    plt.title("abs(Ex) (V/m) and ions")
    plt.xlabel("z (m)")
    plt.ylabel("x (m)")
    plt.subplot(212)
    plt.imshow(np.abs(F), extent=extent, aspect='auto',
               cmap='magma', origin='default')
    plt.colorbar()

    # Plot electrons
    species = 'electrons';
    if species in [x[0] for x in ds.field_list]:
        xe = ad[species, 'particle_position_x'].v
        ze = ad[species, 'particle_position_y'].v
        plt.scatter(ze,xe,s=.1,c='r',label='electrons')
    plt.title("abs(Ex) (V/m) and electrons")
    plt.xlabel("z (m)")
    plt.ylabel("x (m)")
    plt.savefig("image_ionization.pdf", bbox_inches='tight')

error_rel = abs(N5_fraction-0.32) / 0.32
tolerance_rel = 0.07

print("error_rel    : " + str(error_rel))
print("tolerance_rel: " + str(tolerance_rel))

assert( error_rel < tolerance_rel )

test_name = os.path.split(os.getcwd())[1]
checksumAPI.evaluate_checksum(test_name, filename)
t='13' alt='Gravatar' /> Jarred Sumner 1-2/+4 2023-07-28Fix bug with `/path/to/absolute/bun.lockb`Gravatar Jarred Sumner 1-10/+13 2023-07-28markBindingGravatar Dylan Conway 1-0/+1 2023-07-28optional parameterGravatar Dylan Conway 1-3/+3 2023-07-28Fixes #3868Gravatar Jarred Sumner 1-2/+3 2023-07-28Fix assertion failure and possible infinite loop when printing as yarn lock f...Gravatar Jarred Sumner 2-3/+16 2023-07-28Mark broken test as todoGravatar Jarred Sumner 2-1/+5 2023-07-28fix types and add message channel/port gc testGravatar Dylan Conway 2-62/+18 2023-07-28`MessageChannel` and `MessagePort` (#3860)Gravatar Dylan Conway 57-247/+3752 2023-07-28mark tests as todoGravatar Jarred Sumner 2-81/+75 2023-07-28add fork to child_process (#3851)Gravatar Vlad Sirenko 7-19/+446 2023-07-28feat(bun/test): Impl. expect().pass() & expect().fail() (#3843)Gravatar Tiramify (A.K. Daniel) 6-5/+212 2023-07-28fix the chunk boundary (`node:stream:createReadStream`) (#3853)Gravatar Ai Hoshino 3-8/+90 2023-07-28Support file: URLs in `fetch` (#3858)Gravatar Jarred Sumner 6-183/+281 2023-07-28fix(tls) exposes native canonicalizeIP and fix rootCertificates (#3866)Gravatar Ciro Spaciari 7-29/+125 2023-07-28Fixes #3795 (#3856)Gravatar Jarred Sumner 11-6/+140 2023-07-28Add todoGravatar Jarred Sumner 2-0/+8 2023-07-28Update pull_request_template.mdGravatar Jarred Sumner 1-1/+1 2023-07-28Update pull_request_template.mdGravatar Jarred Sumner 1-11/+16 2023-07-27Fix bug with // @bun annotation in main thread (#3855)Gravatar Jarred Sumner 4-2/+53 2023-07-27Add `Bun.isMainThread`Gravatar Jarred Sumner 7-3/+48 2023-07-27Uncomment testGravatar Jarred Sumner 1-1/+1 2023-07-27Resolve watch directories outside main thread + async iterator and symlink fi...Gravatar Ciro Spaciari 8-197/+523 2023-07-27Update pull_request_template.mdGravatar Jarred Sumner 1-1/+1 2023-07-27Update pull_request_template.mdGravatar Jarred Sumner 1-1/+1 2023-07-27Update pull_request_template.mdGravatar Jarred Sumner 1-1/+1 2023-07-27Update pull_request_template.mdGravatar Jarred Sumner 1-2/+2 2023-07-27Update pull_request_template.mdGravatar Jarred Sumner 1-0/+4 2023-07-27Update pull_request_template.mdGravatar Jarred Sumner 1-5/+11