source: trunk/LMDZ.COMMON/libf/dyn3dpar/gcm.F @ 617

Last change on this file since 617 was 492, checked in by emillour, 14 years ago

Common dynamics: updates to keep up with LMDZ5 Earth (rev 1605)
See file "DOC/chantiers/commit_importants.log" for details.
EM

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