Mesh#

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

Bases: object

Class for a plane-stress mesh.

Variables:

Methods

check_nearest_tol

Checks if the point 1 is relatively close to point 2.

create_mesh

Creates a mesh from geometry using gmsh.

create_triangulation

Creates a list of triangle indexes 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

bbox

create_mesh(points: list[Point], facets: list[Facet], curve_loops: list[CurveLoop], surfaces: list[Surface], materials: list[Material], embedded_geometry: list[Point | Facet], mesh_sizes: list[float], quad_mesh: bool, mesh_order: int, serendipity: bool, mesh_algorithm: int, subdivision_algorithm: int, fields: list[Field], verbosity: int = 0) None[source]#

Creates a mesh from geometry using gmsh.

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

Saves the generated gmsh to the Mesh object.

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

  • surface_orientated (list[bool]) – List describing if surface is correctly oriented.

Raises:

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

create_triangulation() None[source]#

Creates a list of triangle indexes 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

check_nearest_tol(point1: tuple[float, float], point2: tuple[float, float]) bool[source]#

Checks if the point 1 is relatively close to point 2.

The acceptable tolerance is taken to be 1% of the minimum dimension of the bounding box.

Parameters:
Returns:

True if point 1 is relatively close to point 2.

Return type:

bool

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.

Raises:

ValueError – If the point is not close to a node.

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.

Raises:

ValueError – If the point is not close to a tagged node.

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.

Raises:

ValueError – If the line is not close to a tagged line.

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(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.

Plots a deformed mesh if ux and/or uy is provided. In this case, the undeformed mesh is also plotted with alpha=0.2 and materials is set to False.

Parameters:
  • 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