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

Last change on this file since 1795 was 1795, checked in by Ehouarn Millour, 11 years ago

Version testing basee sur la r1794


Testing release based on r1794

  • 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 1795 2013-07-18 08:20:28Z 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#ifdef INCA
23! Only INCA needs these informations (from the Earth's physics)
24      USE indice_sol_mod
25#endif
26
27#ifdef CPP_PHYS
28      USE mod_grid_phy_lmdz
29      USE mod_phys_lmdz_para, ONLY : klon_mpi_para_nb
30      USE mod_phys_lmdz_omp_data, ONLY: klon_omp
31      USE dimphy
32      USE comgeomphy
33#endif
34      IMPLICIT NONE
35
36c      ......   Version  du 10/01/98    ..........
37
38c             avec  coordonnees  verticales hybrides
39c   avec nouveaux operat. dissipation * ( gradiv2,divgrad2,nxgraro2 )
40
41c=======================================================================
42c
43c   Auteur:  P. Le Van /L. Fairhead/F.Hourdin
44c   -------
45c
46c   Objet:
47c   ------
48c
49c   GCM LMD nouvelle grille
50c
51c=======================================================================
52c
53c  ... Dans inigeom , nouveaux calculs pour les elongations  cu , cv
54c      et possibilite d'appeler une fonction f(y)  a derivee tangente
55c      hyperbolique a la  place de la fonction a derivee sinusoidale.
56c  ... Possibilite de choisir le schema pour l'advection de
57c        q  , en modifiant iadv dans traceur.def  (MAF,10/02) .
58c
59c      Pour Van-Leer + Vapeur d'eau saturee, iadv(1)=4. (F.Codron,10/99)
60c      Pour Van-Leer iadv=10
61c
62c-----------------------------------------------------------------------
63c   Declarations:
64c   -------------
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 "ener.h"
74#include "description.h"
75#include "serre.h"
76!#include "com_io_dyn.h"
77#include "iniprint.h"
78#include "tracstoke.h"
79
80#ifdef INCA
81! Only INCA needs these informations (from the Earth's physics)
82!#include "indicesol.h"
83#endif
84
85      INTEGER         longcles
86      PARAMETER     ( longcles = 20 )
87      REAL  clesphy0( longcles )
88      SAVE  clesphy0
89
90
91
92      REAL zdtvr
93
94c   variables dynamiques
95      REAL vcov(ip1jm,llm),ucov(ip1jmp1,llm) ! vents covariants
96      REAL teta(ip1jmp1,llm)                 ! temperature potentielle
97      REAL, ALLOCATABLE, DIMENSION(:,:,:) :: q ! champs advectes
98      REAL ps(ip1jmp1)                       ! pression  au sol
99c      REAL p (ip1jmp1,llmp1  )               ! pression aux interfac.des couches
100c      REAL pks(ip1jmp1)                      ! exner au  sol
101c      REAL pk(ip1jmp1,llm)                   ! exner au milieu des couches
102c      REAL pkf(ip1jmp1,llm)                  ! exner filt.au milieu des couches
103      REAL masse(ip1jmp1,llm)                ! masse d'air
104      REAL phis(ip1jmp1)                     ! geopotentiel au sol
105c      REAL phi(ip1jmp1,llm)                  ! geopotentiel
106c      REAL w(ip1jmp1,llm)                    ! vitesse verticale
107
108c variables dynamiques intermediaire pour le transport
109
110c   variables pour le fichier histoire
111      REAL dtav      ! intervalle de temps elementaire
112
113      REAL time_0
114
115      LOGICAL lafin
116c      INTEGER ij,iq,l,i,j
117      INTEGER i,j
118
119
120      real time_step, t_wrt, t_ops
121
122
123      LOGICAL call_iniphys
124      data call_iniphys/.true./
125
126c      REAL alpha(ip1jmp1,llm),beta(ip1jmp1,llm)
127c+jld variables test conservation energie
128c      REAL ecin(ip1jmp1,llm),ecin0(ip1jmp1,llm)
129C     Tendance de la temp. potentiel d (theta)/ d t due a la
130C     tansformation d'energie cinetique en energie thermique
131C     cree par la dissipation
132c      REAL dhecdt(ip1jmp1,llm)
133c      REAL vcont(ip1jm,llm),ucont(ip1jmp1,llm)
134c      REAL      d_h_vcol, d_qt, d_qw, d_ql, d_ec
135c      CHARACTER (len=15) :: ztit
136c-jld
137
138
139      character (len=80) :: dynhist_file, dynhistave_file
140      character (len=20) :: modname
141      character (len=80) :: abort_message
142! locales pour gestion du temps
143      INTEGER :: an, mois, jour
144      REAL :: heure
145
146
147c-----------------------------------------------------------------------
148c    variables pour l'initialisation de la physique :
149c    ------------------------------------------------
150      INTEGER ngridmx
151      PARAMETER( ngridmx = 2+(jjm-1)*iim - 1/jjm   )
152      REAL zcufi(ngridmx),zcvfi(ngridmx)
153      REAL latfi(ngridmx),lonfi(ngridmx)
154      REAL airefi(ngridmx)
155      SAVE latfi, lonfi, airefi
156     
157      INTEGER :: ierr
158
159
160c-----------------------------------------------------------------------
161c   Initialisations:
162c   ----------------
163
164      abort_message = 'last timestep reached'
165      modname = 'gcm'
166      descript = 'Run GCM LMDZ'
167      lafin    = .FALSE.
168      dynhist_file = 'dyn_hist'
169      dynhistave_file = 'dyn_hist_ave'
170
171
172
173c----------------------------------------------------------------------
174c  lecture des fichiers gcm.def ou run.def
175c  ---------------------------------------
176c
177! Ehouarn: dump possibility of using defrun
178!#ifdef CPP_IOIPSL
179      CALL conf_gcm( 99, .TRUE. , clesphy0 )
180!#else
181!      CALL defrun( 99, .TRUE. , clesphy0 )
182!#endif
183c
184c
185c------------------------------------
186c   Initialisation partie parallele
187c------------------------------------
188      CALL init_const_mpi
189
190      call init_parallel
191      call ini_getparam("out.def")
192      call Read_Distrib
193
194#ifdef CPP_PHYS
195        CALL Init_Phys_lmdz(iim,jjp1,llm,mpi_size,distrib_phys)
196#endif
197      CALL set_bands
198#ifdef CPP_PHYS
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#ifdef CPP_PHYS
211c$OMP PARALLEL
212      call InitComgeomphy
213c$OMP END PARALLEL
214#endif
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 (type_trac == 'inca') 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(q(ip1jmp1,llm,nqtot))
261
262c-----------------------------------------------------------------------
263c   Lecture de l'etat initial :
264c   ---------------------------
265
266c  lecture du fichier start.nc
267      if (read_start) then
268      ! we still need to run iniacademic to initialize some
269      ! constants & fields, if we run the 'newtonian' or 'SW' cases:
270        if (iflag_phys.ne.1) then
271          CALL iniacademic(vcov,ucov,teta,q,masse,ps,phis,time_0)
272        endif
273
274!        if (planet_type.eq."earth") then
275! Load an Earth-format start file
276         CALL dynetat0("start.nc",vcov,ucov,
277     &              teta,q,masse,ps,phis, time_0)
278!        endif ! of if (planet_type.eq."earth")
279
280c       write(73,*) 'ucov',ucov
281c       write(74,*) 'vcov',vcov
282c       write(75,*) 'teta',teta
283c       write(76,*) 'ps',ps
284c       write(77,*) 'q',q
285
286      endif ! of if (read_start)
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
295c-----------------------------------------------------------------------
296c   Lecture des parametres de controle pour la simulation :
297c   -------------------------------------------------------
298c  on recalcule eventuellement le pas de temps
299
300      IF(MOD(day_step,iperiod).NE.0) THEN
301        abort_message =
302     .  'Il faut choisir un nb de pas par jour multiple de iperiod'
303        call abort_gcm(modname,abort_message,1)
304      ENDIF
305
306      IF(MOD(day_step,iphysiq).NE.0) THEN
307        abort_message =
308     * 'Il faut choisir un nb de pas par jour multiple de iphysiq'
309        call abort_gcm(modname,abort_message,1)
310      ENDIF
311
312      zdtvr    = daysec/REAL(day_step)
313        IF(dtvr.NE.zdtvr) THEN
314         WRITE(lunout,*)
315     .    'WARNING!!! changement de pas de temps',dtvr,'>',zdtvr
316        ENDIF
317
318C
319C on remet le calendrier à zero si demande
320c
321      IF (start_time /= starttime) then
322        WRITE(lunout,*)' GCM: Attention l''heure de depart lue dans le'
323     &,' fichier restart ne correspond pas à celle lue dans le run.def'
324        IF (raz_date == 1) then
325          WRITE(lunout,*)'Je prends l''heure lue dans run.def'
326          start_time = starttime
327        ELSE
328          WRITE(lunout,*)'Je m''arrete'
329          CALL abort
330        ENDIF
331      ENDIF
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
399
400      if (iflag_phys.eq.1) then
401      ! these initialisations have already been done (via iniacademic)
402      ! if running in SW or Newtonian mode
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
418      endif ! of if (iflag_phys.eq.1)
419c
420c-----------------------------------------------------------------------
421c   Initialisation de la dissipation :
422c   ----------------------------------
423
424      CALL inidissip( lstardis, nitergdiv, nitergrot, niterh   ,
425     *                tetagdiv, tetagrot , tetatemp, vert_prof_dissip)
426
427c-----------------------------------------------------------------------
428c   Initialisation de la physique :
429c   -------------------------------
430      IF (call_iniphys.and.(iflag_phys==1.or.iflag_phys>=100)) THEN
431         latfi(1)=rlatu(1)
432         lonfi(1)=0.
433         zcufi(1) = cu(1)
434         zcvfi(1) = cv(1)
435         DO j=2,jjm
436            DO i=1,iim
437               latfi((j-2)*iim+1+i)= rlatu(j)
438               lonfi((j-2)*iim+1+i)= rlonv(i)
439               zcufi((j-2)*iim+1+i) = cu((j-1)*iip1+i)
440               zcvfi((j-2)*iim+1+i) = cv((j-1)*iip1+i)
441            ENDDO
442         ENDDO
443         latfi(ngridmx)= rlatu(jjp1)
444         lonfi(ngridmx)= 0.
445         zcufi(ngridmx) = cu(ip1jm+1)
446         zcvfi(ngridmx) = cv(ip1jm-iim)
447         CALL gr_dyn_fi(1,iip1,jjp1,ngridmx,aire,airefi)
448
449         WRITE(lunout,*)
450     .       'GCM: WARNING!!! vitesse verticale nulle dans la physique'
451! Physics:
452#ifdef CPP_PHYS
453         CALL iniphysiq(ngridmx,llm,daysec,day_ini,dtphys/nsplit_phys,
454     &                latfi,lonfi,airefi,zcufi,zcvfi,rad,g,r,cpp,
455     &                iflag_phys)
456#endif
457         call_iniphys=.false.
458      ENDIF ! of IF (call_iniphys.and.(iflag_phys==1.or.iflag_phys>=100))
459
460
461c-----------------------------------------------------------------------
462c   Initialisation des dimensions d'INCA :
463c   --------------------------------------
464      IF (type_trac == 'inca') 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! Write an Earth-format restart file
493        CALL dynredem0_p("restart.nc", day_end, phis)
494!      endif
495
496      ecripar = .TRUE.
497
498#ifdef CPP_IOIPSL
499      time_step = zdtvr
500      IF (mpi_rank==0) then
501        if (ok_dyn_ins) then
502          ! initialize output file for instantaneous outputs
503          ! t_ops = iecri * daysec ! do operations every t_ops
504          t_ops =((1.0*iecri)/day_step) * daysec 
505          t_wrt = daysec ! iecri * daysec ! write output every t_wrt
506          t_wrt = daysec ! iecri * daysec ! write output every t_wrt
507          CALL inithist(day_ref,annee_ref,time_step,
508     &                  t_ops,t_wrt)
509        endif
510
511        IF (ok_dyn_ave) THEN
512          ! initialize output file for averaged outputs
513          t_ops = iperiod * time_step ! do operations every t_ops
514          t_wrt = periodav * daysec   ! write output every t_wrt
515          CALL initdynav(day_ref,annee_ref,time_step,
516     &                   t_ops,t_wrt)
517!         CALL initdynav_p(dynhistave_file,day_ref,annee_ref,time_step,
518!     .        t_ops, t_wrt, histaveid)
519        END IF
520      ENDIF
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
543c$OMP PARALLEL DEFAULT(SHARED) COPYIN(/temps/,/logici/,/logicl/)
544      CALL leapfrog_p(ucov,vcov,teta,ps,masse,phis,q,clesphy0,
545     .              time_0)
546c$OMP END PARALLEL
547
548
549      END
550
Note: See TracBrowser for help on using the repository browser.