source: LMDZ6/branches/cirrus/libf/phydev/physiq_mod.F90 @ 5322

Last change on this file since 5322 was 4619, checked in by yann meurdesoif, 16 months ago

Suppress usage of preprocessing key CPP_XIOS.
Wrapper file is used to suppress XIOS symbol when xios is not linked and not used (-io ioipsl)
The CPP_XIOS key is replaced in model by "using_xios" boolean variable to switch between IOIPSL or XIOS output.

YM

  • Property copyright set to
    Name of program: LMDZ
    Creation date: 1984
    Version: LMDZ5
    License: CeCILL version 2
    Holder: Laboratoire de m\'et\'eorologie dynamique, CNRS, UMR 8539
    See the license file in the root directory
File size: 6.8 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
25      USE lmdz_xios, ONLY: xios_update_calendar, using_xios
26      USE wxios, only: wxios_add_vaxis, wxios_set_cal, wxios_closedef
27      USE iophy, ONLY: histwrite_phy
28
29      IMPLICIT none
30!
31! Routine argument:
32!
33      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
54integer,save :: itau=0 ! counter to count number of calls to physics
55!$OMP THREADPRIVATE(itau)
56real :: temp_newton(klon,klev)
57integer :: k
58logical, save :: first=.true.
59!$OMP THREADPRIVATE(first)
60
61! For I/Os
62integer :: itau0
63real :: zjulian
64real :: dtime
65integer :: nhori ! horizontal coordinate ID
66integer,save :: nid_hist ! output file ID
67!$OMP THREADPRIVATE(nid_hist)
68integer :: zvertid ! vertical coordinate ID
69integer,save :: iwrite_phys ! output every iwrite_phys physics step
70!$OMP THREADPRIVATE(iwrite_phys)
71integer,save :: iwrite_phys_omp ! intermediate variable to read iwrite_phys
72                                ! (must be shared by all threads)
73real :: t_ops ! frequency of the IOIPSL operations (eg average over...)
74real :: t_wrt ! frequency of the IOIPSL outputs
75
76! initializations
77if (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
82! 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#ifndef CPP_IOIPSL_NO_OUTPUT
98  ! Initialize IOIPSL output file
99  call histbeg_phy("histins.nc",itau0,zjulian,dtime,nhori,nid_hist)
100#endif
101
102!$OMP MASTER
103
104#ifndef CPP_IOIPSL_NO_OUTPUT
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#endif
125
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
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
139endif ! of if (debut)
140
141! increment local time counter itau
142itau=itau+1
143
144! set all tendencies to zero
145d_u(1:klon,1:klev)=0.
146d_v(1:klon,1:klev)=0.
147d_t(1:klon,1:klev)=0.
148d_qx(1:klon,1:klev,1:nqtot)=0.
149d_ps(1:klon)=0.
150
151! compute tendencies to return to the dynamics:
152! "friction" on the first layer
153d_u(1:klon,1)=-u(1:klon,1)/86400.
154d_v(1:klon,1)=-v(1:klon,1)/86400.
155! newtonian relaxation towards temp_newton()
156do 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
159enddo
160
161
162print*,'PHYDEV: itau=',itau
163
164! write some outputs:
165! IOIPSL
166#ifndef CPP_IOIPSL_NO_OUTPUT
167if (modulo(itau,iwrite_phys)==0) then
168  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))
172endif
173#endif
174
175!XIOS
176IF (using_xios) THEN
177  !$OMP MASTER
178    !Increment XIOS time
179    CALL xios_update_calendar(itau)
180  !$OMP END MASTER
181  !$OMP BARRIER
182
183    !Send fields to XIOS: (NB these fields must also be defined as
184    ! <field id="..." /> in iodef.xml to be correctly used
185    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))
190ENDIF
191
192! if lastcall, then it is time to write "restartphy.nc" file
193if (lafin) then
194  call phyredem("restartphy.nc")
195endif
196
197end subroutine physiq
198
199END MODULE physiq_mod
Note: See TracBrowser for help on using the repository browser.