Skip to content

Commit 8bd5c91

Browse files
committed
grid of hotwater mixing examples
1 parent 975ed38 commit 8bd5c91

8 files changed

+1230
-262
lines changed

hotwater-grid-stylesheet.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import glob
2+
import os
3+
import re
4+
import sys
5+
6+
import tecplot as tp
7+
from tecplot.constant import *
8+
9+
def frame_grid(nrows, ncols):
10+
scale = max(nrows, ncols)
11+
frames = []
12+
for row in range(nrows):
13+
frame_row = []
14+
for col in range(ncols):
15+
if row or col:
16+
frame = tp.active_page().add_frame()
17+
else:
18+
frame = tp.active_page().active_frame()
19+
pos = (scale * col / ncols,
20+
scale * (1 - row / nrows))
21+
height = scale / nrows
22+
width = scale / ncols
23+
frame.position = pos
24+
frame.height = height
25+
frame.width = width
26+
frame_row.append(frame)
27+
frames.append(frame_row)
28+
tp.macro.execute_command('$!WorkspaceView FitAllFrames')
29+
return frames
30+
31+
if '-c' in sys.argv:
32+
tp.session.connect(port=7601)
33+
tp.new_layout()
34+
35+
# get list of input data files
36+
files = sorted(glob.glob('hotwatermixing/HotWaterMixing_Y05YT10*.plt'))
37+
38+
# setup regular expression to extract input velocity (Z) and temperature (ZT)
39+
pattern = re.compile(r'Z(\d+)ZT(\d+)')
40+
41+
# filename format
42+
filename = 'hotwatermixing/HotWaterMixing_Y05YT10Z{:0>2}ZT{:0>3}.plt'
43+
44+
# get sorted values of input velocity (Z) and temperature (ZT)
45+
Z, ZT = zip(*[[int(x)
46+
for x in pattern.search(f).groups()]
47+
for f in files])
48+
Z = sorted(set(Z))
49+
ZT = sorted(set(ZT))
50+
51+
# create grid of frames
52+
frames = frame_grid(len(ZT), len(Z))
53+
54+
# in each frame, load data and adjust plot style using stylesheet
55+
for zt, frame_row in zip(ZT, frames):
56+
for z, frame in zip(Z, frame_row):
57+
datafile = filename.format(z, zt)
58+
if os.path.exists(datafile):
59+
tp.data.load_tecplot(datafile, frame=frame)
60+
frame.load_stylesheet('isosurface.sty')
61+
62+
tp.save_png('hotwater-grid-stylesheet.png')

hotwater-grid.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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

Comments
 (0)