How to compute the discretization length in OpenFOAM

To plot the convergence on unstructured meshes, the discretization length “h” is required.

OpenFOAM computes $$ 1.0/∥xPf−xNf∥2 $$, inversed distance between two cell centers (N = neighbor, O = owner, O < N), for each face f in the mesh, and stores this in the deltaCoeffs field. This is computed by the surfaceInterpolation class, redirected from the fvMesh class:

fvmesh

Minimal example that computes minimal, average and the maximal discretization distance

#include "fvCFD.H"
 
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
int main(int argc, char *argv[])
{
    #include "setRootCase.H"
    #include "createTime.H"
    #include "createMesh.H"
 
    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
     
    const auto& deltaCoeffs = mesh.deltaCoeffs();
     
    Info << "h_min = " << 1. / max(deltaCoeffs()).value() << endl
        << "h_mean = " << 1. / average(deltaCoeffs()).value() << endl
        << "h_max = " << 1. / min(deltaCoeffs()).value() << endl;
     
    Info<< nl;
    runTime.printExecutionTime(Info);
 
    Info<< "End\n" << endl;
 
    return 0;
}

The application is on Bitbucket.

See also