Skip to content

Refactor MPAS dynamical core in preparation for unit testing - #407

Merged
kuanchihwang merged 18 commits into
ESCOMP:developmentfrom
kuanchihwang:staging/mpas-dycore-refactor
Aug 13, 2025
Merged

Refactor MPAS dynamical core in preparation for unit testing#407
kuanchihwang merged 18 commits into
ESCOMP:developmentfrom
kuanchihwang:staging/mpas-dycore-refactor

Conversation

@kuanchihwang

@kuanchihwang kuanchihwang commented Jul 21, 2025

Copy link
Copy Markdown
Collaborator

Tag name (required for release branches):

None

Originator(s):

kuanchihwang

Descriptions (include the issue title, and the keyword ['closes', 'fixes', 'resolves'] followed by the issue number):

This PR refactors MPAS dynamical core in preparation for unit testing. Specifically,

  1. The dyn_{comp,coupling,grid} modules have been converted to submodules to avoid further circular dependency issues. Now, the dyn_{comp,coupling,grid} modules only contain public interfaces and variables. This is analogous to the header files (*.h) in C. The dyn_{comp,coupling,grid}_impl submodules contain the actual implementations for the respective modules. This is analogous to the source files (*.c) in C.
  2. By doing so, the dyn_exchange_constituent_states subroutine can be moved to dyn_coupling, while the dyn_inquire_mesh_dimensions subroutine as well as its associated variables can be moved to dyn_grid. This relocation better reflects their functional context.
  3. Split out reusable, easily compilable, and testable procedures into the new dyn_{,mpas_}procedure modules in preparation for unit testing. Unit tests will then focus on these two modules in the future.

The points 1. and 2. are the solution in response to a previous review comment by @nusbaume.

Describe any changes made to the build system:

M       src/dynamics/mpas/assets/Makefile.in.CESM
    * Refactor in preparation for unit testing

Describe any changes made to the namelist:

None

List any changes to the defaults for the input datasets (e.g., boundary datasets):

None

List all files eliminated and why:

None

List all files added and what they do:

A       src/dynamics/mpas/driver/dyn_mpas_procedure.F90
A       src/dynamics/mpas/dyn_procedure.F90
    * Refactor in preparation for unit testing
A       src/dynamics/mpas/dyn_comp_impl.F90
A       src/dynamics/mpas/dyn_coupling_impl.F90
A       src/dynamics/mpas/dyn_grid_impl.F90
    * Separate interfaces and implementations by using Fortran submodules
    * Move subroutines to the modules that make more contextual sense
    * Refactor in preparation for unit testing

List all existing files that have been modified, and describe the changes:

M       src/dynamics/mpas/assets/Makefile.in.CESM
M       src/dynamics/mpas/driver/dyn_mpas_subdriver.F90
    * Refactor in preparation for unit testing
M       src/dynamics/mpas/dyn_comp.F90
M       src/dynamics/mpas/dyn_coupling.F90
M       src/dynamics/mpas/dyn_grid.F90
    * Separate interfaces and implementations by using Fortran submodules
    * Move subroutines to the modules that make more contextual sense
    * Refactor in preparation for unit testing

Regression tests:

No changes to any existing tests. All tests pass with respect to the last baseline, sima0_07_000.

The dyn_{comp,coupling,grid} MODULES will only contain public interfaces
and variables. This is analogous to the header files (*.h) in C.

The dyn_{comp,coupling,grid}_impl SUBMODULES will contain the actual
implementations for the respective modules. This is analogous to the
source files (*.c) in C.

Step 1/2: Convert the dyn_{comp,coupling,grid} MODULES into
the dyn_{comp,coupling,grid}_impl SUBMODULES.
The dyn_{comp,coupling,grid} MODULES will only contain public interfaces
and variables. This is analogous to the header files (*.h) in C.

The dyn_{comp,coupling,grid}_impl SUBMODULES will contain the actual
implementations for the respective modules. This is analogous to the
source files (*.c) in C.

Step 2/2: Restore the dyn_{comp,coupling,grid} MODULES that only contain
public interfaces and variables.
Move subroutines as well as related variables to the modules that best reflect
their functional context. For example,

* `dyn_exchange_constituent_states` was moved to `dyn_coupling`.
* `dyn_inquire_mesh_dimensions` was moved to `dyn_grid`.
Step 1/2: Factor out easily compilable and testable procedures on CAM-SIMA
side into the separate module, `dyn_procedure`.
Step 2/2: Factor out easily compilable and testable procedures on MPAS
side into the separate module, `dyn_mpas_procedure`.
Put thermodynamics-related initialization code into separate subroutines
so that it does not bloat and pollute the scope of dyn_init.
@kuanchihwang
kuanchihwang force-pushed the staging/mpas-dycore-refactor branch from 0656bcc to ed50c4d Compare July 21, 2025 18:23
@kuanchihwang

