11 """Read grid file in LES-Flat format"""
12 with open(filename,
'r')
as f:
16 nblocks = int(lines[0].strip())
19 ni, nj, nk = map(int, lines[1].strip().split())
21 print(f
"Grid dimensions: {ni} x {nj} x {nk}")
24 x_coords = np.zeros(ni)
26 vals =
list(map(float, lines[2 + i].strip().split()))
30 y_coords = np.zeros(nj)
32 vals =
list(map(float, lines[2 + ni + j].strip().split()))
36 z_coords = np.zeros(nk)
38 vals =
list(map(float, lines[2 + ni + nj + k].strip().split()))
41 return ni, nj, nk, x_coords, y_coords, z_coords
44 """Write grid file in PICGRID format"""
46 total_points = ni * nj * nk
47 print(f
"Writing {total_points} grid points to {filename}")
49 with open(filename,
'w')
as f:
53 f.write(f
"{ni} {nj} {nk}\n")
61 x = x_coords[i] + min(x_coords)
62 y = y_coords[j] + min(y_coords)
63 z = z_coords[k] + min(z_coords)
64 f.write(f
"{x:.8e} {y:.8e} {z:.8e}\n")
66 print(f
"Successfully wrote {filename}")
69 input_file =
"/mnt/user-data/uploads/LES-Flat_grid.dat"
70 output_file =
"/mnt/user-data/outputs/LES-Flat_PICGRID.grid"
72 print(f
"Reading {input_file}...")
75 print(f
"\nCoordinate ranges:")
76 print(f
" X: [{x_coords.min():.6f}, {x_coords.max():.6f}]")
77 print(f
" Y: [{y_coords.min():.6f}, {y_coords.max():.6f}]")
78 print(f
" Z: [{z_coords.min():.6f}, {z_coords.max():.6f}]")
80 print(f
"\nWriting to {output_file}...")
83 print(
"\nConversion complete!")