CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Bugs (https://www.cfd-online.com/Forums/openfoam-bugs/)
-   -   A tiny error in linear PCG solver (https://www.cfd-online.com/Forums/openfoam-bugs/193957-tiny-error-linear-pcg-solver.html)

Zeppo October 7, 2017 11:22

A tiny error in linear PCG solver
 
A tiny error in linear PCG solver.
https://cpp.openfoam.org/v5/PCG_8C_source.html#l00066
It does one more iteration than specified in variable maxIter_ (which is read from system/fvSolution dictionary):
Code:

// “PCG.C”
Foam::solverPerformance Foam::PCG::solve
(
    ...
) const
{
    ...
    // --- Solver iteration
    do
    {
        ...
    } while
    (
        (
            solverPerf.nIterations()++ < maxIter_
            ...
        )
        ...
    );
    ...
}

Here the loop condition is evaluated first, then number of iterations is incremented. The sequence of operations must be in the reverse order:
Code:

// “PCG.C”
Foam::solverPerformance Foam::PCG::solve
(
    ...
) const
{
    ...
    // --- Solver iteration
    do
    {
        ...
    } while
    (
        (
            ++solverPerf.nIterations() < maxIter_
            ...
        )
        ...
    );
    ...
}


Tobi October 9, 2017 04:37

Hi Sergei,

I came across of that problems several times but never thought about that :) However, based on your post, I thought it is worth to mention in the bug-tracking system:

https://bugs.openfoam.org/view.php?id=2716

Tobi October 9, 2017 07:26

It is already resolved by the commit: https://github.com/OpenFOAM/OpenFOAM...7f0fa442d4ac56

In addition henry changed it in two other gradient based solvers

Zeppo October 14, 2017 06:32

Hi, Tobias. Thanks for taking a burden of posting a bug report from me. The error was found a while ago but was left where it sat till recent moment. Sometimes searching for a bug in the code can be fun.


All times are GMT -4. The time now is 16:35.