Peano
Loading...
Searching...
No Matches
plot-lift-drop-statistics.py
Go to the documentation of this file.
1"""
2
3 A simple Python script to visualise the number of lifts, drops, ... over
4 the simulation runtime.
5
6"""
7
8
9import os, sys
10import argparse
12
13import matplotlib.pyplot as plt
14
15
16class Dataset:
17 def __init__(self):
19 "lifts": [],
20 "drops": [],
21 "lifts-into-sieve-set": [],
22 "drops-from-sieve-set": [],
23 "skipped-drops-from-sieve-set": [],
24 "reassignments": [],
25 "remaining": [],
26 "expired": [],
27 "leaving": [],
28 "incoming particles (previously known as halos)": [],
29 "incoming particles (previously unseen)": [],
30 "redundantly shared particles (local on multiple trees)": [],
31 "added virtual particles (flying into halo)": [],
32 "replaced virtual particles (halo updates)": [],
33 "dropped virtual particles": [],
34 "eliminated local spatial duplicates": [],
35 "eliminated virtual spatial duplicates": []
36 }
37 self.grid_data = {
38 ("local cells", "refined"): [],
39 ("remote cells", "refined"): [],
40 ("local cells", "unrefined"): [],
41 ("remote cells", "unrefined"): []
42 }
43 pass
44
45 def _getValueFromLine( self, line, key, verbose ):
46 result = 0.0
47 try:
48 rhs = line.split( key + "=" )[1]
49 if "," in rhs:
50 rhs = rhs.split(",")[0]
51 result = float( rhs )
52 except:
53 if verbose:
54 print( "ERROR in line {} for key {}".format(line,key) )
55 return result
56
57 def _getTupleFromLine( self, line, key, verbose ):
58 result = (0.0, 0.0)
59 try:
60 rhs = line.split( key[0] + "=(" )[1].split(")")[0]
61 result = (
62 float( rhs.split("/")[0] ),
63 float( rhs.split("/")[1] )
64 )
65 except:
66 if verbose:
67 print( "ERROR for _getTupleFromLine in line {} for key {}".format(line, key) )
68 return result
69
70
72 key,
73 verbose
74 ):
75 """!
76
77 Return true if entry for key is not empty and not all values are exactly the same
78
79 """
80 if verbose:
81 print( "search for entry for key {}".format(key) )
82 if not key in self.mesh_association_data.keys():
83 if verbose:
84 print( "no key {}".format(key) )
85 return False
86 if len(self.mesh_association_data[key])==0:
87 if verbose:
88 print( "no entry for key {}".format(key) )
89 return False
90 first_mesh_association_data_entry = self.mesh_association_data[key][0]
91 for values in self.mesh_association_data[key]:
92 if first_mesh_association_data_entry!=values:
93 return True
94 return False
95
96 def parse_line(self, line, verbose):
97 if "reduceAndPrintStatistics":
98 for key in self.mesh_association_data.keys():
99 if key in line:
100 self.mesh_association_data[key].append( self._getValueFromLine(line, key, verbose) )
101
102 if "TimeStep":
103 for key in self.grid_data.keys():
104 if key[0] in line:
105 self.grid_data[key].append( self._getTupleFromLine(line, key, verbose) )
106
107
108
109
110def parseParticleGridStatistics( filename, verbose ):
111 file = open( filename, "r" )
112 result = Dataset()
113 for line in file:
114 result.parse_line(line, verbose)
115 return result
116
117
118if __name__ == "__main__":
119 parser = argparse.ArgumentParser( description="ExaHyPE 2 - Particle toolbox postprocessing" )
120 parser.add_argument("file", help="Input file")
121 parser.add_argument("--verbose", "-v", dest="verbose", action="store_true", help="Verbose output")
122 args = parser.parse_args()
123
124 mesh_association_dataset = parseParticleGridStatistics( args.file, args.verbose )
125
126 plt.clf()
127 fig = plt.figure()
128 gs = fig.add_gridspec(2, hspace=0)
129 axs = gs.subplots(sharex=True, sharey=False)
130 for key in mesh_association_dataset.mesh_association_data.keys():
131 if mesh_association_dataset.entry_holds_interesting_data(key, args.verbose):
132 axs[0].plot(mesh_association_dataset.mesh_association_data[key], label=key)
133 for key in mesh_association_dataset.grid_data.keys():
134 try:
135 axs[1].plot(mesh_association_dataset.grid_data[key], label="{}/{}".format(key[0],key[1]))
136 except:
137 print( "ERROR: Cannot find data for {}".format(key) )
138
139 axs[0].legend()
140 axs[1].legend()
141 plt.xlabel("Mesh sweeps")
142 plt.savefig(args.file + ".pdf")
143 plt.savefig(args.file + ".png")
144
145
entry_holds_interesting_data(self, key, verbose)
Return true if entry for key is not empty and not all values are exactly the same.
parseParticleGridStatistics(filename, verbose)
-lift-drop-statistics