Skip to content

Commit f604770

Browse files
committed
apply formatting
1 parent e737583 commit f604770

40 files changed

+3345
-2086
lines changed

benchmarks/advection_reaction_3D/scripts/compare_error.py

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
import glob
1616
import sys
1717
import matplotlib
18-
matplotlib.use('Agg')
18+
19+
matplotlib.use("Agg")
1920
from mpl_toolkits.mplot3d import Axes3D
2021
import matplotlib.pyplot as plt
2122
import pandas as pd
@@ -25,75 +26,75 @@
2526
# load pickled data
2627
def load_data(file):
2728
data = np.load(file)
28-
m = data['mesh']
29-
t = data['t']
30-
u = data['u']
31-
v = data['v']
32-
w = data['w']
29+
m = data["mesh"]
30+
t = data["t"]
31+
u = data["u"]
32+
v = data["v"]
33+
w = data["w"]
3334

34-
hx = m[0,1] - m[0,0]
35-
hy = m[1,1] - m[1,0]
36-
hz = m[2,1] - m[2,0]
35+
hx = m[0, 1] - m[0, 0]
36+
hy = m[1, 1] - m[1, 0]
37+
hz = m[2, 1] - m[2, 0]
3738

38-
return { 'm': m, 'h': (hx,hy,hz), 't': t, 'u': u, 'v': v, 'w': w }
39+
return {"m": m, "h": (hx, hy, hz), "t": t, "u": u, "v": v, "w": w}
3940

4041

4142
# grid function norm
4243
def norm_3Dgrid(h, x, q=1):
43-
hx,hy,hz = h
44+
hx, hy, hz = h
4445
s = np.shape(x)
45-
return (hx*hy*hz*np.sum(np.abs(x)**q, axis=(1,2,3)))**(1./q)
46+
return (hx * hy * hz * np.sum(np.abs(x) ** q, axis=(1, 2, 3))) ** (1.0 / q)
4647

4748

4849
# load data files
49-
np111 = load_data('np-111/output-with-h-8.33e-02.npz')
50-
np211 = load_data('np-211/output-with-h-8.33e-02.npz')
51-
np311 = load_data('np-311/output-with-h-8.33e-02.npz')
52-
np131 = load_data('np-131/output-with-h-8.33e-02.npz')
53-
np113 = load_data('np-113/output-with-h-8.33e-02.npz')
54-
np911 = load_data('np-911/output-with-h-8.33e-02.npz')
50+
np111 = load_data("np-111/output-with-h-8.33e-02.npz")
51+
np211 = load_data("np-211/output-with-h-8.33e-02.npz")
52+
np311 = load_data("np-311/output-with-h-8.33e-02.npz")
53+
np131 = load_data("np-131/output-with-h-8.33e-02.npz")
54+
np113 = load_data("np-113/output-with-h-8.33e-02.npz")
55+
np911 = load_data("np-911/output-with-h-8.33e-02.npz")
5556
# np133 = load_data('np-133/output-with-h-8.33e-02.npz')
56-
np313 = load_data('np-313/output-with-h-8.33e-02.npz')
57-
np331 = load_data('np-331/output-with-h-8.33e-02.npz')
58-
np333 = load_data('np-333/output-with-h-8.33e-02.npz')
57+
np313 = load_data("np-313/output-with-h-8.33e-02.npz")
58+
np331 = load_data("np-331/output-with-h-8.33e-02.npz")
59+
np333 = load_data("np-333/output-with-h-8.33e-02.npz")
5960
# np666 = load_data('np-666/output-with-h-8.33e-02.npz')
6061

61-
for component in ['u', 'v', 'w']:
62+
for component in ["u", "v", "w"]:
6263
# Reference solution
6364
ref = np111[component]
6465

6566
# Now compute E(h) = ||U(h) - \bar{U}(h)|| using the grid-function norm
66-
E_np211 = norm_3Dgrid(np211['h'], np211[component] - ref)
67-
E_np311 = norm_3Dgrid(np311['h'], np311[component] - ref)
68-
E_np131 = norm_3Dgrid(np131['h'], np131[component] - ref)
69-
E_np113 = norm_3Dgrid(np113['h'], np113[component] - ref)
70-
E_np911 = norm_3Dgrid(np911['h'], np911[component] - ref)
67+
E_np211 = norm_3Dgrid(np211["h"], np211[component] - ref)
68+
E_np311 = norm_3Dgrid(np311["h"], np311[component] - ref)
69+
E_np131 = norm_3Dgrid(np131["h"], np131[component] - ref)
70+
E_np113 = norm_3Dgrid(np113["h"], np113[component] - ref)
71+
E_np911 = norm_3Dgrid(np911["h"], np911[component] - ref)
7172
# E_np133 = norm_3Dgrid(np133['h'], np133[component] - ref)
72-
E_np313 = norm_3Dgrid(np313['h'], np313[component] - ref)
73-
E_np331 = norm_3Dgrid(np331['h'], np331[component] - ref)
74-
E_np333 = norm_3Dgrid(np333['h'], np333[component] - ref)
73+
E_np313 = norm_3Dgrid(np313["h"], np313[component] - ref)
74+
E_np331 = norm_3Dgrid(np331["h"], np331[component] - ref)
75+
E_np333 = norm_3Dgrid(np333["h"], np333[component] - ref)
7576
# E_np666 = norm_3Dgrid(np666['h'], np666[component] - ref)
7677

