-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathoce_adv_tra_hor.F90
More file actions
835 lines (761 loc) · 40.9 KB
/
Copy pathoce_adv_tra_hor.F90
File metadata and controls
835 lines (761 loc) · 40.9 KB
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
!===============================================================================================================================
!**************** routines for horizontal tracer advection ***********************
module oce_adv_tra_hor_interfaces
interface
! (low order upwind)
! returns flux given at edges which contributes with
! plus sign into 1st. node and with the minus sign into the 2nd node
! IF init_zero=.TRUE. : flux will be set to zero before computation
! IF init_zero=.FALSE. : flux=flux-input flux
! flux is not multiplied with dt
subroutine adv_tra_hor_upw1(vel, ttf, partit, mesh, flux, o_init_zero)
use MOD_MESH
use MOD_TRACER
USE MOD_PARTIT
USE MOD_PARSUP
type(t_partit),intent(in), target :: partit
type(t_mesh), intent(in), target :: mesh
real(kind=WP), intent(in) :: ttf( mesh%nl-1, partit%myDim_nod2D+partit%eDim_nod2D)
real(kind=WP), intent(in) :: vel(2, mesh%nl-1, partit%myDim_elem2D+partit%eDim_elem2D)
real(kind=WP), intent(inout) :: flux( mesh%nl-1, partit%myDim_edge2D)
logical, optional :: o_init_zero
end subroutine adv_tra_hor_upw1
!===============================================================================
! MUSCL
! returns flux given at edges which contributes with
! plus sign into 1st. node and with the minus sign into the 2nd node
! IF init_zero=.TRUE. : flux will be set to zero before computation
! IF init_zero=.FALSE. : flux=flux-input flux
! flux is not multiplied with dt
subroutine adv_tra_hor_muscl(vel, ttf, partit, mesh, num_ord, flux, edge_up_dn_grad, nboundary_lay, o_init_zero)
use MOD_MESH
USE MOD_PARTIT
USE MOD_PARSUP
type(t_partit),intent(in), target :: partit
type(t_mesh), intent(in), target :: mesh
real(kind=WP), intent(in) :: num_ord ! num_ord is the fraction of fourth-order contribution in the solution
real(kind=WP), intent(in) :: ttf( mesh%nl-1, partit%myDim_nod2D+partit%eDim_nod2D)
real(kind=WP), intent(in) :: vel(2, mesh%nl-1, partit%myDim_elem2D+partit%eDim_elem2D)
real(kind=WP), intent(inout) :: flux( mesh%nl-1, partit%myDim_edge2D)
integer, intent(in) :: nboundary_lay(partit%myDim_nod2D+partit%eDim_nod2D)
real(kind=WP), intent(in) :: edge_up_dn_grad(4, mesh%nl-1, partit%myDim_edge2D)
logical, optional :: o_init_zero
end subroutine adv_tra_hor_muscl
! a not stable version of MUSCL (reconstruction in the vicinity of bottom topography is not upwind)
! it runs with FCT option only
subroutine adv_tra_hor_mfct(vel, ttf, partit, mesh, num_ord, flux, edge_up_dn_grad, o_init_zero)
use MOD_MESH
USE MOD_PARTIT
USE MOD_PARSUP
type(t_partit),intent(inout), target :: partit
type(t_mesh), intent(in), target :: mesh
real(kind=WP), intent(in) :: num_ord ! num_ord is the fraction of fourth-order contribution in the solution
real(kind=WP), intent(in) :: ttf( mesh%nl-1, partit%myDim_nod2D+partit%eDim_nod2D)
real(kind=WP), intent(in) :: vel(2, mesh%nl-1, partit%myDim_elem2D+partit%eDim_elem2D)
real(kind=WP), intent(inout) :: flux( mesh%nl-1, partit%myDim_edge2D)
real(kind=WP), intent(in) :: edge_up_dn_grad(4, mesh%nl-1, partit%myDim_edge2D)
logical, optional :: o_init_zero
end subroutine adv_tra_hor_mfct
end interface
end module oce_adv_tra_hor_interfaces
!
!
!===============================================================================
subroutine adv_tra_hor_upw1(vel, ttf, partit, mesh, flux, o_init_zero)
use MOD_MESH
use O_PARAM, only: r_earth
USE MOD_PARTIT
USE MOD_PARSUP
use g_comm_auto
implicit none
type(t_partit),intent(in), target :: partit
type(t_mesh), intent(in), target :: mesh
real(kind=WP), intent(in) :: ttf( mesh%nl-1, partit%myDim_nod2D+partit%eDim_nod2D)
real(kind=WP), intent(in) :: vel(2, mesh%nl-1, partit%myDim_elem2D+partit%eDim_elem2D)
real(kind=WP), intent(inout) :: flux( mesh%nl-1, partit%myDim_edge2D)
logical, optional :: o_init_zero
logical :: l_init_zero
real(kind=WP) :: deltaX1, deltaY1, deltaX2, deltaY2
real(kind=WP) :: a, vflux
integer :: el(2), enodes(2), nz, edge
integer :: nu12, nl12, nl1, nl2, nu1, nu2
#include "associate_part_def.h"
#include "associate_mesh_def.h"
#include "associate_part_ass.h"
#include "associate_mesh_ass.h"
l_init_zero=.true.
if (present(o_init_zero)) then
l_init_zero=o_init_zero
end if
if (l_init_zero) then
#ifndef ENABLE_OPENACC
!$OMP PARALLEL DO
#else
!$ACC PARALLEL LOOP GANG VECTOR COLLAPSE(2) DEFAULT(PRESENT) VECTOR_LENGTH(acc_vl)
#endif
do edge=1, myDim_edge2D
do nz=1, mesh%nl-1
flux(nz,edge)=0.0_WP
end do
end do
#ifndef ENABLE_OPENACC
!$OMP END PARALLEL DO
#else
!$ACC END PARALLEL LOOP
#endif
end if
! The result is the low-order solution horizontal fluxes
! They are put into flux
!___________________________________________________________________________
#ifndef ENABLE_OPENACC
!$OMP PARALLEL DEFAULT(SHARED) PRIVATE(edge, deltaX1, deltaY1, deltaX2, deltaY2, &
!$OMP a, vflux, el, enodes, nz, nu12, nl12, nl1, nl2, nu1, nu2)
!$OMP DO
#else
!$ACC PARALLEL LOOP GANG PRIVATE(enodes, el) DEFAULT(PRESENT) VECTOR_LENGTH(acc_vl)
#endif
do edge=1, myDim_edge2D
! local indice of nodes that span up edge ed
enodes=edges(:,edge)
! local index of element that contribute to edge
el=edge_tri(:,edge)
! number of layers -1 at elem el(1)
nl1=nlevels(el(1))-1
! index off surface layer in case of cavity !=1
nu1=ulevels(el(1))
! edge_cross_dxdy(1:2,ed)... dx,dy distance from element centroid el(1) to
! center of edge --> needed to calc flux perpedicular to edge from elem el(1)
deltaX1=edge_cross_dxdy(1,edge)
deltaY1=edge_cross_dxdy(2,edge)
a=r_earth*elem_cos(el(1))
!_______________________________________________________________________
! same parameter but for other element el(2) that contributes to edge ed
! if el(2)==0 than edge is boundary edge
nl2=0
nu2=0
if(el(2)>0) then
deltaX2=edge_cross_dxdy(3,edge)
deltaY2=edge_cross_dxdy(4,edge)
! number of layers -1 at elem el(2)
nl2=nlevels(el(2))-1
nu2=ulevels(el(2))
a=0.5_WP*(a+r_earth*elem_cos(el(2)))
end if
!_______________________________________________________________________
! nl12 ... minimum number of layers -1 between element el(1) & el(2) that
! contribute to edge ed
! nu12 ... upper index of layers between element el(1) & el(2) that
! contribute to edge ed
! be carefull !!! --> if ed is a boundary edge than el(1)~=0 and el(2)==0
! that means nl1>0, nl2==0, n2=min(nl1,nl2)=0 !!!
nl12=min(nl1,nl2)
nu12=max(nu1,nu2)
!_______________________________________________________________________
! (A) goes only into this loop when the edge has only facing element
! el(1) --> so the edge is a boundary edge --> this is for ocean
! surface in case of cavity
!$ACC LOOP VECTOR
do nz=nu1, nu12-1
!____________________________________________________________________
! volume flux across the segments
vflux=(-VEL(2,nz,el(1))*deltaX1 + VEL(1,nz,el(1))*deltaY1)*helem(nz,el(1))
!____________________________________________________________________
! 1st. low order upwind solution
flux(nz, edge)=-0.5_WP*( &
ttf(nz, enodes(1))*(vflux+abs(vflux))+ &
ttf(nz, enodes(2))*(vflux-abs(vflux)) &
)-flux(nz, edge)
end do
!$ACC END LOOP
!_______________________________________________________________________
! (B) goes only into this loop when the edge has only facing elemenmt
! el(2) --> so the edge is a boundary edge --> this is for ocean
! surface in case of cavity
if (nu2 > 0) then
!$ACC LOOP VECTOR
do nz=nu2, nu12-1
!___________________________________________________________
! volume flux across the segments
vflux=(VEL(2,nz,el(2))*deltaX2 - VEL(1,nz,el(2))*deltaY2)*helem(nz,el(2))
!___________________________________________________________
! 1st. low order upwind solution
flux(nz, edge)=-0.5_WP*( &
ttf(nz, enodes(1))*(vflux+abs(vflux))+ &
ttf(nz, enodes(2))*(vflux-abs(vflux)))-flux(nz, edge)
end do
!$ACC END LOOP
end if
!_______________________________________________________________________
! (C) Both segments
! loop over depth layers from top (nu12) to nl12
! be carefull !!! --> if ed is a boundary edge, el(2)==0 than nl12=0 so
! you wont enter in this loop
!$ACC LOOP VECTOR
do nz=nu12, nl12
!___________________________________________________________________
! 1st. low order upwind solution
! here already assumed that ed is NOT! a boundary edge so el(2) should exist
vflux=(-VEL(2,nz,el(1))*deltaX1 + VEL(1,nz,el(1))*deltaY1)*helem(nz,el(1)) &
+(VEL(2,nz,el(2))*deltaX2 - VEL(1,nz,el(2))*deltaY2)*helem(nz,el(2))
flux(nz, edge)=-0.5_WP*( &
ttf(nz, enodes(1))*(vflux+abs(vflux))+ &
ttf(nz, enodes(2))*(vflux-abs(vflux)))-flux(nz, edge)
end do
!$ACC END LOOP
!_______________________________________________________________________
! (D) remaining segments on the left or on the right
!$ACC LOOP VECTOR
do nz=nl12+1, nl1
!____________________________________________________________________
! volume flux across the segments
vflux=(-VEL(2,nz,el(1))*deltaX1 + VEL(1,nz,el(1))*deltaY1)*helem(nz,el(1))
!____________________________________________________________________
! 1st. low order upwind solution
flux(nz, edge)=-0.5_WP*( &
ttf(nz, enodes(1))*(vflux+abs(vflux))+ &
ttf(nz, enodes(2))*(vflux-abs(vflux)) &
)-flux(nz, edge)
end do
!$ACC END LOOP
!_______________________________________________________________________
! (E) remaining segments on the left or on the right
!$ACC LOOP VECTOR
do nz=nl12+1, nl2
!_______________________________________________________________
! volume flux across the segments
vflux=(VEL(2,nz,el(2))*deltaX2 - VEL(1,nz,el(2))*deltaY2)*helem(nz,el(2))
!_______________________________________________________________
! 1st. low order upwind solution
flux(nz, edge)=-0.5_WP*( &
ttf(nz, enodes(1))*(vflux+abs(vflux))+ &
ttf(nz, enodes(2))*(vflux-abs(vflux)))-flux(nz, edge)
end do
!$ACC END LOOP
end do
#ifndef ENABLE_OPENACC
!$OMP END DO
!$OMP END PARALLEL
#else
!$ACC END PARALLEL LOOP
#endif
end subroutine adv_tra_hor_upw1
!
!
!===============================================================================
subroutine adv_tra_hor_muscl(vel, ttf, partit, mesh, num_ord, flux, edge_up_dn_grad, nboundary_lay, o_init_zero)
use MOD_MESH
use MOD_TRACER
USE MOD_PARTIT
USE MOD_PARSUP
use g_comm_auto
implicit none
type(t_partit),intent(in), target :: partit
type(t_mesh), intent(in), target :: mesh
real(kind=WP), intent(in) :: num_ord ! num_ord is the fraction of fourth-order contribution in the solution
real(kind=WP), intent(in) :: ttf( mesh%nl-1, partit%myDim_nod2D+partit%eDim_nod2D)
real(kind=WP), intent(in) :: vel(2, mesh%nl-1, partit%myDim_elem2D+partit%eDim_elem2D)
real(kind=WP), intent(inout) :: flux( mesh%nl-1, partit%myDim_edge2D)
integer, intent(in) :: nboundary_lay(partit%myDim_nod2D+partit%eDim_nod2D)
real(kind=WP), intent(in) :: edge_up_dn_grad(4, mesh%nl-1, partit%myDim_edge2D)
logical, optional :: o_init_zero
logical :: l_init_zero
real(kind=WP) :: deltaX1, deltaY1, deltaX2, deltaY2
real(kind=WP) :: Tmean1, Tmean2, cHO
real(kind=WP) :: c_lo(2)
real(kind=WP) :: a, vflux
integer :: el(2), enodes(2), nz, edge
integer :: nu12, nl12, nl1, nl2, nu1, nu2
#include "associate_part_def.h"
#include "associate_mesh_def.h"
#include "associate_part_ass.h"
#include "associate_mesh_ass.h"
l_init_zero=.true.
if (present(o_init_zero)) then
l_init_zero=o_init_zero
end if
if (l_init_zero) then
!$OMP PARALLEL DO
do edge=1, myDim_edge2D
flux(:,edge)=0.0_WP
end do
!$OMP END PARALLEL DO
end if
! The result is the low-order solution horizontal fluxes
! They are put into flux
!___________________________________________________________________________
!$OMP PARALLEL DEFAULT(SHARED) PRIVATE(edge, deltaX1, deltaY1, deltaX2, deltaY2, Tmean1, Tmean2, cHO, &
!$OMP c_lo, a, vflux, el, enodes, nz, nu12, nl12, nl1, nl2, nu1, nu2)
!$OMP DO
do edge=1, myDim_edge2D
! local indice of nodes that span up edge ed
enodes=edges(:,edge)
! local index of element that contribute to edge
el=edge_tri(:,edge)
! number of layers -1 at elem el(1)
nl1=nlevels(el(1))-1
! index off surface layer in case of cavity !=1
nu1=ulevels(el(1))
! edge_cross_dxdy(1:2,ed)... dx,dy distance from element centroid el(1) to
! center of edge --> needed to calc flux perpedicular to edge from elem el(1)
deltaX1=edge_cross_dxdy(1,edge)
deltaY1=edge_cross_dxdy(2,edge)
a=r_earth*elem_cos(el(1))
!_______________________________________________________________________
! same parameter but for other element el(2) that contributes to edge ed
! if el(2)==0 than edge is boundary edge
nl2=0
nu2=0
if(el(2)>0) then
deltaX2=edge_cross_dxdy(3,edge)
deltaY2=edge_cross_dxdy(4,edge)
! number of layers -1 at elem el(2)
nl2=nlevels(el(2))-1
nu2=ulevels(el(2))
a=0.5_WP*(a+r_earth*elem_cos(el(2)))
end if
!_______________________________________________________________________
! n2 ... minimum number of layers -1 between element el(1) & el(2) that
! contribute to edge ed
! nu12 ... upper index of layers between element el(1) & el(2) that
! contribute to edge ed
! be carefull !!! --> if ed is a boundary edge than el(1)~=0 and el(2)==0
! that means nl1>0, nl2==0, n2=min(nl1,nl2)=0 !!!
nl12=min(nl1,nl2)
nu12=max(nu1,nu2)
!_______________________________________________________________________
! (A) goes only into this loop when the edge has only facing element
! el(1) --> so the edge is a boundary edge --> this is for ocean
! surface in case of cavity
do nz=nu1, nu12-1
c_lo(1)=real(max(sign(1, nboundary_lay(enodes(1))-nz), 0),WP)
c_lo(2)=real(max(sign(1, nboundary_lay(enodes(2))-nz), 0),WP)
!____________________________________________________________________
Tmean2=ttf(nz, enodes(2))- &
(2.0_WP*(ttf(nz, enodes(2))-ttf(nz,enodes(1)))+ &
edge_dxdy(1,edge)*a*edge_up_dn_grad(2,nz,edge)+ &
edge_dxdy(2,edge)*r_earth*edge_up_dn_grad(4,nz,edge))/6.0_WP*c_lo(2)
Tmean1=ttf(nz, enodes(1))+ &
(2.0_WP*(ttf(nz, enodes(2))-ttf(nz,enodes(1)))+ &
edge_dxdy(1,edge)*a*edge_up_dn_grad(1,nz,edge)+ &
edge_dxdy(2,edge)*r_earth*edge_up_dn_grad(3,nz,edge))/6.0_WP*c_lo(1)
!____________________________________________________________________
! volume flux across the segments
vflux=(-VEL(2,nz,el(1))*deltaX1 + VEL(1,nz,el(1))*deltaY1)*helem(nz,el(1))
cHO=(vflux+abs(vflux))*Tmean1 + (vflux-abs(vflux))*Tmean2
flux(nz,edge)=-0.5_WP*(1.0_WP-num_ord)*cHO - vflux*num_ord*0.5_WP*(Tmean1+Tmean2)-flux(nz,edge)
end do
!_______________________________________________________________________
! (B) goes only into this loop when the edge has only facing elemenmt
! el(2) --> so the edge is a boundary edge --> this is for ocean
! surface in case of cavity
if (nu2 > 0) then
do nz=nu2, nu12-1
c_lo(1)=real(max(sign(1, nboundary_lay(enodes(1))-nz), 0),WP)
c_lo(2)=real(max(sign(1, nboundary_lay(enodes(2))-nz), 0),WP)
!_______________________________________________________________
Tmean2=ttf(nz, enodes(2))- &
(2.0_WP*(ttf(nz, enodes(2))-ttf(nz,enodes(1)))+ &
edge_dxdy(1,edge)*a*edge_up_dn_grad(2,nz,edge)+ &
edge_dxdy(2,edge)*r_earth*edge_up_dn_grad(4,nz,edge))/6.0_WP*c_lo(2)
Tmean1=ttf(nz, enodes(1))+ &
(2.0_WP*(ttf(nz, enodes(2))-ttf(nz,enodes(1)))+ &
edge_dxdy(1,edge)*a*edge_up_dn_grad(1,nz,edge)+ &
edge_dxdy(2,edge)*r_earth*edge_up_dn_grad(3,nz,edge))/6.0_WP*c_lo(1)
!_______________________________________________________________
! volume flux across the segments
vflux=(VEL(2,nz,el(2))*deltaX2 - VEL(1,nz,el(2))*deltaY2)*helem(nz,el(2))
cHO=(vflux+abs(vflux))*Tmean1 + (vflux-abs(vflux))*Tmean2
flux(nz,edge)=-0.5_WP*(1.0_WP-num_ord)*cHO - vflux*num_ord*0.5_WP*(Tmean1+Tmean2)-flux(nz,edge)
end do
end if
!_______________________________________________________________________
! (C) Both segments
! loop over depth layers from top to n2
! be carefull !!! --> if ed is a boundary edge, el(2)==0 than n2=0 so
! you wont enter in this loop
do nz=nu12, nl12
c_lo(1)=real(max(sign(1, nboundary_lay(enodes(1))-nz), 0),WP)
c_lo(2)=real(max(sign(1, nboundary_lay(enodes(2))-nz), 0),WP)
!___________________________________________________________________
! MUSCL-type reconstruction
! check if upwind or downwind triagle is necessary
!
! cross product between velocity vector and cross vector edge-elem-center
! cross product > 0 --> angle vec_v and (dx,dy) --> [0 180] --> upwind triangle
! cross product < 0 --> angle vec_v and (dx,dy) --> [180 360] --> downwind triangle
!
! o o ! o o
! / \ / \ ! / \ / \
! / \ \ vec_v / \ ! / \ / / \
! / up \ \ / dn \ ! / up \ / / dn \
! o-------o----+---->o-------o ! o-------o----+---->o-------o
! 1 / 2 ! 1 \vec_v
! /vec_v ! \
! --> downwind triangle ! --> upwind triangle
!
! edge_up_dn_grad(1,nz,edge) ... gradTR_x upwind
! edge_up_dn_grad(2,nz,edge) ... gradTR_x downwind
! edge_up_dn_grad(3,nz,edge) ... gradTR_y upwind
! edge_up_dn_grad(4,nz,edge) ... gradTR_y downwind
!___________________________________________________________________
! use downwind triangle to interpolate Tracer to edge center with
! fancy scheme --> Linear upwind reconstruction
! T_n+0.5 = T_n+1 - 1/2*deltax*GRADIENT
! --> GRADIENT = 2/3 GRAD_edgecenter + 1/3 GRAD_downwindtri
! T_n+0.5 = T_n+1 - 2/6*(T_n+1-T_n) + 1/6*gradT_down
! --> edge_up_dn_grad ... contains already elemental tracer gradient
! of up and dn wind triangle
! --> Tmean2 ... edge center interpolated Tracer using tracer
! gradient info from upwind triangle
Tmean2=ttf(nz, enodes(2))- &
(2.0_WP*(ttf(nz, enodes(2))-ttf(nz,enodes(1)))+ &
edge_dxdy(1,edge)*a*edge_up_dn_grad(2,nz,edge)+ &
edge_dxdy(2,edge)*r_earth*edge_up_dn_grad(4,nz,edge))/6.0_WP*c_lo(2)
! use upwind triangle to interpolate Tracer to edge center with
! fancy scheme --> Linear upwind reconstruction
! T_n+0.5 = T_n + 1/2*deltax*GRADIENT
! --> GRADIENT = 2/3 GRAD_edgecenter + 1/3 GRAD_downwindtri
! T_n+0.5 = T_n + 2/6*(T_n+1-T_n) + 1/6*gradT_down
! --> Tmean1 ... edge center interpolated Tracer using tracer
! gradient info from downwind triangle
Tmean1=ttf(nz, enodes(1))+ &
(2.0_WP*(ttf(nz, enodes(2))-ttf(nz,enodes(1)))+ &
edge_dxdy(1,edge)*a*edge_up_dn_grad(1,nz,edge)+ &
edge_dxdy(2,edge)*r_earth*edge_up_dn_grad(3,nz,edge))/6.0_WP*c_lo(1)
!___________________________________________________________________
! volume flux along the edge segment ed
! netto volume flux along segment that comes from edge node 1 and 2
!
!
! C1 (centroid el(1)) --> (u1,v1)
! x
! ^
! (dx1,dy1) |
! |---> vec_n1 (dy1,-dx1)--> project vec_u1 onto vec_n1 --> -v1*dx1+u1*dy1 -->
! | |
! enodes(1) o----------O---------o enodes(2) |-> calculate volume flux out of/in
! vflux_________/| | the volume of enode1(enode2) through
! |---> vec_n2 (dy2,-dx2)--> project vec_u2 onto vec_n2 --> -v2*dx2+u2*dy2 --> sections of dx1,dy1 and dx2,dy2
! (dx2,dy2) | --> vflux
! v
! x
! C2 (centroid el(2)) --> (u2,v2)
! here already assumed that ed is NOT! a boundary edge so el(2) should exist
vflux=(-VEL(2,nz,el(1))*deltaX1 + VEL(1,nz,el(1))*deltaY1)*helem(nz,el(1)) &
+(VEL(2,nz,el(2))*deltaX2 - VEL(1,nz,el(2))*deltaY2)*helem(nz,el(2))
!___________________________________________________________________
! (1-num_ord) is done with 3rd order upwind
cHO=(vflux+abs(vflux))*Tmean1 + (vflux-abs(vflux))*Tmean2
flux(nz,edge)=-0.5_WP*(1.0_WP-num_ord)*cHO - vflux*num_ord*0.5_WP*(Tmean1+Tmean2)-flux(nz,edge)
end do
!_______________________________________________________________________
! (D) remaining segments on the left or on the right
do nz=nl12+1, nl1
c_lo(1)=real(max(sign(1, nboundary_lay(enodes(1))-nz), 0),WP)
c_lo(2)=real(max(sign(1, nboundary_lay(enodes(2))-nz), 0),WP)
!____________________________________________________________________
Tmean2=ttf(nz, enodes(2))- &
(2.0_WP*(ttf(nz, enodes(2))-ttf(nz,enodes(1)))+ &
edge_dxdy(1,edge)*a*edge_up_dn_grad(2,nz,edge)+ &
edge_dxdy(2,edge)*r_earth*edge_up_dn_grad(4,nz,edge))/6.0_WP*c_lo(2)
Tmean1=ttf(nz, enodes(1))+ &
(2.0_WP*(ttf(nz, enodes(2))-ttf(nz,enodes(1)))+ &
edge_dxdy(1,edge)*a*edge_up_dn_grad(1,nz,edge)+ &
edge_dxdy(2,edge)*r_earth*edge_up_dn_grad(3,nz,edge))/6.0_WP*c_lo(1)
!____________________________________________________________________
! volume flux across the segments
vflux=(-VEL(2,nz,el(1))*deltaX1 + VEL(1,nz,el(1))*deltaY1)*helem(nz,el(1))
cHO=(vflux+abs(vflux))*Tmean1 + (vflux-abs(vflux))*Tmean2
flux(nz,edge)=-0.5_WP*(1.0_WP-num_ord)*cHO - vflux*num_ord*0.5_WP*(Tmean1+Tmean2)-flux(nz,edge)
end do
!_______________________________________________________________________
! (E) remaining segments on the left or on the right
do nz=nl12+1, nl2
c_lo(1)=real(max(sign(1, nboundary_lay(enodes(1))-nz), 0),WP)
c_lo(2)=real(max(sign(1, nboundary_lay(enodes(2))-nz), 0),WP)
!____________________________________________________________________
Tmean2=ttf(nz, enodes(2))- &
(2.0_WP*(ttf(nz, enodes(2))-ttf(nz,enodes(1)))+ &
edge_dxdy(1,edge)*a*edge_up_dn_grad(2,nz,edge)+ &
edge_dxdy(2,edge)*r_earth*edge_up_dn_grad(4,nz,edge))/6.0_WP*c_lo(2)
Tmean1=ttf(nz, enodes(1))+ &
(2.0_WP*(ttf(nz, enodes(2))-ttf(nz,enodes(1)))+ &
edge_dxdy(1,edge)*a*edge_up_dn_grad(1,nz,edge)+ &
edge_dxdy(2,edge)*r_earth*edge_up_dn_grad(3,nz,edge))/6.0_WP*c_lo(1)
!____________________________________________________________________
! volume flux across the segments
vflux=(VEL(2,nz,el(2))*deltaX2 - VEL(1,nz,el(2))*deltaY2)*helem(nz,el(2))
cHO=(vflux+abs(vflux))*Tmean1 + (vflux-abs(vflux))*Tmean2
flux(nz,edge)=-0.5_WP*(1.0_WP-num_ord)*cHO - vflux*num_ord*0.5_WP*(Tmean1+Tmean2)-flux(nz,edge)
end do
end do
!$OMP END DO
!$OMP END PARALLEL
end subroutine adv_tra_hor_muscl
!
!
!===============================================================================
subroutine adv_tra_hor_mfct(vel, ttf, partit, mesh, num_ord, flux, edge_up_dn_grad, o_init_zero)
use MOD_MESH
use MOD_TRACER
USE MOD_PARTIT
USE MOD_PARSUP
use g_comm_auto
implicit none
type(t_partit),intent(inout), target :: partit
type(t_mesh), intent(in), target :: mesh
real(kind=WP), intent(in) :: num_ord ! num_ord is the fraction of fourth-order contribution in the solution
real(kind=WP), intent(in) :: ttf( mesh%nl-1, partit%myDim_nod2D+partit%eDim_nod2D)
real(kind=WP), intent(in) :: vel(2, mesh%nl-1, partit%myDim_elem2D+partit%eDim_elem2D)
real(kind=WP), intent(inout) :: flux( mesh%nl-1, partit%myDim_edge2D)
real(kind=WP), intent(in) :: edge_up_dn_grad(4, mesh%nl-1, partit%myDim_edge2D)
logical, optional :: o_init_zero
logical :: l_init_zero
real(kind=WP) :: deltaX1, deltaY1, deltaX2, deltaY2
real(kind=WP) :: Tmean1, Tmean2, cHO
real(kind=WP) :: a, vflux
integer :: el(2), enodes(2), nz, edge
integer :: nu12, nl12, nl1, nl2, nu1, nu2
#include "associate_part_def.h"
#include "associate_mesh_def.h"
#include "associate_part_ass.h"
#include "associate_mesh_ass.h"
l_init_zero=.true.
if (present(o_init_zero)) then
l_init_zero=o_init_zero
end if
if (l_init_zero) then
#ifndef ENABLE_OPENACC
!$OMP PARALLEL DO
#else
!$ACC PARALLEL LOOP GANG DEFAULT(PRESENT) VECTOR_LENGTH(acc_vl)
#endif
do edge=1, myDim_edge2D
flux(:,edge)=0.0_WP
end do
#ifndef ENABLE_OPENACC
!$OMP END PARALLEL DO
#else
!$ACC END PARALLEL LOOP
#endif
end if
! The result is the low-order solution horizontal fluxes
! They are put into flux
!___________________________________________________________________________
#ifndef ENABLE_OPENACC
!$OMP PARALLEL DEFAULT(SHARED) PRIVATE(edge, deltaX1, deltaY1, deltaX2, deltaY2, Tmean1, Tmean2, cHO, &
!$OMP a, vflux, el, enodes, nz, nu12, nl12, nl1, nl2, nu1, nu2)
!$OMP DO
#else
!$ACC PARALLEL LOOP GANG PRIVATE(enodes, el) DEFAULT(PRESENT) VECTOR_LENGTH(acc_vl)
#endif
do edge=1, myDim_edge2D
! local indice of nodes that span up edge ed
enodes=edges(:,edge)
! local index of element that contribute to edge
el=edge_tri(:,edge)
! number of layers -1 at elem el(1)
nl1=nlevels(el(1))-1
! index off surface layer in case of cavity !=1
nu1=ulevels(el(1))
! edge_cross_dxdy(1:2,ed)... dx,dy distance from element centroid el(1) to
! center of edge --> needed to calc flux perpedicular to edge from elem el(1)
deltaX1=edge_cross_dxdy(1,edge)
deltaY1=edge_cross_dxdy(2,edge)
a=r_earth*elem_cos(el(1))
!_______________________________________________________________________
! same parameter but for other element el(2) that contributes to edge ed
! if el(2)==0 than edge is boundary edge
nl2=0
nu2=0
if(el(2)>0) then
deltaX2=edge_cross_dxdy(3,edge)
deltaY2=edge_cross_dxdy(4,edge)
! number of layers -1 at elem el(2)
nl2=nlevels(el(2))-1
nu2=ulevels(el(2))
a=0.5_WP*(a+r_earth*elem_cos(el(2)))
end if
!_______________________________________________________________________
! n2 ... minimum number of layers -1 between element el(1) & el(2) that
! contribute to edge ed
! nu12 ... upper index of layers between element el(1) & el(2) that
! contribute to edge ed
! be carefull !!! --> if ed is a boundary edge than el(1)~=0 and el(2)==0
! that means nl1>0, nl2==0, n2=min(nl1,nl2)=0 !!!
nl12=min(nl1,nl2)
nu12=max(nu1,nu2)
!_______________________________________________________________________
! (A) goes only into this loop when the edge has only facing element
! el(1) --> so the edge is a boundary edge --> this is for ocean
! surface in case of cavity
!$ACC LOOP VECTOR
do nz=nu1, nu12-1
!____________________________________________________________________
Tmean2=ttf(nz, enodes(2))- &
(2.0_WP*(ttf(nz, enodes(2))-ttf(nz,enodes(1)))+ &
edge_dxdy(1,edge)*a*edge_up_dn_grad(2,nz,edge)+ &
edge_dxdy(2,edge)*r_earth*edge_up_dn_grad(4,nz,edge))/6.0_WP
Tmean1=ttf(nz, enodes(1))+ &
(2.0_WP*(ttf(nz, enodes(2))-ttf(nz,enodes(1)))+ &
edge_dxdy(1,edge)*a*edge_up_dn_grad(1,nz,edge)+ &
edge_dxdy(2,edge)*r_earth*edge_up_dn_grad(3,nz,edge))/6.0_WP
!____________________________________________________________________
! volume flux across the segments
vflux=(-VEL(2,nz,el(1))*deltaX1 + VEL(1,nz,el(1))*deltaY1)*helem(nz,el(1))
cHO=(vflux+abs(vflux))*Tmean1 + (vflux-abs(vflux))*Tmean2
flux(nz,edge)=-0.5_WP*(1.0_WP-num_ord)*cHO - vflux*num_ord*0.5_WP*(Tmean1+Tmean2)-flux(nz,edge)
end do
!$ACC END LOOP
!_______________________________________________________________________
! (B) goes only into this loop when the edge has only facing elemenmt
! el(2) --> so the edge is a boundary edge --> this is for ocean
! surface in case of cavity
if (nu2 > 0) then
!$ACC LOOP VECTOR
do nz=nu2,nu12-1
!___________________________________________________________________
Tmean2=ttf(nz, enodes(2))- &
(2.0_WP*(ttf(nz, enodes(2))-ttf(nz,enodes(1)))+ &
edge_dxdy(1,edge)*a*edge_up_dn_grad(2,nz,edge)+ &
edge_dxdy(2,edge)*r_earth*edge_up_dn_grad(4,nz,edge))/6.0_WP
Tmean1=ttf(nz, enodes(1))+ &
(2.0_WP*(ttf(nz, enodes(2))-ttf(nz,enodes(1)))+ &
edge_dxdy(1,edge)*a*edge_up_dn_grad(1,nz,edge)+ &
edge_dxdy(2,edge)*r_earth*edge_up_dn_grad(3,nz,edge))/6.0_WP
!___________________________________________________________________
! volume flux across the segments
vflux=(VEL(2,nz,el(2))*deltaX2 - VEL(1,nz,el(2))*deltaY2)*helem(nz,el(2))
cHO=(vflux+abs(vflux))*Tmean1 + (vflux-abs(vflux))*Tmean2
flux(nz,edge)=-0.5_WP*(1.0_WP-num_ord)*cHO - vflux*num_ord*0.5_WP*(Tmean1+Tmean2)-flux(nz,edge)
end do
!$ACC END LOOP
end if
!_______________________________________________________________________
! (C) Both segments
! loop over depth layers from top to n2
! be carefull !!! --> if ed is a boundary edge, el(2)==0 than n2=0 so
! you wont enter in this loop
!$ACC LOOP VECTOR
do nz=nu12, nl12
!___________________________________________________________________
! MUSCL-type reconstruction
! check if upwind or downwind triagle is necessary
!
! cross product between velocity vector and cross vector edge-elem-center
! cross product > 0 --> angle vec_v and (dx,dy) --> [0 180] --> upwind triangle
! cross product < 0 --> angle vec_v and (dx,dy) --> [180 360] --> downwind triangle
!
! o o ! o o
! / \ / \ ! / \ / \
! / \ \ vec_v / \ ! / \ / / \
! / up \ \ / dn \ ! / up \ / / dn \
! o-------o----+---->o-------o ! o-------o----+---->o-------o
! 1 / 2 ! 1 \vec_v
! /vec_v ! \
! --> downwind triangle ! --> upwind triangle
!
! edge_up_dn_grad(1,nz,edge) ... gradTR_x upwind
! edge_up_dn_grad(2,nz,edge) ... gradTR_x downwind
! edge_up_dn_grad(3,nz,edge) ... gradTR_y upwind
! edge_up_dn_grad(4,nz,edge) ... gradTR_y downwind
!___________________________________________________________________
! use downwind triangle to interpolate Tracer to edge center with
! fancy scheme --> Linear upwind reconstruction
! T_n+0.5 = T_n+1 - 1/2*deltax*GRADIENT
! --> GRADIENT = 2/3 GRAD_edgecenter + 1/3 GRAD_downwindtri
! T_n+0.5 = T_n+1 - 2/6*(T_n+1-T_n) + 1/6*gradT_down
! --> edge_up_dn_grad ... contains already elemental tracer gradient
! of up and dn wind triangle
! --> Tmean2 ... edge center interpolated Tracer using tracer
! gradient info from upwind triangle
Tmean2=ttf(nz, enodes(2))- &
(2.0_WP*(ttf(nz, enodes(2))-ttf(nz,enodes(1)))+ &
edge_dxdy(1,edge)*a*edge_up_dn_grad(2,nz,edge)+ &
edge_dxdy(2,edge)*r_earth*edge_up_dn_grad(4,nz,edge))/6.0_WP
! use upwind triangle to interpolate Tracer to edge center with
! fancy scheme --> Linear upwind reconstruction
! T_n+0.5 = T_n + 1/2*deltax*GRADIENT
! --> GRADIENT = 2/3 GRAD_edgecenter + 1/3 GRAD_downwindtri
! T_n+0.5 = T_n + 2/6*(T_n+1-T_n) + 1/6*gradT_down
! --> Tmean1 ... edge center interpolated Tracer using tracer
! gradient info from downwind triangle
Tmean1=ttf(nz, enodes(1))+ &
(2.0_WP*(ttf(nz, enodes(2))-ttf(nz,enodes(1)))+ &
edge_dxdy(1,edge)*a*edge_up_dn_grad(1,nz,edge)+ &
edge_dxdy(2,edge)*r_earth*edge_up_dn_grad(3,nz,edge))/6.0_WP
!___________________________________________________________________
! volume flux along the edge segment ed
! netto volume flux along segment that comes from edge node 1 and 2
!
!
! C1 (centroid el(1)) --> (u1,v1)
! x
! ^
! (dx1,dy1) |
! |---> vec_n1 (dy1,-dx1)--> project vec_u1 onto vec_n1 --> -v1*dx1+u1*dy1 -->
! | |
! enodes(1) o----------O---------o enodes(2) |-> calculate volume flux out of/in
! vflux_________/| | the volume of enode1(enode2) through
! |---> vec_n2 (dy2,-dx2)--> project vec_u2 onto vec_n2 --> -v2*dx2+u2*dy2 --> sections of dx1,dy1 and dx2,dy2
! (dx2,dy2) | --> vflux
! v
! x
! C2 (centroid el(2)) --> (u2,v2)
! here already assumed that ed is NOT! a boundary edge so el(2) should exist
vflux=(-VEL(2,nz,el(1))*deltaX1 + VEL(1,nz,el(1))*deltaY1)*helem(nz,el(1)) &
+(VEL(2,nz,el(2))*deltaX2 - VEL(1,nz,el(2))*deltaY2)*helem(nz,el(2))
!___________________________________________________________________
! (1-num_ord) is done with 3rd order upwind
cHO=(vflux+abs(vflux))*Tmean1 + (vflux-abs(vflux))*Tmean2
flux(nz,edge)=-0.5_WP*(1.0_WP-num_ord)*cHO - vflux*num_ord*0.5_WP*(Tmean1+Tmean2)-flux(nz,edge)
end do
!$ACC END LOOP
!_______________________________________________________________________
! (D) remaining segments on the left or on the right
!$ACC LOOP VECTOR
do nz=nl12+1, nl1
!____________________________________________________________________
Tmean2=ttf(nz, enodes(2))- &
(2.0_WP*(ttf(nz, enodes(2))-ttf(nz,enodes(1)))+ &
edge_dxdy(1,edge)*a*edge_up_dn_grad(2,nz,edge)+ &
edge_dxdy(2,edge)*r_earth*edge_up_dn_grad(4,nz,edge))/6.0_WP
Tmean1=ttf(nz, enodes(1))+ &
(2.0_WP*(ttf(nz, enodes(2))-ttf(nz,enodes(1)))+ &
edge_dxdy(1,edge)*a*edge_up_dn_grad(1,nz,edge)+ &
edge_dxdy(2,edge)*r_earth*edge_up_dn_grad(3,nz,edge))/6.0_WP
!____________________________________________________________________
! volume flux across the segments
vflux=(-VEL(2,nz,el(1))*deltaX1 + VEL(1,nz,el(1))*deltaY1)*helem(nz,el(1))
cHO=(vflux+abs(vflux))*Tmean1 + (vflux-abs(vflux))*Tmean2
flux(nz,edge)=-0.5_WP*(1.0_WP-num_ord)*cHO - vflux*num_ord*0.5_WP*(Tmean1+Tmean2)-flux(nz,edge)
end do
!$ACC END LOOP
!_______________________________________________________________________
! (E) remaining segments on the left or on the right
!$ACC LOOP VECTOR
do nz=nl12+1, nl2
!____________________________________________________________________
Tmean2=ttf(nz, enodes(2))- &
(2.0_WP*(ttf(nz, enodes(2))-ttf(nz,enodes(1)))+ &
edge_dxdy(1,edge)*a*edge_up_dn_grad(2,nz,edge)+ &
edge_dxdy(2,edge)*r_earth*edge_up_dn_grad(4,nz,edge))/6.0_WP
Tmean1=ttf(nz, enodes(1))+ &
(2.0_WP*(ttf(nz, enodes(2))-ttf(nz,enodes(1)))+ &
edge_dxdy(1,edge)*a*edge_up_dn_grad(1,nz,edge)+ &
edge_dxdy(2,edge)*r_earth*edge_up_dn_grad(3,nz,edge))/6.0_WP
!____________________________________________________________________
! volume flux across the segments
vflux=(VEL(2,nz,el(2))*deltaX2 - VEL(1,nz,el(2))*deltaY2)*helem(nz,el(2))
cHO=(vflux+abs(vflux))*Tmean1 + (vflux-abs(vflux))*Tmean2
flux(nz,edge)=-0.5_WP*(1.0_WP-num_ord)*cHO - vflux*num_ord*0.5_WP*(Tmean1+Tmean2)-flux(nz,edge)
end do
!$ACC END LOOP
end do
#ifndef ENABLE_OPENACC
!$OMP END DO
!$OMP END PARALLEL
#else
!$ACC END PARALLEL LOOP
#endif
end subroutine adv_tra_hor_mfct