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)[source]#

Bases: Enum

Data layout of an item.

Function = 3#
HyperSlab = 2#
Uniform = 1#
class pyvisfile.xdmf.DataItemNumberType(value)[source]#

Bases: Enum

Basic number types for an item.

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

Bases: Enum

Format in which the item is stored.

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

Bases: Enum

Endianess of the data stored in the item.

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

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[DataItemType] = DataItemType.Uniform, ntype: Optional[DataItemNumberType] = DataItemNumberType.Float, precision: Optional[int] = 4, reference: Optional[str] = None, function: Optional[str] = None, endian: Optional[DataItemEndian] = DataItemEndian.Native, dformat: Optional[DataItemFormat] = DataItemFormat.XML, parent: Optional[Element] = None, data: Optional[str] = None)[source]#
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[Element] = None) DataItem[source]#
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[Element] = None)[source]#
__init__(*, name: Optional[str] = None, parent: Optional[Element] = None)[source]#
Parameters:

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

Grid#

class pyvisfile.xdmf.GridType(value)[source]#

Bases: Enum

General structure of the connectivity.

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

Bases: Enum

An enumeration.

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

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

Topology#

class pyvisfile.xdmf.TopologyType(value)[source]#

Bases: 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: TopologyType, nodes_per_element: Optional[int] = None, number_of_elements: Optional[int] = None, dimensions: Optional[Tuple[int, ...]] = None, parent: Optional[Element] = None)[source]#
__init__(*, ttype: TopologyType, nodes_per_element: Optional[int] = None, number_of_elements: Optional[int] = None, dimensions: Optional[Tuple[int, ...]] = None, parent: Optional[Element] = None)[source]#
Parameters:

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

Geometry#

class pyvisfile.xdmf.GeometryType(value)[source]#

Bases: 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: GeometryType = GeometryType.XYZ, parent: Optional[Element] = None)[source]#
__init__(*, name: Optional[str] = None, gtype: GeometryType = GeometryType.XYZ, parent: Optional[Element] = None)[source]#
Parameters:

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

Attribute#

class pyvisfile.xdmf.AttributeType(value)[source]#

Bases: 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, ...]) AttributeType[source]#
class pyvisfile.xdmf.AttributeCenter(value)[source]#

Bases: 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: AttributeType = AttributeType.Scalar, acenter: AttributeCenter = AttributeCenter.Node, parent: Optional[Element] = None)[source]#
__init__(*, name: Optional[str] = None, atype: AttributeType = AttributeType.Scalar, acenter: AttributeCenter = AttributeCenter.Node, parent: Optional[Element] = None)[source]#
Parameters:

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

Time#

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

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

Information#

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

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

XInclude#

class pyvisfile.xdmf.XInclude(*, href: Optional[str], xpointer: Optional[str] = None, parent: Optional[Element] = None)[source]#
__init__(*, href: Optional[str], xpointer: Optional[str] = None, parent: Optional[Element] = None)[source]#
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[DataItem, ...], *, name: Optional[str] = None, acenter: Optional[AttributeCenter] = None, atype: Optional[AttributeType] = None)[source]#

An array represented as a list of DataItems.

__init__(components: Tuple[DataItem, ...], *, name: Optional[str] = None, acenter: Optional[AttributeCenter] = None, atype: Optional[AttributeType] = None)[source]#
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[Element] = None) Tuple[DataItem, ...][source]#

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

class pyvisfile.xdmf.NumpyDataArray(ary: ndarray, *, acenter: Optional[AttributeCenter] = None, name: Optional[str] = None)[source]#
__init__(ary: ndarray, *, acenter: Optional[AttributeCenter] = None, name: Optional[str] = None)[source]#
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: Grid)[source]#
__init__(root: Grid)[source]#
add_attribute(ary: DataArray, *, join: bool = True) Attribute[source]#
Parameters:
  • ary

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

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

Bases: XdmfGrid

__init__(points: DataArray, connectivity: DataArray, *, topology_type: Union[Topology, TopologyType], name: Optional[str] = None, geometry_type: Optional[GeometryType] = None)[source]#
class pyvisfile.xdmf.XdmfWriter(grids: Tuple[XdmfGrid, ...], *, arrays: Optional[Tuple[DataArray, ...]] = None, tags: Optional[Tuple[Element, ...]] = None)[source]#
__init__(grids: Tuple[XdmfGrid, ...], *, arrays: Optional[Tuple[DataArray, ...]] = None, tags: Optional[Tuple[Element, ...]] = None)[source]#
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)[source]#

Write the the XDMF file.

write_pretty(filename)[source]#

Produces a nicer-looking XML file with clean indentation.