spectral_galerkin_heat.io_utils.xdmf_io ======================================= .. py:module:: spectral_galerkin_heat.io_utils.xdmf_io .. autoapi-nested-parse:: XDMF file loading and writing utilities. Provides functions to read simulation results from XDMF/HDF5 format and write error fields for visualization in ParaView. Uses xml.etree.ElementTree for proper XML generation instead of hardcoded string templates. Classes ------- .. autoapisummary:: spectral_galerkin_heat.io_utils.xdmf_io.StructuredField spectral_galerkin_heat.io_utils.xdmf_io.UnstructuredField spectral_galerkin_heat.io_utils.xdmf_io.XdmfBuilder Functions --------- .. autoapisummary:: spectral_galerkin_heat.io_utils.xdmf_io.load_xdmf spectral_galerkin_heat.io_utils.xdmf_io.write_structured_fields spectral_galerkin_heat.io_utils.xdmf_io.write_unstructured_fields Module Contents --------------- .. py:class:: StructuredField Temperature on a rectilinear (3DRectMesh / VXVYVZ) grid. .. py:class:: UnstructuredField Temperature at scattered FE nodes (Tetrahedron / XYZ). .. py:class:: XdmfBuilder(version = '2.0') Build XDMF XML documents for structured (3DRectMesh) and unstructured (Tetrahedron) grids, via xml.etree.ElementTree. .. py:method:: add_structured_grid(name, dims, h5_ref, coord_datasets = ('X', 'Y', 'Z'), attributes = None, time = None, step = None, precision = 4, parent = None) Add a structured 3DRectMesh grid to the XDMF document. :param name: Name of the grid (e.g., "Error", "Mesh") :type name: str :param dims: Grid dimensions in (nz, ny, nx) order :type dims: tuple of int :param h5_ref: HDF5 filename reference (basename only) :type h5_ref: str :param coord_datasets: Dataset names for X, Y, Z coordinates in HDF5 :type coord_datasets: tuple of str :param attributes: Mapping of attribute names to HDF5 dataset names :type attributes: dict, optional :param time: Time value for this grid :type time: float, optional :param step: Step number for this grid :type step: int, optional :param precision: Float precision (4 for float32, 8 for float64) :type precision: int :returns: The created Grid element :rtype: ET.Element .. py:method:: add_unstructured_grid(name, n_vertices, n_elements, h5_ref, topology_dataset = 'topology', geometry_dataset = 'geometry', topology_type = 'Tetrahedron', nodes_per_element = 4, attributes = None, time = None, geometry_precision = 8, attribute_precision = 4) Add an unstructured grid to the XDMF document. :param name: Name of the grid :type name: str :param n_vertices: Number of vertices in the mesh :type n_vertices: int :param n_elements: Number of elements (e.g., tetrahedra) :type n_elements: int :param h5_ref: HDF5 filename reference (basename only) :type h5_ref: str :param topology_dataset: HDF5 dataset name for connectivity :type topology_dataset: str :param geometry_dataset: HDF5 dataset name for vertex coordinates :type geometry_dataset: str :param topology_type: Element type (e.g., "Tetrahedron", "Triangle") :type topology_type: str :param nodes_per_element: Nodes per element (e.g., 4 for tetrahedra) :type nodes_per_element: int :param attributes: Mapping of attribute names to HDF5 dataset names :type attributes: dict, optional :param time: Time value for this grid :type time: float, optional :param geometry_precision: Float precision for geometry (default 8 = float64) :type geometry_precision: int :param attribute_precision: Float precision for attributes (default 4 = float32) :type attribute_precision: int :returns: The created Grid element :rtype: ET.Element .. py:method:: to_string(indent = True) Convert the XDMF document to a string. :param indent: Whether to pretty-print with indentation :type indent: bool :returns: The XDMF XML document as a string :rtype: str .. py:method:: write(filepath) Write the XDMF document to a file. :param filepath: Path to the output file :type filepath: Path .. py:function:: load_xdmf(xdmf_path, attr_name = None) Load the **last time step** from an XDMF file. :param xdmf_path: Path to the ``.xdmf`` or ``.xmf`` file. :type xdmf_path: Path :param attr_name: Name of the Attribute to load (e.g. ``"temperature"``). If *None*, the first ```` element found is used. Also used to select among multiple temporal collections. :type attr_name: str or None .. py:function:: write_structured_fields(output_base, fields, x, y, z, time = None, step = None) Write multiple structured fields to HDF5 + XDMF. :param output_base: Base path for output files (without extension) :type output_base: Path :param fields: Mapping of field names to 3D arrays of shape (nz, ny, nx) :type fields: Dict[str, np.ndarray] :param x: 1D coordinate arrays :type x: np.ndarray :param y: 1D coordinate arrays :type y: np.ndarray :param z: 1D coordinate arrays :type z: np.ndarray :param time: Time value :type time: float, optional :param step: Step number :type step: int, optional .. py:function:: write_unstructured_fields(output_base, fields, xyz, connectivity, time = None) Write multiple fields on an unstructured (tetrahedral) mesh to HDF5 + XDMF. :param output_base: Base path for output files (without extension) :type output_base: Path :param fields: Mapping of field names to 1D arrays of shape (n_vertices,) :type fields: Dict[str, np.ndarray] :param xyz: Vertex coordinates of shape (n_vertices, 3) :type xyz: np.ndarray :param connectivity: Element connectivity of shape (n_elements, 4) for tetrahedra :type connectivity: np.ndarray :param time: Time value :type time: float, optional