CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Running, Solving & CFD

Residuals for convergence of segregated solvers

Register Blogs Community New Posts Updated Threads Search

Like Tree34Likes
  • 4 Post By henry
  • 1 Post By duderino
  • 22 Post By hjasak
  • 5 Post By hjasak
  • 1 Post By maka
  • 1 Post By mgc

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 13, 2005, 05:55
Default I would like to use residuals
  #1
New Member
 
Juergen Almanstoetter
Join Date: Mar 2009
Posts: 10
Rep Power: 17
almanstoetter is on a distinguished road
I would like to use residuals to observe the convergence behaviour of the SIMPLE segregated solver.
A measure for the residual R in finite-volume method nomenclature is:

Single cell: R_P = a_P * u_P + \sum_nb a_nb * u_nb - b_P

R = \sum_cells |R_P|

Can the methods .A() and .H() be used for the calculation of R ?

For example for the velocities from the momentum equation in a fashion like this:

volVectorField b = -1.*fvc::grad(pd)+fvc::grad(rho)*gh;
vector R = (sum(UEqn().A()*U)).value()-(sum(UEqn().H())).value()-(sum(b)).value();
Info <<mag(R.x())<< " "<<mag(R.y()))<< " "<< mag(R.z())<<endl;

I know, the magnitude should be taken of R_P not of R like in the above equations. How to formulate this correctly ?

Juergen
almanstoetter is offline   Reply With Quote

Old   July 13, 2005, 08:04
Default The solver returns a solverPer
  #2
Senior Member
 
Join Date: Mar 2009
Posts: 854
Rep Power: 22
henry is on a distinguished road
The solver returns a solverPerformance class which may have everything you need:

//- Class returned by the solver
// containing performance statistics
class solverPerformance
{
word solverName_;
word fieldName_;
scalar initialResidual_;
scalar finalResidual_;
label noIterations_;
bool converged_;
bool singular_;
...

which you can get access to simply be keeping it after solution e.g.

lduMatrix::solverPerformance sp = solve(...

or

lduMatrix::solverPerformance sp = xEqn.solve();

then you can use the access functions to get hold of the residuals etc. e.g.

sp.initialResidual()
henry is offline   Reply With Quote

Old   September 13, 2005, 08:47
Default Hi Can somebody please tel
  #3
Member
 
Duderino
Join Date: Mar 2009
Posts: 40
Rep Power: 17
duderino is on a distinguished road
Hi

Can somebody please tell me how the residuals (initial and final) are defined and where I can find the definition!

Thanks!
granzer likes this.
duderino is offline   Reply With Quote

Old   September 13, 2005, 15:07
Default Me too.
  #4
Senior Member
 
Billy
Join Date: Mar 2009
Posts: 167
Rep Power: 17
billy is on a distinguished road
Me too.
billy is offline   Reply With Quote

Old   September 14, 2005, 07:17
Default For matrix A x = b, resi
  #5
Senior Member
 
Hrvoje Jasak
Join Date: Mar 2009
Location: London, England
Posts: 1,905
Rep Power: 33
hjasak will become famous soon enough
For matrix

A x = b,

residual is defined as

res = b - Ax

We then apply residual scaling with the following normalisation factor procedure:

Type xRef = gAverage(x);


wA = A x;
pA = A xRef;

normFactor =
gSum(cmptMag(wA - pA) + cmptMag(source - pA))
+ matrix.small_;

and the scaled residual is:

residual =
gSum(cmptMag(source - wA))/normFactor;

I will save you from complications with vectors and tensors in my block solver. :-)

Enjoy,

Hrv
__________________
Hrvoje Jasak
Providing commercial FOAM/OpenFOAM and CFD Consulting: http://wikki.co.uk
hjasak is offline   Reply With Quote

Old   September 14, 2005, 16:45
Default Thanks Dr. Jasak but it is
  #6
Member
 
Duderino
Join Date: Mar 2009
Posts: 40
Rep Power: 17
duderino is on a distinguished road
Thanks Dr. Jasak

but it is not clear to me what is:
1. gAverage What means the g?
2. gSum What means the g
3. matrix.small_
4. is source

Best regards jens
duderino is offline   Reply With Quote

Old   September 14, 2005, 17:04
Default 1. gAverage is like average, b
  #7
Senior Member
 
Hrvoje Jasak
Join Date: Mar 2009
Location: London, England
Posts: 1,905
Rep Power: 33
hjasak will become famous soon enough
1. gAverage is like average, but if you're running in parallel, you do average over all processors

2. gSum is like sum, but if in parallel you sum up over all processors

3. matrix.small: lduMatrix.C

const scalar lduMatrix::small_ = 1.0e-20;

4. source is b

Have a look at the code, always instructive :-)

