Changeset 5160 for LMDZ6/branches/Amaury_dev/libf/phydev/physiq_mod.F90
- Timestamp:
- Aug 3, 2024, 2:56:58 PM (7 weeks ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
LMDZ6/branches/Amaury_dev/libf/phydev/physiq_mod.F90
r5134 r5160 2 2 MODULE physiq_mod 3 3 4 IMPLICIT NONE4 IMPLICIT NONE 5 5 6 6 CONTAINS 7 7 8 SUBROUTINE physiq(nlon,nlev, &9 debut,lafin,pdtphys, &10 paprs,pplay,pphi,pphis,presnivs, &11 u,v,t,qx, &12 13 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) 14 14 15 USE dimphy, ONLY: klon,klev16 17 18 19 USE iophy, ONLY: histbeg_phy,histwrite_phy20 USE ioipsl, ONLY: getin,histvert,histdef,histend,ymds2ju21 22 23 USE lmdz_grid_phy, ONLY: nbp_lon,nbp_lat15 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 24 24 25 26 27 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 28 28 29 29 IMPLICIT NONE 30 30 31 ! Routine argument:31 ! Routine argument: 32 32 33 INTEGER,INTENT(IN) :: nlon ! number of atmospheric colums34 INTEGER,INTENT(IN) :: nlev ! number of vertical levels (should be =klev)35 logical,INTENT(IN) :: debut ! signals first CALL to physics36 logical,INTENT(IN) :: lafin ! signals last CALL to physics37 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-layer41 REAL,INTENT(IN) :: pphis(klon) ! surface geopotential42 REAL,INTENT(IN) :: presnivs(klev) ! pseudo-pressure (Pa) of mid-layers43 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 flux48 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 tracers52 REAL,INTENT(OUT) :: d_ps(klon) ! physics tendency on surface pressure33 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 53 53 54 INTEGER,save :: itau=0 ! counter to count number of calls to physics55 !$OMP THREADPRIVATE(itau)56 REAL :: temp_newton(klon,klev)57 INTEGER :: k58 logical, save :: first=.TRUE.59 !$OMP THREADPRIVATE(first)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) 60 60 61 ! For I/Os62 INTEGER :: itau063 REAL :: zjulian64 REAL :: dtime65 INTEGER :: nhori ! horizontal coordinate ID66 INTEGER,save :: nid_hist ! output file ID67 !$OMP THREADPRIVATE(nid_hist)68 INTEGER :: zvertid ! vertical coordinate ID69 INTEGER,save :: iwrite_phys ! output every iwrite_phys physics step70 !$OMP THREADPRIVATE(iwrite_phys)71 INTEGER,save :: iwrite_phys_omp ! intermediate variable to read iwrite_phys72 73 REAL :: t_ops ! frequency of the IOIPSL operations (eg average over...)74 REAL :: t_wrt ! frequency of the IOIPSL outputs61 ! 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 75 75 76 ! initializations77 IF (debut) then ! Things to do only for the first CALL to physics78 ! load initial conditions for physics (including the grid)79 CALL phys_state_var_init() ! some initializations, required before calling phyetat080 CALL phyetat0("startphy.nc")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") 81 81 82 ! Initialize outputs:83 itau0=084 !$OMP MASTER85 iwrite_phys_omp=1 !default: output every physics timestep86 ! NB: getin() is not threadsafe; only one thread should CALL it.87 CALL getin("iwrite_phys",iwrite_phys_omp)88 !$OMP END MASTER89 !$OMP BARRIER90 iwrite_phys=iwrite_phys_omp91 t_ops=pdtphys*iwrite_phys ! frequency of the IOIPSL operation92 t_wrt=pdtphys*iwrite_phys ! frequency of the outputs in the file93 ! compute zjulian for annee0=1979 and month=1 dayref=1 and hour=0.094 !CALL ymds2ju(annee0, month, dayref, hour, zjulian)95 CALL ymds2ju(1979, 1, 1, 0.0, zjulian)96 dtime=pdtphys82 ! 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 97 97 #ifndef CPP_IOIPSL_NO_OUTPUT 98 ! Initialize IOIPSL output file99 CALL histbeg_phy("histins.nc",itau0,zjulian,dtime,nhori,nid_hist)98 ! Initialize IOIPSL output file 99 CALL histbeg_phy("histins.nc", itau0, zjulian, dtime, nhori, nid_hist) 100 100 #endif 101 101 102 !$OMP MASTER102 !$OMP MASTER 103 103 104 104 #ifndef CPP_IOIPSL_NO_OUTPUT 105 ! IOIPSL106 ! define vertical coordinate107 CALL histvert(nid_hist,"presnivs","Vertical levels","Pa",klev, &108 presnivs,zvertid,'down')109 ! define variables which will be written in "histins.nc" file110 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 sequence123 CALL histend(nid_hist)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) 124 124 #endif 125 125 126 IF (using_xios) THEN127 !XIOS128 ! Declare available vertical axes to be used in output files:129 CALL wxios_add_vaxis("presnivs", klev, presnivs)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) 130 130 131 ! Declare calendar and time step 132 CALL wxios_set_cal(dtime,"earth_360d",1,1,1,0.0,1,1,1,0.0) 133 134 !Finalize the context: 135 CALL wxios_closedef() 136 ENDIF 137 !$OMP END MASTER 138 !$OMP BARRIER 139 END IF ! of if (debut) 131 ! Declare calendar and time step 132 CALL wxios_set_cal(dtime, "earth_360d", 1, 1, 1, 0.0, 1, 1, 1, 0.0) 140 133 141 ! increment local time counter itau 142 itau=itau+1 134 !Finalize the context: 135 CALL wxios_closedef() 136 ENDIF 137 !$OMP END MASTER 138 !$OMP BARRIER 139 END IF ! of if (debut) 143 140 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. 141 ! increment local time counter itau 142 itau = itau + 1 150 143 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 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. 160 150 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 161 160 162 PRINT*,'PHYDEV: itau=',itau161 PRINT*, 'PHYDEV: itau=', itau 163 162 164 ! write some outputs:165 ! IOIPSL163 ! write some outputs: 164 ! IOIPSL 166 165 #ifndef CPP_IOIPSL_NO_OUTPUT 167 IF (modulo(itau,iwrite_phys)==0) THEN168 CALL histwrite_phy(nid_hist,.FALSE.,"temperature",itau,t)169 CALL histwrite_phy(nid_hist,.FALSE.,"u",itau,u)170 CALL histwrite_phy(nid_hist,.FALSE.,"v",itau,v)171 CALL histwrite_phy(nid_hist,.FALSE.,"ps",itau,paprs(:,1))172 END IF166 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 173 172 #endif 174 173 175 !XIOS176 IF (using_xios) THEN177 !$OMP MASTER178 !Increment XIOS time179 CALL xios_update_calendar(itau)180 !$OMP END MASTER181 !$OMP BARRIER174 !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 182 181 183 !Send fields to XIOS: (NB these fields must also be defined as184 ! <field id="..." /> in iodef.xml to be correctly used185 CALL histwrite_phy("temperature",t)186 CALL histwrite_phy("temp_newton",temp_newton)187 CALL histwrite_phy("u",u)188 CALL histwrite_phy("v",v)189 CALL histwrite_phy("ps",paprs(:,1))190 ENDIF182 !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 191 190 192 ! if lastcall, then it is time to write "restartphy.nc" file193 IF (lafin) THEN194 CALL phyredem("restartphy.nc")195 END IF191 ! if lastcall, then it is time to write "restartphy.nc" file 192 IF (lafin) THEN 193 CALL phyredem("restartphy.nc") 194 END IF 196 195 197 END SUBROUTINE physiq196 END SUBROUTINE physiq 198 197 199 198 END MODULE physiq_mod
Note: See TracChangeset
for help on using the changeset viewer.