diff --git a/src/core_atmosphere/Registry.xml b/src/core_atmosphere/Registry.xml index 4281c40bba..88c0b0928d 100644 --- a/src/core_atmosphere/Registry.xml +++ b/src/core_atmosphere/Registry.xml @@ -394,6 +394,15 @@ possible_values="`mpas_dmpar', `mpas_halo'"/> +#ifdef MPAS_USE_MUSICA + + + +#endif + diff --git a/src/core_atmosphere/chemistry/mpas_atm_chemistry.F b/src/core_atmosphere/chemistry/mpas_atm_chemistry.F index 39715cf37a..7fda1f27a8 100644 --- a/src/core_atmosphere/chemistry/mpas_atm_chemistry.F +++ b/src/core_atmosphere/chemistry/mpas_atm_chemistry.F @@ -43,7 +43,7 @@ subroutine chemistry_init(configs, dimensions) use mpas_musica, only: musica_init #endif use mpas_log, only : mpas_log_write - use mpas_derived_types, only: mpas_pool_type + use mpas_derived_types, only: mpas_pool_type, MPAS_LOG_CRIT use mpas_kind_types, only: StrKIND use mpas_pool_routines, only: mpas_pool_get_config, mpas_pool_get_dimension @@ -51,13 +51,11 @@ subroutine chemistry_init(configs, dimensions) type (mpas_pool_type), intent(in) :: dimensions #ifdef MPAS_USE_MUSICA - integer :: error_code - character(len=:), allocatable :: error_message - integer :: nVertLevels - integer, pointer :: nVertLevels_ptr - ! MUSICA will get the MICM JSON config from a namelist - ! hardcode filepath for now - character(len=StrKIND) :: filepath = 'chapman.json' + character(len=StrKIND), pointer :: filepath_ptr + integer :: error_code + character(len=:), allocatable :: error_message + integer :: nVertLevels + integer, pointer :: nVertLevels_ptr #endif call mpas_log_write('Initializing chemistry packages...') @@ -66,9 +64,13 @@ subroutine chemistry_init(configs, dimensions) call mpas_pool_get_dimension(dimensions, 'nVertLevels', nVertLevels_ptr) nVertLevels = nVertLevels_ptr - call musica_init(filepath, nVertLevels, error_code, error_message) + call mpas_pool_get_config(configs, 'config_micm_file', filepath_ptr) - ! TODO check error_code and generate MPAS error log message + call musica_init(filepath_ptr, nVertLevels, error_code, error_message) + + if (error_code /= 0) then + call mpas_log_write(error_message, messageType=MPAS_LOG_CRIT) + end if #endif end subroutine chemistry_init diff --git a/src/core_atmosphere/chemistry/musica/mpas_musica.F b/src/core_atmosphere/chemistry/musica/mpas_musica.F index 649b2b3624..a531a2414e 100644 --- a/src/core_atmosphere/chemistry/musica/mpas_musica.F +++ b/src/core_atmosphere/chemistry/musica/mpas_musica.F @@ -29,6 +29,7 @@ module mpas_musica type(micm_t), pointer :: micm => null ( ) ! Pointer to the MICM ODE solver instance type(state_t), pointer :: state => null ( ) ! Pointer to the state of the MICM solver + logical :: musica_is_initialized = .false. ! Flag to track if MUSICA was successfully initialized contains @@ -61,13 +62,22 @@ subroutine musica_init(filename_of_micm_configuration, & type(error_t) :: error type(string_t) :: micm_version - ! TEMPORARY: Hard-coded options for the MICM solver integer :: solver_type = RosenbrockStandardOrder + integer :: i_species + + ! Skip MUSICA initialization if no configuration file is provided + if (len_trim(filename_of_micm_configuration) == 0) then + call mpas_log_write('MUSICA chemistry disabled: no MICM configuration file specified') + error_code = 0 + error_message = '' + return + end if micm_version = get_micm_version() call mpas_log_write('Initializing MUSICA chemistry package...') + call mpas_log_write('MICM configuration file: ' // trim(filename_of_micm_configuration)) call mpas_log_write('MICM version: ' // micm_version%value_) call mpas_log_write('MICM number of grid cells: $i', intArgs=[number_of_grid_cells]) @@ -77,6 +87,12 @@ subroutine musica_init(filename_of_micm_configuration, & state => micm%get_state(number_of_grid_cells, error) if (has_error_occurred(error, error_message, error_code)) return + do i_species = 1, state%species_ordering%size() + call mpas_log_write('MICM species: ' // state%species_ordering%name(i_species)) + end do + + musica_is_initialized = .true. + end subroutine musica_init !------------------------------------------------------------------------ @@ -96,6 +112,8 @@ subroutine musica_step() use mpas_log, only : mpas_log_write + if (.not. musica_is_initialized) return + call mpas_log_write('Stepping MUSICA chemistry package...') ! Here we would typically call the TUV-x and MICM packages to perform @@ -117,6 +135,8 @@ subroutine musica_finalize() use mpas_log, only : mpas_log_write + if (.not. musica_is_initialized) return + call mpas_log_write('Finalizing MUSICA chemistry package...') ! Here we would typically clean up resources, but for now we do nothing.