| 1 |
#!/usr/bin/env python3 |
| 2 |
|
| 3 |
# SPDX-FileCopyrightText: 2026 Oak Ridge National Laboratory and Contributors |
| 4 |
# |
| 5 |
# SPDX-License-Identifier: Apache-2.0 |
| 6 |
|
| 7 |
from adios2 import Adios, Stream # pylint: disable=import-error |
| 8 |
import argparse |
| 9 |
import numpy as np # pylint: disable=import-error |
| 10 |
import matplotlib.pyplot as plt # pylint: disable=import-error |
| 11 |
import matplotlib.gridspec as gridspec # pylint: disable=import-error |
| 12 |
import decomp # pylint: disable=import-error |
| 13 |
|
| 14 |
|
| 15 |
def SetupArgs(): |
| 16 |
parser = argparse.ArgumentParser() |
| 17 |
parser.add_argument("--instream", "-i", help="Name of the input stream", required=True) |
| 18 |
parser.add_argument("--outfile", "-o", help="Name of the output file", default="screen") |
| 19 |
parser.add_argument("--varname", "-v", help="Name of variable read", default="U") |
| 20 |
parser.add_argument( |
| 21 |
"--nompi", "-nompi", help="ADIOS was installed without MPI", action="store_true" |
| 22 |
) |
| 23 |
parser.add_argument( |
| 24 |
"--displaysec", |
| 25 |
"-dsec", |
| 26 |
help="Float representing gap between plot window refresh", |
| 27 |
default=0.2, |
| 28 |
) |
| 29 |
args = parser.parse_args() |
| 30 |
|
| 31 |
args.displaysec = float(args.displaysec) |
| 32 |
args.nx = 1 |
| 33 |
args.ny = 1 |
| 34 |
args.nz = 1 |
| 35 |
|
| 36 |
return args |
| 37 |
|
| 38 |
|
| 39 |
def PlotPDF(pdf, bins, args, start, count, step, fontsize): |
| 40 |
# Plotting part |
| 41 |
displaysec = args.displaysec |
| 42 |
gs = gridspec.GridSpec(1, 1) |
| 43 |
fig = plt.figure(1, figsize=(8, 8)) |
| 44 |
ax = fig.add_subplot(gs[0, 0]) |
| 45 |
localSliceIdx = count[0] // 2 |
| 46 |
globalSliceIdx = start[0] + localSliceIdx |
| 47 |
|
| 48 |
ax.plot(bins, pdf[localSliceIdx], "r*-") |
| 49 |
|
| 50 |
ax.set_title( |
| 51 |
"{0}, slice {1}, step {2}".format(args.varname, globalSliceIdx, step), |
| 52 |
fontsize=fontsize, |
| 53 |
) |
| 54 |
ax.set_xlabel("bins", fontsize=fontsize) |
| 55 |
ax.set_ylabel("count", fontsize=fontsize) |
| 56 |
plt.tick_params(labelsize=fontsize - 4) |
| 57 |
plt.ion() |
| 58 |
if args.outfile == "screen": |
| 59 |
plt.show() |
| 60 |
plt.pause(displaysec) |
| 61 |
else: |
| 62 |
imgfile = args.outfile + "{0:0>5}".format(step) + "_" + str(globalSliceIdx) + ".png" |
| 63 |
fig.savefig(imgfile) |
| 64 |
|
| 65 |
plt.clf() |
| 66 |
|
| 67 |
|
| 68 |
def read_data(args, fr, start_coord, size_dims): |
| 69 |
var1 = args.varname |
| 70 |
data = fr.read(var1, start_coord, size_dims) |
| 71 |
data = np.squeeze(data) |
| 72 |
return data |
| 73 |
|
| 74 |
|
| 75 |
if __name__ == "__main__": |
| 76 |
# fontsize on plot |
| 77 |
fontsize = 24 |
| 78 |
|
| 79 |
args = SetupArgs() |
| 80 |
# print(args) |
| 81 |
|
| 82 |
# Setup up 2D communicators if MPI is installed |
| 83 |
mpi = decomp.MPISetup(args, 4) |
| 84 |
myrank = mpi.rank["app"] |
| 85 |
|
| 86 |
# Read the data from this object |
| 87 |
adios = Adios("adios2.xml", mpi.comm_app) |
| 88 |
io = adios.declare_io("PDFAnalysisOutput") |
| 89 |
fr = Stream(io, args.instream, "r", mpi.comm_app) |
| 90 |
|
| 91 |
# Read through the steps, one at a time |
| 92 |
plot_step = 0 |
| 93 |
for fr_step in fr.steps(): |
| 94 |
cur_step = fr_step.current_step() |
| 95 |
vars_info = fr_step.available_variables() |
| 96 |
# print (vars_info) |
| 97 |
pdfvar = args.varname + "/pdf" |
| 98 |
binvar = args.varname + "/bins" |
| 99 |
shape2_str = vars_info[pdfvar]["Shape"].split(",") |
| 100 |
shape2 = list(map(int, shape2_str)) |
| 101 |
|
| 102 |
# Equally partition the PDF arrays among readers |
| 103 |
s0, c0 = decomp.Locate(myrank, mpi.size, shape2[0]) |
| 104 |
start = [s0, 0] |
| 105 |
count = [c0, shape2[1]] |
| 106 |
start_bins = [0] |
| 107 |
count_bins = [shape2[1]] |
| 108 |
|
| 109 |
# print("Rank {0} reads {1} slices from offset {2}".format(myrank, count[0], start[0])) |
| 110 |
|
| 111 |
pdf = fr_step.read(pdfvar, start, count) |
| 112 |
bins = fr_step.read(binvar, start_bins, count_bins) |
| 113 |
sim_step = fr_step.read("step") |
| 114 |
|
| 115 |
if myrank == 0: |
| 116 |
print( |
| 117 |
"PDF Plot step {0} processing analysis step {1} simulation step {2}".format( |
| 118 |
plot_step, cur_step, sim_step |
| 119 |
), |
| 120 |
flush=True, |
| 121 |
) |
| 122 |
# if cur_step == 0: |
| 123 |
# print("Variable" + pdfvar + " shape is {" + vars_info[pdfvar]["Shape"]+"}") |
| 124 |
|
| 125 |
PlotPDF(pdf, bins, args, start, count, sim_step, fontsize) |
| 126 |
plot_step = plot_step + 1 |
| 127 |
if not args.nompi: |
| 128 |
mpi.comm_app.Barrier() |
| 129 |
|
| 130 |
fr.close() |