Skip to content

Finite volume method to solve some basic partial differential equations numerically

Notifications You must be signed in to change notification settings

BMW009A/FVM-CPP

Repository files navigation

Finite Volume Method Examples

This repo starts from the heat conduction equation, and end up with SIMPLE algorithm step by step. Also there will be some detailed documents to describe the math process and coding structure in case the author may forget something.

2D Diffusion equation

The govern equation is:

$$\frac{\partial T}{\partial t} = \alpha \left( \frac{\partial^2 T}{\partial x^2} + \frac{\partial^2 T}{\partial y^2} \right) \quad (1)$$

The finite difference approximation for the 2D heat equation is:

$$\frac{T_{i,j}^{n+1} - T_{i,j}^n}{\Delta t} = \alpha \left( \frac{T^n_{i+1,j} - 2T^n_{i,j} + T^n_{i-1,j}}{\Delta x^2} + \frac{T^n_{i,j+1} - 2T^n_{i,j} + T^n_{i,j-1}}{\Delta y^2} \right) \quad (2)$$

Euler Explicit Scheme

$$T_{i,j}^{n+1} = T^n_{i,j} + \alpha \Delta t \left( \frac{T^n_{i+1,j} - 2T^n_{i,j} + T^n_{i-1,j}}{\Delta x^2} + \frac{T^n_{i,j+1} - 2T^n_{i,j} + T^n_{i,j-1}}{\Delta y^2} \right) \quad (3)$$

Euler Implicit Scheme

$$\frac{T_{i,j}^{n+1} - T_{i,j}^n}{\Delta t} = \alpha \left( \frac{T_{i+1,j}^{n+1} - 2T_{i,j}^{n+1} + T_{i-1,j}^{n+1}}{\Delta x^2} + \frac{T_{i,j+1}^{n+1} - 2T_{i,j}^{n+1} + T_{i,j-1}^{n+1}}{\Delta y^2} \right) \quad (4)$$

Crank-Nicolson Scheme

$$\frac{T_{i,j}^{n+1} - T_{i,j}^n}{\Delta t} = \frac{\alpha}{2} \left( \frac{T_{i+1,j}^{n+1} - 2T_{i,j}^{n+1} + T_{i-1,j}^{n+1}}{\Delta x^2} + \frac{T_{i+1,j}^n - 2T_{i,j}^n + T_{i-1,j}^n}{\Delta x^2} \right) + \frac{\alpha}{2} \left( \frac{T_{i,j+1}^{n+1} - 2T_{i,j}^{n+1} + T_{i,j-1}^{n+1}}{\Delta y^2} + \frac{T_{i,j+1}^n - 2T_{i,j}^n + T_{i,j-1}^n}{\Delta y^2} \right) \quad (6)$$

3D Diffusion equation

The govern equation is:

$$\frac{\partial T}{\partial t} = \alpha \left( \frac{\partial^2 T}{\partial x^2} + \frac{\partial^2 T}{\partial y^2} + \frac{\partial^2 T}{\partial z^2} \right) \quad (6)$$

Explicit Scheme

Implicit Scheme

Advection equation

$$\frac{\partial \phi}{\partial t} + u \frac{\partial \phi}{\partial x} + v \frac{\partial \phi}{\partial y} + w \frac{\partial \phi}{\partial z} = 0 \quad (7)$$

Advection-Diffusion equation

$$\frac{\partial \phi}{\partial t} + u \frac{\partial \phi}{\partial x} + v \frac{\partial \phi}{\partial y} + w \frac{\partial \phi}{\partial z} = D \left( \frac{\partial^2 \phi}{\partial x^2} + \frac{\partial^2 \phi}{\partial y^2} + \frac{\partial^2 \phi}{\partial z^2} \right) \quad (8)$$

Navier-Stokes equations in 2D under Cartesian Coordinates (SIMPLE algorithm)

$$\rho \left( \frac{\partial \mathbf{u}}{\partial t} + (\mathbf{u} \cdot \nabla) \mathbf{u} \right) = -\nabla p + \mu \nabla^2 \mathbf{u} + \mathbf{f} \quad (9)$$

$$\nabla \cdot \mathbf{u} = 0 \quad (9b)$$

Lid-Driven Cavity Flow

Lid-Driven Cavity Flow

Flow Over a Cylinder(an Airfoil)

Backward Facing Step

Numerical Linear Algebra (in C)

This module provides essential utility functions for linear algebra operations, implemented in C for efficiency and compatibility. These utilities support the main Finite Volume Method (FVM) part of the project, which is in C++. This module includes:

  • Sparse Matrix Storage: Implements the Compressed Row Storage (CRS) format for efficient handling of sparse matrices.
  • Matrix-Vector Multiplication: Optimized functions for performing matrix-vector multiplication, suitable for
  • both dense and sparse matrices.
  • Linear System Solvers: Contains iterative solvers for linear systems, including Preconditioned Conjugate Gradient (PCG),
  • Biconjugate Gradient Stabilized (BiCGSTAB), and Algebraic Multigrid (AMG) methods, designed to handle large, sparse matrices efficiently.

These utilities are optimized for performance and tailored to the matrix operations commonly encountered in FVM-based simulations.

AT THE END

This project serves as a comprehensive practice ground for numerical simulation, C++ coding, and parallel computing techniques. My goal is to incorporate detailed documentation, both within the code and in supplementary descriptions, to provide clarity and aid understanding for myself and others who may review this project.

Feedback and suggestions are warmly welcome! If you have any ideas or improvements, please don’t hesitate to reach out.

About

Finite volume method to solve some basic partial differential equations numerically

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published