codex/elastocapillary-scaling-paths.py

elastocapillary-scaling-paths.py
"""Original sheet-energy scaling illustration; write the PNG to the cwd.

The curves are normalized dimensional estimates, not experimental data or
solutions for the shape of a droplet. Both have eta / eta_0 = 1 at s = 1.
"""
from pathlib import Path

import matplotlib

matplotlib.use("Agg")
import matplotlib.pyplot as plt
import numpy as np


def main():
    scale = np.geomspace(0.1, 4, 400)
    fixed_thickness = scale**2
    similar_sheets = 1 / scale
    assert np.isclose(0.5**2, 0.25)
    assert np.isclose(1 / 0.5, 2)
    fig, ax = plt.subplots(figsize=(8, 5), dpi=100, facecolor="white")
    fig.subplots_adjust(left=0.12, right=0.96, top=0.78, bottom=0.25)
    fig.suptitle("Shrinking a sheet: two different scaling experiments",
                 y=0.96, fontsize=14, weight="bold", color="#172330")
    fig.text(0.5, 0.885, r"Energy-scale ratio $\eta=\gamma L^2/B$; fixed $E$, $\nu$ and $\gamma$",
             ha="center", fontsize=11, color="#45535d")
    ax.loglog(scale, fixed_thickness, color="#216c9b", linewidth=2.5,
              label=r"Fixed thickness $h$:  $\eta/\eta_0=s^2$")
    ax.loglog(scale, similar_sheets, color="#b45335", linewidth=2.5,
              label=r"Geometric similarity $h\propto L$:  $\eta/\eta_0=1/s$")
    ax.axvline(1, color="#87939c", linewidth=0.9, linestyle=":")
    ax.axhline(1, color="#87939c", linewidth=0.9, linestyle=":")
    ax.plot(1, 1, "o", color="#172330", markersize=5)
    ax.set_xlim(0.1, 4)
    ax.set_ylim(0.008, 25)
    ax.set_xlabel(r"Lateral scale factor $s=L/L_0$", fontsize=11)
    ax.set_ylabel(r"Normalized energy-scale ratio $\eta/\eta_0$", fontsize=11)
    ax.grid(which="major", color="#e0e5e8", linewidth=0.7)
    ax.legend(loc="lower right", fontsize=10, frameon=True, framealpha=0.97)
    fig.text(0.5, 0.035, "Larger ratio means more capillary energy relative to bending.\n"
             "These are scaling estimates; the crossing is not a closure threshold.",
             ha="center", fontsize=10, color="#45535d")
    fig.savefig(Path.cwd() / (Path(__file__).stem + ".png"),
                dpi=100, facecolor="white", transparent=False)
    plt.close(fig)


if __name__ == "__main__":
    main()