femlabpy.elements.triangles#
Triangular element kernels for constant-strain and scalar diffusion problems.
Workflow role#
This module covers the three-node triangle family in both structural and potential-flow style settings. It includes single-element stiffness and force evaluations, batch-friendly assembly wrappers, and the triangular mass matrix used in dynamic problems.
Public entry points#
ket3eandqet3eimplement the structural constant-strain triangle.ket3pandqet3pimplement the scalar potential variant.kt3e,qt3e,kt3p, andqt3passemble those kernels globally.met3eandmt3eprovide mass-matrix support for structural triangles.
Functions#
|
Compute the element stiffness matrix for a 3-node triangular element (CST). |
|
Compute the conductivity matrix for a 3-node scalar potential triangle. |
|
Assemble T3 (CST) element stiffness matrices into global stiffness matrix. |
|
Assemble T3 conductivity matrices into a global scalar system. |
|
Compute the element mass matrix for a 3-node triangular (CST) element. |
|
Assemble T3 element mass matrices into the global mass matrix. |
|
Compute stresses and strains for a single T3 element. |
|
Recover gradients and fluxes for one 3-node scalar potential triangle. |
|
Compute element stresses/strains for all T3 elements and assemble internal forces. |
|
Recover T3 scalar gradients and assemble equivalent nodal fluxes. |
Function Reference#
- femlabpy.elements.triangles.ket3e(Xe, Ge)[source]#
Compute the element stiffness matrix for a 3-node triangular element (CST).
This function computes the 6x6 stiffness matrix for a constant strain triangle (T3/CST) element under plane stress or plane strain conditions.
- Parameters:
- Xearray_like, shape (3, 2)
Nodal coordinates of the triangle. Each row contains [x, y] coordinates of a node. Node ordering: counter-clockwise.
- Gearray_like
Material properties vector.
Ge[0]is Young’s modulus,Ge[1]is Poisson’s ratio, and the optionalGe[2]selects the formulation:1or omitted for plane stress and2for plane strain.
- Returns:
- Kendarray, shape (6, 6)
Element stiffness matrix. DOF ordering: [u1, v1, u2, v2, u3, v3]
Notes
The CST element assumes constant strain throughout the element. For better accuracy, use finer meshes or higher-order elements.
Examples
>>> import numpy as np >>> from femlabpy import ket3e >>> # Right triangle with unit sides >>> Xe = np.array([[0, 0], [1, 0], [0, 1]]) >>> Ge = np.array([200e9, 0.3]) # Steel, plane stress >>> Ke = ket3e(Xe, Ge) >>> Ke.shape (6, 6)
- femlabpy.elements.triangles.ket3p(Xe, Ge)[source]#
Compute the conductivity matrix for a 3-node scalar potential triangle.
- Parameters:
- Xe:
Triangle coordinates with shape
(3, 2).- Ge:
Material row
[k]or[k, b]wherekis conductivity andbis an optional reaction term.
- Returns:
- ndarray
3 x 3element conductivity matrix.
- femlabpy.elements.triangles.kt3e(K, T, X, G)[source]#
Assemble T3 (CST) element stiffness matrices into global stiffness matrix.
This function loops over all triangular elements and assembles their contributions into the global stiffness matrix K.
- Parameters:
- Kndarray or sparse matrix, shape (ndof, ndof)
Global stiffness matrix (modified in place).
- Tarray_like, shape (nel, 4)
Element topology matrix. Each row: [n1, n2, n3, mat_id] where n1, n2, n3 are 1-based node indices and mat_id is the material index into G.
- Xarray_like, shape (nn, 2)
Nodal coordinates matrix. Each row: [x, y].
- Garray_like, shape (nmat, 2) or (nmat, 3)
Material properties matrix. Each row: [E, nu] or [E, nu, type]. type=1: plane stress (default), type=2: plane strain.
- Returns:
- Kndarray or sparse matrix
Updated global stiffness matrix.
Notes
Node numbering in T is 1-based (MATLAB/Fortran convention).
Supports both dense and scipy.sparse matrices.
Uses vectorized operations for efficiency.
Examples
>>> from femlabpy import init, kt3e >>> K, q, p, C, P, S = init(nn=10, nd=2) >>> # T: element connectivity, X: node coords, G: materials >>> K = kt3e(K, T, X, G)
- femlabpy.elements.triangles.kt3p(K, T, X, G)[source]#
Assemble T3 conductivity matrices into a global scalar system.
- Parameters:
- K:
Global conductivity matrix.
- T:
Topology table
[n1, n2, n3, mat_id].- X:
Nodal coordinates.
- G:
Material table with conductivity rows.
- Returns:
- ndarray or sparse matrix
Updated global conductivity matrix.
- femlabpy.elements.triangles.met3e(Xe, Ge, *, lumped: bool = False)[source]#
Compute the element mass matrix for a 3-node triangular (CST) element.
- Consistent (6x6):
M = (rho * t * A / 12) * [[2,1,1],[1,2,1],[1,1,2]] tensor I_2
- Lumped (diagonal):
M = (rho * t * A / 3) * I_6
- Parameters:
- Xearray_like, shape (3, 2)
Nodal coordinates.
- Gearray_like
Material row. Thickness
tis taken fromGe[3]if present (default 1). Densityrhois taken fromGe[4]if present (default 1).
- Returns:
- Mendarray, shape (6, 6)
- femlabpy.elements.triangles.mt3e(M, T, X, G, *, lumped: bool = False)[source]#
Assemble T3 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, 4)
Topology table
[n1, n2, n3, 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.triangles.qet3e(Xe, Ge, Ue)[source]#
Compute stresses and strains for a single T3 element.
- Parameters:
- Xearray_like, shape (3, 2)
Nodal coordinates [x, y] for each node.
- Gearray_like
Material properties: [E, nu] or [E, nu, type]. type=1: plane stress, type=2: plane strain.
- Uearray_like, shape (6,)
Element nodal displacements [u1, v1, u2, v2, u3, v3].
- Returns:
- qendarray, shape (6, 1)
Element internal force vector.
- Sendarray, shape (3,)
Stress components [sxx, syy, txy].
- Eendarray, shape (3,)
Strain components [exx, eyy, gxy].
Examples
>>> qe, stress, strain = qet3e(Xe, Ge, Ue) >>> print(f"sxx = {stress[0]:.2f}, syy = {stress[1]:.2f}, txy = {stress[2]:.2f}")
- femlabpy.elements.triangles.qet3p(Xe, Ge, Ue)[source]#
Recover gradients and fluxes for one 3-node scalar potential triangle.
- Parameters:
- Xe:
Triangle coordinates with shape
(3, 2).- Ge:
Material row
[k]or[k, b].- Ue:
Element nodal potentials.
- Returns:
- tuple[ndarray, ndarray, ndarray]
Element flux vector, flux components, and gradient components.
- femlabpy.elements.triangles.qt3e(q, T, X, G, u)[source]#
Compute element stresses/strains for all T3 elements and assemble internal forces.
- Parameters:
- qndarray, shape (ndof, 1)
Global internal force vector (modified in place).
- Tarray_like, shape (nel, 4)
Element topology: [n1, n2, n3, 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.
- uarray_like, shape (nn, 2) or (ndof,)
Nodal displacement vector.
- Returns:
- qndarray
Updated internal force vector.
- Sndarray, shape (nel, 3)
Stress at each element centroid: [sxx, syy, txy].
- Endarray, shape (nel, 3)
Strain at each element centroid: [exx, eyy, gxy].
Examples
>>> q, stresses, strains = qt3e(q, T, X, G, u) >>> max_stress = np.max(np.abs(stresses[:, 0])) # max sxx
- femlabpy.elements.triangles.qt3p(q, T, X, G, u)[source]#
Recover T3 scalar gradients and assemble equivalent nodal fluxes.
- Parameters:
- q:
Global nodal flux vector.
- T:
Topology table
[n1, n2, n3, mat_id].- X:
Nodal coordinates.
- G:
Material table with conductivity rows.
- u:
Global nodal potentials.
- Returns:
- tuple[ndarray, ndarray, ndarray]
Updated nodal flux vector, element fluxes, and element gradients.