Module 5: Finite Volume Method from First Principles
Derive the finite volume method from conservation laws. Learn control-volume integration, face fluxes, diffusion and convection discretization, boundary conditions, conservation, and how to build a basic finite-volume solver in C++.
Introduction
In Module 3, we learned how to approximate derivatives on a discrete grid. In Module 4, we explored how these discrete equations become algebraic systems and how numerical solvers compute their solutions.
Now we will study one of the most widely used approaches for discretizing conservation equations in computational fluid dynamics: the finite volume method (FVM).
Finite volume methods are used in many CFD applications, including internal flows, external aerodynamics, heat transfer, combustion, multiphase flow, and industrial process simulations. They form the foundation of many established CFD software packages, including OpenFOAM and numerous commercial solvers.
The central idea is straightforward:
Instead of enforcing a differential equation only at individual points, we integrate the governing equation over a finite region of space and calculate the fluxes entering and leaving that region.
This approach connects the discrete equations directly to physical conservation.
We will begin with a one-dimensional conservation equation, derive a finite-volume balance, construct diffusion and convection terms, examine boundary conditions, and implement a simple steady heat-conduction solver in C++.
The goal is not merely to learn the formulas. It is to understand why the formulas take their particular form and how to build them into a numerical solver.
Learning Objectives
By the end of this module, you should be able to:
- Explain the physical meaning of a control volume.
- Derive the finite volume method from a conservation equation.
- Distinguish cell-centered unknowns, cell faces, and face fluxes.
- Integrate a one-dimensional conservation equation over a control volume.
- Discretize diffusion and convection terms.
- Derive the central-difference approximation for diffusion fluxes.
- Understand first-order upwind and central interpolation for convection.
- Explain how finite-volume methods incorporate boundary conditions.
- Understand local and global conservation in a numerical mesh.
- Implement a basic one-dimensional finite-volume heat-conduction solver in C++.
- Identify the limitations of a simple finite-volume implementation and plan the next steps toward a CFD solver.
1. Why Do We Need the Finite Volume Method?
Consider a fluid moving through a pipe.
Fluid enters through one section and leaves through another. If the pipe has no leaks and no mass is created or destroyed inside it, the mass entering must equal the mass leaving at steady state.
The same principle applies to energy. Heat can enter a region through one surface and leave through another. Internal heat generation can also add energy to the region.
These physical statements are conservation laws.
The finite volume method translates them into numerical equations by dividing the computational domain into small regions called control volumes.
Each control volume has:
- A finite volume of space.
- A set of boundary faces.
- Physical quantities stored or reconstructed within it.
- Fluxes crossing its faces.
- Sources or sinks acting inside it.
The method calculates the net effect of these contributions and constructs a discrete conservation equation.
A physical analogy
Imagine a water tank with several pipes connected to it. To determine whether the water level rises or falls, you do not need to know the exact water motion at every point inside the tank. You first need to know how much water enters, how much leaves, and whether there is any additional source or sink.
A finite volume calculation follows a similar principle, except that the control volumes are usually small regions of a computational mesh, and the conserved quantities can include mass, momentum, and energy.
Why this is important for CFD
A numerical method should not introduce artificial mass or energy merely because the domain has been divided into cells.
The finite volume method is particularly attractive because it expresses the governing equations as balances of fluxes and sources. With consistent face-flux calculations and assembly, contributions shared by neighboring cells cancel internally when the equations are summed over the domain.
This is a fundamental property of a conservative finite-volume discretization.
2. The General Conservation Equation
Many physical conservation laws can be expressed using a common mathematical structure.
Let be a transported quantity per unit mass. Examples include:
- for mass conservation.
- for one Cartesian component of momentum.
- for specific enthalpy in an appropriate energy formulation.
A general transport equation can be written as
where:
- is the fluid density.
- is the velocity vector.
- is the transported variable.
- is a diffusion coefficient.
- is a source term per unit volume.
- is time.
The terms represent:
The signs follow the convention that a positive divergence represents net outward flux.
This equation is a useful model for learning the finite volume method. Actual governing equations may contain additional terms, different definitions of the transported variable, or specialized constitutive relations.
For example, momentum conservation includes pressure forces and viscous stresses. Energy conservation may contain pressure work, viscous dissipation, radiation, and other effects depending on the formulation.
The discretization process begins by identifying the conservation equation and the physical meaning of each term.
3. From a Differential Equation to an Integral Equation
The finite volume method begins with an integral balance.
For the general transport equation,
integrate over a fixed control volume :
For a fixed control volume, the time derivative can be moved outside the volume integral under the usual smoothness assumptions:
Apply the divergence theorem to the flux-divergence terms:
where is the control-volume surface and is its outward unit normal.
The integral equation becomes
This equation is central to the finite volume method.
It states that the rate of accumulation of the transported quantity, plus its net outward convective flux, equals its net inward diffusive contribution plus its internal source.
Why the divergence theorem matters
The divergence theorem converts a volume integral of a divergence into a surface integral of flux.
This means we can calculate the effect of convection and diffusion by evaluating what crosses the control-volume faces.
For a mesh made of many adjacent cells, each internal face is shared by two cells. A consistent numerical flux is calculated once conceptually and contributes with opposite signs to the neighboring cells.
That shared-face structure is what enables finite-volume schemes to preserve conservation across cell interfaces.
4. Constructing a One-Dimensional Computational Mesh
Consider a one-dimensional domain extending from to .
Divide the domain into equal-sized cells.
The cell width is
For a cell-centered finite-volume mesh, the cell centers are located at
The cell faces are located at
and
The index identifies the cell, while identifies the face between cells and .
Example
Suppose
Then
The cell centers are
The faces are located at
Notice that the boundary faces lie at and , but the first and last unknowns are stored at the cell centers.
This differs from the nodal grid used in the earlier finite-difference example.
Cell-centered storage
A simple implementation may store one value per cell:
std::vector<double> phi(N);
Here, phi[i] represents the cell-centered value of the transported variable in cell i, using zero-based C++ indexing.
Face fluxes may be stored separately:
std::vector<double> flux(N + 1);
There are faces for cells in a one-dimensional mesh, including the two domain boundaries.
This separation between cell values and face fluxes is fundamental to many finite-volume implementations.
5. The One-Dimensional Finite Volume Balance
Consider the steady one-dimensional transport equation
where is the total flux of the transported quantity per unit area and is a source per unit volume.
Integrate over cell , which extends from to :
By the fundamental theorem of calculus,
where:
- is the flux at the east face.
- is the flux at the west face.
If the source is approximately constant across the cell,
Therefore,
This is the discrete finite-volume balance for the one-dimensional cell.
The equation has a direct physical interpretation:
Net outward flux equals the source generated inside the cell.
If there is no source,
and therefore
The flux entering one side of the cell must equal the flux leaving the other side.
For a steady one-dimensional problem with no sources, this condition holds throughout the domain, so the flux is constant from cell to cell.
Extending the balance to multiple dimensions
For a general control volume, the integral balance is
A discrete approximation becomes
for a source that is approximately constant within cell .
Here, is the outward area vector of face , and is the cell volume.
For a planar face,
where is the face area.
The sum runs over the faces of the cell. This is the basic geometric structure used to assemble many finite-volume equations.
6. Diffusion: Deriving the Finite Volume Approximation
Diffusion transports a quantity down its gradient.
For heat conduction in a stationary solid, Fourier’s law states
where:
- is the conductive heat-flux vector.
- is the thermal conductivity.
- is the temperature.
For constant thermal conductivity, the steady heat-conduction equation with volumetric heat generation is
In one dimension,
For constant ,
If there is no internal heat generation,
Integrate over a finite volume:
This gives
The remaining task is to approximate the temperature gradients at the cell faces.
Approximating the east-face gradient
For a uniform grid, the east face lies between cell centers and .
The distance between the centers is , so a central approximation is
Similarly, at the west face,
Substitute these approximations into the integral equation:
Rearranging,
Since ,
This is the same interior discrete equation obtained from the finite-difference method for this particular uniform-grid, constant-property problem.
The important point is that we arrived at the equation by integrating the physical balance over a cell and approximating face fluxes.
The finite-volume derivation makes the role of fluxes explicit.
Diffusion coefficient in a general transport equation
For the diffusion term
the corresponding face contribution is approximated by
For a one-dimensional uniform grid with constant ,
This approximation is often called a central approximation of the face gradient.
On a nonuniform orthogonal mesh, the distance between neighboring cell centers replaces the uniform spacing. On non-orthogonal meshes, additional geometric corrections may be needed to accurately approximate the face-normal gradient.
7. Deriving the Algebraic Equation for Diffusion
Consider the steady one-dimensional diffusion equation with a source:
Integrating over cell gives
For constant and uniform spacing,
Multiply by :
Rearranging,
This equation connects the current cell value to its neighbors and the source term.
The same equation can be expressed using a common coefficient notation:
where:
- identifies the current cell.
- identifies the west neighbor.
- identifies the east neighbor.
- , , and are algebraic coefficients.
- collects source and boundary contributions.
For the source-free uniform-grid diffusion equation, a convenient coefficient form is
where
and , for the corresponding integrated diffusion equation with signs arranged so the central coefficient is positive.
Then
or
This is the finite-volume algebraic equation for the simple interior diffusion cell.
Different software packages may use different sign conventions and coefficient definitions. The essential requirement is that the assembled equation remains algebraically consistent with the original integrated balance.
8. Boundary Conditions in the Finite Volume Method
A finite-volume mesh includes boundary faces as well as internal faces. Boundary conditions determine the flux or variable value associated with those faces.
The treatment depends on the physical boundary condition.
8.1 Prescribed temperature: Dirichlet condition
Suppose the left wall has a specified temperature:
The first cell center is located at
The distance from the boundary face to the first cell center is therefore .
For constant conductivity, a linear-gradient approximation gives
The conductive flux at the boundary can then be approximated using Fourier’s law.
Notice that the boundary-to-cell-center distance is half the distance between two adjacent cell centers on a uniform mesh. Using the wrong distance changes the boundary flux and can introduce error.
8.2 Prescribed heat flux: Neumann condition
Suppose a wall has a specified normal heat flux:
The heat flux is prescribed directly at the boundary. Therefore, the boundary contribution to the finite-volume balance can be inserted from the known value, with the correct sign determined by the outward normal convention.
For an insulated wall,
so the boundary contributes no conductive heat flux.
This does not mean the temperature itself must be zero. It means that there is no heat transfer through that boundary.
8.3 Boundary contributions in the matrix
In a finite-volume solver, the boundary flux contributes to the cell equation.
For a prescribed temperature, the boundary face value can be related to the known wall temperature and the adjacent cell-center value. This generally produces both a coefficient multiplying the cell unknown and a contribution to the right-hand side.
For a prescribed heat flux, the known flux usually contributes directly to the right-hand side.
The exact algebra depends on the governing equation, the sign convention, and the way the source terms are represented.
Why boundary treatment deserves special attention
The interior equation is only one part of the discrete system. Boundary equations and face-flux calculations are equally important.
A solver can have a correct interior stencil and still produce incorrect results if the boundary faces are assembled incorrectly.
For this reason, boundary-condition tests should be part of every numerical solver’s verification process.
9. Convection: Transport by Fluid Motion
Diffusion transports quantities through gradients. Convection transports quantities through fluid motion.
For a transported scalar , the convective flux is
The flux crossing a face is
where:
- is the face density.
- is the face value of the transported quantity.
- is the face velocity.
- is the outward area vector.
For a one-dimensional flow through a face of area ,
The mass flow rate through the face is
so the convective flux becomes
The remaining challenge is determining the face value from the available cell-centered values.
This process is called interpolation or reconstruction.
Two fundamental choices are central differencing and upwind interpolation.
10. Central Interpolation for Convection
For a uniform grid, a central approximation of the face value between cells and is
The corresponding convective flux is
This approximation is second-order accurate for a smooth scalar field on a uniform grid when applied in the usual central-interpolation setting.
However, central interpolation does not account for the direction of the flow when estimating the face value.
For convection-dominated problems, this can produce oscillations or nonphysical undershoots and overshoots.
A central approximation is not inherently wrong, but its stability and suitability depend on the transport problem and the full discretization.
11. First-Order Upwind Interpolation
Upwind interpolation uses the value from the upstream side of a face.
The upstream side is the side from which the fluid is arriving.
For a one-dimensional face between cells and ,
For positive flow from west to east, the upstream cell is . For negative flow, the upstream cell is .
The convective flux is then
This scheme uses the flow direction to choose the face value.
Why upwind interpolation is useful
Upwind schemes generally behave robustly for convection-dominated transport because they account for the direction in which information is carried by the flow.
However, first-order upwind introduces numerical diffusion. Sharp gradients may be smeared over multiple cells.
For example, a transported temperature front may become artificially broadened even when the physical thermal diffusivity is small.
This is a discretization effect, not necessarily physical diffusion.
Numerical diffusion
Numerical diffusion is artificial smoothing introduced by the numerical approximation.
It can make a computation appear stable while reducing the accuracy of gradients, fronts, wakes, and other flow features.
Reducing numerical diffusion may require a finer mesh, a higher-order scheme, a flux-limited method, or another appropriate discretization strategy.
Higher-order schemes must still be selected carefully to avoid spurious oscillations near sharp gradients.
12. The Peclet Number and the Balance Between Convection and Diffusion
The relative importance of convection and diffusion can be characterized by a dimensionless number called the Peclet number.
For a characteristic length , velocity magnitude , density , and diffusion coefficient ,
Here, is the diffusion coefficient in the transport equation for .
For heat transfer in a fluid with constant properties, the thermal Peclet number can be written as
These expressions are dimensionless.
The interpretation is:
- : diffusion is dominant at the selected scale.
- : convection is dominant at the selected scale.
- of order one: both processes may be important.
The relevant length scale matters. A global Peclet number and a cell Peclet number do not necessarily have the same value.
For a uniform one-dimensional mesh, a commonly used cell Peclet number is
using signed , while its magnitude describes the strength of convection relative to diffusion.
The cell Peclet number helps explain why a discretization that works well on a diffusion-dominated problem may behave poorly when the mesh is coarse and convection dominates.
A first-order upwind scheme is generally robust but can be diffusive. Central differencing can be more accurate for smooth fields but may produce oscillations for sufficiently convection-dominated discretizations.
13. Combining Convection and Diffusion
Consider the steady one-dimensional convection–diffusion equation with constant coefficients and no source:
Define the total flux:
The conservation equation becomes
Integrating over cell ,
or
The total flux remains constant across the cell.
At each face, the total flux contains two contributions:
where is the convective contribution and is the diffusive contribution.
The discrete equation for the cell is obtained by calculating the east and west fluxes and enforcing the conservation balance.
A practical interpretation
Imagine warm fluid moving through a cooled channel.
Convection carries heat downstream with the moving fluid. Diffusion transfers heat down the temperature gradient.
The resulting temperature field depends on the competition between these two mechanisms, the boundary conditions, and any internal heat sources.
A finite-volume discretization represents these effects through face fluxes rather than treating convection and diffusion as unrelated pointwise derivatives.
14. Conservation Across Neighboring Cells
Consider two adjacent control volumes, and , sharing one internal face.
Let the flux from toward be .
For cell , the flux contributes as an outward flux:
For cell , the same physical flux contributes as an inward flux, or equivalently as a negative outward flux:
When the equations for the two cells are added, these internal-face contributions cancel:
This cancellation extends to all internal faces in a multi-cell mesh.
When the equations are summed over the entire computational domain, only the fluxes crossing the external boundary remain, along with accumulation and source terms.
This is the basis of global conservation in a conservative finite-volume method.
Local and global conservation
Local conservation means that each control volume satisfies its discrete balance.
Global conservation means that the sum of the discrete balances over the domain is consistent with the net boundary fluxes, accumulation, and sources.
These properties depend on consistent flux definitions and assembly. They do not automatically guarantee that the numerical solution is accurate or physically correct.
For example, a conservative calculation can still use an unsuitable turbulence model or an excessively coarse mesh.
Conservation is necessary for a reliable CFD simulation, but it is not sufficient on its own.
15. A Complete Example: Steady One-Dimensional Heat Conduction
We will now assemble a finite-volume model for a solid wall with prescribed temperatures at both ends.
The physical problem is
with boundary conditions
Assume:
- Constant thermal conductivity .
- No internal heat generation.
- Steady state.
- One-dimensional conduction.
- A uniform cell-centered mesh.
The analytical solution is
This provides a reference for testing the numerical solver.
Step 1: Define the mesh
Divide the domain into cells:
The cell centers are
for .
Step 2: Integrate the equation over a cell
For an interior cell,
Step 3: Approximate the internal face gradients
For a uniform mesh,
and
Thus,
for an interior cell.
Step 4: Treat the left boundary
The left boundary lies from the first cell center.
The eastward temperature gradient at the boundary is approximated by
The factor of two comes from the half-cell distance.
The resulting first-cell equation, after arranging the terms consistently, is
Step 5: Treat the right boundary
Similarly, the right boundary lies from the final cell center.
The final-cell equation becomes
Step 6: Assemble the complete system
For , the matrix system is
For , the matrix consists only of the first and last rows:
The matrix coefficients result from integrating the diffusion equation and applying the boundary-gradient approximations.
Notice that the conductivity and cell spacing cancel in this constant-property, uniform-grid problem. In a general diffusion problem, the coefficients depend on conductivity, geometry, and the distances between cell centers and faces.
Important boundary distinction
The boundary equations above are specific to the cell-centered mesh, constant conductivity, uniform spacing, and prescribed-temperature boundaries. They should not be copied unchanged into every finite-volume problem.
Different meshes, material properties, source terms, or boundary conditions lead to different coefficient formulas.
16. Implementing the Finite Volume Heat Solver in C++
We will implement a complete solver for the one-dimensional steady heat-conduction problem.
The code will:
- Define the physical domain and boundary temperatures.
- Create a uniform cell-centered mesh.
- Assemble the tridiagonal finite-volume equations.
- Solve the equations using the Thomas algorithm.
- Compare the computed temperatures with the analytical solution.
- Write the results to a CSV file for plotting.
The Thomas algorithm is a specialized direct solver for tridiagonal linear systems. It is more efficient than applying general dense Gaussian elimination to this problem.
For a tridiagonal system,
the algorithm performs a forward elimination followed by back substitution.
Its computational cost is proportional to the number of cells, , and its memory requirements are also .
Create a file named finite_volume_heat.cpp.
#include <cmath>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <stdexcept>
#include <vector>
int main()
{
// Physical properties and domain.
const double length = 1.0;
const double conductivity = 10.0;
const double leftTemperature = 100.0;
const double rightTemperature = 20.0;
// Number of finite volumes.
const int N = 20;
if (N < 2)
{
std::cerr << "Error: use at least two cells.\n";
return 1;
}
if (length <= 0.0 || conductivity <= 0.0)
{
std::cerr << "Error: length and conductivity "
"must be positive.\n";
return 1;
}
const double dx = length / N;
// Cell-center coordinates and numerical solution.
std::vector<double> x(N);
std::vector<double> T(N, 0.0);
for (int i = 0; i < N; ++i)
{
x[i] = (i + 0.5) * dx;
}
// Tridiagonal system:
// a[i] * T[i-1] + b[i] * T[i]
// + c[i] * T[i+1] = d[i]
std::vector<double> a(N, 0.0);
std::vector<double> b(N, 0.0);
std::vector<double> c(N, 0.0);
std::vector<double> d(N, 0.0);
// Diffusion conductance between neighboring cell centers.
const double D = conductivity / dx;
// First cell: prescribed temperature at the west boundary.
b[0] = 3.0 * D;
c[0] = -D;
d[0] = 2.0 * D * leftTemperature;
// Interior cells.
for (int i = 1; i < N - 1; ++i)
{
a[i] = -D;
b[i] = 2.0 * D;
c[i] = -D;
d[i] = 0.0;
}
// Last cell: prescribed temperature at the east boundary.
a[N - 1] = -D;
b[N - 1] = 3.0 * D;
d[N - 1] = 2.0 * D * rightTemperature;
// Thomas algorithm: forward elimination.
for (int i = 1; i < N; ++i)
{
if (std::abs(b[i - 1]) < 1.0e-14)
{
std::cerr << "Error: near-zero pivot encountered.\n";
return 1;
}
const double factor = a[i] / b[i - 1];
b[i] -= factor * c[i - 1];
d[i] -= factor * d[i - 1];
}
if (std::abs(b[N - 1]) < 1.0e-14)
{
std::cerr << "Error: near-zero final pivot.\n";
return 1;
}
// Thomas algorithm: back substitution.
T[N - 1] = d[N - 1] / b[N - 1];
for (int i = N - 2; i >= 0; --i)
{
if (std::abs(b[i]) < 1.0e-14)
{
std::cerr << "Error: near-zero pivot encountered.\n";
return 1;
}
T[i] = (d[i] - c[i] * T[i + 1]) / b[i];
}
// Compare against the analytical solution.
double maximumError = 0.0;
for (int i = 0; i < N; ++i)
{
const double exact =
leftTemperature
+ (rightTemperature - leftTemperature)
* x[i] / length;
const double error = std::abs(T[i] - exact);
if (error > maximumError)
{
maximumError = error;
}
}
// Write the solution to CSV.
std::ofstream file("temperature.csv");
if (!file)
{
std::cerr << "Error: could not open temperature.csv.\n";
return 1;
}
file << "x,temperature_numerical,temperature_exact\n";
file << std::setprecision(12);
for (int i = 0; i < N; ++i)
{
const double exact =
leftTemperature
+ (rightTemperature - leftTemperature)
* x[i] / length;
file << x[i] << ','
<< T[i] << ','
<< exact << '\n';
}
file.close();
std::cout << std::fixed << std::setprecision(8);
std::cout << "Finite Volume Heat Conduction\n";
std::cout << "-----------------------------\n";
std::cout << "Cells: " << N << '\n';
std::cout << "Cell width: " << dx << " m\n";
std::cout << "Left temperature: "
<< leftTemperature << " C\n";
std::cout << "Right temperature: "
<< rightTemperature << " C\n";
std::cout << "Maximum absolute error: "
<< maximumError << " C\n";
std::cout << "Results written to temperature.csv\n";
return 0;
}
Understanding the implementation
Mesh construction
The cell centers are located at
when using zero-based indexing.
This differs from the one-based mathematical notation used earlier, but both describe the same cell-centered mesh.
Coefficient assembly
The interior-cell coefficients are
where
The first and last cells use a coefficient of on the diagonal and or on the right-hand side. These coefficients account for the half-cell distance to the prescribed-temperature boundary.
Direct solution
The Thomas algorithm modifies the diagonal coefficients and right-hand-side vector during forward elimination. Back substitution then calculates the cell temperatures from the final cell to the first.
This is a direct solution of the assembled algebraic system. Unlike Jacobi iteration, it does not need a residual-based iteration loop.
Analytical comparison
The exact temperature distribution is
for the chosen domain and boundary temperatures.
The maximum error is calculated at the cell centers:
For this linear, constant-property problem, the computed cell-center values should agree with the analytical solution to floating-point precision, assuming the matrix assembly and implementation are correct.
This exact agreement is a useful verification result, but it does not prove that the solver is correct for nonlinear equations, nonuniform meshes, variable conductivity, or other boundary conditions.
Compile and run
Using GCC:
g++ -std=c++20 -O2 -Wall -Wextra -pedantic finite_volume_heat.cpp -o finite_volume_heat
On Linux or WSL:
./finite_volume_heat
On Windows PowerShell:
.\finite_volume_heat.exe
The program generates temperature.csv in the current working directory.
The file contains three columns:
x: cell-center coordinate.temperature_numerical: finite-volume solution.temperature_exact: analytical reference solution.
You can plot the numerical and analytical temperatures using Python, Excel, MATLAB, or another plotting tool.
17. Verification: How Do We Know the Finite Volume Solver Is Correct?
A numerical result should not be trusted merely because it looks reasonable.
For the current problem, we have an analytical solution:
We can compare the numerical solution against this expression at every cell center.
Maximum absolute error
The maximum absolute error is
Root-mean-square error
Another useful measure is the root-mean-square error:
Both measures quantify differences between the computed solution and the analytical reference.
For this particular problem, both should be very small, generally near the scale of floating-point rounding error.
Why this is a special test
The exact solution is linear in space, so the constant-gradient approximation is exact for this problem. The discrete equations therefore reproduce the analytical cell-center values up to floating-point error.
This makes the problem an excellent test of:
- Mesh construction.
- Boundary coefficient assembly.
- Matrix solution.
- Cell-center coordinates.
- Output and error calculations.
However, because the expected solution is linear, it does not test the solver’s accuracy for a curved temperature profile.
A more demanding follow-up test
Add a uniform volumetric heat-generation term .
The steady heat-conduction equation becomes
For constant , the analytical solution is
The additional quadratic term creates a curved temperature profile.
A finite-volume implementation should now be tested against this analytical solution. The source term must be integrated consistently into the discrete equations.
This is a useful next verification exercise because it tests more than the linear profile.
18. Important Limitations of This Solver
The code above is deliberately simple. It demonstrates the core finite-volume process, but it is not a general-purpose CFD solver.
Its limitations include:
- One-dimensional geometry.
- Steady-state heat conduction only.
- Constant thermal conductivity.
- Uniform cell spacing.
- No internal heat generation in the implemented example.
- Prescribed temperatures at both boundaries.
- A specialized tridiagonal linear solver.
- No general mesh or boundary-condition framework.
- No transient solution, fluid motion, or pressure–velocity coupling.
These limitations are intentional. A reliable numerical code should be developed incrementally, with each new feature supported by a suitable verification test.
For a larger CFD project, the same fundamental structure can be extended to multiple dimensions, nonuniform meshes, variable properties, transient equations, advection–diffusion, and coupled momentum and pressure equations.
19. How Finite Volume Fits into OpenFOAM and Other CFD Solvers
The finite volume method provides the mathematical framework for converting conservation laws into cell-based algebraic equations.
A typical finite-volume CFD workflow involves:
- Creating a computational mesh.
- Defining physical properties and boundary conditions.
- Identifying the governing conservation equations.
- Integrating the equations over the control volumes.
- Calculating face fluxes and source contributions.
- Assembling algebraic equations for the unknown fields.
- Solving the equations.
- Updating coupled variables where necessary.
- Monitoring residuals, conservation, and physical quantities.
- Verifying and validating the results.
In OpenFOAM, this process is implemented through its mesh and field data structures, discretization schemes, finite-volume operators, equation-assembly mechanisms, and linear-solver infrastructure.
For example, an expression such as
fvm::laplacian(k, T)
represents an implicit finite-volume discretization of a diffusion operator in an OpenFOAM equation.
An expression such as
fvm::div(phi, T)
represents an implicit discretization of a divergence or transport operator, depending on the field and scheme configuration.
These operators are part of a larger framework that assembles equations and connects them to appropriate numerical solvers. Their exact behavior depends on the field types, dimensions, schemes, and boundary conditions.
Understanding the derivation behind these operators helps you reason about what the software is calculating instead of treating the code as a collection of unexplained commands.
20. Common Mistakes in Finite Volume Discretization
Mistake 1: Confusing cells with grid points
In a cell-centered finite-volume method, the main unknowns are usually stored at cell centers, while fluxes are evaluated at cell faces.
The mesh indexing and distances must reflect that distinction.
Mistake 2: Forgetting the face area
In multiple dimensions, a flux density must be multiplied by the relevant face area to obtain the flux crossing the face.
For example,
is the mass flow rate through a face when is the outward area vector.
Ignoring the area can produce dimensional and physical errors.
Mistake 3: Using the wrong sign for a flux
An outward flux from one cell is an inward flux into its neighbor.
The same internal face must contribute consistently to both cell equations.
Mistake 4: Ignoring half-cell distances at boundaries
For a uniform cell-centered mesh, the boundary face is only from the adjacent cell center.
Using instead changes the boundary conductance and can produce an incorrect temperature field.
Mistake 5: Assuming central interpolation always works for convection
Central interpolation can be accurate for smooth fields but may generate oscillations in convection-dominated cases.
The convection scheme must be chosen with the mesh, flow regime, and accuracy requirements in mind.
Mistake 6: Confusing numerical diffusion with physical diffusion
A coarse mesh and a diffusive convection scheme can smear a sharp transported front beyond what physical diffusion predicts.
This effect should be investigated through mesh refinement and scheme comparisons.
Mistake 7: Assuming conservation guarantees accuracy
A scheme can conserve mass or energy while still having substantial discretization error.
Conservation checks should be combined with analytical tests, grid-refinement studies, and comparison with trusted reference data.
Key Takeaways
- The finite volume method begins by integrating conservation equations over finite control volumes.
- The divergence theorem converts volume integrals of flux divergences into surface fluxes.
- A finite-volume cell equation balances accumulation, net face fluxes, and internal sources.
- Cell-centered unknowns and face-centered fluxes play different roles in the discretization.
- Diffusion fluxes are calculated from gradients at cell faces.
- Convective fluxes depend on both the face mass flow rate and the transported variable at that face.
- Central interpolation and upwind interpolation have different accuracy and stability characteristics.
- The Peclet number helps describe the relative importance of convection and diffusion.
- Consistent shared-face fluxes enable local and global conservation.
- Boundary conditions modify boundary fluxes and the coefficients of adjacent cell equations.
- A simple finite-volume diffusion equation can be assembled into a tridiagonal algebraic system.
- Analytical solutions and systematic verification tests are essential when developing a CFD solver.
- The finite volume framework used in OpenFOAM and other CFD software follows the same fundamental conservation principles, although practical implementations include much more sophisticated numerical machinery.
What’s Next?
In Module 6: Transient Numerical Methods and Time Integration, we will extend the finite-volume framework to time-dependent problems.
We will derive explicit and implicit time discretization, explore the relationship between time-step size and stability, introduce the Courant–Friedrichs–Lewy (CFL) condition, and implement a transient heat-diffusion solver.
This will connect spatial discretization to time advancement and bring us closer to implementing a complete numerical simulation.