aboutsummaryrefslogtreecommitdiff
path: root/Examples/Tests/nci_fdtd_stability/analysis_ncicorr.py
blob: 118b03fed89e07b68de9f0a88359a8b2bfc39932 (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
#!/usr/bin/env python3

# Copyright 2019 Jean-Luc Vay, Maxence Thevenet, Remi Lehe
# Weiqun Zhang
#
# This file is part of WarpX.
#
# License: BSD-3-Clause-LBNL


import os
import re
import sys

import numpy as np
import scipy.constants as scc
import yt

yt.funcs.mylog.setLevel(0)

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

fn = sys.argv[1]
use_MR = re.search( 'nci_correctorMR', fn ) != None

if use_MR:
    energy_corrector_off = 5.e32
    energy_threshold = 1.e28
else:
    energy_corrector_off = 1.5e26
    energy_threshold = 1.e24

# Check EB energy after 1000 timesteps
filename = sys.argv[1]

ds = yt.load( filename )
ad0 = ds.covering_grid(level=0,left_edge=ds.domain_left_edge, dims=ds.domain_dimensions)
ex = ad0['boxlib', 'Ex'].v
ez = ad0['boxlib', 'Ez'].v
by = ad0['boxlib', 'By'].v
energy = np.sum(ex**2 + ez**2 + scc.c**2*by**2)

print("use_MR: %s" %use_MR)
print("energy if corrector off (from benchmark): %s" %energy_corrector_off)
print("energy threshold (from benchmark): %s" %energy_threshold)
print("energy from this run: %s" %energy)

assert( energy < energy_threshold )

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