Awesome
CFDofReactiveFlows
Collection of codes in Matlab(R) and C++ for solving basic problems presented and discussed in the "Computational Fluid Dynamics of Reactive Flows" course (Politecnico di Milano)
1. Advection-diffusion equation in 1D with the Finite Difference (FD) method
The advection-diffusion equation is solved on a 1D domain using the finite-difference method. Constant, uniform velocity and diffusion coefficients are assumed. The forward (or explicit) Euler method is adopted for the time discretization, while spatial derivatives are discretized using 2nd-order, centered schemes.
- Matlab script: advection_diffusion_1d.m
- Matlab live script: advection_diffusion_1d_live.mlx
2. Advection-diffusion equation in 2D with the Finite Difference (FD) method
The advection-diffusion equation is solved on a 2D rectangular domain using the finite-difference method. Constant, uniform velocity components and diffusion coefficients are assumed. The forward (or explicit) Euler method is adopted for the time discretization, while spatial derivatives are discretized using 2nd-order, centered schemes.
- Matlab script: advection_diffusion_2d.m
- Matlab live script: advection_diffusion_2d_live.mlx
3. Poisson equation in 2D
The Poisson equation is solved on a 2D rectangular domain using the finite-difference method. A constant source term is initially adopted. Spatial derivatives are discretized using 2nd-order, centered schemes. Different methods are adopted for solving the equation: the Jacobi method, the Gauss-Siedler method, and the Successive Over-Relaxation (SOR) method
- Matlab script: poisson_2d.m
- Matlab live script: poisson_2d_live.mlx
The same Poisson equation is solved by explicitly assembling the sparse matrix corresponding to the linear system arising after the spatial discretization
- Matlab script: poisson_2d_matrix.m
4. Navier-Stokes equations in 2D: vorticity-streamline formulation
The Navier-Stokes equations for an incompressible fluid are solved on a 2D rectangular domain according to the vorticity-streamline formulation. The vorticity advection-diffusion equation is solved using the forward Euler method and 2nd order, centered spatial discretizations. The streamline function Poisson equation is solved using the Successive Over-Relaxation method and 2nd order, centered discretization for the spatial derivatives.
- Matlab script (square domain, uniform grid): driven_cavity_2d_vorticity.m
- Matlab live script (square domain, uniform grid): driven_cavity_2d_vorticity_live.mlx
- C++ code (square domain, uniform grid): driven_cavity_2d_vorticity.cpp
- Matlab script (rectangular domain, non-uniform grid): driven_cavity_2d_vorticity_nonuniform.m
5. Advection-diffusion equations in 1D with the Finite Volume (FV) method
The advection-diffusion equations are solved on a 1D domain using the finite volume method. Both explicit (forward) and implicit (backward) Euler methods are considered. Different discretization schemes for the advective term are implemented: centered, upwind, hybrid, power-law and QUICK.
- Diffusion equation with explicit (forward) Euler method and centered differencing scheme. Matlab script: diffusion_1d.m
- Diffusion equation with implicit (backward) Euler method and centered differencing scheme. Matlab script: diffusion_1d_implicit.m
- Steady-state advection-diffusion equation with implicit (backward) Euler method and several discretization schemes for the advective contribution (centered, upwind, hybrid, power-law). Matlab script: steady_advection_diffusion_1d_implicit.m
- Steady-state advection-diffusion equation with implicit (backward) Euler method and QUICK scheme for the discretization of the advective contribution. Matlab script: steady_advection_diffusion_1d_implicit_quick.m
6. Navier-Stokes equations in 2D: staggered grid and projection algorithm
The Navier-Stokes equations for an incompressible fluid are solved on a 2D rectangular domain meshed with a staggered grid. The momentum equations are solved using the forward Euler method and 2nd order, centered spatial discretizations. The projection algorithm is adopted for managing the coupling between pressure and velocity. In particular, the corresponding Poisson equation for pressure is solved using the Successive Over-Relaxation method and 2nd order, centered discretization for the spatial derivatives.
- Matlab script (square domain, uniform grid): driven_cavity_2d_staggered.m
- C++ code (square domain, uniform grid): driven_cavity_2d_staggered.cpp
- Matlab script (rectangular domain, non-uniform grid): driven_cavity_2d_staggered_nonuniform.m
Extensions/Modifications
- Addition of a passive scalar equation governed by the usual advection-diffusion equation without source terms. Passive scalar equation solved with the Finite Volume (FV) or Finite Difference (FD) methods. Matlab script (square domain, uniform grid, FV): driven_cavity_2d_staggered_passivescalar_fv.m. Matlab script (square domain, uniform grid, FD): driven_cavity_2d_staggered_passivescalar_fd.m.
- Addition of inflow and outflow boundaries along the west and east sides, respectively. Matlab script (square domain, uniform grid): driven_cavity_2d_staggered_inout.m
- Addition of inflow and outflow boundaries along the west and east sides, respectively (see above) and addition of a passive scalar equation. Matlab script (square domain, uniform grid): driven_cavity_2d_staggered_inout_passivescalar.m
- Addition of a rectangular obstacle inside the computational domain. Matlab script (square domain, uniform grid): driven_cavity_2d_staggered_obstacle.m
- Addition of buoyancy term in the momentum equation via Boussinesq approximation, together with a temperature equation. Matlab script (square domain, uniform grid): driven_cavity_2d_staggered_buoyancy.m
- Addition of local residence time equation. Matlab script (square domain, uniform grid): driven_cavity_2d_staggered_inout_tau.m
- Addition of automatic calculation of Residence Time Distribution (RTD) and Cumulative Distribution Function (CDF). Matlab script (square domain, uniform grid): driven_cavity_2d_staggered_rtd.m
- Solution of RANS equations for turbulent conditions using the Prandtl's k-l model (or Prandtl's 1-equation model). The k-l model requires the solution of one additional equation for the turbulent kinetic energy k. The turbulent length scale is assumed to be equal to the cell size. Matlab script (square domain, uniform grid): driven_cavity_2d_staggered_kl.m
- Solution of 2nd order reaction based on the linearization method. Two different implementations are available: 1) segregated: the equations of species are solved independently, without any coupling, according to the sequence: A, B, C; 2) coupled: the coupling between the species is retained in the eqations. Matlab scripts (square domain, uniform grid): driven_cavity_2d_staggered_2ndorder_reaction_linearization_segregation.m and driven_cavity_2d_staggered_2ndorder_reaction_linearization_coupling.m
- Solution of 2nd order reaction based on the operator-splitting method. Several techniques are included for the solution od ethe chemical step: LTS (explicit Local Time Stepping), linerations+segregation, analytical solution, solution via a Matlabe ode solver (such as
ode45
orode15s
). Matlab script (square domain, uniform grid): driven_cavity_2d_staggered_2ndorder_reaction_operator_splitting.m
7. Navier-Stokes equations in 2D: examples
Taylor-Green vortex in 2D
The Taylor-Green vortex is an exact closed form solution of 2D, incompressible Navier-Stokes equations. This 2D decaying vortex defined in the square domain, 0-2pi, serves as a benchmark problem for testing and validation of incompressible Navier-Stokes codes. The implementation here proposed is based on the Finite Volume Method (FV) applied on a staggered mesh and coupled with the Porjection Algorithm. Matlab script (square domain, uniform grid, FV): taylor_green_vortex_2d.m.
A. Utilities
Collection of utility functions for linear algebra, pre- and post-processing, analysis of data, etc.
- TDMA (TriDiagonal Matrix Algorithm) for solving tridiagonal linear systems of equations. Matlab script: tridiagonal.m
B. Homework
Homework 1
Numerical solution of advection-diffusion equation in 1D using the Forward Euler method and the centered 2nd order finite-differencing scheme. Comparison with analytical solutions.
- Text: homework1.pdf
- Matlab script: homework1.m
Homework 3
Numerical solution of Poisson and advection-diffusion equation in 2D using the the finite-differencing scheme. Comparison with analytical solutions.
- Text: homework3.pdf
- Matlab script: homework3_poisson.m
- Matlab script: homework3_advdiff.m
Homework 4
Numerical solution of Navier-Stokes equations via the vorticity-streamline function method. Application to the driven cavity test case.
- Text: homework4.pdf
- Matlab script: homework4_southwall.m
- Matlab script: homework4_cutdomain.m
- Matlab script: homework4_nonuniform.m