30 """Interface-biased slope estimate for the phase whose fraction is f (>= 1/2 = holds it)."""
31 fm, fp = np.roll(f, 1) >= 0.5, np.roll(f, -1) >= 0.5
32 est = np.where(fm & fp, 0.5 * (dm + dp), np.where(fm, dm, np.where(fp, dp, 0.0)))
33 return np.where(f >= 0.5, est, 0.0)
41def run(N, ratio, scheme, v0, steps=None, slab=(0.3, 0.7), wisp=0.0):
43 x = (np.arange(N) + 0.5) * h
45 C = np.clip((np.minimum(xl + h, slab[1]) - np.maximum(xl, slab[0])) / h, 0, 1)
46 rg, rl = 1.0, float(ratio)
47 v =
v0(x)
if callable(v0)
else np.array(v0, dtype=float)
48 nst = steps
if steps
is not None else int(round(1.0 / (A * h)))
51 right = np.roll(C, -1) >= np.roll(C, 1)
52 F = np.where(right, np.minimum(A, C), np.maximum(0.0, C - (1 - A)))
53 F = np.where((C <= wisp) | (C >= 1 - wisp), C * A, F)
54 dm, dp = v - np.roll(v, 1), np.roll(v, -1) - v
55 if scheme ==
'upwind':
56 sl = sg = np.zeros_like(v)
57 elif scheme
in (
'muscl_mixed',
'muscl_mixed_capped'):
59 elif scheme ==
'mc_mixed':
61 elif scheme ==
'muscl_phase':
62 sl, sg =
tvd(dm, dp,
phase_est(dm, dp, C)),
tvd(dm, dp,
phase_est(dm, dp, 1 - C))
63 elif scheme ==
'phase_central':
65 if scheme.endswith(
'_capped')
or scheme ==
'muscl_phase':
67 R = np.maximum(rg * (1 - C) + rl * C - (rg * (A - F) + rl * F), 0.0)
68 m = np.minimum(np.abs(dm), np.abs(dp))
69 ext = np.abs(0.5 * (1 - A) * (rg * (A - F) * sg + rl * F * sl))
70 th = np.where(ext > R * m, R * m / np.where(ext > 0, ext, 1.0), 1.0)
71 bites += int((th < 1).sum())
72 sl, sg = th * sl, th * sg
73 ul, ug = v + 0.5 * (1 - A) * sl, v + 0.5 * (1 - A) * sg
76 rn = rg * (1 - Cn) + rl * Cn
77 dev = rg * ((A - FM) * (np.roll(ug, 1) - v) - (A - F) * (ug - v)) \
78 + rl * (FM * (np.roll(ul, 1) - v) - F * (ul - v))
81 return x, C, v, nst, bites
89 Ns = [32, 64, 128, 256, 512]
107 _, _, v, _, _ =
run(64, ratio, sch, 1.0 + noise, steps=200)
108 _, _, w, _, _ =
run(64, ratio, sch, np.ones(64), steps=200)
run(N, ratio, scheme, v0, steps=None, slab=(0.3, 0.7), wisp=0.0)