1. Introduction
This project implements a 1D nonlinear diffusion equation solver using the Finite Element Method (FEM). Diffusion phenomena are commonly observed in fluid flow, heat transfer, and other physical systems where quantities such as temperature, concentration, or velocity diffuse over time due to molecular interactions.
In this particular implementation, we model diffusion in the presence of a nonlinear diffusion coefficient
2. Mathematical Definition
The general form of the 1D nonlinear diffusion equation is given by:
Where:
-
$u(x,t)$ is the scalar field representing the physical quantity being diffused (e.g., temperature or concentration). -
$D(u)$ is the nonlinear diffusion coefficient that depends on the solution$u$ . - The term
$\frac{\partial u}{\partial t}$ represents the rate of change of the field over time. - The term
$\frac {\partial}{\partial x}( D(u) \frac{\partial u}{\partial x} )$ describes the spatial diffusion, with the diffusion coefficient varying based on the solution.
2.1. Boundary and Initial Conditions
- Dirichlet Boundary Conditions: Fixed values for
$u$ are applied at both boundaries of the 1D domain, i.e.,$u(0,t)=u_0$ and$u(L,t)=u_L$ . - Initial Condition: The solution is initialized with a uniform value across the domain,
$u(x,0)=1.0$ .
3. Methodology
The solution to the nonlinear diffusion equation is computed using the Finite Element Method (FEM). This method involves discretizing the domain into small elements and approximating the solution over these elements using basis functions.
3.1. Weak Formulation
To derive the weak form, we multiply the original equation by a test function
Using Galerkin FEM, the solution
3.2. Explanation of Basis Functions
The domain is discretized into
- Local support: Each basis function is associated with a specific node, and its value is non-zero only on the two elements that share this node.
- Piecewise linear: The function is linear between the nodes, meaning it varies linearly within the interval between two adjacent nodes.
For node
This leads to a system of equations of the form:
Where:
-
$M$ is the mass matrix. -
$πΎ$ is the stiffness matrix that depends on$u$ and the nonlinear diffusion coefficient$D(u)$ .
The linear basis function is as follows
Where:
-
$N_i(x)$ takes the value of 1 at node$i$ (at$x=x_i$ ). -
$N_i(x)$ is 0 at nodes$iβ1$ and$i+1$ . -
$N_i(x)$ is linear between the nodes, i.e., it rises from 0 to 1 between$x_{i-1}$ and$x_i$ , and then falls from 1 to 0 between$x_i$ and$x_{i+1}$ . To form the mass matrix, we integrate over the domain using the basis functions:
β« Ξ© π π ( π₯ ) π π ( π₯ ) β π π₯ M ij β =β« Ξ© β N i β (x)N j β (x)dx Where:
π π π M ij β represents the entry in the mass matrix corresponding to basis functions π π ( π₯ ) N i β (x) and π π ( π₯ ) N j β (x). π π ( π₯ ) N i β (x) and π π ( π₯ ) N j β (x) are the linear basis functions (hat functions) defined over the elements. Formula for 1D Linear Basis Functions: For linear basis functions in 1D, the mass matrix entries are calculated using Gaussian quadrature (or analytically) over each element. For an element with length β h (which in 1D corresponds to β
Ξ π₯ h=Ξx), the mass matrix contributions are:
6 h β forΒ i ξ =j Where β h is the element length (or Ξ π₯ Ξx).
Mass Matrix Implementation: In the code, the mass matrix is assembled using these contributions. Here's the formula used:
6
1
β
β
h.
3.3. Properties of the Linear Basis Functions
3.3.1. Partition of Unity: The sum of all basis functions at any point
3.3.2. Locality: Each basis function is non-zero only in the elements adjacent to the node
3.3.2. Continuity: The piecewise linear basis functions are continuous, meaning they ensure that the solution
3.4. Time Discretization
For time integration, we use the forward Euler method:
This results in the update formula:
The solution is iteratively updated over the specified time steps.
3.5. Spatial Discretization
The domain is discretized into
- Mass Matrix: The mass matrix is constant and set initially. It represents how quantities are distributed over the elements.
- Stiffness Matrix: The stiffness matrix is assembled at each time step based on the current value of the solution
$u$ , making it dependent on the nonlinear diffusion coefficient$D(u)$ .