Skip to content

Commit

Permalink
Merge branch 'cooling'
Browse files Browse the repository at this point in the history
  • Loading branch information
Weibo-Hu committed May 22, 2024
2 parents 8186194 + 7679b94 commit 010f3bd
Show file tree
Hide file tree
Showing 18 changed files with 2,222 additions and 218 deletions.
Binary file added logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 6 additions & 6 deletions script/SFD.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
delta = input ("input filter width: delta =")
chi = input ("input dissipation control coefficient: chi =")

plt.semilogy(time, L2)
plt.semilogy(time, L2, 'k-')
# plt.xlim ([0, 3000])
plt.ylim ([1e-10, 1e-1])
plt.xlabel ("time")
plt.ylabel ("residual")
plt.grid(visible=True, which='major', color='grey', linestyle='-')
plt.grid(visible=True, which='minor', color='grey', linestyle=':', alpha=0.2)
plt.ylim([1e-10, 1e-1])
plt.xlabel("time", fontsize=12)
plt.ylabel("residual", fontsize=12)
plt.grid(visible=True, which='major', color='grey', linestyle=':', alpha=0.7)
# plt.grid(visible=True, which='minor', color='grey', linestyle=':', alpha=0.2)
plt.savefig("d"+str(delta)+"x"+str(chi)+".jpg", dpi=600)
plt.show()

