Module 6: Transient Numerical Methods and Time Integration
Learn how CFD simulations advance solutions through time, from the transient conservation equation to explicit and implicit schemes, stability, accuracy, CFL restrictions, and implementing a time-dependent diffusion solver.
Introduction
Many fluid-flow problems change with time. A fluid accelerates after a valve opens, a thermal plume develops above a heated surface, and vortices form and detach behind a cylinder. To simulate these processes, a numerical method must describe not only how physical quantities vary in space, but also how they evolve in time.
In the previous modules, we developed the governing equations, discretized them, assembled algebraic systems, and introduced the finite volume method. We now add another essential component: time integration.
Time integration converts a continuous evolution equation into a sequence of numerical updates. At each time step, the solver calculates the new state from the current state and, depending on the method, possibly from additional unknowns at the new time.
This module develops the underlying ideas before connecting them to practical CFD algorithms.
Learning objectives
By the end of this module, you should be able to:
- Explain the difference between steady-state and transient simulations.
- Derive a time-discrete equation from a transient conservation equation.
- Understand explicit Euler, implicit Euler, and the Crank–Nicolson method.
- Distinguish stability, accuracy, and convergence.
- Explain the Courant–Friedrichs–Lewy condition and its role in time-step selection.
- Understand why explicit and implicit schemes have different computational costs.
- Implement a simple one-dimensional transient diffusion solver.
- Recognize how time integration is used in finite volume CFD software.
1. Why does CFD need time integration?
Consider a physical field such as temperature, pressure, or velocity. Its value may depend on both position and time.
For a temperature field,
The spatial coordinates describe where the temperature is measured. Time describes how the temperature at that location changes.
A transient simulation predicts this evolution over a sequence of time levels:
For a constant time step, the time levels are given by
where:
- is the current time.
- is the next time.
- is the time-step size.
- is the time-step index.
The superscript identifies a time level; it does not represent a power.
1.1 Steady-state and transient simulations
A steady-state solution assumes that the field no longer changes with time:
Here, represents a general transported quantity, such as temperature or a velocity component.
A transient solution retains the time derivative:
This distinction is physical as well as numerical. A steady-state simulation may be appropriate when the final equilibrium is the quantity of interest. A transient simulation is required when the evolution itself matters, or when the system does not settle into a steady state.
For example, a steady calculation may predict the final temperature distribution in a heated enclosure. A transient calculation can reveal how quickly the enclosure heats up and how thermal plumes develop.
1.2 The computational trade-off
A transient calculation introduces an additional numerical resolution requirement: the time step.
Smaller time steps can improve temporal resolution, but they require more updates to reach a given physical time. Larger steps reduce the number of updates, but may miss important dynamics or make the numerical method unstable.
Choosing a time step is therefore a balance among accuracy, stability, computational cost, and the physical time scales of interest.
2. Start from a transient governing equation
Consider one-dimensional diffusion of a scalar quantity with constant diffusivity and no source term:
This equation describes how spatial differences in drive its evolution.
For heat conduction in a stationary solid with constant thermal properties, the corresponding equation is
where the thermal diffusivity is
Here, is thermal conductivity, is density, and is specific heat capacity.
The right-hand side describes diffusion. A region with a high temperature relative to its surroundings tends to lose heat, while a colder region tends to gain heat.
The equation contains two types of derivatives:
- A first-order derivative in time.
- A second-order derivative in space.
We have already studied how spatial derivatives can be approximated using finite differences and finite volumes. We now approximate the time derivative as well.
3. Discretizing the time derivative
At a fixed spatial location, the first-order time derivative is
Using a forward difference between the current and next time levels gives
This approximation is called a forward difference in time.
The superscript indicates the time level, while the spatial coordinate is held fixed.
The approximation follows from a Taylor expansion around :
Rearranging and dividing by gives
Therefore, the forward-difference approximation is first-order accurate in time.
The temporal truncation error decreases proportionally to when the solution is sufficiently smooth and the time step is reduced.
4. Explicit Euler time integration
Consider the ordinary differential equation
The explicit Euler method evaluates the rate of change using known information at the current time:
Rearranging gives the update formula:
The new value is calculated directly from the old value and its current rate of change.
4.1 Physical interpretation
Imagine tracking the temperature of a small thermal mass. If its current heating rate is known, explicit Euler predicts the next temperature by assuming that the rate remains constant throughout the time step.
For a sufficiently small time step, this can be a reasonable approximation. If the rate changes rapidly, the prediction may be inaccurate.
4.2 Explicit Euler applied to diffusion
Return to the diffusion equation:
Approximate the second spatial derivative using a central difference on a uniform grid:
Applying explicit Euler gives
Define the dimensionless diffusion number
The update becomes
Every value on the right-hand side is known from the current time level. No simultaneous algebraic system must be solved for the interior cells.
This is the main computational attraction of explicit time integration.
However, explicit methods can require very small time steps to remain stable.
5. Implicit Euler time integration
The implicit Euler method evaluates the rate of change at the new time level:
Its general form is
Because the unknown new state appears on both sides, the update is generally an equation that must be solved.
5.1 Implicit Euler applied to diffusion
Using the same spatial approximation but evaluating it at time level gives
Using the diffusion number , rearrange the equation:
For all interior cells, these equations form a tridiagonal linear system:
The matrix contains the spatial coupling between neighboring cells. The right-hand side contains the known solution from the previous time level, along with any contributions from boundary conditions.
This connects time integration directly to Module 4: algebraic systems and numerical solvers.
5.2 Why use an implicit method?
For the standard linear diffusion equation with the usual central spatial discretization, implicit Euler is unconditionally stable in the linear stability sense. This means that stability does not impose the same diffusion-number limit required by explicit Euler.
That does not mean an arbitrarily large time step will produce an accurate solution. Large time steps can still smear transients and miss important physical events.
Implicit integration also has a higher cost per step because a linear system must be solved. For complex CFD equations, this can be a major part of the computational workload.
6. Crank–Nicolson time integration
Crank–Nicolson averages the spatial rate of change between the old and new time levels.
For an equation of the form
where represents the spatial operator, Crank–Nicolson is
For linear diffusion, the new-time and old-time spatial operators can be evaluated directly using the corresponding field values.
Crank–Nicolson is second-order accurate in time for sufficiently smooth solutions and a consistent implementation.
6.1 Comparison of the three methods
| Method | Temporal accuracy | Update type | Typical property |
|---|---|---|---|
| Explicit Euler | First order | Explicit | Simple, but often restricted by stability |
| Implicit Euler | First order | Implicit | Strong stability for standard linear diffusion |
| Crank–Nicolson | Second order | Implicit | Higher temporal accuracy, but can show oscillations for very large steps or sharp transients |
Crank–Nicolson is not automatically better in every situation. Its higher formal accuracy is valuable for smooth solutions, but the time step still needs to resolve the physical evolution. For stiff problems or sharp initial changes, implicit Euler can sometimes produce more robust behavior.
7. Stability, accuracy, and convergence
These concepts are related, but they are not interchangeable.
7.1 Stability
Stability concerns how numerical errors evolve as a computation progresses.
A stable numerical method prevents small disturbances, such as round-off or truncation errors, from growing uncontrollably under the method’s applicable stability conditions.
For the one-dimensional diffusion equation discretized using central differences in space and explicit Euler in time, the standard stability restriction is
Equivalently,
This restriction applies to the standard one-dimensional explicit diffusion scheme described above. It should not be treated as a universal time-step formula for all CFD problems.
For the same explicit scheme in spatial dimensions on a uniform grid with the same spacing in each direction, the corresponding diffusion stability condition is
where is the number of spatial dimensions.
For unequal grid spacings, the standard explicit diffusion restriction becomes
with only the terms for the dimensions present in the problem included.
7.2 Accuracy
Accuracy describes how closely the numerical solution approximates the exact solution.
A calculation may be stable but inaccurate. For example, an implicit diffusion solver can remain stable with a large time step while smoothing the temperature field too aggressively to capture a rapid transient.
Accuracy depends on several factors:
- Spatial discretization.
- Temporal discretization.
- Mesh resolution.
- Time-step size.
- Boundary conditions.
- Iterative and linear-solver tolerances.
- Smoothness and time scales of the physical solution.
7.3 Convergence
The word convergence is used in two important ways.
Iterative convergence means that the algebraic or nonlinear equations at a particular time step have been solved to the chosen tolerance.
Grid and time-step convergence means that the computed quantities approach a consistent result as spatial and temporal resolution are refined.
A small residual alone does not prove that a transient solution is physically accurate. It only provides information about the numerical equations being solved.
A reliable transient CFD study should monitor both solver convergence and sensitivity to the mesh and time step.
8. The Courant–Friedrichs–Lewy condition
Diffusion is not the only process that limits time-step selection. In fluid flow, information is also transported by advection.
Consider one-dimensional advection with constant velocity :
The Courant number compares the distance travelled by the flow during one time step with the cell size:
If a fluid travels a distance comparable to a cell width during one time step, the Courant number is approximately one.
For a uniform one-dimensional mesh, explicit upwind discretization of linear advection is stable under the usual condition
This is a scheme-specific condition, not a universal limit for every transient CFD solver.
8.1 Interpreting the Courant number
- If is small, the fluid travels only a fraction of a cell per time step.
- If is around one, the fluid travels approximately one cell per time step.
- If is large, the fluid travels across multiple cells per time step.
The last situation can be problematic for some explicit schemes, but the interpretation depends on the numerical method. Implicit methods can often operate at larger Courant numbers, although accuracy and nonlinear convergence may still deteriorate.
8.2 Diffusion and advection restrictions
For the one-dimensional explicit diffusion scheme, the diffusion number must satisfy
For the one-dimensional explicit upwind advection scheme, the Courant number must satisfy
If a calculation includes both processes, the relevant restrictions depend on the discretization of each term and how the terms are combined.
Do not assume that satisfying one condition automatically satisfies the other.
9. Choosing a practical time step
A useful time step must resolve the relevant physical time scales and satisfy the stability requirements of the selected numerical scheme.
9.1 Estimate an advective time scale
For a characteristic velocity and length scale , the advective time scale is
This estimates how long the flow takes to travel across the characteristic length.
9.2 Estimate a diffusion time scale
For a characteristic length and diffusivity , the diffusion time scale is
This estimates the time required for diffusion to act over that length scale.
These are order-of-magnitude estimates, not exact predictions for every geometry or boundary condition.
9.3 Refine the time step when needed
A practical workflow is:
- Choose a time step that respects the numerical scheme’s stability constraints.
- Run the simulation while monitoring residuals, physical quantities, and time-dependent behavior.
- Repeat with a smaller time step.
- Compare quantities of interest, such as temperature, drag, lift, pressure drop, or oscillation frequency.
- Continue refinement until the change is acceptably small for the intended application.
For a transient calculation, compare the solutions at the same physical times. Comparing different time levels can confuse temporal discretization error with actual physical evolution.
10. Worked example: one-dimensional transient heat conduction
Consider a solid wall initially at a uniform temperature. Its two ends are held at fixed temperatures, and heat diffuses through the wall.
The governing equation is
Let the domain length be . The boundary and initial conditions are
where and are the prescribed boundary temperatures and is the initial interior temperature.
For simplicity, use a uniform grid with spacing and apply explicit Euler in time.
The update for an interior node is
where
The boundary temperatures are imposed at every time step.
10.1 Numerical values
Choose the following illustrative parameters:
| Parameter | Value |
|---|---|
| Domain length, | |
| Thermal diffusivity, | |
| Left boundary temperature, | |
| Right boundary temperature, | |
| Initial interior temperature, | |
| Number of intervals, |
For intervals, the spacing is
Therefore,
The explicit diffusion stability limit is
Substituting the parameters,
Choose a time step of , which gives
Since , this time step satisfies the standard stability condition for the stated one-dimensional explicit diffusion scheme.
This does not guarantee that the time step is sufficiently accurate for every quantity of interest. Temporal refinement should still be checked.
11. Implementing the transient diffusion solver in C++
The following standalone C++ program solves the one-dimensional heat equation using explicit Euler and central differences in space.
It:
- Initializes the temperature field.
- Enforces fixed-temperature boundary conditions.
- Checks the diffusion stability condition.
- Advances the solution to a prescribed final time.
- Writes the temperature field to a CSV file.
Save the file as transient_diffusion.cpp.
#include <cmath>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <stdexcept>
#include <vector>
int main()
{
// Physical parameters
const double L = 0.1; // Domain length [m]
const double alpha = 1.0e-5; // Thermal diffusivity [m^2/s]
const double T_left = 400.0; // Left boundary temperature [K]
const double T_right = 300.0; // Right boundary temperature [K]
const double T_initial = 300.0;
// Numerical parameters
const int intervals = 40;
const double dt = 0.2; // Time step [s]
const double final_time = 20.0;
if (intervals < 2)
{
throw std::runtime_error(
"At least two spatial intervals are required."
);
}
if (alpha <= 0.0 || dt <= 0.0 || final_time < 0.0)
{
throw std::runtime_error(
"Diffusivity must be positive, time step must be positive, "
"and final time must be non-negative."
);
}
const double dx = L / intervals;
const double r = alpha * dt / (dx * dx);
// Stability check for 1D explicit diffusion.
if (r > 0.5)
{
throw std::runtime_error(
"Explicit diffusion scheme is unstable for this time step: "
"alpha * dt / dx^2 must be <= 0.5."
);
}
const int nodes = intervals + 1;
std::vector<double> T(nodes, T_initial);
std::vector<double> T_new(nodes, T_initial);
// Enforce boundary conditions at the initial time.
T.front() = T_left;
T.back() = T_right;
const int steps =
static_cast<int>(std::ceil(final_time / dt));
double time = 0.0;
for (int n = 0; n < steps; ++n)
{
// Use a shorter final step if needed so the simulation
// ends exactly at final_time.
const double dt_step =
std::min(dt, final_time - time);
if (dt_step <= 0.0)
{
break;
}
const double r_step =
alpha * dt_step / (dx * dx);
if (r_step > 0.5)
{
throw std::runtime_error(
"The final time step violates the stability condition."
);
}
// Apply fixed-temperature boundary conditions.
T_new.front() = T_left;
T_new.back() = T_right;
// Update interior nodes using explicit Euler.
for (int i = 1; i < intervals; ++i)
{
T_new[i] = T[i] + r_step *
(T[i + 1] - 2.0 * T[i] + T[i - 1]);
}
T.swap(T_new);
time += dt_step;
}
// Write the final temperature field.
std::ofstream output("temperature.csv");
if (!output)
{
throw std::runtime_error(
"Could not open temperature.csv for writing."
);
}
output << "x_m,temperature_K\n";
output << std::setprecision(12);
for (int i = 0; i < nodes; ++i)
{
const double x = i * dx;
output << x << "," << T[i] << "\n";
}
std::cout << std::fixed << std::setprecision(6);
std::cout << "Simulation completed.\n";
std::cout << "Final time: " << time << " s\n";
std::cout << "Spatial spacing: " << dx << " m\n";
std::cout << "Diffusion number: "
<< alpha * dt / (dx * dx) << "\n";
std::cout << "Output: temperature.csv\n";
return 0;
}
11.1 Compile and run
With a C++ compiler such as g++, run:
g++ -std=c++20 -O2 -Wall -Wextra -pedantic \
transient_diffusion.cpp -o transient_diffusion
./transient_diffusion
The program writes temperature.csv in the current working directory.
11.2 What the code demonstrates
The most important update is
T_new[i] = T[i] + r_step *
(T[i + 1] - 2.0 * T[i] + T[i - 1]);
This is the direct implementation of the explicit diffusion equation.
The old temperature array is used to calculate every new interior temperature. Only after all nodes have been updated do we swap the arrays.
This separation is essential. If each newly calculated value were immediately reused for the next node, the algorithm would no longer implement the stated explicit Euler scheme. It would mix old and new time levels.
The code also handles the final time step so that the simulation reaches the requested final time, even when it is not an exact multiple of the nominal time step.
12. Verify the numerical solution
A solver running without errors does not prove that the numerical result is correct. Verification checks whether the equations have been implemented and solved as intended.
12.1 Check the boundary conditions
The numerical solution should satisfy
and
up to floating-point precision, because these conditions are imposed directly in the code.
12.2 Check the expected long-time behavior
For constant diffusivity and fixed-temperature boundaries, the steady-state equation is
Integrating twice gives a linear temperature distribution:
As the simulation advances, the transient numerical solution should approach this profile.
12.3 Check temporal refinement
Repeat the calculation with smaller time steps, for example:
Compare the temperature distributions at the same physical time.
For a sufficiently smooth solution and a fixed spatial mesh, explicit Euler has first-order temporal accuracy. In the asymptotic refinement range, halving the time step should reduce the temporal component of the error by approximately a factor of two.
Spatial discretization error remains present during this test. To study spatial convergence, refine the grid as a separate investigation.
12.4 A subtle point about the initial condition
The example assigns to the initial interior and the right boundary, while the left boundary is held at . At the initial time, the interior temperature next to the left boundary therefore has a sharp spatial change.
The numerical solution will diffuse this initial change over time. The smooth-solution assumptions used in formal accuracy arguments may not hold exactly at the initial instant, so convergence should be assessed using the actual numerical results rather than relying only on the formal order of the scheme.
13. How transient integration connects to finite volume CFD
The example used finite differences to keep the time-integration logic visible. In finite volume CFD, the same principle is applied to a control-volume conservation equation.
For a scalar , a generic transient transport equation is
Integrating over a control volume gives
For a fixed control volume with constant density and a simple time discretization, the transient contribution can be approximated by
The remaining terms represent convective fluxes, diffusive fluxes, and sources.
After spatial discretization, a transient finite volume equation often takes the schematic form
for an implicit scheme. Here, denotes the current cell and denotes neighboring cells. The coefficients and right-hand side depend on the chosen time scheme, spatial discretization, boundary conditions, and physical models.
The transient term contributes to the cell’s diagonal coefficient and to the right-hand side through the old-time solution. This is one reason time integration and algebraic-system assembly are closely connected.
14. Understanding time integration in OpenFOAM
In practical CFD software, the time scheme is one part of a larger numerical method. The solver also uses spatial discretization, pressure-velocity coupling, boundary conditions, linear solvers, and often turbulence or other physical models.
OpenFOAM cases commonly specify time-discretization choices in system/fvSchemes, under the ddtSchemes section.
A typical configuration may look like this:
ddtSchemes
{
default Euler;
}
The exact available schemes and their behavior depend on the OpenFOAM version and the solver being used. Consult the documentation for your installed release before changing a production case.
Conceptually:
- An Euler time scheme uses a first-order temporal approximation.
- A backward scheme can provide higher-order temporal accuracy, depending on its configuration and implementation.
- A Crank–Nicolson scheme combines information from old and new time levels; practical implementations may offer blending with a more dissipative scheme.
Do not confuse the time scheme with the spatial schemes listed under divSchemes and laplacianSchemes. They control different parts of the discretized equations.
14.1 Time step and output interval are different
In OpenFOAM, the computational time step controls how far the solution advances during one update. The write interval controls when solution fields are saved.
A case can advance using many small time steps while writing fields only occasionally. Reducing the output interval does not automatically improve temporal accuracy; it mainly increases the frequency of saved results and may increase storage requirements.
14.2 Fixed and adjustable time steps
A fixed time step remains constant throughout the simulation.
An adjustable time step can change during the run. In transient fluid-flow calculations, it is common to use a target maximum Courant number to guide time-step selection.
An adjustable time step is not a substitute for verification. The maximum Courant number, time-step history, solver behavior, and sensitivity of quantities of interest should still be examined.
15. Common mistakes in transient CFD
Mistake 1: Assuming an implicit method makes every time step accurate
Implicit schemes can be stable at large time steps for particular problems, but stability does not guarantee temporal accuracy.
Mistake 2: Updating the solution in place in an explicit method
An explicit update must use values from the old time level. Use separate old and new arrays, or an equivalent data structure that preserves the previous state.
Mistake 3: Confusing residual convergence with time accuracy
A solver can converge the equations at each time step while the physical solution remains under-resolved in time.
Mistake 4: Applying one stability condition to every equation
The diffusion-number restriction derived in this module applies to a particular explicit diffusion discretization. Advection, waves, compressibility, reaction terms, and coupled systems can have different restrictions.
Mistake 5: Refining space and time simultaneously without a plan
If both the mesh and time step change at once, it becomes harder to identify the source of a difference. Start with controlled refinement studies, changing one resolution parameter at a time when practical.
Mistake 6: Ignoring the initial condition
Transient simulations depend on the initial field. An incorrect initial condition can create a physically different evolution, even if the governing equations and numerical method are otherwise correct.
16. Key takeaways
- Transient CFD predicts how physical fields evolve through time.
- Time discretization converts a continuous time derivative into a numerical update.
- Explicit Euler computes the new solution directly from the old solution, but may require a restrictive time step.
- Implicit Euler requires solving a system of equations, but is strongly stable for standard linear diffusion problems.
- Crank–Nicolson is second-order accurate in time for sufficiently smooth solutions and a consistent implementation.
- Stability, accuracy, and convergence describe different aspects of numerical quality.
- The Courant number characterizes advective transport over a time step, while the diffusion number characterizes diffusion relative to the mesh and time step.
- Transient finite volume methods combine time discretization with conservative spatial flux balances.
- A reliable simulation requires time-step refinement, physical checks, and numerical verification.
What’s next?
In Module 7: Convection, Transport, and Numerical Stability, we will examine how quantities move with the flow, why convection-dominated problems are challenging, how central differencing and upwind schemes behave, and how numerical diffusion affects CFD predictions.