Function reference

Core functions

CALFEM Core module

Contains all the functions implementing CALFEM standard functionality.

Copyright (c) Division of Structural Mechanics and Division of Solid Mechanics, Lund University.

calfem.core.assem(edof, K, Ke, f=None, fe=None)[source]

Assemble element matrices Ke (and fe) into the global stiffness matrix K (and global force vector f).

Parameters

edofarray_like

DOF topology array.

Karray_like

The global stiffness matrix.

Kearray_like

Element stiffness matrix.

farray_like, optional

The global force vector.

fearray_like, optional

Element force vector.

Returns

Kndarray

The updated global stiffness matrix.

fndarray, optional

The updated global force vector, if f and fe are provided.

calfem.core.bar1e(ex, ep, eq=None)[source]

Compute the stiffness matrix (and optionally load vector) for a 1D bar element.

Parameters

exarray_like

Element node coordinates [x1, x2].

eparray_like

Element properties [E, A], where E is Young’s modulus and A is cross-sectional area.

eqarray_like, optional

Distributed load [qX].

Returns

Kendarray

Bar stiffness matrix, shape (2, 2).

fendarray, optional

Element load vector, shape (2, 1), if eq is not None.

Examples

>>> bar1e([0, 2], [210e9, 0.01])
array([[ 1.05e+09, -1.05e+09],
       [-1.05e+09,  1.05e+09]])

History

LAST MODIFIED: O Dahlblom 2015-10-22

O Dahlblom 2022-11-14 (Python version)

calfem.core.bar1s(ex, ep, ed, eq=None, nep=None)[source]

Compute section forces in a 1D bar element.

Parameters

exarray_like

Element node coordinates [x1, x2].

eparray_like

Element properties [E, A], where E is Young’s modulus and A is cross-sectional area.

edarray_like

Element displacement vector [u1, u2].

eqarray_like, optional

Distributed load [qX].

nepint, optional

Number of evaluation points (default is 2).

Returns

esndarray

Section forces at evaluation points, shape (nep, 1).

edindarray, optional

Element displacements at evaluation points, shape (nep, 1), if nep is given.

ecindarray, optional

Evaluation points on the local x-axis, shape (nep, 1), if nep is given.

Examples

>>> bar1s([0, 2], [210e9, 0.01], [0.0, 0.001])
array([[1.05e+06],
       [1.05e+06]])

History

LAST MODIFIED: O Dahlblom 2021-02-25

O Dahlblom 2022-11-14 (Python version)

calfem.core.bar1we(ex, ep, eq=None)[source]

Compute the stiffness matrix (and optionally load vector) for a 1D bar element with axial springs.

Parameters

exarray_like

Element node coordinates [x1, x2].

eparray_like

Element properties [E, A, kX], where E is Young’s modulus, A is cross-sectional area, and kX is axial spring stiffness.

eqarray_like, optional

Distributed load [qX].

Returns

Kendarray

Bar stiffness matrix, shape (2, 2).

fendarray, optional

Element load vector, shape (2, 1), if eq is not None.

History

LAST MODIFIED: O Dahlblom 2015-12-17

O Dahlblom 2022-10-19 (Python version)

calfem.core.bar1ws(ex, ep, ed, eq=None, nep=None)[source]

Compute section forces in a 1D bar element with axial springs.

Parameters

exarray_like

Element node coordinates [x1, x2].

eparray_like

Element properties [E, A, kX], where E is Young’s modulus, A is cross-sectional area, and kX is axial spring stiffness.

edarray_like

Element displacement vector [u1, u2].

eqarray_like, optional

Distributed load [qX].

nepint, optional

Number of evaluation points (default is 2).

Returns

esndarray

Section forces at evaluation points, shape (nep, 1).

edindarray, optional

Element displacements at evaluation points, shape (nep, 1), if nep is given.

ecindarray, optional

Evaluation points on the local x-axis, shape (nep, 1), if nep is given.

History

LAST MODIFIED: O Dahlblom 2021-02-25

O Dahlblom 2022-11-14 (Python version)

calfem.core.bar2e(ex, ey, ep, eq=None)[source]

Compute the element stiffness matrix (and optionally load vector) for a 2D bar element.

Parameters

exarray_like

Element node x-coordinates [x1, x2].

eyarray_like

Element node y-coordinates [y1, y2].

eparray_like

Element properties [E, A], where E is Young’s modulus and A is cross-sectional area.

eqarray_like, optional

Distributed load [qX].

Returns

Kendarray

Bar stiffness matrix, shape (4, 4).

fendarray, optional

Element load vector, shape (4, 1), if eq is not None.

History

LAST MODIFIED: O Dahlblom 2015-10-20

O Dahlblom 2022-11-16 (Python version)

calfem.core.bar2ge(ex, ey, ep, QX)[source]

Compute the element stiffness matrix for a 2D bar element with additional axial force QX.

Parameters

exarray_like

Element node x-coordinates [x1, x2].

eyarray_like

Element node y-coordinates [y1, y2].

eparray_like

Element properties [E, A], where E is Young’s modulus and A is cross-sectional area.

QXfloat

Additional axial force.

Returns

Kendarray

Bar stiffness matrix, shape (4, 4).

History

LAST MODIFIED: O Dahlblom 2015-12-17

O Dahlblom 2022-11-16 (Python version)

calfem.core.bar2gs(ex, ey, ep, ed, nep=None)[source]

Compute normal force and axial force in a 2D bar element (bar2ge).

Parameters

exarray_like

Element node x-coordinates [x1, x2].

eyarray_like

Element node y-coordinates [y1, y2].

eparray_like

Element properties [E, A], where E is Young’s modulus and A is cross-sectional area.

edarray_like

Element displacement vector [u1, …, u4].

nepint, optional

Number of evaluation points (default is 2).

Returns

esndarray

Section forces at evaluation points, shape (nep, 1).

QXfloat

Axial force.

edindarray, optional

Element displacements at evaluation points, shape (nep, 1), if nep is given.

ecindarray, optional

Evaluation points on the local x-axis, shape (nep, 1), if nep is given.

History

LAST MODIFIED: O Dahlblom 2015-10-20

O Dahlblom 2022-11-16 (Python version)

calfem.core.bar2s(ex, ey, ep, ed, eq=None, nep=None)[source]

Compute normal force in a 2D bar element.

Parameters

exarray_like

Element node x-coordinates [x1, x2].

eyarray_like

Element node y-coordinates [y1, y2].

eparray_like

Element properties [E, A], where E is Young’s modulus and A is cross-sectional area.

edarray_like

Element displacement vector [u1, …, u4].

eqarray_like, optional

Distributed load [qX].

nepint, optional

Number of evaluation points (default is 2).

Returns

esndarray

Section forces at evaluation points, shape (nep, 1).

edindarray, optional

Element displacements at evaluation points, shape (nep, 1), if nep is given.

ecindarray, optional

Evaluation points on the local x-axis, shape (nep, 1), if nep is given.

History

LAST MODIFIED: O Dahlblom 2015-12-04

O Dahlblom 2022-11-16 (Python version)

calfem.core.bar3e(ex, ey, ez, ep, eq=None)[source]

Compute the element stiffness matrix (and optionally load vector) for a 3D bar element.

Parameters

exarray_like

Element node x-coordinates [x1, x2].

eyarray_like

Element node y-coordinates [y1, y2].

ezarray_like

Element node z-coordinates [z1, z2].

eparray_like

Element properties [E, A], where E is Young’s modulus and A is cross-sectional area.

eqarray_like, optional

Distributed load [qX].

Returns

Kendarray

Bar stiffness matrix, shape (6, 6).

fendarray, optional

Element load vector, shape (6, 1), if eq is not None.

History

LAST MODIFIED: O Dahlblom 2015-10-19

O Dahlblom 2022-11-18 (Python version)

calfem.core.bar3s(ex, ey, ez, ep, ed, eq=None, nep=None)[source]

Compute normal force in a 3D bar element.

Parameters

exarray_like

Element node x-coordinates [x1, x2].

eyarray_like

Element node y-coordinates [y1, y2].

ezarray_like

Element node z-coordinates [z1, z2].

eparray_like

Element properties [E, A], where E is Young’s modulus and A is cross-sectional area.

edarray_like

Element displacement vector [u1, …, u6].

eqarray_like, optional

Distributed load [qX].

nepint, optional

Number of evaluation points (default is 2).

Returns

esndarray

Section forces at evaluation points, shape (nep, 1).

edindarray, optional

Element displacements at evaluation points, shape (nep, 1), if nep is given.

ecindarray, optional

Evaluation points on the local x-axis, shape (nep, 1), if nep is given.

History

LAST MODIFIED: O Dahlblom 2021-09-01

O Dahlblom 2022-11-18 (Python version)

calfem.core.beam1e(ex, ep, eq=None)[source]

Compute the stiffness matrix (and optionally load vector) for a 1D beam element.

Parameters

exarray_like

Element node coordinates [x1, x2].

eparray_like

Element properties [E, I], where E is Young’s modulus and I is moment of inertia.

eqarray_like, optional

Distributed load [qY].

Returns

Kendarray

Beam stiffness matrix, shape (4, 4).

fendarray, optional

Element load vector, shape (4, 1), if eq is not None.

History

LAST MODIFIED: O Dahlblom 2019-01-09

O Dahlblom 2022-10-25 (Python version)

calfem.core.beam1s(ex, ep, ed, eq=None, nep=None)[source]

Compute section forces in a 1D beam element (beam1e).

Parameters

exarray_like

Element node coordinates [x1, x2].

eparray_like

Element properties [E, I], where E is Young’s modulus and I is moment of inertia.

edarray_like

Element displacement vector [u1, …, u4].

eqarray_like, optional

Distributed loads [qy], local directions.

nepint, optional

Number of evaluation points (default is 2).

Returns

esndarray

Section forces at evaluation points, shape (nep, 2).

edindarray, optional

Element displacements at evaluation points, shape (nep, 1), if nep is given.

ecindarray, optional

Evaluation points on the local x-axis, shape (nep, 1), if nep is given.

History

LAST MODIFIED: O Dahlblom 2021-09-01

O Dahlblom 2022-10-25 (Python version)

calfem.core.beam1we(ex, ep, eq=None)[source]

Compute the stiffness matrix (and optionally load vector) for a 1D beam element on elastic foundation.

Parameters

exarray_like

Element node coordinates [x1, x2].

eparray_like

Element properties [E, I, kY], where E is Young’s modulus, I is moment of inertia, and kY is transversal foundation stiffness.

eqarray_like, optional

Distributed load [qY].

Returns

Kendarray

Beam stiffness matrix, shape (4, 4).

fendarray, optional

Element load vector, shape (4, 1), if eq is not None.

History

LAST MODIFIED: O Dahlblom 2016-02-17

O Dahlblom 2022-10-18 (Python version)

calfem.core.beam1ws(ex, ep, ed, eq=None, nep=None)[source]

Compute section forces in a 1D beam element on elastic foundation (beam1we).

Parameters

exarray_like

Element node coordinates [x1, x2].

eparray_like

Element properties [E, I, kY], where E is Young’s modulus, I is moment of inertia, and kY is transversal foundation stiffness.

edarray_like

Element displacement vector [u1, …, u4].

eqarray_like, optional

Distributed loads [qy], local directions.

nepint, optional

Number of evaluation points (default is 2).

Returns

esndarray

Section forces at evaluation points, shape (nep, 2).

edindarray, optional

Element displacements at evaluation points, shape (nep, 1), if nep is given.

ecindarray, optional

Evaluation points on the local x-axis, shape (nep, 1), if nep is given.

History

LAST MODIFIED: O Dahlblom 2021-09-01

O Dahlblom 2022-10-18 (Python version)

calfem.core.beam2crd(ex=None, ey=None, ed=None, mag=None)[source]

Calculate the element continuous displacements for multiple identical 2D Bernoulli beam elements.

Parameters

exarray_like, optional

Element node x-coordinates.

eyarray_like, optional

Element node y-coordinates.

edarray_like, optional

Element displacement matrix.

magfloat, optional

Magnification factor.

Returns

excdndarray

Continuous x-coordinates.

eycdndarray

Continuous y-coordinates.

History

LAST MODIFIED: P-E AUSTRELL 1993-10-15

calfem.core.beam2crd_old(ex, ey, ed, mag)[source]

Calculate the element continuous displacements for multiple identical 2D Bernoulli beam elements.

Parameters

exarray_like

Element node x-coordinates.

eyarray_like

Element node y-coordinates.

edarray_like

Element displacement matrix.

magfloat

Magnification factor.

Returns

excdndarray

Continuous x-coordinates.

eycdndarray

Continuous y-coordinates.

History

LAST MODIFIED: P-E AUSTRELL 1993-10-15

J Lindemann 2021-12-30 (Python)

calfem.core.beam2de(ex, ey, ep)[source]

Calculate the stiffness matrix Ke, mass matrix Me, and optionally damping matrix Ce for a 2D elastic Bernoulli beam element.

Parameters

exarray_like

Element node x-coordinates [x1, x2].

eyarray_like

Element node y-coordinates [y1, y2].

eparray_like

Element properties [E, A, I, m, (a, b)], where E is Young’s modulus, A is cross-sectional area, I is moment of inertia, m is mass per unit length, and a, b are optional damping coefficients where Ce = a*Me + b*Ke.

Returns

Kendarray

Element stiffness matrix, shape (6, 6).

Mendarray

Element mass matrix, shape (6, 6).

Cendarray, optional

Element damping matrix, shape (6, 6), if damping coefficients are provided.

History

LAST MODIFIED: K Persson 1995-08-23

O Dahlblom 2022-12-08 (Python version)

calfem.core.beam2ds(ex, ey, ep, ed, ev, ea)[source]

Calculate element forces for multiple identical 2D Bernoulli beam elements in dynamic analysis.

Parameters

exarray_like

Element node x-coordinates [x1, x2].

eyarray_like

Element node y-coordinates [y1, y2].

eparray_like

Element properties [E, A, I, m, (a, b)], where E is Young’s modulus, A is cross-sectional area, I is moment of inertia, m is mass per unit length, and a, b are optional damping coefficients where Ce = a*Me + b*Ke.

edarray_like

Element displacement matrix.

evarray_like

Element velocity matrix.

eaarray_like

Element acceleration matrix.

Returns

esndarray

Element forces in local directions, shape (nie, 6). Each row contains [-N1, -V1, -M1, N2, V2, M2].

History

LAST MODIFIED: K Persson 1995-08-23

O Dahlblom 2022-12-08 (Python version)

calfem.core.beam2e(ex, ey, ep, eq=None)[source]

Compute the stiffness matrix (and optionally load vector) for a 2D beam element.

Parameters

exarray_like

Element node x-coordinates [x1, x2].

eyarray_like

Element node y-coordinates [y1, y2].

eparray_like

Element properties [E, A, I], where E is Young’s modulus, A is cross-sectional area, and I is moment of inertia.

eqarray_like, optional

Distributed loads [qX, qY], local directions.

Returns

Kendarray

Element stiffness matrix, shape (6, 6).

fendarray, optional

Element load vector, shape (6, 1), if eq is not None.

History

LAST MODIFIED: O Dahlblom 2015-08-17

O Dahlblom 2022-11-21 (Python version)

calfem.core.beam2ge(ex, ey, ep, QX, eq=None)[source]

Compute the element stiffness matrix (and optionally load vector) for a 2D beam element with geometric nonlinearity.

Parameters

exarray_like

Element node x-coordinates [x1, x2].

eyarray_like

Element node y-coordinates [y1, y2].

eparray_like

Element properties [E, A, I], where E is Young’s modulus, A is cross-sectional area, and I is moment of inertia.

QXfloat

Axial force in the beam.

eqarray_like, optional

Distributed transverse load [qY].

Returns

Kendarray

Element stiffness matrix, shape (6, 6).

fendarray, optional

Element load vector, shape (6, 1), if eq is not None.

History

LAST MODIFIED: O Dahlblom 2015-12-17

