66 us,vs,zo,t,q,z1,tn,qo,po,psur,dhdt,kpbl,rho, & ! input variables, must be supplied
67 hfx,qfx,xland,ichoice,tcrit,dtime, &
68 zuo,xmb_out,kbcon,ktop,k22,ierr,ierrc, &
69 outt,outq,outqc,outu,outv,cnvwt,pre,cupclw, & ! output tendencies
70 itf,ktf,its,ite, kts,kte,ipr,tropics)
82 logical :: make_calc_for_xk = .true.
83 integer,
intent (in ) :: &
92 real(kind=kind_phys),
dimension (its:ite,kts:kte) &
94 cnvwt,outt,outq,outqc,cupclw,zuo,outu,outv
96 real(kind=kind_phys),
dimension (its:ite) &
99 integer,
dimension (its:ite) &
100 ,
intent (inout ) :: &
102 integer,
dimension (its:ite) &
105 integer,
dimension (its:ite) &
113 real(kind=kind_phys),
dimension (its:ite,kts:kte) &
115 t,po,tn,dhdt,rho,us,vs
116 real(kind=kind_phys),
dimension (its:ite,kts:kte) &
119 real(kind=kind_phys),
dimension (its:ite) &
121 xland,z1,psur,hfx,qfx
123 real(kind=kind_phys) &
167 real(kind=kind_phys),
dimension (its:ite,kts:kte) :: &
168 entr_rate_2d,he,hes,qes,z, &
170 xhe,xhes,xqes,xz,xt,xq, &
171 qes_cup,q_cup,he_cup,hes_cup,z_cup,p_cup,gamma_cup,t_cup, &
172 qeso_cup,qo_cup,heo_cup,heso_cup,zo_cup,po_cup,gammao_cup, &
174 xqes_cup,xq_cup,xhe_cup,xhes_cup,xz_cup, &
176 dbyo,qco,pwo,hco,qrco, &
184 cd,dellah,dellaq,dellat,dellaqc,uc,vc,dellu,dellv,u_cup,v_cup
204 real(kind=kind_phys),
dimension (its:ite) :: &
205 zws,ztexec,zqexec,pre,aa1,aa0,xaa0,hkb, &
206 flux_tun,hkbo,xhkb, &
207 rand_vmas,xmbmax,xmb, &
209 cap_max_increment,lambau
210 integer,
dimension (its:ite) :: &
211 kstabi,xland1,kbmax,ktopx
222 real(kind=kind_phys) :: &
224 cap_maxs,trash,trash2,frh
226 real(kind=kind_phys) buo_flux,pgeoh,dp,entup,detup,totmas
228 real(kind=kind_phys) xff_shal(3),blqe,xkshal
229 character*50 :: ierrc(its:ite)
230 real(kind=kind_phys),
dimension (its:ite,kts:kte) :: &
231 up_massentr,up_massdetr,up_massentro,up_massdetro,up_massentru,up_massdetru
233 real(kind=kind_phys) :: c_up,x_add,qaver,dts,fp,fpi
234 real(kind=kind_phys),
dimension (its:ite,kts:kte) :: c1d,dtempdz
235 integer,
dimension (its:ite,kts:kte) :: k_inv_layers
236 integer,
dimension (its:ite) :: start_level, pmin_lev
239 real(kind=kind_phys),
parameter :: zero = 0
251 xland1(i)=int(xland(i)+.001)
253 if(xland(i).gt.1.5 .or. xland(i).lt.0.5)
then
259 cap_max_increment(i)=25.
286 cd(i,k)=.75*entr_rate(i)
316 buo_flux= (hfx(i)/cp+0.608*t(i,1)*qfx(i)/xlv)/rho(i,1)
319 zws(i) = max(0.,flux_tun(i)*0.41*buo_flux*zo(i,2)*g/t(i,1))
320 if(zws(i) > tiny(pgeoh))
then
322 zws(i) = 1.2*zws(i)**.3333
324 ztexec(i) = max(flux_tun(i)*hfx(i)/(rho(i,1)*zws(i)*cp),0.0)
326 zqexec(i) = max(flux_tun(i)*qfx(i)/xlv/(rho(i,1)*zws(i)),0.)
330 zws(i) = max(0.,flux_tun(i)*0.41*buo_flux*zo(i,kpbl(i))*g/t(i,kpbl(i)))
331 zws(i) = 1.2*zws(i)**.3333
332 zws(i) = zws(i)*rho(i,kpbl(i))
343 call cup_env(z,qes,he,hes,t,q,po,z1, &
344 psur,ierr,tcrit,-1, &
347 call cup_env(zo,qeso,heo,heso,tn,qo,po,z1, &
348 psur,ierr,tcrit,-1, &
355 call cup_env_clev(t,qes,q,he,hes,z,po,qes_cup,q_cup,he_cup, &
356 hes_cup,z_cup,p_cup,gamma_cup,t_cup,psur, &
360 call cup_env_clev(tn,qeso,qo,heo,heso,zo,po,qeso_cup,qo_cup, &
361 heo_cup,heso_cup,zo_cup,po_cup,gammao_cup,tn_cup,psur, &
369 u_cup(i,kts)=us(i,kts)
370 v_cup(i,kts)=vs(i,kts)
372 u_cup(i,k)=.5*(us(i,k-1)+us(i,k))
373 v_cup(i,k)=.5*(vs(i,k-1)+vs(i,k))
383 if(zo_cup(i,k).gt.zkbmax+z1(i))
then
390 kbmax(i)=min(kbmax(i),ktf/2)
402 if(kpbl(i).gt.3)cap_max(i)=po_cup(i,kpbl(i))
404 k22(i)=maxloc(heo_cup(i,2:kbmax(i)),1)
406 if(k22(i).gt.kbmax(i))
then
409 ierrc(i)=
"could not find k22"
425 x_add = xlv*zqexec(i)+cp*ztexec(i)
426 call get_cloud_bc(kte,he_cup(i,1:kte),hkb(i),k22(i),x_add)
427 call get_cloud_bc(kte,heo_cup(i,1:kte),hkbo(i),k22(i),x_add)
443 call cup_kbcon(ierrc,cap_max_increment,5,k22,kbcon,heo_cup,heso_cup, &
444 hkbo,ierr,kbmax,po_cup,cap_max, &
448 z_cup,entr_rate,heo,0)
451 call cup_minimi(heso_cup,kbcon,kbmax,kstabi,ierr, &
456 kbcon,kstabi,dtempdz,itf,ktf,its,ite, kts,kte)
461 entr_rate_2d(i,:)=entr_rate(i)
463 start_level(i)=k22(i)
464 x_add = xlv*zqexec(i)+cp*ztexec(i)
465 call get_cloud_bc(kte,he_cup(i,1:kte),hkb(i),k22(i),x_add)
466 if(kbcon(i).gt.ktf-4)
then
470 frh = 2.*min(qo_cup(i,k)/qeso_cup(i,k),1.)
471 entr_rate_2d(i,k)=entr_rate(i)
472 cd(i,k)=.75*entr_rate_2d(i,k)
479 if(kpbl(i).lt.5)kstart=kbcon(i)
482 if(k_inv_layers(i,1).gt.0 .and. &
483 (po_cup(i,kstart)-po_cup(i,k_inv_layers(i,1))).lt.200.)
then
484 ktop(i)=k_inv_layers(i,1)
487 if((po_cup(i,kstart)-po_cup(i,k)).gt.200.)
then
497 call rates_up_pdf(rand_vmas,ipr,
'shallow',ktop,ierr,po_cup,entr_rate_2d,hkbo,heo,heso_cup,zo_cup, &
498 xland1,kstabi,k22,kbcon,its,ite,itf,kts,kte,ktf,zuo,kpbl,ktopx,kbcon,pmin_lev)
518 do k=maxloc(zuo(i,:),1),ktop(i)
519 if(zuo(i,k).lt.1.e-6)
then
543 ,ierr,ktop,zo_cup,zuo,cd,entr_rate_2d &
544 ,up_massentro, up_massdetro ,up_massentr, up_massdetr &
545 ,2,kbcon,k22,up_massentru,up_massdetru,lambau)
558 if(ierr(i) /= 0) cycle
559 do k=1,start_level(i)
563 do k=1,start_level(i)-1
565 hco(i,k)=heo_cup(i,k)
578 if(ierr(i) /= 0) cycle
580 do k=start_level(i)+1,ktop(i)
581 hc(i,k)=(hc(i,k-1)*zu(i,k-1)-.5*up_massdetr(i,k-1)*hc(i,k-1)+ &
582 up_massentr(i,k-1)*he(i,k-1)) / &
583 (zu(i,k-1)-.5*up_massdetr(i,k-1)+up_massentr(i,k-1))
584 uc(i,k)=(uc(i,k-1)*zu(i,k-1)-.5*up_massdetr(i,k-1)*uc(i,k-1)+ &
585 up_massentr(i,k-1)*us(i,k-1)) / &
586 (zu(i,k-1)-.5*up_massdetr(i,k-1)+up_massentr(i,k-1))
587 vc(i,k)=(vc(i,k-1)*zu(i,k-1)-.5*up_massdetr(i,k-1)*vc(i,k-1)+ &
588 up_massentr(i,k-1)*vs(i,k-1))/ &
589 (zu(i,k-1)-.5*up_massdetr(i,k-1)+up_massentr(i,k-1))
590 dby(i,k)=max(0.,hc(i,k)-hes_cup(i,k))
591 hco(i,k)=(hco(i,k-1)*zuo(i,k-1)-.5*up_massdetro(i,k-1)*hco(i,k-1)+ &
592 up_massentro(i,k-1)*heo(i,k-1)) / &
593 (zuo(i,k-1)-.5*up_massdetro(i,k-1)+up_massentro(i,k-1))
594 dbyo(i,k)=hco(i,k)-heso_cup(i,k)
595 dz=zo_cup(i,k+1)-zo_cup(i,k)
596 if(k.ge.kbcon(i))dbyt(i,k)=dbyt(i,k-1)+dbyo(i,k)*dz
598 ki=maxloc(dbyt(i,:),1)
599 if(ktop(i).gt.ki+1)
then
601 zuo(i,ktop(i)+1:ktf)=0.
602 zu(i,ktop(i)+1:ktf)=0.
603 cd(i,ktop(i)+1:ktf)=0.
604 up_massdetro(i,ktop(i))=zuo(i,ktop(i))
606 up_massentro(i,ktop(i):ktf)=0.
607 up_massdetro(i,ktop(i)+1:ktf)=0.
608 entr_rate_2d(i,ktop(i)+1:ktf)=0.
613 if(ktop(i).lt.kbcon(i)+1)
then
616 ierrc(i)=
'ktop is less than kbcon+1'
620 if(ktop(i).gt.ktf-2)
then
623 ierrc(i)=
"ktop is larger than ktf-2"
628 call get_cloud_bc(kte,qo_cup(i,1:kte),qaver,k22(i),zero)
629 qaver = qaver + zqexec(i)
630 do k=1,start_level(i)-1
631 qco(i,k)= qo_cup(i,k)
637 do k=start_level(i)+1,ktop(i)
638 trash=qeso_cup(i,k)+(1./xlv)*(gammao_cup(i,k) &
639 /(1.+gammao_cup(i,k)))*dbyo(i,k)
642 qco(i,k)= (trash2* ( zuo(i,k-1)-0.5*up_massdetr(i,k-1)) + &
643 up_massentr(i,k-1)*qo(i,k-1)) / &
644 (zuo(i,k-1)-.5*up_massdetr(i,k-1)+up_massentr(i,k-1))
646 if(qco(i,k)>=trash )
then
647 dz=z_cup(i,k)-z_cup(i,k-1)
649 c1d(i,k)=.02*up_massdetr(i,k-1)
650 qrco(i,k)= (qco(i,k)-trash)/(1.+(c0_shal+c1d(i,k))*dz)
651 if(qrco(i,k).lt.0.)
then
655 pwo(i,k)=c0_shal*dz*qrco(i,k)*zuo(i,k)
657 qco(i,k)= trash+qrco(i,k)
662 cupclw(i,k)=qrco(i,k)
667 do k=k22(i)+1,ktop(i)
668 dp=100.*(po_cup(i,k)-po_cup(i,k+1))
669 cnvwt(i,k)=zuo(i,k)*cupclw(i,k)*g/dp
671 trash2=trash2+entr_rate_2d(i,k)
673 qco(i,k)=qco(i,k)-qrco(i,k)
676 do k=k22(i)+1,max(kbcon(i),k22(i)+1)
678 trash=trash+entr_rate_2d(i,k)
683 hco(i,k)=heso_cup(i,k)
684 qco(i,k)=qeso_cup(i,k)
699 if(make_calc_for_xk)
then
700 call cup_up_aa0(aa0,z,zu,dby,gamma_cup,t_cup, &
702 itf,ktf, its,ite, kts,kte)
703 call cup_up_aa0(aa1,zo,zuo,dbyo,gammao_cup,tn_cup, &
705 itf,ktf, its,ite, kts,kte)
712 ierrc(i)=
"cloud work function zero"
782 dp=100.*(po_cup(i,1)-po_cup(i,2))
783 dellu(i,1)= -zuo(i,2)*(uc(i,2)-u_cup(i,2)) *g/dp
784 dellv(i,1)= -zuo(i,2)*(vc(i,2)-v_cup(i,2)) *g/dp
785 dellah(i,1)=-zuo(i,2)*(hco(i,2)-heo_cup(i,2))*g/dp
787 dellaq(i,1)=-zuo(i,2)*(qco(i,2)-qo_cup(i,2))*g/dp
791 entup=up_massentro(i,k)
792 detup=up_massdetro(i,k)
793 totmas=detup-entup+zuo(i,k+1)-zuo(i,k)
795 if(abs(totmas).gt.1.e-6)
then
796 write(0,*)
'*********************',i,k,totmas
797 write(0,*)k22(i),kbcon(i),ktop(i)
800 dp=100.*(po_cup(i,k)-po_cup(i,k+1))
801 dellah(i,k) =-(zuo(i,k+1)*(hco(i,k+1)-heo_cup(i,k+1) )- &
802 zuo(i,k )*(hco(i,k )-heo_cup(i,k ) ))*g/dp
805 dz=zo_cup(i,k+1)-zo_cup(i,k)
806 if(k.lt.ktop(i) .and. c1d(i,k) > 0)
then
807 dellaqc(i,k)= zuo(i,k)*c1d(i,k)*qrco(i,k)*dz/dp*g
809 dellaqc(i,k)=detup*0.5*(qrco(i,k+1)+qrco(i,k)) *g/dp
815 c_up = dellaqc(i,k)+(zuo(i,k+1)* qrco(i,k+1) - &
816 zuo(i,k )* qrco(i,k ) )*g/dp
820 dellaq(i,k) =-(zuo(i,k+1)*(qco(i,k+1)-qo_cup(i,k+1) ) - &
821 zuo(i,k )*(qco(i,k )-qo_cup(i,k ) ) )*g/dp &
822 - c_up - 0.5*(pwo(i,k)+pwo(i,k+1))*g/dp
823 dellu(i,k) =-(zuo(i,k+1)*(uc(i,k+1)-u_cup(i,k+1) ) - &
824 zuo(i,k )*(uc(i,k )-u_cup(i,k ) ) )*g/dp
825 dellv(i,k) =-(zuo(i,k+1)*(vc(i,k+1)-v_cup(i,k+1) ) - &
826 zuo(i,k )*(vc(i,k )-v_cup(i,k ) ) )*g/dp
842 xhe(i,k)=dellah(i,k)*mbdt+heo(i,k)
843 xq(i,k)=max(1.e-16,(dellaq(i,k)+dellaqc(i,k))*mbdt+qo(i,k))
844 dellat(i,k)=(1./cp)*(dellah(i,k)-xlv*(dellaq(i,k)))
845 xt(i,k)= (-dellaqc(i,k)*xlv/cp+dellat(i,k))*mbdt+tn(i,k)
846 xt(i,k)= max(190.,xt(i,k))
853 xhe(i,ktf)=heo(i,ktf)
861 if(make_calc_for_xk)
then
865 call cup_env(xz,xqes,xhe,xhes,xt,xq,po,z1, &
866 psur,ierr,tcrit,-1, &
872 call cup_env_clev(xt,xqes,xq,xhe,xhes,xz,po,xqes_cup,xq_cup, &
873 xhe_cup,xhes_cup,xz_cup,po_cup,gamma_cup,xt_cup,psur, &
892 x_add = xlv*zqexec(i)+cp*ztexec(i)
893 call get_cloud_bc(kte,xhe_cup(i,1:kte),xhkb(i),k22(i),x_add)
894 do k=1,start_level(i)-1
895 xhc(i,k)=xhe_cup(i,k)
907 xzu(i,1:ktf)=zuo(i,1:ktf)
909 do k=start_level(i)+1,ktop(i)
910 xhc(i,k)=(xhc(i,k-1)*xzu(i,k-1)-.5*up_massdetro(i,k-1)*xhc(i,k-1)+ &
911 up_massentro(i,k-1)*xhe(i,k-1)) / &
912 (xzu(i,k-1)-.5*up_massdetro(i,k-1)+up_massentro(i,k-1))
913 xdby(i,k)=xhc(i,k)-xhes_cup(i,k)
917 xhc(i,k)=xhes_cup(i,k)
928 call cup_up_aa0(xaa0,xz,xzu,xdby,gamma_cup,xt_cup, &
948 xkshal=(xaa0(i)-aa1(i))/mbdt
949 if(xkshal.le.0.and.xkshal.gt.-.01*mbdt) &
951 if(xkshal.gt.0.and.xkshal.lt.1.e-2) &
954 xff_shal(1)=max(0.,-(aa1(i)-aa0(i))/(xkshal*dtime))
957 xff_shal(2)=.03*zws(i)
962 blqe=blqe+100.*dhdt(i,k)*(po_cup(i,k)-po_cup(i,k+1))/g
964 trash=max((hc(i,kbcon(i))-he_cup(i,kbcon(i))),1.e1)
965 xff_shal(3)=max(0.,blqe/trash)
966 xff_shal(3)=min(xmbmax(i),xff_shal(3))
968 xmb(i)=(xff_shal(1)+xff_shal(2)+xff_shal(3))/3.
969 xmb(i)=min(xmbmax(i),xmb(i))
970 if(ichoice > 0)xmb(i)=min(xmbmax(i),xff_shal(ichoice))
988 else if(ierr(i).eq.0)
then
996 outt(i,k)= dellat(i,k)*xmb(i)
997 outq(i,k)= dellaq(i,k)*xmb(i)
998 outqc(i,k)= dellaqc(i,k)*xmb(i)
1000 pre(i) = pre(i)+pwo(i,k)*xmb(i)
1002 outt(i,1)= dellat(i,1)*xmb(i)
1003 outq(i,1)= dellaq(i,1)*xmb(i)
1004 outu(i,1)=dellu(i,1)*xmb(i)
1005 outv(i,1)=dellv(i,1)*xmb(i)
1007 outu(i,k)=.25*(dellu(i,k-1)+2.*dellu(i,k)+dellu(i,k+1))*xmb(i)
1008 outv(i,k)=.25*(dellv(i,k-1)+2.*dellv(i,k)+dellv(i,k+1))*xmb(i)
1017 if(ierr(i).eq.0)
then
1021 dp=(po_cup(i,k)-po_cup(i,k+1))*100.
1023 dts= dts -(outu(i,k)*us(i,k)+outv(i,k)*vs(i,k))*dp/g
1025 fpi = fpi +sqrt(outu(i,k)*outu(i,k) + outv(i,k)*outv(i,k))*dp
1029 fp= sqrt((outu(i,k)*outu(i,k)+outv(i,k)*outv(i,k)))/fpi
1030 outt(i,k)=outt(i,k)+fp*dts*g/cp