Skip to content

Commit 5e2e41a

Browse files
committed
plot analytic solution in profile.py
1 parent ffa21a4 commit 5e2e41a

File tree

3 files changed

+48
-19
lines changed

3 files changed

+48
-19
lines changed

Exec/unit_tests/diffusion_test/Prob.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ void Castro::problem_post_simulation(Vector<std::unique_ptr<AmrLevel> >& amr_lev
1111

1212
int nlevels = amr_level.size();
1313

14-
Real err = -1.e30;
15-
14+
Real L0 = -1.e30;
15+
Real L2 = -1.e30;
1616

1717
for (int n = 0; n < nlevels; ++n) {
1818

@@ -53,15 +53,16 @@ void Castro::problem_post_simulation(Vector<std::unique_ptr<AmrLevel> >& amr_lev
5353
// compute the norm of the error
5454
MultiFab::Subtract(*analytic, S, UTEMP, 0, 1, 0);
5555

56-
err = std::max(err, analytic->norm0());
57-
56+
L0 = std::max(L0, analytic->norm0());
57+
L2 = std::max(L2, analytic->norm2());
5858

5959
}
6060

6161
const std::string stars(78,'*');
6262
amrex::Print() << stars << "\n"
6363
<< " diffusion problem post_simulation() \n"
64-
<< " L-inf error against analytic solution: " << err << "\n"
64+
<< " L-inf error against analytic solution: " << L0 << "\n"
65+
<< " L-2 error against analytic solution: " << L2 << "\n"
6566
<< stars << "\n";
6667
}
6768
#endif

Exec/unit_tests/diffusion_test/analysis/profiles.py

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,30 @@ def rgba_to_hex(rgba):
2222
b = int(rgba[2]*255.0)
2323
return '#{:02X}{:02X}{:02X}'.format(r, g, b)
2424

25+
def get_analytic_profile(x_coord, time, problo, probhi,
26+
geometry, dimension):
27+
28+
if geometry == "spherical":
29+
exponent = 1.5
30+
center = 0.0
31+
elif dimension == 2 and geometry == "cylindrical":
32+
exponent = 1.5
33+
center = 0.5 * (problo[1] + probhi[1])
34+
else:
35+
exponent = dimension / 2.0
36+
center = 0.5 * (problo[0] + probhi[0])
37+
38+
dist2 = (x_coord - float(center))**2
39+
T1 = 1.0
40+
T2 = 2.0
41+
t_0 = 0.001
42+
diff_coeff = 1.0
43+
temp = T1 + (T2 - T1) * (t_0 / (time + t_0))**exponent * \
44+
np.exp(-0.25 * dist2 / (diff_coeff * (time + t_0)))
45+
46+
return temp
47+
48+
2549
def get_T_profile(plotfile):
2650

2751
ds = CastroDataset(plotfile)
@@ -32,17 +56,23 @@ def get_T_profile(plotfile):
3256
# Sort the ray values by 'x' so there are no discontinuities
3357
# in the line plot
3458

59+
dimension = ds.dimensionality
3560
coords = {"cartesian":"x",
3661
"cylindrical":"z",
3762
"spherical":"r"}
3863

3964
coord = coords[ds.geometry]
4065

66+
problo = ds.domain_left_edge
67+
probhi = ds.domain_right_edge
68+
4169
srt = np.argsort(ad[coord])
4270
x_coord = np.array(ad[coord][srt])
4371
temp = np.array(ad['Temp'][srt])
72+
analytic_temp = get_analytic_profile(x_coord, time, problo, probhi,
73+
ds.geometry, dimension)
4474

45-
return time, x_coord, temp
75+
return time, x_coord, temp, analytic_temp
4676

4777

4878
def doit(prefix, nums, skip, limitlabels, xmin, xmax):
@@ -52,12 +82,9 @@ def doit(prefix, nums, skip, limitlabels, xmin, xmax):
5282

5383
ax_T = f.add_subplot(111)
5484

55-
# Get set of colors to use and apply to plot
56-
numplots = int(len(nums) / skip)
57-
cm = plt.get_cmap('nipy_spectral')
58-
clist = [cm(0.95*i/numplots) for i in range(numplots + 1)]
59-
hexclist = [rgba_to_hex(ci) for ci in clist]
60-
ax_T.set_prop_cycle(cycler('color', hexclist))
85+
# Get colors
86+
numplots = len(range(0, len(nums), skip))
87+
colors = plt.cm.nipy_spectral(np.linspace(0, 1, numplots))
6188

6289
if limitlabels > 1:
6390
skiplabels = int(numplots / limitlabels)
@@ -69,17 +96,18 @@ def doit(prefix, nums, skip, limitlabels, xmin, xmax):
6996
index = 0
7097

7198
for n in range(0, len(nums), skip):
72-
7399
pfile = "{}{}".format(prefix, nums[n])
74-
75-
time, x, T = get_T_profile(pfile)
100+
i = int(n / skip)
101+
time, x, T, analytic_T = get_T_profile(pfile)
76102

77103
if index % skiplabels == 0:
78-
ax_T.plot(x, T, label="t = {:7.5f} s".format(time))
104+
ax_T.plot(x, T, "-", color=colors[i], label="simulation: t = {:7.5f} s".format(time))
105+
ax_T.plot(x, analytic_T, "--", color=colors[i], label="analytic: t = {:7.5f} s".format(time))
79106
else:
80-
ax_T.plot(x, T)
107+
ax_T.plot(x, T, "-", color=colors[i])
108+
ax_T.plot(x, analytic_T, "--", color=colors[i])
81109

82-
index = index + 1
110+
index += 1
83111

84112
ax_T.legend(frameon=False)
85113
ax_T.set_ylabel("T (K)")

Exec/unit_tests/diffusion_test/inputs.2d.sph

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ castro.allow_non_unit_aspect_zones = 1
1616
# 1 = Inflow 4 = SlipWall
1717
# 2 = Outflow 5 = NoSlipWall
1818
# >>>>>>>>>>>>> BC FLAGS <<<<<<<<<<<<<<<<
19-
castro.lo_bc = 3 3
19+
castro.lo_bc = 2 3
2020
castro.hi_bc = 2 3
2121

2222
# WHICH PHYSICS

0 commit comments

Comments
 (0)