Function reference

Core functions

CALFEM Core module

Contains all the functions implementing CALFEM standard functionality

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

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

Parameters:

edof dof topology array K the global stiffness matrix Ke element stiffness matrix f the global force vector fe element force vector

Output parameters:

K the new global stiffness matrix f the new global force vector fe element force vector
calfem.core.bar1e(ep)[source]

Compute element stiffness matrix for spring element.

Parameters:float (ep) – spring stiffness or analog quantity
Return mat Ke:stiffness matrix, dim(Ke)= 2 x 2
calfem.core.bar1s(ep, ed)[source]

Compute element force in spring element (spring1e).

Parameters:
  • ep (float) – spring stiffness or analog quantity
  • ed (list) – element displacements [d0, d1]
Return float es:
 

element force

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

Compute the element stiffness matrix for two dimensional bar element.

Parameters:
  • ex (list) – element x coordinates [x1, x2]
  • ey (list) – element y coordinates [y1, y2]
  • ep (list) – [E, A]: E - Young’s modulus, A - Cross section area
Return mat Ke:

stiffness matrix, [4 x 4]

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

Compute element stiffness matrix for two dimensional geometric nonlinear bar element.

Parameters:
  • ex (list) – element x coordinates [x1, x2]
  • ey (list) – element y coordinates [y1, y2]
  • ep (list) – element properties [E, A], E - Young’s modulus, A - Cross section area
  • N (float) – normal force
Return mat Ke:

stiffness matrix [4 x 4]

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

Compute normal force in two dimensional bar element.

Parameters:
  • ex (list) – element x coordinates [x1, x2]
  • ey (list) – element y coordinates [y1, y2]
  • ep (list) – element properties [E, A], E - Young’s modulus, A - Cross section area
  • ed (list) – element displacements [u1, u2, u3, u4]
Return float N:

element foce [N]

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

Compute element stiffness matrix for three dimensional bar element.

Parameters:
  • ex (list) – element x coordinates [x1, x2]
  • ey (list) – element y coordinates [y1, y2]
  • ez (list) – element z coordinates [z1, z2]
  • ep (list) – element properties [E, A], E - Young’s modulus, A - Cross section area
Return mat Ke:

stiffness matrix, [6 x 6]

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

Compute normal force in three dimensional bar element.

Parameters:
  • ex (list) – element x coordinates [x1, x2]
  • ey (list) – element y coordinates [y1, y2]
  • ez (list) – element z coordinates [z1, z2]
  • ep (list) – element properties [E, A], E - Young’s modulus, A - Cross section area
  • ed (list) – element displacements [u1, …, u6]
Return float N:

normal force

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

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

Parameters:

ex = [x1, x2] ey = [y1, y2] element node coordinates

ep = [E,A,I,m,(a,b)] element properties;
E: Young’s modulus A: cross section area I: moment of inertia m: mass per unit length
a,b: damping coefficients,
Ce=aMe+bKe

Returns:

Ke element stiffness matrix (6 x 6) Me element mass martix Ce element damping matrix, optional
calfem.core.beam2e(ex, ey, ep, eq=None)[source]

Compute the stiffness matrix for a two dimensional beam element.

Parameters:
  • ex (list) – element x coordinates [x1, x2]
  • ey (list) – element y coordinates [y1, y2]
  • ep (list) – element properties [E, A, I], E - Young’s modulus, A - Cross section area, I - Moment of inertia
  • eq (list) – distributed loads, local directions [qx, qy]
Return mat Ke:

element stiffness matrix [6 x 6]

Return mat fe:

element stiffness matrix [6 x 1] (if eq!=None)

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

Compute the element stiffness matrix for a two dimensional beam element with respect to geometric nonlinearity.

Parameters:

ex = [x1, x2] ey = [y1, y2] element node coordinates

ep = [E,A,I] element properties;
E: Young’s modulus A: cross section area I: moment of inertia

N axial force in the beam

eq distributed transverse load

Returns:

Ke element stiffness matrix (6 x 6)

fe element load vector (6 x 1)

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

Calculate section forces in a two dimensional nonlinear beam element.

Parameters:

ex = [x1, x2] ey = [y1, y2] element node coordinates

ep = [E,A,I] element properties;
E: Young’s modulus A: cross section area I: moment of inertia

ed = [u1, … ,u6] element displacement vector

N axial force

eq = [qy] distributed transverse load

Returns:

es = [[N1,V1,M1], element forces, local directions
[N2,V2,M2]]
calfem.core.beam2s(ex, ey, ep, ed, eq=None, nep=None)[source]

Compute section forces in two dimensional beam element (beam2e).

Parameters:

ex = [x1 x2] ey = [y1 y2] element node coordinates

ep = [E A I] element properties,
E: Young’s modulus A: cross section area I: moment of inertia

ed = [u1 … u6] element displacements

eq = [qx qy] distributed loads, local directions

nep number of evaluation points ( default=2 )

Returns:

es = [ N1 V1 M1 section forces, local directions, in
N2 V2 M2 n points along the beam, dim(es)= n x 3 ………]
edi = [ u1 v1 element displacements, local directions,
u2 v2 in n points along the beam, dim(es)= n x 2 …….]
eci = [ x1 local x-coordinates of the evaluation
x2 points, (x1=0 and xn=L) …]
calfem.core.beam2t(ex, ey, ep, eq=None)[source]

Compute the stiffness matrix for a two dimensional elastic Timoshenko beam element.

Parameters:

ex = [x1 x2] ey = [y1 y2] element node coordinates

ep = [E G A I ks] element properties
E: Young’s modulus G: Shear modulus A: Cross section area I: Moment of inertia

ks: Shear correction factor

eq = [qx qy] distributed loads, local directions

Returns:

Ke element stiffness matrix (6 x 6)

fe element load vector (6 x 1)

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

Compute section forces in two dimensional beam element (beam2e).

Parameters:

ex = [x1, x2] ey = [y1, y2] element node coordinates

ep = [E,G,A,I,ks] element properties,
E: Young’s modulus G: shear modulus A: cross section area I: moment of inertia

ed = [u1, … ,u6] element displacements

eq = [qx, qy] distributed loads, local directions

nep number of evaluation points ( default=2 )

Returns:

es = [[N1,V1,M1], section forces, local directions, in
[N2,V2,M2], n points along the beam, dim(es)= n x 3 ……….]
edi = [[u1,v1,teta1], element displacements, local directions,
[u2,v2,teta2], and rotation of cross section at ………….] in n points along the beam, dim(es)= n x 2

(Note! Rotation of the cross section is not equal to dv/dx for Timoshenko beam element)

eci = [[x1], local x-coordinates of the evaluation
[x2], points, (x1=0 and xn=L) ….]
calfem.core.beam2w(ex, ey, ep, eq=None)[source]

Compute the stiffness matrix for a two dimensional beam element on elastic foundation.

Parameters:

ex = [x1, x2] ey = [y1, y2] element node coordinates

ep = [E,A,I,ka,kt] element properties,
E: Young’s modulus A: cross section area I: moment of inertia

ka: axial foundation stiffness kt: transversal foundation stiffness

eq = [qx, qy] distributed loads, local directions

Returns:

Ke beam stiffness matrix (6 x 6)

fe element load vector (6 x 1)

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

Compute section forces in a two dimensional beam element on elastic foundation.

Parameters:

ex = [x1, x2] ey = [y1, y2] element node coordinates

ep = [E,A,I,ka,kt] element properties,
E: Young’s modulus A: cross section area I: moment of inertia

ka: axial foundation stiffness kt: transversal foundation stiffness

ed = [u1, … ,u6] element displacement vector

eq = [qx, qy] distributed loads, local directions

Returns:

es = [[N1, V1, M1],
[N2, V2, M2]] element forces, local direction
calfem.core.beam3e(ex, ey, ez, eo, ep, eq=None)[source]

Calculate the stiffness matrix for a 3D elastic Bernoulli beam element.

Parameters:

ex = [x1 x2] ey = [y1 y2] ez = [z1 z2] element node coordinates

eo = [xz yz zz] orientation of local z axis

ep = [E G A Iy Iz Kv] element properties
E: Young’s modulus G: Shear modulus A: Cross section area

Iy: Moment of inertia, local y-axis Iz: Moment of inertia, local z-axis Kv: Saint-Venant’s torsion constant

eq = [qx qy qz qw] distributed loads

Returns:

Ke beam stiffness matrix (12 x 12)

fe equivalent nodal forces (12 x 1)

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

Calculate the variation of the section forces and displacements along a three-dimensional beam element.

Parameters:

ex = [x1 x2] element node coordinates ey = [y1 y2] ez = [z1 z2]

eo = [xz yz zz] orientation of local z axis

ep = [E G A Iy Iz Kv] element properties
E: Young’s modulus G: Shear modulus A: Cross section area

Iy: Moment of inertia, local y-axis Iz: Moment of inertia, local z-axis Kv: Saint-Venant’s torsion constant

ed the element displacement vector from the
global coordinate system
eq = [qx qy qz qw] the disibuted axial, transversal and
torsional loads
n the number of point in which displacements
and section forces are to be computed

Returns:

es = [[N1,Vy1,Vz1,T1,My1,Mz1], section forces in n points along
[N2,Vy2,Vz2,T2,My2,Mz2], the local x-axis [..,…,…,..,…,…], [Nn,Vyn,Vzn,Tn,Myn,Mzn]]
edi = [[u1,v1,w1,fi1], displacements in n points along
[u2,v2,w2,fi2], the local x-axis [..,..,..,…], [un,vn,wn,fin]]
eci = [[x1], local x-coordinates of the evaluation
[x2], points [..], [xn]]
calfem.core.coordxtr(edof, coords, dofs)[source]

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

Parameters:

edof [nel x (nen * nnd)], nnd = number of node dofs coords [ncoords x ndims], ndims = node dimensions dofs [ncoords x nnd]

Returns:

ex if ndims = 1 ex, ey if ndims = 2 ex, ey, ez if ndims = 3
calfem.core.createdofs(nCoords, nDof)[source]

Create dof array [nCoords x nDof]

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

Calculate effective von mises stresses.

Parameters:

es

ptype= 1: plane stress
2: plane strain 3: axisymmetry 4: three dimensional
es = [[sigx,sigy,[sigz],tauxy] element stress matrix
[ …… ]] one row for each element

Returns:

eseff = [eseff_0 .. eseff_nel-1]
calfem.core.error(msg)[source]

Write msg to error log.

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

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

Parameters:

a the global displacement vector edof dof topology array

Returns:

ed: element displacement array
calfem.core.extract_eldisp(edof, a)

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

Parameters:

a the global displacement vector edof dof topology array

Returns:

ed: 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:

ex = [x1 x2 x3 x4] element coordinates ey = [y1 y2 y3 y4]

ep = [t ir] thickness and integration rule

D = [[kxx kxy],
[kyx kyy]] constitutive matrix

eq heat supply per unit volume

Returns:
Ke element ‘stiffness’ matrix (4 x 4) fe element load vector (4 x 1)
calfem.core.flw2i4s(ex, ey, ep, D, ed)[source]

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

Parameters:

ex = [x1 x2 x3 x4] element coordinates ey = [y1 y2 y3 y4]

ep = [t ir] thickness and integration rule

D = [[kxx kxy],
[kyx kyy]] constitutive matrix

ed = [u1, u2, u3, u4] u1,u2,u3,u4: nodal values

Returns:
es = [[qx, qy],
[.., ..]] element flows
et = [[qx, qy],
[… ..]] element gradients
eci=[[ix1, iy1], Gauss point location vector
[… …], nint: number of integration points [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:

ex = [x1, …, x8] element coordinates ey = [y1, …, y8]

ep = [t, ir] thickness and integration rule

D = [[kxx, kxy],
[kyx, kyy]] constitutive matrix

eq heat supply per unit volume

Returns:

Ke element ‘stiffness’ matrix (8 x 8) fe element load vector (8 x 1)
calfem.core.flw2i8s(ex, ey, ep, D, ed)[source]

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

Parameters:

ex = [x1,x2,x3….,x8] element coordinates ey = [y1,y2,y3….,y8]

ep = [t,ir] thickness and integration rule

D = [[kxx,kxy],
[kyx,kyy]] constitutive matrix

ed = [u1,….,u8] u1,….,u8: nodal values

Returns:
es = [[qx,qy],
[..,..]] element flows
et = [[qx,qy],
[..,..]] element gradients
eci=[[ix1,iy1], Gauss point location vector
[…,…], nint: number of integration points [ix(nint),iy(nint)]]
calfem.core.flw2qe(ex, ey, ep, D, eq=None)[source]

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

Parameters:

ex = [x1, x2, x3, x4] ey = [y1, y2, y3, y4] element coordinates

ep = [t] element thickness

D = [[kxx, kxy],
[kyx, kyy]] constitutive matrix

eq heat supply per unit volume

Returns:

Ke element ‘stiffness’ matrix (4 x 4)

fe element load vector (4 x 1)

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

Compute flows or corresponding quantities in the quadrilateral field element.

Parameters:

ex = [x1, x2, x3, x4] ey = [y1, y2, y3, y4] element coordinates

ep = [t] element thickness

D = [[kxx, kxy],
[kyx, kyy]] constitutive matrix
ed = [[u1, u2, u3, u4],
[.., .., .., ..]] u1,u2,u3,u4: nodal values

eq heat supply per unit volume

Returns:

es = [[qx, qy],
[.., ..]] element flows
et = [[gx, gy],
[.., ..]] element gradients
calfem.core.flw2te(ex, ey, ep, D, eq=None)[source]

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

Parameters:

ex = [x1 x2 x3] ey = [y1 y2 y3] element coordinates

ep = [t] element thickness

D = [kxx kxy;

kyx kyy] constitutive matrix

eq heat supply per unit volume

Returns:

Ke element ‘stiffness’ matrix (3 x 3)

fe element load vector (3 x 1)

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

Compute flows or corresponding quantities in the triangular field element.

Parameters:

ex = [x1 x2 x3] ey = [y1 y2 y3] element coordinates

D = [kxx kxy
kyx kyy] constitutive matrix
ed =[u1 u2 u3] u1,u2,u3: nodal values

Returns:

es=[ qx qy ]
… ..] element flows
et=[ gx gy ]
… ..] element gradients
calfem.core.flw3i8e(ex, ey, ez, ep, D, eq=None)[source]

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

Parameters:

ex = [x1,x2,x3,…,x8] ey = [y1,y2,y3,…,y8] element coordinates ez = [z1,z2,z3,…,z8]

ep = [ir] Ir: Integration rule

D = [[kxx,kxy,kxz],
[kyx,kyy,kyz], [kzx,kzy,kzz]] constitutive matrix

eq heat supply per unit volume

Output:

