You are on page 1of 5

Institute of Aircraft Design and

Lightweight construction

IFL

Exercise 0: Introduction to ParaView and Python

1 Subscribe to Stud.IP
Stud.IP is a web-based system to support the content and organization of the courses. You
will find the exercise documents, date announcement and a forum, regarding the lecture FEM 2.
Stud.IP is accessible via an Internet-Browser on the website of the TU Braunschweig.

https://studip.tu-braunschweig.de/ → Stud.IP
For login you need a valid y-number and your password. To find the course use the search function,
searching for Finite-Elemente-Methoden 2.

2 Introduction to ParaView
This section describes the program system which is used in the computer exercises.

2.1 What is ParaView ?


ParaView is an open-source tool for the visualization of scientific data. The integrated Python
interface allows to perform multidisciplinary calculations. ParaView serves as a control surface to
the Visualization ToolKit (Vtk). The Finite Element Method includes various aspects and methods
which are covered in the lecture. ParaView is used for the programming and visualization of the
problems treated. The data flow model and a universal graphical user interface supports interactive
working.

2.2 What is ParaView not?


ParaView is not a Fem-System, such as Ansys or Nastran, with broad industrial application. In
the computer exercises, the theories and concepts of Fem will be programmed. ParaView supports
the programming process through visualization of the results and a graphical user interface.

2.3 The concept of ParaView


ParaView consists of several core modules, such as Python, Vtk and other expansion packs.
Modules are written in the object-oriented scripting language Python and can be included in
special filters in ParaView. For engineers, Python is an easy-to-learn programming language,
which is characterized by its simple syntax. The data flow model is implemented by Vtk as
mentioned before. With the help of the Vtk the data flows between the individual modules are
visualized by so-called Pipelines, connecting the input and output data. A large number of modules
exists already in ParaView, which can be divided into two groups: The first group are core modules
without any reference to engineering, and modules including modelling- and analysis-tools. The
second group are the FEM-modules, which have central importance in the computer exercises.

2.4 Working with ParaView - a small tutorial


This brief tutorial demonstrates the concepts and the use of ParaView. It is intended to show
how to call individual modules and to create a pipeline to generate a simple rectangular grid. The
operating system used in the computer exercise, is Linux. However, in later exercises it will no
longer be necessary to build such a pipeline completely, as it will be provided already. The focus
of the exercises will be on the modification of individual modules using Python.

2.4.1 Task: Creation and visualization of a rectangular grid


a.) Start ParaView : Start a console (file → open in terminal ) and type in the command
paraview314. The ParaView GUI appears:

Finite Elemente Methode II 1


Institute of Aircraft Design and
Lightweight construction

IFL

In the Menu bar we focus on the buttons Sources and Filter. Sources are predefined cu-
stomizable data sets. Output data from other programs are often used as source for the
visualization. For visual manipulation, Filter are applied to the existing data. In this way it
is possible to e.g. display only the data which lie in a desired range of the dataset. In this
case a Threshold-Filter would be used. The pipeline, consisting of sources and filters, is shown
in the Pipeline Browser. The properties of the selected sources or filters, are in the Object
Inspector in the Properties-tab, which can be changed as desired. With the mapper settings
- meaning the surface design - the selected object can be defined under the Display-tab. The
Information-tab provides an overview of the object type and the associated values.

b.) Grid generation: Select the Plane in Menu Bar → Sources. In order to create a source, click
Apply in the Object Inspector. The visualisation in the 3D View happens automatically and
can be rotated and zoomed at will.
c.) Change the number of elements: In the Toolbar choose the drop-down menu in which
Surface is selected. Select: Surface with Edges. Under Properties set the X and Y resolu-
tion to 10. For the same plane-dimensions, the number of cell changes now to 100. The 3D
View updates automatically the new settings.
d.) Inserting a Glyph-Filter: Select in the Menu Bar → Filters → Common the filter Glyph.
Select: Apply. The filter creates an arrow at each grid point in the normal direction. The
3D View updates automatically the new settings. Under Properties the Glyph Type can be
customized. Select: Sphere. Change the radius to a value of 0.1 and select: Apply.

