4.1.1.3.1.3. pyfem.fem.DofSpace module
- class DofSpace(elements: Any)[source]
Bases:
objectRepresentation of the global degrees-of-freedom space.
The class maps node identifiers and DOF types to global DOF indices and provides utility routines for constraint handling, solves and eigenvalue computations in the constrained subspace.
- setConstrainFactor(fac: float, loadCase: str = 'All_') None[source]
Set constraint scaling factor for all or a specific load case.
- readFromFile(fname: str) None[source]
Read constraint definitions from a file and create a Constrainer.
The file is parsed with
pyfem.util.fileParser.readNodeTable()and passed tocreateConstrainer().
- createConstrainer(nodeTables: Sequence[Any] | None = None) Constrainer[source]
Create and return a
Constrainerfrom parsed node tables.If
nodeTablesis None a default main constraint group is created. Otherwise the function iterates over provided node tables and registers constraints accordingly.
- getForType(nodeIDs: Sequence[Any], dofType: str) array[source]
Return DOF indices for a given DOF type and node ID(s).
- Parameters:
nodeIDs (Sequence[Any] or int) – Single node ID or sequence of node IDs.
dofType (str) – DOF type name (e.g., ‘u’, ‘v’, ‘w’).
- Returns:
Array of global DOF indices.
- Return type:
numpy.ndarray
- getForTypes(nodeIDs: Sequence[Any], dofTypes: Sequence[str]) List[int][source]
Return DOF indices for multiple DOF types and multiple nodes.
- Parameters:
nodeIDs (Sequence[Any]) – Sequence of node IDs.
dofTypes (Sequence[str]) – Sequence of DOF type names.
- Returns:
Flat list of global DOF indices ordered by node, then by DOF type.
- Return type:
List[int]
- hasType(dofType: str) bool[source]
Check if the given DOF type name exists in the DofSpace.
- Parameters:
dofType (str) – The DOF type name to check.
- Returns:
True if the DOF type exists, False otherwise.
- Return type:
bool
- getTypeIDs(dofNames: Sequence[str]) List[int][source]
Return the type indices for a list of DOF type names, only if they exist in dofTypes.
- Parameters:
dofNames (Sequence[str]) – List of DOF type names to look up.
- Returns:
List of type indices for the names that exist in dofTypes.
- Return type:
List[int]
- get(nodeIDs: Sequence[Any]) array[source]
Return all DOF indices for the provided node ID(s).
- Parameters:
nodeIDs (Sequence[Any], int, or np.integer) – Single node ID or sequence of node IDs. Accepts both Python integers and NumPy integer types.
- Returns:
Flattened array of all DOF indices for the specified nodes, in order.
- Return type:
numpy.ndarray
- copyConstrainer(dofTypes: Sequence[str] | None = None) Constrainer[source]
Return a copy of the current constrainer with additional DOF types.
- Parameters:
dofTypes (Optional[Sequence[str] or str]) – DOF type(s) to constrain to zero. If None, returns a simple copy. Can be a single string or sequence of strings.
- Returns:
Deep copy of the constrainer with additional zero constraints applied.
- Return type:
- solve(A: array, b: array, constrainer: Constrainer | None = None) array[source]
Solve the linear system Ax=b respecting constraints and return x.
For a matrix problem the constrained system is assembled and solved in the reduced space. For a diagonal ‘A’ (len(A.shape)==1) the solve is performed element-wise.
- Parameters:
A (numpy.ndarray) – System matrix (2D) or diagonal elements (1D).
b (numpy.ndarray) – Right-hand side vector.
constrainer (Optional[Constrainer]) – Constrainer to use. If None, uses self.cons.
- Returns:
Solution vector x with constraints applied.
- Return type:
numpy.ndarray
- eigensolve(A: array, B: array, count: int = 5) Tuple[array, array][source]
Compute the lowest
counteigenpairs for the generalized problem A x = lambda B x.The computation is performed in the constrained subspace and the eigenvectors are expanded back to the full DOF space before returning.
- Parameters:
A (numpy.ndarray) – Stiffness matrix.
B (numpy.ndarray) – Mass matrix.
count (int, optional) – Number of eigenpairs to compute (default: 5).
- Returns:
eigvals (numpy.ndarray) – Array of eigenvalues in ascending order.
eigvecs (numpy.ndarray) – Matrix where each column is an eigenvector in the full DOF space.
- norm(r: array, constrainer: Constrainer | None = None) float[source]
Return the norm of
rexcluding constrained DOFs.- Parameters:
r (numpy.ndarray) – Vector to compute the norm of.
constrainer (Optional[Constrainer]) – Constrainer to use. If None, uses self.cons.
- Returns:
L2 norm of the unconstrained portion of r.
- Return type:
float
- maskPrescribed(a: array, val: float = 0.0, constrainer: Constrainer | None = None) array[source]
Replace prescribed DOFs in
awithvaland return the array.- Parameters:
a (numpy.ndarray) – Array to modify.
val (float, optional) – Value to set for prescribed DOFs (default: 0.0).
constrainer (Optional[Constrainer]) – Constrainer to use. If None, uses self.cons.
- Returns:
Modified array with prescribed DOFs set to val.
- Return type:
numpy.ndarray