Hrv
shipman, randolph, mrishi and 2 others like this.
__________________
Hrvoje Jasak
Providing commercial FOAM/OpenFOAM and CFD Consulting: http://wikki.co.uk
hjasak is offline   Reply With Quote

Old   April 18, 2006, 08:48
Default hello I need to compare the r
  #8
New Member
 
Aurelia Cure
Join Date: Mar 2009
Location: Lund, Sweden
Posts: 18
Rep Power: 17
aurelia is on a distinguished road
hello
I need to compare the residual of an analytical solution with the residual of the solution computed by simpleFoam after one iteration.
actually, i need rA (=source-wA) in each cell.
the solverperformance returned in BIccG.C,are average of the residual in the domain
but in my case, I would like to create a vectorField R where the scalarField Rx=R.x() is the residuals computed when soving Ux, R.y() corresponds to Uy and R.z() corresponds to Uz.
My problem is that I am not able to access to the different step (solve ux, solve uy and solve Uz) in "solve UEqn"

Thanks for your help!
Aurelia
aurelia is offline   Reply With Quote

Old   January 25, 2007, 10:05
Default Hi all and sorry for posting i
  #9
Member
 
cosimo bianchini
Join Date: Mar 2009
Location: Florence, Tuscany, Italy
Posts: 88
Rep Power: 17
cosimobianchini is on a distinguished road
Send a message via Skype™ to cosimobianchini
Hi all and sorry for posting in this old thread but I found it very inherent with what I'm searching.

Quote from Jasak's post:
-------------------------------------------------------------
For matrix

A x = b,

residual is defined as

res = b - Ax

We then apply residual scaling with the following normalisation factor procedure:

Type xRef = gAverage(x);


wA = A x;
pA = A xRef;

normFactor =
gSum(cmptMag(wA - pA) + cmptMag(source - pA))
+ matrix.small_;

and the scaled residual is:

residual =
gSum(cmptMag(source - wA))/normFactor;

-------------------------------------------------------------

I got this problem:

InitialResidual goes very low (10e-7 and more) after few iteration when x gets very high values only in a small zone of domain (like turbulent specific dissipation [omega] at the wall) meaning that xRef is almost as big as xMax (most of the domain is basically not contributing) very different from the "mean" value. (Hope I have been clear enough)
It follows that pA differs a lot from wA and finally the normalization factor is too big.
My idea is so to do something like:

residual = gSum(cmptMag((source - wA)/wA))

I have no need to change directly lduMatrix::solverPerformance.initialResidual()
I just want to use this variable to monitor convergence properties but I'm not sure if I have undersood correctly how the following methods and classes work:

1) Let xEqn be a fvScalarMatrix then
volScalarField xEqn.residuals() = source - wA (without scaling)

2)
lduMatrix::solverPerformance sp = xEqn().solve()
scalar sp.initialResidual() = gSum(cmptMag(source - wA))/normFactor (with normFactor like in Jasak's post)

3)
errorEstimate<scalar> eE(x_,x_.dimensions(),xEqn().residuals(),x.interna lField());
eE.error()= gSum(cmptMag(source - wA)/cmptMag(wA))

Is it true?
I'm in the need for sharing my thoughts to be sure not have misunderstood everything.
Thanks a lot for comment on these.
Best Regards
Cosimo
__________________
Cosimo Bianchini

Ergon Research s.r.l.
Via Panciatichi, 92
50127 Florence - ITALY
Tel: +39 055 0763716
Mob: +39 320 9460153
e-mail: cosimo.bianchini@ergonresearch.it
URL: www.ergonresearch.it
cosimobianchini is offline   Reply With Quote

Old   July 24, 2008, 06:04
Default (1) In Ferziger and Peric book
  #10
Senior Member
 
Maka Mohu
Join Date: Mar 2009
Posts: 305
Rep Power: 18
maka is on a distinguished road
(1) In Ferziger and Peric book,
they say that sometimes the residuals can be small even when the error is large and that this is even worse for poorly conditioned matrix. How does the poorly conditioning cause that?

(2) In case we choose our residual criterion based on Tol, is such argument valid here. I ask because in the documention it was mentioned that the objective of normalization is to make the residuals independent of problem scale (not to condition the matrix).

(3) They recommend that we should use residual drop to be 1-2 order of magnitude for inner iterations (that is the pressure equation) and 3-5 for outer iterations (that would be the difference between the initial residual in pressure correction 1 compared to its value at pressure correction n). What do you think? Any experience with that.

Thanks.

Best regards,
Maka.
Tobi likes this.
maka is offline   Reply With Quote

Old   February 24, 2009, 16:21
Default Dear All, Is it possible to
  #11
Senior Member
 
Gavin Tabor
Join Date: Mar 2009
Posts: 181
Rep Power: 17
grtabor is on a distinguished road
Dear All,

Is it possible to access the residuals from the turbulence model object? I've rewritten (just for fun) simpleFoam to use a do...while loop which exits when the p and U residuals drop below specified values. I would like to be able to monitor the solution of the k and epsilon equations, but can't see how to do this (other than rewriting the whole of RASmodels).

Gavin
grtabor is offline   Reply With Quote

Old   April 16, 2009, 14:59
Default "checkConvergence()" for fvVectorMatrix??
  #12
mgc
New Member
 
Maria
Join Date: Apr 2009
Posts: 12
Rep Power: 17
mgc is on a distinguished road
Hi!

I would like to check "UEqn" convergence inside an internal loop of my own solver.

[...]

--> I fixed it! I missed that UEqn was defined as a tmp! Now it works fine.

tmp<fvVectorMatrix> UEqn
(
fvm::div(phi, U)
- fvm::Sp(fvc::div(phi), U)
+ turbulence-> divRhoR(U)
);

lduMatrix::solverPerformance spU = UEqn().solve();

--> For more info about checking convergence have a look at: ~/OpenFOAM/OpenFOAM-1.5-dev/applications/solvers/compressible/rhoSimpleFoam

:-)
mm.abdollahzadeh likes this.

Last edited by mgc; April 28, 2009 at 13:32.
mgc is offline   Reply With Quote

Old   May 15, 2020, 10:34
Default
  #13
Senior Member
 
Reviewer #2
Join Date: Jul 2015
Location: Knoxville, TN
Posts: 141
Rep Power: 10
randolph is on a distinguished road
Hrvoje,

Could you elaborate more on why OpenFOAM choose this guy as denominator? What is the interpretation?

normFactor =
gSum(cmptMag(wA - pA) + cmptMag(source - pA))
+ matrix.small_;


Thanks,
Rdf
randolph is offline   Reply With Quote

Old   September 7, 2020, 17:58
Lightbulb
  #14
New Member
 
Duc Anh
Join Date: Dec 2018
Posts: 22
Rep Power: 7
anhkenyt is on a distinguished road
Hi Jasak,
Thanks a lot for your post, I know this is an old thread but I got a problem. When comparing the residual of your analytical solution with the residual of icoFoam in UEqn's equation, what is function extract with gAverageU (Uref= gAverage(U) ? And how to handle this fuction.
This is my code in icoFoam
Code:
fvVectorMatrix UEqn
        (
            fvm::ddt(U)
          + fvm::div(phi, U)
          - fvm::laplacian(nu, U)
        );
if (piso.momentumPredictor())
        {
            solve(UEqn == -fvc::grad(p));
        }
        Info<< "    Calculating uResidual" << endl;
        volScalarField uResidual
        (
                IOobject
                (
                    "uResidual",
                    runTime.timeName(),
                    mesh,
                    IOobject::NO_READ,
                    IOobject::AUTO_WRITE
                ),
                
         );
        volVectorField  Uref= gAverage(U);
        fvVectorMatrix UEqnRef
        (
            fvm::ddt(Uref)
          + fvm::div(phi, Uref)
          - fvm::laplacian(nu, Uref)
        );
        volVectorField normFactor = gSum(cmptMag(UEqn-UEqnRef)
                                          + cmptMag(-fvc::grad(p)- UEqnRef))
                                       + matrix.small_;
        uResidual = gSum(cmptMag(-fvc::grad(p) - UEqn))/normFactor;
I have a error:
error: conversion from ‘Foam::Vector<double>’ to non-scalar type ‘Foam::volVectorField {aka Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh>}’ requested
volVectorField Uref= gAverage(U);
Thanks a lot for comment on these.
Best Regards
anhkenyt is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Block matrices vs segregated solvers fisher OpenFOAM Running, Solving & CFD 9 June 13, 2010 04:15
convergence of segregated solver Bill Main CFD Forum 2 March 7, 2009 02:15
Segregated flow solver and no convergence Ankit Purohit Siemens 0 June 15, 2007 09:22
Convergence Definition of Segregated Solver Amir FLUENT 0 April 18, 2006 06:21
coupled solver vs segregated solvers RajaniKumar Main CFD Forum 0 December 3, 2001 06:15


All times are GMT -4. The time now is 19:56.