|
| 1 | +import mfc.viz |
| 2 | +import os |
| 3 | + |
| 4 | +import subprocess |
| 5 | +import seaborn as sns |
| 6 | +import matplotlib.pyplot as plt |
| 7 | +from tqdm import tqdm |
| 8 | + |
| 9 | +from case import sol_L as sol |
| 10 | + |
| 11 | +case = mfc.viz.Case(".") |
| 12 | + |
| 13 | +os.makedirs("viz", exist_ok=True) |
| 14 | + |
| 15 | +sns.set_theme(style=mfc.viz.generate_cpg_style()) |
| 16 | + |
| 17 | +Y_VARS = ["H2", "O2", "H2O", "N2"] |
| 18 | + |
| 19 | +variables = [ |
| 20 | + ("rho", "prim.1"), |
| 21 | + ("u_x", "prim.2"), |
| 22 | + ("p", "prim.3"), |
| 23 | + ("E", "cons.3"), |
| 24 | + *[(f"Y_{name}", f"prim.{5 + sol.species_index(name)}") for name in Y_VARS], |
| 25 | + ("T", "prim.15"), |
| 26 | +] |
| 27 | + |
| 28 | +for variable in tqdm(variables, desc="Loading Variables"): |
| 29 | + case.load_variable(*variable) |
| 30 | + |
| 31 | +for step in tqdm(case.get_timesteps(), desc="Rendering Frames"): |
| 32 | + fig, axes = plt.subplots(2, 3, figsize=(16, 9)) |
| 33 | + |
| 34 | + def pad_ylim(ylim, pad=0.1): |
| 35 | + return ( |
| 36 | + ylim[0] - pad * (ylim[1] - ylim[0]), |
| 37 | + ylim[1] + pad * (ylim[1] - ylim[0]), |
| 38 | + ) |
| 39 | + |
| 40 | + case.plot_step(step, "rho", ax=axes[0, 0]) |
| 41 | + axes[0, 0].set_ylim(*pad_ylim(case.get_minmax_time("rho"))) |
| 42 | + axes[0, 0].set_ylabel("$\\rho$") |
| 43 | + case.plot_step(step, "u_x", ax=axes[0, 1]) |
| 44 | + axes[0, 1].set_ylim(*pad_ylim(case.get_minmax_time("u_x"))) |
| 45 | + axes[0, 1].set_ylabel("$u_x$") |
| 46 | + case.plot_step(step, "p", ax=axes[1, 0]) |
| 47 | + axes[1, 0].set_ylim(*pad_ylim(case.get_minmax_time("p"))) |
| 48 | + axes[1, 0].set_ylabel("$p$") |
| 49 | + for y in Y_VARS: |
| 50 | + case.plot_step(step, f"Y_{y}", ax=axes[1, 1], label=y) |
| 51 | + axes[1, 1].set_ylim(0, 1.1 * max(case.get_minmax_time(f"Y_{y}")[1] for y in Y_VARS)) |
| 52 | + axes[1, 1].set_ylabel("$Y_k$") |
| 53 | + case.plot_step(step, "T", ax=axes[1, 2]) |
| 54 | + axes[1, 2].set_ylim(*pad_ylim(case.get_minmax_time("T"))) |
| 55 | + axes[1, 2].set_ylabel("$T$") |
| 56 | + case.plot_step(step, "E", ax=axes[0, 2]) |
| 57 | + axes[0, 2].set_ylim(*pad_ylim(case.get_minmax_time("E"))) |
| 58 | + axes[0, 2].set_ylabel("$E$") |
| 59 | + |
| 60 | + plt.tight_layout() |
| 61 | + plt.savefig(f"viz/{step:06d}.png") |
| 62 | + plt.close() |
| 63 | + |
| 64 | +subprocess.run( |
| 65 | + [ |
| 66 | + "ffmpeg", |
| 67 | + "-y", |
| 68 | + "-framerate", |
| 69 | + "60", |
| 70 | + "-pattern_type", |
| 71 | + "glob", |
| 72 | + "-i", |
| 73 | + "viz/*.png", |
| 74 | + "-c:v", |
| 75 | + "libx264", |
| 76 | + "-pix_fmt", |
| 77 | + "yuv420p", |
| 78 | + "viz.mp4", |
| 79 | + ] |
| 80 | +) |
0 commit comments