source: LMDZ4/trunk/libf/dyn3dpar/gcm.F @ 1279

Last change on this file since 1279 was 1279, checked in by Laurent Fairhead, 14 years ago

Merged LMDZ4-dev branch changes r1241:1278 into the trunk
Running trunk and LMDZ4-dev in LMDZOR configuration on local
machine (sequential) and SX8 (4-proc) yields identical results
(restart and restartphy are identical binarily)
Log history from r1241 to r1278 is available by switching to
source:LMDZ4/branches/LMDZ4-dev-20091210

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