Skip to content

Add new stretching transformation to mesh tools#270

Open
cjohnson-pi wants to merge 27 commits into
MetOffice:mainfrom
cjohnson-pi:stretching
Open

Add new stretching transformation to mesh tools#270
cjohnson-pi wants to merge 27 commits into
MetOffice:mainfrom
cjohnson-pi:stretching

Conversation

@cjohnson-pi

@cjohnson-pi cjohnson-pi commented Feb 10, 2026

Copy link
Copy Markdown

PR Summary

Sci/Tech Reviewer: James Kent (@jameskent-metoffice)
Code Reviewer: Ricky Wong (@mo-rickywong)

Documentation:
#270 (comment)

linked MetOffice/lfric_apps#344

Code Quality Checklist

  • I have performed a self-review of my own code
  • My code follows the project's style guidelines
  • Comments have been included that aid understanding and enhance the readability of the code
  • My changes generate no new warnings
  • All automated checks in the CI pipeline have completed successfully

Testing

  • I have tested this change locally, using the LFRic Core rose-stem suite
  • If required (e.g. API changes) I have also run the LFRic Apps test suite using this branch
  • If any tests fail (rose-stem or CI) the reason is understood and acceptable (e.g. kgo changes)
  • I have added tests to cover new functionality as appropriate (e.g. system tests, unit tests, etc.)
  • Any new tests have been assigned an appropriate amount of compute resource and have been allocated to an appropriate testing group (i.e. the developer tests are for jobs which use a small amount of compute resource and complete in a matter of minutes)

LFRic Apps Testing still to be completed.

trac.log

Test Suite Results - lfric_core - test_stretching/run11

Suite Information

Item Value
Suite Name test_stretching/run11
Suite User christine.johnson
Workflow Start 2026-03-13T14:48:49
Groups Run suite_default
Dependency Reference Main Like
lfric_core cjohnson-pi/lfric_core@stretching False
SimSys_Scripts MetOffice/SimSys_Scripts@2025.12.1 True

Task Information

✅ succeeded tasks - 390

Security Considerations

  • I have reviewed my changes for potential security issues
  • Sensitive data is properly handled (if applicable)
  • Authentication and authorisation are properly implemented (if applicable)

Performance Impact

  • Performance of the code has been considered and, if applicable, suitable performance measurements have been conducted

AI Assistance and Attribution

  • Some of the content of this change has been produced with the assistance of Generative AI tool name (e.g., Met Office Github Copilot Enterprise, Github Copilot Personal, ChatGPT GPT-4, etc) and I have followed the Simulation Systems AI policy (including attribution labels)

Documentation

  • Where appropriate I have updated documentation related to this change and confirmed that it builds correctly

PSyclone Approval

  • If you have edited any PSyclone-related code (e.g. PSyKAl-lite, Kernel interface, optimisation scripts, LFRic data structure code) then please contact the TCD Team

Sci/Tech Review

  • I understand this area of code and the changes being added
  • The proposed changes correspond to the pull request description
  • Documentation is sufficient (do documentation papers need updating)
  • Sufficient testing has been completed

(Please alert the code reviewer via a tag when you have approved the SR)

Code Review

  • All dependencies have been resolved
  • Related Issues have been properly linked and addressed
  • CLA compliance has been confirmed
  • Code quality standards have been met
  • Tests are adequate and have passed
  • Documentation is complete and accurate
  • Security considerations have been addressed
  • Performance impact is acceptable

@github-actions github-actions Bot added the cla-required The CLA has not yet been signed by the author of this PR - added by GA label Feb 10, 2026
@cjohnson-pi cjohnson-pi added the KGO This PR contains changes to KGO label Feb 18, 2026
@cjohnson-pi

Copy link
Copy Markdown
Author
poly_power

@cjohnson-pi

Copy link
Copy Markdown
Author

Document describing the new stretching function and its implementation stretch.pdf

@cjohnson-pi cjohnson-pi marked this pull request as ready for review March 4, 2026 10:46
@cjohnson-pi cjohnson-pi added this to the Summer 2026 milestone Mar 4, 2026
@github-actions github-actions Bot added cla-signed The CLA has been signed as part of this PR - added by GA and removed cla-required The CLA has not yet been signed by the author of this PR - added by GA labels Mar 5, 2026
@cjohnson-pi cjohnson-pi added the Linked Apps This PR is linked to a MetOffice/lfric_apps PR label Mar 6, 2026
@cjohnson-pi

