calfem for python documentation

108
CALFEM for Python Documentation Release 3.5.1 Jonas Lindemann Apr 05, 2022

Upload: others

Post on 15-Apr-2022

36 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CALFEM for Python Documentation

CALFEM for Python DocumentationRelease 3.5.1

Jonas Lindemann

Apr 05, 2022

Page 2: CALFEM for Python Documentation
Page 3: CALFEM for Python Documentation

INSTALLATION

1 Contents: 1

Python Module Index 99

Index 101

i

Page 4: CALFEM for Python Documentation

ii

Page 5: CALFEM for Python Documentation

CHAPTER

ONE

CONTENTS:

1.1 Installation instructions

The simplest way to install CALFEM for Python is via pip. This procedure will ensure that all required dependenciesare fulfilled.

This can be achieved by executing the following command:

pip install calfem-python

or:

sudo pip install calfem-python

to install system-wide (not recommended if your system used a lot of python dependencies):

pip install -u calfem-python

to install just for your own user. You can use the argument –user which is same as -u. If you want to specify yourPython version, use the command like the following:

python3.9 -m pip install --user calfem-python

where python3.9 is the Python version you want to install CALFEM for Python. Change this command with yourpreferable version. This last command is the preferred one according to the Python community.

1.1.1 Installing in a Anaconda environment

If you don’t want to install all packages directly in the base Anaconda environment you could create a new enviromentfor CALFEM:

conda create -n calfem-dev python=3.9conda activate calfem-dev

Now we can install CALFEM for Python and its dependencies directly into this environment using Pip.:

pip install calfem-python

1

Page 6: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

1.2 Using CALFEM for Python

1.2.1 What is CALFEM?

CALFEM is an interactive computer program for teaching the finite element method (FEM). The name CALFEM isan abbreviation of “Computer Aided Learning of the Finite Element Method”. The program can be used for differenttypes of structural mechanics problems and field problems.

CALFEM, the program and its built-in philosophy, have been developed at the Division of Structural Mechanics, LundUniversity, starting in the late 70’s. Many coworkers, former and present, have been engaged in the development atdifferent stages.

1.2.2 What is CALFEM for Python?

• Subset of CALFEM routines implemented in Python

• Using NumPy for matrices

• Additional mesh generation routines supporting Triangle and GMSH

• Plotting with Matplotlib and visvis

1.2.3 CALFEM Python modules

• calfem.core

– Element routines

– System routines

• calfem.utils

– I/O routines

– Misc. routines

• calfem.geometry

– Routines for defining problem geometry used for input in mesh generation

• calfem.mesh

– Mesh generation routines

• calfem.vis/calfem.vis_mpl

– Routines for visualising geometry, meshes and results.

1.2.4 Examples

The example codes show what CALFEM can do for you. The examples are divided into two:

• Numerical examples

• Mesh examples

The next is tutorial on using Calfem for Python for numerical finite element, i.e., solving FEM equation to obtain nodaldisplacements given loading forces and stiffness matrix. The example can be found in examples directories both oncalfem-python root directory (for .py files) and docs directory (for .ipynb files).

2 Chapter 1. Contents:

Page 7: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

1.3 Example: Connected springs

This example is from the CALFEM manual (exs1.py).

Purpose:

Show the basic steps in a finite element calculation.

Description:

The general procedure in linear finite element calculations is carried out for a simple structure. The steps are:

• define the model

• generate element matrices

• assemble element matrices into the global system of equations

• solve the global system of equations

• evaluate element forces

Consider the system of three linear elastic springs, and the corresponding finite element model. The system of springsis fixed in its ends and loaded by a single load F. To make it convenience, we follow notation in “Fundamentals of FiniteElement Analysis” by David Hutton, where square is symbol for nodes, circle is for element, and U is for (global) nodaldisplacement. Capital letter shows global variables while small letter follows local variables.

We begin our FEM computation by importing required modules

1.3. Example: Connected springs 3

Page 8: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

# ----- import necesarry mooules

The computation is initialized by defining the topology matrix Edof, containing element numbers and global elementdegrees of freedom. All input to CALFEM is NumPy arrays. Topology is defined by index 1, i.e., the first row representsthe first element bounded by node 1 and node 2. Hence we write

import calfem.core as cfc

# ----- Topology matrix Edof

edof = np.array([

the initial global stiffness matrix K (3x3) and load force f containing zeros,

[2, 3] # element 3 between node 2 and 3])

Element stiffness matrices are generated by the function spring1e. The element property ep for the springs contains thespring stiffnesses k and 2k respectively, where k = 1500.

# ----- Stiffness matrix K and load vector f

K = np.zeros((3, 3))f = np.zeros((3, 1))

# ----- Element stiffness matrices

k = 1500.ep1 = kep2 = 2.*kKe1 = cfc.spring1e(ep1)Ke2 = cfc.spring1e(ep2)

# ----- Assemble Ke into K

The output is printed as follows:

Stiffness matrix K:[[ 3000. -3000. 0.][-3000. 7500. -4500.][ 0. -4500. 4500.]]

and the load/force vector f (3x1) with the load F = 100 in position 2 (Note that Python indexes from 0, hence f[1]corresponds to edof 2).

cfc.assem(edof[1, :], K, Ke1)

The element stiffness matrices are assembled into the global stiffness matrix K according to the topology. bc is an arrayof prescribed degrees of freedom. Values to be specified are specified in a separate array. If all values are 0, they don’thave to be specified. The global system of equations is solved considering the boundary conditions given in bc.

print("Stiffness matrix K:")print(K)

(continues on next page)

4 Chapter 1. Contents:

Page 9: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

(continued from previous page)

# f[1] corresponds to edof 2

f[1] = 100.0

# ----- Solve the system of equations

output:

Displacements a:[[0. ][0.01333333][0. ]]Reaction forces Q:[[-40.][ 0.][-60.]]

Element forces are evaluated from the element displacements. These are obtained from the global displacements ausing the function extract.

a, r = cfc.solveq(K, f, bc)

print("Displacements a:")

The spring element forces at each element are evaluated using the function spring1s.

ed1 = cfc.extract_ed(edof[0, :], a)ed2 = cfc.extract_ed(edof[1, :], a)

Output:

Element forces N:N1 = 40.0N2 = -20.0N3 = -40.0

1.4 Example: One-dimensional heat flow

This example is from the CALFEM manual (exs2.py).

Purpose:

Analysis of one-dimensional heat flow.

Description:

Consider a wall built up of concrete and thermal insulation. The outdoor temperature is 17 ◦C and the temperatureinside is 20 ◦C. At the inside of the thermal insulation there is a heat source yielding 10 𝑊/𝑚2.

1.4. Example: One-dimensional heat flow 5

Page 10: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

The wall is subdivided into five elements and the one-dimensional spring (analogy) element spring1e is used. Equiv-alent spring stiffnesses are 𝑘𝑖 = 𝐴/𝐿 for thermal conductivity and 𝑘𝑖 = 𝐴/𝑅 for thermal surface resistance. Corre-sponding spring stiffnesses per 𝑚2 of the wall are:

𝑘1 = 1/0.04 = 25.0 𝑊/𝐾 (1.1)𝑘2 = 1.7/0.070 = 24.3 𝑊/𝐾 (1.2)𝑘3 = 0.040/0.100 = 0.4 𝑊/𝐾 (1.3)𝑘4 = 1.7/0.100 = 17.0 𝑊/𝐾 (1.4)𝑘5 = 1/0.13 = 7.7 𝑊/𝐾 (1.5)

A global system matrix K and a heat flow vector f are defined. The heat source inside the wall is considered by setting𝑓4 = 10. The element matrices Ke are computed using spring1e, and the function assem assembles the globalstiffness matrix.

The system of equations is solved using solveq with considerations to the boundary conditions in bc and bcVal. Theprescribed temperatures are 𝑇1 = 17 ∘𝐶 and 𝑇2 = 20 ∘𝐶.

Necessary modules are first imported.

[1]: import numpy as npimport calfem.core as cfc

Next, the element topology is defined

[2]: Edof = np.array([[1,2],[2,3],[3,4],[4,5],[5,6]

])

Create stiffness matrix K and load vector f

[3]: K = np.mat(np.zeros((6,6)))f = np.mat(np.zeros((6,1)))f[3] = 10.0

6 Chapter 1. Contents:

Page 11: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

Define element properties (ep) and create element matrices for the different material layers.

[4]: ep1 = 25.0ep2 = 24.3ep3 = 0.4ep4 = 17.0ep5 = 7.7

Element stiffness matrices

[5]: Ke1 = cfc.spring1e(ep1)Ke2 = cfc.spring1e(ep2)Ke3 = cfc.spring1e(ep3)Ke4 = cfc.spring1e(ep4)Ke5 = cfc.spring1e(ep5)

Assemble all element matrices into the global stiffness matrix

[6]: cfc.assem(Edof[0,:], K, Ke1)cfc.assem(Edof[1,:], K, Ke2)cfc.assem(Edof[2,:], K, Ke3)cfc.assem(Edof[3,:], K, Ke4)cfc.assem(Edof[4,:], K, Ke5)

print("Stiffness matrix K:")print(K)

Stiffness matrix K:[[ 25. -25. 0. 0. 0. 0. ][-25. 49.3 -24.3 0. 0. 0. ][ 0. -24.3 24.7 -0.4 0. 0. ][ 0. 0. -0.4 17.4 -17. 0. ][ 0. 0. 0. -17. 24.7 -7.7][ 0. 0. 0. 0. -7.7 7.7]]

Define the boundary conditions and solve the system of equations

[7]: bc = np.array([1,6])bcVal = np.array([-17.0, 20.0])a,r = cfc.solveq(K, f, bc, bcVal)

print("Displacements a:")print(a)

print("Reaction forces r:")print(r)

Displacements a:[[-17. ][-16.43842455][-15.86067203][ 19.23779344][ 19.47540439][ 20. ]]Reaction forces r:

(continues on next page)

1.4. Example: One-dimensional heat flow 7

Page 12: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

(continued from previous page)

[[-1.40393862e+01][ 0.00000000e+00][ 0.00000000e+00][ 0.00000000e+00][ 5.68434189e-14][ 4.03938619e+00]]

1.5 Example: Bars

This example is from the CALFEM manual (exs2.py).

Purpose:

Analysis the displacement at point of loading on a plane truss

Description:

Consider a plane truss consisting of three bars with the properties 𝐸 = 200𝐺𝑃𝑎, 𝐴1 = 6.0104𝑚2 , 𝐴2 = 3.0104𝑚

2

and 𝐴3 = 10.0104𝑚2 , and loaded by a single force 𝑃 = 80𝑘𝑁 . The corresponding finite element model consists of

three elements and eight degrees of freedom.

[1]: import numpy as npimport calfem.core as cfc

Topology matrix Edof

Define element topology. Element number are not used in the Edof matrix in CALFEM for Python.

[2]: Edof = np.array([[1,2,5,6],[5,6,7,8],[3,4,5,6]

])

Stiffness matrix K and load vector f

8 Chapter 1. Contents:

Page 13: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

[3]: K = np.matrix(np.zeros((8,8)))f = np.matrix(np.zeros((8,1)))

Element properties

[4]: E = 2.0e11A1 = 6.0e-4A2 = 3.0e-4A3 = 10.0e-4ep1 = [E,A1]ep2 = [E,A2]ep3 = [E,A3]

Element coordinates

[5]: ex1 = np.array([0., 1.6])ex2 = np.array([1.6, 1.6])ex3 = np.array([0., 1.6])

ey1 = np.array([0., 0.])ey2 = np.array([0., 1.2])ey3 = np.array([1.2, 0.])

Element stiffness matrices

[6]: Ke1 = cfc.bar2e(ex1,ey1,ep1)Ke2 = cfc.bar2e(ex2,ey2,ep2)Ke3 = cfc.bar2e(ex3,ey3,ep3)

Assemble Ke into K

Based on the topology information, the global stiffness matrix can be generated by assembling the element stiffnessmatrices

[7]: cfc.assem(Edof[0,:],K,Ke1)cfc.assem(Edof[1,:],K,Ke2)cfc.assem(Edof[2,:],K,Ke3)

[7]: matrix([[ 7.50e+07, 0.00e+00, 0.00e+00, 0.00e+00, -7.50e+07,0.00e+00, 0.00e+00, 0.00e+00],

[ 0.00e+00, 0.00e+00, 0.00e+00, 0.00e+00, 0.00e+00,0.00e+00, 0.00e+00, 0.00e+00],

[ 0.00e+00, 0.00e+00, 6.40e+07, -4.80e+07, -6.40e+07,4.80e+07, 0.00e+00, 0.00e+00],

[ 0.00e+00, 0.00e+00, -4.80e+07, 3.60e+07, 4.80e+07,-3.60e+07, 0.00e+00, 0.00e+00],[-7.50e+07, 0.00e+00, -6.40e+07, 4.80e+07, 1.39e+08,-4.80e+07, 0.00e+00, 0.00e+00],[ 0.00e+00, 0.00e+00, 4.80e+07, -3.60e+07, -4.80e+07,8.60e+07, 0.00e+00, -5.00e+07],

[ 0.00e+00, 0.00e+00, 0.00e+00, 0.00e+00, 0.00e+00,0.00e+00, 0.00e+00, 0.00e+00],

[ 0.00e+00, 0.00e+00, 0.00e+00, 0.00e+00, 0.00e+00,-5.00e+07, 0.00e+00, 5.00e+07]])

1.5. Example: Bars 9

Page 14: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

[8]: print("Stiffness matrix K:")print(K)

Stiffness matrix K:[[ 7.50e+07 0.00e+00 0.00e+00 0.00e+00 -7.50e+07 0.00e+00 0.00e+00

0.00e+00][ 0.00e+00 0.00e+00 0.00e+00 0.00e+00 0.00e+00 0.00e+00 0.00e+000.00e+00]

[ 0.00e+00 0.00e+00 6.40e+07 -4.80e+07 -6.40e+07 4.80e+07 0.00e+000.00e+00]

[ 0.00e+00 0.00e+00 -4.80e+07 3.60e+07 4.80e+07 -3.60e+07 0.00e+000.00e+00]

[-7.50e+07 0.00e+00 -6.40e+07 4.80e+07 1.39e+08 -4.80e+07 0.00e+000.00e+00]

[ 0.00e+00 0.00e+00 4.80e+07 -3.60e+07 -4.80e+07 8.60e+07 0.00e+00-5.00e+07]

[ 0.00e+00 0.00e+00 0.00e+00 0.00e+00 0.00e+00 0.00e+00 0.00e+000.00e+00]

[ 0.00e+00 0.00e+00 0.00e+00 0.00e+00 0.00e+00 -5.00e+07 0.00e+005.00e+07]]

Solve the system of equations

Considering the prescribed displacements in bc, the system of equations is solved using the function solveq, yieldingdisplacements a and support forces r.

[9]: bc = np.array([1,2,3,4,7,8])f[5] = -80e3a, r = cfc.solveq(K,f,bc)

print("Displacements a:")print(a)

print("Reaction forces r:")print(r)

Displacements a:[[ 0. ][ 0. ][ 0. ][ 0. ][-0.00039793][-0.00115233][ 0. ][ 0. ]]Reaction forces r:[[ 29844.55958549][ 0. ][-29844.55958549][ 22383.41968912][ 0. ][ 0. ][ 0. ][ 57616.58031088]]

10 Chapter 1. Contents:

Page 15: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

Element forces

The vertical displacement at the point of loading is 1.15 mm. The negative values shows the direction is to the bot-tom, against the direction of node 6. The section forces es1, es2 and es3 are calculated using bar2s from elementdisplacements ed1, ed2 and ed3 obtained using extract

[10]: ed1 = cfc.extractEldisp(Edof[0,:],a);N1 = cfc.bar2s(ex1,ey1,ep1,ed1)ed2 = cfc.extractEldisp(Edof[1,:],a);N2 = cfc.bar2s(ex2,ey2,ep2,ed2)ed3 = cfc.extractEldisp(Edof[2,:],a);N3 = cfc.bar2s(ex3,ey3,ep3,ed3)print("N1=",N1)print("N2=",N2)print("N3=",N3)

N1= -29844.559585492225N2= 57616.580310880825N3= 37305.69948186528

1.6 Example: More bars

This example is from Calfem manual (exs4.py).

Purpose:

Analysis of a plane truss.

Description:

Consider a plane truss, loaded by a single force P = 0.5 MN at 30 ∘ from normal.

The corresponding finite element model consists of ten elements and twelve degrees of freedom.

1.6. Example: More bars 11

Page 16: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

First, import necessart modules.

[1]: import numpy as npimport calfem.core as cfc

The topology is defined by the matrix

[2]: Edof = np.array([[1, 2, 5, 6],[3, 4, 7, 8],[5, 6, 9, 10],[7, 8, 11, 12],[7, 8, 5, 6],[11, 12, 9, 10],[3, 4, 5, 6],[7, 8, 9, 10],[1, 2, 7, 8],[5, 6, 11, 12]

])

A global stiffness matrix K and a load vector f are defined. The load P is divided into x and y components and insertedin the load vector f.

[3]: K = np.zeros([12,12])f = np.zeros([12,1])

The element matrices Ke are computed by the function bar2e. These matrices are then assembled in the global stiffnessmatrix using the function assem.

12 Chapter 1. Contents:

Page 17: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

[4]: A = 25.0e-4E = 2.1e11ep = [E,A]

Element coordinates are defined as follows.

[5]: ex = np.array([[0., 2.],[0., 2.],[2., 4.],[2., 4.],[2., 2.],[4., 4.],[0., 2.],[2., 4.],[0., 2.],[2., 4.]

])

ey = np.array([[2., 2.],[0., 0.],[2., 2.],[0., 0.],[0., 2.],[0., 2.],[0., 2.],[0., 2.],[2., 0.],[2., 0.]

])

All the element matrices are computed and assembled in the loop.

[6]: for elx, ely, eltopo in zip(ex, ey, Edof):Ke = cfc.bar2e(elx, ely, ep)cfc.assem(eltopo, K, Ke)

The displacements in a and the support forces in r are computed by solving the system of equations considering theboundary conditions in bc.

[7]: bc = np.array([1,2,3,4])

f[10]=0.5e6*np.sin(np.pi/6)f[11]=-0.5e6*np.cos(np.pi/6)

a, r = cfc.solveq(K,f,bc)

[8]: print("Displacement: ")print(a)

Displacement:[[ 0. ]

(continues on next page)

1.6. Example: More bars 13

Page 18: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

(continued from previous page)

[ 0. ][ 0. ][ 0. ][ 0.00238453][-0.0044633 ][-0.00161181][-0.00419874][ 0.00303458][-0.01068377][-0.00165894][-0.01133382]]

[9]: print("Support force: ")print(r)

Support force:[[-8.66025404e+05][ 2.40086918e+05][ 6.16025404e+05][ 1.92925784e+05][ 4.65661287e-10][-2.91038305e-11][ 1.16415322e-10][ 1.16415322e-10][-4.65661287e-10][ 3.49245965e-10][-2.03726813e-10][ 4.65661287e-10]]

The displacement at the point of loading is 1.7103𝑚 in the x-direction and 11.3103 𝑚 in the y-direction. At the uppersupport the horizontal force is 0.866𝑀𝑁 and the vertical 0.240𝑀𝑁 . At the lower support the forces are 0.616𝑀𝑁and 0.193 𝑀𝑁 , respectively. Normal forces are evaluated from element displacements. These are obtained from theglobal displacements a using the function extract. The normal forces are evaluated using the function bar2s.

[10]: ed = cfc.extractEldisp(Edof,a)

N = np.zeros([Edof.shape[0]])

print("Element forces:")

i = 0for elx, ely, eld in zip(ex, ey, ed):

N[i] = cfc.bar2s(elx, ely, ep, eld)print("N%d = %g" % (i+1,N[i]))i+=1

Element forces:N1 = 625938N2 = -423100N3 = 170640N4 = -12372.8N5 = -69447N6 = 170640

(continues on next page)

14 Chapter 1. Contents:

Page 19: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

(continued from previous page)

N7 = -272838N8 = -241321N9 = 339534N10 = 371051

The largest normal force N = 0.626 MN is obtained in element 1 and is equivalent to a normal stress = 250 MPa.

To reduce the quantity of input data, the element coordinates matrices Ex and Ey can alternatively be created from aglobal coordinate matrix Coord and a global topology matrix Dof using the function coordxtr, i.e.

[12]: Coord = np.array([[0, 2],[0, 0],[2, 2],[2, 0],[4, 2],[4, 0]])

[14]: Dof = np.array([[1, 2],[3, 4],[5, 6],[7, 8],[9, 10],[11, 12]])

[17]: ex, ey = cfc.coordxtr(Edof, Coord, Dof)

[18]: print(ex)

[18]: array([[0., 2.],[0., 2.],[2., 4.],[2., 4.],[2., 2.],[4., 4.],[0., 2.],[2., 4.],[0., 2.],[2., 4.]])

[19]: print(ey)

[19]: array([[2., 2.],[0., 0.],[2., 2.],[0., 0.],[0., 2.],[0., 2.],[0., 2.],[0., 2.],

(continues on next page)

1.6. Example: More bars 15

Page 20: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

(continued from previous page)

[2., 0.],[2., 0.]])

As can be seen above, ex and ey is same as previous.

1.7 Example: Frame and bars

This example is from the CALFEM MATLAB manual (exs7.m)

Purpose:

Set up a frame, consisting of both beams and bars, and illustrate the calculations by use of graphics functions.

Description:

A frame consists of horizontal and vertical beams, and is stabilized with diagonal bars

As usual, import necessary modules.

[1]: import numpy as npimport calfem.core as cfc

The frame with its coordinates and loading is shown in the left figure, and the finite element model in the right. Thematrices of the global system i.e. the stiffness matrix K, the load vector f, the coordinate matrix Coord, and thecorresponding degrees of freedom matrix Dof are defined by

[2]: K = np.zeros([18,18])f = np.zeros([18,1])

(continues on next page)

16 Chapter 1. Contents:

Page 21: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

(continued from previous page)

f[12,0] = 1.0

coord = np.array([[0.0, 0.0],[1.0, 0.0],[0.0, 1.0],[1.0, 1.0],[0.0, 2.0],[1.0, 2.0]

])

dof1 = np.array([[1, 2, 3],[4, 5, 6],[7, 8, 9],[10, 11, 12],[13, 14, 15],[16, 17, 18]

])

dof2 = np.array([[1, 2],[4, 5],[7, 8],[10, 11],[13, 14],[16, 17]

])

The material properties, the topology, and the element coordinates for the beams and bars respectively, are defined by

[3]: ep1 = [1.0, 1.0, 1.0]

edof1 = np.array([[1, 2, 3, 7, 8, 9],[7, 8, 9, 13, 14, 15],[4, 5, 6, 10, 11, 12],[10, 11, 12, 16, 17, 18],[7, 8, 9, 10, 11, 12],[13, 14, 15, 16, 17, 18]

])

ex1, ey1 = cfc.coordxtr(edof1, coord, dof1);

ep2 = [1.0, 1.0]

edof2 = np.array([[1, 2, 10, 11],[7, 8, 16, 17],[7, 8, 4, 5],[13, 14, 10, 11]

])(continues on next page)

1.7. Example: Frame and bars 17

Page 22: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

(continued from previous page)

ex2, ey2 = cfc.coordxtr(edof2, coord, dof2);

Create and assemble element matrices

[4]: for elx, ely, eltopo in zip(ex1, ey1, edof1):Ke = cfc.beam2e(elx, ely, ep1)cfc.assem(eltopo, K, Ke)

[5]: for elx, ely, eltopo in zip(ex2, ey2, edof2):Ke = cfc.bar2e(elx, ely, ep2)cfc.assem(eltopo,K,Ke)

Solve equation system

[6]: bc_prescr = np.array([1, 2, 3, 4, 5, 6])a, r = cfc.solveq(K, f, bc_prescr)

[7]: print(a)

[[ 0. ][ 0. ][ 0. ][ 0. ][ 0. ][ 0. ][ 0.37905924][ 0.30451926][-0.65956297][ 0.3041448 ][-0.28495132][-0.54570174][ 1.19791809][ 0.44655174][-0.85908643][ 0.96969909][-0.34780417][-0.74373562]]

1.8 Mesh generation with CALFEM

Included in the Python version of CALFEM is a mesh generation library based on GMSH. The library encapsulatesthe usage of GMSH transparently for the user. It will also parse the output from GMSH and create the necessary datastructures required by CALFEM for solving finite element problems.

Mesh generation in CALFEM is divided in three steps:

1. Defining the geometry of the model.

2. Creating a finite element mesh with the desired elements and properties

3. Extracting data structures that can be used by CALFEM.

The following sections describe these steps.

18 Chapter 1. Contents:

Page 23: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

1.8.1 Required modules for geometry and mesh generation

To use the CALFEM geometry and mesh generation routines, we use the following import directives:

import calfem.geometry as cfgimport calfem.mesh as cfmimport calfem.vis as cfv

1.8.2 Defining geometry

Geometry in CALFEM is described using the Geometry class. A Geometry-object will hold all points, lines andsurfaces describing the geometry. This object is also what is passed to the mesh generation routines in the followingsections.

A Geometry-object, g, is created with the following code:

g = cfg.Geometry()

This creates a Geometry object which will be used to described our geometry. Next we define the points that will beused to define lines, splines or ellipses. In this example we define a simple triangle:

g.point([0.0, 0.0]) # point 0g.point([5.0, 0.0]) # point 1g.point([2.5, 4.0]) # point 2

The points are connected together with spline-elements. These can have 2 or three nodes. In this case we only use 2node splines (lines):

g.spline([0, 1]) # line 0g.spline([1, 2]) # line 1g.spline([2, 0]) # line 2

Finally we create the surface by defining what lines make up the surface:

g.surface([0, 1, 2])

To display our geometry, we use the calfem.vis module:

cfv.drawGeometry(g)cfv.showAndWait()

Running this example will show the following window with a simple rectangle:

1.8. Mesh generation with CALFEM 19

Page 24: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

1.8.3 Creating a mesh

To create a mesh we need to create a GmshMesh object and initialize this with our geometry:

mesh = cfm.GmshMesh(g)

Next, we need to set some desired properties on our mesh:

mesh.elType = 3 # Degrees of freedom per node.mesh.dofsPerNode = 1 # Factor that changes element sizes.mesh.elSizeFactor = 0.15 # Element size Factor

The eltype property determines the element used for mesh generation. Elements that can be generated are:

• 2 - 3 node triangle element

• 3 - 4 node quadrangle element

• 5 - 8 node hexahedron

• 16 - 8 node second order quadrangle

The dofsPerNode defines the number of degrees of freedom for each node. elSizeFactor determines the coarseness ofthe mesh.

To generate the mesh and at the same time get the needed data structures for use with CALFEM we call the .create()method of the mesh object:

20 Chapter 1. Contents:

Page 25: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

coords, edof, dofs, bdofs, elementmarkers = mesh.create()

The returned data structures are:

• coords - Element coordinates

• edof - Element topology

• dofs - Degrees of freedom per node

• bdofs - Boundary degrees of freedom. Dictionary containing the dofs for each boundary marker. More onmarkers in the next section.

• elementmarkers - List of integer markers. Row i contains the marker of element i. Can be used to determinewhat region an element is in.

To display the generated mesh we can use the drawMesh() function of the calfem.vis module:

cfv.figure()

# Draw the mesh.

cfv.drawMesh(coords=coords,edof=edof,dofs_per_node=mesh.dofsPerNode,el_type=mesh.elType,filled=True,title="Example 01"

)

Running the example will produce the following mesh with quad elements:

1.8. Mesh generation with CALFEM 21

Page 26: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

Changing the elType property to 2 (mesh.elType = 2) will produce a mesh with triangle elements instead:

22 Chapter 1. Contents:

Page 27: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

1.8.4 Specifying boundary markers

To assist in assigning boundary conditions, markers can be defined on the geometry, which can be used to identifywhich dofs are assigned to nodes, lines and surfaces.

In this example we add a marker, 10, to line number 2. Markers are added as a parameter to the .spline() method of theGeometry object as shown in the following code:

g.spline([0, 1]) # line 0g.spline([1, 2]) # line 1g.spline([2, 0], marker=10) # line 2 with marker 10

It is also possible to assign markers to points. The marker parameter is added to the .point() method of the Geometryobject.

g.point([0.0, 0.0]) # point 0g.point([5.0, 0.0], marker=20) # point 1g.point([2.5, 4.0]) # point 2

In the same way markers can be added to surfaces as well.

1.8. Mesh generation with CALFEM 23

Page 28: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

1.8.5 Extracting dofs defined by markers

To extract the dofs defined by the marker we use the bdofs dictionary returned when the mesh was created by the.create() method. If we print the bdofs dictionary we get the following output:

{20: [2], 0: [1, 2, ... , 67], 10: [1, 3, 68, ... , 98]}

If we examine the output we see that there is a key, 10, containing the dofs of the number 2 line. We also have the key20 with a single dof 2 in this case. If the dofsPerNode property in the mesh generator was set to 2 the marker 20 wouldhave contained 2 integers.

1.8.6 Complete example with a solver

To illustrate the workflow of the mesh generation modules we implement a complete 2D plane stress solver.

Updated module imports

We need to add some additional import directives, such as the core calfem module as well as the calfem.utils module.We will also need NumPy as well as the standard math routines:

import calfem.core as cfcimport calfem.geometry as cfgimport calfem.mesh as cfmimport calfem.vis_mpl as cfvimport calfem.utils as cfu

import numpy as np

Problem variables and constants

To make it easier to update our example we define a number of variables describing our problem. First some geometricparameters describing our module, in this case a simple rectangular beam:

l = 5.0 # lengthh = 1.0 # heightt = 0.2 # thickness

Next, we define our material properties we will need later in the code:

v = 0.35 # PoissonE = 2.1e9 # Young modulusptype = 1 # plane stressep = [ptype,t]D = cfc.hooke(ptype, E, v)

To make it easier to read our code we define 3 constants, which we will use instead of numerical markers.

left_support = 10right_support = 20top_line = 30

24 Chapter 1. Contents:

Page 29: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

Creating a Geometry object

We are now ready to create a Geometry object describing our geometry:

g = cfg.Geometry()

g.point([0.0, 0.0], marker = left_support) # point 0g.point([l, 0.0], marker = right_support) # point 1g.point([l, h]) # point 2g.point([0.0, h]) # point 3

g.spline([0, 1]) # line 0g.spline([1, 2]) # line 1g.spline([2, 3], marker = top_line) # line 3g.spline([3, 0]) # line 3

g.surface([0, 1, 2, 3])

To show the geometry you can use:

cfv.draw_geometry(g)cfv.showAndWait()

The finished geometry is shown in below:

1.8. Mesh generation with CALFEM 25

Page 30: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

Creating a quad mesh

A quadrilateral mesh is now created with the following code. Please not that we use the dofsPerNode property to specify2 dofs per node as this is a mechanical example.

mesh = cfm.GmshMesh(g)

mesh.elType = 3 # Type of meshmesh.dofsPerNode = 2 # Factor that changes element sizesmesh.elSizeFactor = 0.10 # Factor that changes element sizes

coords, edof, dofs, bdofs, elementmarkers = mesh.create()

As previous, to show the finished mesh you can use:

cfv.figure()cfv.drawMesh(

coords=coords,edof=edof,dofs_per_node=mesh.dofsPerNode,el_type=mesh.elType,filled=True)

cfv.showAndWait()

The finished mesh is shown belo:

Implementing a CALFEM solver

We now have the necessary input to implement a simple CALFEM solver. First, we create some convenience variables,nDofs (total number of dofs), ex and ey (element x and y coordinates).

nDofs = np.size(dofs)ex, ey = cfc.coordxtr(edof, coords, dofs)

The global stiffness matrix can now be allocated:

K = np.zeros([nDofs,nDofs])

For larger problems please consider using sparse matrices instead.

26 Chapter 1. Contents:

Page 31: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

To make the assembly loop less cluttered we use the zip() method to extract rows from edof, ex and ey to eltopo, elxand ely. The loop then becomes:

for eltopo, elx, ely in zip(edof, ex, ey):Ke = cfc.planqe(elx, ely, ep, D)cfc.assem(eltopo, K, Ke)

Please not the difference from standard MATLAB CALFEM that the assem routine does not require returning the Kmatrix on the left side as the assembly is done in place.

Next, we need to setup our boundary conditions. Two empty arrays are created, bc for storing the dof to prescribe andand a second bcVal for storing the prescribed values.

bc = np.array([],'i')bcVal = np.array([],'f')

To prescribe a boundary condition the utility function applybc() is used. This function takes the boundary dictionaryas input and applies the boundary condition to the correct dofs. Here we prescribe the left support as fixed and the rightsupport fixed in y-direction.

bc, bcVal = cfu.applybc(bdofs, bc, bcVal, left_support, 0.0, 0)bc, bcVal = cfu.applybc(bdofs, bc, bcVal, right_support, 0.0, 2)

Now, we have some data structures that can be used by CALFEM. If there is no force and displacement, nothinghappens. If we applied force f and calculate the displacement, then we can solve the equation to obtain more data toplot. These next steps are left in the next examples.

1.9 Mesh example: Simple geometry

Shows how to create simple geometry from splines and ellipse arcs, and how to mesh a quad mesh in GmshMesher.Also demonstrates drawGeometry(), drawMesh, and drawing texts and labels in a figure.

[1]: import numpy as np

import calfem.geometry as cfgimport calfem.mesh as cfmimport calfem.vis_mpl as cfvimport calfem.core as cfcimport calfem.utils as cfu

[2]: # %matplotlib notebook%matplotlib inline

Define the problem variables and geometry

*Problem variables*

[3]: kx1 = 100ky1 = 100t = 1.0

# Gauss points or integration points

(continues on next page)

1.9. Mesh example: Simple geometry 27

Page 32: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

(continued from previous page)

n = 2ep = [t, n]

D = np.matrix([[kx1, 0.],[0., ky1]

])

Define geometry

[4]: g = cfg.Geometry() # Create a GeoData object that holds the geometry.

g.point([0, 0])g.point([2, 0])g.point([2, 1])g.point([0, 1])g.point([0.5, 0.3])g.point([0.3, 0.7])g.point([0.7, 0.7])g.point([0.8, 0.5])g.point([1.7, 0.5])g.point([1.5, 0.5])g.point([1.7, 0.7])

id_hole1 = 50id_hole2 = 60id_outer = 80

g.ellipse([7, 8, 9, 10], marker=id_hole1)g.spline([0, 1], marker=id_outer)g.spline([2, 1], marker=id_outer)g.spline([3, 2], marker=id_outer)g.spline([0, 3], marker=id_outer)g.spline([7, 9], marker=id_hole1)g.spline([10, 9], marker=id_hole1)g.spline([4, 5, 6, 4], marker=id_hole2)

g.surface([4, 3, 2, 1], [[7], [5, 6, 0]])

Generate mesh

[14]: mesh = cfm.GmshMesh(g)

mesh.el_type = 16mesh.dofs_per_node = 1 # Degrees of freedom per node.mesh.el_size_factor = 0.05 # Factor that changes element sizes.

coords, edof, dofs, bdofs, element_markers = mesh.create()

Info : GMSH -> Python-module

Solve problem

*Assemble system matrix*

28 Chapter 1. Contents:

Page 33: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

[6]: n_dofs = np.size(dofs)ex, ey = cfc.coordxtr(edof, coords, dofs)

K = np.zeros([n_dofs, n_dofs])

for el_topo, elx, ely, marker in zip(edof, ex, ey, element_markers):

# Calc element stiffness matrix: Conductivity matrix D is taken# from Ddict and depends on which region (which marker) the element is in.

if mesh.el_type == 2:Ke = cfc.flw2te(elx, ely, ep, D)

elif mesh.el_type == 3:Ke = cfc.flw2i4e(elx, ely, ep, D)

elif mesh.el_type == 16:Ke = cfc.flw2i8e(elx, ely, ep, D)

else:print("Element type not supported")

cfc.assem(el_topo, K, Ke)

Solve equation system

[7]: f = np.zeros([n_dofs, 1])

bc = np.array([], 'i')bc_val = np.array([], 'f')

bc, bc_val = cfu.applybc(bdofs, bc, bc_val, id_outer, 30.0)bc, bc_val = cfu.applybc(bdofs, bc, bc_val, id_hole1, 300.0)bc, bc_val = cfu.applybc(bdofs, bc, bc_val, id_hole2, 400.0)

a, r = cfc.solveq(K, f, bc, bc_val)

Compute element forces

[8]: ed = cfc.extract_eldisp(edof, a)

for i in range(np.shape(ex)[0]):if mesh.el_type == 2:

es, et = cfc.flw2ts(ex[i, :], ey[i, :], D, ed[i, :])elif mesh.el_type == 3:

es, et, eci = cfc.flw2i4s(ex[i, :], ey[i, :], ep, D, ed[i, :])elif mesh.el_type == 16:

es, et, eci = cfc.flw2i8s(ex[i, :], ey[i, :], ep, D, ed[i, :])else:

print("Element type not supported.")

Visualise results

*Geometry*

[9]: cfv.figure(fig_size=(10,10))cfv.draw_geometry(g)

1.9. Mesh example: Simple geometry 29

Page 34: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

Mesh

[10]: cfv.figure(fig_size=(10, 10))cfv.draw_mesh(

coords=coords,edof=edof,dofs_per_node=mesh.dofs_per_node,el_type=mesh.el_type,filled=True,title="Example 01"

)

30 Chapter 1. Contents:

Page 35: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

Temperature

[11]: cfv.figure(fig_size=(10,10))cfv.draw_nodal_values_shaded(a, coords, edof, title="Temperature")cfv.colorbar()

[11]: <matplotlib.colorbar.Colorbar at 0x7fbdae7ec4a8>

1.9. Mesh example: Simple geometry 31

Page 36: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

[12]: cfv.figure(fig_size=(10,10))cfv.draw_nodal_values_contourf(a, coords, edof, title="Temperature", dofs_per_node=mesh.→˓dofs_per_node, el_type=mesh.el_type, draw_elements=True)cfv.colorbar()

[12]: <matplotlib.colorbar.Colorbar at 0x7fbdac82ab00>

32 Chapter 1. Contents:

Page 37: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

[13]: cfv.figure(fig_size=(10,10))cfv.draw_nodal_values_contour(a, coords, edof)cfv.colorbar()

[13]: <matplotlib.colorbar.Colorbar at 0x7fbdac779898>

1.9. Mesh example: Simple geometry 33

Page 38: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

[ ]:

1.10 Mesh example: More geometry

This example is from from Calfem for Pyhon Mesh Manual (Mesh_Ex_02.py)

Creating geometry from B-Splines and circle arcs. Also shows how to set ID numbers for geometry entities and howto specify element density.

[2]: import numpy as np

import calfem.geometry as cfgimport calfem.mesh as cfmimport calfem.vis_mpl as cfv

34 Chapter 1. Contents:

Page 39: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

Define geometry

All mesh generation starts by creating a Geometry object.

[3]: g = cfg.Geometry()

Add points

In this example we set the IDs manually.

[4]: g.point([-2, 0], ID=0)

elSize determines the size of the elements near this point.

[5]: g.point([0, 1], ID=1, el_size=5)

elSize is 1 by default. Larger number means less dense mesh. Size means the length of the sides of the elements.

[6]: g.point([1, 0], 2, el_size=5)g.point([0, -2], 3)g.point([0, 0], 4, el_size=5)g.point([.5, .2], 5)g.point([-.5, .5], 6)g.point([-.7, -.5], 7)

Add curves

The 3 points that define the circle arc are [start, center, end]. The arc must be smaller than Pi.

[7]: g.circle([1, 4, 2], 2)

BSplines are similar to Splines, but do not necessarily pass through the control points.

[8]: g.bspline([5, 6, 7, 5], 5)g.bspline([1, 0, 3, 2], 4)

Add surfaces

[9]: g.surface([4, 2], [[5]])

Markers do not have to be set when the curve is created. It can be done afterwards. Set marker=80 for curves 2 and 4:

[10]: for curveID in [2, 4]:g.curveMarker(curveID, 80)

Generate mesh

Create a mesh object and set its attributes.

[11]: mesh = cfm.GmshMesh(g)

mesh.el_type = 3mesh.dofs_per_node = 2mesh.el_size_factor = 0.05

Create the finite element mesh using the create() method of the mesh object.

1.10. Mesh example: More geometry 35

Page 40: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

[12]: coords, edof, dofs, bdofs, elementmarkers = mesh.create()

Info : GMSH -> Python-module

Visualise mesh

*Draw geometry*

[13]: %matplotlib inline# %matplotlib widget

[14]: cfv.figure(fig_size=(8,8))cfv.draw_geometry(

g,label_curves=True,title="Example 2 - Geometry"

)

Draw mesh

[15]: cfv.figure(fig_size=(8,8))cfv.draw_mesh(

coords=coords,(continues on next page)

36 Chapter 1. Contents:

Page 41: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

(continued from previous page)

edof=edof,dofs_per_node=mesh.dofs_per_node,el_type=mesh.el_type,filled=True,title="Example 2 - Mesh"

)

1.11 Mesh example: Meshing in 2D

Shows structured meshing in 2D.

[1]: import calfem.geometry as cfgimport calfem.mesh as cfmimport calfem.vis_mpl as cfv

Define geometry

[4]: g = cfg.Geometry()

Define points

1.11. Mesh example: Meshing in 2D 37

Page 42: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

[5]: g.point([0,0])g.point([1.2, 0])g.point([1, 1.3])g.point([0, 1])g.point([2, 0.5])

Add splines

The first four curves are structured curves, i.e the number of nodes along the curves is pre-determined. Parameter elOn-Curve states how many elements are placed along the curve. Parameters elDistribType and elDistribVal are optionalparameters that specify how elements are distributed.

• “bump” means elements are bunched up at the ends or the middle of the curve. In this case elDistribVal is smallerthan 1, so elements crowd at the edges.

• “progression” means each element along the curve is larger/smaller than the previous one. A larger elDistribValmakes the elements larger at the end of the curves.

[6]: g.spline([0,1], el_on_curve=10, el_distrib_type="bump", el_distrib_val=0.2)g.spline([1,2], el_on_curve=20, el_distrib_type="progression", el_distrib_val=1.1)g.spline([2,3], el_on_curve=10, el_distrib_type="bump", el_distrib_val=0.2)g.spline([0,3], el_on_curve=20, el_distrib_type="progression", el_distrib_val=1.1)→˓#Change order of points to reverse progression distributiong.spline([2, 4, 1])

Add surfaces

A structured surface must contain 4 curves that have the parameter ‘elOnCurve’ defined. The number of elements ontwo opposite curves must be the same (In this case, curves 0 & 2 and 1 & 3).

[8]: g.structuredSurface([0,1,2,3])g.surface([4,1])

Create mesh

[9]: mesh = cfm.GmshMesh(g)

mesh.el_type = 3 # quadmesh.dofs_per_node = 1mesh.el_size_factor = 0.01

coords, edof, dofs, bdofs, elementmarkers = mesh.create()

Info : GMSH -> Python-module

Visualise mesh

*Draw geometry*

[10]: %matplotlib inline

[11]: cfv.figure(fig_size=(10,10))cfv.draw_geometry(g)

38 Chapter 1. Contents:

Page 43: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

Draw mesh

[12]: cfv.figure(fig_size=(10,10))cfv.draw_mesh(coords=coords, edof=edof, dofs_per_node=mesh.dofs_per_node, el_type=mesh.→˓el_type, filled=True)

1.11. Mesh example: Meshing in 2D 39

Page 44: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

1.12 Mesh example: Plane stress problem

This example is from Calfem for Python Mesh Manual (Mesh_Ex_06.py)

Solves a plane stress 2D problem using a structured mesh. Shows how to draw von Mises effective stress as an elementvalue with drawElementValues(). Shows use of GmshMesher attribute ‘nodesOnCurve’ (dictionary that says whichnodes are on a given geometry curve)

[1]: import calfem.geometry as cfgimport calfem.mesh as cfmimport calfem.vis_mpl as cfvimport calfem.utils as cfuimport calfem.core as cfcimport numpy as np

Define problem variables

[19]: t = 0.2v = 0.35E = 2.1e9ptype = 1ep = [ptype,t]D = cfc.hooke(ptype, E, v)

Define geometry

40 Chapter 1. Contents:

Page 45: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

[20]: g = cfg.geometry()

Create points

Just a shorthand. We use this to make the circle arcs.

[21]: s2 = 1/np.sqrt(2)

Using this we then define our points:

[22]: points = [[0, 3], [2.5, 3], [3, 3], [4-s2, 3-s2], [4, 2], #0-4[4+s2, 3-s2], [5, 3], [5.5, 3], [8,3], [0, 1.5], #5-9[2.5, 1.5], [4, 1.5], [5.5, 1.5], [8, 1.5], [0, 0], #10-14[2.5, 0], [3, 0], [4-s2, s2], [4, 1], [4+s2, s2], #15-19[5, 0], [5.5, 0], [8,0], [4,3], [4,0]] #20-24

for xp, yp in points:g.point([xp*0.1, yp*0.1])

Now we create our curves:

[23]: splines = [[0,1], [1,2], [6,7], [7,8], [8,13], #0-4[13,22], [22,21], [21,20], [16,15], [15,14], #5-9[14,9], [9,0], [9,10], [10,1], [10, 15], #10-14[10,11], [11,4], [11,18], [11,12], [12,7], #15-19[12,21], [12,13], [3,10], [5,12], [10,17], #20-24[12,19]] #25

for s in splines:g.spline(s, el_on_curve=10)

In this case we use special functions to assign IDs to our curves.

[24]: g.curve_marker(ID=4, marker=7) #Assign marker 7 to the splines on the right.g.curve_marker(ID=5, marker=7) # We will apply a force on nodes with marker 7.g.curve_marker(ID=10, marker=5) #Assign marker 5 to the splines on the left.g.curve_marker(ID=11, marker=5) # The nodes with marker 5 will be locked in place.

Next we create our circle arcs.

[25]: # Points in circle arcs are [start, center, end]

circlearcs = [[2, 23, 3], [3, 23, 4], [4, 23, 5], [5, 23, 6], #26-29[16, 24, 17], [17, 24, 18], [18, 24, 19], [19, 24, 20]] #30-33

for c in circlearcs:g.circle(c, el_on_curve=10)

Finally we create our structured surfaces:

[26]: g.struct_surf([11,12,13,0]) #0g.struct_surf([14, 12, 10, 9])g.struct_surf([8, 30, 24, 14])g.struct_surf([24, 31, 17, 15])

(continues on next page)

1.12. Mesh example: Plane stress problem 41

Page 46: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

(continued from previous page)

g.struct_surf([15, 16, 27, 22]) #4g.struct_surf([22, 26, 1, 13])g.struct_surf([16, 18, 23, 28])g.struct_surf([19, 2, 29, 23])g.struct_surf([19, 21, 4, 3]) #8g.struct_surf([20, 6, 5, 21])g.struct_surf([25, 20, 7, 33])g.struct_surf([32, 17, 18, 25]) #11

Create mesh

[27]: mesh = cfm.GmshMesh(g)

mesh.el_type = 3mesh.dofs_per_node = 2

coords, edof, dofs, bdofs, elementmarkers = mesh.create()

Info : GMSH -> Python-module

Solve problem

*Assemble system matrix*

[28]: nDofs = np.size(dofs)ex, ey = cfc.coordxtr(edof, coords, dofs)K = np.zeros([nDofs,nDofs])

for eltopo, elx, ely in zip(edof, ex, ey):Ke = cfc.planqe(elx, ely, ep, D)cfc.assem(eltopo, K, Ke)

Solve equation system

[29]: f = np.zeros([nDofs,1])

bc = np.array([],'i')bcVal = np.array([],'f')

bc, bcVal = cfu.applybc(bdofs, bc, bcVal, 5, 0.0, 0)

cfu.applyforce(bdofs, f, 7, 10e5, 1)

a,r = cfc.solveq(K,f,bc,bcVal)

Compute element forces

[30]: ed = cfc.extract_eldisp(edof,a)

vonMises = []

# For each element:for i in range(edof.shape[0]):

(continues on next page)

42 Chapter 1. Contents:

Page 47: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

(continued from previous page)

# Determine element stresses and strains in the element.es, et = cfc.planqs(ex[i,:], ey[i,:], ep, D, ed[i,:])

# Calc and append effective stress to list.vonMises.append(np.sqrt(np.power(es[0],2) - es[0]*es[1] + np.power(es[1],2) +␣

→˓3*es[2] ) )

## es: [sigx sigy tauxy]

Visualise results

[31]: %matplotlib inline

[32]: cfv.figure(fig_size=(10,10))cfv.draw_geometry(g, draw_points=True, label_curves=True, label_points=True)

[33]: cfv.figure(fig_size=(10,10))cfv.draw_mesh(coords, edof, dofs_per_node=mesh.dofs_per_node, el_type=mesh.el_type)

1.12. Mesh example: Plane stress problem 43

Page 48: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

[34]: cfv.figure(fig_size=(10,10))cfv.draw_element_values(vonMises, coords, edof, mesh.dofs_per_node, mesh.el_type, None,␣→˓draw_elements=False, draw_undisplaced_mesh=False, title="Example 6 - Effective stress")

[35]: cfv.figure(fig_size=(10,10))cfv.draw_displacements(a, coords, edof, mesh.dofs_per_node, mesh.el_type, draw_→˓undisplaced_mesh=True, title="Example 06 - Displacements")

[ ]:

44 Chapter 1. Contents:

Page 49: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

1.13 Mesh example: Effective stress

The use case from the user manual. The example does not contain anything that is not covered in the previous examples.

[1]: import calfem.core as cfcimport calfem.geometry as cfgimport calfem.mesh as cfmimport calfem.vis_mpl as cfvimport calfem.utils as cfuimport numpy as np

from scipy.sparse import lil_matrix

[2]: # %matplotlib notebook%matplotlib inline

Problem parameters

[3]: t = 0.2v = 0.35E1 = 2e9E2 = 0.2e9ptype = 1ep = [ptype,t]D1 = cfc.hooke(ptype, E1, v)D2 = cfc.hooke(ptype, E2, v)

# Define marker constants instead of using numbers in the code

mark_E1 = 55mark_E2 = 66mark_fixed = 70mark_load = 90

# Create dictionary for the different element properties

elprop = {}elprop[mark_E1] = [ep, D1]elprop[mark_E2] = [ep, D2]

# Parameters controlling mesh

el_size_factor = 0.05 # Element size factorel_type = 3 # Triangle elementdofs_per_node = 2 # Dof per node

Create geometry

[4]: g = cfg.Geometry()

Add points

1.13. Mesh example: Effective stress 45

Page 50: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

[5]: g.point([0, 0]) #0g.point([1, 0]) #1g.point([1, 1]) #2g.point([0, 1]) #3g.point([0.2, 0.2]) #4g.point([0.8, 0.2]) #5g.point([0.8, 0.8]) #6g.point([0.2, 0.8]) #7

Add curves

[6]: g.spline([0, 1], marker = mark_fixed) #0g.spline([2, 1]) #1g.spline([3, 2], marker = mark_load) #2g.spline([0, 3]) #3g.spline([4, 5]) #4g.spline([5, 6]) #5g.spline([6, 7]) #6g.spline([7, 4]) #7

Add surfaces

[7]: g.surface([0,1,2,3], holes = [[4,5,6,7]], marker = mark_E1)g.surface([4,5,6,7], marker = mark_E2)

Create mesh

[8]: mesh = cfm.GmshMeshGenerator(g)mesh.el_size_factor = el_size_factormesh.el_type = el_typemesh.dofs_per_node = dofs_per_node

# Mesh the geometry:# The first four return values are the same as those that trimesh2d() returns.# value elementmarkers is a list of markers, and is used for finding the# marker of a given element (index).

coords, edof, dofs, bdofs, elementmarkers = mesh.create()

Info : GMSH -> Python-module

Solve problem

*Assemble system*

[9]: nDofs = np.size(dofs)K = lil_matrix((nDofs,nDofs))ex, ey = cfc.coordxtr(edof, coords, dofs)

for eltopo, elx, ely, elMarker in zip(edof, ex, ey, elementmarkers):

if el_type == 2:Ke = cfc.plante(elx, ely, elprop[elMarker][0], elprop[elMarker][1])

else:(continues on next page)

46 Chapter 1. Contents:

Page 51: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

(continued from previous page)

Ke = cfc.planqe(elx, ely, elprop[elMarker][0], elprop[elMarker][1])

cfc.assem(eltopo, K, Ke)

Solve equation system

[10]: bc = np.array([],'i')bcVal = np.array([],'i')

bc, bcVal = cfu.applybc(bdofs, bc, bcVal, mark_fixed, 0.0)

f = np.zeros([nDofs,1])

cfu.applyforcetotal(bdofs, f, mark_load, value = -10e5, dimension=2)

a,r = cfc.spsolveq(K, f, bc, bcVal)

Calculate element forces

[11]: ed = cfc.extractEldisp(edof, a)von_mises = []

for i in range(edof.shape[0]):

# Handle triangle elements

if el_type == 2:es, et = cfc.plants(ex[i,:], ey[i,:],

elprop[elementmarkers[i]][0],elprop[elementmarkers[i]][1],ed[i,:])

von_mises.append( np.math.sqrt( pow(es[0,0],2) - es[0,0]*es[0,1] + pow(es[0,1],→˓2) + 3*pow(es[0,2],2) ) )

else:

# Handle quad elements

es, et = cfc.planqs(ex[i,:], ey[i,:],elprop[elementmarkers[i]][0],elprop[elementmarkers[i]][1],ed[i,:])

von_mises.append( np.math.sqrt( pow(es[0],2) - es[0]*es[1] + pow(es[1],2) +␣→˓3*pow(es[2],2) ) )

Visualise results

*Geometry*

[12]: cfv.figure(fig_size=(10,10))cfv.draw_geometry(g, title="Geometry")

1.13. Mesh example: Effective stress 47

Page 52: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

Mesh

[13]: cfv.figure(fig_size=(10,10))cfv.draw_mesh(coords=coords, edof=edof, dofs_per_node=dofs_per_node, el_type=el_type,

filled=True, title="Mesh") #Draws the mesh.

48 Chapter 1. Contents:

Page 53: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

Displacements

[14]: cfv.figure(fig_size=(10,10))cfv.draw_displacements(a, coords, edof, dofs_per_node, el_type,

draw_undisplaced_mesh=False, title="Displacements",magnfac=25.0)

1.13. Mesh example: Effective stress 49

Page 54: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

Element values

[15]: cfv.figure(fig_size=(10,10))cfv.draw_element_values(von_mises, coords, edof, dofs_per_node, el_type, a,

draw_elements=True, draw_undisplaced_mesh=False,title="Effective Stress", magnfac=25.0)

cfv.colorbar()

[15]: <matplotlib.colorbar.Colorbar at 0x7f65c86de5f8>

50 Chapter 1. Contents:

Page 55: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

[ ]:

1.14 Developing CALFEM for Python

1.14.1 Creating an environment for development

It could be benficial to create an dedicated environment for development. This can be easily created in the Anacondadistribution.:

conda create -n calfem-dev python=3.9conda activate calfem-dev

1.14. Developing CALFEM for Python 51

Page 56: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

1.14.2 Installing dependencies

To develop for CALFEM for Python you will need to install the required dependencies first. The easiest way to do thisis to install the pip version of CALFEM:

pip install calfem-python

1.14.3 Creating a fork in GitHub

To be able to submit code changes and addition it is a good idea to create a fork on GitHub. A fork is your own versionof CALFEM for Python in which you can track changes. From the fork you can also easily create a pull request, that isa suggested change that you can submit to CALFEM for Python.

Please see

https://reflectoring.io/github-fork-and-pull/

for more information on how to create and manage forks.

1.14.4 Checking out code from github

It is also possible to check out a local version of the code from the command line. The master or develop branches canbe checkout with the following procedures:

Cloning the master branch on your local computer.:

git clone https://github.com/CALFEM/calfem-python.git

Cloning the develop branch on your local computer.:

git clone https://github.com/CALFEM/calfem-python.gitgit checkout develop

It is also possible to use the command line tools to clone your github fork:

git clone https://github.com/USERNAME/calfem-python.git

1.14.5 Using GitHub Desktop to manage your code

GitHub Desktop is a graphical client for GitHub that makes the procedure working with git-repos much more easy.More information on how to use GitHub Desktop can be found here:

https://desktop.github.com/

https://docs.github.com/en/desktop

52 Chapter 1. Contents:

Page 57: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

1.14.6 Modifying the Python search PATH

To work on the checked out source directory, set the PYTHONPATH environment variable to the root of the sourcedirectory.

On Windows:

set PYTHONPATH=C:\[Path to source directory]

On other platforms:

export PYTHONPATH=[Path to source directory]

1.14.7 Guidelines

If you want to develop standalone element routines for CALFEM it is probarbly a good idea to develop them standaloneand then submit a change request for inclusion in the calfem.extension module.

Element routines should be named according to the following rule:

[name][1|2|3][e|s]

Where 1,2 and 3 indicates element dimensions. e - denotes that the routine returns element stiffness matrix and or forcevector. s - denotes that the routines returns element forces given element nodal values.

Please look at existing routines to familiar yourself with how they are constructued.

All routines should have documentation strings describing input and output parameters. Code comments describingthe general flow should be added to the function at relevant positions.

1.14.8 Submit a Pull request

If you want your changes to be included in future releases of CALFEM please create a pull request against GitHub.More information on this can be found here:

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request

1.15 Function reference

1.15.1 Core functions

CALFEM Core module

Contains all the functions implementing CALFEM standard functionality

calfem.core.assem(edof, K, Ke, f=None, fe=None)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 forcevector fe element force vector

Output parameters:

1.15. Function reference 53

Page 58: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

K the new global stiffness matrix f the new global force vector fe element force vector

calfem.core.bar1e(ep)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)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)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)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)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)Compute element stiffness matrix for three dimensional bar element.

Parameters

• ex (list) – element x coordinates [x1, x2]

54 Chapter 1. Contents:

Page 59: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

• 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)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.beam2crd(ex=None, ey=None, ed=None, mag=None)

PURPOSE Calculate the element continous displacements for a number of identical 2D Bernoullibeam elements.

INPUT: ex,ey, ed, mag

OUTPUT: excd,eycd

LAST MODIFIED: P-E AUSTRELL 1993-10-15 Copyright (c) Division of Structural Mechanics and

Division of Solid Mechanics. Lund University

calfem.core.beam2crd_old(ex, ey, ed, mag)

PURPOSE Calculate the element continous displacements for a number of identical 2D Bernoullibeam elements.

INPUT: ex,ey, ed, mag

OUTPUT: excd,eycd

LAST MODIFIED: P-E AUSTRELL 1993-10-15 J Lindemann 2021-12-30 (Python)

Copyright (c) Division of Structural Mechanics and Division of Solid Mechanics. Lund Univer-sity

calfem.core.beam2d(ex, ey, ep)Calculate the stiffness matrix Ke, the mass matrix Me and the damping matrix Ce for a 2D elastic Bernoulli beamelement.

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

1.15. Function reference 55

Page 60: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

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)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)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)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)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

56 Chapter 1. Contents:

