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

Last change on this file since 1592 was 1592, checked in by Ehouarn Millour, 13 years ago

Minor cleanup: remove unused variables nbetat, nbetatmoy and nbetatdem.
EM

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