@@ -679,7 +679,7 @@ end subroutine set_pen_shortwave
679
679
! > Diagnose a mixed layer depth (MLD) determined by a given density difference with the surface.
680
680
! > This routine is appropriate in MOM_diabatic_aux due to its position within the time stepping.
681
681
subroutine diagnoseMLDbyDensityDifference (id_MLD , h , tv , densityDiff , G , GV , US , diagPtr , &
682
- id_N2subML , id_MLDsq , dz_subML )
682
+ id_N2subML , id_MLDsq , dz_subML , ref_p_mld , id_ref_z )
683
683
type (ocean_grid_type), intent (in ) :: G ! < Grid type
684
684
type (verticalGrid_type), intent (in ) :: GV ! < ocean vertical grid structure
685
685
type (unit_scale_type), intent (in ) :: US ! < A dimensional unit scaling type
@@ -694,10 +694,14 @@ subroutine diagnoseMLDbyDensityDifference(id_MLD, h, tv, densityDiff, G, GV, US,
694
694
integer , optional , intent (in ) :: id_MLDsq ! < Optional handle (ID) of squared MLD
695
695
real , optional , intent (in ) :: dz_subML ! < The distance over which to calculate N2subML
696
696
! ! or 50 m if missing [Z ~> m]
697
+ real , optional , intent (in ) :: ref_p_mld ! < Optional reference pressure used to calculate the
698
+ ! ! densisty, defults to 0.0 is not present [R L2 T-2 ~> Pa].
699
+ integer , optional , intent (in ) :: id_ref_z ! < Handle (ID) of reference depth diagnostic
697
700
698
701
! Local variables
699
702
real , dimension (SZI_(G)) :: deltaRhoAtKm1, deltaRhoAtK ! Density differences [R ~> kg m-3].
700
703
real , dimension (SZI_(G)) :: pRef_MLD, pRef_N2 ! Reference pressures [R L2 T-2 ~> Pa].
704
+ real , dimension (SZI_(G)) :: hRef_MLD ! Depth of reference pressures [ ~> ].
701
705
real , dimension (SZI_(G)) :: H_subML, dH_N2 ! Summed thicknesses used in N2 calculation [H ~> m or kg m-2]
702
706
real , dimension (SZI_(G)) :: dZ_N2 ! Summed vertical distance used in N2 calculation [Z ~> m]
703
707
real , dimension (SZI_(G)) :: T_subML, T_deeper ! Temperatures used in the N2 calculation [C ~> degC].
@@ -706,6 +710,8 @@ subroutine diagnoseMLDbyDensityDifference(id_MLD, h, tv, densityDiff, G, GV, US,
706
710
real , dimension (SZI_(G),SZK_(GV)) :: dZ_2d ! Layer thicknesses in depth units [Z ~> m]
707
711
real , dimension (SZI_(G)) :: dZ, dZm1 ! Layer thicknesses associated with interfaces [Z ~> m]
708
712
real , dimension (SZI_(G)) :: rhoSurf ! Density used in finding the mixed layer depth [R ~> kg m-3].
713
+ real :: rhoSurf_ref ! Density used in finding the mixed layer depth [R ~> kg m-3].
714
+ real , dimension (SZI_(G), SZJ_(G)) :: z_ref_diag ! the actual depth of the k interface [Z ~> m].
709
715
real , dimension (SZI_(G), SZJ_(G)) :: MLD ! Diagnosed mixed layer depth [Z ~> m].
710
716
real , dimension (SZI_(G), SZJ_(G)) :: subMLN2 ! Diagnosed stratification below ML [T-2 ~> s-2].
711
717
real , dimension (SZI_(G), SZJ_(G)) :: MLD2 ! Diagnosed MLD^2 [Z2 ~> m2].
@@ -716,6 +722,8 @@ subroutine diagnoseMLDbyDensityDifference(id_MLD, h, tv, densityDiff, G, GV, US,
716
722
real :: dZ_sub_ML ! Depth below ML over which to diagnose stratification [Z ~> m]
717
723
real :: aFac ! A nondimensional factor [nondim]
718
724
real :: ddRho ! A density difference [R ~> kg m-3]
725
+ real , dimension (SZI_(G)) :: ks
726
+ real :: errZ, errZm1
719
727
integer , dimension (2 ) :: EOSdom ! The i-computational domain for the equation of state
720
728
integer :: i, j, is, ie, js, je, k, nz, id_N2, id_SQ
721
729
@@ -737,24 +745,100 @@ subroutine diagnoseMLDbyDensityDifference(id_MLD, h, tv, densityDiff, G, GV, US,
737
745
738
746
is = G% isc ; ie = G% iec ; js = G% jsc ; je = G% jec ; nz = GV% ke
739
747
740
- pRef_MLD(:) = 0.0
748
+ pRef_MLD(:) = 0.0 ; hRef_MLD(:) = 0.0
749
+ if (present (ref_p_mld)) pRef_MLD(is:ie) = ref_p_mld
750
+ if (present (ref_p_mld)) hRef_MLD(is:ie) = ref_p_mld ! horrible pressure to depth calc
751
+ z_ref_diag(:,:) = 0 .
752
+
741
753
EOSdom(:) = EOS_domain(G% HI)
742
754
do j= js,je
743
755
! Find the vertical distances across layers.
744
756
call thickness_to_dz(h, tv, dZ_2d, j, G, GV)
745
757
746
- do i= is,ie ; dZ(i) = 0.5 * dZ_2d(i,1 ) ; enddo ! Depth of center of surface layer
747
- call calculate_density(tv% T(:,j,1 ), tv% S(:,j,1 ), pRef_MLD, rhoSurf, tv% eqn_of_state, EOSdom)
748
- do i= is,ie
749
- deltaRhoAtK(i) = 0 .
750
- MLD(i,j) = 0 .
751
- if (id_N2> 0 ) then
752
- subMLN2(i,j) = 0.0
753
- H_subML(i) = h(i,j,1 ) ; dH_N2(i) = 0.0 ; dZ_N2(i) = 0.0
754
- T_subML(i) = 0.0 ; S_subML(i) = 0.0 ; T_deeper(i) = 0.0 ; S_deeper(i) = 0.0
755
- N2_region_set(i) = (G% mask2dT(i,j)<0.5 ) ! Only need to work on ocean points.
756
- endif
757
- enddo
758
+ if (pRef_MLD(is) .ne. 0.0 ) then
759
+ ks(is:ie) = 0
760
+ do i= is,ie
761
+ dZ(i) = 0.5 * dZ_2d(i,1 ) ! Depth of center of surface layer
762
+ if (dZ(i) >= hRef_MLD(i)) ks(i) = k
763
+ enddo
764
+ do k= 2 ,nz
765
+ do i= is,ie
766
+ if (ks(i)==0 .and. k< nz) then ! still havent found 10 m depth
767
+ if (dZ(i) >= hRef_MLD(i)) then ! check whether the previous layer was closer
768
+ errZ = dZ(i) - hRef_MLD(i)
769
+ errZm1 = hRef_MLD(i) - dZm1(i)
770
+ if (errZ <= errZm1) then ; ks(i) = k; z_ref_diag(i,j)= dZ(i); ! set the k reference
771
+ elseif (errZm1 < errZ) then ; ks(i) = k-1 ; z_ref_diag(i,j)= dZm1(i); endif
772
+ elseif (dZ(i) < hRef_MLD(i)) then ! go to the next layer
773
+ dZm1(i) = dZ(i) ! Depth of center of layer K-1
774
+ dZ(i) = dZ(i) + 0.5 * ( dZ_2d(i,k) + dZ_2d(i,k-1 ) ) ! Depth of center of layer K
775
+ endif
776
+ elseif (ks(i)==0 .and. k== nz) then
777
+ ks(i)= 1
778
+ endif
779
+ enddo
780
+ enddo
781
+ do i= is,ie
782
+ call calculate_density(tv% T(i,j,ks(i)), tv% S(i,j,ks(i)), pRef_MLD(i), rhoSurf_ref, tv% eqn_of_state)
783
+ rhoSurf(i) = rhoSurf_ref
784
+ deltaRhoAtK(i) = 0 .
785
+ MLD(i,j) = 0 .
786
+ if (id_N2> 0 ) then
787
+ subMLN2(i,j) = 0.0
788
+ H_subML(i) = h(i,j,1 ) ; dH_N2(i) = 0.0 ; dZ_N2(i) = 0.0 ! may need to cahnge the 1 on this line?
789
+ T_subML(i) = 0.0 ; S_subML(i) = 0.0 ; T_deeper(i) = 0.0 ; S_deeper(i) = 0.0
790
+ N2_region_set(i) = (G% mask2dT(i,j)<0.5 ) ! Only need to work on ocean points.
791
+ endif
792
+ enddo
793
+ ! !!!!!!!!!!!
794
+ ! do i=is,ie
795
+ ! ks(i) = 0
796
+ ! dZm1(i) = 0.0
797
+ ! dZ(i) = 0.5 * dZ_2d(i,1) ! Depth of center of surface layer
798
+ ! if (dZ(i) >= hRef_MLD(i)) then; ks(i) = k;
799
+ ! else
800
+ ! do k=2,nz
801
+ ! if (ks(i)==0) then ! still havent found 10 m depth
802
+ ! if (dZ(i) >= hRef_MLD(i)) then ! find the
803
+ ! errZ = dZ(i) - hRef_MLD(i)
804
+ ! errZm1 = hRef_MLD(i) - dZm1(i)
805
+ ! if (errZ <= errZm1) then; ks(i) = k;
806
+ ! elseif (errZm1 < errZ) then; ks(i) = k-1; endif
807
+ ! elseif (dZ(i) < hRef_MLD(i)) then ! go to the next layer
808
+ ! dZm1(i) = dZ(i) ! Depth of center of layer K-1
809
+ ! dZ(i) = dZ(i) + 0.5 * ( dZ_2d(i,k) + dZ_2d(i,k-1) ) ! Depth of center of layer K
810
+ ! endif
811
+ ! endif
812
+ ! enddo
813
+ ! if (k>=nz .and. ks(i)==0.0) ks(i)=1
814
+ ! endif
815
+ ! !rhoSurf(i,j) = call calculate density
816
+ ! call calculate_density(tv%T(i,j,ks(i)), tv%S(i,j,ks(i)), pRef_MLD(i), rhoSurf_ref, tv%eqn_of_state)
817
+ ! rhoSurf(i) = rhoSurf_ref
818
+ ! deltaRhoAtK(i) = 0.
819
+ ! MLD(i,j) = 0.
820
+ ! if (id_N2>0) then
821
+ ! subMLN2(i,j) = 0.0
822
+ ! H_subML(i) = h(i,j,1) ; dH_N2(i) = 0.0 ; dZ_N2(i) = 0.0 ! may need to cahnge the 1 on this line?
823
+ ! T_subML(i) = 0.0 ; S_subML(i) = 0.0 ; T_deeper(i) = 0.0 ; S_deeper(i) = 0.0
824
+ ! N2_region_set(i) = (G%mask2dT(i,j)<0.5) ! Only need to work on ocean points.
825
+ ! endif
826
+ ! enddo
827
+ elseif (pRef_MLD(is) == 0.0 ) then
828
+ do i= is,ie ; dZ(i) = 0.5 * dZ_2d(i,1 ) ; enddo ! Depth of center of surface layer
829
+ call calculate_density(tv% T(:,j,1 ), tv% S(:,j,1 ), pRef_MLD, rhoSurf, tv% eqn_of_state, EOSdom)
830
+ do i= is,ie
831
+ deltaRhoAtK(i) = 0 .
832
+ MLD(i,j) = 0 .
833
+ if (id_N2> 0 ) then
834
+ subMLN2(i,j) = 0.0
835
+ H_subML(i) = h(i,j,1 ) ; dH_N2(i) = 0.0 ; dZ_N2(i) = 0.0
836
+ T_subML(i) = 0.0 ; S_subML(i) = 0.0 ; T_deeper(i) = 0.0 ; S_deeper(i) = 0.0
837
+ N2_region_set(i) = (G% mask2dT(i,j)<0.5 ) ! Only need to work on ocean points.
838
+ endif
839
+ enddo
840
+ endif
841
+
758
842
do k= 2 ,nz
759
843
do i= is,ie
760
844
dZm1(i) = dZ(i) ! Depth of center of layer K-1
@@ -800,6 +884,7 @@ subroutine diagnoseMLDbyDensityDifference(id_MLD, h, tv, densityDiff, G, GV, US,
800
884
if (id_SQ > 0 ) MLD2(i,j) = MLD(i,j)** 2
801
885
enddo ! i-loop
802
886
enddo ! k-loop
887
+ ! if reference layer is the surface
803
888
do i= is,ie
804
889
if ((MLD(i,j) == 0 .) .and. (deltaRhoAtK(i) < densityDiff)) MLD(i,j) = dZ(i) ! Mixing goes to the bottom
805
890
enddo
@@ -823,6 +908,8 @@ subroutine diagnoseMLDbyDensityDifference(id_MLD, h, tv, densityDiff, G, GV, US,
823
908
if (id_N2 > 0 ) call post_data(id_N2, subMLN2, diagPtr)
824
909
if (id_SQ > 0 ) call post_data(id_SQ, MLD2, diagPtr)
825
910
911
+ if ((id_ref_z > 0 ) .and. (pRef_MLD(is).ne. 0 .)) call post_data(id_ref_z, z_ref_diag , diagPtr)
912
+
826
913
end subroutine diagnoseMLDbyDensityDifference
827
914
828
915
! > Diagnose a mixed layer depth (MLD) determined by the depth a given energy value would mix.
0 commit comments