Mesh#
- class planestress.pre.mesh.Mesh[source]#
Bases:
objectClass 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.STRtreeof the nodes in the mesh.tagged_nodes_str_tree (shapely.STRtree) – A
shapely.STRtreeof the tagged nodes in the mesh.tagged_lines_str_tree (shapely.STRtree) – A
shapely.STRtreeof the tagged lines in the mesh.
Methods
Creates a mesh from geometry using gmsh.
Creates a list of triangle indices that are used for plotting purposes.
Returns a
FiniteElementgiven an element tag.Returns a
LineElementgiven an element tag.Returns the node index at or nearest to the point (
x,y).Returns a
TaggedLinegiven a line tag.Returns a
TaggedLineclosest to the line defined by two points.Returns a
TaggedNodegiven a node tag.Returns a
TaggedNodeat 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
Meshobject.Attributes
nodeselementsline_elementstriangulationmaterialstagged_nodestagged_linesnodes_str_treetagged_nodes_str_treetagged_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:
mesh_sizes (list[float]) – A list of the characteristic mesh lengths for each region in the mesh.
materials (list[Material]) – A list of
Materialobjects for each region in the mesh.verbosity (int) – Gmsh verbosity level, see https://gmsh.info/doc/texinfo/gmsh.html#index-General_002eVerbosity. Defaults to
0.
- save_mesh(materials: list[Material]) None[source]#
Saves the generated gmsh to the
Meshobject.- Parameters:
- 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:
- get_node_idx_by_coordinates(x: float, y: float) int[source]#
Returns the node index at or nearest to the point (
x,y).
- get_tagged_node(tag: int) TaggedNode[source]#
Returns a
TaggedNodegiven a node tag.- Parameters:
tag (int) – Node tag.
- Raises:
ValueError – If there is no
TaggedNodewith 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
TaggedNodeat or nearest to the point (x,y).- Parameters:
- Returns:
Tagged node closest to (
x,y).- Return type:
- get_tagged_line(tag: int) TaggedLine[source]#
Returns a
TaggedLinegiven a line tag.- Parameters:
tag (int) – Line tag.
- Raises:
ValueError – If there is no
TaggedLinewith 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
TaggedLineclosest to the line defined by two points.
- get_line_element_by_tag(tag: int) LineElement[source]#
Returns a
LineElementgiven an element tag.- Parameters:
tag (int) – Line element tag.
- Raises:
ValueError – If there is no
LineElementwith a tag equal totag.- Returns:
Line element identified by
tag.- Return type:
- get_finite_element_by_tag(tag: int) FiniteElement[source]#
Returns a
FiniteElementgiven an element tag.- Parameters:
tag (int) – Finite element tag.
- Raises:
ValueError – If there is no
FiniteElementwith a tag equal totag.- Returns:
Finite element identified by
tag.- Return type:
- 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
uxand/oruyis provided. In this case, the undeformed mesh is also plotted withalpha=0.2,materialsis set toFalseandload_caseis set toNone.- 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
Trueshades 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
xdirection. Defaults toNone.uy (npt.NDArray[np.float64] | None) – Deformation component in the
ydirection. Defaults toNone.kwargs (dict[str, Any]) – Other keyword arguments are passed to
plotting_context().
- Returns:
Matplotlib axes object.
- Return type: