-
Notifications
You must be signed in to change notification settings - Fork 0
/
m_rhs.f90
executable file
·1316 lines (1171 loc) · 41.4 KB
/
m_rhs.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
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! Module computing RHS of the PDE in semi-discrete form
!
! Last update: April 22, 2010
! Author: Keita Ando
! Department of Mechanical Engineering
! Division of Engineering and Applied Science
! California Institute of Technology, Pasadena CA 91125
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
MODULE m_rhs
USE mpi_setup
USE mpi_transfer
USE m_globalvar
USE m_rhsvar
USE m_bubbles
USE m_misc
IMPLICIT NONE
REAL(KIND(0.D0)) :: duwall
CONTAINS
!========================================================================
SUBROUTINE s_rhs( qgvn )
INTEGER :: iv
TYPE(coordinate), DIMENSION(Nv), INTENT(IN) :: qgvn
! transfer neighboring data
DO iv = 1,Nv
qval(iv)%f = qgvn(iv)%f
END DO
CALL s_mpi_transfer( qval )
! compute primitive variables & characteristic speeds
CALL s_compvar
! Roe-averaged right & left eigenvectors at cell edges
CALL s_roeaverage
! numerical flux
CALL s_rhsfv
! source flux for momentum equation & sources in bubble dynamics
DO iv = 1,Nv
rhsrc(iv)%f = 0.D0
END DO
IF ( source=='y' ) THEN
CALL s_compsrc
END IF
! RHS including sources
DO iv = 1,Nv
rhs(iv)%f = rhsfx(iv)%f + rhsrc(iv)%f
END DO
! check Not-a-Number
CALL s_NaN_rhs( rhsfx )
CALL s_NaN_src( rhsrc )
END SUBROUTINE s_rhs
!========================================================================
SUBROUTINE s_rhsfv
INTEGER :: i
INTEGER :: iv
! substitute conserved variables for WENO reconstruction
DO iv = 1,Nv
DO i = 1,N1
inweno(iv)%f(i) = qval(iv)%f(i)
END DO
END DO
IF ( bound%beg=='reflect'.AND.mpi_rank==0 ) THEN
DO iv = 1,Nv
IF ( iv==dir1 ) THEN
DO i = 1,wenonum
! reflected
! moving wall BC incorporated
inweno(iv)%f(1-i) = 2.D0*uwall - inweno(iv)%f(i)
END DO
ELSE
DO i = 1,wenonum
! mirrored
inweno(iv)%f(1-i) = inweno(iv)%f(i)
END DO
END IF
END DO
END IF
IF ( bound%end=='reflect'.AND.mpi_rank==mpi_size-1 ) THEN
DO iv = 1,Nv
IF ( iv==dir1 ) THEN
DO i = 1,wenonum
! reflected
inweno(iv)%f(N1+i) = -inweno(iv)%f(N1+1-i)
END DO
ELSE
DO i = 1,wenonum
! mirrored
inweno(iv)%f(N1+i) = inweno(iv)%f(N1+1-i)
END DO
END IF
END DO
END IF
! WENO reconstruction with monotonicity preserving
CALL s_weno
! characteristic fields => physical space
IF ( chardecomp=='y' ) THEN
CALL s_multiply_rr( lweno,0,-1 )
lweno = v_out ! "R" state
CALL s_multiply_rr( rweno,0,0 )
rweno = v_out ! "L" state
END IF
! correct negative values
IF ( negative=='y' ) CALL s_reconstruct1
! approximate Riemann solver (HLLC)
! boundary conditions implemented
CALL s_approx_riemann
END SUBROUTINE s_rhsfv
!========================================================================
SUBROUTINE s_reconstruct1
INTEGER :: i
INTEGER :: iv
INTEGER :: ir
REAL(KIND(0.D0)), DIMENSION(NR0) :: bval
!!! correct lweno (1st-order reconstruction) !!!
! mixture density
! DO i = 1,N1
! IF ( lweno(1)%f(i)/=lweno(1)%f(i) ) THEN
! DO iv = 1,Nv
! lweno(iv)%f(i) = qval(iv)%f(i)
! END DO
! END IF
! END DO
! void fraction
DO i = 1,N1
IF ( lweno(Nveul)%f(i)<=0.D0 ) THEN
DO iv = 1,Nv
lweno(iv)%f(i) = qval(iv)%f(i)
END DO
END IF
END DO
! radius
DO i = 1,N1
DO ir = 1,NR0
bval(ir) = lweno(ibub(1,ir))%f(i)
END DO
IF ( ANY(bval<=0.D0) ) THEN
DO iv = 1,Nv
lweno(iv)%f(i) = qval(iv)%f(i)
END DO
END IF
END DO
! bubble pressure
IF ( polytropic=='n' ) THEN
DO i = 1,N1
DO ir = 1,NR0
bval(ir) = lweno(ibub(3,ir))%f(i)
END DO
IF ( ANY(bval<=0.D0) ) THEN
DO iv = 1,Nv
lweno(iv)%f(i) = qval(iv)%f(i)
END DO
END IF
END DO
END IF
! mass of vapor
IF ( polytropic=='n'.AND.vapor=='y' ) THEN
DO i = 1,N1
DO ir = 1,NR0
bval(ir) = lweno(ibub(4,ir))%f(i)
END DO
IF ( ANY(bval<=0.D0) ) THEN
DO iv = 1,Nv
lweno(iv)%f(i) = qval(iv)%f(i)
END DO
END IF
END DO
END IF
!!! correct rweno (1st-order reconstruction) !!!
! mixture density
! DO i = 1,N1
! IF ( rweno(1)%f(i)/=rweno(1)%f(i) ) THEN
! DO iv = 1,Nv
! rweno(iv)%f(i) = qval(iv)%f(i)
! END DO
! END IF
! END DO
! void fraction
DO i = 1,N1
IF ( rweno(Nveul)%f(i)<=0.D0 ) THEN
DO iv = 1,Nv
rweno(iv)%f(i) = qval(iv)%f(i)
END DO
END IF
END DO
! radius
DO i = 1,N1
DO ir = 1,NR0
bval(ir) = rweno(ibub(1,ir))%f(i)
END DO
IF ( ANY(bval<=0.D0) ) THEN
DO iv = 1,Nv
rweno(iv)%f(i) = qval(iv)%f(i)
END DO
END IF
END DO
! bubble pressure
IF ( polytropic=='n' ) THEN
DO i = 1,N1
DO ir = 1,NR0
bval(ir) = rweno(ibub(3,ir))%f(i)
END DO
IF ( ANY(bval<=0.D0) ) THEN
DO iv = 1,Nv
rweno(iv)%f(i) = qval(iv)%f(i)
END DO
END IF
END DO
END IF
! mass of vapor
IF ( polytropic=='n'.AND.vapor=='y' ) THEN
DO i = 1,N1
DO ir = 1,NR0
bval(ir) = rweno(ibub(4,ir))%f(i)
END DO
IF ( ANY(bval<=0.D0) ) THEN
DO iv = 1,Nv
rweno(iv)%f(i) = qval(iv)%f(i)
END DO
END IF
END DO
END IF
END SUBROUTINE s_reconstruct1
!========================================================================
SUBROUTINE s_compsrc
INTEGER :: i
INTEGER :: ir
REAL(KIND(0.D0)) :: ra
REAL(KIND(0.D0)) :: vv
REAL(KIND(0.D0)) :: pb
REAL(KIND(0.D0)) :: mv
REAL(KIND(0.D0)) :: vflux
REAL(KIND(0.D0)) :: pbdot
REAL(KIND(0.D0)) :: pldot
REAL(KIND(0.D0)) :: srcvf
REAL(KIND(0.D0)) :: divum
REAL(KIND(0.D0)) :: R2Vbar
REAL(KIND(0.D0)), DIMENSION(NR0) :: R2V
! compute numerical source flux in momentum equation
! returns nsfx(Nbeg:N1) out of nsfx(0:N1)
CALL s_hllc_src
! for nonreflective BCs
IF ( xincoming%end=='undex' .or. xincoming%beg=='undex' ) THEN
IF ( bound%beg=='nonreflect'.AND.mpi_rank==0 ) THEN
nsfx(0) = nsfx(1)
velhf(0) = velhf(1)
END IF
IF ( bound%end=='nonreflect'.AND.mpi_rank==mpi_size-1 ) THEN
nsfx(N1) = nsfx(N1-1)
velhf(N1) = velhf(N1-1)
END IF
ELSE
IF ( bound%beg=='nonreflect'.AND.mpi_rank==0 ) THEN
! returns nsfx(0) and nsfx(1)
CALL s_srcbeg
END IF
IF ( bound%end=='nonreflect'.AND.mpi_rank==mpi_size-1 ) THEN
! returns nsfx(N1) and nsfx(N1-1)
CALL s_srcend
END IF
END IF
! source in momentum equation
DO i = 1,N1
rhsrc(dir1)%f(i) = ( nsfx(i)-nsfx(i-1) )/ds(i)
END DO
! sources for bubble-dynamic equations
IF ( timesplit=='unsplit' ) THEN
IF ( polytropic=='n'.AND.vapor=='y' ) THEN
DO i = 1,N1
DO ir = 1,NR0
R2V(ir) = bub(1,ir)%f(i)**2*bub(2,ir)%f(i)
END DO
CALL s_quad( R2V,R2Vbar )
srcvf = 4.D0*pi*nbub(i)*R2Vbar
divum = ( velhf(i)-velhf(i-1) )/ds(i)
pldot = qval(1)%f(i)*sound(i)**2*( srcvf-divum )
rhsrc(Nveul)%f(i) = srcvf
DO ir = 1,NR0
iR0 = ir
ra = bub(1,ir)%f(i)
vv = bub(2,ir)%f(i)
pb = bub(3,ir)%f(i)
mv = bub(4,ir)%f(i)
CALL s_bwproperty( pb )
rhsrc(ibub(1,ir))%f(i) = qval(ibub(2,ir))%f(i)
vflux = f_vflux( ra,vv,mv )
rhsrc(ibub(4,ir))%f(i) = nbub(i)*vflux*4.D0*pi*ra**2
pbdot = f_bpres_dot( vflux,ra,vv,pb,mv )
rhsrc(ibub(3,ir))%f(i) = nbub(i)*pbdot
rhsrc(ibub(2,ir))%f(i) = nbub(i) &
* f_gilmore( ra,vv,pb,pbdot,pres(i),pldot )
END DO
END DO
ELSE IF ( polytropic=='n'.AND.vapor=='n' ) THEN
DO i = 1,N1
DO ir = 1,NR0
R2V(ir) = bub(1,ir)%f(i)**2*bub(2,ir)%f(i)
END DO
CALL s_quad( R2V,R2Vbar )
srcvf = 4.D0*pi*nbub(i)*R2Vbar
divum = ( velhf(i)-velhf(i-1) )/ds(i)
pldot = qval(1)%f(i)*sound(i)**2*( srcvf-divum )
rhsrc(Nveul)%f(i) = srcvf
DO ir = 1,NR0
iR0 = ir
ra = bub(1,ir)%f(i)
vv = bub(2,ir)%f(i)
pb = bub(3,ir)%f(i)
CALL s_bwproperty( pb )
rhsrc(ibub(1,ir))%f(i) = qval(ibub(2,ir))%f(i)
vflux = f_vflux( ra,vv,0.D0 )
pbdot = f_bpres_dot( vflux,ra,vv,pb,0.D0 )
rhsrc(ibub(3,ir))%f(i) = nbub(i)*pbdot
rhsrc(ibub(2,ir))%f(i) = nbub(i) &
* f_gilmore( ra,vv,pb,pbdot,pres(i),pldot )
END DO
END DO
ELSE IF ( polytropic=='y' ) THEN
DO i = 1,N1
DO ir = 1,NR0
R2V(ir) = bub(1,ir)%f(i)**2*bub(2,ir)%f(i)
END DO
CALL s_quad( R2V,R2Vbar )
srcvf = 4.D0*pi*nbub(i)*R2Vbar
divum = ( velhf(i)-velhf(i-1) )/ds(i)
pldot = qval(1)%f(i)*sound(i)**2*( srcvf-divum )
rhsrc(Nveul)%f(i) = srcvf
DO ir = 1,NR0
iR0 = ir
ra = bub(1,ir)%f(i)
vv = bub(2,ir)%f(i)
rhsrc(ibub(1,ir))%f(i) = qval(ibub(2,ir))%f(i)
rhsrc(ibub(2,ir))%f(i) = nbub(i) &
* f_gilmore( ra,vv,0.D0,0.D0,pres(i),pldot )
END DO
END DO
END IF
ELSE
DO i = 1,N1
DO ir = 1,NR0
R2V(ir) = bub(1,ir)%f(i)**2*bub(2,ir)%f(i)
END DO
CALL s_quad( R2V,R2Vbar )
srcvf = 4.D0*pi*nbub(i)*R2Vbar
divum = ( velhf(i)-velhf(i-1) )/ds(i)
dpldt(i) = qval(1)%f(i)*sound(i)**2*( srcvf-divum )
END DO
END IF
END SUBROUTINE s_compsrc
!========================================================================
SUBROUTINE s_weno
INTEGER :: i
INTEGER :: m
INTEGER :: iv
REAL(KIND(0.D0)), DIMENSION(0:2) :: beta
REAL(KIND(0.D0)), DIMENSION(0:2) :: alpha
REAL(KIND(0.D0)), DIMENSION(0:2) :: poly
REAL(KIND(0.D0)), DIMENSION(0:2) :: d
REAL(KIND(0.D0)), DIMENSION(-2:1) :: dvd
REAL(KIND(0.D0)) :: tmpmin
REAL(KIND(0.D0)) :: tmpmax
REAL(KIND(0.D0)), DIMENSION(0:2) :: curv
REAL(KIND(0.D0)) :: ulc
REAL(KIND(0.D0)) :: umd
REAL(KIND(0.D0)) :: uul
REAL(KIND(0.D0)) :: minmod
REAL(KIND(0.D0)) :: diff1
REAL(KIND(0.D0)) :: diff2
REAL(KIND(0.D0)) :: wenosum
! characteristic decomposition
IF ( chardecomp=='y' ) THEN
DO m = -wenonum,wenonum
!!! left-going wave at i-1/2 (left celledge) !!!
CALL s_multiply_ll( inweno,m,-1 )
linw%w(m) = v_out
!!! right-going wave at i+1/2 (right celledge) !!!
CALL s_multiply_ll( inweno,m,0 )
rinw%w(m) = v_out
END DO
ELSE ! component-wise
IF ( bound%beg=='reflect'.AND.mpi_rank==0 ) THEN
DO m = -wenonum,0
DO iv = 1,Nv
DO i = 1,N1
linw(iv)%w(m)%f(i) = inweno(iv)%f(i+m)
END DO
END DO
END DO
ELSE
DO m = -wenonum,0
DO iv = 1,Nv
DO i = 1,N1
linw(iv)%w(m)%f(i) = inweno(iv)%f(ip(i,m))
END DO
END DO
END DO
END IF
IF ( bound%end=='reflect'.AND.mpi_rank==mpi_size-1 ) THEN
DO m = 0,wenonum
DO iv = 1,Nv
DO i = 1,N1
linw(iv)%w(m)%f(i) = inweno(iv)%f(i+m)
END DO
END DO
END DO
ELSE
DO m = 0,wenonum
DO iv = 1,Nv
DO i = 0,N1
linw(iv)%w(m)%f(i) = inweno(iv)%f(ip(i,m))
END DO
END DO
END DO
END IF
rinw = linw
END IF
! build interpolation polynomial with WENO reconstruction
IF ( wenoord==1 ) THEN
DO iv = 1,Nv
DO i = 1,N1
rweno(iv)%f(i) = rinw(iv)%w(0)%f(i)
lweno(iv)%f(i) = linw(iv)%w(0)%f(i)
END DO
END DO
ELSE IF ( wenoord==3 ) THEN
DO iv = 1,Nv
DO i = 1,N1
!!! right-going wave at i+1/2 ("L" state) !!!
! differences
dvd(-1) = rinw(iv)%w(0)%f(i) - rinw(iv)%w(-1)%f(i)
dvd(0) = rinw(iv)%w(1)%f(i) - rinw(iv)%w(0)%f(i)
! smoothness indicators
beta(0) = w3beta(0,i)*dvd(-1)*dvd(-1) + eps
beta(1) = w3beta(1,i)*dvd(0)*dvd(0) + eps
! weights
d(0) = w3dr(0,i)
d(1) = w3dr(1,i)
DO m = 0,1
alpha(m) = d(m)/( beta(m)*beta(m) )
END DO
wenosum = alpha(0) + alpha(1)
alpha = alpha/wenosum
! polynomials
poly(0) = rinw(iv)%w(0)%f(i) + w3polyr(0,i)*dvd(-1)
poly(1) = rinw(iv)%w(0)%f(i) + w3polyr(1,i)*dvd(0)
! WENO value
rweno(iv)%f(i) = alpha(0)*poly(0) + alpha(1)*poly(1)
!!! left-going wave at i-1/2 ("R" state) !!!
! differences
dvd(-1) = linw(iv)%w(0)%f(i) - linw(iv)%w(-1)%f(i)
dvd(0) = linw(iv)%w(1)%f(i) - linw(iv)%w(0)%f(i)
! smoothness indicators
beta(0) = w3beta(0,i)*dvd(-1)*dvd(-1) + eps
beta(1) = w3beta(1,i)*dvd(0)*dvd(0) + eps
! weights
d(0) = w3dl(0,i)
d(1) = w3dl(1,i)
DO m = 0,1
alpha(m) = d(m)/( beta(m)*beta(m) )
END DO
wenosum = alpha(0) + alpha(1)
alpha = alpha/wenosum
! polynomials
poly(0) = linw(iv)%w(0)%f(i) + w3polyl(0,i)*dvd(-1)
poly(1) = linw(iv)%w(0)%f(i) + w3polyl(1,i)*dvd(0)
! WENO value
lweno(iv)%f(i) = alpha(0)*poly(0) + alpha(1)*poly(1)
END DO
END DO
ELSE IF ( wenoord==5 ) THEN
DO iv = 1,Nv
DO i = 1,N1 ! within computational domain
!!! right-going wave at i+1/2 ("L" state) !!!
! differences
DO m = -2,1
dvd(m) = rinw(iv)%w(m+1)%f(i) - rinw(iv)%w(m)%f(i)
END DO
! smoothness indicators
beta(0) = eps + betaw0(0,i)*dvd(-1)*dvd(-1) &
+ betaw0(1,i)*dvd(-1)*dvd(-2) &
+ betaw0(2,i)*dvd(-2)*dvd(-2)
beta(1) = eps + betaw1(0,i)*dvd(0)*dvd(0) &
+ betaw1(1,i)*dvd(0)*dvd(-1) &
+ betaw1(2,i)*dvd(-1)*dvd(-1)
beta(2) = eps + betaw2(0,i)*dvd(1)*dvd(1) &
+ betaw2(1,i)*dvd(1)*dvd(0) &
+ betaw2(2,i)*dvd(0)*dvd(0)
! weights
DO m = 0,2
d(m) = dwenor(m,i)
END DO
DO m = 0,2
alpha(m) = d(m)/( beta(m)*beta(m) )
END DO
wenosum = alpha(0) + alpha(1) + alpha(2)
alpha = alpha/wenosum
! polynomials
poly(0) = rinw(iv)%w(0)%f(i) + dvd(-1)*polyr0(0,i) &
+ dvd(-2)*polyr0(1,i)
poly(1) = rinw(iv)%w(0)%f(i) + dvd(0)*polyr1(0,i) &
+ dvd(-1)*polyr1(1,i)
poly(2) = rinw(iv)%w(0)%f(i) + dvd(1)*polyr2(0,i) &
+ dvd(0)*polyr2(1,i)
! WENO value
rweno(iv)%f(i) = alpha(0)*poly(0) + alpha(1)*poly(1) &
+ alpha(2)*poly(2)
! for nonreflective BCs
IF ( ((bound%beg=='nonreflect'.AND.i==2).AND.mpi_rank==0) &
.OR. &
((bound%end=='nonreflect'.AND.i==N1-1).AND. &
mpi_rank==mpi_size-1) ) THEN
! WENO3
dvd(-1) = rinw(iv)%w(0)%f(i) - rinw(iv)%w(-1)%f(i)
dvd(0) = rinw(iv)%w(1)%f(i) - rinw(iv)%w(0)%f(i)
beta(0) = w3beta(0,i)*dvd(-1)*dvd(-1) + eps
beta(1) = w3beta(1,i)*dvd(0)*dvd(0) + eps
d(0) = w3dr(0,i)
d(1) = w3dr(1,i)
DO m = 0,1
alpha(m) = d(m)/( beta(m)*beta(m) )
END DO
wenosum = alpha(0) + alpha(1)
alpha = alpha/wenosum
poly(0) = rinw(iv)%w(0)%f(i) + w3polyr(0,i)*dvd(-1)
poly(1) = rinw(iv)%w(0)%f(i) + w3polyr(1,i)*dvd(0)
rweno(iv)%f(i) = alpha(0)*poly(0) + alpha(1)*poly(1)
END IF
! monotonicity preserving (Balsara 2000)
IF ( mpweno=='y' ) THEN
curv(0) = dvd(-1) - dvd(-2)
curv(1) = dvd(0) - dvd(-1)
minmod = 0.5D0 &
* ( SIGN(1.D0,curv(0))+SIGN(1.D0,curv(1)) ) &
* MIN( DABS(curv(0)),DABS(curv(1)) )
ulc = rinw(iv)%w(0)%f(i) + 0.5D0*dvd(-1) &
+ four3rd*minmod
curv(0) = dvd(0) - dvd(-1)
curv(1) = dvd(1) - dvd(0)
minmod = 0.5D0 &
* ( SIGN(1.D0,curv(0))+SIGN(1.D0,curv(1)) ) &
* MIN( DABS(curv(0)),DABS(curv(1)) )
umd = 0.5D0*( rinw(iv)%w(0)%f(i)+rinw(iv)%w(1)%f(i) &
- minmod )
uul = rinw(iv)%w(0)%f(i) + 2.D0*dvd(-1)
tmpmin = MAX( &
MIN(rinw(iv)%w(0)%f(i),rinw(iv)%w(1)%f(i),umd), &
MIN(rinw(iv)%w(0)%f(i),uul,ulc) )
tmpmax = MIN( &
MAX(rinw(iv)%w(0)%f(i),rinw(iv)%w(1)%f(i),umd), &
MAX(rinw(iv)%w(0)%f(i),uul,ulc) )
diff1 = tmpmin - rweno(iv)%f(i)
diff2 = tmpmax - rweno(iv)%f(i)
rweno(iv)%f(i) = rweno(iv)%f(i) + 0.5D0*( &
SIGN(1.D0,diff1)+SIGN(1.D0,diff2) ) &
* MIN( DABS(diff1),DABS(diff2) )
END IF
!!! left-going wave at i-1/2 ("R" state) !!!
! differences
DO m = -2,1
dvd(m) = linw(iv)%w(m+1)%f(i) - linw(iv)%w(m)%f(i)
END DO
! smoothness indicatiors
beta(0) = eps + betaw0(0,i)*dvd(-1)*dvd(-1) &
+ betaw0(1,i)*dvd(-1)*dvd(-2) &
+ betaw0(2,i)*dvd(-2)*dvd(-2)
beta(1) = eps + betaw1(0,i) * dvd(0) * dvd(0) &
+ betaw1(1,i)*dvd(0)*dvd(-1) &
+ betaw1(2,i)*dvd(-1)*dvd(-1)
beta(2) = eps + betaw2(0,i)*dvd(1)*dvd(1) &
+ betaw2(1,i)*dvd(1)*dvd(0) &
+ betaw2(2,i)*dvd(0)*dvd(0)
! weights
DO m = 0,2
d(m) = dwenol(m,i)
END DO
DO m = 0,2
alpha(m) = d(m)/( beta(m)*beta(m) )
END DO
wenosum = alpha(0) + alpha(1) + alpha(2)
alpha = alpha/wenosum
! polynomials
poly(0) = linw(iv)%w(0)%f(i) + dvd(-1)*polyl0(0,i) &
+ dvd(-2) * polyl0(1,i)
poly(1) = linw(iv)%w(0)%f(i) + dvd(0)*polyl1(0,i) &
+ dvd(-1)*polyl1(1,i)
poly(2) = linw(iv)%w(0)%f(i) + dvd(1)*polyl2(0,i) &
+ dvd(0)*polyl2(1,i)
! WENO value
lweno(iv)%f(i) = alpha(0)*poly(0) + alpha(1)*poly(1) &
+ alpha(2)*poly(2)
! for nonreflective BCs
IF ( ((bound%beg=='nonreflect'.AND.i==2).AND.mpi_rank==0) &
.OR. &
((bound%end=='nonreflect'.AND.i==N1-1).AND. &
mpi_rank==mpi_size-1) ) THEN
! WENO3
dvd(-1) = linw(iv)%w(0)%f(i) - linw(iv)%w(-1)%f(i)
dvd(0) = linw(iv)%w(1)%f(i) - linw(iv)%w(0)%f(i)
beta(0) = w3beta(0,i)*dvd(-1)*dvd(-1) + eps
beta(1) = w3beta(1,i)*dvd(0)*dvd(0) + eps
d(0) = w3dl(0,i)
d(1) = w3dl(1,i)
DO m = 0,1
alpha(m) = d(m)/( beta(m)*beta(m) )
END DO
wenosum = alpha(0) + alpha(1)
alpha = alpha/wenosum
poly(0) = linw(iv)%w(0)%f(i) + w3polyl(0,i)*dvd(-1)
poly(1) = linw(iv)%w(0)%f(i) + w3polyl(1,i)*dvd(0)
lweno(iv)%f(i) = alpha(0)*poly(0) + alpha(1)*poly(1)
END IF
! monotonicity preserving (Balsara 2000)
IF ( mpweno=='y' ) THEN
curv(0) = dvd(0) - dvd(-1)
curv(1) = dvd(1) - dvd(0)
minmod = 0.5D0*( SIGN(1.D0,curv(0))+SIGN(1.D0,curv(1)) ) &
* MIN( DABS(curv(0)),DABS(curv(1)) )
ulc = linw(iv)%w(0)%f(i) - 0.5D0*dvd(0) + four3rd*minmod
curv(0) = dvd(-1) - dvd(-2)
curv(1) = dvd(0) - dvd(-1)
minmod = 0.5D0*( SIGN(1.D0,curv(0))+SIGN(1.D0,curv(1)) ) &
* MIN( DABS(curv(0)),DABS(curv(1)) )
umd = 0.5D0*( linw(iv)%w(0)%f(i)+linw(iv)%w(-1)%f(i) &
- minmod )
uul = linw(iv)%w(0)%f(i) - 2.D0*dvd(0)
tmpmin = MAX( &
MIN(linw(iv)%w(0)%f(i),linw(iv)%w(-1)%f(i),umd), &
MIN(linw(iv)%w(0)%f(i),uul,ulc) )
tmpmax = MIN( &
MAX(linw(iv)%w(0)%f(i),linw(iv)%w(-1)%f(i),umd), &
MAX(linw(iv)%w(0)%f(i),uul,ulc) )
diff1 = tmpmin - lweno(iv)%f(i)
diff2 = tmpmax - lweno(iv)%f(i)
lweno(iv)%f(i) = lweno(iv)%f(i) + 0.5D0*( &
SIGN(1.D0,diff1)+SIGN(1.D0,diff2) ) &
* MIN( DABS(diff1),DABS(diff2) )
END IF
END DO
END DO
END IF
END SUBROUTINE s_weno
!========================================================================
SUBROUTINE s_approx_riemann
INTEGER :: i
INTEGER :: iv
! compute conserved variables & flux at cell edges
! reflective BCs implmented
CALL s_celledgevalue
! HLLC Riemann solvers (returns nfx(:)%f)
CALL s_hllc
! compute wall pressure
duwall = 0.D0
IF ( xincoming%beg=='freeplate'.AND.mpi_rank==0 ) CALL s_wallpres
! modify nfx(:)%f(1) or nfx(:)%f(N1-1) for nonreflective BCs
IF ( wenoord/=1 ) THEN
IF ( bound%beg=='nonreflect'.AND.mpi_rank==0 ) THEN
CALL s_modifynfx_beg
END IF
IF ( bound%end=='nonreflect'.AND.mpi_rank==mpi_size-1 ) THEN
CALL s_modifynfx_end
END IF
END IF
! RHS for the hyperbolic parts
DO iv = 1,Nv
DO i = 1,N1 ! within computational domain
rhsfx(iv)%f(i) = ( nfx(iv)%f(ip(i,-1))-nfx(iv)%f(i) )/ds(i)
END DO
END DO
! modify rhsfx(:)%f(1) or rhsfx(:)%f(N1) for Thompson BCs
IF ( bound%beg=='nonreflect'.AND.mpi_rank==0 ) THEN
CALL s_thompsonbc_beg
END IF
IF ( bound%end=='nonreflect'.AND.mpi_rank==mpi_size-1 ) THEN
CALL s_thompsonbc_end
END IF
END SUBROUTINE s_approx_riemann
!========================================================================
SUBROUTINE s_hllc
INTEGER :: i
INTEGER :: iv
REAL(KIND(0.D0)) :: tmp, tmpm
REAL(KIND(0.D0)) :: Sminus, Splus
! returns sl, sr & sstar at celledges
CALL s_hllwavespeed
! intermediate state
DO i = Nbeg,N1
!!! "R*" state !!!
tmp = ( sr(i)-rvel(ip(i,1)) )/( sr(i)-sstar(i) )
rqstar(1)%f(i) = tmp*rqval(1)%f(ip(i,1))
rqstar(dir1)%f(i) = rqstar(1)%f(i)*sstar(i)
DO iv = Nveul,Nv
rqstar(iv)%f(i) = tmp*rqval(iv)%f(ip(i,1))
END DO
!!! "L*" state !!!
tmp = ( sl(i)-lvel(i) )/( sl(i)-sstar(i) )
lqstar(1)%f(i) = tmp*lqval(1)%f(i)
lqstar(dir1)%f(i) = lqstar(1)%f(i)*sstar(i)
DO iv = Nveul,Nv
lqstar(iv)%f(i) = tmp*lqval(iv)%f(i)
END DO
!!! HLLC flux !!!
tmpm = SIGN( 0.5D0,sstar(i) )
Sminus = MIN( 0.D0,sl(i) )
Splus = MAX( 0.D0,sr(i) )
DO iv = 1,Nv
nfx(iv)%f(i) = ( 0.5D0+tmpm )*( lflux(iv)%f(i) &
+ Sminus*(lqstar(iv)%f(i)-lqval(iv)%f(i)) ) &
+ ( 0.5D0-tmpm )*( rflux(iv)%f(ip(i,1)) &
+ Splus*(rqstar(iv)%f(i)-rqval(iv)%f(ip(i,1))) )
END DO
! IF ( nfx(1)%f(i)/=nfx(1)%f(i) ) THEN
! PRINT*, 'NaN in nfx(1)%f(i) at (i,it,mpi_rank): ', i, it, mpi_rank
! PRINT*, 'lqval(iv)%f(i) =', (lqval(iv)%f(i),iv=1,1)
! PRINT*, 'lqstar(iv)%f(i) =', (lqstar(iv)%f(i),iv=1,1)
! PRINT*, 'rqstar(iv)%f(i) =', (rqstar(iv)%f(i),iv=1,1)
! PRINT*, 'rqval(iv)%f(i+1) =', (rqval(iv)%f(ip(i,1)),iv=1,1)
! END IF
END DO
END SUBROUTINE s_hllc
!========================================================================
SUBROUTINE s_wallpres
INTEGER :: iv
REAL(KIND(0.D0)), DIMENSION(Nv) :: qtmp
REAL(KIND(0.D0)) :: tmpm
REAL(KIND(0.D0)) :: tmpl
REAL(KIND(0.D0)) :: tmpr
! choose one state out of four states
! IF ( sstar(0)>=0.D0.AND.sl(0)>=0.D0 ) qtmp = lqval
! IF ( sstar(0)>=0.D0.AND.sl(0)<0.D0 ) qtmp = lqstar
! IF ( sstar(0)<0.D0.AND.sr(0)>=0.D0 ) qtmp = rqstar
! IF ( sstar(0)<0.D0.AND.sr(0)<0.D0 ) qtmp = rqval
tmpm = SIGN( 0.5D0,sstar(0) )
tmpl = SIGN( 0.5D0,sl(0) )
tmpr = SIGN( 0.5D0,sr(0) )
DO iv = 1,Nv
qtmp(iv) = ( 0.5D0+tmpm )*( lqstar(iv)%f(0) &
+ (0.5D0+tmpl)*(lqval(iv)%f(0)-lqstar(iv)%f(0)) ) &
+ ( 0.5D0-tmpm )*( rqstar(iv)%f(0) &
+ (0.5D0-tmpr)*(rqval(iv)%f(ip(0,1))-rqstar(iv)%f(0)) )
END DO
! wall pressure
pwall = qtmp(1)/( 1.D0-qtmp(Nveul) )
pwall = ( pl0+B_tait )*pwall**n_tait - B_tait
! wall velocity increment
duwall = mp_inv*( pl0-pwall )
END SUBROUTINE s_wallpres
!========================================================================
SUBROUTINE s_hllc_src
INTEGER :: i
INTEGER :: iv
REAL(KIND(0.D0)), DIMENSION(Nv) :: qtmp
REAL(KIND(0.D0)) :: tmpm
REAL(KIND(0.D0)) :: tmpl
REAL(KIND(0.D0)) :: tmpr
DO i = Nbeg,N1
! choose one state out of four states
! IF ( sstar(i)>=0.D0.AND.sl(i)>=0.D0 ) qtmp = lqval
! IF ( sstar(i)>=0.D0.AND.sl(i)<0.D0 ) qtmp = lqstar
! IF ( sstar(i)<0.D0.AND.sr(i)>=0.D0 ) qtmp = rqstar
! IF ( sstar(i)<0.D0.AND.sr(i)<0.D0 ) qtmp = rqval
tmpm = SIGN( 0.5D0,sstar(i) )
tmpl = SIGN( 0.5D0,sl(i) )
tmpr = SIGN( 0.5D0,sr(i) )
DO iv = 1,Nv
qtmp(iv) = ( 0.5D0+tmpm )*( lqstar(iv)%f(i) &
+ (0.5D0+tmpl)*(lqval(iv)%f(i)-lqstar(iv)%f(i)) ) &
+ ( 0.5D0-tmpm )*( rqstar(iv)%f(i) &
+ (0.5D0-tmpr)*(rqval(iv)%f(ip(i,1))-rqstar(iv)%f(i)) )
END DO
! numerical source flux in momentum equation
nsfx(i) = f_nsfx( qtmp )
! IF ( nsfx(i)/=nsfx(i) ) THEN
! PRINT*, 'NaN in pltilde at (i,it,mpi_rank): ', i, it, mpi_rank
! PRINT*, 'lqval(iv)%f(i) =', (lqval(iv)%f(i),iv=1,1)
! PRINT*, 'lqstar(iv)%f(i) =', (lqstar(iv)%f(i),iv=1,1)
! PRINT*, 'rqstar(iv)%f(i) =', (rqstar(iv)%f(i),iv=1,1)
! PRINT*, 'rqval(iv)%f(i+1) =', (rqval(iv)%f(ip(i,1)),iv=1,1)
! PRINT*, 'Computation stopped.'
! STOP
! END IF
! cell-edge velocity
velhf(i) = qtmp(dir1)/qtmp(1)
END DO
END SUBROUTINE s_hllc_src
!========================================================================
FUNCTION f_nsfx( q_in )
REAL(KIND(0.D0)), DIMENSION(Nv), INTENT(IN) :: q_in
REAL(KIND(0.D0)) :: f_nsfx
INTEGER :: ir
REAL(KIND(0.D0)) :: pltmp
REAL(KIND(0.D0)) :: ntmp
REAL(KIND(0.D0)) :: R3av
REAL(KIND(0.D0)) :: R3pbwav
REAL(KIND(0.D0)) :: R3V2av
REAL(KIND(0.D0)), DIMENSION(NR0) :: ra
REAL(KIND(0.D0)), DIMENSION(NR0) :: vv
REAL(KIND(0.D0)), DIMENSION(NR0) :: pbw
REAL(KIND(0.D0)), DIMENSION(NR0) :: nRtmp
REAL(KIND(0.D0)) :: pbtmp
REAL(KIND(0.D0)) :: vf1
DO ir = 1,NR0
nRtmp(ir) = q_in(ibub(1,ir))
END DO
CALL s_comp_n( q_in(Nveul),nRtmp,ntmp )
pbtmp = 0.D0
DO ir = 1,NR0
iR0 = ir
ra(ir) = q_in(ibub(1,ir))/ntmp
vv(ir) = q_in(ibub(2,ir))/ntmp
IF ( polytropic=='n' ) pbtmp = q_in(ibub(3,ir))/ntmp
pbw(ir) = f_bwpres_1( ra(ir),vv(ir),pbtmp )
END DO
vf1 = 1.D0 - q_in(Nveul)
pltmp = ( pl0+B_tait )*( q_in(1)/vf1 )**n_tait - B_tait
CALL s_quad( ra**3,R3av )
CALL s_quad( ra**3*pbw,R3pbwav )
CALL s_quad( ra**3*vv**2,R3V2av )
! numerical source flux in momentum equation
f_nsfx = q_in(Nveul)*( pltmp-(R3pbwav+q_in(1)*R3V2av)/R3av )
END FUNCTION f_nsfx
!========================================================================
SUBROUTINE s_modifynfx_beg
INTEGER :: i
INTEGER :: iv
! numerical flux at 3/2 (Pirozzoli 2002) used for rhsfx(:)%f(2)
DO i = 1,4
fxtmp(1)%f(i) = qval(dir1)%f(i)
fxtmp(dir1)%f(i) = qval(dir1)%f(i)*vel1(i) + pres(i)
DO iv = Nveul,Nv
fxtmp(iv)%f(i) = qval(iv)%f(i)*vel1(i)
END DO
END DO
DO iv = 1,Nv
nfx(iv)%f(1) = ( 3.D0*fxtmp(iv)%f(1)+13.D0*fxtmp(iv)%f(2) &
- 5.D0*fxtmp(iv)%f(3)+fxtmp(iv)%f(4) )*twelfth
END DO
END SUBROUTINE s_modifynfx_beg
!========================================================================
SUBROUTINE s_modifynfx_end
INTEGER :: i
INTEGER :: iv
! numerical flux at N1-1/2 used for rhsfx(:)%f(N1-1)
DO i = N1-3,N1
fxtmp(1)%f(i) = qval(dir1)%f(i)
fxtmp(dir1)%f(i) = qval(dir1)%f(i)*vel1(i) + pres(i)
DO iv = Nveul,Nv
fxtmp(iv)%f(i) = qval(iv)%f(i)*vel1(i)
END DO
END DO
DO iv = 1,Nv
nfx(iv)%f(N1-1) = ( fxtmp(iv)%f(N1-3)-5.D0*fxtmp(iv)%f(N1-2) &
+ 13.D0*fxtmp(iv)%f(N1-1) &
+ 3.D0*fxtmp(iv)%f(N1) )*twelfth
END DO
END SUBROUTINE s_modifynfx_end
!========================================================================
SUBROUTINE s_thompsonbc_beg
INTEGER :: ib
INTEGER :: ir
INTEGER :: iv
REAL(KIND(0.D0)), DIMENSION(Nv) :: diff
REAL(KIND(0.D0)), DIMENSION(Nv) :: lch
REAL(KIND(0.D0)), DIMENSION(Nv) :: charsptmp
REAL(KIND(0.D0)) :: vftmp
REAL(KIND(0.D0)) :: vftmp1
REAL(KIND(0.D0)) :: cltmp
REAL(KIND(0.D0)) :: utmp
REAL(KIND(0.D0)) :: pltmp
REAL(KIND(0.D0)) :: rhotmp
REAL(KIND(0.D0)), DIMENSION(Nb,NR0) :: nbubtmp
REAL(KIND(0.D0)) :: tmp1
REAL(KIND(0.D0)) :: tmp2
!!! one-sided differences !!!
DO iv = 1,Nv
CALL s_onesidebc( qval(iv)%f,'beg' )
diff(iv) = oneside
END DO
!!! Substitution of values at i=1 !!!
rhotmp = qval(1)%f(1)
utmp = vel1(1)
cltmp = sound(1)
pltmp = pres(1)
vftmp = qval(Nveul)%f(1)
vftmp1 = 1.D0 - qval(Nveul)%f(1)
DO ib = 1,Nb
DO ir = 1,NR0
nbubtmp(ib,ir) = qval(ibub(ib,ir))%f(1)
END DO
END DO
DO iv = 1,Nv