Finite Elemente Methode II 2


Institute of Aircraft Design and
Lightweight construction

IFL

3 The Python programming language


Python is an easy to learn, object-oriented programming scripting language and is therefore
used in the computer exercises. Scripting language means that the program code can be written
to a file which is executed immediately by the Python interpreter. Thus, the source file does not
need to be compiled as it is the case e.g. in C++. In this chapter, only the most important aspects
of the language should be summarized in a kind of short reference for the exercise. For a deeper
look please see: www.python.org or textbooks.
1. Datatype:
• General information:
In Python it is not necessary to declare variables with specific data types, the data
type is instead implicitly defined. Comments are preceded by #.
• Integer: i=2
• Float: f=0.5
• Bool: b=True
• String: s=’Guten Tag’ or s="Guten Tag"
• Liste: l=[2, 3.3, "d", "fem2"] #changeable
• Tupel: t=(1.2, "ifl", 5) #unchangeable
• Dictionary: d={1:"wert", "a":6, 1.2:122 } #Assignment Key: Value
• Listen, Tupels, Dictionaries can be nested to any depth, e.g.:
beisp = {1:[1.1,3,3]; "z":{4.3:5}, 3:7}
• Access to individual elements of a string, a list, or a tuple takes place via the clip
operator:
s[0]; l[2]; t[1]
• The dictionary is accessed via the key:
d["a"]; d[1.2]; d[1]

Finite Elemente Methode II 3


Institute of Aircraft Design and
Lightweight construction

IFL

2. Basic elements:
• Operators: -, +, *, /, %
• Potencies: i=2**3 #2 to the power of 3
• Slicing:
s="Finite Elemente"
print s[7] #Output: "E"
print s[7:] #Output: "Elemente"
print s[7:10] #Output: "Ele"
print s[-1] #Output: "e"
print s[-5:] #Output: "mente"
Slicing also works with lists and tuples.
3. Control flow:
Note: In general, you have to indent the code in Python .
• Choice:
if i>5:
print "i greater than 5"
else:
print "i smaller than or equal to 5"

• for-loops: This loop runs on lists or tupels:


for x in [1,2,3,4]:
print x

The function range(n) creates a list [0,...,n]:


for x in range(6):
print x

• while-loop: this loop runs until a condition is fulfilled:


while x>5:
print x
i += 1

4. Modules:
A new module is defined by the keyword def, followed by the modules name and the parameter
list.

def plus(a,b):
return a+b

print plus(6,4) #Output: 10

5. Classes:
• Classes are templates for data structures, containing methods and attributes.
• Objects are instances of classes.
• Methods are functions of objects.
• Attributes are the object data.
• The dot operator allows access to methods and attributes.
For example: A list of l=[8,9,7] is actually an object of the class List:

Finite Elemente Methode II 4


Institute of Aircraft Design and
Lightweight construction

IFL

l=[8,9,7]
l.append(5)
print l[3] #Output: 5
l.sort()
print l #Output: [5,7,8,9]

• Custom classes are defined by the keyword class followed by class name.

6. Numeric package
• In the exercise the numerics package fem2 is used, which is based on the Standard-
Numeric-Package.
• The package is included with import fem2 in order to use the containing functions,
classes and methods.
• The package allows to instantiate matrices and vectors as objects in order to perform
easy calculations, such as inverse computation, transpose, determinant etc.
#import fem2
m1 = fem2.Identity(3) #creates a 3x3 unit-matrix
m2 = fem2.Zeros((3,3)) #creates a 3x3 null-Matrix
m3 = fem2.FMatrix( [[1,2],[3,4]] ) #creates a 2x2 matrix from lists
v1 = fem3.FVector([1,2,3]) #creates a vektor from a List
print m3**-1 #calculates the inverse of m3
print m3.I #calculates the inverse of m3
print m3.det() #calculates the determinant of m3
print m3.T #creates the transposed to m3
print m3.I * m3 #performes matrix-matrix-multiplication
print m1*v1 #performes matrix-vector-multiplication

Finite Elemente Methode II 5

You might also like