O Dahlblom 2022-12-08 (Python version)

calfem.core.beam2gs(ex, ey, ep, ed, QX, eq=None, nep=None)[source]

Calculate section forces in a 2D nonlinear beam element (beam2ge).

Parameters

exarray_like

Element node x-coordinates [x1, x2].

eyarray_like

Element node y-coordinates [y1, y2].

eparray_like

Element properties [E, A, I], where E is Young’s modulus, A is cross-sectional area, and I is moment of inertia.

edarray_like

Element displacement vector [u1, …, u6].

QXfloat

Axial force in the beam.

eqarray_like, optional

Distributed transverse load [qY].

nepint, optional

Number of evaluation points (default is 2).

Returns

esndarray

Section forces at evaluation points, shape (nep, 3).

QXfloat

Axial force.

edindarray, optional

Element displacements at evaluation points, shape (nep, 2), if nep is given.

ecindarray, optional

Evaluation points on the local x-axis, shape (nep, 1), if nep is given.

History

LAST MODIFIED: O Dahlblom 2021-09-01

O Dahlblom 2022-12-06 (Python version)

calfem.core.beam2gxe(ex, ey, ep, QX, eq=None)[source]

Compute the element stiffness matrix (and optionally load vector) for a 2D beam element with geometric nonlinearity (exact solution).

Parameters

exarray_like

Element node x-coordinates [x1, x2].

eyarray_like

Element node y-coordinates [y1, y2].

eparray_like

Element properties [E, A, I], where E is Young’s modulus, A is cross-sectional area, and I is moment of inertia.

QXfloat

Axial force in the beam.

eqarray_like, optional

Distributed transverse load.

Returns

Kendarray

Element stiffness matrix, shape (6, 6).

fendarray, optional

Element load vector, shape (6, 1), if eq is not None.

History

LAST MODIFIED: O Dahlblom 2021-06-21

O Dahlblom 2022-12-06 (Python version)

calfem.core.beam2gxs(ex, ey, ep, ed, QX, eq=None, nep=None)[source]

Calculate section forces in a 2D nonlinear beam element (beam2gxe).

Parameters

exarray_like

Element node x-coordinates [x1, x2].

eyarray_like

Element node y-coordinates [y1, y2].

eparray_like

Element properties [E, A, I], where E is Young’s modulus, A is cross-sectional area, and I is moment of inertia.

edarray_like

Element displacement vector [u1, …, u6].

QXfloat

Axial force in the beam.

eqarray_like, optional

Distributed transverse load.

nepint, optional

Number of evaluation points (default is 2).

Returns

esndarray

Section forces at evaluation points, shape (nep, 3).

QXfloat

Axial force.

edindarray, optional

Element displacements at evaluation points, shape (nep, 2), if nep is given.

ecindarray, optional

Evaluation points on the local x-axis, shape (nep, 1), if nep is given.

History

LAST MODIFIED: O Dahlblom 2021-06-21

O Dahlblom 2022-12-06 (Python version)

calfem.core.beam2s(ex, ey, ep, ed, eq=None, nep=None)[source]

Compute section forces in a 2D beam element (beam2e).

Parameters

exarray_like

Element node x-coordinates [x1, x2].

eyarray_like

Element node y-coordinates [y1, y2].

eparray_like

Element properties [E, A, I], where E is Young’s modulus, A is cross-sectional area, and I is moment of inertia.

edarray_like

Element displacement vector [u1, …, u6].

eqarray_like, optional

Distributed loads [qX, qY], local directions.

nepint, optional

Number of evaluation points (default is 2).

Returns

esndarray

Section forces at evaluation points, shape (nep, 3).

edindarray, optional

Element displacements at evaluation points, shape (nep, 2), if nep is given.

ecindarray, optional

Evaluation points on the local x-axis, shape (nep, 1), if nep is given.

History

LAST MODIFIED: O Dahlblom 2015-08-17

O Dahlblom 2022-11-21 (Python version)

calfem.core.beam2te(ex, ey, ep, eq=None)[source]

Compute the stiffness matrix (and optionally load vector) for a 2D Timoshenko beam element.

Parameters

exarray_like

Element node x-coordinates [x1, x2].

eyarray_like

Element node y-coordinates [y1, y2].

eparray_like

Element properties [E, Gm, A, I, ks], where E is Young’s modulus, Gm is shear modulus, A is cross-sectional area, I is moment of inertia, and ks is shear correction factor.

eqarray_like, optional

Distributed loads in local directions [qX, qY].

Returns

Kendarray

Element stiffness matrix, shape (6, 6).

fendarray, optional

Element load vector, shape (6, 1), if eq is not None.

History

LAST MODIFIED: O Dahlblom 2021-11-05

O Dahlblom 2022-12-08 (Python version)

calfem.core.beam2ts(ex, ey, ep, ed, eq=None, nep=None)[source]

Compute section forces in a 2D Timoshenko beam element (beam2te).

Parameters

exarray_like

Element node x-coordinates [x1, x2].

eyarray_like

Element node y-coordinates [y1, y2].

eparray_like

Element properties [E, G, A, I, ks], where E is Young’s modulus, G is shear modulus, A is cross-sectional area, I is moment of inertia, and ks is shear correction factor.

edarray_like

Element displacement vector [u1, …, u6].

eqarray_like, optional

Distributed loads in local directions [qx, qy].

nepint, optional

Number of evaluation points (default is 2).

Returns

esndarray

Section forces in local directions at evaluation points, shape (nep, 3). Each row contains [N, V, M] (normal force, shear force, moment).

edindarray, optional

Element displacements in local directions at evaluation points, shape (nep, 3), if nep is given. Each row contains [u, v, theta]. Note: For Timoshenko beam element, the rotation of the cross section is not equal to dv/dx.

ecindarray, optional

Local x-coordinates of the evaluation points, shape (nep, 1), if nep is given.

History

LAST MODIFIED: O Dahlblom 2021-11-05

O Dahlblom 2022-12-08 (Python version)

calfem.core.beam2we(ex, ey, ep, eq=None)[source]

Compute the stiffness matrix (and optionally load vector) for a 2D beam element on elastic foundation.

Parameters

exarray_like

Element node x-coordinates [x1, x2].

eyarray_like

Element node y-coordinates [y1, y2].

eparray_like

Element properties [E, A, I, kX, kY], where E is Young’s modulus, A is cross-sectional area, I is moment of inertia, kX is axial foundation stiffness, and kY is transversal foundation stiffness.

eqarray_like, optional

Distributed loads [qX, qY], local directions.

Returns

Kendarray

Element stiffness matrix, shape (6, 6).

fendarray, optional

Element load vector, shape (6, 1), if eq is not None.

History

LAST MODIFIED: O Dahlblom 2015-08-07

O Dahlblom 2022-11-21 (Python version)

calfem.core.beam2ws(ex, ey, ep, ed, eq=None, nep=None)[source]

Compute section forces in a 2D beam element on elastic foundation.

Parameters

exarray_like

Element node x-coordinates [x1, x2].

eyarray_like

Element node y-coordinates [y1, y2].

eparray_like

Element properties [E, A, I, kX, kY], where E is Young’s modulus, A is cross-sectional area, I is moment of inertia, kX is axial foundation stiffness, and kY is transversal foundation stiffness.

edarray_like

Element displacement vector [u1, …, u6].

eqarray_like, optional

Distributed loads [qX, qY], local directions.

nepint, optional

Number of evaluation points (default is 2).

Returns

esndarray

Section forces at evaluation points, shape (nep, 3).

edindarray, optional

Element displacements at evaluation points, shape (nep, 2), if nep is given.

ecindarray, optional

Evaluation points on the local x-axis, shape (nep, 1), if nep is given.

History

LAST MODIFIED: O Dahlblom 2022-09-30

O Dahlblom 2022-11-21 (Python version)

calfem.core.beam3e(ex, ey, ez, eo, ep, eq=None)[source]

Calculate the stiffness matrix (and optionally load vector) for a 3D elastic Bernoulli beam element.

Parameters

exarray_like

Element node x-coordinates [x1, x2].

eyarray_like

Element node y-coordinates [y1, y2].

ezarray_like

Element node z-coordinates [z1, z2].

eoarray_like

Orientation of local z-axis [xz, yz, zz].

eparray_like

Element properties [E, G, A, Iy, Iz, Kv], where E is Young’s modulus, G is shear modulus, A is cross-sectional area, Iy is moment of inertia about local y-axis, Iz is moment of inertia about local z-axis, and Kv is Saint-Venant’s torsion constant.

eqarray_like, optional

Distributed loads in local directions [qX, qY, qZ, qW].

Returns

Kendarray

Element stiffness matrix, shape (12, 12).

fendarray, optional

Element load vector, shape (12, 1), if eq is not None.

History

LAST MODIFIED: O Dahlblom 2015-10-19

O Dahlblom 2022-11-21 (Python version)

calfem.core.beam3s(ex, ey, ez, eo, ep, ed, eq=None, nep=None)[source]

Calculate the variation of section forces and displacements along a 3D beam element.

Parameters

exarray_like

Element node x-coordinates [x1, x2].

eyarray_like

Element node y-coordinates [y1, y2].

ezarray_like

Element node z-coordinates [z1, z2].

eoarray_like

Orientation of local z-axis [xz, yz, zz].

eparray_like

Element properties [E, G, A, Iy, Iz, Kv], where E is Young’s modulus, G is shear modulus, A is cross-sectional area, Iy is moment of inertia about local y-axis, Iz is moment of inertia about local z-axis, and Kv is Saint-Venant’s torsion constant.

edarray_like

Element displacement vector [u1, …, u12].

eqarray_like, optional

Distributed loads in local directions [qX, qY, qZ, qW].

nepint, optional

Number of evaluation points (default is 2).

Returns

esndarray

Section forces at evaluation points, shape (nep, 6). Each row contains [N, Vy, Vz, T, My, Mz] (normal force, shear forces, torque, moments).

edindarray, optional

Element displacements at evaluation points, shape (nep, 4), if nep is given. Each row contains [u, v, w, phi] (displacements and rotation).

ecindarray, optional

Local x-coordinates of the evaluation points, shape (nep, 1), if nep is given.

History

LAST MODIFIED: O Dahlblom 2015-10-19

O Dahlblom 2022-11-23 (Python version)

calfem.core.c_mul(a, b)[source]

Multiply two integers with 32-bit overflow handling.

Parameters

aint

First integer.

bint

Second integer.

Returns

int

Product of a and b with 32-bit overflow handling.

calfem.core.check_length(v, length, error_string)[source]

Check if the input has the specified length, raise ValueError if not.

Parameters

vobject

Object to check (must support len()).

calfem.core.check_list_array(v, error_string)[source]

Check if the input is a list or numpy array, raise TypeError if not.

Parameters

vobject

Object to check.

error_stringstr

Error message to display if check fails.

calfem.core.coord_extract(edof, coords, dofs, nen=-1)[source]

Create element coordinate matrices ex, ey, ez from edof coord and dofs matrices.

Parameters

edofarray_like

Element topology array, shape (nel, nen * nnd), where nel is number of elements, nen is number of element nodes, and nnd is number of node DOFs.

coordsarray_like

Node coordinates array, shape (ncoords, ndims), where ncoords is number of coordinates and ndims is node dimensions.

dofsarray_like

DOF array, shape (ncoords, nnd), where nnd is number of node DOFs.

nenint, optional

Number of element nodes. If -1, calculated from edof and dofs.

Returns

exndarray

Element x-coordinates, returned if ndims = 1.

ex, eytuple of ndarray

Element x and y coordinates, returned if ndims = 2.

ex, ey, eztuple of ndarray

Element x, y and z coordinates, returned if ndims = 3.

calfem.core.coordxtr(edof, coords, dofs, nen=-1)

Create element coordinate matrices ex, ey, ez from edof coord and dofs matrices.

Parameters

edofarray_like

Element topology array, shape (nel, nen * nnd), where nel is number of elements, nen is number of element nodes, and nnd is number of node DOFs.

coordsarray_like

Node coordinates array, shape (ncoords, ndims), where ncoords is number of coordinates and ndims is node dimensions.

dofsarray_like

DOF array, shape (ncoords, nnd), where nnd is number of node DOFs.

nenint, optional

Number of element nodes. If -1, calculated from edof and dofs.

Returns

exndarray

Element x-coordinates, returned if ndims = 1.

ex, eytuple of ndarray

Element x and y coordinates, returned if ndims = 2.

ex, ey, eztuple of ndarray

Element x, y and z coordinates, returned if ndims = 3.

calfem.core.create_dofs(nCoords, nDof)[source]

Create degree of freedom (DOF) array.

Parameters

nCoordsint

Number of coordinates (nodes).

nDofint

Number of degrees of freedom per coordinate.

Returns

ndarray

DOF array, shape (nCoords, nDof), with sequential DOF numbering starting from 1.

calfem.core.createdofs(nCoords, nDof)

Create degree of freedom (DOF) array.

Parameters

nCoordsint

Number of coordinates (nodes).

nDofint

Number of degrees of freedom per coordinate.

Returns

ndarray

DOF array, shape (nCoords, nDof), with sequential DOF numbering starting from 1.

calfem.core.disable_friendly_errors()[source]

Disable friendly error logging and restore the previous exception hook.

calfem.core.dofHash(dof)

Compute a hash value for a degree of freedom array.

Parameters

dofarray_like

Degree of freedom array.

Returns

int

Hash value for the DOF array.

calfem.core.dof_hash(dof)[source]

Compute a hash value for a degree of freedom array.

Parameters

dofarray_like

Degree of freedom array.

Returns

int

Hash value for the DOF array.

calfem.core.easy_off()

Disable friendly error logging and restore the previous exception hook.

calfem.core.easy_on()

Enable friendly error logging by setting a custom exception hook.

calfem.core.effmises(es, ptype)[source]

Calculate effective von mises stresses.

Parameters

esarray_like

Element stress matrix [[sigx, sigy, [sigz], tauxy], […]], one row for each element.

ptypeint

Analysis type: 1 : plane stress 2 : plane strain 3 : axisymmetry 4 : three dimensional

Returns

eseffndarray

Effective stress array [eseff_0, …, eseff_nel-1].

calfem.core.eigen(K, M, b=None)[source]

Solve the generalized eigenvalue problem |K-LM|X = 0, considering boundary conditions.

Parameters

Karray_like

Global stiffness matrix, shape (ndof, ndof).

Marray_like

Global mass matrix, shape (ndof, ndof).

barray_like, optional

Boundary condition vector, shape (nbc, 1).

Returns

Lndarray

Eigenvalue vector, shape (ndof-nbc, 1).

Xndarray

Eigenvectors, shape (ndof, ndof-nbc).

calfem.core.enable_friendly_errors()[source]

Enable friendly error logging by setting a custom exception hook.

calfem.core.error(msg)[source]

Log an error message.

Parameters

msgstr

Error message to log.

calfem.core.extractEldisp(edof, a)

Extract element displacements from the global displacement vector according to the topology matrix edof.

Parameters

aarray_like

The global displacement vector.

edofarray_like

DOF topology array.

Returns

edndarray

Element displacement array.

calfem.core.extract_ed(edof, a)

Extract element displacements from the global displacement vector according to the topology matrix edof.

Parameters

aarray_like

The global displacement vector.

edofarray_like

DOF topology array.

Returns

edndarray

Element displacement array.

calfem.core.extract_eldisp(edof, a)[source]

Extract element displacements from the global displacement vector according to the topology matrix edof.

Parameters

aarray_like

The global displacement vector.

edofarray_like

DOF topology array.

Returns

edndarray

Element displacement array.

calfem.core.flw2i4e(ex, ey, ep, D, eq=None)[source]

Compute element stiffness (conductivity) matrix for 4 node isoparametric field element.

Parameters

exarray_like

Element coordinates [x1, x2, x3, x4].

eyarray_like

Element coordinates [y1, y2, y3, y4].

eparray_like

Element properties [t, ir], where t is thickness and ir is integration rule.

Darray_like

Constitutive matrix [[kxx, kxy], [kyx, kyy]].

eqfloat, optional

Heat supply per unit volume.

Returns

Kendarray

Element ‘stiffness’ matrix, shape (4, 4).

fendarray, optional

Element load vector, shape (4, 1), if eq is not None.

calfem.core.flw2i4s(ex, ey, ep, D, ed)[source]

Compute flows or corresponding quantities in the 4 node isoparametric element.

Parameters

exarray_like

Element coordinates [x1, x2, x3, x4].

eyarray_like

Element coordinates [y1, y2, y3, y4].

eparray_like

Element properties [t, ir], where t is thickness and ir is integration rule.

Darray_like

Constitutive matrix [[kxx, kxy], [kyx, kyy]].

edarray_like

Element nodal values [u1, u2, u3, u4].

Returns

esndarray

Element flows [[qx, qy], [.., ..]].

etndarray

Element gradients [[qx, qy], […, ..]].

ecindarray

Gauss point location vector [[ix1, iy1], […, …], [ix(nint), iy(nint)]].

calfem.core.flw2i8e(ex, ey, ep, D, eq=None)[source]

Compute element stiffness (conductivity) matrix for 8 node isoparametric field element.

Parameters

exarray_like

Element coordinates [x1, …, x8].

eyarray_like

Element coordinates [y1, …, y8].

eparray_like

Element properties [t, ir], where t is thickness and ir is integration rule.

Darray_like

Constitutive matrix [[kxx, kxy], [kyx, kyy]].

eqfloat, optional

Heat supply per unit volume.

Returns

Kendarray

Element ‘stiffness’ matrix, shape (8, 8).

fendarray, optional

Element load vector, shape (8, 1), if eq is not None.

calfem.core.flw2i8s(ex, ey, ep, D, ed)[source]

Compute flows or corresponding quantities in the 8 node isoparametric element.

Parameters

exarray_like

Element coordinates [x1, x2, x3, …, x8].

eyarray_like

Element coordinates [y1, y2, y3, …, y8].

eparray_like

Element properties [t, ir], where t is thickness and ir is integration rule.

Darray_like

Constitutive matrix [[kxx, kxy], [kyx, kyy]].

edarray_like

Element nodal values [u1, …, u8].

Returns

esndarray

Element flows [[qx, qy], [.., ..]].

etndarray

Element gradients [[qx, qy], [.., ..]].

ecindarray

Gauss point location vector [[ix1, iy1], […, …], [ix(nint), iy(nint)]].

calfem.core.flw2qe(ex, ey, ep, D, eq=None)[source]

Compute element stiffness (conductivity) matrix for a quadrilateral field element. This function calculates the element stiffness matrix and optionally the load vector for a 4-node quadrilateral element used in 2D heat flow analysis. The quadrilateral is divided into 4 triangular sub-elements using the centroid as a common node.

Parameters

exarray_like

Element x-coordinates [x1, x2, x3, x4] for the 4 corner nodes.

eyarray_like

Element y-coordinates [y1, y2, y3, y4] for the 4 corner nodes.

eparray_like

Element properties [t] where t is the element thickness.

Darray_like

Constitutive matrix (2x2) for heat conductivity: [[kxx, kxy],

[kyx, kyy]]

where kxx, kyy are conductivities in x and y directions, and kxy, kyx are cross-conductivities.

eqfloat, optional

Heat supply per unit volume. If None, only stiffness matrix is computed. Default is None.

Returns

Kendarray

Element stiffness matrix (4x4) for the quadrilateral element.

fendarray, optional

Element load vector (4x1). Only returned when eq is provided.

calfem.core.flw2qs(ex, ey, ep, D, ed, eq=None)[source]

Compute flows or corresponding quantities in the quadrilateral field element.

Parameters

exarray_like

Element node x-coordinates [x1, x2, x3, x4].

eyarray_like

Element node y-coordinates [y1, y2, y3, y4].

eparray_like

Element properties [t], where t is element thickness.

Darray_like

Constitutive matrix [[kxx, kxy], [kyx, kyy]].

edarray_like

Element nodal values [[u1, u2, u3, u4], [.., .., .., ..]], where u1,u2,u3,u4 are nodal values.

Returns

esndarray

Element flows [[qx, qy], [.., ..]].

etndarray

Element gradients [[gx, gy], [.., ..]].

calfem.core.flw2te(ex, ey, ep, D, eq=None)[source]

Compute element stiffness (conductivity) matrix for a triangular field element.

Parameters

exarray_like

Element node x-coordinates [x1, x2, x3].

eyarray_like

Element node y-coordinates [y1, y2, y3].

eparray_like

Element properties [t], where t is the element thickness.

Darray_like

Constitutive matrix [[kxx, kxy], [kyx, kyy]].

eqfloat, optional

Heat supply per unit volume.

Returns

Kendarray

Element ‘stiffness’ matrix, shape (3, 3).

fendarray

Element load vector, shape (3, 1).

calfem.core.flw2ts(ex, ey, D, ed)[source]

Compute flows or corresponding quantities in the triangular field element.

Parameters

exarray_like

Element node x-coordinates [x1, x2, x3].

eyarray_like

Element node y-coordinates [y1, y2, y3].

Darray_like

Constitutive matrix [[kxx, kxy], [kyx, kyy]].

edarray_like

Element nodal values [u1, u2, u3], one row per element.

Returns

esndarray

Element flows, shape (n_elem, 2) or (2,) for single element.

etndarray

Element gradients, shape (n_elem, 2) or (2,) for single element.

calfem.core.flw3i8e(ex, ey, ez, ep, D, eq=None)[source]

Compute element stiffness (conductivity) matrix for 8 node isoparametric field element.

Parameters

exarray_like

Element node x-coordinates [x1, x2, x3, …, x8].

eyarray_like

Element node y-coordinates [y1, y2, y3, …, y8].

ezarray_like

Element node z-coordinates [z1, z2, z3, …, z8].

eparray_like

Element properties [ir], where ir is integration rule.

Darray_like

Constitutive matrix [[kxx, kxy, kxz], [kyx, kyy, kyz], [kzx, kzy, kzz]].

eqfloat, optional

Heat supply per unit volume.

Returns

Kendarray

Element ‘stiffness’ matrix, shape (8, 8).

fendarray, optional

Element load vector, shape (8, 1), if eq is not None.

calfem.core.flw3i8s(ex, ey, ez, ep, D, ed)[source]

Compute flows or corresponding quantities in the 8 node (3-dim) isoparametric field element.

Parameters

exarray_like

Element node x-coordinates [x1, x2, x3, …, x8].

eyarray_like

Element node y-coordinates [y1, y2, y3, …, y8].

ezarray_like

Element node z-coordinates [z1, z2, z3, …, z8].

eparray_like

Element properties [ir], where ir is integration rule.

Darray_like

Constitutive matrix [[kxx, kxy, kxz], [kyx, kyy, kyz], [kzx, kzy, kzz]].

edarray_like

Element nodal values [[u1, …, u8], [.., …, ..]].

Returns

esndarray

Element flows [[qx, qy, qz], [.., .., ..]].

etndarray

Element gradients [[qx, qy, qz], [.., .., ..]].

ecindarray

Gauss point location vector [[ix1, iy1, iz1], […, …, …], [ix(nint), iy(nint), iz(nint)]].

calfem.core.gfunc(G, dt)[source]

Form vector with function values at equally spaced points by linear interpolation.

Parameters

Garray_like

Time-function pairs [t_i, g_i], where t_i is time i and g_i is g(t_i), shape (np, 2).

dtfloat

Time step.

Returns

tndarray

1-D vector with equally spaced time points.

gndarray

1-D vector with corresponding function values.

calfem.core.hooke(ptype, E, v)[source]

Calculate the material matrix for a linear elastic and isotropic material.

Parameters

ptypeint

Analysis type: 1 : plane stress 2 : plane strain 3 : axisymmetry 4 : three dimensional

Efloat

Young’s modulus.

vfloat

Poisson’s ratio.

Returns

Dndarray

Material matrix.

calfem.core.info(msg)[source]

Log an informational message.

Parameters

msgstr

Informational message to log.

calfem.core.plani4e(ex, ey, ep, D, eq=None)[source]

Calculate the stiffness matrix for a 4 node isoparametric element in plane strain or plane stress.

Parameters

exarray_like

Element coordinates [x1, x2, x3, x4].

eyarray_like

Element coordinates [y1, y2, y3, y4].

eparray_like

Element properties [ptype, t, ir], where ptype is analysis type, t is thickness, and ir is integration rule.

Darray_like

Constitutive matrix.

eqarray_like, optional

Body force vector [bx, by], where bx, by are body forces in x, y directions.

Returns

Kendarray

Element stiffness matrix, shape (8, 8).

fendarray, optional

Equivalent nodal forces, shape (8, 1), if eq is provided.

calfem.core.planqe(ex, ey, ep, D, eq=None)[source]

Calculate the stiffness matrix for a quadrilateral plane stress or plane strain element.

Parameters

exarray_like

Element coordinates [x1, x2, x3, x4].

eyarray_like

Element coordinates [y1, y2, y3, y4].

eparray_like

Element properties [ptype, t], where ptype is analysis type and t is element thickness.

Darray_like

Constitutive matrix.

eqarray_like, optional

Body force vector [bx, by], where bx, by are body forces in x, y directions.

Returns

Kendarray

Element stiffness matrix, shape (8, 8).

fendarray, optional

Equivalent nodal forces, if eq is provided.

calfem.core.planqs(ex, ey, ep, D, ed, eq=None)[source]

Calculate element normal and shear stress for a quadrilateral plane stress or plane strain element.

Parameters

exarray_like

Element node x-coordinates [x1, x2, x3, x4].

eyarray_like

Element node y-coordinates [y1, y2, y3, y4].

eparray_like

Element properties [ptype, t], where ptype is analysis type and t is thickness.

Darray_like

Constitutive matrix.

edarray_like

Element displacement vector [u1, u2, …, u8].

eqarray_like, optional

Body force vector [bx, by], where bx, by are body forces in x, y directions.

Returns

esndarray

Element stress array [sigx, sigy, (sigz), tauxy].

etndarray

Element strain array [epsx, epsy, (epsz), gamxy].

calfem.core.plante(ex, ey, ep, D, eq=None)[source]

Calculate the stiffness matrix for a triangular plane stress or plane strain element.

Parameters

exarray_like

Element coordinates [x1, x2, x3].

eyarray_like

Element coordinates [y1, y2, y3].

eparray_like

Element properties [ptype, t], where ptype is analysis type and t is thickness.

Darray_like

Constitutive matrix.

eqarray_like, optional

Body force vector [bx, by], where bx, by are body forces in x, y directions.

Returns

Kendarray

Element stiffness matrix, shape (6, 6).

fendarray, optional

Equivalent nodal forces, shape (6, 1), if eq is given.

calfem.core.plantf(ex, ey, ep, es)[source]

Compute internal element force vector in a triangular element in plane stress or plane strain.

Parameters

exarray_like

Element node x-coordinates [x1, x2, x3].

eyarray_like

Element node y-coordinates [y1, y2, y3].

eparray_like

Element properties [ptype, t], where ptype is analysis type and t is thickness.

esarray_like

Element stress matrix [[sigx, sigy, [sigz], tauxy], […]], one row for each element.

Returns

fendarray

Internal force vector [[f1], [f2], …, [f8]].

calfem.core.plants(ex, ey, ep, D, ed)[source]

Calculate element normal and shear stress for a triangular plane stress or plane strain element.

Parameters

exarray_like

Element node x-coordinates [x1, x2, x3].

eyarray_like

Element node y-coordinates [y1, y2, y3].

eparray_like

Element properties [ptype, t], where ptype is analysis type and t is thickness.

Darray_like

Constitutive matrix.

edarray_like

Element displacement vector [u1, u2, …, u6], one row for each element.

Returns

esndarray

Element stress matrix, one row for each element. Each row contains [sigx, sigy, [sigz], tauxy].

etndarray

Element strain matrix, one row for each element. Each row contains [epsx, epsy, [epsz], gamxy].

calfem.core.platre(ex, ey, ep, D, eq=None)[source]

Calculate the stiffness matrix for a rectangular plate element.

NOTE! Element sides must be parallel to the coordinate axis.

Parameters

exarray_like

Element coordinates [x1, x2, x3, x4].

eyarray_like

Element coordinates [y1, y2, y3, y4].

eparray_like

Element properties [t], where t is thickness.

Darray_like

Constitutive matrix for plane stress.

eqarray_like, optional

Load per unit area [qz].

Returns

Kendarray

Element stiffness matrix, shape (12, 12).

fendarray, optional

Equivalent nodal forces, shape (12, 1), if eq is not None.

calfem.core.red(A, b)[source]

Reduce the size of a square matrix by omitting rows and columns.

Algorithm for reducing the size of a square matrix A by omitting rows and columns defined by the matrix b.

Parameters

Aarray_like

Unreduced square matrix, shape (nd, nd).

barray_like

Boundary condition matrix containing DOF indices to remove, shape (nbc, 1) or (nbc,), where nbc is the number of constraints.

Returns

Bndarray

Reduced matrix with rows and columns removed.

Examples

>>> K = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
>>> bc = np.array([[2]])  # Remove row/column 2 (1-indexed)
>>> K_red = red(K, bc)
calfem.core.soli8e(ex, ey, ez, ep, D, eqp=None)[source]

Calculate the stiffness matrix (and optionally load vector) for an 8-node (brick) isoparametric element.

Parameters

exarray_like

Element node x-coordinates [x1, x2, x3, …, x8].

eyarray_like

Element node y-coordinates [y1, y2, y3, …, y8].

ezarray_like

Element node z-coordinates [z1, z2, z3, …, z8].

eparray_like

Element properties [ir], where ir is the integration rule.

Darray_like

Constitutive matrix.

eqparray_like, optional

Body force vector [bx, by, bz], where bx, by, bz are body forces in x, y, z directions.

Returns

Kendarray

Element stiffness matrix.

fendarray, optional

Equivalent nodal forces, if eqp is not None.

History

LAST MODIFIED: M Ristinmaa 1995-10-25

J Lindemann 2022-01-24 (Python version)

calfem.core.soli8s(ex, ey, ez, ep, D, ed)[source]

Calculate element normal and shear stress for an 8-node (brick) isoparametric element.

Parameters

exarray_like

Element node x-coordinates [x1, x2, x3, …, x8].

eyarray_like

Element node y-coordinates [y1, y2, y3, …, y8].

ezarray_like

Element node z-coordinates [z1, z2, z3, …, z8].

eparray_like

Element properties [Ir], where Ir is the integration rule.

Darray_like

Constitutive matrix.

edarray_like

Element displacement vector [u1, u2, …, u24].

Returns

esndarray

Element stress matrix, one row for each integration point. Each row contains [sigx, sigy, sigz, sigxy, sigyz, sigxz].

etndarray

Element strain matrix, one row for each integration point. Each row contains [epsx, epsy, epsz, epsxy, epsyz, epsxz].

History

LAST MODIFIED: M Ristinmaa 1995-10-25

J Lindemann 2022-02-23 (Python version)

calfem.core.solveq(K, f, bcPrescr=None, bcVal=None)[source]

Solve static FE-equations considering boundary conditions.

Parameters

Karray_like

Global stiffness matrix, shape (nd, nd).

farray_like

Global load vector, shape (nd, 1).

bcPrescrarray_like

1-dim integer array containing prescribed dofs.

bcValarray_like, optional

1-dim float array containing prescribed values. If not given all prescribed dofs are assumed 0.

Returns

andarray

Solution including boundary values, shape (nd, 1).

rndarray

Reaction force vector, shape (nd, 1).

calfem.core.spring1e(ep)[source]

Compute the element stiffness matrix for a spring element.

Parameters

eparray_like

Spring stiffness or analog quantity [k].

Returns

Kendarray

Spring stiffness matrix, shape (2, 2).

Examples

>>> spring1e(100)
array([[ 100, -100],
       [-100,  100]])

