source: LMDZ5/branches/IPSLCM6.0.10/libf/phylmd/climb_hq_mod.F90 @ 5407

Last change on this file since 5407 was 2839, checked in by Laurent Fairhead, 8 years ago

Merged trunk changes r2785:2838 into testing branch

  • Property copyright set to
    Name of program: LMDZ
    Creation date: 1984
    Version: LMDZ5
    License: CeCILL version 2
    Holder: Laboratoire de m\'et\'eorologie dynamique, CNRS, UMR 8539
    See the license file in the root directory
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 17.6 KB
Line 
1MODULE climb_hq_mod
2!
3! Module to solve the verctical diffusion of "q" and "H";
4! specific humidity and potential energi.
5!
6  USE dimphy
7
8  IMPLICIT NONE
9  SAVE
10  PRIVATE
11  PUBLIC :: climb_hq_down, climb_hq_up, d_h_col_vdf, f_h_bnd
12
13  REAL, DIMENSION(:,:), ALLOCATABLE :: gamaq, gamah
14  !$OMP THREADPRIVATE(gamaq,gamah)
15  REAL, DIMENSION(:,:), ALLOCATABLE :: Ccoef_Q, Dcoef_Q
16  !$OMP THREADPRIVATE(Ccoef_Q, Dcoef_Q)
17  REAL, DIMENSION(:,:), ALLOCATABLE :: Ccoef_H, Dcoef_H
18  !$OMP THREADPRIVATE(Ccoef_H, Dcoef_H)
19  REAL, DIMENSION(:), ALLOCATABLE   :: Acoef_Q, Bcoef_Q
20  !$OMP THREADPRIVATE(Acoef_Q, Bcoef_Q)
21  REAL, DIMENSION(:), ALLOCATABLE   :: Acoef_H, Bcoef_H
22  !$OMP THREADPRIVATE(Acoef_H, Bcoef_H)
23  REAL, DIMENSION(:,:), ALLOCATABLE :: Kcoefhq
24  !$OMP THREADPRIVATE(Kcoefhq)
25  REAL, SAVE, DIMENSION(:,:), ALLOCATABLE :: h_old ! for diagnostics, h before solving diffusion
26  !$OMP THREADPRIVATE(h_old)
27  REAL, SAVE, DIMENSION(:), ALLOCATABLE :: d_h_col_vdf ! for diagnostics, vertical integral of enthalpy change
28  !$OMP THREADPRIVATE(d_h_col_vdf)
29  REAL, SAVE, DIMENSION(:), ALLOCATABLE :: f_h_bnd ! for diagnostics, enthalpy flux at surface
30  !$OMP THREADPRIVATE(f_h_bnd)
31
32CONTAINS
33!
34!****************************************************************************************
35!
36  SUBROUTINE climb_hq_down(knon, coefhq, paprs, pplay, &
37       delp, temp, q, dtime, &
38!!! nrlmd le 02/05/2011
39       Ccoef_H_out, Ccoef_Q_out, Dcoef_H_out, Dcoef_Q_out, &
40       Kcoef_hq_out, gama_q_out, gama_h_out, &
41!!!
42       Acoef_H_out, Acoef_Q_out, Bcoef_H_out, Bcoef_Q_out)
43
44! This routine calculates recursivly the coefficients C and D
45! for the quantity X=[Q,H] in equation X(k) = C(k) + D(k)*X(k-1), where k is
46! the index of the vertical layer.
47!
48! Input arguments
49!****************************************************************************************
50    INTEGER, INTENT(IN)                      :: knon
51    REAL, DIMENSION(klon,klev), INTENT(IN)   :: coefhq
52    REAL, DIMENSION(klon,klev), INTENT(IN)   :: pplay
53    REAL, DIMENSION(klon,klev+1), INTENT(IN) :: paprs
54    REAL, DIMENSION(klon,klev), INTENT(IN)   :: temp, delp  ! temperature
55    REAL, DIMENSION(klon,klev), INTENT(IN)   :: q
56    REAL, INTENT(IN)                         :: dtime
57
58! Output arguments
59!****************************************************************************************
60    REAL, DIMENSION(klon), INTENT(OUT)       :: Acoef_H_out
61    REAL, DIMENSION(klon), INTENT(OUT)       :: Acoef_Q_out
62    REAL, DIMENSION(klon), INTENT(OUT)       :: Bcoef_H_out
63    REAL, DIMENSION(klon), INTENT(OUT)       :: Bcoef_Q_out
64
65!!! nrlmd le 02/05/2011
66    REAL, DIMENSION(klon,klev), INTENT(OUT)  :: Ccoef_H_out
67    REAL, DIMENSION(klon,klev), INTENT(OUT)  :: Ccoef_Q_out
68    REAL, DIMENSION(klon,klev), INTENT(OUT)  :: Dcoef_H_out
69    REAL, DIMENSION(klon,klev), INTENT(OUT)  :: Dcoef_Q_out
70    REAL, DIMENSION(klon,klev), INTENT(OUT)  :: Kcoef_hq_out
71    REAL, DIMENSION(klon,klev), INTENT(OUT)  :: gama_q_out
72    REAL, DIMENSION(klon,klev), INTENT(OUT)  :: gama_h_out
73!!!
74
75! Local variables
76!****************************************************************************************
77    LOGICAL, SAVE                            :: first=.TRUE.
78    !$OMP THREADPRIVATE(first)
79! JLD now renamed h_old and declared in module
80!    REAL, DIMENSION(klon,klev)               :: local_H
81    REAL, DIMENSION(klon)                    :: psref
82    REAL                                     :: delz, pkh
83    INTEGER                                  :: k, i, ierr
84! Include
85!****************************************************************************************
86    INCLUDE "YOMCST.h"
87    INCLUDE "compbl.h"   
88
89
90!****************************************************************************************
91! 1)
92! Allocation at first time step only
93!   
94!****************************************************************************************
95
96    IF (first) THEN
97       first=.FALSE.
98       ALLOCATE(Ccoef_Q(klon,klev), STAT=ierr)
99       IF ( ierr /= 0 )  PRINT*,' pb in allloc Ccoef_Q, ierr=', ierr
100       
101       ALLOCATE(Dcoef_Q(klon,klev), STAT=ierr)
102       IF ( ierr /= 0 )  PRINT*,' pb in allloc Dcoef_Q, ierr=', ierr
103       
104       ALLOCATE(Ccoef_H(klon,klev), STAT=ierr)
105       IF ( ierr /= 0 )  PRINT*,' pb in allloc Ccoef_H, ierr=', ierr
106       
107       ALLOCATE(Dcoef_H(klon,klev), STAT=ierr)
108       IF ( ierr /= 0 )  PRINT*,' pb in allloc Dcoef_H, ierr=', ierr
109       
110       ALLOCATE(Acoef_Q(klon), Bcoef_Q(klon), Acoef_H(klon), Bcoef_H(klon), STAT=ierr)
111       IF ( ierr /= 0 )  PRINT*,' pb in allloc Acoef_X and Bcoef_X, ierr=', ierr
112       
113       ALLOCATE(Kcoefhq(klon,klev), STAT=ierr)
114       IF ( ierr /= 0 )  PRINT*,' pb in allloc Kcoefhq, ierr=', ierr
115       
116       ALLOCATE(gamaq(1:klon,2:klev), STAT=ierr)
117       IF ( ierr /= 0 ) PRINT*,' pb in allloc gamaq, ierr=', ierr
118       
119       ALLOCATE(gamah(1:klon,2:klev), STAT=ierr)
120       IF ( ierr /= 0 ) PRINT*,' pb in allloc gamah, ierr=', ierr
121       
122       ALLOCATE(h_old(klon,klev), STAT=ierr)
123       IF ( ierr /= 0 )  PRINT*,' pb in allloc h_old, ierr=', ierr
124       
125       ALLOCATE(d_h_col_vdf(klon), STAT=ierr)
126       IF ( ierr /= 0 )  PRINT*,' pb in allloc d_h_col_vdf, ierr=', ierr
127       
128       ALLOCATE(f_h_bnd(klon), STAT=ierr)
129       IF ( ierr /= 0 )  PRINT*,' pb in allloc f_h_bnd, ierr=', ierr
130    END IF
131
132!****************************************************************************************
133! 2)
134! Definition of the coeficient K
135!
136!****************************************************************************************
137    Kcoefhq(:,:) = 0.0
138    DO k = 2, klev
139       DO i = 1, knon
140          Kcoefhq(i,k) = &
141               coefhq(i,k)*RG*RG*dtime /(pplay(i,k-1)-pplay(i,k)) &
142               *(paprs(i,k)*2/(temp(i,k)+temp(i,k-1))/RD)**2
143       ENDDO
144    ENDDO
145
146!****************************************************************************************
147! 3)
148! Calculation of gama for "Q" and "H"
149!
150!****************************************************************************************
151!   surface pressure is used as reference
152    psref(:) = paprs(:,1)
153
154!   definition of gama
155    IF (iflag_pbl == 1) THEN
156       gamaq(:,:) = 0.0
157       gamah(:,:) = -1.0e-03
158       gamah(:,2) = -2.5e-03
159 
160! conversion de gama
161       DO k = 2, klev
162          DO i = 1, knon
163             delz = RD * (temp(i,k-1)+temp(i,k)) / &
164                    2.0 / RG / paprs(i,k) * (pplay(i,k-1)-pplay(i,k))
165             pkh  = (psref(i)/paprs(i,k))**RKAPPA
166         
167! convertie gradient verticale d'humidite specifique en difference d'humidite specifique entre centre de couches
168             gamaq(i,k) = gamaq(i,k) * delz   
169! convertie gradient verticale de temperature en difference de temperature potentielle entre centre de couches
170             gamah(i,k) = gamah(i,k) * delz * RCPD * pkh
171          ENDDO
172       ENDDO
173
174    ELSE
175       gamaq(:,:) = 0.0
176       gamah(:,:) = 0.0
177    ENDIF
178   
179
180!****************************************************************************************   
181! 4)
182! Calculte the coefficients C and D for specific humidity, q
183!
184!****************************************************************************************
185   
186    CALL calc_coef(knon, Kcoefhq(:,:), gamaq(:,:), delp(:,:), q(:,:), &
187         Ccoef_Q(:,:), Dcoef_Q(:,:), Acoef_Q, Bcoef_Q)
188
189!****************************************************************************************
190! 5)
191! Calculte the coefficients C and D for potentiel entalpie, H
192!
193!****************************************************************************************
194    h_old(:,:) = 0.0
195
196    DO k=1,klev
197       DO i = 1, knon
198          ! convertie la temperature en entalpie potentielle
199          h_old(i,k) = RCPD * temp(i,k) * &
200               (psref(i)/pplay(i,k))**RKAPPA
201       ENDDO
202    ENDDO
203
204    CALL calc_coef(knon, Kcoefhq(:,:), gamah(:,:), delp(:,:), h_old(:,:), &
205         Ccoef_H(:,:), Dcoef_H(:,:), Acoef_H, Bcoef_H)
206 
207!****************************************************************************************
208! 6)
209! Return the first layer in output variables
210!
211!****************************************************************************************
212    Acoef_H_out = Acoef_H
213    Bcoef_H_out = Bcoef_H
214    Acoef_Q_out = Acoef_Q
215    Bcoef_Q_out = Bcoef_Q
216
217!****************************************************************************************
218! 7)
219! If Pbl is split, return also the other layers in output variables
220!
221!****************************************************************************************
222!!! jyg le 07/02/2012
223       IF (mod(iflag_pbl_split,2) .eq.1) THEN
224!!! nrlmd le 02/05/2011
225    DO k= 1, klev
226      DO i= 1, klon
227        Ccoef_H_out(i,k) = Ccoef_H(i,k)
228        Dcoef_H_out(i,k) = Dcoef_H(i,k)
229        Ccoef_Q_out(i,k) = Ccoef_Q(i,k)
230        Dcoef_Q_out(i,k) = Dcoef_Q(i,k)
231        Kcoef_hq_out(i,k) = Kcoefhq(i,k)
232          IF (k.eq.1) THEN
233            gama_h_out(i,k)  = 0.
234            gama_q_out(i,k)  = 0.
235          ELSE
236            gama_h_out(i,k)  = gamah(i,k)
237            gama_q_out(i,k)  = gamaq(i,k)
238          ENDIF
239      ENDDO
240    ENDDO
241!!!     
242       ENDIF  ! (mod(iflag_pbl_split,2) .eq.1)
243!!!
244
245  END SUBROUTINE climb_hq_down
246!
247!****************************************************************************************
248!
249  SUBROUTINE calc_coef(knon, Kcoef, gama, delp, X, Ccoef, Dcoef, Acoef, Bcoef)
250!
251! Calculate the coefficients C and D in : X(k) = C(k) + D(k)*X(k-1)
252! where X is H or Q, and k the vertical level k=1,klev
253!
254    INCLUDE "YOMCST.h"
255! Input arguments
256!****************************************************************************************
257    INTEGER, INTENT(IN)                      :: knon
258    REAL, DIMENSION(klon,klev), INTENT(IN)   :: Kcoef, delp
259    REAL, DIMENSION(klon,klev), INTENT(IN)   :: X
260    REAL, DIMENSION(klon,2:klev), INTENT(IN) :: gama
261
262! Output arguments
263!****************************************************************************************
264    REAL, DIMENSION(klon), INTENT(OUT)       :: Acoef, Bcoef
265    REAL, DIMENSION(klon,klev), INTENT(OUT)  :: Ccoef, Dcoef
266
267! Local variables
268!****************************************************************************************
269    INTEGER                                  :: k, i
270    REAL                                     :: buf
271
272!****************************************************************************************
273! Niveau au sommet, k=klev
274!
275!****************************************************************************************
276    Ccoef(:,:) = 0.0
277    Dcoef(:,:) = 0.0
278
279    DO i = 1, knon
280       buf = delp(i,klev) + Kcoef(i,klev)
281       
282       Ccoef(i,klev) = (X(i,klev)*delp(i,klev) - Kcoef(i,klev)*gama(i,klev))/buf
283       Dcoef(i,klev) = Kcoef(i,klev)/buf
284    END DO
285
286
287!****************************************************************************************
288! Niveau  (klev-1) <= k <= 2
289!
290!****************************************************************************************
291
292    DO k=(klev-1),2,-1
293       DO i = 1, knon
294          buf = delp(i,k) + Kcoef(i,k) + Kcoef(i,k+1)*(1.-Dcoef(i,k+1))
295          Ccoef(i,k) = (X(i,k)*delp(i,k) + Kcoef(i,k+1)*Ccoef(i,k+1) + &
296               Kcoef(i,k+1)*gama(i,k+1) - Kcoef(i,k)*gama(i,k))/buf
297          Dcoef(i,k) = Kcoef(i,k)/buf
298       END DO
299    END DO
300
301!****************************************************************************************
302! Niveau k=1
303!
304!****************************************************************************************
305
306    DO i = 1, knon
307       buf = delp(i,1) + Kcoef(i,2)*(1.-Dcoef(i,2))
308       Acoef(i) = (X(i,1)*delp(i,1) + Kcoef(i,2)*(gama(i,2)+Ccoef(i,2)))/buf
309       Bcoef(i) = -1. * RG / buf
310    END DO
311
312  END SUBROUTINE calc_coef
313!
314!****************************************************************************************
315!
316  SUBROUTINE climb_hq_up(knon, dtime, t_old, q_old, &
317       flx_q1, flx_h1, paprs, pplay, &
318!!! nrlmd le 02/05/2011
319       Acoef_H_in, Acoef_Q_in, Bcoef_H_in, Bcoef_Q_in, &
320       Ccoef_H_in, Ccoef_Q_in, Dcoef_H_in, Dcoef_Q_in, &
321       Kcoef_hq_in, gama_q_in, gama_h_in, &
322!!!
323       flux_q, flux_h, d_q, d_t)
324!
325! This routine calculates the flux and tendency of the specific humidity q and
326! the potential engergi H.
327! The quantities q and H are calculated according to
328! X(k) = C(k) + D(k)*X(k-1) for X=[q,H], where the coefficients
329! C and D are known from before and k is index of the vertical layer.
330!   
331
332! Input arguments
333!****************************************************************************************
334    INTEGER, INTENT(IN)                      :: knon
335    REAL, INTENT(IN)                         :: dtime
336    REAL, DIMENSION(klon,klev), INTENT(IN)   :: t_old, q_old
337    REAL, DIMENSION(klon), INTENT(IN)        :: flx_q1, flx_h1
338    REAL, DIMENSION(klon,klev+1), INTENT(IN) :: paprs
339    REAL, DIMENSION(klon,klev), INTENT(IN)   :: pplay
340
341!!! nrlmd le 02/05/2011
342    REAL, DIMENSION(klon), INTENT(IN)        :: Acoef_H_in,Acoef_Q_in, Bcoef_H_in, Bcoef_Q_in
343    REAL, DIMENSION(klon,klev), INTENT(IN)   :: Ccoef_H_in, Ccoef_Q_in, Dcoef_H_in, Dcoef_Q_in
344    REAL, DIMENSION(klon,klev), INTENT(IN)   :: Kcoef_hq_in, gama_q_in, gama_h_in
345!!!
346
347! Output arguments
348!****************************************************************************************
349    REAL, DIMENSION(klon,klev), INTENT(OUT)  :: flux_q, flux_h, d_q, d_t
350
351! Local variables
352!****************************************************************************************
353    LOGICAL, SAVE                            :: last=.FALSE.
354    REAL, DIMENSION(klon,klev)               :: h_new, q_new
355    REAL, DIMENSION(klon)                    :: psref         
356    INTEGER                                  :: k, i, ierr
357 
358! Include
359!****************************************************************************************
360    INCLUDE "YOMCST.h"
361    INCLUDE "compbl.h"   
362
363!****************************************************************************************
364! 1)
365! Definition of some variables
366    REAL, DIMENSION(klon,klev)               :: d_h, zairm
367!
368!****************************************************************************************
369    flux_q(:,:) = 0.0
370    flux_h(:,:) = 0.0
371    d_q(:,:)    = 0.0
372    d_t(:,:)    = 0.0
373    d_h(:,:)    = 0.0
374    f_h_bnd(:)= 0.0
375
376    psref(1:knon) = paprs(1:knon,1) 
377
378!!! jyg le 07/02/2012
379       IF (mod(iflag_pbl_split,2) .eq.1) THEN
380!!! nrlmd le 02/05/2011
381    DO i = 1, knon
382      Acoef_H(i)=Acoef_H_in(i)
383      Acoef_Q(i)=Acoef_Q_in(i)
384      Bcoef_H(i)=Bcoef_H_in(i)
385      Bcoef_Q(i)=Bcoef_Q_in(i)
386    ENDDO
387    DO k = 1, klev
388      DO i = 1, knon
389        Ccoef_H(i,k)=Ccoef_H_in(i,k)
390        Ccoef_Q(i,k)=Ccoef_Q_in(i,k)
391        Dcoef_H(i,k)=Dcoef_H_in(i,k)
392        Dcoef_Q(i,k)=Dcoef_Q_in(i,k)
393        Kcoefhq(i,k)=Kcoef_hq_in(i,k)
394          IF (k.gt.1) THEN
395            gamah(i,k)=gama_h_in(i,k)
396            gamaq(i,k)=gama_q_in(i,k)
397          ENDIF
398      ENDDO
399    ENDDO
400!!!     
401       ENDIF  ! (mod(iflag_pbl_split,2) .eq.1)
402!!!
403
404!****************************************************************************************
405! 2)
406! Calculation of Q and H
407!
408!****************************************************************************************
409
410!- First layer
411    q_new(1:knon,1) = Acoef_Q(1:knon) + Bcoef_Q(1:knon)*flx_q1(1:knon)*dtime
412    h_new(1:knon,1) = Acoef_H(1:knon) + Bcoef_H(1:knon)*flx_h1(1:knon)*dtime
413    f_h_bnd(1:knon) = flx_h1(1:knon)
414!- All the other layers
415    DO k = 2, klev
416       DO i = 1, knon
417          q_new(i,k) = Ccoef_Q(i,k) + Dcoef_Q(i,k)*q_new(i,k-1)
418          h_new(i,k) = Ccoef_H(i,k) + Dcoef_H(i,k)*h_new(i,k-1)
419       END DO
420    END DO
421!****************************************************************************************
422! 3)
423! Calculation of the flux for Q and H
424!
425!****************************************************************************************
426
427!- The flux at first layer, k=1
428    flux_q(1:knon,1)=flx_q1(1:knon)
429    flux_h(1:knon,1)=flx_h1(1:knon)
430
431!- The flux at all layers above surface
432    DO k = 2, klev
433       DO i = 1, knon
434          flux_q(i,k) = (Kcoefhq(i,k)/RG/dtime) * &
435               (q_new(i,k)-q_new(i,k-1)+gamaq(i,k))
436
437          flux_h(i,k) = (Kcoefhq(i,k)/RG/dtime) * &
438               (h_new(i,k)-h_new(i,k-1)+gamah(i,k))
439       END DO
440    END DO
441
442!****************************************************************************************
443! 4)
444! Calculation of tendency for Q and H
445!
446!****************************************************************************************
447    d_h_col_vdf(:) = 0.0
448    DO k = 1, klev
449       DO i = 1, knon
450          d_t(i,k) = h_new(i,k)/(psref(i)/pplay(i,k))**RKAPPA/RCPD - t_old(i,k)
451          d_q(i,k) = q_new(i,k) - q_old(i,k)
452          d_h(i,k) = h_new(i,k) - h_old(i,k)
453!JLD          d_t(i,k) = d_h(i,k)/(psref(i)/pplay(i,k))**RKAPPA/RCPD    !correction a venir
454    ! layer air mass
455          zairm(i, k) = (paprs(i,k)-paprs(i,k+1))/rg
456          d_h_col_vdf(i) = d_h_col_vdf(i) + d_h(i,k)*zairm(i,k)
457        END DO
458    END DO
459
460!****************************************************************************************
461! Some deallocations
462!
463!****************************************************************************************
464    IF (last) THEN
465       DEALLOCATE(Ccoef_Q, Dcoef_Q, Ccoef_H, Dcoef_H,stat=ierr)   
466       IF ( ierr /= 0 )  PRINT*,' pb in dealllocate Ccoef_Q, Dcoef_Q, Ccoef_H, Dcoef_H, ierr=', ierr
467       DEALLOCATE(Acoef_Q, Bcoef_Q, Acoef_H, Bcoef_H,stat=ierr)   
468       IF ( ierr /= 0 )  PRINT*,' pb in dealllocate Acoef_Q, Bcoef_Q, Acoef_H, Bcoef_H, ierr=', ierr
469       DEALLOCATE(gamaq, gamah,stat=ierr)
470       IF ( ierr /= 0 )  PRINT*,' pb in dealllocate gamaq, gamah, ierr=', ierr
471       DEALLOCATE(Kcoefhq,stat=ierr)
472       IF ( ierr /= 0 )  PRINT*,' pb in dealllocate Kcoefhq, ierr=', ierr
473       DEALLOCATE(h_old, d_h_col_vdf, f_h_bnd, stat=ierr)
474       IF ( ierr /= 0 )  PRINT*,' pb in dealllocate h_old, d_h_col_vdf, f_h_bnd, ierr=', ierr
475    END IF
476  END SUBROUTINE climb_hq_up
477!
478!****************************************************************************************
479!
480END MODULE climb_hq_mod
481
482 
483
484
485
486
Note: See TracBrowser for help on using the repository browser.