Page 61: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

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)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)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 areaI: 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 crosssection 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) . . . .]

1.15. Function reference 57

Page 62: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

calfem.core.beam2w(ex, ey, ep, eq=None)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)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)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 torsionconstant

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)Calculate the variation of the section forces and displacements along a three-dimensional beam element.

Parameters:

58 Chapter 1. Contents:

Page 63: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

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 torsionconstant

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.coord_extract(edof, coords, dofs, nen=- 1)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 dimen-sions dofs [ncoords x nnd]

Returns:

ex if ndims = 1 ex, ey if ndims = 2 ex, ey, ez 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:

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

Returns:

ex if ndims = 1 ex, ey if ndims = 2 ex, ey, ez if ndims = 3

calfem.core.create_dofs(nCoords, nDof )Create dof array [nCoords x nDof]

calfem.core.createdofs(nCoords, nDof )Create dof array [nCoords x nDof]

calfem.core.effmises(es, ptype)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

1.15. Function reference 59

Page 64: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

Returns:

eseff = [eseff_0 .. eseff_nel-1]

calfem.core.error(msg)Write msg to error log.

calfem.core.exception_logging(exctype, value, tb)Log exception by using the root logger.

exctype : type value : NameError tb : traceback

calfem.core.extractEldisp(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.extract_ed(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.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)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)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

