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)

writeHeader(cycle=None)[source]
writeFooter(globdat)[source]

pyfem.util.BezierShapeFunctions module

getBezierLine4(xi, C)[source]
calcWeight(jac)[source]
getElemBezierData(elemCoords, C, order=4, method='Gauss', elemType='default')[source]

pyfem.util.dataStructures module

cleanVariable(a)[source]
class solverStatus[source]

Bases: object

increaseStep()[source]
class Properties(dictionary={})[source]

Bases: object

store(key, val)[source]
class GlobalData(nodes, elements, dofs)[source]

Bases: Properties

readFromFile(fname)[source]
printNodes(fileName=None, inodes=None)[source]
getData(outputName, inodes)[source]
resetNodalOutput()[source]
close()[source]
class elementData(elstate, elDstate)[source]

Bases: object

pyfem.util.fileParser module

containsValue(db, val)[source]

Addition of two numbers

Parameters:
  • db (integer) – a

  • val (integer) – btted

Returns:

new value

Return type:

integer

cleanVariable(a)[source]
isNodeDof(nodeDof)[source]
decodeNodeDof(nodeDof, nodes)[source]
getType(a)[source]
storeValue(db, key, a)[source]
readItem(l1, db)[source]
readBlock(ln, db)[source]
fileParser(fileName)[source]
deepFileParser(fileName, db)[source]
class nodeTable(label, subLabel='None')[source]

Bases: object

readNodeTable(fileName, label, nodes=None)[source]

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]

findID(index: int) int[source]

Returns the ID of an index in the list.

Parameters:

index (int) – the index of the item

Returns:

the ID of the item

Return type:

int

pyfem.util.kinematics module

class Kinematics(nDim: int, nStr: int)[source]

Bases: object

Class that contains the kinematic state of a material point, i.e. strain and deformation gradient.

Parameters:
  • nDim (int) – the number of spatial dimensions of the problem (2 or 3)

  • nStr (int) – the number of strain components (2, 3 or 6)

pyfem.util.logger module

setLogger(props: dict)[source]

Creates a logger for the current analysis with a given format and level.

Parameters:

props (dict) – A dictionary containing the input file of the problem.

Returns:

an instance of the logger.

Return type:

logger

getLogger()[source]

Function that returns an instance of the active logger.

Parameters:

None

Returnslogger: an instance of the active logger.

pyfem.util.plotUtils module

plotCurve(output: ndarray) None[source]

Plots a curve based on the given output data points.

Parameters:

output (List[Tuple[float, float]]) – A list of (x, y) data points to plot.

Returns:

None

plotTime(t: float) str[source]

Formats a given time duration into a human-readable string.

Parameters:

t (float) – Time duration in seconds.

Returns:

A formatted string representing the time in seconds, minutes, or hours.

Return type:

str

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:

shapeData

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:

shapeData

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:

shapeData

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:

shapeData

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:

shapeData

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:

shapeData

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:

shapeData

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:

shapeData

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:

shapeData

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:

shapeData

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:

shapeData

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:

shapeData

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:

elemShapeData

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:

elemShapeData

Raises:

Error – when the elementType is not known.

pyfem.util.transformations module

getRotationMatrix(el_coords)[source]
vectorToElementCoordinates(a, el_coords)[source]
matrixToElementCoordinates(a, el_coords)[source]
vectorToGlobalCoordinates(a_bar, el_coords)[source]
matrixToGlobalCoordinates(a_bar, el_coords)[source]
toElementCoordinates(a, el_coords)[source]
toGlobalCoordinates(a, el_coords)[source]

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

sign(x: float) float[source]

Function that returns the sign of a value

Parameters:

x (float) – The input to the function

Returns:

the sign (-1.0 or 1.0).

Return type:

float

pyfem.util.vtkUtils module

storeNodes(grid, globdat)[source]
storeElements(grid, globdat, elementGroup='All')[source]
storeDofField(grid, data, globdat, dofTypes, label)[source]
storeDofFields(grid, data, globdat)[source]
storeNodeField(grid, data, globdat, name)[source]
storeElementField(grid, data, globdat, name)[source]
setCellNodes(cell, elemNodes)[source]
insertElement(grid, elemNodes, rank, family)[source]

Inserts an element

insert2Dcontinuum(grid, elemNodes)[source]
insert3Dcontinuum(grid, elemNodes)[source]
insert2Dinterface(grid, elemNodes)[source]
insert3Dinterface(grid, elemNodes)[source]
insert2Dsurface(grid, elemNodes)[source]
insert3Dsurface(grid, elemNodes)[source]
insertBeam(grid, elemNodes)[source]
insertShell(grid, elemNodes)[source]

Module contents