|
| 1 | +#!/usr/bin/env python |
| 2 | +from __future__ import absolute_import, division, print_function, unicode_literals |
| 3 | + |
| 4 | +""" |
| 5 | +Example: |
| 6 | +
|
| 7 | +$ mpirun -n 1 python ./heat_transfer.py -f inputstream -o outputstream -v varname |
| 8 | +""" |
| 9 | + |
| 10 | +import adios2 |
| 11 | +import argparse |
| 12 | + |
| 13 | +import numpy as np |
| 14 | +import matplotlib.pyplot as plt |
| 15 | +import matplotlib.gridspec as gridspec |
| 16 | +import decomp |
| 17 | + |
| 18 | + |
| 19 | +def SetupArgs(): |
| 20 | + parser = argparse.ArgumentParser() |
| 21 | + |
| 22 | + parser.add_argument("--instream", "-i", help="Name of the input stream", required=True) |
| 23 | + parser.add_argument("--outfile", "-o", help="Name of the output file", default="screen") |
| 24 | + parser.add_argument("--varname", "-v", help="Name of variable read", default="T") |
| 25 | + parser.add_argument("--nompi", "-nompi", help="ADIOS was installed without MPI", action="store_true") |
| 26 | + |
| 27 | + args = parser.parse_args() |
| 28 | + args.nx = 1 |
| 29 | + args.ny = 1 |
| 30 | + return args |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | +def Plot2D(args, fr, data, fullshape, step, fontsize, displaysec): |
| 35 | + gs = gridspec.GridSpec(1, 1) |
| 36 | + fig = plt.figure(1, figsize=(8,10)) |
| 37 | + ax = fig.add_subplot(gs[0, 0]) |
| 38 | + ax.imshow(data, origin='lower', extent=[0, fullshape[1], 0, fullshape[0]] ) |
| 39 | + |
| 40 | + for i in range(args.ny): |
| 41 | + y = fullshape[0] / args.ny * i |
| 42 | + ax.plot([0, fullshape[1]], [y, y], color='black') |
| 43 | + |
| 44 | + for i in range(args.nx): |
| 45 | + x = fullshape[1] / args.nx * i |
| 46 | + ax.plot([x, x], [0, fullshape[0]], color='black') |
| 47 | + |
| 48 | + ax.set_title("Timestep = {0}".format(step), fontsize=fontsize) |
| 49 | + ax.set_xlabel("x") |
| 50 | + ax.set_ylabel("y") |
| 51 | + |
| 52 | + plt.ion() |
| 53 | + if (args.outfile == "screen"): |
| 54 | + plt.show() |
| 55 | + plt.pause(displaysec) |
| 56 | + else: |
| 57 | + imgfile = args.outfile+str(step)+".png" |
| 58 | + fig.savefig(imgfile) |
| 59 | + |
| 60 | + plt.clf() |
| 61 | + |
| 62 | + |
| 63 | +if __name__ == "__main__": |
| 64 | + |
| 65 | + # fontsize on plot |
| 66 | + fontsize = 22 |
| 67 | + displaysec = 0.01 |
| 68 | + |
| 69 | + # Parse command line arguments |
| 70 | + args = SetupArgs() |
| 71 | + |
| 72 | + # Setup up 2D communicators if MPI is installed |
| 73 | + mpi = decomp.MPISetup(args) |
| 74 | + |
| 75 | + |
| 76 | + # Read the data from this object |
| 77 | + fr = adios2.open(args.instream, "r", mpi.comm_world, "adios2.xml", "VizInput") |
| 78 | + |
| 79 | + # Get the ADIOS selections -- equally partition the data if parallelization is requested |
| 80 | + start, size, fullshape = mpi.Partition(fr, args) |
| 81 | + |
| 82 | + # Read through the steps, one at a time |
| 83 | + step = 0 |
| 84 | + while (not fr.eof()): |
| 85 | + data = fr.read(args.varname, start, size, endl=True) |
| 86 | + |
| 87 | + # Print a couple simple diagnostics |
| 88 | + avg = np.average(data) |
| 89 | + std = np.std(data) |
| 90 | + print("step:{0}, rank: {1}, avg: {2:.3f}, std: {3:.3f}".format(step, mpi.rank['world'], avg, std)) |
| 91 | + Plot2D(args, fr, data, fullshape, step, fontsize, displaysec) |
| 92 | + |
| 93 | + step += 1 |
| 94 | + |
| 95 | + fr.close() |
| 96 | + |
0 commit comments