7778
# Plot error across time
78-
X, Y = np.meshgrid(np111['m'][0,:], np111['t'])
79+
X, Y = np.meshgrid(np111["m"][0, :], np111["t"])
7980
# fig = plt.figure()
8081
# ax = plt.subplot(311, projection='3d')
8182
# ax.plot_surface(X, Y, np.abs(np911[component][:,:,0,0] - ref[:,:,0,0]))
8283
# ax = plt.subplot(312, projection='3d')
8384
# ax.plot_surface(X, Y, np.abs(np911[component][:,0,:,0] - ref[:,0,:,0]))
8485
# ax = plt.subplot(313, projection='3d')
8586
# ax.plot_surface(X, Y, np.abs(np911[component][:,0,0,:] - ref[:,0,0,:]))
86-
plt.plot(np111['t'], E_np211)
87-
plt.plot(np111['t'], E_np131)
88-
plt.plot(np111['t'], E_np113)
89-
plt.plot(np111['t'], E_np911)
87+
plt.plot(np111["t"], E_np211)
88+
plt.plot(np111["t"], E_np131)
89+
plt.plot(np111["t"], E_np113)
90+
plt.plot(np111["t"], E_np911)
9091
# plt.plot(np111['t'], E_np133)
91-
plt.plot(np111['t'], E_np313)
92-
plt.plot(np111['t'], E_np331)
93-
plt.plot(np111['t'], E_np333)
92+
plt.plot(np111["t"], E_np313)
93+
plt.plot(np111["t"], E_np331)
94+
plt.plot(np111["t"], E_np333)
9495
# plt.plot(np111['t'], E_np666)
9596
# plt.legend(['2 1 1', '3 1 1', '1 3 3', '3 1 3', '3 3 1', '3 3 3', '6 6 6'])
9697
# plt.legend(['3 1 1', '1 3 1', '1 1 3', '9 1 1', '1 3 3', '3 1 3', '3 3 1'])
97-
plt.ylabel('||E(hx,hy,hz)||')
98-
plt.xlabel('time')
99-
plt.savefig('compare-error-plot-%s.png' % component)
98+
plt.ylabel("||E(hx,hy,hz)||")
99+
plt.xlabel("time")
100+
plt.savefig("compare-error-plot-%s.png" % component)

benchmarks/advection_reaction_3D/scripts/compute_error.py

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
import glob
1616
import sys
1717
import matplotlib
18-
matplotlib.use('Agg')
18+
19+
matplotlib.use("Agg")
1920
import matplotlib.pyplot as plt
2021
import pandas as pd
2122
import numpy as np
@@ -24,65 +25,67 @@
2425
# load pickled data
2526
def load_data(file):
2627
data = np.load(file)
27-
m = data['mesh']
28-
t = data['t']
29-
u = data['u']
30-
v = data['v']
31-
w = data['w']
28+
m = data["mesh"]
29+
t = data["t"]
30+
u = data["u"]
31+
v = data["v"]
32+
w = data["w"]
3233

33-
hx = m[0,1] - m[0,0]
34-
hy = m[1,1] - m[1,0]
35-
hz = m[2,1] - m[2,0]
34+
hx = m[0, 1] - m[0, 0]
35+
hy = m[1, 1] - m[1, 0]
36+
hz = m[2, 1] - m[2, 0]
3637

37-
return { 'm': m, 'h': (hx,hy,hz), 't': t, 'u': u, 'v': v, 'w': w }
38+
return {"m": m, "h": (hx, hy, hz), "t": t, "u": u, "v": v, "w": w}
3839

3940

4041
# grid function norm
4142
def norm_3Dgrid(h, x, q=1):
42-
hx,hy,hz = h
43-
return (hx*hy*hz*np.sum(np.abs(x)**q, axis=(1,2,3)))**(1/q)
43+
hx, hy, hz = h
44+
return (hx * hy * hz * np.sum(np.abs(x) ** q, axis=(1, 2, 3))) ** (1 / q)
4445