60 Chapter 1. Contents:

Page 65: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

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

1.15. Function reference 61

Page 66: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

Ke element ‘stiffness’ matrix (4 x 4)

fe element load vector (4 x 1)

calfem.core.flw2qs(ex, ey, ep, D, ed, eq=None)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)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)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)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

62 Chapter 1. Contents:

Page 67: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

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)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)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)Write msg to info log.

calfem.core.plani4e(ex, ey, ep, D, eq=None)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)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

1.15. Function reference 63

Page 68: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

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)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 strainarray

calfem.core.plante(ex, ey, ep, D, eq=None)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)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)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

64 Chapter 1. Contents:

Page 69: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

calfem.core.platre(ex, ey, ep, D, eq=None)Calculate the stiffness matrix for a rectangular plate element. NOTE! Element sides must be parallel to thecoordinate 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.soli8e(ex, ey, ez, ep, D, eqp=None)Ke=soli8e(ex,ey,ez,ep,D) [Ke,fe]=soli8e(ex,ey,ez,ep,D,eq) ————————————————————-PURPOSE Calculate the stiffness matrix for a 8 node (brick) isoparametric element.

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

ep = [ir] ir integration rule

D constitutive matrix

eq = [bx; by; bz] bx: body force in x direction by: body force in y direction bz: body force in z direction

OUTPUT: Ke [element stiffness matrix] fe : equivalent nodal forces

LAST MODIFIED: M Ristinmaa 1995-10-25 J Lindemann 2022-01-24 (Python version)

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

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

[es,et]=soli8s(ex,ey,ez,ep,D,ed)

PURPOSE Calculate element normal and shear stress for a 8 node (brick) isoparametric element.

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

ep = [Ir] Ir: integration rule

D constitutive matrix

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

OUTPUT: es = [ sigx sigy sigz sigxy sigyz sigxz ;

. . . . . . . . . ]

element stress matrix, one row for each integration point

es = [ eps epsy epsz epsxy epsyz epsxz ; . . . . . . . . . ]

element strain matrix, one row for each integration point

LAST MODIFIED: M Ristinmaa 1995-10-25 J Lindemann 2022-02-23 (Python version)

Copyright (c) Division of Structural Mechanics and Division of Solid Mechanics. Lund Univer-sity

1.15. Function reference 65

Page 70: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

calfem.core.solveq(K, f, bcPrescr, bcVal=None)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 prescribedvalues.

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)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)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)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 prescribedvalues.

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)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

66 Chapter 1. Contents:

Page 71: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

calfem.core.stress2nodal(eseff, edof )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]

1.15.2 Geometry functions

CALFEM Geometry module

Contains functions and classes for describing geometry.

class calfem.geometry.GeometryInstances of GeoData can hold geometric data and be passed to GmshMesher in pycalfem_Mesh to mesh thegeometry.

