source: codes/icosagcm/trunk/src/physics_dcmip2016.f90 @ 434

Last change on this file since 434 was 434, checked in by dubos, 8 years ago

Dry/moist output cleanup

File size: 9.1 KB
Line 
1MODULE physics_dcmip2016_mod
2  USE ICOSA
3  PRIVATE
4 
5  INTEGER,SAVE :: testcase
6!$OMP THREADPRIVATE(testcase)
7
8  TYPE(t_field),POINTER :: f_out_i(:)
9  REAL(rstd),POINTER :: out_i(:,:)
10
11  TYPE(t_field),POINTER  :: f_precl(:)
12  REAL(rstd),ALLOCATABLE :: precl_packed(:)
13
14  TYPE(t_field),POINTER  :: f_Q1(:)
15  TYPE(t_field),POINTER  :: f_Q2(:)
16  TYPE(t_field),POINTER  :: f_PS(:)
17  TYPE(t_field),POINTER  :: f_rhodz(:)
18  TYPE(t_field),POINTER  :: f_Q1_col_int(:)
19  TYPE(t_field),POINTER  :: f_Q2_col_int(:)
20  PUBLIC :: init_physics, full_physics, write_physics
21
22  INTEGER, PARAMETER :: dry_baroclinic=0
23  INTEGER, PARAMETER :: moist_baroclinic_full=1
24  INTEGER, PARAMETER :: moist_baroclinic_kessler=2
25  INTEGER, PARAMETER :: cyclone=3
26  INTEGER, PARAMETER :: supercell=4
27
28  LOGICAL,SAVE :: PBL   !  boundary layer
29                        !  True : George Bryan
30                        !  False : Reed & Jablonowsi
31  !$OMP THREADPRIVATE(PBL)
32CONTAINS
33
34  SUBROUTINE init_physics
35    USE physics_interface_mod
36    USE omp_para
37    IMPLICIT NONE
38    INTEGER :: ngrid
39    CHARACTER(LEN=255) :: testcase_str 
40   
41    testcase_str='undefined'
42    CALL getin("physics_dcmip2016",testcase_str)
43   
44    SELECT CASE (TRIM(testcase_str))
45      CASE ('dry_baroclinic')
46        testcase=dry_baroclinic
47      CASE ('moist_baroclinic_full') 
48        testcase=moist_baroclinic_full
49      CASE ('moist_baroclinic_kessler') 
50        testcase=moist_baroclinic_kessler
51      CASE ('cyclone') 
52        testcase=cyclone
53      CASE ('supercell') 
54        testcase=supercell
55      CASE DEFAULT
56         PRINT*, 'Bad selector for dcmip2016 test case <', testcase_str, &
57              '> options are <dry_baroclinic>, <moist_baroclinic_full>, <moist_baroclinic_kessler>, <cyclone>, <supercell>'
58         STOP
59    END SELECT
60
61    PBL=.FALSE.
62    CALL getin("physics_dcmip2016_PBL",PBL)
63    IF(is_master) THEN
64       IF(PBL) THEN
65          PRINT *, 'PBL=.TRUE., Bryan PBL activated'
66       ELSE
67          PRINT *, 'PBL=.FALSE., Reed & Jablonowski PBL activated'
68       END IF
69    END IF
70
71    ngrid = physics_inout%ngrid
72    ! Input
73    ALLOCATE(physics_inout%Ai(ngrid))
74    ALLOCATE(physics_inout%lon(ngrid))
75    ALLOCATE(physics_inout%lat(ngrid))
76    ALLOCATE(physics_inout%phis(ngrid))
77    ALLOCATE(physics_inout%p(ngrid,llm+1))
78    ALLOCATE(physics_inout%pk(ngrid,llm))
79    ALLOCATE(physics_inout%Temp(ngrid,llm))
80    ALLOCATE(physics_inout%ulon(ngrid,llm))
81    ALLOCATE(physics_inout%ulat(ngrid,llm))
82    ALLOCATE(physics_inout%q(ngrid,llm,nqtot))
83    ! Output (tendencies)
84    ALLOCATE(physics_inout%dTemp(ngrid,llm))
85    ALLOCATE(physics_inout%dulon(ngrid,llm))
86    ALLOCATE(physics_inout%dulat(ngrid,llm))
87    ALLOCATE(physics_inout%dq(ngrid,llm,nqtot))
88    ! Physics-specific data
89    ALLOCATE(precl_packed(ngrid))
90    CALL allocate_field(f_precl, field_t,type_real)
91    CALL allocate_field(f_Q1, field_t,type_real,llm)
92    CALL allocate_field(f_Q2, field_t,type_real,llm)
93    CALL allocate_field(f_PS, field_t,type_real)
94    CALL allocate_field(f_rhodz, field_t,type_real,llm)
95    CALL allocate_field(f_Q1_col_int, field_t,type_real)
96    CALL allocate_field(f_Q2_col_int, field_t,type_real)
97
98    PRINT *, 'init_physics_new', SIZE(physics_inout%Ai)
99  END SUBROUTINE init_physics
100
101  SUBROUTINE full_physics
102    USE physics_interface_mod
103    CALL compute_physics(physics_inout%ngrid, physics_inout%dt_phys, &
104         physics_inout%lon, physics_inout%lat, physics_inout%p, physics_inout%pk, physics_inout%Temp, & 
105         physics_inout%ulon, physics_inout%ulat, physics_inout%q(:,:,1:5), &
106         physics_inout%dTemp, physics_inout%dulon, physics_inout%dulat, &
107         physics_inout%dq(:,:,1:5), precl_packed)
108  END SUBROUTINE full_physics
109
110  SUBROUTINE write_physics
111    USE output_field_mod
112    USE physics_interface_mod
113    use disvert_mod
114    REAL(rstd), POINTER :: Q1(:,:)
115    REAL(rstd), POINTER :: Q2(:,:)
116    REAL(rstd), POINTER :: PS(:)
117    REAL(rstd), POINTER :: rhodz(:,:)
118    REAL(rstd), POINTER :: Q1_col_int(:)
119    REAL(rstd), POINTER :: Q2_col_int(:)
120   
121   
122    CALL unpack_field(f_precl, precl_packed)
123    CALL output_field("precl",f_precl)
124   
125    CALL unpack_field(f_Q1,physics_inout%q(:,:,4))
126    CALL unpack_field(f_Q2,physics_inout%q(:,:,5))
127    CALL unpack_field(f_ps,physics_inout%p(:,1))
128   
129    DO ind=1,ndomain
130      IF (.NOT. assigned_domain(ind)) CYCLE
131        Q1=f_Q1(ind)
132        Q2=f_Q2(ind)
133        Q1_col_int=f_Q1_col_int(ind)
134        Q2_col_int=f_Q2_col_int(ind)
135        PS=f_PS(ind)
136        rhodz=f_rhodz(ind)
137        DO l=1,llm
138          rhodz(:,l)= ( ap(l)-ap(l+1) + (bp(l)-bp(l+1))*ps(:) )/g   
139        ENDDO
140        Q1_col_int=SUM(Q1*rhodz,2)/SUM(rhodz,2)
141        Q2_col_int=SUM(Q2*rhodz,2)/SUM(rhodz,2)
142    ENDDO
143     
144    CALL output_field("Q1_col_int",f_Q1_col_int)
145    CALL output_field("Q2_col_int",f_Q2_col_int)
146   
147  END SUBROUTINE write_physics
148
149  SUBROUTINE compute_physics(ngrid,dt_phys,lon, lat, p, pk, Temp,u,v,q, dTemp,du,dv,dq, precl)
150    USE icosa
151    USE dcmip2016_simple_physics_mod
152    USE dcmip2016_kessler_physic_mod
153    USE earth_const
154    USE terminator
155    IMPLICIT NONE
156    INTEGER    :: ngrid
157    REAL(rstd) :: lat(ngrid)
158    REAL(rstd) :: lon(ngrid)
159    REAL(rstd) :: ps(ngrid)
160    REAL(rstd) :: precl(ngrid)
161    ! arguments with bottom-up indexing (DYNAMICO)
162    REAL(rstd) :: p(ngrid,llm+1)
163    REAL(rstd) :: pk(ngrid,llm)
164    REAL(rstd) :: Temp(ngrid,llm)
165    REAL(rstd) :: u(ngrid,llm)
166    REAL(rstd) :: v(ngrid,llm)
167    REAL(rstd) :: q(ngrid,llm,5)
168    REAL(rstd) :: dTemp(ngrid,llm)
169    REAL(rstd) :: du(ngrid,llm)
170    REAL(rstd) :: dv(ngrid,llm)
171    REAL(rstd) :: dq(ngrid,llm,5)
172    ! local arrays with top-down vertical indexing (DCMIP)
173    REAL(rstd) :: pint(ngrid,llm+1)
174    REAL(rstd) :: pmid(ngrid,llm)
175    REAL(rstd) :: pdel(ngrid,llm)
176    REAL(rstd) :: Tfi(ngrid,llm)
177    REAL(rstd) :: ufi(ngrid,llm)
178    REAL(rstd) :: vfi(ngrid,llm)
179    REAL(rstd) :: qfi(ngrid,llm,5)
180
181    REAL(rstd)  :: rho(llm), z(llm), theta(llm), qv(llm),qc(llm),qr(llm)
182    REAL(rstd)  :: lastz
183    REAL(rstd)  :: dcl1,dcl2
184     INTEGER :: l,ll,ij
185    REAL(rstd) :: dt_phys, inv_dt
186    INTEGER :: simple_physic_testcase
187   
188    ! prepare input fields and mirror vertical index     
189    ps(:) = p(:,1) ! surface pressure
190
191    DO l=1,llm+1
192      DO ij=1,ngrid
193          pint(ij,l)=p(ij,llm+2-l)
194      ENDDO
195    ENDDO
196
197    DO l=1,llm
198       ll=llm+1-l
199       DO ij=1,ngrid
200          pmid(ij,l)=0.5*(pint(ij,l)+pint(ij,l+1)) ! Pressure inside layers
201          pdel(ij,l)=pint(ij,l+1)-pint(ij,l)       ! Pressure difference between two layers
202          ufi(ij,l)=u(ij,ll)
203          vfi(ij,l)=v(ij,ll)
204          qfi(ij,l,:)=q(ij,ll,:)
205          IF (physics_thermo==thermo_fake_moist) THEN
206            Tfi(ij,l)=Temp(ij,ll)/(1+0.608*qfi(ij,l,1)) 
207          ELSE
208            Tfi(ij,l)=Temp(ij,ll)
209          ENDIF
210       ENDDO
211    ENDDO
212   
213    precl=0.
214    IF (testcase==moist_baroclinic_full .OR. testcase==cyclone  ) THEN
215      IF (testcase==moist_baroclinic_full) simple_physic_testcase=1
216      IF (testcase==cyclone) simple_physic_testcase=0
217      CALL simple_physics(ngrid, llm, dt_phys, lat, tfi, qfi(:,:,1) , ufi, vfi, pmid, pint, pdel, 1./pdel, ps, precl, &
218                          simple_physic_testcase, .FALSE., PBL)
219    ENDIF
220
221 
222    IF (testcase==moist_baroclinic_full .OR. testcase==moist_baroclinic_kessler .OR. testcase==cyclone .OR. testcase==supercell ) THEN
223       DO ij=1,ngrid
224          lastz=0 
225          DO l=1,llm
226           ll=llm+1-l
227           rho(l) = pmid(ij,ll)/(287*Temp(ij,l))
228           z(l)=lastz
229           lastz=lastz+ (p(ij,l)-p(ij,l+1)) /g / rho(l)
230           theta(l)= Tfi(ij,ll) / ( pk(ij,l) / cpp)
231          ENDDO
232         
233          DO l=1,llm-1
234           z(l)= 0.5*(z(l)+z(l+1))
235          ENDDO
236          z(llm)=z(llm)+(z(llm)-z(llm-1))
237         
238          qv(:)=max(qfi(ij,llm:1:-1,1),0.)
239          qc(:)=max(qfi(ij,llm:1:-1,2),0.)
240          qr(:)=max(qfi(ij,llm:1:-1,3),0.)
241         
242          CALL KESSLER(theta(:), qv, qc, qr, rho(:),  &
243                       pk(ij,:)/cpp, dt_phys, z(:), llm, precl(ij)) 
244         
245         
246          DO l=1,llm
247           ll=llm+1-l
248           Tfi(ij,ll) = theta(l)  * ( pk(ij,l) / cpp)
249          ENDDO
250
251          qfi(ij,:,1)=qv(llm:1:-1)
252          qfi(ij,:,2)=qc(llm:1:-1)
253          qfi(ij,:,3)=qr(llm:1:-1)
254
255       ENDDO
256    ENDIF
257   
258    DO l=1,llm
259      ll=llm+1-l
260      DO ij=1,ngrid
261        CALL  tendency_terminator( lat(ij), lon(ij), qfi(ij,ll,4), qfi(ij,ll,5), dt_phys, dcl1, dcl2)
262        qfi(ij,ll,4)=qfi(ij,ll,4)+ dt_phys*dcl1
263        qfi(ij,ll,5)=qfi(ij,ll,5)+ dt_phys*dcl2
264      ENDDO
265    ENDDO
266   
267   
268    ! Mirror vertical index and compute tendencies
269    inv_dt = 1./dt_phys
270    DO l=1,llm
271       ll=llm+1-l
272       DO ij=1,ngrid
273          IF (physics_thermo==thermo_fake_moist) THEN
274            dTemp(ij,l) = inv_dt * ( Tfi(ij,ll)*(1+0.608*qfi(ij,ll,1)) - Temp(ij,l) )
275          ELSE
276            dTemp(ij,l) = inv_dt * ( Tfi(ij,ll) - Temp(ij,l) )
277          ENDIF
278         
279          du(ij,l) = inv_dt * (ufi(ij,ll) - u(ij,l))
280          dv(ij,l) = inv_dt * (vfi(ij,ll) - v(ij,l))
281          dq(ij,l,:)  = inv_dt * (qfi(ij,ll,:) - q(ij,l,:))
282       ENDDO
283    ENDDO
284
285  END SUBROUTINE compute_physics
286   
287END MODULE physics_dcmip2016_mod
288
289
Note: See TracBrowser for help on using the repository browser.