Symbolic Integration at Compile Time in Finite Element Methods

Symbolic Integration at Compile Time in Finite Element Methods

Symbolic Integration At Compile Time In Finite Element Methods Karl Rupp Christian Doppler Laboratory for Reliability Issues in Microelectronics at the Institute for Microelectronics, TU Wien Gußhausstraße 27–29/E360 A-1040 Wien, Austria [email protected] ABSTRACT vide facilities for a higher level of abstraction and thus low In most existing software packages for the finite element level programming approaches are extensively documented method it is not possible to supply the weak formulation in the literature. With the advent of pure object-oriented of the problem of interest in a compact form, which was programming, abstraction was long said to be achievable in the early days of programming due to the low abstrac- only in trade-off with run time efficiency, which is again one tion capabilities of available programming languages. With of the major aims of scientific software. In order to still the advent of pure object-oriented programming, abstrac- achieve a reasonably high level of abstraction and good run tion was long said to be achievable only in trade-off with time efficiency, program generators have been designed to run time efficiency. In this work we show that it is possible parse higher level descriptions and to generate the required to obtain both a high level of abstraction and good run time source code, which is then compiled into an executable form. efficiency by the use of template metaprogramming in C++. Examples for such an approach are freeFEM++ [6] or DOL- We focus on a mathematical expressions engine, by which PHIN [5]. element matrices are computed during compile time and by The introduction of another layer in the compilation pro- which the weak formulation can be specified in a single line cess is in fact not very satisfactory: On the one hand, an of code. A comparison of system matrix assembly times input file syntax needs to be specified and parsed correctly, of existing finite element software shows that the template and on the other hand, proper source-code should generated metaprogramming approach is up to an order of magnitude for all semantically valid inputs. Moreover, it gets much faster than traditional software designs. harder to access or manipulate objects at source code level, because any modifications in the higher level input file causes another precompilation run, potentially producing entirely Categories and Subject Descriptors different source code. Thus, it pays off to avoid any addi- D.1.m [Programming Techniques]: Miscellaneous; G.1.4 tional external precompilation, and instead provide higher- [Numerical Analysis]: Quadrature and Numerical Dif- level components directly at source code level. To the au- ferentiation—Automatic differentiation; G.1.8 [Numerical thor’s knowledge, the highest level of abstraction for FEM at Analysis]: Partial Differential Equations—Finite element source code level has so far been achieved by Sundance [10], methods; G.4 [Mathematical Software]: Efficiency; I.1.3 which heavily relies on object oriented programming to raise [Symbolic and Algebraic Manipulation]: Languages the level of abstraction directly at source code level while and Systems—Special-purpose algebraic systems reducing run time penalties to a minimum. In this work we present a compile time engine for math- ematical expressions obtained through template metapro- Keywords gramming [1], so that the level of abstraction at source code Template Metaprogramming, Symbolic Integration, Finite level effectively meets that of the underlying mathemati- Element Methods, C++ cal description. Additionally, due to dispatches at compile time, any penalties due to virtual dispatches at run time are 1. INTRODUCTION avoided. Since both the weak formulation of the underlying mathematical problem and the test and trial functions are The level of abstraction in most software packages dealing available at compile time, we evaluate local element matrices with the finite element method (FEM) is low, mainly be- symbolically by the compiler, so any unnecessary numerical cause for a long time programming languages could not pro- integration at run time is avoided. Our approach only relies on facilities provided with standard-conforming C++ com- pilers to generate the appropriate code that finally enters the executable, thus no further external dependencies have Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are to be fulfilled. not made or distributed for profit or commercial advantage and that copies As driving example throughout this work we consider the bear this notice and the full citation on the first page. To copy otherwise, to Poisson equation republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. −∆u =1 (1) ISSAC 2010, 25–28 July 2010, Munich, Germany. Copyright 2010 ACM 978-1-4503-0150-3/10/0007 ...$10.00. in a domain Ω with, say, homogeneous Dirichlet boundary conditions. However, the techniques presented in the fol- a trial function. The template parameter diff_tag allows to lowing can also be applied to more general problems with specify derivatives of function for which basisfun is a place- additional flux terms, a more complicated right hand side or holder. The differentiation tag diff_tag can also be nested: different types of boundary conditions. The weak formula- 1 // placeholder for a test function v tion of (1) is to find u in a suitable trial space such that 2 basisfun <1> 3 basisfun<1, diff<0> > // for dv/dx a(u, v) := ∇u∇v dx = v dx =: L(v) (2) 4 basisfun<1, diff<1> > // for dv/dy ZΩ ZΩ 5 for all test functions v in a certain test space. After dis- 6 //placeholder for d^2 v/dx^2 7 basisfun<1, diff<0, cretization, the resulting system matrix S is given by 8 diff<0> > N 9 > S =(Si,j )i,j=1, Si,j = a(ϕj , ψi) , (3) where ϕj and ψi are the trial and test functions from the The latter allows for example to deal with PDEs of fourth trial and test spaces respectively [3,13]. S is typically sparse order. due to the local support of the chosen basis functions. A key ingredient in weak formulations are integrations In the following we assume that the system matrix S is over the full domain, the full boundary or parts of the bound- fully set up prior to solving the resulting system of linear ary. Our compile time representation of integrals in the weak equations. Since typically iterative solvers are used for the formulation is driven by two tag classes [2] that indicate the solution of the linear system, it is in principle sufficient to desired integration domain: provide matrix-vector multiplications and never set up the 1 struct Omega {}; full system matrix. Our approach is also suitable for such a 2 configuration, but for better comparison with other software 3 template <long id> packages in Sec. 5 and Sec. 6 we consider the case that S is 4 struct Gamma {}; set up explicitly. According to (2) and (3), a generic finite element imple- The first tag refers to integration over the whole segment mentation must be able to evaluate bilinear forms for varying and the latter to integration over (parts of) the boundary function arguments. Moreover, since the bilinear form is to of the segment. The free template parameter id allows to be supplied by the user, its specification should be as easy distinguish between several (not necessarily disjoint) subre- and as convenient as possible. Consequently, we start with gions of the boundary, where for example Neumann fluxes the discussion of higher-level components for the specifica- are prescribed. tion of the weak formulation in Sec. 2. The specification and The meta class representing integrals takes three template manipulation of test and trial functions is outlined in Sec. 3. arguments: The domain of integration, the integrand and In Sec. 4 the higher-level components are joined in order to the type of integration (symbolical or numerical): compute local element matrices at compile time. The influ- 1 template <typename IntDomain, ence on compilation times and execution times is quantified 2 typename Integrand, in Sec. 5 and Sec. 6 respectively. 3 typename IntTag> 4 struct IntegrationType; 2. EXPRESSION ENGINE IntDomain is one of the two tag classes Omega and Gamma, We have implemented high level components for the com- Integrand is an expression that encodes the integrand, typ- pile time representation of mathematical expressions in the ically of type Expression, and IntTag is used to select the style of expression templates [11,12]. The concept of syntax desired integration method. trees often used at run time was adapted to handle operators After suitable overloads of arithmetic operators acting on and operands at compile time: basisfun, we are ready to specify weak formulations in mne- 1 template <typename ScalarType, monic form directly in code. Let us again consider the weak 2 typename LHS, form given in (2). Transferred to code, it reads in two spatial 3 typename RHS, dimensions 4 typename OP > 1 basisfun<1> v; 5 class Expression; 2 basisfun<1, diff<0> > v_x; 3 basisfun<1, diff<1> > v_y; ScalarType denotes the underlying integral type used for the 4 basisfun<2, diff<0> > u_x; arithmetic operations, LHS and RHS are the left and right hand 5 basisfun<2, diff<1> > u_y; side operands and OP encodes the type of the arithmetic op- 6 eration. In the following we refer to this combination of 7 //the weak formulation: expression templates and syntax trees as expression trees. 8 integral<Omega>( u_x*v_x + u_y*v_y ) As we have seen in (3), the system matrix is build from 9 = integral<Omega>( v ); plugging trial and test functions into the bilinear form.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    8 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us