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#
keq4eandqeq4eare the core elastic structural kernels.keq4pandqeq4pcover the scalar potential form.keq4epsandkeq4epewith their matchingqfunctions implement plane-stress and plane-strain plasticity.kq4*,qq4*, andmq4eare the assembled global wrappers.
Functions#
|
Compute element stiffness matrix for a 4-node quadrilateral (Q4) element. |
|
Compute the consistent tangent of a plane-strain elastoplastic Q4 element. |
|
Compute the consistent tangent of a plane-stress elastoplastic Q4 element. |
|
Compute the scalar conductivity matrix for a 4-node quadrilateral. |
|
Assemble Q4 element stiffness matrices into global stiffness matrix. |
|
Assemble plane-strain plastic Q4 tangent matrices into the global matrix. |
|
Assemble plane-stress plastic Q4 tangent matrices into the global matrix. |
|
Assemble Q4 scalar conductivity matrices into the global system. |
|
Compute the element mass matrix for a 4-node quadrilateral (Q4) element. |
|
Assemble Q4 element mass matrices into the global mass matrix. |
|
Compute stresses and strains at Gauss points for a single Q4 element. |
|
Update plane-strain elastoplastic Q4 response at the four Gauss points. |
|
Update plane-stress elastoplastic Q4 response at the four Gauss points. |
|
Recover gradients and fluxes for one Q4 scalar potential element. |
|
Compute stresses/strains for all Q4 elements and assemble internal forces. |
|
Compute plane-strain plastic Q4 internal forces and updated history fields. |
|
Compute plane-stress plastic Q4 internal forces and updated history fields. |
|
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:
1for von Mises and2for Drucker-Prager.
- Returns:
- ndarray
8 x 8consistent 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:
1for von Mises and2for Drucker-Prager.
- Returns:
- ndarray
8 x 8consistent 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]wherebis an optional reaction coefficient.
- Returns:
- ndarray
4 x 4conductivity matrix integrated with2 x 2Gauss 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
tfromGe[3](default 1). DensityrhofromGe[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:
1for von Mises and2for 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:
1for von Mises and2for 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.