source: LMDZ5/trunk/libf/gcm.F @ 1630

Last change on this file since 1630 was 1630, checked in by Laurent Fairhead, 12 years ago

Importation initiale du répertoire dyn3dmem


Initial import of dyn3dmem directory

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