-
Notifications
You must be signed in to change notification settings - Fork 0
/
redist_module.f90
1340 lines (1161 loc) · 44 KB
/
redist_module.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 redistribute2D
implicit none
real(kind=8):: g,drytol
! real(8),parameter :: grav=1.d0
real(8),parameter :: dry_tolerance=1.e-8
contains
subroutine barrier_passing(hL,hR,huL,huR,bL,bR,wall_height,&
L2R,R2L,hstarL,hstarR,ustarL,ustarR)
! determine whether water will overtop a barrier from L2R or R2L
! and what intermed height and velocity will be upon impact
implicit none
logical L2R, R2L, rare1, rare2
real(kind=8) :: hL,hR,huL,huR,bL,bR,wall_height,hm,s1m,s2m
real(kind=8) :: uL,um,uR
real(kind=8) :: hstarL,hstarR,ustarL,ustarR,hstartest
real(kind=8) :: ustartest,grav
common /cparam/ grav
g = grav
drytol = dry_tolerance
! print *, "hL,hR: " , hL,hR,g,drytol
L2R = .false.
R2L = .false.
hstarL = 0.d0
hstarR = 0.d0
ustarL = 0.d0
ustarR = 0.d0
if ( hL.gt.drytol ) then
uL = huL/hL
call riemanntype(hL,hL,uL,-uL,hm,um,s1m,s2m,rare1,rare2,&
5,drytol,g)
hstartest = max(hL,hm)
ustartest = max(uL,um)
! print *, "HM,BL,BR:",hm,bL,bR
! print*, "rise1:",hstartest+bL,min(bL,bR)+wall_height
if ( hstartest+bL.gt.min(bL,bR)+wall_height ) then
L2R = .true.
hstarL = hstartest + bL - wall_height - min(bL,bR)
end if
ustarL = ustartest
end if
if ( hR.gt.drytol ) then
uR = huR/hR
call riemanntype(hR,hR,-uR,uR,hm,um,s1m,s2m,rare1,rare2,&
5,drytol,g)
hstartest = max(hR,hm)
ustartest = max(uR,um)
! print*, "rise2:",hstartest+bR,min(bL,bR)+wall_height
if ( hstartest+bR.gt.min(bL,bR)+wall_height ) then
R2L = .true.
hstarR = hstartest + bR - wall_height - min(bL,bR)
end if
ustarR = ustartest
end if
! print *, "RESULT OVERTOP:", L2R, R2L
return
end subroutine barrier_passing
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
subroutine redistribute_fwave(ixy,ql,qr,auxl,auxr,wall_height,&
maxiter,wave_wall,s_wall,amdq_wall,apdq_wall,mwaves,&
meqn,L2R,R2L) !turn on for general angled problems
! redistributes waves at the barrier to left going and right going fluctuations using augmented solver
implicit none
real(kind=8) :: fwave(3,3,2),s(3,2),amdq(3,2),apdq(3,2)
real(kind=8) :: q_wall(3,3),aux_wall(3),s_wall(3)
real(kind=8) :: amdq_wall(3),apdq_wall(3),wave_wall(3,3),pL
real(kind=8) :: ql(3),qr(3),auxl,auxr,wall_height,hvL,hvR,pR
real(kind=8) :: hstarL,hstarR,ustarL,ustarR,diff1,diff2,hL,hR
real(kind=8) :: huL,huR,bL,bR,delb,hstar,um,hstartest,phiL,phiR
real(kind=8) :: uL,uR,vL,vR,wall(3),sL,sR,uhat,chat,sRoe1,sRoe2
real(kind=8) :: sE1,sE2,swr(mwaves),fwr(meqn,mwaves),s1m,s2m
real(kind=8) :: del(3),r(3,3),A(3,3),det1,det2,det3,v_av,v_L,v_R
real(kind=8) :: determinant,beta(3),hustar_interface
real(kind=8) :: q_wall_l(3,2),q_wall_r(3,2),aux_wall_l(2)
real(kind=8) :: aux_wall_r(2),grav
integer :: maxiter,ixy,mu,nv,i,mw,meqn,mwaves,k
logical :: L2R,R2L,rare1,rare2
common /cparam/ grav
! print *, "ql: ",ql
! print *, "qr: ", qr
! print *, "WALL HT:", wall_height
! print *, "L2R,R2L:", L2R,R2L
g = grav
drytol = dry_tolerance
! set up orientation
if (ixy==1) then
mu=2 ! "x-axis" is normal direction
nv=3 ! transverse
else if (ixy ==2 ) then
mu=3 ! "y-axis" is normal direction
nv=2
end if
! avoid negative values
if (qr(1).lt.0.d0) then
qr(1)=0.d0
qr(2)=0.d0
qr(3)=0.d0
endif
if (ql(1).lt.0.d0) then
ql(1)=0.d0
ql(2)=0.d0
ql(3)=0.d0
endif
! set up wall problem
q_wall(1:3,1) = ql
q_wall(:,2) = 0.d0
q_wall(1:3,3) = qr
aux_wall(1) = auxl
aux_wall(3) = auxr
aux_wall(2) = min(auxl,auxr) + wall_height
if ( ql(1) .gt.drytol ) then
v_L = ql(nv)/ql(1)
else
v_L = 0.d0
end if
if (qr(1) .gt. drytol ) then
v_R = qr(nv)/qr(1)
else
v_R = 0.d0
end if
if (ql(1).lt.drytol .and. qr(1).lt.drytol) then
v_av = 0.5d0 * (v_L+v_R)
else
v_av=(sqrt(g*ql(1))*v_L + sqrt(g*qr(1))*v_R) &
/(sqrt(g*qr(1))+sqrt(g*ql(1))) !ROE AV
end if
! overtop or not
! ghost state setup
if ( L2R .and. R2L ) then
! if wall is shorter than the bathymetry on the right
if ( aux_wall(2) .le. aux_wall(3) .or. wall_height.eq.0.d0) then
q_wall(1:3,2) = q_wall(1:3,3)
aux_wall(2) = aux_wall(3)
! if wall is shorter " " " " left
else if ( aux_wall(2) .le. aux_wall(1).or.wall_height.eq.0.d0 ) then
q_wall(1:3,2) = q_wall(1:3,1)
aux_wall(2) = aux_wall(1)
! wall is higher than both bathymetries
elseif (aux_wall(2).gt.aux_wall(1).and. &
aux_wall(2).gt.aux_wall(3)) then
diff2=aux_wall(2)-aux_wall(3)
diff1=aux_wall(2)-aux_wall(1)
q_wall(1,2)=min(q_wall(1,3)-diff2,q_wall(1,1)-diff1)
q_wall(mu,2)=min(q_wall(mu,3),q_wall(mu,1))
q_wall(nv,2)=min(q_wall(nv,3),q_wall(nv,1))!0.5d0*(q_wall(nv,3)+q_wall(nv,1))
end if
end if
! print *,"HTS:", q_wall(1,:)
! initialize amdq and apdq
amdq(1:3,:) = 0.d0
apdq(1:3,:) = 0.d0
q_wall_l = q_wall(:,1:2)
q_wall_r = q_wall(:,2:3)
aux_wall_l = aux_wall(1:2)
aux_wall_r = aux_wall(2:3)
! riemann problems
do i = 1, 2
hL = q_wall_l(1,i)
hR = q_wall_r(1,i)
huL = q_wall_l(mu,i)
huR = q_wall_r(mu,i)
bL = aux_wall_l(i)
bR = aux_wall_r(i)
delb = bR-bL
hvL = q_wall_l(nv,i)
hvR = q_wall_r(nv,i)
!check for wet/dry boundary
if (hR.gt.drytol) then
uR=huR/hR
vR=hvR/hR
phiR = 0.5d0*g*hR**2 + huR**2/hR
else
hR = 0.d0
huR = 0.d0
hvR = 0.d0
uR = 0.d0
vR = 0.d0
phiR = 0.d0
endif
if (hL.gt.drytol) then
uL=huL/hL
vL=hvL/hL
phiL = 0.5d0*g*hL**2 + huL**2/hL
else
hL=0.d0
huL=0.d0
hvL=0.d0
uL=0.d0
vL=0.d0
phiL = 0.d0
endif
! throw away the problem if there are no water at all
if (hL <= drytol .and. hR <= drytol) then
fwave(:,:,i) = 0.d0
s(:,i) = 0.d0
go to 30
endif
wall(1) = 1.d0
wall(2) = 1.d0
wall(3) = 1.d0
if (hR.le.drytol) then
call riemanntype(hL,hL,uL,-uL,hstar,um,s1m,s2m,&
rare1,rare2,1,drytol,g)
hstartest=max(hL,hstar)
! write(*,*) "slosh from left HIGHER THAN WALL", hstartest+bL.ge.bR
if (hstartest+bL.lt.bR) then !then !right state should become ghost values that mirror left for wall problem
! bR=hstartest+bL
wall(2)=0.d0
wall(3)=0.d0
hR=hL
huR=-huL
bR=bL
phiR=phiL
uR=-uL
hvR=hvL
vR=vL
elseif (hL+bL.le.bR) then
bR=hL+bL
endif
elseif (hL.le.drytol) then ! right surface is lower than left topo
call riemanntype(hR,hR,-uR,uR,hstar,um,s1m,s2m,&
rare1,rare2,1,drytol,g)
hstartest=max(hR,hstar)
! write(*,*) "slosh from rght HIGHER THAN WALL", hstartest+bR.ge.bL
if (hstartest+bR.lt.bL) then !left state should become ghost values that mirror right
! bL=hstartest+bR
wall(1)=0.d0
wall(2)=0.d0
hL=hR
huL=-huR
bL=bR
phiL=phiR
uL=-uR
hvL=hvR
vL=vR
elseif (hR+bR.le.bL) then
bL=hR+bR
endif
endif
!determine wave speeds
sL=uL-sqrt(g*hL) ! 1 wave speed of left state
sR=uR+sqrt(g*hR) ! 2 wave speed of right state
uhat=(sqrt(g*hL)*uL + sqrt(g*hR)*uR)/(sqrt(g*hR)+sqrt(g*hL)) ! Roe average
chat=sqrt(g*0.5d0*(hR+hL)) ! Roe average
sRoe1=uhat-chat ! Roe wave speed 1 wave
sRoe2=uhat+chat ! Roe wave speed 2 wave
sE1 = min(sL,sRoe1) ! Eindfeldt speed 1 wave
sE2 = max(sR,sRoe2) ! Eindfeldt speed 2 wave
!--------------------end initializing...finally----------
!solve Riemann problem.
!maxiter = 1
fwr = 0.d0
swr = 0.d0
pL = 0.d0
pR = 0.d0
call riemann_aug_JCP(1,3,3,hL,hR,huL,&
huR,hvL,hvR,bL,bR,uL,uR,vL,vR,phiL,phiR,sE1,sE2,&
drytol,g,swr,fwr)
! call riemann_ssqfwave(maxiter,meqn,mwaves,hL,hR,huL,huR,
! & hvL,hvR,bL,bR,uL,uR,vL,vR,phiL,phiR,pL,pR,sE1,sE2,drytol,g,
! & rho,sw,fw)
! call riemann_fwave(meqn,mwaves,hL,hR,huL,huR,hvL,hvR,&
! bL,bR,uL,uR,vL,vR,phiL,phiR,pL,pR,sE1,sE2,drytol,g,1.d0,swr,&
! fwr)
!eliminate ghost fluxes for wall
if (swr(2).lt.0.d0) then
wall(2) = wall(1)
else if (swr(2).gt.0.d0) then
wall(2) = wall(3)
else
wall(2) = 0.d0
end if
! print *, "WALL:", wall
do mw=1,3
s(mw,i)=swr(mw)*wall(mw)
fwave(1,mw,i)=fwr(1,mw)*wall(mw)
fwave(mu,mw,i)=fwr(2,mw)*wall(mw)
fwave(nv,mw,i)=fwr(3,mw)*wall(mw)
end do
! print *, "Spped: ", s(:,i)
30 continue
do mw=1,3
if (s(mw,i) < 0.d0) then
amdq(1:3,i) = amdq(1:3,i) + fwave(1:3,mw,i)
else if (s(mw,i) > 0.d0) then
apdq(1:3,i) = apdq(1:3,i) + fwave(1:3,mw,i)
else
amdq(1:3,i) = amdq(1:3,i) + 0.5d0 * fwave(1:3,mw,i)
apdq(1:3,i) = apdq(1:3,i) + 0.5d0 * fwave(1:3,mw,i)
endif
enddo
enddo
! print *,"AMDQ:", amdq
s_wall(1) = 0.5d0*(s(1,1)+s(1,2))!
s_wall(2) = 0.5d0*(s(2,1)+s(2,2))!
s_wall(3) = 0.5d0*(s(3,1)+s(3,2))!
if (.not. L2R .and. .not. R2L) then
s_wall(1) =minval(s)
s_wall(2) =0.d0
s_wall(3) =maxval(s)
end if
wave_wall = 0.d0
if ( s_wall(3)-s_wall(1)/=0.d0 ) then
! wave_wall(1,1) = (s_wall(3)*s_wall(2)*sum(fwave(1,:,:))&
! -(s_wall(2)+s_wall(3))*sum(fwave(mu,:,:)) + sum(fwave(nv,:,:))) /&
! ((s_wall(3)-s_wall(1))*(s_wall(2)-s_wall(1)))
! wave_wall(1,3) = (-(s_wall(2)+s_wall(1))*sum(fwave(mu,:,:) +&
! s_wall(2)*s_wall(1)*sum(fwave(1,:,:)+sum(fwave(nv,:,:))))) /&
! ((s_wall(3)-s_wall(1)*(s_wall(3)-s_wall(2))))
! wave_wall(1,2) = (s_wall(1)*s_wall(3)*sum(fwave(1,:,:) -&
! (s_wall(1)+s_wall(3))*sum(fwave(mu,:,:))+sum(fwave(nv,:,:)))) /&
! ((s_wall(2)-s_wall(3)*(s_wall(2)-s_wall(1))))
! wave_wall(mu,1) = wave_wall(1,1)*s_wall(1)
! wave_wall(nv,1) = wave_wall(2,1)*s_wall(1)
! wave_wall(mu,3) = wave_wall(1,3)*s_wall(3)
! wave_wall(nv,3) = wave_wall(2,3)*s_wall(3)
! wave_wall(mu,2) = wave_wall(1,2)*s_wall(2)
! wave_wall(nv,2) = wave_wall(2,2)*s_wall(2)
wave_wall(1,1)=(s_wall(3)*sum(fwave(1,:,:))-sum(fwave(mu,:,:)))&
/ (s_wall(3)-s_wall(1))
wave_wall(1,3)=(sum(fwave(mu,:,:))-s_wall(1)*sum(fwave(1,:,:)))&
/ (s_wall(3)-s_wall(1))
wave_wall(nv,2) = -v_av*sum(fwave(1,:,:)) + sum(fwave(nv,:,:))
wave_wall(mu,1) = wave_wall(1,1)*s_wall(1)
wave_wall(nv,1) = wave_wall(1,1)*v_av
wave_wall(mu,3) = wave_wall(1,3)*s_wall(3)
wave_wall(nv,3) = wave_wall(1,3)*v_av
end if
amdq_wall = 0.d0
apdq_wall = 0.d0
do mw=1,size(s_wall)
if ( s_wall(mw).lt.0.d0 ) then
amdq_wall(1:3) = amdq_wall(1:3) + wave_wall(:,mw)
else if (s_wall(mw).gt.0.d0) then
apdq_wall(1:3) = apdq_wall(1:3) + wave_wall(:,mw)
else
amdq_wall(1:3) = amdq_wall(1:3) + 0.5d0*wave_wall(:,mw)
apdq_wall(1:3) = apdq_wall(1:3) + 0.5d0*wave_wall(:,mw)
end if
end do
!
! print *, "AMDQ: ", amdq_wall
! print *, "APDQ: ", apdq_wall
! print *, "wavw:" ,fwave
end subroutine redistribute_fwave
function f(Q,ixy) result(F_vec)
implicit none
integer :: ixy,mu,nv
real(kind=8) :: Q(3),F_vec(3),grav
common /cparam/ grav
g = grav
drytol = dry_tolerance
if ( Q(1).lt.drytol ) then
F_vec(1:3) = 0.d0
return
else
if ( ixy==1 ) then
mu = 2
nv = 3
else
mu = 3
nv = 2
end if
F_vec(1) = Q(mu)
F_vec(mu) = (Q(mu)**2)/(Q(1)) + 0.5d0*g*Q(1)**2
F_vec(nv) = Q(nv)*Q(mu)/Q(1)
return
end if
end function f
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
function f_rot(q_rot,alpha,beta)
implicit none
real(8) :: alpha, beta
real(8) :: q_rot(3), f_rot(3)
f_rot = alpha*f(q_rot,1) + beta*f(q_rot,2)
end function
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
subroutine riemann_solver(ql,qr,bL,bR,s,fwave,amdq,apdq,ixy,ord,dtdxave,mthlim)
implicit none
integer :: ixy,ord,mthlim(3),i
real(8) :: dtdxave
real(8) :: ql(3,3),qr(3,3),bL(3),bR(3),s(3,3),fwave(3,3,3),amdq(3,3),apdq(3,3)
! local
real(8) :: swl(3),fwl(3,3),bLi,bRi
real(8) :: hL,hR,uL,um,uR,huL,huR,vL,vR,hvL,hvR,wall(3),phiL,phiR
integer :: mw,mu,nv,m
real(8) :: hstar,s1m,s2m,hstartest,sL,sR,uhat,chat,sRoe1,sRoe2
real(8) :: sE1,sE2,grav,dry_tolerance,g,drytol,cqxx(3,3)
logical :: rare1,rare2
common /cparam/ grav,dry_tolerance
g= grav
drytol = dry_tolerance
do i=1,3
do mw=1,3
s(mw,i)=0.d0
fwave(1,mw,i)=0.d0
fwave(2,mw,i)=0.d0
fwave(3,mw,i)=0.d0
enddo
! set normal direction
if (ixy.eq.1) then
mu=2
nv=3
else
mu=3
nv=2
endif
! zero (small) negative values if they exist
if (qr(1,i).lt.0.d0) then
qr(1,i)=0.d0
qr(2,i)=0.d0
qr(3,i)=0.d0
endif
if (ql(1,i).lt.0.d0) then
ql(1,i)=0.d0
ql(2,i)=0.d0
ql(3,i)=0.d0
endif
!skip problem if in a completely dry area
if (qr(1,i) <= drytol .and. ql(1,i) <= drytol) then
go to 30
endif
!Riemann problem variables
hL = ql(1,i)
hR = qr(1,i)
huL = ql(mu,i)
huR = qr(mu,i)
hvL=ql(nv,i)
hvR=qr(nv,i)
bLi = bL(i)
bRi = bR(i)
!check for wet/dry boundary
if (hR.gt.drytol) then
uR=huR/hR
vR=hvR/hR
phiR = 0.5d0*g*hR**2 + huR**2/hR
else
hR = 0.d0
huR = 0.d0
hvR = 0.d0
uR = 0.d0
vR = 0.d0
phiR = 0.d0
endif
if (hL.gt.drytol) then
uL=huL/hL
vL=hvL/hL
phiL = 0.5d0*g*hL**2 + huL**2/hL
else
hL=0.d0
huL=0.d0
hvL=0.d0
uL=0.d0
vL=0.d0
phiL = 0.d0
endif
wall(1) = 1.d0
wall(2) = 1.d0
wall(3) = 1.d0
if (hR.le.drytol) then
call riemanntype(hL,hL,uL,-uL,hstar,um,s1m,s2m,rare1,rare2,1,drytol,g)
hstartest=max(hL,hstar)
if (hstartest+bLi.lt.bRi) then !right state should become ghost values that mirror left for wall problem
! bR=hstartest+bL
wall(2)=0.d0
wall(3)=0.d0
hR=hL
huR=-huL
bRi=bLi
phiR=phiL
uR=-uL
vR=vL
elseif (hL+bLi.lt.bRi) then
bRi=hL+bLi
endif
elseif (hL.le.drytol) then ! right surface is lower than left topo
call riemanntype(hR,hR,-uR,uR,hstar,um,s1m,s2m,rare1,rare2,1,drytol,g)
hstartest=max(hR,hstar)
if (hstartest+bRi.lt.bLi) then !left state should become ghost values that mirror right
! bL=hstartest+bR
wall(1)=0.d0
wall(2)=0.d0
hL=hR
huL=-huR
bLi=bRi
phiL=phiR
uL=-uR
vL=vR
elseif (hR+bRi.lt.bLi) then
bLi=hR+bRi
endif
endif
!determine wave speeds
sL=uL-sqrt(g*hL) ! 1 wave speed of left state
sR=uR+sqrt(g*hR) ! 2 wave speed of right state
uhat=(sqrt(g*hL)*uL + sqrt(g*hR)*uR)/(sqrt(g*hR)+sqrt(g*hL)) ! Roe average
chat=sqrt(g*0.5d0*(hR+hL)) ! Roe average
sRoe1=uhat-chat ! Roe wave speed 1 wave
sRoe2=uhat+chat ! Roe wave speed 2 wave
sE1 = min(sL,sRoe1) ! Eindfeldt speed 1 wave
sE2 = max(sR,sRoe2) ! Eindfeldt speed 2 wave
!--------------------end initializing...finally----------
!solve Riemann problem.
call riemann_aug_JCP(1,3,3,hL,hR,huL, &
huR,hvL,hvR,bLi,bRi,uL,uR,vL,vR,phiL,phiR,sE1,sE2, &
drytol,g,swl,fwl)
! !eliminate ghost fluxes for wall
do mw=1,3
swl(mw)=swl(mw)*wall(mw)
fwl(1,mw)=fwl(1,mw)*wall(mw)
fwl(2,mw)=fwl(2,mw)*wall(mw)
fwl(3,mw)=fwl(3,mw)*wall(mw)
enddo
do mw=1,3
s(mw,i)=swl(mw)
fwave(1,mw,i)=fwl(1,mw)
fwave(mu,mw,i)=fwl(2,mw)
fwave(nv,mw,i)=fwl(3,mw)
enddo
30 continue
amdq(1:3,i) = 0.d0
apdq(1:3,i) = 0.d0
do mw=1,3
if (s(mw,i) < 0.d0) then
amdq(1:3,i) = amdq(1:3,i) + fwave(1:3,mw,i)
else if (s(mw,i) > 0.d0) then
apdq(1:3,i) = apdq(1:3,i) + fwave(1:3,mw,i)
else
amdq(1:3,i) = amdq(1:3,i) + 0.5d0 * fwave(1:3,mw,i)
apdq(1:3,i) = apdq(1:3,i) + 0.5d0 * fwave(1:3,mw,i)
endif
enddo
end do
if (ord .eq. 2 ) then
call lim(3,3,3,fwave,s,mthlim)
do i = 1, 3
! modified in Version 4.3 to use average only in cqxx, not transverse
do m=1,3
cqxx(m,i) = 0.d0
do mw=1,3
cqxx(m,i) = cqxx(m,i) + dabs(s(mw,i)) &
* (1.d0 - dabs(s(mw,i))*dtdxave) * fwave(m,mw,i)
enddo
amdq(m,i) = amdq(m,i) + 0.5d0 * cqxx(m,i)
apdq(m,i) = apdq(m,i) - 0.5d0 * cqxx(m,i)
enddo
enddo
end if
end subroutine
subroutine sec_ord_cor(fwave,s,mthlim,dtdxave,amdq,apdq)
implicit none
integer :: mthlim(3)
real(8) :: fwave(3,3,3), s(3,3), dtdxave
integer :: m,i,mw
real(8) :: cqxx(3,3), amdq(3,3),apdq(3,3)
call lim(3,3,3,fwave,s,mthlim)
do i = 1, 3
! modified in Version 4.3 to use average only in cqxx, not transverse
do m=1,3
cqxx(m,i) = 0.d0
do mw=1,3
cqxx(m,i) = cqxx(m,i) + dabs(s(mw,i)) &
* (1.d0 - dabs(s(mw,i))*dtdxave) * fwave(m,mw,i)
enddo
amdq(m,i) = amdq(m,i) + 0.5d0 * cqxx(m,i)
apdq(m,i) = apdq(m,i) - 0.5d0 * cqxx(m,i)
enddo
enddo
end subroutine
subroutine lim(num_eqn,num_waves,mx,wave,s,mthlim)
! =====================================================
! Apply a limiter to the waves.
! The limiter is computed by comparing the 2-norm of each wave with
! the projection of the wave from the interface to the left or
! right onto the current wave. For a linear system this would
! correspond to comparing the norms of the two waves. For a
! nonlinear problem the eigenvectors are not colinear and so the
! projection is needed to provide more limiting in the case where the
! neighboring wave has large norm but points in a different direction
! in phase space.
! The specific limiter used in each family is determined by the
! value of the corresponding element of the array mthlim, as used in
! the function philim.
! Note that a different limiter may be used in each wave family.
! dotl and dotr denote the inner product of wave with the wave to
! the left or right. The norm of the projections onto the wave are then
! given by dotl/wnorm2 and dotr/wnorm2, where wnorm2 is the 2-norm
! of wave.
implicit none
integer :: mw,num_waves,m,num_eqn,mx,i,mthlim(3)
real(8) :: wave(num_eqn,num_waves,mx)
real(8) :: s(num_waves,mx)
real(8) :: dotr,dotl,wnorm2,wlimitr
do mw=1,num_waves
if (mthlim(mw) == 0) cycle
dotr = 0.d0
do i = 1, mx
wnorm2 = 0.d0
dotl = dotr
dotr = 0.d0
do m=1,num_eqn
wnorm2 = wnorm2 + wave(m,mw,i)**2
dotr = dotr + wave(m,mw,i)*wave(m,mw,i+1)
end do
if (i == 0) cycle
if (wnorm2 == 0.d0) cycle
if (s(mw,i) > 0.d0) then
wlimitr = philim(wnorm2, dotl, mthlim(mw))
else
wlimitr = philim(wnorm2, dotr, mthlim(mw))
endif
do m=1,num_eqn
wave(m,mw,i) = wlimitr * wave(m,mw,i)
end do
end do
end do
return
end subroutine lim
function philim(a,b,meth)
! =====================================================
implicit none
real(8) :: a,b,philim
integer :: meth
real(8) :: r,c
! Compute a limiter based on wave strengths a and b.
! meth determines what limiter is used.
! a is assumed to be nonzero.
! NOTE: This routine is obsolete. Instead of using limiter.f,
! which calls philim.f for every wave, it is more efficient to
! use inlinelimiter.f, which eliminates all these function calls
! to philim. If you wish to change the limiter function and are
! using inlinelimiter.f, the formulas must be changed in that routine.
r = b/a
select case (meth)
case (1) ! minmod
philim = dmax1(0.d0, dmin1(1.d0, r))
case (2) ! superbee
philim = dmax1(0.d0, dmin1(1.d0, 2.d0*r), dmin1(2.d0, r))
case (3) ! van Leer
philim = (r + dabs(r)) / (1.d0 + dabs(r))
case (4) ! monotonized centered
c = (1.d0 + r)/2.d0
philim = dmax1(0.d0, dmin1(c, 2.d0, 2.d0*r))
case (5) ! Beam-Warming
philim = r
end select
return
end function
subroutine riemanntype(hL,hR,uL,uR,hm,um,s1m,s2m,rare1,rare2,&
maxiter,drytol,g)
!determine the Riemann structure (wave-type in each family)
implicit none
!input
real(8):: hL,hR,uL,uR,drytol,g
integer maxiter
!output
real(8):: s1m,s2m
logical rare1,rare2
!local
real(8):: hm,u1m,u2m,um,delu
real(8):: h_max,h_min,h0,F_max,F_min,dfdh,F0,slope,gL,gR
integer iter
h_min=min(hR,hL)
h_max=max(hR,hL)
delu=uR-uL
if (h_min.le.drytol) then
hm=0.d0
um=0.d0
s1m=uR+uL-2.d0*sqrt(g*hR)+2.d0*sqrt(g*hL)
s2m=uR+uL-2.d0*sqrt(g*hR)+2.d0*sqrt(g*hL)
if (hL.le.0.d0) then
rare2=.true.
rare1=.false.
else
rare1=.true.
rare2=.false.
endif
else
F_min= delu+2.d0*(sqrt(g*h_min)-sqrt(g*h_max))
F_max= delu + &
(h_max-h_min)*(sqrt(.5d0*g*(h_max+h_min)/(h_max*h_min)))
if (F_min.gt.0.d0) then !2-rarefactions
hm=(1.d0/(16.d0*g))* &
max(0.d0,-delu+2.d0*(sqrt(g*hL)+sqrt(g*hR)))**2
um=sign(1.d0,hm)*(uL+2.d0*(sqrt(g*hL)-sqrt(g*hm)))
s1m=uL+2.d0*sqrt(g*hL)-3.d0*sqrt(g*hm)
s2m=uR-2.d0*sqrt(g*hR)+3.d0*sqrt(g*hm)
rare1=.true.
rare2=.true.
elseif (F_max.le.0.d0) then !2 shocks
h0=h_max
do iter=1,maxiter
gL=sqrt(.5d0*g*(1/h0 + 1/hL))
gR=sqrt(.5d0*g*(1/h0 + 1/hR))
F0=delu+(h0-hL)*gL + (h0-hR)*gR
dfdh=gL-g*(h0-hL)/(4.d0*(h0**2)*gL)+ &
gR-g*(h0-hR)/(4.d0*(h0**2)*gR)
slope=2.d0*sqrt(h0)*dfdh
h0=(sqrt(h0)-F0/slope)**2
enddo
hm=h0
u1m=uL-(hm-hL)*sqrt((.5d0*g)*(1/hm + 1/hL))
u2m=uR+(hm-hR)*sqrt((.5d0*g)*(1/hm + 1/hR))
um=.5d0*(u1m+u2m)
s1m=u1m-sqrt(g*hm)
s2m=u2m+sqrt(g*hm)
rare1=.false.
rare2=.false.
else !one shock one rarefaction
h0=h_min
do iter=1,maxiter
F0=delu + 2.d0*(sqrt(g*h0)-sqrt(g*h_max)) &
+ (h0-h_min)*sqrt(.5d0*g*(1/h0+1/h_min))
slope=(F_max-F0)/(h_max-h_min)
h0=h0-F0/slope
enddo
hm=h0
if (hL.gt.hR) then
um=uL+2.d0*sqrt(g*hL)-2.d0*sqrt(g*hm)
s1m=uL+2.d0*sqrt(g*hL)-3.d0*sqrt(g*hm)
s2m=uL+2.d0*sqrt(g*hL)-sqrt(g*hm)
rare1=.true.
rare2=.false.
else
s2m=uR-2.d0*sqrt(g*hR)+3.d0*sqrt(g*hm)
s1m=uR-2.d0*sqrt(g*hR)+sqrt(g*hm)
um=uR-2.d0*sqrt(g*hR)+2.d0*sqrt(g*hm)
rare2=.true.
rare1=.false.
endif
endif
endif
return
end subroutine !riemanntype----------------------------------------------------------------
subroutine riemann_aug_JCP(maxiter,meqn,mwaves,hL,hR,huL,huR,&
hvL,hvR,bL,bR,uL,uR,vL,vR,phiL,phiR,sE1,sE2,drytol,g,&
sw,fw)
! solve shallow water equations given single left and right states
! This solver is described in J. Comput. Phys. (6): 3089-3113, March 2008
! Augmented Riemann Solvers for the Shallow Equations with Steady States and Inundation
! To use the original solver call with maxiter=1.
! This solver allows iteration when maxiter > 1. The iteration seems to help with
! instabilities that arise (with any solver) as flow becomes transcritical over variable topo
! due to loss of hyperbolicity.
implicit none
!input
integer meqn,mwaves,maxiter
real(8):: sw(3),fw(3,3)
real(8):: hL,hR,huL,huR,bL,bR,uL,uR,phiL,phiR,sE1,sE2
real(8):: hvL,hvR,vL,vR,pL,pR,um
real(8):: drytol,g,rho
!local
integer m,mw,k,iter
real(8):: A(3,3)
real(8):: r(3,3)
real(8):: lambda(3)
real(8):: del(3)
real(8):: beta(3)
real(8):: delh,delhu,delphi,delb,delnorm
real(8):: rare1st,rare2st,sdelta,raremin,raremax
real(8):: criticaltol,convergencetol,raretol
real(8):: criticaltol_2, hustar_interface
real(8):: s1s2bar,s1s2tilde,hbar,hLstar,hRstar,hustar
real(8):: huRstar,huLstar,uRstar,uLstar,hstarHLL
real(8):: deldelh,deldelphi,delP
real(8):: s1m,s2m,hm
real(8):: det1,det2,det3,determinant
logical rare1,rare2,rarecorrector,rarecorrectortest,sonic
!determine del vectors
delh = hR-hL
delhu = huR-huL
delphi = phiR-phiL
delb = bR-bL
delnorm = delh**2 + delphi**2
call riemanntype(hL,hR,uL,uR,hm,um,s1m,s2m,rare1,rare2,&
5,drytol,g)
! print *, "I make it here tho",sE1,s2m,sE2,s1m
lambda(1)= min(sE1,s2m) !Modified Einfeldt speed
lambda(3)= max(sE2,s1m) !Modified Eindfeldt speed
sE1=lambda(1)
sE2=lambda(3)
lambda(2) = 0.d0 ! ### Fix to avoid uninitialized value in loop on mw -- Correct?? ###
! print *, "lambda:", lambda
hstarHLL = max((huL-huR+sE2*hR-sE1*hL)/(sE2-sE1),0.d0) ! middle state in an HLL solve
! !determine the middle entropy corrector wave------------------------
rarecorrectortest=.false.
rarecorrector=.false.
if (rarecorrectortest) then
sdelta=lambda(3)-lambda(1)
raremin = 0.5d0
raremax = 0.9d0
if (rare1.and.sE1*s1m.lt.0.d0) raremin=0.2d0
if (rare2.and.sE2*s2m.lt.0.d0) raremin=0.2d0
if (rare1.or.rare2) then
!see which rarefaction is larger
rare1st=3.d0*(sqrt(g*hL)-sqrt(g*hm))
rare2st=3.d0*(sqrt(g*hR)-sqrt(g*hm))
if (max(rare1st,rare2st).gt.raremin*sdelta.and. &
max(rare1st,rare2st).lt.raremax*sdelta) then
rarecorrector=.true.
if (rare1st.gt.rare2st) then
lambda(2)=s1m
elseif (rare2st.gt.rare1st) then
lambda(2)=s2m
else
lambda(2)=0.5d0*(s1m+s2m)
endif
endif
endif
if (hstarHLL.lt.min(hL,hR)/5.d0) rarecorrector=.false.
endif
do mw=1,mwaves
r(1,mw)=1.d0
r(2,mw)=lambda(mw)
r(3,mw)=(lambda(mw))**2
enddo
if (.not.rarecorrector) then
lambda(2) = 0.5d0*(lambda(1)+lambda(3))
r(1,2)=0.d0
r(2,2)=0.d0
r(3,2)=1.d0
endif
!criticaltol = 1.d-6
! MODIFIED:
criticaltol = max(drytol*g, 1d-6)
criticaltol_2 = sqrt(criticaltol)
deldelh = -delb
deldelphi = -0.5d0 * (hR + hL) * (g * delb ) !+ delp / rho)
hLstar=hL
hRstar=hR
uLstar=uL
uRstar=uR
huLstar=uLstar*hLstar
huRstar=uRstar*hRstar
!iterate to better determine the steady state wave
convergencetol=1.d-6
do iter=1,maxiter
!determine steady state wave (this will be subtracted from the delta vectors)
if (min(hLstar,hRstar).lt.drytol.and.rarecorrector) then
rarecorrector=.false.
hLstar=hL
hRstar=hR
uLstar=uL
uRstar=uR
huLstar=uLstar*hLstar
huRstar=uRstar*hRstar
lambda(2) = 0.5d0*(lambda(1)+lambda(3))
r(1,2)=0.d0
r(2,2)=0.d0
r(3,2)=1.d0
endif
hbar = max(0.5d0*(hLstar+hRstar),0.d0)
s1s2bar = 0.25d0*(uLstar+uRstar)**2 - g*hbar
s1s2tilde= max(0.d0,uLstar*uRstar) - g*hbar
! MODIFIED from 5.3.1 version
sonic = .false.
if (abs(s1s2bar) <= criticaltol) then
sonic = .true.
else if (s1s2bar*s1s2tilde <= criticaltol**2) then
sonic = .true.
else if (s1s2bar*sE1*sE2 <= criticaltol**2) then
sonic = .true.
else if (min(abs(sE1),abs(sE2)) < criticaltol_2) then
sonic = .true.
else if (sE1 < criticaltol_2 .and. s1m > -criticaltol_2) then
sonic = .true.
else if (sE2 > -criticaltol_2 .and. s2m < criticaltol_2) then
sonic = .true.
else if ((uL+dsqrt(g*hL))*(uR+dsqrt(g*hR)) < 0.d0) then
sonic = .true.
else if ((uL- dsqrt(g*hL))*(uR- dsqrt(g*hR)) < 0.d0) then
sonic = .true.
end if
if (sonic) then
deldelh = -delb
else
deldelh = delb*g*hbar/s1s2bar
endif