SCALE-RM
mod_atmos_phy_mp_vars.f90
Go to the documentation of this file.
1 !-------------------------------------------------------------------------------
13 !-------------------------------------------------------------------------------
14 #include "inc_openmp.h"
16  !-----------------------------------------------------------------------------
17  !
18  !++ used modules
19  !
20  use scale_precision
21  use scale_stdio
22  use scale_prof
24  use scale_tracer
25  !-----------------------------------------------------------------------------
26  implicit none
27  private
28  !-----------------------------------------------------------------------------
29  !
30  !++ Public procedure
31  !
32  public :: atmos_phy_mp_vars_setup
36 
42 
43  !-----------------------------------------------------------------------------
44  !
45  !++ Public parameters & variables
46  !
47  logical, public :: atmos_phy_mp_restart_output = .false.
48 
49  character(len=H_LONG), public :: atmos_phy_mp_restart_in_basename = ''
50  character(len=H_LONG), public :: atmos_phy_mp_restart_out_basename = ''
51  character(len=H_MID), public :: atmos_phy_mp_restart_out_title = 'ATMOS_PHY_MP restart'
52  character(len=H_MID), public :: atmos_phy_mp_restart_out_dtype = 'DEFAULT'
53 
54  real(RP), public, allocatable :: atmos_phy_mp_dens_t(:,:,:) ! tendency DENS [kg/m3/s]
55  real(RP), public, allocatable :: atmos_phy_mp_momz_t(:,:,:) ! tendency MOMZ [kg/m2/s2]
56  real(RP), public, allocatable :: atmos_phy_mp_momx_t(:,:,:) ! tendency MOMX [kg/m2/s2]
57  real(RP), public, allocatable :: atmos_phy_mp_momy_t(:,:,:) ! tendency MOMY [kg/m2/s2]
58  real(RP), public, allocatable :: atmos_phy_mp_rhot_t(:,:,:) ! tendency RHOT [K*kg/m3/s]
59  real(RP), public, allocatable :: atmos_phy_mp_rhoq_t(:,:,:,:) ! tendency rho*QTRC [kg/kg/s]
60 
61  real(RP), public, allocatable :: atmos_phy_mp_evaporate(:,:,:) ! number concentration of evaporated cloud [/m3]
62  real(RP), public, allocatable :: atmos_phy_mp_sflx_rain(:,:) ! precipitation flux (liquid) [kg/m2/s]
63  real(RP), public, allocatable :: atmos_phy_mp_sflx_snow(:,:) ! precipitation flux (solid) [kg/m2/s]
64 
65  !-----------------------------------------------------------------------------
66  !
67  !++ Private procedure
68  !
69  !-----------------------------------------------------------------------------
70  !
71  !++ Private parameters & variables
72  !
73  integer, private, parameter :: vmax = 2
74  integer, private, parameter :: i_sflx_rain = 1
75  integer, private, parameter :: i_sflx_snow = 2
76 
77  character(len=H_SHORT), private :: var_name(vmax)
78  character(len=H_MID), private :: var_desc(vmax)
79  character(len=H_SHORT), private :: var_unit(vmax)
80  integer, private :: var_id(vmax)
81  integer, private :: restart_fid = -1 ! file ID
82 
83  data var_name / 'SFLX_rain', &
84  'SFLX_snow' /
85  data var_desc / 'precipitation flux (liquid)', &
86  'precipitation flux (solid)' /
87  data var_unit / 'kg/m2/s', &
88  'kg/m2/s' /
89 
90  !-----------------------------------------------------------------------------
91 contains
92  !-----------------------------------------------------------------------------
94  subroutine atmos_phy_mp_vars_setup
95  use scale_process, only: &
97  use scale_const, only: &
98  undef => const_undef
99  implicit none
100 
101  namelist / param_atmos_phy_mp_vars / &
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_MP] / Origin[SCALE-RM]'
114 
115  allocate( atmos_phy_mp_dens_t(ka,ia,ja) )
116  allocate( atmos_phy_mp_momz_t(ka,ia,ja) )
117  allocate( atmos_phy_mp_momx_t(ka,ia,ja) )
118  allocate( atmos_phy_mp_momy_t(ka,ia,ja) )
119  allocate( atmos_phy_mp_rhot_t(ka,ia,ja) )
120  allocate( atmos_phy_mp_rhoq_t(ka,ia,ja,qa) )
121  allocate( atmos_phy_mp_evaporate(ka,ia,ja) )
122  ! tentative approach
123  atmos_phy_mp_dens_t(:,:,:) = 0.0_rp
124  atmos_phy_mp_momz_t(:,:,:) = 0.0_rp
125  atmos_phy_mp_momx_t(:,:,:) = 0.0_rp
126  atmos_phy_mp_momy_t(:,:,:) = 0.0_rp
127  atmos_phy_mp_rhot_t(:,:,:) = 0.0_rp
128  atmos_phy_mp_rhoq_t(:,:,:,:) = 0.0_rp
129  atmos_phy_mp_evaporate(:,:,:) = 0.0_rp
130 
131  allocate( atmos_phy_mp_sflx_rain(ia,ja) )
132  allocate( atmos_phy_mp_sflx_snow(ia,ja) )
133  atmos_phy_mp_sflx_rain(:,:) = undef
134  atmos_phy_mp_sflx_snow(:,:) = undef
135 
136  !--- read namelist
137  rewind(io_fid_conf)
138  read(io_fid_conf,nml=param_atmos_phy_mp_vars,iostat=ierr)
139  if( ierr < 0 ) then !--- missing
140  if( io_l ) write(io_fid_log,*) '*** Not found namelist. Default used.'
141  elseif( ierr > 0 ) then !--- fatal error
142  write(*,*) 'xxx Not appropriate names in namelist PARAM_ATMOS_PHY_MP_VARS. Check!'
143  call prc_mpistop
144  endif
145  if( io_lnml ) write(io_fid_log,nml=param_atmos_phy_mp_vars)
146 
147  if( io_l ) write(io_fid_log,*)
148  if( io_l ) write(io_fid_log,*) '*** [ATMOS_PHY_MP] prognostic/diagnostic variables'
149  if( io_l ) write(io_fid_log,'(1x,A,A15,A,A32,3(A))') &
150  '*** |','VARNAME ','|', 'DESCRIPTION ','[', 'UNIT ',']'
151  do iv = 1, vmax
152  if( io_l ) write(io_fid_log,'(1x,A,i3,A,A15,A,A32,3(A))') &
153  '*** NO.',iv,'|',var_name(iv),'|',var_desc(iv),'[',var_unit(iv),']'
154  enddo
155 
156  if( io_l ) write(io_fid_log,*)
157  if ( atmos_phy_mp_restart_in_basename /= '' ) then
158  if( io_l ) write(io_fid_log,*) '*** Restart input? : ', trim(atmos_phy_mp_restart_in_basename)
159  else
160  if( io_l ) write(io_fid_log,*) '*** Restart input? : NO'
161  endif
163  .AND. atmos_phy_mp_restart_out_basename /= '' ) then
164  if( io_l ) write(io_fid_log,*) '*** Restart output? : ', trim(atmos_phy_mp_restart_out_basename)
165  else
166  if( io_l ) write(io_fid_log,*) '*** Restart output? : NO'
168  endif
169 
170  return
171  end subroutine atmos_phy_mp_vars_setup
172 
173  !-----------------------------------------------------------------------------
175  subroutine atmos_phy_mp_vars_fillhalo
176  use scale_comm, only: &
177  comm_vars8, &
178  comm_wait
179  implicit none
180  !---------------------------------------------------------------------------
181 
182  call comm_vars8( atmos_phy_mp_sflx_rain(:,:), 1 )
183  call comm_vars8( atmos_phy_mp_sflx_snow(:,:), 2 )
184  call comm_wait ( atmos_phy_mp_sflx_rain(:,:), 1 )
185  call comm_wait ( atmos_phy_mp_sflx_snow(:,:), 2 )
186 
187  return
188  end subroutine atmos_phy_mp_vars_fillhalo
189 
190  !-----------------------------------------------------------------------------
193  use scale_fileio, only: &
194  fileio_read
195  use scale_rm_statistics, only: &
196  stat_total
197  implicit none
198 
199  real(RP) :: total
200  !---------------------------------------------------------------------------
201 
202  if( io_l ) write(io_fid_log,*)
203  if( io_l ) write(io_fid_log,*) '*** Input restart file (ATMOS_PHY_MP) ***'
204 
205  if ( atmos_phy_mp_restart_in_basename /= '' ) then
206  if( io_l ) write(io_fid_log,*) '*** basename: ', trim(atmos_phy_mp_restart_in_basename)
207 
208  call fileio_read( atmos_phy_mp_sflx_rain(:,:), & ! [OUT]
209  atmos_phy_mp_restart_in_basename, var_name(1), 'XY', step=1 ) ! [IN]
210  call fileio_read( atmos_phy_mp_sflx_snow(:,:), & ! [OUT]
211  atmos_phy_mp_restart_in_basename, var_name(2), 'XY', step=1 ) ! [IN]
212 
214 
215  call stat_total( total, atmos_phy_mp_sflx_rain(:,:), var_name(1) )
216  call stat_total( total, atmos_phy_mp_sflx_snow(:,:), var_name(2) )
217  else
218  if( io_l ) write(io_fid_log,*) '*** restart file for ATMOS_PHY_MP is not specified.'
219  endif
220 
221  return
222  end subroutine atmos_phy_mp_vars_restart_read
223 
224  !-----------------------------------------------------------------------------
227  use scale_time, only: &
229  use scale_fileio, only: &
230  fileio_write
231  use scale_rm_statistics, only: &
232  stat_total
233  implicit none
234 
235  character(len=20) :: timelabel
236  character(len=H_LONG) :: basename
237 
238  real(RP) :: total
239  !---------------------------------------------------------------------------
240 
241  if ( atmos_phy_mp_restart_out_basename /= '' ) then
242 
243  call time_gettimelabel( timelabel )
244  write(basename,'(A,A,A)') trim(atmos_phy_mp_restart_out_basename), '_', trim(timelabel)
245 
246  if( io_l ) write(io_fid_log,*)
247  if( io_l ) write(io_fid_log,*) '*** Output restart file (ATMOS_PHY_MP) ***'
248  if( io_l ) write(io_fid_log,*) '*** basename: ', trim(basename)
249 
251 
252  call stat_total( total, atmos_phy_mp_sflx_rain(:,:), var_name(1) )
253  call stat_total( total, atmos_phy_mp_sflx_snow(:,:), var_name(2) )
254 
255  call fileio_write( atmos_phy_mp_sflx_rain(:,:), basename, atmos_phy_mp_restart_out_title, & ! [IN]
256  var_name(1), var_desc(1), var_unit(1), 'XY', atmos_phy_mp_restart_out_dtype ) ! [IN]
257  call fileio_write( atmos_phy_mp_sflx_snow(:,:), basename, atmos_phy_mp_restart_out_title, & ! [IN]
258  var_name(2), var_desc(2), var_unit(2), 'XY', atmos_phy_mp_restart_out_dtype ) ! [IN]
259 
260  endif
261 
262  return
263  end subroutine atmos_phy_mp_vars_restart_write
264 
265  !-----------------------------------------------------------------------------
268  use scale_time, only: &
270  use scale_fileio, only: &
272  implicit none
273 
274  character(len=20) :: timelabel
275  character(len=H_LONG) :: basename
276 
277  !---------------------------------------------------------------------------
278 
279  if ( atmos_phy_mp_restart_out_basename /= '' ) then
280 
281  call time_gettimelabel( timelabel )
282  write(basename,'(A,A,A)') trim(atmos_phy_mp_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_MP) ***'
286  if( io_l ) write(io_fid_log,*) '*** basename: ', trim(basename)
287 
288  call fileio_create(restart_fid, basename, atmos_phy_mp_restart_out_title, &
290 
291  endif
292 
293  return
294  end subroutine atmos_phy_mp_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_mp_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_mp_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), 'XY', atmos_phy_mp_restart_out_dtype ) ! [IN]
338  call fileio_def_var( restart_fid, var_id(2), var_name(2), var_desc(2), &
339  var_unit(2), 'XY', atmos_phy_mp_restart_out_dtype ) ! [IN]
340 
341  endif
342 
343  return
344  end subroutine atmos_phy_mp_vars_restart_def_var
345 
346  !-----------------------------------------------------------------------------
349  use scale_fileio, only: &
350  fileio_write_var
351  use scale_rm_statistics, only: &
352  stat_total
353  implicit none
354 
355  real(RP) :: total
356  !---------------------------------------------------------------------------
357 
358  if ( restart_fid .NE. -1 ) then
359 
361 
362  call stat_total( total, atmos_phy_mp_sflx_rain(:,:), var_name(1) )
363  call stat_total( total, atmos_phy_mp_sflx_snow(:,:), var_name(2) )
364 
365  call fileio_write_var( restart_fid, var_id(1), atmos_phy_mp_sflx_rain(:,:), &
366  var_name(1), 'XY' ) ! [IN]
367  call fileio_write_var( restart_fid, var_id(2), atmos_phy_mp_sflx_snow(:,:), &
368  var_name(2), 'XY' ) ! [IN]
369 
370  endif
371 
372  return
374 
375 end module mod_atmos_phy_mp_vars
real(rp), dimension(:,:,:,:), allocatable, public atmos_phy_mp_rhoq_t
real(rp), dimension(:,:,:), allocatable, public atmos_phy_mp_momy_t
subroutine, public prc_mpistop
Abort MPI.
subroutine, public atmos_phy_mp_vars_restart_enddef
Exit netCDF define mode.
module Atmosphere / Physics Cloud Microphysics
logical, public io_l
output log or not? (this process)
Definition: scale_stdio.F90:59
character(len=h_long), public atmos_phy_mp_restart_in_basename
basename of the restart file
module STDIO
Definition: scale_stdio.F90:12
subroutine, public atmos_phy_mp_vars_restart_def_var
Define variables in restart file.
integer, public qa
real(rp), dimension(:,:,:), allocatable, public atmos_phy_mp_momz_t
real(rp), dimension(:,:), allocatable, public atmos_phy_mp_sflx_rain
module FILE I/O (netcdf)
real(rp), public const_undef
Definition: scale_const.F90:43
module Statistics
module grid index
character(len=h_mid), public atmos_phy_mp_restart_out_title
title of the output file
module TRACER
subroutine, public fileio_def_var(fid, vid, varname, desc, unit, axistype, datatype, timeintv)
Define a variable to file.
integer, public ia
of x whole cells (local, with HALO)
real(rp), dimension(:,:,:), allocatable, public atmos_phy_mp_rhot_t
subroutine, public time_gettimelabel(timelabel)
generate time label
Definition: scale_time.F90:90
integer, public ka
of z whole cells (local, with HALO)
character(len=h_long), public atmos_phy_mp_restart_out_basename
basename of the output file
real(rp), dimension(:,:,:), allocatable, public atmos_phy_mp_dens_t
subroutine, public atmos_phy_mp_vars_restart_create
Create restart file.
subroutine, public fileio_create(fid, basename, title, datatype, date, subsec, append, nozcoord)
Create/open a netCDF file.
module COMMUNICATION
Definition: scale_comm.F90:23
module TIME
Definition: scale_time.F90:15
module PROCESS
logical, public atmos_phy_mp_restart_output
output restart file?
subroutine, public atmos_phy_mp_vars_fillhalo
HALO Communication.
module CONSTANT
Definition: scale_const.F90:14
character(len=h_mid), public atmos_phy_mp_restart_out_dtype
REAL4 or REAL8.
subroutine, public atmos_phy_mp_vars_restart_write_var
Write restart.
real(rp), dimension(:,:,:), allocatable, public atmos_phy_mp_evaporate
subroutine, public fileio_enddef(fid)
Exit netCDF file define mode.
real(rp), dimension(:,:), allocatable, public atmos_phy_mp_sflx_snow
subroutine, public atmos_phy_mp_vars_setup
Setup.
module profiler
Definition: scale_prof.F90:10
subroutine, public atmos_phy_mp_vars_restart_write
Write restart.
subroutine, public atmos_phy_mp_vars_restart_read
Read restart.
subroutine, public atmos_phy_mp_vars_restart_close
Close restart file.
logical, public io_lnml
output log or not? (for namelist, this process)
Definition: scale_stdio.F90:60
module PRECISION
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_mp_momx_t
integer, public ja
of y whole cells (local, with HALO)