-
Notifications
You must be signed in to change notification settings - Fork 4
/
restart_init.py
executable file
·98 lines (67 loc) · 2.82 KB
/
restart_init.py
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
## Initialise the state from a previous solution to restart
def read_init(file):
''' Read from a previous solution file (only valid for cartesian rectangular mesh '''
import numpy as _np
BLprof = _np.loadtxt(file,comments=('#','ZONE'),skiprows=3 )
X = BLprof[:,0]
Y = BLprof[:,1]
ro = BLprof[:,2]
rou = BLprof[:,3]
rov = BLprof[:,4]
row = BLprof[:,5]
roe = BLprof[:,6]
Ntot= _np.shape(X)[0]
# print Ntot
count=1
Y0=Y[0]
while Y[count] == Y0:
count+= 1
im = count
jm = Ntot//im
# print('im = ', im)
# print('jm = ', jm)
X = _np.reshape(X ,(im,jm), order='F')
Y = _np.reshape(Y ,(im,jm), order='F')
ro = _np.reshape(ro ,(im,jm), order='F')
rou = _np.reshape(rou,(im,jm), order='F')
rov = _np.reshape(rov,(im,jm), order='F')
row = _np.reshape(row,(im,jm), order='F')
roe = _np.reshape(roe,(im,jm), order='F')
return X, Y, ro, rou, rov, row, roe
def interpolate_field_from_clicet(file ,x ,y ,R_pg ,gamma ,interptype='cubic'):
'''Interpolate the conservative variables (except rhow) from 2D BL data from clicet file on the grid made by x and y'''
from scipy.interpolate import griddata
import numpy as _np
BLprof = _np.loadtxt(file,comments=('#','ZONE'),skiprows=3 )
X = BLprof[:,0]
Y = BLprof[:,1]
U = BLprof[:,2]
V = BLprof[:,3]
rho = BLprof[:,5]
T = BLprof[:,6]
gridX, gridY = _np.meshgrid(x,y)
Uinter = griddata(_np.transpose([X,Y]), U, (gridX,gridY), interptype)
Vinter = griddata(_np.transpose([X,Y]), V, (gridX,gridY), interptype)
rhointer = griddata(_np.transpose([X,Y]), rho, (gridX,gridY), interptype)
Tinter = griddata(_np.transpose([X,Y]), T, (gridX,gridY), interptype)
return rhointer, rhointer*Uinter, rhointer*Vinter, rhointer*(R_pg/(gamma-1.)*Tinter+0.5*(Uinter**2+Vinter**2))
def interpolate_field_from_data(file ,x ,y ,interptype='cubic'):
'''Interpolate the conservative variables (except rhow) from 2D BL data from previous solution file on the grid made by x and y'''
from scipy.interpolate import griddata
import numpy as _np
BLprof = _np.loadtxt(file,comments=('#','ZONE'),skiprows=3 )
X = BLprof[:,0]
Y = BLprof[:,1]
ro = BLprof[:,2]
rou = BLprof[:,3]
rov = BLprof[:,4]
row = BLprof[:,5]
roe = BLprof[:,6]
gridX, gridY = _np.meshgrid(x,y, sparse=True)
rointer = griddata(_np.transpose([X,Y]), ro , (gridX,gridY), interptype)
roUinter = griddata(_np.transpose([X,Y]), rou, (gridX,gridY), interptype)
roVinter = griddata(_np.transpose([X,Y]), rov, (gridX,gridY), interptype)
roWinter = griddata(_np.transpose([X,Y]), row, (gridX,gridY), interptype)
roEinter = griddata(_np.transpose([X,Y]), roe, (gridX,gridY), interptype)
print(_np.shape(gridX))
return gridX, gridY, rointer, roUinter, roVinter, roWinter, roEinter