Skip to content

Commit f1c26f9

Browse files
committed
add missing files
1 parent 87e0dcb commit f1c26f9

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed

examples/1D_convergence/plot.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import matplotlib.pyplot as plt
2+
import numpy as np
3+
import pandas as pd
4+
5+
N = [32, 64, 128, 256, 512, 1024]
6+
Ord = [1, 3, 5]
7+
8+
errors = np.nan * np.zeros((len(N), len(Ord), 3))
9+
10+
TEND = 200000
11+
12+
for i in range(len(N)):
13+
for j in range(len(Ord)):
14+
15+
sim_a1 = pd.read_csv(f"N{N[i]}_O{Ord[j]}/D/cons.5.00.{TEND}.dat", sep=r"\s+", header=None, names=["x", "y"])
16+
sim_a2 = pd.read_csv(f"N{N[i]}_O{Ord[j]}/D/cons.6.00.{TEND}.dat", sep=r"\s+", header=None, names=["x", "y"])
17+
18+
exact_a1 = pd.read_csv(f"N{N[i]}_O{Ord[j]}/D/cons.5.00.000000.dat", sep=r"\s+", header=None, names=["x", "y"])
19+
exact_a2 = pd.read_csv(f"N{N[i]}_O{Ord[j]}/D/cons.6.00.000000.dat", sep=r"\s+", header=None, names=["x", "y"])
20+
21+
## 2 norm
22+
errors[i, j, 0] = 1 / N[i] * np.sum(np.sqrt((sim_a1.y - exact_a1.y) ** 2))
23+
errors[i, j, 0] += 1 / N[i] * np.sum(np.sqrt((sim_a2.y - exact_a2.y) ** 2))
24+
25+
## 1 norm
26+
errors[i, j, 1] = 1 / N[i] * np.sum(np.abs(sim_a1.y - exact_a1.y))
27+
errors[i, j, 1] += 1 / N[i] * np.sum(np.abs(sim_a2.y - exact_a2.y))
28+
29+
## Inf norm
30+
errors[i, j, 2] = np.nanmax(np.abs(sim_a1.y - exact_a1.y))
31+
errors[i, j, 2] += np.nanmax(np.abs(sim_a2.y - exact_a2.y))
32+
33+
fig, ax = plt.subplots(1, 3, figsize=(12, 8), sharex=True)
34+
35+
colors = ["blue", "green", "red", "purple"]
36+
37+
ref = np.nan * np.zeros((len(N), len(Ord)))
38+
39+
for i in range(3):
40+
ax[i].plot(N, 30 / np.array(N) ** 1, label="Slope = -1", color=colors[0])
41+
ax[i].plot(N, 3000 / np.array(N) ** 3, label="Slope = -3", color=colors[1])
42+
ax[i].plot(N, 5000 / np.array(N) ** 5, label="Slope = -5", color=colors[2])
43+
44+
for j in range(len(Ord)):
45+
ax[0].plot(N, errors[:, j, 0], "o-", color=colors[j])
46+
ax[0].set_xscale("log", base=2)
47+
ax[0].set_yscale("log")
48+
ax[0].set_title("||error||_2")
49+
ax[0].legend()
50+
51+
ax[1].plot(N, errors[:, j, 1], "o-", color=colors[j])
52+
ax[1].set_xscale("log", base=2)
53+
ax[1].set_yscale("log")
54+
ax[1].set_title("||error||_1")
55+
56+
ax[2].plot(N, errors[:, j, 2], "o-", color=colors[j])
57+
ax[2].set_xscale("log", base=2)
58+
ax[2].set_yscale("log")
59+
ax[2].set_title("||error||_inf")
60+
61+
plt.tight_layout()
62+
plt.show()
63+
64+
errors = np.column_stack((N, errors[:, :, 0]))
65+
errors = np.column_stack((errors, 7 / np.array(N) ** 1))
66+
errors = np.column_stack((errors, 700 / np.array(N) ** 3))
67+
errors = np.column_stack((errors, 2000 / np.array(N) ** 5))
68+
69+
df = pd.DataFrame(errors, columns=["N", "1", "3", "5", "R1", "R3", "R5"], index=N)
70+
df.to_csv("errors.csv", index=False)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env sh
2+
Nx=(32 64 128 256 512 1024)
3+
Order=(1 3 5)
4+
ME=2 # Model equations = 2 for five-equation model
5+
RS=2 # Riemann solver = 2 for HLLC
6+
7+
#ROOT_DIR=<WORKING DIRECTORY>
8+
#MFC_DIR=<MFC ROOT DIR>
9+
ROOT_DIR="/Users/benwilfong/Documents/software/MFC-Wilfong/examples/1D_convergence"
10+
MFC_DIR="/Users/benwilfong/Documents/software/MFC-Wilfong"
11+
12+
for i in "${Nx[@]}"; do
13+
for j in "${Order[@]}"; do
14+
rm -rf N${i}_O${j}
15+
mkdir N${i}_O${j}
16+
cp case.py N${i}_O${j}/
17+
done
18+
done
19+
20+
cd $MFC_DIR
21+
22+
for i in "${Nx[@]}"; do
23+
for j in "${Order[@]}"; do
24+
./mfc.sh run $ROOT_DIR/N${i}_O${j}/case.py --case-optimization --no-debug -- --order $j -N $i --meqns $ME --rs $RS
25+
done
26+
done
27+

0 commit comments

Comments
 (0)