-
Notifications
You must be signed in to change notification settings - Fork 339
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
base: develop
Are you sure you want to change the base?
Prefix all namelist group and option names for MPAS dycore #1285
Conversation
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.
183fed2
to
930e9f9
Compare
Just started looking at this. One question I have is why the leading |
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? |
Sure! I will also provide the instructions here for clarity and convenience:
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! |
Thanks for the instructions @kuanchihwang . I follow them and inspected the 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. |
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:
config_
is removed recursively from the name. Case-insensitive.mpas_
is removed recursively from the name. Case-insensitive.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 theparse
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 theparse
utility stay the same. Its regression tests all pass, indicating identical model results to the previous baseline.