dyn_mpas_init_phase1 Subroutine

private subroutine dyn_mpas_init_phase1(self, mpi_comm, model_error_impl, log_level, log_unit, mpas_log_unit)

Uses

    • mpas_framework
    • mpas_domain_routines
    • atm_core_interface
  • proc~~dyn_mpas_init_phase1~~UsesGraph proc~dyn_mpas_init_phase1 mpas_dynamical_core_type%dyn_mpas_init_phase1 atm_core_interface atm_core_interface proc~dyn_mpas_init_phase1->atm_core_interface mpas_domain_routines mpas_domain_routines proc~dyn_mpas_init_phase1->mpas_domain_routines mpas_framework mpas_framework proc~dyn_mpas_init_phase1->mpas_framework

This subroutine follows the stand-alone MPAS subdriver up to, but not including, the point where namelist is read. Ported and refactored for CAM-SIMA. (KCW, 2024-02-02)

Type Bound

mpas_dynamical_core_type

Arguments

Type IntentOptional Attributes Name
class(mpas_dynamical_core_type), intent(inout) :: self
integer, intent(in) :: mpi_comm
procedure(model_error_if) :: model_error_impl
integer, intent(in) :: log_level
integer, intent(in) :: log_unit
integer, intent(in) :: mpas_log_unit(2)

Calls

proc~~dyn_mpas_init_phase1~~CallsGraph proc~dyn_mpas_init_phase1 mpas_dynamical_core_type%dyn_mpas_init_phase1 atm_setup_core atm_setup_core proc~dyn_mpas_init_phase1->atm_setup_core atm_setup_domain atm_setup_domain proc~dyn_mpas_init_phase1->atm_setup_domain mpas_allocate_domain mpas_allocate_domain proc~dyn_mpas_init_phase1->mpas_allocate_domain mpas_framework_init_phase1 mpas_framework_init_phase1 proc~dyn_mpas_init_phase1->mpas_framework_init_phase1 mpi_comm_rank mpi_comm_rank proc~dyn_mpas_init_phase1->mpi_comm_rank proc~dyn_mpas_debug_print mpas_dynamical_core_type%dyn_mpas_debug_print proc~dyn_mpas_init_phase1->proc~dyn_mpas_debug_print setup_log setup_log proc~dyn_mpas_init_phase1->setup_log proc~stringify stringify proc~dyn_mpas_debug_print->proc~stringify

Called by

proc~~dyn_mpas_init_phase1~~CalledByGraph proc~dyn_mpas_init_phase1 mpas_dynamical_core_type%dyn_mpas_init_phase1 proc~dyn_readnl dyn_readnl proc~dyn_readnl->proc~dyn_mpas_init_phase1

Variables

Type Visibility Attributes Name Initial
integer, private :: ierr
character(len=*), private, parameter :: subname = 'dyn_mpas_subdriver::dyn_mpas_init_phase1'

Source Code

    subroutine dyn_mpas_init_phase1(self, mpi_comm, model_error_impl, log_level, log_unit, mpas_log_unit)
        ! Module(s) from MPAS.
        use atm_core_interface, only: atm_setup_core, atm_setup_domain
        use mpas_domain_routines, only: mpas_allocate_domain
        use mpas_framework, only: mpas_framework_init_phase1

        class(mpas_dynamical_core_type), intent(inout) :: self
#ifdef MPAS_USE_MPI_F08
        type(mpi_comm_type), intent(in) :: mpi_comm
#else
        integer, intent(in) :: mpi_comm
#endif
        procedure(model_error_if) :: model_error_impl
        integer, intent(in) :: log_level
        integer, intent(in) :: log_unit
        integer, intent(in) :: mpas_log_unit(2)

        character(*), parameter :: subname = 'dyn_mpas_subdriver::dyn_mpas_init_phase1'
        integer :: ierr

        self % mpi_comm = mpi_comm
        self % model_error => model_error_impl

        if (self % mpi_comm == mpi_comm_null) then
            call self % model_error('Invalid MPI communicator group', subname, __LINE__)
        end if

        call mpi_comm_rank(self % mpi_comm, self % mpi_rank, ierr)

        if (ierr /= mpi_success) then
            call self % model_error('Invalid MPI communicator group', subname, __LINE__)
        end if

        self % mpi_rank_root = (self % mpi_rank == 0)
        self % log_level = max(min(log_level, log_level_debug), log_level_quiet)
        self % log_unit = log_unit

        call self % debug_print(log_level_debug, subname // ' entered')

        call self % debug_print(log_level_info, 'Allocating core')

        allocate(self % corelist, stat=ierr)

        if (ierr /= 0) then
            call self % model_error('Failed to allocate corelist', subname, __LINE__)
        end if

        nullify(self % corelist % next)

        call self % debug_print(log_level_info, 'Allocating domain')

        allocate(self % corelist % domainlist, stat=ierr)

        if (ierr /= 0) then
            call self % model_error('Failed to allocate corelist % domainlist', subname, __LINE__)
        end if

        nullify(self % corelist % domainlist % next)

        self % domain_ptr => self % corelist % domainlist
        self % domain_ptr % core => self % corelist

        call mpas_allocate_domain(self % domain_ptr)

        self % domain_ptr % domainid = 0

        call self % debug_print(log_level_info, 'Initializing MPAS framework (Phase 1/2)')

        ! Initialize MPAS framework with the supplied MPI communicator group.
        call mpas_framework_init_phase1(self % domain_ptr % dminfo, external_comm=self % mpi_comm)

        call self % debug_print(log_level_info, 'Setting up core')

        call atm_setup_core(self % corelist)

        call self % debug_print(log_level_info, 'Setting up domain')

        call atm_setup_domain(self % domain_ptr)

        call self % debug_print(log_level_info, 'Setting up log')

        ! Set up the log manager as early as possible so we can use it for any errors/messages during subsequent
        ! initialization steps.
        !
        ! We need:
        ! 1. `domain_ptr` to be allocated;
        ! 2. `dmpar_init` to be completed for accessing `dminfo`;
        ! 3. `*_setup_core` to assign the `setup_log` procedure pointer.
        ierr = self % domain_ptr % core % setup_log(self % domain_ptr % loginfo, self % domain_ptr, unitnumbers=mpas_log_unit)

        if (ierr /= 0) then
            call self % model_error('Log setup failed for core ' // trim(self % domain_ptr % core % corename), &
                subname, __LINE__)
        end if

        ! At this point, we should be ready to read namelist in `dyn_mpas_read_namelist`.
        call self % debug_print(log_level_debug, subname // ' completed')
    end subroutine dyn_mpas_init_phase1