-
Notifications
You must be signed in to change notification settings - Fork 0
Ensure that discontinuous fields are correctly saved in the checkpoint_xdmf method. #327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure that discontinuous fields are correctly saved in the checkpoint_xdmf method. #327
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR updates the checkpoint_xdmf method to distinguish between discontinuous (cell-based) and continuous (node-based) fields, ensuring correct file naming and attribute generation in the XDMF output. Key changes include:
- Adjusting the filename format for mesh-variable HDF5 files.
- Adding a helper function and conditional logic to select between cell_fields and vertex_fields based on the variable’s continuity.
- Adding a comprehensive test to verify that discontinuous fields are correctly saved and referenced.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/test_0005_check_xdmf.py | Introduces tests to check that XDMF files correctly reference HDF5 datasets for mesh fields. |
| src/underworld3/discretisation.py | Modifies checkpoint_xdmf to support discontinuous fields and updates file naming and data paths. |
| var_filename = filename + f".mesh.{var.clean_name}.{index:05}.h5" | ||
|
|
||
| def get_cell_field_shape(h5_filename): | ||
| with h5py.File(h5_filename, 'r') as f: |
Copilot
AI
Jun 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The helper function 'get_cell_field_shape' assumes that the expected dataset exists in the HDF5 file. Consider adding error handling to provide a clearer message if the dataset is missing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If not cell fields are found what does this return? Is it well handled?
Co-authored-by: Copilot <[email protected]>
julesghub
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good - just see how it handles if no cell_fields are defined.
| var_filename = filename + f".mesh.{var.clean_name}.{index:05}.h5" | ||
|
|
||
| def get_cell_field_shape(h5_filename): | ||
| with h5py.File(h5_filename, 'r') as f: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If not cell fields are found what does this return? Is it well handled?
|
Yes, it is handled properly. # Determine if data is stored on nodes (vertex_fields) or cells (cell_fields)
if not getattr(var, "continuous") or getattr(var, "degree")==0:
center = "Cell"
numItems = get_cell_field_shape(var_filename)
field_group = "cell_fields"
else:
center = "Node"
numItems = numVertices
field_group = "vertex_fields" |
| var_filename = filename + f"mesh.{var.clean_name}.{index:05}.h5" | ||
| var_filename = filename + f".mesh.{var.clean_name}.{index:05}.h5" | ||
|
|
||
| def get_cell_field_shape(h5_filename): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on second inspection I don't think this function should be called get..._shape. Consider get...._size.
Also can you not define this function in the for var in meshVars loop. This is not a good design. Move the function out of the loop. That will make it much less coupled to the loop.
|
check #328 |
The
checkpoint_xdmfmethod has been updated to correctly save discontinuous fields.