pyfem.util package
Submodules
pyfem.util.BaseModule module
- class BaseModule(props)[source]
Bases:
object
- type
- def get_nested_attr(obj, attr_path, default=None):
“”” Access a nested attribute in an object hierarchy.
Parameters: - obj: The base object - attr_path: A string of dot-separated attribute names (e.g., “bar.foo.y”) - default: The value to return if any attribute in the chain doesn’t exist
Returns: - The value of the nested attribute, or the default if any attribute is missing “”” try:
- for attr in attr_path.split(‘.’):
obj = getattr(obj, attr)
return obj
- except AttributeError:
return default
# Example usage: # Assuming x.bar.foo.y exists value = get_nested_attr(x, “bar.foo.y”, default=”Attribute not found”) print(value)
pyfem.util.BezierShapeFunctions module
pyfem.util.dataStructures module
- class GlobalData(nodes, elements, dofs)[source]
Bases:
Properties
pyfem.util.fileParser module
pyfem.util.itemList module
- class itemList[source]
Bases:
dict
Class to construct a list of items that have a coninuous local number, and a global ID.
- add(ID: int, item)[source]
Adds an item with an ID to the list. This item will be stored in the list.
- Parameters:
ID (int) – the ID of the item to be stored.
item – the value(s) of the item to be stored.
- get(IDs)[source]
Returns the index / indices of an ID or list of IDs of items in the list.
- Parameters:
IDs (list[int]|int,optional) – the ID/IDs. If ommited, a list with all indces
returned. (will be)
- Returns:
a list with the indices. In the case of a single ID, this list has length 1.
- Return type:
list[int]
- getIndices(IDs: list[int] | int = -1) list[int] [source]
Returns the index / indices of an ID or list of IDs of items in the list.
- Parameters:
IDs (list[int]|int,optional) – the ID/IDs. If ommited, a list with all indces
returned. (will be)
- Returns:
a list with the indices. In the case of a single ID, this list has length 1.
- Return type:
list[int]
pyfem.util.kinematics module
pyfem.util.logger module
pyfem.util.plotUtils module
pyfem.util.shapeFunctions module
- class shapeData[source]
Bases:
object
Class that contains the shape function data for a single integration point.
- class elemShapeData[source]
Bases:
object
Class that contains the shape function data for an entire element. This class is iterable.
- getShapeLine2(xi: float) shapeData [source]
Function that returns the shape function data in a single integration point for a parent 1D line element with 2 nodes (Line2).
- Parameters:
xi (float) – Location of the integration point
- Returns:
The integration point shape data containin the parent parameters, h, dhdxi and xi
- Return type:
- Raises:
Error – when the input is not a 1D coordinate (float)
- getShapeLine3(xi)[source]
Function that returns the shape function data in a single integration point for a parent 1D line element with 3 nodes (Line3).
- Parameters:
xi (float) – Location of the integration point
- Returns:
The integration point shape data containin the parent parameters, h, dhdxi and xi
- Return type:
- Raises:
Error – when the input is not a 1D coordinate (float)
- getShapeTria3(xi: ndarray) shapeData [source]
Function that returns the shape function data in a single integration point for a parent 2D triangular element with 3 nodes (Tria3).
- Parameters:
xi (ndarray) – Location of the integration point
- Returns:
The integration point shape data containin the parent parameters, h, dhdxi and xi
- Return type:
- Raises:
Error – when the input is not a 2D coordinate (ndarray of length 2)
- getShapeQuad4(xi: ndarray) shapeData [source]
Function that returns the shape function data in a single integration point for a parent 2D quadrilateral element with 4 nodes (Quad4).
- Parameters:
xi (ndarray) – Location of the integration point
- Returns:
The integration point shape data containin the parent parameters, h, dhdxi and xi
- Return type:
- Raises:
Error – when the input is not a 2D coordinate (ndarray of length 2)
- getShapeTria6(xi: ndarray) shapeData [source]
Function that returns the shape function data in a single integration point for a parent 2D triangular element with 6 nodes (Tria4).
- Parameters:
xi (ndarray) – Location of the integration point
- Returns:
The integration point shape data containin the parent parameters, h, dhdxi and xi
- Return type:
- Raises:
Error – when the input is not a 2D coordinate (ndarray of length 2)
- getShapeQuad8(xi: ndarray) shapeData [source]
Function that returns the shape function data in a single integration point for a parent 2D quadrilateral element with 8 nodes (Quad8).
- Parameters:
xi (ndarray) – Location of the integration point
- Returns:
The integration point shape data containin the parent parameters, h, dhdxi and xi
- Return type:
- Raises:
Error – when the input is not a 2D coordinate (ndarray of length 2)
- getShapeQuad9(xi)[source]
Function that returns the shape function data in a single integration point for a parent 2D quadrilateral element with 9 nodes (Quad9).
- Parameters:
xi (ndarray) – Location of the integration point
- Returns:
The integration point shape data containin the parent parameters, h, dhdxi and xi
- Return type:
- Raises:
Error – when the input is not a 2D coordinate (ndarray of length 2)
- getShapeTetra4(xi: ndarray) shapeData [source]
Function that returns the shape function data in a single integration point for a parent 3D tetrahedral element with 4 nodes (Tetra4).
- Parameters:
xi (ndarray) – Location of the integration point
- Returns:
The integration point shape data containin the parent parameters, h, dhdxi and xi
- Return type:
- Raises:
Error – when the input is not a 3D coordinate (ndarray of length 3)
- getShapePyramid5(xi: ndarray) shapeData [source]
Function that returns the shape function data in a single integration point for a parent 3D pyramid element with 5 nodes (Pyramid5).
- Parameters:
xi (ndarray) – Location of the integration point
- Returns:
The integration point shape data containin the parent parameters, h, dhdxi and xi
- Return type:
- Raises:
Error – when the input is not a 3D coordinate (ndarray of length 3)
- getShapePrism6(xi: ndarray) shapeData [source]
Function that returns the shape function data in a single integration point for a parent 3D prsimatic element with 6 nodes (Prism6).
- Parameters:
xi (ndarray) – Location of the integration point
- Returns:
The integration point shape data containin the parent parameters, h, dhdxi and xi
- Return type:
- Raises:
Error – when the input is not a 3D coordinate (ndarray of length 3)
- getShapePrism18(xi: ndarray) shapeData [source]
Function that returns the shape function data in a single integration point for a parent 3D prismatic element with 18 nodes (Prism18).
- Parameters:
xi (ndarray) – Location of the integration point
- Returns:
The integration point shape data containin the parent parameters, h, dhdxi and xi
- Return type:
- Raises:
Error – when the input is not a 3D coordinate (ndarray of length 3)
- getShapeHexa8(xi: ndarray) shapeData [source]
Function that returns the shape function data in a single integration point for a parent 3D hexahedron element with 8 nodes (Hexa8).
- Parameters:
xi (ndarray) – Location of the integration point
- Returns:
The integration point shape data containin the parent parameters, h, dhdxi and xi
- Return type:
- Raises:
Error – when the input is not a 3D coordinate (ndarray of length 3)
- getElemType(elemCoords: ndarray) str [source]
Function that returns the element type based on the nodal coordinates of the element.
- Parameters:
elemCoords (ndarray) – Matrix (2D array) containing the nodal coordinates of the element. The number of rows is the number of nodes, the number of columns is the spatial dimensions (1,2 or 3).
- Returns:
- elementType
1D elements: Line2 and Line3
2D elements: Tria3, Tria6, Quad4, Quad8 and Quad9
3D elements: Tetra4, Pyramid5, Prism6, Hexa8 and Prism18
- Return type:
str
- Raises:
Error – When the element type cannot be found, or when the spatial dimensions (rank) is not 1,2 or 3.
- tria_scheme(order: int)[source]
Function that returns the integration scheme (coordinates in the parent element and weights) for a 2D triangular element.
- Parameters:
order (int) – the integration order. This number is either 1,3 or 7 (representing the number of integration points).
- Returns:
- A list of coordinates in the parent
element and a list of weights. The length of the lists is idential to the order.
- Return type:
tuple(list[list],list[float])
- Raises:
Error – when the order is not equal to 1, 3 or 7.
- tetra_scheme(order: int)[source]
Function that returns the integration scheme (coordinates in the parent element and weights) for a 3D tetrahedral element.
- Parameters:
order (int) – the integration order. This number is only 1, which means a three point integration scheme.
- Returns:
A list of coordinates in the parent element and a list of weights. The length of the lists is equal to 3.
- Return type:
tuple(list[list],list[float])
- Raises:
Error – when the order is not equal to 1.
- pyramid_scheme(order: int)[source]
Function that returns the integration scheme (coordinates in the parent element and weights) for a 3D pyramid element.
- Parameters:
order (int) – the integration order. This number is only 1, which means a one point integration scheme.
- Returns:
A list of coordinates in the parent element and a list of weights. The length of the lists is equal to 1.
- Return type:
tuple(list[list],list[float])
- Raises:
Error – when the order is not equal to 1.
- getIntegrationPoints(elemType: str, order: int, scheme: str)[source]
Function that returns the integration scheme (coordinates in the parent element and weights) for any elemement type
- Parameters:
elemType (str) – Indicating the type of element. - 1D elements: Line2 and Line3 - 2D elements: Tria3, Tria6, Quad4, Quad8 and Quad9 - 3D elements: Tetra4, Pyramid5, Prism6, Hexa8 and Prism18
order (int) – the integration order. 0 represents the standard integration for an element (e.g. Guass 2x2 for a Quad4 element); +1 indicates a higher order integration (3x3 for a Quad4 element); -1 indicates a lower order (1x1).
scheme (str) – Integration scheme (is redundant).
- Returns:
A list of coordinates in the parent element and a list of weights. The length of the lists is equal to 3.
- Return type:
tuple(list[list],list[float])
- Raises:
Error – when the element type is not known.
- calcWeightandDerivatives(elemCoords: ndarray, sData: shapeData, weight: float)[source]
Function that calculates the derivatives of shapefunctions and their weight in the physical element.
- Parameters:
elemCoords (ndarray) – Matrix (2D array) containing the nodal coordinates of the element. The number of rows is the number of nodes, the number of columns is the spatial dimensions (1,2 or 3).
sData (shapeData) – the current shape data in this integration point. This contains the coordinate of the integration point xi and the shape function h and its derivative dhdx.
weight (float) – Integration weight.
- Return type:
None
The physical derivative and weight are store in sData.
- getElemShapeData(elemCoords: ndarray, order: int = 0, method: str = 'Gauss', elemType: str = 'Default') elemShapeData [source]
Function to determine the element shape functions and integration point data for a given element with nodal coordinates.
- Parameters:
elemCoords (ndarray) – Matrix (2D array) containing the nodal coordinates of the element. The number of rows is the number of nodes, the number of columns is the spatial dimensions (1,2 or 3).
order (int) – the order of integration. ) is default and indicates a regular integration for such an element.
method (str) – the integration type. Gauss is default.
elemType (str) – the element type. If the default value is chosen, the element type will be determined by means of the dimensions of the elemCoords array.
- Return type:
- Raises:
Error – when the elementType is not known.
- getShapeData(order: int = 0, method: str = 'Gauss', elemType: str = 'Default') elemShapeData [source]
Function to determine the element shape functions and integration point data for a given elementtype.
- Parameters:
order (int) – the order of integration. ) is default and indicates a regular integration for such an element.
method (str) – the integration type. Gauss is default.
elemType (str) – the element type.
- Return type:
- Raises:
Error – when the elementType is not known.
pyfem.util.transformations module
pyfem.util.utilFunctions module
- macauley(x: float) float [source]
Function that performs the macaulay operation to a variable. The macaulay operation returns the exact same value when that value is positive and returns zero when the values is negative.
- Parameters:
x (float) – The input to the function
- Returns:
The macauley value.
- Return type:
float