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.

param data_length_unit:

Length unit of the mesh data.

param output_length_unit:

Length unit in plots.

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

plot_linesample(x, variable, profile_points, ax, resolution=100, grid=None, **kwargs)#

Plot selected variables obtained from sample_over_polyline function, this function calls to it internally. Values provided in param x and y refer to columns of the DataFrame returned by it.

Parameters:
  • x (str) – Value to be used on x-axis of the plot

  • variable (str | Variable) – Values to be used on y-axis of the plot

  • profile_points (ndarray) – Points defining the profile (and its segments)

  • ax (Axes) – User-created array of Matplotlib axis object

  • resolution (int | None) – Resolution of the sampled profile. Total number of points within all profile segments.

  • resolution – Resolution of the sampled profile. Total number of points within all profile segments.

  • grid (Literal['major', 'both', None]) – Which gridlines should be drawn?

  • kwargs (Any) – Optional keyword arguments passed to matplotlib.pyplot.plot to customize plot options like a line label (for auto legends), linewidth, antialiasing, marker face color.

Returns:

Matplotlib Axes object

Return type:

Axes

plot_linesample_contourf(variables, profile_points, resolution=None, plot_nodal_pts=True, nodal_pts_labels=None)#

Default plot for the data obtained from sampling along a profile on a mesh.

Parameters:
  • variables (str | list | Variable) – Variables to be read from the mesh

  • profile_points (ndarray) – Points defining the profile (and its segments)

  • resolution (int | None) – Resolution of the sampled profile. Total number of points within all profile segments.

  • plot_nodal_pts (bool | None) – Plot and annotate all nodal points in profile

  • nodal_pts_labels (str | list | None) – Labels for nodal points (only use if plot_nodal_points is set to True)

Returns:

Tuple containing Matplotlib Figure and Axis objects

Return type:

tuple[Figure, Axes]

to_ip_mesh()[source]#

Create a mesh with cells centered around integration points.

Return type:

Mesh

to_ip_point_cloud()[source]#

Convert integration point data to a pyvista point cloud.

Return type:

Mesh

__init__(pv_mesh=None, spatial_unit='m', spatial_output_unit='m', **kwargs)[source]#

Initialize a Mesh object

param pv_mesh:

Underlying pyvista mesh.

param data_length_unit:

Length unit of the mesh data.

param output_length_unit:

Length unit in plots.

classmethod read(filepath, spatial_unit='m', spatial_output_unit='m')[source]#

Initialize a Mesh object

param filepath:

Path to the mesh or shapefile file.

param data_length_unit:

Spatial data unit of the mesh.

param output_length_unit:

Spatial output unit of the mesh.

returns:

A Mesh object

Return type:

Mesh

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