Add VTKHDF output support for all structured mesh types (#3620)#3877
Add VTKHDF output support for all structured mesh types (#3620)#3877Jarvis2001 wants to merge 6 commits intoopenmc-dev:developfrom
Conversation
391fb53 to
ede21b4
Compare
|
Thanks for the PR i am keen to see vtkhdf export as an option for these meshes, thanks for your efforts in adding this feature. My main question is about the code for sort each element's materials by material ID, is that something we need for the vtkhdf? It is a bit hard to review this PR as there are a lot of changes here that are unrelated to the objective of the PR, mainly formatting changes. While these are good it does swamp the actual code additions of the PR a bit. |
|
Yeah, the material volume sorting is unrelated to the VTKHDF changes. It was a material ID ordering mismatch; the |
Description
PR #3252 added
.vtkhdfoutput forUnstructuredMesh. This PR extends that support to all four structured mesh types —RegularMesh,RectilinearMesh,CylindricalMesh, andSphericalMesh— following the same pattern. The legacy ASCII.vtkpath is unchanged.Changes
StructuredMesh.write_data_to_vtkvolume_normalizationdefault changed fromTruetoNone, with format-appropriate fallback:Falsefor.vtkhdfandTruefor legacy ASCII.vtk. The previous hardcodedTruedefault would silently callself.volumeson 1D/2D meshes, which raisesRuntimeErrorsince volumes are only defined for 3D meshes.Fixed unconditional
.T.ravel()in the ASCII path for 3D datasets. The transpose is now conditional:RegularMeshandRectilinearMeshstore data in C (ijk) order that matches the VTK writer directly — no transpose is needed or correct.CylindricalMeshandSphericalMeshstill require the transpose to produce Fortran (kji) order expected by the curvilinear VTK writer. The same condition applies tovolumesduring normalization.RegularMesh._write_vtk_hdf5(new method)StructuredGridVTKHDF format with explicitPoints,Dimensions, andCellData, consistent with the existingUnstructuredMeshVTKHDF writer.Typeattribute written as a fixed-length ASCII HDF5 string viah5py.string_dtype, matching theUnstructuredMeshpattern. Without this, h5py stores a variable-length string that reads back asstrrather thanbytes, breaking== b"StructuredGrid"comparisons in VTK readers.Dimensionscarries onlyndimentries (not padded to 3), so 1D and 2D meshes write the correct number of dimensions.datasets=None, calls_reshape_vtk_datasetbefore validation, and validates both shape and element count.RectilinearMesh._write_vtk_hdf5,CylindricalMesh._write_vtk_hdf5,SphericalMesh._write_vtk_hdf5(new methods)RegularMesh._write_vtk_hdf5. Points are computed from the respective coordinate grids: Cartesian forRectilinearMesh, converted from(r, φ, z)forCylindricalMesh, and from(r, θ, φ)forSphericalMesh, each respecting the meshorigin.vtkRectilinearGridis not part of the VTKHDF spec, soRectilinearMeshusesStructuredGridas the closest equivalent.New tests (
test_mesh.py)test_write_vtkhdf_regular_mesh— checksStructuredGridtype,Points,Dimensions, andCellDatastructure.test_write_vtkhdf_rectilinear_mesh— checks file is created andCellDatais populated.test_write_vtkhdf_cylindrical_mesh— checks vertexDimensionsmatch(nr+1, nφ+1, nz+1).test_write_vtkhdf_spherical_mesh— checksPointsandCellDataare present.test_write_vtkhdf_volume_normalization— verifies both normalised and unnormalised output against known cell volumes.test_write_vtkhdf_multiple_datasets— verifies multiple named datasets are written with correct data ordering (data.T.ravel()).test_write_vtkhdf_invalid_data_shape— verifiesValueErroris raised for shape mismatches.test_write_vtkhdf_1d_mesh— verifies a 1DRegularMeshwrites successfully without hitting the 3D-only volumes guard.test_write_vtkhdf_2d_mesh— verifies a 2DRegularMeshwrites the correct number ofDimensionsentries.test_write_ascii_vtk_unchanged— round-trip test confirming the legacy.vtkpath is unaffected by these changes.Fixes #3620
Checklist