-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloadfds.py
More file actions
163 lines (118 loc) · 4.83 KB
/
loadfds.py
File metadata and controls
163 lines (118 loc) · 4.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import numpy as np
import matplotlib.pyplot as plt
import fdsreader
from scipy.interpolate import RegularGridInterpolator, griddata
import sys
import pdb
###########################
def load_slice(sim, id_var):
slc = sim.slices[id_var] # to load temperature. see order of &SLCF in fds config file
data, grid = slc.to_global(return_coordinates=True, masked=True) # need version 1.9.13
times = slc.times
return data, grid, times
###########################
def load_3dsmoke(sim, id_var, dx, dy, dz):
data = sim.smoke_3d[id_var] #0, for smoke, 1 for HRRPUV
datapermesh = list(data.subsmokes)
nmesh = len(datapermesh)
grids = []
data = []
xmin = 1.e6; xmax = -1.e6
ymin = 1.e6; ymax = -1.e6
zmin = 1.e6; zmax = -1.e6
print('loading data ...')
for imesh in range(nmesh):
data.append(datapermesh[imesh][1].data)
grids.append(datapermesh[imesh][1].mesh)
xmin = min([xmin, grids[-1].coordinates['x'].min()])
xmax = max([xmax, grids[-1].coordinates['x'].max()])
ymin = min([ymin, grids[-1].coordinates['y'].min()])
ymax = max([ymax, grids[-1].coordinates['y'].max()])
zmin = min([zmin, grids[-1].coordinates['z'].min()])
zmax = max([zmax, grids[-1].coordinates['z'].max()])
if imesh == 0:
times = datapermesh[imesh][1].times
xg = np.round(np.arange(xmin,xmax,dx), 4)
yg = np.round(np.arange(ymin,ymax,dy), 4)
zg = np.round(np.arange(zmin,zmax,dz), 4)
ngx = xg.shape[0]
ngy = yg.shape[0]
ngz = zg.shape[0]
ntime = times.shape[0]
dataf = np.zeros([ntime,ngx,ngy,ngz]) - 999
yyg, xxg, zzg = np.meshgrid(yg,xg,zg)
jjg, iig, kkg = np.meshgrid(np.arange(ngy),np.arange(ngx),np.arange(ngz))
print('running interpolation ...')
for it in range(ntime)[::100]:
print('{:4.1f} % '.format(100.*it/ntime), end='\r')
sys.stdout.flush()
interps = []
if it == 0 :
x,y,z = [], [], []
xx,yy,zz = [], [], []
bounds = []
for im in range(nmesh):
x.append(np.round(grids[im].coordinates['x'][:],4)[1:-1])
y.append(np.round(grids[im].coordinates['y'][:],4)[1:-1])
z.append(np.round(grids[im].coordinates['z'][:],4)[1:-1])
x[-1][0] -= 0.001
x[-1][-1] += 0.001
y[-1][0] -= 0.001
y[-1][-1] += 0.001
z[-1][0] -= 0.001
z[-1][-1] += 0.001
bounds.append([x[-1].min(),x[-1].max(),y[-1].min(),y[-1].max(),z[-1].min(),z[-1].max()])
yy_, xx_, zz_ = np.meshgrid(y[-1],x[-1],z[-1])
xx.append(xx_)
yy.append(yy_)
zz.append(zz_)
points = []; values = []
for im in range(nmesh):
[points.append( (x_,y_,z_) ) for x_,y_,z_ in zip(xx[im].flatten(),yy[im].flatten(),zz[im].flatten())]
[values.append( data_) for data_ in data[im][it,1:-1,1:-1,1:-1].flatten() ]
dataf[it,:,:,:] = griddata(points, values, (xxg,yyg,zzg), method='nearest') # any other method is very slow in 3D
print('done ')
return dataf, (xg,yg,zg), times
###############
if __name__ == '__main__':
###############
if False:
'''
example for loading temperature from simulation NIST_PoolFire
center vertical slice is shown at last time, t=2.5s
'''
sim = fdsreader.Simulation('./data/NIST_PoolFire/') #load simulation
dx = 1.e-2
dy = 1.e-2
dz = 1.e-2
temp, grid, times = load_slice(sim, 3)
ax = plt.subplot(111)
plt.imshow(temp[-1,:,30,:].T, origin='lower')
plt.title('center vertical slice at t = {:.1f}s '.format(times[-1]))
plt.show()
if False:
'''
example for loading 3d smoke from simulation NIST_PoolFire
center vertical slice is shown at last time
'''
sim = fdsreader.Simulation('./data/NIST_PoolFire/') #load simulation
dx = 1.e-2 # also tested to dx=dy=dx=2cm
dy = 1.e-2
dz = 1.e-2
smoke, grid, times = load_3dsmoke(sim, 0, dx, dy, dz)
plt.imshow(smoke[800,:,int(smoke.shape[1]/2),:].T, origin='lower')
plt.show()
sys.exit()
if True:
'''
example for loading 3d smoke from simulation Entrepinos HF LC 7.6.5
center vertical slice is shown at last time
'''
sim = fdsreader.Simulation('./data/Entrepinos HF LC 7.6.5/') #load simulation
dx = 20.e-2
dy = 20.e-2
dz = 20.e-2
smoke, grid, times = load_3dsmoke(sim, 0, dx, dy, dz)
plt.imshow(smoke[200,:,int(smoke.shape[2]/2),:].T, origin='lower')
plt.show()
sys.exit()