|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# McGrattan |
| 3 | +# 2-26-2018 |
| 4 | +# umd_line_burner_process.py |
| 5 | +# |
| 6 | +# Read and process FDS output files for UMD Line Burner |
| 7 | + |
| 8 | +import os |
| 9 | +import numpy as np |
| 10 | +import pandas as pd |
| 11 | + |
| 12 | +Lf_dt = 10 |
| 13 | + |
| 14 | +outdir = '../../../out/UMD_Line_Burner/' |
| 15 | + |
| 16 | +fuel_name = ['methane', 'propane'] |
| 17 | +res_name = ['1p25cm', 'p625cm', 'p3125cm'] |
| 18 | + |
| 19 | +for i_fuel in range(2): |
| 20 | + |
| 21 | + for fds_resolution in range(3): |
| 22 | + |
| 23 | + dev_file = os.path.join(outdir, f"{fuel_name[i_fuel]}_dx_{res_name[fds_resolution]}_devc.csv") |
| 24 | + hrr_file = os.path.join(outdir, f"{fuel_name[i_fuel]}_dx_{res_name[fds_resolution]}_hrr.csv") |
| 25 | + |
| 26 | + # Read CSVs, skipping first two header lines |
| 27 | + DEV = pd.read_csv(dev_file, skiprows=2, header=None) |
| 28 | + HRR = pd.read_csv(hrr_file, skiprows=2, header=None) |
| 29 | + |
| 30 | + # Read headers separately (the first row after skiprows=1) |
| 31 | + with open(dev_file, 'r') as f: |
| 32 | + header_lines = [next(f) for _ in range(2)] |
| 33 | + dev_headers = header_lines[1].strip().split(',') |
| 34 | + |
| 35 | + with open(hrr_file, 'r') as f: |
| 36 | + header_lines = [next(f) for _ in range(2)] |
| 37 | + hrr_headers = header_lines[1].strip().split(',') |
| 38 | + |
| 39 | + # Locate columns (match MATLAB’s strcmp behavior exactly) |
| 40 | + Time_idx = dev_headers.index('Time') |
| 41 | + XO2_idx = dev_headers.index('"XO2"') |
| 42 | + qrad1_idx = dev_headers.index('"qrad1"') |
| 43 | + qrad2_idx = dev_headers.index('"qrad2"') |
| 44 | + Lf_idx = dev_headers.index('"L_F"') |
| 45 | + |
| 46 | + HRR_idx = hrr_headers.index('HRR') |
| 47 | + Qrad_idx = hrr_headers.index('Q_RADI') |
| 48 | + |
| 49 | + Time_FDS = DEV.iloc[:, Time_idx].values |
| 50 | + XO2_FDS = DEV.iloc[:, XO2_idx].values |
| 51 | + Qdot_FDS = HRR.iloc[:, HRR_idx].values |
| 52 | + Qrad_FDS = HRR.iloc[:, Qrad_idx].values |
| 53 | + q_R_FDS = 0.5 * (DEV.iloc[:, qrad1_idx].values + DEV.iloc[:, qrad2_idx].values) |
| 54 | + Lf_FDS = DEV.iloc[:, Lf_idx].values.copy() |
| 55 | + |
| 56 | + ntp = len(Time_FDS) |
| 57 | + |
| 58 | + # Moving-average Lf_FDS with Lf_dt window |
| 59 | + Lf_tmp = Lf_FDS.copy() |
| 60 | + for n in range(ntp): |
| 61 | + mask = Time_FDS > (Time_FDS[n] - Lf_dt) |
| 62 | + # indices from first True to n inclusive |
| 63 | + idxs = np.where(mask)[0] |
| 64 | + idxs = idxs[idxs <= n] |
| 65 | + Lf_FDS[n] = np.mean(Lf_tmp[idxs]) |
| 66 | + |
| 67 | + # Write output file |
| 68 | + out_file = os.path.join(outdir, f"{fuel_name[i_fuel]}_dx_{res_name[fds_resolution]}.csv") |
| 69 | + with open(out_file, 'w') as fid: |
| 70 | + fid.write('XO2,eta,Chi_R,Lf,q_R\n') |
| 71 | + for ii in range(ntp): |
| 72 | + eta = Qdot_FDS[ii] / 50.0 |
| 73 | + Chi_R = max(0, -Qrad_FDS[ii] / max(0.001, Qdot_FDS[ii])) |
| 74 | + fid.write(f"{XO2_FDS[ii]:5.3f},{eta:6.2f},{Chi_R:6.2f},{Lf_FDS[ii]:6.2f},{q_R_FDS[ii]:6.2f}\n") |
0 commit comments