-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathice_fct.F90
More file actions
executable file
·1625 lines (1557 loc) · 53.7 KB
/
ice_fct.F90
File metadata and controls
executable file
·1625 lines (1557 loc) · 53.7 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
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 ice_fct_interfaces
interface
subroutine ice_mass_matrix_fill(ice, partit, mesh)
USE MOD_ICE
USE MOD_PARTIT
USE MOD_PARSUP
USE MOD_MESH
type(t_ice), intent(inout), target :: ice
type(t_partit), intent(inout), target :: partit
type(t_mesh), intent(in), target :: mesh
end subroutine ice_mass_matrix_fill
subroutine ice_solve_high_order(ice, partit, mesh)
USE MOD_ICE
USE MOD_PARTIT
USE MOD_PARSUP
USE MOD_MESH
type(t_ice), intent(inout), target :: ice
type(t_partit), intent(inout), target :: partit
type(t_mesh), intent(in), target :: mesh
end subroutine ice_solve_high_order
subroutine ice_solve_low_order(ice, partit, mesh)
USE MOD_ICE
USE MOD_PARTIT
USE MOD_PARSUP
USE MOD_MESH
type(t_ice), intent(inout), target :: ice
type(t_partit), intent(inout), target :: partit
type(t_mesh), intent(in), target :: mesh
end subroutine ice_solve_low_order
subroutine ice_fem_fct(tr_array_id, ice, partit, mesh)
USE MOD_ICE
USE MOD_PARTIT
USE MOD_PARSUP
USE MOD_MESH
integer :: tr_array_id
type(t_ice), intent(inout), target :: ice
type(t_partit), intent(inout), target :: partit
type(t_mesh), intent(in), target :: mesh
end subroutine ice_fem_fct
subroutine ice_TG_rhs_div(ice, partit, mesh)
USE MOD_ICE
USE MOD_PARTIT
USE MOD_PARSUP
USE MOD_MESH
type(t_ice), intent(inout), target :: ice
type(t_partit), intent(inout), target :: partit
type(t_mesh), intent(in), target :: mesh
end subroutine ice_TG_rhs_div
subroutine ice_TG_rhs(ice, partit, mesh)
USE MOD_ICE
USE MOD_PARTIT
USE MOD_PARSUP
USE MOD_MESH
type(t_ice), intent(inout), target :: ice
type(t_partit), intent(inout), target :: partit
type(t_mesh), intent(in), target :: mesh
end subroutine ice_TG_rhs
subroutine ice_update_for_div(ice, partit, mesh)
USE MOD_ICE
USE MOD_PARTIT
USE MOD_PARSUP
USE MOD_MESH
type(t_ice), intent(inout), target :: ice
type(t_partit), intent(inout), target :: partit
type(t_mesh), intent(in), target :: mesh
end subroutine ice_update_for_div
end interface
end module ice_fct_interfaces
!
!
!_______________________________________________________________________________
! This file collect subroutines implementing FE-FCT
! advection scheme by Loehner et al.
! There is a tunable parameter ice_gamma_fct.
! Increasing it leads to positivity preserving solution.
!
! Driving routine is fct_ice_solve. It calles other routines
! that do low-order and figh order solutions and then combine them in a flux
! corrected way. Taylor-Galerkin scheme is used as a high-order one.
!
! The code is adapted from FESOM
!
!
!_______________________________________________________________________________
subroutine ice_TG_rhs(ice, partit, mesh)
use MOD_MESH
USE MOD_PARTIT
USE MOD_PARSUP
USE MOD_ICE
use o_PARAM
USE g_CONFIG
implicit none
type(t_ice), intent(inout), target :: ice
type(t_partit), intent(inout), target :: partit
type(t_mesh), intent(in), target :: mesh
!___________________________________________________________________________
real(kind=WP) :: diff, entries(3), um, vm, vol, dx(3), dy(3)
integer :: n, q, row, elem, elnodes(3)
!___________________________________________________________________________
! pointer on necessary derived types
real(kind=WP), dimension(:), pointer :: u_ice, v_ice
real(kind=WP), dimension(:), pointer :: a_ice, m_ice, m_snow
real(kind=WP), dimension(:), pointer :: rhs_a, rhs_m, rhs_ms
#if defined (__oifs) || defined (__ifsinterface)
real(kind=WP), dimension(:), pointer :: ice_temp, rhs_temp
#endif
#include "associate_part_def.h"
#include "associate_mesh_def.h"
#include "associate_part_ass.h"
#include "associate_mesh_ass.h"
u_ice => ice%uice(:)
v_ice => ice%vice(:)
a_ice => ice%data(1)%values(:)
m_ice => ice%data(2)%values(:)
m_snow => ice%data(3)%values(:)
rhs_a => ice%data(1)%values_rhs(:)
rhs_m => ice%data(2)%values_rhs(:)
rhs_ms => ice%data(3)%values_rhs(:)
#if defined (__oifs) || defined (__ifsinterface)
ice_temp => ice%data(4)%values(:)
rhs_temp => ice%data(4)%values_rhs(:)
#endif
!___________________________________________________________________________
! Taylor-Galerkin (Lax-Wendroff) rhs
#ifndef ENABLE_OPENACC
!$OMP PARALLEL DEFAULT(SHARED) PRIVATE(n, q, row, elem, elnodes, diff, entries, um, vm, vol, dx, dy)
!$OMP DO
#else
!$ACC PARALLEL LOOP GANG VECTOR DEFAULT(PRESENT)
#endif
DO row=1, myDim_nod2D
rhs_m(row)=0._WP
rhs_a(row)=0._WP
rhs_ms(row)=0._WP
#if defined (__oifs) || defined (__ifsinterface)
rhs_temp(row)=0._WP
#endif
END DO
#ifndef ENABLE_OPENACC
!$OMP END DO
#else
!$ACC END PARALLEL LOOP
#endif
! Velocities at nodes
#ifndef ENABLE_OPENACC
!$OMP DO
#else
!$ACC PARALLEL LOOP GANG VECTOR DEFAULT(PRESENT) private(n, q, row, elem, elnodes, diff, entries, um, vm, vol, dx, dy)
#endif
do elem=1,myDim_elem2D !assembling rhs over elements
elnodes=elem2D_nodes(:,elem)
!_______________________________________________________________________
! if cavity element skip it
if (ulevels(elem)>1) cycle
!derivatives
dx=gradient_sca(1:3,elem)
dy=gradient_sca(4:6,elem)
vol=elem_area(elem)
!um=sum(U_ice(elnodes))/3.0_WP
!vm=sum(V_ice(elnodes))/3.0_WP
um=sum(U_ice(elnodes))
vm=sum(V_ice(elnodes))
!diffusivity
diff=ice%ice_diff*sqrt(elem_area(elem)/scale_area)
!$ACC LOOP SEQ
DO n=1,3
row=elnodes(n)
!$ACC LOOP SEQ
DO q = 1,3
!entries(q)= vol*dt*((dx(n)*um+dy(n)*vm)/3.0_WP - &
! diff*(dx(n)*dx(q)+ dy(n)*dy(q))- &
! 0.5*dt*(um*dx(n)+vm*dy(n))*(um*dx(q)+vm*dy(q)))
entries(q)= vol*ice%ice_dt*((dx(n)*(um+u_ice(elnodes(q)))+ &
dy(n)*(vm+v_ice(elnodes(q))))/12.0_WP - &
diff*(dx(n)*dx(q)+ dy(n)*dy(q))- &
0.5_WP*ice%ice_dt*(um*dx(n)+vm*dy(n))*(um*dx(q)+vm*dy(q))/9.0_WP)
END DO
!$ACC END LOOP
rhs_m(row)=rhs_m(row)+sum(entries*m_ice(elnodes))
rhs_a(row)=rhs_a(row)+sum(entries*a_ice(elnodes))
rhs_ms(row)=rhs_ms(row)+sum(entries*m_snow(elnodes))
#if defined (__oifs) || defined (__ifsinterface)
rhs_temp(row)=rhs_temp(row)+sum(entries*ice_temp(elnodes))
#endif
END DO
!$ACC END LOOP
end do
#ifndef ENABLE_OPENACC
!$OMP END DO
!$OMP END PARALLEL
#else
!$ACC END PARALLEL LOOP
#endif
end subroutine ice_TG_rhs
!
!
!_______________________________________________________________________________
subroutine ice_fct_solve(ice, partit, mesh)
USE MOD_ICE
USE MOD_PARTIT
USE MOD_PARSUP
USE MOD_MESH
use ice_fct_interfaces
implicit none
type(t_ice), intent(inout), target :: ice
type(t_partit), intent(inout), target :: partit
type(t_mesh), intent(in), target :: mesh
#include "associate_part_def.h"
#include "associate_mesh_def.h"
#include "associate_part_ass.h"
#include "associate_mesh_ass.h"
!_____________________________________________________________________________
! Driving routine
call ice_solve_high_order(ice, partit, mesh) ! uses arrays of low-order solutions as temp
! storage. It should preceed the call of low
! order solution.
call ice_solve_low_order(ice, partit, mesh)
call ice_fem_fct(1, ice, partit, mesh) ! m_ice
call ice_fem_fct(2, ice, partit, mesh) ! a_ice
call ice_fem_fct(3, ice, partit, mesh) ! m_snow
#if defined (__oifs) || defined (__ifsinterface)
call ice_fem_fct(4, ice, partit, mesh) ! ice_temp
#endif
end subroutine ice_fct_solve
!
!
!_______________________________________________________________________________
subroutine ice_solve_low_order(ice, partit, mesh)
!============================
! Low-order solution
!============================
!
! It is assumed that m_ice, a_ice and m_snow from the previous time step
! are known at 1:myDim_nod2D+eDim_nod2D.
! We add diffusive contribution to the rhs. The diffusion operator
! is implemented as the difference between the consistent and lumped mass
! matrices acting on the field from the previous time step. The consistent
! mass matrix on the lhs is replaced with the lumped one.
USE MOD_ICE
USE MOD_PARTIT
USE MOD_PARSUP
USE MOD_MESH
use g_comm_auto
implicit none
type(t_ice), intent(inout), target :: ice
type(t_partit), intent(inout), target :: partit
type(t_mesh), intent(in), target :: mesh
!___________________________________________________________________________
integer :: row, clo, clo2, cn, location(100)
real(kind=WP) :: gamma
!___________________________________________________________________________
! pointer on necessary derived types
real(kind=WP), dimension(:), pointer :: a_ice, m_ice, m_snow
real(kind=WP), dimension(:), pointer :: rhs_a, rhs_m, rhs_ms
real(kind=WP), dimension(:), pointer :: a_icel, m_icel, m_snowl
real(kind=WP), dimension(:), pointer :: mass_matrix
#if defined (__oifs) || defined (__ifsinterface)
real(kind=WP), dimension(:), pointer :: ice_temp, rhs_temp, m_templ
#endif
#include "associate_part_def.h"
#include "associate_mesh_def.h"
#include "associate_part_ass.h"
#include "associate_mesh_ass.h"
a_ice => ice%data(1)%values(:)
m_ice => ice%data(2)%values(:)
m_snow => ice%data(3)%values(:)
rhs_a => ice%data(1)%values_rhs(:)
rhs_m => ice%data(2)%values_rhs(:)
rhs_ms => ice%data(3)%values_rhs(:)
a_icel => ice%data(1)%valuesl(:)
m_icel => ice%data(2)%valuesl(:)
m_snowl => ice%data(3)%valuesl(:)
mass_matrix => ice%work%fct_massmatrix(:)
#if defined (__oifs) || defined (__ifsinterface)
ice_temp => ice%data(4)%values(:)
rhs_temp => ice%data(4)%values_rhs(:)
m_templ => ice%data(4)%valuesl(:)
#endif
!___________________________________________________________________________
gamma=ice%ice_gamma_fct ! Added diffusivity parameter
! Adjust it to ensure posivity of solution
#ifndef ENABLE_OPENACC
!$OMP PARALLEL DO DEFAULT(SHARED) PRIVATE(row, clo, clo2, cn, location)
#else
!$ACC PARALLEL LOOP GANG VECTOR PRESENT(ssh_stiff, ssh_stiff%rowptr) PRIVATE(location) DEFAULT(PRESENT)
#endif
do row=1,myDim_nod2D
!_______________________________________________________________________
! if there is cavity no ice fxt low order
if (ulevels_nod2D(row)>1) cycle
!_______________________________________________________________________
clo=ssh_stiff%rowptr(row)-ssh_stiff%rowptr(1)+1
clo2=ssh_stiff%rowptr(row+1)-ssh_stiff%rowptr(1)
cn=clo2-clo+1
location(1:cn)=nn_pos(1:cn, row)
m_icel(row)=(rhs_m(row)+gamma*sum(mass_matrix(clo:clo2)* &
m_ice(location(1:cn))))/area(1,row) + &
(1.0_WP-gamma)*m_ice(row)
a_icel(row)=(rhs_a(row)+gamma*sum(mass_matrix(clo:clo2)* &
a_ice(location(1:cn))))/area(1,row) + &
(1.0_WP-gamma)*a_ice(row)
m_snowl(row)=(rhs_ms(row)+gamma*sum(mass_matrix(clo:clo2)* &
m_snow(location(1:cn))))/area(1,row) + &
(1.0_WP-gamma)*m_snow(row)
#if defined (__oifs) || defined (__ifsinterface)
m_templ(row)=(rhs_temp(row)+gamma*sum(mass_matrix(clo:clo2)* &
ice_temp(location(1:cn))))/area(1,row) + &
(1.0_WP-gamma)*ice_temp(row)
#endif
end do
#ifndef ENABLE_OPENACC
!$OMP END PARALLEL DO
#else
!$ACC END PARALLEL LOOP
#endif
! Low-order solution must be known to neighbours
call exchange_nod(m_icel,a_icel,m_snowl, partit, luse_g2g = .true.)
#if defined (__oifs) || defined (__ifsinterface)
call exchange_nod(m_templ, partit, luse_g2g = .true.)
#endif
#ifndef ENABLE_OPENACC
!$OMP BARRIER
#endif
end subroutine ice_solve_low_order
!
!
!_______________________________________________________________________________
subroutine ice_solve_high_order(ice, partit, mesh)
USE MOD_ICE
USE MOD_TRACER
USE MOD_PARTIT
USE MOD_PARSUP
USE MOD_MESH
use o_PARAM
use g_comm_auto
implicit none
type(t_ice) , intent(inout), target :: ice
type(t_partit), intent(inout), target :: partit
type(t_mesh) , intent(in) , target :: mesh
!___________________________________________________________________________
integer :: n,clo,clo2,cn,location(100),row
real(kind=WP) :: rhs_new
integer :: num_iter_solve=3
!___________________________________________________________________________
! pointer on necessary derived types
real(kind=WP), dimension(:), pointer :: rhs_a, rhs_m, rhs_ms
real(kind=WP), dimension(:), pointer :: a_icel, m_icel, m_snowl
real(kind=WP), dimension(:), pointer :: da_ice, dm_ice, dm_snow
real(kind=WP), dimension(:), pointer :: mass_matrix
#if defined (__oifs) || defined (__ifsinterface)
real(kind=WP), dimension(:), pointer :: rhs_temp, m_templ, dm_temp
#endif
#include "associate_part_def.h"
#include "associate_mesh_def.h"
#include "associate_part_ass.h"
#include "associate_mesh_ass.h"
rhs_a => ice%data(1)%values_rhs(:)
rhs_m => ice%data(2)%values_rhs(:)
rhs_ms => ice%data(3)%values_rhs(:)
a_icel => ice%data(1)%valuesl(:)
m_icel => ice%data(2)%valuesl(:)
m_snowl => ice%data(3)%valuesl(:)
da_ice => ice%data(1)%dvalues(:)
dm_ice => ice%data(2)%dvalues(:)
dm_snow => ice%data(3)%dvalues(:)
mass_matrix => ice%work%fct_massmatrix(:)
#if defined (__oifs) || defined (__ifsinterface)
rhs_temp => ice%data(4)%values_rhs(:)
m_templ => ice%data(4)%valuesl(:)
dm_temp => ice%data(4)%dvalues(:)
#endif
!___________________________________________________________________________
! Does Taylor-Galerkin solution
!
!the first approximation
#ifndef ENABLE_OPENACC
!$OMP PARALLEL DO DEFAULT(SHARED) PRIVATE(row)
#else
!$ACC PARALLEL LOOP GANG VECTOR DEFAULT(PRESENT)
#endif
do row=1,myDim_nod2D
! if cavity node skip it
if (ulevels_nod2d(row)>1) cycle
dm_ice(row)=rhs_m(row)/area(1,row)
da_ice(row)=rhs_a(row)/area(1,row)
dm_snow(row)=rhs_ms(row)/area(1,row)
#if defined (__oifs) || defined (__ifsinterface)
dm_temp(row)=rhs_temp(row)/area(1,row)
#endif
end do
#ifndef ENABLE_OPENACC
!$OMP END PARALLEL DO
#else
!$ACC END PARALLEL LOOP
#endif
call exchange_nod(dm_ice, da_ice, dm_snow, partit, luse_g2g = .true.)
#if defined (__oifs) || defined (__ifsinterface)
call exchange_nod(dm_temp, partit, luse_g2g = .true.)
#endif /* (__oifs) */
#ifndef ENABLE_OPENACC
!$OMP BARRIER
#endif
!___________________________________________________________________________
!iterate
do n=1,num_iter_solve-1
#ifndef ENABLE_OPENACC
!$OMP PARALLEL DEFAULT(SHARED) PRIVATE(n, clo, clo2, cn, location, row, rhs_new)
!$OMP DO
#else
!$ACC PARALLEL LOOP GANG VECTOR PRESENT(ssh_stiff, ssh_stiff%rowptr) PRIVATE(location) DEFAULT(PRESENT)
#endif
do row=1,myDim_nod2D
! if cavity node skip it
if (ulevels_nod2d(row)>1) cycle
!___________________________________________________________________
clo = ssh_stiff%rowptr(row)-ssh_stiff%rowptr(1)+1
clo2 = ssh_stiff%rowptr(row+1)-ssh_stiff%rowptr(1)
cn = clo2-clo+1
location(1:cn)=nn_pos(1:cn,row)
!___________________________________________________________________
rhs_new = rhs_m(row) - sum(mass_matrix(clo:clo2)*dm_ice(location(1:cn)))
m_icel(row) = dm_ice(row)+rhs_new/area(1,row)
rhs_new = rhs_a(row) - sum(mass_matrix(clo:clo2)*da_ice(location(1:cn)))
a_icel(row) = da_ice(row)+rhs_new/area(1,row)
rhs_new = rhs_ms(row) - sum(mass_matrix(clo:clo2)*dm_snow(location(1:cn)))
m_snowl(row)= dm_snow(row)+rhs_new/area(1,row)
#if defined (__oifs) || defined (__ifsinterface)
rhs_new = rhs_temp(row) - sum(mass_matrix(clo:clo2)*dm_temp(location(1:cn)))
m_templ(row)= dm_temp(row)+rhs_new/area(1,row)
#endif
end do
#ifndef ENABLE_OPENACC
!$OMP END DO
#else
!$ACC END PARALLEL LOOP
#endif
!_______________________________________________________________________
#ifndef ENABLE_OPENACC
!$OMP DO
#else
!$ACC PARALLEL LOOP GANG VECTOR DEFAULT(PRESENT)
#endif
do row=1,myDim_nod2D
! if cavity node skip it
if (ulevels_nod2d(row)>1) cycle
dm_ice(row)=m_icel(row)
da_ice(row)=a_icel(row)
dm_snow(row)=m_snowl(row)
#if defined (__oifs) || defined (__ifsinterface)
dm_temp(row)=m_templ(row)
#endif
end do
#ifndef ENABLE_OPENACC
!$OMP END DO
!$OMP END PARALLEL
#else
!$ACC END PARALLEL LOOP
#endif
!_______________________________________________________________________
call exchange_nod(dm_ice, da_ice, dm_snow, partit, luse_g2g = .true.)
#if defined (__oifs) || defined (__ifsinterface)
call exchange_nod(dm_temp, partit, luse_g2g = .true.)
#endif /* (__oifs) */
#ifndef ENABLE_OPENACC
!$OMP BARRIER
#endif
end do
end subroutine ice_solve_high_order
!
!
!_______________________________________________________________________________
! Flux corrected transport algorithm for tracer advection
! It is based on Loehner et al. (Finite-element flux-corrected
! transport (FEM-FCT) for the Euler and Navier-Stokes equation,
! Int. J. Numer. Meth. Fluids, 7 (1987), 1093--1109) as described by Kuzmin and
! Turek. (kuzmin@math.uni-dortmund.de)
subroutine ice_fem_fct(tr_array_id, ice, partit, mesh)
USE MOD_ICE
USE MOD_PARTIT
USE MOD_PARSUP
USE MOD_MESH
use o_PARAM
use g_comm_auto
implicit none
type(t_ice) , intent(inout), target :: ice
type(t_partit), intent(inout), target :: partit
type(t_mesh) , intent(in) , target :: mesh
!___________________________________________________________________________
integer :: tr_array_id
integer :: icoef(3,3), n, q, elem, elnodes(3), row
real(kind=WP) :: vol, flux, ae, gamma
!___________________________________________________________________________
! pointer on necessary derived types
real(kind=WP), dimension(:) , pointer :: a_ice, m_ice, m_snow
real(kind=WP), dimension(:) , pointer :: a_icel, m_icel, m_snowl
real(kind=WP), dimension(:) , pointer :: da_ice, dm_ice, dm_snow
real(kind=WP), dimension(:) , pointer :: icepplus, icepminus, tmax, tmin
real(kind=WP), dimension(:,:), pointer :: icefluxes
#if defined (__oifs) || defined (__ifsinterface)
real(kind=WP), dimension(:) , pointer :: ice_temp, m_templ, dm_temp
#endif
#include "associate_part_def.h"
#include "associate_mesh_def.h"
#include "associate_part_ass.h"
#include "associate_mesh_ass.h"
a_ice => ice%data(1)%values(:)
m_ice => ice%data(2)%values(:)
m_snow => ice%data(3)%values(:)
a_icel => ice%data(1)%valuesl(:)
m_icel => ice%data(2)%valuesl(:)
m_snowl => ice%data(3)%valuesl(:)
da_ice => ice%data(1)%dvalues(:)
dm_ice => ice%data(2)%dvalues(:)
dm_snow => ice%data(3)%dvalues(:)
icefluxes => ice%work%fct_fluxes(:,:)
icepplus => ice%work%fct_plus(:)
icepminus => ice%work%fct_minus(:)
tmax => ice%work%fct_tmax(:)
tmin => ice%work%fct_tmin(:)
#if defined (__oifs) || defined (__ifsinterface)
ice_temp => ice%data(4)%values(:)
m_templ => ice%data(4)%valuesl(:)
dm_temp => ice%data(4)%dvalues(:)
#endif
!___________________________________________________________________________
! It should coinside with gamma in ts_solve_low_order
gamma=ice%ice_gamma_fct
!___________________________________________________________________________
! Compute elemental antidiffusive fluxes to nodes
! This is the most unpleasant part ---
! it takes memory and time. For every element
! we need its antidiffusive contribution to
! each of its 3 nodes
#ifndef ENABLE_OPENACC
!$OMP PARALLEL DO
#else
!$ACC DATA CREATE(icoef, elnodes)
!$ACC PARALLEL LOOP GANG VECTOR DEFAULT(PRESENT)
#endif
do n = 1, myDim_nod2D + eDim_nod2D
tmax(n) = 0.0_WP
tmin(n) = 0.0_WP
end do
#ifndef ENABLE_OPENACC
!$OMP END PARALLEL DO
#else
!$ACC END PARALLEL LOOP
#endif
! Auxiliary elemental operator (mass matrix- lumped mass matrix)
! do we need to make the entire array of icoef equal to 1 ?
! if so, we have to write another loop for that. For now, I am running it on cpu.
icoef = 1
#ifdef ENABLE_OPENACC
!$ACC PARALLEL LOOP GANG VECTOR DEFAULT(PRESENT)
#endif
do n=1,3 ! three upper nodes
! Cycle over rows row=elnodes(n)
icoef(n,n)=-2
end do
#ifdef ENABLE_OPENACC
!$ACC END PARALLEL LOOP
#endif
#ifndef ENABLE_OPENACC
!$OMP PARALLEL DEFAULT(SHARED) PRIVATE(n, q, elem, elnodes, row, vol, flux, ae)
!$OMP DO
#else
!$ACC PARALLEL LOOP GANG VECTOR PRIVATE(elnodes) DEFAULT(PRESENT)
#endif
do elem=1, myDim_elem2D
!_______________________________________________________________________
elnodes=elem2D_nodes(:,elem)
!_______________________________________________________________________
! if cavity cycle over
if(ulevels(elem)>1) cycle !LK89140
!_______________________________________________________________________
vol=elem_area(elem)
if (tr_array_id==1) then
do q=1,3
icefluxes(elem,q)=-sum(icoef(:,q)*(gamma*m_ice(elnodes) + &
dm_ice(elnodes)))*(vol/area(1,elnodes(q)))/12.0_WP
end do
end if
if (tr_array_id==2) then
do q=1,3
icefluxes(elem,q)=-sum(icoef(:,q)*(gamma*a_ice(elnodes) + &
da_ice(elnodes)))*(vol/area(1,elnodes(q)))/12.0_WP
end do
end if
if (tr_array_id==3) then
do q=1,3
icefluxes(elem,q)=-sum(icoef(:,q)*(gamma*m_snow(elnodes) + &
dm_snow(elnodes)))*(vol/area(1,elnodes(q)))/12.0_WP
end do
end if
#if defined (__oifs) || defined (__ifsinterface)
if (tr_array_id==4) then
do q=1,3
icefluxes(elem,q)=-sum(icoef(:,q)*(gamma*ice_temp(elnodes) + &
dm_temp(elnodes)))*(vol/area(1,elnodes(q)))/12.0_WP
end do
end if
#endif
end do
#ifndef ENABLE_OPENACC
!$OMP END DO
#else
!$ACC END PARALLEL LOOP
#endif
!___________________________________________________________________________
! Screening the low-order solution
! TO BE ADDED IF FOUND NECESSARY
! Screening means comparing low-order solutions with the
! solution on the previous time step and using whichever
! is greater/smaller in computations of max/min below
!___________________________________________________________________________
! Cluster min/max
if (tr_array_id==1) then
#ifndef ENABLE_OPENACC
!$OMP DO
#else
!$ACC PARALLEL LOOP GANG VECTOR DEFAULT(PRESENT)
#endif
do row=1, myDim_nod2D
if (ulevels_nod2d(row)>1) cycle
n=nn_num(row)
tmax(row)=max(maxval(m_icel(nn_pos(1:n,row))), maxval(m_ice(nn_pos(1:n,row))))
tmin(row)=min(minval(m_icel(nn_pos(1:n,row))), minval(m_ice(nn_pos(1:n,row))))
! tmax(row)=maxval(m_icel(nn_pos(1:n,row)))
! tmin(row)=minval(m_icel(nn_pos(1:n,row)))
! Admissible increments
tmax(row)=tmax(row)-m_icel(row)
tmin(row)=tmin(row)-m_icel(row)
end do
#ifndef ENABLE_OPENACC
!$OMP END DO
#else
!$ACC END PARALLEL LOOP
#endif
end if
if (tr_array_id==2) then
#ifndef ENABLE_OPENACC
!$OMP DO
#else
!$ACC PARALLEL LOOP GANG VECTOR DEFAULT(PRESENT)
#endif
do row=1, myDim_nod2D
if (ulevels_nod2d(row)>1) cycle
n=nn_num(row)
tmax(row)=max(maxval(a_icel(nn_pos(1:n,row))), maxval(a_ice(nn_pos(1:n,row))))
tmin(row)=min(minval(a_icel(nn_pos(1:n,row))), minval(a_ice(nn_pos(1:n,row))))
!tmax(row)=maxval(a_icel(nn_pos(1:n,row)))
!tmin(row)=minval(a_icel(nn_pos(1:n,row)))
! Admissible increments
tmax(row)=tmax(row)-a_icel(row)
tmin(row)=tmin(row)-a_icel(row)
end do
#ifndef ENABLE_OPENACC
!$OMP END DO
#else
!$ACC END PARALLEL LOOP
#endif
end if
if (tr_array_id==3) then
#ifndef ENABLE_OPENACC
!$OMP DO
#else
!$ACC PARALLEL LOOP GANG VECTOR DEFAULT(PRESENT)
#endif
do row=1, myDim_nod2D
if (ulevels_nod2d(row)>1) cycle
n=nn_num(row)
tmax(row)=max(maxval(m_snowl(nn_pos(1:n,row))), maxval(m_snow(nn_pos(1:n,row))))
tmin(row)=min(minval(m_snowl(nn_pos(1:n,row))), minval(m_snow(nn_pos(1:n,row))))
!tmax(row)=maxval(m_snowl(nn_pos(1:n,row)))
!tmin(row)=minval(m_snowl(nn_pos(1:n,row)))
! Admissible increments
tmax(row)=tmax(row)-m_snowl(row)
tmin(row)=tmin(row)-m_snowl(row)
end do
#ifndef ENABLE_OPENACC
!$OMP END DO
#else
!$ACC END PARALLEL LOOP
#endif
end if
#if defined (__oifs) || defined (__ifsinterface)
if (tr_array_id==4) then
#ifndef ENABLE_OPENACC
!$OMP DO
#else
!$ACC PARALLEL LOOP GANG VECTOR DEFAULT(PRESENT)
#endif
do row=1, myDim_nod2D
if (ulevels_nod2d(row)>1) cycle
n=nn_num(row)
tmax(row)=max(maxval(m_templ(nn_pos(1:n,row))), maxval(ice_temp(nn_pos(1:n,row))))
tmin(row)=min(minval(m_templ(nn_pos(1:n,row))), minval(ice_temp(nn_pos(1:n,row))))
! Admissible increments
tmax(row)=tmax(row)-m_templ(row)
tmin(row)=tmin(row)-m_templ(row)
end do
#ifndef ENABLE_OPENACC
!$OMP END DO
#else
!$ACC END PARALLEL LOOP
#endif
end if
#endif
!___________________________________________________________________________
! Sums of positive/negative fluxes to node row
#ifndef ENABLE_OPENACC
!$OMP DO
#else
!$ACC PARALLEL LOOP GANG VECTOR DEFAULT(PRESENT)
#endif
do n=1, myDim_nod2D+eDim_nod2D
icepplus (n)=0._WP
icepminus(n)=0._WP
end do
#ifndef ENABLE_OPENACC
!$OMP END DO
#else
!$ACC END PARALLEL LOOP
#endif
#ifndef ENABLE_OPENACC
!$OMP DO
#else
#if !defined(DISABLE_OPENACC_ATOMICS)
!$ACC PARALLEL LOOP GANG VECTOR PRIVATE(elnodes) DEFAULT(PRESENT)
#else
!$ACC UPDATE SELF(icefluxes, icepplus, icepminus)
#endif
#endif
do elem=1, myDim_elem2D
! if cavity cycle over
if(ulevels(elem)>1) cycle !LK89140
!_______________________________________________________________________
elnodes=elem2D_nodes(:,elem)
do q=1,3
n=elnodes(q)
flux=icefluxes(elem,q)
#ifndef ENABLE_OPENACC
#if defined(_OPENMP) && !defined(__openmp_reproducible)
call omp_set_lock (partit%plock(n))
#else
!$OMP ORDERED
#endif
#endif
if (flux>0) then
#if !defined(DISABLE_OPENACC_ATOMICS)
!$ACC ATOMIC UPDATE
#endif
icepplus(n)=icepplus(n)+flux
else
#if !defined(DISABLE_OPENACC_ATOMICS)
!$ACC ATOMIC UPDATE
#endif
icepminus(n)=icepminus(n)+flux
end if
#ifndef ENABLE_OPENACC
#if defined(_OPENMP) && !defined(__openmp_reproducible)
call omp_unset_lock(partit%plock(n))
#else
!$OMP END ORDERED
#endif
#endif
end do
end do
#ifndef ENABLE_OPENACC
!$OMP END DO
#else
#if !defined(DISABLE_OPENACC_ATOMICS)
!$ACC END PARALLEL LOOP
#else
!$ACC UPDATE DEVICE(icepplus, icepminus)
#endif
#endif
!___________________________________________________________________________
! The least upper bound for the correction factors
#ifndef ENABLE_OPENACC
!$OMP DO
#else
!$ACC PARALLEL LOOP GANG VECTOR PRESENT(icepplus, icepminus) DEFAULT(PRESENT)
#endif
do n=1,myDim_nod2D
! if cavity cycle over
if(ulevels_nod2D(n)>1) cycle !LK89140
flux=icepplus(n)
if (abs(flux)>0) then
icepplus(n)=min(1.0_WP,tmax(n)/max(flux,1.e-12))
else
icepplus(n)=0._WP
end if
flux=icepminus(n)
if (abs(flux)>0) then
icepminus(n)=min(1.0_WP,tmin(n)/min(flux,-1.e-12))
else
icepminus(n)=0._WP
end if
end do
#ifndef ENABLE_OPENACC
!$OMP END DO
#else
!$ACC END PARALLEL LOOP
#endif
! pminus and pplus are to be known to neighbouting PE
!$ACC wait
#if defined(_OPENMP)
!$OMP MASTER
#endif
call exchange_nod(icepminus, icepplus, partit, luse_g2g = .true.)
#if defined(_OPENMP)
!$OMP END MASTER
!$OMP BARRIER
#endif
!___________________________________________________________________________
! Limiting
#ifndef ENABLE_OPENACC
!$OMP DO
#else
!$ACC PARALLEL LOOP GANG VECTOR PRESENT(icepplus, icepminus) PRIVATE(elnodes) DEFAULT(PRESENT)
#endif
do elem=1, myDim_elem2D
! if cavity cycle over
if(ulevels(elem)>1) cycle !LK89140
!_______________________________________________________________________
elnodes=elem2D_nodes(:,elem)
ae=1.0_WP
do q=1,3
n=elnodes(q)
flux=icefluxes(elem,q)
if(flux>=0._WP) ae=min(ae,icepplus(n))
if(flux<0._WP) ae=min(ae,icepminus(n))
end do
icefluxes(elem,:)=ae*icefluxes(elem,:)
end do
#ifndef ENABLE_OPENACC
!$OMP END DO
#else
!$ACC END PARALLEL LOOP
#endif
!___________________________________________________________________________
! Update the solution
if(tr_array_id==1) then
#ifndef ENABLE_OPENACC
!$OMP DO
#else
!$ACC PARALLEL LOOP GANG VECTOR DEFAULT(PRESENT)
#endif
do n=1,myDim_nod2D
if(ulevels_nod2D(n)>1) cycle !LK89140
m_ice(n)=m_icel(n)
end do
#ifndef ENABLE_OPENACC
!$OMP END DO
#else
!$ACC END PARALLEL LOOP
#endif
#ifndef ENABLE_OPENACC
!$OMP DO
#else
#if !defined(DISABLE_OPENACC_ATOMICS)
!$ACC PARALLEL LOOP GANG VECTOR PRIVATE(elnodes) DEFAULT(PRESENT)
#else
!$ACC UPDATE SELF(m_ice, icefluxes)
#endif
#endif
do elem=1, myDim_elem2D
! if cavity cycle over
if(ulevels(elem)>1) cycle !LK89140
elnodes=elem2D_nodes(:,elem)
do q=1,3
n=elnodes(q)
#ifndef ENABLE_OPENACC
#if defined(_OPENMP) && !defined(__openmp_reproducible)
call omp_set_lock (partit%plock(n))
#else
!$OMP ORDERED
#endif
#endif
#if !defined(DISABLE_OPENACC_ATOMICS)
!$ACC ATOMIC UPDATE
#endif
m_ice(n)=m_ice(n)+icefluxes(elem,q)
#ifndef ENABLE_OPENACC
#if defined(_OPENMP) && !defined(__openmp_reproducible)
call omp_unset_lock(partit%plock(n))
#else
!$OMP END ORDERED
#endif
#endif
end do
end do
#ifndef ENABLE_OPENACC
!$OMP END DO
#else
#if !defined(DISABLE_OPENACC_ATOMICS)
!$ACC END PARALLEL LOOP
#else
!$ACC UPDATE DEVICE(m_ice)
#endif
#endif
end if
if(tr_array_id==2) then
#ifndef ENABLE_OPENACC
!$OMP DO
#else
!$ACC PARALLEL LOOP GANG VECTOR DEFAULT(PRESENT)
#endif
do n=1,myDim_nod2D
if(ulevels_nod2D(n)>1) cycle !LK89140
a_ice(n)=a_icel(n)
end do
#ifndef ENABLE_OPENACC
!$OMP END DO
!$OMP DO
#else
!$ACC END PARALLEL LOOP
#if !defined(DISABLE_OPENACC_ATOMICS)
!$ACC PARALLEL LOOP GANG VECTOR PRIVATE(elnodes) DEFAULT(PRESENT)
#else
!$ACC UPDATE SELF(a_ice, icefluxes)
#endif
#endif
do elem=1, myDim_elem2D
! if cavity cycle over
if(ulevels(elem)>1) cycle !LK89140
elnodes=elem2D_nodes(:,elem)
do q=1,3
n=elnodes(q)
#ifndef ENABLE_OPENACC
#if defined(_OPENMP) && !defined(__openmp_reproducible)
call omp_set_lock (partit%plock(n))
#else
!$OMP ORDERED
#endif
#endif
#if !defined(DISABLE_OPENACC_ATOMICS)
!$ACC ATOMIC UPDATE
#endif
a_ice(n)=a_ice(n)+icefluxes(elem,q)
#ifndef ENABLE_OPENACC
#if defined(_OPENMP) && !defined(__openmp_reproducible)
call omp_unset_lock(partit%plock(n))
#else
!$OMP END ORDERED
#endif
#endif
end do
end do
#ifndef ENABLE_OPENACC
!$OMP END DO
#else