Copy link
Copy Markdown
Collaborator Author

To reviewers, the lines of change might look terrifying, but all of them are just moving things around (i.e., conversion to Fortran submodules and splitting out procedures for unit testing). Absolutely no functionalities are being added or changed. There are no answer changes as confirmed by the passing regression tests. I have also structured the commits in a way that should be easier to follow one by one in order.

@kuanchihwang
kuanchihwang marked this pull request as ready for review July 21, 2025 18:34
@kuanchihwang
kuanchihwang requested review from mgduda and nusbaume July 21, 2025 18:36
nusbaume added a commit that referenced this pull request Aug 6, 2025
Tag name (required for release branches):
Originator(s): nusbaume

Description (include the issue title, and the keyword ['closes',
'fixes', 'resolves'] followed by the issue number):

Updated the CAM-SIMA external submodules to match cam6_4_106, along with
a newer CIME tag to enable dependency checking of Fortran submodules,
which is needed for CAM-SIMA PR #407

Also removed the "mct" submodule, as that was no longer being used by
CAM-SIMA.

Describe any changes made to build system:  N/A

Describe any changes made to the namelist:  N/A

List any changes to the defaults for the input datasets (e.g. boundary
datasets): N/A

List all files eliminated and why: 

D       libraries/mct
  - Remove unused git submodule.

List all files added and what they do:  N/A

List all existing files that have been modified, and describe the
changes:
(Helpful git command: `git diff --name-status
development...<your_branch_name>`)

M       .gitmodules
M       ccs_config
M       cime
M       components/cdeps
M       components/cice
M       components/cism
M       components/clm
M       components/cmeps
M       components/mosart
M       components/rtm
M       libraries/FMS
M       libraries/parallelio
M       tools/CUPiD
- Update git submodules to match/exceed the versions used in cam6_4_106

If there are new failures (compared to the
`test/existing-test-failures.txt` file),
have them OK'd by the gatekeeper, note them here, and add them to the
file.
If there are baseline differences, include the test and the reason for
the
diff. What is the nature of the change? Roundoff?

derecho/intel/aux_sima:  ALL PASS

derecho/gnu/aux_sima:   


SMS_Ln9.ne3pg3_ne3pg3_mg37.FCAM4.derecho_gnu.cam-outfrq_se_cslam_analy_ic
(Overall: DIFF)

SMS_Ln9.ne3pg3_ne3pg3_mg37.FCAM7.derecho_gnu.cam-outfrq_se_cslam_analy_ic
(Overall: DIFF)
SMS_Ln9.ne3pg3_ne3pg3_mg37.FHS94.derecho_gnu.cam-outfrq_se_cslam
(Overall: DIFF)
SMS_Ln9.ne3pg3_ne3pg3_mg37.FKESSLER.derecho_gnu.cam-outfrq_se_cslam
(Overall: DIFF)
SMS_Ln9.ne3pg3_ne3pg3_mg37.FTJ16.derecho_gnu.cam-outfrq_se_cslam
(Overall: DIFF)
 - Answer changes due to updated externals.

If this changes climate describe any run(s) done to evaluate the new
climate in enough detail that it(they) could be reproduced:

CAM-SIMA date used for the baseline comparison tests if different than
latest:

@nusbaume nusbaume left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I have some hopefully minor cleanup and comment/wording requests, but otherwise it all looks good to me. Thanks @kuanchihwang!

Comment thread src/dynamics/mpas/driver/dyn_mpas_procedure.F90 Outdated
Comment thread src/dynamics/mpas/driver/dyn_mpas_procedure.F90
Comment thread src/dynamics/mpas/dyn_comp_impl.F90 Outdated
Comment thread src/dynamics/mpas/dyn_comp.F90 Outdated
Comment thread src/dynamics/mpas/dyn_procedure.F90 Outdated
@kuanchihwang
kuanchihwang requested a review from nusbaume August 12, 2025 19:44

@nusbaume nusbaume left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Everything looks great to me now. Thanks again @kuanchihwang!

@mgduda mgduda left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Apologies for taking so long to provide a review!

@kuanchihwang
kuanchihwang merged commit 8a0689e into ESCOMP:development Aug 13, 2025
12 checks passed
@kuanchihwang
kuanchihwang deleted the staging/mpas-dycore-refactor branch August 13, 2025 23:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants