Geometry#
- class planestress.pre.geometry.Geometry(polygons: Polygon | MultiPolygon, materials: Material | list[Material] = Material(name='default', elastic_modulus=1.0, poissons_ratio=0.0, thickness=1.0, density=1.0, color='w'), embedded_geometry: list[Point | Facet] | None = None, tol: int = 12)[source]#
Bases:
objectClass describing a geometric region.
Methods
Aligns the centroid of the geometry to another
Geometry, point or origin.Aligns the geometry to another
Geometryobject or point.Calculates the area of the geometry.
Calculates the centroid of the geometry.
Calculate geometry extents.
Creates points, facets and holes from shapely geometry.
Creates points, facets and holes given a
Polygon.Creates a closed list of facets from a list of points.
Creates and stores a triangular mesh of the geometry.
Embeds a point into the mesh.
Embeds a point into the mesh.
Filters shapely geometries to return only polygons.
Mirrors the geometry about a point on either the
xoryaxis.Plots the geometry.
Plots the finite element mesh.
Rotates the geometry by an
angleabout arot_point.Shifts the geometry by (
x,y).- __init__(polygons: Polygon | MultiPolygon, materials: Material | list[Material] = Material(name='default', elastic_modulus=1.0, poissons_ratio=0.0, thickness=1.0, density=1.0, color='w'), embedded_geometry: list[Point | Facet] | None = None, tol: int = 12) None[source]#
Inits the Geometry class.
Note
Length of
materialsmust equal the number ofpolygons, i.e.len(polygons.geoms).- Parameters:
polygons (Polygon | MultiPolygon) – A
shapely.Polygonorshapely.MultiPolygondescribing the geometry. AMultiPolygoncomprises of a list ofPolygonobjects, that can describe a geometry with multiple distinct regions.materials (Material | list[Material]) – A list of
Materialobjects describing the material properties of eachpolygonwithin the geometry. If a singleplanestress.pre.Materialis supplied, this material is applied to all regions. Defaults toDEFAULT_MATERIAL, i.e. a material with unit properties and a Poisson’s ratio of zero.embedded_geometry (list[Point | Facet] | None) – List of
PointorFacetobjects to embed into the mesh. Can also be added by using theembed_point()orembed_line()methods. Defaults toNone.tol (int) – The points in the geometry get rounded to
toldigits. Defaults to12.
- Raises:
ValueError – If the number of
materialsdoes not equal the number ofpolygons.
Example
TODO.
- compile_polygon(polygon: Polygon, poly_idx: int, loop_idx: int) tuple[list[Point], list[Facet], list[Point], int][source]#
Creates points, facets and holes given a
Polygon.
- create_facet_list(pt_list: list[Point], loop_idx: int) tuple[list[Facet], CurveLoop][source]#
Creates a closed list of facets from a list of points.
- embed_point(x: float, y: float, mesh_size: float | None = None) None[source]#
Embeds a point into the mesh.
- Parameters:
- Raises:
ValueError – If the point does not lie within any polygons.
Warning
Ensure that embedded points lie within the meshed region and are not located within any holes in the mesh.
Further, due to floating point precision errors, it is recommended that embedded points are also not placed on the edges of polygons.
Note, not all the above conditions are checked.
- embed_line(point1: tuple[float, float], point2: tuple[float, float], mesh_size: float | None = None) None[source]#
Embeds a point into the mesh.
- Parameters:
point1 (tuple[float, float]) – Point location (
x,y) of the start of the embedded line.point2 (tuple[float, float]) – Point location (
x,y) of the end of the embedded line.mesh_size (float | None) – Optional mesh size along the embedded line. If not provided takes the mesh size of the polygon the line is embedded into. Defaults to
None.
- Raises:
ValueError – If one of the points does not lie within any polygons.
ValueError – If the points lie within different polygons.
Warning
Ensure that embedded lines lie within the meshed region and are not located within any holes in the mesh.
Due to floating point precision errors, it is recommended that embedded lines do not touch the edges of polygons.
Embedded lines should not cross any other embedded lines or geometry, i.e. should not cross from one polygon to another.
Note, not all the above conditions are checked.
- calculate_area() float[source]#
Calculates the area of the geometry.
- Returns:
Geometry area
- Return type:
- calculate_extents() tuple[float, float, float, float][source]#
Calculate geometry extents.
Calculates the minimum and maximum
xandyvalues amongst the list of points, i.e. the points that describe the bounding box of theGeometryinstance.
- align_to(other: Geometry | tuple[float, float], on: str, inner: bool = False) Geometry[source]#
Aligns the geometry to another
Geometryobject or point.Returns a new
Geometryobject, representingselftranslated so that is aligned on one of the outer or inner bounding box edges ofother.- Parameters:
- Returns:
New
Geometryobject aligned toother.- Return type:
Example
TODO.
- align_center(align_to: Geometry | tuple[float, float] | None = None) Geometry[source]#
Aligns the centroid of the geometry to another
Geometry, point or origin.Returns a new
Geometryobject, translated such that its centroid is aligned to the centroid of anotherGeometry, a point, or the origin.- Parameters:
align_to (Geometry | tuple[float, float] | None) – Location to align the centroid to, either another
Geometryobject, a point (x,y) orNone. Defaults toNone(i.e. align to the origin).- Raises:
ValueError – If
align_tois not a valid input.- Returns:
New
Geometryobject aligned toalign_to.- Return type:
Example
TODO.
- shift_geometry(x: float = 0.0, y: float = 0.0) Geometry[source]#
Shifts the geometry by (
x,y).- Parameters:
- Returns:
New
Geometryobject shifted by (x,y).- Return type:
Example
TODO.
- rotate_geometry(angle: float, rot_point: tuple[float, float] | str = 'center', use_radians: bool = False) Geometry[source]#
Rotates the geometry by an
angleabout arot_point.- Parameters:
angle (float) – Angle by which to rotate the geometry. A positive angle leads to a counter-clockwise rotation.
rot_point (tuple[float, float] | str) – Point (
x,y) about which to rotate the geometry. May also be"center"(rotates about center of bounding box) or “centroid” (rotates about centroid). Defaults to"center".use_radians (bool) – If True,
angleis in radians, ifFalseangle is in degrees. Defaults toFalse.
- Returns:
New
Geometryobject rotated byangleaboutrot_point.- Return type:
Example
TODO.
- mirror_geometry(axis: str = 'x', mirror_point: tuple[float, float] | str = 'center') Geometry[source]#
Mirrors the geometry about a point on either the
xoryaxis.- Parameters:
- Raises:
ValueError – If
axisis not"x"or"y".- Returns:
New
Geometryobject mirrored aboutmirror_pointonaxis.- Return type:
Example
TODO.
- __or__(other: Geometry) Geometry[source]#
Performs a union operation using the
|operator.Note
The material of the first geometry is applied to the entire region of the “unioned” geometry. Keeps the smallest value of
tolbetween the two geometries.- Parameters:
other (Geometry) –
Geometryobject to union with.- Raises:
ValueError – If
shapelyis unable to perform the union.- Returns:
New
Geometryobject unioned withother.- Return type:
Example
TODO.
- __sub__(other: Geometry) Geometry[source]#
Performs a difference operation using the
-operator.Warning
If
selforothercontains multiple regions, these regions may be combined into one region after the difference operation. It is recommended to first perform difference operations onPolygonobjects, and later combine into intoshapely.MultiPolygonobjects, see the example below. Check the assignment of materials after a difference operation.- Parameters:
other (Geometry) –
Geometryobject to difference with.- Raises:
ValueError – If
shapelyis unable to perform the difference.- Returns:
New
Geometryobject differenced withother.- Return type:
Example
TODO. Use brackets to show order of operations important!
- __add__(other: Geometry) Geometry[source]#
Performs an addition operation using the
+operator.Note
The smallest value of
tolis applied to both geometries.- Parameters:
other (Geometry) –
Geometryobject to add to.- Returns:
New
Geometryobject added withother.- Return type:
Example
TODO.
- __and__(other: Geometry) Geometry[source]#
Performs an intersection operation using the
&operator.Note
The material of the first geometry is applied to the entire region of the “intersected” geometry. Keeps the smallest value of
tolbetween the two geometries.- Parameters:
other (Geometry) –
Geometryobject to intersection with.- Raises:
ValueError – If
shapelyis unable to perform the intersection.- Returns:
New
Geometryobject intersected withother.- Return type:
Example
TODO.
- static filter_non_polygons(input_geom: GeometryCollection | LineString | Point | Polygon | MultiPolygon) Polygon | MultiPolygon[source]#
Filters shapely geometries to return only polygons.
Returns a
Polygonor aMultiPolygonrepresenting any suchPolygonorMultiPolygonthat may exist in theinput_geom. Ifinput_geomis aLineStringorPoint, an emptyPolygonis returned.- Parameters:
input_geom (GeometryCollection | LineString | Point | Polygon | MultiPolygon) – Shapely geometry to filter
- Returns:
Filtered polygon
- Return type:
- create_mesh(mesh_sizes: float | list[float] = 0.0, quad_mesh: bool = False, mesh_order: int = 1, serendipity: bool = False, mesh_algorithm: int = 6, subdivision_algorithm: int = 0, fields: list[Field] | None = None) None[source]#
Creates and stores a triangular mesh of the geometry.
- Parameters:
mesh_sizes (float | list[float]) – A list of the characteristic mesh lengths for each
polygonin theGeometryobject. If a list of length 1 or afloati passed, then this one size will be applied to allpolygons. A value of0removes the area constraint. Defaults to0.0.quad_mesh (bool) – If set to
True, recombines the triangular mesh to create quadrilaterals. Defaults toFalse.mesh_order (int) – Order of the mesh,
1- linear or2- quadratic. Defaults to1.serendipity (bool) – If set to
True, creates serendipity elements for quadrilateral meshes, i.e. creates"Quad8"elements instead of"Quad9"elements. Defaults toFalse.mesh_algorithm (int) – Gmsh meshing algorithm, see below for more details. Defaults to
6.subdivision_algorithm (int) – Gmsh subdivision algorithm, see below for more details. Defaults to
0.fields (list[Field] | None) – A list of
Fieldobjects, describing mesh refinement fields.
- Raises:
ValueError – If the length of
mesh_sizesdoes not equal the number of polygons, or is not a float/list of length 1.
mesh_algorithmTODO - information about meshing algorithm.
subdivision_algorithmTODO - information about subdivision algorithm.
- plot_geometry(analysis_case: AnalysisCase | None = None, **kwargs: Any) matplotlib.axes.Axes[source]#
Plots the geometry.
Optionally also renders the boundary conditions of an analysis case if provided.
- Parameters:
analysis_case (AnalysisCase | None) – Plots the boundary conditions within an analysis case if provided. Defaults to
None.kwargs (Any) – See below.
- Keyword Arguments:
title (str) – Plot title. Defaults to
"Geometry".tags (list[str]) – A list of tags to plot, can contain any of the following:
"points","facets". Defaults to[].legend (bool) – If set to
True, plots the legend. Defaults toTrue.bc_text (bool) – If set to
True, plots the values of the boundary conditions. Defaults toFalse.bc_fmt (str) – Boundary condition text formatting string. Defaults to
".3e".arrow_length_scale (float) – Arrow length scaling factor. Defaults to
0.1.arrow_width_scale (float) – Arrow width scaling factor. Defaults to
0.003.support_scale (float) – Support scaling factor. Defaults to
0.03.num_supports (int) – Number of line supports to plot internally. Defaults to
1.kwargs (dict[str, Any]) – Other keyword arguments are passed to
plotting_context().
- Returns:
Matplotlib axes object.
- Return type:
Example
TODO.
- plot_mesh(**kwargs: Any) matplotlib.axes.Axes[source]#
Plots the finite element mesh.
- Parameters:
kwargs (Any) – See below.
- Keyword Arguments:
title (str) – Plot title. Defaults to
"Finite Element Mesh".materials (bool) – If set to
Trueshades the elements with the specified material colors. Defaults toTrue.node_indexes (bool) – If set to
True, plots the indexes of each node. Defaults toFalse.element_indexes (bool) – If set to
True, plots the indexes of each element. Defaults toFalse.alpha (float) – Transparency of the mesh outlines, \(0 \leq \alpha \leq 1\). Defaults to
0.5.kwargs (dict[str, Any]) – Other keyword arguments are passed to
plotting_context().
- Raises:
RuntimeError – If a mesh has not yet been generated.
- Returns:
Matplotlib axes object.
- Return type:
Example
TODO.