source: dynamico_lmdz/aquaplanet/LMDZ5/libf/phydev/physiq_mod.F90 @ 4249

Last change on this file since 4249 was 4028, checked in by millour, 8 years ago

Rearrange ICOSAGCM/Physics interface so that multiple different LMDZ physics packages may be used.
So far only interfaces with 'lmd' and 'dev' physics are handled.
Added a 'DEV_PHYSICS' directory with sample def and xml files to test correct integration with 'dev' physics.
EM

File size: 7.0 KB
Line 
1! $Id: physiq.F 1565 2011-08-31 12:53:29Z jghattas $
2MODULE physiq_mod
3
4IMPLICIT NONE
5
6CONTAINS
7
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
15      USE dimphy, only : klon,klev
16      USE infotrac_phy, only : nqtot
17      USE geometry_mod, 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 mod_phys_lmdz_para, only : jj_nb
22      USE phys_state_var_mod, only : phys_state_var_init
23      USE mod_grid_phy_lmdz, ONLY: nbp_lon,nbp_lat
24      USE mod_phys_lmdz_omp_data, ONLY: is_omp_master
25      USE write_field_phy, ONLY: writefield_phy
26
27#ifdef CPP_XIOS
28      USE xios, ONLY: xios_update_calendar, xios_context_finalize
29      USE wxios, only: wxios_add_vaxis, wxios_set_cal, wxios_closedef
30      USE iophy, ONLY: histwrite_phy
31#endif
32
33      IMPLICIT none
34!
35! Routine argument:
36!
37      integer,intent(in) :: nlon ! number of atmospheric colums
38      integer,intent(in) :: nlev ! number of vertical levels (should be =klev)
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
57
58integer,save :: itau=0 ! counter to count number of calls to physics
59!$OMP THREADPRIVATE(itau)
60real :: temp_newton(klon,klev)
61integer :: k
62logical, save :: first=.true.
63!$OMP THREADPRIVATE(first)
64
65! For I/Os
66integer :: itau0
67real :: zjulian
68real :: dtime
69integer :: nhori ! horizontal coordinate ID
70integer,save :: nid_hist ! output file ID
71!$OMP THREADPRIVATE(nid_hist)
72integer :: zvertid ! vertical coordinate ID
73integer,save :: iwrite_phys ! output every iwrite_phys physics step
74!$OMP THREADPRIVATE(iwrite_phys)
75integer,save :: iwrite_phys_omp ! intermediate variable to read iwrite_phys
76                                ! (must be shared by all threads)
77real :: t_ops ! frequency of the IOIPSL operations (eg average over...)
78real :: t_wrt ! frequency of the IOIPSL outputs
79
80! initializations
81if (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")
85
86! Initialize outputs:
87  itau0=0
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
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
101#ifndef CPP_IOIPSL_NO_OUTPUT
102  ! Initialize IOIPSL output file
103  call histbeg_phy("histins.nc",itau0,zjulian,dtime,nhori,nid_hist)
104#endif
105
106!$OMP MASTER
107
108#ifndef CPP_IOIPSL_NO_OUTPUT
109! IOIPSL
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', &
115               nbp_lon,jj_nb,nhori,klev,1,klev,zvertid,32, &
116               'inst(X)',t_ops,t_wrt)
117  call histdef(nid_hist,'u','Eastward Zonal Wind','m/s', &
118               nbp_lon,jj_nb,nhori,klev,1,klev,zvertid,32, &
119               'inst(X)',t_ops,t_wrt)
120  call histdef(nid_hist,'v','Northward Meridional Wind','m/s', &
121               nbp_lon,jj_nb,nhori,klev,1,klev,zvertid,32, &
122               'inst(X)',t_ops,t_wrt)
123  call histdef(nid_hist,'ps','Surface Pressure','Pa', &
124               nbp_lon,jj_nb,nhori,1,1,1,zvertid,32, &
125               'inst(X)',t_ops,t_wrt)
126  ! end definition sequence
127  call histend(nid_hist)
128#endif
129
130#ifdef CPP_XIOS
131!XIOS
132    ! Declare available vertical axes to be used in output files:   
133    CALL wxios_add_vaxis("presnivs", klev, presnivs)
134
135    ! Declare calendar and time step
136    CALL wxios_set_cal(dtime,"earth_360d",1,1,1,0.0,1,1,1,0.0)
137   
138    !Finalize the context:
139    CALL wxios_closedef()
140#endif
141!$OMP END MASTER
142!$OMP BARRIER
143endif ! of if (debut)
144
145! increment local time counter itau
146itau=itau+1
147
148! set all tendencies to zero
149d_u(1:klon,1:klev)=0.
150d_v(1:klon,1:klev)=0.
151d_t(1:klon,1:klev)=0.
152d_qx(1:klon,1:klev,1:nqtot)=0.
153d_ps(1:klon)=0.
154
155! compute tendencies to return to the dynamics:
156! "friction" on the first layer
157d_u(1:klon,1)=-u(1:klon,1)/86400.
158d_v(1:klon,1)=-v(1:klon,1)/86400.
159! newtonian relaxation towards temp_newton()
160do k=1,klev
161  temp_newton(1:klon,k)=280.+cos(latitude(1:klon))*40.-pphi(1:klon,k)/rg*6.e-3
162  d_t(1:klon,k)=(temp_newton(1:klon,k)-t(1:klon,k))/1.e5
163enddo
164
165
166print*,'PHYDEV: itau=',itau
167
168! write some outputs:
169! IOIPSL
170#ifndef CPP_IOIPSL_NO_OUTPUT
171if (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))
176endif
177#endif
178
179!XIOS
180#ifdef CPP_XIOS
181!$OMP MASTER
182    !Increment XIOS time
183    CALL xios_update_calendar(itau)
184!$OMP END MASTER
185!$OMP BARRIER
186
187    !Send fields to XIOS: (NB these fields must also be defined as
188    ! <field id="..." /> in iodef.xml to be correctly used
189    CALL histwrite_phy("temperature",t)
190    CALL histwrite_phy("temp_newton",temp_newton)
191    CALL histwrite_phy("u",u)
192    CALL histwrite_phy("v",v)
193    CALL histwrite_phy("ps",paprs(:,1))
194#endif
195
196! if lastcall, then it is time to write "restartphy.nc" file
197if (lafin) then
198  call phyredem("restartphy.nc")
199#ifdef CPP_XIOS
200  IF (is_omp_master) CALL xios_context_finalize
201#endif
202endif
203
204end subroutine physiq
205
206END MODULE physiq_mod
Note: See TracBrowser for help on using the repository browser.