How to use OpenFOAM warning and error messages

OpenFOAM/foam has its own warnings and errors that can be used in the code.

The warnings are defined as macros in $FOAM_SRC/OpenFOAM/messageStream.H for OpenFOAM, and $FOAM_SRC/foam/messageStream.H for foam-extend. The error message stream macros are located in error.H, it can also be found in $FOAM_SRC/OpenFOAM/lnInclude or $FOAM_SRC/foam/lnInclude, depending on the OF version used.

They can be used in the code, together with the formatting described in the article How to get function names from within functions in C++ for example like this:

if(mesh.nCells() > 64 * 64 * 64)
    WarningIn(__PRETTY_FUNCTION__)
        << "RBF system factorization is memory intensive: NxN x nCells x 64 bits.\n";

The result is:

Create time
 
Create mesh for time = 0

--> FOAM Warning :
    From function int main(int, char**)
    in file lentTestrbfCellsInterpolationEigen.C at line 128
    RBF system factorization is memory intensive: NxN x nCells x 64 bits.

See also