Newer
Older

WAUTELET Philippe
committed
!MNH_LIC Copyright 1994-2022 CNRS, Meteo-France and Universite Paul Sabatier
!MNH_LIC This is part of the Meso-NH software governed by the CeCILL-C licence

WAUTELET Philippe
committed
!MNH_LIC version 1. See LICENSE, CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt
!MNH_LIC for details. version 1.
!-----------------------------------------------------------------

WAUTELET Philippe
committed
!###############
module mode_turb
!###############

WAUTELET Philippe
committed
#ifdef MNH_OPENACC
use mode_msg
USE MODE_MNH_ZWORK , ONLY : MNH_ALLOCATE_ZT3D , MNH_REL_ZT3D, MNH_ALLOCATE_ZT3DP , MNH_ALLOCATE_ZT2D, &
MNH_ALLOCATE_ZT4D , MNH_REL_ZT4D , &
MNH_CHECK_IN_ZT3D,MNH_CHECK_OUT_ZT3D
#endif

WAUTELET Philippe
committed
#ifdef MNH_BITREP
use modi_bitrep
#endif
implicit none
private

WAUTELET Philippe
committed
contains
! #################################################################

WAUTELET Philippe
committed
SUBROUTINE TURB(KKA, KKU, KKL, KMI,KRR,KRRL,KRRI,HLBCX,HLBCY, &
KSPLIT,KMODEL_CL, &
OTURB_FLX,OTURB_DIAG,OSUBG_COND,ORMC01, &
HTURBDIM,HTURBLEN,HTOM,HTURBLEN_CL,HCLOUD,PIMPL, &

WAUTELET Philippe
committed
PTSTEP,TPFILE,PDXX,PDYY,PDZZ,PDZX,PDZY,PZZ, &
PDIRCOSXW,PDIRCOSYW,PDIRCOSZW,PCOSSLOPE,PSINSLOPE, &

WAUTELET Philippe
committed
PRHODJ,PTHVREF, &

WAUTELET Philippe
committed
PBL_DEPTH, PSBL_DEPTH, &
PCEI,PCEI_MIN,PCEI_MAX,PCOEF_AMPL_SAT, &
PTHLT,PRT, &
PRUS,PRVS,PRWS,PRTHLS,PRRS,PRSVS,PRTKES,PRTKEMS,PSIGS,&
PFLXZTHVMF,PWTH,PWRC,PWSV,PDYP,PTHP,PTR,PDISS,PLEM )
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
! #################################################################
!
!
!!**** *TURB* - computes the turbulent source terms for the prognostic
!! variables.
!!
!! PURPOSE
!! -------
!!**** The purpose of this routine is to compute the source terms in
!! the evolution equations due to the turbulent mixing.
!! The source term is computed as the divergence of the turbulent fluxes.
!! The cartesian fluxes are obtained by a one and a half order closure, based
!! on a prognostic equation for the Turbulence Kinetic Energy( TKE ). The
!! system is closed by prescribing a turbulent mixing length. Different
!! choices are available for this length.
!
!!** METHOD
!! ------
!!
!! The dimensionality of the turbulence parameterization can be chosen by
!! means of the parameter HTURBDIM:
!! * HTURBDIM='1DIM' the parameterization is 1D but can be used in
!! 3D , 2D or 1D simulations. Only the sources associated to the vertical
!! turbulent fluxes are taken into account.
!! * HTURBDIM='3DIM' the parameterization is fully 2D or 3D depending
!! on the model dimensionality. Of course, it does not make any sense to
!! activate this option with a 1D model.
!!
!! The following steps are made:
!! 1- Preliminary computations.
!! 2- The metric coefficients are recovered from the grid knowledge.
!! 3- The mixing length is computed according to its choice:
!! * HTURBLEN='BL89' the Bougeault and Lacarrere algorithm is used.
!! The mixing length is given by the vertical displacement from its
!! original level of an air particule having an initial internal
!! energy equal to its TKE and stopped by the buoyancy forces.
!! The discrete formulation is second order accurate.
!! * HTURBLEN='DELT' the mixing length is given by the mesh size
!! depending on the model dimensionality, this length is limited
!! with the ground distance.
!! * HTURBLEN='DEAR' the mixing length is given by the mesh size
!! depending on the model dimensionality, this length is limited
!! with the ground distance and also by the Deardorff mixing length
!! pertinent in the stable cases.
!! * HTURBLEN='KEPS' the mixing length is deduced from the TKE
!! dissipation, which becomes a prognostic variable of the model (
!! Duynkerke formulation).
!! 3'- The cloud mixing length is computed according to HTURBLEN_CLOUD
!! and emphasized following the CEI index
!! 4- The conservative variables are computed along with Lv/Cp.
!! 5- The turbulent Prandtl numbers are computed from the resolved fields
!! and TKE
!! 6- The sources associated to the vertical turbulent fluxes are computed
!! with a temporal scheme allowing a degree of implicitness given by
!! PIMPL, varying from PIMPL=0. ( purely explicit scheme) to PIMPL=1.
!! ( purely implicit scheme)
!! The sources associated to the horizontal fluxes are computed with a
!! purely explicit temporal scheme. These sources are only computed when
!! the turbulence parameterization is 2D or 3D( HTURBDIM='3DIM' ).
!! 7- The sources for TKE are computed, along with the dissipation of TKE
!! if HTURBLEN='KEPS'.
!! 8- Some turbulence-related quantities are stored in the synchronous
!! FM-file.
!! 9- The non-conservative variables are retrieved.
!!
!!
!! The saving of the fields in the synchronous FM-file is controlled by:
!! * OTURB_FLX => saves all the turbulent fluxes and correlations
!! * OTURB_DIAG=> saves the turbulent Prandtl and Schmidt numbers, the
!! source terms of TKE and dissipation of TKE
!!
!! EXTERNAL
!! --------
!! SUBROUTINE PRANDTL : computes the turbulent Prandtl number
!! SUBROUTINE TURB_VER : computes the sources from the vertical fluxes
!! SUBROUTINE TURB_HOR : computes the sources from the horizontal fluxes
!! SUBROUTINE TKE_EPS_SOURCES : computes the sources for TKE and its
!! dissipation
!! SUBROUTINE BUDGET : computes and stores the budgets
!!
!! IMPLICIT ARGUMENTS
!! ------------------
!!
!! MODD_PARAMETERS : JPVEXT number of marginal vertical points
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
!!
!! MODD_CONF : CCONF model configuration (start/restart)
!! L1D switch for 1D model version
!! L2D switch for 2D model version
!!
!! MODD_CST : contains physical constants
!! XG gravity constant
!! XRD Gas constant for dry air
!! XRV Gas constant for vapor
!!
!! MODD_CTURB : contains turbulence scheme constants
!! XCMFS,XCED to compute the dissipation mixing length
!! XTKEMIN minimum values for the TKE
!! XLINI,XLINF to compute Bougeault-Lacarrere mixing
!! length
!! Module MODD_BUDGET:
!! NBUMOD
!! CBUTYPE
!! LBU_RU
!! LBU_RV
!! LBU_RW
!! LBU_RTH
!! LBU_RSV1
!! LBU_RRV
!! LBU_RRC
!! LBU_RRR
!! LBU_RRI
!! LBU_RRS
!! LBU_RRG
!! LBU_RRH
!!
!! REFERENCE
!! ---------
!! Book 2 of documentation (routine TURB)
!! Book 1 of documentation (Chapter: Turbulence)
!!
!! AUTHOR
!! ------
!! Joan Cuxart * INM and Meteo-France *
!!
!! MODIFICATIONS
!! -------------
!! Original 05/10/94
!! Modifications: Feb 14, 1995 (J.Cuxart and J.Stein)
!! Doctorization and Optimization
!! Modifications: March 21, 1995 (J.M. Carriere)
!! Introduction of cloud water
!! Modifications: June 1, 1995 (J.Cuxart )
!! take min(Kz,delta)
!! Modifications: June 1, 1995 (J.Stein J.Cuxart)
!! remove unnecessary arrays and change Prandtl
!! and Schmidt numbers localizations
!! Modifications: July 20, 1995 (J.Stein) remove MODI_ground_ocean +
!! TZDTCUR + MODD_TIME because they are not used
!! change RW in RNP for the outputs
!! Modifications: August 21, 1995 (Ph. Bougeault)
!! take min(K(z-zsol),delta)
!! Modifications: Sept 14, 1995 (Ph Bougeault, J. Cuxart)
!! second order BL89 mixing length computations + add Deardorff length
!! in the Delta case for stable cases
!! Modifications: Sept 19, 1995 (J. Stein, J. Cuxart)
!! define a DEAR case for the mixing length, add MODI_BUDGET and change
!! some BUDGET calls, add LES tools
!! Modifications: Oct 16, 1995 (J. Stein) change the budget calls
!! Modifications: Feb 28, 1996 (J. Stein) optimization +
!! remove min(K(z-zsol),delta)+
!! bug in the tangential fluxes
!! Modifications: Oct 16, 1996 (J. Stein) change the subgrid condensation
!! scheme + temporal discretization
!! Modifications: Dec 19, 1996 (J.-P. Pinty) update the budget calls
!! Jun 22, 1997 (J. Stein) use the absolute pressure and
!! change the Deardorf length at the surface
!! Modifications: Apr 27, 1997 (V. Masson) BL89 mix. length computed in
!! a separate routine
!! Oct 13, 1999 (J. Stein) switch for the tgt fluxes
!! Jun 24, 1999 (P Jabouille) Add routine UPDATE_ROTATE_WIND
!! Feb 15, 2001 (J. Stein) remove tgt fluxes
!! Mar 8, 2001 (V. Masson) forces the same behaviour near the surface
!! for all mixing lengths
!! Nov 06, 2002 (V. Masson) LES budgets
!! Nov, 2002 (V. Masson) implement modifications of
!! mixing and dissipative lengths
!! near the surface (according
!! Redelsperger et al 2001)
!! Apr, 2003 (V. Masson) bug in Blackadar length
!! bug in LES in 1DIM case
!! Feb 20, 2003 (J.-P. Pinty) Add reversible ice processes
!! May,26 2004 (P Jabouille) coef for computing dissipative heating
!! Sept 2004 (M.Tomasini) Cloud Mixing length modification
!! following the instability
!! criterium CEI calculated in modeln
!! May 2006 Remove KEPS
!! Sept.2006 (I.Sandu): Modification of the stability criterion for
!! DEAR (theta_v -> theta_l)
!! Oct 2007 (J.Pergaud) Add MF contribution for vert. turb. transport
!! Oct.2009 (C.Lac) Introduction of different PTSTEP according to the
!! advection schemes
!! October 2009 (G. Tanguy) add ILENCH=LEN(YCOMMENT) after
!! change of YCOMMENT
!! 06/2011 (J.escobar ) Bypass Bug with ifort11/12 on HLBCX,HLBC
!! 2012-02 Y. Seity, add possibility to run with reversed
!! vertical levels
!! 10/2012 (J. Colin) Correct bug in DearDoff for dry simulations
!! 10/2012 J.Escobar Bypass PGI bug , redefine some allocatable array inplace of automatic
!! 04/2016 (C.Lac) correction of negativity for KHKO

WAUTELET Philippe
committed
! P. Wautelet 05/2016-04/2018: new data structures and calls for I/O
! Q. Rodier 01/2018: introduction of RM17

WAUTELET Philippe
committed
! P. Wautelet 20/05/2019: add name argument to ADDnFIELD_ll + new ADD4DFIELD_ll subroutine

WAUTELET Philippe
committed
! P. Wautelet 20/06/2019: take DELT and DEAR subroutines out of the TURB one (PGI compiler bug workaround) + transform into a mode_ module

WAUTELET Philippe
committed
! P. Wautelet 02/2020: use the new data structures and subroutines for budgets
! B. Vie 03/2020: LIMA negativity checks after turbulence, advection and microphysics budgets
! P. Wautelet 11/06/2020: bugfix: correct PRSVS array indices

WAUTELET Philippe
committed
! P. Wautelet + Benoit Vié 06/2020: improve removal of negative scalar variables + adapt the corresponding budgets
! P. Wautelet 30/06/2020: move removal of negative scalar variables to Sources_neg_correct

WAUTELET Philippe
committed
! R. Honnert/V. Masson 02/2021: new mixing length in the grey zone

WAUTELET Philippe
committed
! J.L. Redelsperger 03/2021: add Ocean LES case

WAUTELET Philippe
committed
! --------------------------------------------------------------------------
!
!* 0. DECLARATIONS
! ------------
!
use modd_budget, only: lbudget_u, lbudget_v, lbudget_w, lbudget_th, lbudget_rv, lbudget_rc, &
lbudget_rr, lbudget_ri, lbudget_rs, lbudget_rg, lbudget_rh, lbudget_sv, &
NBUDGET_U, NBUDGET_V, NBUDGET_W, NBUDGET_TH, NBUDGET_RV, NBUDGET_RC, &
NBUDGET_RR, NBUDGET_RI, NBUDGET_RS, NBUDGET_RG, NBUDGET_RH, NBUDGET_SV1, &

WAUTELET Philippe
committed
tbudgets

WAUTELET Philippe
committed
USE MODD_CONF

RODIER Quentin
committed
USE MODD_DYN_n, ONLY : LOCEAN

WAUTELET Philippe
committed
use modd_field, only: tfielddata, TYPEREAL
USE MODD_IBM_PARAM_n, ONLY: LIBM, XIBM_LS, XIBM_XMUT

WAUTELET Philippe
committed
USE MODD_IO, ONLY: TFILEDATA

WAUTELET Philippe
committed
USE MODD_PARAMETERS, ONLY: JPVEXT_TURB

RODIER Quentin
committed
USE MODD_PARAM_LIMA

RODIER Quentin
committed
USE MODD_TURB_n, ONLY: XCADAP
USE MODI_IBM_MIXINGLENGTH
USE MODI_GRADIENT_M
USE MODI_GRADIENT_U
USE MODI_GRADIENT_V
USE MODI_BL89
USE MODI_TURB_VER
USE MODI_ROTATE_WIND
USE MODI_TURB_HOR_SPLT
USE MODI_TKE_EPS_SOURCES

WAUTELET Philippe
committed
#ifndef MNH_OPENACC

WAUTELET Philippe
committed
#else
!PW: TODO: remove use modi_shuman

WAUTELET Philippe
committed
USE MODI_SHUMAN_DEVICE
#endif
USE MODI_GRADIENT_M
USE MODI_LES_MEAN_SUBGRID
USE MODI_RMC01
USE MODI_GRADIENT_W
USE MODI_TM06
USE MODI_UPDATE_LM
USE MODI_GET_HALO

WAUTELET Philippe
committed
use mode_budget, only: Budget_store_init, Budget_store_end

WAUTELET Philippe
committed
USE MODE_IO_FIELD_WRITE, only: IO_Field_write
USE MODE_MPPDB

WAUTELET Philippe
committed
USE MODE_SBL

WAUTELET Philippe
committed
use mode_sources_neg_correct, only: Sources_neg_correct
!
USE MODI_EMOIST
USE MODI_ETHETA
!
USE MODI_SECOND_MNH
!

WAUTELET Philippe
committed
!
IMPLICIT NONE
!
!
!* 0.1 declarations of arguments
!
!
!
INTEGER, INTENT(IN) :: KKA !near ground array index
INTEGER, INTENT(IN) :: KKU !uppest atmosphere array index
INTEGER, INTENT(IN) :: KKL !vert. levels type 1=MNH -1=ARO
INTEGER, INTENT(IN) :: KMI ! model index number
INTEGER, INTENT(IN) :: KRR ! number of moist var.
INTEGER, INTENT(IN) :: KRRL ! number of liquid water var.
INTEGER, INTENT(IN) :: KRRI ! number of ice water var.
CHARACTER(LEN=*),DIMENSION(:),INTENT(IN):: HLBCX, HLBCY ! X- and Y-direc LBC
INTEGER, INTENT(IN) :: KSPLIT ! number of time-splitting
INTEGER, INTENT(IN) :: KMODEL_CL ! model number for cloud mixing length
LOGICAL, INTENT(IN) :: OTURB_FLX ! switch to write the
! turbulent fluxes in the syncronous FM-file
LOGICAL, INTENT(IN) :: OTURB_DIAG ! switch to write some
! diagnostic fields in the syncronous FM-file
LOGICAL, INTENT(IN) :: OSUBG_COND ! switch for SUBGrid
! CONDensation
LOGICAL, INTENT(IN) :: ORMC01 ! switch for RMC01 lengths in SBL

WAUTELET Philippe
committed
CHARACTER(len=4), INTENT(IN) :: HTURBDIM ! dimensionality of the
! turbulence scheme
CHARACTER(len=4), INTENT(IN) :: HTURBLEN ! kind of mixing length
CHARACTER(len=4), INTENT(IN) :: HTOM ! kind of Third Order Moment
CHARACTER(len=4), INTENT(IN) :: HTURBLEN_CL ! kind of cloud mixing length
REAL, INTENT(IN) :: PIMPL ! degree of implicitness
CHARACTER (LEN=4), INTENT(IN) :: HCLOUD ! Kind of microphysical scheme

WAUTELET Philippe
committed
TYPE(TFILEDATA), INTENT(INOUT) :: TPFILE ! Output file
!
REAL, DIMENSION(:,:,:), INTENT(IN) :: PDXX,PDYY,PDZZ,PDZX,PDZY
! metric coefficients
REAL, DIMENSION(:,:,:), INTENT(IN) :: PZZ ! physical distance
! between 2 succesive grid points along the K direction
REAL, DIMENSION(:,:), INTENT(IN) :: PDIRCOSXW, PDIRCOSYW, PDIRCOSZW
! Director Cosinus along x, y and z directions at surface w-point
REAL, DIMENSION(:,:), INTENT(IN) :: PCOSSLOPE ! cosinus of the angle
! between i and the slope vector
REAL, DIMENSION(:,:), INTENT(IN) :: PSINSLOPE ! sinus of the angle
! between i and the slope vector
REAL, DIMENSION(:,:,:), INTENT(IN) :: PRHODJ ! dry density * Grid size
REAL, DIMENSION(:,:,:), INTENT(IN) :: PTHVREF ! Virtual Potential
! Temperature of the reference state
!
REAL, DIMENSION(:,:), INTENT(IN) :: PSFTH,PSFRV, &
! normal surface fluxes of theta and Rv
PSFU,PSFV

WAUTELET Philippe
committed
! normal surface fluxes of (u,v) parallel to the orography
REAL, DIMENSION(:,:,:), INTENT(IN) :: PSFSV
! normal surface fluxes of Scalar var.
!
! prognostic variables at t- deltat
REAL, DIMENSION(:,:,:), INTENT(IN) :: PPABST ! Pressure at time t
REAL, DIMENSION(:,:,:), INTENT(IN) :: PUT,PVT,PWT ! wind components
REAL, DIMENSION(:,:,:), INTENT(IN) :: PTKET ! TKE
REAL, DIMENSION(:,:,:,:), INTENT(IN) :: PSVT ! passive scal. var.
REAL, DIMENSION(:,:,:), INTENT(IN) :: PSRCT ! Second-order flux
! s'rc'/2Sigma_s2 at time t-1 multiplied by Lambda_3
REAL, DIMENSION(:,:), INTENT(INOUT) :: PBL_DEPTH ! BL height for TOMS
REAL, DIMENSION(:,:), INTENT(INOUT) :: PSBL_DEPTH ! SBL depth for RMC01
!
! variables for cloud mixing length
REAL, DIMENSION(:,:,:), INTENT(IN) :: PCEI ! Cloud Entrainment instability
! index to emphasize localy
! turbulent fluxes
REAL, INTENT(IN) :: PCEI_MIN ! minimum threshold for the instability index CEI
REAL, INTENT(IN) :: PCEI_MAX ! maximum threshold for the instability index CEI
REAL, INTENT(IN) :: PCOEF_AMPL_SAT ! saturation of the amplification coefficient
!
! thermodynamical variables which are transformed in conservative var.
REAL, DIMENSION(:,:,:), INTENT(INOUT) :: PTHLT ! conservative pot. temp.
REAL, DIMENSION(:,:,:,:), INTENT(INOUT) :: PRT ! water var. where
! PRT(:,:,:,1) is the conservative mixing ratio

RODIER Quentin
committed
!
! sources of momentum, conservative potential temperature, Turb. Kin. Energy,
! TKE dissipation
REAL, DIMENSION(:,:,:), INTENT(INOUT) :: PRUS,PRVS,PRWS,PRTHLS,PRTKES
! Source terms for all water kinds, PRRS(:,:,:,1) is used for the conservative
! mixing ratio
REAL, DIMENSION(:,:,:,:), INTENT(INOUT) :: PRRS
! Source terms for all passive scalar variables
REAL, DIMENSION(:,:,:,:), INTENT(INOUT) :: PRSVS
! Sigma_s at time t+1 : square root of the variance of the deviation to the

