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  logical, public :: atmos_phy_mp_restart_in_postfix_timelabel = .false.
51  character(len=H_LONG), public :: atmos_phy_mp_restart_out_basename = ''
52  logical, public :: atmos_phy_mp_restart_out_postfix_timelabel = .true.
53  character(len=H_MID), public :: atmos_phy_mp_restart_out_title = 'ATMOS_PHY_MP restart'
54  character(len=H_SHORT), public :: atmos_phy_mp_restart_out_dtype = 'DEFAULT'
55 
56  real(RP), public, allocatable :: atmos_phy_mp_dens_t(:,:,:) ! tendency DENS [kg/m3/s]
57  real(RP), public, allocatable :: atmos_phy_mp_momz_t(:,:,:) ! tendency MOMZ [kg/m2/s2]
58  real(RP), public, allocatable :: atmos_phy_mp_momx_t(:,:,:) ! tendency MOMX [kg/m2/s2]
59  real(RP), public, allocatable :: atmos_phy_mp_momy_t(:,:,:) ! tendency MOMY [kg/m2/s2]
60  real(RP), public, allocatable :: atmos_phy_mp_rhot_t(:,:,:) ! tendency RHOT [K*kg/m3/s]
61  real(RP), public, allocatable :: atmos_phy_mp_rhoq_t(:,:,:,:) ! tendency rho*QTRC [kg/kg/s]
62 
63  real(RP), public, allocatable :: atmos_phy_mp_evaporate(:,:,:) ! number concentration of evaporated cloud [/m3]
64  real(RP), public, allocatable :: atmos_phy_mp_sflx_rain(:,:) ! precipitation flux (liquid) [kg/m2/s]
65  real(RP), public, allocatable :: atmos_phy_mp_sflx_snow(:,:) ! precipitation flux (solid) [kg/m2/s]
66 
67  !-----------------------------------------------------------------------------
68  !
69  !++ Private procedure
70  !
71  !-----------------------------------------------------------------------------
72  !
73  !++ Private parameters & variables
74  !
75  integer, private, parameter :: vmax = 2
76  integer, private, parameter :: i_sflx_rain = 1
77  integer, private, parameter :: i_sflx_snow = 2
78 
79  character(len=H_SHORT), private :: var_name(vmax)
80  character(len=H_MID), private :: var_desc(vmax)
81  character(len=H_SHORT), private :: var_unit(vmax)
82  integer, private :: var_id(vmax)
83  integer, private :: restart_fid = -1 ! file ID
84 
85  data var_name / 'SFLX_rain', &
86  'SFLX_snow' /
87  data var_desc / 'precipitation flux (liquid)', &
88  'precipitation flux (solid)' /
89  data var_unit / 'kg/m2/s', &
90  'kg/m2/s' /
91 
92  !-----------------------------------------------------------------------------
93 contains
94  !-----------------------------------------------------------------------------
96  subroutine atmos_phy_mp_vars_setup
97  use scale_process, only: &
99  use scale_const, only: &
100  undef => const_undef
101  use scale_atmos_phy_mp, only: &
102  qs_mp, &
103  qe_mp
104  implicit none
105 
106  namelist / param_atmos_phy_mp_vars / &
114 
115  integer :: ierr
116  integer :: iv
117  !---------------------------------------------------------------------------
118 
119  if( io_l ) write(io_fid_log,*)
120  if( io_l ) write(io_fid_log,*) '++++++ Module[VARS] / Categ[ATMOS PHY_MP] / Origin[SCALE-RM]'
121 
122  allocate( atmos_phy_mp_dens_t(ka,ia,ja) )
123  allocate( atmos_phy_mp_momz_t(ka,ia,ja) )
124  allocate( atmos_phy_mp_momx_t(ka,ia,ja) )
125  allocate( atmos_phy_mp_momy_t(ka,ia,ja) )
126  allocate( atmos_phy_mp_rhot_t(ka,ia,ja) )
127  allocate( atmos_phy_mp_rhoq_t(ka,ia,ja,qs_mp:qe_mp) )
128  allocate( atmos_phy_mp_evaporate(ka,ia,ja) )
129  ! tentative approach
130  atmos_phy_mp_dens_t(:,:,:) = 0.0_rp
131  atmos_phy_mp_momz_t(:,:,:) = 0.0_rp
132  atmos_phy_mp_momx_t(:,:,:) = 0.0_rp
133  atmos_phy_mp_momy_t(:,:,:) = 0.0_rp
134  atmos_phy_mp_rhot_t(:,:,:) = 0.0_rp
135  atmos_phy_mp_rhoq_t(:,:,:,:) = 0.0_rp
136  atmos_phy_mp_evaporate(:,:,:) = 0.0_rp
137 
138  allocate( atmos_phy_mp_sflx_rain(ia,ja) )
139  allocate( atmos_phy_mp_sflx_snow(ia,ja) )
140  atmos_phy_mp_sflx_rain(:,:) = undef
141  atmos_phy_mp_sflx_snow(:,:) = undef
142 
143  !--- read namelist
144  rewind(io_fid_conf)
145  read(io_fid_conf,nml=param_atmos_phy_mp_vars,iostat=ierr)
146  if( ierr < 0 ) then !--- missing
147  if( io_l ) write(io_fid_log,*) '*** Not found namelist. Default used.'
148  elseif( ierr > 0 ) then !--- fatal error
149  write(*,*) 'xxx Not appropriate names in namelist PARAM_ATMOS_PHY_MP_VARS. Check!'
150  call prc_mpistop
151  endif
152  if( io_nml ) write(io_fid_nml,nml=param_atmos_phy_mp_vars)
153 
154  if( io_l ) write(io_fid_log,*)
155  if( io_l ) write(io_fid_log,*) '*** [ATMOS_PHY_MP] prognostic/diagnostic variables'
156  if( io_l ) write(io_fid_log,'(1x,A,A24,A,A48,A,A12,A)') &
157  '*** |', 'VARNAME ','|', &
158  'DESCRIPTION ', '[', 'UNIT ', ']'
159  do iv = 1, vmax
160  if( io_l ) write(io_fid_log,'(1x,A,I3,A,A24,A,A48,A,A12,A)') &
161  '*** NO.',iv,'|',var_name(iv),'|',var_desc(iv),'[',var_unit(iv),']'
162  enddo
163 
164  if( io_l ) write(io_fid_log,*)
165  if ( atmos_phy_mp_restart_in_basename /= '' ) then
166  if( io_l ) write(io_fid_log,*) '*** Restart input? : YES, file = ', trim(atmos_phy_mp_restart_in_basename)
167  if( io_l ) write(io_fid_log,*) '*** Add timelabel? : ', atmos_phy_mp_restart_in_postfix_timelabel
168  else
169  if( io_l ) write(io_fid_log,*) '*** Restart input? : NO'
170  endif
172  .AND. atmos_phy_mp_restart_out_basename /= '' ) then
173  if( io_l ) write(io_fid_log,*) '*** Restart output? : YES, file = ', trim(atmos_phy_mp_restart_out_basename)
174  if( io_l ) write(io_fid_log,*) '*** Add timelabel? : ', atmos_phy_mp_restart_out_postfix_timelabel
175  else
176  if( io_l ) write(io_fid_log,*) '*** Restart output? : NO'
178  endif
179 
180  return
181  end subroutine atmos_phy_mp_vars_setup
182 
183  !-----------------------------------------------------------------------------
185  subroutine atmos_phy_mp_vars_fillhalo
186  use scale_comm, only: &
187  comm_vars8, &
188  comm_wait
189  implicit none
190  !---------------------------------------------------------------------------
191 
192  call comm_vars8( atmos_phy_mp_sflx_rain(:,:), 1 )
193  call comm_vars8( atmos_phy_mp_sflx_snow(:,:), 2 )
194  call comm_wait ( atmos_phy_mp_sflx_rain(:,:), 1 )
195  call comm_wait ( atmos_phy_mp_sflx_snow(:,:), 2 )
196 
197  return
198  end subroutine atmos_phy_mp_vars_fillhalo
199 
200  !-----------------------------------------------------------------------------
203  use scale_time, only: &
205  use scale_fileio, only: &
207  implicit none
208 
209  character(len=19) :: timelabel
210  character(len=H_LONG) :: basename
211  !---------------------------------------------------------------------------
212 
213  if( io_l ) write(io_fid_log,*)
214  if( io_l ) write(io_fid_log,*) '*** Open restart file (ATMOS_PHY_MP) ***'
215 
216  if ( atmos_phy_mp_restart_in_basename /= '' ) then
217 
219  call time_gettimelabel( timelabel )
220  basename = trim(atmos_phy_mp_restart_in_basename)//'_'//trim(timelabel)
221  else
222  basename = trim(atmos_phy_mp_restart_in_basename)
223  endif
224 
225  if( io_l ) write(io_fid_log,*) '*** basename: ', trim(basename)
226 
227  call fileio_open( restart_fid, basename )
228  else
229  if( io_l ) write(io_fid_log,*) '*** restart file for ATMOS_PHY_MP is not specified.'
230  endif
231 
232  return
233  end subroutine atmos_phy_mp_vars_restart_open
234 
235  !-----------------------------------------------------------------------------
238  use scale_rm_statistics, only: &
240  stat_total
241  use scale_fileio, only: &
242  fileio_read, &
244  implicit none
245 
246  real(RP) :: total
247  !---------------------------------------------------------------------------
248 
249  if ( restart_fid /= -1 ) then
250  if( io_l ) write(io_fid_log,*)
251  if( io_l ) write(io_fid_log,*) '*** Read from restart file (ATMOS_PHY_MP) ***'
252 
253  call fileio_read( atmos_phy_mp_sflx_rain(:,:), & ! [OUT]
254  restart_fid, var_name(1), 'XY', step=1 ) ! [IN]
255  call fileio_read( atmos_phy_mp_sflx_snow(:,:), & ! [OUT]
256  restart_fid, var_name(2), 'XY', step=1 ) ! [IN]
257 
258  if ( io_aggregate ) then
259  call fileio_flush( restart_fid ) ! X/Y halos have been read from file
260  else
262  end if
263 
264  if ( statistics_checktotal ) then
265  call stat_total( total, atmos_phy_mp_sflx_rain(:,:), var_name(1) )
266  call stat_total( total, atmos_phy_mp_sflx_snow(:,:), var_name(2) )
267  endif
268  else
269  if( io_l ) write(io_fid_log,*) '*** invalid restart file ID for ATMOS_PHY_MP.'
270  endif
271 
272  return
273  end subroutine atmos_phy_mp_vars_restart_read
274 
275  !-----------------------------------------------------------------------------
278  use scale_time, only: &
280  use scale_fileio, only: &
282  implicit none
283 
284  character(len=19) :: timelabel
285  character(len=H_LONG) :: basename
286  !---------------------------------------------------------------------------
287 
288  if ( atmos_phy_mp_restart_out_basename /= '' ) then
289 
290  if( io_l ) write(io_fid_log,*)
291  if( io_l ) write(io_fid_log,*) '*** Create restart file (ATMOS_PHY_AE) ***'
292 
294  call time_gettimelabel( timelabel )
295  basename = trim(atmos_phy_mp_restart_out_basename)//'_'//trim(timelabel)
296  else
297  basename = trim(atmos_phy_mp_restart_out_basename)
298  endif
299 
300  if( io_l ) write(io_fid_log,*) '*** basename: ', trim(basename)
301 
302  call fileio_create( restart_fid, & ! [OUT]
304 
305  endif
306 
307  return
308  end subroutine atmos_phy_mp_vars_restart_create
309 
310  !-----------------------------------------------------------------------------
313  use scale_fileio, only: &
315  implicit none
316 
317  if ( restart_fid /= -1 ) then
318  call fileio_enddef( restart_fid ) ! [IN]
319  endif
320 
321  return
322  end subroutine atmos_phy_mp_vars_restart_enddef
323 
324  !-----------------------------------------------------------------------------
327  use scale_fileio, only: &
329  implicit none
330  !---------------------------------------------------------------------------
331 
332  if ( restart_fid /= -1 ) then
333  if( io_l ) write(io_fid_log,*)
334  if( io_l ) write(io_fid_log,*) '*** Close restart file (ATMOS_PHY_MP) ***'
335 
336  call fileio_close( restart_fid ) ! [IN]
337 
338  restart_fid = -1
339  endif
340 
341  return
342  end subroutine atmos_phy_mp_vars_restart_close
343 
344  !-----------------------------------------------------------------------------
347  use scale_fileio, only: &
349  implicit none
350  !---------------------------------------------------------------------------
351 
352  if ( restart_fid /= -1 ) then
353 
354  call fileio_def_var( restart_fid, var_id(1), var_name(1), var_desc(1), &
355  var_unit(1), 'XY', atmos_phy_mp_restart_out_dtype ) ! [IN]
356  call fileio_def_var( restart_fid, var_id(2), var_name(2), var_desc(2), &
357  var_unit(2), 'XY', atmos_phy_mp_restart_out_dtype ) ! [IN]
358 
359  endif
360 
361  return
362  end subroutine atmos_phy_mp_vars_restart_def_var
363 
364  !-----------------------------------------------------------------------------
367  use scale_rm_statistics, only: &
369  stat_total
370  use scale_fileio, only: &
371  fileio_write_var
372  implicit none
373 
374  real(RP) :: total
375  !---------------------------------------------------------------------------
376 
377  if ( restart_fid /= -1 ) then
378 
380 
381  if ( statistics_checktotal ) then
382  call stat_total( total, atmos_phy_mp_sflx_rain(:,:), var_name(1) )
383  call stat_total( total, atmos_phy_mp_sflx_snow(:,:), var_name(2) )
384  endif
385 
386  call fileio_write_var( restart_fid, var_id(1), atmos_phy_mp_sflx_rain(:,:), &
387  var_name(1), 'XY' ) ! [IN]
388  call fileio_write_var( restart_fid, var_id(2), atmos_phy_mp_sflx_snow(:,:), &
389  var_name(2), 'XY' ) ! [IN]
390 
391  endif
392 
393  return
394  end subroutine atmos_phy_mp_vars_restart_write
395 
396 end module mod_atmos_phy_mp_vars
real(rp), dimension(:,:,:,:), allocatable, public atmos_phy_mp_rhoq_t
logical, public statistics_checktotal
calc&report variable totals to logfile?
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:61
character(len=h_long), public atmos_phy_mp_restart_in_basename
Basename of the input file.
subroutine, public fileio_flush(fid)
Flush all pending requests to a netCDF file (PnetCDF only)
module ATMOSPHERE / Physics Cloud Microphysics
module STDIO
Definition: scale_stdio.F90:12
logical, public atmos_phy_mp_restart_in_postfix_timelabel
Add timelabel to the basename of input file?
subroutine, public atmos_phy_mp_vars_restart_def_var
Define variables in restart file.
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
logical, public io_nml
output log or not? (for namelist, this process)
Definition: scale_stdio.F90:62
module TRACER
integer, public ia
of whole cells: x, 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 whole cells: z, 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_short), public atmos_phy_mp_restart_out_dtype
REAL4 or REAL8.
real(rp), dimension(:,:,:), allocatable, public atmos_phy_mp_evaporate
subroutine, public atmos_phy_mp_vars_restart_open
Open restart file for read.
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_aggregate
do parallel I/O through PnetCDF
Definition: scale_stdio.F90:66
subroutine, public fileio_open(fid, basename)
open a netCDF file for read
module PRECISION
subroutine, public fileio_def_var(fid, vid, varname, desc, unit, axistype, datatype, timeintv, nsteps)
Define a variable to file.
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
integer, public io_fid_nml
Log file ID (only for output namelist)
Definition: scale_stdio.F90:57
logical, public atmos_phy_mp_restart_out_postfix_timelabel
Add timelabel to the basename of output file?
real(rp), dimension(:,:,:), allocatable, public atmos_phy_mp_momx_t
integer, public ja
of whole cells: y, local, with HALO