Skip to content

Fix ContinuousForcing field index mismatch in HydrostaticFreeSurfaceModel#5370

Merged
glwagner merged 2 commits intomainfrom
fix/hydrostatic-forcing-field-index-mismatch
Mar 4, 2026
Merged

Fix ContinuousForcing field index mismatch in HydrostaticFreeSurfaceModel#5370
glwagner merged 2 commits intomainfrom
fix/hydrostatic-forcing-field-index-mismatch

Conversation

@glwagner
Copy link
Copy Markdown
Member

@glwagner glwagner commented Mar 4, 2026

Summary

  • Fixes a bug where ContinuousForcing with field_dependencies (including Relaxation) silently read the wrong field in HydrostaticFreeSurfaceModel
  • The model_fields used during forcing materialization was built from hydrostatic_prognostic_fields (u, v, T, S, η) which excludes w, while the model_fields in tendency kernels uses hydrostatic_fields (u, v, w, T, S, η) which includes w
  • This shifted all tracer indices by 1 — e.g. a forcing with field_dependencies=:T would read w instead of T at runtime

Fix

One-line change: use hydrostatic_fields (which includes w) instead of prognostic_fields when building model_fields for forcing materialization, matching what the tendency kernels use.

Closes #5369

Test plan

🤖 Generated with Claude Code

…cFreeSurfaceModel

The model_fields NamedTuple used during forcing materialization was built
from hydrostatic_prognostic_fields (u, v, T, S, η) which excludes w,
while the model_fields in tendency kernels is built from hydrostatic_fields
(u, v, w, T, S, η) which includes w. This caused ContinuousForcing to
store wrong field_dependencies_indices — e.g. index 3 for T at
materialization time mapped to w at tendency computation time.

Any ContinuousForcing with field_dependencies (including Relaxation) on
HydrostaticFreeSurfaceModel was silently reading the wrong field.

Fixes #5369

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Tests that ContinuousForcing with field_dependencies and an equivalent
DiscreteForcing produce identical tendencies on HydrostaticFreeSurfaceModel.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@glwagner glwagner merged commit af754a9 into main Mar 4, 2026
73 of 77 checks passed
@glwagner glwagner deleted the fix/hydrostatic-forcing-field-index-mismatch branch March 4, 2026 23:29
briochemc added a commit to briochemc/Oceananigans.jl that referenced this pull request Mar 5, 2026
* glw/prescribed-free-surface:
  (0.105.3) Fix interpolation of terms in chain horizontal derivatives for MutableVerticalDiscretization (CliMA#5339)
  Fix ContinuousForcing field index mismatch in HydrostaticFreeSurfaceModel (CliMA#5370)
  Add dependency guardrail to Common Pitfalls (CliMA#5371)
  Fix typo SKR3 -> SRK3 (CliMA#5360)
  Add new reference to Zheng et al. (2025) in index (CliMA#5364)
  Add 9 missing papers to the reference list (CliMA#5363)
  Update papers section in index.md (CliMA#5362)
  Restructure AGENTS.md into multi-file agent configuration (CliMA#5350)
  (0.105.2) Fix `with_halo` for a `TripolarGrid` (CliMA#5353)
  (0.105.2) Fix and test checkpointing with open-domain simulations with a radiation `OpenBoundaryCondition` (CliMA#5347)
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.

Reformulating continuous forcing in discrete form giving unexpected results

1 participant