cjohnson-pi commented Mar 6, 2026

Copy link
Copy Markdown
Author

The coordinates and the cell spacing for the new method (with various polynomial powers) and the old 'inflation' method that is currently used in the UM (in black).

with_inflation

So the new method gives similar answers to the UM inflation method.

@cjohnson-pi

Copy link
Copy Markdown
Author

The ratio of the cell spacing between neighbouring cells.

ratio

@cjohnson-pi

Copy link
Copy Markdown
Author

A non-symmetrical mesh, where the centre of the high resolution region is at (30,10).

mesh

Relevant Configuration is:
edge_cells_x = 24
edge_cells_y = 24
domain_centre = 30.0, 10.0
cell_size_inner = 0.0135,0.0135
cell_size_outer = 0.036,0.036
n_cells_outer_nsew = 1, 8, 5, 1
n_cells_stretch_nsew = 1, 1, 1, 1
poly_power = 3

@cjohnson-pi

Copy link
Copy Markdown
Author

Updated documentation (including non-symmetrical meshes) stretch.pdf

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR adds a new stretching transform based on polynomial stretching. I've worked through the document and I'm happy that this stretching is correct, and it has been coded correctly. There are a number of places where the "&" need to be aligned, and there is one erroneous print statement. When these are corrected I am happy this science review is approved.

Comment thread mesh_tools/source/support/gen_planar_mod.F90 Outdated
Comment thread mesh_tools/source/support/gen_planar_mod.F90
Comment thread mesh_tools/source/support/gen_planar_mod.F90
Comment thread mesh_tools/source/support/polynomial_stretching_mod.F90 Outdated
Comment thread mesh_tools/source/support/stretch_transform_mod.F90 Outdated
Comment thread mesh_tools/unit-test/calc_global_cell_map_mod_test.pf Outdated
Comment thread mesh_tools/unit-test/gen_lbc_mod_test.pf Outdated
Comment thread mesh_tools/unit-test/gen_planar_mod_test_cartesian.pf Outdated
@cjohnson-pi

Copy link
Copy Markdown
Author

Thank you for completing the science review. I have now completed the requested minor suggestions.

@mo-rickywong

Copy link
Copy Markdown
Contributor

Is the documentation, on the core repo. I suppose it should be for reference. Though do we have permission to do so?

@mo-rickywong Ricky Wong (mo-rickywong) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quite a lot of comments to address, mostly stemming from aligning with existing mesh_tools code and conventions on ordering.

Implementation approach is not made clear and prominent, leading to confusion when interpreting the code. There is mention in the pdf, though the code should be able to be followed it's own without the stretch.pdf.

Mesh tools sphinx documentation has not been updated. The PR documentation paper (pdf) on the approach is useful information though doesn't necessarily translate to understanding the implemented code. At present there is no details on stretching in the mesh documentation so thats not a major issue, Though the generators namelist options and usage has been completed and should be updated with changes in this PR.

I've not commented fully on polynominal stretching mod as I suspect it will change as requested changes filter down.

There are changes to unrelated test cases, though there is no mention of these on the PR. have the changes been confirmed to be negligible? checksums don't give any indication of the size of the change.

create_lbc_mesh = .true.
lbc_rim_depth = 6
lbc_parent_mesh = 'primary'
stretch_function = 'uniform'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stretch_function doesn't seem appropriate as uniform is one function that applies to the whole domain, whereas polynominal and inflation have different functions in different regions. Suggest stretch_profile is a better fit.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uniform, polynomial and inflation are all applied to the whole domain. I therefore suggest that keeping stretch_function is the appropriate name. Given input coordinates x, calculate new coordinates y=f(x) using the mathematical function f.

@mo-rickywong Ricky Wong (mo-rickywong) Jun 15, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not change the example namelist except to add required entries. The example file is to try and demo a working config (with new functionality if required/possible). These changes look like they are left-over from development for this change.

sort-key=Panel-A10
type=logical

[namelist:planar_mesh=stretch_function]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As before, suggest alternative name &stretch_profile