WAUTELET Philippe
committed
! saturation
REAL, DIMENSION(:,:,:), INTENT(OUT) :: PSIGS
REAL, DIMENSION(:,:,:), INTENT(IN) :: PFLXZTHVMF
! MF contribution for vert. turb. transport
! used in the buoy. prod. of TKE
REAL, DIMENSION(:,:,:), INTENT(OUT) :: PWTH ! heat flux
REAL, DIMENSION(:,:,:), INTENT(OUT) :: PWRC ! cloud water flux
REAL, DIMENSION(:,:,:,:),INTENT(OUT) :: PWSV ! scalar flux
REAL, DIMENSION(:,:,:), INTENT(OUT) :: PDYP ! Dynamical production of TKE
REAL, DIMENSION(:,:,:), INTENT(OUT) :: PTHP ! Thermal production of TKE
REAL, DIMENSION(:,:,:), INTENT(OUT) :: PTR ! Transport production of TKE
REAL, DIMENSION(:,:,:), INTENT(OUT) :: PDISS ! Dissipation of TKE
REAL, DIMENSION(:,:,:), INTENT(OUT) :: PLEM ! Mixing length
!
!-------------------------------------------------------------------------------
!
! 0.2 declaration of local variables
!
REAL, POINTER , CONTIGUOUS, DIMENSION(:,:,:) ::&
ZCP, & ! Cp at t-1
ZEXN, & ! EXN at t-1
ZT, & ! T at t-1
ZLOCPEXNM, & ! Lv/Cp/EXNREF at t-1

RODIER Quentin
committed
ZLMW, & ! Turbulent mixing length (work array)
ZTRH, & ! Dynamic and Thermal Production of TKE
ZATHETA,ZAMOIST, & ! coefficients for s = f (Thetal,Rnp)
ZCOEF_DISS, & ! 1/(Cph*Exner) for dissipative heating
ZFRAC_ICE, & ! ri fraction of rc+ri
ZMWTH,ZMWR,ZMTH2,ZMR2,ZMTHR,& ! 3rd order moments
ZFWTH,ZFWR,ZFTH2,ZFR2,ZFTHR,& ! opposite of verticale derivate of 3rd order moments

WAUTELET Philippe
committed
ZTHLM ! initial potential temp.

WAUTELET Philippe
committed
#ifdef MNH_OPENACC
INTEGER :: IZCP,IZEXN,IZT,IZLOCPEXNM,IZLEPS,IZTRH,IZATHETA,IZAMOIST &
,IZCOEF_DISS,IZFRAC_ICE,IZMWTH,IZMWR,IZMTH2,IZMR2,IZMTHR &
,IZFWTH,IZFWR,IZFTH2,IZFR2,IZFTHR,IZTHLM

WAUTELET Philippe
committed
#endif

WAUTELET Philippe
committed
!
REAL, POINTER , CONTIGUOUS, DIMENSION(:,:,:,:) :: &
ZRM ! initial mixing ratio
REAL, POINTER , CONTIGUOUS, DIMENSION(:,:) :: ZTAU11M,ZTAU12M, &
ZTAU22M,ZTAU33M, &
! tangential surface fluxes in the axes following the orography
ZUSLOPE,ZVSLOPE, &
! wind components at the first mass level parallel
! to the orography
! - Cd*||u|| where ||u|| is the module of the wind tangential to
! orography (ZUSLOPE,ZVSLOPE) at the surface.
ZUSTAR, ZLMO, &
ZRVM, ZSFRV
! friction velocity, Monin Obuhkov length, work arrays for vapor
!
! Virtual Potential Temp. used
! in the Deardorff mixing length computation

WAUTELET Philippe
committed
#ifdef MNH_OPENACC
INTEGER :: IZRM,IZTAU11M,IZTAU12M,IZTAU22M,IZTAU33M,IZUSLOPE,IZVSLOPE &
,IZCDUEFF,IZUSTAR,IZLMO,IZRVM,IZSFRV

WAUTELET Philippe
committed
#endif
REAL, DIMENSION(:,:,:), POINTER , CONTIGUOUS :: &
ZLVOCPEXNM,ZLSOCPEXNM, & ! Lv/Cp/EXNREF and Ls/Cp/EXNREF at t-1
ZATHETA_ICE,ZAMOIST_ICE ! coefficients for s = f (Thetal,Rnp)

WAUTELET Philippe
committed
#ifdef MNH_OPENACC
INTEGER :: IZLVOCPEXNM,IZLSOCPEXNM,IZATHETA_ICE,IZAMOIST_ICE

WAUTELET Philippe
committed
#endif
!
REAL :: ZEXPL ! 1-PIMPL deg of expl.
REAL :: ZRVORD ! RV/RD
!
INTEGER :: IKB,IKE ! index value for the
! Beginning and the End of the physical domain for the mass points
INTEGER :: IKT ! array size in k direction
INTEGER :: IKTB,IKTE ! start, end of k loops in physical domain
INTEGER :: JRR,JK,JSV ! loop counters
INTEGER :: JI,JJ ! loop counters
REAL :: ZL0 ! Max. Mixing Length in Blakadar formula

RODIER Quentin
committed
REAL :: ZALPHA ! work coefficient :
! - proportionnality constant between Dz/2 and
! ! BL89 mixing length near the surface
REAL, DIMENSION(:,:,:), pointer , contiguous :: ZTT,ZEXNE,ZLV,ZCPH
REAL, DIMENSION(:,:,:), pointer , contiguous :: ZSHEAR, ZDUDZ, ZDVDZ

WAUTELET Philippe
committed
#ifdef MNH_OPENACC
INTEGER :: IZTT,IZEXNE,IZLV,IZCPH,IZSHEAR, IZDUDZ, IZDVDZ

WAUTELET Philippe
committed
#endif

WAUTELET Philippe
committed
TYPE(TFIELDDATA) :: TZFIELD

WAUTELET Philippe
committed
#ifdef MNH_OPENACC
REAL, DIMENSION(:,:,:), pointer , contiguous :: ZTMP1_DEVICE,ZTMP2_DEVICE,ZTMP3_DEVICE
INTEGER :: IZTMP1_DEVICE,IZTMP2_DEVICE,IZTMP3_DEVICE

WAUTELET Philippe
committed
#endif

WAUTELET Philippe
committed
!
INTEGER :: JIU,JJU,JKU
INTEGER :: JLU_ZRM, JLU_TURB, JJU_ORMC01, JKU_CLOUD, JKU_TURB
LOGICAL :: GOCEAN !Intermediate variable used to work around a Cray compiler bug (CCE 13.0.0)
!------------------------------------------------------------------------------------------

WAUTELET Philippe
committed
!
! IN variables
!
!$acc data present( PDXX, PDYY, PDZZ, PDZX, PDZY, PRHODJ) &
!$acc & copyin ( PZZ, PDIRCOSXW, PDIRCOSYW, PDIRCOSZW, &
!$acc & PCOSSLOPE, PSINSLOPE, PTHVREF, PSFTH, PSFRV, PSFU, PSFV, PSFSV, &
!$acc & PPABST, PUT, PVT, PWT, PTKET, PSVT, PSRCT, PCEI, PRTKEMS, PFLXZTHVMF ) &
!
! INOUT variables
!
!$acc & create ( PBL_DEPTH, PSBL_DEPTH, PTHLT, PRT, &
!$acc & PRUS, PRVS, PRWS, PRTKES, PRRS, PRSVS ) &
!$acc & present( PRTHLS ) &

WAUTELET Philippe
committed
!
! OUT variables
!
!$acc & create ( PSIGS, PWTH, PWRC, PWSV, PDYP, PTHP, PTR, PDISS, PLEM )

WAUTELET Philippe
committed
!
! Local variables
!
! !$acc & create ( ZSHEAR )

