MPI Support in Py2VTK

Py2VTK has functions to easily create VTK files in a distributed context using mpi4py. Those functions are available under the py2vtk.mpi submodule.

py2vtk.mpi.api.parallelImageToVTK(path, starts, ends=None, dimension=None, origin=(0.0, 0.0, 0.0), spacing=(1.0, 1.0, 1.0), cellData=None, pointData=None, fieldData=None, comm=<mpi4py.MPI.Intracomm object>, ghostlevel=0, direct_format='ascii', appended_format='raw', compression=False, compressor='zlib', append=True)

Export one vtk image data per rank and one vtk parallel image data on rank 0.

Parameters

pathstr

name of the file without extension or rank specific numbering where data should be saved. Each rank will produce a file named filename + f".{rank}.vti". Rank 0 will also produce a parallel VTI file named filename.pvti.

startsdict or tuple

If starts is a dictionnary, it should map each rank to its start. If starts is a tuple, then it is assumed to be the start of the current rank.

endsdict or tuple, optional

If ends is a dictionnary, it should map each rank to its end. If ends is a tuple, then it is assumed to be the end of the current rank. If ends is None it is deduced from the data.

dimensiontuple or None, optional

dimension of the image.

origintuple, optional

grid origin. The default is (0.0, 0.0, 0.0).

spacingtuple, optional

grid spacing. The default is (1.0, 1.0, 1.0).

cellDatadict, optional

dictionary with variables associated to each cell. Keys should be the names of the variable stored in each array. Values should be arrays or 3-tuple of arrays. All arrays must have the same number of elements.

pointDatadict, optional

dictionary with variables associated to each vertex. Keys should be the names of the variable stored in each array. Values should be arrays or 3-tuple of arrays. All arrays must have the same number of elements.

fieldDatadict, optional

dictionary with variables associated with the field. Keys should be the names of the variable stored in each array. Values should be arrays or 3-tuple of arrays.

commMPI.Intracomm, default=MPI.COMM_WORLD

Communicator.

ghotslevelint default=0,

Number of cells which are shared between neighbouring files.

direct_formatstr in {‘ascii’, ‘binary’}, default=’ascii’

how the data that isn’t appended will be encoded. If 'ascii', the data will be human readable, if 'binary' it will use base 64 and can be compressed. See compressor argument.

appended_formatstr in {‘raw’, ‘binary’}, default=’raw’

how that appended data will be encoded. If 'raw', raw binary data will be written to file. This is space efficient and supported by vtk but isn’t valid XML. If 'binary', data will be encoded using base64 and can be compressed. See compressor argument.

compressionBool or int, default=False

compression level of the binary data. Can be True, False or any integer in [-1, 9] included. If True, compression will be set to -1 and use the default value of the compressor.

compressor: str in {‘zlib’, ‘lzma’}, default=’zlib’

compression library to use for the binary data.

appendbool, default=True

Whether to write the data in appended mode or not.

py2vtk.mpi.api.parallelRectilinearGridToVTK(path, x, y, z, starts, ends=None, dimension=None, cellData=None, pointData=None, fieldData=None, comm=<mpi4py.MPI.Intracomm object>, ghostlevel=0, direct_format='ascii', appended_format='raw', compression=False, compressor='zlib', append=True)

Export one vtk rectilinear grid per rank and one vtk parallel rectilinear grid on rank 0.

Parameters

pathstr

name of the file without extension or rank specific numbering where data should be saved. Each rank will produce a file named filename + f".{rank}.vtr". Rank 0 will also produce a parallel VTI file named filename.pvtr.

xarray-like

x coordinates of the points..

yarray-like

y coordinates of the points..

zarray-like

z coordinates of the points..

startsdict or tuple

If starts is a dictionnary, it should map each rank to its start. If starts is a tuple, then it is assumed to be the start of the current rank.

endsdict or tuple, optional

