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: object

Class describing a geometric region.

Methods

add_line_load

Adds a line load to the geometry.

add_line_spring

Adds a line spring to the geometry.

add_line_support

Adds a line support to the geometry.

add_node_load

Adds a node load to the geometry.

add_node_spring

Adds a node spring to the geometry.

add_node_support

Adds a node support to the geometry.

align_centre

Aligns the centroid of the geometry to another Geometry, point or origin.

align_to

Aligns the geometry to another Geometry object or point.

calculate_area

Calculates the area of the geometry.

calculate_centroid

Calculates the centroid of the geometry.

calculate_extents

Calculate geometry extents.

compile_geometry

Creates points, facets and holes from shapely geometry.

compile_polygon

Creates points, facets and holes given a Polygon.

create_facet_list

Creates a closed list of facets from a list of points.

create_mesh

Creates and stores a triangular mesh of the geometry.

filter_non_polygons

Filters shapely geometries to return only polygons.

mirror_section

Mirrors the geometry about a point on either the x or y axis.

plot_geometry

Plots the geometry.

plot_mesh

Plots the finite element mesh.

rotate_section

Rotates the geometry by an angle about a rot_point.

shift_section

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 materials must equal the number of polygons, i.e. len(polygons.geoms).

Parameters:
  • polygons (Polygon | MultiPolygon) – A shapely.Polygon or shapely.MultiPolygon describing the geometry. A MultiPolygon comprises of a list of Polygon objects, that can describe a geometry with multiple distinct regions.

  • materials (Material | list[Material]) – A list of Material objects describing the material properties of each polygon within the geometry. If a single planestress.pre.Material is supplied, this material is applied to all regions. Defaults to DEFAULT_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 tol digits. Defaults to 12.

Raises:

ValueError – If the number of materials does not equal the number of polygons.

Example

TODO.

compile_geometry() None[source]#

Creates points, facets and holes from shapely geometry.

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.

Parameters:
  • polygon (Polygon) – A Polygon object.

  • poly_idx (int) – Polygon index.

  • loop_idx (int) – Loop index.

Returns:

A list of points, facets, and holes, and the current loop index (points, facets, holes, loop_idx).

Return type:

tuple[list[Point], list[Facet], list[Point], int]

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.

Parameters:
  • pt_list (list[Point]) – List of points.

  • loop_idx (int) – Loop index.

Returns:

Closed list of facets and curve loop.

Return type:

tuple[list[Facet], CurveLoop]

calculate_area() float[source]#

Calculates the area of the geometry.

Returns:

Geometry area

Return type:

float

calculate_centroid() tuple[float, float][source]#

Calculates the centroid of the geometry.

Returns:

Geometry centroid

Return type:

tuple[float, float]

calculate_extents() tuple[float, float, float, float][source]#

Calculate geometry extents.

Calculates the minimum and maximum x and y values amongst the list of points, i.e. the points that describe the bounding box of the Geometry instance.

Returns:

Minimum and maximum x and y values (x_min, x_max, y_min, y_max)

Return type:

tuple[float, float, float, float]

align_to(other: Geometry | tuple[float, float], on: str, inner: bool = False) Geometry[source]#

Aligns the geometry to another Geometry object or point.

Returns a new Geometry object, representing self translated so that is aligned on one of the outer or inner bounding box edges of other.

Parameters:
  • other (Geometry | tuple[float, float]) – A Geometry or point (x, y) to align to.

  • on (str) – Which side of other to align to, either “left”, “right”, “bottom”, or “top”.

  • inner (bool) – If True, aligns to the inner bounding box edge of other. Defaults to False.

Returns:

New Geometry object aligned to other.

Return type:

Geometry

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 Geometry object, translated such that its centroid is aligned to the centroid of another Geometry, a point, or the origin.

Parameters:

align_to (Geometry | tuple[float, float] | None) – Location to align the centroid to, either another Geometry object, a point (x, y) or None. Defaults to None (i.e. align to the origin).

Raises:

ValueError – If align_to is not a valid input.

Returns:

New Geometry object aligned to align_to.

Return type:

Geometry

Example

TODO.

shift_section(x: float = 0.0, y: float = 0.0) Geometry[source]#

Shifts the geometry by (x, y).

Parameters:
  • x (float) – Distance to shift along the x axis. Defaults to 0.0.

  • y (float) – Distance to shift along the y axis. Defaults to 0.0.

Returns:

New Geometry object shifted by (x, y).

Return type:

Geometry

Example

TODO.

rotate_section(angle: float, rot_point: tuple[float, float] | str = 'center', use_radians: bool = False) Geometry[source]#

Rotates the geometry by an angle about a rot_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, angle is in radians, if False angle is in degrees. Defaults to False.

Returns:

New Geometry object rotated by angle about rot_point.

Return type:

Geometry

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 x or y axis.