History

LAST MODIFIED: P-E Austrell 1994-11-02

O Dahlblom 2022-11-15 (Python version)

calfem.core.spring1s(ep, ed)[source]

Compute the element force in a spring element.

Parameters

eparray_like

Spring stiffness or analog quantity [k].

edarray_like

Element displacement vector [u1, u2].

Returns

esfloat

Element force.

Examples

>>> spring1s(100, [0.1, 0.2])
10.0

History

LAST MODIFIED: P-E Austrell 1994-11-02

O Dahlblom 2022-11-14 (Python version)

calfem.core.spsolveq(K, f, bcPrescr, bcVal=None)[source]

Solve static FE-equations considering boundary conditions.

Parameters

Karray_like

Global stiffness matrix, shape (nd, nd).

farray_like

Global load vector, shape (nd, 1).

bcPrescrarray_like

1-dim integer array containing prescribed dofs.

bcValarray_like, optional

1-dim float array containing prescribed values. If not given all prescribed dofs are assumed 0.

Returns

andarray

Solution including boundary values, shape (nd, 1).

Qndarray

Reaction force vector, shape (nd, 1).

calfem.core.statcon(K, f, cd)[source]

Condensation of static FE-equations according to the vector cd.

Parameters

Karray_like

Global stiffness matrix, shape (nd, nd).

farray_like

Global load vector, shape (nd, 1).

cdarray_like

Vector containing dof’s to be eliminated, shape (nc, 1), where nc is number of condensed dof’s.

Returns

K1ndarray

Condensed stiffness matrix, shape (nd-nc, nd-nc).

f1ndarray

Condensed load vector, shape (nd-nc, 1).

calfem.core.step1(K, C, f, a0, bc, ip, times, dofs)[source]

Algorithm for dynamic solution of first-order FE equations considering boundary conditions.

Parameters

Karray_like

Conductivity matrix, shape (ndof, ndof).

Carray_like

Capacity matrix, shape (ndof, ndof).

farray_like

Load vector, shape (ndof, nstep + 1). If shape (ndof, 1), the values are kept constant during time integration.

a0array_like

Initial vector a(0), shape (ndof, 1).

bcarray_like

Boundary condition matrix, shape (nbc, nstep + 2). where nbc = number of prescribed degrees of freedom (either constant or time-dependent). The first column contains the numbers of the prescribed degrees of freedom and the subsequent columns contain the time history. If shape (nbc, 2), the values from the second column are kept constant during time integration.

iparray_like

Array [dt, tottime, alpha], where dt is the size of the time increment, tottime is the total time, alpha is time integration constant. Frequently used values of alpha are: alpha=0: forward difference; forward Euler, alpha=1/2: trapezoidal rule; Crank-Nicholson alpha=1: backward difference; backward Euler

timesarray_like

Array [t(i) …] of times at which output should be written to a and da.

dofsarray_like

Array [dof(i) …] of degree of freedom numbers for which history output should be written to ahist and dahist.

Returns

modelhistdict

Dictionary containing solution history for the whole model with keys:

  • ‘a’ndarray

    Values of a at all timesteps, alternatively at times specified in ‘times’, shape (ndof, nstep + 1) or (ndof, ntimes).

  • ‘da’ndarray

    Values of da at all timesteps, alternatively at times specified in ‘times’, shape (ndof, nstep + 1) or (ndof, ntimes).

dofhistdict

Dictionary containing solution history for the degrees of freedom selected in ‘dofs’ with keys:

  • ‘a’ndarray

    Time history of a at the dofs specified in ‘dofs’, shape (ndof, nstep + 1).

  • ‘da’ndarray

    Time history of da at the dofs specified in ‘dofs’, shape (ndof, nstep + 1).

calfem.core.step2(K, C, M, f, a0, da0, bc, ip, times, dofs)[source]

Algorithm for dynamic solution of second-order FE equations considering boundary conditions.

Parameters

Karray_like

Global stiffness matrix, shape (ndof, ndof).

Carray_like

Global damping matrix, shape (ndof, ndof). If there is no damping in the system, simply set C=[].

Marray_like

Global mass matrix, shape (ndof, ndof).

farray_like

Global load vector, shape (ndof, nstep + 1). If shape (ndof, 1), the values are kept constant during time integration.

a0array_like

Initial displacement vector a(0), shape (ndof, 1).

da0array_like

Initial velocity vector v(0), shape (ndof, 1).

bcarray_like

Boundary condition matrix, shape (nbc, nstep + 2). where nbc = number of prescribed degrees of freedom (either constant or time-dependent). The first column contains the numbers of the prescribed degrees of freedom and the subsequent columns contain the time history. If shape (nbc, 2), the values from the second column are kept constant during time integration.

iparray_like

Array [dt, tottime, alpha, delta], where dt is the size of the time increment, tottime is the total time, alpha and delta are time integration constants for the Newmark family of methods. Frequently used values of alpha and delta are: alpha=1/4, delta=1/2: average acceleration (trapezoidal) rule, alpha=1/6, delta=1/2: linear acceleration, alpha=0, delta=1/2: central difference.

timesarray_like

Array [t(i) …] of times at which output should be written to a, da and d2a.

dofsarray_like

Array [dof(i) …] of degree of freedom numbers for which history output should be written to ahist, dahist and d2ahist.

Returns

modelhistdict

Dictionary containing solution history for the whole model with keys:

  • ‘a’ndarray

    Displacement values at all timesteps, alternatively at times specified in ‘times’, shape (ndof, nstep + 1) or (ndof, ntimes).

  • ‘da’ndarray

    Velocity values at all timesteps, alternatively at times specified in ‘times’, shape (ndof, nstep + 1) or (ndof, ntimes).

  • ‘d2a’ndarray

    Acceleration values at all timesteps, alternatively at times specified in ‘times’, shape (ndof, nstep + 1) or (ndof, ntimes).

dofhistdict

Dictionary containing solution history for the degrees of freedom selected in ‘dofs’ with keys:

  • ‘a’ndarray

    Displacement time history at the dofs specified in ‘dofs’, shape (ndof, nstep + 1).

  • ‘da’ndarray

    Velocity time history at the dofs specified in ‘dofs’, shape (ndof, nstep + 1).

  • ‘d2a’ndarray

    Acceleration time history at the dofs specified in ‘dofs’, shape (ndof, nstep + 1).

calfem.core.stress2nodal(eseff, edof)[source]

Convert element effective stresses to nodal effective stresses.

Parameters:

eseff = [eseff_0 .. eseff_nel-1] edof = [dof topology array]

Returns:

ev: element value array [[ev_0_0 ev_0_1 ev_0_nen-1 ]

ev_nel-1_0 ev_nel-1_1 ev_nel-1_nen-1]

calfem.core.user_warning(msg)[source]

Print a user warning message.

Parameters

msgstr

Warning message to display.

Geometry functions

CALFEM Geometry module

Contains functions and classes for describing geometry.

class calfem.geometry.Geometry[source]

Instances of GeoData can hold geometric data and be passed to GmshMesher in pycalfem_Mesh to mesh the geometry.

addBSpline(points, ID=None, marker=0, el_on_curve=None, el_distrib_type=None, el_distrib_val=None)

Adds a B-Spline curve

Parameters

pointslist

List of indices of control points that make a B-spline [p1, p2, … , pn]

IDint, optional

Positive integer ID of this curve. If left unspecified the curve will be assigned the smallest unused curve-ID. It is recommended to specify all curve-IDs or none.

markerint, optional

Marker applied to this curve. Default 0.

el_on_curveint, optional

Elements on curve. The number of element edges that will be distributed along this curve. Only works for structured meshes.

el_distrib_typestr, optional

Either “bump” or “progression”. Determines how the density of elements vary along the curve for structured meshes. Only works for structured meshes. el_on_curve and el_distrib_val must be be defined if this param is used.

el_distrib_valfloat, optional

Determines how severe the element distribution is. Only works for structured meshes. el_on_curve and el_distrib_type must be be defined if this param is used.

bump: Smaller value means elements are bunched up at the edges of the curve, larger means bunched in the middle.

progression: The edge of each element along this curve (from starting point to end) will be larger than the preceding one by this factor. el_distrib_val = 2 meaning for example that each line element in the series will be twice as long as the preceding one. el_distrib_val < 1 makes each element smaller than the preceeding one.

addCircle(points, ID=None, marker=0, el_on_curve=None, el_distrib_type=None, el_distrib_val=None)

Adds a Circle arc curve.

Parameters

pointslist

List of 3 indices of point that make a circle arc smaller than Pi. [startpoint, centerpoint, endpoint]

IDint, optional

Positive integer ID of this curve. If left unspecified the curve will be assigned the smallest unused curve-ID. It is recommended to specify all curve-IDs or none.

markerint, optional

Marker applied to this curve. Default 0.

el_on_curveint, optional

Elements on curve. The number of element edges that will be distributed along this curve. Only works for structured meshes.

el_distrib_typestr, optional

Either “bump” or “progression”. Determines how the density of elements vary along the curve for structured meshes. Only works for structured meshes. el_on_curve and el_distrib_val must be be defined if this param is used.

el_distrib_valfloat, optional

Determines how severe the element distribution is. Only works for structured meshes. el_on_curve and el_distrib_type must be be defined if this param is used.

bump: Smaller value means elements are bunched up at the edges of the curve, larger means bunched in the middle.

progression: The edge of each element along this curve (from starting point to end) will be larger than the preceding one by this factor. el_distrib_val = 2 meaning for example that each line element in the series will be twice as long as the preceding one. el_distrib_val < 1 makes each element smaller than the preceeding one.

addEllipse(points, ID=None, marker=0, el_on_curve=None, el_distrib_type=None, el_distrib_val=None)

Adds a Ellipse arc curve.

Parameters

pointslist

List of 4 indices of point that make a ellipse arc smaller than Pi. [startpoint, centerpoint, mAxisPoint, endpoint] Startpoint is the starting point of the arc. Centerpoint is the point at the center of the ellipse. MAxisPoint is any point on the major axis of the ellipse. Endpoint is the end point of the arc.

IDint, optional

Positive integer ID of this curve. If left unspecified the curve will be assigned the smallest unused curve-ID. It is recommended to specify all curve-IDs or none.

markerint, optional

Marker applied to this curve. Default 0.

el_on_curveint, optional

Elements on curve. The number of element edges that will be distributed along this curve. Only works for structured meshes.

el_distrib_typestr, optional

Either “bump” or “progression”. Determines how the density of elements vary along the curve for structured meshes. Only works for structured meshes. el_on_curve and el_distrib_val must be be defined if this param is used.

el_distrib_valfloat, optional

Determines how severe the element distribution is. Only works for structured meshes. el_on_curve and el_distrib_type must be be defined if this param is used.

bump: Smaller value means elements are bunched up at the edges of the curve, larger means bunched in the middle.

progression: The edge of each element along this curve (from starting point to end) will be larger than the preceding one by this factor. el_distrib_val = 2 meaning for example that each line element in the series will be twice as long as the preceding one. el_distrib_val < 1 makes each element smaller than the preceeding one.

addPoint(coord, ID=None, marker=0, el_size=1)

Adds a point.

Parameters

coordlist

[x, y] or [x, y, z]. List, not array.

IDint, optional

Positive integer ID of this point. If left unspecified the point will be assigned the smallest unused point-ID. It is recommended to specify all point-IDs or none.

markerint, optional

Marker applied to this point. Default 0. It is not a good idea to apply non-zero markers to points that are control points on B-splines or center points on circles/ellipses, since this can lead to “loose” nodes that are not part of any elements.

el_sizefloat, optional

The size of elements at this point. Default 1. Use to make a mesh denser or sparser here. Only affects unstructured meshes.

addPoints(points, markers=None, ids=None, elSizes=None)

Add points from a numpy-array

addRuledSurface(outer_loop, ID=None, marker=0)

Adds a Ruled Surface (bent surface).

Parameters

outer_looplist

List of 3 or 4 curve IDs that make up the boundary of the surface.

IDint, optional

Positive integer ID of this surface. If left unspecified the surface will be assigned the smallest unused surface-ID. It is recommended to specify all surface-IDs or none.

markerint, optional

Marker applied to this surface. Default 0.

addSpline(points, ID=None, marker=0, el_on_curve=None, el_distrib_type=None, el_distrib_val=None)

Adds a Spline curve

Parameters

pointslist

List of indices of control points that make a Spline [p1, p2, … , pn]

IDint, optional

Positive integer ID of this curve. If left unspecified the curve will be assigned the smallest unused curve-ID. It is recommended to specify all curve-IDs or none.

markerint, optional

Marker applied to this curve. Default 0.

el_on_curveint, optional

Elements on curve. The number of element edges that will be distributed along this curve. Only works for structured meshes.

el_distrib_typestr, optional

Either “bump” or “progression”. Determines how the density of elements vary along the curve for structured meshes. Only works for structured meshes. el_on_curve and el_distrib_val must be be defined if this param is used.

el_distrib_valfloat, optional

Determines how severe the element distribution is. Only works for structured meshes. el_on_curve and el_distrib_type must be be defined if this param is used.

bump: Smaller value means elements are bunched up at the edges of the curve, larger means bunched in the middle.

progression: The edge of each element along this curve (from starting point to end) will be larger than the preceding one by this factor. el_distrib_val = 2 meaning for example that each line element in the series will be twice as long as the preceding one. el_distrib_val < 1 makes each element smaller than the preceeding one.

addStructuredSurface(outer_loop, ID=None, marker=0)

Adds a Structured Surface.

Parameters

outer_looplist

List of 4 curve IDs that make up the boundary of the surface. The curves must be structured, i.e. their parameter ‘elOnCurv’ must be defined.

IDint, optional

Positive integer ID of this surface. If left unspecified the surface will be assigned the smallest unused surface-ID. It is recommended to specify all surface-IDs or none.

markerint, optional

Marker applied to this surface. Default 0.

addStructuredVolume(outer_surfaces, ID=None, marker=0)

Adds a Structured Volume

Parameters

outer_surfaceslist

List of surface IDs that make up the outer boundary of the volume. The surfaces must be Structured Surfaces.

IDint, optional

Positive integer ID of this volume. If left unspecified the volume will be assigned the smallest unused volume-ID. It is recommended to specify all volume-IDs or none.

markerint, optional

Marker applied to this volume. Default 0.

addSurface(outer_loop, holes=[], ID=None, marker=0)

Adds a plane surface (flat).

Parameters

outer_looplist

List of curve IDs that make up the outer boundary of the surface. The curves must lie in the same plane.

holeslist, optional

List of lists of curve IDs that make up the inner boundaries of the surface. The curves must lie in the same plane. Default [].

IDint, optional

Positive integer ID of this surface. If left unspecified the surface will be assigned the smallest unused surface-ID. It is recommended to specify all surface-IDs or none.

markerint, optional

Marker applied to this surface. Default 0.

addVolume(outer_surfaces, holes=[], ID=None, marker=0)

Adds a Volume

Parameters

outer_surfaceslist

List of surface IDs that make up the outer boundary of the volume.

holeslist, optional

List of lists of surface IDs that make up the inner boundaries of the volume. Default [].

IDint, optional

Positive integer ID of this volume. If left unspecified the volume will be assigned the smallest unused volume-ID. It is recommended to specify all volume-IDs or none.

markerint, optional

Marker applied to this volume. Default 0.

bounding_box_2d()[source]

Calculate bounding box geometry

bspline(points, ID=None, marker=0, el_on_curve=None, el_distrib_type=None, el_distrib_val=None)[source]

Adds a B-Spline curve

Parameters

pointslist

List of indices of control points that make a B-spline [p1, p2, … , pn]

IDint, optional

Positive integer ID of this curve. If left unspecified the curve will be assigned the smallest unused curve-ID. It is recommended to specify all curve-IDs or none.

markerint, optional

Marker applied to this curve. Default 0.

el_on_curveint, optional

Elements on curve. The number of element edges that will be distributed along this curve. Only works for structured meshes.

el_distrib_typestr, optional

