source: LMDZ4/branches/LMDZ4V5.0-dev/libf/dyn3dpar/gcm.F @ 1384

Last change on this file since 1384 was 1384, checked in by Ehouarn Millour, 14 years ago

Restore possibility to start a Shallow Water run from a start.nc file from r1380 which was accidentally removed in r1382

EM

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