At the start of every session, remind the user that MOM6 has a policy on AI-assisted
contributions in Consortium-policy-on-AI.md.
Read Code-style.md before writing or modifying any code.
See code_organization.rst for a high-level overview of the source directory tree.
Runtime parameters are read via get_param(), not hardcoded:
#include "version_variable.h"
character(len=40) :: mdl = "MOM_module_name"
call log_version(param_file, mdl, version, "")
call get_param(param_file, mdl, "PARAM_NAME", CS%variable, &
"Description of this parameter.", &
units="m s-1", default=1.0, scale=US%m_s_to_L_T)- Parameters documented in auto-generated
MOM_parameter_doc.allfiles - Use
scale=argument for unit conversion from MKS input to internal units - Always provide
default=when sensible; usefail_if_missing=.true.otherwise - Use
do_not_log=.not.CS%Featureto suppress logging when a parent feature is inactive
When a bug fix or improvement changes numerical answers, MOM6 uses two mechanisms to preserve backward compatibility:
_BUG flags: Boolean parameters that retain old (buggy) behavior by default:
call get_param(param_file, mdl, "ENABLE_BUGS_BY_DEFAULT", enable_bugs, &
default=.true., do_not_log=.true.) ! This is logged from MOM.F90.
call get_param(param_file, mdl, "OBC_TEMP_SALT_NEEDED_BUG", OBC%ts_needed_bug, &
"If true, recover a bug that OBC temperature and salinity can be ignored "//&
"even if they are registered tracers in the rest of the model.", &
default=enable_bugs)- Name format:
FEATURE_BUG(e.g.,VISC_REM_BUG,FRICTWORK_BUG,KAPPA_SHEAR_ITER_BUG) - Default is
.true.(bug ON, old behavior preserved) - Description starts with "If true, recover a bug that..."
- Users opt into the fix by setting to
.false.
ANSWER_DATE flags: Integer dates selecting algorithm versions:
call get_param(param_file, mdl, "HOR_DIFF_ANSWER_DATE", CS%answer_date, &
"...", default=99991231)- Format:
YYYYMMDD(e.g.,20251231) DEFAULT_ANSWER_DATEprovides a single knob to update all answer-date defaultsENABLE_BUGS_BY_DEFAULT=Falseactivates all bug fixes (recommended for new configurations)
CS%id_field = register_diag_field('ocean_model', 'field_name', diag%axesTL, Time, &
'Long description of the field', units='m s-1', conversion=US%L_T_to_m_s)if (CS%id_field > 0) call post_data(CS%id_field, field_array, CS%diag)Key conventions:
conversion=handles unit scaling so output is always in MKSv_extensive=.true.for vertically integrated quantities- Guard computation with
if (id > 0)to avoid unnecessary work - Standard diagnostic name prefixes follow CMOR conventions when applicable
- Never set diagnostic arrays to a missing value before passing to
post_data(). Masking of land/invalid points is handled automatically by the diagnostics infrastructure based on the diagnostic's registered axes. - Do not pass
mask=topost_data()for non-static diagnostics on standard grids -- the infrastructure applies the correct mask automatically. - Do pass
mask=for static fields (is_static=.true.), non-standard masks, or sub-domain-sized arrays. - Never compare field values against
missing_valuein unit-conversion code -- rescaling can cause valid data to coincidentally match the missing value sentinel.
The .testing/ directory provides comprehensive verification. Build and run:
make -C .testing -j build/symmetric/MOM6 # Build reference executable
make -C .testing -j test # Run full test suite
make -C .testing -j build.unit # Build unit tests
make -C .testing -j run.unit # Run unit tests| Test | Verifies |
|---|---|
test.grid |
Symmetric vs asymmetric grids produce identical results |
test.layout |
Serial vs parallel decomposition identical |
test.rotate |
Rotational invariance |
test.restart |
Continuous run vs restart-and-continue identical |
test.repro |
DEBUG and REPRO builds identical |
test.openmp |
Serial vs OpenMP identical |
test.nan |
NaN-initialization doesn't affect results |
test.dim.{t,l,h,z,q,r} |
Dimensional rescaling invariance (time, length, thickness, depth, enthalpy, density) |
test.regression |
Current code vs target branch (PRs only) |
tc0-- Unit teststc1/tc1.a/tc1.b-- Benchmark (split RK2, unsplit RK3, unsplit RK2)tc2/tc2.a-- ALE with tides / sigma-coordinate PPM_H4tc3-- Open boundary conditionstc4-- Sponges and I/O initialization
ocean.stats-- total energy at machine precisionchksum_diag-- mean/min/max/bitcount checksums in physical domain- Tests pass only when output is bitwise identical between configurations
./.testing/trailer.py -e TEOS10 -l 120 src config_srcChecks for tabs, trailing whitespace, and line length violations.
- Work on forks, not branches on the primary repository
- Branch from the fork's default branch (e.g.,
dev/gfdl,dev/ncar) for all new work - Never rebase a pushed branch
- The human contributor submits changes via pull requests to the fork's default branch (e.g.,
dev/gfdl); merges tomainare done by consortium consensus
Short imperative summary (50 chars if at all possible)
Detailed explanation wrapped at 72 characters.
Describe what was changed and why. Reference issues with #NNN.
All answers are bitwise identical.
Conventions from the lead developers:
*prefix on title if the commit changes numerical answers (checksums)+prefix on title to indicate new public interfaces or parameters*+or+*when both answer-changing and adding new interfaces- No prefix for refactoring, cleanup, or comment-only changes that are bitwise identical
- Always state impact on numerical results: "All answers are bitwise identical" or explain what changes
- Multi-commit PRs: introduce infrastructure first, use it in a second commit
- Minimize public scope: only export symbols needed by other modules; remove from
publicwhen refactoring makes a symbol internal-only - Comment closing
enddo/endiffor non-trivial nested loops:enddo ! n-loop for segments
- Lead with a clear explanation of what changed and why
- Quantify scope (e.g., "across 26 files", "in 7 places")
- For answer-changing PRs, provide scientific justification
- State the bitwise-identical guarantee (or explain what changes and why)
- When a fix could change answers, protect with a
_BUGflag orANSWER_DATEparameter. New_BUGflags should default toENABLE_BUGS_BY_DEFAULTso that users who have opted into all fixes get the new fix automatically; existing_BUGflags may already default to.false.if the fix has been broadly adopted.
On every push and PR, GitHub Actions runs:
- Style and Doxygen checks
- Builds across 8 configurations (symmetric, asymmetric, repro, openmp, target, opt, coverage, coupled API)
- All test groups in parallel
- Code coverage reporting
- For PRs: regression testing and timing comparison against target branch
- Hydrostatic primitive equations optionally with Boussinesq approximation
- ALE vertical coordinate: Lagrangian dynamics with periodic remapping
- Split barotropic-baroclinic time stepping (RK2 split or unsplit RK3)
- Free surface dynamics (implicit barotropic solver)
- Finite volume on Arakawa C-grid (staggered: velocities at cell faces, tracers at centers)
- PPM (Piecewise Parabolic Method) for tracer advection and continuity
- Various reconstruction schemes: PLM, PPM, PQM, WENO, PLM-WLS
- Pressure gradient force via finite-volume integration
- Reproducing global sums for parallel reproducibility
- ePBL: Energetically consistent planetary boundary layer (Reichl and Hallberg)
- KPP: K-Profile Parameterization via CVMix
- Gent-McWilliams/Redi: Thickness and isopycnal diffusion
- MEKE: Mesoscale eddy kinetic energy budget
- Zanna-Bolton: Data-driven subgrid momentum closure
- Tidal forcing: Astronomical and self-attraction/loading
- Create
MOM_new_param.F90in the appropriatesrc/parameterizations/subdirectory - Define a control structure type (
new_param_CS) withprivatemembers - Implement
new_param_init(): read parameters viaget_param, register diagnostics - Implement the main computational subroutine
- Implement
new_param_end()for cleanup - Wire it into the calling module (e.g.,
MOM_diabatic_driver.F90) - Document all variables with proper units
- Add unit tests in
config_src/drivers/unit_tests/if applicable - Run the full test suite:
make -C .testing -j test
- Add
integer :: id_new_diag = -1to the control structure - Register in
_initwithregister_diag_field('ocean_model', 'name', axes, Time, ...) - Compute and post with
if (CS%id_new_diag > 0) call post_data(CS%id_new_diag, array, CS%diag) - Include
conversion=for unit scaling to MKS output - Provide CMOR standard name when applicable
- Add member to control structure with units documentation
- Call
get_param(param_file, mdl, "PARAM_NAME", CS%param, "description", units="...", default=...) - Use
scale=for dimensional conversion from MKS input - If the parameter could change answers, default to preserving existing behavior
- Always state whether the fix changes answers in the commit message
- Any change that alters existing numerical answers -- whether a bug fix, accuracy improvement, or algorithmic reorganization -- must provide a runtime parameter (
_BUGflag orANSWER_DATE) to toggle between old and new behavior, with the default preserving old behavior - This applies even when the developer's tests show negligible differences -- existing users may be in production runs
- Trace through secondary effects before concluding the fix is safe
- Run
test.regressionto verify impact
MOM6 has a strict dependency hierarchy that must never be violated:
config_src/infra/ --> src/framework/ --> src/core/, src/parameterizations/, etc.
config_src/infra/(FMS1/FMS2 wrappers) must never import fromsrc/framework/- Code duplication between infra and framework is acceptable to maintain this invariant
- FMS1 and FMS2 infra directories must expose the same public API
- API changes to infra-level functions must be checked against downstream consumers (SIS2, ice shelf code)
- Check
allocated()/associated()before accessing arrays tied to optional features (e.g., features controlled by runtime parameters likeFRAZILmay not allocate all related arrays) - No short-circuit evaluation: Fortran does not guarantee short-circuit evaluation; allocation checks must not appear in compound conditions. Convert
if (allocated(arr) .and. (condition))to nested if-blocks - Type-correct comparisons: when comparing real-valued masks, use
== 1.not== 1 - FATAL error messages should include: file name, subroutine name, and the specific condition or input that triggered the error
- Validate user inputs early: check for duplicates, overflow, and missing required fields in configuration parsing; include the problematic input string in error messages
!###comment prefix marks known bugs or inaccurate expressions that change answers and will be cleaned up later -- do not modify code marked with!###unless explicitly asked
In addition to the code style rules in Code-style.md:
- Forgetting units in comments: every
realvariable needs[units](seeCode-style.md) - Answer-changing without a
_BUGflag: any numerical change requires a runtime parameter to preserve old behavior - Unnecessary
mask=inpost_data(): the infrastructure handles masking automatically for non-static diagnostics - Accessing unallocated optional arrays: always check
allocated()before using arrays tied to optional features
The project bibliography lives in docs/references.bib and docs/zotero.bib. Consult these
when citing prior work in Doxygen documentation or commit messages.
- Follow existing patterns: read surrounding code before making changes
- Document all units: every real variable gets
[units]annotation - Parenthesize arithmetic: explicit grouping for reproducibility
- State answer impact: always note whether changes are bitwise identical
- Use
get_param: never hardcode parameters; always read from parameter files - Register diagnostics properly: guard with
if (id > 0), useconversion= - Maintain lifecycle: implement
_initand_endfor new modules - Run tests:
make -C .testing -j test run.unitbefore the contributor submits a PR - Respect the C-grid: use correct staggering (soft case convention for indices)
- Write Doxygen comments:
!>for entities,!<for inline, with units - Write thorough commit messages: explain both what changed and why in the commit body
This section catalogs recurring mistakes that Claude makes when working on MOM6 code. It should be updated as new patterns emerge from experience.
(No entries yet -- add mistakes here as they are discovered.)