Skip to content

Refactor code implementing initial chi transform with respect to North Pole and Schmit stretching - #460

Open
Ricky Wong (mo-rickywong) wants to merge 10 commits into
MetOffice:mainfrom
mo-rickywong:RefactorChiTrans
Open

Refactor code implementing initial chi transform with respect to North Pole and Schmit stretching#460
Ricky Wong (mo-rickywong) wants to merge 10 commits into
MetOffice:mainfrom
mo-rickywong:RefactorChiTrans

Conversation

@mo-rickywong

@mo-rickywong Ricky Wong (mo-rickywong) commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

PR Summary

Sci/Tech Reviewer: Reviewer requested, awaiting confirmation
Code Reviewer: Mike Hobson (@mike-hobson)

While generating the chi fields from meshes, the routine init_chi_transform is called from init_fem. The implementation of this is rather complicated and has in the past resulted in changes to test-suite KGOs if altered. This PR refactors/simplifies the implementation.

Issues with the existing implementation.

The initial chi transform as it stands:

  • Passes in a mesh collection by argument (when it is available in module scope), only to extract the 1st mesh (which is only dependent on load order) to obtain the North Pole, Null Island, Equator latitude from the mesh. It doesn't allow for the case where there may be different meshes in the collection such as with the lfric2lfric application.
  • The variables in the module init_chi_transform_mod are uninitialized and require that init_chi_transform is called in order to prevent random data. The transform is only for certain meshes (spherical geometry), however, omitting the call to init_chi_transform when not required still resulted in some KGO changes in the test-suite tasks.
  • While the initialization is required only once, calls are made from init_fem for each mesh in the mesh_collection.

PR changes

  • Simplify the API, only the key reference points are sent to the routine, north_pole, null_island, equator_latitiude. The determination of what those values are should be made by the application, though for the purposes of this PR, that determination is still applied in init_fem.
  • Initialise (on declaration) and finalise the settings in init_chi_transform_mod so that they are for the default case, i.e. unrotated, unstretched mesh, to prevent random data.
  • Only require the init_chi_transform to be called once for spherical geometry meshes. Even then its only necessary if the mesh has been rotated or stretched. This removes the bulk of required calls to init_chi_transform in the unit-tests routines.

Out-of-Scope issue

The current change refactors and tidies the existing code. Though there is still the issue of assuming that all spherical meshes in an application will use the pole/stretching criteria held in the module sci_chi_transforms_mod. Specifically in the general case with lfric2lfric where source/destination meshes could potentially have different pole location/stretching criteria.

Linked PRs

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)

trac.log

Test Suite Results - lfric_core - RefactorChiTrans/run1

Suite Information

Item Value
Suite Name RefactorChiTrans/run1
Suite User ricky.wong
Workflow Start 2026-09-03T07:04:11
Groups Run developer
Dependency Reference Main Like
lfric_core mo-rickywong/lfric_core@RefactorChiTrans False
SimSys_Scripts MetOffice/SimSys_Scripts@cab3315 True

Task Information

✅ succeeded tasks - 433

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 HPC Optimisation 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-modified The CLA has been modified as part of this PR - added by GA label Sep 2, 2026
@mo-rickywong Ricky Wong (mo-rickywong) changed the title Refactor chi trans Refactor code implementing initial chi transform wrt North Pole and Schmit streching Sep 2, 2026
@mo-rickywong Ricky Wong (mo-rickywong) changed the title Refactor code implementing initial chi transform wrt North Pole and Schmit streching Refactor code implementing initial chi transform with respect to North Pole and Schmit stretching Sep 2, 2026
@github-actions github-actions Bot removed the cla-modified The CLA has been modified as part of this PR - added by GA label Sep 3, 2026
@mo-rickywong Ricky Wong (mo-rickywong) added this to the Autumn 2026 milestone Sep 3, 2026
@mo-rickywong
Ricky Wong (mo-rickywong) marked this pull request as ready for review September 3, 2026 11:15
@mo-rickywong
Ricky Wong (mo-rickywong) requested review from Mike Hobson (mike-hobson) and removed request for a team September 3, 2026 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants