femlabpy.elements.quads#

Quadrilateral element kernels for elastic, plastic, scalar, and dynamic cases.

Workflow role#

This is the largest element module in the project. It contains the bilinear Q4 family used in most two-dimensional examples, including elastic plane-stress and plane-strain kernels, scalar diffusion kernels, elastoplastic updates, and consistent or lumped mass matrices.

Public entry points#

  • keq4e and qeq4e are the core elastic structural kernels.

  • keq4p and qeq4p cover the scalar potential form.

  • keq4eps and keq4epe with their matching q functions implement plane-stress and plane-strain plasticity.

  • kq4*, qq4*, and mq4e are the assembled global wrappers.

Functions#

keq4e(Xe, Ge)

Compute element stiffness matrix for a 4-node quadrilateral (Q4) element.

keq4epe(Xe, Ge, Se, Ee[, mtype])

Compute the consistent tangent of a plane-strain elastoplastic Q4 element.

keq4eps(Xe, Ge, Se, Ee[, mtype])

Compute the consistent tangent of a plane-stress elastoplastic Q4 element.

keq4p(Xe, Ge)

Compute the scalar conductivity matrix for a 4-node quadrilateral.

kq4e(K, T, X, G)

Assemble Q4 element stiffness matrices into global stiffness matrix.

kq4epe(K, T, X, G, S, E[, mtype])

Assemble plane-strain plastic Q4 tangent matrices into the global matrix.

kq4eps(K, T, X, G, S, E[, mtype])

Assemble plane-stress plastic Q4 tangent matrices into the global matrix.

kq4p(K, T, X, G)

Assemble Q4 scalar conductivity matrices into the global system.

meq4e(Xe, Ge, *[, lumped])

Compute the element mass matrix for a 4-node quadrilateral (Q4) element.

mq4e(M, T, X, G, *[, lumped])

Assemble Q4 element mass matrices into the global mass matrix.

qeq4e(Xe, Ge, Ue)

Compute stresses and strains at Gauss points for a single Q4 element.

qeq4epe(Xe, Ge, Ue, Se, Ee[, mtype])

Update plane-strain elastoplastic Q4 response at the four Gauss points.

qeq4eps(Xe, Ge, Ue, Se, Ee[, mtype])

Update plane-stress elastoplastic Q4 response at the four Gauss points.

qeq4p(Xe, Ge, Ue)

Recover gradients and fluxes for one Q4 scalar potential element.

qq4e(q, T, X, G, u)

Compute stresses/strains for all Q4 elements and assemble internal forces.

qq4epe(q, T, X, G, u, S, E[, mtype])

Compute plane-strain plastic Q4 internal forces and updated history fields.

qq4eps(q, T, X, G, u, S, E[, mtype])

Compute plane-stress plastic Q4 internal forces and updated history fields.

qq4p(q, T, X, G, u)

Recover Q4 scalar gradients and assemble equivalent nodal fluxes.

Function Reference#

femlabpy.elements.quads.keq4e(Xe, Ge)[source]#

Compute element stiffness matrix for a 4-node quadrilateral (Q4) element.

Uses 2x2 Gauss quadrature for numerical integration.

Parameters:
Xearray_like, shape (4, 2)

Nodal coordinates [x, y] for each node. Node ordering: counter-clockwise starting from bottom-left.

Gearray_like

Material properties: [E, nu] or [E, nu, type]. - E: Young’s modulus - nu: Poisson’s ratio - type: 1=plane stress (default), 2=plane strain

Returns:
Kendarray, shape (8, 8)

Element stiffness matrix. DOF ordering: [u1, v1, u2, v2, u3, v3, u4, v4]

Notes

The Q4 element uses bilinear shape functions: Ni = 0.25 * (1 + xi_i * xi) * (1 + eta_i * eta)

Examples

>>> from femlabpy import keq4e
>>> Xe = np.array([[0,0], [1,0], [1,1], [0,1]])
>>> Ge = np.array([200e9, 0.3])  # E, nu for plane stress
>>> Ke = keq4e(Xe, Ge)
>>> Ke.shape
(8, 8)
femlabpy.elements.quads.keq4epe(Xe, Ge, Se, Ee, mtype: int = 1)[source]#

Compute the consistent tangent of a plane-strain elastoplastic Q4 element.

Parameters:
Xe:

Element coordinates with shape (4, 2).

Ge:

Material row [E, nu, Sy0, H] or [E, nu, Sy0, H, phi].

Se, Ee:

Previous Gauss-point stress and history tables with shape (4, 5).

mtype:

1 for von Mises and 2 for Drucker-Prager.

Returns:
ndarray

8 x 8 consistent tangent stiffness matrix.

femlabpy.elements.quads.keq4eps(Xe, Ge, Se, Ee, mtype: int = 1)[source]#

Compute the consistent tangent of a plane-stress elastoplastic Q4 element.

Parameters:
Xe:

Element coordinates with shape (4, 2).

Ge:

Material row [E, nu, Sy0, H] or [E, nu, Sy0, H, phi].

Se, Ee:

Previous Gauss-point stress and history tables with shape (4, 4).

mtype:

1 for von Mises and 2 for Drucker-Prager.

Returns:
ndarray

8 x 8 consistent tangent stiffness matrix.

femlabpy.elements.quads.keq4p(Xe, Ge)[source]#

Compute the scalar conductivity matrix for a 4-node quadrilateral.

Parameters:
Xe:

Element coordinates with shape (4, 2).

Ge:

Material row [k] or [k, b] where b is an optional reaction coefficient.

Returns:
ndarray

4 x 4 conductivity matrix integrated with 2 x 2 Gauss points.

femlabpy.elements.quads.kq4e(K, T, X, G)[source]#

Assemble Q4 element stiffness matrices into global stiffness matrix.

Parameters:
Kndarray, shape (ndof, ndof)

Global stiffness matrix (modified in place).

Tarray_like, shape (nel, 5)

Element topology: [n1, n2, n3, n4, mat_id] per row (1-based).

Xarray_like, shape (nn, 2)

Nodal coordinates.

Garray_like, shape (nmat, 2+)

Material properties: [E, nu, type] per material.

Returns:
Kndarray

Updated global stiffness matrix.

Examples

>>> from femlabpy import init, kq4e
>>> K, q, p, C, P, S = init(nn=27, nd=2)
>>> K = kq4e(K, T, X, G)
femlabpy.elements.quads.kq4epe(K, T, X, G, S, E, mtype: int = 1)[source]#

Assemble plane-strain plastic Q4 tangent matrices into the global matrix.

femlabpy.elements.quads.kq4eps(K, T, X, G, S, E, mtype: int = 1)[source]#

Assemble plane-stress plastic Q4 tangent matrices into the global matrix.

femlabpy.elements.quads.kq4p(K, T, X, G)[source]#

Assemble Q4 scalar conductivity matrices into the global system.

Parameters:
K:

Global conductivity matrix.

T:

Topology table [n1, n2, n3, n4, mat_id].

X:

Nodal coordinates.

G:

Material table with conductivity rows.

Returns:
ndarray or sparse matrix

Updated global conductivity matrix.

femlabpy.elements.quads.meq4e(Xe, Ge, *, lumped: bool = False)[source]#

Compute the element mass matrix for a 4-node quadrilateral (Q4) element.

Parameters:
Xearray_like, shape (4, 2)

Nodal coordinates.

Gearray_like

Material row. Thickness t from Ge[3] (default 1). Density rho from Ge[4] (default 1).

lumpedbool

If True, return the diagonally lumped mass matrix.

Returns:
Mendarray, shape (8, 8)
femlabpy.elements.quads.mq4e(M, T, X, G, *, lumped: bool = False)[source]#

Assemble Q4 element mass matrices into the global mass matrix.

Parameters:
Mndarray or sparse, shape (ndof, ndof)

Global mass matrix (modified in place).

Tarray_like, shape (nel, 5)

Topology table [n1, n2, n3, n4, mat_id].

Xarray_like, shape (nn, 2)

Nodal coordinates.

Garray_like

Material table.

lumpedbool

If True, assemble lumped mass.

Returns:
Mndarray or sparse

Updated global mass matrix.

femlabpy.elements.quads.qeq4e(Xe, Ge, Ue)[source]#

Compute stresses and strains at Gauss points for a single Q4 element.