Either “bump” or “progression”. Determines how the density of elements vary along the curve for structured meshes. Only works for structured meshes. el_on_curve and el_distrib_val must be be defined if this param is used.

el_distrib_valfloat, optional

Determines how severe the element distribution is. Only works for structured meshes. el_on_curve and el_distrib_type must be be defined if this param is used.

bump: Smaller value means elements are bunched up at the edges of the curve, larger means bunched in the middle.

progression: The edge of each element along this curve (from starting point to end) will be larger than the preceding one by this factor. el_distrib_val = 2 meaning for example that each line element in the series will be twice as long as the preceding one. el_distrib_val < 1 makes each element smaller than the preceeding one.

circle(points, ID=None, marker=0, el_on_curve=None, el_distrib_type=None, el_distrib_val=None)[source]

Adds a Circle arc curve.

Parameters

pointslist

List of 3 indices of point that make a circle arc smaller than Pi. [startpoint, centerpoint, endpoint]

IDint, optional

Positive integer ID of this curve. If left unspecified the curve will be assigned the smallest unused curve-ID. It is recommended to specify all curve-IDs or none.

markerint, optional

Marker applied to this curve. Default 0.

el_on_curveint, optional

Elements on curve. The number of element edges that will be distributed along this curve. Only works for structured meshes.

el_distrib_typestr, optional

Either “bump” or “progression”. Determines how the density of elements vary along the curve for structured meshes. Only works for structured meshes. el_on_curve and el_distrib_val must be be defined if this param is used.

el_distrib_valfloat, optional

Determines how severe the element distribution is. Only works for structured meshes. el_on_curve and el_distrib_type must be be defined if this param is used.

bump: Smaller value means elements are bunched up at the edges of the curve, larger means bunched in the middle.

progression: The edge of each element along this curve (from starting point to end) will be larger than the preceding one by this factor. el_distrib_val = 2 meaning for example that each line element in the series will be twice as long as the preceding one. el_distrib_val < 1 makes each element smaller than the preceeding one.

ellipse(points, ID=None, marker=0, el_on_curve=None, el_distrib_type=None, el_distrib_val=None)[source]

Adds a Ellipse arc curve.

Parameters

pointslist

List of 4 indices of point that make a ellipse arc smaller than Pi. [startpoint, centerpoint, mAxisPoint, endpoint] Startpoint is the starting point of the arc. Centerpoint is the point at the center of the ellipse. MAxisPoint is any point on the major axis of the ellipse. Endpoint is the end point of the arc.

IDint, optional

Positive integer ID of this curve. If left unspecified the curve will be assigned the smallest unused curve-ID. It is recommended to specify all curve-IDs or none.

markerint, optional

Marker applied to this curve. Default 0.

el_on_curveint, optional

Elements on curve. The number of element edges that will be distributed along this curve. Only works for structured meshes.

el_distrib_typestr, optional

Either “bump” or “progression”. Determines how the density of elements vary along the curve for structured meshes. Only works for structured meshes. el_on_curve and el_distrib_val must be be defined if this param is used.

el_distrib_valfloat, optional

Determines how severe the element distribution is. Only works for structured meshes. el_on_curve and el_distrib_type must be be defined if this param is used.

bump: Smaller value means elements are bunched up at the edges of the curve, larger means bunched in the middle.

progression: The edge of each element along this curve (from starting point to end) will be larger than the preceding one by this factor. el_distrib_val = 2 meaning for example that each line element in the series will be twice as long as the preceding one. el_distrib_val < 1 makes each element smaller than the preceeding one.

getPointCoords(IDs=None)[source]

Returns an N-by-3 list of point coordinates if the parameter is a list of IDs. If the parameter is just a single integer then a single coordinate (simple 3-element list) is returned. If the parameter is undefined (or None) all point coords will be returned

get_point_coords(IDs=None)

Returns an N-by-3 list of point coordinates if the parameter is a list of IDs. If the parameter is just a single integer then a single coordinate (simple 3-element list) is returned. If the parameter is undefined (or None) all point coords will be returned

line(points, ID=None, marker=0, el_on_curve=None, el_distrib_type=None, el_distrib_val=None)

Adds a Spline curve

Parameters

pointslist

List of indices of control points that make a Spline [p1, p2, … , pn]

IDint, optional

Positive integer ID of this curve. If left unspecified the curve will be assigned the smallest unused curve-ID. It is recommended to specify all curve-IDs or none.

markerint, optional

Marker applied to this curve. Default 0.

el_on_curveint, optional

Elements on curve. The number of element edges that will be distributed along this curve. Only works for structured meshes.

el_distrib_typestr, optional

Either “bump” or “progression”. Determines how the density of elements vary along the curve for structured meshes. Only works for structured meshes. el_on_curve and el_distrib_val must be be defined if this param is used.

el_distrib_valfloat, optional

Determines how severe the element distribution is. Only works for structured meshes. el_on_curve and el_distrib_type must be be defined if this param is used.

bump: Smaller value means elements are bunched up at the edges of the curve, larger means bunched in the middle.

progression: The edge of each element along this curve (from starting point to end) will be larger than the preceding one by this factor. el_distrib_val = 2 meaning for example that each line element in the series will be twice as long as the preceding one. el_distrib_val < 1 makes each element smaller than the preceeding one.

point(coord, ID=None, marker=0, el_size=1)[source]

Adds a point.

Parameters

coordlist

[x, y] or [x, y, z]. List, not array.

IDint, optional

Positive integer ID of this point. If left unspecified the point will be assigned the smallest unused point-ID. It is recommended to specify all point-IDs or none.

markerint, optional

Marker applied to this point. Default 0. It is not a good idea to apply non-zero markers to points that are control points on B-splines or center points on circles/ellipses, since this can lead to “loose” nodes that are not part of any elements.

el_sizefloat, optional

The size of elements at this point. Default 1. Use to make a mesh denser or sparser here. Only affects unstructured meshes.

points(points, markers=None, ids=None, elSizes=None)[source]

Add points from a numpy-array

pointsOnCurves(IDs)[source]

Returns a list of all geometric points (not nodes) on the curves specified in IDs. IDs may be an integer or a list of integers.

removeCurve(ID)[source]

Removes the curve with this ID

removePoint(ID)[source]

Removes the point with this ID

removeSurface(ID)[source]

Removes the surface with this ID

removeVolume(ID)[source]

Removes the volume with this ID

ruledSurface(outer_loop, ID=None, marker=0)

Adds a Ruled Surface (bent surface).

Parameters

outer_looplist

List of 3 or 4 curve IDs that make up the boundary of the surface.

IDint, optional

Positive integer ID of this surface. If left unspecified the surface will be assigned the smallest unused surface-ID. It is recommended to specify all surface-IDs or none.

markerint, optional

Marker applied to this surface. Default 0.

ruled_surf(outer_loop, ID=None, marker=0)

Adds a Ruled Surface (bent surface).

Parameters

outer_looplist

List of 3 or 4 curve IDs that make up the boundary of the surface.

IDint, optional

Positive integer ID of this surface. If left unspecified the surface will be assigned the smallest unused surface-ID. It is recommended to specify all surface-IDs or none.

markerint, optional

Marker applied to this surface. Default 0.

ruled_surface(outer_loop, ID=None, marker=0)[source]

Adds a Ruled Surface (bent surface).

Parameters

outer_looplist

List of 3 or 4 curve IDs that make up the boundary of the surface.

IDint, optional

Positive integer ID of this surface. If left unspecified the surface will be assigned the smallest unused surface-ID. It is recommended to specify all surface-IDs or none.

markerint, optional

Marker applied to this surface. Default 0.

setCurveMarker(ID, marker)[source]

Sets the marker of the curve with the ID

setPointMarker(ID, marker)[source]

Sets the marker of the point with the ID

setSurfaceMarker(ID, marker)[source]

Sets the marker of the surface with the ID

setVolumeMarker(ID, marker)[source]

Sets the marker of the volume with the ID

spline(points, ID=None, marker=0, el_on_curve=None, el_distrib_type=None, el_distrib_val=None)[source]

Adds a Spline curve

Parameters

pointslist

List of indices of control points that make a Spline [p1, p2, … , pn]

IDint, optional

Positive integer ID of this curve. If left unspecified the curve will be assigned the smallest unused curve-ID. It is recommended to specify all curve-IDs or none.

markerint, optional

Marker applied to this curve. Default 0.

el_on_curveint, optional

Elements on curve. The number of element edges that will be distributed along this curve. Only works for structured meshes.

el_distrib_typestr, optional

Either “bump” or “progression”. Determines how the density of elements vary along the curve for structured meshes. Only works for structured meshes. el_on_curve and el_distrib_val must be be defined if this param is used.

el_distrib_valfloat, optional

Determines how severe the element distribution is. Only works for structured meshes. el_on_curve and el_distrib_type must be be defined if this param is used.

bump: Smaller value means elements are bunched up at the edges of the curve, larger means bunched in the middle.

progression: The edge of each element along this curve (from starting point to end) will be larger than the preceding one by this factor. el_distrib_val = 2 meaning for example that each line element in the series will be twice as long as the preceding one. el_distrib_val < 1 makes each element smaller than the preceeding one.

splines(points)[source]

Add splines from numpy array

struct_surface(outer_loop, ID=None, marker=0)[source]

Adds a Structured Surface.

Parameters

outer_looplist

List of 4 curve IDs that make up the boundary of the surface. The curves must be structured, i.e. their parameter ‘elOnCurv’ must be defined.

IDint, optional

Positive integer ID of this surface. If left unspecified the surface will be assigned the smallest unused surface-ID. It is recommended to specify all surface-IDs or none.

markerint, optional

Marker applied to this surface. Default 0.

struct_volume(outer_surfaces, ID=None, marker=0)[source]

Adds a Structured Volume

Parameters

outer_surfaceslist

List of surface IDs that make up the outer boundary of the volume. The surfaces must be Structured Surfaces.

IDint, optional

Positive integer ID of this volume. If left unspecified the volume will be assigned the smallest unused volume-ID. It is recommended to specify all volume-IDs or none.

markerint, optional

Marker applied to this volume. Default 0.

structuredSurface(outer_loop, ID=None, marker=0)

Adds a Structured Surface.

Parameters

outer_looplist

List of 4 curve IDs that make up the boundary of the surface. The curves must be structured, i.e. their parameter ‘elOnCurv’ must be defined.

IDint, optional

Positive integer ID of this surface. If left unspecified the surface will be assigned the smallest unused surface-ID. It is recommended to specify all surface-IDs or none.

markerint, optional

Marker applied to this surface. Default 0.

structuredVolume(outer_surfaces, ID=None, marker=0)

Adds a Structured Volume

Parameters

outer_surfaceslist

List of surface IDs that make up the outer boundary of the volume. The surfaces must be Structured Surfaces.

IDint, optional

Positive integer ID of this volume. If left unspecified the volume will be assigned the smallest unused volume-ID. It is recommended to specify all volume-IDs or none.

markerint, optional

Marker applied to this volume. Default 0.

structured_surface(outer_loop, ID=None, marker=0)

Adds a Structured Surface.

Parameters

outer_looplist

List of 4 curve IDs that make up the boundary of the surface. The curves must be structured, i.e. their parameter ‘elOnCurv’ must be defined.

IDint, optional

Positive integer ID of this surface. If left unspecified the surface will be assigned the smallest unused surface-ID. It is recommended to specify all surface-IDs or none.

markerint, optional

Marker applied to this surface. Default 0.

structured_volume(outer_surfaces, ID=None, marker=0)

Adds a Structured Volume

Parameters

outer_surfaceslist

List of surface IDs that make up the outer boundary of the volume. The surfaces must be Structured Surfaces.

IDint, optional

Positive integer ID of this volume. If left unspecified the volume will be assigned the smallest unused volume-ID. It is recommended to specify all volume-IDs or none.

markerint, optional

Marker applied to this volume. Default 0.

stuffOnSurfaces(IDs)[source]

Returns lists of all geometric points and curves on the surfaces specified in IDs. IDs may be an integer or a list of integers

stuffOnVolumes(IDs)[source]

Returns lists of all geometric points, curves, and surfaces on the volumes specified in IDs. IDs may be an integer or a list of integers

surface(outer_loop, holes=[], ID=None, marker=0)[source]

Adds a plane surface (flat).

Parameters

outer_looplist

List of curve IDs that make up the outer boundary of the surface. The curves must lie in the same plane.

holeslist, optional

List of lists of curve IDs that make up the inner boundaries of the surface. The curves must lie in the same plane. Default [].

IDint, optional

Positive integer ID of this surface. If left unspecified the surface will be assigned the smallest unused surface-ID. It is recommended to specify all surface-IDs or none.

markerint, optional

Marker applied to this surface. Default 0.

volume(outer_surfaces, holes=[], ID=None, marker=0)[source]

Adds a Volume

Parameters

outer_surfaceslist

List of surface IDs that make up the outer boundary of the volume.

holeslist, optional

List of lists of surface IDs that make up the inner boundaries of the volume. Default [].

IDint, optional

Positive integer ID of this volume. If left unspecified the volume will be assigned the smallest unused volume-ID. It is recommended to specify all volume-IDs or none.

markerint, optional

Marker applied to this volume. Default 0.

Mesh functions

Utility functions

This is a utility module for the CALFEM Python library. It contains various utility functions that is used throughout the library. It includes functions for reading and writing files, applying boundary conditions, displaying messages, and exporting data in different formats.

calfem.utils.applyTractionLinearElement(boundaryElements, coords, dofs, F, marker, q)

Apply traction on part of boundary with marker.

q is added to all boundaryDofs defined by marker. Applicable to 2D problems with 2 dofs per node. The function works with linear line elements. (elm-type 1 in GMSH).

Parameters

boundaryElementsdict

Dictionary with boundary elements, the key is a marker and the values are lists of elements.

coordsarray_like

Coordinates matrix

dofsarray_like

Dofs matrix

Farray_like

force matrix.

markerint

Boundary marker to assign boundary condition.

qarray_like

Value to assign boundary condition. shape = [qx qy] in global coordinates

calfem.utils.apply_bc(boundaryDofs, bcPrescr, bcVal, marker, value=0.0, dimension=0)[source]

Apply boundary condition to bcPresc and bcVal matrices. For 2D problems with 2 dofs per node.

Parameters

boundaryDofsdict

Dictionary with boundary dofs.

bcPrescarray_like

1-dim integer array containing prescribed dofs.

bcValarray_like

1-dim float array containing prescribed values.

markerint

Boundary marker to assign boundary condition.

valuefloat, optional

Value to assign boundary condition. If not given 0.0 is assigned.

dimensionint, optional

dimension to apply bc. 0 - all, 1 - x, 2 - y

Returns

bcPrescarray_like

Updated 1-dim integer array containing prescribed dofs.

bcValarray_like

Updated 1-dim float array containing prescribed values.

calfem.utils.apply_bc_3d(boundaryDofs, bcPrescr, bcVal, marker, value=0.0, dimension=0)[source]

Apply boundary condition to bcPresc and bcVal matrices. For 3D problems with 3 dofs per node.

Parameters

boundaryDofsdict

Dictionary with boundary dofs.

bcPrescrarray_like

1-dim integer array containing prescribed dofs.

bcValarray_like

1-dim float array containing prescribed values.

markerint

Boundary marker to assign boundary condition.

valuefloat, optional

Value to assign boundary condition. If not given 0.0 is assigned.

dimensionint, optional

dimension to apply bc. 0 - all, 1 - x, 2 - y, 3 - z

Returns

bcPrescrarray_like

Updated 1-dim integer array containing prescribed dofs.

bcValarray_like

Updated 1-dim float array containing prescribed values.

calfem.utils.apply_bc_node(nodeIdx, dofs, bcPrescr, bcVal, value=0.0, dimension=0)[source]

Apply boundary conditions to a specific node. This function adds boundary condition prescriptions and values for a given node to existing boundary condition arrays.

Parameters

nodeIdxint

Index of the node to apply boundary conditions to.

