4.1.1.3.1.4. pyfem.fem.ElementSet module

class ElementSet(nodes: Any, props: Properties)[source]

Bases: itemList

Container for finite elements and element groups.

Manages a collection of finite element objects indexed by element ID. Elements are organized into named groups based on their model type (material, element type, etc.). Provides methods for iterating over elements, reading from input files, and managing element groups.

nodes

NodeSet object containing the mesh nodes.

props

Properties object containing model and material properties.

solverStat

Solver status tracker for time stepping and iterations.

groups

Dictionary mapping group names to lists of element IDs.

Examples

>>> elements = ElementSet(nodes, props)
>>> elements.readFromFile('input.pro')
>>> for element in elements:
...     # Process each element
logInfo() None[source]

Log element and group information using the logger.

Outputs the same information as __repr__ but using the logger, with properly formatted output for number of elements and groups.

getDofTypes() List[str][source]

Get all unique degree of freedom (DOF) types from all elements.

Iterates through all elements and collects unique DOF types (e.g., ‘u’, ‘v’, ‘w’ for displacements, ‘temp’ for temperature, etc.).

Returns:

List of unique DOF type strings.

readFromFile(fname: str) None[source]

Read element definitions from an input file.

Parses elements from a legacy .pro file format or references a Gmsh file. Supports <Elements> blocks with element definitions or gmsh file references.

Parameters:

fname – Path to input file (.pro format or referencing Gmsh file).

Notes

Format for <Elements> block: elemID modelName nodeID1 nodeID2 …;

Format for Gmsh reference: gmsh = “filename.msh”;

readGmshFile(fname: str) None[source]

Read elements from a Gmsh mesh file.

Uses meshio to parse Gmsh format and extract elements. Physical groups from Gmsh become element groups in PyFEM.

Parameters:

fname – Path to the Gmsh file (.msh format).

Requires:

meshio package for reading Gmsh files.

add(ID: int, modelName: str, elementNodes: List[int]) None[source]

Add a finite element to the element set.

Creates an element instance of the specified type with given nodes, validates node IDs, and adds the element to the appropriate group.

Parameters:
  • ID – Unique element identifier.

  • modelName – Name of the model/material (must exist in props).

  • elementNodes – List of node IDs that define the element connectivity.

Raises:
  • RuntimeError – If model is missing ‘type’ attribute or node ID invalid.

  • ImportError – If element module or class cannot be found.

addToGroup(modelType: str, ID: int) None[source]

Register an element ID to a named group.

Creates the group if it doesn’t exist, otherwise appends the element ID.

Parameters:
  • modelType – Name of the element group.

  • ID – Element identifier to add to the group.

addGroup(groupName: str, groupIDs: List[int]) None[source]

Create or replace a named group with specified element IDs.

Parameters:
  • groupName – Name for the element group.

  • groupIDs – List of element IDs to include in the group.

iterGroupNames() Dict[str, List[int]][source]

Return the dictionary of group names and their element IDs.

Returns:

Dictionary mapping group names to lists of element IDs.

iterElementGroup(groupName: str | List[str]) Iterator[source]

Iterate over element objects in specified group(s).

Parameters:

groupName – Name of group to iterate, ‘All’ for all elements, or list of group names to iterate multiple groups.

Returns:

Iterator over element objects in the specified group(s).

Examples

>>> for elem in elements.iterElementGroup('Material1'):
...     # Process elements in Material1 group
>>> for elem in elements.iterElementGroup(['Mat1', 'Mat2']):
...     # Process elements in both groups
elementGroupCount(groupName: str | List[str]) int[source]

Return the number of elements in specified group(s).

Parameters:

groupName – Name of group, ‘All’ for all elements, or list of group names.

Returns:

Total count of elements in the specified group(s).

getFamilyIDs() List[int][source]

Get family type indices for all elements.

Returns a list of integer indices representing the element family (CONTINUUM=0, INTERFACE=1, SURFACE=2, BEAM=3, SHELL=4) for each element.

Returns:

List of family indices, one per element.

commitHistory() None[source]

Commit history variables for all elements.

Calls commitHistory() on all element objects to update internal state variables after a successful time/load step. Typically used for storing plastic strains, damage variables, etc.