Usage Reference for pyvisfile.xdmf

This implementation targets XDMF3 and takes available fields directly from the code in the xdmf library. Additional documentation can be found online, but (at the time of this writing, December 2020) does not appear to be kept up to date.

Xdmf Tags

DataItem

class pyvisfile.xdmf.DataItemType(value)

Bases: enum.Enum

Data layout of an item.

Function = 3
HyperSlab = 2
Uniform = 1
class pyvisfile.xdmf.DataItemNumberType(value)

Bases: enum.Enum

Basic number types for an item.

Char = 1
Float = 5
Int = 3
UChar = 2
UInt = 4
static from_dtype(dtype: numpy.dtype)pyvisfile.xdmf.DataItemNumberType
class pyvisfile.xdmf.DataItemFormat(value)

Bases: enum.Enum

Format in which the item is stored.

Binary = 3
HDF = 2
TIFF = 4
XML = 1
class pyvisfile.xdmf.DataItemEndian(value)

Bases: enum.Enum

Endianess of the data stored in the item.

Big = 50
Little = 51
Native = 52
static from_system()pyvisfile.xdmf.DataItemEndian
class pyvisfile.xdmf.DataItem(*, dimensions: Optional[Tuple[int, ...]] = None, name: Optional[str] = None, itype: Optional[pyvisfile.xdmf.DataItemType] = <DataItemType.Uniform: 1>, ntype: Optional[pyvisfile.xdmf.DataItemNumberType] = <DataItemNumberType.Float: 5>, precision: Optional[int] = 4, reference: Optional[str] = None, function: Optional[str] = None, endian: Optional[pyvisfile.xdmf.DataItemEndian] = <DataItemEndian.Native: 52>, dformat: Optional[pyvisfile.xdmf.DataItemFormat] = <DataItemFormat.XML: 1>, parent: Optional[xml.etree.ElementTree.Element] = None, data: Optional[str] = None)

A DataItem describes the storage of actual values in an XDMF file. This can be inline ASCII data, the path to a binary file or a reference to another DataItem.

dimensions

Analogous to numpy.ndarray.shape.

__init__(*, dimensions: Optional[Tuple[int, ...]] = None, name: Optional[str] = None, itype: Optional[pyvisfile.xdmf.DataItemType] = <DataItemType.Uniform: 1>, ntype: Optional[pyvisfile.xdmf.DataItemNumberType] = <DataItemNumberType.Float: 5>, precision: Optional[int] = 4, reference: Optional[str] = None, function: Optional[str] = None, endian: Optional[pyvisfile.xdmf.DataItemEndian] = <DataItemEndian.Native: 52>, dformat: Optional[pyvisfile.xdmf.DataItemFormat] = <DataItemFormat.XML: 1>, parent: Optional[xml.etree.ElementTree.Element] = None, data: Optional[str] = None)
Parameters
  • parent – if provided, self is appended to the element.

  • reference – path to another DataItem. Use as_reference() to populate.

  • data – data contained inside the DataItem. This is usually a path to a binary file.

classmethod as_reference(reference_name: str, *, parent: Optional[xml.etree.ElementTree.Element] = None)pyvisfile.xdmf.DataItem
Parameters

reference_name – a name or an absolute reference to another DataItem. The name is just the Name attribute of the item, which is assumed to be in the top Domain. If another DataItem needs to be references, or there are multiple domains, use an absolute reference path, as defined in the XDMF docs.

Domain

class pyvisfile.xdmf.Domain(*, name: Optional[str] = None, parent: Optional[xml.etree.ElementTree.Element] = None)
__init__(*, name: Optional[str] = None, parent: Optional[xml.etree.ElementTree.Element] = None)
Parameters

parent – if provided, self is appended to the element.

Grid

class pyvisfile.xdmf.GridType(value)

Bases: enum.Enum

General structure of the connectivity.

Collection = 2
SubSet = 4
Tree = 3
Uniform = 1
class pyvisfile.xdmf.CollectionType(value)

Bases: enum.Enum

An enumeration.

Spatial = 1
Temporal = 2
class pyvisfile.xdmf.Grid(*, name: Optional[str] = None, gtype: pyvisfile.xdmf.GridType = <GridType.Uniform: 1>, ctype: Optional[pyvisfile.xdmf.CollectionType] = None, parent: Optional[xml.etree.ElementTree.Element] = None)
__init__(*, name: Optional[str] = None, gtype: pyvisfile.xdmf.GridType = <GridType.Uniform: 1>, ctype: Optional[pyvisfile.xdmf.CollectionType] = None, parent: Optional[xml.etree.ElementTree.Element] = None)
Parameters

parent – if provided, self is appended to the element.

Topology

class pyvisfile.xdmf.TopologyType(value)

Bases: enum.IntEnum

Element and mesh layouts.

CoRectMesh2D = 4354
CoRectMesh3D = 4354
Edge_3 = 34
Hexahedron = 9
Hexahedron_1000 = 57
Hexahedron_125 = 52
Hexahedron_1331 = 64
Hexahedron_20 = 48
Hexahedron_216 = 53
Hexahedron_24 = 49
Hexahedron_27 = 50
Hexahedron_343 = 54
Hexahedron_512 = 55
Hexahedron_64 = 51
Hexahedron_729 = 56
Hexahedron_Spectral_1000 = 71
Hexahedron_Spectral_125 = 66
Hexahedron_Spectral_1331 = 72
Hexahedron_Spectral_216 = 67
Hexahedron_Spectral_343 = 68
Hexahedron_Spectral_512 = 69
Hexahedron_Spectral_64 = 65
Hexahedron_Spectral_729 = 70
Mixed = 112
NoTopology = 0
Polygon = 3
Polyhedron = 16
Polyline = 2
Polyvertex = 1
Pyramid = 7
Pyramid_13 = 39
Quadrilateral = 5
Quadrilateral_8 = 37
RectMesh2D = 4353
RectMesh3D = 4353
SMesh2D = 4368
SMesh3D = 4368
Tetrahedron = 6
Tetrahedron_10 = 38
Triangle = 4
Triangle_6 = 36
Wedge = 8
Wedge_15 = 40
Wedge_18 = 41
class pyvisfile.xdmf.Topology(*, ttype: pyvisfile.xdmf.TopologyType, nodes_per_element: Optional[int] = None, number_of_elements: Optional[int] = None, dimensions: Optional[Tuple[int, ...]] = None, parent: Optional[xml.etree.ElementTree.Element] = None)
__init__(*, ttype: pyvisfile.xdmf.TopologyType, nodes_per_element: Optional[int] = None, number_of_elements: Optional[int] = None, dimensions: Optional[Tuple[int, ...]] = None, parent: Optional[xml.etree.ElementTree.Element] = None)
Parameters

parent – if provided, self is appended to the element.

Geometry

class pyvisfile.xdmf.GeometryType(value)

Bases: enum.Enum

Data layout of the node coordinates.

ORIGIN_DXDY = 5
ORIGIN_DXDYDZ = 6
VXVY = 3
VXVYVZ = 4
XY = 1
XYZ = 2
class pyvisfile.xdmf.Geometry(*, name: Optional[str] = None, gtype: pyvisfile.xdmf.GeometryType = <GeometryType.XYZ: 2>, parent: Optional[xml.etree.ElementTree.Element] = None)
__init__(*, name: Optional[str] = None, gtype: pyvisfile.xdmf.GeometryType = <GeometryType.XYZ: 2>, parent: Optional[xml.etree.ElementTree.Element] = None)
Parameters

parent – if provided, self is appended to the element.

Attribute

class pyvisfile.xdmf.AttributeType(value)

Bases: enum.Enum

Rank of the attribute stored on the mesh.

GlobalId = 205
Matrix = 203
Scalar = 200
Tensor = 202
Tensor6 = 204
Vector = 201
static from_shape(shape: Tuple[int, ...])pyvisfile.xdmf.AttributeType
class pyvisfile.xdmf.AttributeCenter(value)

Bases: enum.Enum

Center of the attribute stored on the mesh.

Cell = 101
Edge = 103
Face = 102
Grid = 100
Node = 104
Other = 105
class pyvisfile.xdmf.Attribute(*, name: Optional[str] = None, atype: pyvisfile.xdmf.AttributeType = <AttributeType.Scalar: 200>, acenter: pyvisfile.xdmf.AttributeCenter = <AttributeCenter.Node: 104>, parent: Optional[xml.etree.ElementTree.Element] = None)
__init__(*, name: Optional[str] = None, atype: pyvisfile.xdmf.AttributeType = <AttributeType.Scalar: 200>, acenter: pyvisfile.xdmf.AttributeCenter = <AttributeCenter.Node: 104>, parent: Optional[xml.etree.ElementTree.Element] = None)
Parameters

parent – if provided, self is appended to the element.

Time

