Reference Guide

OpenFOAM fixedFluxPressure: What It Sets, and When zeroGradient Gives the Same Result

You copied fixedFluxPressure from a tutorial into 0/p_rgh, because every interFoam and buoyant case has it on the walls. Then you start to wonder what it does that zeroGradient does not. Or the solver stops with a message about updateCoeffs(const scalarField& snGradp). The condition is a fixed gradient whose value you never type. The solver computes it at every pressure solve so that the flux through the patch equals the flux of your velocity condition. On a plain wall that gradient often comes out as zero, and then the two conditions give the same numbers.

Checked against the source of OpenFOAM 9 and OpenFOAM-dev (Foundation, openfoam.org) and of OpenFOAM v2506 (ESI, openfoam.com). The formula and the error message are the same in both forks. No case was run for this page. Where a statement comes from reading a solver file, the section names the file.

By Rayan Bhar, CFD Engineer ยท Updated November 2026

1. What fixedFluxPressure does

fixedFluxPressure derives from fixedGradient, but the gradient is not read from your dictionary. Before each pressure solve the solver calls constrainPressure. That function loops over the pressure patches, picks the ones of this type and sets their normal gradient to:

snGrad(p) = ( phiHbyA - rho * (Sf . U) ) / ( |Sf| * rAU )

Every term is taken on the patch faces:

The pressure equation then gives a boundary flux phi = phiHbyA - rAU * |Sf| * snGrad(p). With the gradient above, that is exactly rho * (Sf . U). The flux through the patch is the flux of your velocity condition, whatever body force is included in phiHbyA.

Both forks do this in constrainPressure.C. In OpenFOAM 9 the pressure equations of simpleFoam, pimpleFoam, interFoam and buoyantPimpleFoam all call it.

2. fixedFluxPressure vs zeroGradient

The two conditions differ only when the computed gradient is not zero, which means phiHbyA on the patch is not already the flux of the velocity condition.

On a patch with a fixed velocity, the solver overwrites HbyA on the boundary with U (in constrainHbyA.C), and the transient flux correction is set to zero on patches that are not coupled. The only thing left is what the solver adds to phiHbyA afterwards: the buoyancy and surface tension flux, named phig in the solver files. So the question becomes whether phig is zero on the patch.

PatchComputed gradientSame as zeroGradient?
simpleFoam or pimpleFoam, p, wall or velocity inletZeroYes
interFoam, p_rgh, wall with alpha zeroGradientZeroYes
interFoam, p_rgh, wall with a contact angle on alphaNot zero where the interface touches the wallNo
interFoam, p_rgh, velocity inlet with a fixed alphaNot zero when the first cell holds a different alphaNo
Buoyant solver, p_rgh, wall with a fixed temperature or a heat fluxNot zeroNo

In the rows marked "No", zeroGradient leaves the boundary flux equal to phiHbyA, which is the velocity flux plus phig. A wall then carries a small flux through it, and an inlet delivers a flow rate that is not the one you set.

This is why the usual advice holds: put fixedFluxPressure on p_rgh for every patch where the velocity is prescribed. Where the gradient is zero it changes nothing, and where it is not zero it is the right value.

3. Where the gradient comes from in p_rgh solvers

Solvers with gravity solve for p_rgh = p - rho*gh. At a wall with no flow through it, the momentum balance normal to the wall is hydrostatic, dp/dn = rho * (g . n). Substitute that into the definition of p_rgh and one term is left:

d(p_rgh)/dn = - gh * d(rho)/dn

So p_rgh has a zero normal gradient at a wall unless the density changes in the wall-normal direction at the wall. The code computes the same thing. In pEqn.H of interFoam:

phig = ( surfaceTensionForce - ghf*snGrad(rho) ) * rAUf * |Sf|
phiHbyA += phig
constrainPressure(p_rgh, U, phiHbyA, rAUf, MRF)

On a fixed-velocity patch constrainPressure therefore returns snGrad(p_rgh) = surfaceTensionForce - ghf*snGrad(rho). Two details decide whether this is zero:

Stuck on this in your own case?

