Skip to content

CoMorph convection scheme refactoring#292

Open
MichaelWhitall wants to merge 9 commits intoMetOffice:mainfrom
MichaelWhitall:comorph_refact
Open

CoMorph convection scheme refactoring#292
MichaelWhitall wants to merge 9 commits intoMetOffice:mainfrom
MichaelWhitall:comorph_refact

Conversation

@MichaelWhitall
Copy link

@MichaelWhitall MichaelWhitall commented Feb 25, 2026

PR Summary

Sci/Tech Reviewer: @AlisonStirling
Code Reviewer: @t00sa

closes #178

This aims to lodge the first tranch of changes to the CoMorph convection scheme code-base for CoMorph B. In preparation for numerous other tickets yet to come to lodge new science, this one just restructures various things to lay the ground work.

The key aim here is to lodge the numerous changes in code-structure from the comorph_dev branch, independent from the new science and the various changes / fixes which affect KGO. This will allow those subsequent things to be viewed as clean diffs against the trunk, making them easier to review and lodge in subsequent pull requests. While the changes to CoMorph for this pull request may look hideously large and widespread, the key thing is that they don't change answers, so they have identically preserved the existing science and technical implementation of CoMorph.

Please see linked issue #178 for full details.

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 Apps rose-stem suite
  • 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)

* All rose stem tests pass.

** This pull request imports the existing set of unit tests for CoMorph and some of its components, that were already present in the UM copy of CoMorph but hadn't been lodged in LFRic yet. These tests are best run simply at the command-line rather than integrated into rose-stem or CI.

trac.log

Test Suite Results - lfric_apps - comorph_refact/run1

Suite Information

Item Value
Suite Name comorph_refact/run1
Suite User michael.whitall
Workflow Start 2026-02-25T17:32:24
Groups Run developer', 'lfric_atm_nwp_azspice_extra', 'lfric_atm_nwp_ex1a_extra
Dependency Reference Main Like
casim MetOffice/casim@2025.12.1 True
jules MetOffice/jules@2025.12.1 True
lfric_apps MichaelWhitall/lfric_apps@comorph_refact False
lfric_core MetOffice/lfric_core@2025.12.1 True
moci MetOffice/moci@2025.12.1 True
SimSys_Scripts MetOffice/SimSys_Scripts@2025.12.1 True
socrates MetOffice/socrates@2025.12.1 True
socrates-spectral MetOffice/socrates-spectral@2025.12.1 True
ukca MetOffice/ukca@2025.12.1 True

Task Information

✅ succeeded tasks - 1195

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

@MichaelWhitall MichaelWhitall self-assigned this Feb 25, 2026
@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 25, 2026
Copy link

Choose a reason for hiding this comment

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

I'm not entirely sure I follow this - can you explain?

  • how does this not change answers in existing tests where cca/ccw are inputs to Comorph, or are they just not used if so?
  • I'm not sure you need to set them in comorph_kernel above n_conv_levs every timestep - they should just stay at their originally initialised value of 0 here
  • if Comorph sets every point below this, then I'm not sure this pre-initialisation is needed at all?
  • For the current implicit_bl placement things should be okay, as it's working on the output of the convection anyway. If this setting to 0 needs to happen in the implicit_bl before convection case, would it be better as part of my branch?

Copy link
Author

Choose a reason for hiding this comment

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

Hi thanks Ian, that was quick! (maybe I was meant to open this in "draft mode" so I could finish documenting it before reviews begin!) I'll try and scribble some more explanations:

  • CoMorph itself doesn't have any dependence on cca, ccw; it just sets them (on levels 1, n_conv_levels only).
  • The issue is that under the rearrangements, the cca, ccw passed into CoMorph are now just local arrays (cca_3d, ccw_3d) which have not been pre-populated with the input values of the prognostics (as cca_3d0, ccw_3d0 are). Subroutine comorph_conv_cloud_extras then sets cca_3d0, ccw_3d0 to the max out of their existing input values and the cca_3d, ccw_3d output by CoMorph. It does this on all levels, so the local arrays cca_3d, ccw_3d need to be set on all levels, but CoMorph doesn't set anything on the top level.
  • Under this arrangement, the prognostics need to be initialised to zero somewhere in the timestep, otherwise any conv cloud created by either comorph or forced cu will just hang around for the next timestep and forevermore!
  • Removing the initialisation to zero (currently in fast_physics_alg) from my branch will make conv cloud persist forever, changing answers, so needs to be in my branch.

The point of the rearrangement (making CoMorph set local copies instead of setting the prognostics directly) is to make CoMorph agnostic to whether another scheme has already added contributions to the cca, ccw prognostics before it. CoMorph should supplement them not overwrite them.

Cheers!
Mike

Copy link

Choose a reason for hiding this comment

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

Thanks - that makes sense. In which case, I wonder if it's worth wrapping this code inside an "if-comorph" test, so that it's not being done for the 6A scheme where it isn't really needed?

Copy link
Author

Choose a reason for hiding this comment

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

Yep no problem, I've put the cca, ccw initialisation in fast_physics_alg inside an if test on comorph as suggested: fast_physics_alg_mod.X90

@MichaelWhitall MichaelWhitall added this to the Summer 2026 milestone Feb 25, 2026

! Set convective cloud fields to zero above the top convection level
! (comorph only sets them up to n_conv_levels)
cca_3d(:,:,n_conv_levels+1:nlayers) = 0.0_r_um
Copy link

Choose a reason for hiding this comment

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

Is this really needed? As the copying back of cca/ccw only happens up to n_conv_levels, so I'm not really sure why we ever need to worry about what's happening above this here?

Copy link
Author

@MichaelWhitall MichaelWhitall Feb 26, 2026

Choose a reason for hiding this comment

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

I agree its not needed in terms of what gets copied into the prognostics, but the rigorous compile jobs in rose stem were failing due to referencing uninitialised values where cca_3d, ccw_3d, cca_bulk are used inside subroutine comorph_conv_cloud_extras. That's what prompted me to add this code. An alternative solution would be to change the k-loops inside comorph_conv_cloud_extras so they only go up to n_conv_levels instead of model_levels. Would that be preferable?

Copy link

Choose a reason for hiding this comment

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

That would seem sensible, then Comorph isn't really worried about what happens above n_conv_levels - this is just left alone?

Copy link
Author

Choose a reason for hiding this comment

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

Yep done (I misremembered, it was actually just the k-loop inside conv_update_precfrac.F90 that needed to be changed to only loop up to n_conv_levels). With that I've now deleted the initialisation of cca_3d, ccw_3d on the top model-level and the tests look OK:
2529025

Cheers!
Mike

@github-actions
Copy link

Hello @MichaelWhitall! 👋

Thank you for your contribution. Since this is your first time contributing to this repository, we ask that you sign our Contributor Licence Agreement (CLA).

📄 You can read the CLA here.

To agree to the CLA, please add your details (GitHub username, Real Name, Affiliation, and Date) to the CONTRIBUTORS.md file (create one, if required) in the development branch for this PR. After signing the CLA, you won't need to do this again for future PRs.

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

Labels

cla-required The CLA has not yet been signed by the author of this PR - added by GA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CoMorph convection scheme refactoring

2 participants