FV3DYCORE  Version 2.0.0
fv_control.F90
Go to the documentation of this file.
1 
2 !***********************************************************************
3 !* GNU Lesser General Public License
4 !*
5 !* This file is part of the FV3 dynamical core.
6 !*
7 !* The FV3 dynamical core is free software: you can redistribute it
8 !* and/or modify it under the terms of the
9 !* GNU Lesser General Public License as published by the
10 !* Free Software Foundation, either version 3 of the License, or
11 !* (at your option) any later version.
12 !*
13 !* The FV3 dynamical core is distributed in the hope that it will be
14 !* useful, but WITHOUT ANYWARRANTY; without even the implied warranty
15 !* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 !* See the GNU General Public License for more details.
17 !*
18 !* You should have received a copy of the GNU Lesser General Public
19 !* License along with the FV3 dynamical core.
20 !* If not, see <http://www.gnu.org/licenses/>.
21 !***********************************************************************
22 
25 !----------------
26 ! FV control panel
27 !----------------
28 
30 ! Modules Included:
31 ! <table>
32 ! <tr>
33 ! <th>Module Name</th>
34 ! <th>Functions Included</th>
35 ! </tr>
36 ! <table>
37 ! <tr>
38 ! <td>constants_mod</td>
39 ! <td>pi=>pi_8, kappa, radius, grav, rdgas</td>
40 ! </tr>
41 ! <tr>
42 ! <td>field_manager_mod</td>
43 ! <td>MODEL_ATMOS</td>
44 ! </tr>
45 ! <tr>
46 ! <td>fms_mod</td>
47 ! <td>write_version_number, open_namelist_file,
48 ! check_nml_error, close_file, file_exist</td>
49 ! </tr>
50 ! <tr>
51 ! <td>fv_arrays_mod</td>
52 ! <td>fv_atmos_type, allocate_fv_atmos_type, deallocate_fv_atmos_type,
53 ! R_GRID</td>
54 ! </tr>
55 ! <tr>
56 ! <td>fv_diagnostics_mod</td>
57 ! <td>fv_diag_init_gn</td>
58 ! </tr>
59 ! <tr>
60 ! <td>fv_eta_mod</td>
61 ! <td>set_eta</td>
62 ! </tr>
63 ! <tr>
64 ! <td>fv_grid_tools_mod</td>
65 ! <td>init_grid</td>
66 ! </tr>
67 ! <tr>
68 ! <td>fv_grid_utils_mod</td>
69 ! <td>grid_utils_init, grid_utils_end, ptop_min</td>
70 ! </tr>
71 ! <tr>
72 ! <td>fv_mp_mod</td>
73 ! <td>mp_start, mp_assign_gid, domain_decomp,ng, switch_current_Atm,
74 ! broadcast_domains, mp_barrier, is_master, setup_master </td>
75 ! </tr>
76 ! <tr>
77 ! <td>fv_io_mod</td>
78 ! <td>fv_io_exit</td>
79 ! </tr>
80 ! <tr>
81 ! <td>fv_restart_mod</td>
82 ! <td>fv_restart_init, fv_restart_end</td>
83 ! </tr>
84 ! <tr>
85 ! <td>fv_timing_mod</td>
86 ! <td>timing_on, timing_off, timing_init, timing_prt</td>
87 ! </tr>
88 ! <tr>
89 ! <td>mpp_mod</td>
90 ! <td>mpp_send, mpp_sync, mpp_transmit, mpp_set_current_pelist, mpp_declare_pelist,
91 ! mpp_root_pe, mpp_recv, mpp_sync_self, mpp_broadcast, read_input_nml,
92 ! FATAL, mpp_error, mpp_pe, stdlog, mpp_npes, mpp_get_current_pelist,
93 ! input_nml_file, get_unit, WARNING, read_ascii_file, INPUT_STR_LENGTH</td>
94 ! </tr>
95 ! <tr>
96 ! <td>mpp_domains_mod</td>
97 ! <td>mpp_get_data_domain, mpp_get_compute_domain, domain2D, mpp_define_nest_domains,
98 ! nest_domain_type, mpp_get_global_domain, mpp_get_C2F_index, mpp_get_F2C_index,
99 ! mpp_broadcast_domain, CENTER, CORNER, NORTH, EAST, WEST, SOUTH</td>
100 ! </tr>
101 ! <tr>
102 ! <td>mpp_parameter_mod</td>
103 ! <td>AGRID_PARAM=>AGRID</td>
104 ! </tr>
105 ! <tr>
106 ! <td>test_cases_mod</td>
107 ! <td>test_case, bubble_do, alpha, nsolitons, soliton_Umax, soliton_size</td>
108 ! </tr>
109 ! <tr>
110 ! <td>tracer_manager_mod</td>
111 ! <td>tm_get_number_tracers => get_number_tracers,tm_get_tracer_index => get_tracer_index,
112 ! tm_get_tracer_indices => get_tracer_indices, tm_set_tracer_profile => set_tracer_profile,
113 ! tm_get_tracer_names => get_tracer_names,tm_check_if_prognostic=> check_if_prognostic,
114 ! tm_register_tracers => register_tracers</td>
115 ! </tr>
116 ! </table>
117 
118  use constants_mod, only: pi=>pi_8, kappa, radius, grav, rdgas
119  use field_manager_mod, only: model_atmos
120  use fms_mod, only: write_version_number, open_namelist_file, &
121  check_nml_error, close_file, file_exist
122  use fms_io_mod, only: set_domain
123  use mpp_mod, only: fatal, mpp_error, mpp_pe, stdlog, &
124  mpp_npes, mpp_get_current_pelist, &
125  input_nml_file, get_unit, warning, &
126  read_ascii_file, input_str_length
127  use mpp_domains_mod, only: mpp_get_data_domain, mpp_get_compute_domain, mpp_get_tile_id
128  use tracer_manager_mod, only: tm_get_number_tracers => get_number_tracers, &
129  tm_get_tracer_index => get_tracer_index, &
130  tm_get_tracer_indices => get_tracer_indices, &
131  tm_set_tracer_profile => set_tracer_profile, &
132  tm_get_tracer_names => get_tracer_names, &
133  tm_check_if_prognostic=> check_if_prognostic,&
134  tm_register_tracers => register_tracers
135 
136  use fv_io_mod, only: fv_io_exit
139  r_grid
141  use fv_eta_mod, only: set_eta
142  use fv_grid_tools_mod, only: init_grid
143  use fv_mp_mod, only: mp_start, domain_decomp, mp_assign_gid, global_nest_domain
144  use fv_mp_mod, only: broadcast_domains, mp_barrier, is_master, setup_master, grids_master_procs, tile_fine
145  use fv_mp_mod, only: max_nnest, max_ntile
148  use mpp_domains_mod, only: domain2d
149  use mpp_domains_mod, only: mpp_define_nest_domains, nest_domain_type, mpp_get_global_domain
150  use mpp_domains_mod, only: mpp_get_c2f_index, mpp_get_f2c_index
151  use mpp_domains_mod, only: center, corner, north, east, west, south
152  use mpp_mod, only: mpp_send, mpp_sync, mpp_transmit, mpp_set_current_pelist, &
153  mpp_declare_pelist, mpp_root_pe, mpp_recv, mpp_sync_self, read_input_nml, &
154  mpp_max
156 
157 #ifdef MULTI_GASES
158  use constants_mod, only: rvgas, cp_air
159  use multi_gases_mod, only: multi_gases_init, &
161 #endif
162 
163  implicit none
164  private
165 
166 #ifdef OVERLOAD_R4
167  real :: too_big = 1.e8
168 #else
169  real :: too_big = 1.e35
170 #endif
171  public :: fv_control_init, fv_end
172 
173  integer, public :: ngrids = 1
174  integer :: commid, global_commid
175 
176  integer :: halo_update_type = 1 ! 1 for two-interfaces non-block
177  ! 2 for block
178  ! 3 for four-interfaces non-block
179 
180 ! version number of this module
181 ! Include variable "version" to be written to log file.
182 #include<file_version.h>
183 
184  contains
185 
186 !-------------------------------------------------------------------------------
187 
188  subroutine fv_control_init(Atm, dt_atmos, this_grid, grids_on_this_pe, p_split)
190  type(fv_atmos_type), allocatable, intent(inout), target :: Atm(:)
191  real, intent(in) :: dt_atmos
192  integer, intent(OUT) :: this_grid
193  logical, allocatable, intent(OUT) :: grids_on_this_pe(:)
194 
195  integer, intent(INOUT) :: p_split
196  character(100) :: pe_list_name, errstring
197  integer :: n, npes, pecounter, i, num_family, ntiles_nest_all
198  integer, allocatable :: global_pelist(:)
199  integer, dimension(MAX_NNEST) :: grid_pes = 0
200  integer, dimension(MAX_NNEST) :: grid_coarse = -1
201  integer, dimension(MAX_NNEST) :: nest_refine = 3
202  integer, dimension(MAX_NNEST) :: nest_ioffsets = -999, nest_joffsets = -999
203  integer, dimension(MAX_NNEST) :: all_npx = 0
204  integer, dimension(MAX_NNEST) :: all_npy = 0
205  integer, dimension(MAX_NNEST) :: all_npz = 0
206  integer, dimension(MAX_NNEST) :: all_ntiles = 0
207  integer, dimension(MAX_NNEST) :: all_twowaynest = 0 ! > 0 implies two-way
208  !integer, dimension(MAX_NNEST) :: tile_fine = 0
209  integer, dimension(MAX_NNEST) :: icount_coarse = 1
210  integer, dimension(MAX_NNEST) :: jcount_coarse = 1
211  integer, dimension(MAX_NNEST) :: nest_level = 0
212  integer, dimension(MAX_NNEST) :: tile_coarse = 0
213  integer, dimension(MAX_NTILE) :: npes_nest_tile = 0
214 
215  real :: sdt
216  integer :: unit, ens_root_pe, tile_id(1)
217 
218  !!!!!!!!!! POINTERS FOR READING NAMELISTS !!!!!!!!!!
219 
220  !------------------------------------------
221  ! Model Domain parameters
222  ! See fv_arrays.F90 for descriptions
223  !------------------------------------------
224  !CLEANUP module pointers
225  character(len=80) , pointer :: grid_name
226  character(len=120), pointer :: grid_file
227  integer, pointer :: grid_type
228  integer , pointer :: hord_mt
229  integer , pointer :: kord_mt
230  integer , pointer :: kord_wz
231  integer , pointer :: hord_vt
232  integer , pointer :: hord_tm
233  integer , pointer :: hord_dp
234  integer , pointer :: kord_tm
235  integer , pointer :: hord_tr
236  integer , pointer :: kord_tr
237  real , pointer :: scale_z
238  real , pointer :: w_max
239  real , pointer :: z_min
240  real , pointer :: lim_fac
241 
242  integer , pointer :: nord
243  integer , pointer :: nord_tr
244  real , pointer :: dddmp
245  real , pointer :: d2_bg
246  real , pointer :: d4_bg
247  real , pointer :: vtdm4
248  real , pointer :: trdm2
249  real , pointer :: d2_bg_k1
250  real , pointer :: d2_bg_k2
251  real , pointer :: d2_divg_max_k1
252  real , pointer :: d2_divg_max_k2
253  real , pointer :: damp_k_k1
254  real , pointer :: damp_k_k2
255  integer , pointer :: n_zs_filter
256  integer , pointer :: nord_zs_filter
257  logical , pointer :: full_zs_filter
258 
259  logical , pointer :: RF_fast
260  logical , pointer :: consv_am
261  logical , pointer :: do_sat_adj
262  logical , pointer :: do_f3d
263  logical , pointer :: no_dycore
264  logical , pointer :: convert_ke
265  logical , pointer :: do_vort_damp
266  logical , pointer :: use_old_omega
267  ! PG off centering:
268  real , pointer :: beta
269  integer , pointer :: n_sponge
270  real , pointer :: d_ext
271  integer , pointer :: nwat
272  logical , pointer :: warm_start
273  logical , pointer :: inline_q
274  real , pointer :: shift_fac
275  logical , pointer :: do_schmidt, do_cube_transform
276  real(kind=R_GRID) , pointer :: stretch_fac
277  real(kind=R_GRID) , pointer :: target_lat
278  real(kind=R_GRID) , pointer :: target_lon
279 
280  logical , pointer :: reset_eta
281  real , pointer :: p_fac
282  real , pointer :: a_imp
283  integer , pointer :: n_split
284  real , pointer :: fac_n_spl
285  real , pointer :: fhouri
286  ! Default
287  integer , pointer :: m_split
288  integer , pointer :: k_split
289  logical , pointer :: use_logp
290 
291  integer , pointer :: q_split
292  integer , pointer :: print_freq
293  logical , pointer :: write_3d_diags
294 
295  integer , pointer :: npx
296  integer , pointer :: npy
297  integer , pointer :: npz
298  character(len=24), pointer :: npz_type
299  integer , pointer :: npz_rst
300 
301  integer , pointer :: ncnst
302  integer , pointer :: pnats
303  integer , pointer :: dnats
304  integer , pointer :: dnrts
305  integer , pointer :: ntiles
306  integer , pointer :: nf_omega
307  integer , pointer :: fv_sg_adj
308  real , pointer :: sg_cutoff
309 
310  integer , pointer :: na_init
311  logical , pointer :: nudge_dz
312  real , pointer :: p_ref
313  real , pointer :: dry_mass
314  integer , pointer :: nt_prog
315  integer , pointer :: nt_phys
316  real , pointer :: tau_h2o
317 
318  real , pointer :: delt_max
319  real , pointer :: d_con
320  real , pointer :: ke_bg
321  real , pointer :: consv_te
322  real , pointer :: tau
323  real , pointer :: rf_cutoff
324  logical , pointer :: filter_phys
325  logical , pointer :: dwind_2d
326  logical , pointer :: breed_vortex_inline
327  logical , pointer :: range_warn
328  logical , pointer :: fill
329  logical , pointer :: fill_dp
330  logical , pointer :: fill_wz
331  logical , pointer :: fill_gfs
332  logical , pointer :: check_negative
333  logical , pointer :: non_ortho
334  logical , pointer :: adiabatic
335  logical , pointer :: moist_phys
336  logical , pointer :: do_Held_Suarez
337  logical , pointer :: do_reed_physics
338  logical , pointer :: reed_cond_only
339  logical , pointer :: reproduce_sum
340  logical , pointer :: adjust_dry_mass
341  logical , pointer :: fv_debug
342  logical , pointer :: srf_init
343  logical , pointer :: mountain
344  logical , pointer :: remap_t
345  logical , pointer :: z_tracer
346 
347  logical , pointer :: old_divg_damp
348  logical , pointer :: fv_land
349  logical , pointer :: nudge
350  logical , pointer :: nudge_ic
351  logical , pointer :: ncep_ic
352  logical , pointer :: nggps_ic
353  logical , pointer :: ecmwf_ic
354  logical , pointer :: gfs_phil
355  logical , pointer :: agrid_vel_rst
356  logical , pointer :: use_new_ncep
357  logical , pointer :: use_ncep_phy
358  logical , pointer :: fv_diag_ic
359  logical , pointer :: external_ic
360  logical , pointer :: external_eta
361  logical , pointer :: read_increment
362  logical , pointer :: hydrostatic
363  logical , pointer :: phys_hydrostatic
364  logical , pointer :: use_hydro_pressure
365  logical , pointer :: do_uni_zfull !miz
366  logical , pointer :: adj_mass_vmr ! f1p
367  logical , pointer :: hybrid_z
368  logical , pointer :: Make_NH
369  logical , pointer :: make_hybrid_z
370  logical , pointer :: nudge_qv
371  real, pointer :: add_noise
372  logical , pointer :: butterfly_effect
373 
374  integer , pointer :: a2b_ord
375  integer , pointer :: c2l_ord
376 
377  integer, pointer :: ndims
378 
379  real(kind=R_GRID), pointer :: dx_const
380  real(kind=R_GRID), pointer :: dy_const
381  real(kind=R_GRID), pointer :: deglon_start, deglon_stop, & ! boundaries of latlon patch
382  deglat_start, deglat_stop
383  real(kind=R_GRID), pointer :: deglat
384 
385  logical, pointer :: nested, twowaynest
386  logical, pointer :: regional
387  integer, pointer :: bc_update_interval
388  integer, pointer :: nrows_blend
389  logical, pointer :: regional_bcs_from_gsi
390  logical, pointer :: write_restart_with_bcs
391  integer, pointer :: parent_tile, refinement, nestbctype, nestupdate, nsponge, ioffset, joffset
392  real, pointer :: s_weight, update_blend
393 
394  integer, pointer :: layout(:), io_layout(:)
395 
396  !!!!!!!!!! END POINTERS !!!!!!!!!!!!!!!!!!!!!!!!!!!!
397 
398  this_grid = -1 ! default
399  call mp_assign_gid
400  ens_root_pe = mpp_root_pe()
401 
402  ! 1. read nesting namelists
405 
406  ! 2. Set up Atm and PElists
407 
408  ngrids = 1
409  do n=2,max_nnest
410  if (grid_coarse(n) <= 0) then
411  exit
412  endif
413  ngrids = ngrids + 1
414  enddo
415  allocate(atm(ngrids))
416  npes = mpp_npes() ! now on global pelist
417 
418  allocate(global_pelist(npes))
419  call mpp_get_current_pelist(global_pelist, commid=global_commid) ! for commID
420 
421 
422  allocate(grids_master_procs(ngrids))
423  pecounter = 0
424  allocate(grids_on_this_pe(ngrids))
425  grids_on_this_pe(:) = .false.
426 
427  do n=1,ngrids
428 
429  if (ngrids == 1 .or. grid_pes(n) == 0) then
430  grid_pes(n) = npes - sum(grid_pes)
431  if (grid_pes(n) == 0) then
432  if ( n > 1 ) then
433  call mpp_error(fatal, 'Only one zero entry in grid_pes permitted.')
434  else
435  grid_pes(n) = npes
436  endif
437  endif
438  endif
439 
440  allocate(atm(n)%pelist(grid_pes(n)))
441  grids_master_procs(n) = pecounter
442  do i=1,grid_pes(n)
443  if (pecounter >= npes) then
444  if (mpp_pe() == 0) then
445  print*, 'ngrids = ', ngrids, ', grid_pes = ', grid_pes(1:ngrids)
446  endif
447  call mpp_error(fatal, 'grid_pes assigns more PEs than are available.')
448  endif
449  atm(n)%pelist(i) = pecounter + ens_root_pe !TODO PELIST set up by mpp_define_nest_domains???
450  pecounter = pecounter + 1
451  atm(n)%npes_this_grid = grid_pes(n)
452  enddo
453  atm(n)%grid_number = n
454 
455  !TODO: we are required to use PE name for reading INTERNAL namelist
456  ! and the actual file name for EXTERNAL namelists. Need to clean up this code
457  if (n == 1) then
458  pe_list_name = ''
459  else
460  write(pe_list_name,'(A4, I2.2)') 'nest', n
461  endif
462  call mpp_declare_pelist(atm(n)%pelist, pe_list_name)
463  !If nest need to re-initialize internal NML
464  if (n > 1) then
465  atm(n)%nml_filename = 'input_'//trim(pe_list_name)//'.nml'
466  else
467  atm(n)%nml_filename = 'input.nml'
468  endif
469  if (.not. file_exist(atm(n)%nml_filename)) then
470  call mpp_error(fatal, "Could not find nested grid namelist "//atm(n)%nml_filename)
471  endif
472  enddo
473 
474  do n=1,ngrids
475  !ONE grid per pe
476  if (any(mpp_pe() == atm(n)%pelist)) then
477  if (this_grid > 0) then
478  print*, mpp_pe(), this_grid, n
479  call mpp_error(fatal, " Grid assigned to multiple pes")
480  endif
481  call mpp_set_current_pelist(atm(n)%pelist)
482  call setup_master(atm(n)%pelist)
483  this_grid = n
484  grids_on_this_pe(n) = .true.
485  endif
486  atm(n)%neststruct%nested = ( grid_coarse(n) > 0 )
487 
488  if (atm(n)%neststruct%nested) then
489  if ( grid_coarse(n) > ngrids .or. grid_coarse(n) == n .or. grid_coarse(n) < 1) then
490  write(errstring,'(2(A,I3))') "Could not find parent grid #", grid_coarse(n), ' for grid #', n
491  call mpp_error(fatal, errstring)
492  endif
493  atm(n)%parent_grid => atm(grid_coarse(n))
494 
495  atm(n)%neststruct%ioffset = nest_ioffsets(n)
496  atm(n)%neststruct%joffset = nest_joffsets(n)
497  atm(n)%neststruct%parent_tile = tile_coarse(n)
498  atm(n)%neststruct%refinement = nest_refine(n)
499 
500  else
501 
502  atm(n)%neststruct%ioffset = -999
503  atm(n)%neststruct%joffset = -999
504  atm(n)%neststruct%parent_tile = -1
505  atm(n)%neststruct%refinement = -1
506 
507  endif
508 
509  enddo
510 
511  if (pecounter /= npes) then
512  if (mpp_pe() == 0) then
513  print*, 'npes = ', npes, ', grid_pes = ', grid_pes(1:ngrids)
514  call mpp_error(fatal, 'grid_pes in fv_nest_Nml does not assign all of the available PEs')
515  endif
516  endif
517 
518  ! 3pre.
519  call timing_init
520  call timing_on('TOTAL')
521 
522  ! 3. Read namelists, do option processing and I/O
523 
524  call set_namelist_pointers(atm(this_grid))
525  call fv_diag_init_gn(atm(this_grid))
526 #ifdef INTERNAL_FILE_NML
527  if (this_grid .gt. 1) then
528  write(atm(this_grid)%nml_filename,'(A4, I2.2)') 'nest', this_grid
529  if (.not. file_exist('input_'//trim(atm(this_grid)%nml_filename)//'.nml')) then
530  call mpp_error(fatal, "Could not find nested grid namelist "//'input_'//trim(atm(this_grid)%nml_filename)//'.nml')
531  endif
532  else
533  atm(this_grid)%nml_filename = ''
534  endif
535  call read_input_nml(atm(this_grid)%nml_filename) !re-reads into internal namelist
536 #endif
538  call read_namelist_fv_core_nml(atm(this_grid)) ! do options processing here too?
539 #ifdef MULTI_GASES
540  call read_namelist_multi_gases_nml(atm(this_grid)%nml_filename, &
541  atm(this_grid)%flagstruct%ncnst, atm(this_grid)%flagstruct%nwat)
542 #endif
543  call read_namelist_test_case_nml(atm(this_grid)%nml_filename)
544  call mpp_get_current_pelist(atm(this_grid)%pelist, commid=commid) ! for commID
545  call mp_start(commid,halo_update_type)
546 
547  ! 4. Set up domains
548  ! This should make use of new fv_nest_nml namelists
549  !!!! TODO TEMPORARY location for this code
550  if (atm(this_grid)%neststruct%nested) then
551 
552  if ( atm(this_grid)%flagstruct%consv_te > 0.) then
553  call mpp_error(fatal, 'The global energy fixer cannot be used on a nested grid. consv_te must be set to 0.')
554  end if
555 
556  if (mod(atm(this_grid)%flagstruct%npx-1 , atm(this_grid)%neststruct%refinement) /= 0 .or. &
557  mod(atm(this_grid)%flagstruct%npy-1, atm(this_grid)%neststruct%refinement) /= 0) then
558  call mpp_error(fatal, 'npx or npy not an even refinement of its coarse grid.')
559  endif
560 
561  endif
562 
563  if (atm(this_grid)%flagstruct%regional) then
564  if ( atm(this_grid)%flagstruct%consv_te > 0.) then
565  call mpp_error(fatal, 'The global energy fixer cannot be used on a regional grid. consv_te must be set to 0.')
566  end if
567  endif
568 
569  !Now only one call to mpp_define_nest_domains for ALL nests
570  ! set up nest_level, tile_fine, tile_coarse
571  ! need number of tiles, npx, and npy on each grid
572  ! need to define a global PElist
573 
574  all_ntiles(this_grid) = ntiles
575  call mpp_max(all_ntiles, ngrids, global_pelist)
576 
577  all_npx(this_grid) = npx
578  call mpp_max(all_npx, ngrids, global_pelist)
579 
580  all_npy(this_grid) = npy
581  call mpp_max(all_npy, ngrids, global_pelist)
582 
583  all_npz(this_grid) = npz
584  call mpp_max(all_npz, ngrids, global_pelist)
585 
586  if (atm(this_grid)%neststruct%twowaynest) all_twowaynest(this_grid) = 1
587  call mpp_max(all_twowaynest, ngrids, global_pelist)
588  ntiles_nest_all = 0
589  do n=1,ngrids
590  if (n/=this_grid) then
591  atm(n)%flagstruct%npx = all_npx(n)
592  atm(n)%flagstruct%npy = all_npy(n)
593  atm(n)%flagstruct%npz = all_npz(n)
594  atm(n)%flagstruct%ntiles = all_ntiles(n)
595  atm(n)%neststruct%twowaynest = (all_twowaynest(n) > 0) ! disabled
596  endif
597  npes_nest_tile(ntiles_nest_all+1:ntiles_nest_all+all_ntiles(n)) = &
598  atm(n)%npes_this_grid / all_ntiles(n)
599  ntiles_nest_all = ntiles_nest_all + all_ntiles(n)
600 
601  if (n > 1) then
602  tile_fine(n) = all_ntiles(n) + tile_fine(n-1)
603  if (tile_coarse(n) < 1) then !set automatically; only works for single tile parents
604  tile_coarse(n) = tile_fine(grid_coarse(n))
605  endif
606  icount_coarse(n) = all_npx(n)/nest_refine(n)
607  jcount_coarse(n) = all_npy(n)/nest_refine(n)
608  nest_level(n) = nest_level(grid_coarse(n)) + 1
609  else
610  tile_fine(n) = all_ntiles(n)
611  nest_level(n) = 0
612  endif
613  enddo
614 
615  if (mpp_pe() == 0 .and. ngrids > 1) then
616  print*, ' NESTING TREE'
617  do n=1,ngrids
618  write(*,'(12i4)') n, nest_level(n), nest_ioffsets(n), nest_joffsets(n), icount_coarse(n), jcount_coarse(n), tile_fine(n), tile_coarse(n), nest_refine(n), all_ntiles(n), all_npx(n), all_npy(n)
619  write(*,*)
620  enddo
621  print*, npes_nest_tile(1:ntiles_nest_all)
622  print*, ''
623  endif
624 
625  ! 5. domain_decomp()
626  call domain_decomp(atm(this_grid)%flagstruct%npx,atm(this_grid)%flagstruct%npy,atm(this_grid)%flagstruct%ntiles,&
627  atm(this_grid)%flagstruct%grid_type,atm(this_grid)%neststruct%nested, &
628  atm(this_grid)%layout,atm(this_grid)%io_layout,atm(this_grid)%bd,atm(this_grid)%tile_of_mosaic, &
629  atm(this_grid)%gridstruct%square_domain,atm(this_grid)%npes_per_tile,atm(this_grid)%domain, &
630  atm(this_grid)%domain_for_coupler,atm(this_grid)%num_contact,atm(this_grid)%pelist)
631  call set_domain(atm(this_grid)%domain)
632  call broadcast_domains(atm,atm(this_grid)%pelist,size(atm(this_grid)%pelist))
633  do n=1,ngrids
634  tile_id = mpp_get_tile_id(atm(n)%domain)
635  atm(n)%global_tile = tile_id(1) ! only meaningful locally
636  atm(n)%npes_per_tile = size(atm(n)%pelist)/atm(n)%flagstruct%ntiles ! domain decomp doesn't set this globally
637  enddo
638 
639  ! 6. Set up domain and Atm structure
640  call tm_register_tracers (model_atmos, atm(this_grid)%flagstruct%ncnst, atm(this_grid)%flagstruct%nt_prog, &
641  atm(this_grid)%flagstruct%pnats, num_family)
642  if(is_master()) then
643  write(*,*) 'ncnst=', ncnst,' num_prog=',atm(this_grid)%flagstruct%nt_prog,' pnats=',atm(this_grid)%flagstruct%pnats,' dnats=',dnats,&
644  ' num_family=',num_family
645  print*, ''
646  endif
647  if (dnrts < 0) dnrts = dnats
648 
649  do n=1,ngrids
650  !FIXME still setting up dummy structures for other grids for convenience reasons
651  !isc, etc. set in domain_decomp
652  call allocate_fv_atmos_type(atm(n), &
653  atm(n)%bd%isd, atm(n)%bd%ied, &
654  atm(n)%bd%jsd, atm(n)%bd%jed, &
655  atm(n)%bd%isc, atm(n)%bd%iec, &
656  atm(n)%bd%jsc, atm(n)%bd%jec, &
657  atm(n)%flagstruct%npx, atm(n)%flagstruct%npy, atm(n)%flagstruct%npz, &
658  atm(n)%flagstruct%ndims, atm(n)%flagstruct%ncnst, atm(n)%flagstruct%ncnst-atm(n)%flagstruct%pnats, &
659  n/=this_grid, n==this_grid, ngrids) !TODO don't need both of the last arguments
660  enddo
661  if ( (atm(this_grid)%bd%iec-atm(this_grid)%bd%isc+1).lt.4 .or. (atm(this_grid)%bd%jec-atm(this_grid)%bd%jsc+1).lt.4 ) then
662  if (is_master()) write(*,'(6I6)') atm(this_grid)%bd%isc, atm(this_grid)%bd%iec, atm(this_grid)%bd%jsc, atm(this_grid)%bd%jec, this_grid
663  call mpp_error(fatal,'Domain Decomposition: Cubed Sphere compute domain has a &
664  &minium requirement of 4 points in X and Y, respectively')
665  end if
666 
667 
668  !Tile_coarse is needed to determine which processors are needed to send around their
669  ! data for computing the interpolation coefficients
670  if (ngrids > 1) then
671  !reset to universal pelist
672  call mpp_set_current_pelist( global_pelist )
673  !Except for npes_nest_tile all arrays should be just the nests and should NOT include the top level
674  call mpp_define_nest_domains(global_nest_domain, atm(this_grid)%domain, &
675  ngrids-1, nest_level=nest_level(2:ngrids) , &
676  istart_coarse=nest_ioffsets(2:ngrids), jstart_coarse=nest_joffsets(2:ngrids), &
677  icount_coarse=icount_coarse(2:ngrids), jcount_coarse=jcount_coarse(2:ngrids), &
678  npes_nest_tile=npes_nest_tile(1:ntiles_nest_all), &
679  tile_fine=tile_fine(2:ngrids), tile_coarse=tile_coarse(2:ngrids), &
680  x_refine=nest_refine(2:ngrids), y_refine=nest_refine(2:ngrids), name="global_nest_domain")
681  call mpp_set_current_pelist(atm(this_grid)%pelist)
682 
683  endif
684 
685  allocate(atm(this_grid)%neststruct%child_grids(ngrids))
686  do n=1,ngrids
687  atm(this_grid)%neststruct%child_grids(n) = (grid_coarse(n) == this_grid)
688  allocate(atm(n)%neststruct%do_remap_bc(ngrids))
689  atm(n)%neststruct%do_remap_bc(:) = .false.
690  enddo
691  atm(this_grid)%neststruct%parent_proc = any(atm(this_grid)%neststruct%child_grids) !ANY(tile_coarse == Atm(this_grid)%global_tile)
692  atm(this_grid)%neststruct%child_proc = ASSOCIATED(atm(this_grid)%parent_grid) !this means a nested grid
693 
694  if (ngrids > 1) call setup_update_regions
695  if (atm(this_grid)%neststruct%nestbctype > 1) then
696  call mpp_error(fatal, 'nestbctype > 1 not yet implemented')
697  atm(this_grid)%neststruct%upoff = 0
698  endif
699 
700  if (atm(this_grid)%gridstruct%bounded_domain .and. is_master()) print*, &
701  ' Bounded domain: nested = ', atm(this_grid)%neststruct%nested, ', regional = ', atm(this_grid)%flagstruct%regional
702 
703  ! 7. Init_grid() (including two-way nesting)
704  call init_grid(atm(this_grid), atm(this_grid)%flagstruct%grid_name, atm(this_grid)%flagstruct%grid_file, &
705  atm(this_grid)%flagstruct%npx, atm(this_grid)%flagstruct%npy, atm(this_grid)%flagstruct%npz, atm(this_grid)%flagstruct%ndims, atm(this_grid)%flagstruct%ntiles, atm(this_grid)%ng, tile_coarse)
706 
707 
708  ! 8. grid_utils_init()
709  ! Initialize the SW (2D) part of the model
710  call grid_utils_init(atm(this_grid), atm(this_grid)%flagstruct%npx, atm(this_grid)%flagstruct%npy, atm(this_grid)%flagstruct%npz, atm(this_grid)%flagstruct%non_ortho, atm(this_grid)%flagstruct%grid_type, atm(this_grid)%flagstruct%c2l_ord)
711 
712  ! Finish up initialization; write damping coefficients dependent upon
713 
714  if ( is_master() ) then
715  sdt = dt_atmos/real(atm(this_grid)%flagstruct%n_split*atm(this_grid)%flagstruct%k_split*abs(p_split))
716  write(*,*) ' '
717  write(*,*) 'Divergence damping Coefficients'
718  write(*,*) 'For small dt=', sdt
719  write(*,*) 'External mode del-2 (m**2/s)=', atm(this_grid)%flagstruct%d_ext*atm(this_grid)%gridstruct%da_min_c/sdt
720  write(*,*) 'Internal mode del-2 SMAG dimensionless coeff=', atm(this_grid)%flagstruct%dddmp
721  write(*,*) 'Internal mode del-2 background diff=', atm(this_grid)%flagstruct%d2_bg*atm(this_grid)%gridstruct%da_min_c/sdt
722 
723  if (nord==1) then
724  write(*,*) 'Internal mode del-4 background diff=', atm(this_grid)%flagstruct%d4_bg
725  write(*,*) 'Vorticity del-4 (m**4/s)=', (atm(this_grid)%flagstruct%vtdm4*atm(this_grid)%gridstruct%da_min)**2/sdt*1.e-6
726  endif
727  if (atm(this_grid)%flagstruct%nord==2) write(*,*) 'Internal mode del-6 background diff=', atm(this_grid)%flagstruct%d4_bg
728  if (atm(this_grid)%flagstruct%nord==3) write(*,*) 'Internal mode del-8 background diff=', atm(this_grid)%flagstruct%d4_bg
729  write(*,*) 'tracer del-2 diff=', atm(this_grid)%flagstruct%trdm2
730 
731  write(*,*) 'Vorticity del-4 (m**4/s)=', (atm(this_grid)%flagstruct%vtdm4*atm(this_grid)%gridstruct%da_min)**2/sdt*1.e-6
732  write(*,*) 'beta=', atm(this_grid)%flagstruct%beta
733  write(*,*) ' '
734  endif
735 
736 
737 !!$ Atm(this_grid)%ts = 300.
738 !!$ Atm(this_grid)%phis = too_big
739 !!$ ! The following statements are to prevent the phantom corner regions from
740 !!$ ! growing instability
741 !!$ Atm(this_grid)%u = 0.
742 !!$ Atm(this_grid)%v = 0.
743 !!$ Atm(this_grid)%ua = too_big
744 !!$ Atm(this_grid)%va = too_big
745 !!$
746 
747  !Initialize restart
748  call fv_restart_init()
749 ! if ( reset_eta ) then
750 ! do n=1, ntilesMe
751 ! call set_eta(npz, Atm(this_grid)%ks, ptop, Atm(this_grid)%ak, Atm(this_grid)%bk, Atm(this_grid)%flagstruct%npz_type)
752 ! enddo
753 ! if(is_master()) write(*,*) "Hybrid sigma-p coordinate has been reset"
754 ! endif
755 
756 
757  contains
761  subroutine set_namelist_pointers(Atm)
762  type(fv_atmos_type), intent(INOUT), target :: Atm
763 
764  !This routine associates the MODULE flag pointers with the ARRAY flag variables for the grid active on THIS pe so the flags can be read in from the namelist.
765 
766  grid_type => atm%flagstruct%grid_type
767  grid_name => atm%flagstruct%grid_name
768  grid_file => atm%flagstruct%grid_file
769  hord_mt => atm%flagstruct%hord_mt
770  kord_mt => atm%flagstruct%kord_mt
771  kord_wz => atm%flagstruct%kord_wz
772  hord_vt => atm%flagstruct%hord_vt
773  hord_tm => atm%flagstruct%hord_tm
774  hord_dp => atm%flagstruct%hord_dp
775  kord_tm => atm%flagstruct%kord_tm
776  hord_tr => atm%flagstruct%hord_tr
777  kord_tr => atm%flagstruct%kord_tr
778  scale_z => atm%flagstruct%scale_z
779  w_max => atm%flagstruct%w_max
780  z_min => atm%flagstruct%z_min
781  lim_fac => atm%flagstruct%lim_fac
782  nord => atm%flagstruct%nord
783  nord_tr => atm%flagstruct%nord_tr
784  dddmp => atm%flagstruct%dddmp
785  d2_bg => atm%flagstruct%d2_bg
786  d4_bg => atm%flagstruct%d4_bg
787  vtdm4 => atm%flagstruct%vtdm4
788  trdm2 => atm%flagstruct%trdm2
789  d2_bg_k1 => atm%flagstruct%d2_bg_k1
790  d2_bg_k2 => atm%flagstruct%d2_bg_k2
791  d2_divg_max_k1 => atm%flagstruct%d2_divg_max_k1
792  d2_divg_max_k2 => atm%flagstruct%d2_divg_max_k2
793  damp_k_k1 => atm%flagstruct%damp_k_k1
794  damp_k_k2 => atm%flagstruct%damp_k_k2
795  n_zs_filter => atm%flagstruct%n_zs_filter
796  nord_zs_filter => atm%flagstruct%nord_zs_filter
797  full_zs_filter => atm%flagstruct%full_zs_filter
798  rf_fast => atm%flagstruct%RF_fast
799  consv_am => atm%flagstruct%consv_am
800  do_sat_adj => atm%flagstruct%do_sat_adj
801  do_f3d => atm%flagstruct%do_f3d
802  no_dycore => atm%flagstruct%no_dycore
803  convert_ke => atm%flagstruct%convert_ke
804  do_vort_damp => atm%flagstruct%do_vort_damp
805  use_old_omega => atm%flagstruct%use_old_omega
806  beta => atm%flagstruct%beta
807  n_sponge => atm%flagstruct%n_sponge
808  d_ext => atm%flagstruct%d_ext
809  nwat => atm%flagstruct%nwat
810  use_logp => atm%flagstruct%use_logp
811  warm_start => atm%flagstruct%warm_start
812  inline_q => atm%flagstruct%inline_q
813  shift_fac => atm%flagstruct%shift_fac
814  do_schmidt => atm%flagstruct%do_schmidt
815  do_cube_transform => atm%flagstruct%do_cube_transform
816  stretch_fac => atm%flagstruct%stretch_fac
817  target_lat => atm%flagstruct%target_lat
818  target_lon => atm%flagstruct%target_lon
819  regional => atm%flagstruct%regional
820  bc_update_interval => atm%flagstruct%bc_update_interval
821  nrows_blend => atm%flagstruct%nrows_blend
822  regional_bcs_from_gsi => atm%flagstruct%regional_bcs_from_gsi
823  write_restart_with_bcs => atm%flagstruct%write_restart_with_bcs
824  reset_eta => atm%flagstruct%reset_eta
825  p_fac => atm%flagstruct%p_fac
826  a_imp => atm%flagstruct%a_imp
827  n_split => atm%flagstruct%n_split
828  fac_n_spl => atm%flagstruct%fac_n_spl
829  fhouri => atm%flagstruct%fhouri
830  m_split => atm%flagstruct%m_split
831  k_split => atm%flagstruct%k_split
832  use_logp => atm%flagstruct%use_logp
833  q_split => atm%flagstruct%q_split
834  print_freq => atm%flagstruct%print_freq
835  write_3d_diags => atm%flagstruct%write_3d_diags
836  npx => atm%flagstruct%npx
837  npy => atm%flagstruct%npy
838  npz => atm%flagstruct%npz
839  npz_type => atm%flagstruct%npz_type
840  npz_rst => atm%flagstruct%npz_rst
841  ncnst => atm%flagstruct%ncnst
842  pnats => atm%flagstruct%pnats
843  dnats => atm%flagstruct%dnats
844  dnrts => atm%flagstruct%dnrts
845  ntiles => atm%flagstruct%ntiles
846  nf_omega => atm%flagstruct%nf_omega
847  fv_sg_adj => atm%flagstruct%fv_sg_adj
848  sg_cutoff => atm%flagstruct%sg_cutoff
849  na_init => atm%flagstruct%na_init
850  nudge_dz => atm%flagstruct%nudge_dz
851  p_ref => atm%flagstruct%p_ref
852  dry_mass => atm%flagstruct%dry_mass
853  nt_prog => atm%flagstruct%nt_prog
854  nt_phys => atm%flagstruct%nt_phys
855  tau_h2o => atm%flagstruct%tau_h2o
856  delt_max => atm%flagstruct%delt_max
857  d_con => atm%flagstruct%d_con
858  ke_bg => atm%flagstruct%ke_bg
859  consv_te => atm%flagstruct%consv_te
860  tau => atm%flagstruct%tau
861  rf_cutoff => atm%flagstruct%rf_cutoff
862  filter_phys => atm%flagstruct%filter_phys
863  dwind_2d => atm%flagstruct%dwind_2d
864  breed_vortex_inline => atm%flagstruct%breed_vortex_inline
865  range_warn => atm%flagstruct%range_warn
866  fill => atm%flagstruct%fill
867  fill_dp => atm%flagstruct%fill_dp
868  fill_wz => atm%flagstruct%fill_wz
869  fill_gfs => atm%flagstruct%fill_gfs
870  check_negative => atm%flagstruct%check_negative
871  non_ortho => atm%flagstruct%non_ortho
872  adiabatic => atm%flagstruct%adiabatic
873  moist_phys => atm%flagstruct%moist_phys
874  do_held_suarez => atm%flagstruct%do_Held_Suarez
875  do_reed_physics => atm%flagstruct%do_reed_physics
876  reed_cond_only => atm%flagstruct%reed_cond_only
877  reproduce_sum => atm%flagstruct%reproduce_sum
878  adjust_dry_mass => atm%flagstruct%adjust_dry_mass
879  fv_debug => atm%flagstruct%fv_debug
880  srf_init => atm%flagstruct%srf_init
881  mountain => atm%flagstruct%mountain
882  remap_t => atm%flagstruct%remap_t
883  z_tracer => atm%flagstruct%z_tracer
884  old_divg_damp => atm%flagstruct%old_divg_damp
885  fv_land => atm%flagstruct%fv_land
886  nudge => atm%flagstruct%nudge
887  nudge_ic => atm%flagstruct%nudge_ic
888  ncep_ic => atm%flagstruct%ncep_ic
889  nggps_ic => atm%flagstruct%nggps_ic
890  ecmwf_ic => atm%flagstruct%ecmwf_ic
891  gfs_phil => atm%flagstruct%gfs_phil
892  agrid_vel_rst => atm%flagstruct%agrid_vel_rst
893  use_new_ncep => atm%flagstruct%use_new_ncep
894  use_ncep_phy => atm%flagstruct%use_ncep_phy
895  fv_diag_ic => atm%flagstruct%fv_diag_ic
896  external_ic => atm%flagstruct%external_ic
897  external_eta => atm%flagstruct%external_eta
898  read_increment => atm%flagstruct%read_increment
899 
900  hydrostatic => atm%flagstruct%hydrostatic
901  phys_hydrostatic => atm%flagstruct%phys_hydrostatic
902  use_hydro_pressure => atm%flagstruct%use_hydro_pressure
903  do_uni_zfull => atm%flagstruct%do_uni_zfull !miz
904  adj_mass_vmr => atm%flagstruct%adj_mass_vmr !f1p
905  hybrid_z => atm%flagstruct%hybrid_z
906  make_nh => atm%flagstruct%Make_NH
907  make_hybrid_z => atm%flagstruct%make_hybrid_z
908  nudge_qv => atm%flagstruct%nudge_qv
909  add_noise => atm%flagstruct%add_noise
910  butterfly_effect => atm%flagstruct%butterfly_effect
911  a2b_ord => atm%flagstruct%a2b_ord
912  c2l_ord => atm%flagstruct%c2l_ord
913  ndims => atm%flagstruct%ndims
914 
915  dx_const => atm%flagstruct%dx_const
916  dy_const => atm%flagstruct%dy_const
917  deglon_start => atm%flagstruct%deglon_start
918  deglon_stop => atm%flagstruct%deglon_stop
919  deglat_start => atm%flagstruct%deglat_start
920  deglat_stop => atm%flagstruct%deglat_stop
921 
922  deglat => atm%flagstruct%deglat
923 
924  nested => atm%neststruct%nested
925  twowaynest => atm%neststruct%twowaynest
926  parent_tile => atm%neststruct%parent_tile
927  refinement => atm%neststruct%refinement
928  nestbctype => atm%neststruct%nestbctype
929  nestupdate => atm%neststruct%nestupdate
930  nsponge => atm%neststruct%nsponge
931  s_weight => atm%neststruct%s_weight
932  ioffset => atm%neststruct%ioffset
933  joffset => atm%neststruct%joffset
934  update_blend => atm%neststruct%update_blend
935 
936  layout => atm%layout
937  io_layout => atm%io_layout
938  end subroutine set_namelist_pointers
939 
940 
941  subroutine read_namelist_nest_nml
943  integer :: f_unit, ios, ierr, dum
944  namelist /nest_nml/ dum ! ngrids, ntiles, nest_pes, p_split !emptied lmh 7may2019
945 
946 #ifdef INTERNAL_FILE_NML
947  read (input_nml_file,nest_nml,iostat=ios)
948  ierr = check_nml_error(ios,'nest_nml')
949 #else
950  f_unit=open_namelist_file()
951  rewind(f_unit)
952  read (f_unit,nest_nml,iostat=ios)
953  ierr = check_nml_error(ios,'nest_nml')
954  call close_file(f_unit)
955 #endif
956  if (ierr > 0) then
957  call mpp_error(fatal, " &nest_nml is depreciated. Please use &fv_nest_nml instead.")
958  endif
959 
960  end subroutine read_namelist_nest_nml
961 
962  subroutine read_namelist_fv_nest_nml
964  integer :: f_unit, ios, ierr
965  namelist /fv_nest_nml/ grid_pes, grid_coarse, tile_coarse, nest_refine, &
966  nest_ioffsets, nest_joffsets, p_split
967 
968 #ifdef INTERNAL_FILE_NML
969  read (input_nml_file,fv_nest_nml,iostat=ios)
970  ierr = check_nml_error(ios,'fv_nest_nml')
971 #else
972  f_unit=open_namelist_file()
973  rewind(f_unit)
974  read (f_unit,fv_nest_nml,iostat=ios)
975  ierr = check_nml_error(ios,'fv_nest_nml')
976  call close_file(f_unit)
977 #endif
978 
979  end subroutine read_namelist_fv_nest_nml
980 
981  subroutine read_namelist_fv_grid_nml
983  integer :: f_unit, ios, ierr
984  ! local version of these variables to allow PGI compiler to compile
985  character(len=80) :: grid_name = ''
986  character(len=120) :: grid_file = ''
987  namelist /fv_grid_nml/ grid_name, grid_file
988 
989 #ifdef INTERNAL_FILE_NML
990  ! Read Main namelist
991  read (input_nml_file,fv_grid_nml,iostat=ios)
992  ierr = check_nml_error(ios,'fv_grid_nml')
993 #else
994  f_unit=open_namelist_file()
995  rewind(f_unit)
996  ! Read Main namelist
997  read (f_unit,fv_grid_nml,iostat=ios)
998  ierr = check_nml_error(ios,'fv_grid_nml')
999  call close_file (f_unit)
1000 #endif
1001  call write_version_number ( 'FV_CONTROL_MOD', version )
1002  unit = stdlog()
1003  write(unit, nml=fv_grid_nml)
1004 
1005  !Basic option processing
1006  if (len_trim(grid_file) /= 0) atm(this_grid)%flagstruct%grid_file = grid_file
1007  if (len_trim(grid_name) /= 0) atm(this_grid)%flagstruct%grid_name = grid_name
1008 
1009 
1010  end subroutine read_namelist_fv_grid_nml
1011 
1012  subroutine read_namelist_fv_core_nml(Atm)
1013 
1014  type(fv_atmos_type), intent(inout) :: Atm
1015  integer :: f_unit, ios, ierr
1016  real :: dim0 = 180. ! base dimension
1017  real :: dt0 = 1800. ! base time step
1018  real :: ns0 = 5. ! base nsplit for base dimension
1019  real :: dimx, dl, dp, dxmin, dymin, d_fac
1020  real :: umax = 350. ! max wave speed for grid_type>3
1021 
1022  integer :: n0split
1023 
1024  ! local version of these variables to allow PGI compiler to compile
1025  character(len=128) :: res_latlon_dynamics = ''
1026  character(len=128) :: res_latlon_tracers = ''
1027 
1045 
1147 
1423  namelist /fv_core_nml/npx, npy, ntiles, npz, npz_type, npz_rst, layout, io_layout, ncnst, nwat, &
1424  use_logp, p_fac, a_imp, k_split, n_split, m_split, q_split, print_freq, write_3d_diags, &
1425  do_schmidt, do_cube_transform, &
1426  hord_mt, hord_vt, hord_tm, hord_dp, hord_tr, shift_fac, stretch_fac, target_lat, target_lon, &
1427  kord_mt, kord_wz, kord_tm, kord_tr, fv_debug, fv_land, nudge, do_sat_adj, do_f3d, &
1428  external_ic, read_increment, ncep_ic, nggps_ic, ecmwf_ic, use_new_ncep, use_ncep_phy, fv_diag_ic, &
1429  external_eta, res_latlon_dynamics, res_latlon_tracers, scale_z, w_max, z_min, lim_fac, &
1430  dddmp, d2_bg, d4_bg, vtdm4, trdm2, d_ext, delt_max, beta, non_ortho, n_sponge, &
1431  warm_start, adjust_dry_mass, mountain, d_con, ke_bg, nord, nord_tr, convert_ke, use_old_omega, &
1432  dry_mass, grid_type, do_held_suarez, do_reed_physics, reed_cond_only, &
1433  consv_te, fill, filter_phys, fill_dp, fill_wz, fill_gfs, consv_am, rf_fast, &
1434  range_warn, dwind_2d, inline_q, z_tracer, reproduce_sum, adiabatic, do_vort_damp, no_dycore, &
1435  tau, tau_h2o, rf_cutoff, nf_omega, hydrostatic, fv_sg_adj, sg_cutoff, breed_vortex_inline, &
1436  na_init, nudge_dz, hybrid_z, make_nh, n_zs_filter, nord_zs_filter, full_zs_filter, reset_eta, &
1437  pnats, dnats, dnrts, a2b_ord, remap_t, p_ref, d2_bg_k1, d2_bg_k2, &
1438  c2l_ord, dx_const, dy_const, umax, deglat, &
1439  deglon_start, deglon_stop, deglat_start, deglat_stop, &
1440  phys_hydrostatic, use_hydro_pressure, make_hybrid_z, old_divg_damp, add_noise, butterfly_effect, &
1441  nested, twowaynest, nudge_qv, &
1442  nestbctype, nestupdate, nsponge, s_weight, &
1443  check_negative, nudge_ic, halo_update_type, gfs_phil, agrid_vel_rst, &
1444  do_uni_zfull, adj_mass_vmr, fac_n_spl, fhouri, update_blend, regional, bc_update_interval, &
1445  regional_bcs_from_gsi, write_restart_with_bcs, nrows_blend
1446 
1447 #ifdef INTERNAL_FILE_NML
1448  ! Read FVCORE namelist
1449  read (input_nml_file,fv_core_nml,iostat=ios)
1450  ierr = check_nml_error(ios,'fv_core_nml')
1451  ! Reset input_file_nml to default behavior (CHECK do we still need this???)
1452  !call read_input_nml
1453 #else
1454  f_unit = open_namelist_file(atm%nml_filename)
1455  ! Read FVCORE namelist
1456  read (f_unit,fv_core_nml,iostat=ios)
1457  ierr = check_nml_error(ios,'fv_core_nml')
1458  call close_file(f_unit)
1459 #endif
1460  call write_version_number ( 'FV_CONTROL_MOD', version )
1461  unit = stdlog()
1462  write(unit, nml=fv_core_nml)
1463 
1464  if (len_trim(res_latlon_dynamics) /= 0) atm%flagstruct%res_latlon_dynamics = res_latlon_dynamics
1465  if (len_trim(res_latlon_tracers) /= 0) atm%flagstruct%res_latlon_tracers = res_latlon_tracers
1466 
1467  !*** single tile for Cartesian grids
1468  if (grid_type>3) then
1469  ntiles=1
1470  non_ortho = .false.
1471  nf_omega = 0
1472  endif
1473 
1474  if (.not. (nested .or. regional)) atm%neststruct%npx_global = npx
1475 
1476  ! Define n_split if not in namelist
1477  if (ntiles==6) then
1478  dimx = 4.0*(npx-1)
1479  if ( hydrostatic ) then
1480  if ( npx >= 120 ) ns0 = 6
1481  else
1482  if ( npx <= 45 ) then
1483  ns0 = 6
1484  elseif ( npx <=90 ) then
1485  ns0 = 7
1486  else
1487  ns0 = 8
1488  endif
1489  endif
1490  else
1491  dimx = max( npx, 2*(npy-1) )
1492  endif
1493 
1494  if (grid_type < 4) then
1495  n0split = nint( ns0*abs(dt_atmos)*dimx/(dt0*dim0) + 0.49 )
1496  elseif (grid_type == 4 .or. grid_type == 7) then
1497  n0split = nint( 2.*umax*dt_atmos/sqrt(dx_const**2 + dy_const**2) + 0.49 )
1498  elseif (grid_type == 5 .or. grid_type == 6) then
1499  if (grid_type == 6) then
1500  deglon_start = 0.; deglon_stop = 360.
1501  endif
1502  dl = (deglon_stop-deglon_start)*pi/(180.*(npx-1))
1503  dp = (deglat_stop-deglat_start)*pi/(180.*(npy-1))
1504 
1505  dxmin=dl*radius*min(cos(deglat_start*pi/180.-atm%bd%ng*dp), &
1506  cos(deglat_stop *pi/180.+atm%bd%ng*dp))
1507  dymin=dp*radius
1508  n0split = nint( 2.*umax*dt_atmos/sqrt(dxmin**2 + dymin**2) + 0.49 )
1509  endif
1510  n0split = max( 1, n0split )
1511 
1512  if ( n_split == 0 ) then
1513  n_split = nint( real(n0split)/real(k_split*abs(p_split)) * stretch_fac + 0.5 )
1514  if(is_master()) write(*,*) 'For k_split (remapping)=', k_split
1515  if(is_master()) write(*,198) 'n_split is set to ', n_split, ' for resolution-dt=',npx,npy,ntiles,dt_atmos
1516  else
1517  if(is_master()) write(*,199) 'Using n_split from the namelist: ', n_split
1518  endif
1519  if (is_master() .and. n == 1 .and. abs(p_split) > 1) then
1520  write(*,199) 'Using p_split = ', p_split
1521  endif
1522 
1523  if (old_divg_damp) then
1524  if (is_master()) write(*,*) " fv_control: using AM2/AM3 damping methods "
1525  d2_bg_k1 = 6. ! factor for d2_bg (k=1) - default(4.)
1526  d2_bg_k2 = 4. ! factor for d2_bg (k=2) - default(2.)
1527  d2_divg_max_k1 = 0.02 ! d2_divg max value (k=1) - default(0.05)
1528  d2_divg_max_k2 = 0.01 ! d2_divg max value (k=2) - default(0.02)
1529  damp_k_k1 = 0. ! damp_k value (k=1) - default(0.05)
1530  damp_k_k2 = 0. ! damp_k value (k=2) - default(0.025)
1531  elseif (n_sponge == 0 ) then
1532  if ( d2_bg_k1 > 1. ) d2_bg_k1 = 0.20
1533  if ( d2_bg_k2 > 1. ) d2_bg_k2 = 0.015
1534  endif
1535 
1536  if ( .not.hydrostatic ) then
1537  if ( m_split==0 ) then
1538  m_split = 1. + abs(dt_atmos)/real(k_split*n_split*abs(p_split))
1539  if (abs(a_imp) < 0.5) then
1540  if(is_master()) write(*,199) 'm_split is set to ', m_split
1541  endif
1542  endif
1543  if(is_master()) then
1544  write(*,*) 'Off center implicit scheme param=', a_imp
1545  write(*,*) ' p_fac=', p_fac
1546  endif
1547  endif
1548 
1549  if(is_master()) then
1550  if (n_sponge >= 0) write(*,199) 'Using n_sponge : ', n_sponge
1551  write(*,197) 'Using non_ortho : ', non_ortho
1552  endif
1553 
1554 197 format(a,l7)
1555 198 format(a,i2.2,a,i4.4,'x',i4.4,'x',i1.1,'-',f9.3)
1556 199 format(a,i3.3)
1557 
1558  !if (.not. (nested .or. regional)) alpha = alpha*pi !TODO for test_case_nml
1559 
1560  !allocate(Atm%neststruct%child_grids(size(Atm))) !TODO want to remove
1561  !Atm(N)%neststruct%child_grids = .false.
1562 
1563  target_lon = target_lon * pi/180.
1564  target_lat = target_lat * pi/180.
1565 
1566  end subroutine read_namelist_fv_core_nml
1567 
1568  subroutine setup_update_regions
1570  integer :: isu, ieu, jsu, jeu ! update regions
1571  integer :: isc, jsc, iec, jec
1572  integer :: upoff
1573 
1574  isc = atm(this_grid)%bd%isc
1575  jsc = atm(this_grid)%bd%jsc
1576  iec = atm(this_grid)%bd%iec
1577  jec = atm(this_grid)%bd%jec
1578 
1579  upoff = atm(this_grid)%neststruct%upoff
1580 
1581  do n=2,ngrids
1582  if (tile_coarse(n) == atm(this_grid)%global_tile) then
1583 
1584  isu = nest_ioffsets(n)
1585  ieu = isu + icount_coarse(n) - 1
1586  jsu = nest_joffsets(n)
1587  jeu = jsu + jcount_coarse(n) - 1
1588 
1589  !update offset adjustment
1590  isu = isu + upoff
1591  ieu = ieu - upoff
1592  jsu = jsu + upoff
1593  jeu = jeu - upoff
1594 
1595  !restriction to current domain
1596 !!$ !!! DEBUG CODE
1597 !!$ if (Atm(this_grid)%flagstruct%fv_debug) then
1598 !!$ write(*,'(I, A, 4I)') mpp_pe(), 'SETUP_UPDATE_REGIONS : ', isu, jsu, ieu, jeu
1599 !!$ write(*,'(I, A, 4I)') mpp_pe(), 'SETUP_UPDATE_REGIONS 2: ', isc, jsc, iec, jsc
1600 !!$ endif
1601 !!$ !!! END DEBUG CODE
1602  if (isu > iec .or. ieu < isc .or. &
1603  jsu > jec .or. jeu < jsc ) then
1604  isu = -999 ; jsu = -999 ; ieu = -1000 ; jeu = -1000
1605  else
1606  isu = max(isu,isc) ; jsu = max(jsu,jsc)
1607  ieu = min(ieu,iec) ; jeu = min(jeu,jec)
1608  endif
1609 !!$ !!! DEBUG CODE
1610 !!$ if (Atm(this_grid)%flagstruct%fv_debug) &
1611 !!$ write(*,'(I, A, 4I)') mpp_pe(), 'SETUP_UPDATE_REGIONS 3: ', isu, jsu, ieu, jeu
1612 !!$ !!! END DEBUG CODE
1613 
1614  atm(n)%neststruct%isu = isu
1615  atm(n)%neststruct%ieu = ieu
1616  atm(n)%neststruct%jsu = jsu
1617  atm(n)%neststruct%jeu = jeu
1618  endif
1619  enddo
1620 
1621  end subroutine setup_update_regions
1622 
1623  end subroutine fv_control_init
1624 
1625 !-------------------------------------------------------------------------------
1626 
1629  subroutine fv_end(Atm, this_grid, restart_endfcst)
1631  type(fv_atmos_type), intent(inout) :: Atm(:)
1632  integer, intent(IN) :: this_grid
1633  logical, intent(in) :: restart_endfcst
1634 
1635  integer :: n
1636 
1637  call timing_off('TOTAL')
1638  call timing_prt( mpp_pe() )
1639 
1640  call fv_restart_end(atm(this_grid), restart_endfcst)
1641  call fv_io_exit()
1642 
1643  ! Free temporary memory from sw_core routines
1644  ! Deallocate
1645  call grid_utils_end
1646 
1647  do n = 1, ngrids
1648  call deallocate_fv_atmos_type(atm(n))
1649  end do
1650 
1651 
1652  end subroutine fv_end
1653 !-------------------------------------------------------------------------------
1654 
1655 end module fv_control_mod
subroutine allocate_fv_atmos_type(Atm, isd_in, ied_in, jsd_in, jed_in, is_in, ie_in, js_in, je_in, npx_in, npy_in, npz_in, ndims_in, ncnst_in, nq_in, dummy, alloc_2d, ngrids_in)
The subroutine &#39;allocate_fv_atmos_type&#39; allocates the fv_atmos_type.
Definition: fv_arrays.F90:1382
subroutine setup_update_regions
The module &#39;fv_mp_mod&#39; is a single program multiple data (SPMD) parallel decompostion/communication m...
Definition: fv_mp_mod.F90:24
subroutine timing_off(blk_name)
The subroutine &#39;timing_off&#39; stops a timer.
Definition: fv_timing.F90:180
The module &#39;multi_gases&#39; peforms multi constitutents computations.
Definition: multi_gases.F90:25
subroutine read_namelist_fv_grid_nml
Definition: fv_control.F90:982
integer, public ngrids
Definition: fv_control.F90:173
subroutine read_namelist_fv_nest_nml
Definition: fv_control.F90:963
subroutine set_namelist_pointers(Atm)
The subroutine &#39;setup_namelist_pointers&#39; associates the MODULE flag pointers with the ARRAY flag vari...
Definition: fv_control.F90:762
subroutine, public read_namelist_multi_gases_nml(nml_filename, ncnst, nwat)
The module &#39;fv_io&#39; contains restart facilities for FV core.
Definition: fv_io.F90:30
integer, parameter, public r_grid
Definition: fv_arrays.F90:34
subroutine, public fv_diag_init_gn(Atm)
The module &#39;fv_timing&#39; contains FV3 timers.
Definition: fv_timing.F90:24
subroutine, public fv_restart_init()
Definition: fv_restart.F90:186
real, parameter, public ptop_min
The module &#39;fv_arrays&#39; contains the &#39;fv_atmos_type&#39; and associated datatypes.
Definition: fv_arrays.F90:24
subroutine read_namelist_nest_nml
Definition: fv_control.F90:942
subroutine, public set_eta(km, ks, ptop, ak, bk, npz_type)
Definition: fv_eta.F90:288
The module &#39;fv_eta&#39; contains routine to set up the reference (Eulerian) pressure coordinate.
Definition: fv_eta.F90:25
subroutine, public read_namelist_test_case_nml(nml_filename)
subroutine, public fv_control_init(Atm, dt_atmos, this_grid, grids_on_this_pe, p_split)
Definition: fv_control.F90:189
subroutine, public fv_io_exit
Close the fv core restart facilities.
Definition: fv_io.F90:141
subroutine, public multi_gases_init(ngas, nwat)
Definition: multi_gases.F90:72
subroutine, public grid_utils_init(Atm, npx, npy, npz, non_ortho, grid_type, c2l_order)
integer global_commid
Definition: fv_control.F90:174
subroutine, public init_grid(Atm, grid_name, grid_file, npx, npy, npz, ndims, nregions, ng, tile_coarse)
The subroutine &#39;init_grid&#39; reads the grid from the input file and sets up grid descriptors.
subroutine timing_on(blk_name)
The subroutine &#39;timing_on&#39; starts a timer.
Definition: fv_timing.F90:116
subroutine, public fv_end(Atm, this_grid, restart_endfcst)
The subroutine &#39;fv_end&#39; terminates FV3, deallocates memory, saves restart files, and stops I/O...
subroutine timing_prt(gid)
The subroutine &#39;timing_prt&#39; prints all timers.
Definition: fv_timing.F90:249
@ The module &#39;fv_diagnostics&#39; contains routines to compute diagnosic fields.
The module &#39;fv_grid_utils&#39; contains routines for setting up and computing grid-related quantities...
subroutine timing_init
The subroutine &#39;timing_init&#39; initializes timers.
Definition: fv_timing.F90:79
subroutine, public grid_utils_end
The module &#39;FV3_control&#39; is for initialization and termination of the model, and controls namelist pa...
Definition: fv_control.F90:29
integer halo_update_type
Definition: fv_control.F90:176
subroutine, public fv_restart_end(Atm, restart_endfcst)
The subroutine &#39;fv_restart_end&#39; writes ending restart files, terminates I/O, and prints out diagnosti...
subroutine deallocate_fv_atmos_type(Atm)
The subroutine &#39;deallocate_fv_atmos_type&#39; deallocates the fv_atmos_type.
Definition: fv_arrays.F90:1832