|
| 1 | +from mpi4py import MPI |
| 2 | +import numpy as np |
| 3 | +import adios2 |
| 4 | +import matplotlib.pyplot as plt |
| 5 | +import matplotlib |
| 6 | + |
| 7 | +import h5py |
| 8 | +import pathlib |
| 9 | + |
| 10 | +comm = MPI.COMM_WORLD |
| 11 | + |
| 12 | +cases = ["Blankenbach_1a", "Blankenbach_2a", |
| 13 | + "Tosi_1", "Tosi_2", "Tosi_3", "Tosi_4"] |
| 14 | +formulation = "C0_SIPG" |
| 15 | +p = 3 |
| 16 | +n_ele = 128 |
| 17 | + |
| 18 | +import dolfinx |
| 19 | +import adios4dolfinx |
| 20 | + |
| 21 | +n = (128)*1j |
| 22 | +XY = np.mgrid[0:1:n, 0:1:n] |
| 23 | +X, Y = XY |
| 24 | +x = np.c_[XY.reshape(2, -1)].T |
| 25 | +x = np.c_[x, np.zeros_like(x[:,0])] # Padding for 2d geometry |
| 26 | + |
| 27 | +for case in cases: |
| 28 | + prefix = f"{case}_{formulation}_p{p}_n{n_ele}" |
| 29 | + finame = pathlib.Path(f"../checkpoints") |
| 30 | + mesh = adios4dolfinx.read_mesh( |
| 31 | + MPI.COMM_WORLD, finame / (prefix + "_velocity.bp"), "bp4", |
| 32 | + dolfinx.mesh.GhostMode.none) |
| 33 | + u = dolfinx.fem.Function(dolfinx.fem.FunctionSpace(mesh, ("DG", p - 1, (2, )))) |
| 34 | + adios4dolfinx.read_function(u, finame / (prefix + "_velocity.bp"), "bp4") |
| 35 | + |
| 36 | + T = dolfinx.fem.Function(dolfinx.fem.FunctionSpace(mesh, ("CG", p))) |
| 37 | + adios4dolfinx.read_function(T, finame / (prefix + "_temperature.bp"), "bp4") |
| 38 | + |
| 39 | + mu = dolfinx.fem.Function(dolfinx.fem.FunctionSpace(mesh, ("DG", p - 2))) |
| 40 | + adios4dolfinx.read_function(mu, finame / (prefix + "_viscosity.bp"), "bp4") |
| 41 | + |
| 42 | + # Find cells |
| 43 | + bb_tree = dolfinx.geometry.bb_tree(mesh, mesh.topology.dim) |
| 44 | + cell_candidates = dolfinx.geometry.compute_collisions_points(bb_tree, x) |
| 45 | + colliding_cells = dolfinx.geometry.compute_colliding_cells( |
| 46 | + mesh, cell_candidates, x) |
| 47 | + cells = colliding_cells.array[colliding_cells.offsets[:-1]] |
| 48 | + |
| 49 | + # Temperature plot |
| 50 | + plt.figure(1, figsize=(2, 2)) |
| 51 | + T_data = T.eval(x, cells) |
| 52 | + triplt = plt.tricontourf(x[:,0], x[:,1], T_data.ravel(), vmin=0, vmax=1.0, |
| 53 | + cmap="inferno") |
| 54 | + plt.xlabel(r"$x$") |
| 55 | + plt.ylabel(r"$y$") |
| 56 | + plt.gca().set_aspect("equal") |
| 57 | + plt.axis("off") |
| 58 | + plt.savefig(f"{case}_temperature.png", bbox_inches="tight", pad_inches=0) |
| 59 | + plt.clf() |
| 60 | + |
| 61 | + # Velocity plot |
| 62 | + u_data = u.eval(x, cells) |
| 63 | + U, V = u_data[:,0], u_data[:,1] |
| 64 | + speed = np.sqrt(U**2 + V**2) |
| 65 | + tcf = plt.tricontourf(x[:,0], x[:,1], speed / speed.max(), cmap="Blues") |
| 66 | + # skip = slice(None, None, 8) |
| 67 | + # plt.quiver(x[skip,0], x[skip,1], U[skip], V[skip], linewidth=1, color="black") |
| 68 | + plt.xlabel(r"$x$") |
| 69 | + plt.ylabel(r"$y$") |
| 70 | + plt.gca().set_aspect("equal") |
| 71 | + plt.axis("off") |
| 72 | + plt.savefig(f"{case}_velocity.png", bbox_inches="tight", pad_inches=0) |
| 73 | + plt.clf() |
| 74 | + |
| 75 | + # Viscosity plot |
| 76 | + mu_data = mu.eval(x, cells) |
| 77 | + # lev_exp = np.arange(np.floor(np.log10(mu_data.min()) - 1), |
| 78 | + # np.ceil(np.log10(mu_data.max()) + 1)) |
| 79 | + lev_exp = np.arange(-5.0, 2.0) |
| 80 | + levs = np.power(10, lev_exp) |
| 81 | + |
| 82 | + import matplotlib.colors |
| 83 | + import matplotlib.ticker |
| 84 | + triplt = plt.tricontourf(x[:,0], x[:,1], mu_data.ravel()-1e-10, levs, |
| 85 | + locator=matplotlib.ticker.LogLocator(), |
| 86 | + norm=matplotlib.colors.LogNorm(), cmap="Blues") |
| 87 | + plt.xlabel(r"$x$") |
| 88 | + plt.ylabel(r"$y$") |
| 89 | + plt.gca().set_aspect("equal") |
| 90 | + plt.axis("off") |
| 91 | + plt.savefig(f"{case}_viscosity.png", bbox_inches="tight", pad_inches=0) |
| 92 | + plt.clf() |
0 commit comments