aboutsummaryrefslogtreecommitdiff
path: root/Examples/Tests/pass_mpi_communicator/analysis.py
blob: db23c70473acf6683738a9806788cecd8807fa53 (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
#!/usr/bin/env python3

# This is a script that analyses the simulation results from
# the script `PICMI_inputs_2d`.

import sys

import matplotlib

matplotlib.use('Agg')
import yt

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

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

# this will be the name of the first plot file
fn1 = "Python_pass_mpi_comm_plt1_00010"
# second plot file
fn2 = "Python_pass_mpi_comm_plt2_00010"

test_name1 = fn1[:-9]
test_name2 = fn2[:-9]


checksum1 = checksum.Checksum(test_name1, fn1, do_fields=True,
                             do_particles=True)

checksum2 = checksum.Checksum(test_name2, fn2, do_fields=True,
                             do_particles=True)

rtol=1.e-9
atol=1.e-40

# Evaluate checksums against each other, adapted from
# Checksum.evaluate() method

# Dictionaries have same outer keys (levels, species)?
if (checksum1.data.keys() != checksum2.data.keys()):
    print("ERROR: plotfile 1 and plotfile 2 checksums "
            "have different outer keys:")
    print("Plot1: %s" % checksum1.data.keys())
    print("Plot2: %s" % checksum2.data.keys())
    sys.exit(1)

# Dictionaries have same inner keys (field and particle quantities)?
for key1 in checksum1.data.keys():
    if (checksum1.data[key1].keys() != checksum2.data[key1].keys()):
        print("ERROR: plotfile 1 and plotfile 2 checksums have "
                "different inner keys:")
        print("Common outer keys: %s" % checksum2.data.keys())
        print("Plotfile 1 inner keys in %s: %s"
                % (key1, checksum1.data[key1].keys()))
        print("Plotfile 2 inner keys in %s: %s"
                % (key1, checksum2.data[key1].keys()))
        sys.exit(1)

# Dictionaries have same values?
checksums_same = False
for key1 in checksum1.data.keys():
    for key2 in checksum1.data[key1].keys():
        passed = np.isclose(checksum2.data[key1][key2],
                            checksum1.data[key1][key2],
                            rtol=rtol, atol=atol)
        # skip over these, since they will be the same if communicators
        # have same number of procs
        if key2 in ["particle_cpu", "particle_id", "particle_position_y"]:
            continue
        if passed:
            print("ERROR: plotfile 1 and plotfile 2 checksums have "
                    "same values for key [%s,%s]" % (key1, key2))
            print("Plotfile 1: [%s,%s] %.15e"
                    % (key1, key2, checksum1.data[key1][key2]))
            print("Plotfile 2: [%s,%s] %.15e"
                    % (key1, key2, checksum2.data[key1][key2]))
            checksums_same = True
if checksums_same:
    sys.exit(1)