Upload
duongnhi
View
218
Download
1
Embed Size (px)
Citation preview
1/15
Introduction Choice of Language Example Conclusion
SfePy - Introduction, Examples, and Plans
Robert Cimrman1 & others2
1Department of Mechanics & New Technologies Research CentreUniversity of West Bohemia in Plzen, Czech Republic
2other guys from around the world, currently including:Vladimır Lukes (Department of Mechanics),
Andre Smit (?, USA),Logan Sorenson (Georgia Institute of Technology, USA),
Eduard Rohan (Department of Mechanics)
3rd European meeting on Python in Science, Paris,Ecole Normale Superieure, July 8-11 2010
2/15
Introduction Choice of Language Example Conclusion
Outline
1 IntroductionThe Finite Element Method OutlineIntroductionSfePy Interfaces
2 Choice of LanguageMixing Languages — Best of Both WorldsSoftware Dependencies
3 ExampleSettingProblem Description FileRunning SfePyTime-dependent ProblemHomogenization Engine
4 Conclusion
3/15
Introduction Choice of Language Example Conclusion
The Finite Element Method Outline
problem: solve a partial differential equation (PDE)
on some domain on a computer
discretize ↓approximate the domain → mesh
approximate the functions u(x) ≈∑N
i=1 uiϕi(x)ui = degrees of freedom, ϕi(x) piece-wise polynomial base
the simplest case: values in mesh nodes
approximate the integral (weak) forms and their derivatives→ vectors, sparse matrices forming a linear system to solve→ vector of ui
→ →
4/15
Introduction Choice of Language Example Conclusion
Introduction
SfePy = simple finite elements in Pythongeneral finite element analysis softwaresolving systems of PDEs
BSD open-source license
multi-platform (Linux, Mac OS X, Windows)
available athttp://sfepy.org (developers)
mailing lists, issue (bug) trackingwe encourage and support everyone who joins!
http://sfepy.kme.zcu.cz (project information)http://docs.sfepy.org (documentation)
selected applications:homogenization of porous media (parallel flows in a deformableporous medium)acoustic band gaps (homogenization of a strongly heterogenouselastic structure: phononic materials)acoustic waves in thin perforated layersshape optimization in incompressible flow problemsfinite element formulation of Schrodinger equation
5/15
Introduction Choice of Language Example Conclusion
SfePy Interfaces
SfePy can be viewed as
collection of modules (a library)containing
FE engineproblem description facilitiesinterfaces to various solverspostprocessing utilities
usable to build custom applications
“black box” PDE solver
no real programming involvedjust prepare a problem description file and solve ithighly customizable behaviour (with a bit of coding)
this presentation is about the latter (high-level) interface
6/15
Introduction Choice of Language Example Conclusion
Mixing Languages — Best of Both Worlds
low level code (C): element matrix evaluations, . . .
high level code (Python): logic of the code, particular applications,configuration files, problem description files
www.python.org
SfePy = Python + C
notable features:
small size (complete sources + documentation + examples withmeshes are just about 5.5 MB, March 2010)problem description files in pure Pythonproblem description form similar to mathematical description “onpaper”isfepy . . . interactive shell based in IPython
7/15
Introduction Choice of Language Example Conclusion
Software Dependencies
to install and use SfePy, several other packages or libraries areneeded:
NumPy and SciPy: free (BSD license) collection of numericalcomputing libraries for Python
enables Matlab-like array/matrix manipulations and indexing
other: UMFPACK, Pyparsing, Matplotlib, Pytables (+ HDF5), swigvisualization of results: ParaView, MayaVi2, or any otherVTK-capable viewerisfepy requires IPython
SfePy has no built-in meshing capabilitiesFE meshes can be prepared using several free tools:
gmsh, netgen, tetgen
there are now open-source tools for everything
still, the situation is not perfect . . .
8/15
Introduction Choice of Language Example Conclusion
Setting
problem description file is a regular Python module, i.e. all Pythonsyntax and power is accessibleconsists of entities defining:
fields of various FE approximations, variablesequations in the weak form, quadraturesboundary conditions (Dirichlet, periodic, “rigid body”)FE mesh file name, options, solvers, . . .
simple example: the Laplace equation:
c∆u = 0 in Ω, u = u on Γ, weak form:
∫Ω
c ∇u · ∇v = 0, ∀v ∈ V0
9/15
Introduction Choice of Language Example Conclusion
Problem Description FileSolving Laplace Equation — FE Approximations
mesh → define FE approximation to Ω:
filename mesh = ’simple.mesh’
regions → define domain Ω, regions Γleft, Γright, Γ = Γleft ∪ Γright:
h omitted from now on . . .regions =
’Omega’ : (’all’, ),’Gamma Left’ : (’nodes in (x < 0.0001)’, ),’Gamma Right’ : (’nodes in (x > 0.0999)’, ),
fields → define space Vh:fields =
’temperature’ : ((1,1), ’real’, ’Omega’,
’Omega’ : ’3 4 P1’)
’3 4 P1’ means P1 approximation, in 3D, on 4-node FEs (tetrahedra)variables → define uh, vh:variables =
’u’ : (’unknown field’, ’temperature’, 0),
’v’ : (’test field’, ’temperature’, ’u’),
10/15
Introduction Choice of Language Example Conclusion
Problem Description FileSolving Laplace Equation — Equations
materials → define c:
materials = ’m’ : (’c’ : 1.0,),
integrals → define numerical quadrature:
integrals = ’i1’ : (’v’, ’gauss o1 d3’)
equations → define what and where should be solved:
equations = ’eq’ : ’dw laplace.i1.Omega( m.c, v, u ) = 0’
Dirichlet BCs → define u on Γleft, Γright:
ebcs = ’t left’ : (’Gamma Left’, ’u.0’ : 2.0),’t right’ : (’Gamma Right’, ’u.all’ : -2.0),
11/15
Introduction Choice of Language Example Conclusion
Running SfePy
$ s i m p l e . py examples / e x a m p l e l a p l a c e . pys f e p y : r e a d i n g mesh ( examples / s i m p l e . mesh ) . . .s f e p y : . . . done i n 0 . 0 4 ss f e p y : s e t t i n g up domain edges . . .s f e p y : . . . done i n 0 . 0 3 ss f e p y : s e t t i n g up domain f a c e s . . .s f e p y : . . . done i n 0 . 0 2 ss f e p y : c r e a t i n g r e g i o n s . . .s f e p y : Gamma Rights f e p y : Omegas f e p y : Gamma Lefts f e p y : . . . done i n 0 . 0 7 ss f e p y : e q u a t i o n ” L a p l a c e e q u a t i o n ” :s f e p y : d w l a p l a c e . i 1 . Omega( m. c , v , u ) = 0s f e p y : s e t t i n g up d o f c o n n e c t i v i t i e s . . .s f e p y : . . . done i n 0 . 0 0 ss f e p y : d e s c r i b i n g g e o m e t r i e s . . .s f e p y : . . . done i n 0 . 0 1 ss f e p y : u s i n g s o l v e r s :
n l s : newtonl s : l s
s f e p y : m a t r i x shape : ( 30 0 , 300)s f e p y : a s s e m b l i n g m a t r i x graph . . .s f e p y : . . . done i n 0 . 0 1 ss f e p y : m a t r i x s t r u c t u r a l n o n z e r o s : 3538 ( 3 . 9 3 e−02% f i l l )s f e p y : u p d a t i n g m a t e r i a l s . . .s f e p y : ms f e p y : . . . done i n 0 . 0 0 ss f e p y : u p d a t i n g v a r i a b l e s . . .s f e p y : . . . dones f e p y : n l s : i t e r : 0 , r e s i d u a l : 1 .176265 e−01 ( r e l : 1 .000000 e +00)s f e p y : r e z i d u a l : 0 . 0 0 [ s ]s f e p y : s o l v e : 0 . 0 0 [ s ]s f e p y : m a t r i x : 0 . 0 0 [ s ]s f e p y : n l s : i t e r : 1 , r e s i d u a l : 9 .709500 e−17 ( r e l : 8 .254515 e−16)
top level of SfePy code is acollection of executable scriptstailored for various applications
simple.py is dumb script ofbrute force, attempting to solveany equations it finds by theNewton method
. . . exactly what we need here(solver options were omitted inprevious slides)
↓
→
12/15
Introduction Choice of Language Example Conclusion
Time-dependent Problem
adding time to the Laplace equation:
∂u
∂t− c∆u = 0 in Ω, u(·, x) = u on Γ, u(0, ·) = 0,
weak form:
∫Ω
v · ∂u
∂t+
∫Ω
c ∇u · ∇v = 0, ∀v ∈ V0
variables
variables = ’u’ : (’unknown field’, ’temperature’, 0, ’previous’),’v’ : (’test field’, ’temperature’, ’u’),
equations
equations = ’eq’ : """dw mass scalar.i1.Omega( v, du/dt )
+ dw laplace.i1.Omega( m.c, v, u ) = 0"""
+ define time-stepping solver options
↓
13/15
Introduction Choice of Language Example Conclusion
Homogenization Engine
theory of homogenization:
derive macroscopic material parameters from microstructure(topology)kind of “data compression” to avoid brute force
3Y
2Y
1Y1Γ
2ΓΩ
allows recovery of microscopic quantities (e.g. stresses)computing homogenized coefficients requires solution of manyauxiliary problems to get corrector functions
→ homogenization engine
to express data dependencies among subproblems and coefficients
14/15
Introduction Choice of Language Example Conclusion
Conclusion
what is done:basic finite element (FE) engine:
variables, boundary conditions, FE assemblingequations, terms, regionsmaterials, material caches
homogenization enginevarious solvers accessed via abstract interfaceunit tests, sphinx-based documentationmany linear and nonlinear example problems (usually multiphysical)
immediate plans (work in progress):decouple high level API from FE engineimprove interactive API (isfepy)even better documentationfast problem-specific solvers (!)
other plans:adaptive mesh refinement (!) - couple with hermes(http://hpfem.org)parallelization (petsc4py)
http://sfepy.org