-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathles_chan.F90
1427 lines (1141 loc) · 37.8 KB
/
les_chan.F90
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
subroutine les_chan
! This subroutine models the terms owing to the subgrid scale stress
! if the computation is to be treated as an LES not a DNS
!C This subroutine should be called when the velocity is in fourier space
!C in the periodic directions, on output, the velocity will be
!C in physical space.
!C It is assumed that the test filter and the LES filter are performed
!C by the same operation
!C On output S1 should contain |S| which may be used again in les_chan_th
!C if for the subgrid scalar dissipation
use ntypes
use Domain
use Grid
use Fft_var
use TIME_STEP_VAR
use run_variable
use les_chan_var
use mpi_var, only : rank
implicit none
integer i,j,k,l,m,ij
CHARACTER*35 FNAME, FNAME_tke
CHARACTER*28 file_name
real*8 S1_mean(1:NY)
! Variables for Dynamic Smagorinsky model:
real*8 C_SMAG
parameter (C_SMAG=0.13d0)
real*8 alpha,beta
! Array to store the velocity index for each component of the strain rate tensor
integer U_index1(6)
integer U_index2(6)
logical ADD_LES,LES_IMPLICIT
! Here, alpha is the test/LES filter width ratio
parameter (alpha=2.44950)
! beta is the LES/grid filter width ratio
parameter (beta=1.d0)
ADD_LES = .TRUE.
LES_IMPLICIT =.TRUE.
damp_fact(:) = 0.0d0 ;
! Set the velocity index for each component of the stress tensor
U_index1(1)=1
U_index2(1)=1
U_index1(2)=2
U_index2(2)=2
U_index1(3)=3
U_index2(3)=3
U_index1(4)=1
U_index2(4)=2
U_index1(5)=1
U_index2(5)=3
U_index1(6)=2
U_index2(6)=3
! When using a Near-wall model, don't use LES at the wall
! IF ((U_BC_YMIN.EQ.3).or.(W_BC_YMIN.EQ.3)) then
!C J1=2
!C ELSE
!C J1=JSTART
!C END IF
!C IF ((U_BC_YMAX.EQ.3).or.(W_BC_YMAX.EQ.3)) then
!C J2=NY-1
!C ELSE
!C J2=JEND
!C END IF
! First, for all models, apply boundary conditions to the velocity field
! (fill ghost cells) to ensure accurate calculation of gradients
!C Apply Boundary conditions to velocity field
IF (USE_MPI) THEN
J1 = JSTART
J2 = JEND
J1i= 1
J2e=NY+1
ELSE
J1 = JSTART
J2 = JEND
J1i= 1
J2e=NY+1
END IF
if (LES_MODEL_TYPE.EQ.1) then
! Constant Smagorinsky model
! First, compute the rate of strain tensor S_ij
call compute_strain_chan
! Compute |S| at GYF points, store in S2X
! Interpolation to GYF points is easy since by definition
! GYF points are exactly midway between neighboring GY points
DO J=JSTART,JEND
DO K=ZSTART,ZEND
DO I=0,NXP
S2X(I,K,J)=SQRT( &
2.d0*Sij(I,K,J,1)**2.d0 &
+4.d0*Sij(I,K,J,4)**2.d0 &
+4.d0*Sij(I,K,J,5)**2.d0 &
+2.d0*Sij(I,K,J,2)**2.d0 &
+4.d0*Sij(I,K,J,6)**2.d0 &
+2.d0*Sij(I,K,J,3)**2.d0 )
END DO
END DO
END DO
! Extend |S| to ghost cells
DO K=0,NZ+1
DO I=0,NXP
S2X(I,K,0)=S2X(I,K,1)
S2X(I,K,NY+1)=S2X(I,K,NY)
END DO
END DO
! Now, compute |S|*S_ij, storing in Sij
! First compute at GYF points
DO J=JSTART,JEND
DO K=ZSTART,ZEND
DO I=0,NXP
Sij(I,K,J,1)=S2X(I,K,J)*Sij(I,K,J,1)
Sij(I,K,J,5)=S2X(I,K,J)*Sij(I,K,J,5)
! CSij(:,:,:,2) is added through an implicit eddy viscosity
Sij(I,K,J,2)=0.d0
Sij(I,K,J,3)=S2X(I,K,J)*Sij(I,K,J,3)
END DO
END DO
END DO
! Now, compute at GY points, interpolating |S|
DO J=1,NY+1
DO K=0,NZ+1
DO I=0,NXP
! |S| interpolated to GY point
TEMP(I,K,J)=(S2X(I,K,J)*DYF(j-1)+S2X(I,K,J-1)*DYF(j)) &
/(2.d0*DY(j))
! The terms dU1/dy and dU3/dy in CSij(:,:,:,4) and CSij(:,:,:,6) respectively
! are subtracted out from Sij here since they are treated implicitly
! in eddy viscosity terms
Sij(I,K,J,4)=TEMP(I,K,J) &
*(Sij(I,K,J,4)-0.5*(CU1X(I,K,J)-CU1X(I,K,J-1))/DY(j))
Sij(I,K,J,6)=TEMP(I,K,J) &
*(Sij(I,K,J,6)-0.5*(CU3X(I,K,J)-CU3X(I,K,J-1))/DY(j))
END DO
END DO
END DO
! We now have |S|*S_ij stored in Sij in Physical space
! Convert |S|*S_ij to Fourier space
do ij=1,6
S1X=Sij(:,:,:,ij)
CALL MPI_TRANSPOSE_REAL_X_TO_Z(S1X,S1Z)
varp(:,:,:) = 0.d0
DO I=0,NXM
varp(I,:,:)=S1Z(I,:,:)
ENDDO
CALL FFT_X_TO_FOURIER_OP(varp,cvarp,0,NY+1,0,NZP)
DO I=0,NKX
CS1Z(I,:,:)=cvarp(I,:,:)
ENDDO
CS1Z(NKX+1:NX2V-1,:,:)=(0.0,0.0)
CALL MPI_TRANSPOSE_COMPLEX_Z_TO_X(CS1Z,CS1X)
CSij(:,:,:,ij)=CS1X
! CALL FFT_X_TO_FOURIER(Sij(0,0,0,ij),CSij(0,0,0,ij),0,NY+1,0,NZ+1)
end do
! Compute the filter lengthscale
! Absorb -2.d0*C_SMAG**2.d0 here for effienciency
! DO J=1,NY
! ! At GYF points:
! ! Constant Smagorinsky
! ! DELTA_YF(J)=-2.d0*C_SMAG**2.d0
! ! & *(DX(1)*beta*DYF(J)*2.d0*DZ(1)*beta)**(2.d0/3.d0)
! ! Wall Damping
! DELTA_YF(J)= &
! -2.d0*(0.1d0*(1.d0-exp((-GYF(J)/(NU*25.d0))**3.d0)))**2.d0 &
! *(DX(1)*beta*DYF(J)*2.d0*DZ(1)*beta)**(2.d0/3.d0)
!
! END DO
! Extend to ghost cells
DO J=1,NY+1
! At GY points:
! Constant Smagorinsky
! DELTA_Y(J)=-2.d0*C_SMAG**2.d0
! & *(DX(1)*beta*DY(J)*2.d0*DZ(1)*beta)**(2.d0/3.d0)
! Wall Damping
DELTA_Y(k,j)= &
-2.d0*(0.1d0*(1.d0-exp((-GY(J)/(NU*25.d0))**3.d0)))**2.d0 &
*(DX(1)*beta*DY(J)*2.d0*DZ(1)*beta)**(2.d0/3.d0)
END DO
! Get the eddy viscosity at GY points
! NU_T = (C_S^2 * DELTA^2)*|S|
DO J=1,NY+1
DO K=0,NZ+1
DO I=0,NXP
NU_T(I,K,J)=-0.5d0*DELTA_Y(K,J)*TEMP(I,K,J)
END DO
END DO
END DO
! Now, compute TAU, store in the corresponging Sij
DO J=1,NY
DO K=1,NZ
DO I=0,NX2P
CSij(I,K,J,1)=DELTA_Y(k,J)*CSij(I,K,J,1)
CSij(I,K,J,5)=DELTA_Y(k,J)*CSij(I,K,J,5)
! CSij(:,:,:,2) is added through an implicit eddy viscosity
! CSij(I,K,J,2)=DELTA_Y(K,J)*CSij(I,K,J,2)
CSij(I,K,J,3)=DELTA_Y(K,J)*CSij(I,K,J,3)
END DO
END DO
END DO
DO J=1,NY+1
DO K=1,NZ+1
DO I=0,NX2P
CSij(I,K,J,4)=DELTA_Y(K,J)*CSij(I,K,J,4)
CSij(I,K,J,6)=DELTA_Y(K,J)*CSij(I,K,J,6)
END DO
END DO
END DO
! tau_ij is now contained in CSij in Fourier space
! Convert the velocity to physical space
CALL REAL_FOURIER_TRANS_U1 (.false.)
CALL REAL_FOURIER_TRANS_U2 (.false.)
CALL REAL_FOURIER_TRANS_U3 (.false.)
! CALL FFT_X_TO_PHYSICAL(CU1,U1,0,NY+1,0,NZ+1)
! CALL FFT_X_TO_PHYSICAL(CU2,U2,0,NY+1,0,NZ+1)
! CALL FFT_X_TO_PHYSICAL(CU3,U3,0,NY+1,0,NZ+1)
else if ((LES_MODEL_TYPE.EQ.2).or.(LES_MODEL_TYPE.eq.3)) then
! Here, use a dynamic smagorinsky model with or without scale similar part
! Compute the filter width
DO J=0,NY+1
! At GYF points:
! DELTA_YF(J)=(beta*DX(1)*DYF(J)*beta*DZ(1))**(1.d0/3.d0)
! DELTA_YF(J)=sqrt((beta*DX(1))**2.d0+(DYF(J)*2.d0)**2.d0
! & +(beta*DZ(1))**2.d0)
END DO
DO J=0,NY+1
DO K=0,NZ+1
! At cell centered points:
DELTA_Y(K,J)=(beta*DX(1)*DYF(J)*DZF(K))**(1.d0/3.d0)
END DO
END DO
! We need to calculate the components of C, the dynamic coefficient
! Compute the rate of strain tensor, store in Sij
call compute_strain_chan
! Compute |S| , store in S2X, bcz S2X will be used for ffts and filter variables
DO J=JSTART,JEND
DO K=ZSTART,ZEND
DO I=0,NXP
S2X(I,K,J)=SQRT( &
2.d0*Sij(I,K,J,1)**2.d0 &
+4.d0*Sij(I,K,J,4)**2.d0 &
+4.d0*Sij(I,K,J,5)**2.d0 &
+2.d0*Sij(I,K,J,2)**2.d0 &
+4.d0*Sij(I,K,J,6)**2.d0 &
+2.d0*Sij(I,K,J,3)**2.d0 )
END DO
END DO
END DO
! Extend |S| to ghost cells
DO K=0,NZ+1
DO I=0,NXP
S2X(I,K,0) =S2X(I,K,1)
S2X(I,K,NY+1)=S2X(I,K,NY)
END DO
END DO
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!! Storing for tke les
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
DO ij=1,6
DO J=0,NY+1
DO K=0,NZ+1
DO I=0,NXP
St_rij(I,K,J,ij)=Sij(I,K,J,ij)
ENDDO
ENDDO
ENDDO
ENDDO
! Need to calculate Mean Strain Rate
do ij=1,6
do j=0,NY+1
do k=0,NZ+1
Sij_mean(k,j,ij) = SUM(Sij(0:min(NXP,NXP_L),k,j,ij))/dble(NX)
enddo
enddo
CALL MPI_COMBINE_STATS(Sij_mean(0,0,ij),NZ+2,NY+2)
enddo
DO K=0,NZ+1
DO J=0,NY+1
U1_BAR_les(k,j) = dble(CU1X(0,k,j))
U2_BAR_les(k,j) = dble(CU2X(0,k,j))
U3_BAR_les(k,j) = dble(CU3X(0,k,j))
ENDDO
ENDDO
CALL MPI_BCAST_REAL(U1_BAR_les,NZ+2,NY+2)
CALL MPI_BCAST_REAL(U2_BAR_les,NZ+2,NY+2)
CALL MPI_BCAST_REAL(U3_BAR_les,NZ+2,NY+2)
! Convert Ui to physical space
CALL REAL_FOURIER_TRANS_U1 (.false.)
CALL REAL_FOURIER_TRANS_U2 (.false.)
CALL REAL_FOURIER_TRANS_U3 (.false.)
! CALL FFT_X_TO_PHYSICAL(CU1,U1,0,NY+1,0,NZ+1)
! CALL FFT_X_TO_PHYSICAL(CU2,U2,0,NY+1,0,NZ+1)
! CALL FFT_X_TO_PHYSICAL(CU3,U3,0,NY+1,0,NZ+1)
! Apply the filter to the LES velocity and save
do j=0,NY+1
do k=0,NZ+1
do i=0,NXP
U_BAR_TIL(i,k,j,1)=U1X(i,k,j)
U_BAR_TIL(i,k,j,2)=U2X(i,k,j)
U_BAR_TIL(i,k,j,3)=U3X(i,k,j)
end do
end do
end do
if (les_model_type.eq.3) then
! storing in the U_2BAR
do j=0,NY+1
do k=0,NZ+1
do i=0,NXP
do ij =1,3
U_2BAR(i,k,j,ij) = U_BAR_TIL(i,k,j,ij)
end do
end do
end do
end do
do i=1,3
! application of grid filter i.e. filter_type = 1
S1X = U_2BAR(:,:,:,i)
call FILTER_VAR(1)
U_2BAR(:,:,:,i)=S1X
! call les_filter_chan(U_2BAR(0,0,0,i),0,NY+1,1)
enddo
endif
! Now, filter the velocity
do i=1,3
! application of test filter i.e. filter_type = 2
S1X = U_BAR_TIL(:,:,:,i)
call FILTER_VAR(2)
U_BAR_TIL(:,:,:,i)=S1X
! call les_filter_chan(U_BAR_TIL(0,0,0,i),0,NY+1,2)
end do
! Compute C_DYN only every x # of timesteps
if (((MOD(TIME_STEP,10).eq.0).AND.(RK_STEP.eq.1)) &
.or.FIRST_TIME) THEN
if (rank .eq. 0)then
write(6,*)'##############################'
write(6,*)'C_dyn is recalculating'
write(6,*)'##############################'
endif
! call allocate_les_tmp
! Filter |S| and store in S_2BAR
DO J=0,NY+1
DO K=0,NZ+1
DO I=0,NXP
S_2BAR(I,K,J)=S2X(I,K,J)
END DO
END DO
END DO
! Test filtering operation filter type = 2
S1X = S_2BAR
call FILTER_VAR(2)
S_2BAR=S1X
! call les_filter_chan(S_2BAR,0,NY+1,2)
! Save a copy of the velocity which will be filtered twice more
if (les_model_type.eq.3) then
! Do only if a scale similar part is needed
do ij=1,3
do j=0,NY+1
do k=0,NZ+1
do i=0,NXP
U_4BAR(i,k,j,ij)=U_BAR_TIL(i,k,j,ij)
end do
end do
end do
end do
do i=1,3
! application of test and bar filter togather i.e. two filtering
! operation first filter type = 1, second filter type = 2
S1X = U_4BAR(:,:,:,i)
call FILTER_VAR(1)
call FILTER_VAR(2)
U_4BAR(:,:,:,i)=S1X
! call les_filter_chan(U_4BAR(0,0,0,i),0,NY+1,1)
! call les_filter_chan(U_4BAR(0,0,0,i),0,NY+1,2)
end do
end if
! Zero C_DYN
do j=0,NY+1
do k=0,NZ+1
C_DYN(k,j)=0.d0
end do
end do
! The prep. work is now done, we are ready to start the algorithm to compute
! the dynamic model coefficient
DO j =0,NY+1
DO k =0,NZ+1
denominator_sum(k,j) = 0.d0
numerator_sum(k,j) = 0.d0
ENDDO
ENDDO
if (rank.eq.0)then
write(6,*) 'I am here 1', rank
endif
! Do over all non-repeating components of the stress tensor
do ij=1,6
! Here ij=1 -> l=1,m=1
! ij=2 -> l=2,m=2
! ij=3 -> l=3,m=3
! ij=4 -> l=1,m=2
! ij=5 -> l=1,m=3
! ij=6 -> l=2,m=3
! Zero the numerator and denominator:
do j=0,NY+1
do k=0,NZ+1
do i=0,NXP
numerator(i,k,j)=0.d0
denominator(i,k,j)=0.d0
end do
end do
end do
! cross is used to multiply by two to include the contribution from the
! other symmetric term if we are dealing with a cross-term
if (ij.le.3) then
! We are computing a diagonal term
cross=1.d0
else
! We are computing a cross term
cross=2.d0
end if
! First, compute Mij
do j=0,NY+1
do k=0,NZ+1
do i=0,NXP
! Sij is defined at GYF points, no interpolation needed
temp(i,k,j)=Sij(i,k,j,ij)
end do
end do
end do
! Filter temp test filter operation filter type = 2
S1X = temp
call FILTER_VAR(2)
temp=S1X
! call les_filter_chan(temp,0,NY+1,2)
! Multiply by |S| filtered
do j=0,NY+1
do k=0,NZ+1
do i=0,NXP
temp(i,k,j)=temp(i,k,j)*(alpha*DELTA_Y(k,j))**2.d0 &
*S_2BAR(i,k,j)
end do
end do
end do
! Sij is used for Mij
do j=0,NY+1
do i=0,NXP
do k=0,NZ+1
Mij(i,k,j)=DELTA_Y(k,j)**2.d0*S2X(i,k,j)*Sij(i,k,j,ij)
end do
end do
end do
! Filter Mij test filter operation filter type = 2
S1X = Mij
call FILTER_VAR(2)
Mij=S1X
! call les_filter_chan(Mij,0,NY+1,2)
! Add the second term of Mij stored in temp
do j=0,NY+1
do k=0,NZ+1
do i=0,NXP
Mij(i,k,j)=temp(i,k,j)-Mij(i,k,j)
end do
end do
end do
! Now, compute Lij and add Lij*Mij to the numerator
! temp=Ui*Uj:
temp(:,:,:) = 0.0d0 ;
SELECT CASE (ij)
CASE(1)
do j=0,NY+1
do k=0,NZ+1
do i=0,NXP
temp(i,k,j)=U1X(i,k,j)*U1X(i,k,j)
end do
end do
end do
CASE(2)
do j=jstart,jend
do k=0,NZ+1
do i=0,NXP
temp(i,k,j)=0.250d0*(U2X(i,k,j+1)+U2X(i,k,j))**2.0d0
end do
end do
end do
CASE(3)
do j=0,NY+1
do k=zstart,zend
do i=0,NXP
temp(i,k,j)=0.250d0*(U3X(i,k+1,j)+U3X(i,k,j))**2.0d0
end do
end do
end do
CASE(4)
do j=jstart,jend
do k=0,NZ+1
do i=0,NXP
temp(i,k,j)=U1X(i,k,j)*0.50d0*(U2X(i,k,j+1)+U2X(i,k,j))
end do
end do
end do
CASE(5)
do j=0,NY+1
do k=zstart,zend
do i=0,NXP
temp(i,k,j)=U1X(i,k,j)*0.50d0*(U3X(i,k+1,j)+U3X(i,k,j))
end do
end do
end do
CASE(6)
do j=jstart,jend
do k=zstart,zend
do i=0,NXP
temp(i,k,j)=0.50d0*(U2X(i,k,j+1)+U2X(i,k,j))*0.50d0*(U3X(i,k+1,j)+U3X(i,k,j))
end do
end do
end do
!end select
END SELECT
! if (rank.eq.0)then
! write(6,*) 'I am here 1.1', rank
! endif
do k=0,NZ+1
do i=0,NXP
do j=0,NY+1
temp_1(i,k,j) = temp(i,k,j)
end do
end do
end do
! Filter temp: test filter operation i.e. filter type = 2
S1X = temp
call FILTER_VAR(2)
temp=S1X
! call les_filter_chan(temp,0,NY+1,2)
! Add Lij*Mij to numerator
do j=0,NY+1
do k=0,NZ+1
do i=0,NXP
numerator(i,k,j)=Mij(i,k,j) &
*(temp(i,k,j) &
-U_BAR_TIL(i,k,j,U_index1(ij))*U_BAR_TIL(i,k,j,U_index2(ij)))
end do
end do
end do
if (LES_MODEL_TYPE.eq.3) then
end if
! Now, the denominator for this ij
do j=0,NY+1
do k=0,NZ+1
do i=0,NXP
denominator(i,k,j)=Mij(i,k,j)*Mij(i,k,j)
end do
end do
end do
DO j=0,NY+1
do k=0,NZ+1
denominator_sum(k,j) = denominator_sum(k,j) + &
cross*SUM(denominator(0:min(NXP,NXP_L),k,j))
numerator_sum(k,j) = numerator_sum(k,j) + &
cross*SUM(numerator(0:min(NXP,NXP_L),k,j))
ENDDO
ENDDO
! if (rank.eq.0)then
! write(6,*) 'I am here 1.2', rank
! endif
! End to ij
end do
CALL MPI_COMBINE_STATS(denominator_sum,NZ+2,NY+2)
CALL MPI_COMBINE_STATS(numerator_sum,NZ+2,NY+2)
! if (rank.eq.0)then
! write(6,*) 'I am here 2', rank
! endif
! Get plane average of numerator and denominator, add to C
! Note, since both the numerator and denominator are averaged, there
! is not need to divide the sum by NX*NZ
do j=jstart,jend
do k=zstart,zend
if (denominator_sum(k,j).ne.0.) then
C_DYN(k,j) =-0.5d0* numerator_sum(k,j)/denominator_sum(k,j)
else
C_DYN(k,j)=0.d0
end if
end do
end do
! We are now done with the dynamic procedure to calculate C
! If C_DYN < 0 at any level, set C_DYN=0 for numerical stability
do j=0,NY+1
do k=0,NZ+1
if (C_DYN(k,j).lt.0) C_DYN(k,j)=0.d0
damp_fact(k) = 1.0 - sqrt(0.5*(1.0**2.0- 0.d0**2.0)*tanh((GZ(k)-0.6)/0.015) + 0.5*(1.0d0**2.0 + 0.0d0**2.0)) ;
C_DYN(k,j) = C_DYN(k,j)*damp_fact(k)
end do
end do
! At this point we have C_DYN and Sij
CALL MPI_BCAST_REAL(C_DYN, NZ+2, NY+2)
! End if compute C_DYN
! call deallocate_les_tmp
END IF
! Get the eddy viscosity at cell centered points
! NU_T = C_DYN * (DELTA^2)*|S|
! DO J=J1,J2
DO J=JSTART,JEND
DO K=ZSTART,ZEND
DO I=0,NXP
NU_T(I,K,J)=C_DYN(k,j)*DELTA_Y(k,j)**2.d0*S2X(i,k,j)
END DO
END DO
END DO
! Calculate TAUij in physical space, stored in Sij
do ij=1,6
if (LES_MODEL_TYPE.eq.2) then
! Dynamic Smagorinsky model, no scale similar part
if ( ij.eq.1 ) then
! Here, Sij is defined at GYF points
do j=1,NY+1
do k=1,NZ+1
do i=0,NXP
Sij(i,k,j,ij)= &
-2.d0*C_DYN(k,j)*DELTA_Y(k,j)**2.d0*S2X(i,k,j)*Sij(i,k,j,ij)
end do
end do
end do
else if (ij.eq.2) then
! Sij(:,:,:,2) = du2/dy, but this term will be added implicitly through
! an eddy viscosity, so set it equal to zero here
do j=1,NY+1
do k=1,NZ+1
do i=0,NXP
Sij(i,k,j,ij)=0.d0
end do
end do
end do
else if (ij.eq.3) then
! Sij(:,:,:,3) = du3/dz, but this term will be added implicitly through
! an eddy viscosity, so set it equal to zero here
do j=0,NY+1
do k=1,NZ+1
do i=0,NXP
Sij(i,k,j,ij)=0.d0
end do
end do
end do
else if (ij.eq.4) then
! Here, Sij is defined at GY points, interpolate C_DYN, etc
! Use exact second order interpolation
! Sij(:,:,:,4)=0.5*(dU1/dy + dU2/dx)
! But dU1/dy will be accounted for as an implicit eddy viscosity term,
! So, subtract if off from Sij here
do j=JSTART,JEND
do k=ZSTART,ZEND
do i=0,NXP
temp_1(i,k,j)=-2.d0 &
*C_DYN(k,j)*DELTA_Y(k,j)**2.d0*S2X(i,k,j)*Sij(i,k,j,ij)
Sij(i,k,j,ij)=-2.d0 &
*C_DYN(k,j)*DELTA_Y(k,j)**2.d0*S2X(i,k,j)*(Sij(i,k,j,ij)- &
0.50d0*(U1X(I,K,J+1) - U1X(I,K,J-1)) /(2.0d0*DYF(J)) )
end do
end do
end do
else if (ij.eq.5) then
! Here, Sij is defined at GY points, interpolate C_DYN, etc
! Use exact second order interpolation
! Sij(:,:,:,5)=0.5*(dU1/dz + dU3/dx)
! But dU1/dz will be accounted for as an implicit eddy viscosity term,
! So, subtract it off from Sij here
do j=JSTART,JEND
do k=ZSTART,ZEND
do i=0,NXP
temp_2(i,k,j)=-2.d0 &
*C_DYN(k,j)*DELTA_Y(k,j)**2.d0*S2X(i,k,j)*Sij(i,k,j,ij)
Sij(i,k,j,ij)=-2.d0 &
*C_DYN(k,j)*DELTA_Y(k,j)**2.d0*S2X(i,k,j)*(Sij(i,k,j,ij)- &
0.50d0*(U1X(I,K+1,J) - U1X(I,K-1,J)) /(2.0d0*DZF(K)) )
end do
end do
end do
else if (ij.eq.6) then
! Here, Sij is defined at GY points, interpolate C_DYN, etc
! Use exact second order interpolation
! Sij(:,:,:,6)=0.5*(dU3/dy + dU2/dz)
! But dU3/dy as well as dU2/dz will be accounted for as an implicit eddy viscosity term,
! So, subtract it off from Sij here
do j=JSTART,JEND
do k=ZSTART,ZEND
do i=0,NXP
temp_3(i,k,j)=-2.d0 &
*C_DYN(k,j) *DELTA_Y(k,j)**2.d0*S2X(i,k,j)*(Sij(i,k,j,ij)- &
0.5*( 0.5*(U3X(I,K+1,J+1) + U3X(I,K,J+1) &
- U3X(I,K+1,J-1) - U3X(I,K,J-1) )/(2.0d0*DYF(j)) ))
Sij(i,k,j,ij)=-2.d0 &
*C_DYN(k,j)*DELTA_Y(k,j)**2.d0*S2X(i,k,j)*(Sij(i,k,j,ij)- &
0.5*( 0.5*(U2X(I,K+1,J+1) + U2X(I,K+1,J) &
- U2X(I,K-1,J+1) - U2X(I,K-1,J) )/(2.0d0*DZF(K))) )
end do
end do
end do
do k=0,NZ+1
do i=0,NXP
temp_3(i,k,NY+1) = temp_3(i,k,NY)
temp_3(i,k,0) = temp_3(i,k,1)
end do
end do
do j=0,NY+1
do i=0,NXP
temp_3(i,NZ+1,j) = temp_3(i,NZ,j)
temp_3(i,0,j) = temp_3(i,1,j)
end do
end do
! End if ij
end if
! EXTRAPOLATING VALUES
do k=0,NZ+1
do i=0,NXP
Sij(i,k,NY+1,ij)=Sij(i,k,NY,ij)
Sij(i,k,0,ij)=Sij(i,k,1,ij)
end do
end do
do j=0,NY+1
do i=0,NXP
Sij(i,NZ+1,j,ij)=Sij(i,NZ,j,ij)
Sij(i,0,j,ij)=Sij(i,1,j,ij)
end do
end do
else if (LES_MODEL_TYPE.eq.3) then
! Model type = 3, dynamic mixed model with scale similar part
! Always define temp at GYF points to match U_2BAR
! temp=Ui*Uj:
! End if Mixed Model
end if
!write(6,*) 'I am here 1', rank, ij
! Convert TAUij, now stored in Sij to Fourier space
S1X=Sij(:,:,:,ij)
CALL MPI_TRANSPOSE_REAL_X_TO_Z(S1X,S1Z)
varp(:,:,:) = 0.d0
DO I=0,NXM
varp(I,:,:)=S1Z(I,:,:)
ENDDO
CALL FFT_X_TO_FOURIER_OP(varp,cvarp,0,NY+1,0,NZP)
DO I=0,NKX
CS1Z(I,:,:)=cvarp(I,:,:)
ENDDO
CS1Z(NKX+1:NX2V-1,:,:)=(0.0,0.0)
CALL MPI_TRANSPOSE_COMPLEX_Z_TO_X(CS1Z,CS1X)
CSij(:,:,:,ij)=CS1X
! call FFT_X_TO_FOURIER(Sij(0,0,0,ij),CSij(0,0,0,ij),0,NY+1,0,NZ+1)
! End do ij
end do
! Convert TAUij, now stored in Sij to Fourier space (for only u momentum equation)
S1X=temp_1
CALL MPI_TRANSPOSE_REAL_X_TO_Z(S1X,S1Z)
varp(:,:,:) = 0.d0
DO I=0,NXM
varp(I,:,:)=S1Z(I,:,:)
ENDDO
CALL FFT_X_TO_FOURIER_OP(varp,cvarp,0,NY+1,0,NZP)
DO I=0,NKX
CS1Z(I,:,:)=cvarp(I,:,:)
ENDDO
CS1Z(NKX+1:NX2V-1,:,:)=(0.0,0.0)
CALL MPI_TRANSPOSE_COMPLEX_Z_TO_X(CS1Z,CS1X)
Ctemp_1=CS1X
S1X=temp_2
CALL MPI_TRANSPOSE_REAL_X_TO_Z(S1X,S1Z)
varp(:,:,:) = 0.d0
DO I=0,NXM
varp(I,:,:)=S1Z(I,:,:)
ENDDO
CALL FFT_X_TO_FOURIER_OP(varp,cvarp,0,NY+1,0,NZP)
DO I=0,NKX
CS1Z(I,:,:)=cvarp(I,:,:)
ENDDO
CS1Z(NKX+1:NX2V-1,:,:)=(0.0,0.0)
CALL MPI_TRANSPOSE_COMPLEX_Z_TO_X(CS1Z,CS1X)
Ctemp_2=CS1X
S1X=temp_3
CALL MPI_TRANSPOSE_REAL_X_TO_Z(S1X,S1Z)
varp(:,:,:) = 0.d0
DO I=0,NXM
varp(I,:,:)=S1Z(I,:,:)
ENDDO
CALL FFT_X_TO_FOURIER_OP(varp,cvarp,0,NY+1,0,NZP)
DO I=0,NKX
CS1Z(I,:,:)=cvarp(I,:,:)
ENDDO
CS1Z(NKX+1:NX2V-1,:,:)=(0.0,0.0)
CALL MPI_TRANSPOSE_COMPLEX_Z_TO_X(CS1Z,CS1X)
Ctemp_3=CS1X
! call FFT_X_TO_FOURIER(temp_1,ctemp_1,0,NY+1,0,NZ+1)
! call FFT_X_TO_FOURIER(temp_2,ctemp_2,0,NY+1,0,NZ+1)
! call FFT_X_TO_FOURIER(s2,cs2,0,NY+1,0,NZ+1)
! End if LES_MODEL_TYPE dynamic Smagorinsky or Dynamic mixed model
else
stop
write(6,*) 'Error, unsupported LES_MODEL_TYPE chosen'
end if
! Now, add the subgrid scale forcing to CFi
! (This includes the subgrid scale stress as an explicit R-K term
!If ()
! write(6,*) 'Adding LES', rank
IF (ADD_LES) THEN
IF (LES_IMPLICIT) THEN
DO J=JSTART,JEND
DO K=ZSTART,ZEND
DO I=0,NX2P
CF1X(I,K,J)=CF1X(I,K,J) &
- CIKXP(I)*CSij(I,K,J,1) &
- (CSij(I,K,J+1,4) - CSij(I,K,J-1,4))/(2.0d0*DYF(J)) &
- (CSij(I,K+1,J,5) - CSij(I,K-1,J,5))/(2.0d0*DZF(K))
CF2X(I,K,J)=CF2X(I,K,J) &
- CIKXP(I)*Ctemp_1(i,k,j) &
- (CSij(I,K,J+1,2) - CSij(I,K,J,2))/DY(J) &
-0.5*(CSij(I,K+1,J,6) + CSij(I,K+1,J-1,6) &
- CSij(I,K-1,J,6) - CSij(I,K-1,J-1,6))/(2.0d0*DZ(K))
CF3X(I,K,J)=CF3X(I,K,J) &
- CIKXP(I)*Ctemp_2(i,k,j) &
- 0.5*(Ctemp_3(I,K,J+1) + Ctemp_3(I,K-1,J+1) &
- Ctemp_3(I,K,J-1) - Ctemp_3(I,K-1,J-1) )/(2.0d0*DY(J)) &
- (CSij(I,K,J,3) - CSij(I,K-1,J,3))/DZ(K)
END DO
END DO
END DO
ELSE
ENDIF
ENDIF
! Periodically, output mean quantities
IF ((MOD(TIME_STEP,SAVE_STATS_INT).EQ.0).AND.(RK_STEP.EQ.1)) THEN
! Get plane averages
! allocate (tke_sgs_t(0:NZ+1,0:NY+1))