/
Joukowski.py
executable file
·172 lines (135 loc) · 5.73 KB
/
Joukowski.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
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
164
165
166
167
168
169
170
171
from __future__ import division
import numpy as npy
from plot3d import writePlot2D, writeLaballiur, writePlot3D, writePlot3Dxz, writeOVERFLOW
from grm import writeGRM
from vtk import writeVTK
from fec import writeFEC
from gmsh import writeGMSH
from ebg import writeEBG
from geo import writeGEO
from curve import writeCurve
from Joukowski_Challenge import make_joukowski_challenge
import matplotlib.pyplot as plt
def make_joukowski(ref, Q, TriFlag, Distribution, FileFormat, reynolds, filename_base):
if Distribution == "Challenge":
XC, YC = make_joukowski_challenge(ref, Q, reynolds)
nWK = 8*Q*2**ref+1
else:
raise ValueError("Distribution should be 'Challenge'")
nLE = 16*Q*2**ref+1
nWB = XC.shape[0]
nr = XC.shape[1]
filename_base += "_tri" if TriFlag else "_quad"
fac = 2 if TriFlag else 1
print('Cell size ' + str( int((nWB-1)/Q) ) + 'x' + str( int((nr-1)/Q) ) + ' with ' + str( fac*int((nWB-1)/Q)*int((nr-1)/Q) ) + ' Elements')
if FileFormat == 'p2d':
writePlot2D(filename_base + '_ref'+str(ref)+ '_Q'+str(Q)+'.p2d.x', XC, YC)
if FileFormat == 'labl':
assert Q == 1
writeLaballiur(filename_base + '_ref'+str(ref)+ '_Q'+str(Q)+'.labl', XC, YC, nWK)
if FileFormat == 'p3dxy':
writeNMF(filename_base + '_ref'+str(ref)+ '_Q'+str(Q)+'.nmf', XC, nLE, nWK, nWB, nr, 'z')
writePlot3D(filename_base + '_ref'+str(ref)+ '_Q'+str(Q)+'.p3d.x', XC, YC)
if FileFormat == 'p3dxz':
writeNMF(filename_base + '_ref'+str(ref)+ '_Q'+str(Q)+'.nmf', XC, nLE, nWK, nWB, nr, 'y')
writePlot3Dxz(filename_base + '_ref'+str(ref)+ '_Q'+str(Q)+'.p3d.x', XC, YC)
if FileFormat == 'in':
writeOVERFLOW('grid.in.'+str(ref), XC, YC)
if FileFormat == 'hypgen':
writePlot2D('joukowski_c.crv', XC[:,0:1], YC[:,0:1])
if FileFormat == 'ebg':
writeEBG('joukowski.ebg', XC, YC, nWK)
if FileFormat == 'geo':
writeGEO('joukowski.geo', XC, YC, nWK)
if FileFormat == 'curve':
writeCurve(XC, YC, nWK)
#--------------------#
# Vertices, unrolled #
#--------------------#
V = npy.zeros((nWB*nr,2),float)
V[:,0] = XC.T.reshape(nWB*nr)
V[:,1] = YC.T.reshape(nWB*nr)
#pyl.plot(XC.reshape(nWB*nr),YC.reshape(nWB*nr),'o')
#pyl.show()
#pyl.plot(V[:,0],V[:,1],'o')
#pyl.show()
#---------------------------------------------#
# node number matrices for writing out blocks #
#---------------------------------------------#
NC = npy.arange(nWB*nr).reshape( (nr, nWB) ).T+1
V = npy.delete(V,NC[nWB-nWK:nWB,0]-1,0)
NC[nWB-nWK:nWB,0] = NC[nWK-1::-1,0]
NC[:,1:] = NC[:,1:]-nWK
#---------------#
# form elements #
#---------------#
E = block_elem(NC, Q);
#---------------#
# write file #
#---------------#
if FileFormat == 'grm':
writeGRM(filename_base, ref, Q, TriFlag, E, V, nLE, NC, nWK, nWB, nr);
if FileFormat == 'fec':
writeVTK(filename_base, ref, Q, E, V);
writeFEC(filename_base, ref, Q, E, V, nLE, NC, nWK, nWB, nr);
if FileFormat == 'msh':
writeGMSH(filename_base, ref, Q, TriFlag, E, V, nLE, NC, nWK, nWB, nr);
print("Done with refinement " + str(ref))
#-----------------------------------
def block_elem(N, Q):
nx, ny = N.shape;
#if (Q != 1) and ((mod(nx,Q) != 1) or (mod(ny,Q) != 1)): print('ERROR 2'); return;
mx = int((nx-1)/Q);
my = int((ny-1)/Q);
E = npy.zeros( (mx*my,(Q+1)*(Q+1)),int);
i = 0;
for imy in range(my):
for imx in range(mx):
ix = Q*(imx+1)-(Q-1)-1;
iy = Q*(imy+1)-(Q-1)-1;
k = 0;
for ky in range(Q+1):
for kx in range(Q+1):
E[i,k] = N[ix+kx,iy+ky]
k = k+1;
i = i + 1;
return E
#-----------------------------------------------------------
# writes BC information for FUN3D
def writeNMF(fname, X, nLE, nWK, nWB, nr, sym):
ni, nj = X.shape; nk = 2
# NMF file expects all comments and extra empty lines
f = open(fname, 'w')
f.write('# ===== Neutral Map File generated by Python =====\n')
f.write('# =================================================\n')
f.write('# Block# IDIM JDIM KDIM\n')
f.write('# -------------------------------------------------\n')
f.write('1\n\n')
f.write('1 ' + str(ni) + ' ' + str(nj) + ' ' + str(nk) + '\n\n')
f.write('# =================================================\n')
f.write('# Type B1 F1 S1 E1 S2 E2 B2 F2 S1 E1 S2 E2 Swap\n')
f.write('# ---------------------------------------------------\n')
f.write("'symmetry_" + sym + "' 1 1 1 " + str(ni) + " 1 " +str(nj) + "\n")
f.write("'symmetry_" + sym + "' 1 2 1 " + str(ni) + " 1 " +str(nj) + "\n")
f.write("'one-to-one' 1 5 1 " + str(nk) + " 1 " +str(nWK) + " 1 5 1 " + str(nk) + " " + str(ni) + " " + str(nWK+nLE-1) +" False\n")
f.write("'viscous_solid' 1 5 1 " + str(nk) + " " + str(nWK) + " " + str(nWK+nLE-1) + "\n")
f.write("'farfield_riem' 1 6 1 " + str(nk) + " 1 " +str(ni) + "\n");
f.write("'farfield_riem' 1 3 1 " + str(nj) + " 1 " +str(nk) + "\n");
f.write("'farfield_riem' 1 4 1 " + str(nj) + " 1 " +str(nk) + "\n");
if __name__ == "__main__":
ref = 0
Q = 3
reynolds = 1000
plt.clf()
plt.axis('equal')
XC, YC = make_joukowski_challenge(ref, Q, reynolds)
plt.pcolor(XC, YC, 0*XC, edgecolor='k', cmap='Greens')
TriFlag = False
Distribution = 'Challenge'
FileFormat = 'msh'
filename_base = 'jouk'
make_joukowski(ref, Q, TriFlag, Distribution, FileFormat, reynolds, filename_base)
#XC, YC = make_joukowski_classic(ref, Q, reynolds)
#plt.pcolor(XC, YC, 0*XC, edgecolor='r', cmap='Greens')
plt.show()
plt.draw()