-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathgen_modules_diag.F90
More file actions
3492 lines (3241 loc) · 182 KB
/
gen_modules_diag.F90
File metadata and controls
3492 lines (3241 loc) · 182 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 diagnostics
use g_config
use mod_mesh
USE MOD_PARTIT
USE MOD_PARSUP
use MOD_TRACER
use MOD_DYN
use MOD_ICE
use g_clock
use g_comm_auto
use o_ARRAYS
use o_tracers
use g_forcing_arrays
use o_mixing_KPP_mod
use g_rotate_grid
use g_support
use Toy_Channel_Soufflet
use cmor_variables_diag
implicit none
private
public :: ldiag_solver, lcurt_stress_surf, ldiag_Ri, ldiag_TurbFlux, ldiag_dMOC, &
ldiag_forc, ldiag_salt3D, ldiag_curl_vel3, diag_list, ldiag_extflds, ldiag_ice, &
compute_diagnostics, rhs_diag, curl_stress_surf, curl_vel3, shear, Ri, KvdTdZ, KvdSdZ, &
std_dens_min, std_dens_max, std_dens_N, std_dens, ldiag_trflx, ldiag_destine, &
std_dens_UVDZ, std_dens_DIV, std_dens_DIV_fer, std_dens_Z, std_dens_H, std_dens_dVdT, std_dens_flux, &
dens_flux_e, zisotherm, tempzavg, saltzavg, heatcontent, vol_ice, vol_snow, compute_ice_diag, thetao, &
tuv, suv, &
ldiag_DVD, compute_dvd, dvd_KK_tot, dvd_SD_tot, dvd_SD_chi_adv_h, dvd_SD_chi_adv_v, dvd_SD_chi_dif_he,&
dvd_SD_chi_dif_heR, dvd_SD_chi_dif_hbh, dvd_SD_chi_dif_veR, dvd_SD_chi_dif_viR, dvd_SD_chi_dif_vi, &
dvd_SD_chi_dif_ve, dvd_SD_chi_dif_sbc, dvd_xdfac, &
ldiag_uvw_sqr, uv2, wvel2, &
ldiag_trgrd_xyz, trgrd_x, trgrd_y, trgrd_z, &
ldiag_cmor
! Arrays used for diagnostics, some shall be accessible to the I/O
! 1. solver diagnostics: A*x=rhs?
! A=ssh_stiff, x=d_eta, rhs=ssh_rhs; rhs_diag=A*x;
real(kind=WP), save, allocatable, target :: rhs_diag(:)
real(kind=WP), save, allocatable, target :: curl_stress_surf(:)
real(kind=WP), save, allocatable, target :: curl_vel3(:,:)
real(kind=WP), save, allocatable, target :: shear(:,:), Ri(:,:), KvdTdZ(:,:), KvdSdZ(:,:)
real(kind=WP), save, allocatable, target :: stress_bott(:,:), u_bott(:), v_bott(:), u_surf(:), v_surf(:)
real(kind=WP), save, allocatable, target :: zisotherm(:) !target temperature is specified as whichtemp in compute_extflds
real(kind=WP), save, allocatable, target :: tempzavg(:), saltzavg(:) !target depth for averaging is specified as whichdepth in compute_extflds
real(kind=WP), save, allocatable, target :: heatcontent(:,:)
real(kind=WP), save, allocatable, target :: vol_ice(:), vol_snow(:)
! defining a set of standard density bins which will be used for computing densMOC
! integer, parameter :: std_dens_N = 100
! real(kind=WP), save, target :: std_dens(std_dens_N)
integer, parameter :: std_dens_N =89
real(kind=WP), save, target :: std_dens(std_dens_N)=(/ &
0.0000, 30.00000, 30.55556, 31.11111, 31.36000, 31.66667, 31.91000, 32.22222, 32.46000, &
32.77778, 33.01000, 33.33333, 33.56000, 33.88889, 34.11000, 34.44444, 34.62000, 35.00000, &
35.05000, 35.10622, 35.20319, 35.29239, 35.37498, 35.41300, 35.45187, 35.52380, 35.59136, &
35.65506, 35.71531, 35.77247, 35.82685, 35.87869, 35.92823, 35.97566, 35.98000, 36.02115, &
36.06487, 36.10692, 36.14746, 36.18656, 36.22434, 36.26089, 36.29626, 36.33056, 36.36383, &
36.39613, 36.42753, 36.45806, 36.48778, 36.51674, 36.54495, 36.57246, 36.59500, 36.59932, &
36.62555, 36.65117, 36.67621, 36.68000, 36.70071, 36.72467, 36.74813, 36.75200, 36.77111, &
36.79363, 36.81570, 36.83733, 36.85857, 36.87500, 36.87940, 36.89985, 36.91993, 36.93965, &
36.95904, 36.97808, 36.99682, 37.01524, 37.03336, 37.05119, 37.06874, 37.08602, 37.10303, &
37.11979, 37.13630, 37.15257, 37.16861, 37.18441, 37.50000, 37.75000, 40.00000/)
real(kind=WP), save, target :: std_dd(std_dens_N-1)
real(kind=WP), save, target :: std_dens_min=1030., std_dens_max=1040.
real(kind=WP), save, allocatable, target :: std_dens_UVDZ(:,:,:), std_dens_flux(:,:,:), std_dens_dVdT(:,:), std_dens_DIV(:,:), std_dens_DIV_fer(:,:), std_dens_Z(:,:), std_dens_H(:,:)
real(kind=WP), save, allocatable, target :: dens_flux_e(:)
real(kind=WP), save, allocatable, target :: thetao(:) ! sst in K
real(kind=WP), save, allocatable, target :: tuv(:,:,:), suv(:,:,:)
real(kind=WP), save, allocatable, target :: uv2(:,:,:), wvel2(:,:)
real(kind=WP), save, allocatable, target :: trgrd_x(:,:,:), trgrd_y(:,:,:), trgrd_z(:,:,:)
!_____________________________________________________________________________
! DVD diagnostics
real(kind=WP), save, allocatable, target :: dvd_KK_tot(:,:,:), dvd_SD_tot(:,:,:), dvd_SD_chi_adv_h(:,:,:), &
dvd_SD_chi_adv_v( :,:,:), dvd_SD_chi_dif_heR(:,:,:), dvd_SD_chi_dif_veR(:,:,:), &
dvd_SD_chi_dif_viR(:,:,:), dvd_SD_chi_dif_vi(:,:,:), dvd_SD_chi_dif_hbh(:,:,:), &
dvd_SD_chi_dif_ve(:,:,:), dvd_SD_chi_dif_he(:,:,:), dvd_SD_chi_dif_sbc(:,:,:), trstar(:,:)
real(kind=WP), parameter :: dvd_xdfac=0.5_WP ! Xchi distribution factor, default distribute
! equal amount (50:50) of xchi on both side of face
!_____________________________________________________________________________
! Define diagnostic flags + with corresponding namelist
logical :: ldiag_solver =.false.
logical :: lcurt_stress_surf=.false.
logical :: ldiag_curl_vel3 =.false.
logical :: ldiag_Ri =.false.
logical :: ldiag_TurbFlux =.false.
logical :: ldiag_KE =.false.
logical :: ldiag_salt3D =.false.
! this option activates writing the horizintal velocity transports within the density bins (U_rho_x_DZ and V_rho_x_DZ)
! an additional field (RHO_Z) will be computed which allows for diagnosing the numerical diapycnal mixing after A. Megann 2018
logical :: ldiag_dMOC =.false.
! flag for calculating the Discrete Variance Decay --> estimator for numerical/
! spurious mixing in the advection schemes
logical :: ldiag_DVD =.false.
logical :: ldiag_forc =.false.
logical :: ldiag_extflds =.false.
logical :: ldiag_destine =.false.
logical :: ldiag_ice =.false.
logical :: ldiag_trflx =.false.
logical :: ldiag_uvw_sqr =.false.
logical :: ldiag_trgrd_xyz =.false.
namelist /diag_list/ ldiag_solver, lcurt_stress_surf, ldiag_curl_vel3, ldiag_Ri, &
ldiag_TurbFlux, ldiag_dMOC, ldiag_DVD, ldiag_salt3D, ldiag_forc, &
ldiag_extflds, ldiag_destine, ldiag_trflx, ldiag_ice, ldiag_uvw_sqr, ldiag_trgrd_xyz, &
ldiag_cmor
contains
! ==============================================================
!rhs_diag=ssh_rhs?
subroutine diag_solver(mode, dynamics, partit, mesh)
implicit none
type(t_mesh) , intent(in), target :: mesh
type(t_partit), intent(inout), target :: partit
type(t_dyn) , intent(inout), target :: dynamics
integer, intent(in) :: mode
integer :: n, is, ie
logical, save :: firstcall=.true.
real(kind=WP), dimension(:) , pointer :: d_eta
#include "associate_part_def.h"
#include "associate_mesh_def.h"
#include "associate_part_ass.h"
#include "associate_mesh_ass.h"
d_eta =>dynamics%d_eta(:)
!=====================
if (firstcall) then !allocate the stuff at the first call
allocate(rhs_diag(mydim_nod2D))
firstcall=.false.
if (mode==0) return
end if
do n=1, myDim_nod2D
is=ssh_stiff%rowptr_loc(n)
ie=ssh_stiff%rowptr_loc(n+1)-1
rhs_diag(n)=sum(ssh_stiff%values(is:ie)*d_eta(ssh_stiff%colind_loc(is:ie)))
end do
end subroutine diag_solver
! ==============================================================
!curt(stress_surf)
subroutine diag_curl_stress_surf(mode, partit, mesh)
implicit none
type(t_mesh), intent(in), target :: mesh
type(t_partit), intent(inout), target :: partit
integer, intent(in) :: mode
logical, save :: firstcall=.true.
integer :: enodes(2), el(2), ed, n
real(kind=WP) :: deltaX1, deltaY1, deltaX2, deltaY2, c1
!=====================
#include "associate_part_def.h"
#include "associate_mesh_def.h"
#include "associate_part_ass.h"
#include "associate_mesh_ass.h"
if (firstcall) then !allocate the stuff at the first call
allocate(curl_stress_surf(myDim_nod2D+eDim_nod2D))
firstcall=.false.
if (mode==0) return
end if
curl_stress_surf=0.
DO ed=1, myDim_edge2D
enodes=edges(:,ed)
el=edge_tri(:,ed)
deltaX1=edge_cross_dxdy(1,ed)
deltaY1=edge_cross_dxdy(2,ed)
if (el(2)>0) then
deltaX2=edge_cross_dxdy(3,ed)
deltaY2=edge_cross_dxdy(4,ed)
end if
c1=deltaX1*stress_surf(1,el(1))+deltaY1*stress_surf(2,el(1))
curl_stress_surf(enodes(1))=curl_stress_surf(enodes(1))+c1
curl_stress_surf(enodes(2))=curl_stress_surf(enodes(2))-c1
if (el(2)>0) then
c1= -deltaX2*stress_surf(1,el(2))-deltaY2*stress_surf(2,el(2))
curl_stress_surf(enodes(1))=curl_stress_surf(enodes(1))+c1
curl_stress_surf(enodes(2))=curl_stress_surf(enodes(2))-c1
end if
END DO
DO n=1, myDim_nod2D+eDim_nod2D
!!PS curl_stress_surf(n)=curl_stress_surf(n)/area(1,n)
curl_stress_surf(n)=curl_stress_surf(n)/areasvol(ulevels_nod2D(n),n)
END DO
end subroutine diag_curl_stress_surf
!
!
!_______________________________________________________________________________
!3D curl(velocity)
subroutine diag_curl_vel3(mode, dynamics, partit, mesh)
implicit none
type(t_dyn) , intent(inout), target :: dynamics
type(t_partit), intent(inout), target :: partit
type(t_mesh) , intent(in) , target :: mesh
integer, intent(in) :: mode
logical, save :: firstcall=.true.
integer :: enodes(2), el(2), ed, n, nz, nl1, nl2, nl12, nu1, nu2, nu12
real(kind=WP) :: deltaX1, deltaY1, deltaX2, deltaY2, c1
real(kind=WP), dimension(:,:,:), pointer :: UV
#include "associate_part_def.h"
#include "associate_mesh_def.h"
#include "associate_part_ass.h"
#include "associate_mesh_ass.h"
UV => dynamics%uv(:,:,:)
!___________________________________________________________________________
if (firstcall) then !allocate the stuff at the first call
allocate(curl_vel3(nl-1, myDim_nod2D+eDim_nod2D))
firstcall=.false.
if (mode==0) return
end if
!___________________________________________________________________________
curl_vel3=0.
do ed=1,myDim_edge2D
enodes=edges(:,ed)
el=edge_tri(:,ed)
!_______________________________________________________________________
nl1=nlevels(el(1))-1
nu1=ulevels(el(1))
deltaX1=edge_cross_dxdy(1,ed)
deltaY1=edge_cross_dxdy(2,ed)
!_______________________________________________________________________
if (el(2)>0) then
deltaX2=edge_cross_dxdy(3,ed)
deltaY2=edge_cross_dxdy(4,ed)
nl2=nlevels(el(2))-1
nu2=ulevels(el(2))
nl12 = min(nl1,nl2)
nu12 = max(nu1,nu2)
!___________________________________________________________________
do nz=nu1,nu12-1
c1=deltaX1*UV(1,nz,el(1))+deltaY1*UV(2,nz,el(1))
curl_vel3(nz,enodes(1))=curl_vel3(nz,enodes(1))+c1
curl_vel3(nz,enodes(2))=curl_vel3(nz,enodes(2))-c1
end do
do nz=nu2,nu12-1
c1= -deltaX2*UV(1,nz,el(2))-deltaY2*UV(2,nz,el(2))
curl_vel3(nz,enodes(1))=curl_vel3(nz,enodes(1))+c1
curl_vel3(nz,enodes(2))=curl_vel3(nz,enodes(2))-c1
end do
!___________________________________________________________________
do nz=nu12,nl12
c1=deltaX1*UV(1,nz,el(1))+deltaY1*UV(2,nz,el(1))- &
deltaX2*UV(1,nz,el(2))-deltaY2*UV(2,nz,el(2))
curl_vel3(nz,enodes(1))=curl_vel3(nz,enodes(1))+c1
curl_vel3(nz,enodes(2))=curl_vel3(nz,enodes(2))-c1
end do
!___________________________________________________________________
do nz=nl12+1,nl1
c1=deltaX1*UV(1,nz,el(1))+deltaY1*UV(2,nz,el(1))
curl_vel3(nz,enodes(1))=curl_vel3(nz,enodes(1))+c1
curl_vel3(nz,enodes(2))=curl_vel3(nz,enodes(2))-c1
end do
do nz=nl12+1,nl2
c1= -deltaX2*UV(1,nz,el(2))-deltaY2*UV(2,nz,el(2))
curl_vel3(nz,enodes(1))=curl_vel3(nz,enodes(1))+c1
curl_vel3(nz,enodes(2))=curl_vel3(nz,enodes(2))-c1
end do
!_______________________________________________________________________
else
do nz=nu1,nl1
c1=deltaX1*UV(1,nz,el(1))+deltaY1*UV(2,nz,el(1))
curl_vel3(nz,enodes(1))=curl_vel3(nz,enodes(1))+c1
curl_vel3(nz,enodes(2))=curl_vel3(nz,enodes(2))-c1
end do
end if
end do
!___________________________________________________________________________
do n=1, myDim_nod2D
do nz=ulevels_nod2D(n), nlevels_nod2D(n)-1
curl_vel3(nz,n)=curl_vel3(nz,n)/areasvol(nz,n)
end do
end do
end subroutine diag_curl_vel3
!
!
!_______________________________________________________________________________
subroutine diag_turbflux(mode, dynamics, tracers, partit, mesh)
implicit none
type(t_dyn) , intent(inout), target :: dynamics
type(t_tracer), intent(in) , target :: tracers
type(t_partit), intent(inout), target :: partit
type(t_mesh) , intent(in) , target :: mesh
integer, intent(in) :: mode
logical, save :: firstcall=.true.
integer :: n, nz, nzmax, nzmin
real(kind=WP), dimension(:,:,:), pointer :: UVnode
real(kind=WP), dimension(:,:), pointer :: temp, salt
real(kind=WP) :: dz_inv
#include "associate_part_def.h"
#include "associate_mesh_def.h"
#include "associate_part_ass.h"
#include "associate_mesh_ass.h"
UVnode=>dynamics%uvnode(:,:,:)
temp => tracers%data(1)%values(:,:)
salt => tracers%data(2)%values(:,:)
!=====================
if (firstcall) then !allocate the stuff at the first call
allocate(KvdTdZ(nl, myDim_nod2D+eDim_nod2D), KvdSdZ(nl, myDim_nod2D+eDim_nod2D))
KvdTdZ =0.0_WP
KvdSdZ =0.0_WP
firstcall=.false.
if (mode==0) return
end if
do n=1, myDim_nod2D+eDim_nod2D
nzmin = ulevels_nod2d(n)
nzmax = nlevels_nod2d(n)
do nz=nzmin+1,nzmax-1
dz_inv=1.0_WP/(Z_3d_n(nz-1,n)-Z_3d_n(nz,n))
KvdTdZ(nz,n) = -Kv(nz,n)*(temp(nz-1,n)-temp(nz,n))*dz_inv
KvdSdZ(nz,n) = -Kv(nz,n)*(salt(nz-1,n)-salt(nz,n))*dz_inv
end do
end do
end subroutine diag_turbflux
! ==============================================================
!
subroutine diag_trflx(mode, dynamics, tracers, partit, mesh)
implicit none
type(t_dyn) , intent(inout), target :: dynamics
type(t_tracer), intent(in) , target :: tracers
type(t_partit), intent(inout), target :: partit
type(t_mesh) , intent(in) , target :: mesh
integer, intent(in) :: mode
logical, save :: firstcall=.true.
integer :: elem, nz, nzu, nzl, elnodes(3)
real(kind=WP), dimension(:,:,:), pointer :: UV, fer_UV
real(kind=WP), dimension(:,:), pointer :: temp, salt
#include "associate_part_def.h"
#include "associate_mesh_def.h"
#include "associate_part_ass.h"
#include "associate_mesh_ass.h"
UV => dynamics%uv(:,:,:)
temp => tracers%data(1)%values(:,:)
salt => tracers%data(2)%values(:,:)
fer_UV => dynamics%fer_uv(:,:,:)
!=====================
if (firstcall) then !allocate the stuff at the first call
allocate(tuv(2,nl-1,myDim_elem2D+eDim_elem2D))
allocate(suv(2,nl-1,myDim_elem2D+eDim_elem2D))
tuv = 0.0_WP
suv = 0.0_WP
firstcall=.false.
if (mode==0) return
end if
!___________________________________________________________________________
! compute tracer fluxes
do elem=1,myDim_elem2D
elnodes = elem2D_nodes(:,elem)
nzu = ulevels(elem)
nzl = nlevels(elem)-1
if (Fer_GM) then
do nz=nzu, nzl
tuv(1,nz,elem) = (UV(1,nz,elem) + fer_UV(1,nz, elem)) * sum(temp(nz,elnodes))/3._WP
tuv(2,nz,elem) = (UV(2,nz,elem) + fer_UV(2,nz, elem)) * sum(temp(nz,elnodes))/3._WP
suv(1,nz,elem) = (UV(1,nz,elem) + fer_UV(1,nz, elem)) * sum(salt(nz,elnodes))/3._WP
suv(2,nz,elem) = (UV(2,nz,elem) + fer_UV(2,nz, elem)) * sum(salt(nz,elnodes))/3._WP
end do
else
do nz=nzu, nzl
tuv(1,nz,elem) = UV(1,nz,elem) * sum(temp(nz,elnodes))/3._WP
tuv(2,nz,elem) = UV(2,nz,elem) * sum(temp(nz,elnodes))/3._WP
suv(1,nz,elem) = UV(1,nz,elem) * sum(salt(nz,elnodes))/3._WP
suv(2,nz,elem) = UV(2,nz,elem) * sum(salt(nz,elnodes))/3._WP
end do
end if
end do
end subroutine diag_trflx
! ==============================================================
!
subroutine diag_Ri(mode, dynamics, partit, mesh)
implicit none
type(t_dyn) , intent(inout), target :: dynamics
type(t_partit), intent(inout), target :: partit
type(t_mesh) , intent(in) , target :: mesh
integer, intent(in) :: mode
logical, save :: firstcall=.true.
integer :: n, nz, nzmax, nzmin
real(kind=WP), dimension(:,:,:), pointer :: UVnode
real(kind=WP) :: val, dz_inv
#include "associate_part_def.h"
#include "associate_mesh_def.h"
#include "associate_part_ass.h"
#include "associate_mesh_ass.h"
UVnode=>dynamics%uvnode(:,:,:)
!=====================
if (firstcall) then !allocate the stuff at the first call
allocate(shear(nl, myDim_nod2D+eDim_nod2D), Ri(nl, myDim_nod2D+eDim_nod2D))
shear=0.0_WP
Ri =0.0_WP
firstcall=.false.
if (mode==0) return
end if
do n=1, myDim_nod2D+eDim_nod2D
nzmin = ulevels_nod2d(n)
nzmax = nlevels_nod2d(n)
do nz=nzmin+1,nzmax-1
dz_inv=1.0_WP/(Z_3d_n(nz-1,n)-Z_3d_n(nz,n))
val = (UVnode(1,nz-1,n)-UVnode(1,nz,n))**2 +&
(UVnode(2,nz-1,n)-UVnode(2,nz,n))**2
shear(nz,n) = val*dz_inv*dz_inv
Ri(nz,n) = bvfreq(nz,n)/max(shear(nz,n), 1.e-12)
end do
end do
end subroutine diag_Ri
! ==============================================================
subroutine diag_densMOC(mode, dynamics, tracers, partit, mesh)
implicit none
integer, intent(in) :: mode
type(t_mesh) , intent(in) , target :: mesh
type(t_partit), intent(inout), target :: partit
type(t_tracer), intent(in) , target :: tracers
type(t_dyn) , intent(in) , target :: dynamics
integer :: nz, snz, elem, nzmax, nzmin, elnodes(3), is, ie, pos
integer :: e, edge, enodes(2), eelems(2)
real(kind=WP) :: div, deltaX, deltaY, locz
integer :: jj
real(kind=WP), save :: dd
real(kind=WP) :: uvdz_el(2), rhoz_el, vol_el, dz, weight, dmin, dmax, ddiff, test, test1, test2, test3
real(kind=WP), save, allocatable :: dens(:), aux(:), el_depth(:)
real(kind=WP), save, allocatable :: std_dens_w(:,:), std_dens_VOL1(:,:), std_dens_VOL2(:,:)
logical, save :: firstcall_s=.true., firstcall_e=.true.
real(kind=WP), dimension(:,:), pointer :: temp, salt
real(kind=WP), dimension(:,:,:), pointer :: UV, fer_UV
#include "associate_part_def.h"
#include "associate_mesh_def.h"
#include "associate_part_ass.h"
#include "associate_mesh_ass.h"
UV => dynamics%uv(:,:,:)
temp => tracers%data(1)%values(:,:)
salt => tracers%data(2)%values(:,:)
fer_UV => dynamics%fer_uv(:,:,:)
if (firstcall_s) then !allocate the stuff at the first call
allocate(std_dens_UVDZ(2,std_dens_N, myDim_elem2D))
allocate(std_dens_w ( std_dens_N, myDim_elem2D))
allocate(std_dens_dVdT( std_dens_N, myDim_elem2D))
allocate(std_dens_DIV ( std_dens_N, myDim_nod2D+eDim_nod2D))
if (Fer_GM) allocate(std_dens_DIV_fer( std_dens_N, myDim_nod2D+eDim_nod2D))
allocate(std_dens_VOL1( std_dens_N, myDim_elem2D))
allocate(std_dens_VOL2( std_dens_N, myDim_elem2D))
allocate(std_dens_flux(3,std_dens_N, myDim_elem2D))
allocate(std_dens_Z ( std_dens_N, myDim_elem2D))
allocate(std_dens_H ( std_dens_N, myDim_elem2D))
allocate(dens_flux_e(elem2D))
allocate(aux (nl-1))
allocate(dens (nl))
allocate(el_depth(nl))
!
!std_dens(1)=0.
!std_dens(2)=30.
!do nz=3, std_dens_N-1
!std_dens(nz)=std_dens(nz-1)+10.5/real(std_dens_N-2)
!end do
!std_dens(std_dens_N)=40.
!
std_dd(:)=std_dens(2:)-std_dens(:std_dens_N-1)
dens =0.
std_dens_UVDZ=0. !will be U & V transports within the density class
std_dens_dVdT=0. !rate of change of a bin volume (for estimating the 'model drift')
std_dens_DIV =0. !meridional divergence within a density bin (for reconstruction of the diapycnal velocity) !TOP PRIORITY
if (Fer_GM) std_dens_DIV_fer =0. !meridional divergence of bolus velocity within a density bin (for reconstruction of the diapycnal velocity) !TOP PRIORITY
std_dens_VOL1=0. !temporal arrays for computing std_dens_dVdT
std_dens_VOL2=0.
std_dens_flux=0. !bouyancy flux for computation of surface bouyancy transformations
std_dens_Z =0. !will be the vertical position of the density class (for convertion between dAMOC <-> zMOC)
std_dens_H =0. !will be the vertical layerthickness of the density class (for convertion between dAMOC <-> zMOC)
depth =0.
el_depth =0.
firstcall_s=.false.
if (mode==0) return
end if
std_dens_UVDZ=0.
std_dens_w =0.! temporat thing for wiighting (ageraging) mean fields within a bin
std_dens_flux=0.
dens_flux_e =0.
std_dens_VOL2=0.
std_dens_DIV =0.
if (Fer_GM) std_dens_DIV_fer =0. !meridional divergence of bolus velocity within a density bin (for reconstruction of the diapycnal velocity) !TOP PRIORITY
std_dens_Z =0.
std_dens_H =0.
! proceed with fields at elements...
do elem=1, myDim_elem2D
elnodes=elem2D_nodes(:,elem)
nzmax = nlevels(elem)
nzmin = ulevels(elem)
! density flux on elements (although not related to binning it might be usefull for diagnostic and to verify the consistency)
do jj=1,3
dens_flux_e(elem)=dens_flux_e(elem) + (sw_alpha(ulevels_nod2D(elnodes(jj)),elnodes(jj)) * heat_flux_in(elnodes(jj)) / vcpw + &
sw_beta(ulevels_nod2D(elnodes(jj)),elnodes(jj)) * (relax_salt (elnodes(jj)) + water_flux(elnodes(jj)) * &
salt(ulevels_nod2D(elnodes(jj)),elnodes(jj))))
end do
dens_flux_e(elem) =dens_flux_e(elem)/3.0_WP
! density_dmoc is the sigma_2 density given at nodes. it is computed in oce_ale_pressure_bv
do nz=nzmin, nzmax-1
aux(nz)=sum(density_dmoc(nz, elnodes))/3.-1000.
end do
! dens will be the density within the column at nodes
el_depth(nzmax)=zbar_e_bot(elem)
do nz=nzmax-1,nzmin+1,-1
dens(nz) = (aux(nz) * helem(nz-1,elem)+&
aux(nz-1) * helem(nz, elem))/sum(helem(nz-1:nz,elem))
el_depth(nz) = el_depth(nz+1) + helem(nz, elem)
end do
dens(nzmax)=dens(nzmax-1)+(dens(nzmax-1)-dens(nzmax-2))*helem(nzmax-1,elem)/helem(nzmax-2,elem)
dens(nzmin) =dens(nzmin+1) +(dens(nzmin+1)-dens(nzmin+2)) *helem(nzmin, elem)/helem(nzmin+1,elem)
el_depth(1)=0.
! heat, freshwater and restoring at density classes
is=minloc(abs(std_dens-dens(1)),1)
std_dens_flux(1, is,elem)=std_dens_flux(1, is,elem)+elem_area(elem)*sum(sw_alpha(1,elnodes) * heat_flux_in(elnodes ))/3./vcpw
std_dens_flux(2, is,elem)=std_dens_flux(2, is,elem)+elem_area(elem)*sum(sw_beta (1,elnodes) * relax_salt (elnodes ))/3.
dd = 0.0_WP
do jj=1,3
dd = dd + (sw_beta (1,elnodes(jj)) * water_flux(elnodes(jj)) * salt(ulevels_nod2D(elnodes(jj)), elnodes(jj)))
end do
std_dens_flux(3, is,elem)=std_dens_flux(3, is,elem)+elem_area(elem)*dd/3.
do nz=nzmax-1,nzmin,-1
dmin=minval(dens(nz:nz+1))
dmax=maxval(dens(nz:nz+1))
ddiff=abs(dens(nz)-dens(nz+1))
! do vertical binning onto prescribed density classes
is=std_dens_N
do jj = 1, std_dens_N
if (std_dens(jj) > dmin) then
is = jj
exit
endif
end do
ie=1
do jj = std_dens_N,1,-1
if (std_dens(jj) < dmax) then
ie = jj
exit
endif
end do
if (std_dens(is)>=dmax) is=ie
if (std_dens(ie)<=dmin) ie=is
if (Fer_GM) then
uvdz_el=(UV(:,nz,elem)+fer_uv(:,nz,elem))*helem(nz,elem)
else
uvdz_el=UV(:,nz,elem)*helem(nz,elem)
end if
rhoz_el=(dens(nz)-dens(nz+1))/helem(nz,elem)
vol_el =helem(nz,elem)*elem_area(elem)
if (ie-is > 0) then
weight=(std_dens(is)-dmin)+std_dd(is)/2.
weight=max(weight, 0.)/ddiff
std_dens_UVDZ(:, is, elem)=std_dens_UVDZ(:, is, elem)+weight*uvdz_el
std_dens_VOL2( is, elem)=std_dens_VOL2( is, elem)+weight*vol_el
locz=el_depth(nz+1)+weight*helem(nz,elem)
std_dens_Z ( is, elem)=std_dens_Z ( is, elem)+locz*weight
std_dens_w( is, elem)=std_dens_w ( is, elem)+weight
do snz=is+1, ie-1
weight=(sum(std_dd(snz-1:snz))/2.)/ddiff
std_dens_UVDZ(:, snz, elem)=std_dens_UVDZ(:, snz, elem)+weight*uvdz_el
std_dens_VOL2( snz, elem)=std_dens_VOL2( snz, elem)+weight*vol_el
locz=locz+weight*helem(nz,elem)
std_dens_Z ( snz, elem)=std_dens_Z ( snz, elem)+locz*weight
std_dens_w ( snz, elem)=std_dens_w ( snz, elem)+weight
end do
weight=(dmax-std_dens(ie))+std_dd(ie-1)/2.
weight=max(weight, 0.)/ddiff
std_dens_UVDZ(:, ie, elem)=std_dens_UVDZ(:, ie, elem)+weight*uvdz_el
std_dens_VOL2( ie, elem)=std_dens_VOL2( ie, elem)+weight*vol_el
locz=locz+weight*helem(nz,elem)
std_dens_Z ( ie, elem)=std_dens_Z ( ie, elem)+locz*weight
std_dens_w ( ie, elem)=std_dens_w ( ie, elem)+weight
else
std_dens_UVDZ(:, is, elem)=std_dens_UVDZ(:, is, elem)+uvdz_el
std_dens_VOL2( is, elem)=std_dens_VOL2( is, elem)+vol_el
std_dens_Z ( is, elem)=std_dens_Z ( is, elem)+el_depth(nz+1)+helem(nz,elem)/2.
std_dens_w ( is, elem)=std_dens_w ( is, elem)+1._wp
end if
end do
end do
!___________________________________________________________________________
! proceed with fields at nodes (cycle over edges to compute the divergence)...
do edge=1, myDim_edge2D
if (myList_edge2D(edge) > edge2D_in) cycle
enodes=edges(:,edge)
eelems=edge_tri(:,edge)
nzmax =nlevels(eelems(1))
nzmin =ulevels(eelems(1))
if (eelems(2)>0) nzmax=max(nzmax, nlevels(eelems(2)))
do nz=nzmin, nzmax-1
aux(nz)=sum(density_dmoc(nz, enodes))/2.-1000.
end do
!_______________________________________________________________________
do e=1,2
elem=eelems(e)
if (elem<=0) CYCLE
deltaX=edge_cross_dxdy(1+(e-1)*2,edge)
deltaY=edge_cross_dxdy(2+(e-1)*2,edge)
nzmax =nlevels(elem)
nzmin =ulevels(elem)
!___________________________________________________________________
do nz=nzmax-1,nzmin+1,-1
dens(nz) = (aux(nz) * helem(nz-1,elem)+&
aux(nz-1) * helem(nz, elem))/sum(helem(nz-1:nz,elem))
end do
dens(nzmax)=dens(nzmax-1)+(dens(nzmax-1)-dens(nzmax-2))*helem(nzmax-1,elem)/helem(nzmax-2,elem)
dens(nzmin) =dens(nzmin+1) +(dens(nzmin+1)-dens(nzmin+2)) *helem(nzmin, elem) /helem(nzmin+1,elem)
is=minloc(abs(std_dens-dens(nzmin)),1)
!___________________________________________________________________
do nz=nzmax-1,nzmin,-1
div=(UV(2,nz,elem)*deltaX-UV(1,nz,elem)*deltaY)*helem(nz,elem)
if (e==2) div=-div
dmin =minval(dens(nz:nz+1))
dmax =maxval(dens(nz:nz+1))
ddiff=abs(dens(nz)-dens(nz+1))
! do vertical binning onto prescribed density classes
is=std_dens_N
do jj = 1, std_dens_N
if (std_dens(jj) > dmin) then
is = jj
exit
endif
end do
ie=1
do jj = std_dens_N,1,-1
if (std_dens(jj) < dmax) then
ie = jj
exit
endif
end do
if (std_dens(is)>=dmax) is=ie
if (std_dens(ie)<=dmin) ie=is
if (ie-is > 0) then
weight=(std_dens(is)-dmin)+std_dd(is)/2.
weight=max(weight, 0.)/ddiff
std_dens_DIV(is, enodes(1))=std_dens_DIV(is, enodes(1))+weight*div
std_dens_DIV(is, enodes(2))=std_dens_DIV(is, enodes(2))-weight*div
do snz=is+1, ie-1
weight=(sum(std_dd(snz-1:snz))/2.)/ddiff
std_dens_DIV(snz, enodes(1))=std_dens_DIV(snz, enodes(1))+weight*div
std_dens_DIV(snz, enodes(2))=std_dens_DIV(snz, enodes(2))-weight*div
end do
weight=(dmax-std_dens(ie))+std_dd(ie-1)/2.
weight=max(weight, 0.)/ddiff
std_dens_DIV(ie, enodes(1))=std_dens_DIV(ie, enodes(1))+weight*div
std_dens_DIV(ie, enodes(2))=std_dens_DIV(ie, enodes(2))-weight*div
else
std_dens_DIV(is, enodes(1))=std_dens_DIV(is, enodes(1))+div
std_dens_DIV(is, enodes(2))=std_dens_DIV(is, enodes(2))-div
end if ! --> if (ie-is > 0) then
end do ! --> do nz=nzmax-1,nzmin,-1
!___________________________________________________________________
! compute density class divergence from GM Bolus velocity
if (Fer_GM) then
do nz=nzmax-1,nzmin,-1
div=(fer_uv(2,nz,elem)*deltaX-fer_uv(1,nz,elem)*deltaY)*helem(nz,elem)
if (e==2) div=-div
dmin =minval(dens(nz:nz+1))
dmax =maxval(dens(nz:nz+1))
ddiff=abs(dens(nz)-dens(nz+1))
! do vertical binning onto prescribed density classes
is=std_dens_N
do jj = 1, std_dens_N
if (std_dens(jj) > dmin) then
is = jj
exit
endif
end do
ie=1
do jj = std_dens_N,1,-1
if (std_dens(jj) < dmax) then
ie = jj
exit
endif
end do
if (std_dens(is)>=dmax) is=ie
if (std_dens(ie)<=dmin) ie=is
if (ie-is > 0) then
weight=(std_dens(is)-dmin)+std_dd(is)/2.
weight=max(weight, 0.)/ddiff
std_dens_DIV_fer(is, enodes(1))=std_dens_DIV_fer(is, enodes(1))+weight*div
std_dens_DIV_fer(is, enodes(2))=std_dens_DIV_fer(is, enodes(2))-weight*div
do snz=is+1, ie-1
weight=(sum(std_dd(snz-1:snz))/2.)/ddiff
std_dens_DIV_fer(snz, enodes(1))=std_dens_DIV_fer(snz, enodes(1))+weight*div
std_dens_DIV_fer(snz, enodes(2))=std_dens_DIV_fer(snz, enodes(2))-weight*div
end do
weight=(dmax-std_dens(ie))+std_dd(ie-1)/2.
weight=max(weight, 0.)/ddiff
std_dens_DIV_fer(ie, enodes(1))=std_dens_DIV_fer(ie, enodes(1))+weight*div
std_dens_DIV_fer(ie, enodes(2))=std_dens_DIV_fer(ie, enodes(2))-weight*div
else
std_dens_DIV_fer(is, enodes(1))=std_dens_DIV_fer(is, enodes(1))+div
std_dens_DIV_fer(is, enodes(2))=std_dens_DIV_fer(is, enodes(2))-div
end if ! --> if (ie-is > 0) then
end do ! --> do nz=nzmax-1,nzmin,-1
end if ! --> if (Fer_GM) then
end do ! --> do e=1,2
end do ! --> do edge=1, myDim_edge2D
!_____________________________________________________________________________
where (std_dens_w > 0.)
std_dens_Z =std_dens_Z / std_dens_w
end where
!_____________________________________________________________________________
! compute density class volume change over time
if (.not. firstcall_e) then
std_dens_dVdT=(std_dens_VOL2-std_dens_VOL1)/dt
end if
std_dens_VOL1=std_dens_VOL2
!_____________________________________________________________________________
! compute mean thickness of density class, try to extract better vertical position
! when do projection into zcoord.
std_dens_H = std_dens_VOL2
do jj = 1, std_dens_N
std_dens_H(jj,1:myDim_elem2D) = std_dens_H(jj,1:myDim_elem2D)/elem_area(1:myDim_elem2D)
end do
firstcall_e=.false.
end subroutine diag_densMOC
!
!
!_______________________________________________________________________________
subroutine compute_extflds(mode, dynamics, tracers, partit, mesh)
IMPLICIT NONE
integer, intent(in) :: mode
logical, save :: firstcall=.true.
type(t_dyn) , intent(in), target :: dynamics
type(t_tracer), intent(in) , target :: tracers
type(t_partit), intent(inout), target :: partit
type(t_mesh) , intent(in) , target :: mesh
real(kind=WP), dimension(:,:), pointer :: temp, salt
real(kind=WP) :: zn, zint, tup, tlo
integer :: n, nz, nzmin, nzmax
real(kind=WP) :: whichtemp= 20.0_WP ! which isotherm to compute (set 20 per default)
real(kind=WP) :: whichdepth=300.0_WP ! for which tepth to average for tempzavg & saltzavg
#include "associate_part_def.h"
#include "associate_mesh_def.h"
#include "associate_part_ass.h"
#include "associate_mesh_ass.h"
if (firstcall) then !allocate the stuff at the first call
allocate(zisotherm(myDim_nod2D+eDim_nod2D))
allocate(tempzavg(myDim_nod2D+eDim_nod2D), saltzavg(myDim_nod2D+eDim_nod2D))
zisotherm=0.0_WP
tempzavg =0.0_WP
saltzavg =0.0_WP
firstcall=.false.
if (mode==0) return
end if
temp => tracers%data(1)%values(:,:)
salt => tracers%data(2)%values(:,:)
!$OMP PARALLEL DO DEFAULT(SHARED) PRIVATE(n, nz, nzmin, nzmax, zn, tup, tlo)
DO n=1, myDim_nod2D
saltzavg(n) =0.0_WP
nzmax=nlevels_nod2D(n)
nzmin=ulevels_nod2D(n)
zn =0.0_WP
do nz=nzmin+1, nzmax-1
tup=temp(nz-1, n)
if (tup < whichtemp) exit
tlo=temp(nz, n)
if ((tup-whichtemp)*(tlo-whichtemp)<0) then
zn=zn+0.5_WP*(hnode(nz-1, n)+(whichtemp-tup)*sum(hnode(nz-1:nz, n))/(tlo-tup))
exit
end if
zn=zn+hnode(nz-1, n)
end do
zisotherm(n)=zn
END DO
!$OMP END PARALLEL DO
!$OMP PARALLEL DO DEFAULT(SHARED) PRIVATE(n, nz, nzmin, nzmax, zint)
DO n=1, myDim_nod2D
tempzavg(n) =0.0_WP
saltzavg(n) =0.0_WP
nzmax=nlevels_nod2D(n)
nzmin=ulevels_nod2D(n)
zint=0.0_WP
do nz=nzmin, nzmax-1
zint=zint+hnode(nz, n)
tempzavg(n)=tempzavg(n)+temp(nz, n)*hnode(nz, n)
saltzavg(n)=saltzavg(n)+salt(nz, n)*hnode(nz, n)
if (zint>=whichdepth) exit
end do
tempzavg(n)=tempzavg(n)/zint
saltzavg(n)=saltzavg(n)/zint
END DO
!$OMP END PARALLEL DO
call exchange_nod(zisotherm, partit)
call exchange_nod(tempzavg, partit)
call exchange_nod(saltzavg, partit)
end subroutine compute_extflds
!_______________________________________________________________________________
subroutine compute_destinE(mode, dynamics, tracers, partit, mesh)
IMPLICIT NONE
integer, intent(in) :: mode
logical, save :: firstcall=.true.
type(t_dyn) , intent(in), target :: dynamics
type(t_tracer), intent(in) , target :: tracers
type(t_partit), intent(inout), target :: partit
type(t_mesh) , intent(in) , target :: mesh
real(kind=WP), dimension(:,:), pointer :: temp, salt
real(kind=WP) :: zn, zint, tup, tlo
integer :: n, nz, nzmin, nzmax
integer :: ndepths=3
real(kind=WP), dimension(3) :: whichdepth = (/ 300.0_WP, 700.0_WP, 100000._WP /)
#include "associate_part_def.h"
#include "associate_mesh_def.h"
#include "associate_part_ass.h"
#include "associate_mesh_ass.h"
if (firstcall) then !allocate the stuff at the first call
allocate(heatcontent(myDim_nod2D+eDim_nod2D, ndepths))
heatcontent =0.0_WP
firstcall=.false.
if (mode==0) return
end if
temp => tracers%data(1)%values(:,:)
!$OMP PARALLEL DO DEFAULT(SHARED) PRIVATE(n, nz, nzmin, nzmax, zint)
DO n=1, myDim_nod2D
heatcontent(n, :) =0.0_WP
nzmax=nlevels_nod2D(n)
nzmin=ulevels_nod2D(n)
zint=0.0_WP
do nz=nzmin, nzmax-1
zint=zint+hnode(nz, n)
where (whichdepth>zint)
heatcontent(n,:)=heatcontent(n,:)+temp(nz,n)*hnode(nz,n)
end where
end do
heatcontent(n,:)=1025.*3990.*heatcontent(n,:)
END DO
!$OMP END PARALLEL DO
do n=1, size(whichdepth)
call exchange_nod(heatcontent(:,n), partit)
end do
end subroutine compute_destinE
!_______________________________________________________________________________
subroutine compute_ice_diag(mode, ice, partit, mesh)
IMPLICIT NONE
integer, intent(in) :: mode
logical, save :: firstcall=.true.
type(t_ice) , intent(in), target :: ice
type(t_partit), intent(inout), target :: partit
type(t_mesh) , intent(in) , target :: mesh
integer :: n
#include "associate_part_def.h"
#include "associate_mesh_def.h"
#include "associate_part_ass.h"
#include "associate_mesh_ass.h"
if (firstcall) then !allocate the stuff at the first call
allocate(vol_ice(myDim_nod2D+eDim_nod2D), vol_snow(myDim_nod2D+eDim_nod2D))
vol_ice =0.0_WP
vol_snow=0.0_WP
firstcall=.false.
if (mode==0) return
end if
!$OMP PARALLEL DO
DO n=1, myDim_nod2D
vol_ice(n) =ice%data(1)%values(n)*ice%data(2)%values(n)
vol_snow(n)=ice%data(1)%values(n)*ice%data(3)%values(n)
END DO
!$OMP END PARALLEL DO
end subroutine compute_ice_diag
! SST in K
subroutine compute_thetao(mode, tracers, partit, mesh)
implicit none
integer, intent(in) :: mode
type(t_tracer), intent(in) , target :: tracers
type(t_mesh) , intent(in) , target :: mesh
type(t_partit), intent(in), target :: partit
logical, save :: firstcall=.true.
#include "associate_part_def.h"
#include "associate_mesh_def.h"
#include "associate_part_ass.h"
#include "associate_mesh_ass.h"
if (firstcall) then !allocate the stuff at the first call
allocate(thetao(mydim_nod2D))
firstcall=.false.
if (mode==0) return
end if
!skipping loop
thetao(:) = tracers%data(1)%values(1,1:myDim_nod2D)+273.15_WP
end subroutine compute_thetao
!
!
!
!_______________________________________________________________________________
subroutine diag_uvw_sqr(mode, dynamics, partit, mesh)
implicit none
type(t_dyn) , intent(inout), target :: dynamics
type(t_partit), intent(inout), target :: partit
type(t_mesh) , intent(in) , target :: mesh
integer, intent(in) :: mode
logical, save :: firstcall=.true.
integer :: elem, node, nz, nzu, nzl, elnodes(3)
real(kind=WP), dimension(:,:,:), pointer :: UV, fer_UV
real(kind=WP), dimension(:,:), pointer :: Wvel, fer_Wvel
#include "associate_part_def.h"
#include "associate_mesh_def.h"
#include "associate_part_ass.h"
#include "associate_mesh_ass.h"
!___________________________________________________________________________
UV => dynamics%uv(:,:,:)
Wvel => dynamics%w(:,:)
if (Fer_GM) then
fer_UV => dynamics%fer_uv(:,:,:)
fer_Wvel => dynamics%fer_w(:,:)
end if
!___________________________________________________________________________
if (firstcall) then !allocate the stuff at the first call
allocate(uv2(2,nl-1,myDim_elem2D))
allocate(wvel2(nl-1,myDim_nod2D))
uv2 = 0.0_WP
wvel2 = 0.0_WP
firstcall=.false.
if (mode==0) return
end if
!___________________________________________________________________________
! compute squared horizontal velocities
do elem=1,myDim_elem2D
nzu = ulevels(elem)
nzl = nlevels(elem)-1
if (Fer_GM) then
do nz=nzu, nzl
uv2(1,nz,elem) = (UV(1,nz,elem) + fer_UV(1,nz, elem))
uv2(2,nz,elem) = (UV(2,nz,elem) + fer_UV(2,nz, elem))
uv2(1,nz,elem) = uv2(1,nz,elem) * uv2(1,nz,elem)
uv2(2,nz,elem) = uv2(2,nz,elem) * uv2(2,nz,elem)
end do
else
do nz=nzu, nzl
uv2(1,nz,elem) = UV(1,nz,elem)*UV(1,nz,elem)
uv2(2,nz,elem) = UV(2,nz,elem)*UV(2,nz,elem)
end do
end if
end do
!___________________________________________________________________________
! compute squared vertical velocities
do node=1,myDim_nod2D
nzu = ulevels_nod2D(node)
nzl = nlevels_nod2D(node)-1
if (Fer_GM) then
do nz=nzu, nzl
wvel2(nz,node) = (Wvel(nz,node) + fer_Wvel(nz, node))
wvel2(nz,node) = wvel2(nz,node) * wvel2(nz,node)
end do
else
do nz=nzu, nzl
wvel2(nz,node) = Wvel(nz,node)*Wvel(nz,node)
end do
end if
end do
end subroutine diag_uvw_sqr