Mesh#

class planestress.pre.mesh.Mesh[source]#

Bases: object

Class for a plane-stress mesh.

Variables:
  • nodes (npt.NDArray[np.float64]) – List of nodes describing the mesh, e.g. [[x1, y1], [x2, y2], ... ].

  • elements (list[fe.FiniteElement]) – List of finite element objects in the mesh.

  • line_elements (list[fe.LineElement]) – List of line element objects in the mesh.

  • triangulation (list[tuple[int, int, int]]) – List of indices defining the triangles in the mesh (quads & higher order elements converted to triangles) for plotting purposes.

  • materials (list[Material]) – List of material objects for each region in the mesh.

  • tagged_nodes (list[TaggedNode]) – List of nodes tagged in the mesh.

  • tagged_lines (list[TaggedLine]) – List of lines tagged in the mesh.

  • nodes_str_tree (shapely.STRtree) – A shapely.STRtree of the nodes in the mesh.

  • tagged_nodes_str_tree (shapely.STRtree) – A shapely.STRtree of the tagged nodes in the mesh.

  • tagged_lines_str_tree (shapely.STRtree) – A shapely.STRtree of the tagged lines in the mesh.

Methods

create_mesh

Creates a mesh from geometry using gmsh.

create_triangulation

Creates a list of triangle indices that are used for plotting purposes.

get_finite_element_by_tag

Returns a FiniteElement given an element tag.

get_line_element_by_tag

Returns a LineElement given an element tag.

get_node_idx_by_coordinates

Returns the node index at or nearest to the point (x, y).

get_tagged_line

Returns a TaggedLine given a line tag.

get_tagged_line_by_coordinates

Returns a TaggedLine closest to the line defined by two points.

get_tagged_node

Returns a TaggedNode given a node tag.

get_tagged_node_by_coordinates

Returns a TaggedNode at or nearest to the point (x, y).

num_nodes

Returns the number of nodes in the mesh.

plot_mesh

Plots the finite element mesh.

save_mesh

Saves the generated gmsh to the Mesh object.

Attributes

nodes

elements

line_elements

triangulation

materials

tagged_nodes

tagged_lines

nodes_str_tree

tagged_nodes_str_tree

tagged_lines_str_tree

create_mesh(points: list[Point], facets: list[Facet], curve_loops: list[CurveLoop], surfaces: list[Surface], mesh_sizes: list[float], materials: list[Material], verbosity: int = 0) None[source]#

Creates a mesh from geometry using gmsh.

Parameters:
save_mesh(materials: list[Material]) None[source]#

Saves the generated gmsh to the Mesh object.

Parameters:

materials (list[Material]) – List of material objects.

Raises:
  • ValueError – If there is an unsupported gmsh element type in the mesh.

  • NotImplementedError – If an element in the mesh is yet to be implemented.

create_triangulation() None[source]#

Creates a list of triangle indices that are used for plotting purposes.

Elements that are not three-noded triangles need to be further subdivided into triangles to allow for the use of triangular plotting functions in post-processing.

num_nodes() int[source]#

Returns the number of nodes in the mesh.

Returns:

Number of nodes in the mesh.

Return type:

int

get_node_idx_by_coordinates(x: float, y: float) int[source]#

Returns the node index at or nearest to the point (x, y).

Parameters:
  • x (float) – x location of the node to find.

  • y (float) – y location of the node to find.

Returns:

Index of the node closest to (x, y).

Return type:

int

get_tagged_node(tag: int) TaggedNode[source]#

Returns a TaggedNode given a node tag.

Parameters:

tag (int) – Node tag.

Raises:

ValueError – If there is no TaggedNode with a tag equal to tag.

Returns:

Tagged node identified by tag.

Return type:

TaggedNode

get_tagged_node_by_coordinates(x: float, y: float) TaggedNode[source]#

Returns a TaggedNode at or nearest to the point (x, y).

Parameters:
  • x (float) – x location of the tagged node to find.

  • y (float) – y location of the tagged node to find.

Returns:

Tagged node closest to (x, y).

Return type:

TaggedNode

get_tagged_line(tag: int) TaggedLine[source]#

Returns a TaggedLine given a line tag.

Parameters:

tag (int) – Line tag.

Raises:

ValueError – If there is no TaggedLine with a tag equal to tag.

Returns:

Tagged line identified by tag.

Return type:

TaggedLine

get_tagged_line_by_coordinates(point1: tuple[float, float], point2: tuple[float, float]) TaggedLine[source]#

Returns a TaggedLine closest to the line defined by two points.

Parameters:
  • point1 (tuple[float, float]) – First point (x, y) of the tagged line to find.

  • point2 (tuple[float, float]) – Second point (x, y) of the tagged line to find.

Returns:

Tagged line closest to the line defined by two points.

Return type:

TaggedLine

get_line_element_by_tag(tag: int) LineElement[source]#

Returns a LineElement given an element tag.

Parameters:

tag (int) – Line element tag.

Raises:

ValueError – If there is no LineElement with a tag equal to tag.

Returns:

Line element identified by tag.

Return type:

LineElement

get_finite_element_by_tag(tag: int) FiniteElement[source]#

Returns a FiniteElement given an element tag.

Parameters:

tag (int) – Finite element tag.

Raises:

ValueError – If there is no FiniteElement with a tag equal to tag.

Returns:

Finite element identified by tag.

Return type:

FiniteElement

plot_mesh(load_case: LoadCase | None, title: str, materials: bool, node_indexes: bool, element_indexes: bool, alpha: float, ux: npt.NDArray[np.float64] | None = None, uy: npt.NDArray[np.float64] | None = None, **kwargs: Any) matplotlib.axes.Axes[source]#

Plots the finite element mesh.

Optionally also renders the boundary conditions of a load case if provided. Also plots a deformed mesh if ux and/or uy is provided. In this case, the undeformed mesh is also plotted with alpha=0.2, materials is set to False and load_case is set to None.

Parameters:
  • load_case (LoadCase | None) – Plots the boundary conditions within a load case if provided. Defaults to None.

  • title (str) – Plot title.

  • materials (bool) – If set to True shades the elements with the specified material colors.

  • node_indexes (bool) – If set to True, plots the indexes of each node.

  • element_indexes (bool) – If set to True, plots the indexes of each element.

  • alpha (float) – Transparency of the mesh outlines, \(0 \leq \alpha \leq 1\).

  • ux (npt.NDArray[np.float64] | None) – Deformation component in the x direction. Defaults to None.

  • uy (npt.NDArray[np.float64] | None) – Deformation component in the y direction. Defaults to None.

  • kwargs (dict[str, Any]) – Other keyword arguments are passed to plotting_context().

Returns:

Matplotlib axes object.

Return type:

matplotlib.axes.Axes