If ends is a dictionnary, it should map each rank to its end. If ends is a tuple, then it is assumed to be the end of the current rank. If ends is None it is deduced from the data.

dimensiontuple or None, optional

dimension of the complete grid.

cellDatadict, optional

dictionary with variables associated to each cell. Keys should be the names of the variable stored in each array. Values should be arrays or 3-tuple of arrays. All arrays must have the same number of elements.

pointDatadict, optional

dictionary with variables associated to each vertex. Keys should be the names of the variable stored in each array. Values should be arrays or 3-tuple of arrays. All arrays must have the same number of elements.

fieldDatadict, optional

dictionary with variables associated with the field. Keys should be the names of the variable stored in each array. Values should be arrays or 3-tuple of arrays.

commMPI.Intracomm, default=MPI.COMM_WORLD

Communicator.

ghotslevelint default=0,

Number of cells which are shared between neighbouring files.

direct_formatstr in {‘ascii’, ‘binary’}, default=’ascii’

how the data that isn’t appended will be encoded. If 'ascii', the data will be human readable, if 'binary' it will use base 64 and can be compressed. See compressor argument.

appended_formatstr in {‘raw’, ‘binary’}, default=’raw’

how that appended data will be encoded. If 'raw', raw binary data will be written to file. This is space efficient and supported by vtk but isn’t valid XML. If 'binary', data will be encoded using base64 and can be compressed. See compressor argument.

compressionBool or int, default=False

compression level of the binary data. Can be True, False or any integer in [-1, 9] included. If True, compression will be set to -1 and use the default value of the compressor.

compressor: str in {‘zlib’, ‘lzma’}, default=’zlib’

compression library to use for the binary data.

appendbool, default=True

Whether to write the data in appended mode or not.

py2vtk.mpi.api.parallelStructuredGridToVTK(path, x, y, z, starts, ends=None, dimension=None, cellData=None, pointData=None, fieldData=None, comm=<mpi4py.MPI.Intracomm object>, ghostlevel=0, direct_format='ascii', appended_format='raw', compression=False, compressor='zlib', append=True)

Export one vtk structured grid per rank and one vtk parallel structured grid on rank 0.

Parameters

pathstr

name of the file without extension or rank specific numbering where data should be saved. Each rank will produce a file named filename + f".{rank}.vts". Rank 0 will also produce a parallel VTI file named filename.pvts.

xarray-like

x coordinates of the points..

yarray-like

y coordinates of the points..

zarray-like

z coordinates of the points..

startsdict or tuple

If starts is a dictionnary, it should map each rank to its start. If starts is a tuple, then it is assumed to be the start of the current rank.

endsdict or tuple, optional

If ends is a dictionnary, it should map each rank to its end. If ends is a tuple, then it is assumed to be the end of the current rank. If ends is None it is deduced from the data.

dimensiontuple or None, optional

dimension of the complete grid.

cellDatadict, optional

dictionary with variables associated to each cell. Keys should be the names of the variable stored in each array. Values should be arrays or 3-tuple of arrays. All arrays must have the same number of elements.

pointDatadict, optional

dictionary with variables associated to each vertex. Keys should be the names of the variable stored in each array. Values should be arrays or 3-tuple of arrays. All arrays must have the same number of elements.

fieldDatadict, optional

dictionary with variables associated with the field. Keys should be the names of the variable stored in each array. Values should be arrays or 3-tuple of arrays.

commMPI.Intracomm, default=MPI.COMM_WORLD

Communicator.

ghotslevelint default=0,

Number of cells which are shared between neighbouring files.

direct_formatstr in {‘ascii’, ‘binary’}, default=’ascii’

how the data that isn’t appended will be encoded. If 'ascii', the data will be human readable, if 'binary' it will use base 64 and can be compressed. See compressor argument.

appended_formatstr in {‘raw’, ‘binary’}, default=’raw’

