# SimpleFoam

**SimpleFoam**

SimpleFoam is a steady-state solver for incompressible, turbulent flow, using the SIMPLE (Semi-Implicit Method for Pressure Linked Equations) algorithm. In the newer releases it also includes an option to use the SIMPLEC (Semi-Implicit Method for Pressure Linked Equations Consistent) algorithm.

## Contents

## 1 Solution Strategy

The solver follows a segregated solution strategy. This means that the equations for each variable characterizing the system (the velocity , the pressure and the variables characterizing turbulence) is solved sequentially and the solution of the preceding equations is inserted in the subsequent equation. The non-linearity appearing in the momentum equation (the face flux which is a function of the velocity) is resolved by computing it from the velocity and pressure values of the preceding iteration. The dependence from the pressure is introduced to avoid a decoupling between the momentum and pressure equations and hence the appearance of high frequency oscillation in the solution (check board effect). The first equation to be solve is the momentum equation. It delivers a velocity field which is in general not divergence free, i.e. it does not satisfy the continuity equation. After that the momentum and the continuity equations are used to construct an equation for the pressure. The aim is to obtain a pressure field , which, if inserted in the momentum equation, delivers a divergence free velocity field . After correcting the velocity field, the equations for turbulence are solved. The above iterative solution procedure is repeated until convergence.

The source code can be found in simpleFoam.C

/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License This file is part of OpenFOAM. OpenFOAM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. OpenFOAM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. Application simpleFoam Description Steady-state solver for incompressible, turbulent flow, using the SIMPLE algorithm. \*---------------------------------------------------------------------------*/ #include "fvCFD.H" #include "singlePhaseTransportModel.H" #include "turbulentTransportModel.H" #include "simpleControl.H" #include "fvOptions.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // int main(int argc, char *argv[]) { #include "postProcess.H" #include "setRootCaseLists.H" #include "createTime.H" #include "createMesh.H" #include "createControl.H" #include "createFields.H" #include "initContinuityErrs.H" turbulence->validate(); // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // Info<< "\nStarting time loop\n" << endl; while (simple.loop(runTime)) { Info<< "Time = " << runTime.timeName() << nl << endl; // --- Pressure-velocity SIMPLE corrector { #include "UEqn.H" #include "pEqn.H" } laminarTransport.correct(); turbulence->correct(); runTime.write(); Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s" << " ClockTime = " << runTime.elapsedClockTime() << " s" << nl << endl; } Info<< "End\n" << endl; return 0; } // ************************************************************************* //

## 2 Equations

### 2.1 Momentum Equation

| (1) |

represent the velocity and and are the viscose and turbulent stresses. Not that in simpleFoam the momentum equation solve, is divided by the constant density .

The source code can be found in UEqn.H:

// Momentum predictor MRF.correctBoundaryVelocity(U); tmp<fvVectorMatrix> tUEqn ( fvm::div(phi, U) + MRF.DDt(U) + turbulence->divDevReff(U) == fvOptions(U) ); fvVectorMatrix& UEqn = tUEqn.ref(); UEqn.relax(); fvOptions.constrain(UEqn); if (simple.momentumPredictor()) { solve(UEqn == -fvc::grad(p)); fvOptions.correct(U); }

In the following the numeric used to solve the momentum equation are briefly explained. The first step performed is to assemble the matrix which is later solved to obtain the estimate of the velocity :

tmp<fvVectorMatrix> tUEqn ( fvm::div(phi, U) + MRF.DDt(U) + turbulence->divDevReff(U) == fvOptions(U) );

In the usual semi discrete form it can be written as (see also ^{[1]}. ):

| (1) |

are the matrix coefficient associated with the centre point P, the matrix coefficients associated with all neighbours influencing the computational stencil around point P and is the source therm. The sum is taken over all neighbours influencing the computational stencil around point P.

The next step performed is the under relax the equation:

UEqn.relax();

The under relaxation is required in order to prevent the solution to diverge. Even though the discrete equation of the momentum

equation is linear, the non linearity is resolve by using the solution of the previous iteration. This causes a large change of the new velocity
leading often to divergence ^{[2]}. Using Patankar's implicit under relaxation the new semi discrete momentum equation can be written as:

| (1) |

