-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix planarIntersect
formula in MPAS mesh converter
#567
Conversation
@mwarusz, have you checked whether a similar fix is needed for spherical meshes? |
A question to @mwarusz and reviewers: is it not the case the correct edge location halfway between vertices (see #565 (comment)) rather than at this intersection? Perhaps the intersection formula might be correct but even if so, is it actually the case that we want the edge to be located halfway between cell centers along a great circle rather than at the intersection? |
Finally, currently the edge location for edges with only one neighboring cell are halfway between vertices:
I don't see a good alternative to this but wanted to bring it up. |
@xylar , The mesh specification is indeed a bit confusing regarding that.
Which is what me and @mwarusz have been suggesting. But later, in the first paragraph of Chapter 3 it also says:
Which suggests your point of view. But I take that that "nominally" in the text means it isn't truly there... I'll also note that my advisor published a paper in 2016 where, one of the things analyzed, is precisely the current edge positioning of MPAS (at intersections) vs a modified method that uses the edge midpoint. |
I haven't checked the formula, but it seems to be doing the right thing based on numerical testing. Note that the current behavior of the spherical version and the planar version on distorted meshes is opposite with respect to edge point placement.
I believe this recent paper https://www.sciencedirect.com/science/article/abs/pii/S146350032100161X |
@matthewhoffman and @trhille, MALI is likely to be the component most affected by this change, since you use irregular, planar meshes more often than the other components do. |
@mgduda, this is one you should definitely weigh in on if you have time. |
I tested this on our Compass ocean |
I will make an |
A package with this change can be installed with:
or in an existing environment with:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I agree with these changes based on @xylar's explanation and results.
More testingI ran @favba's mesh through the converter with this update. Before the fix, the edges and cells around the 13th vertex looked like this: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved based on my compass testing and plotting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For MPAS-Atmsophere, we use the TRiSK placement of edge locations (i.e., at the midpoint of triangle faces), consistent with the changes in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to accept the change on the planar mesh, and to confirm that for spherical meshes, the edge point falls at the intersection of the great circles between vertices and cell centers. I have confirmed this graphically for the MPAS-Ocean/SeaIce EC30to60E2r2 mesh, centered here for the Pacific 14.5˚N 166.4˚E on a 0.75˚ horizon:
Mesh lines on this plot are great circles at 1 NM resolution. Edge points as defined in mesh files are plotted as blue dots.
@proteanplanet, thank you so much, that's reassuring! |
Based on the discussion and inspection of the changes, this is convincing. @trhille and I will test this with a few of our mesh generation workflows before approving to ensure it doesn't generate any surprises for us. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ran a few of our compass mesh generation test cases for nonuniform meshes generated via JIGSAW using the rc mpas-tools package that @xylar conveniently set up.
As expected, all meshes generated without incident and look identical in Paraview, even with the vtk converter. At first I expected to see very slightly different edge locations, but I believe the vtk polygons don't actually use xEdge, yEdge, and those are the only fields modified by this PR. I did confirm that xEdge, yEdge differ slightly before and after this PR, and that xCell, yCell, xVertex, yVertex, dcEdge, and dvEdge all are identical before and after. Given that we don't use xEdge,yEdge anywhere in MALI (other than the mpas_li_velocity_simple.F module which hasn't been used in years), I don't anticipate this PR to actually impact simulations in any way.
So to summarize, no impact on MALI simulation, no impact on common visualization tools, and clearly a correct change - I'm happy to approve and let this move forward.
@matthewhoffman, that's wonderful! I expected MALI to be impacted. If not, I think we can merge this without concerns. @mwarusz, I really appreciate your diligent and thoughtful work on this. @favba, I deeply appreciate you bringing this up and engaging with us long enough for us to both appreciate that it was a real, significant problem and to find a solution we're happy with. |
I will make a new MPAS-Tools release soon with this fix. I just need to check if anything else should be included. |
The new formula is from: https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection#Given_two_points_on_each_line