source: LMDZ6/branches/Amaury_dev/libf/phylmd/climb_wind_mod.F90 @ 5119

Last change on this file since 5119 was 5117, checked in by abarral, 4 months ago

rename modules properly lmdz_*
move some unused files to obsolete/
(lint) uppercase fortran keywords

  • 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:keywords set to Author Date Id Revision
File size: 13.1 KB
Line 
1
2MODULE climb_wind_mod
3
4! Module to solve the verctical diffusion of the wind components "u" and "v".
5
6  USE dimphy
7  USE lmdz_abort_physic, ONLY: abort_physic
8
9  IMPLICIT NONE
10
11  SAVE
12  PRIVATE
13 
14  REAL, DIMENSION(:),   ALLOCATABLE  :: alf1, alf2
15  !$OMP THREADPRIVATE(alf1,alf2)
16  REAL, DIMENSION(:,:), ALLOCATABLE  :: Kcoefm
17  !$OMP THREADPRIVATE(Kcoefm)
18  REAL, DIMENSION(:,:), ALLOCATABLE  :: Ccoef_U, Dcoef_U
19  !$OMP THREADPRIVATE(Ccoef_U, Dcoef_U)
20  REAL, DIMENSION(:,:), ALLOCATABLE  :: Ccoef_V, Dcoef_V
21  !$OMP THREADPRIVATE(Ccoef_V, Dcoef_V)
22  REAL, DIMENSION(:), ALLOCATABLE   :: Acoef_U, Bcoef_U
23  !$OMP THREADPRIVATE(Acoef_U, Bcoef_U)
24  REAL, DIMENSION(:), ALLOCATABLE   :: Acoef_V, Bcoef_V
25  !$OMP THREADPRIVATE(Acoef_V, Bcoef_V)
26  LOGICAL                            :: firstcall=.TRUE.
27  !$OMP THREADPRIVATE(firstcall)
28
29 
30  PUBLIC :: climb_wind_down, climb_wind_up
31
32CONTAINS
33
34!****************************************************************************************
35
36  SUBROUTINE climb_wind_init
37
38    INTEGER             :: ierr
39    CHARACTER(len = 20) :: modname = 'climb_wind_init'   
40
41!****************************************************************************************
42! Allocation of global module variables
43
44!****************************************************************************************
45
46    ALLOCATE(alf1(klon), stat=ierr)
47    IF (ierr /= 0) CALL abort_physic(modname,'Pb in allocate alf1',1)
48
49    ALLOCATE(alf2(klon), stat=ierr)
50    IF (ierr /= 0) CALL abort_physic(modname,'Pb in allocate alf2',1)
51
52    ALLOCATE(Kcoefm(klon,klev), stat=ierr)
53    IF (ierr /= 0) CALL abort_physic(modname,'Pb in allocate Kcoefm',1)
54
55    ALLOCATE(Ccoef_U(klon,klev), stat=ierr)
56    IF (ierr /= 0) CALL abort_physic(modname,'Pb in allocate Ccoef_U',1)
57
58    ALLOCATE(Dcoef_U(klon,klev), stat=ierr)
59    IF (ierr /= 0) CALL abort_physic(modname,'Pb in allocation Dcoef_U',1)
60
61    ALLOCATE(Ccoef_V(klon,klev), stat=ierr)
62    IF (ierr /= 0) CALL abort_physic(modname,'Pb in allocation Ccoef_V',1)
63
64    ALLOCATE(Dcoef_V(klon,klev), stat=ierr)
65    IF (ierr /= 0) CALL abort_physic(modname,'Pb in allocation Dcoef_V',1)
66
67    ALLOCATE(Acoef_U(klon), Bcoef_U(klon), Acoef_V(klon), Bcoef_V(klon), STAT=ierr)
68    IF ( ierr /= 0 )  PRINT*,' pb in allloc Acoef_U and Bcoef_U, ierr=', ierr
69
70    firstcall=.FALSE.
71
72  END SUBROUTINE climb_wind_init
73
74!****************************************************************************************
75
76  SUBROUTINE climb_wind_down(knon, dtime, coef_in, pplay, paprs, temp, delp, u_old, v_old, &
77!!! nrlmd le 02/05/2011
78       Ccoef_U_out, Ccoef_V_out, Dcoef_U_out, Dcoef_V_out, &
79       Kcoef_m_out, alf_1_out, alf_2_out, &
80!!!
81       Acoef_U_out, Acoef_V_out, Bcoef_U_out, Bcoef_V_out)
82
83! This routine calculates for the wind components u and v,
84! recursivly the coefficients C and D in equation
85! X(k) = C(k) + D(k)*X(k-1), X=[u,v], k=[1,klev] is the vertical layer.
86
87
88! Input arguments
89!****************************************************************************************
90    INTEGER, INTENT(IN)                      :: knon
91    REAL, INTENT(IN)                         :: dtime
92    REAL, DIMENSION(klon,klev), INTENT(IN)   :: coef_in
93    REAL, DIMENSION(klon,klev), INTENT(IN)   :: pplay ! pres au milieu de couche (Pa)
94    REAL, DIMENSION(klon,klev+1), INTENT(IN) :: paprs ! pression a inter-couche (Pa)
95    REAL, DIMENSION(klon,klev), INTENT(IN)   :: temp  ! temperature
96    REAL, DIMENSION(klon,klev), INTENT(IN)   :: delp
97    REAL, DIMENSION(klon,klev), INTENT(IN)   :: u_old
98    REAL, DIMENSION(klon,klev), INTENT(IN)   :: v_old
99
100! Output arguments
101!****************************************************************************************
102    REAL, DIMENSION(klon), INTENT(OUT)       :: Acoef_U_out
103    REAL, DIMENSION(klon), INTENT(OUT)       :: Acoef_V_out
104    REAL, DIMENSION(klon), INTENT(OUT)       :: Bcoef_U_out
105    REAL, DIMENSION(klon), INTENT(OUT)       :: Bcoef_V_out
106
107!!! nrlmd le 02/05/2011
108    REAL, DIMENSION(klon,klev), INTENT(OUT)  :: Ccoef_U_out
109    REAL, DIMENSION(klon,klev), INTENT(OUT)  :: Ccoef_V_out
110    REAL, DIMENSION(klon,klev), INTENT(OUT)  :: Dcoef_U_out
111    REAL, DIMENSION(klon,klev), INTENT(OUT)  :: Dcoef_V_out
112    REAL, DIMENSION(klon,klev), INTENT(OUT)  :: Kcoef_m_out
113    REAL, DIMENSION(klon), INTENT(OUT)       :: alf_1_out
114    REAL, DIMENSION(klon), INTENT(OUT)       :: alf_2_out
115!!!
116
117! Local variables
118!****************************************************************************************
119    REAL, DIMENSION(klon)                    :: u1lay, v1lay
120    INTEGER                                  :: k, i
121
122! Include
123!****************************************************************************************
124    INCLUDE "YOMCST.h"
125    INCLUDE "compbl.h"   
126
127!****************************************************************************************
128! Initialize module
129    IF (firstcall) CALL climb_wind_init
130
131!****************************************************************************************
132! Calculate the coefficients C and D in : u(k) = C(k) + D(k)*u(k-1)
133
134!****************************************************************************************
135! - Define alpha (alf1 and alf2)
136    alf1(:) = 1.0
137    alf2(:) = 1.0 - alf1(:)
138
139! - Calculate the coefficients K
140    Kcoefm(:,:) = 0.0
141    DO k = 2, klev
142       DO i=1,knon
143          Kcoefm(i,k) = coef_in(i,k)*RG*RG*dtime/(pplay(i,k-1)-pplay(i,k)) &
144               *(paprs(i,k)*2/(temp(i,k)+temp(i,k-1))/RD)**2
145       END DO
146    END DO
147
148! - Calculate the coefficients C and D, component "u"
149    CALL calc_coef(knon, Kcoefm(:,:), delp(:,:), &
150         u_old(:,:), alf1(:), alf2(:),  &
151         Ccoef_U(:,:), Dcoef_U(:,:), Acoef_U(:), Bcoef_U(:))
152
153! - Calculate the coefficients C and D, component "v"
154    CALL calc_coef(knon, Kcoefm(:,:), delp(:,:), &
155         v_old(:,:), alf1(:), alf2(:),  &
156         Ccoef_V(:,:), Dcoef_V(:,:), Acoef_V(:), Bcoef_V(:))
157
158!****************************************************************************************
159! 6)
160! Return the first layer in output variables
161
162!****************************************************************************************
163    Acoef_U_out = Acoef_U
164    Bcoef_U_out = Bcoef_U
165    Acoef_V_out = Acoef_V
166    Bcoef_V_out = Bcoef_V
167
168!****************************************************************************************
169! 7)
170! If Pbl is split, return also the other layers in output variables
171
172!****************************************************************************************
173!!! jyg le 07/02/2012
174!!jyg       IF (mod(iflag_pbl_split,2) .EQ.1) THEN
175       IF (mod(iflag_pbl_split,10) >=1) THEN
176!!! nrlmd le 02/05/2011
177    DO k= 1, klev
178      DO i= 1, klon
179        Ccoef_U_out(i,k) = Ccoef_U(i,k)
180        Ccoef_V_out(i,k) = Ccoef_V(i,k)
181        Dcoef_U_out(i,k) = Dcoef_U(i,k)
182        Dcoef_V_out(i,k) = Dcoef_V(i,k)
183        Kcoef_m_out(i,k) = Kcoefm(i,k)
184      ENDDO
185    ENDDO
186    DO i= 1, klon
187      alf_1_out(i)   = alf1(i)
188      alf_2_out(i)   = alf2(i)
189    ENDDO
190!!!     
191       ENDIF  ! (mod(iflag_pbl_split,2) .ge.1)
192!!!
193
194  END SUBROUTINE climb_wind_down
195
196!****************************************************************************************
197
198  SUBROUTINE calc_coef(knon, Kcoef, delp, X, alfa1, alfa2, Ccoef, Dcoef, Acoef, Bcoef)
199
200! Find the coefficients C and D in fonction of alfa, K and delp
201
202! Input arguments
203!****************************************************************************************
204    INTEGER, INTENT(IN)                      :: knon
205    REAL, DIMENSION(klon,klev), INTENT(IN)   :: Kcoef, delp
206    REAL, DIMENSION(klon,klev), INTENT(IN)   :: X
207    REAL, DIMENSION(klon), INTENT(IN)        :: alfa1, alfa2
208
209! Output arguments
210!****************************************************************************************
211    REAL, DIMENSION(klon), INTENT(OUT)       :: Acoef, Bcoef
212    REAL, DIMENSION(klon,klev), INTENT(OUT)  :: Ccoef, Dcoef
213 
214! local variables
215!****************************************************************************************
216    INTEGER                                  :: k, i
217    REAL                                     :: buf
218
219    INCLUDE "YOMCST.h"
220!****************************************************************************************
221
222! Calculate coefficients C and D at top level, k=klev
223
224    Ccoef(:,:) = 0.0
225    Dcoef(:,:) = 0.0
226
227    DO i = 1, knon
228       buf = delp(i,klev) + Kcoef(i,klev)
229
230       Ccoef(i,klev) = X(i,klev)*delp(i,klev)/buf
231       Dcoef(i,klev) = Kcoef(i,klev)/buf
232    END DO
233
234! Calculate coefficients C and D at top level (klev-1) <= k <= 2
235
236    DO k=(klev-1),2,-1
237       DO i = 1, knon
238          buf = delp(i,k) + Kcoef(i,k) + Kcoef(i,k+1)*(1.-Dcoef(i,k+1))
239         
240          Ccoef(i,k) = (X(i,k)*delp(i,k) + Kcoef(i,k+1)*Ccoef(i,k+1))/buf
241          Dcoef(i,k) = Kcoef(i,k)/buf
242       END DO
243    END DO
244
245! Calculate coeffiecent A and B at surface
246
247    DO i = 1, knon
248       buf = delp(i,1) + Kcoef(i,2)*(1-Dcoef(i,2))
249       Acoef(i) = (X(i,1)*delp(i,1) + Kcoef(i,2)*Ccoef(i,2))/buf
250       Bcoef(i) = -RG/buf
251    END DO
252
253  END SUBROUTINE calc_coef
254
255!****************************************************************************************
256
257  SUBROUTINE climb_wind_up(knon, dtime, u_old, v_old, flx_u1, flx_v1,  &
258!!! nrlmd le 02/05/2011
259       Acoef_U_in, Acoef_V_in, Bcoef_U_in, Bcoef_V_in, &
260       Ccoef_U_in, Ccoef_V_in, Dcoef_U_in, Dcoef_V_in, &
261       Kcoef_m_in, &
262!!!
263       flx_u_new, flx_v_new, d_u_new, d_v_new)
264
265! Diffuse the wind components from the surface layer and up to the top layer.
266! Coefficents A, B, C and D are known from before. Start values for the diffusion are the
267! momentum fluxes at surface.
268
269! u(k=1) = A + B*flx*dtime
270! u(k)   = C(k) + D(k)*u(k-1)  [2 <= k <= klev]
271
272!****************************************************************************************
273
274! Input arguments
275!****************************************************************************************
276    INTEGER, INTENT(IN)                     :: knon
277    REAL, INTENT(IN)                        :: dtime
278    REAL, DIMENSION(klon,klev), INTENT(IN)  :: u_old
279    REAL, DIMENSION(klon,klev), INTENT(IN)  :: v_old
280    REAL, DIMENSION(klon), INTENT(IN)       :: flx_u1, flx_v1 ! momentum flux
281
282!!! nrlmd le 02/05/2011
283    REAL, DIMENSION(klon), INTENT(IN)       :: Acoef_U_in,Acoef_V_in, Bcoef_U_in, Bcoef_V_in
284    REAL, DIMENSION(klon,klev), INTENT(IN)  :: Ccoef_U_in, Ccoef_V_in, Dcoef_U_in, Dcoef_V_in
285    REAL, DIMENSION(klon,klev), INTENT(IN)  :: Kcoef_m_in
286!!!
287
288! Output arguments
289!****************************************************************************************
290    REAL, DIMENSION(klon,klev), INTENT(OUT) :: flx_u_new, flx_v_new
291    REAL, DIMENSION(klon,klev), INTENT(OUT) :: d_u_new, d_v_new
292
293! Local variables
294!****************************************************************************************
295    REAL, DIMENSION(klon,klev)              :: u_new, v_new
296    INTEGER                                 :: k, i
297
298! Include
299!****************************************************************************************
300    INCLUDE "YOMCST.h"
301    INCLUDE "compbl.h"   
302
303!****************************************************************************************
304
305!!! jyg le 07/02/2012
306!!jyg       IF (mod(iflag_pbl_split,2) .EQ.1) THEN
307       IF (mod(iflag_pbl_split,10) >=1) THEN
308!!! nrlmd le 02/05/2011
309    DO i = 1, knon
310      Acoef_U(i)=Acoef_U_in(i)
311      Acoef_V(i)=Acoef_V_in(i)
312      Bcoef_U(i)=Bcoef_U_in(i)
313      Bcoef_V(i)=Bcoef_V_in(i)
314    ENDDO
315    DO k = 1, klev
316      DO i = 1, knon
317        Ccoef_U(i,k)=Ccoef_U_in(i,k)
318        Ccoef_V(i,k)=Ccoef_V_in(i,k)
319        Dcoef_U(i,k)=Dcoef_U_in(i,k)
320        Dcoef_V(i,k)=Dcoef_V_in(i,k)
321        Kcoefm(i,k)=Kcoef_m_in(i,k)
322      ENDDO
323    ENDDO
324!!!
325       ENDIF  ! (mod(iflag_pbl_split,2) .ge.1)
326!!!
327
328! Niveau 1
329    DO i = 1, knon
330       u_new(i,1) = Acoef_U(i) + Bcoef_U(i)*flx_u1(i)*dtime
331       v_new(i,1) = Acoef_V(i) + Bcoef_V(i)*flx_v1(i)*dtime
332    END DO
333
334! Niveau 2 jusqu'au sommet klev
335    DO k = 2, klev
336       DO i=1, knon
337          u_new(i,k) = Ccoef_U(i,k) + Dcoef_U(i,k) * u_new(i,k-1)
338          v_new(i,k) = Ccoef_V(i,k) + Dcoef_V(i,k) * v_new(i,k-1)
339       END DO
340    END DO
341
342!****************************************************************************************
343! Calcul flux
344
345!== flux_u/v est le flux de moment angulaire (positif vers bas)
346!== dont l'unite est: (kg m/s)/(m**2 s)
347
348!****************************************************************************************
349
350    flx_u_new(:,:) = 0.0
351    flx_v_new(:,:) = 0.0
352
353    flx_u_new(1:knon,1)=flx_u1(1:knon)
354    flx_v_new(1:knon,1)=flx_v1(1:knon)
355
356! Niveau 2->klev
357    DO k = 2, klev
358       DO i = 1, knon
359          flx_u_new(i,k) = Kcoefm(i,k)/RG/dtime * &
360               (u_new(i,k)-u_new(i,k-1))
361         
362          flx_v_new(i,k) = Kcoefm(i,k)/RG/dtime * &
363               (v_new(i,k)-v_new(i,k-1))
364       END DO
365    END DO
366
367!****************************************************************************************
368! Calcul tendances
369
370!****************************************************************************************
371    d_u_new(:,:) = 0.0
372    d_v_new(:,:) = 0.0
373    DO k = 1, klev
374       DO i = 1, knon
375          d_u_new(i,k) = u_new(i,k) - u_old(i,k)
376          d_v_new(i,k) = v_new(i,k) - v_old(i,k)
377       END DO
378    END DO
379
380  END SUBROUTINE climb_wind_up
381
382!****************************************************************************************
383
384END MODULE climb_wind_mod
Note: See TracBrowser for help on using the repository browser.