|
| 1 | +# radiation_box.py Collect heat fluxes from radiation box cases to a single csv file in Verification/Radiation folder |
| 2 | + |
| 3 | +import os |
| 4 | +import numpy as np |
| 5 | +import pandas as pd |
| 6 | + |
| 7 | +# Define positions |
| 8 | +x = np.array([ |
| 9 | + 2.50E-02, 7.50E-02, 1.25E-01, 1.75E-01, 2.25E-01, |
| 10 | + 2.75E-01, 3.25E-01, 3.75E-01, 4.25E-01, 4.75E-01, |
| 11 | + 5.25E-01, 5.75E-01, 6.25E-01, 6.75E-01, 7.25E-01, |
| 12 | + 7.75E-01, 8.25E-01, 8.75E-01, 9.25E-01, 9.75E-01 |
| 13 | +]) |
| 14 | + |
| 15 | +# Directory |
| 16 | +dir = '../../Verification/Radiation/' |
| 17 | + |
| 18 | +# Input files |
| 19 | +infile = [ |
| 20 | + f'{dir}radiation_box__20___50_devc.csv', |
| 21 | + f'{dir}radiation_box__20__100_devc.csv', |
| 22 | + f'{dir}radiation_box__20__300_devc.csv', |
| 23 | + f'{dir}radiation_box__20_1000_devc.csv', |
| 24 | + f'{dir}radiation_box__20_2000_devc.csv', |
| 25 | + f'{dir}radiation_box_100___50_devc.csv', |
| 26 | + f'{dir}radiation_box_100__100_devc.csv', |
| 27 | + f'{dir}radiation_box_100__300_devc.csv', |
| 28 | + f'{dir}radiation_box_100_1000_devc.csv', |
| 29 | + f'{dir}radiation_box_100_2000_devc.csv' |
| 30 | +] |
| 31 | + |
| 32 | +# Corresponding labels |
| 33 | +label = [ |
| 34 | + 'Flux_20_50', 'Flux_20_100', 'Flux_20_300', 'Flux_20_1000', 'Flux_20_2000', |
| 35 | + 'Flux_100_50', 'Flux_100_100', 'Flux_100_300', 'Flux_100_1000', 'Flux_100_2000' |
| 36 | +] |
| 37 | + |
| 38 | +# Initialize matrix for flux data |
| 39 | +flux = np.zeros((20, 10)) |
| 40 | + |
| 41 | +# Read data and populate flux |
| 42 | +for n in range(10): |
| 43 | + if not os.path.exists(infile[n]): |
| 44 | + print(f'Error: File {infile[n]} does not exist. Skipping case.') |
| 45 | + else: |
| 46 | + # Read CSV file starting from the 4th row |
| 47 | + data = pd.read_csv(infile[n], skiprows=3, header=None) |
| 48 | + t = data.iloc[0, 0] |
| 49 | + flux[:, n] = data.iloc[0, 1:21].values |
| 50 | + |
| 51 | +# Output file |
| 52 | +filename = f'{dir}radiation_box_devc.csv' |
| 53 | + |
| 54 | +# Write to CSV |
| 55 | +with open(filename, 'w') as fid: |
| 56 | + fid.write('Position, ' + ', '.join(label) + '\n') |
| 57 | + for i in range(20): |
| 58 | + fid.write(f'{x[i]:.6f}, ' + ', '.join(f'{flux[i, j]:.6f}' for j in range(10)) + '\n') |
0 commit comments