arXiv:2611.01414cs.MSNov 2026

Manuscript Offprint

arXiv:2611.01414

Extensible Programmatic Specification of Finite Element Methods

Theadora Fields Collin, Oded Stein, Gilbert Bernstein, Saman Amarasinghe

THEADORA FIELDS COLLIN, Massachusetts Institute of Technology, USA

ODED STEIN, University of Southern California, USA and Technion—Israel Institute of Technology, Israel

GILBERT BERNSTEIN, University of Washington, USA

SAMAN AMARASINGHE, Massachusetts Institute of Technology, USA

Figure

Fig. 1. From a high level description of a finite element and an operator, our system produces routines that can be used to deliver better higher order solutions to a variety of graphics problems. Yellow dotted circles indicate telltales that the bottom solutions are higher quality.

Finite element methods (FEMs) are a powerful and ubiquitous tool for solving engineering problems. Experimenting with different finite elements can improve the quality and efficiency of solutions. In some cases, the wrong (but nonetheless most common) choice of finite element will produce solutions which converge to the wrong answer regardless of mesh resolution. However, in practice, the choice of finite element is not explored due to the complexity of re-deriving and re-implementing finite element methods. Trying a new finite element is challenging because practitioners must manually deduce formulas to use these elements and they must implement these formulas within the context of a potentially complex system. We address this problem by introducing ElementForge, a finite element system that is parametric over the literate mathematical specification of a finite element in a domain-specific language (DSL). The ElementForge compiler reasons about tensor spaces, tensors, and tensor bases from first principles to derive implementations of finite elements. The ElementForge compiler is able to automatically derive implementations of finite elements previously only derived by hand. Further, ElementForge minimally couples several key mathematical concepts, mainly tensor fields, mesh topologies, sparse tensors, and assembled finite element operators, to produce a complete finite element system that is parametric over the choice of element. Consequently, the elements derived by the compiler can be applied parametrically to new meshes, PDEs, and boundary conditions. We evaluate our system by implementing several simulations with different finite elements, demonstrating that our system can explore tradeoffs in generality, accuracy, speed, and representational complexity. For example, we are able to implement the Morley, Bell, Argyris, and Hermite like elements with less than 50 lines of code and use them all in a single simulation.

CCS Concepts: • Mathematics of computing → Discretization; Partial differential equations; • Computing methodologies → Computer graphics; Symbolic and algebraic manipulation; • Software and its engineering → Domain specific languages.

Additional Key Words and Phrases: Finite Element Methods, Domain Specific Languages, Programming Languages, Physical Simulation

1 Introduction

Finite Element Methods (FEMs) have become an important tool in a variety of fields, including applied mathematics, scientific computing, engineering, and computer graphics [Brenner and Scott 2008; Ciarlet 2002; Hughes 2000]. Within computer graphics, FEMs are a fundamental tool for many simulation and geometry processing pipelines. FEMs are powerful because one can vary the mesh, the problem formulation, the solver, and the element, a discrete local function space. One can choose from more than 100 families of finite elements [Scroggs 2023], each of which provide specific quantitative and qualitative advantages and disadvantages. Within computer graphics specifically, practitioners have examined the trade-offs between convergence and computational cost of various higher order Lagrange elements [Fernández-Fernández et al. 2025; Schneider et al. 2019, 2022].

However, practitioners face three challenges if they want to determine and exploit the trade-offs that different finite elements (FEs) offer. The first challenge is that practitioners must deduce, from the definition of the FE, various mathematical formulas that software packages require to implement an FE [Ham et al. 2025; Kirby 2004]. The second challenge is that practitioners must understand global FE operations (e.g., methods to build a sparse matrix or enforce a boundary condition) at both a mathematical and software level so that they can reimplement these operations for their class of FE. The third challenge is that for practitioners to explore these trade-offs, they must experiment with multiple FEs, encountering the first two challenges each time, and they must also experiment with their problem formulation to properly exploit some FEs.

