This finite element method (FEM) solver is capable of solving a variety of partial differential equations (PDEs), such as Poisson, heat, wave, and both linear and nonlinear elasticity equations. It supports both Dirichlet and Neumann boundary conditions and can be applied to simulate both 2D and 3D meshes. Interesting features include custom meshing algorithms, adaptive mesh refinement to enhance simulation accuracy and topology optimization for optimizing structural design. (note: this README is a bit behind the current state of the project, reach out for more details)
This solver uses the Galerkin finite element method with linear basis functions on triangular meshes for 2D problems and tetrahedral meshes for 3D. It is designed to be modular, making it easy to add new PDEs, finite element types, or energy density functions.
Given a function
Poisson's equation is a partial differential equation that can be used to model heat transfer, electrostatics, fluid flow, and other phenomena. It is defined as
Using the finite element method, we can solve for
This example shows the velocity potential
The wave equation is a partial differential equation that describes waves as they propogate through space and time. It is defined as
We can simulate the wave propogation over time with Crank-Nicolson integration, solving for
The wave starts as a single pulse and propogates outwards at a constant speed. When it collides with the boundary, it reflects back and interferes with itself, creating a standing wave pattern.
The heat equation is a partial differential equation that describes the distribution of heat over time. It is defined as
We can simulate the heat distribution over time with Backwards Euler integration, solving for
In this example, there is an initial high temperature bump in the corner of the domain. The heat diffuses outwards and eventually will reach a steady state where the temperature is constant. Heat is conserved in this simulation, where the mean temperature of the domain is constant over time.
The linear elastic mechanics solver can solve for the displacement and stress field of a solid object given applied forces and boundary conditions.
The starting mesh is a supported cantilever beam. We fix the left edge and apply a downward force on the right most edge, and a uniform body force due to gravity.
The resulting deformed mesh shows the beam bending under the forces with a max stress at the corner of the support.
Note: This example shows extreme displacement, in reality, the object would no longer be in the linear elastic regime and the solver would not be accurate.
The solver can also perform adaptive mesh refinement to increase the accuracy of the solution. It works by calculating the a posteriori error estimate of each element and refining the elements with the largest error. We maintain the triangle quality of the mesh with regular (red-green) refinement.
Here, we show adaptive refinement on solving Poisson's equation.
We can see that the residual error is concentrated near the center of the domain, so the solver refines the mesh in that area. The final mesh has a much higher resolution in the center and much lower residual error.
Topology optimization is a method of structural design where the material distribution of a structure is optimized to minimize some objective function. In this case, we are minimizing the compliance of the structure, which is the amount of deformation under a given load.
The boundary conditions are that the left edge is fixed and a downward force is applied to the right edge. The material distribution is represented by a density field, where 0 is no material and 1 is full material. The solver uses the SIMP (Solid Isotropic Material with Penalization) method to penalize intermediate densities.
The solver starts with a uniform density field and iteratively updates the density field to minimize the compliance. This image shows the final density field. This structure uses approx 55% of the original material and only deforms slightly more.
- Galerkin Finite Element Method
- Boundary conditions: Dirichlet, Neumann
- Partial Differential Equations (PDEs): L2 projection, Poisson's equation, Heat equation, Wave equation, Navier-Cauchy equation (linear elastics), hyperelasticity
- Integration: Forward/Backward Euler, Crank-Nicolson
- Energy measures: Dirichlet energy, Kinetic energy
- Error estimates: A posteriori error residuals
- Optimization: Gradient descent, Newton-Raphson method, Optimality criteria method (SIMP)
- Mesh algorithms: Delaunay triangulation, Ruppert's algorithm (line segments -> triangle mesh), Red-Green refinement, half-edge data structure
- Nonlinear elements: quadratic basis functions
- More PDEs: time-dependent dynamics, thermal expansion, transport equations, fluid mechanics, etc.
- Error estimates: a posteriori error estimates for adaptive refinement
- Efficiency: sparse solver
- Interesting Applications: cage-based shape optimization, inverse spring design
The Finite Element Method: Theory, Implementation, and Applications by Mats G. Larson and Fredrik Bengzon.
SIMP Method for Topology Optimization by Dassault Systèmes.