source: LMDZ5/trunk/libf/dyn3dmem/gcm.F @ 2239

Last change on this file since 2239 was 2239, checked in by Ehouarn Millour, 9 years ago

Reorganizing physics/dynamics interface:

  • what is related to dynamics-physics interface is now in a seperate directory: dynlmdz_phy* for physics in phy*
  • 1d model and related dependencies (including a couple from "dynamics", set up as symbolic links) is now in subdirectory "dyn1d" of phy*.
  • "bibio" directory is now "misc" and should only contain autonomous utilities.
  • "cosp" is now a subdirectory of phylmd.

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