source: LMDZ6/branches/Amaury_dev/libf/phydev/physiq_mod.F90 @ 5327

Last change on this file since 5327 was 5160, checked in by abarral, 3 months ago

Put .h into modules

  • 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
File size: 7.3 KB
RevLine 
[1615]1! $Id: physiq.F 1565 2011-08-31 12:53:29Z jghattas $
[2418]2MODULE physiq_mod
[1615]3
[5160]4  IMPLICIT NONE
[2418]5
6CONTAINS
7
[5160]8  SUBROUTINE physiq(nlon, nlev, &
9          debut, lafin, pdtphys, &
10          paprs, pplay, pphi, pphis, presnivs, &
11          u, v, t, qx, &
12          flxmass_w, &
13          d_u, d_v, d_t, d_qx, d_ps)
[1615]14
[5160]15    USE dimphy, ONLY: klon, klev
16    USE infotrac_phy, ONLY: nqtot
17    USE lmdz_geometry, ONLY: latitude
18    USE comcstphy, ONLY: rg
19    USE iophy, ONLY: histbeg_phy, histwrite_phy
20    USE ioipsl, ONLY: getin, histvert, histdef, histend, ymds2ju
21    USE lmdz_phys_para, ONLY: jj_nb
22    USE phys_state_var_mod, ONLY: phys_state_var_init
23    USE lmdz_grid_phy, ONLY: nbp_lon, nbp_lat
[1615]24
[5160]25    USE lmdz_xios, ONLY: xios_update_calendar, using_xios
26    USE lmdz_wxios, ONLY: wxios_add_vaxis, wxios_set_cal, wxios_closedef
27    USE iophy, ONLY: histwrite_phy
[1852]28
[5160]29    IMPLICIT NONE
[5099]30
[5160]31    ! Routine argument:
[5099]32
[5160]33    INTEGER, INTENT(IN) :: nlon ! number of atmospheric colums
34    INTEGER, INTENT(IN) :: nlev ! number of vertical levels (should be =klev)
35    LOGICAL, INTENT(IN) :: debut ! signals first CALL to physics
36    LOGICAL, INTENT(IN) :: lafin ! signals last CALL to physics
37    REAL, INTENT(IN) :: pdtphys ! physics time step (s)
38    REAL, INTENT(IN) :: paprs(klon, klev + 1) ! interlayer pressure (Pa)
39    REAL, INTENT(IN) :: pplay(klon, klev) ! mid-layer pressure (Pa)
40    REAL, INTENT(IN) :: pphi(klon, klev) ! geopotential at mid-layer
41    REAL, INTENT(IN) :: pphis(klon) ! surface geopotential
42    REAL, INTENT(IN) :: presnivs(klev) ! pseudo-pressure (Pa) of mid-layers
43    REAL, INTENT(IN) :: u(klon, klev) ! eastward zonal wind (m/s)
44    REAL, INTENT(IN) :: v(klon, klev) ! northward meridional wind (m/s)
45    REAL, INTENT(IN) :: t(klon, klev) ! temperature (K)
46    REAL, INTENT(IN) :: qx(klon, klev, nqtot) ! tracers (.../kg_air)
47    REAL, INTENT(IN) :: flxmass_w(klon, klev) ! vertical mass flux
48    REAL, INTENT(OUT) :: d_u(klon, klev) ! physics tendency on u (m/s/s)
49    REAL, INTENT(OUT) :: d_v(klon, klev) ! physics tendency on v (m/s/s)
50    REAL, INTENT(OUT) :: d_t(klon, klev) ! physics tendency on t (K/s)
51    REAL, INTENT(OUT) :: d_qx(klon, klev, nqtot) ! physics tendency on tracers
52    REAL, INTENT(OUT) :: d_ps(klon) ! physics tendency on surface pressure
[1615]53
[5160]54    INTEGER, save :: itau = 0 ! counter to count number of calls to physics
55    !$OMP THREADPRIVATE(itau)
56    REAL :: temp_newton(klon, klev)
57    INTEGER :: k
58    logical, save :: first = .TRUE.
59    !$OMP THREADPRIVATE(first)
[1615]60
[5160]61    ! For I/Os
62    INTEGER :: itau0
63    REAL :: zjulian
64    REAL :: dtime
65    INTEGER :: nhori ! horizontal coordinate ID
66    INTEGER, save :: nid_hist ! output file ID
67    !$OMP THREADPRIVATE(nid_hist)
68    INTEGER :: zvertid ! vertical coordinate ID
69    INTEGER, save :: iwrite_phys ! output every iwrite_phys physics step
70    !$OMP THREADPRIVATE(iwrite_phys)
71    INTEGER, save :: iwrite_phys_omp ! intermediate variable to read iwrite_phys
72    ! (must be shared by all threads)
73    REAL :: t_ops ! frequency of the IOIPSL operations (eg average over...)
74    REAL :: t_wrt ! frequency of the IOIPSL outputs
[1615]75
[5160]76    ! initializations
77    IF (debut) then ! Things to do only for the first CALL to physics
78      ! load initial conditions for physics (including the grid)
79      CALL phys_state_var_init() ! some initializations, required before calling phyetat0
80      CALL phyetat0("startphy.nc")
[1615]81
[5160]82      ! Initialize outputs:
83      itau0 = 0
84      !$OMP MASTER
85      iwrite_phys_omp = 1 !default: output every physics timestep
86      ! NB: getin() is not threadsafe; only one thread should CALL it.
87      CALL getin("iwrite_phys", iwrite_phys_omp)
88      !$OMP END MASTER
89      !$OMP BARRIER
90      iwrite_phys = iwrite_phys_omp
91      t_ops = pdtphys * iwrite_phys ! frequency of the IOIPSL operation
92      t_wrt = pdtphys * iwrite_phys ! frequency of the outputs in the file
93      ! compute zjulian for annee0=1979 and month=1 dayref=1 and hour=0.0
94      !CALL ymds2ju(annee0, month, dayref, hour, zjulian)
95      CALL ymds2ju(1979, 1, 1, 0.0, zjulian)
96      dtime = pdtphys
[2097]97#ifndef CPP_IOIPSL_NO_OUTPUT
[5160]98      ! Initialize IOIPSL output file
99      CALL histbeg_phy("histins.nc", itau0, zjulian, dtime, nhori, nid_hist)
[1882]100#endif
[1852]101
[5160]102      !$OMP MASTER
[1852]103
[2097]104#ifndef CPP_IOIPSL_NO_OUTPUT
[5160]105      ! IOIPSL
106      ! define vertical coordinate
107      CALL histvert(nid_hist, "presnivs", "Vertical levels", "Pa", klev, &
108              presnivs, zvertid, 'down')
109      ! define variables which will be written in "histins.nc" file
110      CALL histdef(nid_hist, 'temperature', 'Atmospheric temperature', 'K', &
111              nbp_lon, jj_nb, nhori, klev, 1, klev, zvertid, 32, &
112              'inst(X)', t_ops, t_wrt)
113      CALL histdef(nid_hist, 'u', 'Eastward Zonal Wind', 'm/s', &
114              nbp_lon, jj_nb, nhori, klev, 1, klev, zvertid, 32, &
115              'inst(X)', t_ops, t_wrt)
116      CALL histdef(nid_hist, 'v', 'Northward Meridional Wind', 'm/s', &
117              nbp_lon, jj_nb, nhori, klev, 1, klev, zvertid, 32, &
118              'inst(X)', t_ops, t_wrt)
119      CALL histdef(nid_hist, 'ps', 'Surface Pressure', 'Pa', &
120              nbp_lon, jj_nb, nhori, 1, 1, 1, zvertid, 32, &
121              'inst(X)', t_ops, t_wrt)
122      ! end definition sequence
123      CALL histend(nid_hist)
[1882]124#endif
[1852]125
[5160]126      IF (using_xios) THEN
127        !XIOS
128        ! Declare available vertical axes to be used in output files:
129        CALL wxios_add_vaxis("presnivs", klev, presnivs)
[1852]130
[5160]131        ! Declare calendar and time step
132        CALL wxios_set_cal(dtime, "earth_360d", 1, 1, 1, 0.0, 1, 1, 1, 0.0)
[1615]133
[5160]134        !Finalize the context:
135        CALL wxios_closedef()
136      ENDIF
137      !$OMP END MASTER
138      !$OMP BARRIER
139    END IF ! of if (debut)
[1686]140
[5160]141    ! increment local time counter itau
142    itau = itau + 1
[1615]143
[5160]144    ! set all tendencies to zero
145    d_u(1:klon, 1:klev) = 0.
146    d_v(1:klon, 1:klev) = 0.
147    d_t(1:klon, 1:klev) = 0.
148    d_qx(1:klon, 1:klev, 1:nqtot) = 0.
149    d_ps(1:klon) = 0.
[1671]150
[5160]151    ! compute tendencies to return to the dynamics:
152    ! "friction" on the first layer
153    d_u(1:klon, 1) = -u(1:klon, 1) / 86400.
154    d_v(1:klon, 1) = -v(1:klon, 1) / 86400.
155    ! newtonian relaxation towards temp_newton()
156    DO k = 1, klev
157      temp_newton(1:klon, k) = 280. + cos(latitude(1:klon)) * 40. - pphi(1:klon, k) / rg * 6.e-3
158      d_t(1:klon, k) = (temp_newton(1:klon, k) - t(1:klon, k)) / 1.e5
159    END DO
[1671]160
[5160]161    PRINT*, 'PHYDEV: itau=', itau
[1671]162
[5160]163    ! write some outputs:
164    ! IOIPSL
[2097]165#ifndef CPP_IOIPSL_NO_OUTPUT
[5160]166    IF (modulo(itau, iwrite_phys)==0) THEN
167      CALL histwrite_phy(nid_hist, .FALSE., "temperature", itau, t)
168      CALL histwrite_phy(nid_hist, .FALSE., "u", itau, u)
169      CALL histwrite_phy(nid_hist, .FALSE., "v", itau, v)
170      CALL histwrite_phy(nid_hist, .FALSE., "ps", itau, paprs(:, 1))
171    END IF
[1882]172#endif
[1686]173
[5160]174    !XIOS
175    IF (using_xios) THEN
176      !$OMP MASTER
177      !Increment XIOS time
178      CALL xios_update_calendar(itau)
179      !$OMP END MASTER
180      !$OMP BARRIER
[1852]181
[5160]182      !Send fields to XIOS: (NB these fields must also be defined as
183      ! <field id="..." /> in iodef.xml to be correctly used
184      CALL histwrite_phy("temperature", t)
185      CALL histwrite_phy("temp_newton", temp_newton)
186      CALL histwrite_phy("u", u)
187      CALL histwrite_phy("v", v)
188      CALL histwrite_phy("ps", paprs(:, 1))
189    ENDIF
[1852]190
[5160]191    ! if lastcall, then it is time to write "restartphy.nc" file
192    IF (lafin) THEN
193      CALL phyredem("restartphy.nc")
194    END IF
[1671]195
[5160]196  END SUBROUTINE  physiq
[2418]197
198END MODULE physiq_mod
Note: See TracBrowser for help on using the repository browser.