1+ import numpy as np
2+ import os
3+ import matplotlib .pyplot as plt
4+ from pylab import rcParams
5+
6+ axis_font = {'fontname' :'Arial' , 'size' :'8' , 'family' :'serif' }
7+ fs = 8
8+ ms = 8
9+ lw = 2
10+
11+ if __name__ == "__main__" :
12+
13+ ref = 'PFASST_BOUSSINESQ_stats_hf_NOFAULT_P16.npz'
14+
15+ list = [ ('PFASST_BOUSSINESQ_stats_hf_SPREAD_P16.npz' ,'SPREAD' ,'1-sided' ,'red' ,'s' ),
16+ ('PFASST_BOUSSINESQ_stats_hf_INTERP_P16.npz' ,'INTERP' ,'2-sided' ,'orange' ,'o' ),
17+ ('PFASST_BOUSSINESQ_stats_hf_SPREAD_PREDICT_P16.npz' ,'SPREAD_PREDICT' ,'1-sided+corr' ,'blue' ,'^' ),
18+ ('PFASST_BOUSSINESQ_stats_hf_INTERP_PREDICT_P16.npz' ,'INTERP_PREDICT' ,'2-sided+corr' ,'green' ,'d' ) ]
19+
20+ nprocs = 16
21+
22+ xtick_dist = 8
23+
24+ minstep = 128
25+ maxstep = 176
26+ # minstep = 0
27+ # maxstep = 320
28+
29+ nblocks = int (320 / nprocs )
30+
31+ # maxiter = 14
32+ nsteps = 0
33+ maxiter = 0
34+ for file ,strategy ,label ,color ,marker in list :
35+
36+ data = np .load (file )
37+
38+ iter_count = data ['iter_count' ][minstep :maxstep ]
39+ residual = data ['residual' ][:,minstep :maxstep ]
40+
41+ residual = np .where (residual > 0 , np .log10 (residual ), - 99 )
42+ vmin = - 9
43+ vmax = int (np .amax (residual ))
44+
45+ maxiter = max (maxiter ,int (max (iter_count )))
46+ nsteps = max (nsteps ,len (iter_count ))
47+
48+ data = np .load (ref )
49+ ref_iter_count = data ['iter_count' ][nprocs - 1 ::nprocs ]
50+
51+ rcParams ['figure.figsize' ] = 6.0 , 2.5
52+ fig , ax = plt .subplots ()
53+
54+ plt .plot (range (nblocks ),[0 ]* nblocks ,'k-' ,linewidth = 2 )
55+
56+ ymin = 99
57+ ymax = 0
58+ for file ,strategy ,label ,color ,marker in list :
59+
60+ if not file is ref :
61+ data = np .load (file )
62+ iter_count = data ['iter_count' ][nprocs - 1 ::nprocs ]
63+
64+ ymin = min (ymin ,min (iter_count - ref_iter_count ))
65+ ymax = max (ymax ,max (iter_count - ref_iter_count ))
66+
67+ plt .plot (range (nblocks ),iter_count - ref_iter_count ,color = color ,label = label ,marker = marker ,linestyle = '' ,linewidth = lw ,markersize = ms )
68+
69+
70+ plt .xlabel ('block' , ** axis_font )
71+ plt .ylabel ('$K_\\ mathrm{add}$' , ** axis_font )
72+ plt .xlim (- 1 ,nblocks )
73+ plt .ylim (- 1 + ymin ,ymax + 1 )
74+ plt .legend (loc = 2 ,numpoints = 1 ,fontsize = fs )
75+ plt .tick_params (axis = 'both' , which = 'major' , labelsize = fs )
76+ ax .xaxis .labelpad = - 0.5
77+ ax .yaxis .labelpad = - 1
78+ plt .tight_layout ()
79+
80+ fname = 'BOUSSINESQ_Kadd_vs_NOFAULT_hf.pdf'
81+ plt .savefig (fname , bbox_inches = 'tight' )
82+ os .system ('pdfcrop ' + fname + ' ' + fname )
83+ # exit()
84+
85+ for file ,strategy ,label ,color ,marker in list :
86+
87+ data = np .load (file )
88+
89+ iter_count = data ['iter_count' ][minstep :maxstep ]
90+ residual = data ['residual' ][:,minstep :maxstep ]
91+ stats = data ['hard_stats' ]
92+
93+ residual = np .where (residual > 0 , np .log10 (residual ), - 99 )
94+
95+ rcParams ['figure.figsize' ] = 6.0 , 2.5
96+ fig , ax = plt .subplots ()
97+
98+ cmap = plt .get_cmap ('Reds' ,vmax - vmin + 1 )
99+ pcol = plt .pcolor (residual ,cmap = cmap ,vmin = vmin ,vmax = vmax )
100+ pcol .set_edgecolor ('face' )
101+
102+ for item in stats :
103+ if item [0 ] in range (minstep ,maxstep ):
104+ plt .text (item [0 ]+ 0.5 - (maxstep - nsteps ),item [1 ]- 1 + 0.5 ,'x' ,horizontalalignment = 'center' ,verticalalignment = 'center' )
105+
106+ plt .axis ([0 ,nsteps ,0 ,maxiter ])
107+
108+ ticks = np .arange (vmin ,vmax + 1 ,2 )
109+ tickpos = np .linspace (ticks [0 ]+ 0.5 , ticks [- 1 ]- 0.5 , len (ticks ))
110+ cax = plt .colorbar (pcol , ticks = tickpos , pad = 0.02 )
111+ cax .set_ticklabels (ticks )
112+ cax .ax .tick_params (labelsize = fs )
113+
114+ cax .set_label ('log10(residual)' , ** axis_font )
115+ plt .tick_params (axis = 'both' , which = 'major' , labelsize = fs )
116+ ax .xaxis .labelpad = - 0.5
117+ ax .yaxis .labelpad = - 0.5
118+
119+ ax .set_xlabel ('step' , ** axis_font )
120+ ax .set_ylabel ('iteration' , ** axis_font )
121+
122+ ax .set_yticks (np .arange (1 ,maxiter ,2 )+ 0.5 , minor = False )
123+ ax .set_xticks (np .arange (0 ,nsteps ,xtick_dist )+ 0.5 , minor = False )
124+ ax .set_yticklabels (np .arange (1 ,maxiter ,2 )+ 1 , minor = False )
125+ ax .set_xticklabels (np .arange (minstep ,maxstep ,xtick_dist ), minor = False )
126+
127+ plt .tight_layout ()
128+
129+ fname = 'BOUSSINESQ_steps_vs_iteration_hf_' + strategy + '.pdf'
130+ plt .savefig (fname , bbox_inches = 'tight' )
131+ os .system ('pdfcrop ' + fname + ' ' + fname )
132+
133+ exit ()
0 commit comments