# FEM Optimization for 1D PDE

**Date published:**Sep 8, 2021

**Last updated:**Jan 25, 2022

PDF | GitHub

Full treatment is in the linked PDF and GitHub repo. This page summarizes the main ideas.

## Description

The project’s full title is:

Finite Element Analysis of a 1D Convection–Diffusion ProblemFormulation, Implementation, and Optimization

## Problem Statement

Suppose that an ionic fluid is trapped between two flat parallel electrodes. The fluid cations are propelled by the cathode and attracted by the anode. The objective is to determine the cation concentration $C$ at any point in space between the two electrodes.

The cation flow is assumed one-dimensional and perpendicular to the plates. The cation concentration $C$ at any point $x$ between the plates is governed by **Diffusion** and **Convection**. Diffusion depends on the fluid diffusivity $D$ whereas convection depends on the flow velocity $u$.

The governing PDE commonly used to model the cation concentration between the plates is the Convection–Diffusion equation: $$ \frac{\partial C}{\partial t} = \nabla \cdot (D \nabla C) - \nabla \cdot (C\mathbf{u} ) + R $$ Our setting is steady-state $(\frac{\partial}{\partial t}C = 0)$, one-dimensional $(\nabla = \frac{\partial}{\partial x} \widehat{\mathbf{i}})$, without sources nor sinks $(R = 0)$. Thus, this PDE is equivalent to, $$ -\frac{\partial}{\partial x}\left(D \frac{\partial C}{\partial x}\right) + u \frac{\partial C}{\partial x} = 0 \qquad \textrm{for } x \in (0, L) $$ where $D$, $u$, and $L \in \R$ are given constants.

The boundary conditions are, $$ C(x=0) = 0 \; \mathrm{mol \cdot m^{-3}} \qquad C(x=L) = 1 \; \mathrm{mol \cdot m^{-3}} $$ Assume $L = 1 \; \mathrm{m}$, $D = 2 \; \mathrm{m^2 \cdot s^{-1}}$, and $u = 10 \; \mathrm{m \cdot s^{-1}}$.

## Project Summary

A weak-form **Galerkin formulation** is used for the finite element analysis of this PDE. In the numerical implementation, the total number of elements $N$ is inputted by the user. The mesh size is deduced from the number $N$ of elements. The interpolation order is quadratic. Numerical integration is performed using the **Gauss–Legendre Quadrature** method. A **sparse matrix structure** is implemented. The assembly procedure is carried out using an optimized connectivity matrix. The system is solved with a direct sparse linear solver. A **convergence analysis** with respect to the mesh size is performed. The same model is built using *COMSOL*, while the exact solution is obtained using *Mathematica*. The three solutions are compared.

## Figures

These two figures summarize the project results.

In this first figure, the FEM solution is shown to converge as the number $N$ of elements grows; notice that for larger values of $N$, the solution values vary little.

In this second figure, the implemented FEM solution, comparative COMSOL solution, and exact PDE solution are compared. As shown, with the optimizations, a quick solution can be obtained for relatively small $N$ that approximates the exact solution very well.

## References

Koutromanos, *Fundamentals of Finite Element Analysis*, 2018.