dofsarray_like

Degrees of freedom array. Can be 1D (for single DOF per node) or 2D (for multiple DOFs per node).

bcPrescrarray_like

Existing array of prescribed boundary condition DOF indices.

bcValarray_like

Existing array of prescribed boundary condition values.

valuefloat, optional

Value to prescribe for the boundary condition. Default is 0.0.

dimensionint, optional

Dimension/direction to apply BC. If 0, applies to all DOFs of the node. If 1, 2, or 3, applies to specific dimension (1-indexed). Default is 0.

Returns

tuple of numpy.ndarray

A tuple containing: - Updated prescribed DOF indices array (bcPrescr concatenated with new DOFs) - Updated prescribed values array (bcVal concatenated with new values)

Notes

When dimension=0, boundary conditions are applied to all degrees of freedom for the specified node. When dimension is 1, 2, or 3, the boundary condition is applied only to that specific dimension (using 1-based indexing).

Examples

>>> # Apply BC to all DOFs of node 5 with value 0.0
>>> bc_dofs, bc_vals = apply_bc_node(5, dofs, [], [], 0.0, 0)
>>> 
>>> # Apply BC to x-direction (dimension 1) of node 10 with value 5.0
>>> bc_dofs, bc_vals = apply_bc_node(10, dofs, bc_dofs, bc_vals, 5.0, 1)
calfem.utils.apply_force(boundaryDofs, f, marker, value=0.0, dimension=0)[source]

Apply boundary force to f matrix. The value is added to all boundaryDofs defined by marker. Applicable to 2D problems with 2 dofs per node.

Parameters:

boundaryDofs Dictionary with boundary dofs. f force matrix. marker Boundary marker to assign boundary condition. value Value to assign boundary condition.

If not given 0.0 is assigned.

dimension dimension to apply force. 0 - all, 1 - x, 2 - y

calfem.utils.apply_force_3d(boundaryDofs, f, marker, value=0.0, dimension=0)[source]

Apply boundary force to f matrix for 3D problems. The value is added to all boundaryDofs defined by marker. Applicable to 3D problems with 3 degrees of freedom per node. Parameters ———- boundaryDofs : dict

Dictionary with boundary degrees of freedom.

fnumpy.ndarray

Force matrix to be modified.

markerint or str

Boundary marker to identify which boundary condition to apply.

valuefloat, optional

Value to add to the force matrix at specified boundary DOFs. Default is 0.0.

dimensionint, optional

Dimension to apply force: * 0 - all dimensions (default) * 1 - x-direction only * 2 - y-direction only * 3 - z-direction only

Notes

If the specified marker does not exist in boundaryDofs, an error message is printed. If an invalid dimension is specified (not 0, 1, 2, or 3), an error message is printed. Examples ——– >>> boundaryDofs = {1: [1, 2, 3, 4, 5, 6]} >>> f = np.zeros(6) >>> apply_force_3d(boundaryDofs, f, 1, value=100.0, dimension=1) # Applies force of 100.0 in x-direction to DOFs 1, 4

calfem.utils.apply_force_node(nodeIdx, dofs, f, value=0.0, dimension=0)[source]

Apply a force to a specific node in the finite element model. This function adds a force value to the global force vector at the degrees of freedom corresponding to a specified node. The force can be applied to all DOFs of the node or to a specific dimension. Parameters ———- nodeIdx : int

Index of the node where the force is to be applied.

dofsarray_like

Degrees of freedom array that maps nodes to their DOF indices in the global system. Can be 1D (for single DOF per node) or 2D (for multiple DOFs per node).

farray_like

Global force vector where the force will be added.

valuefloat, optional

Magnitude of the force to be applied. Default is 0.0.

dimensionint, optional

Specific dimension/DOF to apply the force to. If 0, applies to all DOFs of the node. If 1 or higher, applies to the specified dimension (1-indexed). Default is 0.

Notes

  • When dimension=0, the force is applied to all DOFs of the node (assumes 1D dofs array)

  • When dimension>=1, the force is applied to the specific dimension of the node (assumes 2D dofs array with shape [node, dimension])

  • The dimension parameter uses 1-based indexing (dimension=1 corresponds to first DOF)

Examples

>>> # Apply force to all DOFs of node 5
>>> apply_force_node(5, dofs, f, value=100.0, dimension=0)
>>> # Apply force to x-direction (dimension 1) of node 3
>>> apply_force_node(3, dofs, f, value=50.0, dimension=1)
calfem.utils.apply_force_total(boundaryDofs, f, marker, value=0.0, dimension=0)[source]

Apply boundary force to f matrix. Total force, value, is distributed over all boundaryDofs defined by marker. Applicable to 2D problems with 2 dofs per node.

Parameters

boundaryDofsdict

Dictionary with boundary dofs.

farray_like

Force matrix.

markerint

Boundary marker to assign boundary condition.

valuefloat, optional

Total force value to assign boundary condition. If not given 0.0 is assigned.

dimensionint, optional

Dimension to apply force. 0 - all, 1 - x, 2 - y

calfem.utils.apply_force_total_3d(boundaryDofs, f, marker, value=0.0, dimension=0)[source]

Apply boundary force to f matrix. Total force, value, is distributed over all boundaryDofs defined by marker. Applicable to 3D problems with 3 dofs per node.

Parameters

boundaryDofsdict

Dictionary with boundary dofs.

farray_like

Force matrix.

markerint

Boundary marker to assign boundary condition.

valuefloat, optional

Total force value to assign boundary condition. If not given 0.0 is assigned.

dimensionint, optional

Dimension to apply force. 0 - all, 1 - x, 2 - y, 3 - z

calfem.utils.apply_traction_linear_element(boundaryElements, coords, dofs, F, marker, q)[source]

Apply traction on part of boundary with marker.

q is added to all boundaryDofs defined by marker. Applicable to 2D problems with 2 dofs per node. The function works with linear line elements. (elm-type 1 in GMSH).

Parameters

boundaryElementsdict

Dictionary with boundary elements, the key is a marker and the values are lists of elements.

coordsarray_like

Coordinates matrix

dofsarray_like

Dofs matrix

Farray_like

force matrix.

markerint

Boundary marker to assign boundary condition.

qarray_like

Value to assign boundary condition. shape = [qx qy] in global coordinates

calfem.utils.applybc(boundaryDofs, bcPrescr, bcVal, marker, value=0.0, dimension=0)

Apply boundary condition to bcPresc and bcVal matrices. For 2D problems with 2 dofs per node.

Parameters

boundaryDofsdict

Dictionary with boundary dofs.

bcPrescarray_like

1-dim integer array containing prescribed dofs.

bcValarray_like

1-dim float array containing prescribed values.

markerint

Boundary marker to assign boundary condition.

valuefloat, optional

Value to assign boundary condition. If not given 0.0 is assigned.

dimensionint, optional

dimension to apply bc. 0 - all, 1 - x, 2 - y

Returns

bcPrescarray_like

Updated 1-dim integer array containing prescribed dofs.

bcValarray_like

Updated 1-dim float array containing prescribed values.

calfem.utils.applybc3D(boundaryDofs, bcPrescr, bcVal, marker, value=0.0, dimension=0)

Apply boundary condition to bcPresc and bcVal matrices. For 3D problems with 3 dofs per node.

Parameters

boundaryDofsdict

Dictionary with boundary dofs.

bcPrescrarray_like

1-dim integer array containing prescribed dofs.

bcValarray_like

1-dim float array containing prescribed values.

markerint

Boundary marker to assign boundary condition.

valuefloat, optional

Value to assign boundary condition. If not given 0.0 is assigned.

dimensionint, optional

dimension to apply bc. 0 - all, 1 - x, 2 - y, 3 - z

Returns

bcPrescrarray_like

Updated 1-dim integer array containing prescribed dofs.

bcValarray_like

Updated 1-dim float array containing prescribed values.

calfem.utils.applybcnode(nodeIdx, dofs, bcPrescr, bcVal, value=0.0, dimension=0)

Apply boundary conditions to a specific node. This function adds boundary condition prescriptions and values for a given node to existing boundary condition arrays.

Parameters

nodeIdxint

Index of the node to apply boundary conditions to.

dofsarray_like

Degrees of freedom array. Can be 1D (for single DOF per node) or 2D (for multiple DOFs per node).

bcPrescrarray_like

Existing array of prescribed boundary condition DOF indices.

bcValarray_like

Existing array of prescribed boundary condition values.

valuefloat, optional

Value to prescribe for the boundary condition. Default is 0.0.

dimensionint, optional

Dimension/direction to apply BC. If 0, applies to all DOFs of the node. If 1, 2, or 3, applies to specific dimension (1-indexed). Default is 0.

Returns

tuple of numpy.ndarray

A tuple containing: - Updated prescribed DOF indices array (bcPrescr concatenated with new DOFs) - Updated prescribed values array (bcVal concatenated with new values)

Notes

When dimension=0, boundary conditions are applied to all degrees of freedom for the specified node. When dimension is 1, 2, or 3, the boundary condition is applied only to that specific dimension (using 1-based indexing).

Examples

>>> # Apply BC to all DOFs of node 5 with value 0.0
>>> bc_dofs, bc_vals = apply_bc_node(5, dofs, [], [], 0.0, 0)
>>> 
>>> # Apply BC to x-direction (dimension 1) of node 10 with value 5.0
>>> bc_dofs, bc_vals = apply_bc_node(10, dofs, bc_dofs, bc_vals, 5.0, 1)
calfem.utils.applyforce(boundaryDofs, f, marker, value=0.0, dimension=0)

Apply boundary force to f matrix. The value is added to all boundaryDofs defined by marker. Applicable to 2D problems with 2 dofs per node.

Parameters:

boundaryDofs Dictionary with boundary dofs. f force matrix. marker Boundary marker to assign boundary condition. value Value to assign boundary condition.

If not given 0.0 is assigned.

dimension dimension to apply force. 0 - all, 1 - x, 2 - y

calfem.utils.applyforce3D(boundaryDofs, f, marker, value=0.0, dimension=0)

Apply boundary force to f matrix for 3D problems. The value is added to all boundaryDofs defined by marker. Applicable to 3D problems with 3 degrees of freedom per node. Parameters ———- boundaryDofs : dict

Dictionary with boundary degrees of freedom.

fnumpy.ndarray

Force matrix to be modified.

markerint or str

Boundary marker to identify which boundary condition to apply.

valuefloat, optional

Value to add to the force matrix at specified boundary DOFs. Default is 0.0.

dimensionint, optional

Dimension to apply force: * 0 - all dimensions (default) * 1 - x-direction only * 2 - y-direction only * 3 - z-direction only

Notes

If the specified marker does not exist in boundaryDofs, an error message is printed. If an invalid dimension is specified (not 0, 1, 2, or 3), an error message is printed. Examples ——– >>> boundaryDofs = {1: [1, 2, 3, 4, 5, 6]} >>> f = np.zeros(6) >>> apply_force_3d(boundaryDofs, f, 1, value=100.0, dimension=1) # Applies force of 100.0 in x-direction to DOFs 1, 4

calfem.utils.applyforcenode(nodeIdx, dofs, f, value=0.0, dimension=0)

Apply a force to a specific node in the finite element model. This function adds a force value to the global force vector at the degrees of freedom corresponding to a specified node. The force can be applied to all DOFs of the node or to a specific dimension. Parameters ———- nodeIdx : int

Index of the node where the force is to be applied.

dofsarray_like

Degrees of freedom array that maps nodes to their DOF indices in the global system. Can be 1D (for single DOF per node) or 2D (for multiple DOFs per node).

farray_like

Global force vector where the force will be added.

valuefloat, optional

Magnitude of the force to be applied. Default is 0.0.

dimensionint, optional

Specific dimension/DOF to apply the force to. If 0, applies to all DOFs of the node. If 1 or higher, applies to the specified dimension (1-indexed). Default is 0.

Notes

  • When dimension=0, the force is applied to all DOFs of the node (assumes 1D dofs array)

  • When dimension>=1, the force is applied to the specific dimension of the node (assumes 2D dofs array with shape [node, dimension])

  • The dimension parameter uses 1-based indexing (dimension=1 corresponds to first DOF)

Examples

>>> # Apply force to all DOFs of node 5
>>> apply_force_node(5, dofs, f, value=100.0, dimension=0)
>>> # Apply force to x-direction (dimension 1) of node 3
>>> apply_force_node(3, dofs, f, value=50.0, dimension=1)
calfem.utils.applyforcetotal(boundaryDofs, f, marker, value=0.0, dimension=0)

Apply boundary force to f matrix. Total force, value, is distributed over all boundaryDofs defined by marker. Applicable to 2D problems with 2 dofs per node.

Parameters

boundaryDofsdict

Dictionary with boundary dofs.

farray_like

Force matrix.

markerint

Boundary marker to assign boundary condition.

valuefloat, optional

Total force value to assign boundary condition. If not given 0.0 is assigned.

dimensionint, optional

Dimension to apply force. 0 - all, 1 - x, 2 - y

calfem.utils.applyforcetotal3D(boundaryDofs, f, marker, value=0.0, dimension=0)

Apply boundary force to f matrix. Total force, value, is distributed over all boundaryDofs defined by marker. Applicable to 3D problems with 3 dofs per node.

Parameters

boundaryDofsdict

Dictionary with boundary dofs.

farray_like

Force matrix.

markerint

Boundary marker to assign boundary condition.

valuefloat, optional

Total force value to assign boundary condition. If not given 0.0 is assigned.

dimensionint, optional

Dimension to apply force. 0 - all, 1 - x, 2 - y, 3 - z

calfem.utils.calc_bar_displ_limits(a, coords, edof, dofs)[source]

Calculate max and min global displacements for bars.

Parameters

aarray_like

Global displacement array with 3 dofs / node.

coordsarray_like

Node coordinates.

edofarray_like

Bar topology.

dofsarray_like

Node dofs.

Returns

tuple

Tuple containing (min_displ, max_displ).

calfem.utils.calc_beam_displ_limits(a, coords, edof, dofs)[source]

Calculate max and min displacements for beams.

Parameters

aarray_like

Global displacement array with 6 dofs / node.

coordsarray_like

Node coordinates.

edofarray_like

Beam topology.

dofsarray_like

Node dofs.

Returns

tuple

Tuple containing (min_displ, max_displ).

calfem.utils.calc_limits(coords)[source]

Calculate max an min limits of 3d coordinates

calfem.utils.calc_size(coords)[source]

Calculate max and min sizes of 3d coordinates.

calfem.utils.convert_to_node_topo(edof, ex, ey, ez, n_dofs_per_node=3, ignore_first=True)[source]

Routine to convert dof based topology and element coordinates to node based topology required for visualisation with VTK and other visualisation frameworks

Parameters

edofarray_like

Element topology [nel x (n_dofs_per_node)|(n_dofs_per_node+1)*n_nodes ]

exarray_like

Element x coordinates [nel x n_nodes]

eyarray_like

Element y coordinates [nel x n_nodes]

ezarray_like

Element z coordinates [nel x n_nodes]

n_dofs_per_nodeint, optional

Number of dofs per node. Default is 3.

ignore_firstbool, optional

Ignore first column of edof. Default is True.

Returns

coordsnumpy.ndarray

Array of node coordinates. [n_nodes x 3]

toponumpy.ndarray

Node topology. [nel x n_nodes]

node_dofsnumpy.ndarray

Dofs for each node. [n_nodes x n_dofs_per_node]

calfem.utils.disp_array(a, headers=[], fmt='.4e', tablefmt='psql', showindex=False)[source]

Print a numpy array in a nice way.

calfem.utils.export_vtk_stress(filename, coords, topo, a=None, el_scalar=None, el_vec1=None, el_vec2=None)[source]

Export mesh and results for a 2D stress problem.

Parameters

filenamestr

Filename of vtk-file

coordsnumpy.ndarray

Element coordinates

toponumpy.ndarray

Element topology (not dof topology). mesh.topo.

anumpy.ndarray, optional

Element displacements 2-dof

el_scalarlist, optional

