Allow meshes to be renamed on load - #452
Ricky Wong (mo-rickywong) wants to merge 15 commits into
Conversation
|
Sci/Tech review: Thanks for making these changes to enable using meshes with the same name in lfric2lfric. I am generally happy with the implementation with only a couple of minor comments. But please could I encourage the developer to move any changes that are not essential to this work to a separate PR - it will make it a lot easier for reviewers to give a proper assessment of the work. |
|
All comments addressed, test-suite green, passing back to reviewer |
cjohnson-pi
left a comment
There was a problem hiding this comment.
Many thanks for your response to my previous review. I am happy with those changes. There are still just a couple of minor changes to be made, including reverting further changes that are not required for this ticket.
|
Back with cjohnson-pi |
cjohnson-pi
left a comment
There was a problem hiding this comment.
Thanks for completing the requested changes.
Matthew Hambley (MatthewHambley)
left a comment
There was a problem hiding this comment.
Generally looks okay. I've noted a few issues of code style. If you want to postpone them to a subsequent ticket, please raise the ticket and link to it on this one.
I wont insist on the string changes because I see string handling is shot throughout this change and modifying it would delay further. But consider them for future.
| 'Adding intergrid map "'// & | ||
| trim(source_mesh%get_mesh_name())//'"-->"'// & | ||
| trim(target_mesh%get_mesh_name())//'"' | ||
| call log_event( log_scratch_space, log_level_info ) |
There was a problem hiding this comment.
Is this an informative or a narrative message? Should it be at log level "info" or "debug"?
There was a problem hiding this comment.
Following my reasoning, I'd say debug.
| character(str_max_filename), intent(in) :: input_mesh_file | ||
| character(str_def), intent(in) :: mesh_names(:) | ||
| character(str_def), optional, intent(in) :: rename_to(:) | ||
|
|
||
| character(str_def), allocatable :: names(:) |
There was a problem hiding this comment.
Is there a reason for not using character(*) and therefore not having to worry about string length?
Are mesh_names and rename_to co-indexed arrays? If so, is there a way to do this so they aren't.
There was a problem hiding this comment.
Reason for not using character(*), --- habit. not sure about the co-indexed, Would seem ideally suited for duplicate mesh namelists i.e.
&Mesh
file_prefix=
file_mesh_name=
app_mesh_name=
prepartitioned=
/
with the instance_key_member being the app_mesh_name, but I think that is out of scope on this PR.
| if (size(rename_to) == size(mesh_names)) then | ||
| deallocate(names) | ||
| allocate(names, source=rename_to) | ||
| end if |
There was a problem hiding this comment.
If the arrays are not the same size, rule of least surprise suggests the user should at least be warned of this. It might even be an error condition. At the moment it looks like the rename just doesn't happen, silently.
Furthermore, why do the names have to be the same size?
There was a problem hiding this comment.
Good spot on the silent warning. Same size is co-indexing issue if mesh_names is array >1 how do you know which rename goes to which mesh unless you ensure the same size.
| type(global_mesh_type) :: global_mesh | ||
|
|
||
| if (.not. global_mesh_collection%check_for(mesh_name)) then | ||
| character(str_def) :: name |
There was a problem hiding this comment.
Given that incoming strings could be larger than str_def, you might be better off using character(:), allocatable :: name. Because character arrays are magic, you can still use name = rename_to and it will be automatically allocated to the correct size.
| !> @param[in] stencil_depths Depth of cells outside the base cell | ||
| !! of stencil for each mesh. | ||
| !> @param[in] partitioner_ptr Mesh partitioning strategy | ||
| !> @param[in] mapping_factors Partitioning constraints applied to each mesh. |
There was a problem hiding this comment.
More co-indexing of arrays?
There was a problem hiding this comment.
Yup, necessary evil for want factor out code that was committed in the wrong place to begin with. The whole lot needs rethinking, so this is more of a stepping stone
|
|
||
| end if ! test if the source has any targets listed | ||
|
|
||
| return |
There was a problem hiding this comment.
No need for return statements at the end of subroutines.
| !> @return origin_name Tag name of mesh that identifies it in the | ||
| !> UGRID file that it was read in from. | ||
| ! | ||
| function get_origin_name( self ) result ( origin_name ) |
There was a problem hiding this comment.
Is it worth saving 2 characters on get_original_name?
| !> @return origin_name Tag name of mesh that identifies it in the | ||
| !> UGRID file that it was read in from. | ||
| !> | ||
| function get_origin_name( self ) result ( origin_name ) |
There was a problem hiding this comment.
Two character saving again.
There was a problem hiding this comment.
Like to couch it as a 25% saving
| !> @return origin_name Tag name of mesh that identifies it in the | ||
| !> UGRID file that it was read in from. | ||
| !> | ||
| function get_origin_name( self ) result ( origin_name ) |
There was a problem hiding this comment.
Two character saving?
There was a problem hiding this comment.
Was more to mean get the name of the mesh in its origin file.
PR Summary
Sci/Tech Reviewer: cjohnson-pi
Code Reviewer: Matthew Hambley (@MatthewHambley)
Access to meshes in input files produced from the mesh generators should contain unique mesh names by design. The mesh names are used as a more user-friendly means to reference meshes in downstream applications. This however becomes an issue when applications such as lfric2lfric are required to read in multiple files produced for other applications. Applications which generate their input files may have used mesh(es) with identical names (e.g. dynamics, multigrid_l1, etc) in their individual tasks which produce output.
Adopting a practice of naming a mesh after the process/scheme that uses it, rather than a name that describes the mesh is not ideal. However, this practice has come about as a result of XIOS iodef.xml files which reference the specific mesh name, having the same mesh names allow for a template iodef.xml to be used. The alternative would significantly increase the number of iodef.xml files (with only a mesh name change between them). Having a constant mesh name, thus results in meshes from separate files having the same name.
This poses a problem for applications like lfric2lfric, where it needs to read different meshes from one or more files, were the meshes might have the same name in each of the files.
The simple solution here is to allow an application to read in the meshes (which have the same name) from individual files as separate instances and allow the application (lfric2lfric) to rename when the instance are created. This allows a method for an application to not violate the unique naming of objects restrictions in the mesh collections. This neatly allows lfric2lfric to use the meshes it requires (with the names they wish) without impacting the upstream applications that produced the input files.
Implementation
Allowing the meshes to be renamed before storing them in the collections is relatively straight forward. An optional argument on the method on the mesh constructors (global/local) allow the mesh objects to be renamed on creation before storing them in the collection. After that, the application should only worked with the "stored mesh names".
Complications
Mesh inter-grid maps: These where designed to be valid at the point of mesh generation, i.e. applications should only use maps between meshes sourced from the same file. In this case, the meshes are being renamed and potentially from separate files. The maps themselves are logged from mesh to mesh via their ids, which remain unique, so that shouldn't be an issue. The complication comes when identifying which maps from which files should be assigned to which mesh during setup.
The solution here is to log at the point of creation the original mesh name and file that the mesh came from. This means that during the intergrid map setup, maps are only read, created and attached if the meshes (using their original names) came from the same file. After the maps are read and attached, the rest of the code should proceed as normal.
Chi transforms (Out-of-Scope see Refactor code implementing initial chi transform with respect to North Pole and Schmit stretching #460): This does a lot of unnecessary things, however changes to make it more sensible change kgos. So it should be done as separate PR.
Mapping factors: Implementation of mapping factors is too low in the code, in addition it computes for every mesh in the mesh collection which is overkill. It should only need to do this for meshes that are required to be aligned. The routine was overloaded so that a mapping factor could be computed between a global_mesh and a single reference global mesh rather than the whole collection.
Potential downstream issues
Linked PRs
Code Quality Checklist
Testing
Test Suite Results - lfric_core - lfric2lfric_in_and_out/run1
Suite Information
Task Information
✅ succeeded tasks - 433
Security Considerations
Performance Impact
AI Assistance and Attribution
Documentation
PSyclone Approval
Sci/Tech Review
(Please alert the code reviewer via a tag when you have approved the SR)
Code Review