Initialize physics grid in terms of dynamics decomposition.
Provide grid and mapping information between global and local indexes to physics by calling phys_grid_init
.
(KCW, 2024-03-27)
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
real(kind=kind_dyn_mpas), | private, | pointer | :: | areacell(:) | |||
character(len=max_hcoordname_len), | private, | allocatable | :: | dyn_attribute_name(:) | |||
type(physics_column_t), | private, | allocatable | :: | dyn_column(:) | |||
integer, | private | :: | hdim1_d | ||||
integer, | private | :: | hdim2_d | ||||
integer, | private | :: | i | ||||
integer, | private | :: | ierr | ||||
integer, | private, | pointer | :: | indextocellid(:) | |||
real(kind=kind_dyn_mpas), | private, | pointer | :: | latcell(:) | |||
real(kind=kind_dyn_mpas), | private, | pointer | :: | loncell(:) | |||
character(len=*), | private, | parameter | :: | subname | = | 'dyn_grid::init_physics_grid' |
subroutine init_physics_grid() ! Module(s) from CAM-SIMA. use cam_abortutils, only: check_allocate use cam_logfile, only: debugout_debug use dyn_comp, only: dyn_debug_print, mpas_dynamical_core, ncells_global, ncells_solve, sphere_radius use dynconst, only: constant_pi => pi, rad_to_deg use physics_column_type, only: kind_pcol, physics_column_t use physics_grid, only: phys_grid_init use spmd_utils, only: iam use string_utils, only: stringify ! Module(s) from CESM Share. use shr_kind_mod, only: kind_r8 => shr_kind_r8 ! Module(s) from MPAS. use dyn_mpas_subdriver, only: kind_dyn_mpas => mpas_dynamical_core_real_kind character(*), parameter :: subname = 'dyn_grid::init_physics_grid' character(max_hcoordname_len), allocatable :: dyn_attribute_name(:) integer :: hdim1_d, hdim2_d ! First and second horizontal dimensions of physics grid. integer :: i integer :: ierr integer, pointer :: indextocellid(:) ! Global indexes of cell centers. real(kind_dyn_mpas), pointer :: areacell(:) ! Cell areas (m2). real(kind_dyn_mpas), pointer :: latcell(:) ! Cell center latitudes (rad). real(kind_dyn_mpas), pointer :: loncell(:) ! Cell center longitudes (rad). type(physics_column_t), allocatable :: dyn_column(:) ! Grid and mapping information between global and local indexes. call dyn_debug_print(debugout_debug, subname // ' entered') nullify(areacell) nullify(indextocellid) nullify(latcell) nullify(loncell) hdim1_d = ncells_global ! Setting `hdim2_d` to `1` indicates unstructured grid. hdim2_d = 1 call mpas_dynamical_core % get_variable_pointer(areacell, 'mesh', 'areaCell') call mpas_dynamical_core % get_variable_pointer(indextocellid, 'mesh', 'indexToCellID') call mpas_dynamical_core % get_variable_pointer(latcell, 'mesh', 'latCell') call mpas_dynamical_core % get_variable_pointer(loncell, 'mesh', 'lonCell') allocate(dyn_column(ncells_solve), stat=ierr) call check_allocate(ierr, subname, 'dyn_column(ncells_solve)', 'dyn_grid', __LINE__) do i = 1, ncells_solve ! Column information. dyn_column(i) % lat_rad = real(latcell(i), kind_pcol) dyn_column(i) % lon_rad = real(loncell(i), kind_pcol) dyn_column(i) % lat_deg = real(real(latcell(i), kind_r8) * rad_to_deg, kind_pcol) dyn_column(i) % lon_deg = real(real(loncell(i), kind_r8) * rad_to_deg, kind_pcol) ! Cell areas normalized to unit sphere. dyn_column(i) % area = real(areacell(i) / (sphere_radius ** 2), kind_pcol) ! Cell weights normalized to unity. dyn_column(i) % weight = & real(real(areacell(i), kind_r8) / (4.0_kind_r8 * constant_pi * real(sphere_radius, kind_r8) ** 2), kind_pcol) ! File decomposition. ! For unstructured grid, `coord_indices` is not used by `phys_grid_init`. dyn_column(i) % coord_indices(:) = -1 ! In this case, `global_col_num` is used instead. dyn_column(i) % global_col_num = indextocellid(i) ! Dynamics decomposition. dyn_column(i) % dyn_task = iam dyn_column(i) % global_dyn_block = indextocellid(i) dyn_column(i) % local_dyn_block = i ! `dyn_block_index` is not used due to no dynamics block offset, but it still needs to be allocated. allocate(dyn_column(i) % dyn_block_index(0), stat=ierr) call check_allocate(ierr, subname, 'dyn_column(' // stringify([i]) // ') % dyn_block_index(0)', & 'dyn_grid', __LINE__) end do nullify(areacell) nullify(indextocellid) nullify(latcell) nullify(loncell) ! `phys_grid_init` expects to receive the `area` attribute from dynamics. ! However, do not let it because dynamics grid is different from physics grid. allocate(dyn_attribute_name(0), stat=ierr) call check_allocate(ierr, subname, 'dyn_attribute_name(0)', 'dyn_grid', __LINE__) call phys_grid_init(hdim1_d, hdim2_d, 'mpas', dyn_column, 'mpas_cell', dyn_attribute_name) deallocate(dyn_column) deallocate(dyn_attribute_name) call dyn_debug_print(debugout_debug, subname // ' completed') end subroutine init_physics_grid