Ke element ‘stiffness’ matrix (8 x 8) fe element load vector (8 x 1)
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:

ex = [x1,x2,x3,…,x8] ey = [y1,y2,y3,…,y8] element coordinates ez = [z1,z2,z3,…,z8]

ep = [ir] Ir: Integration rule

D = [[kxx,kxy,kxz],
[kyx,kyy,kyz], [kzx,kzy,kzz]] constitutive matrix
ed = [[u1,….,u8], element nodal values
[..,….,..]]

Output:

es = [[qx,qy,qz],
[..,..,..]] element flows(s)
et = [[qx,qy,qz], element gradients(s)
[..,..,..]]
eci = [[ix1,ix1,iz1], location vector
[…,…,…], nint: number of integration points [ix(nint),iy(nint),iz(nint)]]
calfem.core.hooke(ptype, E, v)[source]

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

Parameters:

ptype= 1: plane stress
2: plane strain 3: axisymmetry 4: three dimensional

E Young’s modulus v Poissons const.

Returns:

D material matrix
calfem.core.info(msg)[source]

Write msg to info 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:

ex = [x1 … x4] element coordinates. Row array ey = [y1 … y4]

ep =[ptype, t, ir] ptype: analysis type
t : thickness ir: integration rule

D constitutive matrix

eq = [bx; by] bx: body force in x direction
by: body force in y direction
Any array with 2 elements acceptable
Returns:
Ke : element stiffness matrix (8 x 8) fe : equivalent nodal forces (8 x 1)
calfem.core.planqe(ex, ey, ep, D, eq=None)[source]

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

Parameters:

ex=[x1 x2 x3 x4] element coordinates ey=[y1 y2 y3 y4]

ep = [ptype, t] ptype: analysis type
t: element thickness

D constitutive matrix

eq = [bx; bx: body force in x direction
by] by: body force in y direction
OUTPUT: Ke : element stiffness matrix (8 x 8)
fe : equivalent nodal forces (row array)
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:

ex = [x1 x2 x3 x4] element coordinates ey = [y1 y2 y3 y4]

ep = [ptype, t] ptype: analysis type
t: thickness

D constitutive matrix

ed = [u1 u2 ..u8] element displacement vector

eq = [[bx] bx: body force in x direction
[by]] by: body force in y direction
OUTPUT: es = [ sigx sigy (sigz) tauxy] element stress array
et = [ epsx epsy (epsz) gamxy] element strain array
calfem.core.plante(ex, ey, ep, D, eq=None)[source]

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

Parameters:

ex = [x1,x2,x3] element coordinates ey = [y1,y2,y3]

ep = [ptype,t] ptype: analysis type
t: thickness

D constitutive matrix

eq = [[bx], bx: body force x-dir
[by]] by: body force y-dir

Returns:

Ke element stiffness matrix (6 x 6) fe equivalent nodal forces (6 x 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:

ex = [x1,x2,x3] node coordinates ey = [y1,y2,y3]

ep = [ptype,t] ptype: analysis type
t: thickness
es = [[sigx,sigy,[sigz],tauxy] element stress matrix
[ …… ]] one row for each element

OUTPUT:

fe = [[f1],[f2],…,[f8]] internal force vector
calfem.core.plants(ex, ey, ep, D, ed)[source]

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

INPUT: ex = [x1 x2 x3] element coordinates

ey = [y1 y2 y3]

ep = [ptype t ] ptype: analysis type
t: thickness

D constitutive matrix

ed =[u1 u2 …u6 element displacement vector
…… ] one row for each element
OUTPUT: es = [ sigx sigy [sigz] tauxy element stress matrix
…… ] one row for each element
et = [ epsx epsy [epsz] gamxy element strain matrix
…… ] one row for each element
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:

ex = [x1,x2,x3,x4] element coordinates ey = [y1,y2,y3,y4]

ep = [t] thicknes

D constitutive matrix for
plane stress

eq = [qz] load/unit area

Returns:

Ke element stiffness matrix (12 x 12) fe equivalent nodal forces (12 x 1)
calfem.core.solveq(K, f, bcPrescr, bcVal=None)[source]

Solve static FE-equations considering boundary conditions.

Parameters:

K global stiffness matrix, dim(K)= nd x nd f global load vector, dim(f)= nd x 1

bcPrescr 1-dim integer array containing prescribed dofs. bcVal 1-dim float array containing prescribed values.

If not given all prescribed dofs are assumed 0.

Returns:

a solution including boundary values Q reaction force vector

dim(a)=dim(Q)= nd x 1, nd : number of dof’s
calfem.core.spring1e(ep)[source]

Compute element stiffness matrix for spring element.

Parameters:ep (float) – spring stiffness or analog quantity (ep = k).
Return mat Ke:stiffness matrix, dim(Ke)= 2 x 2
calfem.core.spring1s(ep, ed)[source]

Compute element force in spring element (spring1e).

Parameters:
  • ep (float) – spring stiffness or analog quantity
  • ed (list) – element displacements [d0, d1]
Return float es:
 

element force [N]

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

Solve static FE-equations considering boundary conditions.

Parameters:

K global stiffness matrix, dim(K)= nd x nd f global load vector, dim(f)= nd x 1

bcPrescr 1-dim integer array containing prescribed dofs. bcVal 1-dim float array containing prescribed values.

If not given all prescribed dofs are assumed 0.

Returns:

a solution including boundary values Q reaction force vector

dim(a)=dim(Q)= nd x 1, nd : number of dof’s
calfem.core.statcon(K, f, cd)[source]

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

Parameters:

K global stiffness matrix, dim(K) = nd x nd f global load vector, dim(f)= nd x 1

cd vector containing dof’s to be eliminated
dim(cd)= nc x 1, nc: number of condensed dof’s

Returns:

K1 condensed stiffness matrix,
dim(K1)= (nd-nc) x (nd-nc)

f1 condensed load vector, dim(f1)= (nd-nc) x 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]

Geometry functions

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)[source]

Adds a B-Spline curve

points - List of indices of control points that make a B-spline
[p1, p2, … , pn]
ID - 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.

marker - Integer. Marker applied to this curve. Default 0.

elOnCurv - Positive integer. Elements on curve.
The number of element edges that will be distributed along this curve. Only works for structured meshes.
el_distrib_type -
String. Either “bump” or “progression”. Determines how the density of elements vary along the curve for structured meshes. Only works for structured meshes. elOnCurv and el_distrib_val must be be defined if this param is used.
el_distrib_val -

Float. Determines how severe the element distribution is. Only works for structured meshes. elOnCurv 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)[source]

Adds a Circle arc curve.

points - list of 3 indices of point that make a circle arc smaller
than Pi. [startpoint, centerpoint, endpoint]
ID - 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.

marker - Marker applied to this curve. Default 0.

elOnCurv - Elements on curve.
The number of element edges that will be distributed along this curve. Only works for structured meshes.
el_distrib_type -
String. Either “bump” or “progression”. Determines how the density of elements vary along the curve for structured meshes. Only works for structured meshes. elOnCurv and el_distrib_val must be be defined if this param is used.
el_distrib_val -

Float. Determines how severe the element distribution is. Only works for structured meshes. elOnCurv 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)[source]

Adds a Ellipse arc curve.

points - 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.
ID - 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.

marker - Integer. Marker applied to this curve. Default 0.