= interior, with a stretch region in between.
= Inflation: y_n = y_n-1 + dy * inflation ** stretch
= Polynomial: y = bx + ax^n where n is the power
!kind=default

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
!kind=default
help=The function applied is:
= * "Uniform"
= Uniform resolution mesh
= y = ax
=
= * "Inflation"
= Low resolution outer and a high resolution
= interior, with a stretch region in between.
= y_n = y_n-1 + dy * inflation ** stretch
=
= * "Polynominal"
= Low resolution outer and a high resolution
= interior, with a stretch region in between.
= y = bx + ax^n
= where n is the power.

Format the text for better clarity, Minor duplication to keep it clean. Something like above, please check layout in Cylc-gui

Comment on lines +606 to +609
help=[n_outer_n, n_outer_s, n_outer_e, n_outer_w]
=This is the number of cells in an outer region
=near to a domain edge for the North, South,
=East and West edges.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
help=[n_outer_n, n_outer_s, n_outer_e, n_outer_w]
=This is the number of cells in an outer region
=near to a domain edge for the North, South,
=East and West edges.
help=[n_outer_w, n_outer_s, n_outer_e, n_outer_n]
=
=Number of cells in the outer region adjacent
=to domain boundary. Values are ordered for
=domain boundaries as West, South, East and
=North.
=

Instructure arrays index locations follow the reference element, for Faces/edges it goes [W,S,E,N] so this should follow accordingly. I accept there is a conflict in naming here with the original transform namelist options, though the ordering of arrays really shouldn't be encoded into variable names. please bear this in mind. Could possibly rename these later or remove the ordering in the name if the inflation profile is deprecated.

@cjohnson-pi cjohnson-pi Jun 16, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surely the choice of index locations should be chosen to best help the user. The North and South boundaries will most likely have the same number of cells, as will the East and West. So grouping these together makes the most sense. And surely North always comes first. Furthermore, I think NSEW is the traditional ordering of compass directions. Therefore I strongly suggest we keep NSEW.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated the rest of the text following your suggestion, but keeping the NSEW.

Comment on lines +77 to +79
!> @param param_a Parameter a
!> @param param_b Parameter b
!> @param param_c Parameter c

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doxygen comments add no extra information

Suggested change
!> @param param_a Parameter a
!> @param param_b Parameter b
!> @param param_c Parameter c
!> @param param_a Parameter a, for Inner region function
!> @param param_b Parameter b, for Stretch region function
!> @param param_c Parameter c, for Outer region function

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is clear from the definitions in @details

Comment on lines +417 to +419
! This enables support meshes to be created with a variable
! resolution stretching function.
if (configuration%namelist_exists('stretch_transform')) then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still not sure this was the best way to do this, leaving it as it was there before, but may need to be restructured later on with some thought

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I expect more restructuring can be done later.

sort-key=Panel-A04
type=integer

[namelist:stretch_transform=n_cells_outer_nsew]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't follow rest of infrastructure ordering [W,S,E,N] for edges/faces, [SW,SE,NE,NW] for nodes.

@cjohnson-pi cjohnson-pi Jun 16, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As explained in another comment, I would prefer to leave as is.

sort-key=Panel-A04
type=integer

[namelist:stretch_transform=n_cells_stretch_nsew]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar comments as earlier with respect to the ordering encoded in the variable name

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to keep the NSEW ordering

Comment on lines +139 to +148
!> @brief Apply a polynomial stretching transformation to a given coordinate
!> @details In inner y = b x, in stretch y = a (x - xi) ^n + b x
!! and in outer y = yo + c x
!> @param param_a Parameter a
!> @param param_b Parameter b
!> @param param_c Parameter c
!> @param x_inner Unit mesh coordinate betwen inner and stretch
!> @param x_outer Unit mesh coordinate between stretch and outer
!> @param dx Unit mesh cell size
!> @param direction North-south or East-west

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dyoygen comments do not match, Similar comments to on doxygen comments in in polynominal parameters

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@cjohnson-pi

Copy link
Copy Markdown
Author

Is the documentation, on the core repo. I suppose it should be for reference. Though do we have permission to do so?

I'm not quite understanding this question. But regarding documentation, please let me know the location of any documentation that needs to be updated. I cannot find any Sphinx documentation. It may be that further documentation (in addition to the pdf that I have provided) needs to follow in a follow-on PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The CLA has been signed as part of this PR - added by GA KGO This PR contains changes to KGO Linked Apps This PR is linked to a MetOffice/lfric_apps PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants