SCALE-RM
mod_atmos_phy_tb_vars.f90
Go to the documentation of this file.
1 !-------------------------------------------------------------------------------
12 !-------------------------------------------------------------------------------
13 #include "inc_openmp.h"
15  !-----------------------------------------------------------------------------
16  !
17  !++ used modules
18  !
19  use scale_precision
20  use scale_stdio
21  use scale_prof
23  use scale_tracer
24  !-----------------------------------------------------------------------------
25  implicit none
26  private
27  !-----------------------------------------------------------------------------
28  !
29  !++ Public procedure
30  !
31  public :: atmos_phy_tb_vars_setup
35 
41 
42  !-----------------------------------------------------------------------------
43  !
44  !++ Public parameters & variables
45  !
46  logical, public :: atmos_phy_tb_restart_output = .false.
47 
48  character(len=H_LONG), public :: atmos_phy_tb_restart_in_basename = ''
49  character(len=H_LONG), public :: atmos_phy_tb_restart_out_basename = ''
50  character(len=H_MID), public :: atmos_phy_tb_restart_out_title = 'ATMOS_PHY_TB restart'
51  character(len=H_MID), public :: atmos_phy_tb_restart_out_dtype = 'DEFAULT'
52 
53  real(RP), public, allocatable :: atmos_phy_tb_momz_t(:,:,:) ! tendency MOMZ [kg/m2/s2]
54  real(RP), public, allocatable :: atmos_phy_tb_momx_t(:,:,:) ! tendency MOMX [kg/m2/s2]
55  real(RP), public, allocatable :: atmos_phy_tb_momy_t(:,:,:) ! tendency MOMY [kg/m2/s2]
56  real(RP), public, allocatable :: atmos_phy_tb_rhot_t(:,:,:) ! tendency RHOT [K*kg/m3/s]
57  real(RP), public, allocatable :: atmos_phy_tb_rhoq_t(:,:,:,:) ! tendency rho*QTRC [kg/kg/s]
58  real(RP), public, allocatable :: atmos_phy_tb_tke_t(:,:,:) ! tendency TKE @m2/s3]
59 
60  real(RP), public, allocatable :: atmos_phy_tb_tke(:,:,:) ! turburent kinetic energy [m2/s2]
61  real(RP), public, allocatable :: atmos_phy_tb_nu (:,:,:) ! eddy viscosity [m2/s]
62 
63  !-----------------------------------------------------------------------------
64  !
65  !++ Private procedure
66  !
67  !-----------------------------------------------------------------------------
68  !
69  !++ Private parameters & variables
70  !
71  integer, private, parameter :: vmax = 2
72  integer, private, parameter :: i_tke = 1
73  integer, private, parameter :: i_nu = 2
74 
75  character(len=H_SHORT), private :: var_name(vmax)
76  character(len=H_MID), private :: var_desc(vmax)
77  character(len=H_SHORT), private :: var_unit(vmax)
78  integer, private :: var_id(vmax)
79  integer, private :: restart_fid = -1 ! file ID
80 
81  data var_name / 'TKE', &
82  'NU' /
83  data var_desc / 'turburent kinetic energy', &
84  'eddy viscosity' /
85  data var_unit / 'm2/s2', &
86  'm2/s' /
87 
88  !-----------------------------------------------------------------------------
89 contains
90  !-----------------------------------------------------------------------------
92  subroutine atmos_phy_tb_vars_setup
93  use scale_process, only: &
95  use scale_const, only: &
96  undef => const_undef
97  implicit none
98  real(RP) :: ATMOS_PHY_TB_TKE_INIT = 1.0e-10_rp
99 
100  namelist / param_atmos_phy_tb_vars / &
106  atmos_phy_tb_tke_init
107 
108  integer :: ierr
109  integer :: iv
110  !---------------------------------------------------------------------------
111 
112  if( io_l ) write(io_fid_log,*)
113  if( io_l ) write(io_fid_log,*) '++++++ Module[VARS] / Categ[ATMOS PHY_TB] / Origin[SCALE-RM]'
114 
115  allocate( atmos_phy_tb_momz_t(ka,ia,ja) )
116  allocate( atmos_phy_tb_momx_t(ka,ia,ja) )
117  allocate( atmos_phy_tb_momy_t(ka,ia,ja) )
118  allocate( atmos_phy_tb_rhot_t(ka,ia,ja) )
119  allocate( atmos_phy_tb_rhoq_t(ka,ia,ja,qa) )
120  allocate( atmos_phy_tb_tke_t(ka,ia,ja) )
121 
122  allocate( atmos_phy_tb_tke(ka,ia,ja) )
123  allocate( atmos_phy_tb_nu(ka,ia,ja) )
124 
125  !--- read namelist
126  rewind(io_fid_conf)
127  read(io_fid_conf,nml=param_atmos_phy_tb_vars,iostat=ierr)
128  if( ierr < 0 ) then !--- missing
129  if( io_l ) write(io_fid_log,*) '*** Not found namelist. Default used.'
130  elseif( ierr > 0 ) then !--- fatal error
131  write(*,*) 'xxx Not appropriate names in namelist PARAM_ATMOS_PHY_TB_VARS. Check!'
132  call prc_mpistop
133  endif
134  if( io_lnml ) write(io_fid_log,nml=param_atmos_phy_tb_vars)
135 
136  if( io_l ) write(io_fid_log,*)
137  if( io_l ) write(io_fid_log,*) '*** [ATMOS_PHY_TB] prognostic/diagnostic variables'
138  if( io_l ) write(io_fid_log,'(1x,A,A15,A,A32,3(A))') &
139  '*** |','VARNAME ','|', 'DESCRIPTION ','[', 'UNIT ',']'
140  do iv = 1, vmax
141  if( io_l ) write(io_fid_log,'(1x,A,i3,A,A15,A,A32,3(A))') &
142  '*** NO.',iv,'|',var_name(iv),'|',var_desc(iv),'[',var_unit(iv),']'
143  enddo
144 
145  if( io_l ) write(io_fid_log,*)
146  if ( atmos_phy_tb_restart_in_basename /= '' ) then
147  if( io_l ) write(io_fid_log,*) '*** Restart input? : ', trim(atmos_phy_tb_restart_in_basename)
148  else
149  if( io_l ) write(io_fid_log,*) '*** Restart input? : NO'
150  endif
152  .AND. atmos_phy_tb_restart_out_basename /= '' ) then
153  if( io_l ) write(io_fid_log,*) '*** Restart output? : ', trim(atmos_phy_tb_restart_out_basename)
154  else
155  if( io_l ) write(io_fid_log,*) '*** Restart output? : NO'
157  endif
158 
159  atmos_phy_tb_momz_t(:,:,:) = undef
160  atmos_phy_tb_momx_t(:,:,:) = undef
161  atmos_phy_tb_momy_t(:,:,:) = undef
162  atmos_phy_tb_rhot_t(:,:,:) = undef
163  atmos_phy_tb_rhoq_t(:,:,:,:) = undef
164  atmos_phy_tb_tke_t(:,:,:) = undef
165 
166  atmos_phy_tb_tke(:,:,:) = atmos_phy_tb_tke_init
167  atmos_phy_tb_nu(:,:,:) = undef
168 
169  return
170  end subroutine atmos_phy_tb_vars_setup
171 
172  !-----------------------------------------------------------------------------
174  subroutine atmos_phy_tb_vars_fillhalo
175  use scale_comm, only: &
176  comm_vars8, &
177  comm_wait
178  implicit none
179 
180  integer :: i, j
181  !---------------------------------------------------------------------------
182 
183  do j = js, je
184  do i = is, ie
185  atmos_phy_tb_tke( 1:ks-1,i,j) = atmos_phy_tb_tke(ks,i,j)
186  atmos_phy_tb_nu( 1:ks-1,i,j) = atmos_phy_tb_nu(ks,i,j)
187  atmos_phy_tb_tke(ke+1:ka, i,j) = atmos_phy_tb_tke(ke,i,j)
188  atmos_phy_tb_nu(ke+1:ka, i,j) = atmos_phy_tb_nu(ke,i,j)
189  enddo
190  enddo
191 
192  call comm_vars8( atmos_phy_tb_tke(:,:,:), 1 )
193  call comm_vars8( atmos_phy_tb_nu(:,:,:), 2 )
194  call comm_wait ( atmos_phy_tb_tke(:,:,:), 1 )
195  call comm_wait ( atmos_phy_tb_nu(:,:,:), 2 )
196 
197  return
198  end subroutine atmos_phy_tb_vars_fillhalo
199 
200  !-----------------------------------------------------------------------------
203  use scale_fileio, only: &
204  fileio_read
205  use scale_rm_statistics, only: &
206  stat_total
207  implicit none
208 
209  real(RP) :: total
210  !---------------------------------------------------------------------------
211 
212  if( io_l ) write(io_fid_log,*)
213  if( io_l ) write(io_fid_log,*) '*** Input restart file (ATMOS_PHY_TB) ***'
214 
215  if ( atmos_phy_tb_restart_in_basename /= '' ) then
216  if( io_l ) write(io_fid_log,*) '*** basename: ', trim(atmos_phy_tb_restart_in_basename)
217 
218  call fileio_read( atmos_phy_tb_tke(:,:,:), & ! [OUT]
219  atmos_phy_tb_restart_in_basename, var_name(1), 'ZXY', step=1 ) ! [IN]
220 ! call FILEIO_read( ATMOS_PHY_TB_NU (:,:,:), & ! [OUT]
221 ! ATMOS_PHY_TB_RESTART_IN_BASENAME, VAR_NAME(2), 'ZXY', step=1 ) ! [IN]
222 !
223 ! call ATMOS_PHY_TB_vars_fillhalo
224 !
225  call stat_total( total, atmos_phy_tb_tke(:,:,:), var_name(1) )
226 ! call STAT_total( total, ATMOS_PHY_TB_NU (:,:,:), VAR_NAME(2) )
227  else
228  if( io_l ) write(io_fid_log,*) '*** restart file for ATMOS_PHY_TB is not specified.'
229  endif
230 
231  return
232  end subroutine atmos_phy_tb_vars_restart_read
233 
234  !-----------------------------------------------------------------------------
237  use scale_time, only: &
239  use scale_fileio, only: &
240  fileio_write
241  implicit none
242 
243  character(len=20) :: timelabel
244  character(len=H_LONG) :: basename
245  !---------------------------------------------------------------------------
246 
247  if ( atmos_phy_tb_restart_out_basename /= '' ) then
248 
249  call time_gettimelabel( timelabel )
250  write(basename,'(A,A,A)') trim(atmos_phy_tb_restart_out_basename), '_', trim(timelabel)
251 
252  if( io_l ) write(io_fid_log,*)
253  if( io_l ) write(io_fid_log,*) '*** Output restart file (ATMOS_PHY_TB) ***'
254  if( io_l ) write(io_fid_log,*) '*** basename: ', trim(basename)
255 
256  call fileio_write( atmos_phy_tb_tke(:,:,:), basename, atmos_phy_tb_restart_out_title, & ! [IN]
257  var_name(1), var_desc(1), var_unit(1), 'ZXY', atmos_phy_tb_restart_out_dtype ) ! [IN]
258 ! call FILEIO_write( ATMOS_PHY_TB_NU (:,:,:), basename, ATMOS_PHY_TB_RESTART_OUT_TITLE, & ! [IN]
259 ! VAR_NAME(2), VAR_DESC(2), VAR_UNIT(2), 'ZXY', ATMOS_PHY_TB_RESTART_OUT_DTYPE ) ! [IN]
260 
261  endif
262 
263  return
264  end subroutine atmos_phy_tb_vars_restart_write
265 
266  !-----------------------------------------------------------------------------
269  use scale_time, only: &
271  use scale_fileio, only: &
273  implicit none
274 
275  character(len=20) :: timelabel
276  character(len=H_LONG) :: basename
277  !---------------------------------------------------------------------------
278 
279  if ( atmos_phy_tb_restart_out_basename /= '' ) then
280 
281  call time_gettimelabel( timelabel )
282  write(basename,'(A,A,A)') trim(atmos_phy_tb_restart_out_basename), '_', trim(timelabel)
283 
284  if( io_l ) write(io_fid_log,*)
285  if( io_l ) write(io_fid_log,*) '*** Output restart file (ATMOS_PHY_TB) ***'
286  if( io_l ) write(io_fid_log,*) '*** basename: ', trim(basename)
287 
288  call fileio_create(restart_fid, basename, atmos_phy_tb_restart_out_title, &
290 
291  endif
292 
293  return
294  end subroutine atmos_phy_tb_vars_restart_create
295 
296  !-----------------------------------------------------------------------------
299  use scale_fileio, only: &
301  implicit none
302 
303  if ( restart_fid .NE. -1 ) then
304  call fileio_enddef( restart_fid ) ! [IN]
305  endif
306 
307  return
308  end subroutine atmos_phy_tb_vars_restart_enddef
309 
310  !-----------------------------------------------------------------------------
313  use scale_fileio, only: &
315  implicit none
316 
317  if ( restart_fid .NE. -1 ) then
318  call fileio_close( restart_fid ) ! [IN]
319  restart_fid = -1
320  endif
321 
322  return
323  end subroutine atmos_phy_tb_vars_restart_close
324 
325  !-----------------------------------------------------------------------------
328  use scale_fileio, only: &
330  implicit none
331 
332  !---------------------------------------------------------------------------
333 
334  if ( restart_fid .NE. -1 ) then
335 
336  call fileio_def_var( restart_fid, var_id(1), var_name(1), var_desc(1), &
337  var_unit(1), 'ZXY', atmos_phy_tb_restart_out_dtype ) ! [IN]
338 ! call FILEIO_def_var( restart_fid, VAR_ID(2), VAR_NAME(2), VAR_DESC(2), &
339 ! VAR_UNIT(2), 'ZXY', ATMOS_PHY_TB_RESTART_OUT_DTYPE ) ! [IN]
340 
341  endif
342 
343  return
344  end subroutine atmos_phy_tb_vars_restart_def_var
345 
346  !-----------------------------------------------------------------------------
349  use scale_fileio, only: &
350  fileio_write_var
351  implicit none
352 
353  !---------------------------------------------------------------------------
354 
355  if ( restart_fid .NE. -1 ) then
356 
357  call fileio_write_var( restart_fid, var_id(1), atmos_phy_tb_tke(:,:,:), &
358  var_name(1), 'ZXY' ) ! [IN]
359 ! call FILEIO_write_var( restart_fid, VAR_ID(2), ATMOS_PHY_TB_NU (:,:,:), &
360 ! VAR_NAME(2), 'ZXY' ) ! [IN]
361 
362  endif
363 
364  return
366 
367 end module mod_atmos_phy_tb_vars
integer, public is
start point of inner domain: x, local
subroutine, public atmos_phy_tb_vars_restart_enddef
Exit netCDF define mode.
integer, public je
end point of inner domain: y, local
subroutine, public atmos_phy_tb_vars_restart_read
Read restart.
real(rp), dimension(:,:,:), allocatable, public atmos_phy_tb_momx_t
subroutine, public prc_mpistop
Abort MPI.
real(rp), dimension(:,:,:), allocatable, public atmos_phy_tb_rhot_t
logical, public io_l
output log or not? (this process)
Definition: scale_stdio.F90:59
subroutine, public atmos_phy_tb_vars_restart_write
Write restart.
module STDIO
Definition: scale_stdio.F90:12
integer, public ke
end point of inner domain: z, local
real(rp), dimension(:,:,:), allocatable, public atmos_phy_tb_tke
integer, public qa
character(len=h_mid), public atmos_phy_tb_restart_out_title
title of the output file
module FILE I/O (netcdf)
real(rp), public const_undef
Definition: scale_const.F90:43
subroutine, public atmos_phy_tb_vars_restart_create
Create restart file.
module Statistics
module grid index
character(len=h_long), public atmos_phy_tb_restart_in_basename
basename of the restart file
character(len=h_mid), public atmos_phy_tb_restart_out_dtype
REAL4 or REAL8.
module TRACER
subroutine, public fileio_def_var(fid, vid, varname, desc, unit, axistype, datatype, timeintv)
Define a variable to file.
real(rp), dimension(:,:,:), allocatable, public atmos_phy_tb_nu
integer, public ia
of x whole cells (local, with HALO)
subroutine, public time_gettimelabel(timelabel)
generate time label
Definition: scale_time.F90:90
integer, public ka
of z whole cells (local, with HALO)
subroutine, public fileio_create(fid, basename, title, datatype, date, subsec, append, nozcoord)
Create/open a netCDF file.
module COMMUNICATION
Definition: scale_comm.F90:23
integer, public js
start point of inner domain: y, local
subroutine, public atmos_phy_tb_vars_setup
Setup.
module TIME
Definition: scale_time.F90:15
module PROCESS
module Atmosphere / Physics Turbulence
module CONSTANT
Definition: scale_const.F90:14
integer, public ks
start point of inner domain: z, local
real(rp), dimension(:,:,:), allocatable, public atmos_phy_tb_momy_t
subroutine, public fileio_enddef(fid)
Exit netCDF file define mode.
module profiler
Definition: scale_prof.F90:10
integer, public ie
end point of inner domain: x, local
character(len=h_long), public atmos_phy_tb_restart_out_basename
basename of the output file
logical, public io_lnml
output log or not? (for namelist, this process)
Definition: scale_stdio.F90:60
logical, public atmos_phy_tb_restart_output
output restart file?
subroutine, public atmos_phy_tb_vars_restart_def_var
Write restart.
subroutine, public atmos_phy_tb_vars_fillhalo
HALO Communication.
module PRECISION
real(rp), dimension(:,:,:,:), allocatable, public atmos_phy_tb_rhoq_t
subroutine, public fileio_close(fid)
Close a netCDF file.
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
real(rp), dimension(:,:,:), allocatable, public atmos_phy_tb_tke_t
subroutine, public atmos_phy_tb_vars_restart_close
Close restart file.
subroutine, public atmos_phy_tb_vars_restart_write_var
Write restart.
real(rp), dimension(:,:,:), allocatable, public atmos_phy_tb_momz_t
integer, public ja
of y whole cells (local, with HALO)