SCALE-RM
scale_grid_index.F90
Go to the documentation of this file.
1 !-------------------------------------------------------------------------------
13 !-------------------------------------------------------------------------------
15  !-----------------------------------------------------------------------------
16  !
17  !++ used modules
18  !
19  use scale_precision
20  use scale_stdio
21  use scale_prof
22  !-----------------------------------------------------------------------------
23  implicit none
24  private
25  !-----------------------------------------------------------------------------
26  !
27  !++ Public procedure
28  !
29  public :: grid_index_setup
30 
31  !-----------------------------------------------------------------------------
32  !
33  !++ Public parameters & variables
34  !
35  integer, public, parameter :: zdir = 1
36  integer, public, parameter :: xdir = 2
37  integer, public, parameter :: ydir = 3
38 
39 #ifdef FIXEDINDEX
40  include "inc_index.h"
41  include "inc_index_common.h"
42 #else
43  integer, public :: kmax = -1
44  integer, public :: imax = -1
45  integer, public :: jmax = -1
46 
47  integer, public :: iblock = -1
48  integer, public :: jblock = -1
49 
50  integer, public, parameter :: khalo = 2
51  integer, public :: ihalo = 2
52  integer, public :: jhalo = 2
53 
54  integer, public :: ka
55  integer, public :: ia
56  integer, public :: ja
57 
58  integer, public :: ks
59  integer, public :: ke
60  integer, public :: is
61  integer, public :: ie
62  integer, public :: js
63  integer, public :: je
64 
65  integer, public :: kijmax = -1
66 #endif
67 
68  ! indices considering boundary
69  integer, public :: imaxb
70  integer, public :: jmaxb
71  integer, public :: isb
72  integer, public :: ieb
73  integer, public :: jsb
74  integer, public :: jeb
75  integer, public :: ieh
76  integer, public :: jeh
77 
78  ! global size and offset
79  integer, public :: imaxg = -1
80  integer, public :: jmaxg = -1
81  integer, public :: iag
82  integer, public :: jag
83  integer, public :: iagb
84  integer, public :: jagb
85  integer, public :: is_ing
86  integer, public :: ie_ing
87  integer, public :: js_ing
88  integer, public :: je_ing
89  integer, public :: isga
90  integer, public :: iega
91  integer, public :: jsga
92  integer, public :: jega
93  integer, public :: isgb
94  integer, public :: iegb
95  integer, public :: jsgb
96  integer, public :: jegb
97 
98  !-----------------------------------------------------------------------------
99  !
100  !++ Private procedure
101  !
102  !-----------------------------------------------------------------------------
103  !
104  !++ Private parameters & variables
105  !
106  !-----------------------------------------------------------------------------
107 contains
108  !-----------------------------------------------------------------------------
110  subroutine grid_index_setup
111  use scale_process, only: &
112  prc_mpistop, &
113  prc_myrank
114  use scale_rm_process, only: &
115  prc_periodic_x, &
116  prc_periodic_y, &
117  prc_2drank, &
118  prc_num_x, &
119  prc_num_y, &
120  prc_has_w, &
121  prc_has_e, &
122  prc_has_s, &
123  prc_has_n
124  implicit none
125 
126 #ifndef FIXEDINDEX
127  namelist / param_index / &
128  imaxg, &
129  jmaxg, &
130  kmax, &
131  imax, &
132  jmax, &
133  ihalo, &
134  jhalo, &
135  iblock, &
136  jblock
137 #endif
138 
139  integer :: ierr
140  !---------------------------------------------------------------------------
141 
142  if( io_l ) write(io_fid_log,*)
143  if( io_l ) write(io_fid_log,*) '++++++ Module[GRID_INDEX] / Categ[ATMOS-RM GRID] / Origin[SCALElib]'
144 
145 #ifdef FIXEDINDEX
146  if( io_l ) write(io_fid_log,*) '*** No namelists.'
147  if( io_l ) write(io_fid_log,*)
148  if( io_l ) write(io_fid_log,*) '*** fixed index mode'
149 
150  imaxg = imax * prc_num_y
151  jmaxg = jmax * prc_num_y
152 #else
153  !--- read namelist
154  rewind(io_fid_conf)
155  read(io_fid_conf,nml=param_index,iostat=ierr)
156  if( ierr < 0 ) then !--- missing
157  if( io_l ) write(io_fid_log,*) '*** Not found namelist. Default used.'
158  elseif( ierr > 0 ) then !--- fatal error
159  write(*,*) 'xxx Not appropriate names in namelist PARAM_INDEX. Check!'
160  call prc_mpistop
161  endif
162  if( io_nml ) write(io_fid_nml,nml=param_index)
163 
164  if ( imaxg * jmaxg < 0 ) then
165  write(*,*) 'xxx Both IMAXG and JMAXG must set! ', imaxg, jmaxg
166  call prc_mpistop
167  endif
168  if ( imax * jmax < 0 ) then
169  write(*,*) 'xxx Both IMAX and JMAX must set! ', imax, jmax
170  call prc_mpistop
171  endif
172 
173  if ( imax > 0 .AND. jmax > 0 ) then
174  imaxg = imax * prc_num_x
175  jmaxg = jmax * prc_num_y
176  elseif( imaxg > 0 .AND. jmaxg > 0 ) then
177  imax = (imaxg-1) / prc_num_x + 1
178  jmax = (jmaxg-1) / prc_num_y + 1
179 
180  if ( mod(imaxg,prc_num_x) > 0 ) then
181  if( io_l ) write(io_fid_log,*) 'xxx number of IMAXG should be divisible by PRC_NUM_X'
182  write(*,*) 'xxx number of IMAXG should be divisible by PRC_NUM_X'
183  call prc_mpistop
184 ! if( IO_L ) write(IO_FID_LOG,*) '*** number of IMAXG should be divisible by PRC_NUM_X'
185 ! if( IO_L ) write(IO_FID_LOG,*) '*** Small IMAX is used in ranks(X,*)=', PRC_NUM_X-1
186 ! if ( PRC_2Drank(PRC_myrank,1) == PRC_NUM_X-1 ) then
187 ! IMAX = IMAXG - IMAX * (PRC_NUM_X-1)
188 ! if( IO_L ) write(IO_FID_LOG,*) '*** Small IMAX is used in this rank. IMAX=', IMAX
189 ! endif
190  endif
191 
192  if ( mod(jmaxg,prc_num_y) > 0 ) then
193  if( io_l ) write(io_fid_log,*) 'xxx number of JMAXG should be divisible by PRC_NUM_Y'
194  write(*,*) 'xxx number of JMAXG should be divisible by PRC_NUM_Y'
195  call prc_mpistop
196 ! if( IO_L ) write(IO_FID_LOG,*) '*** number of JMAXG should be divisible by PRC_NUM_Y'
197 ! if( IO_L ) write(IO_FID_LOG,*) '*** Small JMAX is used in ranks(*,Y)=', PRC_NUM_Y-1
198 ! if ( PRC_2Drank(PRC_myrank,2) == PRC_NUM_Y-1 ) then
199 ! JMAX = JMAXG - JMAX * (PRC_NUM_Y-1)
200 ! if( IO_L ) write(IO_FID_LOG,*) '*** Small JMAX is used in this rank. JMAX=', JMAX
201 ! endif
202  endif
203  else
204  write(*,*) 'xxx IMAXG&JMAXG or IMAX&JMAX must set!'
205  call prc_mpistop
206  endif
207 
208  if ( imax < ihalo ) then
209  write(*,*) 'xxx number of grid size IMAX must >= IHALO! ', imax, ihalo
210  call prc_mpistop
211  endif
212  if ( jmax < jhalo ) then
213  write(*,*) 'xxx number of grid size JMAX must >= JHALO! ', jmax, jhalo
214  call prc_mpistop
215  endif
216 
217  ka = kmax + khalo * 2
218  ia = imax + ihalo * 2
219  ja = jmax + jhalo * 2
220 
221  ks = 1 + khalo
222  ke = kmax + khalo
223  is = 1 + ihalo
224  ie = imax + ihalo
225  js = 1 + jhalo
226  je = jmax + jhalo
227 
228  if( iblock == -1 ) iblock = imax
229  if( jblock == -1 ) jblock = jmax
230 
231  kijmax = kmax * imax * jmax
232 #endif
233 
234  !-- Block size must be divisible
235  if ( mod(imax,iblock) > 0 ) then
236  write(*,*) 'xxx number of grid size IMAX must be divisible by IBLOCK! ', imax, iblock
237  call prc_mpistop
238  elseif( mod(jmax,jblock) > 0 ) then
239  write(*,*) 'xxx number of grid size JMAX must be divisible by JBLOCK! ', jmax, jblock
240  call prc_mpistop
241  endif
242 
243  ! array size (global domain)
244  iag = imaxg + ihalo * 2
245  jag = jmaxg + jhalo * 2
246 
247  ! horizontal index (global domain)
248  is_ing = ihalo + 1 + prc_2drank(prc_myrank,1) * imax
250  js_ing = jhalo + 1 + prc_2drank(prc_myrank,2) * jmax
252 
253  if ( prc_2drank(prc_myrank,1) == 0 ) then
254  isga = 1
255  else
256  isga = is_ing
257  end if
258  if ( prc_2drank(prc_myrank,1) == prc_num_x - 1 ) then
259  iega = iag
260  else
261  iega = ie_ing
262  end if
263  if ( prc_2drank(prc_myrank,2) == 0 ) then
264  jsga = 1
265  else
266  jsga = js_ing
267  end if
268  if ( prc_2drank(prc_myrank,2) == prc_num_y - 1 ) then
269  jega = jag
270  else
271  jega = je_ing
272  end if
273 
274  if ( prc_periodic_x ) then
275  iagb = imaxg
276  isgb = is_ing - ihalo
277  iegb = ie_ing - ihalo
278  else
279  iagb = iag
280  if ( prc_has_w ) then
281  isgb = is_ing
282  else ! western boundary
283  isgb = is_ing - ihalo ! ISGB = 1
284  end if
285  if ( prc_has_e ) then
286  iegb = ie_ing
287  else ! eastern boundary
288  iegb = ie_ing + ihalo
289  end if
290  end if
291  if ( prc_periodic_y ) then
292  jagb = jmaxg
293  jsgb = js_ing - jhalo
294  jegb = je_ing - jhalo
295  else
296  jagb = jag
297  if ( prc_has_s ) then
298  jsgb = js_ing
299  else ! southern boundary
300  jsgb = js_ing - jhalo ! JSGY = 1
301  end if
302  if ( prc_has_n ) then
303  jegb = je_ing
304  else ! northern boundary
305  jegb = je_ing + jhalo
306  end if
307  end if
308 
309  ! index considering boundary region
310  imaxb = imax
311  jmaxb = jmax
312  isb = is
313  ieb = ie
314  jsb = js
315  jeb = je
316  ieh = ie
317  jeh = je
318 
319  if ( .NOT. prc_has_w ) then
320  imaxb = imaxb + ihalo
321  isb = 1
322  endif
323  if ( .NOT. prc_has_e ) then
324  imaxb = imaxb + ihalo
325  ieb = ia
326  ieh = ie - 1
327  endif
328  if ( .NOT. prc_has_s ) then
329  jmaxb = jmaxb + jhalo
330  jsb = 1
331  endif
332  if ( .NOT. prc_has_n ) then
333  jmaxb = jmaxb + jhalo
334  jeb = ja
335  jeh = je - 1
336  endif
337 
338  if( io_l ) write(io_fid_log,*)
339  if( io_l ) write(io_fid_log,*) '*** Atmosphere grid index information ***'
340 
341  ! global
342  if( io_l ) write(io_fid_log,'(1x,3(A,I6))') '*** No. of Computational Grid (global) :', &
343  kmax,' x ',imaxg,' x ',jmaxg
344  if( io_l ) write(io_fid_log,'(1x,2(A,I6))') '*** Global index of local grid (X) :', &
345  is_ing," - ",ie_ing
346  if( io_l ) write(io_fid_log,'(1x,2(A,I6))') '*** Global index of local grid (Y) :', &
347  js_ing," - ",je_ing
348 
349  ! local
350  if( io_l ) write(io_fid_log,*)
351  if( io_l ) write(io_fid_log,'(1x,3(A,I6))') '*** No. of Computational Grid (local) :', &
352  kmax,' x ',imax,' x ',jmax
353  if( io_l ) write(io_fid_log,'(1x,3(A,I6))') '*** No. of Grid (including HALO, local) :', &
354  ka," x ",ia," x ",ja
355  if( io_l ) write(io_fid_log,'(1x,2(A,I6))') '*** Local index of inner grid (X) :', &
356  isb," - ",ieb
357  if( io_l ) write(io_fid_log,'(1x,2(A,I6))') '*** Local index of inner grid (Y) :', &
358  jsb," - ",jeb
359 
360  return
361  end subroutine grid_index_setup
362 
363 end module scale_grid_index
integer, public imax
of computational cells: x, local
integer, public iagb
of computational grids
integer, public prc_num_x
x length of 2D processor topology
integer, public is
start point of inner domain: x, local
integer, public iegb
end point of the inner domain: x, global
integer, public je
end point of inner domain: y, local
logical, public prc_has_n
subroutine, public prc_mpistop
Abort MPI.
integer, public jeb
logical, public prc_periodic_y
periodic condition or not (Y)?
integer, public iblock
block size for cache blocking: x
integer, public iega
end point of the full domain: cx, global
logical, public io_l
output log or not? (this process)
Definition: scale_stdio.F90:61
integer, public jsgb
start point of the inner domain: y, global
integer, parameter, public zdir
logical, public prc_has_e
module STDIO
Definition: scale_stdio.F90:12
integer, parameter, public ydir
integer, public ke
end point of inner domain: z, local
integer, parameter, public xdir
subroutine, public grid_index_setup
Setup.
integer, public imaxb
logical, public prc_periodic_x
periodic condition or not (X)?
integer, public jmaxb
logical, public prc_has_s
integer, public ieb
integer, public prc_num_y
y length of 2D processor topology
module grid index
logical, public io_nml
output log or not? (for namelist, this process)
Definition: scale_stdio.F90:62
integer, public jsga
start point of the full domain: cy, global
integer, public isgb
start point of the inner domain: x, global
integer, public ia
of whole cells: x, local, with HALO
integer, public jag
of computational grids
integer, public jega
end point of the full domain: cy, global
integer, public ka
of whole cells: z, local, with HALO
integer, public jblock
block size for cache blocking: y
integer, public kmax
of computational cells: z, local
integer, public jhalo
of halo cells: y
integer, public js
start point of inner domain: y, local
integer, public iag
of computational grids
module PROCESS
integer, public jagb
of computational grids
integer, public ie_ing
end point of the inner domain: cx, global
integer, public is_ing
start point of the inner domain: cx, global
integer, public ks
start point of inner domain: z, local
integer, public prc_myrank
process num in local communicator
integer, parameter, public khalo
of halo cells: z
integer, public jeh
end point of inner domain: y, local (half level)
integer, public ieh
end point of inner domain: x, local (half level)
integer, public kijmax
of computational cells: z*x*y
module RM PROCESS
integer, public isga
start point of the full domain: cx, global
module profiler
Definition: scale_prof.F90:10
integer, public ie
end point of inner domain: x, local
integer, public imaxg
of computational cells: x, global
integer, public jegb
end point of the inner domain: y, global
module PRECISION
integer, dimension(:,:), allocatable, public prc_2drank
node index in 2D topology
integer, public js_ing
start point of the inner domain: cy, global
integer, public isb
integer, public je_ing
end point of the inner domain: cy, global
integer, public io_fid_conf
Config file ID.
Definition: scale_stdio.F90:55
integer, public io_fid_log
Log file ID.
Definition: scale_stdio.F90:56
integer, public jsb
integer, public jmaxg
of computational cells: y, global
logical, public prc_has_w
integer, public jmax
of computational cells: y, local
integer, public io_fid_nml
Log file ID (only for output namelist)
Definition: scale_stdio.F90:57
integer, public ihalo
of halo cells: x
integer, public ja
of whole cells: y, local, with HALO