Ensure that discontinuous fields are correctly saved in the checkpoint_xdmf method.#327
Ensure that discontinuous fields are correctly saved in the checkpoint_xdmf method.#327gthyagi wants to merge 5 commits intounderworldcode:developmentfrom
Conversation
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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.
If not cell fields are found what does this return? Is it well handled?
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
julesghub
left a comment
There was a problem hiding this comment.
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.
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.
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.