Skip to content

Accurately-reversible PC2 homogeneous forcing option#406

Open
MichaelWhitall wants to merge 19 commits intoMetOffice:mainfrom
MichaelWhitall:pc2_homog_reversible
Open

Accurately-reversible PC2 homogeneous forcing option#406
MichaelWhitall wants to merge 19 commits intoMetOffice:mainfrom
MichaelWhitall:pc2_homog_reversible

Conversation

@MichaelWhitall
Copy link
Copy Markdown

@MichaelWhitall MichaelWhitall commented Mar 30, 2026

PR Summary

Sci/Tech Reviewer:
Code Reviewer: Benjamin Went (@MetBenjaminWent)

In the PC2 cloud-scheme, many processes which modify the grid-mean Relative Humidity alter the liquid cloud water content and fraction by assuming the process acts homogeneously over the grid-box, shifting the mean of the sub-grid moisture PDF without changing its shape. These increments to liquid-cloud water and fraction are calculated by the many calls to PC2 homogeneous forcing subroutines across the model. This calculation has to make some assumptions about the sub-grid moisture PDF, so-as to reconstruct it from only the prognosed grid-mean cloud water and fraction.

Under balanced forcings from different processes (e.g. resolved-scale uplift balanced by "compensating subsidence" from the convection scheme), where the grid-mean Relative Humidity is increased by one process but decreased by another with zero net change, the cloud amount ought to remain constant under the assumed homogeneous forcing. However, the time discretisation used in the existing homogeneous forcing calculations introduces numerical errors which cause the cloud amount to drift when it should be in balance.

We now introduce an accurately reversible time discretisation to eliminate spurious drift in cloud amount.

While we're here, this PR also tidies-up the rose meta-data for the cloud namelist, removing confusing UM-isms from the help text and consistently renaming multi-option switches without the preceding i_ that was used in the UM namelists.

Branch at vn3.1: vn3.1_pc2_homog_reversible

Test branch: pc2_homog_reversible_test

closes #247

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 **

* I have checked for compiler warnings output by each file I modified in the job.err file from the build_lfric_atm_azspice_gnu_full-debug-32bit compile in rose-stem. No warnings were found for the modified files.

** The check_cr_approved CI task clearly won't succeed until code review is approved.

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) NA

* I have switched the new functionality on in the existing comorph_dev rose-stem app for testing, so the rose-stem tests of this app fail the KGO checks by design. In addition, KGO-checks have failed for CCE-fast 64-bit compile lfric_atm global jobs. The equivalent jobs at 32-bit preserve KGO. The change in answers at 64-bit is presumably due to compiler optimisations harmlessly changing behaviour of the existing code around my modifications.

trac.log

Test Suite Results - lfric_apps - pc2_homog_reversible_test/run1

Suite Information

Item Value
Suite Name pc2_homog_reversible_test/run1
Suite User michael.whitall
Workflow Start 2026-04-02T09:21:44
Groups Run all
Dependency Reference Main Like
casim MetOffice/casim@2026.03.2 True
jules MetOffice/jules@2026.03.2 True
lfric_apps MichaelWhitall/lfric_apps@vn3.1_port_pc2_doc False
lfric_core MetOffice/lfric_core@2026.03.2 True
moci MetOffice/moci@2026.03.2 True
SimSys_Scripts MetOffice/SimSys_Scripts@2026.03.2 True
socrates MetOffice/socrates@2026.03.2 True
socrates-spectral MetOffice/socrates-spectral@2026.03.2 True
ukca MetOffice/ukca@2026.03.2 True

Task Information

❌ failed tasks - 7
Task State
check_lfric_atm_nwp_comorph_dev-C12_ex1a_cce_fast-debug-32bit-crun1 failed
check_lfric_atm_nwp_gal9-C12_ex1a_cce_fast-debug-64bit-crun1 failed
check_lfric_atm_scm_comorph_dev_bomex-BiP2x2-50000x50000_azspice_gnu_fast-debug-32bit failed
check_lfric_atm_scm_comorph_dev_bomex-BiP2x2-50000x50000_ex1a_cce_fast-debug-32bit failed
check_lfric_atm_scm_comorph_dev_toga-BiP2x2-50000x50000_azspice_gnu_fast-debug-32bit failed
check_lfric_atm_scm_comorph_dev_toga-BiP2x2-50000x50000_ex1a_cce_fast-debug-32bit failed
check_lfric_coupled_nwp_gal9-C48_ex1a_cce_fast-debug-64bit failed
✅ succeeded tasks - 1503
⌛ waiting tasks - 2
Task State
housekeep_azspice waiting
housekeep_ex1a waiting

