-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBuildGridBinary.f
More file actions
458 lines (401 loc) · 12.1 KB
/
BuildGridBinary.f
File metadata and controls
458 lines (401 loc) · 12.1 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
c----------------------------------------------------------------------
program Intake_Gridgen
c----------------------------------------------------------------------
c
implicit none
integer, parameter :: rk = 8!selected_real_kind(10,100)
integer :: i,j,k,xb,zb,recnum,nxt,nzt,ntot,ifi
integer :: xm, xp, ym, yp, zm, zp, npt3, npt1
real(kind=rk) :: xpr,ypr,zpr, dummy
integer, parameter :: nbX = 3,nbZ = 1
integer :: bcxm(nbX,nbZ),bcxp(nbX,nbZ),
& bcym(nbX,nbZ),bcyp(nbX,nbZ),
& bczm(nbX,nbZ),bczp(nbX,nbZ)
integer :: nxb(nbX,nbZ), nyb(nbX,nbZ),nzb(nbX,nbZ),
& xmintf(nbX,nbZ),xpintf(nbX,nbZ),
& zmintf(nbX,nbZ),zpintf(nbX,nbZ)
integer, parameter :: halo=3 !nplus=355,itmax=25 !!nz=1
integer :: ib
integer :: nxpb(nbX,nbZ),nypb(nbX,nbZ),nzpb(nbX,nbZ)
real(kind=rk) :: xlb(nbX,nbZ),ylb(nbX,nbZ),zlb(nbX,nbZ)
real(kind=rk), allocatable :: xx(:,:), yy(:,:)
real(kind=rk), allocatable :: xx1(:,:), yy1(:,:)
real(kind=rk), allocatable :: xx2(:,:), yy2(:,:)
real(kind=rk), allocatable :: xx3(:,:), yy3(:,:)
real(kind=rk), allocatable :: tmp1(:,:), tmp2(:,:)
character(75) :: filename, outdir, tail
outdir ='./'
! Set flow info and boundary conditions
xm=1;xp=2;ym=3;yp=4;zm=5;zp=6
bcxm(1,1) = 1 ! Interface
bcxm(2,1) = 1 ! Interface
bcxm(3,1) = 1 ! Interface
c.
bcxp(1,1) = 3
bcxp(2,1) = 1 ! Interface
bcxp(3,1) = 3
c.
bcym(1,1) = 1 ! Interface
bcym(2,1) = 1
bcym(3,1) = 1 ! Interface
c.
bcyp(1,1) = 2
bcyp(2,1) = 2
bcyp(3,1) = 2
cnn domain sizes = to 1
xlb(:,:) = 1.0d0
ylb(:,:) = 1.0d0
zlb(:,:) = 1.0d0
c
open(57,file='Airfoil_2D.bin',form='unformatted')
cnn write num of blocks
write(57) nbX*nbZ
do zb=1,nbZ
do xb=1,nbX
ib=nbX*(zb-1)+xb
if(ib.eq.1)then
open(11,file='Bl1.dat',form='formatted')
elseif(ib.eq.2)then
open(11,file='Bl2.dat',form='formatted')
else
open(11,file='Bl3.dat',form='formatted')
end if
nzpb(:,:)=1
read(11,*) nxpb(xb,zb), nypb(xb,zb)
print *,'Just read', nxpb(xb,zb)
close(11)
if(ib .eq. 2) then
write(57) nxpb(xb,zb)-1,nypb(xb,zb)-1,nzpb(xb,zb)-1
else
write(57) nxpb(xb,zb)-1,nypb(xb,zb)-1,nzpb(xb,zb)-1
end if
cnn write num of procs
if(ib.eq.1)then
write(57) 5,6,1 !2,1,1
elseif(ib.eq.2)then
write(57) 14,6,1 !4,1,1
else
write(57) 5,6,1 !2,1,1
end if
write(57) xlb(xb,zb),ylb(xb,zb),zlb(xb,zb)
xpr=0.0d0; ypr=0.0d0; zpr=0.0d0
write(57) xpr,ypr,zpr
write(57) bcxm(xb,zb),bcxp(xb,zb),bcym(xb,zb),
& bcyp(xb,zb),bczm(xb,zb),bczp(xb,zb)
cnn write interfaces stuff
cnn INTERF ALL POINTS
cnn
! write(57)0,0,0
cnn
if(ib.eq.1) then
write(57)2,2,3,1,2
elseif(ib.eq.2) then
write(57)2,1,3,1,1
else
write(57)2,2,1,2,2
end if
! if(ib.eq.1) then
! write(57)1,2,1
! elseif(ib.eq.2) then
! write(57)2,1,3,1,1
! else
! write(57)1,2,2
! end if
npt1=8
npt3=8
if(ib.eq.1) then
write(57)xm,npt1+1,nypb(xb,zb),2,1,1,1
write(57)ym,1,nxpb(xb,zb),1,1,1,1
elseif(ib.eq.2) then
write(57)xm,2,nypb(xb,zb),npt1+1,1,1,1
write(57)xp,2,nypb(xb,zb),npt3+1,1,1,1
else
write(57)xm,npt3+1,nypb(xb,zb),2,1,1,1
write(57)ym,1,nxpb(xb,zb),1,1,1,1
end if
cnn end looping blocks for initial info
end do
end do
cnn ###################################
c. Open Matlab grid
print *,'start loop through blocks and allocate'
open(47,file='grid_matlab.bin',access='direct',
& form='unformatted',recl=8)
recnum = 0
print *,'grid_matlab.bin opened'
c.
do zb=1,nbZ
do xb=1,nbX
ib=nbX*(zb-1)+xb
print *,'ib=',ib
if(ib.eq.1)then
open(11,file='Bl1.dat',form='formatted')
allocate(xx1(1-halo:nxpb(xb,zb)+halo,
& 1-halo:nypb(xb,zb)+halo))
allocate(yy1(1-halo:nxpb(xb,zb)+halo,
& 1-halo:nypb(xb,zb)+halo))
elseif(ib.eq.2)then
print *,'allocate block 2'
open(11,file='Bl2.dat',form='formatted')
allocate(tmp1(1-halo:nxpb(xb,zb)+halo,
& 1-halo:nypb(xb,zb)+halo))
allocate(tmp2(1-halo:nxpb(xb,zb)+halo,
& 1-halo:nypb(xb,zb)+halo))
allocate(xx2(1-halo:nxpb(xb,zb)+halo,
& 1-halo:nypb(xb,zb)+halo))
allocate(yy2(1-halo:nxpb(xb,zb)+halo,
& 1-halo:nypb(xb,zb)+halo))
print *,'Allocated: Bl2.dat - xx2',1-halo,':',nxpb(xb,zb)+halo
print *,'Allocated: Bl2.dat - xx2',1-halo,':',nypb(xb,zb)+halo
print *,'Allocated: Bl2.dat - yy2',1-halo,':',nxpb(xb,zb)+halo
print *,'Allocated: Bl2.dat - yy2',1-halo,':',nypb(xb,zb)+halo
else
open(11,file='Bl3.dat',form='formatted')
allocate(xx3(1-halo:nxpb(xb,zb)+halo,
& 1-halo:nypb(xb,zb)+halo))
allocate(yy3(1-halo:nxpb(xb,zb)+halo,
& 1-halo:nypb(xb,zb)+halo))
end if
print *,'Allocated: Bl3.dat - xx3',1-halo,':',nxpb(xb,zb)+halo
print *,'Allocated: Bl3.dat - xx3',1-halo,':',nypb(xb,zb)+halo
nzpb(:,:)=1
read(11,*) nxpb(xb,zb),nypb(xb,zb)
if(ib.eq.1)then
do i=1,nxpb(xb,zb)
do j=1,nypb(xb,zb)
read(11,*) xx1(i,j), dummy, yy1(i,j)
end do
end do
print *,'xx1 read in'
elseif(ib.eq.2)then
do i=1,nxpb(xb,zb)
do j=1,nypb(xb,zb)
read(11,*) tmp1(i,j), dummy, tmp2(i,j)
end do
end do
do i=1,nxpb(xb,zb)
do j=1,nypb(xb,zb)
xx2(i,j) = tmp1(i,j)
yy2(i,j) = tmp2(i,j)
end do
end do
print *,'xx2 read in'
! nxpb(xb,zb) = nxpb(xb,zb)-2
else
do i=1,nxpb(xb,zb)
do j=1,nypb(xb,zb)
read(11,*) xx3(i,j), dummy, yy3(i,j)
end do
end do
print *,'xx3 read in'
end if
close(11)
print *,'start print N',ib,xb,zb
print *,'N',ib,nxpb(xb,zb),nypb(xb,zb)
end do
end do
print *,'xx & yy created'
cnn Add the halos
c. xm - Bl1
! print *,'test TElow:', xx1(1,npt1),xx2(1,1)
! print *,'test TElow:', yy1(1,npt1),yy2(1,1)
!
! print *,'test TEup:' ,xx3(1,npt3),xx2(nxpb(2,1),1)
! print *,'test TEup:' ,yy3(1,npt3),yy2(nxpb(2,1),1)
print *,'add halos'
do i=1-halo,0
xx1(i,:) = xx1(1,:)
yy1(i,:) = yy1(1,:)
end do
ifi = halo+1
do i=1-halo,0
ifi = ifi-1
xx1(i,npt1:nypb(1,1)+halo) = xx2(ifi,1:nypb(2,1)+halo)
yy1(i,npt1:nypb(1,1)+halo) = yy2(ifi,1:nypb(2,1)+halo)
end do
c. xm - Bl3
do i=1-halo,0
xx3(i,:) = xx3(1,:)
yy3(i,:) = yy3(1,:)
end do
ifi = halo+1
do i=1-halo,0
ifi = ifi-1
xx3(i,npt3:nypb(3,1)+halo) =
& xx2(nxpb(2,1)-ifi+1,1:nypb(2,1)+halo)
yy3(i,npt3:nypb(3,1)+halo) =
& yy2(nxpb(2,1)-ifi+1,1:nypb(2,1)+halo)
end do
print *,'BL3xm done'
c. xp - Bl1
do i=nxpb(1,1)+1,nxpb(1,1)+halo
xx1(i,:) = xx1(nxpb(1,1),:)
yy1(i,:) = yy1(nxpb(1,1),:)
end do
c. xp - Bl3
do i=nxpb(3,1)+1,nxpb(3,1)+halo
xx3(i,:) = xx3(nxpb(3,1),:)
yy3(i,:) = yy3(nxpb(3,1),:)
end do
print *,'BL1&3xp done'
c. ym - Bl1
ifi = halo+1 !+1+1 for sharp trailing edge case!!!
do j=1-halo,0
ifi = ifi-1
xx1(:,j) = xx3(:,ifi)
yy1(:,j) = yy3(:,ifi)
end do
c. ym - Bl3
ifi = halo+1 !+1+1 for sharp trailing edge case!!!
do j=1-halo,0
ifi = ifi-1
xx3(:,j) = xx1(:,ifi)
yy3(:,j) = yy1(:,ifi)
end do
print *,'BL1&3ym done'
c. yp - Bl1
do j=nypb(1,1)+1,nypb(1,1)+halo
xx1(:,j) = xx1(:,nypb(1,1))
yy1(:,j) = yy1(:,nypb(1,1))
end do
c. yp - Bl3
do j=nypb(3,1)+1,nypb(3,1)+halo
xx3(:,j) = xx3(:,nypb(3,1))
yy3(:,j) = yy3(:,nypb(3,1))
end do
print *,'BL1&3yp done'
c. Block 2
c. xm
ifi = halo+1
do i=1-halo,0
ifi = ifi-1
print *, nypb(2,1)+halo-1, '=', nypb(1,1)+halo-npt1
xx2(i,1-halo:nypb(2,1)+halo) = xx1(ifi,npt1-halo:nypb(1,1)+halo)
yy2(i,1-halo:nypb(2,1)+halo) = yy1(ifi,npt1-halo:nypb(1,1)+halo)
end do
c. ym
do j=1-halo,0
xx2(:,j) = xx2(:,1)
yy2(:,j) = yy2(:,1)
end do
c. yp
do j=nypb(2,1)+1,nypb(2,1)+halo
xx2(:,j) = xx2(:,nypb(2,1))
yy2(:,j) = yy2(:,nypb(2,1))
end do
c. xm
! ifi = halo+1
! do i=1-halo,0
! ifi = ifi-1
! xx2(i,1:nypb(2,1)+halo) = xx1(ifi,npt1:nypb(1,1)+halo)
! yy2(i,1:nypb(2,1)+halo) = yy1(ifi,npt1:nypb(1,1)+halo)
! end do
c. xp
ifi = 0
do i=nxpb(2,1)+1,nxpb(2,1)+halo
ifi = ifi+1
print *, nypb(2,1)+halo-1, '=', nypb(3,1)+halo-npt3
xx2(i,1-halo:nypb(2,1)+halo) = xx3(ifi,npt3-halo:nypb(3,1)+halo)
yy2(i,1-halo:nypb(2,1)+halo) = yy3(ifi,npt3-halo:nypb(3,1)+halo)
end do
c. xm
ifi = halo+1
do i=1-halo,0
ifi = ifi-1
print *, nypb(2,1)+halo-1, '=', nypb(1,1)+halo-npt1
xx2(i,1-halo:nypb(2,1)+halo) = xx1(ifi,npt1-halo:nypb(1,1)+halo)
yy2(i,1-halo:nypb(2,1)+halo) = yy1(ifi,npt1-halo:nypb(1,1)+halo)
end do
c.
print *,'test TElow:', xx1(1,npt1),xx2(1,1)
print *,'test TElow:', yy1(1,npt1),yy2(1,1)
print *,'test TEup:' ,xx3(1,npt3),xx2(nxpb(2,1),1)
print *,'test TEup:' ,yy3(1,npt3),yy2(nxpb(2,1),1)
c. Check grid
do zb=1,nbZ
do xb=1,nbX
ib=nbX*(zb-1)+xb
allocate(xx(1-halo:nxpb(xb,zb)+halo,
& 1-halo:nypb(xb,zb)+halo))
allocate(yy(1-halo:nxpb(xb,zb)+halo,
& 1-halo:nypb(xb,zb)+halo))
c.
if(ib.eq.1)then
open(11,file='Bl1h.dat',form='formatted')
xx = xx1
yy = yy1
elseif(ib.eq.2)then
open(11,file='Bl2h.dat',form='formatted')
xx = xx2
yy = yy2
else
open(11,file='Bl3h.dat',form='formatted')
xx = xx3
yy = yy3
end if
c.
write(11,*) nxpb(xb,zb)+2*halo,nypb(xb,zb)+2*halo
c.
do i=1-halo,nxpb(xb,zb)+halo
do j=1-halo,nypb(xb,zb)+halo
write(11,*) xx(i,j),yy(i,j)
end do
end do
close(11)
c.
deallocate(xx,yy)
end do
end do
c.
do zb=1,nbZ
do xb=1,nbX
ib=nbX*(zb-1)+xb
c.
allocate(xx(1-halo:nxpb(xb,zb)+halo,
& 1-halo:nypb(xb,zb)+halo))
allocate(yy(1-halo:nxpb(xb,zb)+halo,
& 1-halo:nypb(xb,zb)+halo))
if(ib.eq.1)then
xx = xx1
yy = yy1
elseif(ib.eq.2)then
xx = xx2
yy = yy2
else
xx = xx3
yy = yy3
end if
write(57) ((xx(i,j),i=1-halo,nxpb(xb,zb)+halo)
& ,j=1-halo,nypb(xb,zb)+halo)
write(57) ((yy(i,j),i=1-halo,nxpb(xb,zb)+halo)
& ,j=1-halo,nypb(xb,zb)+halo)
c...
c. Matlab grid
c.
do k=1,nzpb(xb,zb)
do j=1-halo,nypb(xb,zb)+halo
do i=1-halo,nxpb(xb,zb)+halo
recnum=recnum+1
write(47,rec=recnum) xx(i,j)
end do
end do
end do
do k=1,nzpb(xb,zb)
do j=1-halo,nypb(xb,zb)+halo
do i=1-halo,nxpb(xb,zb)+halo
recnum=recnum+1
write(47,rec=recnum) yy(i,j)
end do
end do
end do
deallocate(xx,yy)
cnn end looping blocks
end do
end do
cnn ###############
close(57)
close(47)
c
stop
c
end