This subroutine does epipycnal diffusion of all tracers between the mixed and buffer layers and the interior, using the diffusivity in CSKhTr. Multiple iterations are used (if necessary) so that there is no limit on the acceptable time increment.
579 type(ocean_grid_type),
intent(inout) :: G
580 type(verticalGrid_type),
intent(in) :: GV
581 real,
dimension(SZI_(G),SZJ_(G),SZK_(G)),
intent(in) :: h
582 real,
intent(in) :: dt
583 type(tracer_type),
intent(inout) :: Tr(:)
584 integer,
intent(in) :: ntr
585 real,
dimension(SZIB_(G),SZJ_(G)),
intent(in) :: khdt_epi_x
588 real,
dimension(SZI_(G),SZJB_(G)),
intent(in) :: khdt_epi_y
591 type(unit_scale_type),
intent(in) :: US
592 type(tracer_hor_diff_CS),
intent(inout) :: CS
593 type(thermo_var_ptrs),
intent(in) :: tv
594 integer,
intent(in) :: num_itts
597 real,
dimension(SZI_(G), SZJ_(G)) :: &
599 real,
dimension(SZI_(G), SZJ_(G), max(1,GV%nk_rho_varies)) :: &
604 type(p2d),
dimension(SZJ_(G)) :: &
605 deep_wt_Lu, deep_wt_Ru, &
608 type(p2d),
dimension(SZJB_(G)) :: &
609 deep_wt_Lv, deep_wt_Rv, &
612 type(p2di),
dimension(SZJ_(G)) :: &
615 type(p2di),
dimension(SZJB_(G)) :: &
619 real,
dimension(SZI_(G), SZJ_(G), SZK_(G)) :: &
621 real,
dimension(SZI_(G), SZJ_(G), SZK_(G)) :: Tr_flux_3d, Tr_adj_vert_L, Tr_adj_vert_R
623 real,
dimension(SZI_(G), SZK_(G), SZJ_(G)) :: &
626 integer,
dimension(SZI_(G), SZK_(G), SZJ_(G)) :: &
630 real,
dimension(SZK_(G)) :: &
637 integer,
dimension(SZK_(G)) :: &
641 integer,
dimension(SZI_(G), SZJ_(G)) :: &
647 integer,
dimension(SZJ_(G)) :: &
649 integer,
dimension(SZIB_(G), SZJ_(G)) :: &
651 integer,
dimension(SZI_(G), SZJB_(G)) :: &
657 real :: rho_pair, rho_a, rho_b
670 logical,
dimension(SZK_(G)) :: &
674 real :: p_ref_cv(SZI_(G))
676 integer :: k_max, k_min, k_test, itmp
677 integer :: i, j, k, k2, m, is, ie, js, je, nz, nkmb
678 integer :: isd, ied, jsd, jed, IsdB, IedB, k_size
679 integer :: kL, kR, kLa, kLb, kRa, kRb, nP, itt, ns, max_itt
680 integer :: PEmax_kRho
681 integer :: isv, iev, jsv, jev
683 is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = gv%ke
684 isd = g%isd ; ied = g%ied ; jsd = g%jsd ; jed = g%jed
685 isdb = g%IsdB ; iedb = g%IedB
687 nkmb = gv%nk_rho_varies
689 if (num_itts <= 1)
then
690 max_itt = 1 ; i_maxitt = 1.0
692 max_itt = num_itts ; i_maxitt = 1.0 / (real(max_itt))
695 do i=is-2,ie+2 ; p_ref_cv(i) = tv%P_Ref ;
enddo
697 call do_group_pass(cs%pass_t, g%Domain, clock=id_clock_pass)
700 do k=1,nkmb ;
do j=js-2,je+2
701 call calculate_density(tv%T(:,j,k),tv%S(:,j,k), p_ref_cv, &
702 rho_coord(:,j,k), is-2, ie-is+5, tv%eqn_of_state, scale=us%kg_m3_to_R)
705 do j=js-2,je+2 ;
do i=is-2,ie+2
706 rml_max(i,j) = rho_coord(i,j,1)
707 num_srt(i,j) = 0 ; max_krho(i,j) = 0
709 do k=2,nkmb ;
do j=js-2,je+2 ;
do i=is-2,ie+2
710 if (rml_max(i,j) < rho_coord(i,j,k)) rml_max(i,j) = rho_coord(i,j,k)
711 enddo ;
enddo ;
enddo
717 do j=js-2,je+2 ;
do i=is-2,ie+2 ;
if (g%mask2dT(i,j) > 0.5)
then
718 if (rml_max(i,j) > gv%Rlay(nz))
then ; max_krho(i,j) = nz+1
719 elseif (rml_max(i,j) <= gv%Rlay(nkmb+1))
then ; max_krho(i,j) = nkmb+1
721 k_min = nkmb+2 ; k_max = nz
723 k_test = (k_min + k_max) / 2
724 if (rml_max(i,j) <= gv%Rlay(k_test-1))
then ; k_max = k_test-1
725 elseif (gv%Rlay(k_test) < rml_max(i,j))
then ; k_min = k_test+1
726 else ; max_krho(i,j) = k_test ;
exit ;
endif
728 if (k_min == k_max)
then ; max_krho(i,j) = k_max ;
exit ;
endif
731 endif ;
enddo ;
enddo
734 do j=js-1,je+1 ;
do i=is-1,ie+1
735 k_end_srt(i,j) = max(max_krho(i,j), max_krho(i-1,j), max_krho(i+1,j), &
736 max_krho(i,j-1), max_krho(i,j+1))
737 if (pemax_krho < k_end_srt(i,j)) pemax_krho = k_end_srt(i,j)
739 if (pemax_krho > nz) pemax_krho = nz
741 h_exclude = 10.0*(gv%Angstrom_H + gv%H_subroundoff)
747 do k=1,nkmb ;
do i=is-1,ie+1 ;
if (g%mask2dT(i,j) > 0.5)
then
748 if (h(i,j,k) > h_exclude)
then
749 num_srt(i,j) = num_srt(i,j) + 1 ; ns = num_srt(i,j)
751 rho_srt(i,ns,j) = rho_coord(i,j,k)
752 h_srt(i,ns,j) = h(i,j,k)
754 endif ;
enddo ;
enddo
755 do k=nkmb+1,pemax_krho ;
do i=is-1,ie+1 ;
if (g%mask2dT(i,j) > 0.5)
then
756 if ((k<=k_end_srt(i,j)) .and. (h(i,j,k) > h_exclude))
then
757 num_srt(i,j) = num_srt(i,j) + 1 ; ns = num_srt(i,j)
759 rho_srt(i,ns,j) = gv%Rlay(k)
760 h_srt(i,ns,j) = h(i,j,k)
762 endif ;
enddo ;
enddo
767 do j=js-1,je+1;
do i=is-1,ie+1
768 do k=2,num_srt(i,j) ;
if (rho_srt(i,k,j) < rho_srt(i,k-1,j))
then
770 do k2 = k,2,-1 ;
if (rho_srt(i,k2,j) >= rho_srt(i,k2-1,j))
exit
771 itmp = k0_srt(i,k2-1,j) ; k0_srt(i,k2-1,j) = k0_srt(i,k2,j) ; k0_srt(i,k2,j) = itmp
772 tmp = rho_srt(i,k2-1,j) ; rho_srt(i,k2-1,j) = rho_srt(i,k2,j) ; rho_srt(i,k2,j) = tmp
773 tmp = h_srt(i,k2-1,j) ; h_srt(i,k2-1,j) = h_srt(i,k2,j) ; h_srt(i,k2,j) = tmp
780 do i=is-1,ie+1 ; max_srt(j) = max(max_srt(j), num_srt(i,j)) ;
enddo
785 k_size = max(2*max_srt(j),1)
786 allocate(deep_wt_lu(j)%p(isdb:iedb,k_size))
787 allocate(deep_wt_ru(j)%p(isdb:iedb,k_size))
788 allocate(hp_lu(j)%p(isdb:iedb,k_size))
789 allocate(hp_ru(j)%p(isdb:iedb,k_size))
790 allocate(k0a_lu(j)%p(isdb:iedb,k_size))
791 allocate(k0a_ru(j)%p(isdb:iedb,k_size))
792 allocate(k0b_lu(j)%p(isdb:iedb,k_size))
793 allocate(k0b_ru(j)%p(isdb:iedb,k_size))
803 do j=js,je ;
do i=is-1,ie ;
if (g%mask2dCu(i,j) > 0.5)
then
806 do k=1,num_srt(i,j) ; h_demand_l(k) = 0.0 ; h_used_l(k) = 0.0 ;
enddo
807 do k=1,num_srt(i+1,j) ; h_demand_r(k) = 0.0 ; h_used_r(k) = 0.0 ;
enddo
814 if (rho_srt(i,1,j) < rho_srt(i+1,1,j))
then
816 do kl=2,num_srt(i,j) ;
if (rho_srt(i,kl,j) >= rho_srt(i+1,1,j))
exit ;
enddo
817 elseif (rho_srt(i+1,1,j) < rho_srt(i,1,j))
then
819 do kr=2,num_srt(i+1,j) ;
if (rho_srt(i+1,kr,j) >= rho_srt(i,1,j))
exit ;
enddo
825 if ((kl > num_srt(i,j)) .or. (kr > num_srt(i+1,j)))
exit
827 if (rho_srt(i,kl,j) > rho_srt(i+1,kr,j))
then
830 rho_pair = rho_srt(i+1,kr,j)
832 k0b_lu(j)%p(i,k) = k0_srt(i,kl,j) ; k0b_ru(j)%p(i,k) = k0_srt(i+1,kr,j)
833 k0a_lu(j)%p(i,k) = k0_srt(i,kl-1,j) ; k0a_ru(j)%p(i,k) = k0b_ru(j)%p(i,k)
834 kbs_lp(k) = kl ; kbs_rp(k) = kr
836 rho_a = rho_srt(i,kl-1,j) ; rho_b = rho_srt(i,kl,j)
837 wt_b = 1.0 ;
if (abs(rho_a - rho_b) > abs(rho_pair - rho_a)) &
838 wt_b = (rho_pair - rho_a) / (rho_b - rho_a)
839 deep_wt_lu(j)%p(i,k) = wt_b ; deep_wt_ru(j)%p(i,k) = 1.0
841 h_demand_l(kl) = h_demand_l(kl) + 0.5*h_srt(i+1,kr,j) * wt_b
842 h_demand_l(kl-1) = h_demand_l(kl-1) + 0.5*h_srt(i+1,kr,j) * (1.0-wt_b)
844 kr = kr+1 ; left_set(k) = .false. ; right_set(k) = .true.
845 elseif (rho_srt(i,kl,j) < rho_srt(i+1,kr,j))
then
848 rho_pair = rho_srt(i,kl,j)
849 k0b_lu(j)%p(i,k) = k0_srt(i,kl,j) ; k0b_ru(j)%p(i,k) = k0_srt(i+1,kr,j)
850 k0a_lu(j)%p(i,k) = k0b_lu(j)%p(i,k) ; k0a_ru(j)%p(i,k) = k0_srt(i+1,kr-1,j)
852 kbs_lp(k) = kl ; kbs_rp(k) = kr
854 rho_a = rho_srt(i+1,kr-1,j) ; rho_b = rho_srt(i+1,kr,j)
855 wt_b = 1.0 ;
if (abs(rho_a - rho_b) > abs(rho_pair - rho_a)) &
856 wt_b = (rho_pair - rho_a) / (rho_b - rho_a)
857 deep_wt_lu(j)%p(i,k) = 1.0 ; deep_wt_ru(j)%p(i,k) = wt_b
859 h_demand_r(kr) = h_demand_r(kr) + 0.5*h_srt(i,kl,j) * wt_b
860 h_demand_r(kr-1) = h_demand_r(kr-1) + 0.5*h_srt(i,kl,j) * (1.0-wt_b)
862 kl = kl+1 ; left_set(k) = .true. ; right_set(k) = .false.
863 elseif ((k0_srt(i,kl,j) <= nkmb) .or. (k0_srt(i+1,kr,j) <= nkmb))
then
866 k0b_lu(j)%p(i,k) = k0_srt(i,kl,j) ; k0b_ru(j)%p(i,k) = k0_srt(i+1,kr,j)
867 k0a_lu(j)%p(i,k) = k0b_lu(j)%p(i,k) ; k0a_ru(j)%p(i,k) = k0b_ru(j)%p(i,k)
868 kbs_lp(k) = kl ; kbs_rp(k) = kr
869 deep_wt_lu(j)%p(i,k) = 1.0 ; deep_wt_ru(j)%p(i,k) = 1.0
871 h_demand_l(kl) = h_demand_l(kl) + 0.5*h_srt(i+1,kr,j)
872 h_demand_r(kr) = h_demand_r(kr) + 0.5*h_srt(i,kl,j)
874 kl = kl+1 ; kr = kr+1 ; left_set(k) = .true. ; right_set(k) = .true.
878 h_demand_l(kl) = h_demand_l(kl) + 0.5*h_srt(i+1,kr,j)
879 h_demand_r(kr) = h_demand_r(kr) + 0.5*h_srt(i,kl,j)
881 kl = kl+1 ; kr = kr+1
887 do k=1,num_srt(i+1,j)
888 h_supply_frac_r(k) = 1.0
889 if (h_demand_r(k) > 0.5*h_srt(i+1,k,j)) &
890 h_supply_frac_r(k) = 0.5*h_srt(i+1,k,j) / h_demand_r(k)
893 h_supply_frac_l(k) = 1.0
894 if (h_demand_l(k) > 0.5*h_srt(i,k,j)) &
895 h_supply_frac_l(k) = 0.5*h_srt(i,k,j) / h_demand_l(k)
900 kl = kbs_lp(k) ; kr = kbs_rp(k)
901 hp_lu(j)%p(i,k) = 0.0 ; hp_ru(j)%p(i,k) = 0.0
902 if (left_set(k))
then
903 if (deep_wt_ru(j)%p(i,k) < 1.0)
then
904 hp_ru(j)%p(i,k) = 0.5*h_srt(i,kl,j) * min(h_supply_frac_r(kr), h_supply_frac_r(kr-1))
905 wt_b = deep_wt_ru(j)%p(i,k)
906 h_used_r(kr-1) = h_used_r(kr-1) + (1.0 - wt_b)*hp_ru(j)%p(i,k)
907 h_used_r(kr) = h_used_r(kr) + wt_b*hp_ru(j)%p(i,k)
909 hp_ru(j)%p(i,k) = 0.5*h_srt(i,kl,j) * h_supply_frac_r(kr)
910 h_used_r(kr) = h_used_r(kr) + hp_ru(j)%p(i,k)
913 if (right_set(k))
then
914 if (deep_wt_lu(j)%p(i,k) < 1.0)
then
915 hp_lu(j)%p(i,k) = 0.5*h_srt(i+1,kr,j) * min(h_supply_frac_l(kl), h_supply_frac_l(kl-1))
916 wt_b = deep_wt_lu(j)%p(i,k)
917 h_used_l(kl-1) = h_used_l(kl-1) + (1.0 - wt_b)*hp_lu(j)%p(i,k)
918 h_used_l(kl) = h_used_l(kl) + wt_b*hp_lu(j)%p(i,k)
920 hp_lu(j)%p(i,k) = 0.5*h_srt(i+1,kr,j) * h_supply_frac_l(kl)
921 h_used_l(kl) = h_used_l(kl) + hp_lu(j)%p(i,k)
929 if (left_set(k)) hp_lu(j)%p(i,k) = hp_lu(j)%p(i,k) + &
930 (h_srt(i,kbs_lp(k),j) - h_used_l(kbs_lp(k)))
931 if (right_set(k)) hp_ru(j)%p(i,k) = hp_ru(j)%p(i,k) + &
932 (h_srt(i+1,kbs_rp(k),j) - h_used_r(kbs_rp(k)))
935 endif ;
enddo ;
enddo
938 k_size = max(max_srt(j)+max_srt(j+1),1)
939 allocate(deep_wt_lv(j)%p(isd:ied,k_size))
940 allocate(deep_wt_rv(j)%p(isd:ied,k_size))
941 allocate(hp_lv(j)%p(isd:ied,k_size))
942 allocate(hp_rv(j)%p(isd:ied,k_size))
943 allocate(k0a_lv(j)%p(isd:ied,k_size))
944 allocate(k0a_rv(j)%p(isd:ied,k_size))
945 allocate(k0b_lv(j)%p(isd:ied,k_size))
946 allocate(k0b_rv(j)%p(isd:ied,k_size))
956 do j=js-1,je ;
do i=is,ie ;
if (g%mask2dCv(i,j) > 0.5)
then
959 do k=1,num_srt(i,j) ; h_demand_l(k) = 0.0 ; h_used_l(k) = 0.0 ;
enddo
960 do k=1,num_srt(i,j+1) ; h_demand_r(k) = 0.0 ; h_used_r(k) = 0.0 ;
enddo
967 if (rho_srt(i,1,j) < rho_srt(i,1,j+1))
then
969 do kl=2,num_srt(i,j) ;
if (rho_srt(i,kl,j) >= rho_srt(i,1,j+1))
exit ;
enddo
970 elseif (rho_srt(i,1,j+1) < rho_srt(i,1,j))
then
972 do kr=2,num_srt(i,j+1) ;
if (rho_srt(i,kr,j+1) >= rho_srt(i,1,j))
exit ;
enddo
978 if ((kl > num_srt(i,j)) .or. (kr > num_srt(i,j+1)))
exit
980 if (rho_srt(i,kl,j) > rho_srt(i,kr,j+1))
then
983 rho_pair = rho_srt(i,kr,j+1)
985 k0b_lv(j)%p(i,k) = k0_srt(i,kl,j) ; k0b_rv(j)%p(i,k) = k0_srt(i,kr,j+1)
986 k0a_lv(j)%p(i,k) = k0_srt(i,kl-1,j) ; k0a_rv(j)%p(i,k) = k0b_rv(j)%p(i,k)
987 kbs_lp(k) = kl ; kbs_rp(k) = kr
989 rho_a = rho_srt(i,kl-1,j) ; rho_b = rho_srt(i,kl,j)
990 wt_b = 1.0 ;
if (abs(rho_a - rho_b) > abs(rho_pair - rho_a)) &
991 wt_b = (rho_pair - rho_a) / (rho_b - rho_a)
992 deep_wt_lv(j)%p(i,k) = wt_b ; deep_wt_rv(j)%p(i,k) = 1.0
994 h_demand_l(kl) = h_demand_l(kl) + 0.5*h_srt(i,kr,j+1) * wt_b
995 h_demand_l(kl-1) = h_demand_l(kl-1) + 0.5*h_srt(i,kr,j+1) * (1.0-wt_b)
997 kr = kr+1 ; left_set(k) = .false. ; right_set(k) = .true.
998 elseif (rho_srt(i,kl,j) < rho_srt(i,kr,j+1))
then
1001 rho_pair = rho_srt(i,kl,j)
1002 k0b_lv(j)%p(i,k) = k0_srt(i,kl,j) ; k0b_rv(j)%p(i,k) = k0_srt(i,kr,j+1)
1003 k0a_lv(j)%p(i,k) = k0b_lv(j)%p(i,k) ; k0a_rv(j)%p(i,k) = k0_srt(i,kr-1,j+1)
1005 kbs_lp(k) = kl ; kbs_rp(k) = kr
1007 rho_a = rho_srt(i,kr-1,j+1) ; rho_b = rho_srt(i,kr,j+1)
1008 wt_b = 1.0 ;
if (abs(rho_a - rho_b) > abs(rho_pair - rho_a)) &
1009 wt_b = (rho_pair - rho_a) / (rho_b - rho_a)
1010 deep_wt_lv(j)%p(i,k) = 1.0 ; deep_wt_rv(j)%p(i,k) = wt_b
1012 h_demand_r(kr) = h_demand_r(kr) + 0.5*h_srt(i,kl,j) * wt_b
1013 h_demand_r(kr-1) = h_demand_r(kr-1) + 0.5*h_srt(i,kl,j) * (1.0-wt_b)
1015 kl = kl+1 ; left_set(k) = .true. ; right_set(k) = .false.
1016 elseif ((k0_srt(i,kl,j) <= nkmb) .or. (k0_srt(i,kr,j+1) <= nkmb))
then
1019 k0b_lv(j)%p(i,k) = k0_srt(i,kl,j) ; k0b_rv(j)%p(i,k) = k0_srt(i,kr,j+1)
1020 k0a_lv(j)%p(i,k) = k0b_lv(j)%p(i,k) ; k0a_rv(j)%p(i,k) = k0b_rv(j)%p(i,k)
1021 kbs_lp(k) = kl ; kbs_rp(k) = kr
1022 deep_wt_lv(j)%p(i,k) = 1.0 ; deep_wt_rv(j)%p(i,k) = 1.0
1024 h_demand_l(kl) = h_demand_l(kl) + 0.5*h_srt(i,kr,j+1)
1025 h_demand_r(kr) = h_demand_r(kr) + 0.5*h_srt(i,kl,j)
1027 kl = kl+1 ; kr = kr+1 ; left_set(k) = .true. ; right_set(k) = .true.
1031 h_demand_l(kl) = h_demand_l(kl) + 0.5*h_srt(i,kr,j+1)
1032 h_demand_r(kr) = h_demand_r(kr) + 0.5*h_srt(i,kl,j)
1034 kl = kl+1 ; kr = kr+1
1040 do k=1,num_srt(i,j+1)
1041 h_supply_frac_r(k) = 1.0
1042 if (h_demand_r(k) > 0.5*h_srt(i,k,j+1)) &
1043 h_supply_frac_r(k) = 0.5*h_srt(i,k,j+1) / h_demand_r(k)
1046 h_supply_frac_l(k) = 1.0
1047 if (h_demand_l(k) > 0.5*h_srt(i,k,j)) &
1048 h_supply_frac_l(k) = 0.5*h_srt(i,k,j) / h_demand_l(k)
1053 kl = kbs_lp(k) ; kr = kbs_rp(k)
1054 hp_lv(j)%p(i,k) = 0.0 ; hp_rv(j)%p(i,k) = 0.0
1055 if (left_set(k))
then
1056 if (deep_wt_rv(j)%p(i,k) < 1.0)
then
1057 hp_rv(j)%p(i,k) = 0.5*h_srt(i,kl,j) * min(h_supply_frac_r(kr), h_supply_frac_r(kr-1))
1058 wt_b = deep_wt_rv(j)%p(i,k)
1059 h_used_r(kr-1) = h_used_r(kr-1) + (1.0 - wt_b) * hp_rv(j)%p(i,k)
1060 h_used_r(kr) = h_used_r(kr) + wt_b * hp_rv(j)%p(i,k)
1062 hp_rv(j)%p(i,k) = 0.5*h_srt(i,kl,j) * h_supply_frac_r(kr)
1063 h_used_r(kr) = h_used_r(kr) + hp_rv(j)%p(i,k)
1066 if (right_set(k))
then
1067 if (deep_wt_lv(j)%p(i,k) < 1.0)
then
1068 hp_lv(j)%p(i,k) = 0.5*h_srt(i,kr,j+1) * min(h_supply_frac_l(kl), h_supply_frac_l(kl-1))
1069 wt_b = deep_wt_lv(j)%p(i,k)
1070 h_used_l(kl-1) = h_used_l(kl-1) + (1.0 - wt_b) * hp_lv(j)%p(i,k)
1071 h_used_l(kl) = h_used_l(kl) + wt_b * hp_lv(j)%p(i,k)
1073 hp_lv(j)%p(i,k) = 0.5*h_srt(i,kr,j+1) * h_supply_frac_l(kl)
1074 h_used_l(kl) = h_used_l(kl) + hp_lv(j)%p(i,k)
1082 if (left_set(k)) hp_lv(j)%p(i,k) = hp_lv(j)%p(i,k) + &
1083 (h_srt(i,kbs_lp(k),j) - h_used_l(kbs_lp(k)))
1084 if (right_set(k)) hp_rv(j)%p(i,k) = hp_rv(j)%p(i,k) + &
1085 (h_srt(i,kbs_rp(k),j+1) - h_used_r(kbs_rp(k)))
1089 endif ;
enddo ;
enddo
1094 do k=1,pemax_krho ;
do j=js-1,je+1 ;
do i=is-1,ie+1
1095 tr_flux_conv(i,j,k) = 0.0
1096 enddo ;
enddo ;
enddo
1101 call do_group_pass(cs%pass_t, g%Domain, clock=id_clock_pass)
1111 do j=js,je ;
do i=is-1,ie ;
if (g%mask2dCu(i,j) > 0.5)
then
1115 if (npu(i,j) >= 1)
then
1116 tr_min_face = min(tr(m)%t(i,j,1), tr(m)%t(i+1,j,1))
1117 tr_max_face = max(tr(m)%t(i,j,1), tr(m)%t(i+1,j,1))
1119 tr_min_face = min(tr_min_face, tr(m)%t(i,j,k), tr(m)%t(i+1,j,k))
1120 tr_max_face = max(tr_max_face, tr(m)%t(i,j,k), tr(m)%t(i+1,j,k))
1124 kla = nkmb+1 ;
if (max_krho(i,j) < nz+1) kla = max_krho(i,j)
1125 klb = kla ;
if (max_krho(i,j) < nz) klb = max_krho(i,j)+1
1126 kra = nkmb+1 ;
if (max_krho(i+1,j) < nz+1) kra = max_krho(i+1,j)
1127 krb = kra ;
if (max_krho(i+1,j) < nz) krb = max_krho(i+1,j)+1
1128 tr_la = tr_min_face ; tr_lb = tr_la ; tr_ra = tr_la ; tr_rb = tr_la
1129 if (h(i,j,kla) > h_exclude) tr_la = tr(m)%t(i,j,kla)
1130 if (h(i,j,klb) > h_exclude) tr_la = tr(m)%t(i,j,klb)
1131 if (h(i+1,j,kra) > h_exclude) tr_ra = tr(m)%t(i+1,j,kra)
1132 if (h(i+1,j,krb) > h_exclude) tr_rb = tr(m)%t(i+1,j,krb)
1133 tr_min_face = min(tr_min_face, tr_la, tr_lb, tr_ra, tr_rb)
1134 tr_max_face = max(tr_max_face, tr_la, tr_lb, tr_ra, tr_rb)
1138 tr_lb = tr(m)%t(i,j,k0b_lu(j)%p(i,k))
1139 tr_rb = tr(m)%t(i+1,j,k0b_ru(j)%p(i,k))
1140 tr_la = tr_lb ; tr_ra = tr_rb
1141 if (deep_wt_lu(j)%p(i,k) < 1.0) tr_la = tr(m)%t(i,j,k0a_lu(j)%p(i,k))
1142 if (deep_wt_ru(j)%p(i,k) < 1.0) tr_ra = tr(m)%t(i+1,j,k0a_ru(j)%p(i,k))
1143 tr_min_face = min(tr_min_face, tr_la, tr_lb, tr_ra, tr_rb)
1144 tr_max_face = max(tr_max_face, tr_la, tr_lb, tr_ra, tr_rb)
1149 klb = k0b_lu(j)%p(i,k) ; tr_lb = tr(m)%t(i,j,klb) ; tr_av_l = tr_lb
1150 if (deep_wt_lu(j)%p(i,k) < 1.0)
then
1151 kla = k0a_lu(j)%p(i,k) ; tr_la = tr(m)%t(i,j,kla)
1152 wt_b = deep_wt_lu(j)%p(i,k)
1153 tr_av_l = wt_b*tr_lb + (1.0-wt_b)*tr_la
1156 krb = k0b_ru(j)%p(i,k) ; tr_rb = tr(m)%t(i+1,j,krb) ; tr_av_r = tr_rb
1157 if (deep_wt_ru(j)%p(i,k) < 1.0)
then
1158 kra = k0a_ru(j)%p(i,k) ; tr_ra = tr(m)%t(i+1,j,kra)
1159 wt_b = deep_wt_ru(j)%p(i,k)
1160 tr_av_r = wt_b*tr_rb + (1.0-wt_b)*tr_ra
1163 h_l = hp_lu(j)%p(i,k) ; h_r = hp_ru(j)%p(i,k)
1164 tr_flux = i_maxitt * khdt_epi_x(i,j) * (tr_av_l - tr_av_r) * &
1165 ((2.0 * h_l * h_r) / (h_l + h_r))
1168 if (deep_wt_lu(j)%p(i,k) >= 1.0)
then
1169 tr_flux_conv(i,j,klb) = tr_flux_conv(i,j,klb) - tr_flux
1172 wt_b = deep_wt_lu(j)%p(i,k) ; wt_a = 1.0 - wt_b
1173 vol = hp_lu(j)%p(i,k) * g%areaT(i,j)
1181 if (tr_flux > 0.0)
then
1182 if (tr_la < tr_lb)
then ;
if (vol*(tr_la-tr_min_face) < tr_flux) &
1183 tr_adj_vert = -wt_a * min(tr_flux - vol * (tr_la-tr_min_face), &
1184 (vol*wt_b) * (tr_lb - tr_la))
1185 else ;
if (vol*(tr_lb-tr_min_face) < tr_flux) &
1186 tr_adj_vert = wt_b * min(tr_flux - vol * (tr_lb-tr_min_face), &
1187 (vol*wt_a) * (tr_la - tr_lb))
1189 elseif (tr_flux < 0.0)
then
1190 if (tr_la > tr_lb)
then ;
if (vol * (tr_max_face-tr_la) < -tr_flux) &
1191 tr_adj_vert = wt_a * min(-tr_flux - vol * (tr_max_face-tr_la), &
1192 (vol*wt_b) * (tr_la - tr_lb))
1193 else ;
if (vol*(tr_max_face-tr_lb) < -tr_flux) &
1194 tr_adj_vert = -wt_b * min(-tr_flux - vol * (tr_max_face-tr_lb), &
1195 (vol*wt_a)*(tr_lb - tr_la))
1199 tr_flux_conv(i,j,kla) = tr_flux_conv(i,j,kla) - (wt_a*tr_flux + tr_adj_vert)
1200 tr_flux_conv(i,j,klb) = tr_flux_conv(i,j,klb) - (wt_b*tr_flux - tr_adj_vert)
1203 if (deep_wt_ru(j)%p(i,k) >= 1.0)
then
1204 tr_flux_conv(i+1,j,krb) = tr_flux_conv(i+1,j,krb) + tr_flux
1207 wt_b = deep_wt_ru(j)%p(i,k) ; wt_a = 1.0 - wt_b
1208 vol = hp_ru(j)%p(i,k) * g%areaT(i+1,j)
1216 if (tr_flux < 0.0)
then
1217 if (tr_ra < tr_rb)
then ;
if (vol * (tr_ra-tr_min_face) < -tr_flux) &
1218 tr_adj_vert = -wt_a * min(-tr_flux - vol * (tr_ra-tr_min_face), &
1219 (vol*wt_b) * (tr_rb - tr_ra))
1220 else ;
if (vol*(tr_rb-tr_min_face) < (-tr_flux)) &
1221 tr_adj_vert = wt_b * min(-tr_flux - vol * (tr_rb-tr_min_face), &
1222 (vol*wt_a) * (tr_ra - tr_rb))
1224 elseif (tr_flux > 0.0)
then
1225 if (tr_ra > tr_rb)
then ;
if (vol * (tr_max_face-tr_ra) < tr_flux) &
1226 tr_adj_vert = wt_a * min(tr_flux - vol * (tr_max_face-tr_ra), &
1227 (vol*wt_b) * (tr_ra - tr_rb))
1228 else ;
if (vol*(tr_max_face-tr_rb) < tr_flux) &
1229 tr_adj_vert = -wt_b * min(tr_flux - vol * (tr_max_face-tr_rb), &
1230 (vol*wt_a)*(tr_rb - tr_ra))
1234 tr_flux_conv(i+1,j,kra) = tr_flux_conv(i+1,j,kra) + &
1235 (wt_a*tr_flux - tr_adj_vert)
1236 tr_flux_conv(i+1,j,krb) = tr_flux_conv(i+1,j,krb) + &
1237 (wt_b*tr_flux + tr_adj_vert)
1239 if (
associated(tr(m)%df2d_x)) &
1240 tr(m)%df2d_x(i,j) = tr(m)%df2d_x(i,j) + tr_flux * idt
1242 endif ;
enddo ;
enddo
1251 do j=js-1,je ;
do i=is,ie ;
if (g%mask2dCv(i,j) > 0.5)
then
1255 if (npv(i,j) >= 1)
then
1256 tr_min_face = min(tr(m)%t(i,j,1), tr(m)%t(i,j+1,1))
1257 tr_max_face = max(tr(m)%t(i,j,1), tr(m)%t(i,j+1,1))
1259 tr_min_face = min(tr_min_face, tr(m)%t(i,j,k), tr(m)%t(i,j+1,k))
1260 tr_max_face = max(tr_max_face, tr(m)%t(i,j,k), tr(m)%t(i,j+1,k))
1264 kla = nkmb+1 ;
if (max_krho(i,j) < nz+1) kla = max_krho(i,j)
1265 klb = kla ;
if (max_krho(i,j) < nz) klb = max_krho(i,j)+1
1266 kra = nkmb+1 ;
if (max_krho(i,j+1) < nz+1) kra = max_krho(i,j+1)
1267 krb = kra ;
if (max_krho(i,j+1) < nz) krb = max_krho(i,j+1)+1
1268 tr_la = tr_min_face ; tr_lb = tr_la ; tr_ra = tr_la ; tr_rb = tr_la
1269 if (h(i,j,kla) > h_exclude) tr_la = tr(m)%t(i,j,kla)
1270 if (h(i,j,klb) > h_exclude) tr_la = tr(m)%t(i,j,klb)
1271 if (h(i,j+1,kra) > h_exclude) tr_ra = tr(m)%t(i,j+1,kra)
1272 if (h(i,j+1,krb) > h_exclude) tr_rb = tr(m)%t(i,j+1,krb)
1273 tr_min_face = min(tr_min_face, tr_la, tr_lb, tr_ra, tr_rb)
1274 tr_max_face = max(tr_max_face, tr_la, tr_lb, tr_ra, tr_rb)
1278 tr_lb = tr(m)%t(i,j,k0b_lv(j)%p(i,k)) ; tr_rb = tr(m)%t(i,j+1,k0b_rv(j)%p(i,k))
1279 tr_la = tr_lb ; tr_ra = tr_rb
1280 if (deep_wt_lv(j)%p(i,k) < 1.0) tr_la = tr(m)%t(i,j,k0a_lv(j)%p(i,k))
1281 if (deep_wt_rv(j)%p(i,k) < 1.0) tr_ra = tr(m)%t(i,j+1,k0a_rv(j)%p(i,k))
1282 tr_min_face = min(tr_min_face, tr_la, tr_lb, tr_ra, tr_rb)
1283 tr_max_face = max(tr_max_face, tr_la, tr_lb, tr_ra, tr_rb)
1288 klb = k0b_lv(j)%p(i,k) ; tr_lb = tr(m)%t(i,j,klb) ; tr_av_l = tr_lb
1289 if (deep_wt_lv(j)%p(i,k) < 1.0)
then
1290 kla = k0a_lv(j)%p(i,k) ; tr_la = tr(m)%t(i,j,kla)
1291 wt_b = deep_wt_lv(j)%p(i,k)
1292 tr_av_l = wt_b * tr_lb + (1.0-wt_b) * tr_la
1295 krb = k0b_rv(j)%p(i,k) ; tr_rb = tr(m)%t(i,j+1,krb) ; tr_av_r = tr_rb
1296 if (deep_wt_rv(j)%p(i,k) < 1.0)
then
1297 kra = k0a_rv(j)%p(i,k) ; tr_ra = tr(m)%t(i,j+1,kra)
1298 wt_b = deep_wt_rv(j)%p(i,k)
1299 tr_av_r = wt_b * tr_rb + (1.0-wt_b) * tr_ra
1302 h_l = hp_lv(j)%p(i,k) ; h_r = hp_rv(j)%p(i,k)
1303 tr_flux = i_maxitt * ((2.0 * h_l * h_r) / (h_l + h_r)) * &
1304 khdt_epi_y(i,j) * (tr_av_l - tr_av_r)
1305 tr_flux_3d(i,j,k) = tr_flux
1307 if (deep_wt_lv(j)%p(i,k) < 1.0)
then
1309 wt_b = deep_wt_lv(j)%p(i,k) ; wt_a = 1.0 - wt_b
1310 vol = hp_lv(j)%p(i,k) * g%areaT(i,j)
1314 if (tr_flux > 0.0)
then
1315 if (tr_la < tr_lb)
then ;
if (vol * (tr_la-tr_min_face) < tr_flux) &
1316 tr_adj_vert = -wt_a * min(tr_flux - vol * (tr_la-tr_min_face), &
1317 (vol*wt_b) * (tr_lb - tr_la))
1318 else ;
if (vol*(tr_lb-tr_min_face) < tr_flux) &
1319 tr_adj_vert = wt_b * min(tr_flux - vol * (tr_lb-tr_min_face), &
1320 (vol*wt_a) * (tr_la - tr_lb))
1322 elseif (tr_flux < 0.0)
then
1323 if (tr_la > tr_lb)
then ;
if (vol * (tr_max_face-tr_la) < -tr_flux) &
1324 tr_adj_vert = wt_a * min(-tr_flux - vol * (tr_max_face-tr_la), &
1325 (vol*wt_b) * (tr_la - tr_lb))
1326 else ;
if (vol*(tr_max_face-tr_lb) < -tr_flux) &
1327 tr_adj_vert = -wt_b * min(-tr_flux - vol * (tr_max_face-tr_lb), &
1328 (vol*wt_a)*(tr_lb - tr_la))
1331 tr_adj_vert_l(i,j,k) = tr_adj_vert
1334 if (deep_wt_rv(j)%p(i,k) < 1.0)
then
1336 wt_b = deep_wt_rv(j)%p(i,k) ; wt_a = 1.0 - wt_b
1337 vol = hp_rv(j)%p(i,k) * g%areaT(i,j+1)
1341 if (tr_flux < 0.0)
then
1342 if (tr_ra < tr_rb)
then ;
if (vol * (tr_ra-tr_min_face) < -tr_flux) &
1343 tr_adj_vert = -wt_a * min(-tr_flux - vol * (tr_ra-tr_min_face), &
1344 (vol*wt_b) * (tr_rb - tr_ra))
1345 else ;
if (vol*(tr_rb-tr_min_face) < (-tr_flux)) &
1346 tr_adj_vert = wt_b * min(-tr_flux - vol * (tr_rb-tr_min_face), &
1347 (vol*wt_a) * (tr_ra - tr_rb))
1349 elseif (tr_flux > 0.0)
then
1350 if (tr_ra > tr_rb)
then ;
if (vol * (tr_max_face-tr_ra) < tr_flux) &
1351 tr_adj_vert = wt_a * min(tr_flux - vol * (tr_max_face-tr_ra), &
1352 (vol*wt_b) * (tr_ra - tr_rb))
1353 else ;
if (vol*(tr_max_face-tr_rb) < tr_flux) &
1354 tr_adj_vert = -wt_b * min(tr_flux - vol * (tr_max_face-tr_rb), &
1355 (vol*wt_a)*(tr_rb - tr_ra))
1358 tr_adj_vert_r(i,j,k) = tr_adj_vert
1360 if (
associated(tr(m)%df2d_y)) &
1361 tr(m)%df2d_y(i,j) = tr(m)%df2d_y(i,j) + tr_flux * idt
1363 endif ;
enddo ;
enddo
1368 do i=is,ie ;
do j=js-1,je ;
if (g%mask2dCv(i,j) > 0.5)
then
1370 klb = k0b_lv(j)%p(i,k); krb = k0b_rv(j)%p(i,k)
1371 if (deep_wt_lv(j)%p(i,k) >= 1.0)
then
1372 tr_flux_conv(i,j,klb) = tr_flux_conv(i,j,klb) - tr_flux_3d(i,j,k)
1374 kla = k0a_lv(j)%p(i,k)
1375 wt_b = deep_wt_lv(j)%p(i,k) ; wt_a = 1.0 - wt_b
1376 tr_flux_conv(i,j,kla) = tr_flux_conv(i,j,kla) - (wt_a*tr_flux_3d(i,j,k) + tr_adj_vert_l(i,j,k))
1377 tr_flux_conv(i,j,klb) = tr_flux_conv(i,j,klb) - (wt_b*tr_flux_3d(i,j,k) - tr_adj_vert_l(i,j,k))
1379 if (deep_wt_rv(j)%p(i,k) >= 1.0)
then
1380 tr_flux_conv(i,j+1,krb) = tr_flux_conv(i,j+1,krb) + tr_flux_3d(i,j,k)
1382 kra = k0a_rv(j)%p(i,k)
1383 wt_b = deep_wt_rv(j)%p(i,k) ; wt_a = 1.0 - wt_b
1384 tr_flux_conv(i,j+1,kra) = tr_flux_conv(i,j+1,kra) + &
1385 (wt_a*tr_flux_3d(i,j,k) - tr_adj_vert_r(i,j,k))
1386 tr_flux_conv(i,j+1,krb) = tr_flux_conv(i,j+1,krb) + &
1387 (wt_b*tr_flux_3d(i,j,k) + tr_adj_vert_r(i,j,k))
1390 endif ;
enddo ;
enddo
1392 do k=1,pemax_krho ;
do j=js,je ;
do i=is,ie
1393 if ((g%mask2dT(i,j) > 0.5) .and. (h(i,j,k) > 0.0))
then
1394 tr(m)%t(i,j,k) = tr(m)%t(i,j,k) + tr_flux_conv(i,j,k) / &
1395 (h(i,j,k)*g%areaT(i,j))
1396 tr_flux_conv(i,j,k) = 0.0
1398 enddo ;
enddo ;
enddo
1404 deallocate(deep_wt_lu(j)%p) ;
deallocate(deep_wt_ru(j)%p)
1405 deallocate(hp_lu(j)%p) ;
deallocate(hp_ru(j)%p)
1406 deallocate(k0a_lu(j)%p) ;
deallocate(k0a_ru(j)%p)
1407 deallocate(k0b_lu(j)%p) ;
deallocate(k0b_ru(j)%p)
1411 deallocate(deep_wt_lv(j)%p) ;
deallocate(deep_wt_rv(j)%p)
1412 deallocate(hp_lv(j)%p) ;
deallocate(hp_rv(j)%p)
1413 deallocate(k0a_lv(j)%p) ;
deallocate(k0a_rv(j)%p)
1414 deallocate(k0b_lv(j)%p) ;
deallocate(k0b_rv(j)%p)