elOnCurv - Positive integer. Elements on curve.
The number of element edges that will be distributed along this curve. Only works for structured meshes.
el_distrib_type -
String. Either “bump” or “progression”. Determines how the density of elements vary along the curve for structured meshes. Only works for structured meshes. elOnCurv and el_distrib_val must be be defined if this param is used.
el_distrib_val -

Float. Determines how severe the element distribution is. Only works for structured meshes. elOnCurv 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)[source]

Adds a point.

Parameters: coord - [x, y] or [x, y, z].

List, not array.
ID - 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.
marker - 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.
elSize - 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)[source]

Add points from a numpy-array

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

Adds a Ruled Surface (bent surface). Parameters: outer_loop - List of 3 or 4 curve IDs that make up the boundary of

the surface.
ID - 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.

marker - Integer. 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)[source]

Adds a Spline curve

points - List of indices of control points that make a Spline
[p1, p2, … , pn]
ID - 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.

marker - Integer. Marker applied to this curve. Default 0.

elOnCurv - Positive integer. Elements on curve.
The number of element edges that will be distributed along this curve. Only works for structured meshes.
el_distrib_type -
String. Either “bump” or “progression”. Determines how the density of elements vary along the curve for structured meshes. Only works for structured meshes. elOnCurv and el_distrib_val must be be defined if this param is used.
el_distrib_val -

Float. Determines how severe the element distribution is. Only works for structured meshes. elOnCurv 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.

addSplines(points)[source]

Add splines from numpy array

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

Adds a Structured Surface. Parameters: outer_loop - 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.
ID - 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.

marker - Integer. Marker applied to this surface. Default 0.

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

Adds a Structured Volume Parameters: outer_surfaces - List of surface IDs that make up the outer boundary of

the volume. The surfaces must be Structured Surfaces.
ID - 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.

marker - Integer. Marker applied to this volume. Default 0.

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

Adds a plane surface (flat). Parameters: outer_loop - List of curve IDs that make up the outer boundary of

the surface. The curves must lie in the same plane.
holes - List of lists of curve IDs that make up the inner
boundaries of the surface. The curves must lie in the same plane.
ID - 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.

marker - Integer. Marker applied to this surface. Default 0.

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

Adds a Volume Parameters: outer_surfaces - List of surface IDs that make up the outer boundary of

the volume.
holes - List of lists of surface IDs that make up the inner
boundaries of the volume.
ID - 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.

marker - Integer. 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)

Adds a B-Spline curve

points - List of indices of control points that make a B-spline
[p1, p2, … , pn]
ID - 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.

marker - Integer. Marker applied to this curve. Default 0.

elOnCurv - Positive integer. Elements on curve.
The number of element edges that will be distributed along this curve. Only works for structured meshes.
el_distrib_type -
String. Either “bump” or “progression”. Determines how the density of elements vary along the curve for structured meshes. Only works for structured meshes. elOnCurv and el_distrib_val must be be defined if this param is used.
el_distrib_val -

Float. Determines how severe the element distribution is. Only works for structured meshes. elOnCurv 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)

Adds a Circle arc curve.

points - list of 3 indices of point that make a circle arc smaller
than Pi. [startpoint, centerpoint, endpoint]
ID - 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.

marker - Marker applied to this curve. Default 0.

elOnCurv - Elements on curve.
The number of element edges that will be distributed along this curve. Only works for structured meshes.
el_distrib_type -
String. Either “bump” or “progression”. Determines how the density of elements vary along the curve for structured meshes. Only works for structured meshes. elOnCurv and el_distrib_val must be be defined if this param is used.
el_distrib_val -

Float. Determines how severe the element distribution is. Only works for structured meshes. elOnCurv 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)

Adds a Ellipse arc curve.

points - 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.
ID - 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.

marker - Integer. Marker applied to this curve. Default 0.

elOnCurv - Positive integer. Elements on curve.
The number of element edges that will be distributed along this curve. Only works for structured meshes.
el_distrib_type -
String. Either “bump” or “progression”. Determines how the density of elements vary along the curve for structured meshes. Only works for structured meshes. elOnCurv and el_distrib_val must be be defined if this param is used.
el_distrib_val -

Float. Determines how severe the element distribution is. Only works for structured meshes. elOnCurv 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

points - List of indices of control points that make a Spline
[p1, p2, … , pn]
ID - 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.

marker - Integer. Marker applied to this curve. Default 0.

elOnCurv - Positive integer. Elements on curve.
The number of element edges that will be distributed along this curve. Only works for structured meshes.
el_distrib_type -
String. Either “bump” or “progression”. Determines how the density of elements vary along the curve for structured meshes. Only works for structured meshes. elOnCurv and el_distrib_val must be be defined if this param is used.
el_distrib_val -

Float. Determines how severe the element distribution is. Only works for structured meshes. elOnCurv 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)

Adds a point.

Parameters: coord - [x, y] or [x, y, z].

List, not array.
ID - 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.
marker - 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.
elSize - The size of elements at this point. Default 1. Use to make
a mesh denser or sparser here. Only affects unstructured meshes
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_loop - List of 3 or 4 curve IDs that make up the boundary of

the surface.
ID - 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.

marker - Integer. Marker applied to this surface. Default 0.

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

Adds a Ruled Surface (bent surface). Parameters: outer_loop - List of 3 or 4 curve IDs that make up the boundary of

the surface.
ID - 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.

marker - Integer. Marker applied to this surface. Default 0.

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

Adds a Ruled Surface (bent surface). Parameters: outer_loop - List of 3 or 4 curve IDs that make up the boundary of

the surface.
ID - 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.

marker - Integer. 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)

Adds a Spline curve

points - List of indices of control points that make a Spline
[p1, p2, … , pn]
ID - 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.

marker - Integer. Marker applied to this curve. Default 0.

elOnCurv - Positive integer. Elements on curve.
The number of element edges that will be distributed along this curve. Only works for structured meshes.
el_distrib_type -
String. Either “bump” or “progression”. Determines how the density of elements vary along the curve for structured meshes. Only works for structured meshes. elOnCurv and el_distrib_val must be be defined if this param is used.
el_distrib_val -

Float. Determines how severe the element distribution is. Only works for structured meshes. elOnCurv 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.

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

Adds a Structured Surface. Parameters: outer_loop - 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.
ID - 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.

marker - Integer. Marker applied to this surface. Default 0.

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

Adds a Structured Surface. Parameters: outer_loop - 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.
ID - 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.

marker - Integer. Marker applied to this surface. Default 0.

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

Adds a Structured Volume Parameters: outer_surfaces - List of surface IDs that make up the outer boundary of

the volume. The surfaces must be Structured Surfaces.
ID - 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.

marker - Integer. Marker applied to this volume. Default 0.

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

Adds a Structured Surface. Parameters: outer_loop - 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.
ID - 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.

marker - Integer. Marker applied to this surface. Default 0.

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

Adds a Structured Volume Parameters: outer_surfaces - List of surface IDs that make up the outer boundary of

the volume. The surfaces must be Structured Surfaces.
ID - 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.

marker - Integer. 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

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

Adds a plane surface (flat). Parameters: outer_loop - List of curve IDs that make up the outer boundary of

the surface. The curves must lie in the same plane.
holes - List of lists of curve IDs that make up the inner
boundaries of the surface. The curves must lie in the same plane.
ID - 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.

marker - Integer. Marker applied to this surface. Default 0.

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

Adds a plane surface (flat). Parameters: outer_loop - List of curve IDs that make up the outer boundary of

the surface. The curves must lie in the same plane.
holes - List of lists of curve IDs that make up the inner
boundaries of the surface. The curves must lie in the same plane.
ID - 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.

