4.1.1.3.1.1. pyfem.fem.Assembly module

class MatrixBuilder(nDofs: int)[source]

Bases: object

Incrementally build sparse matrix data in COO format for finite element assembly. Also stores a global vector B and a scalar c for additional model data.

nDofs

Number of global degrees of freedom.

Type:

int

val

Values of the matrix entries.

Type:

np.ndarray

row

Row indices for COO format.

Type:

np.ndarray

col

Column indices for COO format.

Type:

np.ndarray

B

Global vector (initialized to zeros).

Type:

np.ndarray

c

Scalar value (initialized to 0.0).

Type:

float

clear() None[source]

Reset stored row/col/value arrays, B, and c.

append(a: ndarray[tuple[Any, ...], dtype[floating]], dofs: ndarray[tuple[Any, ...], dtype[integer]]) None[source]

Append element matrix a using associated dof indices.

Parameters:
  • a (np.ndarray) – Element matrix (square, shape [n, n]).

  • dofs (np.ndarray) – DOF indices for the element (length n).

getMatrix() coo_matrix[source]

Return the assembled COO sparse matrix.

Returns:

Assembled sparse matrix.

Return type:

scipy.sparse.coo_matrix

prepare(props: Properties, globdat: Any) None[source]

Commit element states by calling the element ‘commit’ method.

This function is called after a successful time step or load step to finalize and store the current element states (e.g., history variables, plastic strains, damage parameters).

Parameters:
  • props (Properties) – Global properties container.

  • globdat (Any) – Global data/state object.

assembleInternalForce(props: Properties, globdat: Any) ndarray[tuple[Any, ...], dtype[floating]][source]

Assemble and return the global internal force vector.

Computes the internal force vector by calling the ‘getInternalForce’ method on all elements and assembling their contributions.

Parameters:
  • props (Properties) – Global properties container.

  • globdat (Any) – Global data/state object.

Returns:

The assembled internal force vector.

Return type:

np.ndarray

assembleExternalForce(props: Properties, globdat: Any) ndarray[tuple[Any, ...], dtype[floating]][source]

Assemble and return the global external force vector.

Computes the external force vector by calling the ‘getExternalForce’ method on all elements and assembling their contributions. The external force returned includes contributions assembled from elements plus any scaled forcing term stored on globdat.

Parameters:
  • props (Properties) – Global properties container.

  • globdat (Any) – Global data/state object.

Returns:

The assembled external force vector, including the scaled load factor contribution (globdat.fhat * globdat.solverStatus.lam).

Return type:

np.ndarray

assembleDissipation(props: Properties, globdat: Any) Tuple[ndarray[tuple[Any, ...], dtype[floating]], float][source]

Assemble and return dissipation contributions.

Computes dissipation by calling the ‘getDissipation’ method on all elements.

Parameters:
  • props (Properties) – Global properties container.

  • globdat (Any) – Global data/state object.

Returns:

  • dissipation_vector: Assembled dissipation force vector

  • accumulated_dissipation: Total scalar dissipation from all elements

Return type:

tuple[np.ndarray, float]

assembleTangentStiffness(props: Properties, globdat: Any) Tuple[coo_matrix, ndarray[tuple[Any, ...], dtype[floating]]][source]

Assemble and return the global tangent stiffness matrix and residual.

Computes the tangent stiffness matrix by calling the ‘getTangentStiffness’ method on all elements and assembling their contributions into a sparse matrix.

Parameters:
  • props (Properties) – Global properties container.

  • globdat (Any) – Global data/state object.

Returns:

  • stiff_matrix: Global tangent stiffness matrix in COO sparse format

  • residual_vector: Assembled internal force residual vector

Return type:

tuple[scipy.sparse.coo_matrix, np.ndarray]

assembleMassMatrix(props: Properties, globdat: Any) Tuple[coo_matrix, ndarray[tuple[Any, ...], dtype[floating]]][source]

Assemble and return the global mass matrix and lumped mass vector.

Computes the mass matrix by calling the ‘getMassMatrix’ method on all elements and assembling their contributions into a sparse matrix.

Parameters:
  • props (Properties) – Global properties container.

  • globdat (Any) – Global data/state object.

Returns:

  • mass_matrix: Global mass matrix in COO sparse format

  • lumped_mass_vector: Assembled lumped mass vector (diagonal approximation)

Return type:

tuple[scipy.sparse.coo_matrix, np.ndarray]

commit(props: Properties, globdat: Any) None[source]

Commit element states by calling the element ‘commit’ method.

This function is called after a successful time step or load step to finalize and store the current element states (e.g., history variables, plastic strains, damage parameters).

Parameters:
  • props (Properties) – Global properties container.

  • globdat (Any) – Global data/state object.

getAllConstraints(props: Properties, globdat: Any) None[source]

Invoke ‘getConstraints’ on all elements to collect constraint data.

This function iterates over all element groups and elements, calling their ‘getConstraints’ method if available. This is typically used for multi-point constraints, contact constraints, or other element-level constraint definitions.

Parameters:
  • props (Properties) – Global properties container.

  • globdat (Any) – Global data/state object.

Note

The current implementation creates a minimal elemdat structure for each element. This mirrors the original behavior and intentionally does not change the logic.

getElementData(iElm: int, element: Any, el_props: Properties, globdat: Any) elementData[source]

Create and populate an elementData instance for an element.

This helper function gathers all necessary data for an element from the global data structure, including:

  • Node indices and coordinates

  • Degree of freedom indices and values

  • Current state vector and state increment

  • Element properties and material properties

Parameters:
  • iElm (int) – Element index in the group.

  • element (Any) – The element object for which to gather data.

  • el_props (Properties) – Properties object for the element’s group.

  • globdat (Any) – Global data/state object containing mesh, DOFs, and state.

Returns:

An instance populated with all element-specific information needed for element computations.

Return type:

elementData