From f7261d2e6bfa03d01390a27775b4b1029a5f50f7 Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Fri, 15 Apr 2022 11:22:36 +0200 Subject: [PATCH] Highly improved efficiency in processing.animate to find grid --- olaflow/processing/animate.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/olaflow/processing/animate.py b/olaflow/processing/animate.py index 408ad58..8ef1766 100644 --- a/olaflow/processing/animate.py +++ b/olaflow/processing/animate.py @@ -38,21 +38,19 @@ x0 = config.getfloat("post", "x") z0 = config.getfloat("post", "z") i0 = np.argmin(np.abs((model.x - x0) + 1j * (model.z - z0))) -X, Z = np.meshgrid(np.unique(model.x), np.unique(model.z)) +x0, idx0 = np.unique(model.x.astype(np.half), return_inverse=True) +z0, idz0 = np.unique(model.z.astype(np.half), return_inverse=True) -C = np.where( - (model.x[:, None, None].astype(np.single) == X[None, :, :].astype(np.single)) - & (model.z[:, None, None].astype(np.single) == Z[None, :, :].astype(np.single)) -) +X, Z = np.meshgrid(x0, z0) P = np.full((model.t.size, *X.shape), np.nan) -P[:, C[1], C[2]] = model.fields["porosity"][:, C[0]] +P[:, idz0, idx0] = model.fields["porosity"] AW = np.full((model.t.size, *X.shape), np.nan) -AW[:, C[1], C[2]] = model.fields["alpha.water"][:, C[0]] +AW[:, idz0, idx0] = model.fields["alpha.water"] U = np.full((model.t.size, *X.shape), np.nan) -U[:, C[1], C[2]] = np.linalg.norm(model.fields["U"], axis=1)[:, C[0]] +U[:, idz0, idx0] = np.linalg.norm(model.fields["U"], axis=1) fig, ax = plt.subplots(figsize=(19.2, 10.8), dpi=100) tit = ax.text( @@ -129,9 +127,10 @@ def animU(i): ur_m.set_array(U[i]) ur_m.set_alpha(1 - np.nan_to_num(AW[i]).clip(0, 1)) +plt.show() -ani = animation.FuncAnimation(fig, anim, frames=model.t.size, interval=1 / 24) -aniU = animation.FuncAnimation(figU, animU, frames=model.t.size, interval=1 / 24) - -ani.save(out.joinpath("anim.mp4"), fps=24) -aniU.save(out.joinpath("animU.mp4"), fps=24) +#ani = animation.FuncAnimation(fig, anim, frames=model.t.size, interval=1/24) +#aniU = animation.FuncAnimation(figU, animU, frames=model.t.size, interval=1/24) +# +#ani.save(out.joinpath("anim.mp4"), fps=24) +#aniU.save(out.joinpath("animU.mp4"), fps=24)