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

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

Remove CPP_IOIPSL cpp keys uses

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