WAUTELET Philippe
committed
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
if ( mppdb_initialized ) then
!Check all in arrays
call Mppdb_check( pdxx, "Turb beg:pdxx" )
call Mppdb_check( pdyy, "Turb beg:pdyy" )
call Mppdb_check( pdzz, "Turb beg:pdzz" )
call Mppdb_check( pdzx, "Turb beg:pdzx" )
call Mppdb_check( pdzy, "Turb beg:pdzy" )
call Mppdb_check( prhodj, "Turb beg:prhodj" )
call Mppdb_check( pzz, "Turb beg:pzz" )
call Mppdb_check( pdircosxw, "Turb beg:pdircosxw" )
call Mppdb_check( pdircosyw, "Turb beg:pdircosyw" )
call Mppdb_check( pdircoszw, "Turb beg:pdircoszw" )
call Mppdb_check( pcosslope, "Turb beg:pcosslope" )
call Mppdb_check( psinslope, "Turb beg:psinslope" )
call Mppdb_check( pthvref, "Turb beg:pthvref" )
call Mppdb_check( psfth, "Turb beg:psfth" )
call Mppdb_check( psfrv, "Turb beg:psfrv" )
call Mppdb_check( psfu, "Turb beg:psfu" )
call Mppdb_check( psfv, "Turb beg:psfv" )
call Mppdb_check( psfsv, "Turb beg:psfsv" )
call Mppdb_check( ppabst, "Turb beg:ppabst" )
call Mppdb_check( put, "Turb beg:put" )
call Mppdb_check( pvt, "Turb beg:pvt" )
call Mppdb_check( pwt, "Turb beg:pwt" )
call Mppdb_check( ptket, "Turb beg:ptket" )
call Mppdb_check( psvt, "Turb beg:psvt" )
call Mppdb_check( psrct, "Turb beg:psrct" )
call Mppdb_check( pcei, "Turb beg:pcei" )
call Mppdb_check( prtkems, "Turb beg:prtkems" )
call Mppdb_check( pflxzthvmf, "Turb beg:pflxzthvmf" )
!check all inout arrays
call Mppdb_check( pbl_depth, "Turb beg:pbl_depth" )
call Mppdb_check( psbl_depth, "Turb beg:psbl_depth" )
call Mppdb_check( pthlt, "Turb beg:pthlt" )
call Mppdb_check( prt, "Turb beg:prt" )
call Mppdb_check( prus, "Turb beg:prus" )
call Mppdb_check( prvs, "Turb beg:prvs" )
call Mppdb_check( prws, "Turb beg:prws" )
call Mppdb_check( prthls, "Turb beg:prthls" )
call Mppdb_check( prtkes, "Turb beg:prtkes" )
call Mppdb_check( prrs, "Turb beg:prrs" )
call Mppdb_check( prsvs, "Turb beg:prsvs" )
end if
JIU = size(pthlt, 1 )
JJU = size(pthlt, 2 )
JKU = size(pthlt, 3 )

WAUTELET Philippe
committed
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
#ifndef MNH_OPENACC
ALLOCATE (ZCP (JIU,JJU,JKU) )
ALLOCATE (ZEXN (JIU,JJU,JKU) )
ALLOCATE (ZT (JIU,JJU,JKU) )
ALLOCATE (ZLOCPEXNM (JIU,JJU,JKU) )
ALLOCATE (ZLEPS (JIU,JJU,JKU) )
ALLOCATE (ZTRH (JIU,JJU,JKU) )
ALLOCATE (ZATHETA (JIU,JJU,JKU) )
ALLOCATE (ZAMOIST (JIU,JJU,JKU) )
ALLOCATE (ZCOEF_DISS(JIU,JJU,JKU) )
ALLOCATE (ZFRAC_ICE (JIU,JJU,JKU) )
ALLOCATE (ZMWTH (JIU,JJU,JKU) )
ALLOCATE (ZMWR (JIU,JJU,JKU) )
ALLOCATE (ZMTH2 (JIU,JJU,JKU) )
ALLOCATE (ZMR2 (JIU,JJU,JKU) )
ALLOCATE (ZMTHR (JIU,JJU,JKU) )
ALLOCATE (ZFWTH (JIU,JJU,JKU) )
ALLOCATE (ZFWR (JIU,JJU,JKU) )
ALLOCATE (ZFTH2 (JIU,JJU,JKU) )
ALLOCATE (ZFR2 (JIU,JJU,JKU) )
ALLOCATE (ZFTHR (JIU,JJU,JKU) )
ALLOCATE (ZTHLM (JIU,JJU,JKU) )
JLU_TURB = 0
IF ( HTURBLEN == 'BL89' .OR. HTURBLEN == 'RM17' .OR. ORMC01 ) JLU_TURB = SIZE(PRT,4)
ALLOCATE ( ZRM(JIU,JJU,JKU, JLU_TURB ) )
ALLOCATE ( ZTAU11M(JIU,JJU) )
ALLOCATE ( ZTAU12M(JIU,JJU) )
ALLOCATE ( ZTAU22M(JIU,JJU) )
ALLOCATE ( ZTAU33M(JIU,JJU) )
ALLOCATE ( ZUSLOPE(JIU,JJU) )
ALLOCATE ( ZVSLOPE(JIU,JJU) )
ALLOCATE ( ZCDUEFF(JIU,JJU) )
ALLOCATE ( ZLMO (JIU,JJU) )
JJU_ORMC01 = 0
IF (ORMC01) JJU_ORMC01 = SIZE(PTHLT,2)
ALLOCATE ( ZUSTAR (JIU,JJU_ORMC01) )
ALLOCATE ( ZRVM (JIU,JJU_ORMC01) )
ALLOCATE ( ZSFRV (JIU,JJU_ORMC01) )
JKU_CLOUD = 0
IF ( HCLOUD == 'KHKO' .OR. HCLOUD == 'C2R2' ) JKU_CLOUD = size( put, 3 )
allocate( ztt (JIU,JJU, JKU_CLOUD ) )
allocate( zexne (JIU,JJU, JKU_CLOUD ) )
allocate( zlv (JIU,JJU, JKU_CLOUD ) )
allocate( zcph (JIU,JJU, JKU_CLOUD ) )
JKU_TURB = 0
IF ( HTURBLEN == 'BL89' .OR. HTURBLEN == 'RM17' ) JKU_TURB = size( put, 3 )
allocate( zshear(JIU,JJU, JKU_TURB ) )
JKU_TURB = 0
IF ( HTURBLEN == 'RM17' ) JKU_TURB = size( put, 3 )
allocate( zdudz (JIU,JJU, JKU_TURB ) )
allocate( zdvdz (JIU,JJU, JKU_TURB ) )
#else
CALL MNH_CHECK_IN_ZT3D("TURB")
IZCP = MNH_ALLOCATE_ZT3D (ZCP ,JIU,JJU,JKU )
IZEXN = MNH_ALLOCATE_ZT3D (ZEXN ,JIU,JJU,JKU )
IZT = MNH_ALLOCATE_ZT3D (ZT ,JIU,JJU,JKU )
IZLOCPEXNM = MNH_ALLOCATE_ZT3D (ZLOCPEXNM ,JIU,JJU,JKU )
IZLEPS = MNH_ALLOCATE_ZT3D (ZLEPS ,JIU,JJU,JKU )
IZTRH = MNH_ALLOCATE_ZT3D (ZTRH ,JIU,JJU,JKU )
IZATHETA = MNH_ALLOCATE_ZT3D (ZATHETA ,JIU,JJU,JKU )
IZAMOIST = MNH_ALLOCATE_ZT3D (ZAMOIST ,JIU,JJU,JKU )
IZCOEF_DISS = MNH_ALLOCATE_ZT3D (ZCOEF_DISS,JIU,JJU,JKU )
IZFRAC_ICE = MNH_ALLOCATE_ZT3D (ZFRAC_ICE ,JIU,JJU,JKU )
IZMWTH = MNH_ALLOCATE_ZT3D (ZMWTH ,JIU,JJU,JKU )
IZMWR = MNH_ALLOCATE_ZT3D (ZMWR ,JIU,JJU,JKU )
IZMTH2 = MNH_ALLOCATE_ZT3D (ZMTH2 ,JIU,JJU,JKU )
IZMR2 = MNH_ALLOCATE_ZT3D (ZMR2 ,JIU,JJU,JKU )
IZMTHR = MNH_ALLOCATE_ZT3D (ZMTHR ,JIU,JJU,JKU )
IZFWTH = MNH_ALLOCATE_ZT3D (ZFWTH ,JIU,JJU,JKU )
IZFWR = MNH_ALLOCATE_ZT3D (ZFWR ,JIU,JJU,JKU )
IZFTH2 = MNH_ALLOCATE_ZT3D (ZFTH2 ,JIU,JJU,JKU )
IZFR2 = MNH_ALLOCATE_ZT3D (ZFR2 ,JIU,JJU,JKU )
IZFTHR = MNH_ALLOCATE_ZT3D (ZFTHR ,JIU,JJU,JKU )
IZTHLM = MNH_ALLOCATE_ZT3D (ZTHLM ,JIU,JJU,JKU )
JLU_ZRM = 0
IF ( HTURBLEN == 'BL89' .OR. HTURBLEN == 'RM17' .OR. ORMC01 ) JLU_ZRM = SIZE(PRT,4)
IZRM = MNH_ALLOCATE_ZT4D ( ZRM,JIU,JJU,JKU, JLU_ZRM )
IZTAU11M = MNH_ALLOCATE_ZT2D ( ZTAU11M,JIU,JJU )
IZTAU12M = MNH_ALLOCATE_ZT2D ( ZTAU12M,JIU,JJU )
IZTAU22M = MNH_ALLOCATE_ZT2D ( ZTAU22M,JIU,JJU )
IZTAU33M = MNH_ALLOCATE_ZT2D ( ZTAU33M,JIU,JJU )
IZUSLOPE = MNH_ALLOCATE_ZT2D ( ZUSLOPE,JIU,JJU )
IZVSLOPE = MNH_ALLOCATE_ZT2D ( ZVSLOPE,JIU,JJU )
IZCDUEFF = MNH_ALLOCATE_ZT2D ( ZCDUEFF,JIU,JJU )
IZLMO = MNH_ALLOCATE_ZT2D ( ZLMO ,JIU,JJU )
JJU_ORMC01 = 0
IF (ORMC01) JJU_ORMC01 = SIZE(PTHLT,2)
IZUSTAR = MNH_ALLOCATE_ZT2D ( ZUSTAR ,JIU,JJU_ORMC01 )
IZRVM = MNH_ALLOCATE_ZT2D ( ZRVM ,JIU,JJU_ORMC01 )
IZSFRV = MNH_ALLOCATE_ZT2D ( ZSFRV ,JIU,JJU_ORMC01 )
JKU_CLOUD = 0
IF ( HCLOUD == 'KHKO' .OR. HCLOUD == 'C2R2' ) JKU_CLOUD = size( put, 3 )
iztt = MNH_ALLOCATE_ZT3D( ztt ,JIU,JJU,JKU_CLOUD )
izexne = MNH_ALLOCATE_ZT3D( zexne ,JIU,JJU,JKU_CLOUD )
izlv = MNH_ALLOCATE_ZT3D( zlv ,JIU,JJU,JKU_CLOUD )
izcph = MNH_ALLOCATE_ZT3D( zcph ,JIU,JJU,JKU_CLOUD )
JKU_TURB = 0
IF ( HTURBLEN == 'BL89' .OR. HTURBLEN == 'RM17' ) JKU_TURB = size( put, 3 )
izshear = MNH_ALLOCATE_ZT3D( zshear,JIU,JJU, JKU_TURB )
JKU_TURB = 0
IF ( HTURBLEN == 'RM17' ) JKU_TURB = size( put, 3 )
izdudz = MNH_ALLOCATE_ZT3D( zdudz ,JIU,JJU, JKU_TURB )
izdvdz = MNH_ALLOCATE_ZT3D( zdvdz ,JIU,JJU, JKU_TURB )
#endif

