Skip to content

Fix show(field) + zipper BC validation for (distributed) tripolar grids#5489

Open
briochemc wants to merge 8 commits intomainfrom
bp-claude/fix-show-distributed-tripolar-field
Open

Fix show(field) + zipper BC validation for (distributed) tripolar grids#5489
briochemc wants to merge 8 commits intomainfrom
bp-claude/fix-show-distributed-tripolar-field

Conversation

@briochemc
Copy link
Copy Markdown
Collaborator

@briochemc briochemc commented Apr 12, 2026

Two fixes for distributed tripolar grids:

  1. show(field) crashes on 2×2 pencil decompositions. This is because show calls reduced fields (to show the min/max, with loc Nothing) and hits has_fold_line(::TY, ::Nothing) which does not exist. This PR adds the needed methods.

  2. Zipper north BC on tripolar grids are not enforced (Tripolar grids north BC validation #5503). A user-supplied non-zipper north BC was silently discarded (distributed) or silently used (serial, producing wrong halos). Now in this PR:

    • validate_boundary_conditions rejects any non-zipper/DCBC/nothing on a folded-y direction (new FoldedTopology union, mirrors the Periodic validation pattern).
    • Tripolar regularize_field_boundary_conditions only fills the default Zipper when the user omitted the north BC (DefaultBoundaryCondition placeholder); user-supplied BCs flow through untouched.
    • Dead sign(LX, LY) fallback removed; zipper_sign collapsed to a 2-method dispatch.
    • FoldedTopology split into SerialFoldedTopology / SlabFoldedTopology / PencilFoldedTopology / DistributedFoldedTopology for clarity.
    • includes tests exercising the new validation.

Closes #5503

🤖 Generated with help from Claude Code

`show` calls `maximum` which creates a reduced Field with (Nothing, Nothing, Nothing)
location. On pencil-decomposed (Rx > 1) tripolar grids, the Field constructor injected
a DistributedZipper north BC for this reduced field, then `communication_buffers` called
`has_fold_line(TY, Nothing)` which had no method.

Two fixes, matching the existing pattern from distributed LatitudeLongitudeGrid:
1. `default_auxiliary_bc` returns `nothing` for Nothing y-location on tripolar grids
2. The MPI tripolar Field constructor respects `nothing` north BCs instead of
   overriding them with a zipper

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@navidcy
Copy link
Copy Markdown
Member

navidcy commented Apr 12, 2026

Wait, can we partition tri-polar grids in x now?

@navidcy navidcy added user interface/experience 💻 distributed 🕸️ Our plan for total cluster domination labels Apr 12, 2026
@briochemc
Copy link
Copy Markdown
Collaborator Author

Wait, can we partition tri-polar grids in x now?

Yes but only for pencil partition, so 2x2 is ok but 2x1 isn't.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 12, 2026

Codecov Report

❌ Patch coverage is 82.53968% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.17%. Comparing base (e86351d) to head (54132d3).

Files with missing lines Patch % Lines
...alSphericalShellGrids/distributed_tripolar_grid.jl 76.92% 9 Missing ⚠️
...rc/BoundaryConditions/field_boundary_conditions.jl 75.00% 1 Missing ⚠️
...alSphericalShellGrids/tripolar_field_extensions.jl 83.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5489      +/-   ##
==========================================
+ Coverage   74.10%   74.17%   +0.06%     
==========================================
  Files         403      403              
  Lines       23288    23285       -3     
==========================================
+ Hits        17257    17271      +14     
+ Misses       6031     6014      -17     
Flag Coverage Δ
buildkite 68.69% <30.15%> (+0.02%) ⬆️
julia 68.69% <30.15%> (+0.02%) ⬆️
reactant_1 6.43% <0.00%> (+<0.01%) ⬆️
reactant_2 11.31% <0.00%> (+<0.01%) ⬆️
reactant_3 9.71% <0.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

if yrank == processor_size[2] - 1 && processor_size[1] == 1
if isnothing(global_bcs.north)
# Reduced fields (Nothing location) have no north boundary
north_bc = local_bcs.north
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this is what happens with the else at the end though

Can we make it clearer?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes probably. I think this is the minimal way of fixing it. I guess something clearner with dispatch would be better. I'll think about it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

OK I went down a rabbit hole a bit (#5503), but I think the latest commits fix this and make this a bit cleaner.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

PS: I updated the PR description to reflect that (see point 2. in the PR description)

briochemc and others added 3 commits April 14, 2026 15:37
…patch

Replace if/else branching with dispatch on y-topology (`OneDFoldTopology` /
`TwoDFoldTopology`) and incoming north BC. Extract `zipper_sign`, `with_north_bc`,
and a tripolar-specific `inject_halo_communication_boundary_conditions`.

Behavior is preserved across serial, slab, and pencil partitions (verified
with MWE — see #5503).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Validates that the north boundary of a (folded-y) tripolar grid is a
Zipper / distributed communication BC / nothing, both at Field construction
and at the top of tripolar regularize_field_boundary_conditions. Drops the
now-dead location-based `sign(LX, LY)` fallback and simplifies `zipper_sign`.

- Adds `FoldedTopology` union in Grids and the matching
  `validate_boundary_condition_topology` methods (mirroring the Periodic
  pattern), guarded on `side == :north`.
- Accepts `DefaultBoundaryCondition` placeholders at the regularize-entry
  validate so the model construction path isn't rejected before
  placeholders resolve.
- Passes `boundary_conditions = nothing` on the internal metric helper
  Fields inside the `TripolarGrid` constructor so their default BCs
  (NoFlux / Impenetrable on folded y) don't trip the new validator.
- Documents the sign convention on `UPivot/FPivotZipperBoundaryCondition`
  and adds a `!!! info "North boundary condition"` admonition to
  `TripolarGrid`'s docstring.
- Adds serial + distributed tests covering validation (TESTSET 4 in
  gadi_test_env, plus test/test_tripolar_grid.jl).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…h cleanup

Regularize no longer clobbers user-supplied north BCs. It only fills the
default Zipper when the north slot holds a `DefaultBoundaryCondition`
placeholder (the model-construction path). A user-supplied north BC flows
through untouched; invalid BCs are then caught downstream by Field's
`validate_boundary_condition_topology` (the Periodic-style check). This
removes the need to validate at regularize entry and to accept
`DefaultBoundaryCondition` in the FoldedTopology validator.

- Replace the regularize-entry validate call + unconditional override with
  7-arg `regularize_boundary_condition` overloads that pass `sign` through
  and dispatch on BC type × grid y-topology. `DefaultBC` + fold-north
  yields the right Zipper/DistributedZipper; user BCs pass through.
- Refactor the fold-topology unions into a four-way split that matches
  how each case is dispatched:
    SerialFoldedTopology       — serial tripolar
    SlabFoldedTopology         — distributed slab fold-north (Rx=1)
    PencilFoldedTopology       — distributed pencil fold-north (Rx>1)
    DistributedFoldedTopology  — Slab ∪ Pencil
    FoldedTopology             — Serial ∪ Distributed (used for north-BC validation)
  All live in `Grids/grid_utils.jl` and are exported. The previously
  duplicate `DistributedFoldTopology` in `field_boundary_conditions.jl`
  is deleted in favor of the shared `DistributedFoldedTopology`.
- Add short dispatch aliases (`SerialFTG`, `SlabFTG`, `PencilFTG`,
  `DistFTG`) to keep method signatures readable.
- Update `north_zipper_bc` and `distributed_zipper.jl` dispatch to use
  the renamed unions (`SlabFoldedTopology`, `DistributedPencilFoldedTopology`
  → `PencilFoldedTopology`).
- Update the test so it only exercises Field's validation path (Alt B
  design: regularize deliberately doesn't throw on bad input).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@briochemc briochemc changed the title Fix show(field) crash on 2x2 distributed tripolar grids Fix show(field) + zipper BC validation for (distributed) tripolar grids Apr 15, 2026
@briochemc briochemc requested a review from navidcy April 18, 2026 03:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

distributed 🕸️ Our plan for total cluster domination user interface/experience 💻

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tripolar grids north BC validation

2 participants