how that appended data will be encoded. If 'raw', raw binary data will be written to file. This is space efficient and supported by vtk but isn’t valid XML. If 'binary', data will be encoded using base64 and can be compressed. See compressor argument.

compressionBool or int, default=False

compression level of the binary data. Can be True, False or any integer in [-1, 9] included. If True, compression will be set to -1 and use the default value of the compressor.

compressor: str in {‘zlib’, ‘lzma’}, default=’zlib’

compression library to use for the binary data.

appendbool, default=True

Whether to write the data in appended mode or not.

py2vtk.mpi.api.parallelPolyDataToVTK(path, x, y, z, vertices=None, lines=None, strips=None, polys=None, cellData=None, pointData=None, fieldData=None, comm=<mpi4py.MPI.Intracomm object>, ghostlevel=0, direct_format='ascii', appended_format='raw', compression=False, compressor='zlib', append=True)

Export one vtk polydata per rank and one vtk parallel polydata on rank 0.

Parameters

pathstr

name of the file without extension where data should be saved.

xarray-like

x coordinates of the points.

yarray-like

y coordinates of the points.

zarray-like

z coordinates of the points.

verticesarray-like or None, optional

1-D array containing the index of the points which should be saved as vertices.

lines2-tuple of array-likes or list of array-likes or None, optional

If a 2-tuple or array-likes, should be (connectivity, offsets) where connectivity should defines the points associated to each line and offsets should define the index of the last point in each cell (here line). If a list of array-likes, each element in the list should define the points associated to each line.

strips2-tuple of array-likes or list of array-likes or None, optional

If a 2-tuple or array-likes, should be (connectivity, offsets) where connectivity should defines the points associated to each strip and offsets should define the index of the last point in each cell (here strip). If a list of array-likes, each element in the list should define the points associated to each strip.

polys2-tuple of array-likes or list of array-likes or None, optional

If a 2-tuple or array-likes, should be (connectivity, offsets) where connectivity should defines the points associated to each polygon and offsets should define the index of the last point in each cell (here polygon). If a list of array-likes, each element in the list should define the points associated to each polygon.

cellDatadict or 4-tuple of dicts, optional

dictionary containing cell centered data or tuple of 4 dictionaries, one for each cell type (vertices, lines, strips and polys). Keys should be the names of the data arrays. Values should be arrays or 3-tuple of arrays. Arrays must have the same dimensions in all directions and must only contain scalar data.

pointDatadict, optional

dictionary with variables associated to each vertex. Keys should be the names of the variable stored in each array. Values should be arrays or 3-tuple of arrays. All arrays must have the same number of elements.

fieldDatadict, optional

dictionary with variables associated with the field. Keys should be the names of the variable stored in each array. Values should be arrays or 3-tuple of arrays.

commMPI.Intracomm, default=MPI.COMM_WORLD

Communicator.

ghotslevelint default=0,

Number of cells which are shared between neighbouring files.

direct_formatstr in {‘ascii’, ‘binary’}, default=’ascii’

how the data that isn’t appended will be encoded. If 'ascii', the data will be human readable, if 'binary' it will use base 64 and can be compressed. See compressor argument.

appended_formatstr in {‘raw’, ‘binary’}, default=’raw’

how that appended data will be encoded. If 'raw', raw binary data will be written to file. This is space efficient and supported by vtk but isn’t valid XML. If 'binary', data will be encoded using base64 and can be compressed. See compressor argument.

compressionBool or int, default=False

compression level of the binary data. Can be True, False or any integer in [-1, 9] included. If True, compression will be set to -1 and use the default value of the compressor.

compressor: str in {‘zlib’, ‘lzma’}, default=’zlib’

compression library to use for the binary data.

appendbool, default=True

Whether to write the data in appended mode or not.

Notes

