CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Getting iterations number of matrix solver (https://www.cfd-online.com/Forums/openfoam-programming-development/149329-getting-iterations-number-matrix-solver.html)

danny123 March 2, 2015 11:56

Getting iterations number of matrix solver
 
Hi,

I am trying to get the number of iterations of the matrix solver (e.g. PCG) back into the application solver, such as interFoam etc. I have looked at the code. In ldumatrix.H the iteration number is defined under solverPerformance.

There are other values that I can get. If I call prghEq.residual(), I get the residual vector of the ldumatrix calculation. Is there some simple trick to get the iteration number? The iteration number of the matrix solver is printed out on screen, but this is done within a seperated routine (while the matrix solver is called).

Regards,

Daniel

alexeym March 2, 2015 13:01

Hi,

Solve method returns SolverPerformance object. Using this object you can learn initial residual, final residual and number of iterations.

danny123 March 3, 2015 03:14

Thanks alexeym,

I got to that page already. In InterDymFoam the pressure equation is called like this:

Code:

while (pimple.correctNonOrthogonal())
    {
        fvScalarMatrix p_rghEqn
        (
            fvm::laplacian(rAUf, p_rgh) == fvc::div(phiHbyA)
        );

        p_rghEqn.solve(mesh.solver(p_rgh.select(pimple.finalInnerIter())));

      ...

So solve is already called. I do not understand what "solve" calls in this case (I guess it ought to stop iteration when it exceeds the maximum number, but I am not sure.

p_rghEqn has a number of objects that can be called directly (e.g. A, residuals() etc.), but not the number of iterations. What you suggest is to change the solve call, I assume, but how?

I had already the idea to add a new object to fvMatrix, but it is not that easy to get the number of iterations of the matrix solver.

Regards,

Daniel

alexeym March 3, 2015 03:52

Hi,

You can access nIterations with something like this:

Code:

        const solverPerformance& sp =
            p_rghEqn.solve(mesh.solver(p_rgh.select(pimple.finalInnerIter())));

        Info<< sp.nIterations() << endl;


danny123 March 3, 2015 08:00

Thanks, works as a charme!

Regards Daniel


All times are GMT -4. The time now is 09:03.