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

Last change on this file since 1405 was 1395, checked in by emillour, 10 years ago

All GCMS:
Some cleanup and tidying on the dynamics/physics interface.
Essentially affects the "iniphysiq" routine in all physics packages.
EM

File size: 19.2 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      USE mod_interface_dyn_phys
17      USE mod_hallo
18      USE Bands
19      USE getparam
20      USE filtreg_mod
21      USE control_mod, only: planet_type,nday,day_step,iperiod,iphysiq,
22     &                       raz_date,anneeref,starttime,dayref,
23     &                       ok_dyn_ins,ok_dyn_ave,iecri,periodav,
24     &                       less1day,fractday,ndynstep,nsplit_phys
25      use cpdet_mod, only: ini_cpdet
26
27
28#ifdef INCA
29! Only INCA needs these informations (from the Earth's physics)
30      USE indice_sol_mod
31#endif
32
33! Ehouarn: the following are needed with (parallel) physics:
34#ifdef CPP_PHYS
35      USE mod_grid_phy_lmdz
36!      USE mod_phys_lmdz_para, ONLY : klon_mpi_para_nb
37      USE mod_phys_lmdz_omp_data, ONLY: klon_omp
38      USE dimphy
39      USE comgeomphy
40#endif
41      IMPLICIT NONE
42
43c      ......   Version  du 10/01/98    ..........
44
45c             avec  coordonnees  verticales hybrides
46c   avec nouveaux operat. dissipation * ( gradiv2,divgrad2,nxgraro2 )
47
48c=======================================================================
49c
50c   Auteur:  P. Le Van /L. Fairhead/F.Hourdin
51c   -------
52c
53c   Objet:
54c   ------
55c
56c   GCM LMD nouvelle grille
57c
58c=======================================================================
59c
60c  ... Dans inigeom , nouveaux calculs pour les elongations  cu , cv
61c      et possibilite d'appeler une fonction f(y)  a derivee tangente
62c      hyperbolique a la  place de la fonction a derivee sinusoidale.
63c  ... Possibilite de choisir le schema pour l'advection de
64c        q  , en modifiant iadv dans traceur.def  (MAF,10/02) .
65c
66c      Pour Van-Leer + Vapeur d'eau saturee, iadv(1)=4. (F.Codron,10/99)
67c      Pour Van-Leer iadv=10
68c
69c-----------------------------------------------------------------------
70c   Declarations:
71c   -------------
72
73#include "dimensions.h"
74#include "paramet.h"
75#include "comconst.h"
76#include "comdissnew.h"
77#include "comvert.h"
78#include "comgeom.h"
79#include "logic.h"
80#include "temps.h"
81!!!!!!!!!!!#include "control.h"
82#include "ener.h"
83#include "description.h"
84#include "serre.h"
85!#include "com_io_dyn.h"
86#include "iniprint.h"
87#include "tracstoke.h"
88#ifdef INCA
89! Only INCA needs these informations (from the Earth's physics)
90#include "indicesol.h"
91#endif
92
93
94      REAL zdtvr
95
96c   variables dynamiques
97      REAL vcov(ip1jm,llm),ucov(ip1jmp1,llm) ! vents covariants
98      REAL teta(ip1jmp1,llm)                 ! temperature potentielle
99      REAL, ALLOCATABLE, DIMENSION(:,:,:):: q! champs advectes
100      REAL ps(ip1jmp1)                       ! pression  au sol
101c      REAL p (ip1jmp1,llmp1  )               ! pression aux interfac.des couches
102c      REAL pks(ip1jmp1)                      ! exner au  sol
103c      REAL pk(ip1jmp1,llm)                   ! exner au milieu des couches
104c      REAL pkf(ip1jmp1,llm)                  ! exner filt.au milieu des couches
105      REAL masse(ip1jmp1,llm)                ! masse d'air
106      REAL phis(ip1jmp1)                     ! geopotentiel au sol
107c      REAL phi(ip1jmp1,llm)                  ! geopotentiel
108c      REAL w(ip1jmp1,llm)                    ! vitesse verticale
109
110c variables dynamiques intermediaire pour le transport
111
112c   variables pour le fichier histoire
113      REAL dtav      ! intervalle de temps elementaire
114
115      REAL time_0
116
117      LOGICAL lafin
118c      INTEGER ij,iq,l,i,j
119      INTEGER i,j
120
121
122      real time_step, t_wrt, t_ops
123
124
125!      LOGICAL call_iniphys
126!      data call_iniphys/.true./
127
128c      REAL alpha(ip1jmp1,llm),beta(ip1jmp1,llm)
129c+jld variables test conservation energie
130c      REAL ecin(ip1jmp1,llm),ecin0(ip1jmp1,llm)
131C     Tendance de la temp. potentiel d (theta)/ d t due a la
132C     tansformation d'energie cinetique en energie thermique
133C     cree par la dissipation
134c      REAL dhecdt(ip1jmp1,llm)
135c      REAL vcont(ip1jm,llm),ucont(ip1jmp1,llm)
136c      REAL      d_h_vcol, d_qt, d_qw, d_ql, d_ec
137c      CHARACTER (len=15) :: ztit
138c-jld
139
140
141      character (len=80) :: dynhist_file, dynhistave_file
142      character (len=20) :: modname
143      character (len=80) :: abort_message
144! locales pour gestion du temps
145      INTEGER :: an, mois, jour
146      REAL :: heure
147
148
149c-----------------------------------------------------------------------
150c    variables pour l'initialisation de la physique :
151c    ------------------------------------------------
152!      INTEGER ngridmx
153!      PARAMETER( ngridmx = 2+(jjm-1)*iim - 1/jjm   )
154!      REAL zcufi(ngridmx),zcvfi(ngridmx)
155!      REAL latfi(ngridmx),lonfi(ngridmx)
156!      REAL airefi(ngridmx)
157!      SAVE latfi, lonfi, airefi
158     
159      INTEGER :: ierr
160
161
162c-----------------------------------------------------------------------
163c   Initialisations:
164c   ----------------
165
166      abort_message = 'last timestep reached'
167      modname = 'gcm'
168      descript = 'Run GCM LMDZ'
169      lafin    = .FALSE.
170      dynhist_file = 'dyn_hist'
171      dynhistave_file = 'dyn_hist_ave'
172
173
174
175c----------------------------------------------------------------------
176c  lecture des fichiers gcm.def ou run.def
177c  ---------------------------------------
178c
179! Ehouarn: dump possibility of using defrun
180!#ifdef CPP_IOIPSL
181      CALL conf_gcm( 99, .TRUE. )
182      if (mod(iphysiq, iperiod) /= 0) call abort_gcm("conf_gcm",
183     s "iphysiq must be a multiple of iperiod", 1)
184!#else
185!      CALL defrun( 99, .TRUE. , clesphy0 )
186!#endif
187c
188c
189c------------------------------------
190c   Initialisation partie parallele
191c------------------------------------
192
193      CALL init_const_mpi
194      call init_parallel
195      call ini_getparam("out.def")
196      call Read_Distrib
197
198#ifdef CPP_PHYS
199        CALL init_phys_lmdz(iim,jjp1,llm,mpi_size,distrib_phys)
200!#endif
201!      CALL set_bands
202!#ifdef CPP_PHYS
203      CALL Init_interface_dyn_phys
204#endif
205      CALL barrier
206
207      CALL set_bands
208      if (mpi_rank==0) call WriteBands
209      call SetDistrib(jj_Nb_Caldyn)
210
211c$OMP PARALLEL
212      call Init_Mod_hallo
213c$OMP END PARALLEL
214
215#ifdef CPP_PHYS
216!c$OMP PARALLEL
217!      call initcomgeomphy
218!c$OMP END PARALLEL
219#endif
220
221!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
222! Initialisation de XIOS
223!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
224
225
226c
227c Initialisations pour Cp(T) Venus
228      call ini_cpdet
229c
230c-----------------------------------------------------------------------
231c   Choix du calendrier
232c   -------------------
233
234c      calend = 'earth_365d'
235
236#ifdef CPP_IOIPSL
237      if (calend == 'earth_360d') then
238        call ioconf_calendar('360d')
239        write(lunout,*)'CALENDRIER CHOISI: Terrestre a 360 jours/an'
240      else if (calend == 'earth_365d') then
241        call ioconf_calendar('noleap')
242        write(lunout,*)'CALENDRIER CHOISI: Terrestre a 365 jours/an'
243      else if (calend == 'earth_366d') then
244        call ioconf_calendar('gregorian')
245        write(lunout,*)'CALENDRIER CHOISI: Terrestre bissextile'
246      else if (calend == 'titan') then
247!        call ioconf_calendar('titan')
248        write(lunout,*)'CALENDRIER CHOISI: Titan'
249        abort_message = 'A FAIRE...'
250        call abort_gcm(modname,abort_message,1)
251      else if (calend == 'venus') then
252!        call ioconf_calendar('venus')
253        write(lunout,*)'CALENDRIER CHOISI: Venus'
254        abort_message = 'A FAIRE...'
255        call abort_gcm(modname,abort_message,1)
256      else
257        abort_message = 'Mauvais choix de calendrier'
258        call abort_gcm(modname,abort_message,1)
259      endif
260#endif
261c-----------------------------------------------------------------------
262
263      IF (type_trac == 'inca') THEN
264#ifdef INCA
265         call init_const_lmdz(
266     $        nbtr,anneeref,dayref,
267     $        iphysiq,day_step,nday,
268     $        nbsrf, is_oce,is_sic,
269     $        is_ter,is_lic, calend)
270
271         call init_inca_para(
272     $        iim,jjm+1,llm,klon_glo,mpi_size,
273     $        distrib_phys,COMM_LMDZ)
274#endif
275      END IF
276
277c-----------------------------------------------------------------------
278c   Initialisation des traceurs
279c   ---------------------------
280c  Choix du nombre de traceurs et du schema pour l'advection
281c  dans fichier traceur.def, par default ou via INCA
282      call infotrac_init
283
284c Allocation de la tableau q : champs advectes   
285      ALLOCATE(q(ip1jmp1,llm,nqtot))
286
287c-----------------------------------------------------------------------
288c   Lecture de l'etat initial :
289c   ---------------------------
290
291c  lecture du fichier start.nc
292      if (read_start) then
293      ! we still need to run iniacademic to initialize some
294      ! constants & fields, if we run the 'newtonian' or 'SW' cases:
295        if (iflag_phys.ne.1) then
296          CALL iniacademic(vcov,ucov,teta,q,masse,ps,phis,time_0)
297        endif
298
299        CALL dynetat0("start.nc",vcov,ucov,
300     &              teta,q,masse,ps,phis, time_0)
301       
302        ! Load relaxation fields (simple nudging). AS 09/2013
303        ! ---------------------------------------------------
304        if (planet_type.eq."generic") then
305         if (ok_guide) then
306           CALL relaxetat0("relax.nc")
307         endif
308        endif
309 
310c       write(73,*) 'ucov',ucov
311c       write(74,*) 'vcov',vcov
312c       write(75,*) 'teta',teta
313c       write(76,*) 'ps',ps
314c       write(77,*) 'q',q
315
316      endif ! of if (read_start)
317
318c le cas echeant, creation d un etat initial
319      IF (prt_level > 9) WRITE(lunout,*)
320     .              'GCM: AVANT iniacademic AVANT AVANT AVANT AVANT'
321      if (.not.read_start) then
322         CALL iniacademic(vcov,ucov,teta,q,masse,ps,phis,time_0)
323      endif
324
325
326c-----------------------------------------------------------------------
327c   Lecture des parametres de controle pour la simulation :
328c   -------------------------------------------------------
329c  on recalcule eventuellement le pas de temps
330
331      IF(MOD(day_step,iperiod).NE.0) THEN
332        abort_message =
333     .  'Il faut choisir un nb de pas par jour multiple de iperiod'
334        call abort_gcm(modname,abort_message,1)
335      ENDIF
336
337      IF(MOD(day_step,iphysiq).NE.0) THEN
338        abort_message =
339     * 'Il faut choisir un nb de pas par jour multiple de iphysiq'
340        call abort_gcm(modname,abort_message,1)
341      ENDIF
342
343      zdtvr    = daysec/REAL(day_step)
344        IF(dtvr.NE.zdtvr) THEN
345         WRITE(lunout,*)
346     .    'WARNING!!! changement de pas de temps',dtvr,'>',zdtvr
347        ENDIF
348
349C
350C on remet le calendrier à zero si demande
351c
352      IF (start_time /= starttime) then
353        WRITE(lunout,*)' GCM: Attention l''heure de depart lue dans le'
354     &,' fichier restart ne correspond pas à celle lue dans le run.def'
355        IF (raz_date == 1) then
356          WRITE(lunout,*)'Je prends l''heure lue dans run.def'
357          start_time = starttime
358        ELSE
359          call abort_gcm("gcm", "'Je m''arrete'", 1)
360        ENDIF
361      ENDIF
362      IF (raz_date == 1) THEN
363        annee_ref = anneeref
364        day_ref = dayref
365        day_ini = dayref
366        itau_dyn = 0
367        itau_phy = 0
368        time_0 = 0.
369        write(lunout,*)
370     .   'GCM: On reinitialise a la date lue dans gcm.def'
371      ELSE IF (annee_ref .ne. anneeref .or. day_ref .ne. dayref) THEN
372        write(lunout,*)
373     .  'GCM: Attention les dates initiales lues dans le fichier'
374        write(lunout,*)
375     .  ' restart ne correspondent pas a celles lues dans '
376        write(lunout,*)' gcm.def'
377        write(lunout,*)' annee_ref=',annee_ref," anneeref=",anneeref
378        write(lunout,*)' day_ref=',day_ref," dayref=",dayref
379        write(lunout,*)' Pas de remise a zero'
380      ENDIF
381
382c      if (annee_ref .ne. anneeref .or. day_ref .ne. dayref) then
383c        write(lunout,*)
384c     .  'GCM: Attention les dates initiales lues dans le fichier'
385c        write(lunout,*)
386c     .  ' restart ne correspondent pas a celles lues dans '
387c        write(lunout,*)' gcm.def'
388c        write(lunout,*)' annee_ref=',annee_ref," anneeref=",anneeref
389c        write(lunout,*)' day_ref=',day_ref," dayref=",dayref
390c        if (raz_date .ne. 1) then
391c          write(lunout,*)
392c     .    'GCM: On garde les dates du fichier restart'
393c        else
394c          annee_ref = anneeref
395c          day_ref = dayref
396c          day_ini = dayref
397c          itau_dyn = 0
398c          itau_phy = 0
399c          time_0 = 0.
400c          write(lunout,*)
401c     .   'GCM: On reinitialise a la date lue dans gcm.def'
402c        endif
403c      ELSE
404c        raz_date = 0
405c      endif
406
407#ifdef CPP_IOIPSL
408      mois = 1
409      heure = 0.
410! Ce n'est defini pour l'instant que pour la Terre...
411      if (planet_type.eq.'earth') then
412      call ymds2ju(annee_ref, mois, day_ref, heure, jD_ref)
413      jH_ref = jD_ref - int(jD_ref)
414      jD_ref = int(jD_ref)
415
416      call ioconf_startdate(INT(jD_ref), jH_ref)
417
418      write(lunout,*)'DEBUG'
419      write(lunout,*)'annee_ref, mois, day_ref, heure, jD_ref'
420      write(lunout,*)annee_ref, mois, day_ref, heure, jD_ref
421      call ju2ymds(jD_ref+jH_ref,an, mois, jour, heure)
422      write(lunout,*)'jD_ref+jH_ref,an, mois, jour, heure'
423      write(lunout,*)jD_ref+jH_ref,an, mois, jour, heure
424      else
425! A voir pour Titan et Venus
426        jD_ref=0
427        jH_ref=0
428      write(lunout,*)'A VOIR POUR VENUS ET TITAN: jD_ref, jH_ref'
429      write(lunout,*)jD_ref,jH_ref
430      endif ! planet_type
431#else
432! Ehouarn: we still need to define JD_ref and JH_ref
433! and since we don't know how many days there are in a year
434! we set JD_ref to 0 (this should be improved ...)
435      jD_ref=0
436      jH_ref=0
437#endif
438
439      if (iflag_phys.eq.1) then
440      ! these initialisations have already been done (via iniacademic)
441      ! if running in SW or Newtonian mode
442c-----------------------------------------------------------------------
443c   Initialisation des constantes dynamiques :
444c   ------------------------------------------
445        dtvr = zdtvr
446        CALL iniconst
447
448c-----------------------------------------------------------------------
449c   Initialisation de la geometrie :
450c   --------------------------------
451        CALL inigeom
452
453c-----------------------------------------------------------------------
454c   Initialisation du filtre :
455c   --------------------------
456        CALL inifilr
457      endif ! of if (iflag_phys.eq.1)
458c
459c-----------------------------------------------------------------------
460c   Initialisation de la dissipation :
461c   ----------------------------------
462
463      CALL inidissip( lstardis, nitergdiv, nitergrot, niterh   ,
464     *                tetagdiv, tetagrot , tetatemp, vert_prof_dissip)
465
466c-----------------------------------------------------------------------
467c   Initialisation de la physique :
468c   -------------------------------
469
470      IF ((iflag_phys==1).or.(iflag_phys>=100)) THEN
471!         latfi(1)=rlatu(1)
472!         lonfi(1)=0.
473!         zcufi(1) = cu(1)
474!         zcvfi(1) = cv(1)
475!         DO j=2,jjm
476!            DO i=1,iim
477!               latfi((j-2)*iim+1+i)= rlatu(j)
478!               lonfi((j-2)*iim+1+i)= rlonv(i)
479!               zcufi((j-2)*iim+1+i) = cu((j-1)*iip1+i)
480!               zcvfi((j-2)*iim+1+i) = cv((j-1)*iip1+i)
481!            ENDDO
482!         ENDDO
483!         latfi(ngridmx)= rlatu(jjp1)
484!         lonfi(ngridmx)= 0.
485!         zcufi(ngridmx) = cu(ip1jm+1)
486!         zcvfi(ngridmx) = cv(ip1jm-iim)
487
488         ! build airefi(), mesh area on physics grid
489!         CALL gr_dyn_fi(1,iip1,jjp1,ngridmx,aire,airefi)
490         ! Poles are single points on physics grid
491!         airefi(1)=airefi(1)*iim
492!         airefi(ngridmx)=airefi(ngridmx)*iim
493
494! Physics
495#ifdef CPP_PHYS
496!         CALL iniphysiq(ngridmx,llm,daysec,day_ini,dtphys/nsplit_phys,
497!     &                latfi,lonfi,airefi,zcufi,zcvfi,rad,g,r,cpp,
498!     &                iflag_phys)
499         CALL iniphysiq(iim,jjm,llm,daysec,day_ini,dtphys/nsplit_phys,
500     &                rlatu,rlonv,aire,cu,cv,rad,g,r,cpp,
501     &                iflag_phys)
502#endif
503!         call_iniphys=.false.
504      ENDIF ! of IF (call_iniphys.and.(iflag_phys==1.or.iflag_phys>=100))
505
506
507c-----------------------------------------------------------------------
508c   Initialisation des dimensions d'INCA :
509c   --------------------------------------
510      IF (type_trac == 'inca') THEN
511#ifdef INCA
512!$OMP PARALLEL
513         CALL init_inca_dim(klon_omp,llm,iim,jjm,
514     $        rlonu,rlatu,rlonv,rlatv)
515!$OMP END PARALLEL
516#endif
517      END IF
518
519c-----------------------------------------------------------------------
520c   Initialisation des I/O :
521c   ------------------------
522
523
524      if (nday>=0) then ! standard case
525        day_end=day_ini+nday
526      else ! special case when nday <0, run -nday dynamical steps
527        day_end=day_ini-nday/day_step
528      endif
529      if (less1day) then
530        day_end=day_ini+floor(time_0+fractday)
531      endif
532      if (ndynstep.gt.0) then
533        day_end=day_ini+floor(time_0+float(ndynstep)/float(day_step))
534      endif
535     
536      WRITE(lunout,'(a,i7,a,i7)')
537     &             "run from day ",day_ini,"  to day",day_end
538
539#ifdef CPP_IOIPSL
540! Ce n'est defini pour l'instant que pour la Terre...
541      if (planet_type.eq.'earth') then
542      call ju2ymds(jD_ref + day_ini - day_ref, an, mois, jour, heure)
543      write (lunout,301)jour, mois, an
544      call ju2ymds(jD_ref + day_end - day_ref, an, mois, jour, heure)
545      write (lunout,302)jour, mois, an
546      else
547! A voir pour Titan et Venus
548      write(lunout,*)'A VOIR POUR VENUS/TITAN: separation en annees...'
549      endif ! planet_type
550
551 301  FORMAT('1'/,15x,'run du ', i2,'/',i2,'/',i4)
552 302  FORMAT('1'/,15x,'    au ', i2,'/',i2,'/',i4)
553#endif
554
555      if (planet_type=="mars") then
556         ! For Mars we transmit day_ini
557        CALL dynredem0_p("restart.nc", day_ini, phis)
558      else
559        CALL dynredem0_p("restart.nc", day_end, phis)
560      endif
561      ecripar = .TRUE.
562
563#ifdef CPP_IOIPSL
564      time_step = zdtvr
565      IF (mpi_rank==0) then
566        if (ok_dyn_ins) then
567        ! initialize output file for instantaneous outputs
568        ! t_ops = iecri * daysec ! do operations every t_ops
569        t_ops =((1.0*iecri)/day_step) * daysec 
570        t_wrt = daysec ! iecri * daysec ! write output every t_wrt
571        CALL inithist(day_ref,annee_ref,time_step,
572     &                  t_ops,t_wrt)
573        endif
574
575        IF (ok_dyn_ave) THEN
576          ! initialize output file for averaged outputs
577          t_ops = iperiod * time_step ! do operations every t_ops
578          t_wrt = periodav * daysec   ! write output every t_wrt
579          CALL initdynav(day_ref,annee_ref,time_step,
580     &                   t_ops,t_wrt)
581!         CALL initdynav_p(dynhistave_file,day_ref,annee_ref,time_step,
582!     .        t_ops, t_wrt, histaveid)
583        END IF
584      ENDIF
585      dtav = iperiod*dtvr/daysec
586#endif
587! #endif of #ifdef CPP_IOIPSL
588
589c  Choix des frequences de stokage pour le offline
590c      istdyn=day_step/4     ! stockage toutes les 6h=1jour/4
591c      istdyn=day_step/12     ! stockage toutes les 2h=1jour/12
592      istdyn=day_step/4     ! stockage toutes les 6h=1jour/12
593      istphy=istdyn/iphysiq     
594
595
596c
597c-----------------------------------------------------------------------
598c   Integration temporelle du modele :
599c   ----------------------------------
600
601c       write(78,*) 'ucov',ucov
602c       write(78,*) 'vcov',vcov
603c       write(78,*) 'teta',teta
604c       write(78,*) 'ps',ps
605c       write(78,*) 'q',q
606
607!c$OMP PARALLEL DEFAULT(SHARED) COPYIN(/temps/,/logici/,/logicl/)
608!variable temps no longer exists
609c$OMP PARALLEL DEFAULT(SHARED)
610c$OMP1 COPYIN(/temps_r/,/temps_i/,/temps_c/,/logici/,/logicl/)
611      CALL leapfrog_p(ucov,vcov,teta,ps,masse,phis,q,
612     .              time_0)
613c$OMP END PARALLEL
614
615
616      END
617
Note: See TracBrowser for help on using the repository browser.