Implementation of conservative momentum diffusion and tensorial stress option - #656
Implementation of conservative momentum diffusion and tensorial stress option#656Shusuke Nishimoto (mo-snishimoto) wants to merge 6 commits into
Conversation
iboutle
left a comment
There was a problem hiding this comment.
Just one issue with the metadata
| =angles calculated from the orbital elements but retains the distance | ||
| =of the planet from the host star. | ||
| sort-key=Panel-A17 | ||
| sort-key=Panel-[namelist:mixing=fullstress] |
There was a problem hiding this comment.
Think something has gone wrong here - please revert this change!
Thank you so much for the check! (and apologize for the mistake.) |
Thomas Bendall (tommbendall)
left a comment
There was a problem hiding this comment.
Thanks for this. This is a correct implementation of a very fiddly and technical bit of science, and I really appreciate that you took on this important bit of scientific capability. It's impressive that you've managed to handle the stencils and W1/W2 DoFs correctly, and thank you for using the face selectors and putting the k-loops innermost to ensure that the kernels will run efficiently.
I have no major worries but do have a few requests or suggestions.
1. Documentation: Thank you for writing up your approach in a PDF (in the linked issue), which was very helpful for the review. Actually it would be really good to get this documentation in .rst format onto LFRic-Apps main itself in the documentation folder. I appreciate that there is currently very little documentation in there, and that I didn't do this for the scalar diffusion routines! If you like you could add the documentation in this Pull Request, or we could have a follow-up Pull Request which adds both documentation for both scalar and vector diffusion routines? Let me know which you'd rather...
2. Results: Thank you also for the results PDF in the linked issue, which were helpful in showing the magnitude of the changes and show that it doesn't break the existing behaviour. Do you have any plots from the lfric_atm tests which changed KGOs, just as a sanity check that there is also not much change to these tests?
3. Interpolation kernel: suggest removing the new Wtheta -> W3 interpolation kernel as there is a kernel that already does this (see my comments below)
4. Other comments: I have also added some suggestions to expand on the in-line or Doxygen comments, and some very fussy style suggestions (sorry)
There was a problem hiding this comment.
So there is actually already an LFRic-Core kernel that does this: sci_sample_wtheta_to_w3_kernel_mod.F90, https://github.com/MetOffice/lfric_core/blob/main/components/science/source/kernel/inter_function_space/sci_sample_wtheta_to_w3_kernel_mod.F90
That kernel doesn't use the height fields, but W3 DoFs lie exactly halfway between Wtheta DoFs so I think these are mathematically equivalent.
Can you call that kernel instead of introducing this new one?
| @@ -0,0 +1,547 @@ | |||
| !----------------------------------------------------------------------------- | |||
| ! (C) Crown copyright 2026 Met Office. All rights reserved. | |||
There was a problem hiding this comment.
| ! (C) Crown copyright 2026 Met Office. All rights reserved. | |
| ! (C) Crown copyright Met Office. All rights reserved. |
I think we actually now shouldn't include the year in the copyright statement for new files:
https://metoffice.github.io/lfric_core/how_to_contribute/coding_standards/fortran_coding_standards.html#copyright
| @@ -0,0 +1,309 @@ | |||
| !----------------------------------------------------------------------------- | |||
| ! (C) Crown copyright 2026 Met Office. All rights reserved. | |||
There was a problem hiding this comment.
| ! (C) Crown copyright 2026 Met Office. All rights reserved. | |
| ! (C) Crown copyright Met Office. All rights reserved. |
I think we actually now shouldn't include the year in the copyright statement for new files:
https://metoffice.github.io/lfric_core/how_to_contribute/coding_standards/fortran_coding_standards.html#copyright
| @@ -0,0 +1,302 @@ | |||
| !----------------------------------------------------------------------------- | |||
| ! (c) Crown copyright 2026 Met Office. All rights reserved. | |||
There was a problem hiding this comment.
| ! (c) Crown copyright 2026 Met Office. All rights reserved. | |
| ! (C) Crown copyright Met Office. All rights reserved. |
I think we actually now shouldn't include the year in the copyright statement for new files:
https://metoffice.github.io/lfric_core/how_to_contribute/coding_standards/fortran_coding_standards.html#copyright
| @@ -0,0 +1,239 @@ | |||
| !----------------------------------------------------------------------------- | |||
| ! (c) Crown copyright 2026 Met Office. All rights reserved. | |||
There was a problem hiding this comment.
| ! (c) Crown copyright 2026 Met Office. All rights reserved. | |
| ! (C) Crown copyright Met Office. All rights reserved. |
I think we actually now shouldn't include the year in the copyright statement for new files:
https://metoffice.github.io/lfric_core/how_to_contribute/coding_standards/fortran_coding_standards.html#copyright
| ! This invoke must be separated from the latter one. | ||
| ! because it makes wrong meta data of W2 space(ndf_w2, undf_w2, map_w2) | ||
| ! , passing W2H data as W2 data to a kernel. |
There was a problem hiding this comment.
| ! This invoke must be separated from the latter one. | |
| ! because it makes wrong meta data of W2 space(ndf_w2, undf_w2, map_w2) | |
| ! , passing W2H data as W2 data to a kernel. | |
| ! This invoke must be separated from the following one, to avoid | |
| ! confusing W2H and W2 metadata. |
I'm just suggesting tweaking the wording of this comment, feel free to ignore
| call invoke( & | ||
| setval_C(visc_m_w2h, 0.0_r_def), & | ||
| setval_C(rho_in_w2h, 0.0_r_def), & | ||
| interp_wtheta_to_w3_kernel_type( & |
There was a problem hiding this comment.
I think this could use the sample_wtheta_to_w3_kernel from sci_sample_wtheta_to_w3_kernel_mod which does the same thing
| type(arg_type) :: meta_args(12) = (/ & | ||
| arg_type(GH_FIELD, GH_REAL, GH_WRITE, W2), &! u_inc | ||
| arg_type(GH_FIELD, GH_REAL, GH_READ, W3, STENCIL(CROSS)), &! uflux_w3 | ||
| arg_type(GH_FIELD, GH_REAL, GH_READ, W3, STENCIL(CROSS)), &! vflux_w3 | ||
| arg_type(GH_FIELD, GH_REAL, GH_READ, W1), &! uflux_w1 | ||
| arg_type(GH_FIELD, GH_REAL, GH_READ, W1), &! vflux_w1 | ||
| arg_type(GH_FIELD, GH_REAL, GH_READ, ANY_SPACE_1), &! wflux_sh_w2h | ||
| arg_type(GH_FIELD, GH_REAL, GH_READ, W2), &! detj_at_w2 | ||
| arg_type(GH_FIELD, GH_REAL, GH_READ, Wtheta), &! rho_in_wth | ||
| arg_type(GH_FIELD, GH_REAL, GH_READ, W2H), &! rho_in_w2h | ||
| arg_type(GH_FIELD, GH_REAL, GH_READ, ANY_DISCONTINUOUS_SPACE_9,& | ||
| STENCIL(CROSS)), &! panel_id | ||
| arg_type(GH_FIELD, GH_INTEGER, GH_READ, ANY_DISCONTINUOUS_SPACE_3),&! face_selector_ew | ||
| arg_type(GH_FIELD, GH_INTEGER, GH_READ, ANY_DISCONTINUOUS_SPACE_3) &! face_selector_ns | ||
| /) |
There was a problem hiding this comment.
| type(arg_type) :: meta_args(12) = (/ & | |
| arg_type(GH_FIELD, GH_REAL, GH_WRITE, W2), &! u_inc | |
| arg_type(GH_FIELD, GH_REAL, GH_READ, W3, STENCIL(CROSS)), &! uflux_w3 | |
| arg_type(GH_FIELD, GH_REAL, GH_READ, W3, STENCIL(CROSS)), &! vflux_w3 | |
| arg_type(GH_FIELD, GH_REAL, GH_READ, W1), &! uflux_w1 | |
| arg_type(GH_FIELD, GH_REAL, GH_READ, W1), &! vflux_w1 | |
| arg_type(GH_FIELD, GH_REAL, GH_READ, ANY_SPACE_1), &! wflux_sh_w2h | |
| arg_type(GH_FIELD, GH_REAL, GH_READ, W2), &! detj_at_w2 | |
| arg_type(GH_FIELD, GH_REAL, GH_READ, Wtheta), &! rho_in_wth | |
| arg_type(GH_FIELD, GH_REAL, GH_READ, W2H), &! rho_in_w2h | |
| arg_type(GH_FIELD, GH_REAL, GH_READ, ANY_DISCONTINUOUS_SPACE_9,& | |
| STENCIL(CROSS)), &! panel_id | |
| arg_type(GH_FIELD, GH_INTEGER, GH_READ, ANY_DISCONTINUOUS_SPACE_3),&! face_selector_ew | |
| arg_type(GH_FIELD, GH_INTEGER, GH_READ, ANY_DISCONTINUOUS_SPACE_3) &! face_selector_ns | |
| /) | |
| type(arg_type) :: meta_args(12) = (/ & | |
| arg_type(GH_FIELD, GH_REAL, GH_WRITE, W2), & ! u_inc | |
| arg_type(GH_FIELD, GH_REAL, GH_READ, W3, STENCIL(CROSS)), & ! uflux_w3 | |
| arg_type(GH_FIELD, GH_REAL, GH_READ, W3, STENCIL(CROSS)), & ! vflux_w3 | |
| arg_type(GH_FIELD, GH_REAL, GH_READ, W1), & ! uflux_w1 | |
| arg_type(GH_FIELD, GH_REAL, GH_READ, W1), & ! vflux_w1 | |
| arg_type(GH_FIELD, GH_REAL, GH_READ, ANY_SPACE_1), & ! wflux_sh_w2h | |
| arg_type(GH_FIELD, GH_REAL, GH_READ, W2), & ! detj_at_w2 | |
| arg_type(GH_FIELD, GH_REAL, GH_READ, Wtheta), & ! rho_in_wth | |
| arg_type(GH_FIELD, GH_REAL, GH_READ, W2H), & ! rho_in_w2h | |
| arg_type(GH_FIELD, GH_REAL, GH_READ, ANY_DISCONTINUOUS_SPACE_9,& | |
| STENCIL(CROSS)), & ! panel_id | |
| arg_type(GH_FIELD, GH_INTEGER, GH_READ, ANY_DISCONTINUOUS_SPACE_3),& ! face_selector_ew | |
| arg_type(GH_FIELD, GH_INTEGER, GH_READ, ANY_DISCONTINUOUS_SPACE_3) & ! face_selector_ns | |
| /) |
Sorry, same fussy suggestion about spaces and comments
| use fs_continuity_mod, only : Wtheta, W3, W2, W2H, W1 | ||
| use kernel_mod, only : kernel_type | ||
| use sci_face_selector_support_mod, only : face_from_face_selector | ||
| use mixing_config_mod, only : fullstress |
There was a problem hiding this comment.
Same comment as for the previous kernel, could this be passed through as an argument? There is a desire for the CCD team to avoid importing any config variables into kernels
9087f80 to
d25b738
Compare
|
Hi Thomas Bendall (@tommbendall), I really appreciate the careful review. I fixed my branch and answer your comments as follows:
Many thanks |
Thomas Bendall (tommbendall)
left a comment
There was a problem hiding this comment.
Many thanks for making these changes and adding the extra plots to your results PDF.
We agreed a plan for documenting the diffusion code offline.
I just have a couple of extra suggestions, which are mainly to undo a mistake I made in a suggestion! Once that's done I'll be happy for this to proceed.
| !! \f] | ||
| !! | ||
| !! The terms proportional to the vertical gradient in the vertical | ||
| !! fluxes are ommited as they are calculated separetely |
There was a problem hiding this comment.
| !! fluxes are ommited as they are calculated separetely | |
| !! fluxes are omitted as they are calculated separately |
Typo!
| !! These fluxes for horizontal momentum are expressed as zonal and | ||
| !! meridional fluxes at both W3 and W1 points, creating a |
There was a problem hiding this comment.
| !! These fluxes for horizontal momentum are expressed as zonal and | |
| !! meridional fluxes at both W3 and W1 points, creating a | |
| !! These fluxes for horizontal momentum are expressed as contra- | |
| !! variant flux components at both W3 and W1 points, creating a |
Sorry I've realised that they technically may not be zonal and meridional components, since these are the contravariant component to the mesh
| !> @brief Calculates divergence of horizontal diffusion fluxes for momentum | ||
| !> @details The conservative form of the horizontal diffusion operator for | ||
| !! momentum involves taking the divergence of fluxes. | ||
| !! These fluxes are expressed as zonal and meridional fluxes at |
There was a problem hiding this comment.
| !! These fluxes are expressed as zonal and meridional fluxes at | |
| !! These fluxes are expressed as contravariant components at |
Sorry I've realised that they technically may not be zonal and meridional components, since these are the contravariant component to the mesh
|
Hi Thomas Bendall (@tommbendall) , thank you for checking my change carefully and pointing out my typo! I reflected your comment to my branch. |
PR Summary
Sci/Tech Reviewer: Thomas Bendall (@tommbendall)
Code Reviewer: allynt
Implements conservative form Smagorinsky diffusion operator for momentum and tensorial version of stress option.
Code Quality Checklist
Testing
trac.log
Test Suite Results - lfric_apps - test_fullstress/run2
Suite Information
Task Information
❌ failed tasks - 13
⌛ waiting tasks - 2
Security Considerations
Performance Impact
AI Assistance and Attribution
Documentation
PSyclone Approval
Sci/Tech Review
(Please alert the code reviewer via a tag when you have approved the SR)
Code Review