From 54a90a1fd86b245b76e0903c23a3990eb91f1764 Mon Sep 17 00:00:00 2001 From: David Fillmore Date: Mon, 10 Nov 2025 10:12:29 -0700 Subject: [PATCH] MICM configuration is now driven by a MUSICA namelist option with added logging. Registry.xml: Added a MUSICA namelist record gated by MPAS_USE_MUSICA with the `config_micm_file` option so the MICM JSON path can be provided through the standard configuration system. mpas_atm_chemistry.F: Removed the hardcoded `chapman.json`, pull the MICM file path from the configs pool, then propagate errors from `musica_init` via `mpas_log_write` to fail when initialization breaks. mpas_musica.F: Track the species description pointer and log each MICM species name from `state%species_ordering` so users can verify the runtime mapping. --- src/core_atmosphere/Registry.xml | 9 ++++++++ .../chemistry/mpas_atm_chemistry.F | 22 ++++++++++--------- .../chemistry/musica/mpas_musica.F | 9 +++++++- 3 files changed, 29 insertions(+), 11 deletions(-) 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..3997cc363f 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 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..0f4ef8cd45 100644 --- a/src/core_atmosphere/chemistry/musica/mpas_musica.F +++ b/src/core_atmosphere/chemistry/musica/mpas_musica.F @@ -61,9 +61,10 @@ subroutine musica_init(filename_of_micm_configuration, & type(error_t) :: error type(string_t) :: micm_version - + type(string_t) :: description ! TEMPORARY: Hard-coded options for the MICM solver integer :: solver_type = RosenbrockStandardOrder + integer :: i_species micm_version = get_micm_version() @@ -77,6 +78,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 + associate(map => state%species_ordering) + do i_species = 1, map%size( ) + call mpas_log_write('MICM species: ' // map%name(i_species)) + end do + end associate + end subroutine musica_init !------------------------------------------------------------------------