source: LMDZ5/trunk/libf/dyn3dpar/gcm.F @ 2600

Last change on this file since 2600 was 2600, checked in by Ehouarn Millour, 8 years ago

Cleanup in the dynamics: turn comvert.h into module comvert_mod.F90
EM

  • 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: 15.4 KB
Line 
1!
2! $Id: gcm.F 2600 2016-07-23 05:45:38Z emillour $
3!
4c
5c
6      PROGRAM gcm
7
8#ifdef CPP_IOIPSL
9      USE IOIPSL
10#endif
11
12
13      USE mod_const_mpi, ONLY: init_const_mpi
14      USE parallel_lmdz
15      USE infotrac
16!#ifdef CPP_PHYS
17!      USE mod_interface_dyn_phys, ONLY: init_interface_dyn_phys
18!#endif
19      USE mod_hallo
20      USE Bands
21      USE getparam
22      USE filtreg_mod
23      USE control_mod
24
25#ifdef INCA
26! Only INCA needs these informations (from the Earth's physics)
27      USE indice_sol_mod
28      USE mod_phys_lmdz_omp_data, ONLY: klon_omp
29#endif
30
31#ifdef CPP_PHYS
32      USE iniphysiq_mod, ONLY: iniphysiq
33#endif
34      USE comconst_mod, ONLY: cpp, daysec, dtphys, dtvr, g, r, rad
35
36      IMPLICIT NONE
37
38c      ......   Version  du 10/01/98    ..........
39
40c             avec  coordonnees  verticales hybrides
41c   avec nouveaux operat. dissipation * ( gradiv2,divgrad2,nxgraro2 )
42
43c=======================================================================
44c
45c   Auteur:  P. Le Van /L. Fairhead/F.Hourdin
46c   -------
47c
48c   Objet:
49c   ------
50c
51c   GCM LMD nouvelle grille
52c
53c=======================================================================
54c
55c  ... Dans inigeom , nouveaux calculs pour les elongations  cu , cv
56c      et possibilite d'appeler une fonction f(y)  a derivee tangente
57c      hyperbolique a la  place de la fonction a derivee sinusoidale.
58c  ... Possibilite de choisir le schema pour l'advection de
59c        q  , en modifiant iadv dans traceur.def  (MAF,10/02) .
60c
61c      Pour Van-Leer + Vapeur d'eau saturee, iadv(1)=4. (F.Codron,10/99)
62c      Pour Van-Leer iadv=10
63c
64c-----------------------------------------------------------------------
65c   Declarations:
66c   -------------
67#include "dimensions.h"
68#include "paramet.h"
69#include "comdissnew.h"
70#include "comgeom.h"
71#include "logic.h"
72#include "temps.h"
73#include "ener.h"
74#include "description.h"
75!#include "com_io_dyn.h"
76#include "iniprint.h"
77#include "tracstoke.h"
78
79#ifdef INCA
80! Only INCA needs these informations (from the Earth's physics)
81!#include "indicesol.h"
82#endif
83
84      REAL zdtvr
85
86c   variables dynamiques
87      REAL vcov(ip1jm,llm),ucov(ip1jmp1,llm) ! vents covariants
88      REAL teta(ip1jmp1,llm)                 ! temperature potentielle
89      REAL, ALLOCATABLE, DIMENSION(:,:,:) :: q ! champs advectes
90      REAL ps(ip1jmp1)                       ! pression  au sol
91c      REAL p (ip1jmp1,llmp1  )               ! pression aux interfac.des couches
92      REAL masse(ip1jmp1,llm)                ! masse d'air
93      REAL phis(ip1jmp1)                     ! geopotentiel au sol
94c      REAL phi(ip1jmp1,llm)                  ! geopotentiel
95c      REAL w(ip1jmp1,llm)                    ! vitesse verticale
96
97c variables dynamiques intermediaire pour le transport
98
99c   variables pour le fichier histoire
100      REAL dtav      ! intervalle de temps elementaire
101
102      REAL time_0
103
104      LOGICAL lafin
105
106      real time_step, t_wrt, t_ops
107
108
109c+jld variables test conservation energie
110c      REAL ecin(ip1jmp1,llm),ecin0(ip1jmp1,llm)
111C     Tendance de la temp. potentiel d (theta)/ d t due a la
112C     tansformation d'energie cinetique en energie thermique
113C     cree par la dissipation
114c      REAL dhecdt(ip1jmp1,llm)
115c      REAL vcont(ip1jm,llm),ucont(ip1jmp1,llm)
116c      REAL      d_h_vcol, d_qt, d_qw, d_ql, d_ec
117c      CHARACTER (len=15) :: ztit
118c-jld
119
120
121      character (len=80) :: dynhist_file, dynhistave_file
122      character (len=20) :: modname
123      character (len=80) :: abort_message
124! locales pour gestion du temps
125      INTEGER :: an, mois, jour
126      REAL :: heure
127
128
129c-----------------------------------------------------------------------
130c   Initialisations:
131c   ----------------
132
133      abort_message = 'last timestep reached'
134      modname = 'gcm'
135      descript = 'Run GCM LMDZ'
136      lafin    = .FALSE.
137      dynhist_file = 'dyn_hist'
138      dynhistave_file = 'dyn_hist_ave'
139
140
141
142c----------------------------------------------------------------------
143c  lecture des fichiers gcm.def ou run.def
144c  ---------------------------------------
145c
146      CALL conf_gcm( 99, .TRUE. )
147      if (mod(iphysiq, iperiod) /= 0) call abort_gcm("conf_gcm",
148     s "iphysiq must be a multiple of iperiod", 1)
149c
150c
151c------------------------------------
152c   Initialisation partie parallele
153c------------------------------------
154
155      CALL init_const_mpi
156      call init_parallel
157      call ini_getparam("out.def")
158      call Read_Distrib
159
160!#ifdef CPP_PHYS
161!        CALL Init_Phys_lmdz(iim,jjp1,llm,mpi_size,distrib_phys)
162!#endif
163!      CALL set_bands
164!#ifdef CPP_PHYS
165!      CALL Init_interface_dyn_phys
166!#endif
167      CALL barrier
168
169      CALL set_bands
170      if (mpi_rank==0) call WriteBands
171      call SetDistrib(jj_Nb_Caldyn)
172
173c$OMP PARALLEL
174      call Init_Mod_hallo
175c$OMP END PARALLEL
176
177!#ifdef CPP_PHYS
178!c$OMP PARALLEL
179!      call InitComgeomphy ! now done in iniphysiq
180!c$OMP END PARALLEL
181!#endif
182
183!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
184! Initialisation de XIOS
185!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
186
187
188c-----------------------------------------------------------------------
189c   Choix du calendrier
190c   -------------------
191
192c      calend = 'earth_365d'
193
194#ifdef CPP_IOIPSL
195      if (calend == 'earth_360d') then
196        call ioconf_calendar('360d')
197        write(lunout,*)'CALENDRIER CHOISI: Terrestre a 360 jours/an'
198      else if (calend == 'earth_365d') then
199        call ioconf_calendar('noleap')
200        write(lunout,*)'CALENDRIER CHOISI: Terrestre a 365 jours/an'
201      else if (calend == 'earth_366d') then
202        call ioconf_calendar('gregorian')
203        write(lunout,*)'CALENDRIER CHOISI: Terrestre bissextile'
204      else
205        abort_message = 'Mauvais choix de calendrier'
206        call abort_gcm(modname,abort_message,1)
207      endif
208#endif
209
210      IF (type_trac == 'inca') THEN
211#ifdef INCA
212         call init_const_lmdz(
213     $        nbtr,anneeref,dayref,
214     $        iphysiq,day_step,nday,
215     $        nbsrf, is_oce,is_sic,
216     $        is_ter,is_lic, calend)
217
218         call init_inca_para(
219     $        iim,jjm+1,llm,klon_glo,mpi_size,
220     $        distrib_phys,COMM_LMDZ)
221#endif
222      END IF
223
224c-----------------------------------------------------------------------
225c   Initialisation des traceurs
226c   ---------------------------
227c  Choix du nombre de traceurs et du schema pour l'advection
228c  dans fichier traceur.def, par default ou via INCA
229      call infotrac_init
230
231c Allocation de la tableau q : champs advectes   
232      ALLOCATE(q(ip1jmp1,llm,nqtot))
233
234c-----------------------------------------------------------------------
235c   Lecture de l'etat initial :
236c   ---------------------------
237
238c  lecture du fichier start.nc
239      if (read_start) then
240      ! we still need to run iniacademic to initialize some
241      ! constants & fields, if we run the 'newtonian' or 'SW' cases:
242        if (iflag_phys.ne.1) then
243          CALL iniacademic(vcov,ucov,teta,q,masse,ps,phis,time_0)
244        endif
245
246!        if (planet_type.eq."earth") then
247! Load an Earth-format start file
248         CALL dynetat0("start.nc",vcov,ucov,
249     &              teta,q,masse,ps,phis, time_0)
250!        endif ! of if (planet_type.eq."earth")
251
252c       write(73,*) 'ucov',ucov
253c       write(74,*) 'vcov',vcov
254c       write(75,*) 'teta',teta
255c       write(76,*) 'ps',ps
256c       write(77,*) 'q',q
257
258      endif ! of if (read_start)
259
260c le cas echeant, creation d un etat initial
261      IF (prt_level > 9) WRITE(lunout,*)
262     .              'GCM: AVANT iniacademic AVANT AVANT AVANT AVANT'
263      if (.not.read_start) then
264         CALL iniacademic(vcov,ucov,teta,q,masse,ps,phis,time_0)
265      endif
266
267c-----------------------------------------------------------------------
268c   Lecture des parametres de controle pour la simulation :
269c   -------------------------------------------------------
270c  on recalcule eventuellement le pas de temps
271
272      IF(MOD(day_step,iperiod).NE.0) THEN
273        abort_message =
274     .  'Il faut choisir un nb de pas par jour multiple de iperiod'
275        call abort_gcm(modname,abort_message,1)
276      ENDIF
277
278      IF(MOD(day_step,iphysiq).NE.0) THEN
279        abort_message =
280     * 'Il faut choisir un nb de pas par jour multiple de iphysiq'
281        call abort_gcm(modname,abort_message,1)
282      ENDIF
283
284      zdtvr    = daysec/REAL(day_step)
285        IF(dtvr.NE.zdtvr) THEN
286         WRITE(lunout,*)
287     .    'WARNING!!! changement de pas de temps',dtvr,'>',zdtvr
288        ENDIF
289
290C
291C on remet le calendrier à zero si demande
292c
293      IF (start_time /= starttime) then
294        WRITE(lunout,*)' GCM: Attention l''heure de depart lue dans le'
295     &,' fichier restart ne correspond pas à celle lue dans le run.def'
296        IF (raz_date == 1) then
297          WRITE(lunout,*)'Je prends l''heure lue dans run.def'
298          start_time = starttime
299        ELSE
300          call abort_gcm("gcm", "'Je m''arrete'", 1)
301        ENDIF
302      ENDIF
303      IF (raz_date == 1) THEN
304        annee_ref = anneeref
305        day_ref = dayref
306        day_ini = dayref
307        itau_dyn = 0
308        itau_phy = 0
309        time_0 = 0.
310        write(lunout,*)
311     .   'GCM: On reinitialise a la date lue dans gcm.def'
312      ELSE IF (annee_ref .ne. anneeref .or. day_ref .ne. dayref) THEN
313        write(lunout,*)
314     .  'GCM: Attention les dates initiales lues dans le fichier'
315        write(lunout,*)
316     .  ' restart ne correspondent pas a celles lues dans '
317        write(lunout,*)' gcm.def'
318        write(lunout,*)' annee_ref=',annee_ref," anneeref=",anneeref
319        write(lunout,*)' day_ref=',day_ref," dayref=",dayref
320        write(lunout,*)' Pas de remise a zero'
321      ENDIF
322c      if (annee_ref .ne. anneeref .or. day_ref .ne. dayref) then
323c        write(lunout,*)
324c     .  'GCM: Attention les dates initiales lues dans le fichier'
325c        write(lunout,*)
326c     .  ' restart ne correspondent pas a celles lues dans '
327c        write(lunout,*)' gcm.def'
328c        write(lunout,*)' annee_ref=',annee_ref," anneeref=",anneeref
329c        write(lunout,*)' day_ref=',day_ref," dayref=",dayref
330c        if (raz_date .ne. 1) then
331c          write(lunout,*)
332c     .    'GCM: On garde les dates du fichier restart'
333c        else
334c          annee_ref = anneeref
335c          day_ref = dayref
336c          day_ini = dayref
337c          itau_dyn = 0
338c          itau_phy = 0
339c          time_0 = 0.
340c          write(lunout,*)
341c     .   'GCM: On reinitialise a la date lue dans gcm.def'
342c        endif
343c      ELSE
344c        raz_date = 0
345c      endif
346
347#ifdef CPP_IOIPSL
348      mois = 1
349      heure = 0.
350      call ymds2ju(annee_ref, mois, day_ref, heure, jD_ref)
351      jH_ref = jD_ref - int(jD_ref)
352      jD_ref = int(jD_ref)
353
354      call ioconf_startdate(INT(jD_ref), jH_ref)
355
356      write(lunout,*)'DEBUG'
357      write(lunout,*)'annee_ref, mois, day_ref, heure, jD_ref'
358      write(lunout,*)annee_ref, mois, day_ref, heure, jD_ref
359      call ju2ymds(jD_ref+jH_ref,an, mois, jour, heure)
360      write(lunout,*)'jD_ref+jH_ref,an, mois, jour, heure'
361      write(lunout,*)jD_ref+jH_ref,an, mois, jour, heure
362#else
363! Ehouarn: we still need to define JD_ref and JH_ref
364! and since we don't know how many days there are in a year
365! we set JD_ref to 0 (this should be improved ...)
366      jD_ref=0
367      jH_ref=0
368#endif
369
370
371      if (iflag_phys.eq.1) then
372      ! these initialisations have already been done (via iniacademic)
373      ! if running in SW or Newtonian mode
374c-----------------------------------------------------------------------
375c   Initialisation des constantes dynamiques :
376c   ------------------------------------------
377        dtvr = zdtvr
378        CALL iniconst
379
380c-----------------------------------------------------------------------
381c   Initialisation de la geometrie :
382c   --------------------------------
383        CALL inigeom
384
385c-----------------------------------------------------------------------
386c   Initialisation du filtre :
387c   --------------------------
388        CALL inifilr
389      endif ! of if (iflag_phys.eq.1)
390c
391c-----------------------------------------------------------------------
392c   Initialisation de la dissipation :
393c   ----------------------------------
394
395      CALL inidissip( lstardis, nitergdiv, nitergrot, niterh   ,
396     *                tetagdiv, tetagrot , tetatemp, vert_prof_dissip)
397
398c-----------------------------------------------------------------------
399c   Initialisation de la physique :
400c   -------------------------------
401      IF ((iflag_phys==1).or.(iflag_phys>=100)) THEN
402! Physics:
403#ifdef CPP_PHYS
404         CALL iniphysiq(iim,jjm,llm,
405     &                distrib_phys(mpi_rank),comm_lmdz,
406     &                daysec,day_ini,dtphys/nsplit_phys,
407     &                rlatu,rlatv,rlonu,rlonv,aire,cu,cv,rad,g,r,cpp,
408     &                iflag_phys)
409#endif
410      ENDIF ! of IF ((iflag_phys==1).or.(iflag_phys>=100))
411
412
413c-----------------------------------------------------------------------
414c   Initialisation des dimensions d'INCA :
415c   --------------------------------------
416      IF (type_trac == 'inca') THEN
417!$OMP PARALLEL
418#ifdef INCA
419         CALL init_inca_dim(klon_omp,llm,iim,jjm,
420     $        rlonu,rlatu,rlonv,rlatv)
421#endif
422!$OMP END PARALLEL
423      END IF
424
425c-----------------------------------------------------------------------
426c   Initialisation des I/O :
427c   ------------------------
428
429
430      if (nday>=0) then
431         day_end = day_ini + nday
432      else
433         day_end = day_ini - nday/day_step
434      endif
435
436      WRITE(lunout,300)day_ini,day_end
437 300  FORMAT('1'/,15x,'run du jour',i7,2x,'au jour',i7//)
438
439#ifdef CPP_IOIPSL
440      call ju2ymds(jD_ref + day_ini - day_ref, an, mois, jour, heure)
441      write (lunout,301)jour, mois, an
442      call ju2ymds(jD_ref + day_end - day_ref, an, mois, jour, heure)
443      write (lunout,302)jour, mois, an
444 301  FORMAT('1'/,15x,'run du ', i2,'/',i2,'/',i4)
445 302  FORMAT('1'/,15x,'    au ', i2,'/',i2,'/',i4)
446#endif
447
448!      if (planet_type.eq."earth") then
449! Write an Earth-format restart file
450        CALL dynredem0_p("restart.nc", day_end, phis)
451!      endif
452
453      ecripar = .TRUE.
454
455#ifdef CPP_IOIPSL
456      time_step = zdtvr
457      IF (mpi_rank==0) then
458        if (ok_dyn_ins) then
459          ! initialize output file for instantaneous outputs
460          ! t_ops = iecri * daysec ! do operations every t_ops
461          t_ops =((1.0*iecri)/day_step) * daysec 
462          t_wrt = daysec ! iecri * daysec ! write output every t_wrt
463          t_wrt = daysec ! iecri * daysec ! write output every t_wrt
464          CALL inithist(day_ref,annee_ref,time_step,
465     &                  t_ops,t_wrt)
466        endif
467
468        IF (ok_dyn_ave) THEN
469          ! initialize output file for averaged outputs
470          t_ops = iperiod * time_step ! do operations every t_ops
471          t_wrt = periodav * daysec   ! write output every t_wrt
472          CALL initdynav(day_ref,annee_ref,time_step,
473     &                   t_ops,t_wrt)
474!         CALL initdynav_p(dynhistave_file,day_ref,annee_ref,time_step,
475!     .        t_ops, t_wrt, histaveid)
476        END IF
477      ENDIF
478      dtav = iperiod*dtvr/daysec
479#endif
480! #endif of #ifdef CPP_IOIPSL
481
482c  Choix des frequences de stokage pour le offline
483c      istdyn=day_step/4     ! stockage toutes les 6h=1jour/4
484c      istdyn=day_step/12     ! stockage toutes les 2h=1jour/12
485      istdyn=day_step/4     ! stockage toutes les 6h=1jour/12
486      istphy=istdyn/iphysiq     
487
488
489c
490c-----------------------------------------------------------------------
491c   Integration temporelle du modele :
492c   ----------------------------------
493
494c       write(78,*) 'ucov',ucov
495c       write(78,*) 'vcov',vcov
496c       write(78,*) 'teta',teta
497c       write(78,*) 'ps',ps
498c       write(78,*) 'q',q
499
500c$OMP PARALLEL DEFAULT(SHARED) COPYIN(/temps/,/logici/,/logicl/)
501      CALL leapfrog_p(ucov,vcov,teta,ps,masse,phis,q,time_0)
502c$OMP END PARALLEL
503
504
505      END
506
Note: See TracBrowser for help on using the repository browser.