Skip to content

Lfric2lfric w2#390

Open
Juan Manuel Castillo Sanchez (ukmo-juan-castillo) wants to merge 36 commits intoMetOffice:mainfrom
ukmo-juan-castillo:lfric2lfric_W2
Open

Lfric2lfric w2#390
Juan Manuel Castillo Sanchez (ukmo-juan-castillo) wants to merge 36 commits intoMetOffice:mainfrom
ukmo-juan-castillo:lfric2lfric_W2

Conversation

@ukmo-juan-castillo
Copy link
Copy Markdown
Contributor

@ukmo-juan-castillo Juan Manuel Castillo Sanchez (ukmo-juan-castillo) commented Mar 23, 2026

PR Summary

Sci/Tech Reviewer: Ricky Wong (@mo-rickywong)
Code Reviewer: mo-marqh

This is relatively simple change to allow lfric2lfric to regrid W2 fields. The accepted procedure to deal with W2 is to convert them to a set of two W3 and one Wtheta fields, process these fields, and then regenerate back a W2 field with the resulting W3 and Wtheta fields.

This changes will make use of the existing subroutines converting W2 to W3,Wtheta fields, and back.

When we merged this code to the trunk, we discovered that the results were not bit-comparable. After some investigation, it was discovered that the subroutines converting from W2 to W3 and the other way round have implicit dependencies on base_mesh, which have to be removed. This will be done as part of this new PR.

The dependency is in the kernel compute_sample_u_ops_code, which is called by interp_w3wth_to_w2_alg.

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)

Test Suite Results - lfric_apps - lfric2lfric_W2/run1

Suite Information

Item Value
Suite Name lfric2lfric_W2/run1
Suite User juan.m.castillo
Workflow Start 2026-04-21T09:10:54
Groups Run all
Dependency Reference Main Like
casim MetOffice/casim@2026.03.2 True
jules MetOffice/jules@2026.03.2 True
lfric_apps ukmo-juan-castillo/lfric_apps@lfric2lfric_W2 False
lfric_core ukmo-juan-castillo/lfric_core@b4eab04 True
moci MetOffice/moci@2026.03.2 True
SimSys_Scripts MetOffice/SimSys_Scripts@4387949 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

✅ succeeded tasks - 1511

⌛ waiting tasks - 1
Task State
housekeep_azspice waiting

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

Copy link
Copy Markdown
Contributor

@DrTVockerodtMO DrTVockerodtMO left a comment

Choose a reason for hiding this comment

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

Thanks for the changes. One minor issue regarding consistent style with the rest of the adjoint tests.

@DanStoneMO
Copy link
Copy Markdown
Contributor

DanStoneMO commented Mar 31, 2026

I tried running this against LFRic-JEDI, and the JEDI interface build failed with:
Generation Error: error: expected '5' arguments for the call to kernel 'compute_sample_u_ops_kernel_type' from invoke 'invoke_5' in the algorithm layer but found '7'. Expected '5' standard arguments, '0' stencil arguments, '0' qr_arguments and '0' halo-depth arguments.

From: https://cylchub/services/cylc-review/view/daniel.stone?&suite=mob-develop-next-mobbalt-3&no_fuzzy_time=0&path=log/job/1/build_jelf__exab_gnu/01/job.out

Any ideas what could be causing this? I've not yet ruled out an error on my part, and I will update if that is the case.

@DanStoneMO
Copy link
Copy Markdown
Contributor

It looks like the build fail is due to the addition of two new arguments (geometry, topology) to the compute_sample_u_ops_kernel_type calls in interpolation_alg_mod and adj_interpolation_alg_mod.

@ukmo-juan-castillo
Copy link
Copy Markdown
Contributor Author

Juan Manuel Castillo Sanchez (ukmo-juan-castillo) commented Mar 31, 2026

It looks like the build fail is due to the addition of two new arguments (geometry, topology) to the compute_sample_u_ops_kernel_type calls in interpolation_alg_mod and adj_interpolation_alg_mod.

Exactly, that is why there is a lfric_core linked PR. This lfric_core PR is the one modifying the kernel that you observed failing.

@DanStoneMO
Copy link
Copy Markdown
Contributor

Ah, I see the branch for that now. Is there a PR for that one yet?

@ukmo-juan-castillo
Copy link
Copy Markdown
Contributor Author

Juan Manuel Castillo Sanchez (ukmo-juan-castillo) commented Mar 31, 2026

Ah, I see the branch for that now. Is there a PR for that one yet?

Yes, there is a link in the PR description: MetOffice/lfric_core#312. I added a link to the PR in the issue.

Copy link
Copy Markdown
Contributor

@DanStoneMO DanStoneMO left a comment

Choose a reason for hiding this comment

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

Alright given it another shot and JEDI is all good with this. No linked PR will be needed for lfric-jedi.

Copy link
Copy Markdown
Contributor

@DrTVockerodtMO DrTVockerodtMO left a comment

Choose a reason for hiding this comment

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

Thanks for making the changes, code owner review passed.

Comment on lines +178 to +187
if (fs == W2) then
field_src_ptr => u_in_w3_src
field_dst_ptr => u_in_w3_dst
call lfric2lfric_map_regrid(field_dst_ptr, field_src_ptr)
field_src_ptr => v_in_w3_src
field_dst_ptr => v_in_w3_dst
call lfric2lfric_map_regrid(field_dst_ptr, field_src_ptr)
field_src_ptr => w_in_wth_src
field_dst_ptr => w_in_wth_dst
call lfric2lfric_map_regrid(field_dst_ptr, field_src_ptr)
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.

What's the advantage of setting pointers and then calling lfric2lfric_map_regrid rather than just doing something like:

call lfric2lfric_map_regrid(u_in_w3_dst, u_in_w3_src)
call lfric2lfric_map_regrid(v_in_w3_dst, v_in_w3_src)
call lfric2lfric_map_regrid(w_in_w3_dst, w_in_w3_src)

Comment on lines +202 to +213
field_src_ptr => u_in_w3_src
field_dst_ptr => u_in_w3_dst
call lfric2lfric_oasis_regrid(modeldb, oasis_clock, &
field_dst_ptr, field_src_ptr)
field_src_ptr => v_in_w3_src
field_dst_ptr => v_in_w3_dst
call lfric2lfric_oasis_regrid(modeldb, oasis_clock, &
field_dst_ptr, field_src_ptr)
field_src_ptr => w_in_wth_src
field_dst_ptr => w_in_wth_dst
call lfric2lfric_oasis_regrid(modeldb, oasis_clock, &
field_dst_ptr, field_src_ptr)
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.

Same question here as above - what's the advantage of setting pointers here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Same question here as above - what's the advantage of setting pointers here?

The reason is that, when I tried to remove the pointers, I obtained segmentation faults. I investigated further and it turns out that one only needs to set the algorithm parameters to 'inout' rather than just 'out'. This is now fixed and I send it for a further review. I run all tests successfully and updated the trac.log.

@mo-lottieturner
Copy link
Copy Markdown
Contributor

Hi Juan - the linked section in the PR summary is meant for linked PRs - i.e. PRs in other repositories that need to go on together, rather than related PRs or PRs that need to go on in sequence. Can you move the #238 mention to the "is related to" section, and clarify whether lfric_core#312 is linked, part of a chain, or just related?

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.

All looks good, thanks for fixing the pointers :)

Copy link
Copy Markdown
Contributor

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

Choose a reason for hiding this comment

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

Kgos have changed, most likely due to the change in the geometry/topolgy enumerations used. However, other than a change in KGOs, no evidence is posted on the correctness of the output, Please post plots of the relevant fields that have changed (original and after change would be best).

Other than that, the code appears to fall in line with the PR description

Comment on lines +81 to +83
class(field_parent_type), pointer :: field => null()
type(field_type), pointer :: field_src => null()
type(field_type), pointer :: field_dst => null()
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.

Don't nullify on declaration, nullify variables after declaration section of code.

element_order_h, element_order_v, Wtheta)

! Get the geometry and topology of the destination mesh
mesh_dst => mesh_collection%get_mesh(trim(mesh_names(dst)))
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
mesh_dst => mesh_collection%get_mesh(trim(mesh_names(dst)))
mesh_dst => mesh_collection%get_mesh(trim(mesh_names(dst)))

Comment on lines +155 to +156
fs = field_src%which_function_space()
if (fs == W2) 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.

Suggested change
fs = field_src%which_function_space()
if (fs == W2) then
fs_id = field_src%which_function_space()
if (fs_id == W2) then

Use fs_id instead as fsis sometimes to refer to the function space object, strictly speaking W0,W1,W3 etc are just integers which identify a space configuration defined by the project.

select case (regrid_method)
case (regrid_method_map)
call lfric2lfric_map_regrid(field_dst, field_src)
if (fs == W2) 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.

Suggested change
if (fs == W2) then
if (fs_id == W2) then

type(field_type), target :: v_in_w3_src, v_in_w3_dst
type(field_type), target :: w_in_wth_src, w_in_wth_dst

integer(kind=i_def) :: fs
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
integer(kind=i_def) :: fs
integer(kind=i_def) :: fs_id

#ifdef MCT
call lfric2lfric_oasis_regrid(modeldb, oasis_clock, &
field_dst, field_src)
if (fs == W2) 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.

Suggested change
if (fs == W2) then
if (fs_id == W2) then

end select

! Rebuild the W2 fields from a set of W3 and Wtheta fields
if (fs == W2) 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.

Suggested change
if (fs == W2) then
if (fs_id == W2) then

Comment on lines +117 to +118
!> @param[in] geometry Mesh geometry
!> @param[in] topology Mesh topology
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
!> @param[in] geometry Mesh geometry
!> @param[in] topology Mesh topology
!> @param[in] geometry Mesh geometry enumeration value
!> @param[in] topology Mesh topology enumeration value

Comment on lines +128 to +129
!> @param[in] geometry Mesh geometry
!> @param[in] topology Mesh topology
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
!> @param[in] geometry Mesh geometry
!> @param[in] topology Mesh topology
!> @param[in] geometry Mesh geometry enumeration value
!> @param[in] topology Mesh topology enumeration value

@ukmo-juan-castillo
Copy link
Copy Markdown
Contributor Author

All suggested changes have been addressed, I am running again all the tests just in case and will update the trac.log once it is finished. KGOs changes respect to the trunk because before this PR the W2 fields were not processed in lfric2lfric (they just write zeros to the field output), and now they are. I am afraid I do not have any script to plot W2 fields, so if you could provide them (it could take me a good while to write one myself), I would be happy to generate W2 plots.

@mo-rickywong
Copy link
Copy Markdown
Contributor

All suggested changes have been addressed, I am running again all the tests just in case and will update the trac.log once it is finished. KGOs changes respect to the trunk because before this PR the W2 fields were not processed in lfric2lfric (they just write zeros to the field output), and now they are. I am afraid I do not have any script to plot W2 fields, so if you could provide them (it could take me a good while to write one myself), I would be happy to generate W2 plots.

I do not have any scripts to plot output, which is why I have requested it on this PR

@ukmo-juan-castillo
Copy link
Copy Markdown
Contributor Author

I have asked around and nobody has successfully plotted the output W2 field, I will need some time to write my own plotting scripts.

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.

lfric2lfric: processing W2 fields

7 participants