Parameters:
  • axis (str) – Mirror axis, may be "x" or "y". Defaults to "x".

  • mirror_point (tuple[float, float] | str) – Point (x, y) about which to mirror the section. May also be "center" (mirrors about centre of bounding box) or “centroid” (mirrors about centroid). Defaults to "center".

Raises:

ValueError – If axis is not "x" or "y".

Returns:

New Geometry object mirrored about mirror_point on axis.

Return type:

Geometry

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 tol between the two geometries.

Parameters:

other (Geometry) – Geometry object to union with.

Raises:

ValueError – If shapely is unable to perform the union.

Returns:

New Geometry object unioned with other.

Return type:

Geometry

Example

TODO.

__sub__(other: Geometry) Geometry[source]#

Performs a difference operation using the - operator.

Warning

If self or other contains multiple regions, these regions may be combined into one region after the difference operation. It is recommended to first perform difference operations on Polygon objects, and later combine into into shapely.MultiPolygon objects, see the example below. Check the assignment of materials after a difference operation.

Parameters:

other (Geometry) – Geometry object to difference with.

Raises:

ValueError – If shapely is unable to perform the difference.

Returns:

New Geometry object differenced with other.

Return type:

Geometry

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 tol is applied to both geometries.

Parameters:

other (Geometry) – Geometry object to add to.

Returns:

New Geometry object added with other.

Return type:

Geometry

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 tol between the two geometries.

Parameters:

other (Geometry) – Geometry object to intersection with.

Raises:

ValueError – If shapely is unable to perform the intersection.

Returns:

New Geometry object intersected with other.

Return type:

Geometry

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 Polygon or a MultiPolygon representing any such Polygon or MultiPolygon that may exist in the input_geom. If input_geom is a LineString or Point, an empty Polygon is returned.

Parameters:

input_geom (GeometryCollection | LineString | Point | Polygon | MultiPolygon) – Shapely geometry to filter

Returns:

Filtered polygon

Return type:

Polygon | MultiPolygon

add_node_support(point: tuple[float, float], direction: str, value: float = 0.0) NodeSupport[source]#

Adds a node support to the geometry.

Parameters:
  • point (tuple[float, float]) – Point location (x, y) of the node support.

  • direction (str) – Direction of the node support, either "x" or "y".

  • value (float) – Imposed displacement to apply to the node support. Defaults to 0.0, i.e. a fixed node support.

Returns:

Node support boundary condition object.

Return type:

NodeSupport

Example

TODO.

add_node_spring(point: tuple[float, float], direction: str, value: float) NodeSpring[source]#

Adds a node spring to the geometry.

Parameters:
  • point (tuple[float, float]) – Point location (x, y) of the node spring.

  • direction (str) – Direction of the node spring, either "x" or "y".

  • value (float) – Spring stiffness.

Returns:

Node spring boundary condition object.

Return type:

NodeSpring

Example

TODO.

add_node_load(point: tuple[float, float], direction: str, value: float) NodeLoad[source]#

Adds a node load to the geometry.

Parameters:
  • point (tuple[float, float]) – Point location (x, y) of the node load.

  • direction (str) – Direction of the node load, either "x" or "y".

  • value (float) – Node load.

Returns:

Node load boundary condition object.

Return type:

NodeLoad

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:

LineSupport

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:
  • point1 (tuple[float, float]) – Point location (x, y) of the start of the line spring.

  • point2 (tuple[float, float]) – Point location (x, y) of the end of the line spring.

  • direction (str) – Direction of the line spring, either "x" or "y".

  • value (float) – Spring stiffness per unit length.

Returns:

Line spring boundary condition object.

Return type:

LineSpring

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:
  • point1 (tuple[float, float]) – Point location (x, y) of the start of the line load.

  • point2 (tuple[float, float]) – Point location (x, y) of the end of the line load.

  • direction (str) – Direction of the node load, either "x" or "y".

  • value (float) – Line load per unit length.

Returns:

Line load boundary condition object.

Return type:

LineLoad

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 polygon in the Geometry object. If a list of length 1 or a float i passed, then this one size will be applied to all polygons. A value of 0 removes the area constraint. Defaults to 0.0.

  • linear (bool) – Order of the triangular mesh, if True generates linear Tri3 elements, if False generates quadratic Tri6 elements. Defaults to True.

Raises:

ValueError – If the length of mesh_sizes does 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 to True.

  • kwargs (dict[str, Any]) – Other keyword arguments are passed to plotting_context().

Returns:

Matplotlib axes object.

Return type:

matplotlib.axes.Axes

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 True shades the elements with the specified material colors. Defaults to True.

  • node_indexes (bool) – If set to True, plots the indexes of each node. Defaults to False.

  • element_indexes (bool) – If set to True, plots the indexes of each element. Defaults to False.

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

matplotlib.axes.Axes

Example

TODO.