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