Parameters:
Xearray_like, shape (4, 2)

Nodal coordinates.

Gearray_like

Material properties [E, nu] or [E, nu, type].

Uearray_like, shape (8,)

Element displacements [u1, v1, u2, v2, u3, v3, u4, v4].

Returns:
qendarray, shape (8, 1)

Element internal force vector.

Sendarray, shape (4, 3)

Stresses at 4 Gauss points: [sxx, syy, txy] per row.

Eendarray, shape (4, 3)

Strains at 4 Gauss points: [exx, eyy, gxy] per row.

Examples

>>> qe, stresses, strains = qeq4e(Xe, Ge, Ue)
>>> avg_stress = np.mean(stresses, axis=0)  # element average
femlabpy.elements.quads.qeq4epe(Xe, Ge, Ue, Se, Ee, mtype: int = 1)[source]#

Update plane-strain elastoplastic Q4 response at the four Gauss points.

Parameters:
Xe, Ge:

Element coordinates and material row.

Ue:

Element displacement vector.

Se, Ee:

Previous Gauss-point stress and history tables with shape (4, 5).

mtype:

1 for von Mises and 2 for Drucker-Prager.

Returns:
tuple[ndarray, ndarray, ndarray]

Element internal-force vector together with updated stress and history tables.

femlabpy.elements.quads.qeq4eps(Xe, Ge, Ue, Se, Ee, mtype: int = 1)[source]#

Update plane-stress elastoplastic Q4 response at the four Gauss points.

Parameters:
Xe, Ge:

Element coordinates and material row.

Ue:

Element displacement vector.

Se, Ee:

Previous Gauss-point stress and history tables with shape (4, 4).

mtype:

1 for von Mises and 2 for Drucker-Prager.

Returns:
tuple[ndarray, ndarray, ndarray]

Element internal-force vector together with updated stress and history tables.

femlabpy.elements.quads.qeq4p(Xe, Ge, Ue)[source]#

Recover gradients and fluxes for one Q4 scalar potential element.

Parameters:
Xe:

Element coordinates with shape (4, 2).

Ge:

Material row [k] or [k, b].

Ue:

Element nodal potentials.

Returns:
tuple[ndarray, ndarray, ndarray]

Element flux vector, Gauss-point fluxes, and Gauss-point gradients.

femlabpy.elements.quads.qq4e(q, T, X, G, u)[source]#

Compute stresses/strains for all Q4 elements and assemble internal forces.

Parameters:
qndarray, shape (ndof, 1)

Global internal force vector (modified in place).

Tarray_like, shape (nel, 5)

Element topology: [n1, n2, n3, n4, mat_id] per row (1-based).

Xarray_like, shape (nn, 2)

Nodal coordinates.

Garray_like, shape (nmat, 2+)

Material properties.

uarray_like, shape (nn, 2) or (ndof,)

Nodal displacement vector.

Returns:
qndarray

Updated internal force vector.

Sndarray, shape (nel, 12)

Stresses at 4 Gauss points per element. Each row: [sxx_1, syy_1, txy_1, sxx_2, …, txy_4]

Endarray, shape (nel, 12)

Strains at 4 Gauss points per element.

Examples

>>> q, S, E = qq4e(q, T, X, G, u)
>>> # Get element-averaged stresses
>>> S_avg = S.reshape(-1, 4, 3).mean(axis=1)
femlabpy.elements.quads.qq4epe(q, T, X, G, u, S, E, mtype: int = 1)[source]#

Compute plane-strain plastic Q4 internal forces and updated history fields.

femlabpy.elements.quads.qq4eps(q, T, X, G, u, S, E, mtype: int = 1)[source]#

Compute plane-stress plastic Q4 internal forces and updated history fields.

femlabpy.elements.quads.qq4p(q, T, X, G, u)[source]#

Recover Q4 scalar gradients and assemble equivalent nodal fluxes.

Parameters:
q:

Global nodal flux vector.

T:

Topology table [n1, n2, n3, n4, mat_id].

X:

Nodal coordinates.

G:

Material table with conductivity rows.

u:

Global nodal potentials.

Returns:
tuple[ndarray, ndarray, ndarray]

Updated nodal flux vector, Gauss-point fluxes, and Gauss-point gradients.