<jupyter_start><jupyter_text>Only run the following cell if you don't want to use the cached values and instead want to re-run the calculations.<jupyter_code>params = {}

SIZE = int(1e3)

g = 9.8 # gravity
params["dl"] = 1 # height lower
params["mu_l"] = 1e3 # visc lower
params["rho_l"] = 3000 # density lower
params["rho_u"] = 2970 # density upper
params["r"] = params["rho_l"] / params["rho_u"] # density ratio


dls = np.concatenate([np.linspace(.2, 1, SIZE // 2), np.linspace(1.01, 5, SIZE // 2)])[::-1]

Kls = np.logspace(2, 6, SIZE)

Ups = Kls * (params["dl"] ** 2) / params["mu_l"]

Fs = np.sqrt((params["rho_l"]-params["rho_u"]) / \
                          params["rho_u"] * g * params["dl"] / (Ups ** 2))


d2d2, ff = np.meshgrid(dls, Fs)

zs = []
# for viscosity range
for idx, m in enumerate([.33, .2, .1]):
    params["m"] = m
    params["mu_u"] = params["mu_l"] / m
    
    z = np.zeros((len(dls), len(Fs))).T
    # for k range
    for y_idx, (Kl_p, U_p, F) in enumerate(tqdm(zip(Kls, Ups, Fs), total=SIZE)):
        params["Kl_p"] = Kl_p
        params["U_p"] = U_p
        params["F"] = F
        
        # for height range
        for x_idx, n in enumerate(dls):
                        
            params["du"] = params["dl"] / n
            params["n"] = n
            params["Ku_p"] = params["Kl_p"]

            J = no_slip_J(**params)
            z[y_idx, x_idx] += int(J > 0)
    zs.append(z)
    
if not os.path.exists("cached_matrices"):
    os.mkdir("cached_matrices")
    
pkl.dump(zs, open("cached_matrices/zs.pkl", "wb"))
if USE_CACHE and os.path.exists("cached_matrices"):
    try:
        d2d2 = np.load("cached_matrices/no_slip_d2d2.npy", allow_pickle=True)
    except FileNotFoundError:
        print("Run the previous cell or pull from the github repo to get d2d2 data.")
        
    try:
        ff = np.load("cached_matrices/no_slip_ff.npy", allow_pickle=True)
    except FileNotFoundError:
        print("Run the previous cell or pull from the github repo to get ff data.")
        
    try:
        z = np.load("cached_matrices/no_slip_z.npy", allow_pickle=True)
    except FileNotFoundError:
        print("Run the previous cell or pull from the github repo to get z data.")
# mask each stability simulation for clean graphing
red = zs[0] * 3
orange = zs[1] * 2
orange[np.where(red > 0)] = 0
yellow = zs[2]
yellow[np.where((red > 0) | (orange > 0))] = 0

combo_z = red + orange + yellow
fig, ax = plt.subplots(figsize=(10,10))
ax.contourf(d2d2, ff, combo_z, cmap=custom_map)

LW = 3
a1 = ax.contour(d2d2, ff, zs[0], colors="black", linestyles="-", linewidths=LW)
a2 = ax.contour(d2d2, ff, zs[1], colors="black", linestyles="-.", linewidths=LW - 1)
a3 = ax.contour(d2d2, ff, zs[2], colors="black", linestyles="--", linewidths=LW - 2)

MARKER_SIZE = 13

m1_line = mlines.Line2D([], [], color='black', label='m = 0.1', marker="o", markersize=MARKER_SIZE)
m2_line = mlines.Line2D([], [], color='black', label='m = 0.2', marker="s", markersize=MARKER_SIZE)
m3_line = mlines.Line2D([], [], color='black', label='m = 0.33', marker="D", markersize=MARKER_SIZE)

ax.plot(.37, .14, 'o', markersize=MARKER_SIZE, color="black")
ax.plot(.49, .1, 's', markersize=MARKER_SIZE, color="black")
ax.plot(.63, .073, 'D', markersize=MARKER_SIZE, color="black")


ax.text(4.4, .028, "Unstable", c="black", ha="center")
ax.text(4.4, .058, "Stable", c="black", ha="center")
ax.text(3, .011, "Lower Froude numbers\n promote instability", c="black")

ax.set_ylabel("Froude number, Fr")
ax.set_xlabel("Height ratio n (lower layer / upper layer)")

plt.legend(handles=[m1_line, m2_line, m3_line], \
           loc="upper left", fontsize=22, title="Viscosity contrast")

ax.set_yscale('log')
ax.set_ylim(1e-2, .5)

if not os.path.exists("paper_figures"):
    os.mkdir("paper_figures")

fig.savefig("paper_figures/no_slip_phase.png")
fig.savefig("paper_figures/no_slip_phase.svg", format="svg")
if not os.path.exists("cached_matrices"):
    os.mkdir("cached_matrices")
    
np.save("cached_matrices/no_slip_d2d2.npy", d2d2)
np.save("cached_matrices/no_slip_ff.npy", ff)
np.save("cached_matrices/no_slip_z.npy", z)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1782106782106782, 'fraction_numerical': 0.03006253006253006, 'mean_word_length': 3.5905077262693155, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '520109', 'license': 'MIT', 'n_tokens_mistral': 1725, 'n_tokens_neox': 1618, 'n_words': 360, 'path': 'no_slip_diagrams.ipynb', 'repo_name': 'cculha4/pahoehoe2aa', 'size': '4158'}