4546

4647
# computer order of accuracy p
4748
def calc_order(h1, Eh1, h2, Eh2):
48-
return np.log( Eh1/Eh2 ) / np.log( np.prod(h1)/np.prod(h2) )
49+
return np.log(Eh1 / Eh2) / np.log(np.prod(h1) / np.prod(h2))
4950

5051

5152
# load data files
52-
h_over_8 = load_data('middle-h/output-with-h-1.04e-02.npz')
53-
h_over_4 = load_data('large-h/output-with-h-2.08e-02.npz')
53+
h_over_8 = load_data("middle-h/output-with-h-1.04e-02.npz")
54+
h_over_4 = load_data("large-h/output-with-h-2.08e-02.npz")
5455
# h_over_2 = load_data('larger-h/output-with-h-4.16e-02.npz')
55-
h_over_1 = load_data('largest-h/output-with-h-8.33e-02.npz')
56+
h_over_1 = load_data("largest-h/output-with-h-8.33e-02.npz")
5657

57-
for component in ['u', 'v', 'w']:
58+
for component in ["u", "v", "w"]:
5859
# Restrict reference to the coarsest grid
59-
ref = h_over_8[component][:,::8,::8,::8]
60+
ref = h_over_8[component][:, ::8, ::8, ::8]
6061

6162
# Now compute E(h) = ||U(h) - \bar{U}(h)|| using the grid-function norm
62-
Eh_over_4 = norm_3Dgrid(h_over_4['h'], h_over_4[component][:,::4,::4,::4] - ref)
63-
Eh_over_1 = norm_3Dgrid(h_over_1['h'], h_over_1[component][:,:,:,:] - ref)
63+
Eh_over_4 = norm_3Dgrid(h_over_4["h"], h_over_4[component][:, ::4, ::4, ::4] - ref)
64+
Eh_over_1 = norm_3Dgrid(h_over_1["h"], h_over_1[component][:, :, :, :] - ref)
6465

6566
# Compute order p as in O(h^p)
66-
p = calc_order(h_over_1['h'], Eh_over_1, h_over_4['h'], Eh_over_4)
67-
print('min p for %s component: %.4f' % (component, np.min(p)))
67+
p = calc_order(h_over_1["h"], Eh_over_1, h_over_4["h"], Eh_over_4)
68+
print("min p for %s component: %.4f" % (component, np.min(p)))
6869

6970
# Plot error across time
7071
plt.figure()
71-
plt.plot(h_over_8['t'], Eh_over_4, 'r-')
72-
plt.plot(h_over_8['t'], Eh_over_1, 'b-')
73-
plt.ylabel('||E(hx,hy,hz)||')
74-
plt.xlabel('time')
75-
plt.savefig('error-in-time-plot-%s.png' % component)
72+
plt.plot(h_over_8["t"], Eh_over_4, "r-")
73+
plt.plot(h_over_8["t"], Eh_over_1, "b-")
74+
plt.ylabel("||E(hx,hy,hz)||")
75+
plt.xlabel("time")
76+
plt.savefig("error-in-time-plot-%s.png" % component)
7677

7778
# Plot error norm with respect to h
7879
plt.figure()
79-
x = np.array([np.prod(h_over_4['h']), np.prod(h_over_1['h'])])
80-
plt.plot(x, x, 'k-')
81-
plt.plot(x, x**2, 'k-')
82-
plt.plot(x, [np.linalg.norm(Eh_over_4, np.Inf), np.linalg.norm(Eh_over_1, np.Inf)], 'r-')
83-
plt.legend(['1st order', '2nd order', 'actual'])
84-
plt.ylabel('|| ||E(hx,hy,hz)|| ||_inf')
85-
plt.xlabel('hx * hy * hz')
86-
plt.yscale('log')
87-
plt.xscale('log')
88-
plt.savefig('error-plot-%s.png' % component)
80+
x = np.array([np.prod(h_over_4["h"]), np.prod(h_over_1["h"])])
81+
plt.plot(x, x, "k-")
82+
plt.plot(x, x**2, "k-")
83+
plt.plot(
84+
x, [np.linalg.norm(Eh_over_4, np.Inf), np.linalg.norm(Eh_over_1, np.Inf)], "r-"
85+
)
86+
plt.legend(["1st order", "2nd order", "actual"])
87+
plt.ylabel("|| ||E(hx,hy,hz)|| ||_inf")
88+
plt.xlabel("hx * hy * hz")
89+
plt.yscale("log")
90+
plt.xscale("log")
91+
plt.savefig("error-plot-%s.png" % component)

0 commit comments

Comments
 (0)