Mesh utilities

The utils module of geos-mesh package contains various utilities for VTK meshes.

geos.mesh.utils.genericHelpers module

Generic VTK utilities.

These methods include:
  • extraction of a surface from a given elevation

  • conversion from a list to vtkIdList

  • conversion of vtk container into iterable

geos.mesh.utils.genericHelpers.computeNormals(surface, logger=None)[source]

Compute and set the normals of a given surface.

Parameters:
  • surface (vtkPolyData) – The input surface.

  • logger (Union[Logger, None], optional) – A logger to manage the output messages. Defaults to None, an internal logger is used.

Returns:

The surface with normal attribute.

Return type:

vtkPolyData

geos.mesh.utils.genericHelpers.computeSurfaceTextureCoordinates(surface, logger=None)[source]

Generate the 2D texture coordinates required for tangent computation. The dataset points are mapped onto a plane generated automatically.

Parameters:
  • surface (vtkPolyData) – The input surface.

  • logger (Union[Logger, None], optional) – A logger to manage the output messages. Defaults to None, an internal logger is used.

Returns:

The input surface with generated texture map.

Return type:

vtkPolyData

geos.mesh.utils.genericHelpers.computeTangents(triangulatedSurface, logger=None)[source]

Compute and set the tangents of a given surface.

Warning

The computation of tangents requires a triangulated surface.

Parameters:
  • triangulatedSurface (vtkPolyData) – The input surface. It should be triangulated beforehand.

  • logger (Union[Logger, None], optional) – A logger to manage the output messages. Defaults to None, an internal logger is used.

Returns:

The surface with tangent attribute

Return type:

vtkPolyData

geos.mesh.utils.genericHelpers.convertAttributeFromLocalToXYZForOneCell(vector, localBasisVectors)[source]

Convert one cell attribute from local to XYZ basis.

Warning

Vectors components are considered to be in GEOS output order such that v = ( M00, M11, M22, M12, M02, M01, M21, M20, M10 )

Parameters:
  • vector (npt.NDArray[np.float64]) – The attribute expressed in local basis. The size of the vector must be 3, 9 or 6 (symmetrical case)

  • localBasisVectors (tuple[ npt.NDArray[np.float64], npt.NDArray[np.float64], npt.NDArray[np.float64]]) – The local basis vectors expressed in the XYZ basis.

Returns:

The attribute expressed in XYZ basis.

Return type:

vectorXYZ (npt.NDArray[np.float64])

geos.mesh.utils.genericHelpers.convertUnstructuredGridToPolyData(dataSet, logger=None)[source]

Convert vtkUnstructuredGrid to vtkPolyData.

..Warning:: Work only with triangulated mesh

Parameters:
  • dataSet (vtkUnstructuredGrid) – Input mesh block

  • logger (Union[Logger, None], optional) – A logger to manage the output messages. Defaults to None, an internal logger is used.

Returns:

Extracted surface

Return type:

vtkPolyData

geos.mesh.utils.genericHelpers.createMultiCellMesh(cellTypes, cellPtsCoord, sharePoints=True)[source]

Create a mesh that consists of multiple cells.

Warning

The mesh is not checked for conformity.

Parameters:
  • cellTypes (list[int]) – Cell type

  • cellPtsCoord (list[1DArray[np.float64]]) – List of cell point coordinates

  • sharePoints (bool) – If True, cells share points, else a new point is created for each cell vertex

Returns:

Output mesh

Return type:

vtkUnstructuredGrid

geos.mesh.utils.genericHelpers.createSingleCellMesh(cellType, ptsCoord)[source]

Create a mesh that consists of a single cell.

Parameters:
  • cellType (int) – cell type

  • ptsCoord (1DArray[np.float64]) – cell point coordinates

Returns:

output mesh

Return type:

vtkUnstructuredGrid

geos.mesh.utils.genericHelpers.createVertices(cellPtsCoord, shared=True)[source]

Create vertices from cell point coordinates list.

Parameters:
  • cellPtsCoord (list[npt.NDArray[np.float64]]) – list of cell point coordinates

  • shared (bool, optional) – If True, collocated points are merged. Defaults to True.

Returns:

tuple containing points and the

map of cell point ids

Return type:

tuple[vtkPoints, list[tuple[int, …]]]

geos.mesh.utils.genericHelpers.extractSurfaceFromElevation(mesh, elevation)[source]

Extract surface at a constant elevation from a mesh.

Parameters:
  • mesh (vtkUnstructuredGrid) – input mesh

  • elevation (float) – elevation at which to extract the surface

Returns:

output surface

Return type:

vtkPolyData

geos.mesh.utils.genericHelpers.getBounds(input)[source]

Get bounds of either single of composite data set.

Parameters:

input (Union[vtkUnstructuredGrid, vtkMultiBlockDataSet]) – input mesh

Returns:

tuple containing

bounds (xmin, xmax, ymin, ymax, zmin, zmax)

Return type:

tuple[float, float, float, float, float, float]

geos.mesh.utils.genericHelpers.getBoundsFromPointCoords(cellPtsCoord)[source]

Compute bounding box coordinates of the list of points.

Parameters:

cellPtsCoord (list[npt.NDArray[np.float64]]) – list of points

Returns:

bounding box coordinates (xmin, xmax, ymin, ymax, zmin, zmax)

Return type:

Sequence[float]

geos.mesh.utils.genericHelpers.getLocalBasisVectors(surface, logger=None)[source]

Return the local basis vectors for all cells of the input surface.

Parameters:
  • surface (vtkPolydata) – The input surface.

  • logger (Union[Logger, None], optional) – A logger to manage the output messages. Defaults to None, an internal logger is used.

Returns:

Array with normal, tangential 1 and tangential 2 vectors.

Return type:

npt.NDArray[np.float64]

geos.mesh.utils.genericHelpers.getMonoBlockBounds(input)[source]

Get boundary box extrema coordinates for a vtkUnstructuredGrid.

Parameters:

input (vtkMultiBlockDataSet) – input single block mesh

Returns:

tuple containing

bounds (xmin, xmax, ymin, ymax, zmin, zmax)

Return type:

tuple[float, float, float, float, float, float]

geos.mesh.utils.genericHelpers.getMultiBlockBounds(input)[source]

Get boundary box extrema coordinates for a vtkMultiBlockDataSet.

Parameters:

input (vtkMultiBlockDataSet) – input multiblock mesh

Returns:

bounds.

Return type:

tuple[float, float, float, float, float, float]

geos.mesh.utils.genericHelpers.getNormalVectors(surface)[source]

Return the normal vectors of a surface mesh.

Parameters:

surface (vtkPolyData) – The input surface.

Raises:

ValueError – No normal attribute found in the mesh. Use the computeNormals function beforehand.

Returns:

The normal vectors of the input surface.

Return type:

npt.NDArray[ np.float64 ]

geos.mesh.utils.genericHelpers.getTangentsVectors(surface)[source]

Return the tangential vectors of a surface.

Parameters:

surface (vtkPolyData) – The input surface.

Raises:
  • ValueError – Tangent attribute not found in the mesh. Use computeTangents beforehand.

  • ValueError – Problem during the calculation of the second tangential vectors.

Returns:

The tangents vectors of the input surface.

Return type:

Tuple[npt.NDArray[np.float64], npt.NDArray[np.float64]]

geos.mesh.utils.genericHelpers.isTriangulate(dataSet)[source]

Check if the mesh is fully triangulated.

Parameters:

dataSet (vtkUnstructuredGrid) – The mesh to check

Returns:

True if the mesh is triangulate only, False otherwise.

Return type:

bool

geos.mesh.utils.genericHelpers.toVtkIdList(data)[source]

Utility function transforming a list of ids into a vtkIdList.

Parameters:

data (list[int]) – Id list

Returns:

Vtk Id List corresponding to input data

Return type:

result (vtkIdList)

geos.mesh.utils.genericHelpers.triangulateMesh(dataSet, logger=None)[source]

Triangulate any type of dataset.

Parameters:
  • dataSet (vtkUnstructuredGrid) – The mesh to triangulate

  • logger (Union[Logger, None], optional) – A logger to manage the output messages. Defaults to None, an internal logger is used.

Returns:

Triangulated mesh

Return type:

vtkUnstructuredGrid

geos.mesh.utils.genericHelpers.vtkIter(vtkContainer)[source]

Utility function transforming a vtk “container” into an iterable.

Parameters:

vtkContainer (vtkIdList | vtkCellTypes) – A vtk container

Returns:

The iterator

Return type:

Iterator[ Any ]

geos.mesh.utils.arrayHelpers module

ArrayHelpers module contains several utilities methods to get information on arrays in VTK meshes.

There are two types of functions:
  • Getters

  • Checks

The getter functions:
  • get the vtk or data array of an attribute (dataset and vtkFieldData only)

  • get the component names of an attribute

  • get the number of components of an attribute

  • get the piece of an attribute

  • get the values of an attribute as data frame (polyData only)

  • get the vtk type of an attribute

  • get the set of attributes on one piece of a mesh

  • get the attribute and they number of component on one piece of a mesh

  • get all the cells dimension of a mesh

  • get the GlobalIds array on one piece of a mesh

  • get the cell center coordinates of a mesh

  • get the mapping between cells or points shared by two meshes

The check functions:
  • check if an attribute is on a mesh

  • check if at least one attribute from a list of attributes is on a mesh (dataset only)

  • check if an attribute is global (multiblock dataset only)

  • check if a value is a value of an attribute

geos.mesh.utils.arrayHelpers.checkValidValuesInObject(mesh, attributeName, listValues, piece)[source]

Check if each value is valid, ie if that value is a data of the mesh attribute.

Parameters:
  • mesh (vtkMultiBlockDataSet | vtkDataSet) – The mesh to check.

  • attributeName (str) – The name of the attribute with the data.

  • listValues (list[Any]) – The list of values to check.

  • piece (Piece) – The piece of the attribute.

Returns:

Tuple containing the list of valid values and the list of the invalid ones.

Return type:

tuple[list[Any], list[Any]]

Raises:
  • TypeError – The mesh has to be inherited from vtkMultiBlockDataSet or vtkDataSet.

  • AttributeError – The attribute must be global for multiblock dataset.

geos.mesh.utils.arrayHelpers.computeCellCenterCoordinates(mesh)[source]

Get the coordinates of Cell center.

Parameters:

mesh (vtkDataSet) – Input surface.

Returns:

Cell center coordinates.

Return type:

vtkPoints

geos.mesh.utils.arrayHelpers.computeElementMapping(meshFrom, meshTo, piece)[source]

Compute the map of points/cells between the source mesh and the final mesh.

If the source mesh is a vtkDataSet, its flat index (flatIdDataSetFrom) is set to 0. If the final mesh is a vtkDataSet, its flat index (flatIdDataSetTo) is set to 0.

The elementMap is a dictionary where:
  • Keys are the flat index of all the datasets of the final mesh.

  • Items are arrays of size (nb elements in datasets of the final mesh, 2).

For each element (idElementTo) of each dataset (flatIdDataSetTo) of the final mesh, if the coordinates of an element (idElementFrom) of one dataset (flatIdDataSetFrom) of the source mesh are the same as the coordinates of the element of the final mesh, elementMap[flatIdDataSetTo][idElementTo] = [flatIdDataSetFrom, idElementFrom] else, elementMap[flatIdDataSetTo][idElementTo] = [-1, -1].

For cells, the coordinates of the points in the cell are compared. If one of the two meshes is a surface and the other a volume, all the points of the surface must be points of the volume.

Parameters:
  • meshFrom (Union[vtkDataSet, vtkMultiBlockDataSet]) – The source mesh with the element to map.

  • meshTo (Union[vtkDataSet, vtkMultiBlockDataSet]) – The final mesh with the reference element coordinates.

  • piece (Piece) – The element to map.

Returns:

The map of points/cells between the two meshes.

Return type:

elementMap (dict[int, npt.NDArray[np.int64]])

geos.mesh.utils.arrayHelpers.getArrayInObject(dataSet, attributeName, piece)[source]

Return the numpy array corresponding to input attribute name in the mesh.

Parameters:
  • dataSet (vtkDataSet) – Input dataSet.

  • attributeName (str) – Name of the attribute.

  • piece (Piece) – The piece of the attribute.

Returns:

The numpy array corresponding to input attribute name.

Return type:

NDArray[Any]

geos.mesh.utils.arrayHelpers.getAttributePieceInfo(mesh, attributeName)[source]

Get the attribute piece.

Parameters:
  • mesh (Union[vtkDataSet, vtkMultiBlockDataSet]) – The mesh with the attribute.

  • attributeName (str) – The name of the attribute.

Returns:

The piece of the attribute.

Return type:

Piece

geos.mesh.utils.arrayHelpers.getAttributeSet(mesh, piece)[source]

Get the set of all attributes from an mesh on points or on cells.

Parameters:
  • mesh (Union[vtkMultiBlockDataSet, vtkDataSet]) – Mesh where to find the attributes.

  • piece (Piece) – The piece of the attributes to get.

Returns:

Set of attribute names present in input mesh.

Return type:

set[str]

geos.mesh.utils.arrayHelpers.getAttributeValuesAsDF(surface, attributeNames, piece=Piece.CELLS)[source]

Get attribute values from input surface.

Parameters:
  • surface (vtkPolyData) – Mesh where to get attribute values.

  • attributeNames (tuple[str,...]) – Tuple of attribute names to get the values.

  • piece (Piece) – The piece of the attribute. Defaults to Piece.CELLS

Returns:

DataFrame containing property names as columns.

Return type:

pd.DataFrame

geos.mesh.utils.arrayHelpers.getAttributesWithNumberOfComponents(mesh, piece)[source]

Get the dictionary of all attributes from object on points or cells.

Parameters:
  • mesh (vtkMultiBlockDataSet | vtkDataSet) – Mesh where to find the attributes.

  • piece (Piece) – The piece of the attributes to get.

Returns:

Dictionary where keys are the names of the attributes and values the number of components.

Return type:

dict[str, int]

Raises:
  • ValueError – The piece must be cells or points only

  • AttributeError – One attribute of the mesh is null.

  • TypeError – Input mesh must be a vtkDataSet or vtkMultiBlockDataSet.

geos.mesh.utils.arrayHelpers.getCellDimension(mesh)[source]

Get the set of the different cells dimension of a mesh.

Parameters:

mesh (Union[vtkMultiBlockDataSet, vtkDataSet]) – The input mesh with the cells dimension to get.

Returns:

The set of the different cells dimension in the input mesh.

Return type:

set[int]

geos.mesh.utils.arrayHelpers.getComponentNames(mesh, attributeName, piece)[source]

Get the name of the components of the attribute ‘attributeName’ in a mesh.

Parameters:
  • mesh (vtkDataSet | vtkMultiBlockDataSet | vtkCompositeDataSet | vtkDataObject) – Mesh where the attribute is.

  • attributeName (str) – Name of the attribute.

  • piece (Piece) – The piece of the attribute.

Returns:

Names of the components.

Return type:

tuple[str,…]

Raises:
  • AttributeError – The attribute ‘attributeName’ is not in the mesh for the given piece.

  • TypeError – The mesh has to be inherited from vtkMultiBlockDataSet or vtkDataSet.

  • ValueError – The attribute’s piece must be ‘cells’, ‘points’ or ‘field’.

geos.mesh.utils.arrayHelpers.getNumberOfComponents(mesh, attributeName, piece)[source]

Get the number of components of the attribute ‘attributeName’ in the mesh for a given piece.

Parameters:
  • mesh (vtkMultiBlockDataSet | vtkCompositeDataSet | vtkDataSet) – Mesh where the attribute is.

  • attributeName (str) – Name of the attribute.

  • piece (Piece) – The piece of the attribute.

Returns:

Number of components.

Return type:

int

Raises:
  • AttributeError – The attribute ‘attributeName’ is not in the mesh for the given piece.

  • TypeError – The mesh has to be inherited from vtkMultiBlockDataSet or vtkDataSet.

  • ValueError – The attribute’s piece must be ‘cells’, ‘points’ or ‘field’.

geos.mesh.utils.arrayHelpers.getNumpyArrayByName(data, name, sorted=False)[source]

Get the numpy array of a given vtkDataArray found by its name.

If sorted is selected, this allows the option to reorder the values wrt GlobalIds. If not GlobalIds was found, no reordering will be perform.

Parameters:
  • data (Union[vtkCellData, vtkPointData]) – Vtk field data.

  • name (str) – Array name to sort.

  • sorted (bool, optional) – Sort the output array with the help of GlobalIds. Defaults to False.

Returns:

Sorted array.

Return type:

npt.NDArray

Raises:

AttributeError – There is no array with the given name in the data.

geos.mesh.utils.arrayHelpers.getNumpyGlobalIdsArray(data)[source]

Get a numpy array of the GlobalIds if it exist.

Parameters:

data (Union[ vtkCellData, vtkPointData ]) – Cell or point array.

Returns:

The numpy array of GlobalIds.

Return type:

(npt.NDArray)

Raises:
  • TypeError – The data entered is not a vtkFieldDate object.

  • AttributeError – There is no GlobalIds in the given data.

geos.mesh.utils.arrayHelpers.getVtkArrayInObject(dataSet, attributeName, piece)[source]

Return the array corresponding to input attribute name in the mesh.

Parameters:
  • dataSet (vtkDataSet) – Input mesh with the attribute to get.

  • attributeName (str) – Name of the attribute to get.

  • piece (Piece) – The piece of the attribute to get.

Returns:

The vtk array corresponding to input attribute name.

Return type:

vtkDataArray

Raises:
  • ValueError – The piece must be cells, points or fields.

  • AttributeError – The attribute ‘attributeName’ is not in the mesh.

geos.mesh.utils.arrayHelpers.getVtkArrayTypeInObject(mesh, attributeName, piece)[source]

Return VTK type of requested array from input mesh.

Parameters:
  • mesh (Union[vtkDataSet, vtkMultiBlockDataSet]) – Input mesh.

  • attributeName (str) – Name of the attribute.

  • piece (Piece) – The piece of the attribute.

Returns:

The type of the vtk array corresponding to input attribute name.

Return type:

int

Raises:
  • AttributeError – The attribute ‘attributeName’ is not in the mesh.

  • TypeError – The mesh has to be inherited from vtkMultiBlockDataSet or vtkDataSet.

geos.mesh.utils.arrayHelpers.hasArray(mesh, arrayNames)[source]

Checks if input mesh contains at least one of input data arrays.

Parameters:
  • mesh (vtkUnstructuredGrid) – An unstructured mesh.

  • arrayNames (list[str]) – List of array names.

Returns:

True if at least one array is found, else False.

Return type:

bool

geos.mesh.utils.arrayHelpers.isAttributeGlobal(multiBlockDataSet, attributeName, piece)[source]

Check if an attribute is global in the input multiBlockDataSet.

Parameters:
  • multiBlockDataSet (vtkMultiBlockDataSet) – Input multiBlockDataSet.

  • attributeName (str) – Name of the attribute.

  • piece (Piece) – The piece of the attribute.

Returns:

True if the attribute is global, False if not.

Return type:

bool

geos.mesh.utils.arrayHelpers.isAttributeInObject(mesh, attributeName, piece)[source]

Check if an attribute is in the input mesh for the given piece.

Parameters:
  • mesh (vtkMultiBlockDataSet | vtkDataSet) – Input mesh.

  • attributeName (str) – Name of the attribute.

  • piece (Piece) – The piece of the attribute.

Returns:

True if the attribute is on the mesh, False otherwise.

Return type:

bool

Raises:

TypeError – The mesh has to be inherited from vtkMultiBlockDataSet or vtkDataSet.

geos.mesh.utils.arrayModifiers module

ArrayModifiers contains utilities to process VTK Arrays objects.

These methods include:
  • filling partial VTK arrays with values (useful for block merge)

  • creation of new VTK array, empty or with a given data array

  • copy VTK array from a source mesh to a final mesh

  • transfer VTK array from a source mesh to a final mesh with a element map

  • transfer from VTK point data to VTK cell data

geos.mesh.utils.arrayModifiers.copyAttribute(meshFrom, meshTo, attributeNameFrom, attributeNameTo, piece=Piece.CELLS, logger=None)[source]

Copy an attribute from a mesh to a similar one on the same piece.

The similarity of two meshes means that the two mesh have the same number of elements (cells and points) located in the same coordinates and with the same indexation. Testing this similarity is time consuming therefore, only few metric are compared:
  • the block indexation for multiblock dataset

  • the number of the element where the attribute is located, for multiblock dataset it is done for each block

  • the coordinates of the first element, for multiblock dataset it is done for each block

Parameters:
  • meshFrom (vtkMultiBlockDataSet | vtkDataSet) – mesh from which to copy the attribute.

  • meshTo (vtkMultiBlockDataSet | vtkDataSet) – mesh where to copy the attribute.

  • attributeNameFrom (str) – Attribute name in meshFrom.

  • attributeNameTo (str) – Attribute name to set in meshTo.

  • piece (Piece) – The piece of the attribute. Defaults to Piece.CELLS

  • logger (Union[Logger, None], optional) – A logger to manage the output messages. Defaults to None, an internal logger is used.

Raises:
  • TypeError – Error with the type of the source or final mesh.

  • ValueError – Error with the data of the source or final mesh or the piece.

  • AttributeError – Error with the attribute attributeNameFrom or attributeNameTo.

geos.mesh.utils.arrayModifiers.createAttribute(dataSet, npArray, attributeName, componentNames=(), piece=Piece.CELLS, vtkDataType=None, logger=None)[source]

Create the attribute from the given numpy array on the dataSet.

Parameters:
  • dataSet (vtkDataSet) – DataSet where to create the attribute.

  • npArray (NDArray[Any]) – Array that contains the values.

  • attributeName (str) – Name of the attribute.

  • componentNames (tuple[str,...], optional) – Name of the components for vectorial attributes. If one component, gives an empty tuple. Defaults to an empty tuple.

  • piece (Piece) – The piece of the attribute. Defaults to Piece.CELLS

  • vtkDataType (Union[int, None], optional) –

    Vtk data type of the attribute to create. Defaults to None, the vtk data type is given by the type of the array.

    Warning with int8, uint8 and int64 type, the corresponding vtk data type are multiples. By default: - int8 -> VTK_SIGNED_CHAR - uint8 -> VTK_UNSIGNED_CHAR - int64 -> VTK_LONG_LONG

  • logger (Union[Logger, None], optional) – A logger to manage the output messages. Defaults to None, an internal logger is used.

Raises:
  • TypeError – Error with the type of the mesh or the npArray values.

  • ValueError – Error with the values of npArray or vtkDataType.

  • AttributeError – Error with the attribute attributeName.

geos.mesh.utils.arrayModifiers.createCellCenterAttribute(mesh, cellCenterAttributeName, logger=None)[source]

Create cellElementCenter attribute if it does not exist.

Parameters:
  • mesh (vtkMultiBlockDataSet | vtkDataSet) – Input mesh.

  • cellCenterAttributeName (str) – Name of the attribute.

  • logger (Union[Logger, None], optional) – A logger to manage the output messages. Defaults to None, an internal logger is used.

Raises:
  • TypeError – Error with the mesh type.

  • AttributeError – Error with the attribute cellCenterAttributeName.

geos.mesh.utils.arrayModifiers.createConstantAttribute(mesh, listValues, attributeName, componentNames=(), piece=Piece.CELLS, vtkDataType=None, logger=None)[source]

Create a new attribute with a constant value in the mesh.

Parameters:
  • mesh (Union[vtkMultiBlockDataSet, vtkDataSet]) – Mesh where to create the attribute.

  • listValues (list[Any]) – List of values of the attribute for each components. It is recommended to use numpy scalar type for the values.

  • attributeName (str) – Name of the attribute.

  • componentNames (tuple[str,...], optional) – Name of the components for vectorial attributes. If one component, gives an empty tuple. Defaults to an empty tuple.

  • piece (Piece) – The piece of the attribute. Defaults to Piece.CELLS

  • vtkDataType (Union[int, None], optional) –

    Vtk data type of the attribute to create. Defaults to None, the vtk data type is given by the type of the values.

    Warning with int8, uint8 and int64 type of value, the corresponding vtk data type are multiples. By default: - int8 -> VTK_SIGNED_CHAR - uint8 -> VTK_UNSIGNED_CHAR - int64 -> VTK_LONG_LONG

  • logger (Union[Logger, None], optional) – A logger to manage the output messages. Defaults to None, an internal logger is used.

Raises:
  • TypeError – Error with the type of the input mesh or the type of the input values or the vtkDataType.

  • AttributeError – The attribute is already on the mesh.

  • ValueError – Error with the vtkDataType (unknown) or with the piece.

geos.mesh.utils.arrayModifiers.createEmptyAttribute(attributeName, componentNames, vtkDataType)[source]

Create an empty attribute.

Parameters:
  • attributeName (str) – Name of the attribute

  • componentNames (tuple[str,...]) – Name of the components for vectorial attributes.

  • vtkDataType (int) – Data type.

Raises:

ValueError – Error with the vtkDataType.

Returns:

The empty attribute.

Return type:

vtkDataArray

geos.mesh.utils.arrayModifiers.fillAllPartialAttributes(multiBlockDataSet, logger=None)[source]

Fill all partial attributes of a multiBlockDataSet with the default value.

All components of each attributes are filled with the same value. Depending of the type of the attribute’s data, the default value is different:

0 for uint data, -1 for int data, nan float data,

Parameters:
  • multiBlockDataSet (vtkMultiBlockDataSet | vtkCompositeDataSet | vtkDataObject) – MultiBlockDataSet where to fill attributes.

  • logger (Union[Logger, None], optional) – A logger to manage the output messages. Defaults to None, an internal logger is used.

Raises:

TypeError – Error with the type of the mesh.

geos.mesh.utils.arrayModifiers.fillPartialAttributes(multiBlockDataSet, attributeName, piece=Piece.CELLS, listValues=None, logger=None, fillAll=False)[source]

Fill input partial attribute of multiBlockDataSet with a constant value per component.

Parameters:
  • multiBlockDataSet (vtkMultiBlockDataSet | vtkCompositeDataSet | vtkDataObject) – MultiBlockDataSet where to fill the attribute.

  • attributeName (str) – Attribute name.

  • piece (Piece) – The piece of the attribute. Defaults to Piece.CELLS

  • listValues (list[Any], optional) – List of filling value for each component. Defaults to None, the filling value is for all components: -1 for int VTK arrays. 0 for uint VTK arrays. nan for float VTK arrays.

  • logger (Union[Logger, None], optional) – A logger to manage the output messages. Defaults to None, an internal logger is used.

  • fillAll (bool, optional) – True if fillPartialAttributes is used by fillAllPartialAttributes, else False. Defaults to False.

Raises:
  • TypeError – Error with the type of the mesh.

  • ValueError – Error with the values of the listValues.

  • AttributeError – Error with the attribute attributeName.

geos.mesh.utils.arrayModifiers.renameAttribute(object, attributeName, newAttributeName, piece, logger=None)[source]

Rename an attribute with a unique name.

Parameters:
  • object (vtkMultiBlockDataSet) – Object where the attribute is.

  • attributeName (str) – Name of the attribute.

  • newAttributeName (str) – New name of the attribute.

  • piece (Piece) – The piece of the attribute.

  • logger (Union[Logger, None], optional) – A logger to manage the output messages. Defaults to None, an internal logger is used.

Raises:
  • TypeError – Error with the type of the mesh.

  • AttributeError – Error with the attribute attributeName or newAttributeName.

  • VTKError – Error with a VTK function.

geos.mesh.utils.arrayModifiers.transferAttributeWithElementMap(meshFrom, meshTo, elementMap, attributeName, piece, flatIdDataSetTo=0, logger=None)[source]

Transfer attributes from the source mesh to the final mesh using a map of points/cells.

If the source mesh is a vtkDataSet, its flat index (flatIdDataSetFrom) is set to 0. If the final mesh is a vtkDataSet, its flat index (flatIdDataSetTo) is set to 0.

The map of points/cells used to transfer the attribute is a dictionary where:
  • Keys are the flat indexes of all the datasets of the final mesh.

  • Items are arrays of size (nb elements in datasets of the final mesh, 2).

If an element (idElementTo) of one dataset (flatIdDataSetTo) of the final mesh is mapped with no element of the source mesh:
  • elementMap[flatIdDataSetTo][idElementTo] = [-1, -1].

  • The value of the attribute for this element depends of the type of the value of the attribute (0 for unit, -1 for int, nan for float).

If an element (idElementTo) of one dataset (flatIdDataSetTo) of the final mesh is mapped with an element (idElementFrom) of one of the dataset (flatIdDataSetFrom) of the source mesh:
  • elementMap[flatIdDataSetTo][idElementTo] = [flatIdDataSetFrom, idElementFrom].

  • The value of the attribute for this element is the value of the element (idElementFrom) of the dataset (flatIdDataSetFrom) of the source mesh.

Parameters:
  • meshFrom (Union[vtkDataSet, vtkMultiBlockDataSet]) – The source mesh with the attribute to transfer.

  • meshTo (Union[vtkDataSet, vtkMultiBlockDataSet]) – The final mesh where to transfer the attribute.

  • elementMap (dict[int, npt.NDArray[np.int64]]) – The map of points/cells.

  • attributeName (str) – The name of the attribute to transfer.

  • piece (Piece) – The piece of the attribute.

  • flatIdDataSetTo (int, Optional) – The flat index of the final mesh considered as a dataset of a vtkMultiblockDataSet. Defaults to 0 for final meshes who are not datasets of vtkMultiBlockDataSet.

  • logger (Union[Logger, None], optional) – A logger to manage the output messages. Defaults to None, an internal logger is used.

Raises:
  • TypeError – Error with the type of the mesh to or the mesh from.

  • ValueError – Error with the values of the map elementMap.

  • AttributeError – Error with the attribute attributeName.

geos.mesh.utils.arrayModifiers.transferPointDataToCellData(mesh, logger=None)[source]

Transfer point data to cell data.

Parameters:
  • mesh (vtkPointSet) – Input mesh.

  • logger (Union[Logger, None], optional) – A logger to manage the output messages. Defaults to None, an internal logger is used.

Raises:
  • TypeError – Error with the type of the mesh.

  • VTKError – Error with a VTK function.

Returns:

Output mesh where point data were transferred to cells.

Return type:

vtkPointSet

geos.mesh.utils.multiblockHelpers module

Functions to explore VTK multiblock datasets.

Methods include:
  • getters for blocks names and indexes

  • block extractor

geos.mesh.utils.multiblockHelpers.extractBlock(multiBlockDataSet, blockIndex)[source]

Extract the block with index blockIndex from multiBlockDataSet.

Parameters:
  • multiBlockDataSet (vtkMultiBlockDataSet) – multiblock dataset from which to extract the block

  • blockIndex (int) – block index to extract

Returns:

extracted block

Return type:

vtkMultiBlockDataSet

geos.mesh.utils.multiblockHelpers.getBlockElementIndexes(multiBlockDataSet)[source]

Get a list of list that contains flat indexes of elementary blocks.

Each sublist contains the indexes of elementary blocks that belongs to a same parent node.

Parameters:

multiBlockDataSet (Union[vtkMultiBlockDataSet, vtkCompositeDataSet]) – MultiBlockDataSet with the block indexes to get.

Returns:

List of list of flat indexes.

Return type:

list[list[int]]

geos.mesh.utils.multiblockHelpers.getBlockElementIndexesFlatten(multiBlockDataSet)[source]

Get a flatten list that contains flat indexes of elementary blocks.

Parameters:

multiBlockDataSet (Union[vtkMultiBlockDataSet, vtkCompositeDataSet]) – MultiBlockDataSet with the block flat indexes to get.

Returns:

List of flat indexes.

Return type:

list[int]

geos.mesh.utils.multiblockHelpers.getBlockFromFlatIndex(multiBlockDataSet, blockIndex)[source]

Get the block with blockIndex from the vtkMultiBlockDataSet.

Parameters:
  • multiBlockDataSet (Union[vtkMultiBlockDataSet, vtkCompositeDataSet]) – MultiBlockDataSet with the block to get.

  • blockIndex (int) – The block index og the block to get.

Returns:

The block with the flat index if it exists, None otherwise

Return type:

Union[None, vtkDataObject]

geos.mesh.utils.multiblockHelpers.getBlockIndexFromName(multiBlockDataSet, blockName)[source]

Get flat index of a multiBlockDataSet block with its name.

Parameters:
  • multiBlockDataSet (Union[vtkMultiBlockDataSet, vtkCompositeDataSet]) – MultiBlockDataSet with the block to get the index.

  • blockName (str) – Name of the block to get the flat index.

Returns:

Flat index of the block if found, -1 otherwise.

Return type:

int

geos.mesh.utils.multiblockHelpers.getBlockNameFromIndex(multiBlockDataSet, index)[source]

Get the name of a multiBlockDataSet block with its flat index.

Parameters:
  • multiBlockDataSet (Union[vtkMultiBlockDataSet, vtkCompositeDataSet]) – MultiBlockDataSet with the block to get the name.

  • index (int) – Flat index of the block to get the name.

Returns:

name of the block in the tree.

Return type:

str

geos.mesh.utils.multiblockHelpers.getBlockNames(multiBlockDataSet)[source]

Get the name of all blocks of the multiBlockDataSet.

Parameters:

multiBlockDataSet (Union[vtkMultiBlockDataSet, vtkCompositeDataSet]) – MultiBlockDataSet with the block names to get.

Returns:

list of the names of the block in the multiBlockDataSet.

Return type:

list[str]

geos.mesh.utils.multiblockHelpers.getElementaryCompositeBlockIndexes(multiBlockDataSet)[source]

Get indexes of composite block of the multiBlockDataSet that contains elementary blocks.

Parameters:

multiBlockDataSet (Union[vtkMultiBlockDataSet, vtkCompositeDataSet]) – MultiBlockDataSet.

Returns:

Dictionary that contains names as keys and flat indices as values of the parent composite blocks of elementary blocks.

Return type:

dict[str, int]

geos.mesh.utils.multiblockModifiers module

Contains a method to merge blocks of a VTK multiblock dataset.

geos.mesh.utils.multiblockModifiers.mergeBlocks(inputMesh, keepPartialAttributes=False, logger=None)[source]

Merge all blocks of a multiblock dataset mesh with the possibility of keeping all partial attributes present in the initial mesh.

Parameters:
  • inputMesh (vtkMultiBlockDataSet | vtkCompositeDataSet) – The input multiblock dataset to merge.

  • keepPartialAttributes (bool) – If False (default), only global attributes are kept during the merge. If True, partial attributes are filled with default values and kept in the output mesh.

  • logger (Union[Logger, None], optional) – A logger to manage the output messages. Defaults to None, an internal logger is used.

Returns:

Merged dataset or input mesh if it’s already a single block.

Return type:

vtkUnstructuredGrid

Raises:

geos.utils.VTKError () – Error raised during call of VTK function

Note

Default filling values:
  • 0 for uint data.

  • -1 for int data.

  • nan for float data.

Warning

This function will not work properly if there are duplicated cell IDs in the different blocks of the input mesh.

geos.mesh.utils.pyvistaTools module

This module contains utilities to process meshes using pyvista.

geos.mesh.utils.pyvistaTools.getBlockByName(multiBlockMesh, blockName)[source]

Get a block in a multi block mesh from its name.

Parameters:
  • multiBlockMesh (Union[pv.MultiBlock, pv.UnstructuredGrid]) – input mesh

  • blockName (str) – name of the block

Returns:

wanted block if it

was found

Return type:

Optional[Union[pv.MultiBlock, pv.UnstructuredGrid]]

geos.mesh.utils.pyvistaTools.loadDataSet(reader, timeStepIndexes, elevation, properties)[source]

Load the data using pyvista and extract properties from horizontal slice.

Parameters:
  • reader (pv.PVDReader) – Pyvista pvd reader.

  • timeStepIndexes (list[int]) – List of time step indexes to load.

  • elevation (float) – Elevation (m) of horizontal slice.

  • properties (tuple[str]) – List of properties to extract.

Returns:

Tuple containing

a dictionary with times as keys and dataframe with properties as values, and an array with cell center coordinates of the slice.

Return type:

tuple[dict[str, pd.DataFrame], npt.NDArray[np.float64]]