While Vtk PolyData does support cell-centered data, the way it does is not intuitive as the cell are numbered globally across each cell type and ordered in the following way: verts, lines, polys and strips. On top of that, for what is still a mistery to me, cell data written in base64 is read improperly (despite being written properly) and shows wrong results in paraview and when read using the python vtk library. For this reason, when provided with cell-centered data, this function will enforce ‘raw’ as the appended format and ‘ascii’ as the direct format.

py2vtk.mpi.api.parallelUnstructuredGridToVTK(path, x, y, z, connectivity, offsets, cell_types, faces=None, faceoffsets=None, cellData=None, pointData=None, fieldData=None, comm=<mpi4py.MPI.Intracomm object>, ghostlevel=0, direct_format='ascii', appended_format='raw', compression=False, compressor='zlib', append=True, check_cells=True)

Export one unstructured grid per rank and one vtk parallel unstructured grid on rank 0.

Parameters

pathstr

name of the file without extension or rank specific numbering where data should be saved. Each rank will produce a file named filename + f".{rank}.vtu". Rank 0 will also produce a parallel VTU file named filename.pvtu.

xarray-like

x coordinates of the vertices.

yarray-like

y coordinates of the vertices.

zarray-like

z coordinates of the vertices.

connectivityarray-like

1D array that defines the vertices associated to each element. Together with offset define the connectivity or topology of the grid. It is assumed that vertices in an element are listed consecutively.

offsetsarray-like

1D array with the index of the last vertex of each element in the connectivity array. It should have length nelem, where nelem is the number of cells or elements in the grid.

cell_typesarray_like

1D array with an integer that defines the cell type of each element in the grid. It should have size nelem. This should be filed using py2vtk.core.vtkcells.VtkXXXX.tid, where XXXX represent the type of cell. Please check the VTK file format specification or py2vtk.core.vtkcells.py for allowed cell types.

facesarray_like or None, optional

1D integer array describing the faces of polyhedric cells. This is only required and used if there are polyhedra in the grid (cell id 42). When used it is expected to be formatted in the following way for each polyhedron: Number of faces, Number of points in face 0, first point of face 0, … and so on.

faceoffsetsarray_like or None, optional

1D integer array with the index of the last vertex of each polyhedron in the faces array.

cellDatadict, optional

dictionary with variables associated to each cell. Keys should be the names of the variable stored in each array. Values should be arrays or 3-tuple of arrays. All arrays must have the same number of elements.

pointDatadict, optional

dictionary with variables associated to each vertex. Keys should be the names of the variable stored in each array. Values should be arrays or 3-tuple of arrays. All arrays must have the same number of elements.

fieldDatadict, optional

dictionary with variables associated with the field. Keys should be the names of the variable stored in each array. Values should be arrays or 3-tuple of arrays.

commMPI.Intracomm, default=MPI.COMM_WORLD

Communicator.

ghotslevelint default=0,

Number of cells which are shared between neighbouring files.

direct_formatstr in {‘ascii’, ‘binary’}, default=’ascii’

how the data that isn’t appended will be encoded. If 'ascii', the data will be human readable, if 'binary' it will use base 64 and can be compressed. See compressor argument.

appended_formatstr in {‘raw’, ‘binary’}, default=’raw’

how that appended data will be encoded. If 'raw', raw binary data will be written to file. This is space efficient and supported by vtk but isn’t valid XML. If 'binary', data will be encoded using base64 and can be compressed. See compressor argument.

compressionBool or int, default=False

compression level of the binary data. Can be True, False or any integer in [-1, 9] included. If True, compression will be set to -1 and use the default value of the compressor.

compressor: str in {‘zlib’, ‘lzma’}, default=’zlib’

compression library to use for the binary data.

appendbool, default=True

Whether to write the data in appended mode or not.

check_cellsBool, default=True

If True, checks cell_types and offsets to ensure that the types are correct and the number of points in each cell is coherent with their type. The understood cell types are listed in py2vtk.core.vtkcells.py.