-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathcvmix_kpp.F90
More file actions
3756 lines (3226 loc) · 148 KB
/
cvmix_kpp.F90
File metadata and controls
3756 lines (3226 loc) · 148 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 cvmix_kpp
!BOP
!\newpage
! !MODULE: cvmix_kpp
!
! !AUTHOR:
! Michael N. Levy, NCAR (mlevy@ucar.edu)
!
! !DESCRIPTION:
! This module contains routines to initialize the derived types needed for
! KPP mixing and to set the viscosity and diffusivity coefficients
! accordingly.
!\\
!\\
! References:\\
! * WG Large, JC McWilliams, and SC Doney.
! Oceanic Vertical Mixing: A Review and a Model with a Nonlocal Boundary Layer
! Parameterization.
! Review of Geophysics, 1994.
!\\
!\\
! !USES:
use cvmix_kinds_and_types, only : cvmix_r8, &
cvmix_strlen, &
cvmix_zero, &
cvmix_one, &
cvmix_PI, &
cvmix_data_type, &
cvmix_global_params_type, &
CVMIX_OVERWRITE_OLD_VAL, &
CVMIX_SUM_OLD_AND_NEW_VALS, &
CVMIX_MAX_OLD_AND_NEW_VALS
use cvmix_math, only : CVMIX_MATH_INTERP_LINEAR, &
CVMIX_MATH_INTERP_QUAD, &
CVMIX_MATH_INTERP_CUBE_SPLINE, &
cvmix_math_poly_interp, &
cvmix_math_cubic_root_find, &
cvmix_math_evaluate_cubic
use cvmix_put_get, only : cvmix_put
use cvmix_utils, only : cvmix_update_wrap
!EOP
implicit none
private
save
!BOP
! !DEFINED PARAMETERS:
integer, parameter :: CVMIX_KPP_INTERP_LMD94 = -1
integer, parameter :: CVMIX_KPP_MATCH_BOTH = 1
integer, parameter :: CVMIX_KPP_MATCH_GRADIENT = 2
integer, parameter :: CVMIX_KPP_SIMPLE_SHAPES = 3
integer, parameter :: CVMIX_KPP_PARABOLIC_NONLOCAL = 4
integer, parameter :: NO_LANGMUIR_MIXING = -1
integer, parameter :: LANGMUIR_MIXING_LWF16 = 1
integer, parameter :: LANGMUIR_MIXING_RWHGK16 = 2
integer, parameter :: NO_LANGMUIR_ENTRAINMENT = -1
integer, parameter :: LANGMUIR_ENTRAINMENT_LWF16 = 1
integer, parameter :: LANGMUIR_ENTRAINMENT_LF17 = 2
integer, parameter :: LANGMUIR_ENTRAINMENT_RWHGK16 = 3
integer, parameter :: ML_DIFFUSIVITY_SHAPE = 5 ! ML_Diffusivity
! !PUBLIC MEMBER FUNCTIONS:
public :: cvmix_init_kpp
! Note: cvmix_kpp_compute_OBL_depth would be part of cvmix_coeffs_kpp but
! CVMix can not smooth the boundary layer depth or correct the
! buoyancy flux term
public :: cvmix_kpp_compute_OBL_depth
public :: cvmix_coeffs_kpp
public :: cvmix_put_kpp
public :: cvmix_get_kpp_real
public :: cvmix_kpp_compute_bulk_Richardson
public :: cvmix_kpp_compute_turbulent_scales
public :: cvmix_kpp_compute_unresolved_shear
public :: cvmix_kpp_composite_Gshape !STOKES_MOST
public :: cvmix_kpp_compute_StokesXi !STOKES_MOST
! These are public for testing, may end up private later
public :: cvmix_kpp_compute_shape_function_coeffs
public :: cvmix_kpp_compute_kOBL_depth
public :: cvmix_kpp_compute_enhanced_diff
public :: cvmix_kpp_compute_nu_at_OBL_depth_LMD94
public :: cvmix_kpp_EFactor_model
public :: cvmix_kpp_ustokes_SL_model
public :: cvmix_kpp_compute_ER_depth
interface cvmix_coeffs_kpp
module procedure cvmix_coeffs_kpp_low
module procedure cvmix_coeffs_kpp_wrap
end interface cvmix_coeffs_kpp
interface cvmix_put_kpp
module procedure cvmix_put_kpp_int
module procedure cvmix_put_kpp_real
module procedure cvmix_put_kpp_logical
end interface cvmix_put_kpp
interface cvmix_kpp_compute_OBL_depth
module procedure cvmix_kpp_compute_OBL_depth_low
module procedure cvmix_kpp_compute_OBL_depth_wrap
end interface cvmix_kpp_compute_OBL_depth
interface cvmix_kpp_compute_turbulent_scales
module procedure cvmix_kpp_compute_turbulent_scales_0d
module procedure cvmix_kpp_compute_turbulent_scales_1d_sigma
module procedure cvmix_kpp_compute_turbulent_scales_1d_OBL
end interface cvmix_kpp_compute_turbulent_scales
! !PUBLIC TYPES:
! cvmix_kpp_params_type contains the necessary parameters for KPP mixing
type, public :: cvmix_kpp_params_type
private
real(cvmix_r8) :: Ri_crit ! Critical Richardson number
! (OBL_depth = where bulk Ri = Ri_crit)
real(cvmix_r8) :: minOBLdepth ! Minimum allowable OBL depth
! (Default is 0 m => no minimum)
real(cvmix_r8) :: maxOBLdepth ! Maximum allowable OBL depth
! (Default is 0 m => no maximum)
real(cvmix_r8) :: minVtsqr ! Minimum allowable unresolved shear
! (Default is 1e-10 m^2/s^2)
real(cvmix_r8) :: vonkarman ! von Karman constant
real(cvmix_r8) :: Cstar ! coefficient for nonlinear transport
real(cvmix_r8) :: nonlocal_coeff ! Cs from Eq (20) in LMD94
! Default value comes from paper, but
! some users may set it = 1.
! For velocity scale function, _m => momentum and _s => scalar (tracer)
real(cvmix_r8) :: zeta_m ! parameter for computing vel scale func
real(cvmix_r8) :: zeta_s ! parameter for computing vel scale func
real(cvmix_r8) :: a_m ! parameter for computing vel scale func
real(cvmix_r8) :: c_m ! parameter for computing vel scale func
real(cvmix_r8) :: a_s ! parameter for computing vel scale func
real(cvmix_r8) :: c_s ! parameter for computing vel scale func
real(cvmix_r8) :: surf_layer_ext ! nondimensional extent of surface layer
! (expressed in sigma-coordinates)
integer :: interp_type ! interpolation type used to interpolate
! bulk Richardson number
integer :: interp_type2 ! interpolation type used to interpolate
! diff and visc at OBL_depth
! Cv is a parameter used to compute the unresolved shear. By default, the
! formula from Eq. (A3) of Danabasoglu et al. is used, but a single
! scalar value can be set instead.
real(cvmix_r8) :: Cv
! MatchTechnique is set by a string of the same name as an argument in
! cvmix_init_kpp. It determines how matching between the boundary layer
! and ocean interior is handled at the interface. Note that this also
! controls whether the shape function used to compute the coefficient in
! front of the nonlocal term is the same as that used to compute the
! gradient term.
! Options (for cvmix_init_kpp) are
! (i) SimpleShapes => Shape functions for both the gradient and nonlocal
! terms vanish at interface
! (ii) MatchGradient => Shape function for nonlocal term vanishes at
! interface, but gradient term matches interior
! values.
! (iii) MatchBoth => Shape functions for both the gradient and nonlocal
! term match interior values at interface
! (iv) ParabolicNonLocal => Shape function for the nonlocal term is
! (1-sigma)^2, gradient term is sigma*(1-sigma)^2
integer :: MatchTechnique
! Flag for what to do with old values of CVmix_vars%[MTS]diff
integer :: handle_old_vals
! Logic flags to dictate if / how various terms are computed
logical :: lStokesMOST ! True => use Stokes Similarty package
logical :: lscalar_Cv ! True => use the scalar Cv value
logical :: lEkman ! True => compute Ekman depth limit
logical :: lMonOb ! True => compute Monin-Obukhov limit
logical :: lnoDGat1 ! True => G'(1) = 0 (shape function)
! False => compute G'(1) as in LMD94
logical :: lenhanced_diff ! True => enhance diffusivity at OBL
integer :: Langmuir_Mixing_Opt
! Option of Langmuir enhanced mixing
! - apply an enhancement factor to the
! turbulent velocity scale
integer :: Langmuir_Entrainment_Opt
! Option of Langmuir turbulence enhanced
! entrainment - modify the unresolved shear
logical :: l_LMD_ws ! flag to use original Large et al. (1994)
! equations for computing turbulent scales
! rather than the updated methodology in
! Danabasoglu et al. (2006). The latter
! limits sigma to be < surf_layer_extent
! when computing turbulent scales while
! the former only imposes this restriction
! in unstable regimes.
real(cvmix_r8) :: c_LT, c_ST, c_CT ! Empirical constants in the scaling of the
! entrainment buoyancy flux
! (20) in Li and Fox-Kemper, 2017, JPO
real(cvmix_r8) :: p_LT ! Power of Langmuir number in the above
! scaling
!BGR
real(cvmix_r8) :: RWHGK_ENTR_COEF,& ! Coefficient and exponent from
RWHGK_ENTR_EXP ! RWHGK16 Langmuir parameterization
real(cvmix_r8) :: CVt2 ! Tunable parameter for convection entrainment
! (Only used with StokesMOST)
real(cvmix_r8) :: ER_Cb ! Entrainment Rule TKE buoyancy production weight [nondim]
real(cvmix_r8) :: ER_Cs ! Entrainment Rule TKE Stokes production weight [nondim]
real(cvmix_r8) :: ER_Cu ! Entrainment Rule TKE shear production weight [nondim]
logical :: ML_diffusivity ! uses the Machine Learned equations to set diffusivity
! from Sane et al. (2025) https://doi.org/10.31219/osf.io/uab7v_v2
end type cvmix_kpp_params_type
!EOP
type(cvmix_kpp_params_type), target :: CVmix_kpp_params_saved
contains
!BOP
! !IROUTINE: cvmix_init_kpp
! !INTERFACE:
subroutine cvmix_init_kpp(ri_crit, minOBLdepth, maxOBLdepth, minVtsqr, &
vonkarman, Cstar, zeta_m, zeta_s, surf_layer_ext, &
CVt2, Cv, interp_type, interp_type2, MatchTechnique, &
old_vals, lEkman, lStokesMOST, lMonOb, lnoDGat1, &
lenhanced_diff, lnonzero_surf_nonlocal, &
Langmuir_mixing_str, Langmuir_entrainment_str, &
l_LMD_ws, ML_diffusivity, &
ER_Cb, ER_Cs, ER_Cu, CVmix_kpp_params_user)
! !DESCRIPTION:
! Initialization routine for KPP mixing.
!\\
!\\
! !INPUT PARAMETERS:
real(cvmix_r8), optional, intent(in) :: ri_crit, &
minOBLdepth, &
maxOBLdepth, &
minVtsqr, &
vonkarman, &
Cstar, &
zeta_m, &
zeta_s, &
surf_layer_ext, &
CVt2, &
Cv, &
ER_Cb, &
ER_Cs, &
ER_Cu
character(len=*), optional, intent(in) :: interp_type, &
interp_type2, &
MatchTechnique, &
old_vals, &
Langmuir_mixing_str, &
Langmuir_entrainment_str
logical, optional, intent(in) :: lEkman, &
lStokesMOST, &
lMonOb, &
lnoDGat1, &
lenhanced_diff, &
lnonzero_surf_nonlocal, &
l_LMD_ws, &
ML_diffusivity
! !OUTPUT PARAMETERS:
type(cvmix_kpp_params_type), intent(inout), target, optional :: &
CVmix_kpp_params_user
!EOP
!BOC
real(cvmix_r8) :: zm, zs, a_m, a_s, c_m, c_s
real(cvmix_r8) :: Cstar_loc, vonkar_loc, surf_layer_ext_loc
real(cvmix_r8) :: ER_Cb_loc, ER_Cs_loc, ER_Cu_loc
real(cvmix_r8) :: nonlocal_coeff
if (present(ri_crit)) then
if (ri_crit.lt.cvmix_zero) then
print*, "ERROR: ri_crit can not be negative."
stop 1
end if
call cvmix_put_kpp('Ri_crit', ri_crit, CVmix_kpp_params_user)
else
call cvmix_put_kpp('Ri_crit', 0.3_cvmix_r8, CVmix_kpp_params_user)
end if
if (present(minOBLdepth)) then
if (minOBLdepth.lt.cvmix_zero) then
print*, "ERROR: minOBLdepth can not be negative."
stop 1
end if
call cvmix_put_kpp('minOBLdepth', minOBLdepth, CVmix_kpp_params_user)
else
call cvmix_put_kpp('minOBLdepth', 0, CVmix_kpp_params_user)
end if
if (present(maxOBLdepth)) then
if (maxOBLdepth.lt.cvmix_zero) then
print*, "ERROR: maxOBLdepth can not be negative."
stop 1
end if
call cvmix_put_kpp('maxOBLdepth', maxOBLdepth, CVmix_kpp_params_user)
else
call cvmix_put_kpp('maxOBLdepth', 0, CVmix_kpp_params_user)
end if
if (present(minVtsqr)) then
if (minVtsqr.lt.cvmix_zero) then
print*, "ERROR: minVtsqr can not be negative."
stop 1
end if
call cvmix_put_kpp('minVtsqr', minVtsqr, CVmix_kpp_params_user)
else
call cvmix_put_kpp('minVtsqr', 1e-10_cvmix_r8, CVmix_kpp_params_user)
end if
if (present(vonkarman)) then
if (vonkarman.lt.cvmix_zero) then
print*, "ERROR: vonkarman can not be negative."
stop 1
end if
vonkar_loc = vonkarman
else
vonkar_loc = 0.4_cvmix_r8
end if
call cvmix_put_kpp('vonkarman', vonkar_loc, CVmix_kpp_params_user)
if (present(Cstar)) then
Cstar_loc = Cstar
else
Cstar_loc = real(10,cvmix_r8)
end if
call cvmix_put_kpp('Cstar', Cstar_loc, CVmix_kpp_params_user)
if (present(zeta_m)) then
if (zeta_m.ge.cvmix_zero) then
print*, "ERROR: zeta_m must be negative."
stop 1
end if
zm = zeta_m
else
! default value for zeta_m is -1/5
zm = -0.2_cvmix_r8
end if
call cvmix_put_kpp('zeta_m', zm, CVmix_kpp_params_user)
if (present(zeta_s)) then
if (zeta_s.ge.cvmix_zero) then
print*, "ERROR: zeta_s must be negative."
stop 1
end if
zs = zeta_s
else
! Default value for zeta_s is -1
zs = -cvmix_one
end if
call cvmix_put_kpp('zeta_s', zs, CVmix_kpp_params_user)
! a_m, a_s, c_m, and c_s are computed from zeta_m and zeta_s
! a_m, c_m, and c_s are all non-negative. a_s may be negative depending
! on the value of zeta_s
a_m = ((cvmix_one - real(16,cvmix_r8)*zm)**(-0.25_cvmix_r8))* &
(cvmix_one - real(4,cvmix_r8)*zm)
c_m = ((cvmix_one - real(16,cvmix_r8)*zm)**(-0.25_cvmix_r8))* &
real(12,cvmix_r8)
call cvmix_put_kpp('a_m', a_m, CVmix_kpp_params_user)
call cvmix_put_kpp('c_m', c_m, CVmix_kpp_params_user)
a_s = sqrt(cvmix_one - real(16,cvmix_r8)*zs)* &
(cvmix_one + real(8,cvmix_r8)*zs)
c_s = real(24,cvmix_r8)*sqrt(cvmix_one - real(16,cvmix_r8)*zs)
call cvmix_put_kpp('a_s', a_s, CVmix_kpp_params_user)
call cvmix_put_kpp('c_s', c_s, CVmix_kpp_params_user)
if (present(surf_layer_ext)) then
if ((surf_layer_ext.lt.cvmix_zero).or.(surf_layer_ext.gt.cvmix_one)) &
then
print*, "surf_layer_ext must be between 0 and 1, inclusive."
stop 1
end if
surf_layer_ext_loc = surf_layer_ext
else
surf_layer_ext_loc = 0.1_cvmix_r8
end if
call cvmix_put_kpp('surf_layer_ext', surf_layer_ext_loc, &
CVmix_kpp_params_user)
if (present(Cv)) then
! Use scalar Cv parameter
call cvmix_put_kpp('Cv', CV, CVmix_kpp_params_user)
call cvmix_put_kpp('lscalar_Cv', .true., CVmix_kpp_params_user)
else
! Use Eq. (A3) from Danabasoglu et al.
call cvmix_put_kpp('lscalar_Cv', .false., CVmix_kpp_params_user)
end if
if (present(interp_type)) then
select case (trim(interp_type))
case ('line', 'linear')
call cvmix_put_kpp('interp_type', CVMIX_MATH_INTERP_LINEAR, &
CVmix_kpp_params_user)
case ('quad', 'quadratic')
call cvmix_put_kpp('interp_type', CVMIX_MATH_INTERP_QUAD, &
CVmix_kpp_params_user)
case ('cube', 'cubic', 'cubic_spline', 'cubic spline')
call cvmix_put_kpp('interp_type', CVMIX_MATH_INTERP_CUBE_SPLINE, &
CVmix_kpp_params_user)
case DEFAULT
print*, "ERROR: ", trim(interp_type), " is not a valid type of ", &
"interpolation!"
stop 1
end select
else
call cvmix_put_kpp('interp_type', CVMIX_MATH_INTERP_QUAD, &
CVmix_kpp_params_user)
end if
if (present(interp_type2)) then
select case (trim(interp_type2))
case ('line', 'linear')
call cvmix_put_kpp('interp_type2', CVMIX_MATH_INTERP_LINEAR, &
CVmix_kpp_params_user)
case ('quad', 'quadratic')
call cvmix_put_kpp('interp_type2', CVMIX_MATH_INTERP_QUAD, &
CVmix_kpp_params_user)
case ('cube', 'cubic', 'cubic_spline', 'cubic spline')
call cvmix_put_kpp('interp_type2', CVMIX_MATH_INTERP_CUBE_SPLINE, &
CVmix_kpp_params_user)
case ('POP','LMD94')
call cvmix_put_kpp('interp_type2', CVMIX_KPP_INTERP_LMD94, &
CVmix_kpp_params_user)
case DEFAULT
print*, "ERROR: ", trim(interp_type2), " is not a valid type of ", &
"interpolation!"
stop 1
end select
else
call cvmix_put_kpp('interp_type2', CVMIX_KPP_INTERP_LMD94, &
CVmix_kpp_params_user)
end if
if (present(MatchTechnique)) then
select case (trim(MatchTechnique))
case ('MatchBoth')
call cvmix_put_kpp('MatchTechnique', CVMIX_KPP_MATCH_BOTH, &
CVmix_kpp_params_user)
case ('MatchGradient')
call cvmix_put_kpp('MatchTechnique', CVMIX_KPP_MATCH_GRADIENT, &
CVmix_kpp_params_user)
case ('SimpleShapes')
call cvmix_put_kpp('MatchTechnique', CVMIX_KPP_SIMPLE_SHAPES, &
CVmix_kpp_params_user)
case ('ParabolicNonLocal')
call cvmix_put_kpp('MatchTechnique', CVMIX_KPP_PARABOLIC_NONLOCAL, &
CVmix_kpp_params_user)
case ('ML_Diffusivity_Shape') ! ML_Diffusivity shape function
call cvmix_put_kpp('MatchTechnique', ML_DIFFUSIVITY_SHAPE, CVmix_kpp_params_user)
case DEFAULT
print*, "ERROR: ", trim(MatchTechnique), " is not a valid choice ", &
"for MatchTechnique!"
stop 1
end select
else
call cvmix_put_kpp('MatchTechnique', CVMIX_KPP_SIMPLE_SHAPES, &
CVmix_kpp_params_user)
end if
! --- Add this block to for ML_diffusivity ---
if (present(ML_diffusivity)) then ! ML_diffusivity
call cvmix_put_kpp('ML_diffusivity', ML_diffusivity, CVmix_kpp_params_user)
if (ML_diffusivity) then
call cvmix_put_kpp('MatchTechnique', ML_DIFFUSIVITY_SHAPE, CVmix_kpp_params_user)
end if
else
call cvmix_put_kpp('ML_diffusivity', .false., CVmix_kpp_params_user)
end if
if (present(old_vals)) then
select case (trim(old_vals))
case ("overwrite")
call cvmix_put_kpp('handle_old_vals', CVMIX_OVERWRITE_OLD_VAL, &
cvmix_kpp_params_user)
case ("sum")
call cvmix_put_kpp('handle_old_vals', CVMIX_SUM_OLD_AND_NEW_VALS, &
cvmix_kpp_params_user)
case ("max")
call cvmix_put_kpp('handle_old_vals', CVMIX_MAX_OLD_AND_NEW_VALS, &
cvmix_kpp_params_user)
case DEFAULT
print*, "ERROR: ", trim(old_vals), " is not a valid option for ", &
"handling old values of diff and visc."
stop 1
end select
else
call cvmix_put_kpp('handle_old_vals', CVMIX_OVERWRITE_OLD_VAL, &
cvmix_kpp_params_user)
end if
if (present(lStokesMOST)) then
call cvmix_put_kpp('lStokesMOST', lStokesMOST, CVmix_kpp_params_user)
else
call cvmix_put_kpp('lStokesMOST', .false., CVmix_kpp_params_user)
end if
if (present(CVt2)) then
call cvmix_put_kpp('CVt2', CVt2, CVmix_kpp_params_user)
else
call cvmix_put_kpp('CVt2', 1.6_cvmix_r8, CVmix_kpp_params_user)
end if
if (present(lEkman)) then
call cvmix_put_kpp('lEkman', lEkman, CVmix_kpp_params_user)
else
call cvmix_put_kpp('lEkman', .false., CVmix_kpp_params_user)
end if
if (present(lMonOb)) then
call cvmix_put_kpp('lMonOb', lMonOb, CVmix_kpp_params_user)
else
call cvmix_put_kpp('lMonOb', .false., CVmix_kpp_params_user)
end if
if (present(lnoDGat1)) then
call cvmix_put_kpp('lnoDGat1', lnoDGat1, CVmix_kpp_params_user)
else
call cvmix_put_kpp('lnoDGat1', .true., CVmix_kpp_params_user)
end if
if (present(lenhanced_diff)) then
call cvmix_put_kpp('lenhanced_diff', lenhanced_diff, &
CVmix_kpp_params_user)
else
call cvmix_put_kpp('lenhanced_diff', .true., CVmix_kpp_params_user)
end if
if (present(Langmuir_mixing_str)) then
select case (trim(Langmuir_mixing_str))
case ("LWF16")
call cvmix_put_kpp('Langmuir_Mixing_Opt', LANGMUIR_MIXING_LWF16 , &
CVmix_kpp_params_user)
case ("RWHGK16")
call cvmix_put_kpp('Langmuir_Mixing_Opt', &
LANGMUIR_MIXING_RWHGK16, CVmix_kpp_params_user)
case ("NONE")
call cvmix_put_kpp('Langmuir_Mixing_Opt', &
NO_LANGMUIR_MIXING, CVmix_kpp_params_user)
case DEFAULT
print*, "ERROR: ", trim(Langmuir_mixing_str), " is not a valid ", &
"option for Langmuir_mixing_str!"
stop 1
end select
else
call cvmix_put_kpp('Langmuir_Mixing_Opt', &
NO_LANGMUIR_MIXING, CVmix_kpp_params_user)
end if
if (present(Langmuir_entrainment_str)) then
select case (trim(Langmuir_entrainment_str))
case ("LWF16")
call cvmix_put_kpp('Langmuir_Entrainment_Opt', &
LANGMUIR_ENTRAINMENT_LWF16, CVmix_kpp_params_user)
case ("LF17")
call cvmix_put_kpp('Langmuir_Entrainment_Opt', &
LANGMUIR_ENTRAINMENT_LF17, CVmix_kpp_params_user)
case ("RWHGK16")
call cvmix_put_kpp('Langmuir_Entrainment_Opt', &
LANGMUIR_ENTRAINMENT_RWHGK16, CVmix_kpp_params_user)
case ("NONE")
call cvmix_put_kpp('Langmuir_Entrainment_Opt', &
NO_LANGMUIR_ENTRAINMENT, CVmix_kpp_params_user)
case DEFAULT
print*, "ERROR: ", trim(Langmuir_entrainment_str), " is not a ", &
"valid option for Langmuir_entrainment_str!"
stop 1
end select
else
call cvmix_put_kpp('Langmuir_Entrainment_Opt', &
NO_LANGMUIR_ENTRAINMENT, CVmix_kpp_params_user)
end if
! By default, assume that G(0) = 0 for nonlocal term
nonlocal_coeff = (Cstar_loc*vonkar_loc* &
(vonkar_loc*surf_layer_ext_loc*c_s)** &
(cvmix_one/real(3,cvmix_r8)))
if (present(lnonzero_surf_nonlocal)) then
if (lnonzero_surf_nonlocal) then
nonlocal_coeff = real(1,cvmix_r8)
end if
end if
call cvmix_put_kpp('nonlocal_coeff',nonlocal_coeff,CVmix_kpp_params_user)
! By default, use sigma construction from Danabasoglu et al. when computing
! turbulent scales. Set l_LMD_ws = .true. to use Large et al. construction.
if (present(l_LMD_ws)) then
call cvmix_put_kpp('l_LMD_ws', l_LMD_ws, &
CVmix_kpp_params_user)
else
call cvmix_put_kpp('l_LMD_ws', .false., CVmix_kpp_params_user)
end if
! Initialize parameters for enhanced entrainment
if (present(ER_Cb)) then
ER_Cb_loc = ER_Cb
else
ER_Cb_loc = 0.96_cvmix_r8
end if
call cvmix_put_kpp('ER_Cb', ER_Cb_loc, CVmix_kpp_params_user)
if (present(ER_Cs)) then
ER_Cs_loc = ER_Cs
else
ER_Cs_loc = 0.038_cvmix_r8
end if
call cvmix_put_kpp('ER_Cs', ER_Cs_loc, CVmix_kpp_params_user)
if (present(ER_Cu)) then
ER_Cu_loc = ER_Cu
else
ER_Cu_loc = 0.023_cvmix_r8
end if
call cvmix_put_kpp('ER_Cu', ER_Cu_loc, CVmix_kpp_params_user)
call cvmix_put_kpp('c_ST', 0.17_cvmix_r8, CVmix_kpp_params_user)
call cvmix_put_kpp('c_CT', 0.15_cvmix_r8, CVmix_kpp_params_user)
call cvmix_put_kpp('c_LT', 0.083_cvmix_r8, CVmix_kpp_params_user)
call cvmix_put_kpp('p_LT', 2.0_cvmix_r8, CVmix_kpp_params_user)
call cvmix_put_kpp('RWHGK_ENTR_COEF', 2.3_cvmix_r8, CVmix_kpp_params_user)
call cvmix_put_kpp('RWHGK_ENTR_EXP', -0.5_cvmix_r8, CVmix_kpp_params_user)
!EOC
end subroutine cvmix_init_kpp
!BOP
! !IROUTINE: cvmix_coeffs_kpp_wrap
! !INTERFACE:
subroutine cvmix_coeffs_kpp_wrap(CVmix_vars, CVmix_kpp_params_user)
! !DESCRIPTION:
! Computes vertical diffusion coefficients for the KPP boundary layer mixing
! parameterization.
!\\
!\\
! !INPUT PARAMETERS:
type(cvmix_kpp_params_type), intent(in), optional, target :: &
CVmix_kpp_params_user
! !INPUT/OUTPUT PARAMETERS:
type(cvmix_data_type), intent(inout) :: CVmix_vars
!EOP
!BOC
real(cvmix_r8), dimension(CVmix_vars%max_nlev+1) :: new_Mdiff, new_Tdiff, &
new_Sdiff
integer :: nlev, max_nlev
type(cvmix_kpp_params_type), pointer :: CVmix_kpp_params_in
CVmix_kpp_params_in => CVmix_kpp_params_saved
if (present(CVmix_kpp_params_user)) then
CVmix_kpp_params_in => CVmix_kpp_params_user
end if
nlev = CVmix_vars%nlev
max_nlev = CVmix_vars%max_nlev
if (.not.associated(CVmix_vars%Mdiff_iface)) &
call cvmix_put(CVmix_vars, "Mdiff", cvmix_zero, max_nlev)
if (.not.associated(CVmix_vars%Tdiff_iface)) &
call cvmix_put(CVmix_vars, "Tdiff", cvmix_zero, max_nlev)
if (.not.associated(CVmix_vars%Sdiff_iface)) &
call cvmix_put(CVmix_vars, "Sdiff", cvmix_zero, max_nlev)
call cvmix_put(CVmix_vars, 'kpp_transport', cvmix_zero, max_nlev)
call cvmix_coeffs_kpp(new_Mdiff, new_Tdiff, new_Sdiff, &
CVmix_vars%zw_iface, CVmix_vars%zt_cntr, &
CVmix_vars%Mdiff_iface, CVmix_vars%Tdiff_iface, &
CVMix_vars%Sdiff_iface, &
CVmix_vars%BoundaryLayerDepth, &
CVmix_vars%kOBL_depth, &
CVmix_vars%kpp_Tnonlocal_iface, &
CVmix_vars%kpp_Snonlocal_iface, &
CVmix_vars%SurfaceFriction, &
CVmix_vars%SurfaceBuoyancyForcing, &
nlev, max_nlev, &
CVmix_vars%LangmuirEnhancementFactor, &
CVmix_vars%StokesMostXi, &
CVmix_vars%Coriolis, &
CVmix_kpp_params_user)
call cvmix_update_wrap(CVmix_kpp_params_in%handle_old_vals, max_nlev, &
Mdiff_out = CVmix_vars%Mdiff_iface, &
new_Mdiff = new_Mdiff, &
Tdiff_out = CVmix_vars%Tdiff_iface, &
new_Tdiff = new_Tdiff, &
Sdiff_out = CVmix_vars%Sdiff_iface, &
new_Sdiff = new_Sdiff)
!EOC
end subroutine cvmix_coeffs_kpp_wrap
!BOP
! !IROUTINE: cvmix_coeffs_kpp_low
! !INTERFACE:
subroutine cvmix_coeffs_kpp_low(Mdiff_out, Tdiff_out, Sdiff_out, zw, zt, &
old_Mdiff, old_Tdiff, old_Sdiff, OBL_depth, &
kOBL_depth, Tnonlocal, Snonlocal, surf_fric,&
surf_buoy, nlev, max_nlev, Langmuir_EFactor,&
StokesXI,Coriolis,CVmix_kpp_params_user)
! !DESCRIPTION:
! Computes vertical diffusion coefficients for the KPP boundary layer mixing
! parameterization.
!\\
!\\
! !INPUT PARAMETERS:
type(cvmix_kpp_params_type), intent(in), optional, target :: &
CVmix_kpp_params_user
integer, intent(in) :: nlev, max_nlev
real(cvmix_r8), dimension(max_nlev+1), intent(in) :: old_Mdiff, &
old_Tdiff, &
old_Sdiff, &
zw
real(cvmix_r8), dimension(max_nlev), intent(in) :: zt
real(cvmix_r8), intent(in) :: OBL_depth, &
surf_fric, &
surf_buoy, &
kOBL_depth
! Langmuir enhancement factor
real(cvmix_r8), intent(in), optional :: Langmuir_EFactor
real(cvmix_r8), intent(in), optional :: StokesXI
real(cvmix_r8), intent(in), optional :: Coriolis ! required for ML_diffusivity
! !INPUT/OUTPUT PARAMETERS:
real(cvmix_r8), dimension(max_nlev+1), intent(inout) :: Mdiff_out, &
Tdiff_out, &
Sdiff_out, &
Tnonlocal, &
Snonlocal
!EOP
!BOC
! Local variables
type(cvmix_kpp_params_type), pointer :: CVmix_kpp_params_in
! OBL_[MTS]diff are the diffusivities in the whole OBL
real(cvmix_r8), dimension(nint(kOBL_depth)) :: OBL_Mdiff, OBL_Tdiff, &
OBL_Sdiff
! [MTS]diff_ktup are the enhanced diffusivity and viscosity values at the
! deepest cell center above OBL_depth. Other _ktup vars are intermediary
! variables needed to compute [MTS]diff_ktup
real(cvmix_r8) :: Mdiff_ktup, Tdiff_ktup, Sdiff_ktup
real(cvmix_r8) :: sigma_ktup, wm_ktup, ws_ktup
real(cvmix_r8) :: delta
real(cvmix_r8), dimension(nlev+1) :: sigma, w_m, w_s
! [MTS]shape are the coefficients of the shape function in the gradient
! term; [TS]shape2 are the coefficients for the nonlocal term;
! NMshape is the coefficient for the no-matching case, an option to shape
! a Langmuir enhancement
real(cvmix_r8), dimension(4) :: Mshape, Tshape, Sshape, Tshape2, Sshape2,&
NMshape
! [MTS]shapeAt1 is value of shape function at sigma = 1
! d[MTS]shapeAt1 is value of derivative of shape function at sigma = 1
! (Used for matching the shape function at OBL depth)
real(cvmix_r8) :: MshapeAt1, TshapeAt1, SshapeAt1
real(cvmix_r8) :: dMshapeAt1, dTshapeAt1, dSshapeAt1
! [MTS]shapeAtS is value of shape function at sigma = S
real(cvmix_r8) :: MshapeAtS, TshapeAtS, SshapeAtS, GAtS
! Storing the maximum value of shape function for no-matching case
! that is used as an option for Langmuir mixing
real(cvmix_r8), parameter :: NMshapeMax = 4./27.
! [MTS]diff_OBL is value of diffusivity at OBL depth
! d[MTS]diff_OBL is value of derivative of diffusivity at OBL depth
! w[ms]_OBL is value of wm or ws at OBL depth
real(cvmix_r8) :: Mdiff_OBL, Tdiff_OBL, Sdiff_OBL
real(cvmix_r8) :: dMdiff_OBL, dTdiff_OBL, dSdiff_OBL
real(cvmix_r8) :: wm_OBL, ws_OBL, second_term
! coefficients used for interpolation if interp_type2 is not 'LMD94'
real(kind=cvmix_r8), dimension(4) :: coeffs
! Width of column kw_up and kw_up+1
real(cvmix_r8), dimension(2) :: col_widths, col_centers
real(cvmix_r8), dimension(2) :: Mdiff_vals, Tdiff_vals, Sdiff_vals
! Parameters for RWHGK16 Langmuir parameterization
real(cvmix_r8) :: MixingCoefEnhancement
real(cvmix_r8) :: ShapeNoMatchAtS
! Parameters for Stokes_MOST
real(cvmix_r8) :: Gcomposite, Hsigma, sigh, T_NLenhance , S_NLenhance , XIone
! Parameters for the machine learning part, ML_diffusivity
real(cvmix_r8) :: sigma_max ! sigma coordinate of location of maximum diffusivity
real(cvmix_r8) :: g_sigma ! shape function at a sigma coordinate.
real(cvmix_r8) :: L_h ! Non-dimensional L_h = B*OBL_depth/u_*^3
real(cvmix_r8) :: E_h ! Non-dimensional E_h = OBL_depth * Coriolis /u_*
real(cvmix_r8) :: F_inter_func ! Stands for F_intermediate_function,
! Non-dimensional intermediate function used to calculate sigma_max
! Constant from params
integer :: interp_type2, MatchTechnique
integer :: kw
logical :: lstable
integer :: ktup, & ! kt index of cell center above OBL_depth
kwup ! kw index of iface above OBL_depth (= kt index of
! cell containing OBL_depth)
CVmix_kpp_params_in => CVmix_kpp_params_saved
if (present(CVmix_kpp_params_user)) then
CVmix_kpp_params_in => CVmix_kpp_params_user
end if
interp_type2 = CVmix_kpp_params_in%interp_type2
MatchTechnique = CVmix_kpp_params_in%MatchTechnique
! Output values should be set to input values
Mdiff_out = old_Mdiff
Tdiff_out = old_Tdiff
Sdiff_out = old_Sdiff
! (1) Column-specific parameters
!
! Stability => positive surface buoyancy flux
lstable = (surf_buoy.gt.cvmix_zero)
kwup = floor(kOBL_depth)
ktup = nint(kOBL_depth)-1
if (ktup.eq.nlev) then
! OBL_depth between bottom cell center and ocean bottom, assume
! zt(ktup+1) = ocn_bottom (which is zw(nlev+1)
delta = (OBL_depth+zt(ktup))/(zt(ktup)-zw(ktup+1))
else
delta = (OBL_depth+zt(ktup))/(zt(ktup)-zt(ktup+1))
end if
if ( CVmix_kpp_params_in%lStokesMOST ) then ! Stokes_MOST
! (2a) Compute turbulent scales at OBL depth
call cvmix_kpp_compute_turbulent_scales(cvmix_one, OBL_depth, &
surf_buoy, surf_fric, &
StokesXI, wm_OBL, ws_OBL, &
CVmix_kpp_params_user)
! (2b) Compute diffusivities at OBL depth
col_centers(1) = zt(kwup)
col_widths(1) = zw(kwup) - zw(kwup+1)
Mdiff_vals(1) = old_Mdiff(kwup+1)
Tdiff_vals(1) = old_Tdiff(kwup+1)
Sdiff_vals(1) = old_Sdiff(kwup+1)
if (kwup.eq.nlev) then
col_centers(2) = zw(kwup+1)
col_widths(2) = 1.0_cvmix_r8 !Value doesn't matter, will divide into zero
Mdiff_vals(2) = old_Mdiff(kwup+1) !Mdiff_out(kwup+1)
Tdiff_vals(2) = old_Tdiff(kwup+1)
Sdiff_vals(2) = old_Sdiff(kwup+1)
else
col_centers(2) = zt(kwup+1)
col_widths(2) = zw(kwup+1) - zw(kwup+2)
Mdiff_vals(2) = old_Mdiff(kwup+2)
Tdiff_vals(2) = old_Tdiff(kwup+2)
Sdiff_vals(2) = old_Sdiff(kwup+2)
end if
if (kwup.eq.1) then
Mdiff_OBL = cvmix_kpp_compute_nu_at_OBL_depth_LMD94(col_centers, &
col_widths, &
Mdiff_vals, OBL_depth, &
dnu_dz=dMdiff_OBL)
Tdiff_OBL = cvmix_kpp_compute_nu_at_OBL_depth_LMD94(col_centers, &
col_widths, &
Tdiff_vals, OBL_depth, &
dnu_dz=dTdiff_OBL)
Sdiff_OBL = cvmix_kpp_compute_nu_at_OBL_depth_LMD94(col_centers, &
col_widths, &
Sdiff_vals, OBL_depth, &
dnu_dz=dSdiff_OBL)
else ! interp_type == 'LMD94' and kwup > 1
Mdiff_OBL = cvmix_kpp_compute_nu_at_OBL_depth_LMD94(col_centers, &
col_widths, &
Mdiff_vals, OBL_depth, &
old_Mdiff(kwup), &
dnu_dz=dMdiff_OBL)
Tdiff_OBL = cvmix_kpp_compute_nu_at_OBL_depth_LMD94(col_centers, &
col_widths, &
Tdiff_vals, OBL_depth, &
old_Tdiff(kwup), &
dnu_dz=dTdiff_OBL)
Sdiff_OBL = cvmix_kpp_compute_nu_at_OBL_depth_LMD94(col_centers, &
col_widths, &
Sdiff_vals, OBL_depth, &
old_Sdiff(kwup), &
dnu_dz=dSdiff_OBL)
end if
! (3a) Compute turbulent scales at interfaces throughout column
Tnonlocal = cvmix_zero
Snonlocal = cvmix_zero
OBL_Mdiff = cvmix_zero
OBL_Tdiff = cvmix_zero
OBL_Sdiff = cvmix_zero
sigma = -zw(1:nlev+1)/OBL_depth
call cvmix_kpp_compute_turbulent_scales(sigma, OBL_depth, surf_buoy, & !_1d
surf_fric, xi=StokesXI, w_m=w_m, w_s=w_s, &
CVmix_kpp_params_user = CVmix_kpp_params_user)
do kw=2,kwup ! OBL overwrite loop to kwup
! (3b) Evaluate G(sigma) >= 0 at each cell interface
Gcomposite = cvmix_kpp_composite_shape(sigma(kw))
sigh = MAX(CVmix_kpp_params_in%surf_layer_ext, MIN(sigma(kw) ,cvmix_one))
Hsigma = ((sigh - CVmix_kpp_params_in%surf_layer_ext) / &
(cvmix_one - CVmix_kpp_params_in%surf_layer_ext) )**2
! Hsigma = MAX( cvmix_zero , MIN( cvmix_one , Hsigma ) )
! (3c) Compute nonlocal term at each cell interface
if (.not.lstable) then
Tnonlocal(kw) = 4.7 * Gcomposite ! LMD 6.26 Gcubic
Snonlocal(kw) = 4.7 * Gcomposite
else
Tnonlocal(kw) = cvmix_zero
Snonlocal(kw) = cvmix_zero
end if
! (3d) Diffusivity = (OBL_depth * turbulent scale * G(sigma) + Xdiff_OBL * Hsigma)
OBL_Mdiff(kw) = OBL_depth * w_m(kw) * Gcomposite + Mdiff_OBL * Hsigma
OBL_Tdiff(kw) = OBL_depth * w_s(kw) * Gcomposite + Tdiff_OBL * Hsigma
OBL_Sdiff(kw) = OBL_depth * w_s(kw) * Gcomposite + Sdiff_OBL * Hsigma
end do
! (4) Compute the enhanced diffusivity
! (4a) Compute shape function at last cell center in OBL
sigma_ktup = -zt(ktup)/OBL_depth
Gcomposite = cvmix_kpp_composite_shape(sigma_ktup)
sigh = MAX(CVmix_kpp_params_in%surf_layer_ext, MIN(sigma_ktup ,cvmix_one))
Hsigma = ( (sigh - CVmix_kpp_params_in%surf_layer_ext) / &
(cvmix_one - CVmix_kpp_params_in%surf_layer_ext) )**2
! (4b) Compute turbulent scales at last cell center in OBL
call cvmix_kpp_compute_turbulent_scales(sigma_ktup, OBL_depth, surf_buoy, & !0d
surf_fric, StokesXI, wm_ktup, ws_ktup, &
CVmix_kpp_params_user)
! (4c) Diffusivity at last cell center in OBL
Mdiff_ktup = OBL_depth * wm_ktup * Gcomposite + Mdiff_OBL * Hsigma
Tdiff_ktup = OBL_depth * ws_ktup * Gcomposite + Tdiff_OBL * Hsigma
Sdiff_ktup = OBL_depth * ws_ktup * Gcomposite + Sdiff_OBL * Hsigma
if (CVmix_kpp_params_in%lenhanced_diff) then
if ((ktup.eq.kwup).or.(ktup.eq.kwup-1)) then
T_NLenhance = Tnonlocal(ktup+1)
S_NLenhance = Snonlocal(ktup+1)
call cvmix_kpp_compute_enhanced_diff(Mdiff_ktup, &
Tdiff_ktup, &
Sdiff_ktup, &
Mdiff_out(ktup+1), &
Tdiff_out(ktup+1), &
Sdiff_out(ktup+1), &
OBL_Mdiff(ktup+1), &
OBL_Tdiff(ktup+1), &
OBL_Sdiff(ktup+1), &
T_NLenhance , &
S_NLenhance , &
delta, lkteqkw=(ktup.eq.kwup))
else
print*, "ERROR: ktup should be either kwup or kwup-1!"
print*, "ktup = ", ktup, " and kwup = ", kwup
stop 1
end if
else
if ( kwup .eq. ktup ) then
OBL_Mdiff(ktup+1) = old_Mdiff(ktup+1)
OBL_Tdiff(ktup+1) = old_Tdiff(ktup+1)
OBL_Sdiff(ktup+1) = old_Sdiff(ktup+1)
end if
end if