class pyvisfile.xdmf.Time(*, value: str, parent: Optional[xml.etree.ElementTree.Element] = None)
__init__(*, value: str, parent: Optional[xml.etree.ElementTree.Element] = None)
Parameters

parent – if provided, self is appended to the element.

Information

class pyvisfile.xdmf.Information(*, name: str, value: str, parent: Optional[xml.etree.ElementTree.Element] = None)
__init__(*, name: str, value: str, parent: Optional[xml.etree.ElementTree.Element] = None)
Parameters

parent – if provided, self is appended to the element.

XInclude

class pyvisfile.xdmf.XInclude(*, href: Optional[str], xpointer: Optional[str] = None, parent: Optional[xml.etree.ElementTree.Element] = None)
__init__(*, href: Optional[str], xpointer: Optional[str] = None, parent: Optional[xml.etree.ElementTree.Element] = None)
Parameters
  • parent – if provided, self is appended to the element.

  • xpointer – path inside the file represented by href.

Writing

class pyvisfile.xdmf.DataArray(components: Tuple[pyvisfile.xdmf.DataItem, ...], *, name: Optional[str] = None, acenter: Optional[pyvisfile.xdmf.AttributeCenter] = None, atype: Optional[pyvisfile.xdmf.AttributeType] = None)

An array represented as a list of DataItems.

__init__(components: Tuple[pyvisfile.xdmf.DataItem, ...], *, name: Optional[str] = None, acenter: Optional[pyvisfile.xdmf.AttributeCenter] = None, atype: Optional[pyvisfile.xdmf.AttributeType] = None)
Parameters
  • components – a description of each component of an array.

  • name – name of the array. This name will be used if the array is added as an attribute, otherwise the names of the components are used.

as_data_item(*, parent: Optional[xml.etree.ElementTree.Element] = None)Tuple[pyvisfile.xdmf.DataItem, ...]

Finalize the DataArray and construct DataItems to be written to a file.

class pyvisfile.xdmf.NumpyDataArray(ary: numpy.ndarray, *, acenter: Optional[pyvisfile.xdmf.AttributeCenter] = None, name: Optional[str] = None)
__init__(ary: numpy.ndarray, *, acenter: Optional[pyvisfile.xdmf.AttributeCenter] = None, name: Optional[str] = None)
Parameters

ary – if this is an object array, each entry is considered a different component and will consist of a separate DataItem.

class pyvisfile.xdmf.XdmfGrid(root: pyvisfile.xdmf.Grid)
__init__(root: pyvisfile.xdmf.Grid)

Initialize self. See help(type(self)) for accurate signature.

add_attribute(ary: pyvisfile.xdmf.DataArray, *, join: bool = True)pyvisfile.xdmf.Attribute
Parameters
  • ary

  • join – If True and ary has multiple components, they are joined using an XDMF Function.

class pyvisfile.xdmf.XdmfUnstructuredGrid(points: pyvisfile.xdmf.DataArray, connectivity: pyvisfile.xdmf.DataArray, *, topology_type: Union[pyvisfile.xdmf.Topology, pyvisfile.xdmf.TopologyType], name: Optional[str] = None, geometry_type: Optional[pyvisfile.xdmf.GeometryType] = None)

Bases: pyvisfile.xdmf.XdmfGrid

__init__(points: pyvisfile.xdmf.DataArray, connectivity: pyvisfile.xdmf.DataArray, *, topology_type: Union[pyvisfile.xdmf.Topology, pyvisfile.xdmf.TopologyType], name: Optional[str] = None, geometry_type: Optional[pyvisfile.xdmf.GeometryType] = None)

Initialize self. See help(type(self)) for accurate signature.

class pyvisfile.xdmf.XdmfWriter(grids: Tuple[pyvisfile.xdmf.XdmfGrid, ...], *, arrays: Optional[Tuple[pyvisfile.xdmf.DataArray, ...]] = None, tags: Optional[Tuple[xml.etree.ElementTree.Element, ...]] = None)
__init__(grids: Tuple[pyvisfile.xdmf.XdmfGrid, ...], *, arrays: Optional[Tuple[pyvisfile.xdmf.DataArray, ...]] = None, tags: Optional[Tuple[xml.etree.ElementTree.Element, ...]] = None)
Parameters
  • grids – a tuple of grids to be added to the top Domain. Currently only a single domain is supported.

  • arrays – additional DataArrays to be added to the top Domain, as opposed to as attribute on the grids.

write(filename)

Write the the XDMF file.

write_pretty(filename)

Produces a nicer-looking XML file with clean indentation.