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

Last change on this file since 421 was 130, checked in by slebonnois, 14 years ago

Sebastien:

  • correction de bugs dans phytitan suite a compil avec -debug sur gnome
  • elimination de nbetat* dans gcm.F et leapfrog.F (et dans le parallele)
  • correction rday -> rjour dans sortvarc.F
  • ajustement des arch-GNOME*
File size: 17.9 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 (config_inca /= 'none') 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 (raz_date == 1) THEN
340        annee_ref = anneeref
341        day_ref = dayref
342        day_ini = dayref
343        itau_dyn = 0
344        itau_phy = 0
345        time_0 = 0.
346        write(lunout,*)
347     .   'GCM: On reinitialise a la date lue dans gcm.def'
348      ELSE IF (annee_ref .ne. anneeref .or. day_ref .ne. dayref) THEN
349        write(lunout,*)
350     .  'GCM: Attention les dates initiales lues dans le fichier'
351        write(lunout,*)
352     .  ' restart ne correspondent pas a celles lues dans '
353        write(lunout,*)' gcm.def'
354        write(lunout,*)' annee_ref=',annee_ref," anneeref=",anneeref
355        write(lunout,*)' day_ref=',day_ref," dayref=",dayref
356        write(lunout,*)' Pas de remise a zero'
357      ENDIF
358
359c      if (annee_ref .ne. anneeref .or. day_ref .ne. dayref) then
360c        write(lunout,*)
361c     .  'GCM: Attention les dates initiales lues dans le fichier'
362c        write(lunout,*)
363c     .  ' restart ne correspondent pas a celles lues dans '
364c        write(lunout,*)' gcm.def'
365c        write(lunout,*)' annee_ref=',annee_ref," anneeref=",anneeref
366c        write(lunout,*)' day_ref=',day_ref," dayref=",dayref
367c        if (raz_date .ne. 1) then
368c          write(lunout,*)
369c     .    'GCM: On garde les dates du fichier restart'
370c        else
371c          annee_ref = anneeref
372c          day_ref = dayref
373c          day_ini = dayref
374c          itau_dyn = 0
375c          itau_phy = 0
376c          time_0 = 0.
377c          write(lunout,*)
378c     .   'GCM: On reinitialise a la date lue dans gcm.def'
379c        endif
380c      ELSE
381c        raz_date = 0
382c      endif
383
384#ifdef CPP_IOIPSL
385      mois = 1
386      heure = 0.
387! Ce n'est defini pour l'instant que pour la Terre...
388      if (planet_type.eq.'earth') then
389      call ymds2ju(annee_ref, mois, day_ref, heure, jD_ref)
390      jH_ref = jD_ref - int(jD_ref)
391      jD_ref = int(jD_ref)
392
393      call ioconf_startdate(INT(jD_ref), jH_ref)
394
395      write(lunout,*)'DEBUG'
396      write(lunout,*)'annee_ref, mois, day_ref, heure, jD_ref'
397      write(lunout,*)annee_ref, mois, day_ref, heure, jD_ref
398      call ju2ymds(jD_ref+jH_ref,an, mois, jour, heure)
399      write(lunout,*)'jD_ref+jH_ref,an, mois, jour, heure'
400      write(lunout,*)jD_ref+jH_ref,an, mois, jour, heure
401      else
402! A voir pour Titan et Venus
403        jD_ref=0
404        jH_ref=0
405      write(lunout,*)'A VOIR POUR VENUS ET TITAN: jD_ref, jH_ref'
406      write(lunout,*)jD_ref,jH_ref
407      endif ! planet_type
408#else
409! Ehouarn: we still need to define JD_ref and JH_ref
410! and since we don't know how many days there are in a year
411! we set JD_ref to 0 (this should be improved ...)
412      jD_ref=0
413      jH_ref=0
414#endif
415
416      if (iflag_phys.eq.1) then
417      ! these initialisations have already been done (via iniacademic)
418      ! if running in SW or Newtonian mode
419c-----------------------------------------------------------------------
420c   Initialisation des constantes dynamiques :
421c   ------------------------------------------
422        dtvr = zdtvr
423        CALL iniconst
424
425c-----------------------------------------------------------------------
426c   Initialisation de la geometrie :
427c   --------------------------------
428        CALL inigeom
429
430c-----------------------------------------------------------------------
431c   Initialisation du filtre :
432c   --------------------------
433        CALL inifilr
434      endif ! of if (iflag_phys.eq.1)
435c
436c-----------------------------------------------------------------------
437c   Initialisation de la dissipation :
438c   ----------------------------------
439
440      CALL inidissip( lstardis, nitergdiv, nitergrot, niterh   ,
441     *                tetagdiv, tetagrot , tetatemp              )
442
443c-----------------------------------------------------------------------
444c   Initialisation de la physique :
445c   -------------------------------
446
447      IF (call_iniphys.and.(iflag_phys.eq.1)) THEN
448         latfi(1)=rlatu(1)
449         lonfi(1)=0.
450         zcufi(1) = cu(1)
451         zcvfi(1) = cv(1)
452         DO j=2,jjm
453            DO i=1,iim
454               latfi((j-2)*iim+1+i)= rlatu(j)
455               lonfi((j-2)*iim+1+i)= rlonv(i)
456               zcufi((j-2)*iim+1+i) = cu((j-1)*iip1+i)
457               zcvfi((j-2)*iim+1+i) = cv((j-1)*iip1+i)
458            ENDDO
459         ENDDO
460         latfi(ngridmx)= rlatu(jjp1)
461         lonfi(ngridmx)= 0.
462         zcufi(ngridmx) = cu(ip1jm+1)
463         zcvfi(ngridmx) = cv(ip1jm-iim)
464         CALL gr_dyn_fi(1,iip1,jjp1,ngridmx,aire,airefi)
465         WRITE(lunout,*)
466     .       'GCM: WARNING!!! vitesse verticale nulle dans la physique'
467
468! Initialisation de la physique: pose probleme quand on tourne
469! SANS physique, car iniphysiq.F est dans le repertoire phy[]...
470! Il faut une cle CPP_PHYS
471#ifdef CPP_PHYS
472         CALL iniphysiq(ngridmx,llm,daysec,day_ini,dtphys/nsplit_phys ,
473     ,                latfi,lonfi,airefi,zcufi,zcvfi,rad,g,r,cpp     )
474#endif ! CPP_PHYS
475         call_iniphys=.false.
476      ENDIF ! of IF (call_iniphys.and.(iflag_phys.eq.1))
477!#endif
478
479c-----------------------------------------------------------------------
480c   Initialisation des dimensions d'INCA :
481c   --------------------------------------
482      IF (config_inca /= 'none') THEN
483#ifdef INCA
484!$OMP PARALLEL
485         CALL init_inca_dim(klon_omp,llm,iim,jjm,
486     $        rlonu,rlatu,rlonv,rlatv)
487!$OMP END PARALLEL
488#endif
489      END IF
490
491c-----------------------------------------------------------------------
492c   Initialisation des I/O :
493c   ------------------------
494
495
496      day_end = day_ini + nday
497      WRITE(lunout,300)day_ini,day_end
498 300  FORMAT('1'/,15x,'run du jour',i7,2x,'au jour',i7//)
499
500#ifdef CPP_IOIPSL
501! Ce n'est defini pour l'instant que pour la Terre...
502      if (planet_type.eq.'earth') then
503      call ju2ymds(jD_ref + day_ini - day_ref, an, mois, jour, heure)
504      write (lunout,301)jour, mois, an
505      call ju2ymds(jD_ref + day_end - day_ref, an, mois, jour, heure)
506      write (lunout,302)jour, mois, an
507      else
508! A voir pour Titan et Venus
509      write(lunout,*)'A VOIR POUR VENUS/TITAN: separation en annees...'
510      endif ! planet_type
511
512 301  FORMAT('1'/,15x,'run du ', i2,'/',i2,'/',i4)
513 302  FORMAT('1'/,15x,'    au ', i2,'/',i2,'/',i4)
514#endif
515
516      if (planet_type.eq."mars") then
517! POUR MARS, METTRE UNE FONCTION A PART, genre dynredem0_mars
518         abort_message = 'dynredem0_mars A FAIRE'
519         call abort_gcm(modname,abort_message,0)
520      else
521        CALL dynredem0_p("restart.nc", day_end, phis)
522      endif ! of if (planet_type.eq."mars")
523
524      ecripar = .TRUE.
525
526#ifdef CPP_IOIPSL
527      time_step = zdtvr
528      IF (mpi_rank==0) then
529        if (ok_dyn_ins) then
530        ! initialize output file for instantaneous outputs
531        ! t_ops = iecri * daysec ! do operations every t_ops
532        t_ops =((1.0*iecri)/day_step) * daysec 
533        t_wrt = daysec ! iecri * daysec ! write output every t_wrt
534        CALL inithist(day_ref,annee_ref,time_step,
535     &                  t_ops,t_wrt)
536        endif
537
538        IF (ok_dyn_ave) THEN
539          ! initialize output file for averaged outputs
540          t_ops = iperiod * time_step ! do operations every t_ops
541          t_wrt = periodav * daysec   ! write output every t_wrt
542          CALL initdynav(day_ref,annee_ref,time_step,
543     &                   t_ops,t_wrt)
544!         CALL initdynav_p(dynhistave_file,day_ref,annee_ref,time_step,
545!     .        t_ops, t_wrt, histaveid)
546        END IF
547      ENDIF
548      dtav = iperiod*dtvr/daysec
549#endif
550! #endif of #ifdef CPP_IOIPSL
551
552c  Choix des frequences de stokage pour le offline
553c      istdyn=day_step/4     ! stockage toutes les 6h=1jour/4
554c      istdyn=day_step/12     ! stockage toutes les 2h=1jour/12
555      istdyn=day_step/4     ! stockage toutes les 6h=1jour/12
556      istphy=istdyn/iphysiq     
557
558
559c
560c-----------------------------------------------------------------------
561c   Integration temporelle du modele :
562c   ----------------------------------
563
564c       write(78,*) 'ucov',ucov
565c       write(78,*) 'vcov',vcov
566c       write(78,*) 'teta',teta
567c       write(78,*) 'ps',ps
568c       write(78,*) 'q',q
569
570c$OMP PARALLEL DEFAULT(SHARED) COPYIN(/temps/,/logici/,/logicl/)
571      CALL leapfrog_p(ucov,vcov,teta,ps,masse,phis,q,
572     .              time_0)
573c$OMP END PARALLEL
574
575
576      END
577
Note: See TracBrowser for help on using the repository browser.