Here denotes the under relaxation factor and denotes the solution at the previous iteration step. The source code for the under relaxation can be found in fvMatrix.C (see also https://www.openfoam.com/documentation/cpp-guide/html/fvMatrix_8C_source.html):

template<class Type> void Foam::fvMatrix<Type>::relax(const scalar alpha) { if (alpha <= 0) { return; } if (debug) { InfoInFunction << "Relaxing " << psi_.name() << " by " << alpha << endl; } Field<Type>& S = source(); scalarField& D = diag(); // Store the current unrelaxed diagonal for use in updating the source scalarField D0(D); // Calculate the sum-mag off-diagonal from the interior faces scalarField sumOff(D.size(), 0.0); sumMagOffDiag(sumOff); // Handle the boundary contributions to the diagonal forAll(psi_.boundaryField(), patchi) { const fvPatchField<Type>& ptf = psi_.boundaryField()[patchi]; if (ptf.size()) { const labelUList& pa = lduAddr().patchAddr(patchi); Field<Type>& iCoeffs = internalCoeffs_[patchi]; if (ptf.coupled()) { const Field<Type>& pCoeffs = boundaryCoeffs_[patchi]; // For coupled boundaries add the diagonal and // off-diagonal contributions forAll(pa, face) { D[pa[face]] += component(iCoeffs[face], 0); sumOff[pa[face]] += mag(component(pCoeffs[face], 0)); } } else { // For non-coupled boundaries add the maximum magnitude diagonal // contribution to ensure stability forAll(pa, face) { D[pa[face]] += cmptMax(cmptMag(iCoeffs[face])); } } } } if (debug) { // Calculate amount of non-dominance. label nNon = 0; scalar maxNon = 0.0; scalar sumNon = 0.0; forAll(D, celli) { scalar d = (sumOff[celli] - D[celli])/mag(D[celli]); if (d > 0) { nNon++; maxNon = max(maxNon, d); sumNon += d; } } reduce(nNon, sumOp<label>(), UPstream::msgType(), psi_.mesh().comm()); reduce ( maxNon, maxOp<scalar>(), UPstream::msgType(), psi_.mesh().comm() ); reduce ( sumNon, sumOp<scalar>(), UPstream::msgType(), psi_.mesh().comm() ); sumNon /= returnReduce ( D.size(), sumOp<label>(), UPstream::msgType(), psi_.mesh().comm() ); InfoInFunction << "Matrix dominance test for " << psi_.name() << nl << " number of non-dominant cells : " << nNon << nl << " maximum relative non-dominance : " << maxNon << nl << " average relative non-dominance : " << sumNon << nl << endl; } // Ensure the matrix is diagonally dominant... // Assumes that the central coefficient is positive and ensures it is forAll(D, celli) { D[celli] = max(mag(D[celli]), sumOff[celli]); } // ... then relax D /= alpha; // Now remove the diagonal contribution from coupled boundaries forAll(psi_.boundaryField(), patchi) { const fvPatchField<Type>& ptf = psi_.boundaryField()[patchi]; if (ptf.size()) { const labelUList& pa = lduAddr().patchAddr(patchi); Field<Type>& iCoeffs = internalCoeffs_[patchi]; if (ptf.coupled()) { forAll(pa, face) { D[pa[face]] -= component(iCoeffs[face], 0); } } else { forAll(pa, face) { D[pa[face]] -= cmptMin(iCoeffs[face]); } } } } // Finally add the relaxation contribution to the source. S += (D - D0)*psi_.primitiveField(); }

After the under relaxation the contribution of the pressure gradient is added to the right hand side of the matrix and the system is solve:

solve(UEqn == -fvc::grad(p));

The equation in semi discrete form looks as follows:

| (1) |

denotes the contribution of the pressure gradient to the equation of the cell centre p. It depends on the scheme chosen to discretize the gradient operator.

Important for the understanding of the later described pressure equation is that the contribution of the pressure equation is not added to the source therm of the
matrix object UEqn. Rather a new fvMatrix object is returned by the call of the overloaded operator == to the function solve:

UEqn == -fvc::grad(p)

The function solve is then executed, which solves the new fvMatrix object in order to obtain the estimate by also considering the contribution of the pressure equation. Note that the the volVectorField U is modified by solving the matrix since the solution vector of the matrix is a reference to U. An explanation of the the implementation can be found also in https://www.cfd-online.com/Forums/openfoam/213566-why-solve-ueqn-fvc-grad-p-ueqn-source-not-modified-ueqn-h-chang.html.

### 2.2 Pressure Equation

In this section the pressure equation solved in simpleFoam in order to ensure the mass conservation is derived. A good explanation of the derivation of the SIMPLE and also SIMPLEC method in simpleFoam can be found also in http://hobbyfoam.blogspot.com/2016/01/simplec-algorithm-of-openfoam.html.

Starting point for the derivation of the pressure equation is the momentum equation in semi discrete form after the solution of the momentum equation:

| (1) |

After dividing the above equation by we obtain:

| (1) |

are the modified diagonal coefficients of the matrix after the under relaxation.

The scope of the next step is to find a correction for the velocity and for the pressure in order to find a velocity which satisfies the continuum equation:

| (1) |

The equation for the velocity correction can be written as:

| (1) |

Note that here it is assumed that the diagonal coefficients of the corrector equation are the same as in the momentum equation previously solved. Taking the divergence of the above equation and setting it to zero (we want to obtain a velocity field which satisfies the continuity equation) we get an equation for the pressure :

| (1) |

denotes the values evaluated at the face.

#### 2.2.1 Simple

If we neglect the contribution of the neighbours of the velocity correction (i.e. we set ) we get the pressure equation solved in the simplec algorithm:

| (1) |

#### 2.2.2 Simplec

The starting point for the simplec algorithm is the equation for the velocity correction. The goal is the obtain a simplification to get an explicit relation for the velocity correction and hence avoiding to solve a matrix equation:

| (1) |

Inserting the above approximation into the equation for the velocity correction we get:

| (1) |

Solving for the velocity correction:

| (1) |

The above equation formulates an explicit relation between velocity and pressure equation. In the next step we write down:

| (1) |

By taking the divergence of the above equation and setting it to zero we obtain the pressure equation for the simplec algorithm:

| (1) |

The difference between the pressure equation in the SIMPLE and SIMPLEC consists only in one term.

The source code for the pressure equation can be seen here:

volScalarField rAU(1.0/UEqn.A()); volVectorField HbyA(constrainHbyA(rAU*UEqn.H(), U, p)); surfaceScalarField phiHbyA("phiHbyA", fvc::flux(HbyA)); MRF.makeRelative(phiHbyA); adjustPhi(phiHbyA, U, p); tmp<volScalarField> rAtU(rAU); if (simple.consistent()) { rAtU = 1.0/(1.0/rAU - UEqn.H1()); phiHbyA += fvc::interpolate(rAtU() - rAU)*fvc::snGrad(p)*mesh.magSf(); HbyA -= (rAU - rAtU())*fvc::grad(p); } tUEqn.clear(); // Update the pressure BCs to ensure flux consistency constrainPressure(p, U, phiHbyA, rAtU(), MRF); // Non-orthogonal pressure corrector loop while (simple.correctNonOrthogonal()) { fvScalarMatrix pEqn ( fvm::laplacian(rAtU(), p) == fvc::div(phiHbyA) ); pEqn.setReference(pRefCell, pRefValue); pEqn.solve(); if (simple.finalNonOrthogonalIter()) { phi = phiHbyA - pEqn.flux(); } } #include "continuityErrs.H" // Explicitly relax pressure for momentum corrector p.relax(); // Momentum corrector U = HbyA - rAtU()*fvc::grad(p); U.correctBoundaryConditions(); fvOptions.correct(U); }

### 2.3 Avoiding checker boarder effects

The usual way to avoid the so called "checker board" effect is to interpolate the velocities at the faces by means of the Rhie and Chow
interpolation (see e.g. ^{[3]} or ^{[4]}. ) .
The checker board effect has its origin in the absence of neighbouring pressure terms in the momentum equation due to the discretization of the pressure gradient term in the
frame of the finite volume method. The same absence of neighbouring pressure terms is obtained when the Laplacian term is discretized by linear interpolation of the pressure
gradient on the face centres.
In the implementation of the simpleFoam solver, the Rhie and Chow interpolation is not done in an explicit way. The introduction of neighbour pressure terms in the momentum
and pressure equation is done in the spirit of Rhie and Chow ^{[5]} . It is achieved by two contribution: The first one is the way the Laplacian term is disretized (see also http://www.tfd.chalmers.se/~hani/kurser/OS_CFD_2007/rhiechow.pdf).
The second contribution is achieved by the flux() operator after the solution of the pressure equation:

if (simple.finalNonOrthogonalIter()) { phi = phiHbyA - pEqn.flux(); }

### 2.4 Equations for the turbulence

# 3 References

- ↑ Moukalled, F., L. Mangani, and M. Darwish. "The finite volume method in computational fluid dynamics." An Advanced Introduction with OpenFOAM and Matlab (2016):
- ↑ Moukalled, F., L. Mangani, and M. Darwish. "The finite volume method in computational fluid dynamics." An Advanced Introduction with OpenFOAM and Matlab (2016):
- ↑ Moukalled, F., L. Mangani, and M. Darwish. "The finite volume method in computational fluid dynamics." An Advanced Introduction with OpenFOAM and Matlab (2016):
- ↑ Ferziger, Joel H., and Milovan Peric. Computational methods for fluid dynamics. Springer Science & Business Media, 2012.
- ↑ Jasak, Hrvoje. "Error analysis and estimation for the finite volume method with applications to fluid flows." (1996).