dyn_mpas_init_phase2 Subroutine

private subroutine dyn_mpas_init_phase2(self, pio_iosystem)

Uses

    • mpas_framework
    • pio
    • mpas_stream_inquiry
  • proc~~dyn_mpas_init_phase2~~UsesGraph proc~dyn_mpas_init_phase2 mpas_dynamical_core_type%dyn_mpas_init_phase2 mpas_framework mpas_framework proc~dyn_mpas_init_phase2->mpas_framework mpas_stream_inquiry mpas_stream_inquiry proc~dyn_mpas_init_phase2->mpas_stream_inquiry pio pio proc~dyn_mpas_init_phase2->pio

This subroutine follows the stand-alone MPAS subdriver from the point where we call the second phase of MPAS framework initialization up to the check on the existence of the "streams." file. Ported and refactored for CAM-SIMA. (KCW, 2024-02-07)

Type Bound

mpas_dynamical_core_type

Arguments

Type IntentOptional Attributes Name
class(mpas_dynamical_core_type), intent(in) :: self
type(iosystem_desc_t), intent(in), pointer :: pio_iosystem

Calls

proc~~dyn_mpas_init_phase2~~CallsGraph proc~dyn_mpas_init_phase2 mpas_dynamical_core_type%dyn_mpas_init_phase2 define_packages define_packages proc~dyn_mpas_init_phase2->define_packages mpas_framework_init_phase2 mpas_framework_init_phase2 proc~dyn_mpas_init_phase2->mpas_framework_init_phase2 mpas_stream_inquiry_new_streaminfo mpas_stream_inquiry_new_streaminfo proc~dyn_mpas_init_phase2->mpas_stream_inquiry_new_streaminfo pio_iosystem_is_active pio_iosystem_is_active proc~dyn_mpas_init_phase2->pio_iosystem_is_active proc~dyn_mpas_debug_print mpas_dynamical_core_type%dyn_mpas_debug_print proc~dyn_mpas_init_phase2->proc~dyn_mpas_debug_print setup_clock setup_clock proc~dyn_mpas_init_phase2->setup_clock setup_decompositions setup_decompositions proc~dyn_mpas_init_phase2->setup_decompositions setup_packages setup_packages proc~dyn_mpas_init_phase2->setup_packages proc~stringify stringify proc~dyn_mpas_debug_print->proc~stringify

Called by

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

Variables

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

Source Code

    subroutine dyn_mpas_init_phase2(self, pio_iosystem)
        ! Module(s) from external libraries.
        use pio, only: iosystem_desc_t, pio_iosystem_is_active
        ! Module(s) from MPAS.
        use mpas_framework, only: mpas_framework_init_phase2
        use mpas_stream_inquiry, only: mpas_stream_inquiry_new_streaminfo

        class(mpas_dynamical_core_type), intent(in) :: self
        type(iosystem_desc_t), pointer, intent(in) :: pio_iosystem

        character(*), parameter :: subname = 'dyn_mpas_subdriver::dyn_mpas_init_phase2'
        integer :: ierr
        logical :: pio_iosystem_active

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

        call self % debug_print(log_level_info, 'Checking PIO system descriptor')

        if (.not. associated(pio_iosystem)) then
            call self % model_error('Invalid PIO system descriptor', subname, __LINE__)
        end if

        call pio_iosystem_is_active(pio_iosystem, pio_iosystem_active)

        if (.not. pio_iosystem_active) then
            call self % model_error('Invalid PIO system descriptor', subname, __LINE__)
        end if

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

        ! Initialize MPAS framework with the supplied PIO system descriptor.
        call mpas_framework_init_phase2(self % domain_ptr, io_system=pio_iosystem)

        ! Instantiate `streaminfo`, but do not actually initialize it. Any queries made to it will always return `.false.`.
        ! This is the intended behavior because MPAS as a dynamical core is not responsible for managing IO.
        self % domain_ptr % streaminfo => mpas_stream_inquiry_new_streaminfo()

        if (.not. associated(self % domain_ptr % streaminfo)) then
            call self % model_error('Stream info instantiation failed for core ' // trim(self % domain_ptr % core % corename), &
                subname, __LINE__)
        end if

        call self % debug_print(log_level_info, 'Defining packages')

        ierr = self % domain_ptr % core % define_packages(self % domain_ptr % packages)

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

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

        ierr = self % domain_ptr % core % setup_packages( &
            self % domain_ptr % configs, self % domain_ptr % streaminfo, &
            self % domain_ptr % packages, self % domain_ptr % iocontext)

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

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

        ierr = self % domain_ptr % core % setup_decompositions(self % domain_ptr % decompositions)

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

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

        ierr = self % domain_ptr % core % setup_clock(self % domain_ptr % clock, self % domain_ptr % configs)

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

        ! At this point, we should be ready to set up decompositions, build halos, allocate blocks, etc.
        ! in `dyn_mpas_init_phase3`.
        call self % debug_print(log_level_debug, subname // ' completed')
    end subroutine dyn_mpas_init_phase2