WAUTELET Philippe
committed
#ifdef MNH_OPENACC
iztmp1_device = MNH_ALLOCATE_ZT3D( ztmp1_device,JIU,JJU,JKU )
JKU_TURB = 0
IF (HTURBDIM=="1DIM") JKU_TURB = size( pthlt, 3 )
iztmp2_device = MNH_ALLOCATE_ZT3D( ztmp2_device,JIU,JJU, JKU_TURB )
iztmp3_device = MNH_ALLOCATE_ZT3D( ztmp3_device,JIU,JJU, JKU_TURB )

WAUTELET Philippe
committed
#endif
!$acc data present( zcp, zexn, zt, zlocpexnm, zleps, ztrh, &
!$acc & zatheta, zamoist, zcoef_diss, zfrac_ice, &
!$acc & zmwth, zmwr, zmth2, zmr2, zmthr, &
!$acc & zfwth, zfwr, zfth2, zfr2, zfthr, zthlm, &
!$acc & zrm, &
!$acc & ztau11m, ztau12m, ztau22m, ztau33m, &
!$acc & zuslope, zvslope, zcdueff, zlmo, &
!$acc & zustar, zrvm, zsfrv, &
!$acc & ztt, zexne, zlv, zcph, zshear, zdudz, zdvdz, &
!$acc & ztmp1_device, ztmp2_device, ztmp3_device )
!------------------------------------------------------------------------------------------
!
!* 1.PRELIMINARIES
! -------------
!
!* 1.1 Set the internal domains, ZEXPL
!
!
IKTB=1+JPVEXT_TURB
IKTE=IKT-JPVEXT_TURB
IKB=KKA+JPVEXT_TURB*KKL
IKE=KKU-JPVEXT_TURB*KKL
!
ZEXPL = 1.- PIMPL
ZRVORD= XRV / XRD
!
GOCEAN = LOCEAN
!

WAUTELET Philippe
committed
!$acc update device(PTHLT,PRT)
!$acc kernels

WAUTELET Philippe
committed
!Copy data into ZTHLM and ZRM only if needed
IF (HTURBLEN=='BL89' .OR. HTURBLEN=='RM17' .OR. HTURBLEN == 'ADAP' .OR. ORMC01) THEN

WAUTELET Philippe
committed
ZTHLM(:,:,:) = PTHLT(:,:,:)
ZRM(:,:,:,:) = PRT(:,:,:,:)
END IF

WAUTELET Philippe
committed
ZTRH(:, :, : ) = XUNDEF
!
!----------------------------------------------------------------------------
!
!* 2. COMPUTE CONSERVATIVE VARIABLES AND RELATED QUANTITIES
! -----------------------------------------------------
!
!* 2.1 Cph at t
!