Scalar values for each element

el_vec1list, optional

Vector value for each element

el_vec2list, optional

Vector value for each element

calfem.utils.load_arrays(name)[source]

Load arrays from file.

calfem.utils.load_geometry(name)[source]

Loads a geometry from a file.

calfem.utils.load_mesh(name)[source]

Load a mesh from file.

calfem.utils.readFloat(f)

Read a row from file, f, and return a list of floats.

calfem.utils.readInt(f)

Read a row from file, f, and return a list of integers.

calfem.utils.readSingleFloat(f)

Read a single float from a row in file f. All other values on row are discarded.

calfem.utils.readSingleInt(f)

Read a single integer from a row in file f. All other values on row are discarded.

calfem.utils.read_float(f)[source]

Read a row from file, f, and return a list of floats.

calfem.utils.read_int(f)[source]

Read a row from file, f, and return a list of integers.

calfem.utils.read_single_float(f)[source]

Read a single float from a row in file f. All other values on row are discarded.

calfem.utils.read_single_int(f)[source]

Read a single integer from a row in file f. All other values on row are discarded.

calfem.utils.save_arrays(coords, edof, dofs, bdofs, elementmarkers, boundaryElements, markerDict, name='unnamed_arrays')[source]

Save arrays to file.

calfem.utils.save_geometry(g, name='unnamed_geometry')[source]

Save a geometry to file.

calfem.utils.save_matlab_arrays(coords, edof, dofs, bdofs, elementmarkers, boundaryElements, markerDict, name='Untitled')[source]

Save arrays as MATLAB .mat files.

calfem.utils.save_mesh(mesh, name='Untitled')[source]

Save a mesh to file.

calfem.utils.scalfact2(ex, ey, ed, rat=0.2)[source]

Determine scale factor for drawing computational results, such as displacements, section forces or flux.

Parameters

exarray_like

Element node x coordinates

eyarray_like

Element node y coordinates

edarray_like

Element displacement matrix or section force matrix

ratfloat, optional

Relation between illustrated quantity and element size. Default is 0.2.

Returns

float

Scale factor for drawing computational results

calfem.utils.str_disp_array(a, headers=[], fmt='.4e', tablefmt='psql', showindex=False)[source]

Return a numpy array in a nice way as a string.

calfem.utils.which(filename)[source]

Return complete path to executable given by filename.

Visualisation functions (Matplotlib)

CALFEM Visualisation module (matplotlib)

Contains all the functions implementing visualisation routines.

calfem.vis_mpl.axis(*args, **kwargs)[source]

Define axis of figure (Matplotlib passthrough)

calfem.vis_mpl.camera3d()[source]

Get visvis 3D camera.

calfem.vis_mpl.ce2vf(coords, edof, dofs_per_node, el_type)[source]

Convert coordinates and element topology to vertices and faces for visualization. Extracts vertices, faces and vertices per face from input data for use in visualization routines. Handles both 2D and 3D coordinate systems and various element types including triangular, quadrilateral, tetrahedral and hexahedral elements.

Parameters

coordsndarray

Node coordinates array of shape (n_nodes, 2) for 2D or (n_nodes, 3) for 3D. Contains the spatial coordinates of all nodes in the mesh.

edofndarray

Element degrees of freedom array of shape (n_elements, dofs_per_element). Contains the connectivity information for each element.

dofs_per_nodeint

Number of degrees of freedom per node. Used to extract node numbers from the edof array.

el_typeint

Element type identifier: - 2: Triangular elements - 3: Quadrilateral elements - 4: Tetrahedral elements - 5: Hexahedral elements - 16: 8-node quadrilateral elements

Returns

vertsndarray

Vertex coordinates array of shape (n_nodes, 3). For 2D input, z-coordinates are padded with zeros.

facesndarray

Face connectivity array of shape (n_faces, vertices_per_face) containing node indices that define each face. For 3D elements, this decomposes volume elements into their constituent faces.

vertices_per_faceint

Number of vertices per face (3 for triangular faces, 4 for quadrilateral faces).

is_3dbool

Flag indicating whether the problem is 3D (True) or 2D (False).

Raises

ValueError

If coords array doesn’t have 2 or 3 columns, or if el_type is not supported.

Notes

For 3D volume elements (tetrahedra and hexahedra), the function decomposes each element into its constituent faces using predefined connectivity matrices. The node ordering follows the Gmsh manual conventions. For 8-node quadrilateral elements (el_type=16), only the first 4 corner nodes are used to define the face.

calfem.vis_mpl.clf()[source]

Clear visvis figure

calfem.vis_mpl.close(fig=None)[source]

Close visvis figure

calfem.vis_mpl.closeAll()

Close all visvis windows.

calfem.vis_mpl.close_all()[source]

Close all visvis windows.

calfem.vis_mpl.colorbar(**kwargs)[source]

Add a colorbar to current figure

calfem.vis_mpl.create_ordered_polys(geom, N=10)[source]

Creates ordered polygons from the geometry definition. This function processes geometry surfaces by converting their constituent curves into ordered polygon representations. Each curve is discretized into N points based on its type (Spline, BSpline, Circle, or Ellipse), and the resulting polygons are ordered such that consecutive curves share endpoints.

Parameters

geomobject

Geometry object containing surfaces and curves definitions. Must have ‘surfaces’ and ‘curves’ attributes, and a ‘get_point_coords’ method.

Nint, optional

Number of points to use for curve discretization (default is 10). Note: This parameter is overridden to 10 within the function.

Returns

list of numpy.ndarray

List of ordered polygons, where each polygon is a numpy array of shape (n_points, 3) representing the coordinates of points forming the polygon boundary. Each polygon corresponds to a surface in the geometry.

Notes

  • The function assumes curves can be connected end-to-end to form closed polygons

  • Curves are automatically flipped if needed to maintain proper ordering

  • Only processes the outer boundary of surfaces (holes are ignored)

  • Supported curve types: Spline, BSpline, Circle, Ellipse

calfem.vis_mpl.dispbeam2(ex, ey, edi, plotpar=[2, 1, 1], sfac=None)[source]

Draw the displacement diagram for a two dimensional beam element.

Parameters

exarray_like

Element node coordinates [x1, x2].

eyarray_like

Element node coordinates [y1, y2].

ediarray_like

Matrix containing the displacements in Nbr evaluation points along the beam. Shape: [[u1, v1], [u2, v2], …].

plotparlist, optional

Plot parameters [linetype, linecolour, nodemark]. Default [2, 1, 1].

  • linetype: 1=solid, 2=dashed, 3=dotted

  • linecolour: 1=black, 2=blue, 3=magenta, 4=red

  • nodemark: 0=no mark, 1=circle, 2=star, 3=point

sfacfloat, optional

Scale factor for displacements. If None, auto magnification is used.

Returns

float or None

Scale factor for displacements when sfac is None.

Notes

Default if sfac and plotpar is left out is auto magnification and dashed black lines with circles at nodes -> plotpar=[1 1 1]

LAST MODIFIED: O Dahlblom 2015-11-18

O Dahlblom 2023-01-31 (Python)

Copyright (c) Division of Structural Mechanics and

Division of Solid Mechanics. Lund University

calfem.vis_mpl.drawMesh(coords, edof, dofs_per_node, el_type, title=None, color=(0, 0, 0), face_color=(0.8, 0.8, 0.8), node_color=(0, 0, 0), filled=False, show_nodes=False)

Draws wire mesh of model in 2D or 3D. Returns the Mesh object that represents the mesh.

Parameters

coordsndarray

An N-by-2 or N-by-3 array. Row i contains the x,y,z coordinates of node i.

edofndarray

An E-by-L array. Element topology. (E is the number of elements and L is the number of dofs per element)

dofs_per_nodesint

Integer. Dofs per node.

el_typeint

Integer. Element Type. See Gmsh manual for details. Usually 2 for triangles or 3 for quadrangles.

axesmatplotlib.axes.Axes, optional

Matplotlib Axes. The Axes where the model will be drawn. If unspecified the current Axes will be used, or a new Axes will be created if none exist.

axes_adjustbool, optional

Boolean. True if the view should be changed to show the whole model. Default True.

titlestr, optional

String. Changes title of the figure. Default “Mesh”.

colortuple or str, optional

3-tuple or char. Color of the wire. Defaults to black (0,0,0). Can also be given as a character in ‘rgbycmkw’.

face_colortuple or str, optional

3-tuple or char. Color of the faces. Defaults to white (1,1,1). Parameter filled must be True or faces will not be drawn at all.

filledbool, optional

Boolean. Faces will be drawn if True. Otherwise only the wire is drawn. Default False.

calfem.vis_mpl.draw_displacements(a, coords, edof, dofs_per_node, el_type, draw_undisplaced_mesh=False, magnfac=-1.0, magscale=0.25, title=None, color=(0, 0, 0), node_color=(0, 0, 0))[source]

Draws scalar element values in 2D or 3D. Returns the world object elementsWobject that represents the mesh.

Parameters

evarray_like

An N-by-1 array or a list of scalars. The Scalar values of the elements. ev[i] should be the value of element i.

coordsarray_like

An N-by-2 or N-by-3 array. Row i contains the x,y,z coordinates of node i.

edofarray_like

An E-by-L array. Element topology. (E is the number of elements and L is the number of dofs per element)

dofs_per_nodeint

Dofs per node.

el_typeint

Element Type. See Gmsh manual for details. Usually 2 for triangles or 3 for quadrangles.

displacementsarray_like

An N-by-2 or N-by-3 array. Row i contains the x,y,z displacements of node i.

axesmatplotlib.axes.Axes

Matlotlib Axes. The Axes where the model will be drawn. If unspecified the current Axes will be used, or a new Axes will be created if none exist.

draw_undisplaced_meshbool

True if the wire of the undisplaced mesh should be drawn on top of the displaced mesh. Default False. Use only if displacements != None.

magnfacfloat

Magnification factor. Displacements are multiplied by this value. Use this to make small displacements more visible.

titlestr

Changes title of the figure. Default “Element Values”.

calfem.vis_mpl.draw_element_values(values, coords, edof, dofs_per_node, el_type, displacements=None, draw_elements=True, draw_undisplaced_mesh=False, magnfac=1.0, title=None, color=(0, 0, 0), node_color=(0, 0, 0))[source]

Draws scalar element values in 2D or 3D.

Parameters

valuesarray_like

An N-by-1 array or a list of scalars. The Scalar values of the elements. ev[i] should be the value of element i.

coordsarray_like

An N-by-2 or N-by-3 array. Row i contains the x,y,z coordinates of node i.

edofarray_like

An E-by-L array. Element topology. (E is the number of elements and L is the number of dofs per element)

dofs_per_nodeint

Dofs per node.

el_typeint

Element Type. See Gmsh manual for details. Usually 2 for triangles or 3 for quadrangles.

displacementsarray_like, optional

An N-by-2 or N-by-3 array. Row i contains the x,y,z displacements of node i.

draw_elementsbool, optional

True if mesh wire should be drawn. Default True.

draw_undisplaced_meshbool, optional

True if the wire of the undisplaced mesh should be drawn on top of the displaced mesh. Default False. Use only if displacements != None.

magnfacfloat, optional

Magnification factor. Displacements are multiplied by this value. Use this to make small displacements more visible.

titlestr, optional

Changes title of the figure. Default “Element Values”.

colortuple or str, optional

Color of the wire.

node_colortuple or str, optional

Color of the nodes.

calfem.vis_mpl.draw_elements(ex, ey, title='', color=(0, 0, 0), face_color=(0.8, 0.8, 0.8), node_color=(0, 0, 0), line_style='solid', filled=False, closed=True, show_nodes=False)[source]

Draws wire mesh of model in 2D or 3D. Returns the Mesh object that represents the mesh.

Parameters

exndarray

Element x-coordinates array.

eyndarray

Element y-coordinates array.

titlestr, optional

Changes title of the figure. Default “”.

colortuple or str, optional

Color of the wire. Defaults to black (0,0,0). Can also be given as a character in ‘rgbycmkw’.

face_colortuple or str, optional

Color of the faces. Defaults to (0.8,0.8,0.8). Parameter filled must be True or faces will not be drawn at all.

node_colortuple or str, optional

Color of the nodes. Defaults to black (0,0,0).

line_stylestr, optional

Line style for drawing. Default “solid”.

filledbool, optional

Faces will be drawn if True. Otherwise only the wire is drawn. Default False.

closedbool, optional

Whether elements should be drawn as closed polygons. Default True.

show_nodesbool, optional

Whether to show nodes as markers. Default False.

calfem.vis_mpl.draw_geometry(geometry, draw_points=True, label_points=True, label_curves=True, title=None, font_size=11, N=20, rel_margin=0.05, draw_axis=False, axes=None)[source]

Draws the geometry (points and curves) in geoData.

Parameters

geometryobject

GeoData object. Geodata contains geometric information of the model.

draw_pointsbool, optional

If True points will be drawn. Default True.

label_pointsbool, optional

If True Points will be labeled. The format is: ID[marker]. If a point has marker==0 only the ID is written. Default True.

label_curvesbool, optional

If True Curves will be labeled. The format is: ID(elementsOnCurve)[marker]. Default True.

titlestr, optional

Title for the plot. Default None.

font_sizeint, optional

Size of the text in the text labels. Default 11.

Nint, optional

The number of discrete points per curve segment. Default 20. Increase for smoother curves. Decrease for better performance.

rel_marginfloat, optional

Extra spacing between geometry and axis. Default 0.05.

draw_axisbool, optional

Whether to draw the axis frame. Default False.

axesmatplotlib.axes.Axes, optional

Matplotlib Axes. The Axes where the model will be drawn. If unspecified the current Axes will be used, or a new Axes will be created if none exist. Default None.

calfem.vis_mpl.draw_mesh(coords, edof, dofs_per_node, el_type, title=None, color=(0, 0, 0), face_color=(0.8, 0.8, 0.8), node_color=(0, 0, 0), filled=False, show_nodes=False)[source]

Draws wire mesh of model in 2D or 3D. Returns the Mesh object that represents the mesh.

Parameters

coordsndarray

An N-by-2 or N-by-3 array. Row i contains the x,y,z coordinates of node i.

edofndarray

An E-by-L array. Element topology. (E is the number of elements and L is the number of dofs per element)

dofs_per_nodesint

Integer. Dofs per node.

el_typeint

Integer. Element Type. See Gmsh manual for details. Usually 2 for triangles or 3 for quadrangles.

axesmatplotlib.axes.Axes, optional

Matplotlib Axes. The Axes where the model will be drawn. If unspecified the current Axes will be used, or a new Axes will be created if none exist.

axes_adjustbool, optional

Boolean. True if the view should be changed to show the whole model. Default True.

titlestr, optional

String. Changes title of the figure. Default “Mesh”.

colortuple or str, optional

3-tuple or char. Color of the wire. Defaults to black (0,0,0). Can also be given as a character in ‘rgbycmkw’.

face_colortuple or str, optional

3-tuple or char. Color of the faces. Defaults to white (1,1,1). Parameter filled must be True or faces will not be drawn at all.

filledbool, optional

Boolean. Faces will be drawn if True. Otherwise only the wire is drawn. Default False.

calfem.vis_mpl.draw_nodal_values(values, coords, edof, levels=12, title=None, dofs_per_node=None, el_type=None, draw_elements=False)

Draw filled contour plot of nodal values on a finite element mesh. This function creates a filled contour plot (tricontourf) to visualize scalar values at the nodes of a finite element mesh. The contours are interpolated over triangular elements derived from the mesh topology. Parameters ———- values : array_like

Nodal values to be plotted as contours. Should have one value per node.

coordsarray_like

Node coordinates array with shape (n_nodes, 2) where each row contains [x, y] coordinates of a node.

edofarray_like

Element topology array defining the connectivity between elements and degrees of freedom/nodes.

levelsint, optional

Number of contour levels to draw. Default is 12.

titlestr, optional

Title for the plot. If None, no title is set. Default is None.

dofs_per_nodeint, optional

