CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM (
-   -   Write cell residual value in the solution? (

be_inspired October 1, 2010 08:04

Write cell residual value in the solution?
Hi all,

with respect to other commercial cfd codes, I miss the possibility to plot the cell residual value (Ux, Uy, p, k, epsilon) in the same way as velocity or pressure and so, detect mesh problems or computational problem in the fluid domain......

Does anyone know if there is this option with openfoam or how to implement it into the code?

Thanks in advance

l_r_mcglashan October 1, 2010 08:31

Say you have a scalar transport equation


fvScalarMatrix aField
          + fvm::div(phi, aField)

        eqnResidual = aField.solve().initialResidual();
        maxResidual = max(eqnResidual, maxResidual);

initialResidual() in Foam::lduMatrix::solverPerformance and residual() in Foam::fvMatrix will give the quantities you are looking for.

nikwin October 1, 2010 12:33

I'm also interested in computing the residual, since I need it for a low-dimensional model via POD modes.

Do you know what residual() in Foam::fvMatrix actually computes? I would like to compute the residual (the spatial part of the mom. eq. in rhoPisoFoam) for every cell. However, as a check I tried but I can't get the complete momentum equation to be fulfilled!? Tried the following below. Any idea of what could be wrong?

1) The following two equals, UEqn1Residual == UEqn_Expl_Residual , i.e the .residual() should be divided by the cell volume! And the terms can be computed explicitly, see computations below. (Have also computed the transient term with fvc and fvm which gave the same results!)

fvVectorMatrix UEqn1
fvm::div(phi, U)
+ turbulence->divDevRhoReff(U)
+ fvc::grad(p)

vectorField UEqn1Residual(UEqn1.residual());

volVectorField UEqn1_Residual(UEqn1_Residual[cellI] = UEqn3Residual[cellI]/mesh.V()[cellI]);

volVectorField UEqn_Expl_Residual(
fvc::div(phi, U)
- muEff*fvc::laplacian(U)
- muEff*fvc::div(dev2(fvc::grad(U)().T()))
+ fvc::grad(p));

2) I've computed the transient term as a volField (fvc::ddt(rho, U)) and the spatial terms as a fvMatrix separately. To check that the momentum eq. is fulfilled I added the transient term with the residual of the spatial terms divided by the cell volume. And the results are far from zero!!!?

All the Best

be_inspired October 4, 2010 05:18

Sorry but I do not understand what I have to do. I have not handed on openfoam code so I have no idea.
What I want is to plot with paraView or Tecplot ( with foamToTecplot) the cell residual value ( pressure or Ux, Uy, Uz) but I do not Know what part of the code (files ) I have to modify to obtain this.

Could you explain slowly what I have to do it? Please.
I will put my best.

PD: I am running simpleFoam. OF 1.6.x

nikwin October 4, 2010 05:37

I'm myself are trying to get the residuals and my reply to your thread is just another question to why I'm not getting the result I'm expecting.

However, to answer your question you can look at the code in the following thread,


All times are GMT -4. The time now is 00:13.