addBSpline(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 unusedcurve-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 distributedalong this curve. Only works for structured meshes.

el_distrib_type - String. Either “bump” or “progression”. Determines how the density of elements varyalong the curve for structured meshes. Only works for structured meshes. elOnCurv and el_distrib_valmust be be defined if this param is used.

el_distrib_val - Float. Determines how severe the element distribution is. Only works for structuredmeshes. 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 themiddle.

progression:

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

addCircle(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, end-point]

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

marker - Marker applied to this curve. Default 0.

1.15. Function reference 67

Page 72: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

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 varyalong the curve for structured meshes. Only works for structured meshes. elOnCurv and el_distrib_valmust be be defined if this param is used.

el_distrib_val - Float. Determines how severe the element distribution is. Only works for structuredmeshes. 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 themiddle.

progression:

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

addEllipse(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 centerof the ellipse. MAxisPoint is any point on the major axis of the ellipse. Endpoint is the end point ofthe arc.

ID - Positive integer ID of this curve. If left unspecified the curve will be assigned the smallest unusedcurve-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 distributedalong this curve. Only works for structured meshes.

el_distrib_type - String. Either “bump” or “progression”. Determines how the density of elements varyalong the curve for structured meshes. Only works for structured meshes. elOnCurv and el_distrib_valmust be be defined if this param is used.

el_distrib_val - Float. Determines how severe the element distribution is. Only works for structuredmeshes. 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 themiddle.

progression:

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

addPoint(coord, ID=None, marker=0, el_size=1)Adds a point.

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

List, not array.

68 Chapter 1. Contents:

Page 73: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

ID - Positive integer ID of this point. If left unspecified the point will be assigned the smallest unusedpoint-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 topoints 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. Onlyaffects 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_loop - List of 3 or 4 curve IDs that make up theboundary of

the surface.

ID - Positive integer ID of this surface. If left unspecified the surface will be assigned the smallest un-used 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)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 unusedcurve-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 distributedalong this curve. Only works for structured meshes.

el_distrib_type - String. Either “bump” or “progression”. Determines how the density of elements varyalong the curve for structured meshes. Only works for structured meshes. elOnCurv and el_distrib_valmust be be defined if this param is used.

el_distrib_val - Float. Determines how severe the element distribution is. Only works for structuredmeshes. 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 themiddle.

progression:

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

addSplines(points)Add splines from numpy array

addStructuredSurface(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.

1.15. Function reference 69

Page 74: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

ID - Positive integer ID of this surface. If left unspecified the surface will be assigned the smallest un-used 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)Adds a Structured Volume Parameters: outer_surfaces - List of surface IDs that make up the outer boundaryof

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 un-used 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)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 liein the same plane.

ID - Positive integer ID of this surface. If left unspecified the surface will be assigned the smallest un-used 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)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 un-used volume-ID. It is recommended to specify all volume-IDs or none.

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

bounding_box_2d()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 unusedcurve-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 distributedalong this curve. Only works for structured meshes.

el_distrib_type - String. Either “bump” or “progression”. Determines how the density of elements varyalong the curve for structured meshes. Only works for structured meshes. elOnCurv and el_distrib_valmust be be defined if this param is used.

70 Chapter 1. Contents:

Page 75: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

el_distrib_val - Float. Determines how severe the element distribution is. Only works for structuredmeshes. 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 themiddle.

progression:

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

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, end-point]

ID - Positive integer ID of this curve. If left unspecified the curve will be assigned the smallest unusedcurve-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 varyalong the curve for structured meshes. Only works for structured meshes. elOnCurv and el_distrib_valmust be be defined if this param is used.

el_distrib_val - Float. Determines how severe the element distribution is. Only works for structuredmeshes. 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 themiddle.

progression:

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

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 centerof the ellipse. MAxisPoint is any point on the major axis of the ellipse. Endpoint is the end point ofthe arc.

ID - Positive integer ID of this curve. If left unspecified the curve will be assigned the smallest unusedcurve-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 distributedalong this curve. Only works for structured meshes.

1.15. Function reference 71

Page 76: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

el_distrib_type - String. Either “bump” or “progression”. Determines how the density of elements varyalong the curve for structured meshes. Only works for structured meshes. elOnCurv and el_distrib_valmust be be defined if this param is used.

el_distrib_val - Float. Determines how severe the element distribution is. Only works for structuredmeshes. 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 themiddle.

progression:

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

getPointCoords(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 singleinteger 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 singleinteger 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 unusedcurve-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 distributedalong this curve. Only works for structured meshes.

el_distrib_type - String. Either “bump” or “progression”. Determines how the density of elements varyalong the curve for structured meshes. Only works for structured meshes. elOnCurv and el_distrib_valmust be be defined if this param is used.

el_distrib_val - Float. Determines how severe the element distribution is. Only works for structuredmeshes. 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 themiddle.

progression:

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

point(coord, ID=None, marker=0, el_size=1)Adds a point.

72 Chapter 1. Contents:

Page 77: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

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 unusedpoint-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 topoints 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. Onlyaffects unstructured meshes

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

removeCurve(ID)Removes the curve with this ID

removePoint(ID)Removes the point with this ID

removeSurface(ID)Removes the surface with this ID

removeVolume(ID)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 theboundary of

the surface.

ID - Positive integer ID of this surface. If left unspecified the surface will be assigned the smallest un-used 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 theboundary of

the surface.

ID - Positive integer ID of this surface. If left unspecified the surface will be assigned the smallest un-used 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 theboundary of

the surface.

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

1.15. Function reference 73

Page 78: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

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

setCurveMarker(ID, marker)Sets the marker of the curve with the ID

setPointMarker(ID, marker)Sets the marker of the point with the ID

setSurfaceMarker(ID, marker)Sets the marker of the surface with the ID

setVolumeMarker(ID, marker)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 unusedcurve-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 distributedalong this curve. Only works for structured meshes.

el_distrib_type - String. Either “bump” or “progression”. Determines how the density of elements varyalong the curve for structured meshes. Only works for structured meshes. elOnCurv and el_distrib_valmust be be defined if this param is used.

el_distrib_val - Float. Determines how severe the element distribution is. Only works for structuredmeshes. 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 themiddle.

progression:

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

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 un-used 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 un-used surface-ID. It is recommended to specify all surface-IDs or none.

74 Chapter 1. Contents:

Page 79: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

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 boundaryof

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 un-used 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 un-used 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 boundaryof

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 un-used volume-ID. It is recommended to specify all volume-IDs or none.

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

stuffOnSurfaces(IDs)Returns lists of all geometric points and curves on the surfaces specified in IDs. IDs may be an integer ora list of integers

stuffOnVolumes(IDs)Returns lists of all geometric points, curves, and surfaces on the volumes specified in IDs. IDs may be aninteger 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 liein the same plane.

ID - Positive integer ID of this surface. If left unspecified the surface will be assigned the smallest un-used 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.

1.15. Function reference 75

Page 80: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

holes - List of lists of curve IDs that make up the inner boundaries of the surface. The curves must liein the same plane.

ID - Positive integer ID of this surface. If left unspecified the surface will be assigned the smallest un-used 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 un-used volume-ID. It is recommended to specify all volume-IDs or none.

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

1.15.3 Mesh functions

CALFEM Mesh module

Contains functions and classes for generating meshes from geometries.

calfem.mesh.GmshMeshalias of calfem.mesh.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)

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

create(is3D=False, dim=3)Meshes a surface or volume defined by the geometry in geoData. Parameters: is3D - Optional parameterthat 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. Dictio-nary key = marker id.

elementmarkers List of integer markers. Row i contains the marker of element i. Markersare similar to boundary markers and can be used to identify in which region an element lies.

76 Chapter 1. Contents:

Page 81: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

boundaryElements (optional) returned if self.return_boundary_elements is true. Containsdictionary with boundary elements. The keys are markers and the values are lists of elementsfor that marker.

Running this function also creates object variables:

nodesOnCurve Dictionary containing lists of node-indices. Key is a curve-ID and the valueis 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 thevalue 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 thevalue is a list of indices of the nodes in that volume, including its surface.

calfem.mesh.error(msg)Log error message

calfem.mesh.info(msg)Log information message

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

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

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. Dictionarykey = marker id.

1.15. Function reference 77

Page 82: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

1.15.4 User interface functions

CALFEM UI module

Routines for interfacing wirt user interface toolkits.

calfem.ui.appInstance(useVisVis=True)Create a suitable application instance

calfem.ui.app_instance(useVisVis=True)Create a suitable application instance

calfem.ui.loadUiWidget(uifilename, parent=None)Load user interface file and return object model

calfem.ui.load_ui_widget(uifilename, parent=None)Load user interface file and return object model

1.15.5 Utility functions

calfem.utils.applyTractionLinearElement(boundaryElements, coords, dofs, F, marker, q)Apply traction on part of boundarty with marker. q is added to all boundaryDofs defined by marker. Applicableto 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 ofelements. coords Coordinates matrix dofs Dofs matrix F force matrix. marker Boundary marker toassign boundary condition. q Value to assign boundary condition.

shape = [qx qy] in global coordinates

calfem.utils.apply_bc(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:

boundaryDofs Dictionary with boundary dofs. bcPresc 1-dim integer array containing prescribeddofs. bcVal 1-dim float array containing prescribed values. marker Boundary marker to assign bound-ary 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 arraycontaining prescribed values.

calfem.utils.apply_bc_3d(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:

boundaryDofs Dictionary with boundary dofs. bcPresc 1-dim integer array containing prescribeddofs. bcVal 1-dim float array containing prescribed values. marker Boundary marker to assign bound-ary 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

78 Chapter 1. Contents:

Page 83: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

Returns:

bcPresc Updated 1-dim integer array containing prescribed dofs. bcVal Updated 1-dim float arraycontaining prescribed values.

calfem.utils.apply_force(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 2Dproblems with 2 dofs per node.

Parameters:

boundaryDofs Dictionary with boundary dofs. f force matrix. marker Boundary marker to assignboundary 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)Apply boundary force to f matrix. The value is added to all boundaryDofs defined by marker. Applicable to 3Dproblems with 3 dofs per node.

Parameters:

boundaryDofs Dictionary with boundary dofs. f force matrix. marker Boundary marker to assignboundary 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.apply_force_total(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:

boundaryDofs Dictionary with boundary dofs. f force matrix. marker Boundary marker to assignboundary 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.apply_force_total_3d(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:

boundaryDofs Dictionary with boundary dofs. f force matrix. marker Boundary marker to assignboundary 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.apply_traction_linear_element(boundaryElements, coords, dofs, F, marker, q)Apply traction on part of boundarty with marker. q is added to all boundaryDofs defined by marker. Applicableto 2D problems with 2 dofs per node. The function works with linear line elements. (elm-type 1 in GMSH).

Parameters:

1.15. Function reference 79

Page 84: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

boundaryElements Dictionary with boundary elements, the key is a marker and the values are lists ofelements. coords Coordinates matrix dofs Dofs matrix F force matrix. marker Boundary marker toassign 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)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 prescribeddofs. bcVal 1-dim float array containing prescribed values. marker Boundary marker to assign bound-ary 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 arraycontaining 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:

boundaryDofs Dictionary with boundary dofs. bcPresc 1-dim integer array containing prescribeddofs. bcVal 1-dim float array containing prescribed values. marker Boundary marker to assign bound-ary 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 arraycontaining prescribed values.

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 2Dproblems with 2 dofs per node.

Parameters:

boundaryDofs Dictionary with boundary dofs. f force matrix. marker Boundary marker to assignboundary 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. The value is added to all boundaryDofs defined by marker. Applicable to 3Dproblems with 3 dofs per node.

Parameters:

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

If not given 0.0 is assigned.

80 Chapter 1. Contents:

Page 85: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

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

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:

boundaryDofs Dictionary with boundary dofs. f force matrix. marker Boundary marker to assignboundary 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)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 assignboundary 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)

Export mesh and results for a 2D stress problem.

Parameters:

filename Filename of vtk-file coords Element coordinates (np.array) topo Element topology (not doftopology). mesh.topo. (np.array) a Element displacements 2-dof (np.array) el_scalar Scalar values foreach element (list) el_vec1 Vector value for each element (list) el_vec2 Vector value for each element(list)

calfem.utils.load_arrays(name)Load arrays from file.

calfem.utils.load_geometry(name)Loads a geometry from a file.

calfem.utils.load_mesh(name)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 )Read a row from file, f, and return a list of floats.

1.15. Function reference 81

Page 86: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

calfem.utils.read_int(f )Read a row from file, f, and return a list of integers.

calfem.utils.read_single_float(f )Read a single float from a row in file f. All other values on row are discarded.

calfem.utils.read_single_int(f )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')

Save arrays to file.

calfem.utils.save_geometry(g, name='unnamed_geometry')Save a geometry to file.

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

Save arrays as MATLAB .mat files.

calfem.utils.save_mesh(mesh, name='Untitled')Save a mesh to file.

calfem.utils.scalfact2(ex, ey, ed, rat=0.2)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)Return complete path to executable given by filename.

1.15.6 Visualisation functions (Matplotlib)

CALFEM Visualisation module (matplotlib)

Contains all the functions implementing visualisation routines.

