source: dynamico_lmdz/aquaplanet/LMDZ5/libf/dyn3dmem/gcm.F @ 3981

Last change on this file since 3981 was 3981, checked in by ymipsl, 8 years ago

LMDZ : for aquaplanet run, annee_ref default value is 0 if not specified in run.def

YM

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