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
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.
- 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$ .
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.
To derive the weak form, we multiply the original equation by a test function
Using Galerkin FEM, the solution
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}$ .
Properties of the Linear Basis Functions
Partition of Unity: The sum of all basis functions at any point
Locality: Each basis function is non-zero only in the elements adjacent to the node
Continuity: The piecewise linear basis functions are continuous, meaning they ensure that the solution
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 variable and assembles at each time step based on the current value of the solution
$u$ , making it dependent on the nonlinear diffusion coefficient$D(u)$ .
To form the mass matrix, we integrate over the domain using the basis functions:
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 linear basis functions (hat functions) defined over the elements.
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
Where
- Diagonal terms
$M_{ii}=\frac{2}{3}h$ - Off-diagonal terms
$M_{i,i-1}=M_{i-1,i}=\frac{1}{6}h$
The stiffness matrix
Where:
-
$D(u)$ is the nonlinear diffusion coefficient (a function of$u$ ). -
$\frac{\partial N_i(x)}{\partial x}$ and$\frac{\partial N_j(x)}{\partial x}$ are the derivatives of the basis functions, which are constant for linear basis functions.
For linear basis functions, the derivatives are constant within each element, so the stiffness matrix entries are:
Where
- Diagonal terms
$K_{ii}=\frac{2D(u)}{h}$ . - Off-diagonal terms
$K_{ij}=-\frac{D(u)}{h}$ .
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.
Licensed under the Creative Commons Attribution-NoDerivatives 4.0 International License.
To view a copy of this license, visit https://creativecommons.org/licenses/by-nd/4.0/.