calfem.vis_mpl.axis(*args, **kwargs)Define axis of figure (Matplotlib passthrough)

calfem.vis_mpl.camera3d()Get visvis 3D camera.

calfem.vis_mpl.ce2vf(coords, edof, dofs_per_node, el_type)Duplicate code. Extracts verts, faces and verticesPerFace from input.

calfem.vis_mpl.clf()Clear visvis figure

calfem.vis_mpl.closeAll()Close all visvis windows.

calfem.vis_mpl.close_all()Close all visvis windows.

calfem.vis_mpl.colorbar(**kwargs)Add a colorbar to current figure

82 Chapter 1. Contents:

Page 87: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

calfem.vis_mpl.create_ordered_polys(geom, N=10)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 dofsper element)

dofs_per_nodes: Integer. Dofs per node.

el_type: Integer. Element Type. See Gmsh manual for details. Usually 2 for triangles or 3 forquadrangles.

axes: Matplotlib Axes. The Axes where the model will be drawn. If unspecified the current Axeswill 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 characterin ‘rgbycmkw’.

face_color: 3-tuple or char. Color of the faces. Defaults to white (1,1,1). Parameter filled must beTrue 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))

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 ofelement 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 perelement)

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 beused, 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 ofthe displaced mesh. Default False. Use only if displacements != None.

magnfac: Float. Magnification factor. Displacements are multiplied by this value. Use this to make smalldisplacements more visible.

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

1.15. Function reference 83

Page 88: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

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))

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 ofelement 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 perelement)

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 ofthe displaced mesh. Default False. Use only if displacements != None.

magnfac: Float. Magnification factor. Displacements are multiplied by this value. Use this to make smalldisplacements more visible.

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

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)

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 dofsper element)

dofs_per_nodes: Integer. Dofs per node.

el_type: Integer. Element Type. See Gmsh manual for details. Usually 2 for triangles or 3 forquadrangles.

axes: Matplotlib Axes. The Axes where the model will be drawn. If unspecified the current Axeswill 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 characterin ‘rgbycmkw’.

face_color: 3-tuple or char. Color of the faces. Defaults to white (1,1,1). Parameter filled must beTrue 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_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)

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

geoData: GeoData object. Geodata contains geometric information of the model.

84 Chapter 1. Contents:

Page 89: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

axes: Matplotlib Axes. The Axes where the model will be drawn. If unspecified the current Axeswill 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 hasmarker==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 smoothercurves. 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)

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 dofsper element)

dofs_per_nodes: Integer. Dofs per node.

el_type: Integer. Element Type. See Gmsh manual for details. Usually 2 for triangles or 3 forquadrangles.

axes: Matplotlib Axes. The Axes where the model will be drawn. If unspecified the current Axeswill 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 characterin ‘rgbycmkw’.

face_color: 3-tuple or char. Color of the faces. Defaults to white (1,1,1). Parameter filled must beTrue 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 and8-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)

Draws element nodal values as filled contours. Element topologies supported are triangles, 4-node quads and8-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)

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

1.15. Function reference 85

Page 90: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

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

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

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')

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 dofsper element)

dofs_per_nodes: Integer. Dofs per node.

el_type: Integer. Element Type. See Gmsh manual for details. Usually 2 for triangles or 3 forquadrangles.

axes: Matplotlib Axes. The Axes where the model will be drawn. If unspecified the current Axeswill 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 characterin ‘rgbycmkw’.

face_color: 3-tuple or char. Color of the faces. Defaults to white (1,1,1). Parameter filled must beTrue 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.eldisp2(ex, ey, ed, plotpar, sfac)[sfac]=eldisp2(ex,ey,ed,plotpar) [sfac]=eldisp2(ex,ey,ed) ————————————————————-

PURPOSE

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

1) -> bar element 2) -> beam el. 3) -> triangular 3 node el. 4) -> quadrilateral 4node el. 5) -> 8-node isopar. element

INPUT

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

ed: element displacement matrix

plotpar=[ linetype, linecolor, nodemark]

linetype=1 -> solid linecolor=1 -> black 2 -> dashed 2 -> blue 3 -> dotted 3 -> ma-genta

4 -> red

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

sfac: scale factor for displacements

Rem. Default if sfac and plotpar is left out is auto magnification and dashed blacklines with circles at nodes -> plotpar=[2 1 1]

86 Chapter 1. Contents:

Page 91: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.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 Univer-sity

calfem.vis_mpl.eldraw2(ex, ey, plotpar, elnum)calfem.vis_mpl.eldraw2(ex, ey, plotpar)→ Nonecalfem.vis_mpl.eldraw2(ex, ey)→ None

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-nodeisopar. 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)Log error message

calfem.vis_mpl.figure(figure=None, show=True, fig_size=(4, 3))Create a visvis figure with extras.

calfem.vis_mpl.figureClass()Return visvis Figure class.

calfem.vis_mpl.figure_class()Return visvis Figure class.

calfem.vis_mpl.gca()Get current axis of the current visvis figure.

calfem.vis_mpl.info(msg)Log information message

calfem.vis_mpl.pltstyle(plotpar)

PURPOSE Define define linetype,linecolor and markertype character codes.

INPUT plotpar=[ linetype, linecolor, nodemark ]

linetype=1 -> solid linecolor=1 -> black 2 -> dashed 2 -> blue 3 -> dotted 3 -> ma-genta

4 -> red

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

OUTPUT s1: linetype and color for mesh lines s2: type and color for node markers

LAST MODIFIED: Ola Dahlblom 2004-09-15 Copyright (c) Division of Structural Mechanics and

1.15. Function reference 87

Page 92: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

Division of Solid Mechanics. Lund University

calfem.vis_mpl.pltstyle2(plotpar)

PURPOSE Define define linetype,linecolor and markertype character codes.

INPUT plotpar=[ linetype, linecolor, nodemark ]

linetype=1 -> solid linecolor=1 -> black 2 -> dashed 2 -> blue 3 -> dotted 3 -> ma-genta

4 -> red

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

OUTPUT s1: linetype and color for mesh lines s2: type and color for node markers

LAST MODIFIED: Ola Dahlblom 2004-09-15 Copyright (c) Division of Structural Mechanics and

Division of Solid Mechanics. Lund University

calfem.vis_mpl.scalfact2(ex, ey, ed, rat=0.2)[sfac]=scalfact2(ex,ey,ed,rat) [sfac]=scalfact2(ex,ey,ed) ————————————————————-PURPOSE Determine scale factor for drawing computational results, such as displacements, section forces orflux.

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

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.show()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()Wait for plot to show

calfem.vis_mpl.show_and_wait_mpl()Wait for plot to show

calfem.vis_mpl.subplot(*args)Create a visvis subplot.

calfem.vis_mpl.title(*args, **kwargs)Define title of figure (Matplotlib passthrough)

calfem.vis_mpl.topo_to_tri(edof )Converts 2d element topology to triangle topology to be used with the matplotlib functions tricontour and trip-color.

88 Chapter 1. Contents:

Page 93: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

1.15.7 Visualisation functions (VisVis)

CALFEM Visualisation module (visvis)

Contains all the functions implementing visualisation routines.

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 - Tuplewith 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 textcolor.

Default ‘k’ (black).

bgcolor - Background color. See color. Default None. axes - Axes wherein the label is placed. If None then thecurrent 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 textcolor.

Default ‘k’ (black).

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

chosen.

calfem.vis.add_label(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 - Tuplewith 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 textcolor.

Default ‘k’ (black).

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

chosen.

calfem.vis.add_text(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.

1.15. Function reference 89

Page 94: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

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

Default ‘k’ (black).

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

chosen.

calfem.vis.camera3d()Get visvis 3D camera.

calfem.vis.clf()Clear visvis figure

calfem.vis.closeAll()Close all visvis windows.

calfem.vis.close_all()Close all visvis windows.

calfem.vis.colorBar(axes=None)Short form of getColorbar

calfem.vis.color_bar(axes=None)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 thedisplaced Mesh object. Parameters: displacements-An N-by-1 array (or matrix). Row i contains the displacementof

dof i. N-by-2 or N-by-3 arrays are also accepted, in which case row i contains the x,y,z displacementsof 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 el-ement)

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

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 thevalue of node i.

clim - 2-tuple. Colorbar limits (min, max). Defines the value range of the colorbar. Defaults to None, inwhich 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. Magnificationfactor. Displacements are multiplied by

90 Chapter 1. Contents:

Page 95: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

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 el-ement)

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

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, inwhich 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 smalldisplacements 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 containsgeometric 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. Theformat is:

ID[marker]. If a point has marker==0 only the ID is written.

1.15. Function reference 91

Page 96: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

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 percurve 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 el-ement)

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

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 toblack (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 orfaces 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 perelement)

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

for triangles or 3 for quadrangles.

clim - 2-tuple. Colorbar limits (min, max). Defines the value range of the colorbar. Defaults to None, inwhich 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.

92 Chapter 1. Contents:

Page 97: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

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 thefigure. 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)

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

dof i. N-by-2 or N-by-3 arrays are also accepted, in which case row i contains the x,y,z displacementsof 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 el-ement)

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

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 thevalue of node i.

clim - 2-tuple. Colorbar limits (min, max). Defines the value range of the colorbar. Defaults to None, inwhich 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. Magnificationfactor. 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)

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 el-ement)

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

1.15. Function reference 93

Page 98: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

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, inwhich 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 smalldisplacements 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)

Draws the geometry (points and curves) in geoData Parameters: geoData - GeoData object. Geodata containsgeometric 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. Theformat 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 percurve 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)

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 el-ement)

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

for triangles or 3 for quadrangles.

94 Chapter 1. Contents:

Page 99: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

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 toblack (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 orfaces 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)

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 perelement)

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

for triangles or 3 for quadrangles.

clim - 2-tuple. Colorbar limits (min, max). Defines the value range of the colorbar. Defaults to None, inwhich 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 thefigure. Default “Node Values”.

calfem.vis.eldraw2(ex, ey, plotpar, elnum)calfem.vis.eldraw2(ex, ey, plotpar)→ Nonecalfem.vis.eldraw2(ex, ey)→ None

PURPOSE Draw the undeformed 2D mesh for a number of elements of the same type. Supported elementsare:

1) -> bar element 2) -> beam el. 3) -> triangular 3 node el. 4) -> quadrilateral 4 node el. 5) -> 8-nodeisopar. 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

1.15. Function reference 95

Page 100: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

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=[])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. Supportedelements 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 -> ma-genta

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)Draw elements in 2d.

Parameters:

ex, ey Element coordinates plotpar (not implemented yet)

calfem.vis.eliso2_old(ex, ey, ed, showMesh=False)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)Draw elements values in 2d.

Parameters:

ex, ey Element coordinates ev Element values (scalar) plotpar (not implemented yet)

calfem.vis.error(msg)Log error message

calfem.vis.figure(figure=None, show=True)Create a visvis figure with extras.

calfem.vis.figureClass()Return visvis Figure class.

calfem.vis.figure_class()Return visvis Figure class.

96 Chapter 1. Contents:

Page 101: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

calfem.vis.gca()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 inthe axes the first found will be returned If no colorbar is found None is returned.

calfem.vis.get_color_bar(axes=None)Returns the Colorbar. If axes is None the colorbar in the current axes will be found. If several colorbars exists inthe axes the first found will be returned If no colorbar is found None is returned.

calfem.vis.info(msg)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()Show visvis windows and enter application loop.

calfem.vis.show_grid(flag=True)Show grid.

calfem.vis.subplot(*args)Create a visvis subplot.

1.15.8 Interactive Geometry Editor

CALFEM Editor Module

Contains functions for implementing a interactive geometry editor.

Written by Karl Eriksson

class calfem.editor.EditorWindowMainWindow-klass som hanterar vårt huvudfönster

closeEvent(self, QCloseEvent)

keyPressEvent(self, QKeyEvent)

keyReleaseEvent(self, QKeyEvent)

on_action_arrow()De-selects all other toolButtons and sets the current mode Arrow (normal mode, mouse acting as pointer)

on_action_delete()De-selects all other toolButtons and sets the current mode to drawing polygon

on_action_poly()De-selects all other toolButtons and sets the current mode to drawing polygon

on_action_poly_hole()De-selects all other toolButtons and sets the current mode to drawing polygon hole

on_action_rect()De-selects all other toolButtons and sets the current mode to drawing rectangle

on_action_rect_hole()De-selects all other toolButtons and sets the current mode to drawing rectangle hole

1.15. Function reference 97

Page 102: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

on_action_set_marker()De-selects all other toolButtons and sets the current mode to set marker

on_action_split()De-selects all other toolButtons and sets the current mode to split line

on_action_tab()Action performed when clicking one of the tabs in the tab bar, index of tab clicked determines action

toggle_text_browser()Toggle the text browser to be expanded or collapsed

calfem.editor.edit_geometry(g: Optional[calfem.geometry.Geometry] = None)Start interactive geometry editor

