mixtureAveragedFourier: Cantera-Style Mixture-Averaged Diffusion in OpenFOAM
Contents
In multicomponent reacting flows the species diffuse at different rates (differential diffusion), and this has a large effect in problems such as lean hydrogen flames or the interface between fuel vapour and air. Among the laminar diffusion models in OpenFOAM (openfoam.org), FickianFourier is cheap but differs from the mixture-averaged model of Cantera and Chemkin in several places, while MaxwellStefanFourier is exact but needs a lot of memory and run time once the mechanism has many species. mixtureAveragedTransport is a library I built by modifying FickianFourier. It adds one laminar model, mixtureAveragedFourier, whose goal is to reproduce Cantera’s mixture-averaged model as closely as possible in OpenFOAM while keeping the memory use at the level of FickianFourier.
The model reads the same binary diffusion coefficient dictionary D that MaxwellStefanFourier uses. This is the dictionary that chemkin2foam (described in the previous post) writes when the Full option is selected, so an existing setup only needs the model name changed to mixtureAveragedFourier.
The post first gives the equations of the mixture-averaged model and then follows the structure of the code: the diffusion coefficients, the correction velocity, the time discretisation, the memory layout, the heat flux and the handling of mesh changes.
The three existing models
OpenFOAM offers three laminar models for multicomponent diffusion. unityLewisFourier lets every species diffuse with the thermal diffusivity, so there is no differential diffusion at all, and it is cheap. FickianFourier gives each species one diffusion coefficient and is also cheap. MaxwellStefanFourier solves the full multicomponent problem and is expensive, at about 70 KB of memory per cell for an 88-species mechanism.
According to the comparison in the repository README (OpenFOAM 14), FickianFourier with mixtureDiffusionCoefficients no differs from Cantera in three ways. The numerator of
is
, where Cantera uses
. The flux is driven by
and has no mean molecular weight gradient term. The species fluxes do not sum to zero, and the default species (usually N2) absorbs the imbalance.
MaxwellStefanFourier works with an
matrix in every cell, so its memory grows with the square of the number of species. For 88 species, the
double-precision numbers alone take about 62 KB, and with the other arrays the total is about 70 KB per cell. A 2D case with 640 000 cells would need about 45 GB for this part alone.
The mixture-averaged model
The Hirschfelder–Curtiss approximation writes the diffusion velocity of species as , which gives the mass flux
where is the molar mass of the species and the mean molar mass of the mixture. The mixture-averaged diffusion coefficient is built from the binary coefficients :
This is the same formula used by the mixture-averaged models in Cantera and Chemkin.
From it follows that
so a flux driven by the mole fraction gradient equals a flux driven by
plus an extra term
. Where the mean molecular weight changes sharply, for example at the interface between n-heptane vapour (
) and air (
) or in hydrogen-rich regions, this term is of the same order as
. FickianFourier does not include it.
The approximate fluxes do not in general sum to zero, so they violate mass conservation. Cantera’s one-dimensional flame code fixes this with a correction velocity: it sums the fluxes of all species and subtracts that sum from each species in proportion to its mass fraction. The corrected flux is
Since
, the corrected fluxes satisfy
exactly. mixtureAveragedFourier implements these equations without the Soret effect.
Computing the diffusion coefficients
updateDm() computes
for all species. It first evaluates the mean molar mass
from the old-time mass fractions and then accumulates the denominator for each species:
// sumXbyD = sum_j Y_j/(W_j D_ij) = sum_j (X_j/D_ij)/W, so
// D_i = (1 - Y_i)/sum_j (X_j/D_ij) = (1 - Y_i)/(W sumXbyD)
forAll(Y, j)
{
if (j != i)
{
sumXbyD += Y[j].oldTime()/(Wi(j)*D_ij(p, T));
}
}
Dm_[i] = (1 - Y[i].oldTime())/(W0*max(sumXbyD, small));Because
, the sum can use mass fractions directly and no mole fraction fields have to be built. sumXbyD is a single temporary field that is reset and reused for every species, so the
binary coefficients are evaluated one at a time and never stored together.
The binary coefficients
are Function2 objects read at construction, in the same way as in MaxwellStefanFourier. For every pair with
the code looks for i-j or j-i in the D dictionary. A missing pair is a fatal error, and if both names are present it uses i-j and prints a warning. Only the upper triangle is kept, and evaluation picks i < j ? DFuncs_[i][j] : DFuncs_[j][i].
When a species is nearly pure ( ), goes to zero with . This is physically fine, since the diffusion of that species then comes mostly from the correction velocity, but it causes trouble for the time discretisation. The quantity introduced below deals with this case.
Correction velocity
updateSums() computes
. The uncorrected face flux of each species comes from jMA(i):
// j_i^MA = -rho D_i (grad(Y_i) + Y_i grad(ln W)), evaluated on the faces
-interp.interpolate(alpha*rho*Dm[i])
*(fvc::snGrad(Y0i) + interp.interpolate(Y0i)*snGradLnW)Here snGradLnW is
on the faces, the face-normal gradient of
divided by the interpolated face value of
, and it is shared by all species. The sum runs over every species including the default one, and each species then subtracts
.
In FickianFourier the mass fraction of the default species is
of the others, so any error in the sum of the other fluxes ends up entirely in the default species. If that species is N2, its diffusion flux is wrong by the full imbalance. With the correction velocity the error is shared among all species according to their mass fractions, and every species flux agrees with Cantera.
Time discretisation
Implicit part and deferred correction
OpenFOAM solves the species transport equations one at a time, and each equation can only treat its own
implicitly. The
term and the correction velocity depend on the gradients of all species, so they cannot be written directly as an implicit Laplacian of a single species. Following the explicit/implicit split used in MaxwellStefan, the code introduces an implicit diffusivity
and writes the flux as
Everything inside the bracket uses the old-time mass fractions and the computed at the start of the time step. At the start of the step , so the implicit term cancels the inside the bracket and the flux equals the corrected mixture-averaged flux .
In the code, the implicit part comes from the parent class unityLewisFourier. Its j() and divj() take DEff(Yi) as the diffusion coefficient, and divj() contains an implicit fvm::laplacian. mixtureAveragedFourier overrides DEff() to return
and then adds the explicit bracket jexp(i) in j() and divj():
divj(Yi) = unityLewisFourier::divj(Yi) // -fvm::laplacian(rho Gamma_i, Yi)
+ fvc::div(jexp(i)*Yi.mesh().magSf()); // the bracket, explicit
Choosing
The value of decides whether the scheme is stable. Consider the 1D model equation , where is the actual derivative of the flux with respect to the species’ own gradient, with treated implicitly and explicitly. For a Fourier mode with wavenumber , let . The amplification factor is
If , then for any , so the scheme is unconditionally stable and free of oscillations. If is much smaller than , modes with large have , which gives once , and the solution blows up.
The obvious choice is , with the term and the correction velocity treated as explicit. This fails for a dominant species. As approaches 1, goes to zero and the actual diffusion comes mostly from the explicit correction velocity term, so and the scheme diverges when .
The code therefore computes the derivative of the flux with respect to the species’ own gradient and sets . In this derivative the gradients of the other non-default species are held fixed, and the gradient of the default species follows from the mass fractions summing to one: when increases by , decreases by . Since , then changes by with
Differentiating the corrected flux gives
For a mixture of two species, equals the binary coefficient and does not depend on . For a nearly pure species while stays finite. The code reads:
max
(
D[i],
D[i]*(1 - Y0i) + Y0i*D[d]
- Y0i*W0*(1/Wi(i) - 1/Wi(d))*(D[i] - sumYD)
)The default species has no transport equation of its own, and the code simply sets . When , the bracket has no first-order dependence on and only the coupling through the other species’ gradients remains. When , the implicit part is somewhat larger than needed. Both cases satisfy , so by the analysis above the scheme is stable for any .
,
and the related fields are computed in predict(), which runs once at the start of each time step, and they stay fixed during the step.
Memory
The memory of MaxwellStefanFourier is dominated by the
matrix in each cell. mixtureAveragedFourier caches only these fields:
PtrList<volScalarField> Dm_; // D_i of each species, n volume fields
autoPtr<volScalarField> W0_; // mean molar mass W at the old time
autoPtr<volScalarField> sumYD_; // sum_k Y_k D_k
autoPtr<surfaceScalarField> snGradLnW_; // grad(ln W) on the faces
autoPtr<surfaceScalarField> sumJ_; // sum of the uncorrected fluxes
Apart from the
there are only four fields shared by all species, a constant number on top of the
that FickianFourier also stores. The
,
and the bracket of each species are computed when that species’ equation is solved and released afterwards.
is computed once for the sum in updateSums() and again in jexp(), which trades some extra computation for memory.
In the README test with 640 000 cells, 88 species and chemistry switched off, this model used 8.25 GB and FickianFourier used 8.07 GB.
Heat flux
The heat flux consists of Fourier conduction and the enthalpy carried by species diffusion:
The code accumulates and over the non-default species and takes the flux of the default species as minus the sum of the others. Because the corrected fluxes sum to zero exactly, this gives the same default-species flux as computing it directly.
In the energy source term divq(he), conduction is written explicitly in terms of temperature as
. To help convergence the code adds fvm::laplacianCorrection(alphaEff, he), an implicit Laplacian of the energy variable he minus the explicit value of the same term. The two cancel at convergence and do not change the result. Conduction and the enthalpy flux are therefore correct for both energy forms, sensibleEnthalpy and sensibleInternalEnergy.
OpenFOAM’s own unityLewisFourier diffuses he with
when the energy variable is sensible internal energy. In the same case reported in the README, this heated the lean side before ignition by 4–7 K at 0.1 of the ignition delay and by 10–14 K at 0.6 of the ignition delay.
unityLewisSpecies
The species listed in the optional unityLewisSpecies entry use the thermal diffusivity in place of the mixture-averaged coefficient:
The driving force stays
and the correction velocity is applied as for the other species, which matches Cantera’s definition
. The
of the remaining species still need the binary coefficients of the listed species, so the D dictionary must stay complete.
This entry can switch off differential diffusion for chosen species only, for example giving just the fuel a Lewis number of one, which helps separate the effects of different species. Listing all species gives an exact unity Lewis number model with the correct enthalpy flux for both energy forms. In that case the README reports that the temperature stays on the adiabatic mixing line before ignition, with a deviation of −0.4 K at 0.1 of the ignition delay.
Mesh changes and load balancing
In reacting DNS the chemistry cost is concentrated near the flame, and as the flame moves the mesh has to be redistributed with loadBalancer. The model class also inherits from TopoChangeableMeshObject<fvMesh>, so on a topology change, mesh mapping or redistribution, topoChange(), mapMesh() and distribute() call clear() to delete all cached fields.
The cached fields are not mapped. The next time they are needed, update() finds the cache empty and rebuilds
and the four shared fields from the current old-time fields. This avoids writing mapping code for each cached field, at the cost of one extra call to updateDm() after each mesh change. For pure mesh motion without topology change, movePoints() does nothing.
Usage
Build the library in a terminal with the OpenFOAM environment loaded:
wmake libso # -> $FOAM_USER_LIBBIN/libmixtureAveragedTransport.soLoad it in system/controlDict:
libs ("libmixtureAveragedTransport.so");constant/thermophysicalTransport is written as for MaxwellStefanFourier, with only the model name changed:
simulationType laminar;
laminar
{
model mixtureAveragedFourier;
// unityLewisSpecies (nc7h16); // optional: these species get Le = 1
D // binary diffusion coefficients, as for MaxwellStefanFourier
{
o2-o2 { type binaryDiffusionCoefficient; ... }
o2-n2 { ... }
...
}
}For the thermal conductivity of the mixture, the standard OpenFOAM option mixture coefficientWilkeMulticomponentMixture; in physicalProperties agreed with Cantera to within 0–4 %. The default multicomponentMixture was 5–17 % low in our flames.
Validation
The tests used the 88-species n-heptane skeletal mechanism of Lu and Law at 6 MPa, with n-heptane vapour in contact with H2/air.
On prescribed 1D profiles of
and
, the species fluxes agree with Cantera’s mixture-averaged transport to a relative difference of
, and the sum of the fluxes is zero to round-off. In an autoignition case on a closed 1D strip with a 1 µm grid, the results differ from MaxwellStefanFourier by 0.16 % in ignition delay, by less than 0.8 % in flame front position and by 0.2 % in mean pressure, and the run takes 46 % of the Maxwell–Stefan run time. The unityLewisSpecies fluxes agree to within
with a reference built from the cell values of
,
and
.
With these numbers, fine-grid 2D DNS with skeletal mechanisms of 80 to 100 species can be run on a single workstation.
Summary and limitations
mixtureAveragedFourier builds mixture-averaged diffusion coefficients from the binary coefficients, drives the fluxes with mole fraction gradients and enforces mass conservation with a correction velocity, matching Cantera’s mixture-averaged model. In time, it uses
as the implicit diffusivity and treats the rest as a deferred correction, which stays stable at large time steps. In memory, it caches only the
and four shared fields and computes everything else when needed.
Some limitations remain. The Soret and Dufour effects are not included, and the Soret effect may matter in hydrogen flames. Only a laminar version exists, with no RAS or LES counterpart. The and the coupling terms in the bracket are computed at the start of each time step and are not updated during the step, so they lag by one time step. The model has only been tested with OpenFOAM 14 (openfoam.org).
The code is on GitHub at Fkstone/mixtureAveragedTransport under GPL-3.0, derived from OpenFOAM’s Fickian and FickianFourier. Issues and questions are welcome.