PHYEX 0.9.5
PHYsique EXternalisée
Loading...
Searching...
No Matches
mode_tridiag_wind.F90
Go to the documentation of this file.
1!MNH_LIC Copyright 1994-2025 CNRS, Meteo-France and Universite Paul Sabatier
2!MNH_LIC This is part of the Meso-NH software governed by the CeCILL-C licence
3!MNH_LIC version 1. See LICENSE, CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt
4!MNH_LIC for details. version 1.
6
7!$ACDC singlecolumn
8
9IMPLICIT NONE
10CONTAINS
11SUBROUTINE tridiag_wind(D,PVARM,PSEA_CU,PA,PCOEFS,PTSTEP,IN_PEXPL,IN_PIMPL, &
12 PRHODJA,PSOURCE,PVARP )
13 USE yomhook , ONLY : lhook, dr_hook, jphook
14! #############################################################
15!
16!
17!!**** *TRIDIAG_WIND* - routine to solve a time implicit scheme
18!!
19!!
20!! PURPOSE
21!! -------
22! The purpose of this routine is to give a field PVARP at t+1, by
23! solving an implicit tridiagonal system obtained by the
24! discretization of the vertical turbulent diffusion. It should be noted
25! that the degree of implicitness can be varied (PIMPL parameter) and the
26! sources of evolution other than the turbulent diffusion can be taken
27! into account through the PSOURCE field. PVARP is localized at a wind
28! point either U or V, PRHODJA is averaged to be localized at the same
29! point. The surface flux is also implicitly computed.
30!
31!!** METHOD
32!! ------
33!! First, the Right Hand Side of the implicit equation is computed.
34!! It is build as follows:
35!! ZY = PVARM + PTSTEP*PSOURCE + DIFF_EXPLI
36!! where PVARM is the variable at t-dt, PSOURCE the supplementary sources of
37!! PVAR ( and not PVAR * PRHODJA !!) and DIFF_EXPLI is the explicit part
38!! of the vertical turbulent diffusion. This operator is spatially
39!! discretized as the implicit one, thus:
40!! DIFF_EXPLI(k) = - PEXPL / PRHODJA(k) *
41!! ( PA(k+1) * (PVARM(k+1) - PVARM(k) )
42!! -PA(k) * (PVARM(k) - PVARM(k-1)) )
43!! For the first level, only the upper part is considered, the lower one
44!! is replaced by the turbulent surface flux (taken into account in the
45!! PSOURCE(ikb) term).
46!! DIFF_EXPLI(ikb) = - PEXPL / PRHODJA(ikb) *
47!! ( PA(ikb+1) * (PVARM(ikb+1) - PVARM(ikb)) )
48!! For the last level, only the lower part is considered, the upper one
49!! is replaced by the turbulent flux which is taken equal to 0
50!! (taken into account in the PSOURCE(ike) term).
51!!
52!! DIFF_EXPLI(ike) = + PEXPL / PRHODJA(ike) *
53!! ( PA(ike) * (PVARM(ike) - PVARM(ike-1)) )
54!!
55!! Then, the classical tridiagonal algorithm is used to invert the
56!! implicit operator. Its matrix is given by:
57!!
58!! ( b(ikb) c(ikb) 0 0 0 0 0 0 )
59!! ( 0 a(ikb+1) b(ikb+1) c(ikb+1) 0 ... 0 0 0 )
60!! ( 0 0 a(ikb+2) b(ikb+2) c(ikb+2). 0 0 0 )
61!! .......................................................................
62!! ( 0 ... 0 a(k) b(k) c(k) 0 ... 0 0 )
63!! .......................................................................
64!! ( 0 0 0 0 0 ...a(ike-1) b(ike-1) c(ike-1))
65!! ( 0 0 0 0 0 ... 0 a(ike) b(ike) )
66!!
67!! ikb and ike represent the first and the last inner mass levels of the
68!! model. The coefficients are:
69!!
70!! a(k) = PIMPL * PA(k)/PRHODJA(k)
71!! b(k) = 1 - PIMPL * PA(k)/PRHODJA(k) - PIMPL * PA(k+1)/PRHODJA(k)
72!! c(k) = PIMPL * PA(k+1)/PRHODJA(k)
73!!
74!! for all k /= ikb or ike
75!!
76!! b(ikb) = 1 - PIMPL * PA(ikb+1)/PRHODJA(ikb) - PIMPL * PCOEFS
77!! c(ikb) = PIMPL * PA(ikb+1)/PRHODJA(ikb)
78!! (discretization of the upper part of the implicit operator)
79!! b(ike) = 1 - PIMPL * PA(ike)/PRHODJA(ike)
80!! a(ike) = PIMPL * PA(ike)/PRHODJA(ike)
81!! (discretization of the lower part of the implicit operator)
82!!
83!! The surface flux is given by:
84!! <w'u'> = <w'u'>EXPL + PIMPL * PCOEFS * PVARP
85!! The explicit part is taken into account in PSOURCE(ikb) and the
86!! implicit one is present in the LHS of the equation in b(ikb)
87!!
88!! Finally, the marginal points are prescribed.
89!!
90!! All these computations are purely vertical and vectorizations are
91!! easely achieved by processing all the verticals in parallel.
92!!
93!! EXTERNAL
94!! --------
95!!
96!! NONE
97!!
98!! IMPLICIT ARGUMENTS
99!! ------------------
100!! MODD_PARAMETERS
101!! JPVEXT_TURB: number of vertical external points
102!!
103!! REFERENCE
104!! ---------
105!! Book 1 of Meso-NH documentation (chapter Turbulence)
106!! Press et al: Numerical recipes (1986) Cambridge Univ. Press
107!!
108!! AUTHOR
109!! ------
110!! Joel Stein * Meteo-France *
111!!
112!! MODIFICATIONS
113!! -------------
114!! Original November 16, 1995
115!! (Stein) February 28, 1995 no inversion in the explicit case
116!! (Seity) February 2012 add possibility to run with reversed
117!! vertical levels
118!! ---------------------------------------------------------------------
119!
120!* 0. DECLARATIONS
121!
122USE modd_dimphyex, ONLY: dimphyex_t
123!
124IMPLICIT NONE
125!
126!
127!* 0.1 declarations of arguments
128!
129TYPE(dimphyex_t), INTENT(IN) :: D
130REAL, DIMENSION(D%NIJT,D%NKT), INTENT(IN) :: PVARM ! variable at t-1
131REAL, DIMENSION(D%NIJT), INTENT(IN) :: PSEA_CU ! surface oceanic current
132REAL, DIMENSION(D%NIJT,D%NKT), INTENT(IN) :: PA ! upper diag. elements
133REAL, DIMENSION(D%NIJT), INTENT(IN) :: PCOEFS ! implicit coeff for the
134 ! surface flux
135REAL, INTENT(IN) :: PTSTEP ! Double time step
136REAL, INTENT(IN) :: IN_PEXPL,IN_PIMPL ! weights of the temporal scheme
137REAL, DIMENSION(D%NIJT,D%NKT), INTENT(IN) :: PRHODJA ! (dry rho)*J averaged
138REAL, DIMENSION(D%NIJT,D%NKT), INTENT(IN) :: PSOURCE ! source term of PVAR
139!
140REAL, DIMENSION(D%NIJT,D%NKT), INTENT(OUT) :: PVARP ! variable at t+1
141!
142!* 0.2 declarations of local variables
143!
144REAL, DIMENSION(D%NIJT,D%NKT) :: ZY ,ZGAM
145 ! RHS of the equation, 3D work array
146REAL, DIMENSION(D%NIJT) :: ZBET
147 ! 2D work array
148INTEGER :: JIJ,JK ! loop counter
149INTEGER :: IKB,IKE ! inner vertical limits
150INTEGER :: IKT,IKA,IKU ! array size in k direction
151INTEGER :: IKTB,IKTE ! start, end of k loops in physical domain
152INTEGER :: IIJB, IIJE ! start, end of ij loops in physical domain
153INTEGER :: IKL
154!
155REAL :: PEXPL,PIMPL,PTSTEP_IN ! bypass AMD GPU perf problem with scalar pointer
156! ---------------------------------------------------------------------------
157!
158!* 1. COMPUTE THE RIGHT HAND SIDE
159! ---------------------------
160!
161REAL(KIND=jphook) :: zhook_handle
162!
163IF (lhook) CALL dr_hook('TRIDIAG_WIND',0,zhook_handle)
164!
165pexpl = in_pexpl
166pimpl = in_pimpl
167ptstep_in = ptstep
168!
169!$acc data present( ZY, ZGAM, ZBET )
170ikt=d%NKT
171iktb=d%NKTB
172ikte=d%NKTE
173ikb=d%NKB
174ike=d%NKE
175ika=d%NKA
176iku=d%NKU
177ikl=d%NKL
178iijb=d%NIJB
179iije=d%NIJE
180!
181!$acc kernels
182!$mnh_expand_array(JIJ=IIJB:IIJE)
183zy(iijb:iije,ikb) = pvarm(iijb:iije,ikb) + ptstep_in*psource(iijb:iije,ikb) - &
184 pexpl / prhodja(iijb:iije,ikb) * pa(iijb:iije,ikb+ikl) * &
185 (pvarm(iijb:iije,ikb+ikl) - pvarm(iijb:iije,ikb)) &
186 - pimpl*pcoefs(iijb:iije)*ptstep*psea_cu(iijb:iije)
187!$mnh_end_expand_array(JIJ=IIJB:IIJE)
188!$acc end kernels
189
190!$acc kernels
191DO jk=iktb+1,ikte-1
192 !$mnh_expand_array(JIJ=IIJB:IIJE)
193 zy(iijb:iije,jk)= pvarm(iijb:iije,jk) + ptstep*psource(iijb:iije,jk) - &
194 pexpl / prhodja(iijb:iije,jk) * &
195 ( pvarm(iijb:iije,jk-ikl)*pa(iijb:iije,jk) &
196 -pvarm(iijb:iije,jk)*(pa(iijb:iije,jk)+pa(iijb:iije,jk+ikl)) &
197 +pvarm(iijb:iije,jk+ikl)*pa(iijb:iije,jk+ikl) &
198 )
199 !$mnh_end_expand_array(JIJ=IIJB:IIJE)
200END DO
201!$acc end kernels
202!
203!$acc kernels
204!$mnh_expand_array(JIJ=IIJB:IIJE)
205zy(iijb:iije,ike)= pvarm(iijb:iije,ike) + ptstep*psource(iijb:iije,ike) + &
206 pexpl / prhodja(iijb:iije,ike) * pa(iijb:iije,ike) * (pvarm(iijb:iije,ike)-pvarm(iijb:iije,ike-ikl))
207!$mnh_end_expand_array(JIJ=IIJB:IIJE)
208!$acc end kernels
209!
210! acc wait
211!
212!* 2. INVERSION OF THE TRIDIAGONAL SYSTEM
213! -----------------------------------
214!
215IF ( pimpl > 1.e-10 ) THEN
216!
217 !
218 ! going up
219 !
220 !$acc kernels
221 !$mnh_expand_array(JIJ=IIJB:IIJE)
222 zbet(iijb:iije) = 1. - pimpl * ( pa(iijb:iije,ikb+ikl) / prhodja(iijb:iije,ikb) &
223 + pcoefs(iijb:iije) * ptstep ) ! bet = b(ikb)
224 pvarp(iijb:iije,ikb) = zy(iijb:iije,ikb) / zbet(iijb:iije)
225 !$mnh_end_expand_array(JIJ=IIJB:IIJE)
226 !$acc end kernels
227 !
228 !$acc parallel
229 !$acc loop seq
230 DO jk = ikb+ikl,ike-ikl,ikl
231 !$mnh_expand_array(JIJ=IIJB:IIJE)
232 zgam(iijb:iije,jk) = pimpl * pa(iijb:iije,jk) / prhodja(iijb:iije,jk-ikl) / zbet(iijb:iije)
233 ! gam(k) = c(k-1) / bet
234 zbet(iijb:iije) = 1. - pimpl * ( pa(iijb:iije,jk) * (1. + zgam(iijb:iije,jk)) &
235 + pa(iijb:iije,jk+ikl) &
236 ) / prhodja(iijb:iije,jk)
237 ! bet = b(k) - a(k)* gam(k)
238 pvarp(iijb:iije,jk)= ( zy(iijb:iije,jk) - pimpl * pa(iijb:iije,jk) / prhodja(iijb:iije,jk) &
239 * pvarp(iijb:iije,jk-ikl) &
240 ) / zbet(iijb:iije)
241 ! res(k) = (y(k) -a(k)*res(k-1))/ bet
242 !$mnh_end_expand_array(JIJ=IIJB:IIJE)
243 END DO
244 !$acc end parallel
245 !$acc kernels
246 !$mnh_expand_array(JIJ=IIJB:IIJE)
247 ! special treatment for the last level
248 zgam(iijb:iije,ike) = pimpl * pa(iijb:iije,ike) / prhodja(iijb:iije,ike-ikl) / zbet(iijb:iije)
249 ! gam(k) = c(k-1) / bet
250 zbet(iijb:iije) = 1. - pimpl * ( pa(iijb:iije,ike) * (1. + zgam(iijb:iije,ike)) &
251 ) / prhodja(iijb:iije,ike)
252 ! bet = b(k) - a(k)* gam(k)
253 pvarp(iijb:iije,ike)= ( zy(iijb:iije,ike) - pimpl * pa(iijb:iije,ike) / prhodja(iijb:iije,ike) &
254 * pvarp(iijb:iije,ike-ikl) &
255 ) / zbet(iijb:iije)
256 ! res(k) = (y(k) -a(k)*res(k-1))/ bet
257 !$mnh_end_expand_array(JIJ=IIJB:IIJE)
258 !
259 !$acc end kernels
260 ! going down
261 !
262 !$acc parallel
263 !$acc loop seq
264 DO jk = ike-ikl,ikb,-1*ikl
265 !$mnh_expand_array(JIJ=IIJB:IIJE)
266 pvarp(iijb:iije,jk) = pvarp(iijb:iije,jk) - zgam(iijb:iije,jk+ikl) * pvarp(iijb:iije,jk+ikl)
267 !$mnh_end_expand_array(JIJ=IIJB:IIJE)
268 END DO
269 !$acc end parallel
270!
271ELSE
272!
273 !$acc kernels
274 DO jk=iktb,ikte
275 !$mnh_expand_array(JIJ=IIJB:IIJE)
276 pvarp(iijb:iije,jk) = zy(iijb:iije,jk)
277 !$mnh_end_expand_array(JIJ=IIJB:IIJE)
278 END DO
279 !$acc end kernels
280!
281END IF
282!
283!
284!* 3. FILL THE UPPER AND LOWER EXTERNAL VALUES
285! ----------------------------------------
286!
287!$acc kernels
288!$mnh_expand_array(JIJ=IIJB:IIJE)
289pvarp(iijb:iije,ika)=pvarp(iijb:iije,ikb)
290pvarp(iijb:iije,iku)=pvarp(iijb:iije,ike)
291!$mnh_end_expand_array(JIJ=IIJB:IIJE)
292!$acc end kernels
293!
294!$acc end data
295!
296!-------------------------------------------------------------------------------
297!
298IF (lhook) CALL dr_hook('TRIDIAG_WIND',1,zhook_handle)
299END SUBROUTINE tridiag_wind
300END MODULE mode_tridiag_wind
subroutine tridiag_wind(d, pvarm, psea_cu, pa, pcoefs, ptstep, in_pexpl, in_pimpl, prhodja, psource, pvarp)