Untitled
unknown
plain_text
4 years ago
3.9 kB
11
Indexable
import json
import matplotlib
matplotlib.use('Agg')
from matplotlib.pyplot import subplots, tight_layout
from pandas import read_csv
from numpy import loadtxt, linspace, min, zeros, int, shape
def findZeroCrossing(x, y):
npts = shape(x)[0]
crossed = "false"
i = 1
xR = 0
while (crossed == "false") & (i <= npts - 1):
if (y[i] < 0) & (x[i] > 0.1): # second test to consider only remote location
xR = x[i - 1] - y[i - 1] * (x[i] - x[i - 1]) / (y[i] - y[i - 1])
crossed = "true"
i = i + 1
return xR
def main(name: str,
fname: str) -> None:
with open(fname) as f:
data = json.load(f)
H = 2.0 * data['h']
U0 = data['Uav']
xRA = zeros([101])
xRB = zeros([101])
xRC = zeros([101])
for itr in linspace(0,10,101):
fig, ax = subplots()
fitr = str(round(itr, 1))
figTitle = 'Skin friction coefficient at lower wall, \n t = ' + fitr + ' s'
fig.suptitle(figTitle)
fluidFileA='/g/data/wp10/switt/cht_unst_A_1_200_st_1.25e-3/postProcessing/wallShearStressGraph/fluid/' + fitr + '/line_wallShearStress.xy'
xiFA, CfFA = loadtxt(fluidFileA, skiprows=0, usecols=(0, 1),
dtype = 'float32', unpack='True')
CfFA = CfFA / U0**2 * 2.0
xRA = findZeroCrossing(xiFA, CfFA)
ax.plot(xiFA[:-5] / H, CfFA[:-5],
color='red', linestyle='-', marker='None',
label=r'case A, fluid, $y/H = -1/2$')
ax.plot([xRA],[0], color='black', linestyle='None', marker='o',
label=r'case A, $x_R$ = ' + str(round(xRA, 5)))
fluidFileB='/g/data/wp10/switt/cht_unst_A_1_200_st_2.5e-3/postProcessing/wallShearStressGraph/fluid/' + fitr + '/line_wallShearStress.xy'
xiFB, CfFB = loadtxt(fluidFileB, skiprows=0, usecols=(0, 1),
dtype = 'float32', unpack='True')
CfFB = CfFB / U0**2 * 2.0
xRB = findZeroCrossing(xiFB, CfFB)
ax.plot(xiFB[:-5] / H, CfFB[:-5],
color='red', linestyle='-', marker='None',
label=r'case B, fluid, $y/H = -1/2$')
ax.plot([xRB],[0], color='black', linestyle='None', marker='o',
label=r'case B, $x_R$ = ' + str(round(xRB, 5)))
fluidFileC='/g/data/wp10/switt/cht_unst_A_1_200_st_5e-3/postProcessing/wallShearStressGraph/fluid/' + fitr + '/line_wallShearStress.xy'
xiFC, CfFC = loadtxt(fluidFileC, skiprows=0, usecols=(0, 1),
dtype = 'float32', unpack='True')
CfFC = CfFC / U0**2 * 2.0
xRC = findZeroCrossing(xiFC, CfFC)
ax.plot(xiFB[:-5] / H, CfFB[:-5],
color='red', linestyle='-', marker='None',
label=r'case B, fluid, $y/H = -1/2$')
ax.plot([xRB],[0], color='black', linestyle='None', marker='o',
label=r'case B, $x_R$ = ' + str(round(xRC, 5)))
ax.set_xlabel(r'$x / H$')
ax.set_ylabel(r'$C_f$')
ax.legend(loc='best')
ax.set_xlim([0, 60])
ax.set_ylim([0.8, 1])
figname = 'bfs_' + fitr.zfill(5) + '.png'
fig.tight_layout()
fig.savefig(figname)
matplotlib.pyplot.close()
fig, ax = subplots()
ax.plot(linspace(0,10,101), xRA, 'ro', label='case A: A_1_200_st_1.25e-3')
ax.plot(linspace(0,10,101), xRB, 'bo', label='case B: A_1_200_st_2.5e-3')
ax.plot(linspace(0,10,101), xRC, 'go', label='case C: A_1_200_st_5e-3')
ax.set_xlabel(r'$x / H$')
ax.set_ylabel(r'$C_f$')
ax.legend(loc='best')
ax.set_ylim([-1.5e-4, 1.5e-4])
figname = 'bfs_Cf.png'
fig.tight_layout()
fig.savefig(figname)
matplotlib.pyplot.close()
if __name__ == '__main__':
from sys import argv
from os.path import basename, splitext
main(splitext(basename(argv[0]))[0], *argv[1:])
Editor is loading...