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[FiniteElement]) – List of finite element objects in the mesh.
line_elements (list[LineElement]) – List of line element objects in the mesh.
triangulation (list[tuple[int, int, int]]) – List of indexes 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.bbox (tuple[float, float, float, float, float, float]) – Bounding box of the model geometry
(xmin, ymin, zmin, xmax, ymax, zmax).
Methods
Checks if the point 1 is relatively close to point 2.
Creates a mesh from geometry using gmsh.
Creates a list of triangle indexes that are used for plotting purposes.
Returns a
FiniteElement
given an element tag.Returns a
LineElement
given an element tag.Returns the node index at or nearest to the point (
x
,y
).Returns a
TaggedLine
given a line tag.Returns a
TaggedLine
closest to the line defined by two points.Returns a
TaggedNode
given a node tag.Returns a
TaggedNode
at or nearest to the point (x
,y
).Returns the number of nodes in the mesh.
Plots the finite element 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:
materials (list[Material]) – A list of
Material
objects for each region in the mesh.embedded_geometry (list[Point | Facet]) – List of embedded points and lines.
mesh_sizes (list[float]) – A list of the characteristic mesh lengths for each region in the mesh.
quad_mesh (bool) – If set to
True
, recombines the triangular mesh to create quadrilaterals.mesh_order (int) – Order of the mesh,
1
- linear or2
- quadratic.serendipity (bool) – If set to
True
, creates serendipity elements for quadrilateral meshes.mesh_algorithm (int) – Gmsh mesh algorithm, see https://gmsh.info/doc/texinfo/gmsh.html#index-Mesh_002eAlgorithm
subdivision_algorithm (int) – Gmsh subdivision algorithm, see https://gmsh.info/doc/texinfo/gmsh.html#index-Mesh_002eSubdivisionAlgorithm
fields (list[Field]) – A list of
Field
objects, describing mesh refinement fields.verbosity (int) – Gmsh verbosity level, see https://gmsh.info/doc/texinfo/gmsh.html#index-General_002eVerbosity. Defaults to
0
.
- save_mesh(materials: list[Material], surface_orientated: list[bool]) None [source]#
Saves the generated gmsh to the
Mesh
object.- Parameters:
- 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:
- 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.
- get_node_idx_by_coordinates(x: float, y: float) int [source]#
Returns the node index at or nearest to the point (
x
,y
).- Parameters:
- Raises:
ValueError – If the point is not close to a node.
- Returns:
Index of the node closest to (
x
,y
).- Return type:
- 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 totag
.- Returns:
Tagged node identified by
tag
.- Return type:
- get_tagged_node_by_coordinates(x: float, y: float) TaggedNode [source]#
Returns a
TaggedNode
at or nearest to the point (x
,y
).- Parameters:
- Raises:
ValueError – If the point is not close to a tagged node.
- Returns:
Tagged node closest to (
x
,y
).- Return type:
- 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 totag
.- Returns:
Tagged line identified by
tag
.- Return type:
- 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:
- Returns:
Tagged line closest to the line defined by two points.
- Return type:
- 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 totag
.- Returns:
Line element identified by
tag
.- Return type:
- 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 totag
.- Returns:
Finite element identified by
tag
.- Return type:
- 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/oruy
is provided. In this case, the undeformed mesh is also plotted withalpha=0.2
andmaterials
is set toFalse
.- 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 toNone
.uy (npt.NDArray[np.float64] | None) – Deformation component in the
y
direction. Defaults toNone
.kwargs (dict[str, Any]) – Other keyword arguments are passed to
plotting_context()
.
- Returns:
Matplotlib axes object.
- Return type: