Skip to content

Reconstruct vectors correctly on planar meshes - #748

Merged
xylar merged 2 commits into
MPAS-Dev:masterfrom
xylar:fix-planar-velocity-reconstruction
Aug 20, 2026
Merged

Reconstruct vectors correctly on planar meshes #748
xylar merged 2 commits into
MPAS-Dev:masterfrom
xylar:fix-planar-velocity-reconstruction

Conversation

@xylar

@xylar xylar commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

reconstruct_variable() computed the Cartesian (X, Y, Z) components correctly on any mesh but then applied the spherical rotation to get the zonal and meridional components unconditionally, using latCell and lonCell. Planar meshes (for example from mpas_tools.planar_hex) have latCell = lonCell = 0, so the rotation collapsed to Zonal = Y and Meridional = Z, where Z is essentially zero. Planar zonal fields were really the y component and planar meridional fields were noise.

Branch on the on_a_sphere attribute of the mesh instead, and on a planar mesh take Zonal = X and Meridional = Y, which is what MPAS' own mpas_reconstruct_2d and mpas_reconstruct_1d do. Reading latCell and lonCell now happens only in the spherical branch, so a planar mesh that lacks them works too. A mesh with no on_a_sphere attribute is treated as spherical, preserving the previous behavior.

xylar and others added 2 commits August 20, 2026 06:13
This file predates the repo's ruff configuration, so pre-commit
reformats it wholesale as soon as it is touched.  Get that out of the
way in its own commit so the change that follows stays readable.

The only non-formatting change is an explicit `strict=False` on the
`zip()` in `main()`, which ruff's B905 requires and which preserves the
existing behavior.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
`reconstruct_variable()` computed the Cartesian (X, Y, Z) components
correctly on any mesh but then applied the spherical rotation to get the
zonal and meridional components unconditionally, using `latCell` and
`lonCell`.  Planar meshes (for example from `mpas_tools.planar_hex`) have
`latCell = lonCell = 0`, so the rotation collapsed to `Zonal = Y` and
`Meridional = Z`, where Z is essentially zero.  Planar zonal fields were
really the y component and planar meridional fields were noise.

Branch on the `on_a_sphere` attribute of the mesh instead, and on a
planar mesh take `Zonal = X` and `Meridional = Y`, which is what MPAS'
own `mpas_reconstruct_2d` and `mpas_reconstruct_1d` do.  Reading
`latCell` and `lonCell` now happens only in the spherical branch, so a
planar mesh that lacks them works too.  A mesh with no `on_a_sphere`
attribute is treated as spherical, preserving the previous behavior.

Reported for Polaris in E3SM-Project/polaris#714.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@xylar

xylar commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator Author

@mwarusz, could you have a look? I can't make you an official reviewer but that's just a formality.

@xylar

xylar commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator Author

Just worry about 30220e6. The other commit is just formatting.

@xylar

xylar commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator Author

Testing

I ran the Polaris Ekman column test using this fix and E3SM-Project/polaris#715.

Before this fix, I was seeing:

image

Now, I'm seeing:

Image

By eye, this looks identical to the MPAS-Ocean solution now (which uses its own internal vector reconstruction):

Image

@xylar

xylar commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator Author

@mwarusz, I'm going to go ahead with this fix. We can revisit if need be.

@xylar
xylar merged commit 5a4cdc7 into MPAS-Dev:master Aug 20, 2026
5 checks passed
@xylar
xylar deleted the fix-planar-velocity-reconstruction branch August 20, 2026 12:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant