Mesh

This packages has utilities to handle the two different mesh formats to use in GEOS: - InternalMesh that is provided by GEOS - VtkMesh that is imported by GEOS

InternalMesh

InternalMesh class uses a XML object from input/Xml.py that needs to have parsed a GEOS xml file where an ‘InternalMesh’ block has been defined. This class gathers all the geometric informaion defined.

class geos.pygeos_tools.mesh.InternalMesh.InternalMesh(xml)[source]

Bases: object

GEOSX Internal Mesh

xml

XML object containing the information on the mesh

Type:

XML

bounds

Real bounds of the mesh [[xmin, xmax],[ymin,ymax],[zmin,zmax]]

Type:

list of list

nx

Number of elements in the x direction

Type:

int

ny

Number of elements in the y direction

Type:

int

nz

Number of elements in the z direction

Type:

int

order

Mesh order

Type:

int

cellBlockNames

Names of each mesh block

Type:

str

cellBounds
Type:

npt.NDArray

elementTypes

Element types of each mesh block

Type:

List[ str ]

numberOfCells

Total number of cells

Type:

int

numberOfPoints

Total number of points

Type:

int

fieldSpecifications

Dict containing the mesh field specifications

Type:

dict

Parameters:

xml (XML) – XML object containing the information on the mesh

VtkMesh

VTKMesh class uses a VTK filepath to read, extract data and write a new VTK file. Along with wrapping of VTK methods to extract geometry data and arrays, this class also allows you to extract geometrically a subset of the original mesh.

The input and output VTK file types handled currently are .vtu .vts .pvts .pvtu.

class geos.pygeos_tools.mesh.VtkMesh.VTKMesh(meshfile)[source]

Bases: object

VTK format Mesh. Now handling .vtu .vts .pvts .pvtu

meshfile

Mesh filename

Type:

str

vtktype

Format of the VTK mesh

Type:

str

bounds

Real bounds of the mesh (xmin, xmax, ymin, ymax, zmin, zmax)

Type:

tuple of float

numberOfPoints

Total number of points of the mesh

Type:

int

numberOfCells

Total number of cells of the mesh

Type:

int

isSet

Whether or not the mesh properties have been set

Type:

bool

hasLocator

Whether or not the mesh cell locator has been initialized

Type:

bool

Parameters:

meshfile (str) – Mesh filename

export(data=None, rootname=None, vtktype=None)[source]

Write VTK data in a file

Parameters:
  • data (vtkPointSet) – vtk.vtkStructuredGrid or vtk.vtkUnstructuredGrid. Default is self.read()

  • rootname (str) – Root of the output filename. Default is self.meshfile (without extension)

  • vtktype (str) – Format of the output VTK. Default is self.vtktype

Returns:

filename – Output filename

Return type:

str

extractMesh(center, srootname, dist=[None, None, None], comm=None, export=True)[source]

Extract a rectangular submesh such that for each axis we have the subax: [center-dist, center+dist]

Parameters:
  • center (3d float) – Requested center of the subbox

  • srootname (str) – Submesh root filename

  • dist (3d float) – Distance to the center in each direction

  • comm (MPI.COMM_WORLD) – MPI communicator

  • export (bool)

Returns:

Submesh extracted

Return type:

VTKMesh

getArray(name, dtype='cell', sorted=False)[source]

Return a cell or point data array. If the file is a pvtu, the array is sorted with global ids

Parameters:
  • name (str) – Name of the vtk cell/point data array

  • dtype (str) – Type of vtk data cell or point

  • sorted (bool) – Return the array sorted with respect to GlobalPointIds or GlobalCellIds. Default is False

Returns:

array – Requested array

Return type:

numpy array

getBounds()[source]
Get the bounds of the mesh in the format:

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

Returns:

Bounds of the mesh

Return type:

tuple or None

getCellContainingPoint(point)[source]

Return the global index of the cell containing the coordinates

Parameters:

point (array-like of float) – Point coordinates

Returns:

cellId – id of the cell containing the given point

Return type:

int

getCellData()[source]

Read the cell data

Returns:

Cell data information

Return type:

vtkFieldData

getExtractToGlobalMap()[source]

Return the global cell ids

Returns:

array – Global cell Ids or None if not set in the mesh

Return type:

npt.NDArray

getGlobalIds(dtype='cell')[source]

Return the global ids of the cells or points. If the mesh is an extract of an original mesh, it is the local to global map

Parameters:

dtype (str) – Type of data: cell or point

Returns:

array – Global Ids

Return type:

npt.NDArray

getNumberOfBlocks()[source]

Return the number of blocks of a mesh.

getNumberOfCells(*args, **kwargs)
getNumberOfPoints(*args, **kwargs)
getPointData()[source]

Read the point data

Returns:

Point data information

Return type:

vtkFieldData

getSubAx(*args, **kwargs)
interpolateValues(centers, name, values)[source]

Interpolate the given cell data over the given points

Parameters:
  • centers (list of list of float) – Center coordinates

  • name (str) – Name of the new array

  • values (numpy array) – New values

Returns:

interpValues – interpolated values over the given points

Return type:

npt.NDArray

read(*args, **kwargs)
updateCellLocator()[source]

Set the cell locator

updateMeshProperties()[source]

Read and updates the attributes such as the bounds, number of points and cells

class geos.pygeos_tools.mesh.VtkMesh.VTKSubMesh(meshfile, data, minpos, maxpos, create=True)[source]

Bases: VTKMesh

Class defining a submesh of an existing VTK mesh

meshfile

Submesh filename

Type:

str

vtktype

Format of the VTK submesh

Type:

str

bounds

Real bounds of the mesh (xmin, xmax, ymin, ymax, zmin, zmax)

Type:

tuple of int

numberOfPoints

Total number of points of the submesh

Type:

int

numberOfCells

Total number of cells of the submesh

Type:

int

isSet

Whether or not the mesh properties have been set

Type:

bool

Parameters:
  • meshfile (str) – Submesh filename

  • data (vtk.vtkDataObject) – General representation of the original mesh

  • minpos (3d array-like of float) – Minimal positions for the cropping for each axis

  • maxpos (3d array-like of float) – Maximal positions for the cropping for each axis

  • create (bool) – Whether or not to create the VTKfile Default is True