Solve the 1D steady diffusion equation with the finite volume method (FVM). The domain is split into control-volume cells, a flux budget is written for every cell to assemble a tridiagonal system, and that system is solved with the Thomas algorithm. Change the number of control volumes or the source term to see the cell-centre profile, the error against the analytical solution and the convergence behaviour update in real time.
Parameters
Number of control volumes N
Count of equal-width cells the domain is split into
Diffusion coefficient Γ
Coefficient corresponding to thermal conductivity or diffusivity
Domain length L
m
Left boundary value φL
Value of φ fixed at x=0 (Dirichlet)
Right boundary value φR
Value of φ fixed at x=L (Dirichlet)
Volumetric source term S
Uniform generation/consumption per cell. 0 gives a linear solution, ≠0 a parabola
Results
—
Control volumes N
—
Cell width Δx (m)
—
φ at the central cell
—
Left-boundary diffusive flux
—
Max error vs analytical
—
Effect of the source term
—
Control-volume cells and the φ profile
The domain is split into N control-volume cells; the φ found at each cell-centre node (white dot) is shown as a bar. The blue frames at both ends are the fixed boundary values φL and φR. The colour pulse suggests the iterative solve.
The 1D steady diffusion equation. Γ: diffusion coefficient, φ: the scalar to be found, S: volumetric source term. Dirichlet boundary conditions φ(0)=φL and φ(L)=φR are imposed at both ends.
The discretised balance equation for each control volume (cell P). a_W and a_E are the west and east face conductances (Γ/Δx for interior faces, 2Γ/Δx for boundary faces), Δx: cell width. Through this equation FVM satisfies the conservation law exactly on every control volume.
The exact solution for a uniform source term: a straight line when S=0, a parabola when S≠0. The tool evaluates the maximum error from the difference between this exact solution and the numerical solution at the cell centres.
What is the Finite Volume Method?
🙋
I have heard the name "finite volume method", but how is it different from the finite difference method? Both solve differential equations, right?
🎓
Good question. The finite difference method replaces derivatives themselves with differences from a Taylor series. The finite volume method (FVM) takes a slightly different angle. You split the domain into little boxes called "control volumes" and, for each box, you write the budget of "how much comes in versus how much goes out". So rather than solving a differential equation directly, you assemble a conservation law box by box, with simple additions.
🙋
Taking a budget for each box... does that buy you anything?
🎓
The biggest benefit is "conservation". Two neighbouring boxes share one face, right? In FVM, the flux leaving the left box and the flux entering the right box are always evaluated with the exact same expression. So when you add everything up they cancel perfectly, and conservation holds cleanly across the whole domain. Heat or mass never quietly vanishes or appears out of nowhere. That is why FVM is the standard in CFD. In the "control-volume cells" picture above, you can literally see those boxes lined up.
🙋
I see. Even when I set N to 8 in this tool, the error against the analytical solution comes out almost zero. Is it actually computing correctly?
🎓
That is actually proof that it is computing correctly. When the source term S=0, the exact solution of steady diffusion is a straight line running from the left value to the right value. The central-difference flux evaluation that FVM uses can reproduce a straight line perfectly, so no error appears even on a coarse mesh. Try setting the source term S to around 30. Now the exact solution becomes a parabola, and a finite cell width does produce an error. Look at the "max error vs N" chart below: the error falls as you increase N.
🙋
I see, adding S makes it a parabola. Does that error keep getting smaller and smaller as I increase N?
🎓
Yes. This scheme is second-order accurate, so halving the cell width Δx cuts the error to about a quarter. The way the chart curve keeps approaching zero is the evidence. In a real analysis, though, a finer mesh also costs more computation. So judging "how fine is fine enough" matters, and that check is called a grid (mesh) dependence study. This tool is exactly a practice ground for feeling that relationship.
🙋
One last thing. You mentioned a tridiagonal matrix and the Thomas algorithm — what are those?
🎓
In 1D FVM, each cell only relates to three things: itself, its left neighbour and its right neighbour. So the coefficient matrix of the linear system has entries only on the diagonal and the lines just above and below it — a "tridiagonal matrix". That is far easier to solve than a general matrix. The Thomas algorithm is a solver dedicated to tridiagonal systems, and its work scales only with the number of cells. So even N=30 solves in an instant. FVM being lightweight to implement is partly thanks to this matrix structure.
Frequently Asked Questions
The finite difference method approximates the derivative terms of a differential equation with Taylor-series differences. The finite volume method instead splits the domain into cells called control volumes and writes a conservation balance (the budget of fluxes in and out) directly for each cell. The key strength of FVM is that the flux is exactly conserved within every cell: on the shared face between two neighbouring cells, the outgoing flux and the incoming flux are always evaluated by the same expression, so conservation cannot be broken even across the whole domain. That is why FVM is the standard choice in fluid dynamics (CFD), where the conservation of heat, mass and momentum is essential.
It solves the 1D steady diffusion equation d/dx(Γ dφ/dx) + S = 0 on the interval [0,L] with Dirichlet boundary conditions φ(0)=φL and φ(L)=φR. The domain is split into N equal control volumes and φ is evaluated at each cell centre (the cell-centred method). The conductance of an interior face is Γ/Δx, while a boundary face is 2Γ/Δx because the distance from a cell centre to the boundary is only half a cell. From these the tridiagonal system A·φ = b is assembled and solved with the Thomas algorithm.
When the source term S=0, the exact solution of the steady diffusion equation is the straight line φ(x)=φL+(φR−φL)x/L. The central-difference flux evaluation used by FVM can reproduce a linear function exactly, so the discrete solution matches the exact solution at the cell centres and the maximum error is essentially zero (round-off level). When S≠0 the exact solution becomes a parabola and a finite cell width introduces a discretisation error. That error decreases with second-order accuracy as the number of control volumes N increases.
This tool handles only Dirichlet boundary conditions, which fix the value at each end. In practice you also need Neumann boundary conditions, which fix the flux (gradient), and Robin boundary conditions, such as convective heat transfer. FVM handles all of these naturally. For a Neumann boundary you supply the boundary-face flux directly into b and set the boundary-side conductance of the boundary cell to zero. For a Robin boundary you set an effective conductance that includes the transfer coefficient on the boundary face. The advantage of FVM is that all of them are handled in the same framework — namely, how the flux is supplied into the cell balance equation.
Real-World Applications
Heat conduction analysis: The steady diffusion equation is also the steady heat conduction equation as it stands. Read Γ as thermal conductivity, φ as temperature and S as internal heat generation, and it applies directly to the temperature distribution in walls and pipe insulation, the heat dissipation of electronic components and the assessment of insulation performance. Because FVM takes the heat budget of every cell exactly, the consistency of the heat fluxes in and out is guaranteed, and an energy-balance check is easy.
The foundation of CFD (computational fluid dynamics): The major CFD solvers — OpenFOAM, ANSYS Fluent, STAR-CCM+ — are nearly all based on the finite volume method. A real flow analysis adds convection and pressure terms to the diffusion term treated here, but the skeleton of "taking a flux budget per control volume" is exactly the same. This 1D diffusion problem is the most basic starting point for understanding complex CFD.
Mass diffusion and concentration distributions: Read Γ as a diffusion coefficient and φ as a concentration, and it becomes a model for dopant diffusion in semiconductor processes, mass transport through filters and membranes, or the spread of contaminants in groundwater. The source term S represents generation or consumption by chemical reactions. This kind of discretisation helps when you need a quick estimate of the steady-state concentration profile.
Numerical-methods education and code verification: When learning FVM for the first time, 1D steady diffusion is almost always the first subject. Because the exact solution (a line or a parabola) can be written by hand, the correctness of your own code can be checked directly through the "error against the analytical solution". The fact that the error becomes zero for S=0 and decreases with second-order accuracy as N grows for S≠0 is a standard benchmark for judging whether the implementation is correct.
Common Misconceptions and Pitfalls
The most common mistake is confusing cell-centre values with cell-boundary (node) values. This tool adopts the cell-centred method, so the φ it returns is the value at the cell centre x_i=(i+0.5)Δx, not the value at the boundary x=0 or x=L itself. When the boundary-face flux is evaluated, the distance from a cell centre to the boundary is Δx/2, so the boundary-face conductance is twice that of an interior face (2Γ/Δx). Forgetting this "half cell" treatment shifts the flux and temperature near the boundary. The most frequent FVM implementation bug is exactly this half-cell handling at the boundary.
Next, assuming that "error zero" makes the method universal. The reason the error is almost zero for S=0 in this tool is the special circumstance that the exact solution is a straight line and central differences can reproduce a straight line perfectly. Once a source term enters, or the diffusion coefficient varies with position, or a convection term is added, a discretisation error always appears. "It was error-free on one problem, so it will be fine on another" is not a valid conclusion. In practice you must always check, by varying N, whether the solution has converged (mesh dependence).
Finally, treating conservation and accuracy as the same thing. FVM conserves the flux exactly within each control volume, but that does not mean "the answer is accurate". Even on a coarse mesh the conservation law itself is not broken, yet the shape of the solution departs from the exact solution. In other words, conservation is the property that "mass and heat do not vanish on their own", which is a separate matter from accuracy (how close you are to the exact solution). Distinguishing the two is the first step to using FVM correctly.
How to Use
Set the number of control volumes (nNum) between 10 and 100 to discretize your 1D domain; finer grids reduce truncation error but increase computation time.
Define the domain range (nRange) in meters—typical values are 0 to 1 m for thermal or mass diffusion problems.
Specify the diffusion coefficient (gNum) in m²/s; for example, thermal diffusivity of steel is approximately 1.2×10⁻⁵ m²/s.
Enter the source term magnitude (lNum) in W/m³ or kg/(m³·s) depending on physics; use 0 for pure diffusion.
Set boundary conditions via plNum (left) and plRange (right) as Dirichlet values or flux conditions in SI units.
Execute the solver to compute cell-centered φ values and compare the maximum discretization error against the analytical solution.
Worked Example
A 1 m steel rod with thermal diffusivity α = 1.2×10⁻⁵ m²/s, left boundary T = 100°C, right boundary T = 0°C, uniform heat generation q = 500 W/m³. Using 40 control volumes, Δx = 0.025 m. The simulator predicts T at the central cell (x = 0.5 m) as approximately 38.7°C. The left-boundary diffusive flux is computed as -k·dT/dx ≈ 2400 W/m² (assuming k = 50 W/m·K). Maximum error versus analytical steady-state solution is typically 1.8% with second-order accuracy.
Practical Notes
Grid independence: run the simulation at nNum = 20, 40, and 80 cells; convergence within 2–3% indicates adequate resolution for engineering accuracy in heat exchangers or packed-bed reactors.
Source term stability: negative source terms (sinks) can cause non-physical oscillations near boundaries; validate with a Peclet number Pe = V·Δx/α less than 2 for convection-dominated regimes.
Boundary condition sensitivity: Neumann (flux) conditions at both ends may yield singular systems; ensure at least one Dirichlet condition or integrate the domain-wide source.
Physical validation: compare left-boundary flux output with expected values from materials databases (e.g., thermal conductivity of copper ≈ 400 W/m·K) to catch sign errors.