AI memo on differences between FDM and FEM

Yes! What you describe is a finite difference method (FDM), which is closely related to FEM. Let's connect the dots between these two approaches.


1. Finite Difference Approach (What You Know)

In the finite difference method, you:

  • Represent the domain $ \Omega $ as a regular grid of points.
  • Approximate derivatives using finite difference formulas (e.g., centered differences).
  • Construct a system of equations based on these approximations.

For example, in 2D on a uniform grid, the discrete Laplace equation at a point $ (i, j) $ is approximated as:

$$ \frac{u_{i+1, j} + u_{i-1, j} + u_{i, j+1} + u_{i, j-1} - 4u_{i,j}}{h^2} = 0 $$

where $ h $ is the grid spacing.

This results in a system of linear equations, which can be solved for $ u $ at interior points while using boundary conditions for the edges.


2. How FEM is Different

Finite Element Method (FEM) works differently but arrives at a similar numerical solution:

  1. Mesh & Basis Functions

    Instead of using a regular grid, FEM divides the domain into elements (triangles, quadrilaterals, etc.).

  • Each element has basis functions $ \phi_i(x, y) $, which are typically piecewise linear or higher-order polynomials.
  • These basis functions are used to approximate $ u(x, y) $ as a combination of basis functions.
  1. Weak Formulation
  • FEM doesn't enforce $ \Delta u = 0 $ at each grid point like FDM.
  • Instead, it requires that $ \int_\Omega \nabla u \cdot \nabla \phi_i \, dx = 0 $ for all basis functions $ \phi_i $.
  • This leads to a system of linear equations similar to FDM but derived via integrals.

3. How They Are Similar

  • Both methods discretize the domain and solve for $ u $ at discrete points.
  • Both lead to a system of linear equations of the form $ A u = b $.
  • Both can be used to solve the Laplace equation and similar PDEs.

4. How They Are Different

Feature Finite Difference Method (FDM) Finite Element Method (FEM)
Grid Regular, structured Can be unstructured (triangles, quads)
Derivative Approximation Finite differences (e.g., $ \frac{u_{i+1,j} - u_{i,j}}{h} $) Weak form (integrals over basis functions)
Basis Functions Implicit (grid points only) Explicit (piecewise functions)
Flexibility Best for simple geometries Works for complex shapes

5. Connecting $ \langle \nabla u, \phi_i \rangle = 0 $ to FDM

  • In FDM, the equation $ \Delta u = 0 $ is enforced pointwise at each grid node.
  • In FEM, $ \langle \nabla u, \phi_i \rangle = 0 $ enforces the equation in an integrated (averaged) sense over the domain.

In a regular grid, FEM with piecewise linear basis functions produces a system of equations almost identical to the finite difference method! So if you were to apply FEM to a structured grid with simple elements, you would get a system of equations that closely resembles the finite difference discretization.


Key Takeaway

  • FDM: Uses explicit pointwise finite difference approximations.
  • FEM: Uses a variational (integral) approach but leads to a similar system of equations.
  • On a regular grid with simple elements, FEM and FDM give almost the same results—FEM just has a more general mathematical foundation that extends better to complex geometries.

Example: Solving the Laplace Equation on a 1D Domain

Let’s solve the Laplace equation

$$ \frac{d^2 u}{dx^2} = 0 $$

on the interval $ x \in [0,1] $, with Dirichlet boundary conditions:

$$ u(0) = 0, \quad u(1) = 1. $$

We'll solve this using both the Finite Difference Method (FDM) and the Finite Element Method (FEM) with piecewise linear basis functions.


1. Finite Difference Method (FDM)

We discretize the domain into $ N $ points:

$$ x_0, x_1, x_2, \dots, x_N $$

with uniform spacing $ h = \frac{1}{N} $.

Using the finite difference approximation for the second derivative:

$$ \frac{u_{i-1} - 2u_i + u_{i+1}}{h^2} = 0 $$

for $ i = 1, 2, \dots, N-1 $, we get a linear system for the unknown values $ u_1, u_2, \dots, u_{N-1} $.

For example, with $ N = 4 $ (so 3 unknowns):

$$ \begin{bmatrix} -2 & 1 & 0 \\ 1 & -2 & 1 \\ 0 & 1 & -2 \end{bmatrix} \begin{bmatrix} u_1 \\ u_2 \\ u_3 \end{bmatrix} = \begin{bmatrix} -0 \\ -0 \\ -1 \end{bmatrix} $$

Solving this system gives the approximate values of $ u(x) $.


