source: trunk/LMDZ.COMMON/libf/dynphy_lonlat/inigeomphy_mod.F90 @ 3287

Last change on this file since 3287 was 3078, checked in by emillour, 14 months ago

Common physics/dynamics:
Add, for lon-lat outputs, a cell_area_for_lonlat_outputs()
field where polar mesh areas are adapted to match those
of the dynamics grid (where polar mesh points are replicated
along longitudes).

Mars PCM:
Enable outputing cell area with XIOS and make sure the polar grid point
is correctly handled (i.e. on lon-lat grid outputs polar mesh area must
be adjusted to account for the replicated polar meshes).

EM

File size: 10.2 KB
Line 
1MODULE inigeomphy_mod
2
3CONTAINS
4
5SUBROUTINE inigeomphy(iim,jjm,nlayer, &
6                     nbp, communicator, &
7                     rlatu,rlatv,rlonu,rlonv,aire,cu,cv)
8  USE mod_grid_phy_lmdz, ONLY: klon_glo,  & ! number of atmospheric columns (on full grid)
9                               regular_lonlat  ! regular longitude-latitude grid type
10  USE mod_phys_lmdz_para, ONLY: klon_omp, & ! number of columns (on local omp grid)
11                                klon_omp_begin, & ! start index of local omp subgrid
12                                klon_omp_end, & ! end index of local omp subgrid
13                                klon_mpi_begin ! start indes of columns (on local mpi grid)
14  USE geometry_mod, ONLY : init_geometry, init_geometry_cell_area_for_outputs
15  USE physics_distribution_mod, ONLY : init_physics_distribution
16  USE regular_lonlat_mod, ONLY : init_regular_lonlat, &
17                                 east, west, north, south, &
18                                 north_east, north_west, &
19                                 south_west, south_east
20  USE mod_interface_dyn_phys, ONLY :  init_interface_dyn_phys
21  USE nrtype, ONLY: pi
22  USE comvert_mod, ONLY: preff, ap, bp, aps, bps, presnivs, &
23                         scaleheight, pseudoalt
24  USE vertical_layers_mod, ONLY: init_vertical_layers
25  IMPLICIT NONE
26
27  ! =======================================================================
28  ! Initialisation of the physical constants and some positional and
29  ! geometrical arrays for the physics
30  ! =======================================================================
31
32  include "iniprint.h"
33
34  INTEGER, INTENT (IN) :: nlayer ! number of atmospheric layers
35  INTEGER, INTENT (IN) :: iim ! number of atmospheric columns along longitudes
36  INTEGER, INTENT (IN) :: jjm ! number of atompsheric columns along latitudes
37  INTEGER, INTENT(IN) :: nbp ! number of physics columns for this MPI process
38  INTEGER, INTENT(IN) :: communicator ! MPI communicator
39  REAL, INTENT (IN) :: rlatu(jjm+1) ! latitudes of the physics grid
40  REAL, INTENT (IN) :: rlatv(jjm) ! latitude boundaries of the physics grid
41  REAL, INTENT (IN) :: rlonv(iim+1) ! longitudes of the physics grid
42  REAL, INTENT (IN) :: rlonu(iim+1) ! longitude boundaries of the physics grid
43  REAL, INTENT (IN) :: aire(iim+1,jjm+1) ! area of the dynamics grid (m2)
44  REAL, INTENT (IN) :: cu((iim+1)*(jjm+1)) ! cu coeff. (u_covariant = cu * u)
45  REAL, INTENT (IN) :: cv((iim+1)*jjm) ! cv coeff. (v_covariant = cv * v)
46
47  INTEGER :: ibegin, iend, offset
48  INTEGER :: i,j,k
49  CHARACTER (LEN=20) :: modname = 'inigeomphy'
50  CHARACTER (LEN=80) :: abort_message
51  REAL :: total_area_phy, total_area_dyn
52
53  ! boundaries, on global grid
54  REAL,ALLOCATABLE :: boundslon_reg(:,:)
55  REAL,ALLOCATABLE :: boundslat_reg(:,:)
56
57  ! global array, on full physics grid:
58  REAL,ALLOCATABLE :: latfi_glo(:)
59  REAL,ALLOCATABLE :: lonfi_glo(:)
60  REAL,ALLOCATABLE :: cufi_glo(:)
61  REAL,ALLOCATABLE :: cvfi_glo(:)
62  REAL,ALLOCATABLE :: airefi_glo(:)
63  REAL,ALLOCATABLE :: aire_glo(:)
64  REAL,ALLOCATABLE :: boundslonfi_glo(:,:)
65  REAL,ALLOCATABLE :: boundslatfi_glo(:,:)
66
67  ! local arrays, on given MPI/OpenMP domain:
68  REAL,ALLOCATABLE,SAVE :: latfi(:)
69  REAL,ALLOCATABLE,SAVE :: lonfi(:)
70  REAL,ALLOCATABLE,SAVE :: cufi(:)
71  REAL,ALLOCATABLE,SAVE :: cvfi(:)
72  REAL,ALLOCATABLE,SAVE :: airefi(:)
73  REAL,ALLOCATABLE,SAVE :: airefi_for_outputs(:)
74  REAL,ALLOCATABLE,SAVE :: boundslonfi(:,:)
75  REAL,ALLOCATABLE,SAVE :: boundslatfi(:,:)
76  INTEGER,ALLOCATABLE,SAVE :: ind_cell_glo_fi(:)
77!$OMP THREADPRIVATE (latfi,lonfi,cufi,cvfi,airefi,airefi_for_outputs)
78!$OMP THREADPRIVATE (boundslonfi,boundslatfi,ind_cell_glo_fi)
79
80  ! Initialize Physics distibution and parameters and interface with dynamics
81  IF (iim*jjm>1) THEN ! general 3D case
82    CALL init_physics_distribution(regular_lonlat,4, &
83                                 nbp,iim,jjm+1,nlayer,communicator)
84  ELSE ! For 1D model
85    CALL init_physics_distribution(regular_lonlat,4, &
86                                 1,1,1,nlayer,communicator)
87  ENDIF
88  CALL init_interface_dyn_phys
89 
90  ! init regular global longitude-latitude grid points and boundaries
91  ALLOCATE(boundslon_reg(iim,2))
92  ALLOCATE(boundslat_reg(jjm+1,2))
93 
94  ! specific handling of the -180 longitude scalar grid point boundaries
95  boundslon_reg(1,east)=rlonu(1)
96  boundslon_reg(1,west)=rlonu(iim)-2*PI
97  DO i=2,iim
98   boundslon_reg(i,east)=rlonu(i)
99   boundslon_reg(i,west)=rlonu(i-1)
100  ENDDO
101
102  boundslat_reg(1,north)= PI/2
103  boundslat_reg(1,south)= rlatv(1)
104  DO j=2,jjm
105   boundslat_reg(j,north)=rlatv(j-1)
106   boundslat_reg(j,south)=rlatv(j)
107  ENDDO
108  boundslat_reg(jjm+1,north)= rlatv(jjm)
109  boundslat_reg(jjm+1,south)= -PI/2
110
111  ! Write values in module regular_lonlat_mod
112  CALL init_regular_lonlat(iim,jjm+1, rlonv(1:iim), rlatu, &
113                           boundslon_reg, boundslat_reg)
114
115  ! Generate global arrays on full physics grid
116  ALLOCATE(latfi_glo(klon_glo),lonfi_glo(klon_glo))
117  ALLOCATE(cufi_glo(klon_glo),cvfi_glo(klon_glo))
118  ALLOCATE(airefi_glo(klon_glo))
119  ALLOCATE(aire_glo(klon_glo))
120  ALLOCATE(boundslonfi_glo(klon_glo,4))
121  ALLOCATE(boundslatfi_glo(klon_glo,4))
122
123  IF (klon_glo>1) THEN ! general case
124    ! North pole
125    latfi_glo(1)=rlatu(1)
126    lonfi_glo(1)=0.
127    cufi_glo(1) = cu(1)
128    cvfi_glo(1) = cv(1)
129    boundslonfi_glo(1,north_east)= PI
130    boundslatfi_glo(1,north_east)= PI/2
131    boundslonfi_glo(1,north_west)= -PI
132    boundslatfi_glo(1,north_west)= PI/2
133    boundslonfi_glo(1,south_west)= -PI
134    boundslatfi_glo(1,south_west)= rlatv(1)
135    boundslonfi_glo(1,south_east)= PI
136    boundslatfi_glo(1,south_east)= rlatv(1)
137    DO j=2,jjm
138      DO i=1,iim
139        k=(j-2)*iim+1+i
140        latfi_glo(k)= rlatu(j)
141        lonfi_glo(k)= rlonv(i)
142        cufi_glo(k) = cu((j-1)*(iim+1)+i)
143        cvfi_glo(k) = cv((j-1)*(iim+1)+i)
144        boundslonfi_glo(k,north_east)=rlonu(i)
145        boundslatfi_glo(k,north_east)=rlatv(j-1)
146        if (i.eq.1) then
147          ! special case for the first longitude's west bound
148          boundslonfi_glo(k,north_west)=rlonu(iim)-2*PI
149          boundslonfi_glo(k,south_west)=rlonu(iim)-2*PI
150        else
151          boundslonfi_glo(k,north_west)=rlonu(i-1)
152          boundslonfi_glo(k,south_west)=rlonu(i-1)
153        endif
154        boundslatfi_glo(k,north_west)=rlatv(j-1)
155        boundslatfi_glo(k,south_west)=rlatv(j)
156        boundslonfi_glo(k,south_east)=rlonu(i)
157        boundslatfi_glo(k,south_east)=rlatv(j)
158      ENDDO
159    ENDDO
160    ! South pole
161    latfi_glo(klon_glo)= rlatu(jjm+1)
162    lonfi_glo(klon_glo)= 0.
163    cufi_glo(klon_glo) = cu((iim+1)*jjm+1)
164    cvfi_glo(klon_glo) = cv((iim+1)*jjm-iim)
165    boundslonfi_glo(klon_glo,north_east)= PI
166    boundslatfi_glo(klon_glo,north_east)= rlatv(jjm)
167    boundslonfi_glo(klon_glo,north_west)= -PI
168    boundslatfi_glo(klon_glo,north_west)= rlatv(jjm)
169    boundslonfi_glo(klon_glo,south_west)= -PI
170    boundslatfi_glo(klon_glo,south_west)= -PI/2
171    boundslonfi_glo(klon_glo,south_east)= PI
172    boundslatfi_glo(klon_glo,south_east)= -PI/2
173
174    ! build airefi(), mesh area on physics grid
175    CALL gr_dyn_fi(1,iim+1,jjm+1,klon_glo,aire,airefi_glo)
176    ! Poles are single points on physics grid
177    airefi_glo(1)=sum(aire(1:iim,1))
178    airefi_glo(klon_glo)=sum(aire(1:iim,jjm+1))
179    ! but we also want to store mesh area with poles as on dyn grid
180    ! (for lon-lat outputs)
181    CALL gr_dyn_fi(1,iim+1,jjm+1,klon_glo,aire,aire_glo)
182
183    ! Sanity check: do total planet area match between physics and dynamics?
184    total_area_dyn=sum(aire(1:iim,1:jjm+1))
185    total_area_phy=sum(airefi_glo(1:klon_glo))
186    IF (total_area_dyn/=total_area_phy) THEN
187      WRITE (lunout, *) 'inigeomphy: planet total surface discrepancy !!!'
188      WRITE (lunout, *) '     in the dynamics total_area_dyn=', total_area_dyn
189      WRITE (lunout, *) '  but in the physics total_area_phy=', total_area_phy
190      IF (abs(total_area_dyn-total_area_phy)>0.00001*total_area_dyn) THEN
191        ! stop here if the relative difference is more than 0.001%
192        abort_message = 'planet total surface discrepancy'
193        CALL abort_gcm(modname, abort_message, 1)
194      ENDIF
195    ENDIF
196  ELSE ! klon_glo==1, running the 1D model
197    ! just copy over input values
198    latfi_glo(1)=rlatu(1)
199    lonfi_glo(1)=rlonv(1)
200    cufi_glo(1)=cu(1)
201    cvfi_glo(1)=cv(1)
202    airefi_glo(1)=aire(1,1)
203    aire_glo(1)=aire(1,1)
204    boundslonfi_glo(1,north_east)=rlonu(1)
205    boundslatfi_glo(1,north_east)=PI/2
206    boundslonfi_glo(1,north_west)=rlonu(2)
207    boundslatfi_glo(1,north_west)=PI/2
208    boundslonfi_glo(1,south_west)=rlonu(2)
209    boundslatfi_glo(1,south_west)=rlatv(1)
210    boundslonfi_glo(1,south_east)=rlonu(1)
211    boundslatfi_glo(1,south_east)=rlatv(1)
212  ENDIF ! of IF (klon_glo>1)
213
214!$OMP PARALLEL
215  ! Now generate local lon/lat/cu/cv/area/bounds arrays
216  ALLOCATE(latfi(klon_omp),lonfi(klon_omp),cufi(klon_omp),cvfi(klon_omp))
217  ALLOCATE(airefi(klon_omp))
218  ALLOCATE(airefi_for_outputs(klon_omp))
219  ALLOCATE(boundslonfi(klon_omp,4))
220  ALLOCATE(boundslatfi(klon_omp,4))
221  ALLOCATE(ind_cell_glo_fi(klon_omp))
222
223
224  offset = klon_mpi_begin - 1
225  airefi(1:klon_omp) = airefi_glo(offset+klon_omp_begin:offset+klon_omp_end)
226  airefi_for_outputs(1:klon_omp) = &
227                         aire_glo(offset+klon_omp_begin:offset+klon_omp_end)
228  cufi(1:klon_omp) = cufi_glo(offset+klon_omp_begin:offset+klon_omp_end)
229  cvfi(1:klon_omp) = cvfi_glo(offset+klon_omp_begin:offset+klon_omp_end)
230  lonfi(1:klon_omp) = lonfi_glo(offset+klon_omp_begin:offset+klon_omp_end)
231  latfi(1:klon_omp) = latfi_glo(offset+klon_omp_begin:offset+klon_omp_end)
232  boundslonfi(1:klon_omp,:) = boundslonfi_glo(offset+klon_omp_begin:offset+klon_omp_end,:)
233  boundslatfi(1:klon_omp,:) = boundslatfi_glo(offset+klon_omp_begin:offset+klon_omp_end,:)
234  ind_cell_glo_fi(1:klon_omp)=(/ (i,i=offset+klon_omp_begin,offset+klon_omp_end) /)
235
236  ! copy over local grid longitudes and latitudes
237  CALL init_geometry(klon_omp,lonfi,latfi,boundslonfi,boundslatfi, &
238                     airefi,ind_cell_glo_fi,cufi,cvfi)
239
240  ! copy over lon-lat mesh area for outputs (with polar "correction")
241  CALL init_geometry_cell_area_for_outputs(klon_omp,airefi_for_outputs)
242
243  ! copy over preff , ap(), bp(), etc
244  CALL init_vertical_layers(nlayer,preff,scaleheight, &
245                            ap,bp,aps,bps,presnivs,pseudoalt)
246
247!$OMP END PARALLEL
248
249
250END SUBROUTINE inigeomphy
251
252END MODULE inigeomphy_mod
Note: See TracBrowser for help on using the repository browser.