The first challenge motivates our focus on deriving element transformations directly from mathematical specifications. Many systems offer partial solutions to the second challenge because they internally provide an interface to FEs and use this interface to implement many global FEM operations [Anderson et al. 2021; Kirby

Authors' addresses: Theadora Fields Collin, teoc@mit.edu, Massachusetts Institute of Technology, Cambridge, Massachusetts, USA; Oded Stein, ostein@usc.edu, University of Southern California, Los Angeles, California, USA and Technion—Israel Institute of Technology, Haifa, Israel; Gilbert Bernstein, gilbo@cs.washington.edu, University of Washington, Seattle, Washington, USA; Saman Amarasinghe, saman@csail.mit.edu, Massachusetts Institute of Technology, Cambridge, Massachusetts, USA.

2 • Collin et al.

and Mitchell 2019; Renard and Poulios 2020]. In software packages that offer solutions to a set of narrow problems, interfaces to an FE might not be present (the FE is baked into the script) or the interface only serves a narrow set of problems (e.g., it only supports certain derivatives or boundary conditions (BCs)). Finally, many systems address third problem via libraries or domain specific languages (DSLs) to vary the problem formulation [Alnæs et al. 2014; Anderson et al. 2021; Dedner et al. 2012; Fernández-Fernández et al. 2025; Gangl et al. 2020; Logg et al. 2012; Rathgeber et al. 2016]. These DSLs offer a high degree of flexibility for problem specifications and can work with different FEs. Our focus is the additional step of deriving reference-to-world transformations from element definitions, rather than requiring element-specific implementations of those transformations. As a practical consequence of the prior lack of automation, many communities stick to varying the problem to work with linear Lagrange elements, hiding a large space of trade-offs involving both higher order Lagrange elements and non-Lagrangian elements. Thus, we propose to significantly lower the cost of varying FEs and problems with ElementForge, the first FE DSL that is fully parametric over a mathematical definition of an FE. This parametricity extends through the FEM pipeline: interpolation, boundary-condition handling, and operator assembly are expressed using common primitives that adapt to the chosen element's mathematical definition (section 7). We believe that ElementForge will allow many to find and take advantage of trade-offs among FEs and associated problem formulations.

To meet all three challenges, our work, ElementForge, offers abstractions, languages, and deductive systems for fundamental aspects of FEM. To answer the first challenge, ElementForge contains a language for specifying FEs and a compiler that automatically deduces the formulas required to be implemented by hand in other packages, thus automating work previously found in mathematical journals. To answer the second challenge, ElementForge offers several core primitives that we show are sufficient for users to systematically generate global finite element operations that translate local formulas to useful code for building and manipulating sparse matrices. To answer the third challenge, ElementForge allows users to specify suitable problems with the same language that it provides to specify FEs. Finally, ElementForge agglomerates these solutions into a single package that allows users to define, reuse, and combine various FEs, problem specifications, and global routines to rapidly explore FEMs.

The core design principle of ElementForge is to systematically model the discrete mathematical objects of FEMs. In contrast to prior work, our software architecture does not emphasize either the global theory of PDEs or the structure of a specific class of problems. ElementForge emphasizes the discrete mathematical objects at the core of FEM implementations as these are the tools required to save labor through automation. Consequently, ElementForge pays special care to pointwise manipulation of tensor fields on manifolds, the definition of an FE, the construction of a discrete mesh, and the algebraic construction of global operations via the interaction of pointwise expressions and discrete meshes. These new tools provide the means to go from a mathematically specified FE and operator to a sparse matrix, automatically, and, hopefully, understandably.

Our implementation is not without some limitations, especially as we currently do not pay attention to low level performance issues; many FEM packages have outlined techniques to optimize code generated for FEs with special structures and these techniques could eventually be employed here [Homolya et al. 2017; Kempf et al. 2020; Sun et al. 2020]. Even with these limitations, we are able to implement novel simulations of independent interest to different areas of computer graphics. Moreover, we view these simulations and our software as part of an effort to make FEs more accessible. We make the following contributions:

(1) To the best of our knowledge, the first FE DSL that is fully parametric over a mathematical definition of an FE, enabling users to reuse and adapt global FEM routines across different elements and problems.

(2) A novel DSL and compiler for specifying FEs and operators via pointwise integrals of coordinate-free tensor algebra. This system enables the automated deduction of formulas needed to implement FEs at the local level.

(3) An interface for the systematic construction of global FE operations, enabling core and new global FE operations to be built on a wide variety of elements.

(4) An overall compiler taking as input (i) an FE description, (ii) operator specifications, and (iii) a mesh, and producing discretization operators (and interpolation functions) as output.

(5) Several novel simulations of interest to computer graphics:

(a) A more efficient yet simpler data interpolation/smoothing method based on the natural BCs of the biharmonic equation, identified in [Stein et al. 2018], and the Morley element [Li et al. 2022]. Moreover, we have explored a variety of FEs for this class of problems, leading to characterization of some of the tradeoffs involved.

(b) To the best of our knowledge, the first implementation of the finite element exterior calculus (FEEC) that is derived purely and automatically from the mathematical specification, which allows us to re-implement the analogues of all the discrete exterior calculus (DEC) operators, leading to FEM versions of classic DEC applications. Our methods also expose the cheaper first kind Nédélec elements [Arnold et al. 2010], which are not properly characterized in the graphics literature (compared to the standard second kind elements).

(c) Several FEs for Stokes flows problems in 2D+time and 3D+time, illustrating the phenomena of locking incompressible fluids (in contrast to prior work that focused on elasticity).