source: trunk/libf/dyn3d/gcm.F @ 124

Last change on this file since 124 was 101, checked in by slebonnois, 14 years ago

SL: modifications pour arriver a compiler le gcm VENUS !
Ca marche !
A noter: modifs de makelmdz

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