From 54a90a1fd86b245b76e0903c23a3990eb91f1764 Mon Sep 17 00:00:00 2001 From: David Fillmore Date: Mon, 10 Nov 2025 10:12:29 -0700 Subject: [PATCH 1/5] 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 !------------------------------------------------------------------------ From ce0c7a4087c7ef8e5dee245db01cd705d6278ce4 Mon Sep 17 00:00:00 2001 From: David Fillmore Date: Fri, 14 Nov 2025 07:16:36 -0700 Subject: [PATCH 2/5] Removed unused description variable. --- src/core_atmosphere/chemistry/musica/mpas_musica.F | 1 - 1 file changed, 1 deletion(-) diff --git a/src/core_atmosphere/chemistry/musica/mpas_musica.F b/src/core_atmosphere/chemistry/musica/mpas_musica.F index 0f4ef8cd45..3bbb43063c 100644 --- a/src/core_atmosphere/chemistry/musica/mpas_musica.F +++ b/src/core_atmosphere/chemistry/musica/mpas_musica.F @@ -61,7 +61,6 @@ 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 From effd49239e4bb2c8eb58d47cec27010b7b7edb85 Mon Sep 17 00:00:00 2001 From: David Fillmore Date: Fri, 14 Nov 2025 07:35:51 -0700 Subject: [PATCH 3/5] Restored use mpas_derived_types, only: mpas_pool_type, added MPAS_LOG_CRIT. --- src/core_atmosphere/chemistry/mpas_atm_chemistry.F | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core_atmosphere/chemistry/mpas_atm_chemistry.F b/src/core_atmosphere/chemistry/mpas_atm_chemistry.F index 3997cc363f..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 + 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 From 681778bc07b4778791b2482a85987fffc5bb8d55 Mon Sep 17 00:00:00 2001 From: David Fillmore Date: Fri, 14 Nov 2025 10:04:43 -0700 Subject: [PATCH 4/5] Removed associate block in musica_init. --- src/core_atmosphere/chemistry/musica/mpas_musica.F | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/core_atmosphere/chemistry/musica/mpas_musica.F b/src/core_atmosphere/chemistry/musica/mpas_musica.F index 3bbb43063c..5d5fd8e72f 100644 --- a/src/core_atmosphere/chemistry/musica/mpas_musica.F +++ b/src/core_atmosphere/chemistry/musica/mpas_musica.F @@ -77,11 +77,9 @@ 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 + do i_species = 1, state%species_ordering%size() + call mpas_log_write('MICM species: ' // state%species_ordering%name(i_species)) + end do end subroutine musica_init From bb304f02c6fcd8d22490cea756f783d675ce811d Mon Sep 17 00:00:00 2001 From: David Fillmore Date: Fri, 16 Jan 2026 15:20:02 -0700 Subject: [PATCH 5/5] 1. Added musica_is_initialized flag (line 32) 2. Added early return when config file is empty, with log message (lines 69-75) 3. Added logging of the config file path (line 80) 4. Set musica_is_initialized = .true. after successful init (line 93) 5. Added guard in musica_step (line 114) 6. Added guard in musica_finalize (line 137) --- .../chemistry/musica/mpas_musica.F | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/core_atmosphere/chemistry/musica/mpas_musica.F b/src/core_atmosphere/chemistry/musica/mpas_musica.F index 5d5fd8e72f..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 @@ -65,9 +66,18 @@ subroutine musica_init(filename_of_micm_configuration, & 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]) @@ -81,6 +91,8 @@ subroutine musica_init(filename_of_micm_configuration, & call mpas_log_write('MICM species: ' // state%species_ordering%name(i_species)) end do + musica_is_initialized = .true. + end subroutine musica_init !------------------------------------------------------------------------ @@ -100,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 @@ -121,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.