Академический Документы
Профессиональный Документы
Культура Документы
Our choice
Example Problem
Python + FEM
Introduction to SFE
Robert Cimrman
Department of Mechanics & New Technologies Research Centre University of West Bohemia Plze n, Czech Republic
1/22
Introduction
Our choice
Example Problem
Outline
1
Introduction Programming Languages Programming Techniques Our choice Mixing Languages Best of Both Worlds Python Software Dependencies Example Problem Continuous Formulation Weak Formulation Problem Description File Final slide :-) 2/22
Introduction
Our choice
Example Problem
Programming Languages
1
Pros
speed, speed, speed, . . . , did I say speed? large code base (legacy codes), tradition
Pros
no compiling (very) high-level a few of lines to get (complex) stu done code size easy maintenance dynamic! (often) large code base
3/22
Introduction
Our choice
Example Problem
Programming Languages
1
Pros
speed, speed, speed, . . . , did I say speed? large code base (legacy codes), tradition
Pros
no compiling (very) high-level a few of lines to get (complex) stu done code size easy maintenance dynamic! (often) large code base
3/22
Introduction
Our choice
Example Problem
Programming Languages
1
Pros
speed, speed, speed, . . . , did I say speed? large code base (legacy codes), tradition
Pros
no compiling (very) high-level a few of lines to get (complex) stu done code size easy maintenance dynamic! (often) large code base
3/22
Introduction
Our choice
Example Problem
Programming Languages
1
Pros
speed, speed, speed, . . . , did I say speed? large code base (legacy codes), tradition
Pros
no compiling (very) high-level a few of lines to get (complex) stu done code size easy maintenance dynamic! (often) large code base
3/22
Introduction
Our choice
Example Problem
Programming Languages
1
Pros
speed, speed, speed, . . . , did I say speed? large code base (legacy codes), tradition
Pros
no compiling (very) high-level a few of lines to get (complex) stu done code size easy maintenance dynamic! (often) large code base
3/22
Introduction
Our choice
Example Problem
Programming Languages
1
Pros
speed, speed, speed, . . . , did I say speed? large code base (legacy codes), tradition
Pros
no compiling (very) high-level a few of lines to get (complex) stu done code size easy maintenance dynamic! (often) large code base
3/22
Introduction
Our choice
Example Problem
4/22
Introduction
Our choice
Example Problem
Example C Code
c h a r s [ ] = s e l tudy , mel dudy . a s e l o p r a v d u t u d y . ; i n t s t r f i n d ( char s t r , char t g t ) { int tlen = s t r l e n ( tgt ); i n t max = s t r l e n ( s t r ) t l e n ; register int i ; f o r ( i = 0 ; i < max ; i ++) { i f ( s t r n c m p (& s t r [ i ] , t g t , t l e n ) == 0) return i ; } r e t u r n 1; } int i1 ; i 1 = s t r f i n d ( s , tudy ) ; p r i n t f ( %d \ n , i 1 ) ;
5/22
Introduction
Our choice
Example Problem
Programming Techniques
Random remarks: spaghetti code modular programming OOP design patterns (gang-of-four, GO4) post-OOP dynamic languages . . . all used, but I try to move down the list! :-)
6/22
Introduction
Our choice
Example Problem
Programming Techniques
Random remarks: spaghetti code modular programming OOP design patterns (gang-of-four, GO4) post-OOP dynamic languages . . . all used, but I try to move down the list! :-)
6/22
Introduction
Our choice
Example Problem
+
High level: Python www.python.org batteries included logic of the code conguration les! problem input les! 7/22
Introduction
Our choice
Example Problem
+
High level: Python www.python.org batteries included logic of the code conguration les! problem input les! 7/22
Introduction
Our choice
Example Problem
Python I
Python r is a dynamic object-oriented programming language that can be used for many kinds of software development. It oers strong support for integration with other languages and tools, comes with extensive standard libraries, and can be learned in a few days. Many Python programmers report substantial productivity gains and feel the language encourages the development of higher quality, more maintainable code.
...
batteries included
8/22
Introduction
Our choice
Example Problem
Python II
1.1.16 Why is it called Python? At the same time he began implementing Python, Guido van Rossum was also reading the published scripts from Monty Pythons Flying Circus (a BBC comedy series from the seventies, in the unlikely case you didnt know). It occurred to him that he needed a name that was short, unique, and slightly mysterious, so he decided to call the language Python. 1.1.17 Do I have to like Monty Pythons Flying Circus? No, but it helps. :) . . . General Python FAQ
9/22
Introduction
Our choice
Example Problem
Python III
NASA uses Python. . .
. . . so does Rackspace, Industrial Light and Magic, AstraZeneca, Honeywell, and many others.
http://wiki.python.org/moin/NumericAndScientic
10/22
Introduction
Our choice
Example Problem
Python III
NASA uses Python. . .
. . . so does Rackspace, Industrial Light and Magic, AstraZeneca, Honeywell, and many others.
http://wiki.python.org/moin/NumericAndScientic
10/22
Introduction
Our choice
Example Problem
Software Dependencies
1
libraries & modules SciPy: free (BSD license) collection of numerical computing libraries for Python
enables Matlab-like array/matrix manipulations and indexing
misc: Pyparsing, Matplotlib tools SWIG: automatic generation of Python-C interface code Medit: simple mesh and data viewer ParaView: VTK-based advanced mesh and data viewer in Tcl/Tk MayaVi/MayaVi2: VTK-based advanced mesh and data viewer in Python
11/22
Introduction
Our choice
Example Problem
Software Dependencies
1
libraries & modules SciPy: free (BSD license) collection of numerical computing libraries for Python
enables Matlab-like array/matrix manipulations and indexing
misc: Pyparsing, Matplotlib tools SWIG: automatic generation of Python-C interface code Medit: simple mesh and data viewer ParaView: VTK-based advanced mesh and data viewer in Tcl/Tk MayaVi/MayaVi2: VTK-based advanced mesh and data viewer in Python
11/22
Introduction
Our choice
Example Problem
Software Dependencies
1
libraries & modules SciPy: free (BSD license) collection of numerical computing libraries for Python
enables Matlab-like array/matrix manipulations and indexing
misc: Pyparsing, Matplotlib tools SWIG: automatic generation of Python-C interface code Medit: simple mesh and data viewer ParaView: VTK-based advanced mesh and data viewer in Tcl/Tk MayaVi/MayaVi2: VTK-based advanced mesh and data viewer in Python
11/22
Introduction
Our choice
Example Problem
Software Dependencies
1
libraries & modules SciPy: free (BSD license) collection of numerical computing libraries for Python
enables Matlab-like array/matrix manipulations and indexing
misc: Pyparsing, Matplotlib tools SWIG: automatic generation of Python-C interface code Medit: simple mesh and data viewer ParaView: VTK-based advanced mesh and data viewer in Tcl/Tk MayaVi/MayaVi2: VTK-based advanced mesh and data viewer in Python
11/22
Introduction
Our choice
Example Problem
Software Dependencies
1
libraries & modules SciPy: free (BSD license) collection of numerical computing libraries for Python
enables Matlab-like array/matrix manipulations and indexing
misc: Pyparsing, Matplotlib tools SWIG: automatic generation of Python-C interface code Medit: simple mesh and data viewer ParaView: VTK-based advanced mesh and data viewer in Tcl/Tk MayaVi/MayaVi2: VTK-based advanced mesh and data viewer in Python
11/22
Introduction
Our choice
Example Problem
Software Dependencies
1
libraries & modules SciPy: free (BSD license) collection of numerical computing libraries for Python
enables Matlab-like array/matrix manipulations and indexing
misc: Pyparsing, Matplotlib tools SWIG: automatic generation of Python-C interface code Medit: simple mesh and data viewer ParaView: VTK-based advanced mesh and data viewer in Tcl/Tk MayaVi/MayaVi2: VTK-based advanced mesh and data viewer in Python
11/22
Introduction
Our choice
Example Problem
Software Dependencies
1
libraries & modules SciPy: free (BSD license) collection of numerical computing libraries for Python
enables Matlab-like array/matrix manipulations and indexing
misc: Pyparsing, Matplotlib tools SWIG: automatic generation of Python-C interface code Medit: simple mesh and data viewer ParaView: VTK-based advanced mesh and data viewer in Tcl/Tk MayaVi/MayaVi2: VTK-based advanced mesh and data viewer in Python
11/22
Introduction
Our choice
Example Problem
(1)
minimize gradients of solution (e.g. losses) in c by moving design boundary perturbation of by vector eld V (t ) = + {t V (x )}x c \ where V = 0 in (2)
D in D D
C C out
12/22
Introduction
Our choice
Example Problem
(1)
minimize gradients of solution (e.g. losses) in c by moving design boundary perturbation of by vector eld V (t ) = + {t V (x )}x c \ where V = 0 in (2)
D in D D
C C out
12/22
Introduction
Our choice
Example Problem
(1)
minimize gradients of solution (e.g. losses) in c by moving design boundary perturbation of by vector eld V (t ) = + {t V (x )}x c \ where V = 0 in (2)
D in D D
C C out
12/22
Introduction
Our choice
Example Problem
Appetizer
ow and spline boxes, left: initial, right: nal
13/22
Introduction
Our choice
Example Problem
Continuous Formulation
laminar steady state incompressible Navier-Stokes equations 2 u + u u + p u boundary conditions u = u 0 on in u pn + = p n on out n u = 0 on walls adjoint equations for computing the adjoint solution w : 2 w + u w u w r = c 2 u in w = 0 in w = 0 on in walls and c is the characteristic function of c (6) = = 0 0 in in (3) (4)
(5)
14/22
Introduction
Our choice
Example Problem
Continuous Formulation
laminar steady state incompressible Navier-Stokes equations 2 u + u u + p u boundary conditions u = u 0 on in u pn + = p n on out n u = 0 on walls adjoint equations for computing the adjoint solution w : 2 w + u w u w r = c 2 u in w = 0 in w = 0 on in walls and c is the characteristic function of c (6) = = 0 0 in in (3) (4)
(5)
14/22
Introduction
Our choice
Example Problem
Weak Formulation
state problem: nd u, p (from suitable function spaces) such that v : u +
(u u ) v
p v =
out
p v n
v V0 ,
q u = 0 q Q
(v u ) w +
(u v ) w +
r v (8)
=
c
v : u
v V0 ,
q w = 0 q Q
+ proper BC . . .
15/22
Introduction
Our choice
Example Problem
Weak Formulation
state problem: nd u, p (from suitable function spaces) such that v : u +
(u u ) v
p v =
out
p v n
v V0 ,
q u = 0 q Q
(v u ) w +
(u v ) w +
r v (8)
=
c
v : u
v V0 ,
q w = 0 q Q
+ proper BC . . .
15/22
Introduction
Our choice
Example Problem
Weak Formulation
state problem: nd u, p (from suitable function spaces) such that v : u +
(u u ) v
p v =
out
p v n
v V0 ,
q u = 0 q Q
(v u ) w +
(u v ) w +
r v (8)
=
c
v : u
v V0 ,
q w = 0 q Q
+ proper BC . . .
15/22
Introduction
Our choice
Example Problem
16/22
Introduction
Our choice
Example Problem
16/22
Introduction
Our choice
Example Problem
regions
region 1000 = { name : Omega , s e l e c t : elements of group 6 , } region 0 = { name : W a l l s , s e l e c t : n o d e s o f s u r f a c e n r . O u t l e t , } region 1 = { name : I n l e t , s e l e c t : n o d e s by c i n c ( x , y , z , 0 ) , } region 2 = { name : O u t l e t , s e l e c t : n o d e s by c i n c ( x , y , z , 1 ) , } region 100 = { name : Omega C , # C o n t r o l domain . s e l e c t : n o d e s i n ( x > 25.9999 e 3) & ( x < 18.990 e 3) , } region 101 = { name : Omega D , # D e s i g n domain . s e l e c t : a l l e r . Omega C , }
17/22
Introduction
Our choice
Example Problem
variables
variables u w 0 w v p r q Nu } = : : : : : : : : { ( ( ( ( ( ( ( ( field field field field field field field field , , , , , , , , parameter , 3 v e l o c i t y , ( 3 , 4 , 5 ) ) , parameter , 3 v e l o c i t y , ( 3 , 4 , 5 ) ) , unknown , 3 v e l o c i t y , ( 3 , 4 , 5 ) , 0 ) , test , 3 v e l o c i t y , ( 3 , 4 , 5 ) , w ) , parameter , p r e s s u r e , ( 9 , ) ) , unknown , p r e s s u r e , ( 9 , ) , 1 ) , test , pressure , (9 ,) , r ) , meshVelocity , pressure , ( 9 , ) ) ,
18/22
Introduction
Our choice
Example Problem
variables
variables u w 0 w v p r q Nu } = : : : : : : : : { ( ( ( ( ( ( ( ( field field field field field field field field , , , , , , , , parameter , 3 v e l o c i t y , ( 3 , 4 , 5 ) ) , parameter , 3 v e l o c i t y , ( 3 , 4 , 5 ) ) , unknown , 3 v e l o c i t y , ( 3 , 4 , 5 ) , 0 ) , test , 3 v e l o c i t y , ( 3 , 4 , 5 ) , w ) , parameter , p r e s s u r e , ( 9 , ) ) , unknown , p r e s s u r e , ( 9 , ) , 1 ) , test , pressure , (9 ,) , r ) , meshVelocity , pressure , ( 9 , ) ) ,
18/22
Introduction
Our choice
Example Problem
19/22
Introduction
Our choice
Example Problem
19/22
Introduction
Our choice
Example Problem
materials
material 2 = { name : f l u i d , mode : h e r e , r e g i o n : Omega , v i s c o s i t y : 1 . 2 5 e 1, } material 100 = { name : b p r e s s , mode : h e r e , r e g i o n : Omega , val : 0.0 , }
20/22
Introduction
Our choice
Example Problem
materials
material 2 = { name : f l u i d , mode : h e r e , r e g i o n : Omega , v i s c o s i t y : 1 . 2 5 e 1, } material 100 = { name : b p r e s s , mode : h e r e , r e g i o n : Omega , val : 0.0 , }
20/22
Introduction
Our choice
Example Problem
What is not done general FE engine, with symbolic evaluation (` a la SyFi - merge it?) documentation, unit tests organization of solvers
fast problem-specic solvers
FE assembling equations, terms, regions materials, material caches generic solvers (Newton iteration, direct linear system solution)
What will not be done (?) GUI real symbolic parsing/evaluation of equations 21/22
Introduction
Our choice
Example Problem
What is not done general FE engine, with symbolic evaluation (` a la SyFi - merge it?) documentation, unit tests organization of solvers
fast problem-specic solvers
FE assembling equations, terms, regions materials, material caches generic solvers (Newton iteration, direct linear system solution)
What will not be done (?) GUI real symbolic parsing/evaluation of equations 21/22
Introduction
Our choice
Example Problem
What is not done general FE engine, with symbolic evaluation (` a la SyFi - merge it?) documentation, unit tests organization of solvers
fast problem-specic solvers
FE assembling equations, terms, regions materials, material caches generic solvers (Newton iteration, direct linear system solution)
What will not be done (?) GUI real symbolic parsing/evaluation of equations 21/22
Introduction
Our choice
Example Problem
22/22