-
Notifications
You must be signed in to change notification settings - Fork 0
/
explicit_euler.f08
792 lines (614 loc) · 27.6 KB
/
explicit_euler.f08
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
!*---------------------------------------------------------------------------*!
! |
! | SWMM Engine: Storm Water Management Model
! | Website: https://ehsanmadadi.com
! | Copyright (C) 2018-2020 Ehsan Madadi-Kandjani
!-------------------------------------------------------------------------------
!License
! This file is part of SWMM Engine.
! SWMM Engine 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, either version 3 of the License, or
! (at your option) any later version.
! SWMM Engine 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 SWMM Engine. If not, see <http://www.gnu.org/licenses/>.
!*---------------------------------------------------------------------------*!
!
!==========================================================================
!
module explicit_euler
!
use adjustments
use array_index
use bc
use data_keys
use element_dynamics
use element_geometry
use face_values
use globals
use setting_definition
use utility
implicit none
private
public :: explicit_euler_advance
public :: explicit_test_advance
integer, parameter :: idummy = 0
integer :: debuglevel = 0
contains
!
!==========================================================================
!==========================================================================
!
subroutine explicit_test_advance &
(elem2R, elem2I, elem2YN, &
elemMR, elemMI, elemMYN, &
faceR, faceI, faceYN, &
bcdataDn, bcdataUp, thistime, dt)
character(64) :: subroutine_name = 'explicit_euler_advance'
real, target, intent(in out) :: elem2R(:,:), elemMR(:,:), faceR(:,:)
integer, target, intent(in out) :: elem2I(:,:), elemMI(:,:), faceI(:,:)
logical, target, intent(in out) :: elem2YN(:,:), elemMYN(:,:), faceYN(:,:)
type(bcType), intent(in out) :: bcdataDn(:), bcdataUp(:)
real, intent(in) :: thistime, dt
integer :: e2r_Volume_new, e2r_Velocity_new, eMr_Volume_new, eMr_Velocity_new
real, pointer :: newvolume(:), newvelocity(:)
real, pointer :: volume(:), velocity(:), eta(:)
real, pointer :: depth(:), zbottom(:), perimeter(:), mn(:), rh(:), area(:)
real, pointer :: timesUp(:), timesDn(:), breadth(:), length(:), flowrate(:)
real, pointer :: Qface(:), Vup(:), Vdn(:), Aup(:), Adn(:), Eup(:), Edn(:)
! TEST 20190102
! real, pointer :: newarea(:), newflowrate(:)
integer, pointer :: fup(:), fdn(:), elemDn(:), elemUp(:), elemUp2(:)
integer :: fitmp
!--------------------------------------------------------------------------
if ((debuglevel > 0) .or. (debuglevelall > 0)) print *, '*** enter ',subroutine_name
! set indexes for temporary space
e2r_Volume_new = e2r_Temp(next_e2r_temparray)
next_e2r_temparray = utility_advance_temp_array (next_e2r_temparray,e2r_n_temp)
e2r_Velocity_new = e2r_Temp(next_e2r_temparray)
next_e2r_temparray = utility_advance_temp_array (next_e2r_temparray,e2r_n_temp)
fitmp = fi_Temp(next_fi_temparray)
next_fi_temparray = utility_advance_temp_array (next_fi_temparray,fi_n_temp)
eMr_Volume_new = 0
eMr_Velocity_new = 0
!TEST 20190102
newvolume => elem2R(:,e2r_Volume_new)
newvelocity => elem2R(:,e2r_Velocity_new)
! newarea => elem2R(:,e2r_Volume_new)
! newflowrate => elem2R(:,e2r_Velocity_new)
elemUp2 => faceI(:,fitmp)
volume => elem2R(:,e2r_Volume)
velocity => elem2R(:,e2r_Velocity)
flowrate => elem2R(:,e2r_Flowrate)
eta => elem2R(:,e2r_Eta)
mn => elem2R(:,e2r_Roughness)
rh => elem2R(:,e2r_HydRadius)
area => elem2R(:,e2r_Area)
depth => elem2R(:,e2r_HydDepth)
perimeter=> elem2R(:,e2r_Perimeter)
zbottom => elem2R(:,e2r_Zbottom)
length => elem2R(:,e2r_Length)
breadth => elem2R(:,e2r_BreadthScale)
timesUp => elem2R(:,e2r_Timescale_u)
timesDn => elem2R(:,e2r_Timescale_d)
Qface => faceR(:,fr_Flowrate)
Vup => faceR(:,fr_Velocity_u)
Vdn => faceR(:,fr_Velocity_d)
Aup => faceR(:,fr_Area_u)
Adn => faceR(:,fr_Area_d)
Eup => faceR(:,fr_Eta_u)
Edn => faceR(:,fr_Eta_d)
fup => elem2I(:,e2i_Mface_u)
fdn => elem2I(:,e2i_Mface_d)
!% using free surface as gA deta/dx
! where (elem2I(:,e2I_elem_type) == eChannel)
! newvolume = volume + dt * (Qface(fup) - Qface(fdn))
! newvelocity = (oneR / newvolume) &
! * ( &
! velocity*volume &
! + dt * ( Qface(fup) * Vdn(fup) - Qface(fdn) * Vup(fdn) &
! + grav * area * (Edn(fup) - Eup(fdn)) &
! - grav * volume * (mn**2) * (velocity**2) / (rh**(4.0/3.0)) &
! ) &
! )
! endwhere
!
!% using free surface as T00
where (elem2I(:,e2I_elem_type) == eChannel)
newvolume = volume + dt * (Qface(fup) - Qface(fdn))
! newvelocity = (oneR / newvolume) &
! * ( &
! velocity*volume &
! + dt * ( Qface(fup) * Vdn(fup) - Qface(fdn) * Vup(fdn) &
! + grav * ( Adn(fup)*Edn(fup) - Aup(fdn)*Eup(fdn)) &
! + grav * ( Aup(fdn) - Adn(fup) ) * eta &
! - grav * volume * (mn**2) * (velocity**2) / (rh**(4.0/3.0)) &
! ) &
! )
newvelocity = (oneR / (newvolume*(oneR + dt * grav * (mn**2) * velocity / (rh**(4.0/3.0)) ))) &
* ( &
velocity*volume &
+ dt * ( Qface(fup) * Vdn(fup) - Qface(fdn) * Vup(fdn) &
+ grav * ( Adn(fup)*Edn(fup) - Aup(fdn)*Eup(fdn)) &
+ grav * ( Aup(fdn) - Adn(fup) ) * eta &
) &
)
endwhere
! AREA/FLOWRATE TEST 20180102
! print *, 'flow start :',flowrate(1:3)
! print *, 'qface start:',Qface(1:3)
! print *, 'Edn start:',Edn(1:3)
! print *, 'Eup start:',Eup(1:3)
! where (elem2I(:,e2I_elem_type) == eChannel)
! newarea = area + dt * (Qface(fup) - Qface(fdn)) / length ! now area
! ! now flowrate
! newflowrate = flowrate + &
! ( ( &
! + dt * ( Qface(fup) * Vdn(fup) - Qface(fdn) * Vup(fdn) &
! + grav * ( Adn(fup)*Edn(fup) - Aup(fdn)*Eup(fdn)) &
! + grav * ( Aup(fdn) - Adn(fup) ) * eta &
! ) &
! ) / length) - dt * grav * (mn**2) * (flowrate**2) / ( area * rh**(4.0/3.0))
! endwhere
!
! where (elem2I(:,e2I_elem_type) == eChannel)
! newarea = area + dt * (Qface(fup) - Qface(fdn)) / length ! now area
! ! now flowrate
! newflowrate = (flowrate + &
! ( ( &
! + dt * ( Qface(fup) * Vdn(fup) - Qface(fdn) * Vup(fdn) &
! + grav * ( Adn(fup)*Edn(fup) - Aup(fdn)*Eup(fdn)) &
! + grav * ( Aup(fdn) - Adn(fup) ) * eta &
! ) &
! ) / length)) / (1 + dt * grav * (mn**2) * (flowrate) / ( area * rh**(4.0/3.0)) )
! endwhere
!
! print *, 'new flow ',newflowrate(1:3)
! !print *, 'qface: ',Qface(size(Qface)-3:size(Qface))
! !print *, 'flowrate: ',flowrate(size(flowrate)-3:size(flowrate))
! where (elem2I(:,e2I_elem_type) == eChannel)
! newarea = dt * ( Qface(fup) * Vdn(fup) - Qface(fdn) * Vup(fdn) ) / length
! endwhere
! print *, '1 line ',newarea(1:3)
! where (elem2I(:,e2I_elem_type) == eChannel)
! ! newarea = dt * grav * ( Adn(fup)*Edn(fup) - Aup(fdn)*Eup(fdn)) / length
! newarea = Aup(fdn)*Eup(fdn)
! endwhere
!! print *, '2 line ',newarea(1:3)
! print *, fup(1:3)
! print *, fdn(1:3)
! print *, 'Adn ',Adn(1:3)
! print *, 'Aup ',Aup(1:3)
! print *, 'Edn ',Edn(1:3)
! print *, 'Eup ',Eup(1:3)
!! print *, Adn(fup(1:3))
!! print *, Edn(fup(1:3))
!! print *, Aup(fdn(1:3))
!! print *, Eup(fdn(1:3))
!! print *, fdn(1:3)
!! print *, fup(1:3)
!stop
! where (elem2I(:,e2I_elem_type) == eChannel)
! newarea = dt * grav * ( Aup(fdn) - Adn(fup) ) * eta / length
! endwhere
! print *, '3 line ',newarea(1:3)
! where (elem2I(:,e2I_elem_type) == eChannel)
! newarea = dt * grav * area * (mn**2) * (velocity**2) / (rh**(4.0/3.0))
! endwhere
! print *, '4 line ',newarea(1:3)
! print *, 'new flow ',newflowrate(1:3)
!
! stop
!
!! AREA/FLOWRATE TEST 20180102
!
!% using free surface as T10
! where (elem2I(:,e2I_elem_type) == eChannel)
! newvolume = volume + dt * (Qface(fup) - Qface(fdn))
! newvelocity = (oneR / newvolume) &
! * ( &
! velocity*volume &
! + dt * ( Qface(fup) * Vdn(fup) - Qface(fdn) * Vup(fdn) &
! + onehalfR * grav * ( Adn(fup)*Edn(fup) - Aup(fdn)*Eup(fdn) ) &
! + onehalfR * grav * ( Aup(fdn)*Edn(fup) - Adn(fup)*Eup(fdn) ) &
! - grav * volume * (mn**2) * (velocity**2) / (rh**(4.0/3.0)) &
! ) &
! )
! endwhere
!
!% update geometry and dynamics on element
where (elem2I(:,e2I_elem_type) == eChannel)
volume = newvolume
velocity = newvelocity
area = volume / length
flowrate = velocity * area
depth = area / breadth
perimeter = twoR * depth + breadth
eta = depth + zbottom
rh = area / perimeter
!timesUp = -onehalfR * length / (velocity - sqrt(grav * depth))
!timesDn = +onehalfR * length / (velocity + sqrt(grav * depth))
endwhere
!! AREA/FLOWRATE TEST 20180102
! where (elem2I(:,e2I_elem_type) == eChannel)
! volume = newarea * length !test
! velocity = newflowrate / newarea
! area = newarea !renaming
! flowrate = newflowrate
! depth = area / breadth
! perimeter = twoR * depth + breadth
! eta = depth + zbottom
! rh = area / perimeter
! !timesUp = -onehalfR * length / (velocity - sqrt(grav * depth))
! !timesDn = +onehalfR * length / (velocity + sqrt(grav * depth))
! endwhere
!!! AREA/FLOWRATE TEST 20180102
! BC updates
!call bc_applied_onelement (elem2R, bcdataDn, bcdataUp, thistime+dt, bc_category_elevation,idummy)
call bc_applied_onelement (elem2R, bcdataDn, bcdataUp, thistime+dt, bc_category_inflowrate,e2r_Velocity)
call bc_applied_onelement (elem2R, bcdataDn, bcdataUp, thistime+dt, bc_category_elevation, idummy)
! print *, 'after bc on element'
! print *, 'new flow ',flowrate(size(flowrate)-3:size(flowrate))
! print *, 'Qface ',Qface(size(Qface)-3:size(Qface))
!
call test_face_update (elem2R, elem2I, faceR, faceI, elemUp2)
! print *, 'after face update'
! print *, 'new flow ',flowrate(size(flowrate)-3:size(flowrate))
! print *, 'Qface ',Qface(size(Qface)-3:size(Qface))
! call quadratic_face_update (elem2R, elem2I, faceR, faceI, elemUp2)
! BC applied on face
call bc_applied_onface (faceR, faceI, elem2R, elem2I, bcdataDn, bcdataUp, e2r_Velocity_new, thistime+dt)
! print *, 'after bc on face'
! print *, 'new flow ',flowrate(size(flowrate)-3:size(flowrate))
! print *, 'Qface ',Qface(size(Qface)-3:size(Qface))
! BC extrapolated - moved into bc_applied_onface
! call bc_face_othervalues (faceR, faceI, elem2R, bcdataDn)
! call bc_face_othervalues (faceR, faceI, elem2R, bcdataUp)
if (setting%Method%AdjustVshapedFlowrate%Apply) then
call adjust_Vshaped_flowrate (elem2R, faceR, elem2I, elem2YN)
endif
! set velocities and upstream values on faces (without hydraulic jump)
call adjust_face_dynamic_limits &
(faceR, faceI, newvolume, newvolume, &
( (faceI(:,fi_etype_u) == eChannel) .and. (faceI(:,fi_etype_d) == eChannel) ), .false. )
!call bc_applied (faceR, bcdataDn, bcdataUp, thistime+dt)
!print *, elem2R(elemDn ,e2r_Flowrate)
!print *, faceR(:,fr_Flowrate)
!print *, faceR(:,fr_Area_u)
!print *, faceR(:,fr_Eta_u)
!print *, faceR(:,fr_Velocity_u)
!print *, elem2R(elemUp ,e2r_Flowrate)
!print *, elem2R(elemUp2,e2r_Flowrate)
! reset temporary data space
elem2R(:,e2r_Volume_new) = nullvalueR
elem2R(:,e2r_Velocity_new) = nullvalueR
next_e2r_temparray = next_e2r_temparray - 2
next_fi_temparray = next_fi_temparray - 1
if ((debuglevel > 0) .or. (debuglevelall > 0)) print *, '*** leave ',subroutine_name
end subroutine explicit_test_advance
!
!==========================================================================
!==========================================================================
!
subroutine test_face_update &
(elem2R, elem2I, faceR, faceI, elemUp2)
character(64) :: subroutine_name = 'test_face_update'
real, target, intent(in out) :: elem2R(:,:), faceR(:,:)
integer, target, intent(in out) :: elem2I(:,:), faceI(:,:)
integer, intent(in out) :: elemUp2(:)
integer, pointer :: elemUp(:), elemDn(:)
real, pointer :: tscaleUp(:), tscaleDn(:), wavespeed(:)
integer :: e2r_wavespeed
!--------------------------------------------------------------------------
if ((debuglevel > 0) .or. (debuglevelall > 0)) print *, '*** enter ',subroutine_name
e2r_wavespeed = e2r_Temp(next_e2r_temparray)
next_e2r_temparray = utility_advance_temp_array (next_e2r_temparray,e2r_n_temp)
!% compute wavespeed
wavespeed => elem2R(:,e2r_wavespeed)
wavespeed = sqrt(grav * elem2R(:,e2r_HydDepth))
tscaleUp => elem2R(:,e2r_Timescale_u)
tscaleDn => elem2R(:,e2r_Timescale_d)
tscaleUp = + (onehalfR * elem2R(:,e2r_Length) ) / (wavespeed - elem2R(:,e2r_Velocity))
tscaleDn = + (onehalfR * elem2R(:,e2r_Length) ) / (wavespeed + elem2R(:,e2r_Velocity))
where (tscaleUp < zeroR )
tscaleUp = setting%Limiter%Timescale%Maximum
endwhere
where (tscaleDn < zeroR )
tscaleDn = setting%Limiter%Timescale%Maximum
endwhere
where (tscaleUp < setting%Limiter%Timescale%Minimum)
tscaleUp = setting%Limiter%Timescale%Minimum
endwhere
where (tscaleDn < setting%Limiter%Timescale%Minimum)
tscaleDn = setting%Limiter%Timescale%Minimum
endwhere
where (tscaleUp > setting%Limiter%Timescale%Maximum)
tscaleUp = setting%Limiter%Timescale%Maximum
endwhere
where (tscaleDn > setting%Limiter%Timescale%Maximum)
tscaleDn = setting%Limiter%Timescale%Maximum
endwhere
!wavespeed = tscaleUp + tscaleDn
!tscaleUp = tscaleUp/wavespeed
!tscaleDn = tscaleDn/wavespeed
!% get map to upstream for a quadratic interp
elemUp => faceI(:,fi_Melem_u)
elemDn => faceI(:,fi_Melem_d)
where (elemUp > size(elemUp))
elemUp = size(elemUp)
endwhere
elemUp2 = elemUp
where ((faceI(:,fi_etype_u) == fChannel) .and. (faceI(:,fi_etype_d) == fChannel))
elemUp2 = elem2I(elemUp,e2i_Mface_u)
endwhere
where (elemUp2 > size(elemUp2))
elemUp2 = size(elemUp2)
endwhere
where (elemUp2 < 1)
elemUp2 = 1
endwhere
elemUp2 = faceI(elemUp2,fi_Melem_u)
where (elemUp2 > size(elemUp2))
elemUp2 = size(elemUp2)
endwhere
! print *, elemDn
! print *, elemUp
! print *, elemUp2
! print *, size(faceI,1), size(elemDn), size(elemUp), size(elemUp2)
where( (faceI(:,fi_etype_u) == fChannel) .and. (faceI(:,fi_etype_d) == fChannel))
faceR(:,fr_Flowrate) = 0.375 * elem2R(elemDn ,e2r_Flowrate) &
+ 0.75 * elem2R(elemUp ,e2r_Flowrate) &
- 0.125 * elem2R(elemUp2,e2r_Flowrate)
! faceR(:,fr_Flowrate) = 0.5 * elem2R(elemDn ,e2r_Flowrate) &
! + 0.5 * elem2R(elemUp ,e2r_Flowrate)
! faceR(:,fr_Flowrate) = ( tscaleDn(elemUp) * elem2R(elemDn ,e2r_Flowrate) &
! + tscaleUp(elemDn) * elem2R(elemUp ,e2r_Flowrate)) &
! /( tscaleDn(elemUp) + tscaleUp(elemDn))
faceR(:,fr_Velocity_d) = 0.375 * elem2R(elemDn ,e2r_Velocity) &
+ 0.75 * elem2R(elemUp ,e2r_Velocity) &
- 0.125 * elem2R(elemUp2,e2r_Velocity)
! faceR(:,fr_Velocity_d) = 0.5 * elem2R(elemDn ,e2r_Velocity) &
! + 0.5 * elem2R(elemUp ,e2r_Velocity)
! faceR(:,fr_Velocity_d) = ( tscaleDn(elemDn) * elem2R(elemDn ,e2r_Velocity) &
! + tscaleUp(elemUp) * elem2R(elemUp ,e2r_Velocity)) &
! /( tscaleDn(elemUp) + tscaleUp(elemDn))
faceR(:,fr_Area_d) = 0.375 * elem2R(elemDn ,e2r_Area) &
+ 0.75 * elem2R(elemUp ,e2r_Area) &
- 0.125 * elem2R(elemUp2,e2r_Area)
! faceR(:,fr_Area_d) = 0.5 * elem2R(elemDn ,e2r_Area) &
! + 0.5 * elem2R(elemUp ,e2r_Area)
! faceR(:,fr_Area_d) = ( tscaleDn(elemUp) * elem2R(elemDn ,e2r_Area) &
! + tscaleUp(elemDn) * elem2R(elemUp ,e2r_Area) ) &
! /( tscaleDn(elemUp) + tscaleUp(elemDn))
!faceR(:,fr_Eta_d) = 0.375 * elem2R(elemDn ,e2r_Eta) &
! + 0.75 * elem2R(elemUp ,e2r_Eta) &
! - 0.125 * elem2R(elemUp2,e2r_Eta)
faceR(:,fr_Eta_d) = 0.5 * elem2R(elemDn ,e2r_Eta) &
+ 0.5 * elem2R(elemUp ,e2r_Eta)
faceR(:,fr_Topwidth) = 0.375 * elem2R(elemDn ,e2r_Topwidth) &
+ 0.75 * elem2R(elemUp ,e2r_Topwidth) &
- 0.125 * elem2R(elemUp2,e2r_Topwidth)
! faceR(:,fr_Topwidth) = 0.5 * elem2R(elemDn ,e2r_Topwidth) &
! + 0.5 * elem2R(elemUp ,e2r_Topwidth)
! faceR(:,fr_Topwidth) = ( tscaleDn(elemUp) * elem2R(elemDn ,e2r_Topwidth) &
! + tscaleUp(elemDn) * elem2R(elemUp ,e2r_Topwidth) ) &
! /( tscaleDn(elemUp) + tscaleUp(elemDn))
faceR(:,fr_Eta_u) = faceR(:,fr_Eta_d)
faceR(:,fr_Area_u) = faceR(:,fr_Area_d)
faceR(:,fr_Velocity_u) = faceR(:,fr_Velocity_d)
endwhere
!% reset temporary space
elem2R(:,e2r_wavespeed) = nullvalueR
next_e2r_temparray = next_e2r_temparray - 1
if ((debuglevel > 0) .or. (debuglevelall > 0)) print *, '*** leave ',subroutine_name
end subroutine test_face_update
!
!==========================================================================
!==========================================================================
!
subroutine quadratic_face_update &
(elem2R, elem2I, faceR, faceI, elemUp2)
character(64) :: subroutine_name = 'quadratic_face_update'
real, target, intent(in out) :: elem2R(:,:), faceR(:,:)
integer, target, intent(in out) :: elem2I(:,:), faceI(:,:)
integer, intent(in out) :: elemUp2(:)
integer, pointer :: elemUp(:), elemDn(:)
!--------------------------------------------------------------------------
if ((debuglevel > 0) .or. (debuglevelall > 0)) print *, '*** enter ',subroutine_name
! get map to upstream for a quadratic interp
elemUp => faceI(:,fi_Melem_u)
elemDn => faceI(:,fi_Melem_d)
where (elemUp > size(elemUp))
elemUp = size(elemUp)
endwhere
elemUp2 = elemUp
where ((faceI(:,fi_etype_u) == fChannel) .and. (faceI(:,fi_etype_d) == fChannel))
elemUp2 = elem2I(elemUp,e2i_Mface_u)
endwhere
where (elemUp2 > size(elemUp2))
elemUp2 = size(elemUp2)
endwhere
where (elemUp2 < 1)
elemUp2 = 1
endwhere
elemUp2 = faceI(elemUp2,fi_Melem_u)
where (elemUp2 > size(elemUp2))
elemUp2 = size(elemUp2)
endwhere
! print *, elemDn
! print *, elemUp
! print *, elemUp2
! print *, size(faceI,1), size(elemDn), size(elemUp), size(elemUp2)
where( (faceI(:,fi_etype_u) == fChannel) .and. (faceI(:,fi_etype_d) == fChannel))
faceR(:,fr_Flowrate) = 0.375 * elem2R(elemDn ,e2r_Flowrate) &
+ 0.75 * elem2R(elemUp ,e2r_Flowrate) &
- 0.125 * elem2R(elemUp2,e2r_Flowrate)
faceR(:,fr_Velocity_d) = 0.375 * elem2R(elemDn ,e2r_Velocity) &
+ 0.75 * elem2R(elemUp ,e2r_Velocity) &
- 0.125 * elem2R(elemUp2,e2r_Velocity)
faceR(:,fr_Area_d) = 0.375 * elem2R(elemDn ,e2r_Area) &
+ 0.75 * elem2R(elemUp ,e2r_Area) &
- 0.125 * elem2R(elemUp2,e2r_Area)
!faceR(:,fr_Eta_d) = 0.375 * elem2R(elemDn ,e2r_Eta) &
! + 0.75 * elem2R(elemUp ,e2r_Eta) &
! - 0.125 * elem2R(elemUp2,e2r_Eta)
faceR(:,fr_Eta_d) = 0.5 * elem2R(elemDn ,e2r_Eta) &
+ 0.5 * elem2R(elemUp ,e2r_Eta)
faceR(:,fr_Topwidth) = 0.375 * elem2R(elemDn ,e2r_Topwidth) &
+ 0.75 * elem2R(elemUp ,e2r_Topwidth) &
- 0.125 * elem2R(elemUp2,e2r_Topwidth)
faceR(:,fr_Eta_u) = faceR(:,fr_Eta_d)
faceR(:,fr_Area_u) = faceR(:,fr_Area_d)
faceR(:,fr_Velocity_u) = faceR(:,fr_Velocity_d)
endwhere
if ((debuglevel > 0) .or. (debuglevelall > 0)) print *, '*** leave ',subroutine_name
end subroutine quadratic_face_update
!
!==========================================================================
!==========================================================================
!
subroutine explicit_euler_advance &
(elem2R, elem2I, elem2YN, &
elemMR, elemMI, elemMYN, &
faceR, faceI, faceYN, &
bcdataDn, bcdataUp, thistime, dt)
character(64) :: subroutine_name = 'explicit_euler_advance'
real, target, intent(in out) :: elem2R(:,:), elemMR(:,:), faceR(:,:)
integer, target, intent(in out) :: elem2I(:,:), elemMI(:,:), faceI(:,:)
logical, target, intent(in out) :: elem2YN(:,:), elemMYN(:,:), faceYN(:,:)
type(bcType), intent(in out) :: bcdataDn(:), bcdataUp(:)
real, intent(in) :: thistime, dt
integer :: e2r_Volume_new, e2r_Velocity_new, eMr_Volume_new, eMr_Velocity_new
real, pointer :: newvolume(:), newvelocity(:), volume(:), velocity(:), eta(:)
real, pointer :: depth(:), zbottom(:), perimeter(:), mn(:), rh(:), area(:)
real, pointer :: timesUp(:), timesDn(:), breadth(:), length(:), flowrate(:)
real, pointer :: Qface(:), Vup(:), Vdn(:), Aup(:), Adn(:), Eup(:), Edn(:)
integer, pointer :: fup(:), fdn(:), elemDn(:), elemUp(:), elemUp2(:)
integer :: fitmp
!--------------------------------------------------------------------------
if ((debuglevel > 0) .or. (debuglevelall > 0)) print *, '*** enter ',subroutine_name
! set indexes for temporary space
e2r_Volume_new = e2r_Temp(next_e2r_temparray)
next_e2r_temparray = utility_advance_temp_array (next_e2r_temparray,e2r_n_temp)
e2r_Velocity_new = e2r_Temp(next_e2r_temparray)
next_e2r_temparray = utility_advance_temp_array (next_e2r_temparray,e2r_n_temp)
fitmp = fi_Temp(next_fi_temparray)
next_fi_temparray = utility_advance_temp_array (next_fi_temparray,fi_n_temp)
eMr_Volume_new = 0
eMr_Velocity_new = 0
newvolume => elem2R(:,e2r_Volume_new)
newvelocity => elem2R(:,e2r_Velocity_new)
elemUp2 => faceI(:,fitmp)
volume => elem2R(:,e2r_Volume)
velocity => elem2R(:,e2r_Velocity)
flowrate => elem2R(:,e2r_Flowrate)
eta => elem2R(:,e2r_Eta)
mn => elem2R(:,e2r_Roughness)
rh => elem2R(:,e2r_HydRadius)
area => elem2R(:,e2r_Area)
depth => elem2R(:,e2r_HydDepth)
perimeter=> elem2R(:,e2r_Perimeter)
zbottom => elem2R(:,e2r_Zbottom)
length => elem2R(:,e2r_Length)
breadth => elem2R(:,e2r_BreadthScale)
timesUp => elem2R(:,e2r_Timescale_u)
timesDn => elem2R(:,e2r_Timescale_d)
Qface => faceR(:,fr_Flowrate)
Vup => faceR(:,fr_Velocity_u)
Vdn => faceR(:,fr_Velocity_d)
Aup => faceR(:,fr_Area_u)
Adn => faceR(:,fr_Area_d)
Eup => faceR(:,fr_Eta_u)
Edn => faceR(:,fr_Eta_d)
fup => elem2I(:,e2i_Mface_u)
fdn => elem2I(:,e2i_Mface_d)
where (elem2I(:,e2I_elem_type) == eChannel)
newvolume = volume + dt * (Qface(fup) - Qface(fdn))
newvelocity = (oneR / newvolume) &
* ( &
velocity*volume &
+ dt * ( Qface(fup) * Vdn(fup) - Qface(fdn) * Vup(fdn) &
+ grav * area * (Edn(fup) - Eup(fdn)) &
- grav * volume * (mn**2) * (velocity**2) / (rh**(4.0/3.0)) &
) &
)
endwhere
where (elem2I(:,e2I_elem_type) == eChannel)
volume = newvolume
velocity = newvelocity
area = volume / length
flowrate = velocity * area
depth = area / breadth
perimeter = twoR * depth + breadth
eta = depth + zbottom
rh = area / perimeter
timesUp = -onehalfR * length / (velocity - sqrt(grav * depth))
timesDn = +onehalfR * length / (velocity + sqrt(grav * depth))
endwhere
call bc_applied_onelement (elem2R, bcdataDn, bcdataUp, thistime+dt, bc_category_elevation,idummy)
call bc_applied_onelement (elem2R, bcdataDn, bcdataUp, thistime+dt, bc_category_inflowrate,e2r_Velocity_new)
! get map to upstream for a quadratic interp
elemUp => faceI(:,fi_Melem_u)
elemDn => faceI(:,fi_Melem_d)
where (elemUp > size(elemUp))
elemUp = size(elemUp)
endwhere
elemUp2 = elemUp
where ((faceI(:,fi_etype_u) == fChannel) .and. (faceI(:,fi_etype_d) == fChannel))
elemUp2 = elem2I(elemUp,e2i_Mface_u)
endwhere
where (elemUp2 > size(elemUp2))
elemUp2 = size(elemUp2)
endwhere
where (elemUp2 < 1)
elemUp2 = 1
endwhere
elemUp2 = faceI(elemUp2,fi_Melem_u)
where (elemUp2 > size(elemUp2))
elemUp2 = size(elemUp2)
endwhere
where( (faceI(:,fi_etype_u) == fChannel) .and. (faceI(:,fi_etype_d) == fChannel))
faceR(:,fr_Flowrate) = 0.375 * elem2R(elemDn ,e2r_Flowrate) &
+ 0.75 * elem2R(elemUp ,e2r_Flowrate) &
- 0.125 * elem2R(elemUp2,e2r_Flowrate)
faceR(:,fr_Velocity_d) = 0.375 * elem2R(elemDn ,e2r_Velocity) &
+ 0.75 * elem2R(elemUp ,e2r_Velocity) &
- 0.125 * elem2R(elemUp2,e2r_Velocity)
faceR(:,fr_Area_d) = 0.375 * elem2R(elemDn ,e2r_Area) &
+ 0.75 * elem2R(elemUp ,e2r_Area) &
- 0.125 * elem2R(elemUp2,e2r_Area)
!faceR(:,fr_Eta_d) = 0.375 * elem2R(elemDn ,e2r_Eta) &
! + 0.75 * elem2R(elemUp ,e2r_Eta) &
! - 0.125 * elem2R(elemUp2,e2r_Eta)
faceR(:,fr_Eta_d) = 0.5 * elem2R(elemDn ,e2r_Eta) &
+ 0.5 * elem2R(elemUp ,e2r_Eta)
faceR(:,fr_Topwidth) = 0.375 * elem2R(elemDn ,e2r_Topwidth) &
+ 0.75 * elem2R(elemUp ,e2r_Topwidth) &
- 0.125 * elem2R(elemUp2,e2r_Topwidth)
faceR(:,fr_Eta_u) = faceR(:,fr_Eta_d)
faceR(:,fr_Area_u) = faceR(:,fr_Area_d)
faceR(:,fr_Velocity_u) = faceR(:,fr_Velocity_d)
endwhere
call bc_applied_onface (faceR, faceI, elem2R, elem2I, bcdataDn, bcdataUp, e2r_Velocity_new, thistime+dt)
if (setting%Method%AdjustVshapedFlowrate%Apply) then
call adjust_Vshaped_flowrate (elem2R, faceR, elem2I, elem2YN)
endif
!call bc_applied (faceR, bcdataDn, bcdataUp, thistime+dt)
!call bc_face_othervalues (faceR, faceI, elem2R, bcdataDn)
!call bc_face_othervalues (faceR, faceI, elem2R, bcdataUp)
! reset temporary data space
elem2R(:,e2r_Volume_new) = nullvalueR
elem2R(:,e2r_Velocity_new) = nullvalueR
next_e2r_temparray = next_e2r_temparray - 2
next_fi_temparray = next_fi_temparray - 1
if ((debuglevel > 0) .or. (debuglevelall > 0)) print *, '*** leave ',subroutine_name
end subroutine explicit_euler_advance
!
!==========================================================================
! END OF MODULE explicit_euler
!==========================================================================
end module explicit_euler