Note: I have intentionally left the update of KGO checksums out of the test branch, so that those tests which change KGO show-up above as failures in the check_lfric_atm tasks for clarity. These tasks would not fail on the dev branch as the KGO files have been updated there.

Security Considerations

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

Performance Impact

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

This PR adds new functionality under a switch / option; not expecting any noticeable impact on performance when the new functionality is off.

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

Documentation pending...

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 Mar 30, 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 Mar 30, 2026
@MichaelWhitall MichaelWhitall added KGO This PR contains changes to KGO macro This PR contains a metadata upgrade macro labels Mar 30, 2026
@MichaelWhitall MichaelWhitall added this to the Summer 2026 milestone Mar 30, 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 30, 2026
=Analytical solution
values='explicit','implicit','analytic'

[namelist:cloud=i_pc2_homog_g_method]
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.

I might suggest losing the "i_" from the start of this - we typically don't want to follow the UM in prefacing things with i_ and l_ anyway (their type is documented by the metadata), but that is especially so when this is no longer an integer, but is now an enumeration!

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.

Haha! Just because something was common-practice in the UM doesn't mean its automatically bad does it??

I've carried on using the preceding l_s and i_s in namelist switches (and I'm definitely not the only one!) because its quite handy to be able to tell at a glance (when looking at a list of namelist inputs) which ones are switches (l_ for on/off, i_ for multi-option), as opposed to model free parameters. I know that information is all in the meta-data, but having to go and look it up in there is much more time-consuming than using l_s and i_s. Also this naming convention keeps the switches grouped together in the alphabetically-ordered rose-meta.conf and namelist files, making them easier to search.

It doesn't matter that the multi-option switches aren't labeled using integers in the namelist anymore; the point is everyone knows that i_ denotes a multi-option switch (and actually under the hood they still are integers really!)

In my case there's also the challenge of keeping comorph configurations traceable between the UM and LFRic; keeping that traceability is much easier if the namelist inputs have the same name in both models. So keeping the i_ would make things easier?

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.

I think we did have guidance discouraging it in the early days, although as you point out, many have snuck through somehow! I don't really have an issue with the use of l_ for logicals or i_ for integers, but what I would like to avoid is the use of i_ for enumerations - they are different to integers (even if they use similar machinery under the hood). I see 2 problems with it:

  • it's assuming knowledge on behalf of users that i_ means multi-option switch, which deviates from common practice that i_ means integer
  • it confuses enumeration inputs with genuine integer inputs which use i_ (of which there are some), when these things would be better to clearly distinguish and separate

It should still be obvious from the variable name what it is - in this case pc2_homog_g_method identifies it as a switch (you wouldn't name anything else method), and just losing the i_ but keeping the name the same allows for easy cross-referencing with the UM, and is what we've done with other switches (e.g. pc2_init_logic).

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.

OK I can change i_pc2_... to pc2_... if you're sure that's worth spending the time on? If we're going to do that though, I should probably also change the names of the other existing i_ switches in the cloud-scheme namelist to make it all consistent? (easy enough to add stuff in the upgrade macro to change the names in all upgraded configs too of course). Are you happy for me to lump that in with this PR?

Cheers!
Mike

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.

I think just fix for your new switch here - I'm happy to pick up the rest on a PR I have which is adding quite a lot of new stuff to the namelist, given I'm the one being grumpy about it!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

macro approved

…moving UM-isms, including preceding 'i_'s on multi-option switches.
…moving UM-isms, including preceding 'i_'s on multi-option switches.
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 macro This PR contains a metadata upgrade macro

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Accurately-reversible PC2 homogeneous forcing option

4 participants