Reconstruct vectors correctly on planar meshes - #748
Merged
Conversation
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>
Collaborator
Author
|
@mwarusz, could you have a look? I can't make you an official reviewer but that's just a formality. |
Collaborator
Author
|
Just worry about 30220e6. The other commit is just formatting. |
This was referenced Aug 20, 2026
Collaborator
Author
TestingI ran the Polaris Ekman column test using this fix and E3SM-Project/polaris#715. Before this fix, I was seeing:
Now, I'm seeing:
By eye, this looks identical to the MPAS-Ocean solution now (which uses its own internal vector reconstruction):
|
Collaborator
Author
|
@mwarusz, I'm going to go ahead with this fix. We can revisit if need be. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



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, usinglatCellandlonCell. Planar meshes (for example frommpas_tools.planar_hex) havelatCell = lonCell = 0, so the rotation collapsed toZonal = YandMeridional = 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_sphereattribute of the mesh instead, and on a planar mesh takeZonal = XandMeridional = Y, which is what MPAS' ownmpas_reconstruct_2dandmpas_reconstruct_1ddo. ReadinglatCellandlonCellnow happens only in the spherical branch, so a planar mesh that lacks them works too. A mesh with noon_a_sphereattribute is treated as spherical, preserving the previous behavior.