Skip to content

updated checkpoint_xdmf method save discontinuous fields properly #328

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

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions src/underworld3/discretisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2893,40 +2893,55 @@ def checkpoint_xdmf(
"""

## The mesh Var attributes

def get_cell_field_size(h5_filename, mesh_var):
with h5py.File(h5_filename, 'r') as f:
size = f[f'cell_fields/{mesh_var.clean_name}_{mesh_var.clean_name}'].shape[0]
return size

attributes = ""
for var in meshVars:
var_filename = filename + f"mesh.{var.clean_name}.{index:05}.h5"
var_filename = filename + f".mesh.{var.clean_name}.{index:05}.h5"
Copy link
Preview

Copilot AI Jun 27, 2025

Choose a reason for hiding this comment

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

[nitpick] Building filepaths via string concatenation can lead to errors (e.g. extra dots). Consider using os.path.join or at least a single f-string like f"{filename}.mesh.{var.clean_name}.{index:05}.h5" to improve readability and correctness.

Suggested change
var_filename = filename + f".mesh.{var.clean_name}.{index:05}.h5"
var_filename = f"{filename}.mesh.{var.clean_name}.{index:05}.h5"

Copilot uses AI. Check for mistakes.


if var.num_components == 1:
variable_type = "Scalar"
else:
variable_type = "Vector"
# We should add a tensor type here ...

# 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_size(var_filename, var)
field_group = "cell_fields"
else:
center = "Node"
numItems = numVertices
field_group = "vertex_fields"

var_attribute = f"""
<Attribute
Name="{var.clean_name}"
Type="{variable_type}"
Center="Node">
Center="{center}">
<DataItem ItemType="HyperSlab"
Dimensions="1 {numVertices} {var.num_components}"
Type="HyperSlab">
Dimensions="1 {numItems} {var.num_components}"
Type="HyperSlab">
<DataItem
Dimensions="3 3"
Format="XML">
0 0 0
1 1 1
1 {numVertices} {var.num_components}
1 {numItems} {var.num_components}
</DataItem>
<DataItem
DataType="Float" Precision="8"
Dimensions="1 {numVertices} {var.num_components}"
Dimensions="1 {numItems} {var.num_components}"
Format="HDF">
&{var.clean_name+"_Data"};:/vertex_fields/{var.clean_name+"_"+var.clean_name}
&{var.clean_name+"_Data"};:/{field_group}/{var.clean_name+"_"+var.clean_name}
</DataItem>
</DataItem>
</Attribute>
"""
"""
attributes += var_attribute

for var in swarmVars:
Expand Down