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