Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefix all namelist group and option names for MPAS dycore #1285

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

kuanchihwang
Copy link
Contributor

@kuanchihwang kuanchihwang commented Jan 30, 2025

When MPAS is used as a dynamical core in a host model (e.g., CAM/CAM-SIMA), it needs to share the namelist file with other model components. Therefore, MPAS namelist groups and options may not be easily recognizable at first sight. The solution, which is implemented by this PR, is to add a unique identifier to all MPAS namelist group and option names.

The following transformations are performed for each MPAS namelist group and option name:

  1. Leading config_ is removed recursively from the name. Case-insensitive.
  2. Leading mpas_ is removed recursively from the name. Case-insensitive.
  3. Prepend mpas_ to the name.

As a result, it is now easier to distinguish MPAS namelist groups and options from CAM-SIMA ones. Additionally, the possibility of name collisions with CAM-SIMA ones is also resolved once and for all. Note that only namelist I/O is affected. Internally, MPAS still refers to its namelist options by their original names due to compatibility reasons.

Compared to the implementation in CAM, this PR applies the "name mangling" logic in an algorithmic and predictable way. It works automatically even if there are additions, modifications, or deletions to MPAS namelist groups and options.

The "name mangling" logic is entirely guarded behind the MPAS_CAM_DYCORE macro. For stand-alone MPAS, there is no functional change, which can be confirmed by the parse utility staying bitwise identical. For CAM, it is not affected by this PR because it does not use the code generation functionality of MPAS for namelist reading. For CAM-SIMA, the Fortran include files generated by the parse utility stay the same. Its regression tests all pass, indicating identical model results to the previous baseline.

When MPAS is used as a dynamical core, the following transformations are
performed for each namelist group and option name:

1. Leading `config_` is removed recursively from the name. Case-insensitive.
2. Leading `mpas_` is removed recursively from the name. Case-insensitive.
3. Prepend `mpas_` to the name.

As a result, it is now easier to distinguish MPAS namelist groups and options
from CAM-SIMA ones. Additionally, the possibility of name collisions with
CAM-SIMA ones is also resolved once and for all.

Note that only namelist I/O is affected. Internally, MPAS still refers to its
namelist options by their original names due to compatibility reasons.
@kuanchihwang kuanchihwang force-pushed the staging/dycore-prefix-namelist branch from 183fed2 to 930e9f9 Compare January 31, 2025 18:31
@abishekg7
Copy link
Collaborator

Just started looking at this. One question I have is why the leading mpas_ and config_ strings need to be removed recursively and not just once.

@kuanchihwang
Copy link
Contributor Author

Just started looking at this. One question I have is why the leading mpas_ and config_ strings need to be removed recursively and not just once.

Performing the removal operation only once would also work. However, the recursion should make it more robust in the unlikely case that a namelist option with duplicate prefixes is introduced to MPAS registry.

@abishekg7
Copy link
Collaborator

Just started looking at this. One question I have is why the leading mpas_ and config_ strings need to be removed recursively and not just once.

Performing the removal operation only once would also work. However, the recursion should make it more robust in the unlikely case that a namelist option with duplicate prefixes is introduced to MPAS registry.

Thanks @kuanchihwang. The code itself looks fine, but I was wondering how to go about testing this implementation. You provided some CAM-SIMA build instructions earlier - can I use those?

@kuanchihwang
Copy link
Contributor Author

kuanchihwang commented Feb 7, 2025

@abishekg7

Sure! I will also provide the instructions here for clarity and convenience:

  1. Output the changes in this PR as a patch by git format-patch (git diff also works).
  2. Follow the steps below on Derecho:
git clone https://github.com/ESCOMP/CAM-SIMA.git
cd CAM-SIMA
git checkout development
./bin/git-fleximod update
# Replace the patch at "src/dynamics/mpas/assets/0001-Prefix-all-MPAS-namelist-group-and-option-names.patch" with the one that you generated in step 1. File name needs to end with "*.patch".
mkdir -pv ../PR1285 && cd ../PR1285

# Compile with GNU compilers
../CAM-SIMA/cime/scripts/create_newcase --compiler gnu --case PR1285-GNU --compset FKESSLER --project PROJECT_KEY --res mpasa480_mpasa480 --run-unsupported
cd PR1285-GNU
# Compile with Intel compilers
../CAM-SIMA/cime/scripts/create_newcase --compiler intel --case PR1285-Intel --compset FKESSLER --project PROJECT_KEY --res mpasa480_mpasa480 --run-unsupported
cd PR1285-Intel

./case.setup
./case.build

# Inspect the build artifacts of MPAS at:
#   "$SCRATCH/PR1285-GNU/bld/atm/obj/mpas" for GNU compilers
#   "$SCRATCH/PR1285-Intel/bld/atm/obj/mpas" for Intel compilers
#
# Specifically, inspect the "namelist_call.inc" and "namelist_defines.inc" include files at:
#   "$SCRATCH/PR1285-GNU/bld/atm/obj/mpas/core_atmosphere/inc" for GNU compilers
#   "$SCRATCH/PR1285-Intel/bld/atm/obj/mpas/core_atmosphere/inc" for Intel compilers
#
# You will find that MPAS namelist group and option names have been prefixed with "mpas_".

Similarly, this PR is also an attempt to upstream that particular patch so we do not have to maintain it downstream at CAM-SIMA. Thanks so much for your time!

@abishekg7
Copy link
Collaborator

Thanks for the instructions @kuanchihwang . I follow them and inspected the namelist_defines.inc for both the builds - Looks good to me.

The only comment I have is re. the commit message. Could you reference (CAM/CAM-SIMA) in the title of the commit message and also the first line inside the message. i.e it ends with "When MPAS is used as a dynamical core". Could you add "in a host model (e.g., CAM/CAM-SIMA)" right after this, just like in the PR description.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants