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

Last change on this file since 3916 was 3838, checked in by millour, 10 years ago

Fixed call to iniphysiq from gcm and removed unused "pdayref" argument (day_ini is known from temps.h).
Removed "dtime" from phys_state_var_mod.F90; pdtphys (from time_phylmdz_mod) must be used instead.
With this revision seq and parallel MPI/OpenMP bench runs yield identical restart files.
EM

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         CALL iniacademic_loc(vcov,ucov,teta,q,masse,ps,phis,time_0)
260      endif
261
262c-----------------------------------------------------------------------
263c   Lecture des parametres de controle pour la simulation :
264c   -------------------------------------------------------
265c  on recalcule eventuellement le pas de temps
266
267      IF(MOD(day_step,iperiod).NE.0) THEN
268        abort_message =
269     .  'Il faut choisir un nb de pas par jour multiple de iperiod'
270        call abort_gcm(modname,abort_message,1)
271      ENDIF
272
273      IF(MOD(day_step,iphysiq).NE.0) THEN
274        abort_message =
275     * 'Il faut choisir un nb de pas par jour multiple de iphysiq'
276        call abort_gcm(modname,abort_message,1)
277      ENDIF
278
279      zdtvr    = daysec/REAL(day_step)
280        IF(dtvr.NE.zdtvr) THEN
281         WRITE(lunout,*)
282     .    'WARNING!!! changement de pas de temps',dtvr,'>',zdtvr
283        ENDIF
284
285C
286C on remet le calendrier \`a zero si demande
287c
288      IF (start_time /= starttime) then
289        WRITE(lunout,*)' GCM: Attention l''heure de depart lue dans le'
290     &,' fichier restart ne correspond pas a celle lue dans le run.def'
291        IF (raz_date == 1) then
292          WRITE(lunout,*)'Je prends l''heure lue dans run.def'
293          start_time = starttime
294        ELSE
295          WRITE(lunout,*)'Je m''arrete'
296          CALL abort
297        ENDIF
298      ENDIF
299      IF (raz_date == 1) THEN
300        annee_ref = anneeref
301        day_ref = dayref
302        day_ini = dayref
303        itau_dyn = 0
304        itau_phy = 0
305        time_0 = 0.
306        write(lunout,*)
307     .   'GCM: On reinitialise a la date lue dans gcm.def'
308      ELSE IF (annee_ref .ne. anneeref .or. day_ref .ne. dayref) THEN
309        write(lunout,*)
310     .  'GCM: Attention les dates initiales lues dans le fichier'
311        write(lunout,*)
312     .  ' restart ne correspondent pas a celles lues dans '
313        write(lunout,*)' gcm.def'
314        write(lunout,*)' annee_ref=',annee_ref," anneeref=",anneeref
315        write(lunout,*)' day_ref=',day_ref," dayref=",dayref
316        write(lunout,*)' Pas de remise a zero'
317      ENDIF
318c      if (annee_ref .ne. anneeref .or. day_ref .ne. dayref) then
319c        write(lunout,*)
320c     .  'GCM: Attention les dates initiales lues dans le fichier'
321c        write(lunout,*)
322c     .  ' restart ne correspondent pas a celles lues dans '
323c        write(lunout,*)' gcm.def'
324c        write(lunout,*)' annee_ref=',annee_ref," anneeref=",anneeref
325c        write(lunout,*)' day_ref=',day_ref," dayref=",dayref
326c        if (raz_date .ne. 1) then
327c          write(lunout,*)
328c     .    'GCM: On garde les dates du fichier restart'
329c        else
330c          annee_ref = anneeref
331c          day_ref = dayref
332c          day_ini = dayref
333c          itau_dyn = 0
334c          itau_phy = 0
335c          time_0 = 0.
336c          write(lunout,*)
337c     .   'GCM: On reinitialise a la date lue dans gcm.def'
338c        endif
339c      ELSE
340c        raz_date = 0
341c      endif
342
343#ifdef CPP_IOIPSL
344      mois = 1
345      heure = 0.
346      call ymds2ju(annee_ref, mois, day_ref, heure, jD_ref)
347      jH_ref = jD_ref - int(jD_ref)
348      jD_ref = int(jD_ref)
349
350      call ioconf_startdate(INT(jD_ref), jH_ref)
351
352      write(lunout,*)'DEBUG'
353      write(lunout,*)'annee_ref, mois, day_ref, heure, jD_ref'
354      write(lunout,*)annee_ref, mois, day_ref, heure, jD_ref
355      call ju2ymds(jD_ref+jH_ref,an, mois, jour, heure)
356      write(lunout,*)'jD_ref+jH_ref,an, mois, jour, heure'
357      write(lunout,*)jD_ref+jH_ref,an, mois, jour, heure
358#else
359! Ehouarn: we still need to define JD_ref and JH_ref
360! and since we don't know how many days there are in a year
361! we set JD_ref to 0 (this should be improved ...)
362      jD_ref=0
363      jH_ref=0
364#endif
365
366      if (iflag_phys.eq.1) then
367      ! these initialisations have already been done (via iniacademic)
368      ! if running in SW or Newtonian mode
369c-----------------------------------------------------------------------
370c   Initialisation des constantes dynamiques :
371c   ------------------------------------------
372        dtvr = zdtvr
373        CALL iniconst
374
375c-----------------------------------------------------------------------
376c   Initialisation de la geometrie :
377c   --------------------------------
378        CALL inigeom
379
380c-----------------------------------------------------------------------
381c   Initialisation du filtre :
382c   --------------------------
383        CALL inifilr
384      endif ! of if (iflag_phys.eq.1)
385c
386c-----------------------------------------------------------------------
387c   Initialisation de la dissipation :
388c   ----------------------------------
389
390      CALL inidissip( lstardis, nitergdiv, nitergrot, niterh   ,
391     *                tetagdiv, tetagrot , tetatemp, vert_prof_dissip)
392
393c-----------------------------------------------------------------------
394c   Initialisation des I/O :
395c   ------------------------
396
397
398      if (nday>=0) then
399         day_end = day_ini + nday
400      else
401         day_end = day_ini - nday/day_step
402      endif
403 
404      WRITE(lunout,300)day_ini,day_end
405 300  FORMAT('1'/,15x,'run du jour',i7,2x,'au jour',i7//)
406
407#ifdef CPP_IOIPSL
408      call ju2ymds(jD_ref + day_ini - day_ref, an, mois, jour, heure)
409      write (lunout,301)jour, mois, an
410      call ju2ymds(jD_ref + day_end - day_ref, an, mois, jour, heure)
411      write (lunout,302)jour, mois, an
412 301  FORMAT('1'/,15x,'run du ', i2,'/',i2,'/',i4)
413 302  FORMAT('1'/,15x,'    au ', i2,'/',i2,'/',i4)
414#endif
415
416c-----------------------------------------------------------------------
417c   Initialisation de la physique :
418c   -------------------------------
419      IF ((iflag_phys==1).or.(iflag_phys>=100)) THEN
420! Physics:
421#ifdef CPP_PHYS
422         CALL iniphysiq(iim,jjm, distrib_phys(mpi_rank), comm_lmdz, llm,
423     &                  daysec, dtphys/nsplit_phys,
424     &                  rlatu,rlatv,rlonu,rlonv,aire,cu,cv,rad,g,r,cpp,
425     &                  iflag_phys)
426#endif
427      ENDIF ! of IF ((iflag_phys==1).or.(iflag_phys>=100))
428
429
430c-----------------------------------------------------------------------
431c   Initialisation des dimensions d'INCA :
432c   --------------------------------------
433      IF (type_trac == 'inca') THEN
434!$OMP PARALLEL
435#ifdef INCA
436         CALL init_inca_dim(klon_omp,llm,iim,jjm,
437     $        rlonu,rlatu,rlonv,rlatv)
438#endif
439!$OMP END PARALLEL
440      END IF
441
442!      if (planet_type.eq."earth") then
443! Write an Earth-format restart file
444        CALL dynredem0_loc("restart.nc", day_end, phis)
445!      endif
446
447      ecripar = .TRUE.
448
449#ifdef CPP_IOIPSL
450      time_step = zdtvr
451      IF (mpi_rank==0) then
452        if (ok_dyn_ins) then
453          ! initialize output file for instantaneous outputs
454          ! t_ops = iecri * daysec ! do operations every t_ops
455          t_ops =((1.0*iecri)/day_step) * daysec 
456          t_wrt = daysec ! iecri * daysec ! write output every t_wrt
457          t_wrt = daysec ! iecri * daysec ! write output every t_wrt
458          CALL inithist(day_ref,annee_ref,time_step,
459     &                  t_ops,t_wrt)
460        endif
461
462      IF (ok_dyn_ave) THEN
463         ! initialize output file for averaged outputs
464         t_ops = iperiod * time_step ! do operations every t_ops
465         t_wrt = periodav * daysec   ! write output every t_wrt
466         CALL initdynav_loc(day_ref,annee_ref,time_step,t_ops,t_wrt)
467        END IF
468      ENDIF
469      dtav = iperiod*dtvr/daysec
470#endif
471! #endif of #ifdef CPP_IOIPSL
472
473c  Choix des frequences de stokage pour le offline
474c      istdyn=day_step/4     ! stockage toutes les 6h=1jour/4
475c      istdyn=day_step/12     ! stockage toutes les 2h=1jour/12
476      istdyn=day_step/4     ! stockage toutes les 6h=1jour/12
477      istphy=istdyn/iphysiq     
478
479
480c
481c-----------------------------------------------------------------------
482c   Integration temporelle du modele :
483c   ----------------------------------
484
485c       write(78,*) 'ucov',ucov
486c       write(78,*) 'vcov',vcov
487c       write(78,*) 'teta',teta
488c       write(78,*) 'ps',ps
489c       write(78,*) 'q',q
490
491c$OMP PARALLEL DEFAULT(SHARED) COPYIN(/temps/,/logici/,/logicl/)
492      CALL leapfrog_loc(ucov,vcov,teta,ps,masse,phis,q,time_0)
493c$OMP END PARALLEL
494
495!      OPEN(unit=5487,file='ok_lmdz',status='replace')
496!      WRITE(5487,*) 'ok_lmdz'
497!      CLOSE(5487)
498      END
499
Note: See TracBrowser for help on using the repository browser.