|
| 1 | +import glob |
| 2 | +import os |
| 3 | +import re |
| 4 | +import sys |
| 5 | + |
| 6 | +import numpy as np |
| 7 | + |
| 8 | +import tecplot as tp |
| 9 | +from tecplot.constant import * |
| 10 | + |
| 11 | +def plot_data(datafile, frame): |
| 12 | + """Plot Isosurface of constant Pressure, contouring on Temperature""" |
| 13 | + with frame.activated(): |
| 14 | + tp.data.load_tecplot(datafile) |
| 15 | + plot = frame.plot(PlotType.Cartesian3D) |
| 16 | + plot.activate() |
| 17 | + plot.show_shade = False |
| 18 | + plot.show_slices = True |
| 19 | + plot.show_isosurfaces = True |
| 20 | + contour = plot.slice(0).contour.flood_contour_group |
| 21 | + contour.variable = frame.dataset.variable('Temperature') |
| 22 | + contour.legend.auto_resize = True |
| 23 | + contour.levels.reset_levels(np.linspace(280, 380, 201)) |
| 24 | + isosurf = plot.isosurface(0) |
| 25 | + isosurf.definition_contour_group_index = 1 |
| 26 | + isosurf.definition_contour_group.variable = frame.dataset.variable('Pressure') |
| 27 | + isosurf.isosurface_values = -6000 |
| 28 | + isosurf.contour.flood_contour_group = contour |
| 29 | + slice = frame.plot().slice(0) |
| 30 | + slice.effects.use_translucency = True |
| 31 | + slice.effects.surface_translucency = 40 |
| 32 | + plot.view.psi = 68.2286 |
| 33 | + plot.view.theta = -124.114 |
| 34 | + plot.view.position = 2.95931, 2.15999, 1.45886 |
| 35 | + plot.view.width = 0.339885 |
| 36 | + |
| 37 | +def frame_grid(nrows, ncols): |
| 38 | + scale = max(nrows, ncols) |
| 39 | + frames = [] |
| 40 | + for row in range(nrows): |
| 41 | + frame_row = [] |
| 42 | + for col in range(ncols): |
| 43 | + if row or col: |
| 44 | + frame = tp.active_page().add_frame() |
| 45 | + else: |
| 46 | + frame = tp.active_page().active_frame() |
| 47 | + pos = (scale * col / ncols, |
| 48 | + scale * (1 - row / nrows)) |
| 49 | + height = scale / nrows |
| 50 | + width = scale / ncols |
| 51 | + frame.position = pos |
| 52 | + frame.height = height |
| 53 | + frame.width = width |
| 54 | + frame_row.append(frame) |
| 55 | + frames.append(frame_row) |
| 56 | + tp.macro.execute_command('$!WorkspaceView FitAllFrames') |
| 57 | + return frames |
| 58 | + |
| 59 | +if '-c' in sys.argv: |
| 60 | + tp.session.connect() |
| 61 | + tp.new_layout() |
| 62 | + |
| 63 | +# get list of input data files |
| 64 | +files = sorted(glob.glob('hotwatermixing/HotWaterMixing_Y05YT10*.plt')) |
| 65 | + |
| 66 | +# setup regular expression to extract input velocity (Z) and temperature (ZT) |
| 67 | +pattern = re.compile(r'Z(\d+)ZT(\d+)') |
| 68 | + |
| 69 | +# filename format |
| 70 | +filename = 'hotwatermixing/HotWaterMixing_Y05YT10Z{:0>2}ZT{:0>3}.plt' |
| 71 | + |
| 72 | +# get sorted values of input velocity (Z) and temperature (ZT) |
| 73 | +Z, ZT = zip(*[[int(x) |
| 74 | + for x in pattern.search(f).groups()] |
| 75 | + for f in files]) |
| 76 | +Z = sorted(set(Z)) |
| 77 | +ZT = sorted(set(ZT)) |
| 78 | + |
| 79 | +# create grid of frames |
| 80 | +frames = frame_grid(len(ZT), len(Z)) |
| 81 | + |
| 82 | +# in each frame, load data and adjust plot style |
| 83 | +for zt, frame_row in zip(ZT, frames): |
| 84 | + for z, frame in zip(Z, frame_row): |
| 85 | + datafile = filename.format(z, zt) |
| 86 | + if os.path.exists(datafile): |
| 87 | + plot_data(datafile, frame) |
| 88 | + |
| 89 | +tp.save_png('hotwater-grid.png') |
| 90 | + |
0 commit comments