source: trunk/LMDZ.COMMON/libf/dyn3dpar/gcm.F @ 1615

Last change on this file since 1615 was 1593, checked in by emillour, 9 years ago

Common dynamics:

  • some cleanup around unused or unecessary parameters in the dynamics (ecritphy, grireg and physic) to harmonize with LMDZ5 (Earth dyn core).
  • associated changes in LMDZ.MARS and LMDZ.GENERIC

EM

File size: 18.8 KB
Line 
1!
2! $Id: gcm.F 1446 2010-10-22 09:27:25Z emillour $
3!
4c
5c
6      PROGRAM gcm
7
8#ifdef CPP_IOIPSL
9      USE IOIPSL
10#endif
11
12
13      USE mod_const_mpi, ONLY: init_const_mpi
14      USE parallel_lmdz
15      USE infotrac
16!#ifdef CPP_PHYS
17!      USE mod_interface_dyn_phys
18!#endif
19      USE mod_hallo
20      USE Bands
21      USE getparam
22      USE filtreg_mod
23      USE control_mod, only: planet_type,nday,day_step,iperiod,iphysiq,
24     &                       raz_date,anneeref,starttime,dayref,
25     &                       ok_dyn_ins,ok_dyn_ave,iecri,periodav,
26     &                       less1day,fractday,ndynstep,nsplit_phys
27      use cpdet_mod, only: ini_cpdet
28
29
30! Ehouarn: the following are needed with (parallel) physics:
31#ifdef CPP_PHYS
32      USE iniphysiq_mod, ONLY: iniphysiq
33      USE mod_grid_phy_lmdz
34!      USE mod_phys_lmdz_para, ONLY : klon_mpi_para_nb
35      USE mod_phys_lmdz_omp_data, ONLY: klon_omp
36      USE dimphy
37#endif
38      USE comconst_mod, ONLY: daysec,dtvr,dtphys,rad,g,r,cpp
39      USE logic_mod
40      USE temps_mod, ONLY: calend,start_time,annee_ref,day_ref,
41     .          itau_dyn,itau_phy,day_ini,jD_ref,jH_ref,day_end,
42     .          dt,hour_ini,itaufin
43      IMPLICIT NONE
44
45c      ......   Version  du 10/01/98    ..........
46
47c             avec  coordonnees  verticales hybrides
48c   avec nouveaux operat. dissipation * ( gradiv2,divgrad2,nxgraro2 )
49
50c=======================================================================
51c
52c   Auteur:  P. Le Van /L. Fairhead/F.Hourdin
53c   -------
54c
55c   Objet:
56c   ------
57c
58c   GCM LMD nouvelle grille
59c
60c=======================================================================
61c
62c  ... Dans inigeom , nouveaux calculs pour les elongations  cu , cv
63c      et possibilite d'appeler une fonction f(y)  a derivee tangente
64c      hyperbolique a la  place de la fonction a derivee sinusoidale.
65c  ... Possibilite de choisir le schema pour l'advection de
66c        q  , en modifiant iadv dans traceur.def  (MAF,10/02) .
67c
68c      Pour Van-Leer + Vapeur d'eau saturee, iadv(1)=4. (F.Codron,10/99)
69c      Pour Van-Leer iadv=10
70c
71c-----------------------------------------------------------------------
72c   Declarations:
73c   -------------
74
75#include "dimensions.h"
76#include "paramet.h"
77#include "comdissnew.h"
78#include "comgeom.h"
79!!!!!!!!!!!#include "control.h"
80!#include "com_io_dyn.h"
81#include "iniprint.h"
82#include "tracstoke.h"
83
84
85      REAL zdtvr
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      lafin    = .FALSE.
160      dynhist_file = 'dyn_hist'
161      dynhistave_file = 'dyn_hist_ave'
162
163
164
165c----------------------------------------------------------------------
166c  lecture des fichiers gcm.def ou run.def
167c  ---------------------------------------
168c
169! Ehouarn: dump possibility of using defrun
170!#ifdef CPP_IOIPSL
171      CALL conf_gcm( 99, .TRUE. )
172      if (mod(iphysiq, iperiod) /= 0) call abort_gcm("conf_gcm",
173     s "iphysiq must be a multiple of iperiod", 1)
174!#else
175!      CALL defrun( 99, .TRUE. , clesphy0 )
176!#endif
177c
178c
179c------------------------------------
180c   Initialisation partie parallele
181c------------------------------------
182
183      CALL init_const_mpi
184      call init_parallel
185      call ini_getparam("out.def")
186      call Read_Distrib
187
188!#ifdef CPP_PHYS
189!        CALL init_phys_lmdz(iim,jjp1,llm,mpi_size,distrib_phys)
190!#endif
191!      CALL set_bands
192!#ifdef CPP_PHYS
193!      CALL Init_interface_dyn_phys
194!#endif
195      CALL barrier
196
197      CALL set_bands
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
206!c$OMP PARALLEL
207!      call initcomgeomphy
208!c$OMP END PARALLEL
209#endif
210
211!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
212! Initialisation de XIOS
213!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
214
215
216c
217c Initialisations pour Cp(T) Venus
218      call ini_cpdet
219c
220c-----------------------------------------------------------------------
221c   Choix du calendrier
222c   -------------------
223
224c      calend = 'earth_365d'
225
226#ifdef CPP_IOIPSL
227      if (calend == 'earth_360d') then
228        call ioconf_calendar('360d')
229        write(lunout,*)'CALENDRIER CHOISI: Terrestre a 360 jours/an'
230      else if (calend == 'earth_365d') then
231        call ioconf_calendar('noleap')
232        write(lunout,*)'CALENDRIER CHOISI: Terrestre a 365 jours/an'
233      else if (calend == 'earth_366d') then
234        call ioconf_calendar('gregorian')
235        write(lunout,*)'CALENDRIER CHOISI: Terrestre bissextile'
236      else if (calend == 'titan') then
237!        call ioconf_calendar('titan')
238        write(lunout,*)'CALENDRIER CHOISI: Titan'
239        abort_message = 'A FAIRE...'
240        call abort_gcm(modname,abort_message,1)
241      else if (calend == 'venus') then
242!        call ioconf_calendar('venus')
243        write(lunout,*)'CALENDRIER CHOISI: Venus'
244        abort_message = 'A FAIRE...'
245        call abort_gcm(modname,abort_message,1)
246      else
247        abort_message = 'Mauvais choix de calendrier'
248        call abort_gcm(modname,abort_message,1)
249      endif
250#endif
251c-----------------------------------------------------------------------
252c   Initialisation des traceurs
253c   ---------------------------
254c  Choix du nombre de traceurs et du schema pour l'advection
255c  dans fichier traceur.def, par default ou via INCA
256      call infotrac_init
257
258c Allocation de la tableau q : champs advectes   
259      ALLOCATE(q(ip1jmp1,llm,nqtot))
260
261c-----------------------------------------------------------------------
262c   Lecture de l'etat initial :
263c   ---------------------------
264
265c  lecture du fichier start.nc
266      if (read_start) then
267      ! we still need to run iniacademic to initialize some
268      ! constants & fields, if we run the 'newtonian' or 'SW' cases:
269        if (iflag_phys.ne.1) then
270          CALL iniacademic(vcov,ucov,teta,q,masse,ps,phis,time_0)
271        endif
272
273        CALL dynetat0("start.nc",vcov,ucov,
274     &              teta,q,masse,ps,phis, time_0)
275       
276        ! Load relaxation fields (simple nudging). AS 09/2013
277        ! ---------------------------------------------------
278        if (planet_type.eq."generic") then
279         if (ok_guide) then
280           CALL relaxetat0("relax.nc")
281         endif
282        endif
283 
284c       write(73,*) 'ucov',ucov
285c       write(74,*) 'vcov',vcov
286c       write(75,*) 'teta',teta
287c       write(76,*) 'ps',ps
288c       write(77,*) 'q',q
289
290      endif ! of if (read_start)
291
292c le cas echeant, creation d un etat initial
293      IF (prt_level > 9) WRITE(lunout,*)
294     .              'GCM: AVANT iniacademic AVANT AVANT AVANT AVANT'
295      if (.not.read_start) then
296         CALL iniacademic(vcov,ucov,teta,q,masse,ps,phis,time_0)
297      endif
298
299
300c-----------------------------------------------------------------------
301c   Lecture des parametres de controle pour la simulation :
302c   -------------------------------------------------------
303c  on recalcule eventuellement le pas de temps
304
305      IF(MOD(day_step,iperiod).NE.0) THEN
306        abort_message =
307     .  'Il faut choisir un nb de pas par jour multiple de iperiod'
308        call abort_gcm(modname,abort_message,1)
309      ENDIF
310
311      IF(MOD(day_step,iphysiq).NE.0) THEN
312        abort_message =
313     * 'Il faut choisir un nb de pas par jour multiple de iphysiq'
314        call abort_gcm(modname,abort_message,1)
315      ENDIF
316
317      zdtvr    = daysec/REAL(day_step)
318        IF(dtvr.NE.zdtvr) THEN
319         WRITE(lunout,*)
320     .    'WARNING!!! changement de pas de temps',dtvr,'>',zdtvr
321        ENDIF
322
323C
324C on remet le calendrier à zero si demande
325c
326      IF (start_time /= starttime) then
327        WRITE(lunout,*)' GCM: Attention l''heure de depart lue dans le'
328     &,' fichier restart ne correspond pas à celle lue dans le run.def'
329        IF (raz_date == 1) then
330          WRITE(lunout,*)'Je prends l''heure lue dans run.def'
331          start_time = starttime
332        ELSE
333          call abort_gcm("gcm", "'Je m''arrete'", 1)
334        ENDIF
335      ENDIF
336      IF (raz_date == 1) THEN
337        annee_ref = anneeref
338        day_ref = dayref
339        day_ini = dayref
340        itau_dyn = 0
341        itau_phy = 0
342        time_0 = 0.
343        write(lunout,*)
344     .   'GCM: On reinitialise a la date lue dans gcm.def'
345      ELSE IF (annee_ref .ne. anneeref .or. day_ref .ne. dayref) THEN
346        write(lunout,*)
347     .  'GCM: Attention les dates initiales lues dans le fichier'
348        write(lunout,*)
349     .  ' restart ne correspondent pas a celles lues dans '
350        write(lunout,*)' gcm.def'
351        write(lunout,*)' annee_ref=',annee_ref," anneeref=",anneeref
352        write(lunout,*)' day_ref=',day_ref," dayref=",dayref
353        write(lunout,*)' Pas de remise a zero'
354      ENDIF
355
356c      if (annee_ref .ne. anneeref .or. day_ref .ne. dayref) then
357c        write(lunout,*)
358c     .  'GCM: Attention les dates initiales lues dans le fichier'
359c        write(lunout,*)
360c     .  ' restart ne correspondent pas a celles lues dans '
361c        write(lunout,*)' gcm.def'
362c        write(lunout,*)' annee_ref=',annee_ref," anneeref=",anneeref
363c        write(lunout,*)' day_ref=',day_ref," dayref=",dayref
364c        if (raz_date .ne. 1) then
365c          write(lunout,*)
366c     .    'GCM: On garde les dates du fichier restart'
367c        else
368c          annee_ref = anneeref
369c          day_ref = dayref
370c          day_ini = dayref
371c          itau_dyn = 0
372c          itau_phy = 0
373c          time_0 = 0.
374c          write(lunout,*)
375c     .   'GCM: On reinitialise a la date lue dans gcm.def'
376c        endif
377c      ELSE
378c        raz_date = 0
379c      endif
380
381#ifdef CPP_IOIPSL
382      mois = 1
383      heure = 0.
384! Ce n'est defini pour l'instant que pour la Terre...
385      if (planet_type.eq.'earth') then
386      call ymds2ju(annee_ref, mois, day_ref, heure, jD_ref)
387      jH_ref = jD_ref - int(jD_ref)
388      jD_ref = int(jD_ref)
389
390      call ioconf_startdate(INT(jD_ref), jH_ref)
391
392      write(lunout,*)'DEBUG'
393      write(lunout,*)'annee_ref, mois, day_ref, heure, jD_ref'
394      write(lunout,*)annee_ref, mois, day_ref, heure, jD_ref
395      call ju2ymds(jD_ref+jH_ref,an, mois, jour, heure)
396      write(lunout,*)'jD_ref+jH_ref,an, mois, jour, heure'
397      write(lunout,*)jD_ref+jH_ref,an, mois, jour, heure
398      else
399! A voir pour Titan et Venus
400        jD_ref=0
401        jH_ref=0
402      write(lunout,*)'A VOIR POUR VENUS ET TITAN: jD_ref, jH_ref'
403      write(lunout,*)jD_ref,jH_ref
404      endif ! planet_type
405#else
406! Ehouarn: we still need to define JD_ref and JH_ref
407! and since we don't know how many days there are in a year
408! we set JD_ref to 0 (this should be improved ...)
409      jD_ref=0
410      jH_ref=0
411#endif
412
413      if (iflag_phys.eq.1) then
414      ! these initialisations have already been done (via iniacademic)
415      ! if running in SW or Newtonian mode
416c-----------------------------------------------------------------------
417c   Initialisation des constantes dynamiques :
418c   ------------------------------------------
419        dtvr = zdtvr
420        CALL iniconst
421
422c-----------------------------------------------------------------------
423c   Initialisation de la geometrie :
424c   --------------------------------
425        CALL inigeom
426
427c-----------------------------------------------------------------------
428c   Initialisation du filtre :
429c   --------------------------
430        CALL inifilr
431      endif ! of if (iflag_phys.eq.1)
432c
433c-----------------------------------------------------------------------
434c   Initialisation de la dissipation :
435c   ----------------------------------
436
437      CALL inidissip( lstardis, nitergdiv, nitergrot, niterh   ,
438     *                tetagdiv, tetagrot , tetatemp, vert_prof_dissip)
439
440c-----------------------------------------------------------------------
441c   Initialisation de la physique :
442c   -------------------------------
443
444      IF ((iflag_phys==1).or.(iflag_phys>=100)) THEN
445!         latfi(1)=rlatu(1)
446!         lonfi(1)=0.
447!         zcufi(1) = cu(1)
448!         zcvfi(1) = cv(1)
449!         DO j=2,jjm
450!            DO i=1,iim
451!               latfi((j-2)*iim+1+i)= rlatu(j)
452!               lonfi((j-2)*iim+1+i)= rlonv(i)
453!               zcufi((j-2)*iim+1+i) = cu((j-1)*iip1+i)
454!               zcvfi((j-2)*iim+1+i) = cv((j-1)*iip1+i)
455!            ENDDO
456!         ENDDO
457!         latfi(ngridmx)= rlatu(jjp1)
458!         lonfi(ngridmx)= 0.
459!         zcufi(ngridmx) = cu(ip1jm+1)
460!         zcvfi(ngridmx) = cv(ip1jm-iim)
461
462         ! build airefi(), mesh area on physics grid
463!         CALL gr_dyn_fi(1,iip1,jjp1,ngridmx,aire,airefi)
464         ! Poles are single points on physics grid
465!         airefi(1)=airefi(1)*iim
466!         airefi(ngridmx)=airefi(ngridmx)*iim
467
468! Physics
469#ifdef CPP_PHYS
470!         CALL iniphysiq(ngridmx,llm,daysec,day_ini,dtphys/nsplit_phys,
471!     &                latfi,lonfi,airefi,zcufi,zcvfi,rad,g,r,cpp,
472!     &                iflag_phys)
473         CALL iniphysiq(iim,jjm,llm,
474     &                distrib_phys(mpi_rank),comm_lmdz,
475     &                daysec,day_ini,dtphys/nsplit_phys,
476     &                rlatu,rlatv,rlonu,rlonv,aire,cu,cv,rad,g,r,cpp,
477     &                iflag_phys)
478#endif
479!         call_iniphys=.false.
480      ENDIF ! of IF (call_iniphys.and.(iflag_phys==1.or.iflag_phys>=100))
481
482
483c-----------------------------------------------------------------------
484c   Initialisation des I/O :
485c   ------------------------
486
487
488      if (nday>=0) then ! standard case
489        day_end=day_ini+nday
490      else ! special case when nday <0, run -nday dynamical steps
491        day_end=day_ini-nday/day_step
492      endif
493      if (less1day) then
494        day_end=day_ini+floor(time_0+fractday)
495      endif
496      if (ndynstep.gt.0) then
497        day_end=day_ini+floor(time_0+float(ndynstep)/float(day_step))
498      endif
499     
500      WRITE(lunout,'(a,i7,a,i7)')
501     &             "run from day ",day_ini,"  to day",day_end
502
503#ifdef CPP_IOIPSL
504! Ce n'est defini pour l'instant que pour la Terre...
505      if (planet_type.eq.'earth') then
506      call ju2ymds(jD_ref + day_ini - day_ref, an, mois, jour, heure)
507      write (lunout,301)jour, mois, an
508      call ju2ymds(jD_ref + day_end - day_ref, an, mois, jour, heure)
509      write (lunout,302)jour, mois, an
510      else
511! A voir pour Titan et Venus
512      write(lunout,*)'A VOIR POUR VENUS/TITAN: separation en annees...'
513      endif ! planet_type
514
515 301  FORMAT('1'/,15x,'run du ', i2,'/',i2,'/',i4)
516 302  FORMAT('1'/,15x,'    au ', i2,'/',i2,'/',i4)
517#endif
518
519      if (planet_type=="mars") then
520         ! For Mars we transmit day_ini
521        CALL dynredem0_p("restart.nc", day_ini, phis)
522      else
523        CALL dynredem0_p("restart.nc", day_end, phis)
524      endif
525      ecripar = .TRUE.
526
527#ifdef CPP_IOIPSL
528      time_step = zdtvr
529      IF (mpi_rank==0) then
530        if (ok_dyn_ins) then
531        ! initialize output file for instantaneous outputs
532        ! t_ops = iecri * daysec ! do operations every t_ops
533        t_ops =((1.0*iecri)/day_step) * daysec 
534        t_wrt = daysec ! iecri * daysec ! write output every t_wrt
535        CALL inithist(day_ref,annee_ref,time_step,
536     &                  t_ops,t_wrt)
537        endif
538
539        IF (ok_dyn_ave) THEN
540          ! initialize output file for averaged outputs
541          t_ops = iperiod * time_step ! do operations every t_ops
542          t_wrt = periodav * daysec   ! write output every t_wrt
543          CALL initdynav(day_ref,annee_ref,time_step,
544     &                   t_ops,t_wrt)
545!         CALL initdynav_p(dynhistave_file,day_ref,annee_ref,time_step,
546!     .        t_ops, t_wrt, histaveid)
547        END IF
548      ENDIF
549      dtav = iperiod*dtvr/daysec
550#endif
551! #endif of #ifdef CPP_IOIPSL
552
553c  Choix des frequences de stokage pour le offline
554c      istdyn=day_step/4     ! stockage toutes les 6h=1jour/4
555c      istdyn=day_step/12     ! stockage toutes les 2h=1jour/12
556      istdyn=day_step/4     ! stockage toutes les 6h=1jour/12
557      istphy=istdyn/iphysiq     
558
559
560c
561c-----------------------------------------------------------------------
562c   Integration temporelle du modele :
563c   ----------------------------------
564
565c       write(78,*) 'ucov',ucov
566c       write(78,*) 'vcov',vcov
567c       write(78,*) 'teta',teta
568c       write(78,*) 'ps',ps
569c       write(78,*) 'q',q
570
571!c$OMP PARALLEL DEFAULT(SHARED) COPYIN(/temps/,/logici/,/logicl/)
572!variable temps no longer exists
573c$OMP PARALLEL DEFAULT(SHARED)
574c       Copy all threadprivate variables from temps_mod
575c$OMP1 COPYIN(dt,jD_ref,jH_ref,start_time,hour_ini,day_ini,day_end)
576c$OMP1 COPYIN(annee_ref,day_ref,itau_dyn,itau_phy,itaufin,calend)
577c       Copy all threadprivate variables from logic_mod
578c$OMP1 COPYIN(purmats,forward,leapf,apphys,statcl,conser,apdiss,apdelq)
579c$OMP1 COPYIN(saison,ecripar,fxyhypb,ysinus,read_start,ok_guide)
580c$OMP1 COPYIN(ok_strato,tidal,ok_gradsfile,ok_limit,ok_etat0)
581c$OMP1 COPYIN(iflag_phys,iflag_trac)
582
583
584      CALL leapfrog_p(ucov,vcov,teta,ps,masse,phis,q,
585     .              time_0)
586c$OMP END PARALLEL
587
588
589      END
590
Note: See TracBrowser for help on using the repository browser.