Skip to content

Commit

Permalink
Move all shared variables to dyn_comp due to circular dependency issue
Browse files Browse the repository at this point in the history
The instance of MPAS dynamical core resides in `dyn_comp`. `dyn_grid` depends on
`dyn_comp`, but not vice versa.
  • Loading branch information
kuanchihwang committed Jun 12, 2024
1 parent c38a9b3 commit 932ef82
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 23 deletions.
12 changes: 12 additions & 0 deletions src/dynamics/mpas/dyn_comp.F90
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ module dyn_comp

public :: dyn_debug_print
public :: mpas_dynamical_core
public :: ncells, ncells_solve, nedges, nedges_solve, nvertices, nvertices_solve, nvertlevels
public :: ncells_global, nedges_global, nvertices_global, ncells_max, nedges_max
public :: sphere_radius
public :: deg_to_rad, rad_to_deg

type :: dyn_import_t
end type dyn_import_t
Expand All @@ -41,6 +45,14 @@ module dyn_comp

!> The "instance/object" of MPAS dynamical core.
type(mpas_dynamical_core_type) :: mpas_dynamical_core

! Local and global mesh dimensions of MPAS dynamical core.
integer :: ncells, ncells_solve, nedges, nedges_solve, nvertices, nvertices_solve, nvertlevels
integer :: ncells_global, nedges_global, nvertices_global, ncells_max, nedges_max
real(kind_r8) :: sphere_radius

real(kind_r8), parameter :: deg_to_rad = constant_pi / 180.0_kind_r8 ! Convert degrees to radians.
real(kind_r8), parameter :: rad_to_deg = 180.0_kind_r8 / constant_pi ! Convert radians to degrees.
contains
!> Print a debug message with optionally the value(s) of a variable.
!> If `printer` is not supplied, the MPI root rank will print. Otherwise, the designated MPI rank will print instead.
Expand Down
30 changes: 7 additions & 23 deletions src/dynamics/mpas/dyn_grid.F90
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ module dyn_grid
max_hcoordname_len
use cam_initfiles, only: initial_file_get_id
use cam_map_utils, only: kind_imap => imap
use dyn_comp, only: dyn_debug_print, mpas_dynamical_core
use dyn_comp, only: dyn_debug_print, mpas_dynamical_core, &
ncells, ncells_solve, nedges, nedges_solve, nvertices, nvertices_solve, nvertlevels, &
ncells_global, nedges_global, nvertices_global, ncells_max, nedges_max, &
sphere_radius, &
deg_to_rad, rad_to_deg
use dynconst, only: dynconst_init, pi
use physics_column_type, only: kind_pcol, physics_column_t
use physics_grid, only: phys_decomp, phys_grid_init
Expand Down Expand Up @@ -40,14 +44,6 @@ module dyn_grid
'mpas_edge', &
'mpas_vertex' &
]

real(kind_r8), parameter :: deg_to_rad = pi / 180.0_kind_r8 ! Convert degrees to radians.
real(kind_r8), parameter :: rad_to_deg = 180.0_kind_r8 / pi ! Convert radians to degrees.

! Local and global mesh dimensions.
integer :: ncells_solve, nedges_solve, nvertices_solve
integer :: ncells_global, nedges_global, nvertices_global, nvertlevels, ncells_max, nedges_max
real(kind_r8) :: sphere_radius
contains
!> Initialize various model grids (e.g., dynamics, physics) in terms of dynamics decomposition.
!> Additionally, MPAS framework initialization and reading time-invariant (e.g., grid/mesh) variables
Expand All @@ -57,9 +53,6 @@ module dyn_grid
! Called by `cam_init` in `src/control/cam_comp.F90`.
subroutine model_grid_init()
character(*), parameter :: subname = 'dyn_grid::model_grid_init'
integer, pointer :: ncellssolve => null()
integer, pointer :: nedgessolve => null()
integer, pointer :: nverticessolve => null()
type(file_desc_t), pointer :: pio_file => null()

! Initialize mathematical and physical constants for dynamics.
Expand Down Expand Up @@ -87,17 +80,8 @@ subroutine model_grid_init()
! Inquire local and global mesh dimensions and save them as module variables.
call dyn_debug_print('Inquiring local and global mesh dimensions')

call mpas_dynamical_core % get_variable_pointer(ncellssolve, 'dim', 'nCellsSolve')
call mpas_dynamical_core % get_variable_pointer(nedgessolve, 'dim', 'nEdgesSolve')
call mpas_dynamical_core % get_variable_pointer(nverticessolve, 'dim', 'nVerticesSolve')

ncells_solve = ncellssolve
nedges_solve = nedgessolve
nvertices_solve = nverticessolve

nullify(ncellssolve)
nullify(nedgessolve)
nullify(nverticessolve)
call mpas_dynamical_core % get_local_mesh_dimension( &
ncells, ncells_solve, nedges, nedges_solve, nvertices, nvertices_solve, nvertlevels)

call mpas_dynamical_core % get_global_mesh_dimension( &
ncells_global, nedges_global, nvertices_global, nvertlevels, ncells_max, nedges_max, &
Expand Down

0 comments on commit 932ef82

Please sign in to comment.