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

Residual definition of OpenFoam

Register Blogs Community New Posts Updated Threads Search

Like Tree6Likes
  • 1 Post By boddyouareboy
  • 3 Post By akidess
  • 2 Post By makaveli_lcf

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 9, 2011, 06:04
Default Residual definition of OpenFoam
  #1
New Member
 
......
Join Date: Jan 2011
Posts: 2
Rep Power: 0
boddyouareboy is on a distinguished road
Hi Dear Foamers,

I am a new guy of OpenFOAM, and I just run the test case of pitzDaily in the OpenFoam tutorial, but with 20000 iterations, Because it does not reach the tolerance 1e-6 yet. Anyway, I found that the initial residual has huge oscillation before it reach the tolerance(actually somewhere about 3e-5). So I want to figure out i) what is the type of the initial residual ii) why it behaves like this.

The first thing I do is to check the code (instead of searching answers from the form......). I went directly to the solver PCG and find the definition of the initial residual and finial residual, which will be like this:

solverPerf.initialResidual() = gSumMag(rA)/normFactor;
solverPerf.finalResidual() = solverPerf.initialResidual();

Then I found the definition of the norm Factor:

//-------------------------------------------------------
Foam::scalar Foam::lduMatrix::solver::normFactor
(
const scalarField& psi,
const scalarField& source,
const scalarField& Apsi,
scalarField& tmpField
) const
{
// --- Calculate A dot reference value of psi
matrix_.sumA(tmpField, interfaceBouCoeffs_, interfaces_);
tmpField *= gAverage(psi);
return gSum(mag(Apsi - tmpField) + mag(source - tmpField)) + matrix_.small_;
// At convergence this simpler method is equivalent to the above
// return 2*gSumMag(source) + matrix_.small_;
}
//-------------------------------------------------------------

and also the MACRO definitioin of gSumMag:

//-------------------------------------------------------------

