This repository has been archived by the owner on Nov 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
navier.f90
3148 lines (2693 loc) · 97.1 KB
/
navier.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
!################################################################################
!This file is part of Incompact3d.
!
!Incompact3d
!Copyright (c) 2012 Eric Lamballais and Sylvain Laizet
!
! Incompact3d is free software: you can redistribute it and/or modify
! it under the terms of the GNU General Public License as published by
! the Free Software Foundation.
!
! Incompact3d is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! GNU General Public License for more details.
!
! You should have received a copy of the GNU General Public License
! along with the code. If not, see <http://www.gnu.org/licenses/>.
!-------------------------------------------------------------------------------
!-------------------------------------------------------------------------------
! We kindly request that you cite Incompact3d in your publications and
! presentations. The following citations are suggested:
!
! 1-Laizet S. & Lamballais E., 2009, High-order compact schemes for
! incompressible flows: a simple and efficient method with the quasi-spectral
! accuracy, J. Comp. Phys., vol 228 (15), pp 5989-6015
!
! 2-Laizet S. & Li N., 2011, Incompact3d: a powerful tool to tackle turbulence
! problems with up to 0(10^5) computational cores, Int. J. of Numerical
! Methods in Fluids, vol 67 (11), pp 1735-1757
!################################################################################
!********************************************************************
!
!
!********************************************************************
subroutine intt (ux,uy,uz,gx,gy,gz,hx,hy,hz,ta1,tb1,tc1,rho)
USE param
USE variables
USE decomp_2d
implicit none
integer :: ijk,nxyz
real(mytype),dimension(xsize(1),xsize(2),xsize(3)) :: ux,uy,uz
real(mytype),dimension(xsize(1),xsize(2),xsize(3)) :: rho
real(mytype),dimension(xsize(1),xsize(2),xsize(3)) :: gx,gy,gz
real(mytype),dimension(xsize(1),xsize(2),xsize(3)) :: hx,hy,hz
real(mytype),dimension(xsize(1),xsize(2),xsize(3)) :: ta1,tb1,tc1
nxyz=xsize(1)*xsize(2)*xsize(3)
if (ilmn.ne.0) then
!! First, convert velocity to momentum
if (iskew.ne.2) then
!! Rotational form or Quasi skew-symmetric
do ijk = 1, nxyz
ux(ijk, 1, 1) = rho(ijk, 1, 1) * ux(ijk, 1, 1)
uy(ijk, 1, 1) = rho(ijk, 1, 1) * uy(ijk, 1, 1)
uz(ijk, 1, 1) = rho(ijk, 1, 1) * uz(ijk, 1, 1)
enddo
else
!! Skew-symmetric
ux(:,:,:) = SQRT(rho(:,:,:)) * ux(:,:,:)
uy(:,:,:) = SQRT(rho(:,:,:)) * uy(:,:,:)
uz(:,:,:) = SQRT(rho(:,:,:)) * uz(:,:,:)
endif
endif
if ((nscheme.eq.1).or.(nscheme.eq.2)) then
!! AB2 or RK3
if ((nscheme.eq.1.and.itime.eq.1.and.ilit.eq.0).or.&
(nscheme.eq.2.and.itr.eq.1)) then
do ijk=1,nxyz
ux(ijk,1,1)=gdt(itr)*ta1(ijk,1,1)+ux(ijk,1,1)
uy(ijk,1,1)=gdt(itr)*tb1(ijk,1,1)+uy(ijk,1,1)
uz(ijk,1,1)=gdt(itr)*tc1(ijk,1,1)+uz(ijk,1,1)
gx(ijk,1,1)=ta1(ijk,1,1)
gy(ijk,1,1)=tb1(ijk,1,1)
gz(ijk,1,1)=tc1(ijk,1,1)
enddo
else
if (nz.gt.1) then
do ijk=1,nxyz
ux(ijk,1,1)=adt(itr)*ta1(ijk,1,1)+bdt(itr)*gx(ijk,1,1)+ux(ijk,1,1)
uy(ijk,1,1)=adt(itr)*tb1(ijk,1,1)+bdt(itr)*gy(ijk,1,1)+uy(ijk,1,1)
uz(ijk,1,1)=adt(itr)*tc1(ijk,1,1)+bdt(itr)*gz(ijk,1,1)+uz(ijk,1,1)
gx(ijk,1,1)=ta1(ijk,1,1)
gy(ijk,1,1)=tb1(ijk,1,1)
gz(ijk,1,1)=tc1(ijk,1,1)
enddo
else !! End is 3D
do ijk=1,nxyz
ux(ijk,1,1)=adt(itr)*ta1(ijk,1,1)+bdt(itr)*gx(ijk,1,1)+ux(ijk,1,1)
uy(ijk,1,1)=adt(itr)*tb1(ijk,1,1)+bdt(itr)*gy(ijk,1,1)+uy(ijk,1,1)
gx(ijk,1,1)=ta1(ijk,1,1)
gy(ijk,1,1)=tb1(ijk,1,1)
enddo
endif !! End is 2D
endif
else if (nscheme.eq.3) then
if (nz.gt.1) then
! if (adt(itr)==0._mytype) then
if (itr.eq.0) then ! XXX The above double comparison is only true for itr=0
do ijk=1,nxyz
gx(ijk,1,1)=dt*ta1(ijk,1,1)
gy(ijk,1,1)=dt*tb1(ijk,1,1)
gz(ijk,1,1)=dt*tc1(ijk,1,1)
enddo
else
do ijk=1,nxyz
gx(ijk,1,1)=adt(itr)*gx(ijk,1,1)+dt*ta1(ijk,1,1)
gy(ijk,1,1)=adt(itr)*gy(ijk,1,1)+dt*tb1(ijk,1,1)
gz(ijk,1,1)=adt(itr)*gz(ijk,1,1)+dt*tc1(ijk,1,1)
enddo
endif
do ijk=1,nxyz
ux(ijk,1,1)=ux(ijk,1,1)+bdt(itr)*gx(ijk,1,1)
uy(ijk,1,1)=uy(ijk,1,1)+bdt(itr)*gy(ijk,1,1)
uz(ijk,1,1)=uz(ijk,1,1)+bdt(itr)*gz(ijk,1,1)
enddo
else
! if (adt(itr)==0._mytype) then
if (itr.eq.0) then
do ijk=1,nxyz
gx(ijk,1,1)=dt*ta1(ijk,1,1)
gy(ijk,1,1)=dt*tb1(ijk,1,1)
enddo
else
do ijk=1,nxyz
gx(ijk,1,1)=adt(itr)*gx(ijk,1,1)+dt*ta1(ijk,1,1)
gy(ijk,1,1)=adt(itr)*gy(ijk,1,1)+dt*tb1(ijk,1,1)
enddo
endif
do ijk=1,nxyz
ux(ijk,1,1)=ux(ijk,1,1)+bdt(itr)*gx(ijk,1,1)
uy(ijk,1,1)=uy(ijk,1,1)+bdt(itr)*gy(ijk,1,1)
enddo
endif
else if (nscheme==4) then
if ((itime.eq.1).and.(ilit.eq.0)) then
if (nrank==0) then
print *,'start with Euler',itime
endif
do ijk=1,nxyz !start with Euler
ux(ijk,1,1)=dt*ta1(ijk,1,1)+ux(ijk,1,1)
uy(ijk,1,1)=dt*tb1(ijk,1,1)+uy(ijk,1,1)
uz(ijk,1,1)=dt*tc1(ijk,1,1)+uz(ijk,1,1)
gx(ijk,1,1)=ta1(ijk,1,1)
gy(ijk,1,1)=tb1(ijk,1,1)
gz(ijk,1,1)=tc1(ijk,1,1)
enddo
else
if ((itime.eq.2).and.(ilit.eq.0)) then
if (nrank==0) then
print *,'then with AB2',itime
endif
do ijk=1,nxyz
ux(ijk,1,1)=1.5_mytype*dt*ta1(ijk,1,1)-0.5_mytype*dt*gx(ijk,1,1)+ux(ijk,1,1)
uy(ijk,1,1)=1.5_mytype*dt*tb1(ijk,1,1)-0.5_mytype*dt*gy(ijk,1,1)+uy(ijk,1,1)
uz(ijk,1,1)=1.5_mytype*dt*tc1(ijk,1,1)-0.5_mytype*dt*gz(ijk,1,1)+uz(ijk,1,1)
hx(ijk,1,1)=gx(ijk,1,1)
hy(ijk,1,1)=gy(ijk,1,1)
hz(ijk,1,1)=gz(ijk,1,1)
gx(ijk,1,1)=ta1(ijk,1,1)
gy(ijk,1,1)=tb1(ijk,1,1)
gz(ijk,1,1)=tc1(ijk,1,1)
enddo
else
do ijk=1,nxyz
ux(ijk,1,1)=adt(itr)*ta1(ijk,1,1)+bdt(itr)*gx(ijk,1,1)+&
cdt(itr)*hx(ijk,1,1)+ux(ijk,1,1)
uy(ijk,1,1)=adt(itr)*tb1(ijk,1,1)+bdt(itr)*gy(ijk,1,1)+&
cdt(itr)*hy(ijk,1,1)+uy(ijk,1,1)
uz(ijk,1,1)=adt(itr)*tc1(ijk,1,1)+bdt(itr)*gz(ijk,1,1)+&
cdt(itr)*hz(ijk,1,1)+uz(ijk,1,1)
hx(ijk,1,1)=gx(ijk,1,1)
hy(ijk,1,1)=gy(ijk,1,1)
hz(ijk,1,1)=gz(ijk,1,1)
gx(ijk,1,1)=ta1(ijk,1,1)
gy(ijk,1,1)=tb1(ijk,1,1)
gz(ijk,1,1)=tc1(ijk,1,1)
enddo
endif
endif
endif
return
end subroutine intt
!********************************************************************
!********************************************************************
SUBROUTINE inttdensity(rho1, rhos1, rhoss1, rhos01, tg1, drhodt1)
USE param
USE variables
USE decomp_2d
IMPLICIT NONE
REAL(mytype), DIMENSION(xsize(1), xsize(2), xsize(3)), INTENT(IN) :: tg1
REAL(mytype), DIMENSION(xsize(1), xsize(2), xsize(3)), INTENT(OUT) :: rhos01, drhodt1
REAL(mytype), DIMENSION(xsize(1), xsize(2), xsize(3)), INTENT(INOUT) :: rho1, rhos1, rhoss1
REAL(mytype) :: udenslim, ldenslim
INTEGER :: ijk, nxyz
nxyz = xsize(1) * xsize(2) * xsize(3)
IF ((nscheme.EQ.1).OR.(nscheme.EQ.2)) THEN
!! AB2 or RK3
! First store -rho1 in drhodt1 incase we use simple extrapolation
drhodt1(:,:,:) = -rho1(:,:,:)
IF (nscheme.EQ.1) THEN
!! AB2
rhos01(:,:,:) = rhoss1(:,:,:)
rhoss1(:,:,:) = rho1(:,:,:)
ENDIF
IF ((nscheme.EQ.1.AND.itime.EQ.1.AND.ilit.EQ.0).OR.&
(nscheme.EQ.2.AND.itr.EQ.1)) THEN
rho1(:,:,:) = rho1(:,:,:) + gdt(itr) * tg1(:,:,:)
IF (nscheme.EQ.2) THEN
!! RK3
rhos01(:,:,:) = rhoss1(:,:,:)
rhoss1(:,:,:) = tg1(:,:,:)
ENDIF
ELSE
rho1(:,:,:) = rho1(:,:,:) + adt(itr) * tg1(:,:,:) &
+ bdt(itr) * rhos1(:,:,:)
ENDIF
ELSE IF (nscheme.EQ.3) THEN
!! RK4
!! XXX Not implemented!
IF (nrank.EQ.0) THEN
PRINT *, 'LMN: RK4 not ready'
ENDIF
STOP
ELSE
!! AB3
IF ((itime.EQ.1).AND.(ilit.EQ.0)) THEN
IF (nrank.EQ.0) THEN
PRINT *, 'start with Euler', itime
ENDIF
rho1(:,:,:) = rho1(:,:,:) + dt * tg1(:,:,:)
ELSE
IF ((itime.EQ.2).AND.(ilit.EQ.0)) THEN
IF (nrank.EQ.0) THEN
PRINT *, 'then with AB2', itime
ENDIF
rho1(:,:,:) = rho1(:,:,:) - 0.5_mytype * dt * (rhos1(:,:,:) - 3._mytype * tg1(:,:,:))
ELSE
rho1(:,:,:) = rho1(:,:,:) + adt(itr) * tg1(:,:,:) + bdt(itr) * rhos1(:,:,:) + cdt(itr) &
* rhoss1(:,:,:)
ENDIF
!! Update oldold stage
rhoss1(:,:,:) = rhos1(:,:,:)
ENDIF
ENDIF
!! Update old stage
rhos1(:,:,:) = tg1(:,:,:)
!! Limiting
CALL test_density_min_max(rho1)
udenslim = MAX(dens1, dens2)
ldenslim = MIN(dens1, dens2)
DO ijk = 1, nxyz
rho1(ijk, 1, 1) = MAX(rho1(ijk, 1, 1), ldenslim)
rho1(ijk, 1, 1) = MIN(rho1(ijk, 1, 1), udenslim)
ENDDO
ENDSUBROUTINE inttdensity
!********************************************************************
!********************************************************************
SUBROUTINE eval_densitycoeffs(rho1, temperature1, ta1, rhos1, rhoss1, rhos01, drhodt1)
USE param
USE variables
USE decomp_2d
IMPLICIT NONE
REAL(mytype), DIMENSION(xsize(1), xsize(2), xsize(3)), INTENT(IN) :: rho1, temperature1, ta1
REAL(mytype), DIMENSION(xsize(1), xsize(2), xsize(3)) :: rhos1, rhoss1
REAL(mytype), DIMENSION(xsize(1), xsize(2), xsize(3)) :: rhos01, drhodt1
INTEGER :: ijk, nxyz
nxyz = xsize(1) * xsize(2) * xsize(3)
IF ((nscheme.EQ.1).OR.(nscheme.EQ.2)) THEN
!! AB2 or RK3
! First store -rho1 in drhodt1 incase we use simple extrapolation
drhodt1(:,:,:) = -rho1(:,:,:)
IF (nscheme.EQ.1) THEN
!! AB2
rhos01(:,:,:) = rhoss1(:,:,:)
rhoss1(:,:,:) = rho1(:,:,:)
ELSE IF (itr.EQ.1) THEN
!! RK3, first iteration
rhos01(:,:,:) = rhoss1(:,:,:)
rhoss1(:,:,:) = -(temperature1(:,:,:) / rho1(:,:,:)) * ta1(:,:,:)
ENDIF
ELSE IF (nscheme.EQ.3) THEN
!! RK4
!! XXX Not implemented!
IF (nrank.EQ.0) THEN
PRINT *, 'LMN: RK4 not ready'
STOP
ENDIF
ELSE
!! AB3
!! XXX Not implemented
IF (nrank.EQ.0) THEN
PRINT *, 'LMN: AB3 not ready'
STOP
ENDIF
ENDIF
!! Update old stage
rhos1(:,:,:) = -(temperature1(:,:,:) / rho1(:,:,:)) * ta1(:,:,:)
ENDSUBROUTINE eval_densitycoeffs
!********************************************************************
!********************************************************************
SUBROUTINE intttemperature(temperature1, temperatures1, temperaturess1, tg1)
USE param
USE variables
USE decomp_2d
IMPLICIT NONE
REAL(mytype), DIMENSION(xsize(1), xsize(2), xsize(3)), INTENT(IN) :: tg1
REAL(mytype), DIMENSION(xsize(1), xsize(2), xsize(3)) :: temperature1, temperatures1, temperaturess1
INTEGER :: ijk, nxyz
nxyz = xsize(1) * xsize(2) * xsize(3)
IF ((nscheme.EQ.1).OR.(nscheme.EQ.2)) THEN
!! AB2 or RK3
IF (((nscheme.EQ.1).AND.(itime.EQ.1).AND.(ilit.EQ.0)).OR.&
((nscheme.EQ.2).AND.(itr.EQ.1))) THEN
temperature1(:,:,:) = temperature1(:,:,:) + gdt(itr) * tg1(:,:,:)
ELSE
temperature1(:,:,:) = temperature1(:,:,:) + adt(itr) * tg1(:,:,:) &
+ bdt(itr) * temperatures1(:,:,:)
ENDIF
ELSE IF (nscheme.EQ.3) THEN
!! RK3
IF (nrank.EQ.0) THEN
PRINT *, "LMN: RK4 not ready!"
STOP
ENDIF
ELSE
!! AB3
IF ((itime.EQ.1).AND.(ilit.EQ.0)) THEN
IF (nrank.EQ.0) THEN
PRINT *, 'start with Euler', itime
ENDIF
temperature1(:,:,:) = temperature1(:,:,:) + dt * tg1(:,:,:)
ELSE
IF ((itime.EQ.2).AND.(ilit.EQ.0)) THEN
IF (nrank.EQ.0) THEN
PRINT *, 'then with AB2', itime
ENDIF
temperature1(:,:,:) = temperature1(:,:,:) - 0.5_mytype * dt &
* (temperatures1(:,:,:) - 3._mytype * tg1(:,:,:))
ELSE
temperature1(:,:,:) = temperature1(:,:,:) + adt(itr) * tg1(:,:,:) &
+ bdt(itr) * temperatures1(:,:,:) + cdt(itr) * temperaturess1(:,:,:)
ENDIF
!! Update oldold stage
temperaturess1(:,:,:) = temperatures1(:,:,:)
ENDIF
ENDIF
!! Update old stage
temperatures1(:,:,:) = tg1(:,:,:)
!! Limiting
CALL test_temperature_min_max(temperature1)
DO ijk = 1, nxyz
temperature1(ijk, 1, 1) = MAX(temperature1(ijk, 1, 1), 1._mytype)
temperature1(ijk, 1, 1) = MIN(temperature1(ijk, 1, 1), 1._mytype)
ENDDO
ENDSUBROUTINE intttemperature
!********************************************************************
!
!
!********************************************************************
subroutine corgp (ux,gx,uy,uz,px,py,pz,rho)
USE decomp_2d
USE variables
USE param
USE var
USE MPI
implicit none
integer :: ijk,nxyz
real(mytype),dimension(xsize(1),xsize(2),xsize(3)) :: ux,uy,uz,px,py,pz,rho
real(mytype),dimension(ysize(1),ysize(2),ysize(3)) :: gx
real(mytype) :: invrho
nxyz=xsize(1)*xsize(2)*xsize(3)
if (ilmn.ne.0) then
if (ivarcoeff.eq.0) then
!! We are solving constant-coefficient Poisson equation,
!! first convert momentum->velocity
if (iskew.ne.2) then
!! Rotational or quasi skew-symmetric
do ijk = 1, nxyz
invrho = 1._mytype / rho(ijk, 1, 1)
ux(ijk, 1, 1) = ux(ijk, 1, 1) * invrho
uy(ijk, 1, 1) = uy(ijk, 1, 1) * invrho
uz(ijk, 1, 1) = uz(ijk, 1, 1) * invrho
enddo
else
!! Skew-symmetric
do ijk = 1, nxyz
invrho = 1._mytype / SQRT(rho(ijk, 1, 1))
ux(ijk, 1, 1) = ux(ijk, 1, 1) * invrho
uy(ijk, 1, 1) = uy(ijk, 1, 1) * invrho
uz(ijk, 1, 1) = uz(ijk, 1, 1) * invrho
enddo
endif
endif
if (iskew.ne.2) then
!! Rotational or quasi skew-symmetric
do ijk=1, nxyz
invrho = 1._mytype / rho(ijk, 1, 1)
ux(ijk, 1, 1) = ux(ijk, 1, 1) - invrho * px(ijk, 1, 1)
uy(ijk, 1, 1) = uy(ijk, 1, 1) - invrho * py(ijk, 1, 1)
uz(ijk, 1, 1) = uz(ijk, 1, 1) - invrho * pz(ijk, 1, 1)
enddo
else
!! Skew-symmetric
do ijk = 1, nxyz
invrho = 1._mytype / SQRT(rho(ijk, 1, 1))
ux(ijk, 1, 1) = ux(ijk, 1, 1) - invrho * px(ijk, 1, 1)
uy(ijk, 1, 1) = uy(ijk, 1, 1) - invrho * py(ijk, 1, 1)
uz(ijk, 1, 1) = uz(ijk, 1, 1) - invrho * pz(ijk, 1, 1)
enddo
endif
else
ux(:,:,:) = -px(:,:,:) + ux(:,:,:)
uy(:,:,:) = -py(:,:,:) + uy(:,:,:)
uz(:,:,:) = -pz(:,:,:) + uz(:,:,:)
endif
if (itype==2) then !channel flow
call transpose_x_to_y(ux,gx)
call channel(gx)
call transpose_y_to_x(gx,ux)
endif
return
end subroutine corgp
!*********************************************************
!
!*********************************************************
subroutine inflow (ux, uy, uz, rho, temperature, massfrac, phi)
USE param
USE IBM
USE variables
USE decomp_2d
implicit none
integer :: k, j, n, nmodes
real(mytype), dimension(xsize(1), xsize(2), xsize(3)) :: ux, uy, uz, rho, temperature, phi, massfrac
real(mytype) :: r1, r2, r3, y, z, um, theta, freq, St, mf, s
call ecoule(ux, uy, uz, rho, temperature, massfrac)
call random_number(bxo)
call random_number(byo)
call random_number(bzo)
nmodes = 6
St = 0.3
freq = St * u1 / (1._mytype)
if (t.LT.1._mytype) then
s = SIN(t * (PI / 2._mytype))
else
s = 1._mytype
endif
if (iin.eq.1) then
do k = 1, xsize(3)
z = (k + xstart(3) - 2) * dz - zlz / 2._mytype
do j = 1, xsize(2)
y = (j + xstart(2) - 2) * dy - yly / 2._mytype
r1 = SQRT(y**2 + z**2)
if (r1.lt.0.5_mytype) then
mf = rho(1, j, k) * bxx1(j, k)
IF (z.GT.0._mytype) THEN
IF (y.GT.0._mytype) THEN
theta = ATAN(y / z)
ELSE IF (y.LT.0._mytype) THEN
theta = 2._mytype * PI - ATAN(-y / z)
ELSE
theta = 0._mytype
ENDIF
ELSE IF (z.LT.0._mytype) THEN
IF (y.GT.0._mytype) THEN
theta = PI - ATAN(y / (-z))
ELSE IF (y.LT.0._mytype) THEN
theta = PI + ATAN(y / z)
ELSE
theta = PI
ENDIF
ELSE
IF (y.GT.0._mytype) THEN
theta = 0.5_mytype * PI
ELSE IF (y.LT.0._mytype) THEN
theta = 1.5_mytype * PI
ELSE
theta = 0._mytype
ENDIF
ENDIF
!! Additional forcing
um = 0._mytype
DO n = 1, nmodes
um = um + SIN(2._mytype * PI * (t * freq) / (DBLE(n)) + theta)
ENDDO
um = 0.2_mytype * um / DBLE(nmodes)
IF (t.LT.1._mytype) THEN
um = um * SIN(t * (0.5_mytype * PI))
ENDIF
um = s * um
bxx1(j, k) = (1._mytype + um) * bxx1(j, k)
bxx1(j, k) = bxx1(j, k) + noise1 * (1._mytype - 2._mytype * bxo(j, k))
bxy1(j, k) = bxy1(j, k) + noise1 * (1._mytype - 2._mytype * byo(j, k))
bxz1(j, k) = bxz1(j, k) + noise1 * (1._mytype - 2._mytype * bzo(j, k))
bxx1(j, k) = MAX(bxx1(j, k), u2) ! Prevent backflow
! if ((mf * bxx1(j, k)).gt.0._mytype) then
! rho(1, j, k) = mf / bxx1(j, k)
! endif
endif ! End within jet
enddo
enddo
if (iscalar==1) then
do k = 1, xsize(3)
do j = 1, xsize(2)
phi(1, j, k) = 1._mytype
enddo
enddo
endif
endif
return
end subroutine inflow
!*********************************************************
!
!*********************************************************
subroutine outflow (ux, uy, uz, rho, temperature, massfrac, phi)
USE param
USE variables
USE decomp_2d
USE MPI
implicit none
integer :: j, k, i, code
real(mytype), dimension(xsize(1), xsize(2), xsize(3)) :: ux, uy, uz, rho, temperature, massfrac, phi
real(mytype) :: udx, udy, udz, uddx, uddy, uddz, uxmax, &
uxmin, vphase, coef, uxmax1, uxmin1, volflux, volflux_out
real(mytype), dimension(xsize(2), xsize(3)) :: cx
real(mytype) :: Ay
real(mytype) :: y, z, yc, zc
real(mytype) :: r2
real(mytype) :: ucf, g_umax, gauss
real(mytype) :: g_rext, g_rext2
!! Compute 'convective velocity' at outlet
udx = 1._mytype / dx
udy = 1._mytype / dy
udz = 1._mytype / dz
uddx = 0.5_mytype / dx
uddy = 0.5_mytype / dy
uddz = 0.5_mytype / dz
! ! If inlet velocity specified in terms of u1 and u2
! cx(:,:) = 0.5_mytype * (u1 + u2) * gdt(itr) * udx
! uxmax = -1609._mytype
! uxmin = 1609._mytype
! do k = 1, xsize(3)
! do j = 1, xsize(2)
! if (ux(nx - 1, j, k).gt.uxmax) uxmax = ux(nx - 1, j, k)
! if (ux(nx - 1, j, k).lt.uxmin) uxmin = ux(nx - 1, j, k)
! enddo
! enddo
! call MPI_ALLREDUCE(uxmax, uxmax1, 1, real_type, MPI_MAX, MPI_COMM_WORLD, code)
! call MPI_ALLREDUCE(uxmin, uxmin1, 1, real_type, MPI_MIN, MPI_COMM_WORLD, code)
! vphase = 0.5_mytype * (uxmax1 + uxmin1)
! cx(:,:) = vphase * gdt(itr) * udx
! ! Compute mean velocity (inlet)
! volflux = 0._mytype
! do k = 1, xsize(3)
! do j = 1, xsize(2) - 1
! if (istret.eq.0) then
! Ay = yly / (ny - 1)
! else
! Ay = (yp(j + 1) - yp(j))
! endif
! volflux = volflux + 0.5_mytype * (ux(1, j, k) + ux(1, j + 1, k)) * Ay * dz
! enddo
! enddo
! PRINT *, volflux
! call MPI_ALLREDUCE(MPI_IN_PLACE, volflux, 1, real_type, MPI_SUM, MPI_COMM_WORLD, code)
! volflux = volflux / (yly * zlz)
! cx(:,:) = volflux * gdt(itr) * udx
!! Gaussian outflow (to balance inlet mass flux)
g_rext = 1.5_mytype / 2.14_mytype ! 2.14 is the magic number of (r/R) giving e^(-r**2 / R**2) = 0.01
g_rext2 = g_rext**2
g_umax = 1._mytype ! We will calculate this later to balance mass flux
yc = 0.5_mytype * yly
zc = 0.5_mytype * zlz
if (ilmn.ne.0) then
volflux = outflux ! The required outflux, computed by compute_outflux_lmn
else
volflux = u2 * (yly * zlz)
volflux = volflux + (u1 - u2) * (PI * (0.5_mytype**2))
endif
! volflux_out = 0._mytype
! ucf = 0.1_mytype * u1 * (PI * 0.5_mytype**2) / (yly * zlz)
! DO k = 1, nz
! z = DBLE(k - 1) * dz - zc
! DO j = 1, ny
! y = DBLE(j - 1) * dy - yc
! r2 = y**2 + z**2
! gauss = g_umax * EXP(-r2 / g_rext2) + ucf
! volflux_out = volflux_out + gauss * dy * dz
! ENDDO
! ENDDO
! bxxn_scale = volflux / volflux_out
! DO k = 1, xsize(3)
! z = DBLE(k + xstart(3) - 2) * dz - zc
! DO j = 1, xsize(2)
! y = DBLE(j + xstart(2) - 2) * dy - yc
! r2 = y**2 + z**2
! gauss = bxxn_scale * (g_umax * EXP(-r2 / g_rext2) + ucf)
! cx(j, k) = gauss * (gdt(itr) * udx)
! ENDDO
! ENDDO
!! Set average outflux
volflux = volflux / (xlx * yly)
DO k = 1, xsize(3)
DO j = 1, xsize(2)
cx(j, k) = volflux * (gdt(itr) * udx)
ENDDO
ENDDO
! volflux = u1 * (PI * 0.5_mytype**2) / (yly * zlz)
! cx(:,:) = volflux * gdt(itr) * udx
! !! Volume correction
! volflux = 0._mytype
! DO k = 1, xsize(3)
! DO j = 1, xsize(2) - 1
! IF (istret.EQ.0) THEN
! Ay = yly / (ny - 1)
! ELSE
! Ay = (yp(j + 1) - yp(j))
! ENDIF
! volflux = volflux + 0.5_mytype * (bxx1(j, k) + bxx1(j + 1, k)) * Ay * dz * gdt(itr) * udx
! volflux = volflux - 0.5_mytype * (cx(j, k) + cx(j + 1, k)) * Ay * dz
! ENDDO
! ENDDO
! IF (ncly.EQ.2) THEN
! DO k = 1, xsize(3)
! DO i = 1, xsize(1)
! volflux = volflux + (byy1(i, k) - byyn(i, k)) * dx * dz * gdt(itr) * udx
! ENDDO
! ENDDO
! ENDIF
! IF (nclz.EQ.2) THEN
! DO j = 1, xsize(2) - 1
! IF (istret.EQ.0) THEN
! Ay = yly / (ny - 1)
! ELSE
! Ay = (yp(j + 1) - yp(j))
! ENDIF
! DO i = 1, xsize(1)
! volflux = volflux + 0.5_mytype * ((bzz1(i, j) + bzz1(i, j + 1)) &
! - (bzzn(i, j) + bzzn(i, j + 1))) * dx * Ay * gdt(itr) * udx
! ENDDO
! ENDDO
! ENDIF
! CALL MPI_ALLREDUCE(MPI_IN_PLACE, volflux, 1, real_type, MPI_SUM, MPI_COMM_WORLD, code)
! volflux = volflux / (yly * zlz)
! cx(:,:) = cx(:,:) + volflux
! u2 = 0._mytype
if (itype.ne.9) then
do k = 1, xsize(3)
do j = 1, xsize(2)
bxxn(j, k) = ux(nx, j, k) - cx(j, k) * (ux(nx, j, k) - ux(nx - 1, j, k))
bxyn(j, k) = uy(nx, j, k) - cx(j, k) * (uy(nx, j, k) - uy(nx - 1, j, k))
bxzn(j, k) = uz(nx, j, k) - cx(j, k) * (uz(nx, j, k) - uz(nx - 1, j, k))
! bxyn(j, k) = 0._mytype
! bxzn(j, k) = 0._mytype
massfrac(nx, j, k) = massfrac(nx, j, k) - cx(j, k) &
* (massfrac(nx, j, k) - massfrac(nx - 1, j, k))
enddo
enddo
if (isolvetemp.eq.0) then
do k = 1, xsize(3)
do j = 1, xsize(2)
rho(nx, j, k) = rho(nx, j, k) - cx(j, k) * (rho(nx, j, k) - rho(nx - 1, j, k))
enddo
enddo
else
do k = 1, xsize(3)
do j = 1, xsize(2)
temperature(nx, j, k) = temperature(nx, j, k) - cx(j, k) &
* (temperature(nx, j, k) - temperature(nx - 1, j, k))
enddo
enddo
endif
if (iscalar.eq.1) then
do k = 1, xsize(3)
do j = 1, xsize(2)
phi(nx, j, k) = phi(nx, j, k) - cx(j, k) * (phi(nx, j, k) - phi(nx - 1, j, k))
enddo
enddo
endif
else
print *, 'NOT READY'
stop
endif
return
end subroutine outflow
SUBROUTINE compute_outflux_lmn(temperature1, gradtempx1, di1,&
temperature2, gradtempy2, di2,&
temperature3, gradtempz3, di3)
USE MPI
USE decomp_2d
USE param
USE variables
IMPLICIT NONE
REAL(mytype), DIMENSION(xsize(1), xsize(2), xsize(3)), INTENT(IN) :: temperature1
REAL(mytype), DIMENSION(xsize(1), xsize(2), xsize(3)) :: gradtempx1, di1
REAL(mytype), DIMENSION(ysize(1), ysize(2), ysize(3)) :: temperature2, gradtempy2, di2
REAL(mytype), DIMENSION(zsize(1), zsize(2), zsize(3)) :: temperature3, gradtempz3, di3
INTEGER :: i, j, k
REAL(mytype) :: invpr
INTEGER :: ierr
REAL(mytype) :: outflux_local
outflux_local = 0._mytype
invpr = 1._mytype / pr
IF (itype.NE.7) THEN
IF (nclx.EQ.2) THEN
CALL derx (gradtempx1,temperature1,di1,sx,ffxp,fsxp,fwxp,&
xsize(1),xsize(2),xsize(3),1)
DO k = 1, xsize(3)
DO j = 1, xsize(2)
outflux_local = outflux_local + bxx1(j, k) * (dy * dz)
outflux_local = outflux_local + (xnu * invpr) &
* (gradtempx1(nx, j, k) - gradtempx1(1, j, k)) * (dy * dz)
ENDDO
ENDDO
ENDIF
IF (MAX(ncly, nclz).EQ.2) THEN
CALL transpose_x_to_y(temperature1, temperature2)
IF (ncly.EQ.2) THEN
IF (xstart(2).EQ.1) THEN
DO k = 1, xsize(3)
DO i = 1, xsize(1)
outflux_local = outflux_local + byy1(i, k) * (dx * dz)
ENDDO
ENDDO
ENDIF
IF (xend(2).EQ.ny) THEN
DO k = 1, xsize(3)
DO i = 1, xsize(1)
outflux_local = outflux_local - byyn(i, k) * (dx * dz)
ENDDO
ENDDO
ENDIF
CALL dery (gradtempy2,temperature2,di2,sy,ffyp,fsyp,fwyp,ppy,&
ysize(1),ysize(2),ysize(3),1)
DO k = 1, ysize(3)
DO i = 1, ysize(1)
outflux_local = outflux_local + (xnu * invpr) &
* (gradtempy2(i, ny, k) - gradtempy2(i, 1, k)) * (dx * dz)
ENDDO
ENDDO
ENDIF
IF (nclz.EQ.2) THEN
IF (xstart(3).EQ.1) THEN
DO j = 1, xsize(2)
DO i = 1, xsize(1)
outflux_local = outflux_local + bzz1(i, j) * (dx * dy)
ENDDO
ENDDO
ENDIF
IF (xend(3).EQ.nz) THEN
DO j = 1, xsize(2)
DO i = 1, xsize(1)
outflux_local = outflux_local - bzz1(i, j) * (dx * dy)
ENDDO
ENDDO
ENDIF
CALL transpose_y_to_z(temperature2, temperature3)
CALL derz (gradtempz3,temperature3,di3,sz,ffzp,fszp,fwzp,&
zsize(1),zsize(2),zsize(3),1)
DO j = 1, zsize(2)
DO i = 1, zsize(1)
outflux_local = outflux_local + (xnu * invpr) &
* (gradtempz3(i, j, nz) - gradtempz3(i, j, 1)) * (dx * dy)
ENDDO
ENDDO
ENDIF
ENDIF
ENDIF
CALL MPI_ALLREDUCE(outflux_local, outflux, 1, real_type, MPI_SUM, MPI_COMM_WORLD, ierr)
ENDSUBROUTINE compute_outflux_lmn
SUBROUTINE set_velocity_entrainment_y(clx1, cly1, clz1)
USE decomp_2d
USE variables
USE param
IMPLICIT NONE
REAL(mytype), DIMENSION(xsize(1), xsize(2), xsize(3)), INTENT(IN) :: clx1, cly1, clz1
INTEGER :: i, j, k
IF (xstart(2).EQ.1) THEN
j = 1
DO k = 1, xsize(3)
DO i = 1, xsize(1)
byx1(i, k) = clx1(i, j, k)
byy1(i, k) = cly1(i, j, k)
byz1(i, k) = clz1(i, j, k)
ENDDO
ENDDO
ENDIF
IF (xend(2).EQ.ny) THEN
j = xsize(2)
DO k = 1, xsize(3)
DO i = 1, xsize(1)
byxn(i, k) = clx1(i, j, k)
byyn(i, k) = cly1(i, j, k)
byzn(i, k) = clz1(i, j, k)
ENDDO
ENDDO
ENDIF
ENDSUBROUTINE set_velocity_entrainment_y
SUBROUTINE set_density_entrainment_y(rho1, uy1)
USE decomp_2d
USE variables
USE param
IMPLICIT NONE
REAL(mytype), DIMENSION(xsize(1), xsize(2), xsize(3)), INTENT(IN) :: uy1
REAL(mytype), DIMENSION(xsize(1), xsize(2), xsize(3)) :: rho1
INTEGER :: i, j, k
REAL(mytype) :: x
REAL(mytype) :: cy
REAL(mytype) :: l_fringe, xph_fringe
INTEGER :: iph_fringe
l_fringe = 0.1_mytype * xlx
xph_fringe = xlx - l_fringe
!! Find fringe
DO i = 1, xsize(1)
x = (i + xstart(1) - 2) * dx
IF (x.GT.xph_fringe) THEN
EXIT
ELSE
iph_fringe = i
ENDIF
ENDDO
IF (ilmn.NE.0) THEN
j = 1
IF (xstart(2).EQ.1) THEN
DO k = 1, xsize(3)
DO i = 1, iph_fringe
IF (uy1(i, j, k).GT.0._mytype) THEN
!! INFLOW
rho1(i, j, k) = dens2
ELSE
!! OUTFLOW
cy = uy1(i, j, k) * gdt(itr) / dy
rho1(i, j, k) = rho1(i, j, k) - cy * (rho1(i, j + 1, k) - rho1(i, j, k))
ENDIF
ENDDO
DO i = iph_fringe + 1, xsize(1)
rho1(i, j, k) = rho1(i, j + 1, k)
ENDDO
ENDDO
ENDIF
IF (xend(2).EQ.ny) THEN
j = xsize(2)
DO k = 1, xsize(3)
DO i = 1, iph_fringe
IF (uy1(i, j, k).LT.0._mytype) THEN
!! INFLOW
rho1(i, j, k) = dens2
ELSE
!! OUTFLOW
cy = uy1(i, j, k) * gdt(itr) / dy
rho1(i, j, k) = rho1(i, j, k) - cy * (rho1(i, j, k) - rho1(i, j - 1, k))
ENDIF
ENDDO
DO i = iph_fringe + 1, xsize(1)
rho1(i, j, k) = rho1(i, j - 1, k)
ENDDO
ENDDO
ENDIF
ENDIF
ENDSUBROUTINE set_density_entrainment_y
SUBROUTINE set_velocity_entrainment_z(clx1, cly1, clz1)