ogstools.meshlib.mesh module#
- class ogstools.meshlib.mesh.Mesh[source]#
Bases:
UnstructuredGrid
A wrapper around pyvista.UnstructuredGrid.
Contains additional data and functions mainly for postprocessing.
Initialize a Mesh object
- param pv_mesh:
Underlying pyvista mesh.
- filepath: Path | None = None#
- difference(subtract_mesh, variable=None)#
Compute the difference of variables between two meshes.
- Parameters:
subtract_mesh (Mesh) – The mesh whose data is to be subtracted.
variable (Variable | str | None) – The variable of interest. If not given, all point and cell_data will be processed raw.
- Returns:
A new mesh containing the difference of variable or of all datasets between both meshes.
- Return type:
Mesh
- depth(use_coords=False)#
Returns the depth values of the mesh.
For 2D, the last axis of the plane wherein the mesh is lying is used as the vertical axis (i.e. y if the mesh is in the xy-plane, z if it is in the xz-plane), for 3D, the z-axes is used. If use_coords is True, returns the negative coordinate value of the vertical axis. Otherwise, the vertical distance to the top facing edges surfaces are returned.
- Return type:
ndarray
- p_fluid()#
Return the fluid pressure in the mesh.
If “depth” is given in the mesh’s point _data, it is used return a hypothetical water column defined as:
\[p_{fl} = 1000 \frac{kg}{m^3} 9.81 \frac{m}{s^2} h\]where h is the depth below surface. Otherwise, If “pressure” is given in the mesh, return the “pressure” data of the mesh. If that is also not the case, the hypothetical water column from above is returned with the depth being calculated via
ogstools.meshlib.geo.depth()
.- Return type:
PlainQuantity
- plot_contourf(variable, fig=None, ax=None, **kwargs)#
Plot the variable field of meshes with default settings.
The resulting figure adheres to the configurations in plot.setup. For 2D, the whole domain, for 3D a set of slices is displayed.
- Parameters:
variable (Variable | str) – The field to be visualized on all meshes
fig (Figure | None) – matplotlib figure to use for plotting
ax (Axes | None) – matplotlib axis to use for plotting
- Keyword Arguments:
cb_labelsize: colorbar labelsize
cb_loc: colorbar location (‘left’ or ‘right’)
cb_pad: colorbar padding
cmap: colormap
dpi: resolution
figsize: figure size
fontsize size for labels and captions
levels: user defined levels
log_scaled: logarithmic scaling
show_edges: show element edges
show_max: mark the location of the maximum value
show_min: mark the location of the minimum value
show_region_bounds: show the edges of the different regions
vmin: minimum value
vmax: maximum value
- Return type:
Figure | None
- plot_quiver(ax, variable, projection=None, glyph_type='arrow')#
Plot arrows or lines corresponding to vectors on a matplotlib axis.
- Parameters:
ax (Axes) – Matplotlib axis to plot onto
variable (Vector) – Vector variable to visualize
projection (int | None) – Index of flat dimension (e.g. 2 for z axis), gets automatically determined if not given
glyph_type (Literal['arrow', 'line']) – Whether to plot arrows or lines.
- plot_streamlines(ax, variable, projection=None)#
Plot the vector streamlines on a matplotlib axis.
- Parameters:
ax (Axes) – Matplotlib axis to plot onto
variable (Vector) – Vector variable to visualize
projection (int | None) – Index of flat dimension (e.g. 2 for z axis), gets automatically determined if not given
- __init__(pv_mesh=None, **kwargs)[source]#
Initialize a Mesh object
- param pv_mesh:
Underlying pyvista mesh.
- classmethod read(filepath)[source]#
Initialize a Mesh object
- param filepath:
Path to the mesh or shapefile file.
- returns:
A Mesh object
- Return type:
- classmethod read_shape(simplify=False, mesh_generator='triangle', cellsize=None)#
Generate a pyvista Unstructured grid from a shapefile.
- Parameters:
simplify (bool) – With the Douglas-Peucker algorithm the geometry is simplified. The original line is split into smaller parts. All points with a distance smaller than half the cellsize are removed. Endpoints are preserved. More infos at https://geopandas.org/en/stable/docs/reference/api/geopandas.GeoSeries.simplify.html.
mesh_generator (str) – Choose between ‘triangle’ and ‘gmsh’ to generate the mesh.
cellsize (int | None) – Size of the cells in the mesh - only needed for simplify algorithm. If None - cellsize is 1/100 of larger bound (x or y).
- Returns:
pv.UnstructuredGrid
- Return type:
UnstructuredGrid