| 1 | ! $Id: physiq.F 1565 2011-08-31 12:53:29Z jghattas $ |
|---|
| 2 | MODULE physiq_mod |
|---|
| 3 | USE dimphy, only : klon,klev |
|---|
| 4 | |
|---|
| 5 | IMPLICIT NONE |
|---|
| 6 | PRIVATE |
|---|
| 7 | SAVE |
|---|
| 8 | |
|---|
| 9 | REAL, PARAMETER :: oneday = 86400. ! hard-coded |
|---|
| 10 | |
|---|
| 11 | INTEGER :: itau=0 ! counter to count number of calls to physics |
|---|
| 12 | !$OMP THREADPRIVATE(itau) |
|---|
| 13 | INTEGER :: nid_hist ! NetCDF ID of output file |
|---|
| 14 | !$OMP THREADPRIVATE(nid_hist) |
|---|
| 15 | |
|---|
| 16 | INTEGER :: iwrite_phys ! output every iwrite_phys physics step |
|---|
| 17 | |
|---|
| 18 | PUBLIC :: physiq |
|---|
| 19 | |
|---|
| 20 | CONTAINS |
|---|
| 21 | |
|---|
| 22 | SUBROUTINE physiq (nlon,nlev, & |
|---|
| 23 | & debut,lafin,pdtphys, & |
|---|
| 24 | & paprs,pplay,pphi,pphis,presnivs, & |
|---|
| 25 | & u,v,t,qx, & |
|---|
| 26 | & flxmass_w, & |
|---|
| 27 | & d_u, d_v, d_t, d_qx, d_ps) |
|---|
| 28 | |
|---|
| 29 | USE infotrac_phy, only : nqtot |
|---|
| 30 | USE iophys, ONLY : iophys_ini |
|---|
| 31 | USE phyparam_mod, ONLY : phyparam |
|---|
| 32 | ! |
|---|
| 33 | ! Routine argument: |
|---|
| 34 | ! |
|---|
| 35 | integer,intent(in) :: nlon ! number of atmospheric colums |
|---|
| 36 | integer,intent(in) :: nlev ! number of vertical levels (should be =klev) |
|---|
| 37 | logical,intent(in) :: debut ! signals first call to physics |
|---|
| 38 | logical,intent(in) :: lafin ! signals last call to physics |
|---|
| 39 | real,intent(in) :: pdtphys ! physics time step (s) |
|---|
| 40 | real,intent(in) :: paprs(klon,klev+1) ! interlayer pressure (Pa) |
|---|
| 41 | real,intent(in) :: pplay(klon,klev) ! mid-layer pressure (Pa) |
|---|
| 42 | real,intent(in) :: pphi(klon,klev) ! geopotential at mid-layer |
|---|
| 43 | real,intent(in) :: pphis(klon) ! surface geopotential |
|---|
| 44 | real,intent(in) :: presnivs(klev) ! pseudo-pressure (Pa) of mid-layers |
|---|
| 45 | real,intent(in) :: u(klon,klev) ! eastward zonal wind (m/s) |
|---|
| 46 | real,intent(in) :: v(klon,klev) ! northward meridional wind (m/s) |
|---|
| 47 | real,intent(in) :: t(klon,klev) ! temperature (K) |
|---|
| 48 | real,intent(in) :: qx(klon,klev,nqtot) ! tracers (.../kg_air) |
|---|
| 49 | real,intent(in) :: flxmass_w(klon,klev) ! vertical mass flux |
|---|
| 50 | real,intent(out) :: d_u(klon,klev) ! physics tendency on u (m/s/s) |
|---|
| 51 | real,intent(out) :: d_v(klon,klev) ! physics tendency on v (m/s/s) |
|---|
| 52 | real,intent(out) :: d_t(klon,klev) ! physics tendency on t (K/s) |
|---|
| 53 | real,intent(out) :: d_qx(klon,klev,nqtot) ! physics tendency on tracers |
|---|
| 54 | real,intent(out) :: d_ps(klon) ! physics tendency on surface pressure |
|---|
| 55 | |
|---|
| 56 | logical, save :: first=.true. |
|---|
| 57 | !$OMP THREADPRIVATE(first) |
|---|
| 58 | |
|---|
| 59 | ! For I/Os |
|---|
| 60 | REAL,SAVE :: rjourvrai=0. |
|---|
| 61 | REAL,SAVE :: gmtime=0. |
|---|
| 62 | !$OMP THREADPRIVATE(rjourvrai,gmtime) |
|---|
| 63 | |
|---|
| 64 | ! initializations |
|---|
| 65 | if (debut) CALL init_physiq_mod(pdtphys, presnivs) ! Things to do only for the first call to physics |
|---|
| 66 | |
|---|
| 67 | ! increment local time counter itau |
|---|
| 68 | itau=itau+1 |
|---|
| 69 | gmtime=gmtime+pdtphys/oneday |
|---|
| 70 | IF (gmtime>=1.) THEN |
|---|
| 71 | gmtime=gmtime-1. |
|---|
| 72 | rjourvrai=rjourvrai+1. |
|---|
| 73 | ENDIF |
|---|
| 74 | |
|---|
| 75 | IF(debut) CALL iophys_ini('phys.nc ',presnivs) ! calls iotd_ini |
|---|
| 76 | |
|---|
| 77 | CALL phyparam(klon,klev, & |
|---|
| 78 | debut,lafin, & |
|---|
| 79 | rjourvrai,gmtime,pdtphys, & |
|---|
| 80 | paprs,pplay,pphi, & |
|---|
| 81 | u,v,t, & |
|---|
| 82 | d_u,d_v,d_t,d_ps) |
|---|
| 83 | |
|---|
| 84 | IF(lafin) THEN |
|---|
| 85 | call iotd_fin |
|---|
| 86 | PRINT*,'Ecriture du fichier de reinitialiastion de la physique' |
|---|
| 87 | ! write(75) tsurf,tsoil FIXME |
|---|
| 88 | ENDIF |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | print*,'PHYDEV: itau=',itau |
|---|
| 92 | |
|---|
| 93 | CALL write_hist(paprs, t, u, v) ! write some outputs |
|---|
| 94 | |
|---|
| 95 | ! if lastcall, then it is time to write "restartphy.nc" file |
|---|
| 96 | IF (lafin) CALL phyredem("restartphy.nc") |
|---|
| 97 | |
|---|
| 98 | END SUBROUTINE physiq |
|---|
| 99 | |
|---|
| 100 | SUBROUTINE init_physiq_mod(dtime, presnivs) |
|---|
| 101 | USE iophy, only : histbeg_phy |
|---|
| 102 | USE phys_state_var_mod, only : phys_state_var_init |
|---|
| 103 | USE ioipsl, only : getin,histvert,histdef,histend,ymds2ju |
|---|
| 104 | USE mod_phys_lmdz_para, only : jj_nb |
|---|
| 105 | USE mod_grid_phy_lmdz, ONLY: nbp_lon,nbp_lat |
|---|
| 106 | REAL, INTENT(IN) :: dtime |
|---|
| 107 | REAL, INTENT(IN) :: presnivs(klev) ! pseudo-pressure (Pa) of mid-layers |
|---|
| 108 | |
|---|
| 109 | ! For I/Os |
|---|
| 110 | INTEGER, PARAMETER :: itau0=0, annee0=1979, month=1, dayref=1 |
|---|
| 111 | REAL, PARAMETER :: hour=0.0 |
|---|
| 112 | INTEGER :: nid_hori ! NetCDF ID of horizontal coordinate |
|---|
| 113 | INTEGER :: nid_vert ! NetCDF ID of vertical coordinate |
|---|
| 114 | REAL :: t_ops ! frequency of the IOIPSL operations (eg average over...) |
|---|
| 115 | REAL :: t_wrt ! frequency of the IOIPSL outputs |
|---|
| 116 | REAL :: zjulian |
|---|
| 117 | |
|---|
| 118 | ! load initial conditions for physics (including the grid) |
|---|
| 119 | call phys_state_var_init() ! some initializations, required before calling phyetat0 |
|---|
| 120 | call phyetat0("startphy.nc") |
|---|
| 121 | |
|---|
| 122 | ! Initialize outputs: |
|---|
| 123 | |
|---|
| 124 | ! NB: getin() is not threadsafe; only one thread should call it. |
|---|
| 125 | !$OMP MASTER |
|---|
| 126 | iwrite_phys=1 !default: output every physics timestep |
|---|
| 127 | call getin("iwrite_phys",iwrite_phys) |
|---|
| 128 | !$OMP END MASTER |
|---|
| 129 | !$OMP BARRIER |
|---|
| 130 | |
|---|
| 131 | t_ops=dtime*iwrite_phys ! frequency of the IOIPSL operation |
|---|
| 132 | t_wrt=dtime*iwrite_phys ! frequency of the outputs in the file |
|---|
| 133 | |
|---|
| 134 | ! compute zjulian for annee0=1979 and month=1 dayref=1 and hour=0.0 |
|---|
| 135 | CALL ymds2ju(annee0, month, dayref, hour, zjulian) |
|---|
| 136 | #ifndef CPP_IOIPSL_NO_OUTPUT |
|---|
| 137 | ! Initialize IOIPSL output file |
|---|
| 138 | call histbeg_phy("histins.nc",itau0,zjulian,dtime,nid_hori,nid_hist) |
|---|
| 139 | #endif |
|---|
| 140 | |
|---|
| 141 | !$OMP MASTER |
|---|
| 142 | |
|---|
| 143 | #ifndef CPP_IOIPSL_NO_OUTPUT |
|---|
| 144 | ! IOIPSL |
|---|
| 145 | ! define vertical coordinate |
|---|
| 146 | call histvert(nid_hist,"presnivs","Vertical levels","Pa",klev, & |
|---|
| 147 | presnivs,nid_vert,'down') |
|---|
| 148 | ! define variables which will be written in "histins.nc" file |
|---|
| 149 | call histdef(nid_hist,'temperature','Atmospheric temperature','K', & |
|---|
| 150 | nbp_lon,jj_nb,nid_hori,klev,1,klev,nid_vert,32, & |
|---|
| 151 | 'inst(X)',t_ops,t_wrt) |
|---|
| 152 | call histdef(nid_hist,'u','Eastward Zonal Wind','m/s', & |
|---|
| 153 | nbp_lon,jj_nb,nid_hori,klev,1,klev,nid_vert,32, & |
|---|
| 154 | 'inst(X)',t_ops,t_wrt) |
|---|
| 155 | call histdef(nid_hist,'v','Northward Meridional Wind','m/s', & |
|---|
| 156 | nbp_lon,jj_nb,nid_hori,klev,1,klev,nid_vert,32, & |
|---|
| 157 | 'inst(X)',t_ops,t_wrt) |
|---|
| 158 | call histdef(nid_hist,'ps','Surface Pressure','Pa', & |
|---|
| 159 | nbp_lon,jj_nb,nid_hori,1,1,1,nid_vert,32, & |
|---|
| 160 | 'inst(X)',t_ops,t_wrt) |
|---|
| 161 | ! end definition sequence |
|---|
| 162 | call histend(nid_hist) |
|---|
| 163 | #endif |
|---|
| 164 | |
|---|
| 165 | #ifdef CPP_XIOS |
|---|
| 166 | !XIOS |
|---|
| 167 | ! Declare available vertical axes to be used in output files: |
|---|
| 168 | CALL wxios_add_vaxis("presnivs", klev, presnivs) |
|---|
| 169 | |
|---|
| 170 | ! Declare calendar and time step |
|---|
| 171 | CALL wxios_set_cal(dtime,"earth_360d",1,1,1,0.0,1,1,1,0.0) |
|---|
| 172 | |
|---|
| 173 | !Finalize the context: |
|---|
| 174 | CALL wxios_closedef() |
|---|
| 175 | #endif |
|---|
| 176 | !$OMP END MASTER |
|---|
| 177 | !$OMP BARRIER |
|---|
| 178 | END SUBROUTINE init_physiq_mod |
|---|
| 179 | |
|---|
| 180 | SUBROUTINE write_hist(paprs, t, u, v) |
|---|
| 181 | USE iophy, only : histwrite_phy |
|---|
| 182 | #ifdef CPP_XIOS |
|---|
| 183 | USE xios, ONLY: xios_update_calendar |
|---|
| 184 | USE wxios, only: wxios_add_vaxis, wxios_set_cal, wxios_closedef |
|---|
| 185 | USE iophy, ONLY: histwrite_phy |
|---|
| 186 | #endif |
|---|
| 187 | REAL, INTENT(IN) :: paprs(klon,klev+1), & ! interlayer pressure (Pa) |
|---|
| 188 | & t(klon,klev), & ! temperature (K) |
|---|
| 189 | & u(klon,klev), & ! eastward zonal wind (m/s) |
|---|
| 190 | & v(klon,klev) ! northward meridional wind (m/s) |
|---|
| 191 | ! output using IOIPSL |
|---|
| 192 | #ifndef CPP_IOIPSL_NO_OUTPUT |
|---|
| 193 | if (modulo(itau,iwrite_phys)==0) then |
|---|
| 194 | call histwrite_phy(nid_hist,.false.,"temperature",itau,t) |
|---|
| 195 | call histwrite_phy(nid_hist,.false.,"u",itau,u) |
|---|
| 196 | call histwrite_phy(nid_hist,.false.,"v",itau,v) |
|---|
| 197 | call histwrite_phy(nid_hist,.false.,"ps",itau,paprs(:,1)) |
|---|
| 198 | endif |
|---|
| 199 | #endif |
|---|
| 200 | |
|---|
| 201 | ! output using XIOS |
|---|
| 202 | #ifdef CPP_XIOS |
|---|
| 203 | !$OMP MASTER |
|---|
| 204 | !Increment XIOS time |
|---|
| 205 | CALL xios_update_calendar(itau) |
|---|
| 206 | !$OMP END MASTER |
|---|
| 207 | !$OMP BARRIER |
|---|
| 208 | |
|---|
| 209 | !Send fields to XIOS: (NB these fields must also be defined as |
|---|
| 210 | ! <field id="..." /> in iodef.xml to be correctly used |
|---|
| 211 | CALL histwrite_phy("temperature",t) |
|---|
| 212 | CALL histwrite_phy("temp_newton",temp_newton) |
|---|
| 213 | CALL histwrite_phy("u",u) |
|---|
| 214 | CALL histwrite_phy("v",v) |
|---|
| 215 | CALL histwrite_phy("ps",paprs(:,1)) |
|---|
| 216 | #endif |
|---|
| 217 | |
|---|
| 218 | END SUBROUTINE write_hist |
|---|
| 219 | |
|---|
| 220 | END MODULE physiq_mod |
|---|