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.
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:
phiHbyA is the flux the momentum equation gives before the pressure gradient is applied.Sf . U is the flux of the velocity boundary condition. rho is 1 in incompressible solvers.rAU is the inverse of the diagonal of the momentum matrix.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.
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.
| Patch | Computed gradient | Same as zeroGradient? |
|---|---|---|
simpleFoam or pimpleFoam, p, wall or velocity inlet | Zero | Yes |
interFoam, p_rgh, wall with alpha zeroGradient | Zero | Yes |
interFoam, p_rgh, wall with a contact angle on alpha | Not zero where the interface touches the wall | No |
interFoam, p_rgh, velocity inlet with a fixed alpha | Not zero when the first cell holds a different alpha | No |
Buoyant solver, p_rgh, wall with a fixed temperature or a heat flux | Not zero | No |
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.
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:
alpha, and the surface tension force is proportional to snGrad(alpha). On a boundary face both terms vanish when alpha on the face equals alpha in the cell, which is what zeroGradient on alpha gives.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
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.
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:
T or alpha will accept it when the case is read, and fail at the first evaluation.constrainPressure before the equation is assembled.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).
fixedFluxPressure makes the pressure follow the velocity condition. It belongs on patches where the velocity is prescribed: walls and velocity inlets.
fixedValue, totalPressure or prghPressure. The damBreak tutorial uses totalPressure on the atmosphere patch and fixedFluxPressure on the three walls.zeroGradient. From the formula, the flux through the patch is then pinned to the current boundary velocity. Neither field fixes anything, and the flow rate cannot adjust.p_rgh in the first written time directory and look at the gradient entry of a wall. On an interFoam wall with alpha zeroGradient and no contact angle it should be zero to round-off. Values that are clearly not zero mean density or alpha changes across the first cell at that wall.phi over a wall patch. With fixedFluxPressure on a wall with zero velocity, the sum is zero to round-off. If you switch that patch to zeroGradient and the sum moves away from zero, you are in one of the "No" rows of the table above.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
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.
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.
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.
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.
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.