source: LMDZ6/trunk/libf/dyn3dmem/gcm.F90 @ 5278

Last change on this file since 5278 was 5272, checked in by abarral, 2 days ago

Turn paramet.h into a module

  • Property copyright set to
    Name of program: LMDZ
    Creation date: 1984
    Version: LMDZ5
    License: CeCILL version 2
    Holder: Laboratoire de m\'et\'eorologie dynamique, CNRS, UMR 8539
    See the license file in the root directory
  • Property svn:keywords set to Id
File size: 15.1 KB
Line 
1!
2! $Id: gcm.F90 5272 2024-10-24 15:53:15Z abarral $
3!
4
5PROGRAM gcm
6
7  USE IOIPSL
8
9  USE mod_const_mpi, ONLY: init_const_mpi
10  USE parallel_lmdz
11  USE infotrac, ONLY: nqtot, init_infotrac
12!#ifdef CPP_PHYS
13!  USE mod_interface_dyn_phys, ONLY: init_interface_dyn_phys
14!#endif
15  USE mod_hallo
16  USE Bands
17  USE filtreg_mod
18  USE control_mod
19
20  USE iniphysiq_mod, ONLY: iniphysiq
21  USE comconst_mod, ONLY: cpp, daysec, dtphys, dtvr, g, r, rad
22  USE logic_mod ! all of it, because of copyin clause when calling leapfrog
23  USE temps_mod, ONLY: calend,start_time,annee_ref,day_ref, &
24                       itau_dyn,itau_phy,day_ini,jD_ref,jH_ref,day_end, &
25                       dt,hour_ini,itaufin
26  USE mod_xios_dyn3dmem, ONLY: xios_dyn3dmem_init
27  USE lmdz_cppkeys_wrapper, ONLY: CPPKEY_PHYS
28  USE dimensions_mod, ONLY: iim, jjm, llm, ndm
29  USE paramet_mod_h, ONLY: iip1, iip2, iip3, jjp1, llmp1, llmp2, llmm1, kftd, ip1jm, ip1jmp1, &
30          ip1jmi1, ijp1llm, ijmllm, mvar, jcfil, jcfllm
31IMPLICIT NONE
32
33  !      ......   Version  du 10/01/98    ..........
34
35  !             avec  coordonnees  verticales hybrides
36  !   avec nouveaux operat. dissipation * ( gradiv2,divgrad2,nxgraro2 )
37
38  !=======================================================================
39  !
40  !   Auteur:  P. Le Van /L. Fairhead/F.Hourdin
41  !   -------
42  !
43  !   Objet:
44  !   ------
45  !
46  !   GCM LMD nouvelle grille
47  !
48  !=======================================================================
49  !
50  !  ... Dans inigeom , nouveaux calculs pour les elongations  cu , cv
51  !      et possibilite d'appeler une fonction f(y)  a derivee tangente
52  !      hyperbolique a la  place de la fonction a derivee sinusoidale.
53  !  ... Possibilite de choisir le schema pour l'advection de
54  !        q  , en modifiant iadv dans traceur.def  (MAF,10/02) .
55  !
56  !      Pour Van-Leer + Vapeur d'eau saturee, iadv(1)=4. (F.Codron,10/99)
57  !      Pour Van-Leer iadv=10
58  !
59  !-----------------------------------------------------------------------
60  !   Declarations:
61  !   -------------
62  include "comdissnew.h"
63  include "comgeom.h"
64  include "description.h"
65  include "iniprint.h"
66  include "tracstoke.h"
67
68
69  REAL zdtvr
70
71  !   variables dynamiques
72  REAL,ALLOCATABLE,SAVE  :: vcov(:,:),ucov(:,:) ! vents covariants
73  REAL,ALLOCATABLE,SAVE  :: teta(:,:)     ! temperature potentielle
74  REAL, ALLOCATABLE,SAVE :: q(:,:,:)      ! champs advectes
75  REAL,ALLOCATABLE,SAVE  :: ps(:)         ! pression  au sol
76  !      REAL p (ip1jmp1,llmp1  )               ! pression aux interfac.des couches
77  REAL,ALLOCATABLE,SAVE  :: masse(:,:)    ! masse d'air
78  REAL,ALLOCATABLE,SAVE  :: phis(:)       ! geopotentiel au sol
79  !      REAL phi(ip1jmp1,llm)                  ! geopotentiel
80  !      REAL w(ip1jmp1,llm)                    ! vitesse verticale
81
82  ! variables dynamiques intermediaire pour le transport
83
84  !   variables pour le fichier histoire
85  REAL dtav      ! intervalle de temps elementaire
86
87  REAL time_0
88
89  LOGICAL lafin
90
91  real time_step, t_wrt, t_ops
92
93  !+jld variables test conservation energie
94  !      REAL ecin(ip1jmp1,llm),ecin0(ip1jmp1,llm)
95  !     Tendance de la temp. potentiel d (theta)/ d t due a la
96  !     tansformation d'energie cinetique en energie thermique
97  !     cree par la dissipation
98  !      REAL dhecdt(ip1jmp1,llm)
99  !      REAL vcont(ip1jm,llm),ucont(ip1jmp1,llm)
100  !      REAL      d_h_vcol, d_qt, d_qw, d_ql, d_ec
101  !      CHARACTER (len=15) :: ztit
102  !-jld
103
104
105  character (len=80) :: dynhist_file, dynhistave_file
106  character (len=20) :: modname
107  character (len=80) :: abort_message
108  ! locales pour gestion du temps
109  INTEGER :: an, mois, jour
110  REAL :: heure
111  ! needed for xios interface
112  character (len=10) :: xios_cal_type
113  INTEGER :: anref, moisref, jourref
114  REAL :: heureref
115 
116
117
118  !-----------------------------------------------------------------------
119  !   Initialisations:
120  !   ----------------
121
122  abort_message = 'last timestep reached'
123  modname = 'gcm'
124  descript = 'Run GCM LMDZ'
125  lafin    = .FALSE.
126  dynhist_file = 'dyn_hist'
127  dynhistave_file = 'dyn_hist_ave'
128
129
130
131  !----------------------------------------------------------------------
132  !  lecture des fichiers gcm.def ou run.def
133  !  ---------------------------------------
134  !
135  CALL conf_gcm( 99, .TRUE. )
136  if (mod(iphysiq, iperiod) /= 0) call abort_gcm("conf_gcm", &
137       "iphysiq must be a multiple of iperiod", 1)
138  !
139  !
140  !------------------------------------
141  !   Initialisation partie parallele
142  !------------------------------------
143  CALL init_const_mpi
144
145  call init_parallel
146  call Read_Distrib
147
148!#ifdef CPP_PHYS
149!  CALL Init_Phys_lmdz(iim,jjp1,llm,mpi_size,distrib_phys)
150  !#endif
151  !      CALL set_bands
152  !#ifdef CPP_PHYS
153!  CALL Init_interface_dyn_phys
154!#endif
155  CALL barrier
156
157  CALL set_bands
158  if (mpi_rank==0) call WriteBands
159  call Set_Distrib(distrib_caldyn)
160
161  !$OMP PARALLEL
162  call Init_Mod_hallo
163  !$OMP END PARALLEL
164
165  !#ifdef CPP_PHYS
166  !c$OMP PARALLEL
167  !      call InitComgeomphy ! now done in iniphysiq
168  !c$OMP END PARALLEL
169  !#endif
170
171  !-----------------------------------------------------------------------
172  !   Choix du calendrier
173  !   -------------------
174
175  !      calend = 'earth_365d'
176
177  if (calend == 'earth_360d') then
178     call ioconf_calendar('360_day')
179     write(lunout,*)'CALENDRIER CHOISI: Terrestre a 360 jours/an'
180     xios_cal_type='d360'
181  else if (calend == 'earth_365d') then
182     call ioconf_calendar('noleap')
183     write(lunout,*)'CALENDRIER CHOISI: Terrestre a 365 jours/an'
184     xios_cal_type='noleap'
185  else if (calend == 'gregorian') then
186     call ioconf_calendar('gregorian')
187     write(lunout,*)'CALENDRIER CHOISI: Terrestre bissextile'
188     xios_cal_type='gregorian'
189  else
190     abort_message = 'Mauvais choix de calendrier'
191     call abort_gcm(modname,abort_message,1)
192  endif
193
194
195
196  !-----------------------------------------------------------------------
197  !   Initialisation des traceurs
198  !   ---------------------------
199  !  Choix du nombre de traceurs et du schema pour l'advection
200  !  dans fichier traceur.def, par default ou via INCA
201  call init_infotrac
202
203  ! Allocation de la tableau q : champs advectes   
204  ALLOCATE(ucov(ijb_u:ije_u,llm))
205  ALLOCATE(vcov(ijb_v:ije_v,llm))
206  ALLOCATE(teta(ijb_u:ije_u,llm))
207  ALLOCATE(masse(ijb_u:ije_u,llm))
208  ALLOCATE(ps(ijb_u:ije_u))
209  ALLOCATE(phis(ijb_u:ije_u))
210  ALLOCATE(q(ijb_u:ije_u,llm,nqtot))
211
212  !-----------------------------------------------------------------------
213  !   Lecture de l'etat initial :
214  !   ---------------------------
215
216  !  lecture du fichier start.nc
217  if (read_start) then
218     ! we still need to run iniacademic to initialize some
219     ! constants & fields, if we run the 'newtonian' or 'SW' cases:
220     if (iflag_phys.ne.1) then
221        CALL iniacademic_loc(vcov,ucov,teta,q,masse,ps,phis,time_0)
222     endif
223
224     !        if (planet_type.eq."earth") then
225     ! Load an Earth-format start file
226     CALL dynetat0_loc("start.nc",vcov,ucov, &
227          teta,q,masse,ps,phis, time_0)
228     !        endif ! of if (planet_type.eq."earth")
229
230     !       write(73,*) 'ucov',ucov
231     !       write(74,*) 'vcov',vcov
232     !       write(75,*) 'teta',teta
233     !       write(76,*) 'ps',ps
234     !       write(77,*) 'q',q
235
236  endif ! of if (read_start)
237
238  ! le cas echeant, creation d un etat initial
239  IF (prt_level > 9) WRITE(lunout,*) &
240       'GCM: AVANT iniacademic AVANT AVANT AVANT AVANT'
241  if (.not.read_start) then
242     start_time=0.
243     annee_ref=anneeref
244     CALL iniacademic_loc(vcov,ucov,teta,q,masse,ps,phis,time_0)
245  endif
246
247  !-----------------------------------------------------------------------
248  !   Lecture des parametres de controle pour la simulation :
249  !   -------------------------------------------------------
250  !  on recalcule eventuellement le pas de temps
251
252  IF(MOD(day_step,iperiod).NE.0) THEN
253     abort_message =  &
254          'Il faut choisir un nb de pas par jour multiple de iperiod'
255     call abort_gcm(modname,abort_message,1)
256  ENDIF
257
258  IF(MOD(day_step,iphysiq).NE.0) THEN
259     abort_message =  &
260          'Il faut choisir un nb de pas par jour multiple de iphysiq'
261     call abort_gcm(modname,abort_message,1)
262  ENDIF
263
264  zdtvr    = daysec/REAL(day_step)
265  IF(dtvr.NE.zdtvr) THEN
266     WRITE(lunout,*) &
267          'WARNING!!! changement de pas de temps',dtvr,'>',zdtvr
268  ENDIF
269
270  !
271  ! on remet le calendrier \`a zero si demande
272  !
273  IF (start_time /= starttime) then
274     WRITE(lunout,*)' GCM: Attention l''heure de depart lue dans le' &
275          ,' fichier restart ne correspond pas a celle lue dans le run.def'
276     IF (raz_date == 1) then
277        WRITE(lunout,*)'Je prends l''heure lue dans run.def'
278        start_time = starttime
279     ELSE
280        WRITE(lunout,*)'Je m''arrete'
281        CALL abort
282     ENDIF
283  ENDIF
284  IF (raz_date == 1) THEN
285     annee_ref = anneeref
286     day_ref = dayref
287     day_ini = dayref
288     itau_dyn = 0
289     itau_phy = 0
290     time_0 = 0.
291     write(lunout,*) &
292          'GCM: On reinitialise a la date lue dans gcm.def'
293  ELSE IF (annee_ref .ne. anneeref .or. day_ref .ne. dayref) THEN
294     write(lunout,*) &
295          'GCM: Attention les dates initiales lues dans le fichier'
296     write(lunout,*) &
297          ' restart ne correspondent pas a celles lues dans '
298     write(lunout,*)' gcm.def'
299     write(lunout,*)' annee_ref=',annee_ref," anneeref=",anneeref
300     write(lunout,*)' day_ref=',day_ref," dayref=",dayref
301     write(lunout,*)' Pas de remise a zero'
302  ENDIF
303  !      if (annee_ref .ne. anneeref .or. day_ref .ne. dayref) then
304  !        write(lunout,*)
305  !     .  'GCM: Attention les dates initiales lues dans le fichier'
306  !        write(lunout,*)
307  !     .  ' restart ne correspondent pas a celles lues dans '
308  !        write(lunout,*)' gcm.def'
309  !        write(lunout,*)' annee_ref=',annee_ref," anneeref=",anneeref
310  !        write(lunout,*)' day_ref=',day_ref," dayref=",dayref
311  !        if (raz_date .ne. 1) then
312  !          write(lunout,*)
313  !     .    'GCM: On garde les dates du fichier restart'
314  !        else
315  !          annee_ref = anneeref
316  !          day_ref = dayref
317  !          day_ini = dayref
318  !          itau_dyn = 0
319  !          itau_phy = 0
320  !          time_0 = 0.
321  !          write(lunout,*)
322  !     .   'GCM: On reinitialise a la date lue dans gcm.def'
323  !        endif
324  !      ELSE
325  !        raz_date = 0
326  !      endif
327
328  mois = 1
329  heure = 0.
330  call ymds2ju(annee_ref, mois, day_ref, heure, jD_ref)
331  jH_ref = jD_ref - int(jD_ref)
332  jD_ref = int(jD_ref)
333
334  call ioconf_startdate(INT(jD_ref), jH_ref)
335
336  write(lunout,*)'DEBUG'
337  write(lunout,*)'annee_ref, mois, day_ref, heure, jD_ref'
338  write(lunout,*)annee_ref, mois, day_ref, heure, jD_ref
339  call ju2ymds(jD_ref+jH_ref,anref, moisref, jourref, heureref)
340  write(lunout,*)'jD_ref+jH_ref,an, mois, jour, heure'
341  write(lunout,*)jD_ref+jH_ref,anref, moisref, jourref, heureref
342
343
344  if (iflag_phys.eq.1) then
345     ! these initialisations have already been done (via iniacademic)
346     ! if running in SW or Newtonian mode
347     !-----------------------------------------------------------------------
348     !   Initialisation des constantes dynamiques :
349     !   ------------------------------------------
350     dtvr = zdtvr
351     CALL iniconst
352
353     !-----------------------------------------------------------------------
354     !   Initialisation de la geometrie :
355     !   --------------------------------
356     CALL inigeom
357
358     !-----------------------------------------------------------------------
359     !   Initialisation du filtre :
360     !   --------------------------
361     CALL inifilr
362  endif ! of if (iflag_phys.eq.1)
363  !
364  !-----------------------------------------------------------------------
365  !   Initialisation de la dissipation :
366  !   ----------------------------------
367
368  CALL inidissip( lstardis, nitergdiv, nitergrot, niterh   , &
369       tetagdiv, tetagrot , tetatemp, vert_prof_dissip)
370
371  !-----------------------------------------------------------------------
372  !   Initialisation des I/O :
373  !   ------------------------
374
375
376  if (nday>=0) then
377     day_end = day_ini + nday
378  else
379     day_end = day_ini - nday/day_step
380  endif
381
382  WRITE(lunout,300)day_ini,day_end
383300 FORMAT('1'/,15x,'run du jour',i7,2x,'au jour',i7//)
384
385  call ju2ymds(jD_ref + day_ini - day_ref, an, mois, jour, heure)
386  write (lunout,301)jour, mois, an
387  call ju2ymds(jD_ref + day_end - day_ref, an, mois, jour, heure)
388  write (lunout,302)jour, mois, an
389301 FORMAT('1'/,15x,'run du ', i2,'/',i2,'/',i4)
390302 FORMAT('1'/,15x,'    au ', i2,'/',i2,'/',i4)
391
392
393  !-----------------------------------------------------------------------
394  !   Initialisation de la physique :
395  !   -------------------------------
396
397  !  Choix des frequences de stokage pour le offline
398  !      istdyn=day_step/4     ! stockage toutes les 6h=1jour/4
399  !      istdyn=day_step/12     ! stockage toutes les 2h=1jour/12
400  istdyn=day_step/8     ! stockage toutes les 6h=1jour/12
401  istphy=istdyn/iphysiq
402
403  IF ((iflag_phys==1).or.(iflag_phys>=100)) THEN
404     ! Physics:
405IF (CPPKEY_PHYS) THEN
406     CALL iniphysiq(iim,jjm,llm, &
407          distrib_phys(mpi_rank),comm_lmdz, &
408          daysec,day_ini,dtphys/nsplit_phys, &
409          rlatu,rlatv,rlonu,rlonv,aire,cu,cv,rad,g,r,cpp, &
410          iflag_phys)
411END IF
412  ENDIF ! of IF ((iflag_phys==1).or.(iflag_phys>=100))
413
414
415  !      if (planet_type.eq."earth") then
416  ! Write an Earth-format restart file
417  CALL dynredem0_loc("restart.nc", day_end, phis)
418  !      endif
419
420  ecripar = .TRUE.
421
422#define CPP_IOIPSL
423  time_step = zdtvr
424     if (ok_dyn_ins) then
425        ! initialize output file for instantaneous outputs
426        ! t_ops = iecri * daysec ! do operations every t_ops
427        t_ops =((1.0*iecri)/day_step) * daysec
428        t_wrt = daysec ! iecri * daysec ! write output every t_wrt
429        CALL inithist_loc(day_ref,annee_ref,time_step, &
430             t_ops,t_wrt)
431     endif
432
433     IF (ok_dyn_ave) THEN
434        ! initialize output file for averaged outputs
435        t_ops = iperiod * time_step ! do operations every t_ops
436        t_wrt = periodav * daysec   ! write output every t_wrt
437        CALL initdynav_loc(day_ref,annee_ref,time_step,t_ops,t_wrt)
438     END IF
439  dtav = iperiod*dtvr/daysec
440
441! setting up DYN3D/XIOS inerface
442  if (ok_dyn_xios) then
443      CALL xios_dyn3dmem_init(xios_cal_type, anref, moisref, jourref,heureref, an,   &
444          mois, jour, heure, zdtvr)
445  endif
446
447  !
448  !-----------------------------------------------------------------------
449  !   Integration temporelle du modele :
450  !   ----------------------------------
451
452  !       write(78,*) 'ucov',ucov
453  !       write(78,*) 'vcov',vcov
454  !       write(78,*) 'teta',teta
455  !       write(78,*) 'ps',ps
456  !       write(78,*) 'q',q
457
458  !!$OMP PARALLEL DEFAULT(SHARED) COPYIN(/temps/,/logici/,/logicl/)
459  !     Copy all threadprivate variables in temps_mod logic_mod
460  !$OMP PARALLEL DEFAULT(SHARED) &
461  !$OMP COPYIN(dt,jD_ref,jH_ref,start_time,hour_ini,day_ini,day_end) &
462  !$OMP COPYIN(annee_ref,day_ref,itau_dyn,itau_phy,itaufin,calend) &
463  !$OMP COPYIN(purmats,forward,leapf,apphys,statcl,conser,apdiss,apdelq) &
464  !$OMP COPYIN(saison,ecripar,fxyhypb,ysinus,read_start,ok_guide) &
465  !$OMP COPYIN(ok_strato,ok_gradsfile,ok_limit,ok_etat0) &
466  !$OMP COPYIN(iflag_phys,iflag_trac,adv_qsat_liq)
467  CALL leapfrog_loc(ucov,vcov,teta,ps,masse,phis,q,time_0)
468  !$OMP END PARALLEL
469
470  !      OPEN(unit=5487,file='ok_lmdz',status='replace')
471  !      WRITE(5487,*) 'ok_lmdz'
472  !      CLOSE(5487)
473END PROGRAM gcm
Note: See TracBrowser for help on using the repository browser.