Skip to content

Commit e56e3ae

Browse files
committed
postprocessing for boussinesq
1 parent 42ecc33 commit e56e3ae

File tree

2 files changed

+134
-48
lines changed

2 files changed

+134
-48
lines changed
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
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()

examples/fault_tolerance/postproc_grayscott.py

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
if __name__ == "__main__":
1212

1313
ref = 'PFASST_GRAYSCOTT_stats_hf_NOFAULT_P32.npz'
14-
# ref = 'PFASST_GRAYSCOTT_stats_hf_SPREAD_P32.npz'
1514

16-
# list = [('PFASST_GRAYSCOTT_stats_hf_INTERP_PREDICT_P32.npz','2-sided+corr','green','o')]
1715
list = [ ('PFASST_GRAYSCOTT_stats_hf_SPREAD_P32.npz','SPREAD','1-sided','red','s'),
1816
('PFASST_GRAYSCOTT_stats_hf_INTERP_P32.npz','INTERP','2-sided','orange','o'),
1917
('PFASST_GRAYSCOTT_stats_hf_SPREAD_PREDICT_P32.npz','SPREAD_PREDICT','1-sided+corr','blue','^'),
@@ -132,49 +130,4 @@
132130
plt.savefig(fname, bbox_inches='tight')
133131
os.system('pdfcrop '+fname+' '+fname)
134132

135-
exit()
136-
137-
fig, ax = plt.subplots(figsize=(20,7))
138-
139-
# nblocks = int((maxstep-minstep)/nprocs)
140-
nblocks = 20
141-
142-
data = np.load('PFASST_GRAYSCOTT_stats_hf_NOFAULT_P32.npz')
143-
144-
iter_count = data['iter_count'][:]
145-
146-
iterblocks = np.zeros(nblocks)
147-
iterblocks[:] = iter_count[nprocs-1::nprocs]
148-
# for i in range(nblocks):
149-
# iterblocks[i] = np.sum(iter_count[i*nprocs:(i+1)*nprocs])/nprocs
150-
151-
miniter = np.amin(iterblocks)
152-
153-
plt.plot(range(1,nblocks+1),iterblocks,color='k',label='no fault',marker='',linestyle='--',linewidth=lw,markersize=12)
154-
155-
for file,strategy,label,color,marker in list:
156-
157-
data = np.load(file)
158-
159-
iter_count = data['iter_count']
160-
161-
iterblocks = np.zeros(nblocks)
162-
iterblocks[:] = iter_count[nprocs-1::nprocs]
163-
# for i in range(nblocks):
164-
# iterblocks[i] = np.sum(iter_count[i*nprocs:(i+1)*nprocs])/nprocs
165-
166-
plt.plot(range(1,nblocks+1),iterblocks,color=color,label=label,marker=marker,linestyle='-',linewidth=lw,markersize=12)
167-
168-
plt.xlabel('block')
169-
plt.ylabel('number of iterations')
170-
plt.xlim(0.5,nblocks+0.5)
171-
plt.ylim(miniter-0.5,maxiter+0.5)
172-
ax.set_xticks(np.arange(1,nblocks+1), minor=False)
173-
# ax.set_xticklabels(np.arange(minstep,maxstep,xtick_dist), minor=False)
174-
plt.legend(loc=2,numpoints=1)
175-
176-
plt.tight_layout()
177-
178-
fname = 'GRAYSCOTT_iteration_count_hf.png'
179-
plt.savefig(fname, rasterized=True, transparent=True, bbox_inches='tight')
180-
# plt.show()
133+
exit()

0 commit comments

Comments
 (0)