SCALE-RM
scale_topography.F90
Go to the documentation of this file.
1 !-------------------------------------------------------------------------------
9 !-------------------------------------------------------------------------------
10 #include "scalelib.h"
12  !-----------------------------------------------------------------------------
13  !
14  !++ used modules
15  !
16  use scale_precision
17  use scale_io
18  use scale_prof
20  !-----------------------------------------------------------------------------
21  implicit none
22  private
23  !-----------------------------------------------------------------------------
24  !
25  !++ Public procedure
26  !
27  public :: topography_setup
28  public :: topography_fillhalo
29  public :: topography_write
31  public :: topography_finalize
32 
33  !-----------------------------------------------------------------------------
34  !
35  !++ Public parameters & variables
36  !
37  logical, public :: topography_exist = .false.
38 
39  real(rp), public, allocatable :: topography_zsfc (:,:)
40  real(rp), public, allocatable :: topography_tansl_x(:,:)
41  real(rp), public, allocatable :: topography_tansl_y(:,:)
42 
43  !-----------------------------------------------------------------------------
44  !
45  !++ Private procedure
46  !
47  private :: topography_read
48 
49  !-----------------------------------------------------------------------------
50  !
51  !++ Private parameters & variables
52  !
53  character(len=H_LONG), private :: topography_in_basename = ''
54  character(len=H_LONG), private :: topography_in_varname = 'topo'
55  logical, private :: topography_in_aggregate
56  logical, private :: topography_in_check_coordinates = .false.
57  character(len=H_LONG), private :: topography_out_basename = ''
58  logical, private :: topography_out_aggregate
59  character(len=H_MID), private :: topography_out_title = 'SCALE-RM TOPOGRAPHY'
60  character(len=H_SHORT), private :: topography_out_dtype = 'DEFAULT'
61 
62  !-----------------------------------------------------------------------------
63 contains
64  !-----------------------------------------------------------------------------
66  subroutine topography_setup
67  use scale_file, only: &
69  use scale_prc, only: &
70  prc_abort
71  implicit none
72 
73  namelist / param_topography / &
74  topography_in_basename, &
75  topography_in_varname, &
76  topography_in_aggregate, &
77  topography_in_check_coordinates, &
78  topography_out_basename, &
79  topography_out_aggregate, &
80  topography_out_dtype
81 
82  integer :: ierr
83  !---------------------------------------------------------------------------
84 
85  log_newline
86  log_info("TOPOGRAPHY_setup",*) 'Setup'
87 
88  topography_in_aggregate = file_aggregate
89  topography_out_aggregate = file_aggregate
90 
91  !--- read namelist
92  rewind(io_fid_conf)
93  read(io_fid_conf,nml=param_topography,iostat=ierr)
94  if( ierr < 0 ) then !--- missing
95  log_info("TOPOGRAPHY_setup",*) 'Not found namelist. Default used.'
96  elseif( ierr > 0 ) then !--- fatal error
97  log_error("TOPOGRAPHY_setup",*) 'Not appropriate names in namelist PARAM_TOPOGRAPHY. Check!'
98  call prc_abort
99  endif
100  log_nml(param_topography)
101 
102  allocate( topography_zsfc(ia,ja) )
103  allocate( topography_tansl_x(ia,ja) )
104  allocate( topography_tansl_y(ia,ja) )
105  topography_zsfc(:,:) = 0.0_rp
106  topography_tansl_x(:,:) = 0.0_rp
107  topography_tansl_y(:,:) = 0.0_rp
108  !$acc enter data copyin(TOPOGRAPHY_Zsfc, TOPOGRAPHY_TanSL_X, TOPOGRAPHY_TanSL_Y)
109 
110  ! read from file
111  call topography_read
112 
113  return
114  end subroutine topography_setup
115 
116  !-----------------------------------------------------------------------------
118  subroutine topography_fillhalo( Zsfc, FILL_BND )
119  use scale_comm_cartesc, only: &
120  comm_vars8, &
121  comm_wait
122  implicit none
123 
124  real(rp), intent(inout), optional :: zsfc(ia,ja)
125  logical, intent(in), optional :: fill_bnd
126 
127  logical :: fill_bnd_
128  !---------------------------------------------------------------------------
129 
130  fill_bnd_ = .false.
131  if ( present(fill_bnd) ) fill_bnd_ = fill_bnd
132 
133  if ( present(zsfc) ) then
134  call comm_vars8( zsfc(:,:), 1 )
135  call comm_wait ( zsfc(:,:), 1, fill_bnd_ )
136  else
137  call comm_vars8( topography_zsfc(:,:), 1 )
138  call comm_wait ( topography_zsfc(:,:), 1, fill_bnd_ )
139  end if
140 
141  return
142  end subroutine topography_fillhalo
143 
144  !-----------------------------------------------------------------------------
146  subroutine topography_finalize
147  implicit none
148  !---------------------------------------------------------------------------
149 
150  !$acc exit data delete(TOPOGRAPHY_Zsfc, TOPOGRAPHY_TanSL_X, TOPOGRAPHY_TanSL_Y)
151  deallocate( topography_zsfc )
152  deallocate( topography_tansl_x )
153  deallocate( topography_tansl_y )
154 
155  return
156  end subroutine topography_finalize
157 
158  !-----------------------------------------------------------------------------
160  subroutine topography_read
161  use scale_file_cartesc, only: &
163  file_cartesc_read, &
165  file_cartesc_check_coordinates, &
167  use scale_prc, only: &
168  prc_abort
169  implicit none
170 
171  integer :: fid
172  !---------------------------------------------------------------------------
173 
174  log_newline
175  log_info("TOPOGRAPHY_read",*) 'Input topography file '
176 
177  if ( topography_in_basename /= '' ) then
178 
179  call file_cartesc_open( topography_in_basename, fid, aggregate=topography_in_aggregate )
180  call file_cartesc_read( fid, topography_in_varname, 'XY', topography_zsfc(:,:) )
181 
182  call file_cartesc_flush( fid )
183  !$acc update device( TOPOGRAPHY_Zsfc )
184 
185  if ( topography_in_check_coordinates ) then
186  call file_cartesc_check_coordinates( fid )
187  end if
188 
189  call file_cartesc_close( fid )
190 
191  call topography_fillhalo( fill_bnd=.false. )
192  !$acc update host( TOPOGRAPHY_Zsfc )
193 
194  topography_exist = .true.
195 
196  else
197  log_info_cont(*) 'topography file is not specified.'
198 
199  topography_exist = .false.
200  endif
201 
202  return
203  end subroutine topography_read
204 
205  !-----------------------------------------------------------------------------
207  subroutine topography_write
208  use scale_file_cartesc, only: &
212  file_cartesc_write_var, &
214  implicit none
215 
216  integer :: fid, vid
217  !---------------------------------------------------------------------------
218 
219  if ( topography_out_basename /= '' .and. topography_out_basename /= topography_in_basename ) then
220 
221  log_newline
222  log_info("TOPOGRAPHY_write",*) 'Output topography file '
223 
224  call topography_fillhalo( fill_bnd=.false. )
225 
226  call file_cartesc_create( topography_out_basename, topography_out_title, topography_out_dtype, & ! [IN]
227  fid, & ! [OUT]
228  haszcoord=.false., aggregate=topography_out_aggregate ) ! [IN]
229 
230  call file_cartesc_def_var( fid, 'topo', 'Topography', 'm', 'XY', topography_out_dtype, & ! [IN]
231  vid, & ! [OUT]
232  standard_name="surface_altitude" ) ! [IN]
233 
234  call file_cartesc_enddef( fid )
235 
236  call file_cartesc_write_var( fid, vid, topography_zsfc(:,:), 'topo', 'XY' ) ! [IN]
237 
238 
239  call file_cartesc_close( fid )
240 
241  endif
242 
243  return
244  end subroutine topography_write
245 
246  subroutine topography_calc_tan_slope( &
247  IA, IS, IE, JA, JS, JE, &
248  RCDX, RCDY, MAPF )
249  use scale_prc_cartesc, only: &
250  prc_twod
251  implicit none
252  integer, intent(in) :: ia, is, ie
253  integer, intent(in) :: ja, js, je
254  real(rp), intent(in) :: rcdx(ia), rcdy(ja)
255  real(rp), intent(in) :: mapf(ia,ja,2)
256 
257  integer :: i, j
258 
259  if ( prc_twod ) then
260  !$omp parallel do
261  !$acc kernels
262  do j = js, je
263  do i = is, ie
264  topography_tansl_x(i,j) = 0.0_rp
265  end do
266  end do
267  !$acc end kernels
268  else
269  !$omp parallel do
270  !$acc kernels
271  do j = js, je
272  do i = is, ie
273  topography_tansl_x(i,j) = ( ( topography_zsfc(i+1,j) + topography_zsfc(i ,j) ) * 0.5_rp &
274  - ( topography_zsfc(i ,j) + topography_zsfc(i-1,j) ) * 0.5_rp ) &
275  * rcdx(i) * mapf(i,j,1)
276  end do
277  end do
278  !$acc end kernels
279  end if
280  !$omp parallel do
281  !$acc kernels
282  do j = js, je
283  do i = is, ie
284  topography_tansl_y(i,j) = ( ( topography_zsfc(i,j+1) + topography_zsfc(i,j ) ) * 0.5_rp &
285  - ( topography_zsfc(i,j ) + topography_zsfc(i,j-1) ) * 0.5_rp ) &
286  * rcdy(j) * mapf(i,j,2)
287  end do
288  end do
289  !$acc end kernels
290 
291  call topography_fillhalo( topography_tansl_x(:,:), .true. )
292  call topography_fillhalo( topography_tansl_y(:,:), .true. )
293  !$acc update host(TOPOGRAPHY_TanSL_X, TOPOGRAPHY_TanSL_Y)
294 
295  return
296  end subroutine topography_calc_tan_slope
297 
298 end module scale_topography
scale_prc::prc_abort
subroutine, public prc_abort
Abort Process.
Definition: scale_prc.F90:350
scale_topography::topography_calc_tan_slope
subroutine, public topography_calc_tan_slope(IA, IS, IE, JA, JS, JE, RCDX, RCDY, MAPF)
Definition: scale_topography.F90:249
scale_file_cartesc::file_cartesc_enddef
subroutine, public file_cartesc_enddef(fid)
Exit netCDF file define mode.
Definition: scale_file_cartesC.F90:964
scale_file_cartesc::file_cartesc_def_var
subroutine, public file_cartesc_def_var(fid, varname, desc, unit, dim_type, datatype, vid, standard_name, timeintv, nsteps, cell_measures)
Define a variable to file.
Definition: scale_file_cartesC.F90:3360
scale_topography::topography_tansl_y
real(rp), dimension(:,:), allocatable, public topography_tansl_y
tan(slope_y)
Definition: scale_topography.F90:41
scale_precision
module PRECISION
Definition: scale_precision.F90:14
scale_topography::topography_write
subroutine, public topography_write
Write topography.
Definition: scale_topography.F90:208
scale_topography
module TOPOGRAPHY
Definition: scale_topography.F90:11
scale_file
module file
Definition: scale_file.F90:15
scale_prc
module PROCESS
Definition: scale_prc.F90:11
scale_precision::rp
integer, parameter, public rp
Definition: scale_precision.F90:41
scale_atmos_grid_cartesc_index::ie
integer, public ie
end point of inner domain: x, local
Definition: scale_atmos_grid_cartesC_index.F90:54
scale_io
module STDIO
Definition: scale_io.F90:10
scale_atmos_grid_cartesc_index
module atmosphere / grid / cartesC index
Definition: scale_atmos_grid_cartesC_index.F90:12
scale_atmos_grid_cartesc_index::ia
integer, public ia
Definition: scale_atmos_grid_cartesC_index.F90:48
scale_topography::topography_setup
subroutine, public topography_setup
Setup.
Definition: scale_topography.F90:67
scale_topography::topography_tansl_x
real(rp), dimension(:,:), allocatable, public topography_tansl_x
tan(slope_x)
Definition: scale_topography.F90:40
scale_file_cartesc::file_cartesc_close
subroutine, public file_cartesc_close(fid)
Close a netCDF file.
Definition: scale_file_cartesC.F90:1044
scale_prc_cartesc
module process / cartesC
Definition: scale_prc_cartesC.F90:11
scale_prof
module profiler
Definition: scale_prof.F90:11
scale_topography::topography_exist
logical, public topography_exist
topography exists?
Definition: scale_topography.F90:37
scale_atmos_grid_cartesc_index::is
integer, public is
start point of inner domain: x, local
Definition: scale_atmos_grid_cartesC_index.F90:53
scale_atmos_grid_cartesc_index::ja
integer, public ja
Definition: scale_atmos_grid_cartesC_index.F90:49
scale_topography::topography_zsfc
real(rp), dimension(:,:), allocatable, public topography_zsfc
absolute ground height [m]
Definition: scale_topography.F90:39
scale_file::file_aggregate
logical, public file_aggregate
Definition: scale_file.F90:196
scale_file_cartesc::file_cartesc_create
subroutine, public file_cartesc_create(basename, title, datatype, fid, date, subsec, haszcoord, append, aggregate, single)
Create/open a netCDF file.
Definition: scale_file_cartesC.F90:796
scale_file_cartesc::file_cartesc_flush
subroutine, public file_cartesc_flush(fid)
Flush all pending requests to a netCDF file (PnetCDF only)
Definition: scale_file_cartesC.F90:1018
scale_comm_cartesc
module COMMUNICATION
Definition: scale_comm_cartesC.F90:11
scale_atmos_grid_cartesc_index::js
integer, public js
start point of inner domain: y, local
Definition: scale_atmos_grid_cartesC_index.F90:55
scale_file_cartesc::file_cartesc_open
subroutine, public file_cartesc_open(basename, fid, single, aggregate)
open a netCDF file for read
Definition: scale_file_cartesC.F90:760
scale_topography::topography_finalize
subroutine, public topography_finalize
finalize
Definition: scale_topography.F90:147
scale_topography::topography_fillhalo
subroutine, public topography_fillhalo(Zsfc, FILL_BND)
HALO Communication.
Definition: scale_topography.F90:119
scale_io::io_fid_conf
integer, public io_fid_conf
Config file ID.
Definition: scale_io.F90:57
scale_atmos_grid_cartesc_index::je
integer, public je
end point of inner domain: y, local
Definition: scale_atmos_grid_cartesC_index.F90:56
scale_prc_cartesc::prc_twod
logical, public prc_twod
2D experiment
Definition: scale_prc_cartesC.F90:56
scale_file_cartesc
module file / cartesianC
Definition: scale_file_cartesC.F90:11