4.1. pyfem package
- run(props: str | Path | Tuple[Any, Any]) Any[source]
Convenience function mirroring the old run behavior used in scripts.
Creates a PyFEMAPI instance, runs the analysis to completion and returns the results dictionary.
- class NodeSet[source]
Bases:
itemListContainer for nodes and node groups.
Inherits from itemList to store nodal coordinates indexed by node ID. Maintains nodal coordinates, spatial dimensionality (rank), and named groupings read from legacy .pro files or Gmsh meshes. Provides convenience methods for retrieving coordinates and iterating group contents.
- rank
Spatial dimension of the mesh (2 for 2D, 3 for 3D). Initialized to -1 and set automatically when first node is added.
- Type:
int
- groups
Dictionary mapping group names to lists of node IDs. Groups are typically used to define boundary conditions (e.g., ‘Left’, ‘Right’, ‘Top’, ‘Bottom’).
- Type:
Dict[str, List[int]]
Notes
The NodeSet class extends itemList, inheriting methods like add(), get(), and __len__(). Node coordinates are stored internally and can be retrieved via getNodeCoords().
Examples
>>> nodes = NodeSet() >>> nodes.add(0, [0.0, 0.0]) # Add node 0 at origin >>> nodes.add(1, [1.0, 0.0]) # Add node 1 at (1, 0) >>> nodes.addToGroup('Bottom', 0) >>> nodes.addToGroup('Bottom', 1) >>> coords = nodes.getNodeCoords('Bottom')
- getNodeCoords(nodeIDs: int | List[int] | str) array[source]
Return coordinates for one or more nodes as a NumPy array.
- Parameters:
nodeIDs (Union[int, List[int], str]) – Single node ID (int), list of node IDs (list), or node group name (str). When a string is provided, it references a node group defined in the model.
- Returns:
Array containing nodal coordinates. For a single node, returns a 1D array of shape (rank,). For multiple nodes, returns a 2D array of shape (n, rank) where n is the number of nodes and rank is the spatial dimension.
- Return type:
numpy.array
Examples
>>> nodes.getNodeCoords(5) # Single node array([1.0, 2.0, 0.0])
>>> nodes.getNodeCoords([1, 2, 3]) # Multiple nodes array([[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [2.0, 0.0, 0.0]])
>>> nodes.getNodeCoords('Left') # Node group array([[0.0, 0.0, 0.0], [0.0, 1.0, 0.0]])
- getNodeIDs(groupName: str) List[int][source]
Return list of node IDs in the specified group.
- Parameters:
groupName (str) – Name of the node group.
- Returns:
List of node IDs in the specified group.
- Return type:
List[int]
Examples
>>> nodes.getNodeIDs('Left') [0, 1, 2]
- readFromFile(fname: str) None[source]
Read nodes and groups from legacy .pro file format.
Parses the input file twice: first pass reads nodal coordinates from <Nodes> blocks or references external Gmsh files; second pass reads <NodeGroup> definitions. Duplicate nodes in groups are automatically removed.
- Parameters:
fname (str) – Path to input file (.pro format or referencing a Gmsh file).
Notes
Supported file formats: 1. Native .pro format with <Nodes> and <NodeGroup> blocks 2. Gmsh reference: line containing ‘gmsh = “filename.msh”’
The file is parsed line by line. Comments and whitespace are handled. Node groups are deduplicated after reading.
- readGmshFile(fname: str) None[source]
Read nodes and groups from a Gmsh mesh file.
Uses meshio to parse Gmsh format and extract nodes and physical groups. Automatically detects spatial dimension (2D/3D) based on element types. Physical groups from Gmsh become node groups in PyFEM.
- Parameters:
fname (str) – Path to the Gmsh file (.msh format, versions 2 or 4).
Notes
3D element detection: - Checks for prisms, pyramids, hexahedra, wedges, and tetrahedra - Sets rank=3 if any 3D elements found, otherwise rank=2
Node groups are populated from Gmsh’s cell_sets_dict, with ‘gmsh:bounding_entities’ excluded. All nodes in elements belonging to a physical group are added to the corresponding PyFEM group.
Requires: - meshio package for reading Gmsh files
- addToGroup(modelType: str, ID: int | str) None[source]
Register a node ID to a named group.
Creates the group if it doesn’t exist, otherwise appends the node to the existing group. String node IDs are automatically converted to integers.
- Parameters:
modelType (str) – Name of the node group (e.g., ‘Left’, ‘Right’, ‘Bottom’, ‘Top’).
ID (Union[int, str]) – Node identifier. String values are converted to int.
Examples
>>> nodes.addToGroup('Boundary', 5) >>> nodes.addToGroup('Boundary', '10') # String converted to int
- logInfo() None[source]
Log node and group information using the logger.
Outputs the same information as __repr__ but using the logger, with properly formatted output for number of nodes and groups.
Examples
>>> nodes.logInfo() # Logs: # Number of nodes ................. : 100 # Number of groups ................ : 4 # Group table with names and counts
- readNodalCoords(fin: TextIO) None[source]
Read nodal coordinates from an open file stream.
Parses node definitions from a <Nodes> block until </Nodes> is encountered. Each line should contain: nodeID x [y [z]] with semicolon separators. Comments starting with // or # are ignored. Spatial dimension (rank) is inferred from the first valid node entry.
- Parameters:
fin (TextIO) – Open file handle positioned at the start of the <Nodes> block.
Notes
Format: - Multiple nodes per line separated by semicolons - Format: nodeID x y [z]; - Whitespace is normalized before parsing - Comments (// or #) are skipped - rank is set from first node (2D or 3D)
- readNodegroup(fin: TextIO, key: str) None[source]
Read a node group from an open file stream.
Parses node IDs from a <NodeGroup> block until </NodeGroup> is encountered. Node IDs are whitespace-separated integers. All valid integers found are added to the specified group.
- Parameters:
fin (TextIO) – Open file handle positioned at the start of a <NodeGroup> block.
key (str) – Group name label to assign these nodes to.
Notes
Format: - <NodeGroup name=”groupname”> - nodeID1 nodeID2 nodeID3 … - </NodeGroup>
- class ElementSet(nodes: Any, props: Properties)[source]
Bases:
itemListContainer 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).
4.1.1. Subpackages
- 4.1.1.1. pyfem.core package
- 4.1.1.2. pyfem.elements package
- 4.1.1.2.1. Submodules
- 4.1.1.2.1.1. pyfem.elements.BeamLin module
- 4.1.1.2.1.2. pyfem.elements.BeamNL module
- 4.1.1.2.1.3. pyfem.elements.Composite module
- 4.1.1.2.1.4. pyfem.elements.CondensationManager module
- 4.1.1.2.1.5. pyfem.elements.DistributedLoad module
- 4.1.1.2.1.6. pyfem.elements.Element module
- 4.1.1.2.1.7. pyfem.elements.FiniteStrainAxiSym module
- 4.1.1.2.1.8. pyfem.elements.FiniteStrainContinuum module
- 4.1.1.2.1.9. pyfem.elements.Interface module
- 4.1.1.2.1.10. pyfem.elements.KirchhoffBeam module
- 4.1.1.2.1.11. pyfem.elements.PhaseField module
- 4.1.1.2.1.12. pyfem.elements.Plate module
- 4.1.1.2.1.13. pyfem.elements.SLS module
- 4.1.1.2.1.14. pyfem.elements.SLSgeomdata module
- 4.1.1.2.1.15. pyfem.elements.SLSkinematic module
- 4.1.1.2.1.16. pyfem.elements.SLSutils module
- 4.1.1.2.1.17. pyfem.elements.SmallStrainAxiSym module
- 4.1.1.2.1.18. pyfem.elements.SmallStrainContinuum module
- 4.1.1.2.1.19. pyfem.elements.Spring module
- 4.1.1.2.1.20. pyfem.elements.ThermalBC module
- 4.1.1.2.1.21. pyfem.elements.ThermoAxiSym module
- 4.1.1.2.1.22. pyfem.elements.ThermoContinuum module
- 4.1.1.2.1.23. pyfem.elements.ThermoSmallStrainAxiSym module
- 4.1.1.2.1.24. pyfem.elements.ThermoSmallStrainContinuum module
- 4.1.1.2.1.25. pyfem.elements.ThermoSurface module
- 4.1.1.2.1.26. pyfem.elements.TimoshenkoBeam module
- 4.1.1.2.1.27. pyfem.elements.Truss module
- 4.1.1.2.1. Submodules
- 4.1.1.3. pyfem.fem package
- 4.1.1.4. pyfem.gui package
- 4.1.1.5. pyfem.io package
- 4.1.1.5.1. Submodules
- 4.1.1.5.1.1. pyfem.io.ContourWriter module
- 4.1.1.5.1.2. pyfem.io.DataDump module
- 4.1.1.5.1.3. pyfem.io.GraphWriter module
- 4.1.1.5.1.4. pyfem.io.HDF5Writer module
- 4.1.1.5.1.5. pyfem.io.InputReader module
- 4.1.1.5.1.6. pyfem.io.MeshWriter module
- 4.1.1.5.1.7. pyfem.io.OutputManager module
- 4.1.1.5.1.8. pyfem.io.OutputWriter module
- 4.1.1.5.1. Submodules
- 4.1.1.6. pyfem.materials package
- 4.1.1.6.1. Submodules
- 4.1.1.6.1.1. pyfem.materials.BaseFailure module
- 4.1.1.6.1.2. pyfem.materials.BaseMaterial module
- 4.1.1.6.1.3. pyfem.materials.Crystal module
- 4.1.1.6.1.4. pyfem.materials.Dummy module
- 4.1.1.6.1.5. pyfem.materials.HookesLaw module
- 4.1.1.6.1.6. pyfem.materials.Isotropic module
- 4.1.1.6.1.7. pyfem.materials.IsotropicHardeningPlasticity module
- 4.1.1.6.1.8. pyfem.materials.IsotropicKinematicHardening module
- 4.1.1.6.1.9. pyfem.materials.MatUtils module
- 4.1.1.6.1.10. pyfem.materials.MaterialManager module
- 4.1.1.6.1.11. pyfem.materials.MaxStrain module
- 4.1.1.6.1.12. pyfem.materials.MaxStress module
- 4.1.1.6.1.13. pyfem.materials.MultiMaterial module
- 4.1.1.6.1.14. pyfem.materials.PlaneStrain module
- 4.1.1.6.1.15. pyfem.materials.PlaneStrainDamage module
- 4.1.1.6.1.16. pyfem.materials.PlaneStress module
- 4.1.1.6.1.17. pyfem.materials.PowerLawModeI module
- 4.1.1.6.1.18. pyfem.materials.SOVS module
- 4.1.1.6.1.19. pyfem.materials.SandwichCore module
- 4.1.1.6.1.20. pyfem.materials.ThoulessModeI module
- 4.1.1.6.1.21. pyfem.materials.TransverseIsotropic module
- 4.1.1.6.1.22. pyfem.materials.TsaiWu module
- 4.1.1.6.1.23. pyfem.materials.ViscoElasticity module
- 4.1.1.6.1.24. pyfem.materials.ViscoPlasticity module
- 4.1.1.6.1.25. pyfem.materials.VonMises module
- 4.1.1.6.1.26. pyfem.materials.XuNeedleman module
- 4.1.1.6.1. Submodules
- 4.1.1.7. pyfem.models package
- 4.1.1.8. pyfem.solvers package
- 4.1.1.8.1. Submodules
- 4.1.1.8.1.1. pyfem.solvers.BuckEigSolver module
- 4.1.1.8.1.2. pyfem.solvers.DissipatedEnergySolver module
- 4.1.1.8.1.3. pyfem.solvers.DynEigSolver module
- 4.1.1.8.1.4. pyfem.solvers.ExplicitSolver module
- 4.1.1.8.1.5. pyfem.solvers.LinearSolver module
- 4.1.1.8.1.6. pyfem.solvers.ModalSolver module
- 4.1.1.8.1.7. pyfem.solvers.MultiSolver module
- 4.1.1.8.1.8. pyfem.solvers.NonlinearSolver module
- 4.1.1.8.1.9. pyfem.solvers.RiksSolver module
- 4.1.1.8.1.10. pyfem.solvers.Solver module
- 4.1.1.8.1.11. pyfem.solvers.StaggeredSolver module
- 4.1.1.8.1. Submodules
- 4.1.1.9. pyfem.util package
- 4.1.1.9.1. Submodules
- 4.1.1.9.1.1. pyfem.util.BaseModule module
- 4.1.1.9.1.2. pyfem.util.BezierShapeFunctions module
- 4.1.1.9.1.3. pyfem.util.dataStructures module
- 4.1.1.9.1.4. pyfem.util.fileParser module
- 4.1.1.9.1.5. pyfem.util.itemList module
- 4.1.1.9.1.6. pyfem.util.kinematics module
- 4.1.1.9.1.7. pyfem.util.logger module
- 4.1.1.9.1.8. pyfem.util.plotUtils module
- 4.1.1.9.1.9. pyfem.util.shapeFunctions module
shapeDataelemShapeDatagetShapeLine2()getShapeLine3()getShapeTria3()getShapeQuad4()getShapeTria6()getShapeQuad8()getShapeQuad9()getShapeTetra4()getShapePyramid5()getShapePrism6()getShapePrism18()getShapeHexa8()getElemType()tria_scheme()tetra_scheme()pyramid_scheme()getIntegrationPoints()calcWeightandDerivatives()getElemShapeData()getShapeData()
- 4.1.1.9.1.10. pyfem.util.transformations module
- 4.1.1.9.1.11. pyfem.util.utilFunctions module
- 4.1.1.9.1.12. pyfem.util.vtkUtils module
- 4.1.1.9.1. Submodules