Number of degrees of freedom per node. Required if draw_elements is True. Default is None.

el_typestr, optional

Element type identifier. Required if draw_elements is True. Default is None.

draw_elementsbool, optional

Whether to overlay the mesh elements on the contour plot. If True, dofs_per_node and el_type must be specified. Default is False.

Notes

  • The function uses matplotlib’s tricontourf for creating filled contours

  • Element topology is converted to triangular connectivity using topo_to_tri

  • The plot aspect ratio is set to ‘equal’ for proper geometric representation

  • If draw_elements is True but required parameters are missing, an info message is displayed

Examples

>>> coords = np.array([[0, 0], [1, 0], [0.5, 1]])
>>> edof = np.array([[1, 2, 3]])
>>> values = np.array([1.0, 2.0, 1.5])
>>> draw_nodal_values_contourf(values, coords, edof, levels=10, title="Temperature")
calfem.vis_mpl.draw_nodal_values_contour(values, coords, edof, levels=12, title=None, dofs_per_node=None, el_type=None, draw_elements=False)[source]

Draw contour plot of nodal values on a triangulated mesh.

Parameters

valuesarray_like

Nodal values to be plotted as contours.

coordsarray_like

Coordinates of nodes in the mesh, shape (n_nodes, 2).

edofarray_like

Element degrees of freedom connectivity matrix.

levelsint, optional

Number of contour levels to draw, default is 12.

titlestr, optional

Title for the plot, default is None.

dofs_per_nodeint, optional

Number of degrees of freedom per node, required if draw_elements is True.

el_typestr, optional

Element type, required if draw_elements is True.

draw_elementsbool, optional

Whether to draw the mesh elements on top of contours, default is False.

Notes

The function creates a triangulated contour plot using matplotlib’s tricontour. If draw_elements is True, both dofs_per_node and el_type must be specified to draw the mesh overlay.

The plot uses equal aspect ratio and displays contours of the provided nodal values interpolated over the triangulated mesh.

calfem.vis_mpl.draw_nodal_values_contourf(values, coords, edof, levels=12, title=None, dofs_per_node=None, el_type=None, draw_elements=False)[source]

Draw filled contour plot of nodal values on a finite element mesh. This function creates a filled contour plot (tricontourf) to visualize scalar values at the nodes of a finite element mesh. The contours are interpolated over triangular elements derived from the mesh topology. Parameters ———- values : array_like

Nodal values to be plotted as contours. Should have one value per node.

coordsarray_like

Node coordinates array with shape (n_nodes, 2) where each row contains [x, y] coordinates of a node.

edofarray_like

Element topology array defining the connectivity between elements and degrees of freedom/nodes.

levelsint, optional

Number of contour levels to draw. Default is 12.

titlestr, optional

Title for the plot. If None, no title is set. Default is None.

dofs_per_nodeint, optional

Number of degrees of freedom per node. Required if draw_elements is True. Default is None.

el_typestr, optional

Element type identifier. Required if draw_elements is True. Default is None.

draw_elementsbool, optional

Whether to overlay the mesh elements on the contour plot. If True, dofs_per_node and el_type must be specified. Default is False.

Notes

  • The function uses matplotlib’s tricontourf for creating filled contours

  • Element topology is converted to triangular connectivity using topo_to_tri

  • The plot aspect ratio is set to ‘equal’ for proper geometric representation

  • If draw_elements is True but required parameters are missing, an info message is displayed

Examples

>>> coords = np.array([[0, 0], [1, 0], [0.5, 1]])
>>> edof = np.array([[1, 2, 3]])
>>> values = np.array([1.0, 2.0, 1.5])
>>> draw_nodal_values_contourf(values, coords, edof, levels=10, title="Temperature")
calfem.vis_mpl.draw_nodal_values_shaded(values, coords, edof, title=None, dofs_per_node=None, el_type=None, draw_elements=False)[source]

Draw shaded contour plot of nodal values using triangular interpolation. This function creates a shaded contour plot where nodal values are interpolated across triangular elements using Gouraud shading. The visualization shows smooth color gradients representing the variation of values across the mesh. Parameters ———- values : array-like

Nodal values to be plotted. Should have one value per node.

coordsarray-like

Node coordinates as a 2D array with shape (n_nodes, 2) where each row contains [x, y] coordinates.

edofarray-like

Element degrees of freedom connectivity matrix. Each row defines the nodes that belong to an element.

titlestr, optional

Title for the plot. If None, no title is displayed.

dofs_per_nodeint, optional

Number of degrees of freedom per node. Required if draw_elements is True.

el_typestr, optional

Element type identifier. Required if draw_elements is True.

draw_elementsbool, default False

If True, overlays the mesh elements on the contour plot. Requires dofs_per_node and el_type to be specified.

Notes

  • The function uses matplotlib’s tripcolor with Gouraud shading for smooth interpolation between nodal values

  • Element topology is converted to triangular format using topo_to_tri()

  • If draw_elements is True but dofs_per_node or el_type are not provided, an informational message is displayed and the mesh is not drawn

  • The plot aspect ratio is automatically set to equal for proper visualization

Examples

>>> coords = np.array([[0, 0], [1, 0], [1, 1], [0, 1]])
>>> edof = np.array([[1, 2, 3], [1, 3, 4]])
>>> values = np.array([0.0, 1.0, 1.5, 0.5])
>>> draw_nodal_values_shaded(values, coords, edof, title="Temperature Distribution")
calfem.vis_mpl.draw_node_circles(ex, ey, title='', color=(0, 0, 0), face_color=(0.8, 0.8, 0.8), filled=False, marker_type='o')[source]

Draws wire mesh of model in 2D or 3D. Returns the Mesh object that represents the mesh.

Parameters

exndarray

Element x-coordinates array.

eyndarray

Element y-coordinates array.

titlestr, optional

Changes title of the figure. Default “”.

colortuple or str, optional

Color of the wire. Defaults to black (0,0,0). Can also be given as a character in ‘rgbycmkw’.

face_colortuple or str, optional

Color of the faces. Defaults to (0.8,0.8,0.8). Parameter filled must be True or faces will not be drawn at all.

filledbool, optional

Faces will be drawn if True. Otherwise only the wire is drawn. Default False.

marker_typestr, optional

Marker type for drawing. Default “o”.

calfem.vis_mpl.draw_ordered_polys(o_polys)[source]

Draw ordered polygons on the current matplotlib axes.

This function takes a collection of ordered polygons and renders them as patches on the current matplotlib axes. Each polygon is drawn with an orange face color and a line width of 1.

Parameters

o_polysarray-like

A collection of polygons where each polygon is represented as a numpy array with shape (n_vertices, 2) or (n_vertices, 3+). Only the first two columns (x, y coordinates) are used for drawing.

Notes

  • The function uses the current matplotlib axes (plt.gca())

  • All polygons are drawn with orange face color and line width of 1

  • Only the first two columns of each polygon array are used for coordinates

  • The function requires matplotlib.pyplot, matplotlib.path, and matplotlib.patches to be imported as plt, mpp, and patches respectively

Examples

>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> # Create a simple triangle
>>> triangle = np.array([[0, 0], [1, 0], [0.5, 1], [0, 0]])
>>> draw_ordered_polys([triangle])
>>> plt.show()
calfem.vis_mpl.eldisp2(ex, ey, ed, plotpar=[2, 1, 1], sfac=None)[source]

Draw the deformed 2D mesh for a number of elements of the same type.

Supported elements are: - 1: bar element - 2: beam element - 3: triangular 3 node element - 4: quadrilateral 4 node element - 5: 8-node isoparametric element

Parameters

exarray_like

Element x-coordinates array where nen is number of element nodes and nel is number of elements.

eyarray_like

Element y-coordinates array where nen is number of element nodes and nel is number of elements.

edarray_like

Element displacement matrix.

plotparlist, optional

Plot parameters [linetype, linecolor, nodemark]. Default [2, 1, 1].

  • linetype: 1=solid, 2=dashed, 3=dotted

  • linecolor: 1=black, 2=blue, 3=magenta, 4=red

  • nodemark: 1=circle, 2=star, 0=no mark

sfacfloat, optional

Scale factor for displacements. If None, auto magnification is used.

Returns

float or None

Scale factor for displacements when sfac is None.

Notes

Default if sfac and plotpar is left out is auto magnification and dashed black lines with circles at nodes -> plotpar=[2 1 1]

LAST MODIFIED: O Dahlblom 2004-10-01

J Lindemann 2021-12-30 (Python)

Copyright (c) Division of Structural Mechanics and

Division of Solid Mechanics. Lund University

calfem.vis_mpl.eldraw2(ex, ey, plotpar=[1, 2, 1], elnum=[])[source]

Draw the undeformed 2D mesh for a number of elements of the same type.

Supported elements are: 1) -> bar element 2) -> beam el. 3) -> triangular 3 node el. 4) -> quadrilateral 4 node el. 5) -> 8-node isopar. element

Parameters

ex, eyarray_like

Element node coordinates arrays where nen is number of element nodes and nel is number of elements.

plotparlist, optional

Plot parameters [linetype, linecolor, nodemark]. Default [1, 2, 1].

  • linetype: 1=solid, 2=dashed, 3=dotted

  • linecolor: 1=black, 2=blue, 3=magenta, 4=red

  • nodemark: 0=no mark, 1=circle, 2=star

elnumarray_like, optional

Element numbers.

Notes

Default is solid white lines with circles at nodes.

calfem.vis_mpl.error(msg)[source]

Log error message

calfem.vis_mpl.figure(figure=None, show=True, fig_size=(6, 5.33))[source]

Create a visvis figure with extras.

calfem.vis_mpl.figureClass()

Return visvis Figure class.

calfem.vis_mpl.figure_class()[source]

Return visvis Figure class.

calfem.vis_mpl.gca()[source]

Get current axis of the current visvis figure.

calfem.vis_mpl.info(msg)[source]

Log information message

calfem.vis_mpl.pltstyle(plotpar)[source]

Define linetype, linecolor and markertype character codes.

Parameters

plotparlist

Plot parameters [linetype, linecolor, nodemark]

  • linetypeint

    1 -> solid, 2 -> dashed, 3 -> dotted

  • linecolorint

    1 -> black, 2 -> blue, 3 -> magenta, 4 -> red

  • nodemarkint

    1 -> circle, 2 -> star, 0 -> no mark

Returns

s1str

Linetype and color for mesh lines

s2str

Type and color for node markers

Notes

LAST MODIFIED: Ola Dahlblom 2004-09-15 Copyright (c) Division of Structural Mechanics and

Division of Solid Mechanics. Lund University

calfem.vis_mpl.pltstyle2(plotpar)[source]

Define linetype, linecolor and markertype character codes.

Parameters

plotparlist

Plot parameters [linetype, linecolor, nodemark]

  • linetypeint

    1 -> solid, 2 -> dashed, 3 -> dotted

  • linecolorint

    1 -> black, 2 -> blue, 3 -> magenta, 4 -> red

  • nodemarkint

    1 -> circle, 2 -> star, 0 -> no mark

Returns

line_colortuple

RGB color tuple for mesh lines

line_stylestr or tuple

Line style for mesh lines

node_colortuple

RGB color tuple for node markers

node_typestr

Marker type for nodes

Notes

LAST MODIFIED: Ola Dahlblom 2004-09-15 Copyright (c) Division of Structural Mechanics and

Division of Solid Mechanics. Lund University

calfem.vis_mpl.point_in_geometry(o_polys, point)[source]

Check if a point is inside any of the given polygons.

Parameters

o_polyslist

List of polygon arrays, where each polygon is represented as a numpy array with coordinates in the first two columns (x, y coordinates).

pointarray-like

A point represented as [x, y] coordinates to test for containment.

Returns

bool

True if the point is inside any of the polygons, False otherwise.

Notes

This function uses matplotlib’s Path.contains_points() method to perform the point-in-polygon test. The function returns True as soon as the point is found to be inside any polygon (short-circuit evaluation).

calfem.vis_mpl.scalfact2(ex, ey, ed, rat=0.2)[source]

Determine scale factor for drawing computational results, such as displacements, section forces or flux.

Parameters

exarray_like

Element node x-coordinates.

eyarray_like

Element node y-coordinates.

edarray_like

Element displacement matrix or section force matrix.

ratfloat, optional

Relation between illustrated quantity and element size. If not specified, 0.2 is used.

Returns

float

Scale factor for drawing.

Notes

LAST MODIFIED: O Dahlblom 2004-09-15

J Lindemann 2021-12-29 (Python)

Copyright (c) Division of Structural Mechanics and

Division of Solid Mechanics. Lund University

calfem.vis_mpl.scalgraph2(sfac, magnitude, plotpar=2)[source]

Draw a graphic scale.

Parameters

sfacfloat

Scale factor.

magnitudearray_like

The graphic scale has a length equivalent to Ref and starts at coordinates (x,y). Can be: - [Ref] : scale reference, starts at (0, -0.5) - [Ref, x, y] : scale reference with starting coordinates

plotparint, optional

Line color. Default is 2. - 1 : black - 2 : blue - 3 : magenta - 4 : red

Notes

LAST MODIFIED: O Dahlblom 2015-12-02

O Dahlblom 2023-01-23 (Python)

Copyright (c) Division of Structural Mechanics and

Division of Solid Mechanics. Lund University

calfem.vis_mpl.secforce2(ex, ey, es, plotpar=[2, 1], sfac=None, eci=None)[source]

Draw section force diagram for a two dimensional bar or beam element.

Parameters

exarray_like

Element node coordinates [x1, x2].

eyarray_like

Element node coordinates [y1, y2].

esarray_like

Vector containing the section force in Nbr evaluation points along the element. Shape: [S1, S2, …].

plotparlist, optional

Plot parameters [linecolour, elementcolour]. Default [2, 1].

  • linecolour: 1=black, 2=blue, 3=magenta, 4=red

  • elementcolour: 1=black, 2=blue, 3=magenta, 4=red

sfacfloat, optional

Scale factor for section force diagrams. If None, auto scaling is used.

eciarray_like, optional

Local x-coordinates of the evaluation points (Nbr). If not given, the evaluation points are assumed to be uniformly distributed.

Returns

float or None

Scale factor for section forces when sfac is None.

Notes

LAST MODIFIED: O Dahlblom 2019-12-16

O Dahlblom 2023-01-31 (Python)

Copyright (c) Division of Structural Mechanics and

Division of Solid Mechanics. Lund University

calfem.vis_mpl.show()[source]

Use in Qt applications

calfem.vis_mpl.showAndWait()

Wait for plot to show

calfem.vis_mpl.showAndWaitMpl()

Wait for plot to show

calfem.vis_mpl.show_and_wait()[source]

Wait for plot to show

calfem.vis_mpl.show_and_wait_mpl()[source]

Wait for plot to show

calfem.vis_mpl.subplot(*args)[source]

Create a visvis subplot.

calfem.vis_mpl.title(*args, **kwargs)[source]

Define title of figure (Matplotlib passthrough)

calfem.vis_mpl.topo_to_tri(edof)[source]

Convert element topology to triangular elements for visualization. This function converts different element topologies (triangular, quadrilateral, and 8-node elements) into triangular elements suitable for mesh visualization and plotting.

Parameters

edofnumpy.ndarray

Element topology array where each row represents an element and columns represent the node indices. Supported shapes: - (n, 3): Triangular elements (returned as-is) - (n, 4): Quadrilateral elements (split into 2 triangles each) - (n, 8): 8-node elements (split into 6 triangles each)

Returns

numpy.ndarray

Triangular element topology array with shape (m, 3) where m depends on the input topology: - Triangular input: m = n (no change) - Quadrilateral input: m = 2*n - 8-node input: m = 6*n

Raises

Error

If the element topology is not supported (i.e., edof.shape[1] is not 3, 4, or 8).

Notes

  • For quadrilateral elements, the splitting pattern creates two triangles using nodes [0,1,2] and [2,3,0]

  • For 8-node elements, the splitting creates 6 triangles to represent the element faces for 3D visualization