WAUTELET Philippe
committed
ZCP(:,:,:)=XCPD
IF (KRR > 0) ZCP(:,:,:) = ZCP(:,:,:) + XCPV * PRT(:,:,:,1)
! PGI20.5 BUG or reproductibility problem , with pointer this loop on JRR parallelize whitout reduction
!$acc loop seq
DO JRR = 2,1+KRRL ! loop on the liquid components
ZCP(:,:,:) = ZCP(:,:,:) + XCL * PRT(:,:,:,JRR)
!$acc loop seq
DO JRR = 2+KRRL,1+KRRL+KRRI ! loop on the solid components
ZCP(:,:,:) = ZCP(:,:,:) + XCI * PRT(:,:,:,JRR)
END DO
!
!* 2.2 Exner function at t
!
IF (GOCEAN) THEN

RODIER Quentin
committed
ZEXN(:,:,:) = 1.
ELSE

WAUTELET Philippe
committed
!PW: "BUG" PGI : results different on CPU and GPU due to the power function
!See http://www.pgroup.com/userforum/viewtopic.php?t=5364&sid=ec7b762b17fb9bb3332a47f0db57af55

WAUTELET Philippe
committed
!Use of own functions allows bit-reproducible results

WAUTELET Philippe
committed
#ifndef MNH_BITREP

RODIER Quentin
committed
ZEXN(:,:,:) = (PPABST(:,:,:)/XP00) ** (XRD/XCPD)

WAUTELET Philippe
committed
#else
ZEXN(:,:,:) = BR_POW(PPABST(:,:,:)/XP00,XRD/XCPD)

WAUTELET Philippe
committed
#endif

RODIER Quentin
committed
END IF
!
!* 2.3 dissipative heating coeff a t
!
ZCOEF_DISS(:,:,:) = 1/(ZCP(:,:,:) * ZEXN(:,:,:))
!
!
ZFRAC_ICE(:,:,:) = 0.0
ZATHETA(:,:,:) = 0.0
ZAMOIST(:,:,:) = 0.0

WAUTELET Philippe
committed
!$acc end kernels
!
IF (KRRL >=1) THEN
!
!* 2.4 Temperature at t
!

WAUTELET Philippe
committed
!$acc kernels

WAUTELET Philippe
committed
!$acc end kernels
!
!* 2.5 Lv/Cph/Exn
!
IF ( KRRI >= 1 ) THEN
ALLOCATE(ZLVOCPEXNM(JIU,JJU,JKU))
ALLOCATE(ZLSOCPEXNM(JIU,JJU,JKU))
ALLOCATE(ZAMOIST_ICE(JIU,JJU,JKU))
ALLOCATE(ZATHETA_ICE(JIU,JJU,JKU))
!$acc enter data create( zlvocpexnm, zlsocpexnm )
!$acc data create( zamoist_ice, zatheta_ice )
CALL COMPUTE_FUNCTION_THERMO(XALPW,XBETAW,XGAMW,XLVTT,XCL,ZT,ZEXN,ZCP, &
ZLVOCPEXNM,ZAMOIST,ZATHETA)
CALL COMPUTE_FUNCTION_THERMO(XALPI,XBETAI,XGAMI,XLSTT,XCI,ZT,ZEXN,ZCP, &
ZLSOCPEXNM,ZAMOIST_ICE,ZATHETA_ICE)
!

WAUTELET Philippe
committed
!$acc kernels
WHERE(PRT(:,:,:,2)+PRT(:,:,:,4)>0.0)
ZFRAC_ICE(:,:,:) = PRT(:,:,:,4) / ( PRT(:,:,:,2)+PRT(:,:,:,4) )
END WHERE
!
ZLOCPEXNM(:,:,:) = (1.0-ZFRAC_ICE(:,:,:))*ZLVOCPEXNM(:,:,:) &
+ZFRAC_ICE(:,:,:) *ZLSOCPEXNM(:,:,:)
ZAMOIST(:,:,:) = (1.0-ZFRAC_ICE(:,:,:))*ZAMOIST(:,:,:) &
+ZFRAC_ICE(:,:,:) *ZAMOIST_ICE(:,:,:)
ZATHETA(:,:,:) = (1.0-ZFRAC_ICE(:,:,:))*ZATHETA(:,:,:) &
+ZFRAC_ICE(:,:,:) *ZATHETA_ICE(:,:,:)

WAUTELET Philippe
committed
!$acc end kernels
!$acc end data
DEALLOCATE(ZAMOIST_ICE)
DEALLOCATE(ZATHETA_ICE)
ELSE
CALL COMPUTE_FUNCTION_THERMO(XALPW,XBETAW,XGAMW,XLVTT,XCL,ZT,ZEXN,ZCP, &
ZLOCPEXNM,ZAMOIST,ZATHETA)
END IF
!
!

WAUTELET Philippe
committed
IF ( tpfile%lopened .AND. OTURB_DIAG ) THEN

WAUTELET Philippe
committed
!$acc update self(ZAMOIST,ZATHETA)

WAUTELET Philippe
committed
TZFIELD%CMNHNAME = 'ATHETA'
TZFIELD%CSTDNAME = ''

WAUTELET Philippe
committed
TZFIELD%CLONGNAME = 'ATHETA'

WAUTELET Philippe
committed
TZFIELD%CUNITS = 'm'
TZFIELD%CDIR = 'XY'
TZFIELD%CCOMMENT = 'X_Y_Z_ATHETA'
TZFIELD%NGRID = 1
TZFIELD%NTYPE = TYPEREAL
TZFIELD%NDIMS = 3
TZFIELD%LTIMEDEP = .TRUE.

WAUTELET Philippe
committed
CALL IO_Field_write(TPFILE,TZFIELD,ZATHETA)

WAUTELET Philippe
committed
TZFIELD%CMNHNAME = 'AMOIST'
TZFIELD%CSTDNAME = ''

WAUTELET Philippe
committed
TZFIELD%CLONGNAME = 'AMOIST'

WAUTELET Philippe
committed
TZFIELD%CUNITS = 'm'
TZFIELD%CDIR = 'XY'
TZFIELD%CCOMMENT = 'X_Y_Z_AMOIST'
TZFIELD%NGRID = 1
TZFIELD%NTYPE = TYPEREAL
TZFIELD%NDIMS = 3
TZFIELD%LTIMEDEP = .TRUE.

WAUTELET Philippe
committed
CALL IO_Field_write(TPFILE,TZFIELD,ZAMOIST)

WAUTELET Philippe
committed
!$acc kernels

WAUTELET Philippe
committed
!$acc end kernels
END IF ! loop end on KRRL >= 1
!
! computes conservative variables
!

WAUTELET Philippe
committed
!$acc update device(PRRS,PRTHLS)

WAUTELET Philippe
committed
!$acc kernels

