Expression templates implementation of continuous and discontinuous Galerkin methods

Efficiency and flexibility are often mutually exclusive features in a code. This still prompts a large part of the Scientific Computing community to use traditional procedural languages. In the last years, however, new programming techniques have been introduced allowing for a high level of abstraction without loss of performance. In this paper we present an application of the Expression Templates technique introduced in (Veldhuizen in Expression templates. C++ Report magazine, vol 7, pp 26–31, 1995) to the assembly step of a finite element computation. We show that a suitable implementation, such that the compiler has the role of parsing abstract operations, allows for user-friendliness. Moreover, it gains in performance with respect to more traditional techniques for achieving this kind of abstraction. Both the cases of conforming and discontinuous Galerkin finite element discretization are considered. The proposed implementation is finally applied to a number of problems entailing different kind of complications.