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