WAUTELET Philippe
committed
IF ( KRRI >= 1 ) THEN
! Rnp at t
PRT(:,:,:,1) = PRT(:,:,:,1) + PRT(:,:,:,2) + PRT(:,:,:,4)
PRRS(:,:,:,1) = PRRS(:,:,:,1) + PRRS(:,:,:,2) + PRRS(:,:,:,4)
! Theta_l at t
PTHLT(:,:,:) = PTHLT(:,:,:) - ZLVOCPEXNM(:,:,:) * PRT(:,:,:,2) &
- ZLSOCPEXNM(:,:,:) * PRT(:,:,:,4)
PRTHLS(:,:,:) = PRTHLS(:,:,:) - ZLVOCPEXNM(:,:,:) * PRRS(:,:,:,2) &
- ZLSOCPEXNM(:,:,:) * PRRS(:,:,:,4)
ELSE
! Rnp at t
PRT(:,:,:,1) = PRT(:,:,:,1) + PRT(:,:,:,2)
PRRS(:,:,:,1) = PRRS(:,:,:,1) + PRRS(:,:,:,2)
! Theta_l at t
PTHLT(:,:,:) = PTHLT(:,:,:) - ZLOCPEXNM(:,:,:) * PRT(:,:,:,2)
PRTHLS(:,:,:) = PRTHLS(:,:,:) - ZLOCPEXNM(:,:,:) * PRRS(:,:,:,2)
END IF

WAUTELET Philippe
committed
!$acc end kernels
END IF
!
!----------------------------------------------------------------------------
!
!* 3. MIXING LENGTH : SELECTION AND COMPUTATION
! -----------------------------------------
!
!
SELECT CASE (HTURBLEN)
!
!* 3.1 BL89 mixing length
! ------------------
CASE ('BL89')

WAUTELET Philippe
committed
ZSHEAR(:, :, : ) = 0.
CALL BL89(KKA,KKU,KKL,PZZ,PDZZ,PTHVREF,ZTHLM,KRR,ZRM,PTKET,ZSHEAR,PLEM)
!* 3.2 RM17 mixing length
! ------------------
CASE ('RM17')

WAUTELET Philippe
committed
#ifdef MNH_OPENACC
call Print_msg( NVERB_FATAL, 'GEN', 'TURB', 'OpenACC: HTURBLEN=RM17 not yet implemented' )

WAUTELET Philippe
committed
#endif

WAUTELET Philippe
committed
ZDUDZ = MXF(MZF(GZ_U_UW(PUT,PDZZ)))
ZDVDZ = MYF(MZF(GZ_V_VW(PVT,PDZZ)))
ZSHEAR = SQRT(ZDUDZ*ZDUDZ + ZDVDZ*ZDVDZ)
CALL BL89(KKA,KKU,KKL,PZZ,PDZZ,PTHVREF,ZTHLM,KRR,ZRM,PTKET,ZSHEAR,PLEM)
!

RODIER Quentin
committed
!* 3.3 Grey-zone combined RM17 & Deardorff mixing lengths
! --------------------------------------------------
CASE ('ADAP')
#ifdef MNH_OPENACC
call Print_msg( NVERB_FATAL, 'GEN', 'TURB', 'OpenACC: HTURBLEN=ADAP not yet implemented' )
#endif

RODIER Quentin
committed
ZDUDZ = MXF(MZF(GZ_U_UW(PUT,PDZZ)))
ZDVDZ = MYF(MZF(GZ_V_VW(PVT,PDZZ)))
ZSHEAR = SQRT(ZDUDZ*ZDUDZ + ZDVDZ*ZDVDZ)
CALL BL89(KKA,KKU,KKL,PZZ,PDZZ,PTHVREF,ZTHLM,KRR,ZRM,PTKET,ZSHEAR,PLEM)
CALL DELT(KKA,KKU,KKL,IKB, IKE,IKTB, IKTE,ORMC01,HTURBDIM,PDXX, PDYY,PZZ,PDIRCOSZW,ZLMW,ODZ=.FALSE.)

RODIER Quentin
committed
! The minimum mixing length is chosen between Horizontal grid mesh (not taking into account the vertical grid mesh) and RM17.
! For large horizontal grid meshes, this is equal to RM17
! For LES grid meshes, this is equivalent to Deardorff : the base mixing lentgh is the horizontal grid mesh,
! and it is limited by a stability-based length (RM17), as was done in Deardorff length (but taking into account shear as well)
! For grid meshes in the grey zone, then this is the smaller of the two.

RODIER Quentin
committed
PLEM = MIN(PLEM,XCADAP*ZLMW)

RODIER Quentin
committed
!
!* 3.4 Delta mixing length
! -------------------
!
CASE ('DELT')
CALL DELT(KKA,KKU,KKL,IKB, IKE,IKTB, IKTE,ORMC01,HTURBDIM,PDXX, PDYY,PZZ,PDIRCOSZW,PLEM,ODZ=.TRUE.)

RODIER Quentin
committed
!* 3.5 Deardorff mixing length
! -----------------------
!
CASE ('DEAR')

WAUTELET Philippe
committed
CALL DEAR(KKA,KKU,KKL,KRR, KRRI, IKB, IKE,IKTB, IKTE, &
ORMC01,HTURBDIM,PDXX, PDYY, PDZZ,PZZ,PDIRCOSZW,PTHLT,PTHVREF,PTKET,PSRCT,PRT,&
ZLOCPEXNM,ZATHETA, ZAMOIST, PLEM)

RODIER Quentin
committed
!* 3.6 Blackadar mixing length
! -----------------------
!
CASE ('BLKR')

WAUTELET Philippe
committed
#ifdef MNH_OPENACC
call Print_msg( NVERB_FATAL, 'GEN', 'TURB', 'OpenACC: HTURBLEN=BLKR not yet implemented' )

WAUTELET Philippe
committed
#endif
PLEM(:,:,:) = ZL0
ZALPHA=0.5**(-1.5)
!
DO JK=IKTB,IKTE
PLEM(:,:,JK) = ( 0.5*(PZZ(:,:,JK)+PZZ(:,:,JK+KKL)) - &
& PZZ(:,:,KKA+JPVEXT_TURB*KKL) ) * PDIRCOSZW(:,:)
PLEM(:,:,JK) = ZALPHA * PLEM(:,:,JK) * ZL0 / ( ZL0 + ZALPHA*PLEM(:,:,JK) )
PLEM(:,:,IKTB-1) = PLEM(:,:,IKTB)
PLEM(:,:,IKTE+1) = PLEM(:,:,IKTE)
!
!
!
END SELECT
!
!
!
!* 3.5 Mixing length modification for cloud
! -----------------------

WAUTELET Philippe
committed
IF (KMODEL_CL==KMI .AND. HTURBLEN_CL/='NONE') THEN

WAUTELET Philippe
committed
#ifdef MNH_OPENACC
call Print_msg( NVERB_FATAL, 'GEN', 'TURB', 'OpenACC: CLOUD_MODIF_LM not yet implemented' )

WAUTELET Philippe
committed
#endif
CALL CLOUD_MODIF_LM
END IF
!
!* 3.6 Dissipative length
! ------------------
!

WAUTELET Philippe
committed
!$acc kernels
ZLEPS(:,:,:)=PLEM(:,:,:)
!
!* 3.7 Correction in the Surface Boundary Layer (Redelsperger 2001)
! ----------------------------------------
!
ZLMO=XUNDEF

WAUTELET Philippe
committed
!$acc end kernels
!$acc update self(PLEM,ZLEPS)

WAUTELET Philippe
committed
#ifdef MNH_OPENACC
call Print_msg( NVERB_FATAL, 'GEN', 'TURB', 'OpenACC: ORMC01 not yet implemented' )

WAUTELET Philippe
committed
#endif

WAUTELET Philippe
committed
#ifndef MNH_BITREP

Wautelet Philippe
committed
ZUSTAR(:,:) = (PSFU(:,:)**2+PSFV(:,:)**2)**(0.25)