closure-challenge-v2-cfd-cases / data /extract_wbj_surface_lines.py
anon-closure-challenge-v2's picture
Add extraction utilities and dataset notes
8900ef0 verified
Raw History Blame Contribute Delete
3.84 kB
"""Extract centerline pressure lines from WingBody-junction surface .pvtu files.
DNS 1-6 coordinate convention (per kbwiki):
x = streamwise (origin at airfoil root leading edge)
y = normalwise (wall-normal; bottom wall at y=0)
z = spanwise (symmetry at z=0; lateral boundaries at z/T = +-4)
T = airfoil thickness = 71.7 mm (reference length)
Outputs (CSV with x/T, Cp = averaged_pressure / (rho_ref u_ref^2 / 2)):
bottom_wall_centerline.csv : z = 0 strip on the bottom wall
wing_root_chord.csv : y/T ~= 0.05 strip on the wing surface (near root)
The averaged_pressure stored in the .vtu is dimensionless: p / p_ref. We map to a
"reduced Cp" via: Cp = (p/p_ref - 1) * (gamma * Ma^2)^{-1} using gamma=1.4, Ma=0.078.
Usage: python extract_wbj_surface_lines.py
"""
import os
import pathlib
import sys
import numpy as np
import pandas as pd
import vtk
from vtk.util import numpy_support as ns
T = 1.0 # work in normalised x/T (data is already normalised in the DNS, so keep T=1)
Z_TOL = 0.01 # strip half-width in z/T
Y_TARGET = 0.05 # wing extraction height (near root)
Y_TOL = 0.01
GAMMA = 1.4
MACH = 0.078
DST = os.environ.get('WBJ_HIGHFIDELITY_DIR',
str(pathlib.Path(__file__).parent / 'ERCOFTAC_WingBodyJunction' / 'highfidelity'))
RAW = os.path.join(DST, 'raw_surface')
def load_pvtu(path):
reader = vtk.vtkXMLPUnstructuredGridReader()
reader.SetFileName(path)
reader.Update()
grid = reader.GetOutput()
pts = ns.vtk_to_numpy(grid.GetPoints().GetData()) # shape (N, 3)
pdata = grid.GetPointData()
arr_names = [pdata.GetArrayName(i) for i in range(pdata.GetNumberOfArrays())]
if 'averaged_pressure' not in arr_names:
raise RuntimeError(f'No averaged_pressure in {path}: have {arr_names}')
p = ns.vtk_to_numpy(pdata.GetArray('averaged_pressure'))
return pts, p
def p_to_cp(p_over_pref):
"""Convert dimensionless p/p_ref to a Cp-like coefficient.
For low Mach, Cp = (p - p_ref) / (0.5 rho_ref u_ref^2). Using p = (rho_ref/gamma) * (p/p_ref) * gamma:
Equivalently, (p/p_ref - 1) / (0.5 gamma Ma^2). At Ma=0.078, denom ~ 0.00426.
"""
return (p_over_pref - 1.0) / (0.5 * GAMMA * MACH**2)
def extract_strip(pts, p, axis_to_filter, target, tol):
mask = np.abs(pts[:, axis_to_filter] - target) < tol
return pts[mask], p[mask]
def main():
# --- bottom wall: z=0 strip ---
pts, p = load_pvtu(os.path.join(RAW, 'bottom_wall_averaged_pressure.pvtu'))
sub_pts, sub_p = extract_strip(pts, p, axis_to_filter=2, target=0.0, tol=Z_TOL)
cp = p_to_cp(sub_p)
df = pd.DataFrame({
'x_over_T': sub_pts[:, 0] / T,
'y_over_T': sub_pts[:, 1] / T,
'z_over_T': sub_pts[:, 2] / T,
'p_over_pref': sub_p,
'Cp': cp,
}).sort_values('x_over_T').reset_index(drop=True)
out = os.path.join(DST, 'bottom_wall_centerline.csv')
df.to_csv(out, index=False)
print(f' bottom_wall -> {os.path.basename(out)} '
f'({len(df)} rows; x range [{df.x_over_T.min():.2f}, {df.x_over_T.max():.2f}])')
# --- wing: y/T ~= 0.05 strip (root chord) ---
pts, p = load_pvtu(os.path.join(RAW, 'wing_averaged_pressure.pvtu'))
sub_pts, sub_p = extract_strip(pts, p, axis_to_filter=1, target=Y_TARGET, tol=Y_TOL)
cp = p_to_cp(sub_p)
df = pd.DataFrame({
'x_over_T': sub_pts[:, 0] / T,
'y_over_T': sub_pts[:, 1] / T,
'z_over_T': sub_pts[:, 2] / T,
'p_over_pref': sub_p,
'Cp': cp,
}).sort_values('x_over_T').reset_index(drop=True)
out = os.path.join(DST, 'wing_root_chord.csv')
df.to_csv(out, index=False)
print(f' wing_root -> {os.path.basename(out)} '
f'({len(df)} rows; x range [{df.x_over_T.min():.2f}, {df.x_over_T.max():.2f}])')
if __name__ == '__main__':
main()