-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathutilities.f
1832 lines (1537 loc) · 45.2 KB
/
utilities.f
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
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
c-----------------------------------------------------------------------
real function planar_ave_m1(phi,norm,pt,eps)
implicit none
C
C Compute area average of phi() on the
C plane defined by normal 'norm' and point 'pt'
C
include 'SIZE'
include 'TOTAL'
real phi(lx1*ly1*lz1,1),norm(3),pt(3),eps,phi_ext
real dpdx(lx1*ly1*lz1)
real dpdy(lx1*ly1*lz1)
real dpdz(lx1*ly1*lz1)
real aa,bb,cc,dd,w1,w2,x0,y0,z0,r0,rr,del,xsa,glsum
integer e,i,j,k,n
n=lx1*ly1*lz1
! make sure norm is a unit vector
dd=(norm(1)**2+norm(2)**2+norm(3)**2)
if(dd.gt.0) dd=sqrt(dd)
aa=norm(1)/dd
bb=norm(2)/dd
cc=0.0
if(if3d) cc=norm(3)/dd
dd=-1.0*(aa*pt(1)+bb*pt(2)+cc*pt(3))
w1=0.0
w2=0.0
do e=1,nelv
call gradm11(dpdx,dpdy,dpdz,phi,e)
do i=1,n
x0=xm1(i,1,1,e)
y0=ym1(i,1,1,e)
z0=zm1(i,1,1,e)
r0=aa*(x0-pt(1))+bb*(y0-pt(2))+cc*(z0-pt(3)) !signed distance to plane
rr=min(2.0,abs(r0)*2.0/eps)
phi_ext=phi(i,e)+r0*(aa*dpdx(i)+bb*dpdy(i)+cc*dpdz(i)) !1st order extrapolation to the plane
if(rr.gt.1.0) then
del = 1.0/8.0*(5.0-2.0*rr-sqrt(-7.0+12.0*rr-4.0*rr**2))
else
del = 1.0/8.0*(3.0-2.0*rr+sqrt( 1.0+ 4.0*rr-4.0*rr**2))
endif
w1=w1+phi_ext*bm1(i,1,1,e)*del
w2=w2+bm1(i,1,1,e)*del
enddo
enddo
xsa=glsum(w2,1)
planar_ave_m1 = glsum(w1,1)/max(xsa,1.0e-8)
xsa=2.0*xsa/eps !cross sectional area
return
end
C-----------------------------------------------------------------------
real function planar_ave_m2(phi,norm,pt,eps)
implicit none
C
C Compute area average of phi() on the
C plane defined by normal 'norm' and point 'pt'
C
include 'SIZE'
include 'TOTAL'
real phi(1),norm(3),pt(3),eps
real aa,bb,cc,dd,w1,w2,x0,y0,z0,r0,rr,del,xsa,glsum
integer i,j,k,n
n=lx2*ly2*lz2*nelv
aa=norm(1)
bb=norm(2)
cc=0.0
if(if3d) cc=norm(3)
dd=-1.0*(aa*pt(1)+bb*pt(2)+cc*pt(3))
w1=0.0
w2=0.0
do i=1,n
x0=xm2(i,1,1,1)
y0=ym2(i,1,1,1)
z0=zm2(i,1,1,1)
r0=(aa*x0+bb*y0+cc*z0+dd)/sqrt(aa**2+bb**2+cc**2)
rr=min(2.0,abs(r0)*2.0/eps)
if(rr.gt.1.0) then
del = 1.0/8.0*(5.0-2.0*rr-sqrt(-7.0+12.0*rr-4.0*rr**2))
else
del = 1.0/8.0*(3.0-2.0*rr+sqrt( 1.0+ 4.0*rr-4.0*rr**2))
endif
w1=w1+phi(i)*bm2(i,1,1,1)*del
w2=w2+bm2(i,1,1,1)*del
enddo
xsa=glsum(w2,1)
planar_ave_m2 = glsum(w1,1)/max(xsa,1.0e-8)
xsa=2.0*xsa/eps !cross sectional area
return
end
C-----------------------------------------------------------------------
subroutine div_check(phi)
real phi(1)
if(phi(1).ne.phi(1)) call exitt
return
end
C-----------------------------------------------------------------------
subroutine get_wall_distance(wd,itype)
implicit none
include 'SIZE'
integer icalled
data icalled /0/
save icalled
real wd(*)
real w1(lx1*ly1*lz1*lelv)
real w2(lx1*ly1*lz1*lelv)
real w3(lx1*ly1*lz1*lelv)
real w4(lx1*ly1*lz1*lelv)
real w5(lx1*ly1*lz1*lelv)
real w6(lx1*ly1*lz1*lelv)
common /SCRNS/ w1,w2,w3,w4,w5,w6
integer n,itype
if(icalled.eq.0) then
if(itype.eq.1) then
call cheap_dist(w1,1,'W ')
elseif(itype.eq.2) then
call distf(w1,1,'W ',w2,w3,w4,w5,w6)
else
if(nio.eq.0) write(*,*)
& "Error in get_wall_distance, unsupported distance type"
endif
icalled = 1
endif
n=lx1*ly1*lz1*nelv
call copy(wd,w1,n)
return
end
C-----------------------------------------------------------------------
subroutine set_wwpin_BCs(Nlay,pitch)
include 'SIZE'
include 'TOTAL'
real xxc(271),yyc(271)
logical iflag
radius = 0.5
ipin=1
Npin=1
xxc(1)=0.0
yyc(1)=0.0
do ilay=1,Nlay
Npin=Npin+6*(ilay-1)
if(ilay.gt.1) then
do j= 1,6
tht = (j-1)*pi/3.
do k= 1,(ilay-1)
ipin=ipin+1
xx=(ilay-1)*pitch-(k-1)*pitch*cos(pi/3.)
yy=(k-1)*pitch*sin(pi/3.)
xxc(ipin)= xx*cos(tht)-yy*sin(tht)
yyc(ipin)= xx*sin(tht)+yy*cos(tht)
if(nio.eq.0) write(*,*) ipin,xxc(ipin),yyc(ipin)
enddo
enddo
endif
enddo
do 10 ie=1,nelv
do 10 ic=1,2*ldim
iflag = .false.
cbc(ic,ie,2)=cbc(ic,ie,1)
if(cbc(ic,ie,1).eq.'W ') then
cbc(ic,ie,2)='I '
call facind(i0,i1,j0,j1,k0,k1,lx1,ly1,lz1,ic)
do 20 ipin=1,Npin
do 20 k=k0,k1
do 20 j=j0,j1
do 20 i=i0,i1
xx=xm1(i,j,k,ie)-xxc(ipin)
yy=ym1(i,j,k,ie)-yyc(ipin)
dist=sqrt((xx)**2+(yy)**2)
if(abs(dist-radius).le.1.0e-4) iflag=.true.
20 continue
endif
if(iflag) cbc(ic,ie,2)='f '
10 continue
return
end
C-----------------------------------------------------------------------
real function get_nearest(loc,coord)
include 'mpif.h'
include 'SIZE'
include 'TOTAL'
integer ipoint,ierr
real loc,coord(1),ds(2),dsg(2)
ds(1)=1.0d30
do ipoint=1,lx1*ly1*lz1*nelv
if(abs(coord(ipoint)-loc).lt.ds(1)) then
ds(1)=abs(coord(ipoint)-loc)
ds(2)=coord(ipoint)
endif
enddo
call MPI_ALLREDUCE(ds,dsg,1,MPI_2DOUBLE_PRECISION,MPI_MINLOC
& ,MPI_COMM_WORLD,ierr)
get_nearest=dsg(2)
return
end
c-----------------------------------------------------------------------
subroutine get_point3d(loc1,loc2,loc3,ix,iy,iz,eg)
include 'mpif.h'
include 'SIZE'
include 'TOTAL'
integer ipoint,ierr,dsi,ix,iy,iz,ie,eg,jx,jy,jz,je
real loc1,loc2,loc3,ds(2),dsg(2),dist(2)
dist(2)=1.0d30
do je=1,nelv
do jz=1,lz1
do jy=1,ly1
do jx=1,lx1
dist(1)=sqrt((loc1-xm1(jx,jy,jz,je))**2
& +(loc2-ym1(jx,jy,jz,je))**2+(loc3-zm1(jx,jy,jz,je))**2)
if(dist(1).lt.dist(2)) then
dist(2)=dist(1)
ix=jx
iy=jy
iz=jz
ie=je
endif
enddo
enddo
enddo
enddo
eg=lglel(ie)
ds(1)=dist(2)
ds(2)=dble(ix)
call MPI_ALLREDUCE(ds,dsg,1,MPI_2DOUBLE_PRECISION,MPI_MINLOC
& ,MPI_COMM_WORLD,ierr)
ix=int(dsg(2))
ds(2)=dble(iy)
call MPI_ALLREDUCE(ds,dsg,1,MPI_2DOUBLE_PRECISION,MPI_MINLOC
& ,MPI_COMM_WORLD,ierr)
iy=int(dsg(2))
ds(2)=dble(iz)
call MPI_ALLREDUCE(ds,dsg,1,MPI_2DOUBLE_PRECISION,MPI_MINLOC
& ,MPI_COMM_WORLD,ierr)
iz=int(dsg(2))
ds(2)=dble(eg)
call MPI_ALLREDUCE(ds,dsg,1,MPI_2DOUBLE_PRECISION,MPI_MINLOC
& ,MPI_COMM_WORLD,ierr)
eg=int(dsg(2))
return
end
c-----------------------------------------------------------------------
real function get_nearest_face(loc,coord,norm)
include 'mpif.h'
include 'SIZE'
include 'TOTAL'
integer ielem,iside,i0,i1,j0,j1,k0,k1,i,j,k,ierr
real loc,coord(1),ds(2),dsg(2),norm(3),fnorm(3),dp
ds(1)=1.0d30
do ielem=1,nelv
do iside=1,ldim*2
call facind(i0,i1,j0,j1,k0,k1,lx1,ly1,lz1,iside)
i=(i0+i1)/2
j=(j0+j1)/2
k=(k0+k1)/2
ipoint=i+(j-1)*lx1+(k-1)*lx1*ly1+lx1*ly1*lz1*(ielem-1)
call getSnormal(fnorm,i,j,k,iside,ielem)
dp=fnorm(1)*norm(1)+fnorm(2)*norm(2)
if(if3d) dp=dp+fnorm(3)*norm(3)
if((1.0d0-abs(dp)).lt.1.0d-8)then
if(abs(coord(ipoint)-loc).lt.ds(1)) then
ds(1)=abs(coord(ipoint)-loc)
ds(2)=coord(ipoint)
endif
endif
enddo
enddo
call MPI_ALLREDUCE(ds,dsg,1,MPI_2DOUBLE_PRECISION,MPI_MINLOC
& ,MPI_COMM_WORLD,ierr)
get_nearest_face=dsg(2)
return
end
C-----------------------------------------------------------------------
subroutine weighted_average(phi,wrt,loc,coord,norm,phia)
C
C Compute planar averages of phi() weighted by wrt() on the
C plane normal to norm() with intercept coord = loc
C
include 'SIZE'
include 'TOTAL'
integer ielem,iside,i,i0,i1,j,j0,j1,k,k0,k1
real phi(1),wrt(1),loc,coord(1),norm(3),phia
real fnorm(3),dp,a1,phia1
loc=get_nearest_face(loc,coord,norm)
phia=0.0
phia1=0.0
do ielem=1,nelv
do iside=1,ndim*2
call facind(i0,i1,j0,j1,k0,k1,lx1,ly1,lz1,iside)
i=(i0+i1)/2 !just use the point in the middle of the face
j=(j0+j1)/2
k=(k0+k1)/2
ipoint=i+(j-1)*lx1+(k-1)*lx1*ly1+(ielem-1)*lx1*ly1*lz1
if(abs(coord(ipoint)-loc).lt.1.0d-8)then
call getSnormal(fnorm,i,j,k,iside,ielem)
dp=fnorm(1)*norm(1)+fnorm(2)*norm(2)
if(if3d) dp=dp+fnorm(3)*norm(3)
if(abs(1.0d0-dp).lt.1.0d-8) then
do i=i0,i1
do j=j0,j1
do k=k0,k1
ipoint=i+(j-1)*lx1+(k-1)*lx1*ly1+(ielem-1)*lx1*ly1*lz1
if ((iside.eq.1).or.(iside.eq.3)) then
a1=area(i,k,iside,ielem)
elseif((iside.eq.2).or.(iside.eq.4)) then
a1=area(j,k,iside,ielem)
else
a1=area(i,j,iside,ielem)
endif
phia=phia+phi(ipoint)*wrt(ipoint)*a1
phia1=phia1+wrt(ipoint)*a1
enddo
enddo
enddo
endif
endif
enddo
enddo
phia=glsum(phia,1)
phia1=glsum(phia1,1)
phia=phia/phia1
return
end
C-----------------------------------------------------------------------
subroutine planar_average_weighted(phia,phi,wrt,w1,w2)
include 'SIZE'
include 'GEOM'
include 'PARALLEL'
include 'WZ'
include 'ZPER'
real phi(nx1*ny1,nz1,nelv),wrt(nx1*ny1,nz1,nelv),phia(nz1,nelz)
real w1(nz1,nelz),w2(nz1,nelz) !work arrays
integer e,eg,ez,melxy,nz,i,k
real zz,aa
melxy=nelx*nely !number of elements in the plane
nz=nz1*nelz !number of z-slices
if(melxy.lt.1)then
if(nio.eq.0)write(*,256)'nelx*nely'
return
elseif(nelz.lt.1) then
if(nio.eq.0)write(*,256)'nelz'
return
elseif(melxy.gt.lelx*lely) then
if(nio.eq.0)write(*,257)'nelx*nely','lelx*lely'
return
elseif(nelz.gt.lelz) then
if(nio.eq.0)write(*,257)'nelz','lelz'
return
endif
256 format(5x,'ERROR: ',a,' must be at least 1!')
257 format(5x,'ERROR: ',a,' must be less than ',a,'!')
call rzero(phia,nz)
call rzero(w1,nz)
do e=1,nelt
eg=lglel(e)
ez=1+(eg-1)/melxy !z-slice id
do k=1,nz1
do i=1,nx1*ny1
zz=(1.0-zgm1(k,3))/2.0
aa=zz*area(i,1,5,e)+(1.0-zz)*area(i,1,6,e)
w1(k,ez)=w1(k,ez)+aa*wrt(i,k,e)
phia(k,ez)=phia(k,ez)+aa*wrt(i,k,e)*phi(i,k,e)
enddo
if(abs(w1(k,ez)).lt.1.0d-10) w1(k,ez)=1.0d-10
enddo
enddo
call gop(phia,w2,'+ ',nz)
call gop(w1,w2,'+ ',nz)
call invcol2(phia,w1,nz)
return
end
C-----------------------------------------------------------------------
subroutine x_planar_average(phia,phi,w1,w2)
include 'SIZE'
include 'GEOM'
include 'PARALLEL'
include 'WZ'
include 'ZPER'
real phi(nx1,ny1,nz1,nelv),wrt(nx1,ny1,nz1,nelv),phia(nx1,nelx)
real w1(nx1,nelx),w2(nx1,nelx) !work arrays
integer e,eg,ex,nx,i,j,estride
real xx,aa
if(ldim.gt.2) then
write(*,'(5x,a)')
& "x-average routine only written for 2D genbox meshes!"
return
endif
nx=nx1*nelx !number of z-slices
call rzero(phia,nx)
call rzero(w1,nx)
do e=1,nelt
eg=lglel(e)
ex=mod(eg,nelx) !x-slice id
if(ex.eq.0)ex=nelx
do i=1,nx1
do j=1,ny1
xx=(1.0-zgm1(i,1))/2.0
aa=zz*area(j,1,4,e)+(1.0-zz)*area(j,1,2,e)
w1(i,ex)=w1(i,ex)+aa
phia(i,ex)=phia(i,ex)+aa*phi(i,j,1,e)
enddo
enddo
enddo
call gop(phia,w2,'+ ',nx)
call gop(w1,w2,'+ ',nx)
call invcol2(phia,w1,nx)
return
end
C-----------------------------------------------------------------------
subroutine x_average_weighted(phia,phi,wrt,w1,w2)
include 'SIZE'
include 'GEOM'
include 'PARALLEL'
include 'WZ'
include 'ZPER'
real phi(nx1,ny1,nz1,nelv),wrt(nx1,ny1,nz1,nelv),phia(nx1,nelx)
real w1(nx1,nelx),w2(nx1,nelx) !work arrays
integer e,eg,ex,nx,i,j,estride
real xx,aa
if(lz1.gt.1) then
write(*,'(5x,a)')
& "x-average routine only written for 2D meshes!"
return
endif
nx=nx1*nelx !number of z-slices
call rzero(phia,nx)
call rzero(w1,nx)
do e=1,nelt
eg=lglel(e)
ex=mod(eg,nelx) !x-slice id
if(ex.eq.0)ex=nelx
do i=1,nx1
do j=1,ny1
xx=(1.0-zgm1(i,1))/2.0
aa=zz*area(j,1,4,e)+(1.0-zz)*area(j,1,2,e)
w1(i,ex)=w1(i,ex)+aa*wrt(i,j,1,e)
phia(i,ex)=phia(i,ex)+aa*wrt(i,j,1,e)*phi(i,j,1,e)
enddo
if(abs(w1(i,ex)).lt.1.0d-10) w1(i,ex)=1.0d-10
enddo
enddo
call gop(phia,w2,'+ ',nx)
call gop(w1,w2,'+ ',nx)
call invcol2(phia,w1,nx)
return
end
C-----------------------------------------------------------------------
real function q_vol_periodic(ix,iy,iz,ie,ifld)
implicit none
include 'SIZE'
include 'TOTAL'
integer ix,iy,iz,ie,ifld,n,e,f,dir
logical ifdid(ldimt),ifprintNu(ldimt)
common /printNu/ ifprintNu
real dummy,sarea,tarea,time0(ldimt),tcorr
real f_gm(ldimt),vel_avg,glsum,glsc2,glsc3
data ifdid /ldimt*.false./
data time0 /ldimt*-1.0/
save ifdid,time0,vel_avg,f_gm,dir
n=nx1*ny1*nz1*nelv
if(.not.ifdid(ifld-1)) then
dir=nint(abs(param(54))) !make sure this is an int, for my own sanity
ifdid(ifld-1) = .true.
tarea = 0.0
do e=1,nelv
do f=1,2*ndim
if(cbc(f,e,ifld).eq.'f ') then
call surface_int(dummy,sarea,xm1,e,f)
tarea=tarea+sarea
endif
enddo
enddo
tarea=glsum(tarea,1)
f_gm(ifld-1)=abs(tarea/volvm1) !probably wrong for CHT
endif
ifprintNu(ifld-1)=.true.
e=lglel(ie) !do nothing in solid region
if(e.gt.nelgv) then
q_vol_periodic = 0.0
return
endif
if(time.ne.time0(ifld-1)) then
time0(ifld-1)=time
if(dir.eq.1) then
vel_avg=glsc2(vx,bm1,n)/volvm1
tcorr = -1.0*glsc3(t(1,1,1,1,ifld-1),vx,bm1,n)
elseif(dir.eq.2) then
vel_avg=glsc2(vy,bm1,n)/volvm1
tcorr = -1.0*glsc3(t(1,1,1,1,ifld-1),vy,bm1,n)
elseif(dir.eq.3) then
vel_avg=glsc2(vz,bm1,n)/volvm1
tcorr = -1.0*glsc3(t(1,1,1,1,ifld-1),vz,bm1,n)
endif
tcorr=tcorr/(vel_avg*volvm1)
call cadd (t(1,1,1,1,ifld-1),tcorr,n)
endif
if(dir.eq.1) q_vol_periodic=-f_gm(ifld-1)*vx(ix,iy,iz,ie)/vel_avg
if(dir.eq.2) q_vol_periodic=-f_gm(ifld-1)*vy(ix,iy,iz,ie)/vel_avg
if(dir.eq.3) q_vol_periodic=-f_gm(ifld-1)*vz(ix,iy,iz,ie)/vel_avg
return
end
c-----------------------------------------------------------------------
subroutine print_Nusselt
include 'SIZE'
include 'TOTAL'
logical ifdo,ifprintNu(ldimt)
real rNus(ldimt)
common /printNu/ ifprintNu
save ifdo
data ifdo /.true./
if(.not.ifdo) return
if(istep.eq.0) then
do i=1,ldimt
ifprintNu(i)=.false.
enddo
ifldsv=ifield
do ifield=2,nfield
call makeuq
enddo
ifield=ifldsv
endif
c if(nsteps.eq.0) then
c do i=1,ldimt
c ifprintNu(i)=.true.
c enddo
c endif
if(abs(param(54)).lt.0.1) then
ifdo=.false.
if(nio.eq.0) then
write(*,'(a)') "******************************"
write(*,'(a)')
& "print_Nusselt routine only compatible with forced flow"
write(*,'(a)') "******************************"
endif
return
endif
n=nx1*ny1*nz1*nelv
jfld=0
do ifld=2,ldimt1
if(ifprintNu(ifld-1)) then
jfld=jfld+1
tarea=0.0
twall=0.0
do ie=1,nelt
do ifa=1,2*ndim
if(cbc(ifa,ie,ifld).eq.'f ') then
call surface_int(swall,sarea,t(1,1,1,1,ifld-1),ie,ifa)
twall=twall+swall
tarea=tarea+sarea
endif
enddo
enddo
tarea=glsum(tarea,1)
twall=glsum(twall,1)/tarea
if(nint(abs(param(54))).eq.1)
& tbulk=glsc3(t(1,1,1,1,ifld-1),vx,bm1,n)/glsc2(vx,bm1,n)
if(nint(abs(param(54))).eq.2)
& tbulk=glsc3(t(1,1,1,1,ifld-1),vy,bm1,n)/glsc2(vy,bm1,n)
if(nint(abs(param(54))).eq.3)
& tbulk=glsc3(t(1,1,1,1,ifld-1),vz,bm1,n)/glsc2(vz,bm1,n)
rNus(jfld)=1.0/((twall-tbulk)*cpfld(ifld,1))
endif
enddo
if(nio.eq.0) then
write(*,'(a24,es15.7,10es15.7)')
& "time, Nusselt",time,(rNus(i),i=1,jfld)
endif
return
end
c-----------------------------------------------------------------------
real function bc_area_average(phi,bca,ifld)
c return the area-weighted average of scalar phi on BC bca
implicit none
include 'SIZE'
include 'INPUT'
character*3 bca
integer ifld
real phi(lx1*ly1*lz1*lelv)
integer f,e
real phibc,Abc,dphi,dA
real glsum
phibc=0.0
Abc=0.0
do 10 e=1,nelt
do 10 f=1,ndim*2
if(cbc(f,e,ifld).eq.bca) then
call surface_int(dphi,dA,phi,e,f)
phibc=phibc+dphi
Abc=Abc+dA
endif
10 continue
Abc=glsum(Abc,1)
phibc=glsum(phibc,1)/Abc
bc_area_average = phibc
return
end
c-----------------------------------------------------------------------
real function bcID_area_average(phi,iID)
c return the area-weighted average of scalar phi on boundary iID
implicit none
include 'SIZE'
include 'INPUT'
include 'GEOM'
integer iID
real phi(lx1*ly1*lz1*lelv)
integer f,e
real phibc,Abc,dphi,dA
real glsum
phibc=0.0
Abc=0.0
do 10 e=1,nelt
do 10 f=1,ndim*2
if(boundaryID(f,e).eq.iID.or.boundaryIDt(f,e).eq.iID) then
call surface_int(dphi,dA,phi,e,f)
phibc=phibc+dphi
Abc=Abc+dA
endif
10 continue
Abc=glsum(Abc,1)
phibc=glsum(phibc,1)/Abc
bcID_area_average = phibc
return
end
c-----------------------------------------------------------------------
real function bc_area(bca,ifld)
c return the total area of faces with BC bca
implicit none
include 'SIZE'
include 'INPUT'
character*3 bca
integer ifld
integer f,e
real Abc,dA
real glsum
Abc=0.0
do 10 e=1,nelt
do 10 f=1,ndim*2
if(cbc(f,e,ifld).eq.bca) then
call surface_area(dA,e,f)
Abc=Abc+dA
endif
10 continue
Abc=glsum(Abc,1)
bc_area = Abc
return
end
c-----------------------------------------------------------------------
real function bcID_area(iID)
c return the total area of faces with Boundary ID iID
implicit none
include 'SIZE'
include 'INPUT'
include 'GEOM'
integer iID
integer f,e
real Abc,dA
real glsum
Abc=0.0
do 10 e=1,nelt
do 10 f=1,ndim*2
if(boundaryID(f,e).eq.iID.or.boundaryIDt(f,e).eq.iID) then
call surface_area(dA,e,f)
Abc=Abc+dA
endif
10 continue
Abc=glsum(Abc,1)
bcID_area = Abc
return
end
c-----------------------------------------------------------------------
real function bc_flux_average(phi,bca,ifld)
c return the flux-weighted average of phi on BC bca
implicit none
include 'SIZE'
include 'TOTAL'
character*3 bca
integer ifld
real phi(lx1*ly1*lz1,lelv)
integer f,e,lxyz
parameter (lxyz=lx1*ly1*lz1)
real phibc,AA,dphi,dAA,w(lxyz)
real glsum
phibc=0.0
AA=0.0
do e=1,nelv
do f=1,ndim*2
if(cbc(f,e,ifld).eq.bca) then
call surface_flux2(dphi,phi,e,f)
call surface_flux(dAA,vx,vy,vz,e,f,w)
phibc=phibc+dphi
AA=AA+dAA
endif
enddo
enddo
AA=glsum(AA,1)
phibc=glsum(phibc,1)/AA
bc_flux_average = phibc
return
end
c-----------------------------------------------------------------------
real function bcID_flux_average(phi,bid)
c return the flux-weighted average of phi on faces with boundary bid
implicit none
include 'SIZE'
include 'TOTAL'
integer bid
real phi(lx1*ly1*lz1,lelv)
integer f,e,lxyz
parameter (lxyz=lx1*ly1*lz1)
real phibc,AA,dphi,dAA,w(lxyz)
real glsum
phibc=0.0
AA=0.0
do e=1,nelv
do f=1,ndim*2
if(BoundaryID(f,e).eq.bid) then
call surface_flux2(dphi,phi,e,f)
call surface_flux(dAA,vx,vy,vz,e,f,w)
phibc=phibc+dphi
AA=AA+dAA
endif
enddo
enddo
AA=glsum(AA,1)
phibc=glsum(phibc,1)/AA
bcID_flux_average = phibc
return
end
c-----------------------------------------------------------------------
real function bc_totalflux(phi,ptrans,pdiff,bca,ifld)
c return the total flux through the faces with BC bca
implicit none
include 'SIZE'
include 'TOTAL'
integer lxyz
parameter (lxyz=lx1*ly1*lz1)
real phi(lx1*ly1*lz1,lelt)
real ptrans(lx1*ly1*lz1,lelt)
real pdiff(lx1*ly1*lz1,lelt)
integer ifld
character*3 bca
real face_advective_flux,face_diffusive_flux,glsum
real phibc
integer f,e
phibc=0.0
do e=1,nelv
do f=1,ldim*2
if(cbc(f,e,ifld).eq.bca) then
phibc=phibc+face_advective_flux(phi,ptrans,e,f)
phibc=phibc+face_diffusive_flux(phi,pdiff,e,f)
endif
enddo
enddo
phibc=glsum(phibc,1)
bc_totalflux = phibc
return
end
c-----------------------------------------------------------------------
real function bcID_totalflux(phi,ptrans,pdiff,bcid)
c return the total flux through the faces with boundaryID bcid
implicit none
include 'SIZE'
include 'TOTAL'
integer lxyz
parameter (lxyz=lx1*ly1*lz1)
real phi(lx1*ly1*lz1,lelt)
real ptrans(lx1*ly1*lz1,lelt)
real pdiff(lx1*ly1*lz1,lelt)
integer bcid
real face_advective_flux,face_diffusive_flux,glsum
real phibc
integer f,e
phibc=0.0
do e=1,nelv
do f=1,ndim*2
if(BoundaryID(f,e).eq.bcid) then
phibc=phibc+face_advective_flux(phi,ptrans,e,f)
phibc=phibc+face_diffusive_flux(phi,pdiff,e,f)
endif
enddo
enddo
phibc=glsum(phibc,1)
bcId_totalflux = phibc
return
end
c-----------------------------------------------------------------------
real function face_advective_flux(phi,ptrans,e,f)
c return the advective flux of scalar phi through face f of element e
implicit none
include 'SIZE'
include 'TOTAL' !probably just need SOLN and GEOM
integer lxyz
parameter (lxyz=lx1*ly1*lz1)
real phi(lxyz,lelt)
real ptrans(lxyz,lelt)
integer e,f
real wkx(lxyz),wky(lxyz),wkz(lxyz),dphi,wkk(lxyz)
integer iface,js1,jf1,jskip1,js2,jf2,jskip2
call col3(wkx,vx(1,1,1,e),phi(1,e),lxyz)
call col3(wky,vy(1,1,1,e),phi(1,e),lxyz)
if(if3d) call col3(wkx,vz(1,1,1,e),phi(1,e),lxyz)
call col2(wkx,ptrans(1,e),lxyz)
call col2(wky,ptrans(1,e),lxyz)
if(if3d) call col2(wkz,ptrans(1,e),lxyz)
call surface_flux_local(dphi,wkx,wky,wkz,e,f,wkk)
face_advective_flux=dphi
return
end
c-----------------------------------------------------------------------
real function face_diffusive_flux(phi,pdiff,e,f)
c return the diffusive flux of scalar phi through face f of element e
implicit none
include 'SIZE'
include 'TOTAL' !probably just need SOLN and GEOM
integer lxyz
parameter (lxyz=lx1*ly1*lz1)
real phi(lxyz,lelt)
real pdiff(lxyz,lelt)
integer e,f
real wkx(lxyz),wky(lxyz),wkz(lxyz),dphi,wkk(lxyz)
call gradm11(wkx,wky,wkz,phi,e)
call col2(wkx,pdiff(1,e),lxyz)
call col2(wky,pdiff(1,e),lxyz)
if(if3d) call col2(wkz,pdiff(1,e),lxyz)
call chsign(wkx,lxyz)
call chsign(wky,lxyz)
if(if3d) call chsign(wkz,lxyz)
call surface_flux_local(dphi,wkx,wky,wkz,e,f,wkk)
face_diffusive_flux=dphi
return
end
c-----------------------------------------------------------------------
subroutine surface_flux_local(dq,qx,qy,qz,e,f,w)
c identical to surface_flux in navier5, but qx,qy,qz are only a single element
include 'SIZE'
include 'GEOM'
include 'INPUT'
include 'PARALLEL'
include 'TOPOL'
parameter (l=lx1*ly1*lz1)
real qx(l),qy(l),qz(l),w(lx1,ly1,lz1)
integer e,f
call faccl3 (w,qx,unx(1,1,f,e),f)
call faddcl3 (w,qy,uny(1,1,f,e),f)
if (if3d) call faddcl3 (w,qz,unz(1,1,f,e),f)