source: LMDZ5/trunk/libf/phydev/physiq.F90 @ 1897

Last change on this file since 1897 was 1897, checked in by Ehouarn Millour, 11 years ago

Getting XIOS to work in MPI, OpenMP and mixed MPI/OpenMP modes. Use "-io xios" option with makelmdz or makelmdz_fcm to enable XIOS (this doesn't deactivate IOIPSL outputs; to suppress IOIPSL outputs, add cpp flag CPP_NO_IOIPSL).
EM

File size: 7.0 KB
Line 
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
13      USE dimphy, only : klon,klev
14      USE infotrac, only : nqtot
15      USE comgeomphy, only : rlatd
16      USE comcstphy, only : rg
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
21
22#ifdef CPP_XIOS
23      USE wxios, only: wxios_add_vaxis, wxios_set_timestep, wxios_closedef, &
24                       wxios_update_calendar, histwrite_phy
25#endif
26
27      IMPLICIT none
28#include "dimensions.h"
29
30      integer,parameter :: jjmp1=jjm+1-1/jjm
31      integer,parameter :: iip1=iim+1
32!
33! Routine argument:
34!
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      integer,parameter :: longcles=20
48      real,intent(in) :: clesphy0(longcles) ! Not used
49      real,intent(in) :: u(klon,klev) ! eastward zonal wind (m/s)
50      real,intent(in) :: v(klon,klev) ! northward meridional wind (m/s)
51      real,intent(in) :: t(klon,klev) ! temperature (K)
52      real,intent(in) :: qx(klon,klev,nqtot) ! tracers (.../kg_air)
53      real,intent(in) :: flxmass_w(klon,klev) ! vertical mass flux
54      real,intent(out) :: d_u(klon,klev) ! physics tendency on u (m/s/s)
55      real,intent(out) :: d_v(klon,klev) ! physics tendency on v (m/s/s)
56      real,intent(out) :: d_t(klon,klev) ! physics tendency on t (K/s)
57      real,intent(out) :: d_qx(klon,klev,nqtot) ! physics tendency on tracers
58      real,intent(out) :: d_ps(klon) ! physics tendency on surface pressure
59      real,intent(in) :: dudyn(iim+1,jjmp1,klev) ! Not used
60!FH! REAL PVteta(klon,nbteta)
61!      REAL PVteta(klon,1)
62      real,intent(in) :: PVteta(klon,3) ! Not used ; should match definition
63                                        ! in calfis.F
64
65integer,save :: itau=0 ! counter to count number of calls to physics
66!$OMP THREADPRIVATE(itau)
67real :: temp_newton(klon,klev)
68integer :: k
69logical, save :: first=.true.
70!$OMP THREADPRIVATE(first)
71
72! For I/Os
73integer :: itau0
74real :: zjulian
75real :: dtime
76integer :: nhori ! horizontal coordinate ID
77integer,save :: nid_hist ! output file ID
78!$OMP THREADPRIVATE(nid_hist)
79integer :: zvertid ! vertical coordinate ID
80integer,save :: iwrite_phys ! output every iwrite_phys physics step
81!$OMP THREADPRIVATE(iwrite_phys)
82integer :: iwrite_phys_omp ! intermediate variable to read iwrite_phys
83real :: t_ops ! frequency of the IOIPSL operations (eg average over...)
84real :: t_wrt ! frequency of the IOIPSL outputs
85
86! initializations
87if (debut) then ! Things to do only for the first call to physics
88! load initial conditions for physics (including the grid)
89  call phys_state_var_init() ! some initializations, required before calling phyetat0
90  call phyetat0("startphy.nc")
91
92! Initialize outputs:
93  itau0=0
94!$OMP MASTER
95  iwrite_phys_omp=1 !default: output every physics timestep
96  ! NB: getin() is not threadsafe; only one thread should call it.
97  call getin("iwrite_phys",iwrite_phys_omp)
98!$OMP END MASTER
99!$OMP BARRIER
100  iwrite_phys=iwrite_phys_omp
101  t_ops=pdtphys*iwrite_phys ! frequency of the IOIPSL operation
102  t_wrt=pdtphys*iwrite_phys ! frequency of the outputs in the file
103  ! compute zjulian for annee0=1979 and month=1 dayref=1 and hour=0.0
104  !CALL ymds2ju(annee0, month, dayref, hour, zjulian)
105  call ymds2ju(1979, 1, 1, 0.0, zjulian)
106  dtime=pdtphys
107#ifndef CPP_NO_IOIPSL
108  ! Initialize IOIPSL output file
109  call histbeg_phy("histins.nc",itau0,zjulian,dtime,nhori,nid_hist)
110#endif
111
112!$OMP MASTER
113
114#ifndef CPP_NO_IOIPSL
115! IOIPSL
116  ! define vertical coordinate
117  call histvert(nid_hist,"presnivs","Vertical levels","Pa",klev, &
118                presnivs,zvertid,'down')
119  ! define variables which will be written in "histins.nc" file
120  call histdef(nid_hist,'temperature','Atmospheric temperature','K', &
121               iim,jj_nb,nhori,klev,1,klev,zvertid,32, &
122               'inst(X)',t_ops,t_wrt)
123  call histdef(nid_hist,'u','Eastward Zonal Wind','m/s', &
124               iim,jj_nb,nhori,klev,1,klev,zvertid,32, &
125               'inst(X)',t_ops,t_wrt)
126  call histdef(nid_hist,'v','Northward Meridional Wind','m/s', &
127               iim,jj_nb,nhori,klev,1,klev,zvertid,32, &
128               'inst(X)',t_ops,t_wrt)
129  call histdef(nid_hist,'ps','Surface Pressure','Pa', &
130               iim,jj_nb,nhori,1,1,1,zvertid,32, &
131               'inst(X)',t_ops,t_wrt)
132  ! end definition sequence
133  call histend(nid_hist)
134#endif
135
136#ifdef CPP_XIOS
137!XIOS
138    ! Déclaration de l'axe vertical du fichier:   
139    CALL wxios_add_vaxis("presnivs", "histins", klev, presnivs)
140
141    !Déclaration du pas de temps:
142    CALL wxios_set_timestep(dtime)
143
144    !Finalisation du contexte:
145    CALL wxios_closedef()
146#endif
147!$OMP END MASTER
148endif ! of if (debut)
149
150! increment local time counter itau
151itau=itau+1
152
153! set all tendencies to zero
154d_u(1:klon,1:klev)=0.
155d_v(1:klon,1:klev)=0.
156d_t(1:klon,1:klev)=0.
157d_qx(1:klon,1:klev,1:nqtot)=0.
158d_ps(1:klon)=0.
159
160! compute tendencies to return to the dynamics:
161! "friction" on the first layer
162d_u(1:klon,1)=-u(1:klon,1)/86400.
163d_v(1:klon,1)=-v(1:klon,1)/86400.
164! newtonian relaxation towards temp_newton()
165do k=1,klev
166  temp_newton(1:klon,k)=280.+cos(rlatd(1:klon))*40.-pphi(1:klon,k)/rg*6.e-3
167  d_t(1:klon,k)=(temp_newton(1:klon,k)-t(1:klon,k))/1.e5
168enddo
169
170
171print*,'PHYDEV: itau=',itau
172
173! write some outputs:
174! IOIPSL
175#ifndef CPP_NO_IOIPSL
176if (modulo(itau,iwrite_phys)==0) then
177  call histwrite_phy(nid_hist,.false.,"temperature",itau,t)
178  call histwrite_phy(nid_hist,.false.,"u",itau,u)
179  call histwrite_phy(nid_hist,.false.,"v",itau,v)
180  call histwrite_phy(nid_hist,.false.,"ps",itau,paprs(:,1))
181endif
182#endif
183
184!XIOS
185#ifdef CPP_XIOS
186!$OMP MASTER
187    !Increment XIOS time
188    CALL wxios_update_calendar(itau)
189!$OMP END MASTER
190!$OMP BARRIER
191
192    !Send fields to XIOS:
193    CALL histwrite_phy("temperature",t)
194    CALL histwrite_phy("u",u)
195    CALL histwrite_phy("v",v)
196    CALL histwrite_phy("ps",paprs(:,1))
197#endif
198
199! if lastcall, then it is time to write "restartphy.nc" file
200if (lafin) then
201  call phyredem("restartphy.nc")
202endif
203
204end subroutine physiq
Note: See TracBrowser for help on using the repository browser.