2. Finite Element Method (FEM)

Step 1: Choose Basis Functions

  • Divide the domain into elements (e.g., intervals).
  • Use piecewise linear basis functions $ \phi_i(x) $, which are 1 at node $ i $ and 0 elsewhere.

For $ u(x) = \sum_{i} c_i \phi_i(x) $, we require:

$$ \int_0^1 \frac{du}{dx} \frac{d\phi_i}{dx} \,dx = 0. $$

This gives a similar system of linear equations as in FDM.


Key Observation

For a uniform grid with linear basis functions, FEM and FDM yield nearly the same system of equations! 🎯

---


1. The Laplace Equation

The Laplace equation is:

$$ \Delta u = 0 \quad \text{in} \, \Omega $$

where $ \Omega $ is a domain (region) in space, and $ \Delta $ (the Laplace operator) is essentially the divergence of the gradient of $ u $: $ \Delta u = \nabla \cdot \nabla u $.

Boundary Conditions

The Dirichlet boundary condition specifies the value of $ u $ on the boundary $ \partial \Omega $:

$$ u = g \quad \text{on} \, \partial \Omega $$

This means we know the values of the solution $ u $ at the boundary.


2. Finite Element Approximation

When solving PDEs like this, we often use numerical approximations. The idea is to approximate the solution $ u $ using a finite-dimensional space of basis functions.

Basis Functions

Basis functions, denoted as $ \phi_i $, are a set of functions defined over the domain $ \Omega $. They form the building blocks of the approximate solution. For example, in FEM, $ \phi_i $ might be piecewise linear functions defined over a mesh of the domain.

The approximate solution $ u_h $ is expressed as:

$$ u_h(x) = \sum_i c_i \phi_i(x) $$

where $ c_i $ are the coefficients to be determined.


3. Weak Formulation

Instead of solving the PDE directly, we work with its weak form. This reformulates the problem into one involving integrals.

Why Weak Form?

The weak form allows us to relax the requirements on $ u $. Instead of requiring $ u $ to satisfy $ \Delta u = 0 $ pointwise (which is hard to enforce computationally), we require it to hold in an averaged sense over the domain, weighted by the basis functions $ \phi_i $.


4. The Expression $ \langle \nabla u, \phi_i \rangle = 0 \, \forall i $

This comes from the weak formulation. Here's what it means:

  1. Rewriting Laplace's Equation:

    Multiply $ \Delta u = 0 $ by a test function $ \phi_i $ (which is also part of the basis set) and integrate over the domain $ \Omega $:

$$ \int_\Omega (\Delta u) \phi_i \, dx = 0 $$
  1. Integration by Parts: Use the divergence theorem to move one derivative from $ u $ to $ \phi_i $. This step is crucial in FEM:
$$ \int_\Omega \nabla u \cdot \nabla \phi_i \, dx = 0 \quad \forall i $$

Here, $ \nabla u \cdot \nabla \phi_i $ is the dot product of the gradients.

  1. Weak Formulation:

    The above expression essentially states that the gradient of $ u $ is orthogonal (in the sense of an inner product) to the gradient of all basis functions $ \phi_i $. In compact notation:

$$ \langle \nabla u, \phi_i \rangle = 0 \quad \forall i $$

5. Role of Basis Functions

The basis functions $ \phi_i $ play a dual role:

  • Approximation: They are used to construct the approximate solution $ u_h(x) = \sum_i c_i \phi_i(x) $.
  • Testing: They are also used as test functions to ensure that the weak form of the equation is satisfied.

In FEM, the problem boils down to finding the coefficients $ c_i $ such that:

$$ \int_\Omega \nabla u_h \cdot \nabla \phi_i \, dx = 0 \quad \forall i $$

This results in a system of linear equations for the unknowns $ c_i $, which can be solved numerically.


Intuition

Think of $ \langle \nabla u, \phi_i \rangle = 0 $ as saying:

  • The solution $ u $ minimizes the "energy" of the system (related to $ \nabla u \cdot \nabla u $).
  • The residual error of the approximate solution, when projected onto the space spanned by the basis functions $ \phi_i $, is zero.

In simpler terms, $ u $ is the "smoothest" function that interpolates the boundary values and satisfies the Laplace equation in a weak (integral) sense.


 
Paypal donation Donate

No comments

(optional field, I won't disclose or spam but it's necessary to notify you if I respond to your comment)
All html tags except <b> and <i> will be removed from your comment. You can make links by just typing the url or mail-address.
Anti-spam question: