Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/core_atmosphere/Registry.xml
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,15 @@
possible_values="`mpas_dmpar', `mpas_halo'"/>
</nml_record>

#ifdef MPAS_USE_MUSICA
<nml_record name="musica" in_defaults="true">
<nml_option name="config_micm_file" type="character" default_value=""
units="-"
description="MICM configuration file name"
possible_values="Any valid filename"/>
</nml_record>
#endif

<!-- **************************************************************************************** -->
<!-- ************************************** Packages ************************************** -->
<!-- **************************************************************************************** -->
Expand Down
22 changes: 12 additions & 10 deletions src/core_atmosphere/chemistry/mpas_atm_chemistry.F
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,19 @@ 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was there a specific reason for eliminating the only clause for this use statement?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see now that this was probably to get access to MPAS_LOG_CRIT. In that case, perhaps it would be better to add MPAS_LOG_CRIT to the use, only statement?

use mpas_kind_types, only: StrKIND
use mpas_pool_routines, only: mpas_pool_get_config, mpas_pool_get_dimension

type (mpas_pool_type), intent(in) :: configs
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...')
Expand All @@ -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
Expand Down
9 changes: 8 additions & 1 deletion src/core_atmosphere/chemistry/musica/mpas_musica.F
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ subroutine musica_init(filename_of_micm_configuration, &

type(error_t) :: error
type(string_t) :: micm_version

type(string_t) :: description
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't look like the description variable is used anywhere in this routine.

! TEMPORARY: Hard-coded options for the MICM solver
integer :: solver_type = RosenbrockStandardOrder
integer :: i_species

micm_version = get_micm_version()

Expand All @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although it's completely standard Fortran, it might be worth avoiding an associate block here for a couple of reasons:

  1. With Noah-MP, we hit an internal compiler error with the GCC 13 compilers due to associate blocks in that code; so there is evidence that some compiler releases don't handle associate very well.
  2. With an associate block, it's not possible to tell the type of map, and one would have to look elsewhere to find, e.g., that name is a valid member of an instance of whatever type map has.

So it might prevent compilation issues and lead to clearer code if we provide an explicit declaration of map as a local variable in the musica_init routine.

do i_species = 1, map%size( )
call mpas_log_write('MICM species: ' // map%name(i_species))
end do
end associate

end subroutine musica_init

!------------------------------------------------------------------------
Expand Down