#define G_UNARY_FUNCTION(returnType, gFunc, func, rFunc) \
\
template<template<class> class Field, class Type> \
returnType gFunc(const FieldField<Field, Type>& f) \
{ \
returnType res = func(f); \
reduce(res, rFunc##Op<Type>()); \
return res; \
} \
TMP_UNARY_FUNCTION(returnType, gFunc)
G_UNARY_FUNCTION(Type, gMax, max, max)
G_UNARY_FUNCTION(Type, gMin, min, min)
G_UNARY_FUNCTION(Type, gSum, sum, sum)
G_UNARY_FUNCTION(scalar, gSumMag, sumMag, sum)
#undef G_UNARY_FUNCTION


//----------------------------------------------------------------

Actually I got stuck here....... literally speaking, what I want is just to figure out what kind of norm does PCG (or other solvers ) use, and now I messed all the things up...... I GUESS it was L2 norm or Root Mean Square (RMS) because to my knowledge, only L2 norm is defined as SumFunc()/OtherSumFunc, but I do not know if it was correct.

So my question will be what is the initial residual does PCG use? And why after 20000 iterations, oscillation occurs?

Of couse I also want to understand what does these codes do, especially the macro part, which is really hard for me to understand. If someone can explain sth. about this, I'd really appreciate it!

Thanks for any scanner forward!

BR,
------------
bodyouareboy
Attached Images
File Type: png residual.png (5.4 KB, 492 views)
mm.abdollahzadeh likes this.
boddyouareboy is offline   Reply With Quote

Old   March 13, 2011, 14:30
Default
  #2
New Member
 
Join Date: Feb 2011
Posts: 20
Rep Power: 15
L1011 is on a distinguished road
Hi all!

Does anyone has an answer regarding the question of boddyouareboy? I'm also interested to figure out what type of residual is actually being calculated by OF.

Thank you!

L1011
L1011 is offline   Reply With Quote

Old   March 14, 2011, 05:39
Default
  #3
Senior Member
 
akidess's Avatar
 
Anton Kidess
Join Date: May 2009
Location: Germany
Posts: 1,377
Rep Power: 30
akidess will become famous soon enough
Quote:
Originally Posted by boddyouareboy View Post
[...]
and also the MACRO definitioin of gSumMag:

//-------------------------------------------------------------

#define G_UNARY_FUNCTION(returnType, gFunc, func, rFunc) \
\
template<template<class> class Field, class Type> \
returnType gFunc(const FieldField<Field, Type>& f) \
{ \
returnType res = func(f); \
reduce(res, rFunc##Op<Type>()); \
return res; \
} \
TMP_UNARY_FUNCTION(returnType, gFunc)
G_UNARY_FUNCTION(Type, gMax, max, max)
G_UNARY_FUNCTION(Type, gMin, min, min)
G_UNARY_FUNCTION(Type, gSum, sum, sum)
G_UNARY_FUNCTION(scalar, gSumMag, sumMag, sum)
#undef G_UNARY_FUNCTION


//----------------------------------------------------------------

[...]

Of couse I also want to understand what does these codes do, especially the macro part, which is really hard for me to understand. If someone can explain sth. about this, I'd really appreciate it!
The macro definition is just to save some coding effort for the authors. gXXX is the parallel safe version of all the sum, min, max functions (the only difference is an additional call to MPI_REDUCE). So gSumMag calls sumMag, and then accumulates the result on one CPU. sumMag itself will just sum up the magnitudes of the field components. So if I didn't miss anything your code snippet calculates an L1 norm.
akidess is offline   Reply With Quote

Old   March 15, 2011, 04:08
Default
  #4
New Member
 
Join Date: Feb 2010
Posts: 7
Rep Power: 16
sebi is on a distinguished road
Hello together,

as far as I understood it, it is a the L1-nrom since the magnitudes of the residual-vector are summed up.

But what still is a kind of miracle to me is the role of the normfactor. I don't see what it is necessary for.
sebi is offline   Reply With Quote

Old   May 13, 2011, 09:24
Default
  #5
Senior Member
 
Dr. Alexander Vakhrushev
Join Date: Mar 2009
Posts: 256
Blog Entries: 1
Rep Power: 19
makaveli_lcf is on a distinguished road
Send a message via ICQ to makaveli_lcf
The normalization is required, because you variables can vary in different ranges, so it is a kind of unifying the residuals for different scales in your equations.

But actually a found an issue, when the tol parameter is not so representative than relTol. For example in my case, for RANS simulation when I switch to the 2nd order, for some equations a strong source terms are produced due to non-orthogonal corrections in sqewed cells. If you analyze the line:

Code:
// At convergence this simpler method is equivalent to the above
// return 2*gSumMag(source) + matrix_.small_;
it gives you impression, that residuals a scaled actually to the magnitudes of the source term. And, as I described before, it can cause for some equation for under estimation of the domain residuals.

I tried to get from

Code:
gSum(mag(Apsi - tmpField) + mag(source - tmpField)) + matrix_.small_;
what is stated for the moment when we get convergence

Code:
// At convergence this simpler method is equivalent to the above
// return 2*gSumMag(source) + matrix_.small_;
but can not find the transition! Would be someone so kind to clarify this statement?


The solution is either to set tol to something around 1e-8...1e-10 with relTol 0, or use tol 1e-12 for all equations tuning the level of accuracy by e.g. relTol 0.001. So thus you define to improve your residuals for 3 orders. relTol can vary base are you making steady or transient calculations.
__________________
Best regards,

Dr. Alexander VAKHRUSHEV

Christian Doppler Laboratory for "Metallurgical Applications of Magnetohydrodynamics"

Simulation and Modelling of Metallurgical Processes
Department of Metallurgy
University of Leoben

http://smmp.unileoben.ac.at

Last edited by makaveli_lcf; May 13, 2011 at 12:38.
makaveli_lcf is offline   Reply With Quote

Old   March 16, 2017, 09:28
Default
  #6
Member
 
Fredi Cenci
Join Date: Dec 2016
Posts: 38
Rep Power: 9
fredicenci is on a distinguished road
Hey guys,

I know the post is old but I would like to clarify some questions about residuals.

1- As I understood residual is the difference between a field (phi) from one iteration to another, right? so is it Initial Residual? Final Residual?

2 -Can someone tell me how to get L1, L2 and L infinity from the log file? Equations are attached.

3 -If I decrease the tolerance of p,U then the final residual will be lower, right?


Is it possible? I dont know what type of residuals openfoam ii giving me on log file..

Code:
Time = 0.02

Courant Number mean: 0.107298 max: 1.36175
DILUPBiCG:  Solving for Ux, Initial residual = 0.959413, Final residual = 5.4585e-06, No Iterations 2
DILUPBiCG:  Solving for Uy, Initial residual = 0.317289, Final residual = 8.53016e-07, No Iterations 3
DICPCG:  Solving for p, Initial residual = 0.0109834, Final residual = 0.00109738, No Iterations 112
DICPCG:  Solving for p, Initial residual = 0.336017, Final residual = 0.0308665, No Iterations 17
time step continuity errors : sum local = 0.000179841, global = 1.53469e-07, cumulative = 1.16262e-07
DICPCG:  Solving for p, Initial residual = 0.260022, Final residual = 0.0227987, No Iterations 23
DICPCG:  Solving for p, Initial residual = 0.133745, Final residual = 8.55957e-07, No Iterations 180
time step continuity errors : sum local = 2.53382e-09, global = -4.25928e-11, cumulative = 1.16219e-07
If openfoam is giving me L1, how do I get L_infinity ? L_infinity = max |Delta (Phi_i)|, 1<i<Np

delta (Phi) is the local change of the flow quantity Phi. Np is the mesh total nodes.


Thanks


[Moderator note: merged 3 posts, one moved from L0, L1, L2 ,Linf error norms]
Attached Images
File Type: png resi.png (14.7 KB, 213 views)

Last edited by wyldckat; April 30, 2017 at 12:36. Reason: merged 3 posts on the same topic
fredicenci is offline   Reply With Quote

Old   March 18, 2017, 13:07
Default function
  #7
Member
 
Fredi Cenci
Join Date: Dec 2016
Posts: 38
Rep Power: 9
fredicenci is on a distinguished road
I didnt find any function to calculate the change of a variable (U,p,omega,k..) between consecutive time steps in all cells.
fredicenci is offline   Reply With Quote

Old   May 22, 2023, 05:56
Default
  #8
New Member
 
Anais Messaoudi
Join Date: May 2023
Posts: 3
Rep Power: 3
anais.M is on a distinguished road
Hi, does anyone have answers to fredicenci's questions please?

Thanks!
Anais M
anais.M 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
transsonic nozzle with rhoSimpleFoam Unseen OpenFOAM Running, Solving & CFD 8 July 1, 2022 07:54
Floating point exception error Alan OpenFOAM Running, Solving & CFD 11 July 1, 2021 22:51
How to write k and epsilon before the abnormal end xiuying OpenFOAM Running, Solving & CFD 8 August 27, 2013 16:33
Computational time sunnysun OpenFOAM Running, Solving & CFD 5 March 16, 2009 04:32
Differences between serial and parallel runs carsten OpenFOAM Bugs 11 September 12, 2008 12:16


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