femlabpy.core#

Global array allocation and small indexing helpers for the femlabpy workflow.

Workflow role#

This module is the normal starting point after the node table and the number of degrees of freedom per node are known. It creates the zeroed global arrays that the assembly, boundary, modal, and dynamics modules fill later in the solve sequence.

Public entry points#

  • init allocates stiffness, optional mass, external load, and internal force arrays with dense or sparse storage.

  • rows and cols are lightweight shape helpers re-exported from the private helper layer because the legacy translation code uses them often.

Functions#

cols(data)

Return the column count of an array-like object.

init(nn, dof, *[, dynamic, use_sparse])

Initialize FEM arrays for a problem with nn nodes and dof DOFs per node.

rows(data)

Return the leading dimension of an array-like object.

Function Reference#

femlabpy.core.cols(data: object) int[source]#

Return the column count of an array-like object.

One-dimensional inputs follow the MATLAB classroom convention where a row vector reports its full length as the column count.

Parameters:
data:

Array-like input.

Returns:
int

Number of columns in the array representation.

femlabpy.core.init(nn: int, dof: int, *, dynamic: bool = False, use_sparse: bool | None = None)[source]#

Initialize FEM arrays for a problem with nn nodes and dof DOFs per node.

Parameters:
nnint

Number of nodes in the mesh.

dofint

Degrees of freedom per node (2 for 2D, 3 for 3D).

dynamicbool, default False

If True, also allocate a mass matrix M and return it.

use_sparsebool, optional

If True, use scipy.sparse.lil_matrix for K (and M). If False, use dense numpy array. If None (default), automatically use sparse for nn >= 1000.

Returns:
Kndarray or sparse matrix, shape (ndof, ndof)

Global stiffness matrix (initialized to zero).

Mndarray or sparse matrix, shape (ndof, ndof)

Global mass matrix (only when dynamic=True).

pndarray, shape (ndof, 1)

Load vector (initialized to zero).

qndarray, shape (ndof, 1)

Internal force vector (initialized to zero).

Notes

Total DOFs = nn * dof

Examples

>>> from femlabpy import init
>>> K, p, q = init(nn=100, dof=2)  # 100 nodes, 2D problem
>>> K.shape
(200, 200)
>>> # Dynamic allocation with mass matrix
>>> K, M, p, q = init(nn=100, dof=2, dynamic=True)
>>> # Force sparse storage
>>> K, p, q = init(nn=50, dof=2, use_sparse=True)
femlabpy.core.rows(data: object) int[source]#

Return the leading dimension of an array-like object.

Parameters:
data:

Array-like input.

Returns:
int

Number of rows in the array representation.