Quad Utilities: Enhanced Stability and New Documentation #1089
Quad Utilities: Enhanced Stability and New Documentation #1089
Conversation
Replaced Cramer's rule with Gaussian elimination with partial pivoting. This improves numerical stability especially for severely distored quadrilaterals.
| 'failed. It could be a singularity or a very tiny pivot' | ||
| write(string2, '(2(A, F10.4))') 'Obs location -> lon: ', lon, ', lat: ', lat | ||
| write(string3, '(2(A, 4F10.4))') 'Quad corners -> x: ', x_corners, ', y: ', y_corners | ||
| call error_handler(E_MSG, 'quad_bilinear_interp', string1, & |
There was a problem hiding this comment.
This message will only print on task 0, so if other tasks have failures you will not see the message. To have the message print on any task:
E_ALLMSG
There was a problem hiding this comment.
nice catch! I'll update this
| ! compute deter of m | ||
| !d = deter3(m) | ||
|
|
||
| ! Solve the matrix for b, c and d |
There was a problem hiding this comment.
@mgharamti Does this method need the do_rotate namelist option?
I ask because the code I think is doing a clockwise rotation (vs counterclockwise as the comment stays)
#833 (comment)
so if the rotation is not needed for stability with this new method, I think we should remove the rotation code.
There was a problem hiding this comment.
Helen, in my tests rotations didn't add anything. I find the new solver to be stable without the need for rotations. Would that apply to the CICE examples is the issue you shared? probably.
There was a problem hiding this comment.
The do_rotate true/false did not improve the out-of-bounds for the CICE
There was a problem hiding this comment.
hmm, ok. I don't know if users actively use this rotation option. For legacy reasons, we could keep it. It's defaulted to .false. anyways.
There was a problem hiding this comment.
ok I will put it on the todo list for the future to remove, and we leave it in for this pull request.
| @@ -0,0 +1,200 @@ | |||
| .. _quad_utils_mod: | |||
There was a problem hiding this comment.
Nice docs, I think it would be good to link to the quad_utils_mod from the "required model mod routines" doc
Definitely here:
https://docs.dart.ucar.edu/en/latest/guide/required-model-mod-routines.html#required-model-mod-routines
Maybe here?:
https://docs.dart.ucar.edu/en/latest/guide/advice-for-new-collaborators.html#interpolation
Something like:
"DART provides tools in the quad_utils_mod module for both grid search and interpolation on logically rectangular grids, that is, grids indexed like a regular (i,j) array but potentially curvilinear in physical space. These quad_utils_mod routines can be used within model_interpolate() to avoid having to implement interpolation routines from scratch"
There was a problem hiding this comment.
Good idea, will do.
| Mask Handling | ||
| ^^^^^^^^^^^^^ | ||
|
|
||
| An optional mask can be provided for fully irregular grids. If any of the four |
There was a problem hiding this comment.
This is just a curiosity question, why do only irregular grids except masks?
There was a problem hiding this comment.
Helen, good question. To me, I think of the regular grid's interpolation as index-based. We don't need mask to define geometry; the grid itself is valid everywhere. So, masking here is handled outside (e.g., point_on_land, quad_on_land, ...).
On the other hand, interpolation in the irregular grids is geometry-based (physical space) in which we need the 4 corners to fit a surface. If one corner is land (or invalid), this will corrupt the interpolation. In essense, if any of the corners is masked we do not interpolate.
We could add masks for regular grid, but it adds overhead. It's essential in the irregular case for correctness.
Added references to the ``quad_utils_mod`` in 2 pages: guide/ required-model-mod-routines and advice-for-new-collaborators Also, changed message reporting when quad_interp fails to be done across all tasks.
|
Question on the tests:
Are these test refering to
I'm not sure what the test is in the developer tests for quad_utils are testing, there's not a pass fail. So I just compared the .txt output from main and mgharamti:improve_quad_utils, (and plotted the results #1097) The results are different on the last digit between main and this branch for [hkershaw:work] (improve_quad_utils) > ./test_quad_irreg_interp | grep 'large interp residual' | wc -l [hkershaw:work] (main) > ./test_quad_irreg_interp | grep 'large interp residual' | wc -l gfortran --version |
|
Helen, I built my own distorted quad tests. I also ran the the ones in the developer tests but I didn't find them very informative. |
cool, I figured you had something cooler from the plots you showed at standup. |
Description:
This PR improves the numerical robustness of quadrilateral interpolation in
quad_utils_modand introduces new module documentation.For the interpolation code, Cramer's rule (for solving the 3×3 system in
quad_bilinear_interp) is now replaced with Gaussian Elimination with partial Pivoting (GEP). The new solver improves numerical stability, particularly for highly distorted or nearly degenerate quadrilateral cells. The computational cost remains constant (3×3 system) and negligible relative to the overall interpolation workflow.I also added a new rst documentation page for
quad_utils_mod. The documentation provides an overview of the interpolation procedure with detailed description of the supported grids, interpolation methods, and workflow.Fixes issue
Fixes issue #1081
Types of changes
Documentation changes needed?
Tests
I ran the developer tests for the
quad_utilsand also tested the new changes on small grids using different distorted quads. I got identical results between previous and refactored implementations for well-conditioned grids. For pathological quad configurations, the new solver demonstrates improved accuracy (orders of magnitude reduction in error).Checklist for merging
Checklist for release
Testing Datasets