CFDpilot is an AI agent for OpenFOAM that runs in your terminal. It reads the case files and the solver log on your machine, and shows every change as a diff before it edits a file.

Diagnose my case →

Start free · 200 credits · nothing charged

4. How to write it in 0/p_rgh

walls
{
    type            fixedFluxPressure;
}

That entry is enough. The constructor reads value and gradient only when both are present. Otherwise it starts from the cell value with a zero gradient, and the solver sets the real gradient at the first pressure solve. The tutorials still carry value uniform 0; (damBreak) or value $internalField;. The line is harmless.

Once the solver has written a time directory, the same patch looks different:

walls
{
    type            fixedFluxPressure;
    gradient        nonuniform List<scalar> ...;
    value           nonuniform List<scalar> ...;
}

Both entries are there, so a restart reads them back. Do not delete gradient when you edit a written field by hand.

The condition fixes a gradient and no pressure level. If every patch of the pressure field is fixedFluxPressure or zeroGradient, the solver needs a reference: pRefCell or pRefPoint, with pRefValue, in the algorithm dictionary of fvSolution.

5. The error "updateCoeffs(const scalarField& snGradp) MUST be called"

The full message is:

updateCoeffs(const scalarField& snGradp) MUST be called before updateCoeffs() or evaluate() to set the boundary gradient.

The condition raises it itself. It remembers the time step in which the solver last set its gradient. If the patch is evaluated in a time step where that has not happened, it stops the run. The text is identical from OpenFOAM 2.3 to OpenFOAM-dev, and in ESI v2506.

It means the field carrying the condition is not the one the solver passes to constrainPressure. Two situations lead there by construction:

The fix is the same each time: the condition goes on the pressure field the solver solves for, and nowhere else. In a solver that solves p_rgh, that is 0/p_rgh. The buoyant tutorials set p to calculated on the same walls (hotRoom).

6. Where not to use it

fixedFluxPressure makes the pressure follow the velocity condition. It belongs on patches where the velocity is prescribed: walls and velocity inlets.

7. Two checks on a running case

Stuck on this in your own case?

CFDpilot is an AI agent for OpenFOAM that runs in your terminal. It reads the case files and the solver log on your machine, and shows every change as a diff before it edits a file.

Diagnose my case →

Start free · 200 credits · nothing charged

Source and documentation

Frequently Asked Questions

What does fixedFluxPressure do in OpenFOAM?

It is a fixed gradient condition for pressure whose gradient you do not type. Before each pressure solve the solver computes the normal gradient that makes the flux through the patch equal to the flux of the velocity boundary condition, and sets it on every fixedFluxPressure patch. The function that does this is constrainPressure, in both the Foundation and the ESI versions.

What is the difference between fixedFluxPressure and zeroGradient?

zeroGradient always sets a zero normal gradient. fixedFluxPressure sets the gradient that cancels any buoyancy or surface tension flux on the patch. On a fixed-velocity patch in simpleFoam or pimpleFoam, and on an interFoam wall where alpha is zeroGradient, that gradient is zero and the two conditions give the same result. They differ where density changes between the boundary face and the first cell: a heated wall in a buoyant solver, a wall with a contact angle, a velocity inlet with a fixed alpha.

Do I need a value entry with fixedFluxPressure?

No. The condition reads value and gradient only when both are present, which is the case in a time directory written by the solver. With no entry, or with value alone, it starts from the cell value and a zero gradient, and the solver sets the gradient at the first pressure solve. The value uniform 0 line found in tutorials is harmless.

What does the error about updateCoeffs(const scalarField& snGradp) mean?

The patch was evaluated in a time step where the solver had not set its gradient. That happens when the condition sits on a field that is not the pressure the solver solves for, such as T or alpha, or in a custom solver whose pressure equation does not call constrainPressure. Move the condition to the solved pressure field.

Can I use fixedFluxPressure on an outlet?

Not on an outlet where the flow has to find its own rate. The condition makes the pressure follow the velocity condition, so it belongs on patches where the velocity is prescribed: walls and velocity inlets. An outlet or an open boundary needs a condition that fixes a pressure value, such as fixedValue, totalPressure or prghPressure.