-
Notifications
You must be signed in to change notification settings - Fork 1
/
avg_tensor.usr
594 lines (508 loc) · 17.4 KB
/
avg_tensor.usr
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
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
c-----------------------------------------------------------------------
c AVERAGING ROUTINES
c-----------------------------------------------------------------------
c
c Rely on lexicographical element ordering
c
c-----------------------------------------------------------------------
c
c in usrchk()
c
c integer nelx,nely,nelz,ifld
c integer idir_plnr,idir_line,idir_geom,atyp
c integer gs_plnr_hndl
c save gs_plnr_hndl
c data gs_plnr_hndl / 0 /
c integer gs_line_hndl
c save gs_line_hndl
c data gs_line_hndl / 0 /
c integer gs_geom_hndl
c save gs_geom_hndl
c data gs_geom_hndl / 0 /
c nelx = 64
c nely = 24
c nelz = 32
c ifld = 1
c idir_line = 2
c idir_plnr = 3
c idir_geom = 1
c avgtyp = 0 ! -ve: plnr, 0: line, mag>1: nrep for geomavg
c call avg_tensor(vxa,vx,gs_line_hndl,gs_geom_hndl,nelx,nely,nelz
c $ ,ifld,idir_line,idir_geom,atyp)
c
c-----------------------------------------------------------------------
subroutine avg_tensor(ua,u,avgtyp,nelx,nely,nelz,ifld
$ ,gs_line_hndl,idir_line
$ ,gs_plnr_hndl,idir_plnr
$ ,gs_geom_hndl,idir_geom)
include 'SIZE'
include 'TOTAL'
integer idir_line,idir_plnr,idir_geom
integer avgtyp
integer at,ntot
integer icalld
save icalld
data icalld / 0 /
ntot = nx1*ny1*nz1*nelt
if((nid.eq.0).and.(icalld.eq.0))
$ write(6,*)'in avg_tensor(...)','avgtyp:',avgtyp
if(avgtyp.lt.0) then
if((nid.eq.0).and.(icalld.eq.0))
$ write(6,*)'Plnr averaging in direction',idir_plnr
call plane_avg_tensor(ua,u,gs_plnr_hndl,nelx,nely,nelz
$ ,ifld,idir_plnr)
endif
if(avgtyp.eq.0) then
if((nid.eq.0).and.(icalld.eq.0))
$ write(6,*)'Line averaging in direction',idir_line
call line_avg_tensor(ua,u,gs_line_hndl,nelx,nely,nelz
$ ,ifld,idir_line)
endif
at = abs(avgtyp)
if(at.gt.1) then
if((nid.eq.0).and.(icalld.eq.0))
$ write(6,*)'Geom averaging in direction',idir_geom,'nrep',at
call geom_avg_tensor(ua,u,gs_geom_hndl,nelx,nely,nelz
$ ,ifld,idir_geom,at)
endif
if(avgtyp.eq.1) then
if((nid.eq.0).and.(icalld.eq.0)) write(6,*)'no averaging'
call copy(ua,u,ntot)
endif
icalld = icalld + 1
return
end
c-----------------------------------------------------------------------
subroutine avg_tensor_wrapper(u,avgtyp,nelx,nely,nelz,ifld
$ ,gs_line_hndl,idir_line
$ ,gs_plnr_hndl,idir_plnr
$ ,gs_geom_hndl,idir_geom)
include 'SIZE'
include 'TOTAL'
real u(lx1,ly1,lz1,lelt)
integer avgtyp
c
real w1(lx1,ly1,lz1,lelt)
integer ntot
ntot=lx1*ly1*lz1*nelt
call avg_tensor(w1,u,avgtyp,nelx,nely,nelz,ifld
$ ,gs_line_hndl,idir_line
$ ,gs_plnr_hndl,idir_plnr
$ ,gs_geom_hndl,idir_geom)
call rzero(u,ntot)
do i=1,ntot
u(i,1,1,1) = w1(i,1,1,1)
enddo
return
end
c-----------------------------------------------------------------------
c LINE AVERAGE
c-----------------------------------------------------------------------
c
c call line_avg_tensor(ua,u,gs_hndl,nelx,nely,nelz,ifld,idir)
c
c ua: averaged field, u: field to average
c
c idir=1 ==> average over y-z plane i.e. get X-profile.
c idir=2 ==> average over x-z plane i.e. get Y-profile.
c idir=3 ==> average over x-y plane i.e. get Z-profile.
c
c-----------------------------------------------------------------------
subroutine line_avg_tensor(ua,u,gs_hndl,nelx,nely,nelz,ifld,idir)
include 'SIZE'
include 'TOTAL'
real u (lx1,ly1,lz1,lelt)
real ua(lx1,ly1,lz1,lelt)
integer gs_hndl,e,ex,ey,ez,eg
c common /c_is1/ glo_num(lx1,ly1,lz1,lelv)
c integer*8 glo_num,ex_g
nel = nelfld(ifld)
n = nx1*ny1*nz1*nel
call rzero(ua,n)
if (gs_hndl.eq.0) then
if(idir.eq.1) call set_gs_x_hndl_line(gs_hndl,nelx,nely,nelz,ifld)
if(idir.eq.2) call set_gs_y_hndl_line(gs_hndl,nelx,nely,nelz,ifld)
if(idir.eq.3) call set_gs_z_hndl_line(gs_hndl,nelx,nely,nelz,ifld)
endif
c VERIFIED global numbering
c do i=1,n
c ua(i,1,1,1) = glo_num(i,1,1,1)
c enddo
call copy(ua,bm1,n) ! Set the averaging weights
call fgslib_gs_op(gs_hndl,ua,1,1,0) ! Sum weights over columns
do i=1,n ! ua = (w_j*u_j)/( sum_i w_i)
ua(i,1,1,1) = bm1(i,1,1,1)*u(i,1,1,1)/ua(i,1,1,1)
enddo
call fgslib_gs_op(gs_hndl,ua,1,1,0) ! Sum weighted values
return
end
c-----------------------------------------------------------------------
subroutine set_gs_x_hndl_line(gs_avg_hndl,nelx,nely,nelz,ifld)
include 'SIZE'
include 'TOTAL'
integer gs_avg_hndl,e,ex,ey,ez,eg,nelx,nely,nelz
common /nekmpi/ mid,mp,nekcomm,nekgroup,nekreal
common /c_is1/ glo_num(lx1,ly1,lz1,lelv)
integer*8 glo_num,ex_g
nel = nelfld(ifld)
do e=1,nel
eg = lglel(e)
call get_exyz(ex,ey,ez,eg,nelx,nely,nelz)
ex_g = ey ! Ensure int*8 promotion
do k=1,nz1 ! Enumerate points along x
do j=1,ny1
do i=1,nx1
c glo_num(i,j,k,e) = ex
glo_num(i,j,k,e) = i + (ex-1)*(nx1-1)
enddo
enddo
enddo
enddo
n = nel*nx1*ny1*nz1
call fgslib_gs_setup(gs_avg_hndl,glo_num,n,nekcomm,mp)
return
end
c-----------------------------------------------------------------------
subroutine set_gs_y_hndl_line(gs_avg_hndl,nelx,nely,nelz,ifld)
c Set the y-average handle
include 'SIZE'
include 'TOTAL'
integer gs_avg_hndl,e,ex,ey,ez,eg,nelx,nely,nelz
common /nekmpi/ mid,mp,nekcomm,nekgroup,nekreal
common /c_is1/ glo_num(lx1,ly1,lz1,lelv)
integer*8 glo_num,ex_g
nel = nelfld(ifld)
do e=1,nel
eg = lglel(e)
call get_exyz(ex,ey,ez,eg,nelx,nely,nelz)
ex_g = (ez-1)*nelx+ex ! Ensure int*8 promotion
do k=1,nz1 ! Enumerate points in the x-z plane
do j=1,ny1
do i=1,nx1
c glo_num(i,j,k,e) = ey
glo_num(i,j,k,e) = j + (ey-1)*(ny1-1)
enddo
enddo
enddo
enddo
n = nel*nx1*ny1*nz1
call fgslib_gs_setup(gs_avg_hndl,glo_num,n,nekcomm,mp)
return
end
c-----------------------------------------------------------------------
subroutine set_gs_z_hndl_line(gs_avg_hndl,nelx,nely,nelz,ifld)
c Set the z-average handle
include 'SIZE'
include 'TOTAL'
integer gs_avg_hndl,e,ex,ey,ez,eg,nelx,nely,nelz
common /nekmpi/ mid,mp,nekcomm,nekgroup,nekreal
common /c_is1/ glo_num(lx1,ly1,lz1,lelv)
integer*8 glo_num,ex_g
nel = nelfld(ifld)
do e=1,nel
eg = lglel(e)
call get_exyz(ex,ey,ez,eg,nelx,nely,nelz)
ex_g = ex ! Ensure int*8 promotion
do k=1,nz1 ! Enumerate points in the x-y plane
do j=1,ny1
do i=1,nx1
c glo_num(i,j,k,e) = ez
glo_num(i,j,k,e) = k + (ez-1)*(nz1-1)
enddo
enddo
enddo
enddo
n = nel*nx1*ny1*nz1
call fgslib_gs_setup(gs_avg_hndl,glo_num,n,nekcomm,mp)
return
end
c-----------------------------------------------------------------------
c
c planar average
c
c-----------------------------------------------------------------------
c
c idir=1 ==> average over x direction
c idir=2 ==> average over y direction
c idir=3 ==> average over z direction
c
c-----------------------------------------------------------------------
subroutine plane_avg_tensor(ua,u,gs_hndl,nelx,nely,nelz,ifld,idir)
include 'SIZE'
include 'TOTAL'
real u (lx1,ly1,lz1,lelt)
real ua(lx1,ly1,lz1,lelt)
integer gs_hndl,e,ex,ey,ez,eg
c
c This routine does planar averaging for 'u' and outputs 'ua'
c for box type meshes with structure - nelx x nely x nelz.
c
c Input: u - variable to be averaged
c gs_hndl - handle for gs_setup
c nelx - number of elements in x-direction
c nely - number of elements in y-direction
c nelz - number of elements in z-direction
c ifld - 1 for velocity, 2 for passive-scalar
c idir - direction for averaging, 1-x,2-y,3-z
c
c Output ua = u averaged in direction idir
c
c TYPICAL USAGE:
c
c integer gs_avg_hndl
c save gs_avg_hndl
c data gs_avg_hndl / 0 /
c real vxa(lx1,ly1,lz1,lelt)
c real vya(lx1,ly1,lz1,lelt)
c real vza(lx1,ly1,lz1,lelt)
c nelx = 18
c nely = 12
c nelz = 10
c ifld = 1 !velocity field
c idir = 2 !y_direction
c
c call plane_avg_tensor(vxa,vx,gs_avg_hndl,nelx,nely,nelz,ifld,idir)
c call plane_avg_tensor(vya,vy,gs_avg_hndl,nelx,nely,nelz,ifld,idir)
c call plane_avg_tensor(vza,vz,gs_avg_hndl,nelx,nely,nelz,ifld,idir)
nelxy = nelx*nely
nelyz = nely*nelz
nelzx = nelz*nelx
if (gs_hndl.eq.0) then
if(idir.eq.1) call set_gs_x_hndl_pl(gs_hndl,nelx,nelyz,ifld)
if(idir.eq.2) call set_gs_y_hndl_pl(gs_hndl,nelx,nely,nelz,ifld)
if(idir.eq.3) call set_gs_z_hndl_pl(gs_hndl,nelxy,ifld)
endif
nel = nelfld(ifld)
n = nx1*ny1*nz1*nel
call copy(ua,bm1,n) ! Set the averaging weights
call fgslib_gs_op(gs_hndl,ua,1,1,0) ! Sum weights over columns
do i=1,n ! ua = (w_j*u_j)/( sum_i w_i)
ua(i,1,1,1) = bm1(i,1,1,1)*u(i,1,1,1)/ua(i,1,1,1)
enddo
call fgslib_gs_op(gs_hndl,ua,1,1,0) ! Sum weighted values
return
end
c-----------------------------------------------------------------------
subroutine set_gs_x_hndl_pl(gs_avg_hndl,nelx,nelyz,ifld)
c Set the x-average handle
include 'SIZE'
include 'TOTAL'
integer gs_avg_hndl,e,ex,ey,ez,eg,nelyz,nelx
common /nekmpi/ mid,mp,nekcomm,nekgroup,nekreal
common /c_is1/ glo_num(lx1,ly1,lz1,lelv)
integer*8 glo_num,ex_g
nel = nelfld(ifld)
do e=1,nel
eg = lglel(e)
call get_exyz(ex,ey,ez,eg,nelx,nelyz,1)
ex_g = ey ! Ensure int*8 promotion
do k=1,nz1 ! Enumerate points in the y-z plane
do j=1,ny1
do i=1,nx1
glo_num(i,j,k,e) = j+ny1*(k-1) + ny1*nz1*(ex_g-1)
enddo
enddo
enddo
enddo
n = nel*nx1*ny1*nz1
call fgslib_gs_setup(gs_avg_hndl,glo_num,n,nekcomm,mp)
return
end
c-----------------------------------------------------------------------
subroutine set_gs_y_hndl_pl(gs_avg_hndl,nelx,nely,nelz,ifld)
c Set the y-average handle
include 'SIZE'
include 'TOTAL'
integer gs_avg_hndl,e,ex,ey,ez,eg,nelyz,nelx
common /nekmpi/ mid,mp,nekcomm,nekgroup,nekreal
common /c_is1/ glo_num(lx1,ly1,lz1,lelv)
integer*8 glo_num,ex_g
nel = nelfld(ifld)
do e=1,nel
eg = lglel(e)
call get_exyz(ex,ey,ez,eg,nelx,nely,nelz)
ex_g = (ez-1)*nelx+ex ! Ensure int*8 promotion
do k=1,nz1 ! Enumerate points in the x-z plane
do j=1,ny1
do i=1,nx1
glo_num(i,j,k,e) = k+nz1*(i-1) + nx1*nz1*(ex_g-1)
enddo
enddo
enddo
enddo
n = nel*nx1*ny1*nz1
call fgslib_gs_setup(gs_avg_hndl,glo_num,n,nekcomm,mp)
return
end
c-----------------------------------------------------------------------
subroutine set_gs_z_hndl_pl(gs_avg_hndl,nelxy,ifld)
c Set the z-average handle
include 'SIZE'
include 'TOTAL'
integer gs_avg_hndl,e,ex,ey,ez,eg
common /nekmpi/ mid,mp,nekcomm,nekgroup,nekreal
common /c_is1/ glo_num(lx1,ly1,lz1,lelv)
integer*8 glo_num,ex_g
nel = nelfld(ifld)
do e=1,nel
eg = lglel(e)
call get_exyz(ex,ey,ez,eg,nelxy,1,1)
ex_g = ex ! Ensure int*8 promotion
do k=1,nz1 ! Enumerate points in the x-y plane
do j=1,ny1
do i=1,nx1
glo_num(i,j,k,e) = i+nx1*(j-1) + nx1*ny1*(ex_g-1)
enddo
enddo
enddo
enddo
n = nel*nx1*ny1*nz1
call fgslib_gs_setup(gs_avg_hndl,glo_num,n,nekcomm,mp)
return
end
c-----------------------------------------------------------------------
c
c GEOMETRIC AVERAGES over repeating features in domain
c
c-----------------------------------------------------------------------
subroutine geom_avg_tensor(ua,u,gs_hndl,nelx,nely,nelz,ifld,idir
$ ,nrepeat)
include 'SIZE'
include 'TOTAL'
real u (lx1,ly1,lz1,lelt)
real ua(lx1,ly1,lz1,lelt)
integer gs_hndl,e,ex,ey,ez,eg
integer idir,nrepeat
common /c_is1/ glo_num(lx1,ly1,lz1,lelv)
integer*8 glo_num
if(nrepeat.eq.0) call exitt
if (gs_hndl.eq.0) then
if (idir.eq.1)
$ call set_gs_x_hndl_geom(gs_hndl,nelx,nely,nelz,ifld,nrepeat)
if (idir.eq.2)
$ call set_gs_y_hndl_geom(gs_hndl,nelx,nely,nelz,ifld,nrepeat)
if (idir.eq.3)
$ call set_gs_z_hndl_geom(gs_hndl,nelx,nely,nelz,ifld,nrepeat)
endif
nel = nelfld(ifld)
n = nx1*ny1*nz1*nel
call copy(ua,bm1,n) ! Set the averaging weights
call fgslib_gs_op(gs_hndl,ua,1,1,0) ! Sum weights over columns
do i=1,n ! ua = (w_j*u_j)/( sum_i w_i)
ua(i,1,1,1) = bm1(i,1,1,1)*u(i,1,1,1)/ua(i,1,1,1)
enddo
call fgslib_gs_op(gs_hndl,ua,1,1,0) ! Sum weighted values
return
end
c-----------------------------------------------------------------------
subroutine set_gs_x_hndl_geom(gs_hndl,nelx,nely,nelz,ifld,nrepeat)
c Set the x-average handle
include 'SIZE'
include 'TOTAL'
integer gs_avg_hndl,e,ex,ey,ez,eg,nelx,nely,nelz
common /nekmpi/ mid,mp,nekcomm,nekgroup,nekreal
common /c_is1/ glo_num(lx1,ly1,lz1,lelv)
integer nrepeat,erepeat,elx,ely,elz
integer*8 lx,ly,lz,lb4
integer*8 glo_num
nel = nelfld(ifld)
erepeat = int(nelx/nrepeat)
elx = erepeat
ely = nely
elz = nelz
lx = elx*(nx1-1)+1 ! number of points in x dir
ly = ely*(ny1-1)+1
lz = elz*(nz1-1)+1
do e=1,nel
eg = lglel(e)
call get_exyz(ex,ey,ez,eg,nelx,nely,nelz)
ex = mod1(ex,erepeat)
do k=1,nz1
do j=1,ny1
do i=1,nx1
lb4= ly*lx*(k+(ez-1)*(nz1-1)-1)
lb4= lb4 + lx*(j+(ey-1)*(ny1-1)-1)
glo_num(i,j,k,e)= lb4 + i+(ex-1)*(nx1-1)
enddo
enddo
enddo
enddo
n = nel*nx1*ny1*nz1
call fgslib_gs_setup(gs_hndl,glo_num,n,nekcomm,mp)
return
end
c-----------------------------------------------------------------------
subroutine set_gs_y_hndl_geom(gs_hndl,nelx,nely,nelz,ifld,nrepeat)
c Set the y-average handle
include 'SIZE'
include 'TOTAL'
integer gs_avg_hndl,e,ex,ey,ez,eg,nelx,nely,nelz
common /nekmpi/ mid,mp,nekcomm,nekgroup,nekreal
common /c_is1/ glo_num(lx1,ly1,lz1,lelv)
integer nrepeat,erepeat,elx,ely,elz
integer*8 lx,ly,lz,lb4
integer*8 glo_num
nel = nelfld(ifld)
erepeat = int(nely/nrepeat)
elx = nelx
ely = erepeat
elz = nelz
lx = elx*(nx1-1)+1 ! number of points in x dir
ly = ely*(ny1-1)+1
lz = elz*(nz1-1)+1
do e=1,nel
eg = lglel(e)
call get_exyz(ex,ey,ez,eg,nelx,nely,nelz)
ey = mod1(ey,erepeat)
do k=1,nz1
do j=1,ny1
do i=1,nx1
lb4= ly*lx*(k+(ez-1)*(nz1-1)-1)
lb4= lb4 + lx*(j+(ey-1)*(ny1-1)-1)
glo_num(i,j,k,e)= lb4 + i+(ex-1)*(nx1-1)
enddo
enddo
enddo
enddo
n = nel*nx1*ny1*nz1
call fgslib_gs_setup(gs_hndl,glo_num,n,nekcomm,mp)
return
end
c-----------------------------------------------------------------------
subroutine set_gs_z_hndl_geom(gs_hndl,nelx,nely,nelz,ifld,nrepeat)
c Set the z-average handle
include 'SIZE'
include 'TOTAL'
integer gs_hndl,e,ex,ey,ez,eg,nelx,nely,nelz
common /nekmpi/ mid,mp,nekcomm,nekgroup,nekreal
common /c_is1/ glo_num(lx1,ly1,lz1,lelv)
integer nrepeat,erepeat,elx,ely,elz
integer*8 lx,ly,lz,lb4
integer*8 glo_num
nel = nelfld(ifld)
erepeat = int(nelz/nrepeat)
elx = nelx
ely = nely
elz = erepeat
lx = elx*(nx1-1)+1 ! number of points in x dir
ly = ely*(ny1-1)+1
lz = elz*(nz1-1)+1
do e=1,nel
eg = lglel(e)
call get_exyz(ex,ey,ez,eg,nelx,nely,nelz)
ez = mod1(ez,erepeat)
do k=1,nz1
do j=1,ny1
do i=1,nx1
lb4= ly*lx*(k+(ez-1)*(nz1-1)-1)
lb4= lb4 + lx*(j+(ey-1)*(ny1-1)-1)
glo_num(i,j,k,e)= lb4 + i+(ex-1)*(nx1-1)
enddo
enddo
enddo
enddo
n = nel*nx1*ny1*nz1
call fgslib_gs_setup(gs_hndl,glo_num,n,nekcomm,mp)
return
end
c-----------------------------------------------------------------------