SCALE-RM
mod_atmos_phy_ae_vars.F90
Go to the documentation of this file.
1 !-------------------------------------------------------------------------------
10 !-------------------------------------------------------------------------------
11 #include "scalelib.h"
13  !-----------------------------------------------------------------------------
14  !
15  !++ used modules
16  !
17  use scale_precision
18  use scale_io
19  use scale_prof
21  !-----------------------------------------------------------------------------
22  implicit none
23  private
24  !-----------------------------------------------------------------------------
25  !
26  !++ Public procedure
27  !
28  public :: atmos_phy_ae_vars_setup
32 
38 
40 
43 
44  !-----------------------------------------------------------------------------
45  !
46  !++ Public parameters & variables
47  !
48  logical, public :: atmos_phy_ae_restart_output = .false.
49 
50  character(len=H_LONG), public :: atmos_phy_ae_restart_in_basename = ''
52  logical, public :: atmos_phy_ae_restart_in_postfix_timelabel = .false.
53  character(len=H_LONG), public :: atmos_phy_ae_restart_out_basename = ''
55  logical, public :: atmos_phy_ae_restart_out_postfix_timelabel = .true.
56  character(len=H_MID), public :: atmos_phy_ae_restart_out_title = 'ATMOS_PHY_AE restart'
57  character(len=H_SHORT), public :: atmos_phy_ae_restart_out_dtype = 'DEFAULT'
58 
59  real(RP), public, allocatable :: atmos_phy_ae_rhoq_t(:,:,:,:) ! tendency rho*QTRC [kg/kg/s]
60 
61  real(RP), public, allocatable :: atmos_phy_ae_ccn(:,:,:) ! cloud condensation nuclei [/m3]
62  real(RP), public, allocatable :: atmos_phy_ae_ccn_t(:,:,:) ! tendency CCN [/m3/s]
63  real(RP), public, allocatable :: atmos_phy_ae_emit(:,:,:,:) ! emission of aerosol and gas
64 
65  integer, public :: qa_ae = 0
66  integer, public :: qs_ae = -1
67  integer, public :: qe_ae = -2
68 
69  !-----------------------------------------------------------------------------
70  !
71  !++ Private procedure
72  !
73  !-----------------------------------------------------------------------------
74  !
75  !++ Private parameters & variables
76  !
77  integer, private, parameter :: vmax = 1
78  integer, private, parameter :: i_ccn = 1
79 
80  character(len=H_SHORT), private :: var_name(vmax)
81  character(len=H_MID), private :: var_desc(vmax)
82  character(len=H_SHORT), private :: var_unit(vmax)
83  integer, private :: var_id(vmax)
84  integer, private :: restart_fid = -1 ! file ID
85 
86  data var_name / 'CCN' /
87  data var_desc / 'cloud condensation nuclei' /
88  data var_unit / 'num/m3' /
89 
90 
91  ! for diagnostics
92  real(RP), private, allocatable :: atmos_phy_ae_re(:,:,:,:)
93  real(RP), private, allocatable :: atmos_phy_ae_qe(:,:,:,:)
94  logical, private :: diag_re
95  logical, private :: diag_qe
96 
97  ! for history
98  integer, private,allocatable :: hist_re_id(:)
99  logical, private :: hist_re
100 
101  !-----------------------------------------------------------------------------
102 contains
103  !-----------------------------------------------------------------------------
105  subroutine atmos_phy_ae_vars_setup
106  use scale_prc, only: &
107  prc_abort
108  use scale_const, only: &
109  undef => const_undef
110  use scale_atmos_aerosol, only: &
111  n_ae, &
112  ae_name, &
113  ae_desc
114  use scale_file_history, only: &
116  implicit none
117 
118  namelist / param_atmos_phy_ae_vars / &
128 
129  integer :: ierr
130  integer :: iv
131  !---------------------------------------------------------------------------
132 
133  log_newline
134  log_info("ATMOS_PHY_AE_vars_setup",*) 'Setup'
135 
136  allocate( atmos_phy_ae_rhoq_t(ka,ia,ja,qs_ae:qe_ae) )
137  atmos_phy_ae_rhoq_t(:,:,:, :) = undef
138 
139  allocate( atmos_phy_ae_ccn(ka,ia,ja) )
140  atmos_phy_ae_ccn(:,:,:) = undef
141 
142  allocate( atmos_phy_ae_ccn_t(ka,ia,ja) )
143  atmos_phy_ae_ccn_t(:,:,:) = undef
144 
145  allocate( atmos_phy_ae_emit(ka,ia,ja,qs_ae:qe_ae) )
146  atmos_phy_ae_emit(:,:,:,:) = 0.0_rp
147 
148  !--- read namelist
149  rewind(io_fid_conf)
150  read(io_fid_conf,nml=param_atmos_phy_ae_vars,iostat=ierr)
151  if( ierr < 0 ) then !--- missing
152  log_info("ATMOS_PHY_AE_vars_setup",*) 'Not found namelist. Default used.'
153  elseif( ierr > 0 ) then !--- fatal error
154  log_error("ATMOS_PHY_AE_vars_setup",*) 'Not appropriate names in namelist PARAM_ATMOS_PHY_AE_VARS. Check!'
155  call prc_abort
156  endif
157  log_nml(param_atmos_phy_ae_vars)
158 
159  log_newline
160  log_info("ATMOS_PHY_AE_vars_setup",*) '[ATMOS_PHY_AE] prognostic/diagnostic variables'
161  log_info_cont('(1x,A,A24,A,A48,A,A12,A)') &
162  ' |', 'VARNAME ','|', &
163  'DESCRIPTION ', '[', 'UNIT ', ']'
164  do iv = 1, vmax
165  log_info_cont('(1x,A,I3,A,A24,A,A48,A,A12,A)') &
166  'NO.',iv,'|',var_name(iv),'|',var_desc(iv),'[',var_unit(iv),']'
167  enddo
168 
169  log_newline
170  if ( atmos_phy_ae_restart_in_basename /= '' ) then
171  log_info("ATMOS_PHY_AE_vars_setup",*) 'Restart input? : YES, file = ', trim(atmos_phy_ae_restart_in_basename)
172  log_info("ATMOS_PHY_AE_vars_setup",*) 'Add timelabel? : ', atmos_phy_ae_restart_in_postfix_timelabel
173  else
174  log_info("ATMOS_PHY_AE_vars_setup",*) 'Restart input? : NO'
175  endif
177  .AND. atmos_phy_ae_restart_out_basename /= '' ) then
178  log_info("ATMOS_PHY_AE_vars_setup",*) 'Restart output? : YES, file = ', trim(atmos_phy_ae_restart_out_basename)
179  log_info("ATMOS_PHY_AE_vars_setup",*) 'Add timelabel? : ', atmos_phy_ae_restart_out_postfix_timelabel
180  else
181  log_info("ATMOS_PHY_AE_vars_setup",*) 'Restart output? : NO'
183  endif
184 
185  ! diagnostices
186  allocate( atmos_phy_ae_re(ka,ia,ja,n_ae) )
187  allocate( atmos_phy_ae_qe(ka,ia,ja,n_ae) )
188 !OCL XFILL
189  atmos_phy_ae_re(:,:,:,:) = undef
190 !OCL XFILL
191  atmos_phy_ae_qe(:,:,:,:) = undef
192  diag_re = .false.
193  diag_qe = .false.
194 
195  ! history
196  hist_re = .false.
197  allocate( hist_re_id(n_ae) )
198  do iv = 1, n_ae
199  call file_history_reg( 'Re_'//trim(ae_name(iv)), 'effective radius of '//trim(ae_desc(iv)), 'cm', hist_re_id(iv), fill_halo=.true., dim_type='ZXY' )
200  if ( hist_re_id(iv) > 0 ) hist_re = .true.
201  end do
202 
203  return
204  end subroutine atmos_phy_ae_vars_setup
205 
206  !-----------------------------------------------------------------------------
208  subroutine atmos_phy_ae_vars_fillhalo
209  use scale_comm_cartesc, only: &
210  comm_vars8, &
211  comm_wait
212  implicit none
213 
214  integer :: i, j
215  !---------------------------------------------------------------------------
216 
217  do j = js, je
218  do i = is, ie
219  atmos_phy_ae_ccn( 1:ks-1,i,j) = atmos_phy_ae_ccn(ks,i,j)
220  atmos_phy_ae_ccn(ke+1:ka, i,j) = atmos_phy_ae_ccn(ke,i,j)
221  enddo
222  enddo
223 
224  call comm_vars8( atmos_phy_ae_ccn(:,:,:), 1 )
225  call comm_wait ( atmos_phy_ae_ccn(:,:,:), 1 )
226 
227  return
228  end subroutine atmos_phy_ae_vars_fillhalo
229 
230  !-----------------------------------------------------------------------------
233  use scale_time, only: &
235  use scale_file_cartesc, only: &
237  implicit none
238 
239  character(len=19) :: timelabel
240  character(len=H_LONG) :: basename
241  !---------------------------------------------------------------------------
242 
243  log_newline
244  log_info("ATMOS_PHY_AE_vars_restart_open",*) 'Open restart file (ATMOS_PHY_AE) '
245 
246  if ( atmos_phy_ae_restart_in_basename /= '' ) then
247 
249  call time_gettimelabel( timelabel )
250  basename = trim(atmos_phy_ae_restart_in_basename)//'_'//trim(timelabel)
251  else
252  basename = trim(atmos_phy_ae_restart_in_basename)
253  endif
254 
255  log_info("ATMOS_PHY_AE_vars_restart_open",*) 'basename: ', trim(basename)
256 
257  call file_cartesc_open( basename, restart_fid, aggregate=atmos_phy_ae_restart_in_aggregate )
258  else
259  log_info("ATMOS_PHY_AE_vars_restart_open",*) 'restart file for ATMOS_PHY_AE is not specified.'
260  endif
261 
262  return
263  end subroutine atmos_phy_ae_vars_restart_open
264 
265  !-----------------------------------------------------------------------------
268  use scale_statistics, only: &
270  statistics_total
271  use scale_atmos_grid_cartesc_real, only: &
274  use scale_file, only: &
276  use scale_file_cartesc, only: &
277  file_cartesc_read, &
279  implicit none
280 
281  integer :: i, j
282  !---------------------------------------------------------------------------
283 
284  if ( restart_fid /= -1 ) then
285  log_newline
286  log_info("ATMOS_PHY_AE_vars_restart_read",*) 'Read from restart file (ATMOS_PHY_AE) '
287 
288  call file_cartesc_read( restart_fid, var_name(1), 'ZXY', & ! [IN]
289  atmos_phy_ae_ccn(:,:,:) ) ! [OUT]
290 
291  if ( file_get_aggregate(restart_fid) ) then
292  call file_cartesc_flush( restart_fid ) ! X/Y halos have been read from file
293 
294  ! fill K halos
295  do j = 1, ja
296  do i = 1, ia
297  atmos_phy_ae_ccn( 1:ks-1,i,j) = atmos_phy_ae_ccn(ks,i,j)
298  atmos_phy_ae_ccn(ke+1:ka, i,j) = atmos_phy_ae_ccn(ke,i,j)
299  enddo
300  enddo
301  else
303  end if
304 
305  if ( statistics_checktotal ) then
306  call statistics_total( ka, ks, ke, ia, is, ie, ja, js, je, &
307  atmos_phy_ae_ccn(:,:,:), var_name(1), &
308  atmos_grid_cartesc_real_vol(:,:,:), & ! (in)
310  end if
311  else
312  log_info("ATMOS_PHY_AE_vars_restart_read",*) 'invlaid restart file ID for ATMOS_PHY_AE.'
313  endif
314 
315  return
316  end subroutine atmos_phy_ae_vars_restart_read
317 
318  !-----------------------------------------------------------------------------
321  use scale_time, only: &
323  use scale_file_cartesc, only: &
325  implicit none
326 
327  character(len=19) :: timelabel
328  character(len=H_LONG) :: basename
329  !---------------------------------------------------------------------------
330 
331  if ( atmos_phy_ae_restart_out_basename /= '' ) then
332 
333  log_newline
334  log_info("ATMOS_PHY_AE_vars_restart_create",*) 'Create restart file (ATMOS_PHY_AE) '
335 
337  call time_gettimelabel( timelabel )
338  basename = trim(atmos_phy_ae_restart_out_basename)//'_'//trim(timelabel)
339  else
340  basename = trim(atmos_phy_ae_restart_out_basename)
341  endif
342 
343  log_info("ATMOS_PHY_AE_vars_restart_create",*) 'basename: ', trim(basename)
344 
345  call file_cartesc_create( &
347  restart_fid, & ! [OUT]
348  aggregate=atmos_phy_ae_restart_out_aggregate ) ! [IN]
349 
350  endif
351 
352  return
353  end subroutine atmos_phy_ae_vars_restart_create
354 
355  !-----------------------------------------------------------------------------
358  use scale_file_cartesc, only: &
360  implicit none
361 
362  if ( restart_fid /= -1 ) then
363  call file_cartesc_enddef( restart_fid ) ! [IN]
364  endif
365 
366  return
367  end subroutine atmos_phy_ae_vars_restart_enddef
368 
369  !-----------------------------------------------------------------------------
372  use scale_file_cartesc, only: &
374  implicit none
375  !---------------------------------------------------------------------------
376 
377  if ( restart_fid /= -1 ) then
378  log_newline
379  log_info("ATMOS_PHY_AE_vars_restart_close",*) 'Close restart file (ATMOS_PHY_AE) '
380 
381  call file_cartesc_close( restart_fid ) ! [IN]
382 
383  restart_fid = -1
384  endif
385 
386  return
387  end subroutine atmos_phy_ae_vars_restart_close
388 
389  !-----------------------------------------------------------------------------
392  use scale_file_cartesc, only: &
394  implicit none
395  !---------------------------------------------------------------------------
396 
397  if ( restart_fid /= -1 ) then
398  call file_cartesc_def_var( restart_fid, var_name(1), var_desc(1), var_unit(1), 'ZXY', atmos_phy_ae_restart_out_dtype, &
399  var_id(1) )
400  endif
401 
402  return
403  end subroutine atmos_phy_ae_vars_restart_def_var
404 
405  !-----------------------------------------------------------------------------
408  use scale_statistics, only: &
410  statistics_total
411  use scale_atmos_grid_cartesc_real, only: &
414  use scale_file_cartesc, only: &
415  file_cartesc_write_var
416  implicit none
417  !---------------------------------------------------------------------------
418 
419  if ( restart_fid /= -1 ) then
420 
422 
423  if ( statistics_checktotal ) then
424  call statistics_total( ka, ks, ke, ia, is, ie, ja, js, je, &
425  atmos_phy_ae_ccn(:,:,:), var_name(1), &
426  atmos_grid_cartesc_real_vol(:,:,:), & ! (in)
428  end if
429 
430  call file_cartesc_write_var( restart_fid, var_id(1), atmos_phy_ae_ccn(:,:,:), var_name(1), 'ZXY' ) ! [IN]
431 
432  endif
433 
434  return
435  end subroutine atmos_phy_ae_vars_restart_write
436 
437  subroutine atmos_phy_ae_vars_history( &
438  QTRC, RH )
439  use scale_tracer, only: &
440  qa
441  use scale_atmos_aerosol, only: &
442  n_ae
443  use scale_file_history, only: &
444  file_history_put
445  real(RP), intent(in) :: QTRC(ka,ia,ja,qa)
446  real(RP), intent(in) :: RH(ka,ia,ja)
447 
448  real(RP) :: WORK(ka,ia,ja,n_ae)
449  integer :: iv
450 
451  if ( hist_re ) then
453  qtrc(:,:,:,:), rh(:,:,:), & ! [IN]
454  re=work(:,:,:,:) ) ! [OUT]
455  do iv = 1, n_ae
456  if ( hist_re_id(iv) > 0 ) &
457  call file_history_put( hist_re_id(iv), work(:,:,:,iv) )
458  end do
459  end if
460 
461  return
462  end subroutine atmos_phy_ae_vars_history
463 
465  QTRC, RH, &
466  Re, Qe )
467  use scale_tracer, only: &
468  qa
469  use scale_atmos_aerosol, only: &
470  n_ae
471  use scale_atmos_phy_ae_kajino13, only: &
473  use mod_atmos_admin, only: &
475 
476  real(RP), intent(in) :: QTRC(ka,ia,ja,qa)
477  real(RP), intent(in) :: RH(ka,ia,ja)
478  real(RP), intent(out), optional :: Re(ka,ia,ja,n_ae)
479  real(RP), intent(out), optional :: Qe(ka,ia,ja,n_ae)
480 
481  if ( present(re) ) then
482  if ( .not. diag_re ) then
483  select case ( atmos_phy_ae_type )
484  case ( 'KAJINO13' )
486  ka, ia, ja, qa_ae, &
487  qtrc(:,:,:,qs_ae:qe_ae), rh(:,:,:), & ! [IN]
488  atmos_phy_ae_re(:,:,:,:) ) ! [OUT]
489  case default
490  atmos_phy_ae_re(:,:,:,:) = 0.0_rp
491  end select
492  diag_re = .true.
493  end if
494 !OCL XFILL
495  re(:,:,:,:) = atmos_phy_ae_re(:,:,:,:)
496  end if
497 
498  if ( present(qe) ) then
499  if ( .not. diag_qe ) then
500  select case ( atmos_phy_ae_type )
501  case default
502  atmos_phy_ae_qe(:,:,:,:) = 0.0_rp
503  end select
504  diag_qe = .true.
505  end if
506 !OCL XFILL
507  qe(:,:,:,:) = atmos_phy_ae_qe(:,:,:,:)
508  end if
509 
510  return
511  end subroutine atmos_phy_ae_vars_get_diagnostic
512 
514  diag_re = .false.
515  diag_qe = .false.
516 
517  return
519 
520 end module mod_atmos_phy_ae_vars
logical, public atmos_phy_ae_restart_in_postfix_timelabel
Add timelabel to the basename of input file?
module ATMOS admin
character(len=h_long), public atmos_phy_ae_restart_in_basename
Basename of the input file.
subroutine, public atmos_phy_ae_vars_restart_create
Create restart file.
subroutine, public atmos_phy_ae_vars_fillhalo
HALO Communication.
character(len=h_short), dimension(n_ae), parameter, public ae_name
subroutine, public atmos_phy_ae_vars_get_diagnostic(QTRC, RH, Re, Qe)
integer, parameter, public n_ae
integer, public ia
of whole cells: x, local, with HALO
logical, public atmos_phy_ae_restart_output
output restart file?
integer, public qa
logical, public atmos_phy_ae_restart_out_postfix_timelabel
Add timelabel to the basename of output file?
real(rp), dimension(:,:,:), allocatable, public atmos_grid_cartesc_real_vol
control volume (zxy) [m3]
real(rp), public atmos_grid_cartesc_real_totvol
total volume (zxy, local) [m3]
subroutine, public atmos_phy_ae_kajino13_effective_radius(KA, IA, JA, QA_AE, QTRC, RH, Re)
Calculate Effective Radius.
integer, public ja
of whole cells: y, local, with HALO
character(len=h_short), public atmos_phy_ae_type
integer, public io_fid_conf
Config file ID.
Definition: scale_io.F90:55
subroutine, public atmos_phy_ae_vars_reset_diagnostics
subroutine, public file_history_reg(name, desc, unit, itemid, standard_name, ndims, dim_type, cell_measures, fill_halo)
Register/Append variable to history file.
logical, public statistics_checktotal
calc&report variable totals to logfile?
module atmosphere / aerosol
subroutine, public atmos_phy_ae_vars_history(QTRC, RH)
real(rp), public const_undef
Definition: scale_const.F90:41
module COMMUNICATION
integer, public is
start point of inner domain: x, local
module file
Definition: scale_file.F90:15
integer, public ie
end point of inner domain: x, local
subroutine, public file_cartesc_create(basename, title, datatype, fid, date, subsec, haszcoord, append, aggregate, single)
Create/open a netCDF file.
module TRACER
subroutine, public time_gettimelabel(timelabel)
generate time label
Definition: scale_time.F90:94
module atmosphere / grid / cartesC index
integer, public ke
end point of inner domain: z, local
module PROCESS
Definition: scale_prc.F90:11
real(rp), dimension(:,:,:,:), allocatable, public atmos_phy_ae_emit
integer, public je
end point of inner domain: y, local
subroutine, public file_cartesc_enddef(fid)
Exit netCDF file define mode.
module TIME
Definition: scale_time.F90:16
integer, public ks
start point of inner domain: z, local
real(rp), dimension(:,:,:,:), allocatable, public atmos_phy_ae_rhoq_t
real(rp), dimension(:,:,:), allocatable, public atmos_phy_ae_ccn
character(len=h_mid), public atmos_phy_ae_restart_out_title
title of the output file
subroutine, public atmos_phy_ae_vars_restart_enddef
Exit netCDF define mode.
subroutine, public prc_abort
Abort Process.
Definition: scale_prc.F90:338
module CONSTANT
Definition: scale_const.F90:11
character(len=h_short), public atmos_phy_ae_restart_out_dtype
REAL4 or REAL8.
logical, public atmos_phy_ae_restart_out_aggregate
Switch to use aggregate file.
integer, public js
start point of inner domain: y, local
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.
subroutine, public atmos_phy_ae_vars_setup
Setup.
subroutine, public atmos_phy_ae_vars_restart_read
Read restart.
logical function, public file_get_aggregate(fid)
module profiler
Definition: scale_prof.F90:11
character(len=h_mid), dimension(n_ae), parameter, public ae_desc
module Atmosphere GRID CartesC Real(real space)
module PRECISION
module file / cartesianC
module atmosphere / physics / aerosol / Kajino13
subroutine, public atmos_phy_ae_vars_restart_def_var
Write restart.
subroutine, public atmos_phy_ae_vars_restart_write
Write restart.
integer, public ka
of whole cells: z, local, with HALO
module Statistics
module STDIO
Definition: scale_io.F90:10
subroutine, public atmos_phy_ae_vars_restart_close
Close restart file.
subroutine, public file_cartesc_flush(fid)
Flush all pending requests to a netCDF file (PnetCDF only)
character(len=h_long), public atmos_phy_ae_restart_out_basename
Basename of the output file.
module ATMOSPHERE / Physics Aerosol Microphysics
subroutine, public file_cartesc_open(basename, fid, aggregate)
open a netCDF file for read
subroutine, public file_cartesc_close(fid)
Close a netCDF file.
logical, public atmos_phy_ae_restart_in_aggregate
Switch to use aggregate file.
subroutine, public atmos_phy_ae_vars_restart_open
Open restart file for read.
module file_history
real(rp), dimension(:,:,:), allocatable, public atmos_phy_ae_ccn_t