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