source: LMDZ5/branches/testing/libf/dyn3dpar/gcm.F @ 1665

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

Version testing basée sur la r1628

http://lmdz.lmd.jussieu.fr/utilisateurs/distribution-du-modele/versions-intermediaires


Testing release based on r1628

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 16.7 KB
Line 
1!
2! $Id: gcm.F 1665 2012-10-09 13:35:26Z fairhead $
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#ifdef CPP_PHYS
23      USE mod_grid_phy_lmdz
24      USE mod_phys_lmdz_para, ONLY : klon_mpi_para_nb
25      USE mod_phys_lmdz_omp_data, ONLY: klon_omp
26      USE dimphy
27      USE comgeomphy
28#endif
29      IMPLICIT NONE
30
31c      ......   Version  du 10/01/98    ..........
32
33c             avec  coordonnees  verticales hybrides
34c   avec nouveaux operat. dissipation * ( gradiv2,divgrad2,nxgraro2 )
35
36c=======================================================================
37c
38c   Auteur:  P. Le Van /L. Fairhead/F.Hourdin
39c   -------
40c
41c   Objet:
42c   ------
43c
44c   GCM LMD nouvelle grille
45c
46c=======================================================================
47c
48c  ... Dans inigeom , nouveaux calculs pour les elongations  cu , cv
49c      et possibilite d'appeler une fonction f(y)  a derivee tangente
50c      hyperbolique a la  place de la fonction a derivee sinusoidale.
51c  ... Possibilite de choisir le schema pour l'advection de
52c        q  , en modifiant iadv dans traceur.def  (MAF,10/02) .
53c
54c      Pour Van-Leer + Vapeur d'eau saturee, iadv(1)=4. (F.Codron,10/99)
55c      Pour Van-Leer iadv=10
56c
57c-----------------------------------------------------------------------
58c   Declarations:
59c   -------------
60#include "dimensions.h"
61#include "paramet.h"
62#include "comconst.h"
63#include "comdissnew.h"
64#include "comvert.h"
65#include "comgeom.h"
66#include "logic.h"
67#include "temps.h"
68#include "ener.h"
69#include "description.h"
70#include "serre.h"
71!#include "com_io_dyn.h"
72#include "iniprint.h"
73#include "tracstoke.h"
74
75#ifdef INCA
76! Only INCA needs these informations (from the Earth's physics)
77#include "indicesol.h"
78#endif
79
80      INTEGER         longcles
81      PARAMETER     ( longcles = 20 )
82      REAL  clesphy0( longcles )
83      SAVE  clesphy0
84
85
86
87      REAL zdtvr
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
94c      REAL p (ip1jmp1,llmp1  )               ! pression aux interfac.des couches
95c      REAL pks(ip1jmp1)                      ! exner au  sol
96c      REAL pk(ip1jmp1,llm)                   ! exner au milieu des couches
97c      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
100c      REAL phi(ip1jmp1,llm)                  ! geopotentiel
101c      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
111c      INTEGER ij,iq,l,i,j
112      INTEGER i,j
113
114
115      real time_step, t_wrt, t_ops
116
117
118      LOGICAL call_iniphys
119      data call_iniphys/.true./
120
121c      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
127c      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
130c      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     
152      INTEGER :: ierr
153
154
155c-----------------------------------------------------------------------
156c   Initialisations:
157c   ----------------
158
159      abort_message = 'last timestep reached'
160      modname = 'gcm'
161      descript = 'Run GCM LMDZ'
162      lafin    = .FALSE.
163      dynhist_file = 'dyn_hist'
164      dynhistave_file = 'dyn_hist_ave'
165
166
167
168c----------------------------------------------------------------------
169c  lecture des fichiers gcm.def ou run.def
170c  ---------------------------------------
171c
172! Ehouarn: dump possibility of using defrun
173!#ifdef CPP_IOIPSL
174      CALL conf_gcm( 99, .TRUE. , clesphy0 )
175!#else
176!      CALL defrun( 99, .TRUE. , clesphy0 )
177!#endif
178c
179c
180c------------------------------------
181c   Initialisation partie parallele
182c------------------------------------
183      CALL init_const_mpi
184
185      call init_parallel
186      call ini_getparam("out.def")
187      call Read_Distrib
188
189#ifdef CPP_PHYS
190        CALL Init_Phys_lmdz(iim,jjp1,llm,mpi_size,distrib_phys)
191#endif
192      CALL set_bands
193#ifdef CPP_PHYS
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#ifdef CPP_PHYS
206c$OMP PARALLEL
207      call InitComgeomphy
208c$OMP END PARALLEL
209#endif
210
211c-----------------------------------------------------------------------
212c   Choix du calendrier
213c   -------------------
214
215c      calend = 'earth_365d'
216
217#ifdef CPP_IOIPSL
218      if (calend == 'earth_360d') then
219        call ioconf_calendar('360d')
220        write(lunout,*)'CALENDRIER CHOISI: Terrestre a 360 jours/an'
221      else if (calend == 'earth_365d') then
222        call ioconf_calendar('noleap')
223        write(lunout,*)'CALENDRIER CHOISI: Terrestre a 365 jours/an'
224      else if (calend == 'earth_366d') then
225        call ioconf_calendar('gregorian')
226        write(lunout,*)'CALENDRIER CHOISI: Terrestre bissextile'
227      else
228        abort_message = 'Mauvais choix de calendrier'
229        call abort_gcm(modname,abort_message,1)
230      endif
231#endif
232
233      IF (type_trac == 'inca') THEN
234#ifdef INCA
235         call init_const_lmdz(
236     $        nbtr,anneeref,dayref,
237     $        iphysiq,day_step,nday,
238     $        nbsrf, is_oce,is_sic,
239     $        is_ter,is_lic)
240
241         call init_inca_para(
242     $        iim,jjm+1,llm,klon_glo,mpi_size,
243     $        distrib_phys,COMM_LMDZ)
244#endif
245      END IF
246
247c-----------------------------------------------------------------------
248c   Initialisation des traceurs
249c   ---------------------------
250c  Choix du nombre de traceurs et du schema pour l'advection
251c  dans fichier traceur.def, par default ou via INCA
252      call infotrac_init
253
254c Allocation de la tableau q : champs advectes   
255      ALLOCATE(q(ip1jmp1,llm,nqtot))
256
257c-----------------------------------------------------------------------
258c   Lecture de l'etat initial :
259c   ---------------------------
260
261c  lecture du fichier start.nc
262      if (read_start) then
263      ! we still need to run iniacademic to initialize some
264      ! constants & fields, if we run the 'newtonian' or 'SW' cases:
265        if (iflag_phys.ne.1) then
266          CALL iniacademic(vcov,ucov,teta,q,masse,ps,phis,time_0)
267        endif
268
269!        if (planet_type.eq."earth") then
270! Load an Earth-format start file
271         CALL dynetat0("start.nc",vcov,ucov,
272     &              teta,q,masse,ps,phis, time_0)
273!        endif ! of if (planet_type.eq."earth")
274
275c       write(73,*) 'ucov',ucov
276c       write(74,*) 'vcov',vcov
277c       write(75,*) 'teta',teta
278c       write(76,*) 'ps',ps
279c       write(77,*) 'q',q
280
281      endif ! of if (read_start)
282
283c le cas echeant, creation d un etat initial
284      IF (prt_level > 9) WRITE(lunout,*)
285     .              'GCM: AVANT iniacademic AVANT AVANT AVANT AVANT'
286      if (.not.read_start) then
287         CALL iniacademic(vcov,ucov,teta,q,masse,ps,phis,time_0)
288      endif
289
290c-----------------------------------------------------------------------
291c   Lecture des parametres de controle pour la simulation :
292c   -------------------------------------------------------
293c  on recalcule eventuellement le pas de temps
294
295      IF(MOD(day_step,iperiod).NE.0) THEN
296        abort_message =
297     .  'Il faut choisir un nb de pas par jour multiple de iperiod'
298        call abort_gcm(modname,abort_message,1)
299      ENDIF
300
301      IF(MOD(day_step,iphysiq).NE.0) THEN
302        abort_message =
303     * 'Il faut choisir un nb de pas par jour multiple de iphysiq'
304        call abort_gcm(modname,abort_message,1)
305      ENDIF
306
307      zdtvr    = daysec/REAL(day_step)
308        IF(dtvr.NE.zdtvr) THEN
309         WRITE(lunout,*)
310     .    'WARNING!!! changement de pas de temps',dtvr,'>',zdtvr
311        ENDIF
312
313C
314C on remet le calendrier à zero si demande
315c
316      IF (start_time /= starttime) then
317        WRITE(lunout,*)' GCM: Attention l''heure de depart lue dans le'
318     &,' fichier restart ne correspond pas à celle lue dans le run.def'
319        IF (raz_date == 1) then
320          WRITE(lunout,*)'Je prends l''heure lue dans run.def'
321          start_time = starttime
322        ELSE
323          WRITE(lunout,*)'Je m''arrete'
324          CALL abort
325        ENDIF
326      ENDIF
327      IF (raz_date == 1) THEN
328        annee_ref = anneeref
329        day_ref = dayref
330        day_ini = dayref
331        itau_dyn = 0
332        itau_phy = 0
333        time_0 = 0.
334        write(lunout,*)
335     .   'GCM: On reinitialise a la date lue dans gcm.def'
336      ELSE IF (annee_ref .ne. anneeref .or. day_ref .ne. dayref) THEN
337        write(lunout,*)
338     .  'GCM: Attention les dates initiales lues dans le fichier'
339        write(lunout,*)
340     .  ' restart ne correspondent pas a celles lues dans '
341        write(lunout,*)' gcm.def'
342        write(lunout,*)' annee_ref=',annee_ref," anneeref=",anneeref
343        write(lunout,*)' day_ref=',day_ref," dayref=",dayref
344        write(lunout,*)' Pas de remise a zero'
345      ENDIF
346c      if (annee_ref .ne. anneeref .or. day_ref .ne. dayref) then
347c        write(lunout,*)
348c     .  'GCM: Attention les dates initiales lues dans le fichier'
349c        write(lunout,*)
350c     .  ' restart ne correspondent pas a celles lues dans '
351c        write(lunout,*)' gcm.def'
352c        write(lunout,*)' annee_ref=',annee_ref," anneeref=",anneeref
353c        write(lunout,*)' day_ref=',day_ref," dayref=",dayref
354c        if (raz_date .ne. 1) then
355c          write(lunout,*)
356c     .    'GCM: On garde les dates du fichier restart'
357c        else
358c          annee_ref = anneeref
359c          day_ref = dayref
360c          day_ini = dayref
361c          itau_dyn = 0
362c          itau_phy = 0
363c          time_0 = 0.
364c          write(lunout,*)
365c     .   'GCM: On reinitialise a la date lue dans gcm.def'
366c        endif
367c      ELSE
368c        raz_date = 0
369c      endif
370
371#ifdef CPP_IOIPSL
372      mois = 1
373      heure = 0.
374      call ymds2ju(annee_ref, mois, day_ref, heure, jD_ref)
375      jH_ref = jD_ref - int(jD_ref)
376      jD_ref = int(jD_ref)
377
378      call ioconf_startdate(INT(jD_ref), jH_ref)
379
380      write(lunout,*)'DEBUG'
381      write(lunout,*)'annee_ref, mois, day_ref, heure, jD_ref'
382      write(lunout,*)annee_ref, mois, day_ref, heure, jD_ref
383      call ju2ymds(jD_ref+jH_ref,an, mois, jour, heure)
384      write(lunout,*)'jD_ref+jH_ref,an, mois, jour, heure'
385      write(lunout,*)jD_ref+jH_ref,an, mois, jour, heure
386#else
387! Ehouarn: we still need to define JD_ref and JH_ref
388! and since we don't know how many days there are in a year
389! we set JD_ref to 0 (this should be improved ...)
390      jD_ref=0
391      jH_ref=0
392#endif
393
394
395      if (iflag_phys.eq.1) then
396      ! these initialisations have already been done (via iniacademic)
397      ! if running in SW or Newtonian mode
398c-----------------------------------------------------------------------
399c   Initialisation des constantes dynamiques :
400c   ------------------------------------------
401        dtvr = zdtvr
402        CALL iniconst
403
404c-----------------------------------------------------------------------
405c   Initialisation de la geometrie :
406c   --------------------------------
407        CALL inigeom
408
409c-----------------------------------------------------------------------
410c   Initialisation du filtre :
411c   --------------------------
412        CALL inifilr
413      endif ! of if (iflag_phys.eq.1)
414c
415c-----------------------------------------------------------------------
416c   Initialisation de la dissipation :
417c   ----------------------------------
418
419      CALL inidissip( lstardis, nitergdiv, nitergrot, niterh   ,
420     *                tetagdiv, tetagrot , tetatemp              )
421
422c-----------------------------------------------------------------------
423c   Initialisation de la physique :
424c   -------------------------------
425      IF (call_iniphys.and.iflag_phys.eq.1) THEN
426         latfi(1)=rlatu(1)
427         lonfi(1)=0.
428         zcufi(1) = cu(1)
429         zcvfi(1) = cv(1)
430         DO j=2,jjm
431            DO i=1,iim
432               latfi((j-2)*iim+1+i)= rlatu(j)
433               lonfi((j-2)*iim+1+i)= rlonv(i)
434               zcufi((j-2)*iim+1+i) = cu((j-1)*iip1+i)
435               zcvfi((j-2)*iim+1+i) = cv((j-1)*iip1+i)
436            ENDDO
437         ENDDO
438         latfi(ngridmx)= rlatu(jjp1)
439         lonfi(ngridmx)= 0.
440         zcufi(ngridmx) = cu(ip1jm+1)
441         zcvfi(ngridmx) = cv(ip1jm-iim)
442         CALL gr_dyn_fi(1,iip1,jjp1,ngridmx,aire,airefi)
443
444         WRITE(lunout,*)
445     .       'GCM: WARNING!!! vitesse verticale nulle dans la physique'
446! Physics:
447#ifdef CPP_PHYS
448         CALL iniphysiq(ngridmx,llm,daysec,day_ini,dtphys/nsplit_phys ,
449     ,                latfi,lonfi,airefi,zcufi,zcvfi,rad,g,r,cpp     )
450#endif
451         call_iniphys=.false.
452      ENDIF ! of IF (call_iniphys.and.(iflag_phys.eq.1))
453
454
455c-----------------------------------------------------------------------
456c   Initialisation des dimensions d'INCA :
457c   --------------------------------------
458      IF (type_trac == 'inca') THEN
459!$OMP PARALLEL
460#ifdef INCA
461         CALL init_inca_dim(klon_omp,llm,iim,jjm,
462     $        rlonu,rlatu,rlonv,rlatv)
463#endif
464!$OMP END PARALLEL
465      END IF
466
467c-----------------------------------------------------------------------
468c   Initialisation des I/O :
469c   ------------------------
470
471
472      day_end = day_ini + nday
473      WRITE(lunout,300)day_ini,day_end
474 300  FORMAT('1'/,15x,'run du jour',i7,2x,'au jour',i7//)
475
476#ifdef CPP_IOIPSL
477      call ju2ymds(jD_ref + day_ini - day_ref, an, mois, jour, heure)
478      write (lunout,301)jour, mois, an
479      call ju2ymds(jD_ref + day_end - day_ref, an, mois, jour, heure)
480      write (lunout,302)jour, mois, an
481 301  FORMAT('1'/,15x,'run du ', i2,'/',i2,'/',i4)
482 302  FORMAT('1'/,15x,'    au ', i2,'/',i2,'/',i4)
483#endif
484
485#ifdef CPP_PHYS
486! Create start file (startphy.nc) and boundary conditions (limit.nc)
487! for the Earth verstion
488       if (iflag_phys>=100) then
489          call iniaqua(ngridmx,latfi,lonfi,iflag_phys)
490       endif
491#endif
492
493!      if (planet_type.eq."earth") then
494! Write an Earth-format restart file
495        CALL dynredem0_p("restart.nc", day_end, phis)
496!      endif
497
498      ecripar = .TRUE.
499
500#ifdef CPP_IOIPSL
501      time_step = zdtvr
502      IF (mpi_rank==0) then
503        if (ok_dyn_ins) then
504          ! initialize output file for instantaneous outputs
505          ! t_ops = iecri * daysec ! do operations every t_ops
506          t_ops =((1.0*iecri)/day_step) * daysec 
507          t_wrt = daysec ! iecri * daysec ! write output every t_wrt
508          t_wrt = daysec ! iecri * daysec ! write output every t_wrt
509          CALL inithist(day_ref,annee_ref,time_step,
510     &                  t_ops,t_wrt)
511        endif
512
513        IF (ok_dyn_ave) THEN
514          ! initialize output file for averaged outputs
515          t_ops = iperiod * time_step ! do operations every t_ops
516          t_wrt = periodav * daysec   ! write output every t_wrt
517          CALL initdynav(day_ref,annee_ref,time_step,
518     &                   t_ops,t_wrt)
519!         CALL initdynav_p(dynhistave_file,day_ref,annee_ref,time_step,
520!     .        t_ops, t_wrt, histaveid)
521        END IF
522      ENDIF
523      dtav = iperiod*dtvr/daysec
524#endif
525! #endif of #ifdef CPP_IOIPSL
526
527c  Choix des frequences de stokage pour le offline
528c      istdyn=day_step/4     ! stockage toutes les 6h=1jour/4
529c      istdyn=day_step/12     ! stockage toutes les 2h=1jour/12
530      istdyn=day_step/4     ! stockage toutes les 6h=1jour/12
531      istphy=istdyn/iphysiq     
532
533
534c
535c-----------------------------------------------------------------------
536c   Integration temporelle du modele :
537c   ----------------------------------
538
539c       write(78,*) 'ucov',ucov
540c       write(78,*) 'vcov',vcov
541c       write(78,*) 'teta',teta
542c       write(78,*) 'ps',ps
543c       write(78,*) 'q',q
544
545c$OMP PARALLEL DEFAULT(SHARED) COPYIN(/temps/,/logici/,/logicl/)
546      CALL leapfrog_p(ucov,vcov,teta,ps,masse,phis,q,clesphy0,
547     .              time_0)
548c$OMP END PARALLEL
549
550
551      END
552
Note: See TracBrowser for help on using the repository browser.