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'), tol: int = 12)[source]#
Bases:
objectClass describing a geometric region.
Methods
Adds a line load to the geometry.
Adds a line spring to the geometry.
Adds a line support to the geometry.
Adds a node load to the geometry.
Adds a node spring to the geometry.
Adds a node support to the geometry.
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.
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'), 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.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.
- 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_centre(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_section(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_section(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 section. A positive angle leads to a counter-clockwise rotation.
rot_point (tuple[float, float] | str) – Point (
x,y) about which to rotate the section. May also be"center"(rotates about centre 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_section(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:
- add_node_support(point: tuple[float, float], direction: str, value: float = 0.0) NodeSupport[source]#
Adds a node support to the geometry.
- Parameters:
- Returns:
Node support boundary condition object.
- Return type:
Example
TODO.
- add_node_spring(point: tuple[float, float], direction: str, value: float) NodeSpring[source]#
Adds a node spring to the geometry.
- Parameters:
- Returns:
Node spring boundary condition object.
- Return type:
Example
TODO.
- add_node_load(point: tuple[float, float], direction: str, value: float) NodeLoad[source]#
Adds a node load to the geometry.
- Parameters:
- Returns:
Node load boundary condition object.
- Return type:
Example
TODO.
- add_line_support(point1: tuple[float, float], point2: tuple[float, float], direction: str, value: float = 0.0) LineSupport[source]#
Adds a line support to the geometry.
All nodes along the line will have this boundary condition applied.
- Parameters:
point1 (tuple[float, float]) – Point location (
x,y) of the start of the line support.point2 (tuple[float, float]) – Point location (
x,y) of the end of the line support.direction (str) – Direction of the line support, either
"x"or"y".value (float) – Imposed displacement to apply to the line support. Defaults to
0.0, i.e. a fixed line support.
- Returns:
Line support boundary condition object.
- Return type:
Example
TODO.
- add_line_spring(point1: tuple[float, float], point2: tuple[float, float], direction: str, value: float) LineSpring[source]#
Adds a line spring to the geometry.
The spring stiffness is specified per unit length and equivalent nodal springs applied to nodes along this line.
TODO - look into elastic foundation?
- Parameters:
- Returns:
Line spring boundary condition object.
- Return type:
Example
TODO.
- add_line_load(point1: tuple[float, float], point2: tuple[float, float], direction: str, value: float) LineLoad[source]#
Adds a line load to the geometry.
- Parameters:
- Returns:
Line load boundary condition object.
- Return type:
Example
TODO.
- create_mesh(mesh_sizes: float | list[float] = 0.0, linear: bool = True) 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.linear (bool) – Order of the triangular mesh, if
Truegenerates linearTri3elements, ifFalsegenerates quadraticTri6elements. Defaults toTrue.
- Raises:
ValueError – If the length of
mesh_sizesdoes not equal the number of polygons, or is not a float/list of length 1.
- plot_geometry(load_case: LoadCase | None = None, **kwargs: Any) matplotlib.axes.Axes[source]#
Plots the geometry.
Optionally also renders the boundary conditions of a load case if provided.
- Parameters:
load_case (LoadCase | None) – Plots the boundary conditions within a load case if provided. Defaults to
None.kwargs (Any) – See below.
- Keyword Arguments:
title (str) – Plot title. Defaults to
"Geometry".labels (list[str]) – A list of index labels to plot, can contain any of the following:
"points","facets". Defaults to[].legend (bool) – If set to
True, plots the legend. Defaults toTrue.kwargs (dict[str, Any]) – Other keyword arguments are passed to
plotting_context().
- Returns:
Matplotlib axes object.
- Return type:
Example
TODO.
- plot_mesh(load_case: LoadCase | 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.
- Parameters:
load_case (LoadCase | None) – Plots the boundary conditions within a load case if provided. Defaults to
None.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.