source: LMDZ6/branches/Amaury_dev/libf/dyn3d/advtrac.f90 @ 5123

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

enforce PRIVATE by default in several modules, expose PUBLIC as needed
move eigen.f90 to obsolete/
(lint) aslong the way

  • 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.9 KB
RevLine 
[1279]1! $Id: advtrac.f90 5119 2024-07-24 16:46:45Z abarral $
[1146]2
[5101]3SUBROUTINE advtrac(pbaru, pbarv, p, masse, q, iapptrac, teta, flxw, pk)
4  !     Auteur :  F. Hourdin
[5099]5
[5101]6  !     Modif. P. Le Van     (20/12/97)
7  !            F. Codron     (10/99)
8  !            D. Le Croller (07/2001)
9  !            M.A Filiberti (04/2002)
[5099]10
[5101]11  USE infotrac, ONLY: nqtot, tracers, isoCheck
12  USE control_mod, ONLY: iapp_tracvl, day_step
13  USE comconst_mod, ONLY: dtvr
14  USE lmdz_cppkeys_wrapper, ONLY: CPPKEY_DEBUGIO
[5117]15  USE lmdz_strings, ONLY: int2str
[5114]16  USE lmdz_description, ONLY: descript
[5116]17  USE lmdz_libmath, ONLY: minmax
[5118]18  USE lmdz_iniprint, ONLY: lunout, prt_level
[5119]19  USE lmdz_ssum_scopy, ONLY: scopy
[524]20
[5101]21  IMPLICIT NONE
[5099]22
[5101]23  include "dimensions.h"
24  include "paramet.h"
25  include "comdissip.h"
26  include "comgeom2.h"
[524]27
[5101]28  !---------------------------------------------------------------------------
29  !     Arguments
30  !---------------------------------------------------------------------------
31  INTEGER, INTENT(OUT) :: iapptrac
32  REAL, INTENT(IN) :: pbaru(ip1jmp1, llm)
33  REAL, INTENT(IN) :: pbarv(ip1jm, llm)
34  REAL, INTENT(INOUT) :: q(ip1jmp1, llm, nqtot)
35  REAL, INTENT(IN) :: masse(ip1jmp1, llm)
36  REAL, INTENT(IN) :: p(ip1jmp1, llmp1)
37  REAL, INTENT(IN) :: teta(ip1jmp1, llm)
38  REAL, INTENT(IN) :: pk(ip1jmp1, llm)
39  REAL, INTENT(OUT) :: flxw(ip1jmp1, llm)
40  !---------------------------------------------------------------------------
41  !     Ajout PPM
42  !---------------------------------------------------------------------------
43  REAL :: massebx(ip1jmp1, llm), masseby(ip1jm, llm)
44  !---------------------------------------------------------------------------
45  !     Variables locales
46  !---------------------------------------------------------------------------
47  INTEGER :: ij, l, iq, iadv
48  !   REAL(KIND=KIND(1.d0)) :: t_initial, t_final, tps_cpu
49  REAL :: zdp(ip1jmp1), zdpmin, zdpmax
50  INTEGER, SAVE :: iadvtr = 0
51  REAL, DIMENSION(ip1jmp1, llm) :: pbaruc, pbarug, massem, wg
52  REAL, DIMENSION(ip1jm, llm) :: pbarvc, pbarvg
53  SAVE massem, pbaruc, pbarvc
54  !---------------------------------------------------------------------------
55  !     Rajouts pour PPM
56  !---------------------------------------------------------------------------
57  INTEGER indice, n
58  REAL :: dtbon                       ! Pas de temps adaptatif pour que CFL<1
59  REAL :: CFLmaxz, aaa, bbb           ! CFL maximum
60  REAL, DIMENSION(iim, jjp1, llm) :: unatppm, vnatppm, fluxwppm
61  REAL :: qppm(iim * jjp1, llm, nqtot)
62  REAL :: psppm(iim, jjp1)           ! pression  au sol
63  REAL, DIMENSION(llmp1) :: apppm, bpppm
64  LOGICAL, SAVE :: dum = .TRUE., fill = .TRUE.
[524]65
[5101]66  INTEGER, SAVE :: countcfl = 0
67  REAL, DIMENSION(ip1jmp1, llm) :: cflx, cflz
68  REAL, DIMENSION(ip1jm, llm) :: cfly
69  REAL, DIMENSION(llm), SAVE :: cflxmax, cflymax, cflzmax
[524]70
[5101]71  IF(iadvtr == 0) THEN
72    pbaruc(:, :) = 0
73    pbarvc(:, :) = 0
74  END IF
[524]75
[5101]76  !--- Accumulation des flux de masse horizontaux
77  DO l = 1, llm
78    DO ij = 1, ip1jmp1
79      pbaruc(ij, l) = pbaruc(ij, l) + pbaru(ij, l)
80    END DO
81    DO ij = 1, ip1jm
82      pbarvc(ij, l) = pbarvc(ij, l) + pbarv(ij, l)
83    END DO
84  END DO
[524]85
[5101]86  !--- Selection de la masse instantannee des mailles avant le transport.
87  IF(iadvtr == 0) THEN
88    CALL SCOPY(ip1jmp1 * llm, masse, 1, massem, 1)
89    ! CALL filtreg ( massem ,jjp1, llm,-2, 2, .TRUE., 1 )
90  END IF
[524]91
[5101]92  iadvtr = iadvtr + 1
93  iapptrac = iadvtr
[524]94
[5101]95  !--- Test pour savoir si on advecte a ce pas de temps
96  IF(iadvtr /= iapp_tracvl) RETURN
[524]97
[5101]98  !   ..  Modif P.Le Van  ( 20/12/97 )  ....
[5099]99
[5101]100  !   traitement des flux de masse avant advection.
101  !       1. calcul de w
102  !       2. groupement des mailles pres du pole.
[524]103
[5101]104  CALL groupe(massem, pbaruc, pbarvc, pbarug, pbarvg, wg)
[524]105
[5101]106  !--- Flux de masse diaganostiques traceurs
107  flxw = wg / REAL(iapp_tracvl)
[524]108
[5101]109  !--- Test sur l'eventuelle creation de valeurs negatives de la masse
110  DO l = 1, llm - 1
111    DO ij = iip2 + 1, ip1jm
112      zdp(ij) = pbarug(ij - 1, l) - pbarug(ij, l) &
113              - pbarvg(ij - iip1, l) + pbarvg(ij, l) &
114              + wg(ij, l + 1) - wg(ij, l)
115    END DO
116    ! ym  ---> pourquoi jjm-1 et non jjm ? a cause du pole ?
117    CALL SCOPY(jjm - 1, zdp(iip1 + iip1), iip1, zdp(iip2), iip1)
118    DO ij = iip2, ip1jm
119      zdp(ij) = zdp(ij) * dtvr / massem(ij, l)
120    END DO
[524]121
[5101]122    CALL minmax (ip1jm - iip1, zdp(iip2), zdpmin, zdpmax)
[524]123
[5101]124    IF(MAX(ABS(zdpmin), ABS(zdpmax)) > 0.5) &
125            WRITE(*, *)'WARNING DP/P l=', l, '  MIN:', zdpmin, ' MAX:', zdpmax
[524]126
[5101]127  END DO
[524]128
[5101]129  !-------------------------------------------------------------------------
130  ! Calcul des criteres CFL en X, Y et Z
131  !-------------------------------------------------------------------------
[5116]132  IF(countcfl == 0.) THEN
[5101]133    cflxmax(:) = 0.
134    cflymax(:) = 0.
135    cflzmax(:) = 0.
136  END IF
[524]137
[5101]138  countcfl = countcfl + iapp_tracvl
139  cflx(:, :) = 0.
140  cfly(:, :) = 0.
141  cflz(:, :) = 0.
142  DO l = 1, llm
143    DO ij = iip2, ip1jm - 1
[5116]144      IF(pbarug(ij, l)>=0.) THEN
[5101]145        cflx(ij, l) = pbarug(ij, l) * dtvr / masse(ij, l)
146      ELSE
147        cflx(ij, l) = -pbarug(ij, l) * dtvr / masse(ij + 1, l)
148      END IF
149    END DO
150  END DO
[1279]151
[5101]152  DO l = 1, llm
153    DO ij = iip2, ip1jm - 1, iip1
154      cflx(ij + iip1, l) = cflx(ij, l)
155    END DO
156  END DO
[1279]157
[5101]158  DO l = 1, llm
159    DO ij = 1, ip1jm
[5116]160      IF(pbarvg(ij, l)>=0.) THEN
[5101]161        cfly(ij, l) = pbarvg(ij, l) * dtvr / masse(ij, l)
162      ELSE
163        cfly(ij, l) = -pbarvg(ij, l) * dtvr / masse(ij + iip1, l)
164      END IF
165    END DO
166  END DO
[1279]167
[5101]168  DO l = 2, llm
169    DO ij = 1, ip1jm
170      IF(wg(ij, l) >= 0.) THEN
171        cflz(ij, l) = wg(ij, l) * dtvr / masse(ij, l)
172      ELSE
173        cflz(ij, l) = -wg(ij, l) * dtvr / masse(ij, l - 1)
174      END IF
175    END DO
176  END DO
[1279]177
[5101]178  DO l = 1, llm
179    cflxmax(l) = max(cflxmax(l), maxval(cflx(:, l)))
180    cflymax(l) = max(cflymax(l), maxval(cfly(:, l)))
181    cflzmax(l) = max(cflzmax(l), maxval(cflz(:, l)))
182  END DO
[1279]183
[5101]184  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
185  ! Par defaut, on sort le diagnostic des CFL tous les jours.
186  ! Si on veut le sortir a chaque pas d'advection en cas de plantage
[5116]187  !       IF(countcfl==iapp_tracvl) THEN
[5101]188  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
[5116]189  IF(countcfl==day_step) THEN
[5101]190    DO l = 1, llm
191      WRITE(lunout, *) 'L, CFL[xyz]max:', l, cflxmax(l), cflymax(l), cflzmax(l)
192    END DO
193    countcfl = 0
194  END IF
[1279]195
[5101]196  !---------------------------------------------------------------------------
197  !   Advection proprement dite (Modification Le Croller (07/2001)
198  !---------------------------------------------------------------------------
[1279]199
[5101]200  !---------------------------------------------------------------------------
201  !   Calcul des moyennes basees sur la masse
202  !---------------------------------------------------------------------------
203  CALL massbar(massem, massebx, masseby)
[1549]204
[5101]205  IF (CPPKEY_DEBUGIO) THEN
206    CALL WriteField_u('massem', massem)
207    CALL WriteField_u('wg', wg)
208    CALL WriteField_u('pbarug', pbarug)
209    CALL WriteField_v('pbarvg', pbarvg)
210    CALL WriteField_u('p_tmp', p)
211    CALL WriteField_u('pk_tmp', pk)
212    CALL WriteField_u('teta_tmp', teta)
213    DO iq = 1, nqtot
214      CALL WriteField_u('q_adv' // trim(int2str(iq)), q(:, :, iq))
215    END DO
216  END IF
[1549]217
[5101]218  IF(isoCheck) WRITE(*, *) 'advtrac 227'
219  CALL check_isotopes_seq(q, ip1jmp1, 'advtrac 162')
[524]220
[5101]221  !-------------------------------------------------------------------------
222  !       Appel des sous programmes d'advection
223  !-------------------------------------------------------------------------
224  DO iq = 1, nqtot
225    !     CALL clock(t_initial)
226    IF(tracers(iq)%parent /= 'air') CYCLE
227    iadv = tracers(iq)%iadv
228    !-----------------------------------------------------------------------
229    SELECT CASE(iadv)
[4056]230      !-----------------------------------------------------------------------
[5101]231    CASE(0); CYCLE
232    !--------------------------------------------------------------------
233    CASE(10)  !--- Schema de Van Leer I MUSCL
234      !--------------------------------------------------------------------
235      !           WRITE(*,*) 'advtrac 239: iq,q(1721,19,:)=',iq,q(1721,19,:)
236      CALL vlsplt(q, 2., massem, wg, pbarug, pbarvg, dtvr, iq)
[524]237
[5101]238      !--------------------------------------------------------------------
239    CASE(14)  !--- Schema "pseuDO amont" + test sur humidite specifique
240      !--- pour la vapeur d'eau. F. Codron
241      !--------------------------------------------------------------------
242      !           WRITE(*,*) 'advtrac 248: iq,q(1721,19,:)=',iq,q(1721,19,:)
243      CALL vlspltqs(q, 2., massem, wg, pbarug, pbarvg, dtvr, p, pk, teta, iq)
[960]244
[5101]245      !--------------------------------------------------------------------
246    CASE(12)  !--- Schema de Frederic Hourdin
247      !--------------------------------------------------------------------
248      CALL adaptdt(iadv, dtbon, n, pbarug, massem)   ! pas de temps adaptatif
249      IF(n > 1) WRITE(*, *) 'WARNING horizontal dt=', dtbon, 'dtvr=', dtvr, 'n=', n
250      DO indice = 1, n
251        CALL advn(q(1, 1, iq), massem, wg, pbarug, pbarvg, dtbon, 1)
252      END DO
[524]253
[5101]254      !--------------------------------------------------------------------
255    CASE(13)  !--- Pas de temps adaptatif
256      !--------------------------------------------------------------------
257      CALL adaptdt(iadv, dtbon, n, pbarug, massem)
258      IF(n > 1) WRITE(*, *) 'WARNING horizontal dt=', dtbon, 'dtvr=', dtvr, 'n=', n
259      DO indice = 1, n
260        CALL advn(q(1, 1, iq), massem, wg, pbarug, pbarvg, dtbon, 2)
261      END DO
[524]262
[5101]263      !--------------------------------------------------------------------
264    CASE(20)  !--- Schema de pente SLOPES
265      !--------------------------------------------------------------------
266      CALL pentes_ini (q(1, 1, iq), wg, massem, pbarug, pbarvg, 0)
[524]267
[5101]268      !--------------------------------------------------------------------
269    CASE(30)  !--- Schema de Prather
270      !--------------------------------------------------------------------
271      ! Pas de temps adaptatif
272      CALL adaptdt(iadv, dtbon, n, pbarug, massem)
273      IF(n > 1) WRITE(*, *) 'WARNING horizontal dt=', dtbon, 'dtvr=', dtvr, 'n=', n
274      CALL prather(q(1, 1, iq), wg, massem, pbarug, pbarvg, n, dtbon)
[524]275
[5101]276      !--------------------------------------------------------------------
277    CASE(11, 16, 17, 18)   !--- Schemas PPM Lin et Rood
278      !--------------------------------------------------------------------
279      ! Test sur le flux horizontal
280      CALL adaptdt(iadv, dtbon, n, pbarug, massem)   ! pas de temps adaptatif
281      IF(n > 1) WRITE(*, *) 'WARNING horizontal dt=', dtbon, 'dtvr=', dtvr, 'n=', n
282      ! Test sur le flux vertical
283      CFLmaxz = 0.
284      DO l = 2, llm
285        DO ij = iip2, ip1jm
286          aaa = wg(ij, l) * dtvr / massem(ij, l)
287          CFLmaxz = max(CFLmaxz, aaa)
288          bbb = -wg(ij, l) * dtvr / massem(ij, l - 1)
289          CFLmaxz = max(CFLmaxz, bbb)
290        END DO
291      END DO
292      IF(CFLmaxz>=1) WRITE(*, *) 'WARNING vertical', 'CFLmaxz=', CFLmaxz
293      !----------------------------------------------------------------
294      !     Ss-prg interface LMDZ.4->PPM3d (ss-prg de Lin)
295      !----------------------------------------------------------------
296      CALL interpre(q(1, 1, iq), qppm(1, 1, iq), wg, fluxwppm, massem, &
297              apppm, bpppm, massebx, masseby, pbarug, pbarvg, &
298              unatppm, vnatppm, psppm)
[524]299
[5101]300      !----------------------------------------------------------------
301      DO indice = 1, n     !--- VL (version PPM) horiz. et PPM vert.
302        !----------------------------------------------------------------
303        SELECT CASE(iadv)
304          !----------------------------------------------------------
305        CASE(11)
306          !----------------------------------------------------------
307          CALL ppm3d(1, qppm(1, 1, iq), psppm, psppm, unatppm, vnatppm, fluxwppm, dtbon, &
308                  2, 2, 2, 1, iim, jjp1, 2, llm, apppm, bpppm, 0.01, 6400000, fill, dum, 220.)
309          !----------------------------------------------------------
310        CASE(16) !--- Monotonic PPM
311          !----------------------------------------------------------
312          CALL ppm3d(1, qppm(1, 1, iq), psppm, psppm, unatppm, vnatppm, fluxwppm, dtbon, &
313                  3, 3, 3, 1, iim, jjp1, 2, llm, apppm, bpppm, 0.01, 6400000, fill, dum, 220.)
314          !----------------------------------------------------------
315        CASE(17) !--- Semi monotonic PPM
316          !----------------------------------------------------------
317          CALL ppm3d(1, qppm(1, 1, iq), psppm, psppm, unatppm, vnatppm, fluxwppm, dtbon, &
318                  4, 4, 4, 1, iim, jjp1, 2, llm, apppm, bpppm, 0.01, 6400000, fill, dum, 220.)
319          !----------------------------------------------------------
320        CASE(18) !--- Positive Definite PPM
321          !----------------------------------------------------------
322          CALL ppm3d(1, qppm(1, 1, iq), psppm, psppm, unatppm, vnatppm, fluxwppm, dtbon, &
323                  5, 5, 5, 1, iim, jjp1, 2, llm, apppm, bpppm, 0.01, 6400000, fill, dum, 220.)
324        END SELECT
325        !----------------------------------------------------------------
326      END DO
327      !----------------------------------------------------------------
328      !     Ss-prg interface PPM3d-LMDZ.4
329      !----------------------------------------------------------------
330      CALL interpost(q(1, 1, iq), qppm(1, 1, iq))
[4056]331      !----------------------------------------------------------------------
[5101]332    END SELECT
333    !----------------------------------------------------------------------
[524]334
[5101]335    !----------------------------------------------------------------------
336    ! On impose une seule valeur du traceur au pole Sud j=jjm+1=jjp1 et Nord j=1
337    !----------------------------------------------------------------------
338    !  CALL traceurpole(q(1,1,iq),massem)
[524]339
[5101]340    !--- Calcul du temps cpu pour un schema donne
341    !  CALL clock(t_final)
342    !ym  tps_cpu=t_final-t_initial
343    !ym  cpuadv(iq)=cpuadv(iq)+tps_cpu
[524]344
[5101]345  END DO
[524]346
[5101]347  IF(isoCheck) WRITE(*, *) 'advtrac 402'
348  CALL check_isotopes_seq(q, ip1jmp1, 'advtrac 397')
[524]349
[5101]350  !-------------------------------------------------------------------------
351  !   on reinitialise a zero les flux de masse cumules
352  !-------------------------------------------------------------------------
353  iadvtr = 0
[524]354
[1549]355END SUBROUTINE advtrac
Note: See TracBrowser for help on using the repository browser.