SfePy: finite element analysis software in Python

1
SfePy: finite element analysis software in Python Robert Cimrman, Eduard Rohan, Vladim´ ır Luke ˇ s Department of Mechanics & New Technologies Research Centre University of West Bohemia, Univerzitn´ ı8 306 14 Plzeˇ n, Czech Republic [email protected], [email protected], [email protected] 1. Introduction M ADE publicly available at http://sfepy.kme.zcu. cz under the BSD open-source license, SfePy is a general finite element analysis software. The latest sources can be obtained at the developer’s pages currently at http://code.google.com/p/sfepy/, containing also mailing lists and the issue (bug) tracker. We encourage and support everyone who joins! Current applications include homogenization of porous media (parallel flows in a de- formable porous medium), acoustic band gaps (homogenization of a strongly het- erogenous elastic structure: phononic materials), shape optimization in incompressible flow problems. 2. Appetizer I: shape optimization of channels T HE incompressible flow problem is defined in an open bounded domain Ω IR 3 with two (possibly overlapping) subdomains defined as Ω= Ω D Ω C with Γ C = Ω D Ω C , (1) where Ω C is the control domain and Ω D is the design do- main, see Fig. 1. The shape of Ω D is modified exclusively through the design boundary, Γ D Ω D \ Γ in-out where Γ in-out Ω is the union of the “inlet-outlet” boundary of the channel; in general Γ in-out consists of two disjoint parts, Γ in-out in Γ out . Γ in Γ out Γ D Γ D Γ C C D Figure 1: The decomposition of domain Ω, control domain Ω C at the outlet sector of the channel. We wish to enhance flow uniformity by reducing the gra- dients of flow velocities u in Ω C . Our objective is thus to minimize Ψ(u )= ν 2 Ω C |∇u | 2 (2) by moving the design boundary Γ D . The design changes are performed by means of the free-form deformation (FFD), cf. [4]. Example results can be seen in Fig. 2. Figure 2: Left: initial, right: final shapes of a tube. Flow and domain control boxes; Ω C between two grey planes. For more information, see [2] or [5]. 3. Which language? W ITH the advent of very high level dynamic, or scripting, programming languages new possibilities of code de- velopment emerged, accelerated by easily available com- puting power we have at our hands presently. Nowadays a very popular way of application development relies upon expressing the logic of a code in a high-level scripting lan- guage while, following a careful profiling, the real bottle- necks are implemented in a traditional language like for- tran, C, or C++. The scripting language then serves as a glue, providing high-level interface to both (numerical) for- tran legacy codes and newer libraries. The language of our choice is Python (http://python.org) — a remarkably powerful dynamic programming language that is used in a wide variety of application domains. B Y mixing programming languages we get best of both worlds: the speed of C in relevant parts of the code, and the flexibility, power and maintainability of Python. low level code (C or fortran): element matrix evaluations, costly mesh-related functions, . . . high level code (Python): logic of the code, particular ap- plications, configuration files, problem description files We conclude this section with SfePy = Python + C (+ fortran) 4. Dependencies T O install and use SfePy, several other packages or li- braries are needed: NumPy and SciPy: free (BSD license) collection of nu- merical computing libraries for Python enables Matlab-like array/matrix manipulations and in- dexing other: UMFPACK, Pyparsing, Matplotlib, Pytables (+ HDF5), swig visualization of results: ParaView, Mayavi2, or any other VTK-capable viewer 5. Appetizer II: homogenization of porous media T O tackle strong heterogeneities we use a multiscale ap- proach based on the theory of homogenization, cf. [3]. In Fig. 3 (left) a periodic microstructure with a matrix and two systems of highly permeable channels (strong het- erogeneity in permeability) is shown (3 × 3 × 3 repetition of the reference volume element). Our model of parallel flows in a deformable porous medium is defined in terms of dis- placements u and two pressures p 1 , p 2 in each channel on the macroscale, and by so-called corrector shape functions (displacement- and pressure-like) on the microscale, see Fig. 3 (middle, right). Figure 3: Microstructure (left), example correctors (middle, right), color = pressure. The homogenized constitutive coefficients (elasticity, fad- ing memory effects, Biot-like coefficients, permeability, etc.) computed for such a microstructure are then used within the macroscopic homogenized model, see Fig. 4. t = 60 s: p 1 , w 1 t = 80 s: p 1 , w 1 t = 60 s: p 2 , w 2 t = 80 s: p 2 , w 2 Figure 4: Macroscale solution for two time steps: displace- ments 10× magnified, color = pressures p 1 , p 2 , arrows = diffusion velocities w 1 , w 2 (5000× magnified). Finally let us show corrector shape functions of an ideal- ized 2D microstructure of an osteon in Fig. 5, a structure quasi-periodically repeating in bones. Figure 5: Correctors for an osteon microstructure (color = pressure, arrows = displacements). 6. Describing problems to solve I N order to solve PDEs, these must be translated to a form that SfePy can deal with. Fortunately, this form is similar to a “paper” version of the problem. The problem descrip- tion file is a regular Python module, i.e. all Python syntax and power is accessible, and consists of entities defining: fields of various FE approximations, variables, equations in the weak form, quadratures, boundary conditions (Dirichlet, periodic, “rigid body”), FE mesh file name, options, solvers, . . . Let us illustrate this using a trivial example: the Laplace equation cu =0 in Ω, u u on Γ . (3) E QUATIONS in SfePy are built using terms, which corre- spond directly to the integral forms of weak formulation of a problem to be solved. The weak formulation of (3) is: Find u V , such that Ω c u : v =0, v V 0 . (4) In SfePy input files, this can be written as dw_laplace.i1.Omega( c, v, u ) = 0 , (5) which directly corresponds to the discrete version of (4): Find u V h , such that v T ( Ω h c G T G)u =0, v V h0 , (6) where u Gu. The integral over the discrete domain Ω h is approximated by a numerical quadrature, that is named i1 in our case. 7. Appetizer III: acoustic band gaps A C oustic band gaps appear in strongly heterogeneous media composed of a matrix (mtx) and a periodic pat- tern of inclusions (inc). The strong heterogeneities in the elasticity can lead to negative eigenvalues of an effective mass tensor A * for certain frequency ranges, resulting ei- ther in a strong band gap (no waves at all) or a weak band gap (waves in a particular direction only). The effec- tive mass tensor A * = j J A *,j (ω )+ r * I , r * = inc r i + mtx r m (y ), r i is the inclusion density, r m the matrix density, has the following form: A *,j pq = -ω 2 ω 2 - λ 2 inc r i ϕ j p inc r i ϕ j q , (7) where ω is the frequency and {ϕ j j } j 1 are the eigenele- ments associated to the elasticity operator in the inclusion domain, see [1]. Example results for the spherical inclusion are in Fig. 6 and and for the elliptical inclusion in Fig. 7. no. 1 4 8 Figure 6: Displacement eigenvectors of elasticity operator. Figure 7: Example band gaps (yellow = strong, white = weak), the largest (solid) and smallest (dashed) eigenval- ues of A * and resonance frequencies λ j (vertical lines). Acknowledgement: This work has been supported by the grant project GA ˇ CR 101/07/1471 of the Grant Agency of the Czech Republic, entitled “Finite element modelling of linear, non-linear and multiscale effects in wave propaga- tion in solids and heterogeneous media”. References [1] A. ´ Avila, G. Griso, B. Miara, and E. Rohan. Multi-scale modelling of elastic waves – theoretical justification and numerical simulation of band gaps. Multiscale Modeling and Simulation, SIAM, 2007. [2] R. Cimrman and E. Rohan. On shape optimization of conduits with incompressible flow. Applied and Compu- tational Mechanics, 1(2):393–400, 2007. ISSN: 1802- 680X, Neˇ ctiny. [3] G. Griso and E. Rohan. On the homogenization of a diffusion-deformation problem in strongly heteroge- neous media. Ricerche di Matematica, 56(2):161–188, 2007. [4] S. Menzel, M. Olhofer, and B. Sendhoff. Application of free form deformation techniques in evolutionary de- sign optimization. In Proceedings of 6th World Congress on Structural and Multidisciplinary Optimization, Rio de Janeiro, Brazil, 2005. [5] E. Rohan and R. Cimrman. Shape sensitivity analysis for flow optimization in closed channels. In Proceedings of the conference Engineering Mechanics 2006, Svratka, 2006. Full version on CD-ROM. Colloque Num ´ erique Suisse / Schweizer Numerik Kolloquium, Universit´ e de Fribourg, April 25, 2008

Transcript of SfePy: finite element analysis software in Python

Page 1: SfePy: finite element analysis software in Python

SfePy: finite element analysissoftware in Python

Robert Cimrman, Eduard Rohan, Vladimır LukesDepartment of Mechanics & New Technologies Research Centre

University of West Bohemia, Univerzitnı 8306 14 Plzen, Czech Republic

[email protected], [email protected], [email protected]

1. Introduction

MADE publicly available at http://sfepy.kme.zcu.cz under the BSD open-source license, SfePy is a

general finite element analysis software. The latest sourcescan be obtained at the developer’s pages currently athttp://code.google.com/p/sfepy/, containing alsomailing lists and the issue (bug) tracker. We encourage andsupport everyone who joins! Current applications include• homogenization of porous media (parallel flows in a de-

formable porous medium),• acoustic band gaps (homogenization of a strongly het-

erogenous elastic structure: phononic materials),• shape optimization in incompressible flow problems.

2. Appetizer I: shape optimization of channels

THE incompressible flow problem is defined in an openbounded domain Ω ⊂ IR3 with two (possibly overlapping)

subdomains defined as

Ω = ΩD ∪ ΩC with ΓC = ∂ΩD ∩ ∂ΩC , (1)

where ΩC is the control domain and ΩD is the design do-main, see Fig. 1. The shape of ΩD is modified exclusivelythrough the design boundary, ΓD ⊂ ∂ΩD \ Γin−out whereΓin−out ⊂ ∂Ω is the union of the “inlet-outlet” boundary ofthe channel; in general Γin−out consists of two disjoint parts,Γin−out = Γin ∪ Γout.

Γin ΓoutΓD

ΓD

ΓC ΩC

ΩD

Ω

Figure 1: The decomposition of domain Ω, control domainΩC at the outlet sector of the channel.We wish to enhance flow uniformity by reducing the gra-dients of flow velocities u in ΩC. Our objective is thus tominimize

Ψ(u) =ν

2

∫ΩC

|∇u|2 (2)

by moving the design boundary ΓD. The design changesare performed by means of the free-form deformation(FFD), cf. [4]. Example results can be seen in Fig. 2.

Figure 2: Left: initial, right: final shapes of a tube. Flowand domain control boxes; ΩC between two grey planes.For more information, see [2] or [5].

3. Which language?

WITH the advent of very high level dynamic, or scripting,programming languages new possibilities of code de-

velopment emerged, accelerated by easily available com-puting power we have at our hands presently. Nowadaysa very popular way of application development relies uponexpressing the logic of a code in a high-level scripting lan-guage while, following a careful profiling, the real bottle-necks are implemented in a traditional language like for-tran, C, or C++. The scripting language then serves as aglue, providing high-level interface to both (numerical) for-tran legacy codes and newer libraries. The language of ourchoice is Python (http://python.org) — a remarkablypowerful dynamic programming language that is used in awide variety of application domains.

BY mixing programming languages we get best of bothworlds: the speed of C in relevant parts of the code,

and the flexibility, power and maintainability of Python.• low level code (C or fortran): element matrix evaluations,

costly mesh-related functions, . . .• high level code (Python): logic of the code, particular ap-

plications, configuration files, problem description filesWe conclude this section with

SfePy = Python + C (+ fortran)

4. Dependencies

TO install and use SfePy, several other packages or li-braries are needed:

•NumPy and SciPy: free (BSD license) collection of nu-merical computing libraries for Python– enables Matlab-like array/matrix manipulations and in-

dexing• other: UMFPACK, Pyparsing, Matplotlib, Pytables (+

HDF5), swig• visualization of results: ParaView, Mayavi2, or any other

VTK-capable viewer

5. Appetizer II: homogenization of porous media

TO tackle strong heterogeneities we use a multiscale ap-proach based on the theory of homogenization, cf. [3].

In Fig. 3 (left) a periodic microstructure with a matrix andtwo systems of highly permeable channels (→strong het-erogeneity in permeability) is shown (3× 3× 3 repetition ofthe reference volume element). Our model of parallel flowsin a deformable porous medium is defined in terms of dis-placements u and two pressures p1, p2 in each channel onthe macroscale, and by so-called corrector shape functions(displacement- and pressure-like) on the microscale, seeFig. 3 (middle, right).

Figure 3: Microstructure (left), example correctors (middle,right), color = pressure.The homogenized constitutive coefficients (elasticity, fad-ing memory effects, Biot-like coefficients, permeability, etc.)computed for such a microstructure are then used withinthe macroscopic homogenized model, see Fig. 4.

t = 60 s: p1, w1 t = 80 s: p1, w1

t = 60 s: p2, w2 t = 80 s: p2, w2

Figure 4: Macroscale solution for two time steps: displace-ments 10× magnified, color = pressures p1, p2, arrows =diffusion velocities w1, w2 (5000× magnified).Finally let us show corrector shape functions of an ideal-ized 2D microstructure of an osteon in Fig. 5, a structurequasi-periodically repeating in bones.

Figure 5: Correctors for an osteon microstructure (color =pressure, arrows = displacements).

6. Describing problems to solve

IN order to solve PDEs, these must be translated to a formthat SfePy can deal with. Fortunately, this form is similar

to a “paper” version of the problem. The problem descrip-tion file is a regular Python module, i.e. all Python syntaxand power is accessible, and consists of entities defining:• fields of various FE approximations, variables,• equations in the weak form, quadratures,• boundary conditions (Dirichlet, periodic, “rigid body”),• FE mesh file name, options, solvers, . . .

Let us illustrate this using a trivial example: the Laplaceequation

c∆u = 0 in Ω, u = u on Γ . (3)

EQUATIONS in SfePy are built using terms, which corre-spond directly to the integral forms of weak formulation

of a problem to be solved. The weak formulation of (3) is:Find u ∈ V , such that∫

Ωc ∇u : ∇v = 0, ∀v ∈ V0 . (4)

In SfePy input files, this can be written as

dw_laplace.i1.Omega( c, v, u ) = 0 , (5)

which directly corresponds to the discrete version of (4):Find u ∈ Vh, such that

vT (

∫Ωh

c GTG)u = 0, ∀v ∈ Vh0 , (6)

where ∇u ≈ Gu. The integral over the discrete domain Ωhis approximated by a numerical quadrature, that is namedi1 in our case.

7. Appetizer III: acoustic band gaps

AC oustic band gaps appear in strongly heterogeneousmedia composed of a matrix (mtx) and a periodic pat-

tern of inclusions (inc). The strong heterogeneities in theelasticity can lead to negative eigenvalues of an effectivemass tensor A∗ for certain frequency ranges, resulting ei-ther in a strong band gap (no waves at all) or a weakband gap (waves in a particular direction only). The effec-tive mass tensor A∗ =

∑j∈J A∗,j(ω) + r∗I, r∗ =

∫inc ri +∫

mtx rm(y), ri is the inclusion density, rm the matrix density,has the following form:

A∗,jpq =

−ω2

ω2 − λ2

∫inc

riϕjp

∫inc

riϕjq , (7)

where ω is the frequency and ϕj, λjj≥1 are the eigenele-ments associated to the elasticity operator in the inclusiondomain, see [1].Example results for the spherical inclusion are in Fig. 6 andand for the elliptical inclusion in Fig. 7.no. 1 4 8

Figure 6: Displacement eigenvectors of elasticity operator.

Figure 7: Example band gaps (yellow = strong, white =weak), the largest (solid) and smallest (dashed) eigenval-ues of A∗ and resonance frequencies

√λj (vertical lines).

Acknowledgement: This work has been supported by thegrant project GACR 101/07/1471 of the Grant Agency ofthe Czech Republic, entitled “Finite element modelling oflinear, non-linear and multiscale effects in wave propaga-tion in solids and heterogeneous media”.

References

[1] A. Avila, G. Griso, B. Miara, and E. Rohan. Multi-scalemodelling of elastic waves – theoretical justification andnumerical simulation of band gaps. Multiscale Modelingand Simulation, SIAM, 2007.

[2] R. Cimrman and E. Rohan. On shape optimization ofconduits with incompressible flow. Applied and Compu-tational Mechanics, 1(2):393–400, 2007. ISSN: 1802-680X, Nectiny.

[3] G. Griso and E. Rohan. On the homogenization ofa diffusion-deformation problem in strongly heteroge-neous media. Ricerche di Matematica, 56(2):161–188,2007.

[4] S. Menzel, M. Olhofer, and B. Sendhoff. Applicationof free form deformation techniques in evolutionary de-sign optimization. In Proceedings of 6th World Congresson Structural and Multidisciplinary Optimization, Rio deJaneiro, Brazil, 2005.

[5] E. Rohan and R. Cimrman. Shape sensitivity analysis forflow optimization in closed channels. In Proceedings ofthe conference Engineering Mechanics 2006, Svratka,2006. Full version on CD-ROM.

Colloque Numerique Suisse / Schweizer Numerik Kolloquium, Universite de Fribourg, April 25, 2008