marker - Integer. Marker applied to this surface. Default 0.

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

Adds a Volume Parameters: outer_surfaces - List of surface IDs that make up the outer boundary of

the volume.
holes - List of lists of surface IDs that make up the inner
boundaries of the volume.
ID - 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.

marker - Integer. Marker applied to this volume. Default 0.

Mesh functions

calfem.mesh.GmshMesh

alias of GmshMeshGenerator

class calfem.mesh.GmshMeshGenerator(geometry, el_type=2, el_size_factor=1, dofs_per_node=1, gmsh_exec_path=None, clcurv=False, min_size=None, max_size=None, meshing_algorithm=None, additional_options='', mesh_dir='', return_boundary_elements=False)[source]

Meshes geometry in GeoData objects or geo-files by calling the Gmsh executable. This is done when the function create() is called.

create(is3D=False)[source]

Meshes a surface or volume defined by the geometry in geoData. Parameters: is3D - Optional parameter that only needs to be set if geometry

is loaded from a geo-file, i.e. if geoData is a path string. Default False.

Returns:

coords Node coordinates

[[n0_x, n0_y, n0_z], [ … ], [nn_x, nn_y, nn_z]]

edof Element topology

[[el0_dof1, …, el0_dofn], [ … ], [eln_dof1, …, eln_dofn]]

dofs Node dofs

[[n0_dof1, …, n0_dofn], [ … ], [nn_dof1, …, nn_dofn]]
bdofs Boundary dofs. Dictionary containing lists of dofs for
each boundary marker. Dictionary key = marker id.
elementmarkers List of integer markers. Row i contains the marker of
element i. Markers are similar to boundary markers and can be used to identify in which region an element lies.
boundaryElements (optional) returned if self.return_boundary_elements is true.
Contains dictionary with boundary elements. The keys are markers and the values are lists of elements for that marker.

Running this function also creates object variables:

nodesOnCurve Dictionary containing lists of node-indices. Key is a
curve-ID and the value is a list of indices of all nodes on that curve, including its end points.
nodesOnSurface Dictionary containing lists of node-indices. Key is a
surface-ID and the value is a list of indices of the nodes on that surface, including its boundary.
nodesOnVolume Dictionary containing lists of node-indices. Key is a
volume-ID and the value is a list of indices of the nodes in that volume, including its surface.
calfem.mesh.error(msg)[source]

Log error message

calfem.mesh.info(msg)[source]

Log information message

calfem.mesh.trimesh2d(vertices, segments=None, holes=None, maxArea=None, quality=True, dofs_per_node=1, logFilename='tri.log', triangleExecutablePath=None)[source]

Triangulates an area described by a number vertices (vertices) and a set of segments that describes a closed polygon.

Parameters:

vertices array [nVertices x 2] with vertices describing the geometry.

[[v0_x, v0_y],
[ … ], [vn_x, vn_y]]

segments array [nSegments x 3] with segments describing the geometry.

[[s0_v0, s0_v1,marker],
[ … ], [sn_v0, sn_v1,marker]]

holes [Not currently used]

maxArea Maximum area for triangle. (None)

quality If true, triangles are prevented having angles < 30 degrees. (True)

dofs_per_node Number of degrees of freedom per node.

logFilename Filename for triangle output (“tri.log”)

Returns:

coords Node coordinates

[[n0_x, n0_y],
[ … ], [nn_x, nn_y]]

edof Element topology

[[el0_dof1, …, el0_dofn],
[ … ], [eln_dof1, …, eln_dofn]]

dofs Node dofs

[[n0_dof1, …, n0_dofn],
[ … ], [nn_dof1, …, nn_dofn]]
bdofs Boundary dofs. Dictionary containing lists of dofs for
each boundary marker. Dictionary key = marker id.

User interface functions

Created on Mon Apr 11 09:44:29 2016

@author: lindemann

calfem.ui.appInstance(useVisVis=True)[source]

Create a suitable application instance

calfem.ui.loadUiWidget(uifilename, parent=None)[source]

Load user interface file and return object model

Utility functions

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

Apply traction on part of boundarty 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:

boundaryElements Dictionary with boundary elements, the key is a marker and the values are lists of elements. coords Coordinates matrix dofs Dofs matrix F force matrix. marker Boundary marker to assign boundary condition. q Value to assign boundary condition.

shape = [qx qy] in global coordinates
calfem.utils.applybc(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:

boundaryDofs Dictionary with boundary dofs. bcPresc 1-dim integer array containing prescribed dofs. bcVal 1-dim float array containing prescribed values. marker Boundary marker to assign boundary condition. value Value to assign boundary condition.

If not given 0.0 is assigned.

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

Returns:

bcPresc Updated 1-dim integer array containing prescribed dofs. bcVal Updated 1-dim float array containing prescribed values.
calfem.utils.applybc3D(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:

boundaryDofs Dictionary with boundary dofs. bcPresc 1-dim integer array containing prescribed dofs. bcVal 1-dim float array containing prescribed values. marker Boundary marker to assign boundary condition. value Value to assign boundary condition.

If not given 0.0 is assigned.
dimension dimension to apply bc. 0 - all, 1 - x, 2 - y,
3 - z

Returns:

bcPresc Updated 1-dim integer array containing prescribed dofs. bcVal Updated 1-dim float array containing prescribed values.
calfem.utils.applyforce(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.applyforce3D(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 3D problems with 3 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,
3 - z
calfem.utils.applyforcetotal(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:

boundaryDofs Dictionary with boundary dofs. f force matrix. marker Boundary marker to assign boundary condition. value Total force 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.applyforcetotal3D(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:

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

If not given 0.0 is assigned.
dimension dimension to apply force. 0 - all, 1 - x, 2 - y,
3 - z
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:

filename Filename of vtk-file coords Element coordinates (np.array) topo Element topology (not dof topology). mesh.topo. (np.array) a Element displacements 2-dof (np.array) el_scalar Scalar values for each element (list) el_vec1 Vector value for each element (list) el_vec2 Vector value for each element (list)
calfem.utils.readFloat(f)[source]

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

calfem.utils.readInt(f)[source]

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

calfem.utils.readSingleFloat(f)[source]

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

calfem.utils.readSingleInt(f)[source]

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

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:

ex, ey element node coordinates

ed element displacement matrix or section force matrix

rat relation between illustrated quantity and element size.
If not specified, 0.2 is used.
calfem.utils.which(filename)[source]

Return complete path to executable given by filename.

Visualisation functions (Matplotlib)

calfem.vis_mpl.camera3d()[source]

Get visvis 3D camera.

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

Duplicate code. Extracts verts, faces and verticesPerFace from input.

calfem.vis_mpl.clf()[source]

Clear 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

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. Args:

coords:
An N-by-2 or N-by-3 array. Row i contains the x,y,z coordinates of node i.
edof:
An E-by-L array. Element topology. (E is the number of elements and L is the number of dofs per element)
dofs_per_nodes:
Integer. Dofs per node.
el_type:
Integer. Element Type. See Gmsh manual for details. Usually 2 for triangles or 3 for quadrangles.
axes:
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_adjust:
Boolean. True if the view should be changed to show the whole model. Default True.
title:
String. Changes title of the figure. Default “Mesh”.
color:
3-tuple or char. Color of the wire. Defaults to black (0,0,0). Can also be given as a character in ‘rgbycmkw’.
face_color:
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.
filled:
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.

Args:
ev:
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.
coords:
An N-by-2 or N-by-3 array. Row i contains the x,y,z coordinates of node i.
edof:
An E-by-L array. Element topology. (E is the number of elements and L is the number of dofs per element)
dofs_per_node:
Integer. Dofs per node.
el_type:
Integer. Element Type. See Gmsh manual for details. Usually 2 for triangles or 3 for quadrangles.
displacements:
An N-by-2 or N-by-3 array. Row i contains the x,y,z displacements of node i.
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_mesh:
Boolean. True if the wire of the undisplaced mesh should be drawn on top of the displaced mesh. Default False. Use only if displacements != None.
magnfac:
Float. Magnification factor. Displacements are multiplied by this value. Use this to make small displacements more visible.
title:
String. 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.

Args:
ev:
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.
coords:
An N-by-2 or N-by-3 array. Row i contains the x,y,z coordinates of node i.
edof:
An E-by-L array. Element topology. (E is the number of elements and L is the number of dofs per element)
dofs_per_node:
Integer. Dofs per node.
el_type:
Integer. Element Type. See Gmsh manual for details. Usually 2 for triangles or 3 for quadrangles.
displacements:
An N-by-2 or N-by-3 array. Row i contains the x,y,z displacements of node i.
draw_mesh:
Boolean. True if mesh wire should be drawn. Default True.
draw_undisplaced_mesh:
Boolean. True if the wire of the undisplaced mesh should be drawn on top of the displaced mesh. Default False. Use only if displacements != None.
magnfac:
Float. Magnification factor. Displacements are multiplied by this value. Use this to make small displacements more visible.
title:
String. Changes title of the figure. Default “Element Values”.
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)[source]

Draws the geometry (points and curves) in geoData Args:

geoData:
GeoData object. Geodata contains geometric information of the model.
axes:
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_adjust:
Boolean. If True the view will be changed to show the whole model. Default True.
draw_points:
Boolean. If True points will be drawn.
label_points:
Boolean. If True Points will be labeled. The format is: ID[marker]. If a point has marker==0 only the ID is written.
label_curves:
Boolean. If True Curves will be labeled. The format is: ID(elementsOnCurve)[marker].
font_size:
Integer. Size of the text in the text labels. Default 11.
N:
Integer. The number of discrete points per curve segment. Default 20. Increase for smoother curves. Decrease for better performance.
rel_margin:
Extra spacing between geometry and axis
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. Args:

coords:
An N-by-2 or N-by-3 array. Row i contains the x,y,z coordinates of node i.
edof:
An E-by-L array. Element topology. (E is the number of elements and L is the number of dofs per element)
dofs_per_nodes:
Integer. Dofs per node.
el_type:
Integer. Element Type. See Gmsh manual for details. Usually 2 for triangles or 3 for quadrangles.
axes:
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_adjust:
Boolean. True if the view should be changed to show the whole model. Default True.
title:
String. Changes title of the figure. Default “Mesh”.
color:
3-tuple or char. Color of the wire. Defaults to black (0,0,0). Can also be given as a character in ‘rgbycmkw’.
face_color:
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.
filled:
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)

Draws element nodal values as filled contours. Element topologies supported are triangles, 4-node quads and 8-node quads.

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]

Draws element nodal values as filled contours. Element topologies supported are triangles, 4-node quads and 8-node quads.

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]

Draws element nodal values as filled contours. Element topologies supported are triangles, 4-node quads and 8-node quads.

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

Draws element nodal values as shaded triangles. Element topologies supported are triangles, 4-node quads and 8-node quads.

calfem.vis_mpl.eldraw2(ex, ey, plotpar, elnum)[source]

eldraw2(ex,ey,plotpar) eldraw2(ex,ey)

PURPOSE

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. elemen

INPUT
ex,ey:………. nen: number of element nodes
nel: number of elements

plotpar=[ linetype, linecolor, nodemark]

linetype=1 -> solid linecolor=1 -> black

2 -> dashed 2 -> blue 3 -> dotted 3 -> magenta

4 -> red
nodemark=1 -> circle
2 -> star 0 -> no mark

elnum=edof(:,1) ; i.e. the first column in the topology matrix

Rem. 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=(4, 3))[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.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.topo_to_tri(edof)[source]

Converts 2d element topology to triangle topology to be used with the matplotlib functions tricontour and tripcolor.

Visualisation functions (VisVis)

calfem.vis.addLabel(text, pos, angle=0, font_name=None, font_size=9, color='k', bgcolor=None, axes=None)

Adds a label inside the axes. Returns the Label object. Parameters: text - String. The text of the label pos - Tuple with two numbers. The (x,y) position of the label with origin

at the upper left corner.

angle - Float or int. The rotation of the label in degrees. font_name- String. Either ‘mono’, ‘sans’ or ‘serif’. font_size- Int. Size of the text. Default 9. color - A 3-tuple or a character in ‘rgbycmkw’, etc that defines text color.

Default ‘k’ (black).

bgcolor - Background color. See color. Default None. axes - Axes wherein the label is placed. If None then the current axes is

chosen.
calfem.vis.addText(text, pos, angle=0, font_name=None, font_size=9, color='k', bgcolor=None, axes=None)

Adds a text in the world space. Returns the Text object. Parameters: text - String. The text of the label pos - Tuple with two or three numbers. The (x,y,z) position of the text in

world space.

angle - Float or int. The rotation of the label in degrees. font_name- String. Either ‘mono’, ‘sans’ or ‘serif’. font_size- Int. Size of the text. Default 9. color - A 3-tuple or a character in ‘rgbycmkw’, etc that defines text color.

Default ‘k’ (black).

bgcolor - Background color. See color. Default None. axes - Axes wherein the label is placed. If None then the current axes is

chosen.
calfem.vis.add_label(text, pos, angle=0, font_name=None, font_size=9, color='k', bgcolor=None, axes=None)[source]

Adds a label inside the axes. Returns the Label object. Parameters: text - String. The text of the label pos - Tuple with two numbers. The (x,y) position of the label with origin

at the upper left corner.

angle - Float or int. The rotation of the label in degrees. font_name- String. Either ‘mono’, ‘sans’ or ‘serif’. font_size- Int. Size of the text. Default 9. color - A 3-tuple or a character in ‘rgbycmkw’, etc that defines text color.

Default ‘k’ (black).

bgcolor - Background color. See color. Default None. axes - Axes wherein the label is placed. If None then the current axes is

chosen.
calfem.vis.add_text(text, pos, angle=0, font_name=None, font_size=9, color='k', bgcolor=None, axes=None)[source]

Adds a text in the world space. Returns the Text object. Parameters: text - String. The text of the label pos - Tuple with two or three numbers. The (x,y,z) position of the text in

world space.

angle - Float or int. The rotation of the label in degrees. font_name- String. Either ‘mono’, ‘sans’ or ‘serif’. font_size- Int. Size of the text. Default 9. color - A 3-tuple or a character in ‘rgbycmkw’, etc that defines text color.

Default ‘k’ (black).

bgcolor - Background color. See color. Default None. axes - Axes wherein the label is placed. If None then the current axes is

chosen.
calfem.vis.camera3d()[source]

Get visvis 3D camera.

calfem.vis.clf()[source]

Clear visvis figure

calfem.vis.closeAll()

Close all visvis windows.

calfem.vis.close_all()[source]

Close all visvis windows.

calfem.vis.colorBar(axes=None)

Short form of getColorbar

calfem.vis.color_bar(axes=None)[source]

Short form of getColorbar

calfem.vis.drawDisplacements(displacements, coords, edof, dofs_per_node, el_type, node_vals=None, clim=None, axes=None, axes_adjust=True, draw_undisplaced_mesh=True, magnfac=1.0, title=None)

Draws mesh with displacements in 2D or 3D. Scalar nodal values can also be drawn on the mesh. Returns the displaced Mesh object. Parameters: displacements-An N-by-1 array (or matrix). Row i contains the displacement of

dof i. N-by-2 or N-by-3 arrays are also accepted, in which case row i contains the x,y,z displacements of node i.
coords - An N-by-2 or N-by-3 array. Row i contains the x,y,z coordinates
of node i.
edof - An E-by-L array. Element topology. (E is the number of elements
and L is the number of dofs per element)

dofs_per_node - Integer. Dofs per node. el_type - Integer. Element Type. See Gmsh manual for details. Usually 2

for triangles or 3 for quadrangles.
node_vals - An N-by-1 array or a list of scalars. The Scalar values at the
nodes. node_vals[i] should be the value of node i.
clim - 2-tuple. Colorbar limits (min, max). Defines the value range of
the colorbar. Defaults to None, in which case min/max are set to min/max of node_vals.
axes - Visvis 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_adjust - Boolean. True if the view should be changed to show the whole
model. Default True.

draw_elements - Boolean. True if mesh wire should be drawn. Default True. magnfac - Float. Magnification factor. Displacements are multiplied by

this value. Use this to make small displacements more visible.
title - String. Changes title of the figure. Default None (in which case
title depends on other parameters).
calfem.vis.drawElementValues(ev, coords, edof, dofs_per_node, el_type, displacements=None, clim=None, axes=None, axes_adjust=True, draw_elements=True, draw_undisplaced_mesh=False, magnfac=1.0, title=None)

Draws scalar element values in 2D or 3D. Returns the world object elementsWobject that represents the mesh. Parameters: ev - 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.
coords - An N-by-2 or N-by-3 array. Row i contains the x,y,z coordinates
of node i.
edof - An E-by-L array. Element topology. (E is the number of elements
and L is the number of dofs per element)

dofs_per_node - Integer. Dofs per node. el_type - Integer. Element Type. See Gmsh manual for details. Usually 2

for triangles or 3 for quadrangles.
displacements - An N-by-2 or N-by-3 array. Row i contains the x,y,z
displacements of node i.
clim - 2-tuple. Colorbar limits (min, max). Defines the value range of
the colorbar. Defaults to None, in which case min/max are set to min/max of node_vals.
axes - Visvis 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_adjust - Boolean. True if the view should be changed to show the whole
model. Default True.

draw_elements - Boolean. True if mesh wire should be drawn. Default True. draw_undisplaced_mesh - Boolean. True if the wire of the undisplaced mesh

should be drawn on top of the displaced mesh. Default False. Use only if displacements != None.
magnfac - Float. Magnification factor. Displacements are multiplied by
this value. Use this to make small displacements more visible.

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

calfem.vis.drawGeometry(geoData, axes=None, axes_adjust=True, draw_points=True, label_points=True, label_curves=True, title=None, font_size=11, N=20)

Draws the geometry (points and curves) in geoData Parameters: geoData - GeoData object. Geodata contains geometric information of the

model.
axes - Visvis 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_adjust - Boolean. If True the view will be changed to show the whole
model. Default True.

draw_points - Boolean. If True points will be drawn. label_points- Boolean. If True Points will be labeled. The format is:

ID[marker]. If a point has marker==0 only the ID is written.
label_curves- Boolean. If True Curves will be labeled. The format is:
ID(elementsOnCurve)[marker].

font_size - Integer. Size of the text in the text labels. Default 11. N - Integer. The number of discrete points per curve segment.

Default 20. Increase for smoother curves. Decrease for better performance.
calfem.vis.drawMesh(coords, edof, dofs_per_node, el_type, axes=None, axes_adjust=True, title=None, color=(0, 0, 0), face_color=(1, 1, 1), filled=False)

Draws wire mesh of model in 2D or 3D. Returns the Mesh object that represents the mesh. Parameters: coords - An N-by-2 or N-by-3 array. Row i contains the x,y,z coordinates

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

dofs_per_node - Integer. Dofs per node. el_type - Integer. Element Type. See Gmsh manual for details. Usually 2

for triangles or 3 for quadrangles.
axes - Visvis 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_adjust - Boolean. True if the view should be changed to show the whole
model. Default True.

title - String. Changes title of the figure. Default “Mesh”. color - 3-tuple or char. Color of the wire. Defaults to black (0,0,0).

Can also be given as a character in ‘rgbycmkw’.
face_color - 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.
filled - Boolean. Faces will be drawn if True. Otherwise only the wire is
drawn. Default False.
calfem.vis.drawNodalValues(node_vals, coords, edof, dofs_per_node, el_type, clim=None, axes=None, axes_adjust=True, draw_elements=True, title=None)

Draws scalar nodal values in 2D or 3D. Returns the Mesh object that represents the mesh. Parameters: node_vals - An N-by-1 array or a list of scalars. The Scalar values at the

nodes. node_vals[i] should be the value of node i
coords - An N-by-2 or N-by-3 array. Row i contains the x,y,z coordinates
of node i.
edof - An E-by-L array. Element topology. (E is the number of elements
and L is the number of dofs per element)

dofs_per_node - Integer. Dofs per node. el_type - Integer. Element Type. See Gmsh manual for details. Usually 2

for triangles or 3 for quadrangles.
clim - 2-tuple. Colorbar limits (min, max). Defines the value range of
the colorbar. Defaults to None, in which case min/max are set to min/max of node_vals.
axes - Visvis 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_adjust - Boolean. True if the view should be changed to show the whole
model. Default True.

draw_elements - Boolean. True if mesh wire should be drawn. Default True. title - String. Changes title of the figure. Default “Node Values”.

calfem.vis.draw_displacements(displacements, coords, edof, dofs_per_node, el_type, node_vals=None, clim=None, axes=None, axes_adjust=True, draw_undisplaced_mesh=True, magnfac=1.0, title=None)[source]

Draws mesh with displacements in 2D or 3D. Scalar nodal values can also be drawn on the mesh. Returns the displaced Mesh object. Parameters: displacements-An N-by-1 array (or matrix). Row i contains the displacement of

dof i. N-by-2 or N-by-3 arrays are also accepted, in which case row i contains the x,y,z displacements of node i.
coords - An N-by-2 or N-by-3 array. Row i contains the x,y,z coordinates
of node i.
edof - An E-by-L array. Element topology. (E is the number of elements
and L is the number of dofs per element)

dofs_per_node - Integer. Dofs per node. el_type - Integer. Element Type. See Gmsh manual for details. Usually 2

for triangles or 3 for quadrangles.
node_vals - An N-by-1 array or a list of scalars. The Scalar values at the
nodes. node_vals[i] should be the value of node i.
clim - 2-tuple. Colorbar limits (min, max). Defines the value range of
the colorbar. Defaults to None, in which case min/max are set to min/max of node_vals.
axes - Visvis 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_adjust - Boolean. True if the view should be changed to show the whole
model. Default True.

draw_elements - Boolean. True if mesh wire should be drawn. Default True. magnfac - Float. Magnification factor. Displacements are multiplied by

this value. Use this to make small displacements more visible.
title - String. Changes title of the figure. Default None (in which case
title depends on other parameters).
calfem.vis.draw_element_values(ev, coords, edof, dofs_per_node, el_type, displacements=None, clim=None, axes=None, axes_adjust=True, draw_elements=True, draw_undisplaced_mesh=False, magnfac=1.0, title=None)[source]

Draws scalar element values in 2D or 3D. Returns the world object elementsWobject that represents the mesh. Parameters: ev - 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.
coords - An N-by-2 or N-by-3 array. Row i contains the x,y,z coordinates
of node i.
edof - An E-by-L array. Element topology. (E is the number of elements
and L is the number of dofs per element)

dofs_per_node - Integer. Dofs per node. el_type - Integer. Element Type. See Gmsh manual for details. Usually 2

for triangles or 3 for quadrangles.
displacements - An N-by-2 or N-by-3 array. Row i contains the x,y,z
displacements of node i.
clim - 2-tuple. Colorbar limits (min, max). Defines the value range of
the colorbar. Defaults to None, in which case min/max are set to min/max of node_vals.
axes - Visvis 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_adjust - Boolean. True if the view should be changed to show the whole
model. Default True.

draw_elements - Boolean. True if mesh wire should be drawn. Default True. draw_undisplaced_mesh - Boolean. True if the wire of the undisplaced mesh

should be drawn on top of the displaced mesh. Default False. Use only if displacements != None.
magnfac - Float. Magnification factor. Displacements are multiplied by
this value. Use this to make small displacements more visible.

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

calfem.vis.draw_geometry(geoData, axes=None, axes_adjust=True, draw_points=True, label_points=True, label_curves=True, title=None, font_size=11, N=20)[source]

Draws the geometry (points and curves) in geoData Parameters: geoData - GeoData object. Geodata contains geometric information of the

model.
axes - Visvis 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_adjust - Boolean. If True the view will be changed to show the whole
model. Default True.

draw_points - Boolean. If True points will be drawn. label_points- Boolean. If True Points will be labeled. The format is:

ID[marker]. If a point has marker==0 only the ID is written.
label_curves- Boolean. If True Curves will be labeled. The format is:
ID(elementsOnCurve)[marker].

font_size - Integer. Size of the text in the text labels. Default 11. N - Integer. The number of discrete points per curve segment.

Default 20. Increase for smoother curves. Decrease for better performance.
calfem.vis.draw_mesh(coords, edof, dofs_per_node, el_type, axes=None, axes_adjust=True, title=None, color=(0, 0, 0), face_color=(1, 1, 1), filled=False)[source]

Draws wire mesh of model in 2D or 3D. Returns the Mesh object that represents the mesh. Parameters: coords - An N-by-2 or N-by-3 array. Row i contains the x,y,z coordinates

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

dofs_per_node - Integer. Dofs per node. el_type - Integer. Element Type. See Gmsh manual for details. Usually 2

for triangles or 3 for quadrangles.
axes - Visvis 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_adjust - Boolean. True if the view should be changed to show the whole
model. Default True.

title - String. Changes title of the figure. Default “Mesh”. color - 3-tuple or char. Color of the wire. Defaults to black (0,0,0).

Can also be given as a character in ‘rgbycmkw’.
face_color - 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.
filled - Boolean. Faces will be drawn if True. Otherwise only the wire is
drawn. Default False.
calfem.vis.draw_nodal_values(node_vals, coords, edof, dofs_per_node, el_type, clim=None, axes=None, axes_adjust=True, draw_elements=True, title=None)[source]

Draws scalar nodal values in 2D or 3D. Returns the Mesh object that represents the mesh. Parameters: node_vals - An N-by-1 array or a list of scalars. The Scalar values at the

nodes. node_vals[i] should be the value of node i
coords - An N-by-2 or N-by-3 array. Row i contains the x,y,z coordinates
of node i.
edof - An E-by-L array. Element topology. (E is the number of elements
and L is the number of dofs per element)

dofs_per_node - Integer. Dofs per node. el_type - Integer. Element Type. See Gmsh manual for details. Usually 2

for triangles or 3 for quadrangles.
clim - 2-tuple. Colorbar limits (min, max). Defines the value range of
the colorbar. Defaults to None, in which case min/max are set to min/max of node_vals.
axes - Visvis 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_adjust - Boolean. True if the view should be changed to show the whole
model. Default True.

draw_elements - Boolean. True if mesh wire should be drawn. Default True. title - String. Changes title of the figure. Default “Node Values”.

calfem.vis.eldraw2(ex, ey, plotpar, elnum)[source]

eldraw2(ex,ey,plotpar) eldraw2(ex,ey)

PURPOSE

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. elemen

INPUT
ex,ey:………. nen: number of element nodes
nel: number of elements

plotpar=[ linetype, linecolor, nodemark]

linetype=1 -> solid linecolor=1 -> black

2 -> dashed 2 -> blue 3 -> dotted 3 -> magenta

4 -> red
nodemark=1 -> circle
2 -> star 0 -> no mark

elnum=edof(:,1) ; i.e. the first column in the topology matrix

Rem. Default is solid white lines with circles at nodes.

calfem.vis.eldraw2_mpl(ex, ey, plotpar=[1, 2, 1], elnum=[])[source]

eldraw2(ex,ey,plotpar,elnum) eldraw2(ex,ey,plotpar) eldraw2(ex,ey)

PURPOSE

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. elemen

INPUT
ex,ey:………. nen: number of element nodes
nel: number of elements

plotpar=[ linetype, linecolor, nodemark]

linetype=1 -> solid linecolor=1 -> black

2 -> dashed 2 -> blue 3 -> dotted 3 -> magenta

4 -> red
nodemark=1 -> circle
2 -> star 0 -> no mark

elnum=edof(:,1) ; i.e. the first column in the topology matrix

Rem. Default is solid white lines with circles at nodes.

calfem.vis.eldraw2_old(ex, ey)[source]

Draw elements in 2d.

Parameters:

ex, ey Element coordinates plotpar (not implemented yet)
calfem.vis.eliso2_old(ex, ey, ed, showMesh=False)[source]

Draw nodal values in 2d.

Parameters:

ex, ey Element coordinates ed Element nodal values plotpar (not implemented yet)
calfem.vis.elval2(ex, ey, ev, showMesh=False)[source]

Draw elements values in 2d.

Parameters:

ex, ey Element coordinates ev Element values (scalar) plotpar (not implemented yet)
calfem.vis.error(msg)[source]

Log error message

calfem.vis.figure(figure=None, show=True)[source]

Create a visvis figure with extras.

calfem.vis.figureClass()

Return visvis Figure class.

calfem.vis.figure_class()[source]

Return visvis Figure class.

calfem.vis.gca()[source]

Get current axis of the current visvis figure.

calfem.vis.getColorbar(axes=None)

Returns the Colorbar. If axes is None the colorbar in the current axes will be found. If several colorbars exists in the axes the first found will be returned If no colorbar is found None is returned.

calfem.vis.get_color_bar(axes=None)[source]

Returns the Colorbar. If axes is None the colorbar in the current axes will be found. If several colorbars exists in the axes the first found will be returned If no colorbar is found None is returned.

calfem.vis.info(msg)[source]

Log information message

calfem.vis.showAndWait()

Show visvis windows and enter application loop.

calfem.vis.showGrid(flag=True)

Show grid.

calfem.vis.show_and_wait()[source]

Show visvis windows and enter application loop.

calfem.vis.show_grid(flag=True)[source]

Show grid.

calfem.vis.subplot(*args)[source]

Create a visvis subplot.