Expand Down
119 changes: 119 additions & 0 deletions script/grid2plot3d.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wen Feb 21 14:48:11 2024
This code for coverting grid tecplot format to plot3d format
@author: weibo
"""
# %% Load necessary module
import numpy as np
from scipy.interpolate import griddata
from scipy.io import FortranFile
import os
from source import pytecio as pt

# %%
# convert tecplot grid to plot3d grid
def grid2plot3d(path, outpath, option='3d'):
vars = ['x', 'y', 'z']
dirs = os.listdir(path)
for i in range(np.size(dirs)):
data, _ = pt.ReadSinglePlt(path + dirs[i], vars)
grid = 'grid_' + "%06d" % i + '.xyz'
print('processing ' + dirs[i])
xa = np.unique(data['x'])
ya = np.unique(data['y'])
za = np.unique(data['z'])
ymat, zmat, xmat = np.meshgrid(ya, za, xa)
# organize grid
df_grid = np.vstack((
xmat.flatten(order='C'),
ymat.flatten(order='C'),
zmat.flatten(order='C')
))
# df_grid = np.vstack((df_grid, zmat.flatten(order='C')))
dim = np.array([np.size(xa), np.size(ya), np.size(za)], dtype=np.int32)
# output grid
file = FortranFile(outpath + grid, 'w')
file.write_record(np.array([1], dtype=np.int32))
file.write_record(dim)
file.write_record(df_grid)
file.close()
return (df_grid)


def interp2d(x, y, z):
xa = np.unique(x)
ya = np.unique(y)
xmat, ymat = np.meshgrid(xa, ya)
zmat = griddata((x, y), z, (xmat, ymat))
return (zmat)


def select_block(inpath, outpath, zone):
dirs = os.listdir(inpath)
namepick = []
namedrop = []
for i in range(np.size(dirs)):
with open (inpath + dirs[i]) as f:
lines = f.readlines()
xrange = np.float64(lines[13].split()[2:5:2])
yrange = np.float64(lines[14].split()[2:5:2])
zrange = np.float64(lines[15].split()[2:5:2])
cond1 = (xrange[0] >= zone[0][0]) & (xrange[0] <= zone[0][1])
cond2 = (yrange[0] >= zone[1][0]) & (yrange[0] <= zone[1][1])
cond3 = (zrange[0] >= zone[2][0]) & (zrange[0] <= zone[2][1])
if (cond1 & cond2 & cond3):
namepick.append(dirs[i])
else:
namedrop.append(dirs[i])
# list of names
with open(outpath+'namedrop.dat', 'w') as fp:
fp.write('\n'.join(namedrop))
with open(outpath+'namepick.dat', 'w') as fp:
fp.write('\n'.join(namepick))
return (namedrop)

def edit_block(inpath, outpath, zarr):
dirs = os.listdir(inpath)
zstr = [str(j) for j in zarr]
for i in range(np.size(dirs)):
with open (inpath + dirs[i]) as f:
lines = f.readlines()
nz_old = lines[18].split()[2]
if nz_old == '64':
lines[18] = lines[18].replace(nz_old, zstr[0])
elif nz_old == '32':
lines[18] = lines[18].replace(nz_old, zstr[1])
elif nz_old == '16':
lines[18] = lines[18].replace(nz_old, zstr[2])
elif nz_old == '8':
lines[18] = lines[18].replace(nz_old, zstr[3])
else:
print('there is an error for ' + dirs[i])
with open(outpath+dirs[i], 'w') as fp:
fp.write("".join(lines))


# %%
if __name__ == "__main__":
# path = 'E:/cases/'
# filenm = 'slice_3d.dat'

inpath = 'D:/cases/ramp_st1/grid/'
outpath = 'D:/cases/ramp_st1/grid_new/'
zone = np.array(
[[-225, 87.5],
[0, 48],
[-4, 4]]
)
namedrop = select_block(inpath, outpath, zone)
for i in range(np.size(namedrop)):
os.remove(inpath + namedrop[i])

zarr0 = np.array([64, 32, 16, 8])
zarr = np.array([80, 40, 20, 10])
edit_block(inpath, outpath, zarr)
path = '/media/work/data1/flap2/flapping_wall/'
grid2plot3d(path+'TP_grid/', path+'grid/', option='3d')
19 changes: 12 additions & 7 deletions script/tec2plot3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ def csv2plot3d(path, filenm, vars, option='2d', input_nm=None, skip=1):
ext_nm = os.path.splitext(filenm)[-1]
if input_nm is None:
if ext_nm == '.dat':
data = pd.read_csv(path + filenm, sep=',', index_col=False)
data = pd.read_csv(path + filenm, sep=',', skipinitialspace=True, index_col=False)
if ext_nm == '.h5':
data = pd.read_hdf(path + filenm, index_col=False)
else:
if ext_nm == '.dat':
data = pd.read_csv(path + filenm, sep=',', index_col=False,
header=0, names=input_nm)
header=None, names=input_nm)
if ext_nm == '.h5':
data = pd.read_hdf(path + filenm, index_col=False,
header=0, names=input_nm)
header=None, names=input_nm)
grid = 'grid.xyz'
solu = 'uvw3D.q'
xa = np.unique(data['x'])[::skip]
Expand Down Expand Up @@ -93,9 +93,14 @@ def create_meanval(path, filenm):
if __name__ == "__main__":
# path = 'E:/cases/'
# filenm = 'slice_3d.dat'
path = 'E:/cases/flat_base/'
create_meanval(path + 'MeanFlow/', 'MeanFlow.h5')
filenm = 'MeanFlow/MeanFlow.h5'
path = 'D:/cases/flat_plate_last/'
meanflow = False
if meanflow is True:
create_meanval(path + 'MeanFlow/', 'MeanFlow.h5')
filenm = 'MeanFlow/MeanFlow.h5'
else:
filenm = 'MeanFlow.dat'
nms = ['x', 'y', 'z', 'u', 'v', 'w', 'rho', 'p', 'T']
vars = ['rho', 'u', 'v', 'w', 'T', 'p']
csv2plot3d(path, filenm, vars, option='2d', input_nm=nms, skip=4)
# csv2plot3d(path, filenm, vars, option='2d', input_nm=nms, skip=4)
csv2plot3d(path, filenm, vars, option='2d', skip=4)
66 changes: 36 additions & 30 deletions source/3d_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
font = {"family": "Times New Roman", "color": "k", "weight": "normal"}
cm2in = 1 / 2.54
# %%
path = "/mnt/work/cases/wavy_1009/"
path = "/media/weibo/Weibo_data/2023cases/cooling2/"
# path = 'E:/cases/wavy_1009/'
p2p.create_folder(path)
pathP = path + "probes/"
Expand Down Expand Up @@ -77,10 +77,10 @@
va.wall_line(MeanFlow.PlanarData, pathM, mask=corner)
# %% check mesh
temp = MeanFlow.PlanarData # [["x", "y"]]
df = temp.query("x>=00.0 & x<=130.0 & y>=-3.0 & y<=10.0")
df = temp.query("x>=20.0 & x<=350.0 & y>=0.0 & y<=6.0")
# df = temp.query("x>=-5.0 & x<=10.0 & y>=-3.0 & y<=2.0")
ux = np.unique(df.x)
uy = np.unique(df.y)
ux = np.unique(df.x)[::10]
uy = np.unique(df.y)[::5]
fig, ax = plt.subplots(figsize=(9.0, 3.2))
matplotlib.rc("font", size=tsize)
for i in range(np.size(ux)):
Expand All @@ -98,6 +98,10 @@
ax.tick_params(labelsize=nsize)
ax.set_xlabel(r"$x$", fontsize=tsize)
ax.set_ylabel(r"$y$", fontsize=tsize)
plt.tight_layout(pad=0.5, w_pad=0.5, h_pad=1)
plt.savefig(pathF + "Grid.svg", bbox_inches="tight")
plt.show()
# %%
# wavy = temp.loc[np.round(temp['walldist'], 3) == 0.001]
wavy = pd.read_csv(pathM + "wavy.dat", skipinitialspace=True)
ax.plot(wavy["x"], wavy["y"], "b--", linewidth=1.5)
Expand All @@ -111,7 +115,7 @@
edgecolor="red",
)
plt.tight_layout(pad=0.5, w_pad=0.5, h_pad=1)
# plt.savefig(pathF + "Grid.svg", bbox_inches="tight")
plt.savefig(pathF + "Grid.svg", bbox_inches="tight")
plt.show()

# %% dividing streamline
Expand Down Expand Up @@ -172,12 +176,12 @@
MeanFlow.copy_meanval()
x, y = np.meshgrid(np.unique(MeanFlow.x), np.unique(MeanFlow.y))
var = "u"
lh = 3.0
lh = 1.0
u = griddata((MeanFlow.x, MeanFlow.y), MeanFlow.u, (x, y))
walldist = griddata((MeanFlow.x, MeanFlow.y), MeanFlow.walldist, (x, y), method="cubic")
cover1 = walldist < 0.0 # np.where(walldist[:,:] < 0.0)
cover = cover1 | corner
u = np.ma.array(u, mask=cover) # mask=cover
# cover1 = walldist < 0.0 # np.where(walldist[:,:] < 0.0)
# cover = cover1 | corner
# u = np.ma.array(u, mask=cover) # mask=cover
# u[cover] = np.ma.masked
print("u_max=", np.max(MeanFlow.u))
print("u_min=", np.min(MeanFlow.u))
Expand All @@ -189,9 +193,9 @@
rg1 = np.linspace(cval1, cval2, 41)
cbar = ax.contourf(x, y, u, cmap="rainbow", levels=rg1, extend="both") # rainbow_r
# cbar1 = ax.contour(x, y, u, levels=[0.0])
ax.set_xlim(20, 120.0)
ax.set_xlim(30, 350)
ax.set_ylim(np.min(y), 10.0)
ax.set_yticks(np.linspace(0.0, 10.0, 5))
ax.set_yticks(np.linspace(0.0, 8.0, 5))
ax.tick_params(labelsize=nsize)
ax.set_xlabel(r"$x$", fontsize=tsize)
ax.set_ylabel(r"$y$", fontsize=tsize)
Expand All @@ -205,24 +209,24 @@
# %% Plot rho contour of the mean flow field
# MeanFlow.AddVariable('rho', 1.7**2*1.4*MeanFlow.p/MeanFlow.T)
MeanFlow.copy_meanval()
var = "rho"
var = "u"
lh = 1.0
rho = griddata((MeanFlow.x, MeanFlow.y), MeanFlow.rho, (x, y))
u = griddata((MeanFlow.x, MeanFlow.y), MeanFlow.u, (x, y))
walldist = griddata((MeanFlow.x, MeanFlow.y), MeanFlow.walldist, (x, y))
cover = (walldist < 0.0) | corner
rho = np.ma.array(rho, mask=cover)
u = np.ma.array(u, mask=cover)
# cover = (walldist < 0.0) | corner
# rho = np.ma.array(rho, mask=cover)
# u = np.ma.array(u, mask=cover)
print("rho_max=", np.max(rho))
print("rho_min=", np.min(rho))
cval1 = 0.1 # 0.3
cval2 = 1.0 # 1.4
cval1 = 0.1 #1.0 #
cval2 = 1.0 #7.0 #
fig, ax = plt.subplots(figsize=(7.3, 2.3))
matplotlib.rc("font", size=tsize)
rg1 = np.linspace(cval1, cval2, 21)
cbar = ax.contourf(x, y, rho, cmap="rainbow", levels=rg1, extend="both")
ax.contour(x, y, u, levels=[0.0], linestyles="dotted") # rainbow_r
ax.set_xlim(0.0, 160.0)
ax.set_xlim(20, 360)
ax.set_ylim(np.min(y), 10.0)
ax.set_yticks(np.linspace(np.min(y), 10.0, 5))
ax.tick_params(labelsize=nsize)
Expand All @@ -236,7 +240,8 @@
cbar = plt.colorbar(
cbar, cax=cbaxes, extendrect="False", orientation="horizontal", ticks=rg2
)
cbar.set_label(r"$\langle \rho \rangle/\rho_{\infty}$", rotation=0, fontsize=tsize)
lab = r"$\langle \rho \rangle/\rho_{\infty}$" #r"$\langle T \rangle/T_{\infty}$" #
cbar.set_label(lab, rotation=0, fontsize=tsize)
# Add boundary layer
# boundary = np.loadtxt(pathM + "BoundaryEdge.dat", skiprows=1)
boundary = pd.read_csv(pathM + "BoundaryEdge.dat", skipinitialspace=True)
Expand All @@ -251,8 +256,8 @@
# shock2 = np.loadtxt(pathM + "ShockLine2.dat", skiprows=1)
# ax.plot(shock2[:, 0], shock2[:, 1], "w", linewidth=1.5)
# Add sonic line
sonic = pd.read_csv(pathM + "SonicLine.dat", skipinitialspace=True)
ax.plot(sonic.x / lh, sonic.y / lh, "w--", linewidth=1.5)
# sonic = pd.read_csv(pathM + "SonicLine.dat", skipinitialspace=True)
# ax.plot(sonic.x / lh, sonic.y / lh, "w--", linewidth=1.5)
# Add dividing line(separation line)
# dividing = pd.read_csv(pathM + "BubbleLine.dat", skipinitialspace=True)
# ax.plot(dividing.x / lh, dividing.y / lh, "k--", linewidth=1.5)
Expand Down Expand Up @@ -280,7 +285,7 @@
# maxlength=30.0,
# linewidth=1.0,
# )
plt.savefig(pathF + "MeanFlow_test.svg", bbox_inches="tight")
plt.savefig(pathF + "MeanFlow_rho.svg", bbox_inches="tight")
plt.show()
# %%############################################################################
"""
Expand Down Expand Up @@ -430,24 +435,24 @@
#
# %% Plot rms contour of the mean flow field
x, y = np.meshgrid(np.unique(MeanFlow.x), np.unique(MeanFlow.y))
var = "<v`v`>"
var = "<u`u`>"
var_val = getattr(MeanFlow.PlanarData, var)
uu = griddata((MeanFlow.x, MeanFlow.y), var_val, (x, y))
u = griddata((MeanFlow.x, MeanFlow.y), MeanFlow.u, (x, y))
print("uu_max=", np.max(np.sqrt(np.abs(var_val))))
print("uu_min=", np.min(np.sqrt(np.abs(var_val))))
cover = (walldist < 0.0) | corner
uu = np.ma.array(uu, mask=cover)
u = np.ma.array(u, mask=cover)
# cover = (walldist < 0.0) | corner
# uu = np.ma.array(uu, mask=cover)
# u = np.ma.array(u, mask=cover)
fig, ax = plt.subplots(figsize=(7.2, 2.4))
matplotlib.rc("font", size=tsize)
cb1 = 0.0
cb2 = 0.06
cb2 = 0.1
rg1 = np.linspace(cb1, cb2, 21) # 21)
cbar = ax.contourf(
x / lh, y / lh, np.sqrt(np.abs(uu)), cmap="Spectral_r", levels=rg1, extend="both"
) # rainbow_r # jet # Spectral_r
ax.set_xlim(10, 200.0)
ax.set_xlim(20, 360.0)
ax.set_ylim(np.min(y), 10.0)
ax.set_yticks(np.linspace(0.0, 10.0, 5))
ax.tick_params(labelsize=nsize)
Expand Down Expand Up @@ -476,8 +481,9 @@
cbar = plt.colorbar(
cbar, cax=cbaxes, orientation="horizontal", extendrect="False", ticks=rg2
)
lab = r"$\sqrt{\langle u^\prime u^\prime \rangle}$"
cbar.set_label(
r"$\sqrt{\langle v^\prime v^\prime \rangle}$", rotation=0, fontsize=tsize,
lab, rotation=0, fontsize=tsize,
)
# Add boundary layer
boundary = pd.read_csv(pathM + "BoundaryEdge.dat", skipinitialspace=True)
Expand All @@ -497,7 +503,7 @@
# dividing = pd.read_csv(pathM + "DividingLine.dat", skipinitialspace=True)
# ax.plot(dividing.x / lh, dividing.y / lh, "k--", linewidth=1.2)

plt.savefig(pathF + "MeanFlowRMSVV1.svg", bbox_inches="tight")
plt.savefig(pathF + "MeanFlowRMSUU.svg", bbox_inches="tight")
plt.show()

# %%############################################################################
Expand Down
Loading

0 comments on commit 010f3bd

Please sign in to comment.