source: codes/icosagcm/branches/SATURN_DYNAMICO/LMDZ.COMMON/libf/dyn3dpar/init_gcm_lmdz.F @ 242

Last change on this file since 242 was 242, checked in by ymipsl, 10 years ago

calling iniphysics directly from dynamico

YM

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