Parameters cfg.Geometry (g) – Geometry to modify interactively ()

Return cfg.Geometry new_g, line_marker_dict Modfied geometry and marker dictionary.

1.16 Indices and tables

• genindex

• modindex

• search

98 Chapter 1. Contents:

Page 103: CALFEM for Python Documentation

PYTHON MODULE INDEX

ccalfem.core, 53calfem.editor, 97calfem.geometry, 67calfem.mesh, 76calfem.ui, 78calfem.utils, 78calfem.vis, 89calfem.vis_mpl, 82

99

Page 104: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

100 Python Module Index

Page 105: CALFEM for Python Documentation

INDEX

Aadd_label() (in module calfem.vis), 89add_text() (in module calfem.vis), 89addBSpline() (calfem.geometry.Geometry method), 67addCircle() (calfem.geometry.Geometry method), 67addEllipse() (calfem.geometry.Geometry method), 68addLabel() (in module calfem.vis), 89addPoint() (calfem.geometry.Geometry method), 68addPoints() (calfem.geometry.Geometry method), 69addRuledSurface() (calfem.geometry.Geometry

method), 69addSpline() (calfem.geometry.Geometry method), 69addSplines() (calfem.geometry.Geometry method), 69addStructuredSurface() (calfem.geometry.Geometry

method), 69addStructuredVolume() (calfem.geometry.Geometry

method), 70addSurface() (calfem.geometry.Geometry method), 70addText() (in module calfem.vis), 89addVolume() (calfem.geometry.Geometry method), 70app_instance() (in module calfem.ui), 78appInstance() (in module calfem.ui), 78apply_bc() (in module calfem.utils), 78apply_bc_3d() (in module calfem.utils), 78apply_force() (in module calfem.utils), 79apply_force_3d() (in module calfem.utils), 79apply_force_total() (in module calfem.utils), 79apply_force_total_3d() (in module calfem.utils), 79apply_traction_linear_element() (in module

calfem.utils), 79applybc() (in module calfem.utils), 80applybc3D() (in module calfem.utils), 80applyforce() (in module calfem.utils), 80applyforce3D() (in module calfem.utils), 80applyforcetotal() (in module calfem.utils), 81applyforcetotal3D() (in module calfem.utils), 81applyTractionLinearElement() (in module

calfem.utils), 78assem() (in module calfem.core), 53axis() (in module calfem.vis_mpl), 82

Bbar1e() (in module calfem.core), 54bar1s() (in module calfem.core), 54bar2e() (in module calfem.core), 54bar2g() (in module calfem.core), 54bar2s() (in module calfem.core), 54bar3e() (in module calfem.core), 54bar3s() (in module calfem.core), 55beam2crd() (in module calfem.core), 55beam2crd_old() (in module calfem.core), 55beam2d() (in module calfem.core), 55beam2e() (in module calfem.core), 56beam2g() (in module calfem.core), 56beam2gs() (in module calfem.core), 56beam2s() (in module calfem.core), 56beam2t() (in module calfem.core), 57beam2ts() (in module calfem.core), 57beam2w() (in module calfem.core), 57beam2ws() (in module calfem.core), 58beam3e() (in module calfem.core), 58beam3s() (in module calfem.core), 58bounding_box_2d() (calfem.geometry.Geometry

method), 70bspline() (calfem.geometry.Geometry method), 70

Ccalfem.core

module, 53calfem.editor

module, 97calfem.geometry

module, 67calfem.mesh

module, 76calfem.ui

module, 78calfem.utils

module, 78calfem.vis

module, 89calfem.vis_mpl

module, 82

101

Page 106: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

camera3d() (in module calfem.vis), 90camera3d() (in module calfem.vis_mpl), 82ce2vf() (in module calfem.vis_mpl), 82circle() (calfem.geometry.Geometry method), 71clf() (in module calfem.vis), 90clf() (in module calfem.vis_mpl), 82close_all() (in module calfem.vis), 90close_all() (in module calfem.vis_mpl), 82closeAll() (in module calfem.vis), 90closeAll() (in module calfem.vis_mpl), 82closeEvent() (calfem.editor.EditorWindow method), 97color_bar() (in module calfem.vis), 90colorBar() (in module calfem.vis), 90colorbar() (in module calfem.vis_mpl), 82coord_extract() (in module calfem.core), 59coordxtr() (in module calfem.core), 59create() (calfem.mesh.GmshMeshGenerator method),

76create_dofs() (in module calfem.core), 59create_ordered_polys() (in module calfem.vis_mpl),

82createdofs() (in module calfem.core), 59

Ddraw_displacements() (in module calfem.vis), 93draw_displacements() (in module calfem.vis_mpl), 83draw_element_values() (in module calfem.vis), 93draw_element_values() (in module calfem.vis_mpl),

83draw_elements() (in module calfem.vis_mpl), 84draw_geometry() (in module calfem.vis), 94draw_geometry() (in module calfem.vis_mpl), 84draw_mesh() (in module calfem.vis), 94draw_mesh() (in module calfem.vis_mpl), 85draw_nodal_values() (in module calfem.vis), 95draw_nodal_values() (in module calfem.vis_mpl), 85draw_nodal_values_contour() (in module

calfem.vis_mpl), 85draw_nodal_values_contourf() (in module

calfem.vis_mpl), 85draw_nodal_values_shaded() (in module

calfem.vis_mpl), 85draw_node_circles() (in module calfem.vis_mpl), 86drawDisplacements() (in module calfem.vis), 90drawElementValues() (in module calfem.vis), 91drawGeometry() (in module calfem.vis), 91drawMesh() (in module calfem.vis), 92drawMesh() (in module calfem.vis_mpl), 83drawNodalValues() (in module calfem.vis), 92

Eedit_geometry() (in module calfem.editor), 98EditorWindow (class in calfem.editor), 97effmises() (in module calfem.core), 59

eldisp2() (in module calfem.vis_mpl), 86eldraw2() (in module calfem.vis), 95eldraw2() (in module calfem.vis_mpl), 87eldraw2_mpl() (in module calfem.vis), 96eldraw2_old() (in module calfem.vis), 96eliso2_old() (in module calfem.vis), 96ellipse() (calfem.geometry.Geometry method), 71elval2() (in module calfem.vis), 96error() (in module calfem.core), 60error() (in module calfem.mesh), 77error() (in module calfem.vis), 96error() (in module calfem.vis_mpl), 87exception_logging() (in module calfem.core), 60export_vtk_stress() (in module calfem.utils), 81extract_ed() (in module calfem.core), 60extract_eldisp() (in module calfem.core), 60extractEldisp() (in module calfem.core), 60

Ffigure() (in module calfem.vis), 96figure() (in module calfem.vis_mpl), 87figure_class() (in module calfem.vis), 96figure_class() (in module calfem.vis_mpl), 87figureClass() (in module calfem.vis), 96figureClass() (in module calfem.vis_mpl), 87flw2i4e() (in module calfem.core), 60flw2i4s() (in module calfem.core), 60flw2i8e() (in module calfem.core), 61flw2i8s() (in module calfem.core), 61flw2qe() (in module calfem.core), 61flw2qs() (in module calfem.core), 62flw2te() (in module calfem.core), 62flw2ts() (in module calfem.core), 62flw3i8e() (in module calfem.core), 62flw3i8s() (in module calfem.core), 63

Ggca() (in module calfem.vis), 96gca() (in module calfem.vis_mpl), 87Geometry (class in calfem.geometry), 67get_color_bar() (in module calfem.vis), 97get_point_coords() (calfem.geometry.Geometry

method), 72getColorbar() (in module calfem.vis), 97getPointCoords() (calfem.geometry.Geometry

method), 72GmshMesh (in module calfem.mesh), 76GmshMeshGenerator (class in calfem.mesh), 76

Hhooke() (in module calfem.core), 63

Iinfo() (in module calfem.core), 63

102 Index

Page 107: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

info() (in module calfem.mesh), 77info() (in module calfem.vis), 97info() (in module calfem.vis_mpl), 87

KkeyPressEvent() (calfem.editor.EditorWindow

method), 97keyReleaseEvent() (calfem.editor.EditorWindow

method), 97

Lline() (calfem.geometry.Geometry method), 72load_arrays() (in module calfem.utils), 81load_geometry() (in module calfem.utils), 81load_mesh() (in module calfem.utils), 81load_ui_widget() (in module calfem.ui), 78loadUiWidget() (in module calfem.ui), 78

Mmodule

calfem.core, 53calfem.editor, 97calfem.geometry, 67calfem.mesh, 76calfem.ui, 78calfem.utils, 78calfem.vis, 89calfem.vis_mpl, 82

Oon_action_arrow() (calfem.editor.EditorWindow

method), 97on_action_delete() (calfem.editor.EditorWindow

method), 97on_action_poly() (calfem.editor.EditorWindow

method), 97on_action_poly_hole() (calfem.editor.EditorWindow

method), 97on_action_rect() (calfem.editor.EditorWindow

method), 97on_action_rect_hole() (calfem.editor.EditorWindow

method), 97on_action_set_marker()

(calfem.editor.EditorWindow method), 97on_action_split() (calfem.editor.EditorWindow

method), 98on_action_tab() (calfem.editor.EditorWindow

method), 98

Pplani4e() (in module calfem.core), 63planqe() (in module calfem.core), 63planqs() (in module calfem.core), 64

plante() (in module calfem.core), 64plantf() (in module calfem.core), 64plants() (in module calfem.core), 64platre() (in module calfem.core), 64pltstyle() (in module calfem.vis_mpl), 87pltstyle2() (in module calfem.vis_mpl), 88point() (calfem.geometry.Geometry method), 72pointsOnCurves() (calfem.geometry.Geometry

method), 73

Rread_float() (in module calfem.utils), 81read_int() (in module calfem.utils), 81read_single_float() (in module calfem.utils), 82read_single_int() (in module calfem.utils), 82readFloat() (in module calfem.utils), 81readInt() (in module calfem.utils), 81readSingleFloat() (in module calfem.utils), 81readSingleInt() (in module calfem.utils), 81removeCurve() (calfem.geometry.Geometry method),

73removePoint() (calfem.geometry.Geometry method),

73removeSurface() (calfem.geometry.Geometry method),

73removeVolume() (calfem.geometry.Geometry method),

73ruled_surf() (calfem.geometry.Geometry method), 73ruled_surface() (calfem.geometry.Geometry method),

73ruledSurface() (calfem.geometry.Geometry method),

73

Ssave_arrays() (in module calfem.utils), 82save_geometry() (in module calfem.utils), 82save_matlab_arrays() (in module calfem.utils), 82save_mesh() (in module calfem.utils), 82scalfact2() (in module calfem.utils), 82scalfact2() (in module calfem.vis_mpl), 88setCurveMarker() (calfem.geometry.Geometry

method), 74setPointMarker() (calfem.geometry.Geometry

method), 74setSurfaceMarker() (calfem.geometry.Geometry

method), 74setVolumeMarker() (calfem.geometry.Geometry

method), 74show() (in module calfem.vis_mpl), 88show_and_wait() (in module calfem.vis), 97show_and_wait() (in module calfem.vis_mpl), 88show_and_wait_mpl() (in module calfem.vis_mpl), 88show_grid() (in module calfem.vis), 97showAndWait() (in module calfem.vis), 97

Index 103

Page 108: CALFEM for Python Documentation

CALFEM for Python Documentation, Release 3.5.1

showAndWait() (in module calfem.vis_mpl), 88showAndWaitMpl() (in module calfem.vis_mpl), 88showGrid() (in module calfem.vis), 97soli8e() (in module calfem.core), 65soli8s() (in module calfem.core), 65solveq() (in module calfem.core), 65spline() (calfem.geometry.Geometry method), 74spring1e() (in module calfem.core), 66spring1s() (in module calfem.core), 66spsolveq() (in module calfem.core), 66statcon() (in module calfem.core), 66stress2nodal() (in module calfem.core), 66struct_surf() (calfem.geometry.Geometry method),

74structured_surface() (calfem.geometry.Geometry

method), 75structured_volume() (calfem.geometry.Geometry

method), 75structuredSurface() (calfem.geometry.Geometry

method), 74structuredVolume() (calfem.geometry.Geometry

method), 75stuffOnSurfaces() (calfem.geometry.Geometry

method), 75stuffOnVolumes() (calfem.geometry.Geometry

method), 75subplot() (in module calfem.vis), 97subplot() (in module calfem.vis_mpl), 88surf() (calfem.geometry.Geometry method), 75surface() (calfem.geometry.Geometry method), 75

Ttitle() (in module calfem.vis_mpl), 88toggle_text_browser() (calfem.editor.EditorWindow

method), 98topo_to_tri() (in module calfem.vis_mpl), 88trimesh2d() (in module calfem.mesh), 77

Vvolume() (calfem.geometry.Geometry method), 76

Wwhich() (in module calfem.utils), 82

104 Index