Professional Documents
Culture Documents
Calfem For Python Readthedocs Io en Latest
Calfem For Python Readthedocs Io en Latest
Release 3.5.1
Jonas Lindemann
1 Contents: 1
Index 93
i
ii
CHAPTER
ONE
CONTENTS:
The simplest way to install CALFEM for Python is via pip. This procedure will ensure that all required dependencies
are fulfilled.
This can be achieved by executing the following command:
or:
to install system-wide (not recommended if your system used a lot of python dependencies):
to install just for your own user. You can use the argument –user which is same as -u. If you want to specify your
Python version, use the command like the following:
where python3.6 is the Python version you want to install CALFEM for Python. Change this command with your
preferable version. This last command is the preferred one according to the Python community.
CALFEM is an interactive computer program for teaching the finite element method (FEM). The name CALFEM is
an abbreviation of “Computer Aided Learning of the Finite Element Method”. The program can be used for different
types of structural mechanics problems and field problems.
CALFEM, the program and its built-in philosophy, have been developed at the Division of Structural Mechanics, Lund
University, starting in the late 70’s. Many coworkers, former and present, have been engaged in the development at
different stages.
1
CALFEM for Python Documentation, Release 3.5.1
• 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 nodal
displacements given loading forces and stiffness matrix. The example can be found in examples directories both on
calfem-python root directory (for .py files) and docs directory (for .ipynb files).
2 Chapter 1. Contents:
CALFEM for Python Documentation, Release 3.5.1
import numpy as np
import calfem.core as cfc
The computation is initialized by defining the topology matrix Edof, containing element numbers and global element
degrees of freedom. All input to CALFEM is NumPy arrays. Topology is defined by index 1, i.e., the first row represents
the first element bounded by node 1 and node 2. Hence we write
Edof = np.array([
[1,2], # element 1 between node 1 and 2
[2,3], # element 2 between node 2 and 3
[2,3] # element 3 between node 2 and 3
])
the initial global stiffness matrix K (3x3) and load force f containing zeros,
K = np.zeros((3,3))
f = np.zeros((3,1))
Element stiffness matrices are generated by the function spring1e. The element property ep for the springs contains the
spring stiffnesses k and 2k respectively, where k = 1500.
# Assemble Ke into K
cfc.assem(Edof[0,:], K, Ke2)
cfc.assem(Edof[1,:], K, Ke1)
cfc.assem(Edof[2,:], K, Ke2)
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).
f[1]=100
The element stiffness matrices are assembled into the global stiffness matrix K according to the topology. bc is an array
of prescribed degrees of freedom. Values to be specified are specified in a separate array. If all values are 0, they don’t
have to be specified. The global system of equations is solved considering the boundary conditions given in bc.
bc = np.array([1,3])
a, r = cfc.solveq(K, f, bc)
print("Displacements a:")
print(a)
output:
Displacements a:
[[0. ]
[0.01333333]
[0. ]]
(continues on next page)
4 Chapter 1. Contents:
CALFEM for Python Documentation, Release 3.5.1
Element forces are evaluated from the element displacements. These are obtained from the global displacements a
using the function extract.
ed1 = cfc.extractEldisp(Edof[0,:],a)
ed2 = cfc.extractEldisp(Edof[1,:],a)
ed3 = cfc.extractEldisp(Edof[2,:],a)
The spring element forces at each element are evaluated using the function spring1s.
print("N1 = "+str(es1))
print("N2 = "+str(es2))
print("N3 = "+str(es3))
Output:
Element forces N:
N1 = 40.0
N2 = -20.0
N3 = -40.0
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:
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 global
stiffness matrix.
The system of equations is solved using solveq with considerations to the boundary conditions in bc and bcVal. The
prescribed temperatures are 𝑇1 = 17 ∘ 𝐶 and 𝑇2 = 20 ∘ 𝐶.
Necessary modules are first imported.
[3]: K = np.mat(np.zeros((6,6)))
f = np.mat(np.zeros((6,1)))
f[3] = 10.0
6 Chapter 1. Contents:
CALFEM for Python Documentation, Release 3.5.1
Define element properties (ep) and create element matrices for the different material layers.
[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)
8 Chapter 1. Contents:
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.0e11
A1 = 6.0e-4
A2 = 3.0e-4
A3 = 10.0e-4
ep1 = [E,A1]
ep2 = [E,A2]
ep3 = [E,A3]
Element coordinates
Assemble Ke into K
Based on the topology information, the global stiffness matrix can be generated by assembling the element stiffness
matrices
[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]])
[9]: bc = np.array([1,2,3,4,7,8])
f[5] = -80e3
a, r = cfc.solveq(K,f,bc)
print("Displacements a:")
print(a)
10 Chapter 1. Contents:
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 element
displacements ed1, ed2 and ed3 obtained using extract
The corresponding finite element model consists of ten elements and twelve degrees of freedom.
A global stiffness matrix K and a load vector f are defined. The load P is divided into x and y components and inserted
in 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 stiffness
matrix using the function assem.
12 Chapter 1. Contents:
CALFEM for Python Documentation, Release 3.5.1
[4]: A = 25.0e-4
E = 2.1e11
ep = [E,A]
[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.
The displacements in a and the support forces in r are computed by solving the system of equations considering the
boundary 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)
The displacement at the point of loading is 1.7103 𝑚 in the x-direction and 11.3103 𝑚 in the y-direction. At the upper
support 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 the
global 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 = 0
for 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 = 625938
N2 = -423100
N3 = 170640
N4 = -12372.8
N5 = -69447
N6 = 170640
(continues on next page)
14 Chapter 1. Contents:
CALFEM for Python Documentation, Release 3.5.1
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 a
global 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]
])
[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)
The frame with its coordinates and loading is shown in the left figure, and the finite element model in the right. The
matrices of the global system i.e. the stiffness matrix K, the load vector f, the coordinate matrix Coord, and the
corresponding 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:
CALFEM for Python Documentation, Release 3.5.1
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
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]
])
edof2 = np.array([
[1, 2, 10, 11],
[7, 8, 16, 17],
[7, 8, 4, 5],
[13, 14, 10, 11]
])
(continues on next page)
[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]]
Included in the Python version of CALFEM is a mesh generation library based on GMSH. The library encapsulates
the usage of GMSH transparently for the user. It will also parse the output from GMSH and create the necessary data
structures 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:
CALFEM for Python Documentation, Release 3.5.1
To use the CALFEM geometry and mesh generation routines, we use the following import directives:
Geometry in CALFEM is described using the Geometry class. A Geometry-object will hold all points, lines and
surfaces describing the geometry. This object is also what is passed to the mesh generation routines in the following
sections.
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 be
used to define lines, splines or ellipses. In this example we define a simple triangle:
The points are connected together with spline-elements. These can have 2 or three nodes. In this case we only use 2
node splines (lines):
Finally we create the surface by defining what lines make up the surface:
g.surface([0, 1, 2])
cfv.drawGeometry(g)
cfv.showAndWait()
Running this example will show the following window with a simple rectangle:
To create a mesh we need to create a GmshMesh object and initialize this with our geometry:
mesh = cfm.GmshMesh(g)
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 of
the 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:
CALFEM for Python Documentation, Release 3.5.1
cfv.figure()
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:
Changing the elType property to 2 (mesh.elType = 2) will produce a mesh with triangle elements instead:
22 Chapter 1. Contents:
CALFEM for Python Documentation, Release 3.5.1
To assist in assigning boundary conditions, markers can be defined on the geometry, which can be used to identify
which 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 the
Geometry object as shown in the following code:
It is also possible to assign markers to points. The marker parameter is added to the .point() method of the Geometry
object.
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 key
20 with a single dof 2 in this case. If the dofsPerNode property in the mesh generator was set to 2 the marker 20 would
have contained 2 integers.
To illustrate the workflow of the mesh generation modules we implement a complete 2D plane stress solver.
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 numpy as np
To make it easier to update our example we define a number of variables describing our problem. First some geometric
parameters describing our module, in this case a simple rectangular beam:
l = 5.0 # length
h = 1.0 # height
t = 0.2 # thickness
Next, we define our material properties we will need later in the code:
v = 0.35 # Poisson
E = 2.1e9 # Young modulus
ptype = 1 # plane stress
ep = [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 = 10
right_support = 20
top_line = 30
24 Chapter 1. Contents:
CALFEM for Python Documentation, Release 3.5.1
g = cfg.Geometry()
g.surface([0, 1, 2, 3])
cfv.draw_geometry(g)
cfv.showAndWait()
A quadrilateral mesh is now created with the following code. Please not that we use the dofsPerNode property to specify
2 dofs per node as this is a mechanical example.
mesh = cfm.GmshMesh(g)
cfv.figure()
cfv.drawMesh(
coords=coords,
edof=edof,
dofs_per_node=mesh.dofsPerNode,
el_type=mesh.elType,
filled=True)
cfv.showAndWait()
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)
K = np.zeros([nDofs,nDofs])
26 Chapter 1. Contents:
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, elx
and ely. The loop then becomes:
Please not the difference from standard MATLAB CALFEM that the assem routine does not require returning the K
matrix 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 and
and 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 dictionary
as input and applies the boundary condition to the correct dofs. Here we prescribe the left support as fixed and the right
support fixed in y-direction.
Now, we have some data structures that can be used by CALFEM. If there is no force and displacement, nothing
happens. If we applied force f and calculate the displacement, then we can solve the equation to obtain more data to
plot. These next steps are left in the next examples.
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.
D = np.matrix([
[kx1, 0.],
[0., ky1]
])
Define 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 = 50
id_hole2 = 60
id_outer = 80
Generate mesh
mesh.el_type = 16
mesh.dofs_per_node = 1 # Degrees of freedom per node.
mesh.el_size_factor = 0.05 # Factor that changes element sizes.
Solve problem
*Assemble system matrix*
28 Chapter 1. Contents:
CALFEM for Python Documentation, Release 3.5.1
K = np.zeros([n_dofs, n_dofs])
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)
bc = np.array([], 'i')
bc_val = np.array([], 'f')
[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)
Mesh
30 Chapter 1. Contents:
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>
[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:
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>
[ ]:
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 how
to specify element density.
34 Chapter 1. Contents:
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.
elSize is 1 by default. Larger number means less dense mesh. Size means the length of the sides of the elements.
Add curves
The 3 points that define the circle arc are [start, center, end]. The arc must be smaller than Pi.
BSplines are similar to Splines, but do not necessarily pass through the control points.
Add surfaces
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:
Generate mesh
Create a mesh object and set its attributes.
mesh.el_type = 3
mesh.dofs_per_node = 2
mesh.el_size_factor = 0.05
Create the finite element mesh using the create() method of the mesh object.
Visualise mesh
*Draw geometry*
[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:
CALFEM for Python Documentation, Release 3.5.1
Define geometry
[4]: g = cfg.Geometry()
Define points
[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 optional
parameters 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 smaller
than 1, so elements crowd at the edges.
• “progression” means each element along the curve is larger/smaller than the previous one. A larger elDistribVal
makes the elements larger at the end of the curves.
Add surfaces
A structured surface must contain 4 curves that have the parameter ‘elOnCurve’ defined. The number of elements on
two 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
mesh.el_type = 3 # quad
mesh.dofs_per_node = 1
mesh.el_size_factor = 0.01
Visualise mesh
*Draw geometry*
[11]: cfv.figure(fig_size=(10,10))
cfv.draw_geometry(g)
38 Chapter 1. Contents:
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)
[19]: t = 0.2
v = 0.35
E = 2.1e9
ptype = 1
ep = [ptype,t]
D = cfc.hooke(ptype, E, v)
Define geometry
40 Chapter 1. Contents:
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)
[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 s in splines:
g.spline(s, el_on_curve=10)
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)
[26]: g.struct_surf([11,12,13,0]) #0
g.struct_surf([14, 12, 10, 9])
g.struct_surf([8, 30, 24, 14])
g.struct_surf([24, 31, 17, 15])
(continues on next page)
Create mesh
mesh.el_type = 3
mesh.dofs_per_node = 2
Solve problem
*Assemble system matrix*
[29]: f = np.zeros([nDofs,1])
bc = np.array([],'i')
bcVal = np.array([],'f')
cfu.applyforce(bdofs, f, 7, 10e5, 1)
a,r = cfc.solveq(K,f,bc,bcVal)
[30]: ed = cfc.extract_eldisp(edof,a)
vonMises = []
42 Chapter 1. Contents:
CALFEM for Python Documentation, Release 3.5.1
Visualise results
[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)
[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:
CALFEM for Python Documentation, Release 3.5.1
The use case from the user manual. The example does not contain anything that is not covered in the previous examples.
Problem parameters
[3]: t = 0.2
v = 0.35
E1 = 2e9
E2 = 0.2e9
ptype = 1
ep = [ptype,t]
D1 = cfc.hooke(ptype, E1, v)
D2 = cfc.hooke(ptype, E2, v)
mark_E1 = 55
mark_E2 = 66
mark_fixed = 70
mark_load = 90
elprop = {}
elprop[mark_E1] = [ep, D1]
elprop[mark_E2] = [ep, D2]
Create geometry
[4]: g = cfg.Geometry()
Add points
Add curves
Add surfaces
Create mesh
Solve problem
*Assemble system*
if el_type == 2:
Ke = cfc.plante(elx, ely, elprop[elMarker][0], elprop[elMarker][1])
else:
(continues on next page)
46 Chapter 1. Contents:
CALFEM for Python Documentation, Release 3.5.1
cfc.assem(eltopo, K, Ke)
[10]: bc = np.array([],'i')
bcVal = np.array([],'i')
f = np.zeros([nDofs,1])
[11]: ed = cfc.extractEldisp(edof, a)
von_mises = []
for i in range(edof.shape[0]):
if el_type == 2:
es, et = cfc.plants(ex[i,:], ey[i,:],
elprop[elementmarkers[i]][0],
elprop[elementmarkers[i]][1],
ed[i,:])
else:
Visualise results
*Geometry*
[12]: cfv.figure(fig_size=(10,10))
cfv.draw_geometry(g, title="Geometry")
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:
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)
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:
CALFEM for Python Documentation, Release 3.5.1
[ ]:
edof dof topology array K the global stiffness matrix Ke element stiffness matrix f the global force
vector fe element force vector
Output parameters:
K the new global stiffness matrix f the new global force vector fe element force vector
calfem.core.bar1e(ep)
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]
52 Chapter 1. Contents:
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)
54 Chapter 1. Contents:
CALFEM for Python Documentation, Release 3.5.1
56 Chapter 1. Contents:
CALFEM for Python Documentation, Release 3.5.1
eci = [[x1], local x-coordinates of the evaluation [x2], points [..], [xn]]
calfem.core.coordxtr(edof, coords, dofs)
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.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
Returns:
eseff = [eseff_0 .. eseff_nel-1]
calfem.core.error(msg)
Write msg to error log.
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_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
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)]
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)]]
58 Chapter 1. Contents:
CALFEM for Python Documentation, Release 3.5.1
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
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
60 Chapter 1. Contents:
CALFEM for Python Documentation, Release 3.5.1
et = [ epsx epsy [epsz] gamxy element strain matrix . . . . . . ] one row for each element
62 Chapter 1. Contents:
CALFEM for Python Documentation, Release 3.5.1
el_distrib_type - String. Either “bump” or “progression”. Determines how the density of elements vary
along the curve for structured meshes. Only works for structured meshes. elOnCurv and el_distrib_val
must be be defined if this param is used.
el_distrib_val - Float. Determines how severe the element distribution is. Only works for structured
meshes. elOnCurv and el_distrib_type must be be defined if this param is used.
bump:
Smaller value means elements are bunched up at the edges of the curve, larger means bunched in the
middle.
progression:
The edge of each element along this curve (from starting point to end) will be larger than the preceding
one by this factor. el_distrib_val = 2 meaning for example that each line element in the series will be
twice as long as the preceding one. el_distrib_val < 1 makes each element smaller than the preceeding
one.
addCircle(points, ID=None, marker=0, el_on_curve=None, el_distrib_type=None, el_distrib_val=None)
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 unused
curve-ID. It is recommended to specify all curve-IDs or none.
marker - Marker applied to this curve. Default 0.
elOnCurv - Elements on curve. The number of element edges that will be distributed along this curve.
Only works for structured meshes.
el_distrib_type - String. Either “bump” or “progression”. Determines how the density of elements vary
along the curve for structured meshes. Only works for structured meshes. elOnCurv and el_distrib_val
must be be defined if this param is used.
el_distrib_val - Float. Determines how severe the element distribution is. Only works for structured
meshes. elOnCurv and el_distrib_type must be be defined if this param is used.
bump:
Smaller value means elements are bunched up at the edges of the curve, larger means bunched in the
middle.
progression:
The edge of each element along this curve (from starting point to end) will be larger than the preceding
one by this factor. el_distrib_val = 2 meaning for example that each line element in the series will be
twice as long as the preceding one. el_distrib_val < 1 makes each element smaller than the preceeding
one.
addEllipse(points, ID=None, marker=0, el_on_curve=None, el_distrib_type=None, el_distrib_val=None)
Adds a Ellipse arc curve.
points - List of 4 indices of point that make a ellipse arc smaller than Pi. [startpoint, centerpoint,
mAxisPoint, endpoint] Startpoint is the starting point of the arc. Centerpoint is the point at the center
of the ellipse. MAxisPoint is any point on the major axis of the ellipse. Endpoint is the end point of
the arc.
ID - Positive integer ID of this curve. If left unspecified the curve will be assigned the smallest unused
curve-ID. It is recommended to specify all curve-IDs or none.
marker - Integer. Marker applied to this curve. Default 0.
64 Chapter 1. Contents:
CALFEM for Python Documentation, Release 3.5.1
elOnCurv - Positive integer. Elements on curve. The number of element edges that will be distributed
along this curve. Only works for structured meshes.
el_distrib_type - String. Either “bump” or “progression”. Determines how the density of elements vary
along the curve for structured meshes. Only works for structured meshes. elOnCurv and el_distrib_val
must be be defined if this param is used.
el_distrib_val - Float. Determines how severe the element distribution is. Only works for structured
meshes. elOnCurv and el_distrib_type must be be defined if this param is used.
bump:
Smaller value means elements are bunched up at the edges of the curve, larger means bunched in the
middle.
progression:
The edge of each element along this curve (from starting point to end) will be larger than the preceding
one by this factor. el_distrib_val = 2 meaning for example that each line element in the series will be
twice as long as the preceding one. el_distrib_val < 1 makes each element smaller than the preceeding
one.
addPoint(coord, ID=None, marker=0, el_size=1)
Adds a point.
Parameters: coord - [x, y] or [x, y, z].
List, not array.
ID - Positive integer ID of this point. If left unspecified the point will be assigned the smallest unused
point-ID. It is recommended to specify all point-IDs or none.
marker - Marker applied to this point. Default 0. It is not a good idea to apply non-zero markers to
points that are control points on B-splines or center points on circles/ellipses, since this can lead to
“loose” nodes that are not part of any elements.
elSize - The size of elements at this point. Default 1. Use to make a mesh denser or sparser here. Only
affects unstructured meshes
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.
elOnCurv - Positive integer. Elements on curve. The number of element edges that will be distributed
along this curve. Only works for structured meshes.
el_distrib_type - String. Either “bump” or “progression”. Determines how the density of elements vary
along the curve for structured meshes. Only works for structured meshes. elOnCurv and el_distrib_val
must be be defined if this param is used.
el_distrib_val - Float. Determines how severe the element distribution is. Only works for structured
meshes. elOnCurv and el_distrib_type must be be defined if this param is used.
bump:
Smaller value means elements are bunched up at the edges of the curve, larger means bunched in the
middle.
progression:
The edge of each element along this curve (from starting point to end) will be larger than the preceding
one by this factor. el_distrib_val = 2 meaning for example that each line element in the series will be
twice as long as the preceding one. el_distrib_val < 1 makes each element smaller than the preceeding
one.
addSplines(points)
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.
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.
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.
holes - List of lists of curve IDs that make up the inner boundaries of the surface. The curves must lie
in the same plane.
ID - Positive integer ID of this surface. If left unspecified the surface will be assigned the smallest un-
used surface-ID. It is recommended to specify all surface-IDs or none.
66 Chapter 1. Contents:
CALFEM for Python Documentation, Release 3.5.1
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.
bump:
Smaller value means elements are bunched up at the edges of the curve, larger means bunched in the
middle.
progression:
The edge of each element along this curve (from starting point to end) will be larger than the preceding
one by this factor. el_distrib_val = 2 meaning for example that each line element in the series will be
twice as long as the preceding one. el_distrib_val < 1 makes each element smaller than the preceeding
one.
ellipse(points, ID=None, marker=0, el_on_curve=None, el_distrib_type=None, el_distrib_val=None)
Adds a Ellipse arc curve.
points - List of 4 indices of point that make a ellipse arc smaller than Pi. [startpoint, centerpoint,
mAxisPoint, endpoint] Startpoint is the starting point of the arc. Centerpoint is the point at the center
of the ellipse. MAxisPoint is any point on the major axis of the ellipse. Endpoint is the end point of
the arc.
ID - Positive integer ID of this curve. If left unspecified the curve will be assigned the smallest unused
curve-ID. It is recommended to specify all curve-IDs or none.
marker - Integer. Marker applied to this curve. Default 0.
elOnCurv - Positive integer. Elements on curve. The number of element edges that will be distributed
along this curve. Only works for structured meshes.
el_distrib_type - String. Either “bump” or “progression”. Determines how the density of elements vary
along the curve for structured meshes. Only works for structured meshes. elOnCurv and el_distrib_val
must be be defined if this param is used.
el_distrib_val - Float. Determines how severe the element distribution is. Only works for structured
meshes. elOnCurv and el_distrib_type must be be defined if this param is used.
bump:
Smaller value means elements are bunched up at the edges of the curve, larger means bunched in the
middle.
progression:
The edge of each element along this curve (from starting point to end) will be larger than the preceding
one by this factor. el_distrib_val = 2 meaning for example that each line element in the series will be
twice as long as the preceding one. el_distrib_val < 1 makes each element smaller than the preceeding
one.
getPointCoords(IDs=None)
Returns an N-by-3 list of point coordinates if the parameter is a list of IDs. If the parameter is just a single
integer then a single coordinate (simple 3-element list) is returned. If the parameter is undefined (or None)
all point coords will be returned
get_point_coords(IDs=None)
Returns an N-by-3 list of point coordinates if the parameter is a list of IDs. If the parameter is just a single
integer then a single coordinate (simple 3-element list) is returned. If the parameter is undefined (or None)
all point coords will be returned
line(points, ID=None, marker=0, el_on_curve=None, el_distrib_type=None, el_distrib_val=None)
Adds a Spline curve
points - List of indices of control points that make a Spline [p1, p2, . . . , pn]
68 Chapter 1. Contents:
CALFEM for Python Documentation, Release 3.5.1
ID - Positive integer ID of this curve. If left unspecified the curve will be assigned the smallest unused
curve-ID. It is recommended to specify all curve-IDs or none.
marker - Integer. Marker applied to this curve. Default 0.
elOnCurv - Positive integer. Elements on curve. The number of element edges that will be distributed
along this curve. Only works for structured meshes.
el_distrib_type - String. Either “bump” or “progression”. Determines how the density of elements vary
along the curve for structured meshes. Only works for structured meshes. elOnCurv and el_distrib_val
must be be defined if this param is used.
el_distrib_val - Float. Determines how severe the element distribution is. Only works for structured
meshes. elOnCurv and el_distrib_type must be be defined if this param is used.
bump:
Smaller value means elements are bunched up at the edges of the curve, larger means bunched in the
middle.
progression:
The edge of each element along this curve (from starting point to end) will be larger than the preceding
one by this factor. el_distrib_val = 2 meaning for example that each line element in the series will be
twice as long as the preceding one. el_distrib_val < 1 makes each element smaller than the preceeding
one.
point(coord, ID=None, marker=0, el_size=1)
Adds a point.
Parameters: coord - [x, y] or [x, y, z].
List, not array.
ID - Positive integer ID of this point. If left unspecified the point will be assigned the smallest unused
point-ID. It is recommended to specify all point-IDs or none.
marker - Marker applied to this point. Default 0. It is not a good idea to apply non-zero markers to
points that are control points on B-splines or center points on circles/ellipses, since this can lead to
“loose” nodes that are not part of any elements.
elSize - The size of elements at this point. Default 1. Use to make a mesh denser or sparser here. Only
affects unstructured meshes
pointsOnCurves(IDs)
Returns a list of all geometric points (not nodes) on the curves specified in IDs. IDs may be an integer or a
list of integers.
removeCurve(ID)
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 the
boundary 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.
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.
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.
70 Chapter 1. Contents:
CALFEM for Python Documentation, Release 3.5.1
Smaller value means elements are bunched up at the edges of the curve, larger means bunched in the
middle.
progression:
The edge of each element along this curve (from starting point to end) will be larger than the preceding
one by this factor. el_distrib_val = 2 meaning for example that each line element in the series will be
twice as long as the preceding one. el_distrib_val < 1 makes each element smaller than the preceeding
one.
struct_surf(outer_loop, ID=None, marker=0)
Adds a Structured Surface. Parameters: outer_loop - List of 4 curve IDs that make up the boundary of
the surface. The curves must be structured, i.e. their parameter ‘elOnCurv’ must be defined.
ID - Positive integer ID of this surface. If left unspecified the surface will be assigned the smallest un-
used surface-ID. It is recommended to specify all surface-IDs or none.
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.
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.
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.
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.
holes - List of lists of curve IDs that make up the inner boundaries of the surface. The curves must lie
in the same plane.
ID - Positive integer ID of this surface. If left unspecified the surface will be assigned the smallest un-
used surface-ID. It is recommended to specify all surface-IDs or none.
holes - List of lists of curve IDs that make up the inner boundaries of the surface. The curves must lie
in the same plane.
ID - Positive integer ID of this surface. If left unspecified the surface will be assigned the smallest un-
used surface-ID. It is recommended to specify all surface-IDs or none.
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.
72 Chapter 1. Contents:
CALFEM for Python Documentation, Release 3.5.1
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. Markers
are similar to boundary markers and can be used to identify in which region an element lies.
boundaryElements (optional) returned if self.return_boundary_elements is true. Contains
dictionary with boundary elements. The keys are markers and the values are lists of elements
for that marker.
bdofs Boundary dofs. Dictionary containing lists of dofs for each boundary marker. Dictionary
key = marker id.
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
74 Chapter 1. Contents:
CALFEM for Python Documentation, Release 3.5.1
Returns:
bcPresc Updated 1-dim integer array containing prescribed dofs. bcVal Updated 1-dim float array
containing prescribed values.
calfem.utils.applyforce(boundaryDofs, f, marker, value=0.0, dimension=0)
Apply boundary force to f matrix. The value is added to all boundaryDofs defined by marker. Applicable to 2D
problems with 2 dofs per node.
Parameters:
boundaryDofs Dictionary with boundary dofs. f force matrix. marker Boundary marker to assign
boundary condition. value Value to assign boundary condition.
If not given 0.0 is assigned.
dimension dimension to apply force. 0 - all, 1 - x, 2 - y
calfem.utils.applyforce3D(boundaryDofs, f, marker, value=0.0, dimension=0)
Apply boundary force to f matrix. The value is added to all boundaryDofs defined by marker. Applicable to 3D
problems with 3 dofs per node.
Parameters:
boundaryDofs Dictionary with boundary dofs. f force matrix. marker Boundary marker to assign
boundary condition. value Value to assign boundary condition.
If not given 0.0 is assigned.
76 Chapter 1. Contents:
CALFEM for Python Documentation, Release 3.5.1
coords: An N-by-2 or N-by-3 array. Row i contains the x,y,z coordinates of node i.
edof: An E-by-L array. Element topology. (E is the number of elements and L is the number of dofs per
element)
dofs_per_node: Integer. Dofs per node.
el_type: Integer. Element Type. See Gmsh manual for details. Usually 2 for triangles or 3 for quadrangles.
displacements: An N-by-2 or N-by-3 array. Row i contains the x,y,z displacements of node i.
axes: Matlotlib Axes. The Axes where the model will be drawn. If unspecified the current Axes will be
used, or a new Axes will be created if none exist.
draw_undisplaced_mesh: Boolean. True if the wire of the undisplaced mesh should be drawn on top of
the displaced mesh. Default False. Use only if displacements != None.
magnfac: Float. Magnification factor. Displacements are multiplied by this value. Use this to make small
displacements more visible.
title: String. Changes title of the figure. Default “Element Values”.
calfem.vis_mpl.draw_element_values(values, coords, edof, dofs_per_node, el_type, displacements=None,
draw_elements=True, draw_undisplaced_mesh=False, magnfac=1.0,
title=None, color=(0, 0, 0), node_color=(0, 0, 0))
Draws scalar element values in 2D or 3D.
Args:
ev: An N-by-1 array or a list of scalars. The Scalar values of the elements. ev[i] should be the value of
element i.
coords: An N-by-2 or N-by-3 array. Row i contains the x,y,z coordinates of node i.
edof: An E-by-L array. Element topology. (E is the number of elements and L is the number of dofs per
element)
dofs_per_node: Integer. Dofs per node.
el_type: Integer. Element Type. See Gmsh manual for details. Usually 2 for triangles or 3 for quadrangles.
displacements: An N-by-2 or N-by-3 array. Row i contains the x,y,z displacements of node i.
draw_mesh: Boolean. True if mesh wire should be drawn. Default True.
draw_undisplaced_mesh: Boolean. True if the wire of the undisplaced mesh should be drawn on top of
the displaced mesh. Default False. Use only if displacements != None.
magnfac: Float. Magnification factor. Displacements are multiplied by this value. Use this to make small
displacements more visible.
title: String. Changes title of the figure. Default “Element Values”.
calfem.vis_mpl.draw_geometry(geometry, draw_points=True, label_points=True, label_curves=True,
title=None, font_size=11, N=20, rel_margin=0.05, draw_axis=False)
Draws the geometry (points and curves) in geoData Args:
geoData: GeoData object. Geodata contains geometric information of the model.
axes: Matplotlib Axes. The Axes where the model will be drawn. If unspecified the current Axes
will be used, or a new Axes will be created if none exist.
axes_adjust: Boolean. If True the view will be changed to show the whole model. Default True.
draw_points: Boolean. If True points will be drawn.
78 Chapter 1. Contents:
CALFEM for Python Documentation, Release 3.5.1
label_points: Boolean. If True Points will be labeled. The format is: ID[marker]. If a point has
marker==0 only the ID is written.
label_curves: Boolean. If True Curves will be labeled. The format is:
ID(elementsOnCurve)[marker].
font_size: Integer. Size of the text in the text labels. Default 11.
N: Integer. The number of discrete points per curve segment. Default 20. Increase for smoother
curves. Decrease for better performance.
rel_margin: Extra spacing between geometry and axis
calfem.vis_mpl.draw_mesh(coords, edof, dofs_per_node, el_type, title=None, color=(0, 0, 0), face_color=(0.8,
0.8, 0.8), node_color=(0, 0, 0), filled=False, show_nodes=False)
Draws wire mesh of model in 2D or 3D. Returns the Mesh object that represents the mesh. Args:
coords: An N-by-2 or N-by-3 array. Row i contains the x,y,z coordinates of node i.
edof: An E-by-L array. Element topology. (E is the number of elements and L is the number of dofs
per element)
dofs_per_nodes: Integer. Dofs per node.
el_type: Integer. Element Type. See Gmsh manual for details. Usually 2 for triangles or 3 for
quadrangles.
axes: Matplotlib Axes. The Axes where the model will be drawn. If unspecified the current Axes
will be used, or a new Axes will be created if none exist.
axes_adjust: Boolean. True if the view should be changed to show the whole model. Default True.
title: String. Changes title of the figure. Default “Mesh”.
color: 3-tuple or char. Color of the wire. Defaults to black (0,0,0). Can also be given as a character
in ‘rgbycmkw’.
face_color: 3-tuple or char. Color of the faces. Defaults to white (1,1,1). Parameter filled must be
True or faces will not be drawn at all.
filled: Boolean. Faces will be drawn if True. Otherwise only the wire is drawn. Default False.
calfem.vis_mpl.draw_nodal_values(values, coords, edof, levels=12, title=None, dofs_per_node=None,
el_type=None, draw_elements=False)
Draws element nodal values as filled contours. Element topologies supported are triangles, 4-node quads and
8-node quads.
calfem.vis_mpl.draw_nodal_values_contour(values, coords, edof, levels=12, title=None,
dofs_per_node=None, el_type=None, draw_elements=False)
Draws element nodal values as filled contours. Element topologies supported are triangles, 4-node quads and
8-node quads.
calfem.vis_mpl.draw_nodal_values_contourf(values, coords, edof, levels=12, title=None,
dofs_per_node=None, el_type=None, draw_elements=False)
Draws element nodal values as filled contours. Element topologies supported are triangles, 4-node quads and
8-node quads.
calfem.vis_mpl.draw_nodal_values_shaded(values, coords, edof, title=None, dofs_per_node=None,
el_type=None, draw_elements=False)
Draws element nodal values as shaded triangles. Element topologies supported are triangles, 4-node quads and
8-node quads.
calfem.vis_mpl.eldraw2(ex, ey, plotpar, elnum)
calfem.vis_mpl.eldraw2(ex, ey, plotpar) → 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-node
isopar. elemen
INPUT
ex,ey:. . . . . . . . . . nen: number of element nodes nel: number of elements
plotpar=[ linetype, linecolor, nodemark]
linetype=1 -> solid linecolor=1 -> black 2 -> dashed 2 -> blue 3 -> dotted 3 -> magenta
4 -> red
nodemark=1 -> circle 2 -> star 0 -> no mark
elnum=edof(:,1) ; i.e. the first column in the topology matrix
Rem. Default is solid white lines with circles at nodes.
calfem.vis_mpl.error(msg)
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.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.topo_to_tri(edof )
Converts 2d element topology to triangle topology to be used with the matplotlib functions tricontour and trip-
color.
80 Chapter 1. Contents:
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 text
color.
Default ‘k’ (black).
bgcolor - Background color. See color. Default None. axes - Axes wherein the label is placed. If None then the
current axes is
chosen.
calfem.vis.camera3d()
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 the
displaced Mesh object. Parameters: displacements-An N-by-1 array (or matrix). Row i contains the displacement
of
dof i. N-by-2 or N-by-3 arrays are also accepted, in which case row i contains the x,y,z displacements
of node i.
coords - An N-by-2 or N-by-3 array. Row i contains the x,y,z coordinates of node i.
edof - An E-by-L array. Element topology. (E is the number of elements and L is the number of dofs per el-
ement)
dofs_per_node - Integer. Dofs per node. el_type - Integer. Element Type. See Gmsh manual for details. Usually
2
for triangles or 3 for quadrangles.
node_vals - An N-by-1 array or a list of scalars. The Scalar values at the nodes. node_vals[i] should be the
value of node i.
clim - 2-tuple. Colorbar limits (min, max). Defines the value range of the colorbar. Defaults to None, in
which case min/max are set to min/max of node_vals.
axes - Visvis Axes. The Axes where the model will be drawn. If unspecified the current Axes will be used,
or a new Axes will be created if none exist.
axes_adjust - Boolean. True if the view should be changed to show the whole model. Default True.
draw_elements - Boolean. True if mesh wire should be drawn. Default True. magnfac - Float. Magnification
factor. Displacements are multiplied by
82 Chapter 1. Contents:
CALFEM for Python Documentation, Release 3.5.1
title - String. Changes title of the figure. Default None (in which case title depends on other 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. Usually
2
for triangles or 3 for quadrangles.
displacements - An N-by-2 or N-by-3 array. Row i contains the x,y,z displacements of node i.
clim - 2-tuple. Colorbar limits (min, max). Defines the value range of the colorbar. Defaults to None, in
which case min/max are set to min/max of node_vals.
axes - Visvis Axes. The Axes where the model will be drawn. If unspecified the current Axes will be used,
or a new Axes will be created if none exist.
axes_adjust - Boolean. True if the view should be changed to show the whole model. Default True.
draw_elements - Boolean. True if mesh wire should be drawn. Default True. draw_undisplaced_mesh - Boolean.
True if the wire of the undisplaced mesh
should be drawn on top of the displaced mesh. Default False. Use only if displacements != None.
magnfac - Float. Magnification factor. Displacements are multiplied by this value. Use this to make small
displacements more visible.
axes - Visvis Axes. The Axes where the model will be drawn. If unspecified the current Axes will be used,
or a new Axes will be created if none exist.
axes_adjust - Boolean. If True the view will be changed to show the whole model. Default True.
draw_points - Boolean. If True points will be drawn. label_points- Boolean. If True Points will be labeled. The
format is:
ID[marker]. If a point has marker==0 only the ID is written.
label_curves- Boolean. If True Curves will be labeled. The format is: ID(elementsOnCurve)[marker].
font_size - Integer. Size of the text in the text labels. Default 11. N - Integer. The number of discrete points per
curve segment.
Default 20. Increase for smoother curves. Decrease for better performance.
calfem.vis.drawMesh(coords, edof, dofs_per_node, el_type, axes=None, axes_adjust=True, title=None,
color=(0, 0, 0), face_color=(1, 1, 1), filled=False)
Draws wire mesh of model in 2D or 3D. Returns the Mesh object that represents the mesh. Parameters: coords
- An N-by-2 or N-by-3 array. Row i contains the x,y,z coordinates
of node i.
edof - An E-by-L array. Element topology. (E is the number of elements and L is the number of dofs per el-
ement)
dofs_per_node - Integer. Dofs per node. el_type - Integer. Element Type. See Gmsh manual for details. Usually
2
for triangles or 3 for quadrangles.
axes - Visvis Axes. The Axes where the model will be drawn. If unspecified the current Axes will be used,
or a new Axes will be created if none exist.
axes_adjust - Boolean. True if the view should be changed to show the whole model. Default True.
title - String. Changes title of the figure. Default “Mesh”. color - 3-tuple or char. Color of the wire. Defaults to
black (0,0,0).
Can also be given as a character in ‘rgbycmkw’.
face_color - 3-tuple or char. Color of the faces. Defaults to white (1,1,1). Parameter filled must be True or
faces will not be drawn at all.
filled - Boolean. Faces will be drawn if True. Otherwise only the wire is drawn. Default False.
coords - An N-by-2 or N-by-3 array. Row i contains the x,y,z coordinates of node i.
edof - An E-by-L array. Element topology. (E is the number of elements and L is the number of dofs per
element)
dofs_per_node - Integer. Dofs per node. el_type - Integer. Element Type. See Gmsh manual for details. Usually
2
for triangles or 3 for quadrangles.
clim - 2-tuple. Colorbar limits (min, max). Defines the value range of the colorbar. Defaults to None, in
which case min/max are set to min/max of node_vals.
axes - Visvis Axes. The Axes where the model will be drawn. If unspecified the current Axes will be used,
or a new Axes will be created if none exist.
84 Chapter 1. Contents:
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 the
figure. Default “Node Values”.
calfem.vis.draw_displacements(displacements, coords, edof, dofs_per_node, el_type, node_vals=None,
clim=None, axes=None, axes_adjust=True, draw_undisplaced_mesh=True,
magnfac=1.0, title=None)
Draws mesh with displacements in 2D or 3D. Scalar nodal values can also be drawn on the mesh. Returns the
displaced Mesh object. Parameters: displacements-An N-by-1 array (or matrix). Row i contains the displacement
of
dof i. N-by-2 or N-by-3 arrays are also accepted, in which case row i contains the x,y,z displacements
of node i.
coords - An N-by-2 or N-by-3 array. Row i contains the x,y,z coordinates of node i.
edof - An E-by-L array. Element topology. (E is the number of elements and L is the number of dofs per el-
ement)
dofs_per_node - Integer. Dofs per node. el_type - Integer. Element Type. See Gmsh manual for details. Usually
2
for triangles or 3 for quadrangles.
node_vals - An N-by-1 array or a list of scalars. The Scalar values at the nodes. node_vals[i] should be the
value of node i.
clim - 2-tuple. Colorbar limits (min, max). Defines the value range of the colorbar. Defaults to None, in
which case min/max are set to min/max of node_vals.
axes - Visvis Axes. The Axes where the model will be drawn. If unspecified the current Axes will be used,
or a new Axes will be created if none exist.
axes_adjust - Boolean. True if the view should be changed to show the whole model. Default True.
draw_elements - Boolean. True if mesh wire should be drawn. Default True. magnfac - Float. Magnification
factor. Displacements are multiplied by
this value. Use this to make small displacements more visible.
title - String. Changes title of the figure. Default None (in which case title depends on other parameters).
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. Usually
2
displacements - An N-by-2 or N-by-3 array. Row i contains the x,y,z displacements of node i.
clim - 2-tuple. Colorbar limits (min, max). Defines the value range of the colorbar. Defaults to None, in
which case min/max are set to min/max of node_vals.
axes - Visvis Axes. The Axes where the model will be drawn. If unspecified the current Axes will be used,
or a new Axes will be created if none exist.
axes_adjust - Boolean. True if the view should be changed to show the whole model. Default True.
draw_elements - Boolean. True if mesh wire should be drawn. Default True. draw_undisplaced_mesh - Boolean.
True if the wire of the undisplaced mesh
should be drawn on top of the displaced mesh. Default False. Use only if displacements != None.
magnfac - Float. Magnification factor. Displacements are multiplied by this value. Use this to make small
displacements more visible.
axes - Visvis Axes. The Axes where the model will be drawn. If unspecified the current Axes will be used,
or a new Axes will be created if none exist.
axes_adjust - Boolean. If True the view will be changed to show the whole model. Default True.
draw_points - Boolean. If True points will be drawn. label_points- Boolean. If True Points will be labeled. The
format is:
ID[marker]. If a point has marker==0 only the ID is written.
label_curves- Boolean. If True Curves will be labeled. The format is: ID(elementsOnCurve)[marker].
font_size - Integer. Size of the text in the text labels. Default 11. N - Integer. The number of discrete points per
curve segment.
Default 20. Increase for smoother curves. Decrease for better performance.
calfem.vis.draw_mesh(coords, edof, dofs_per_node, el_type, axes=None, axes_adjust=True, title=None,
color=(0, 0, 0), face_color=(1, 1, 1), filled=False)
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. Usually
2
for triangles or 3 for quadrangles.
86 Chapter 1. Contents:
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 to
black (0,0,0).
Can also be given as a character in ‘rgbycmkw’.
face_color - 3-tuple or char. Color of the faces. Defaults to white (1,1,1). Parameter filled must be True or
faces will not be drawn at all.
filled - Boolean. Faces will be drawn if True. Otherwise only the wire is drawn. Default False.
coords - An N-by-2 or N-by-3 array. Row i contains the x,y,z coordinates of node i.
edof - An E-by-L array. Element topology. (E is the number of elements and L is the number of dofs per
element)
dofs_per_node - Integer. Dofs per node. el_type - Integer. Element Type. See Gmsh manual for details. Usually
2
for triangles or 3 for quadrangles.
clim - 2-tuple. Colorbar limits (min, max). Defines the value range of the colorbar. Defaults to None, in
which case min/max are set to min/max of node_vals.
axes - Visvis Axes. The Axes where the model will be drawn. If unspecified the current Axes will be used,
or a new Axes will be created if none exist.
axes_adjust - Boolean. True if the view should be changed to show the whole model. Default True.
draw_elements - Boolean. True if mesh wire should be drawn. Default True. title - String. Changes title of the
figure. Default “Node Values”.
calfem.vis.eldraw2(ex, ey, plotpar, elnum)
calfem.vis.eldraw2(ex, ey, plotpar) → None
calfem.vis.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-node
isopar. elemen
INPUT
ex,ey:. . . . . . . . . . nen: number of element nodes nel: number of elements
plotpar=[ linetype, linecolor, nodemark]
linetype=1 -> solid linecolor=1 -> black 2 -> dashed 2 -> blue 3 -> dotted 3 -> magenta
4 -> red
nodemark=1 -> circle 2 -> star 0 -> no mark
elnum=edof(:,1) ; i.e. the first column in the topology matrix
Rem. Default is solid white lines with circles at nodes.
calfem.vis.eldraw2_mpl(ex, ey, plotpar=[1, 2, 1], elnum=[])
eldraw2(ex,ey,plotpar,elnum) eldraw2(ex,ey,plotpar) eldraw2(ex,ey)
PURPOSE Draw the undeformed 2D mesh for a number of elements of the same type. Supported
elements are:
1) -> bar element 2) -> beam el. 3) -> triangular 3 node el. 4) -> quadrilateral 4 node el. 5) ->
8-node isopar. elemen
INPUT
ex,ey:. . . . . . . . . . nen: number of element nodes nel: number of elements
plotpar=[ linetype, linecolor, nodemark]
linetype=1 -> solid linecolor=1 -> black 2 -> dashed 2 -> blue 3 -> dotted 3 -> 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.
88 Chapter 1. Contents:
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 in
the 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 in
the 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.
• genindex
• modindex
• search
90 Chapter 1. Contents:
PYTHON MODULE INDEX
c
calfem.core, 51
calfem.geometry, 63
calfem.mesh, 72
calfem.ui, 74
calfem.utils, 74
calfem.vis, 81
calfem.vis_mpl, 77
91
CALFEM for Python Documentation, Release 3.5.1
93
CALFEM for Python Documentation, Release 3.5.1
94 Index
CALFEM for Python Documentation, Release 3.5.1
Index 95