CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > OpenFOAM

Residual definition of OpenFoam

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree4Likes
  • 1 Post By boddyouareboy
  • 1 Post By akidess
  • 2 Post By makaveli_lcf

Reply
 
LinkBack Thread Tools 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, 262 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: 7
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: Delft, Netherlands
Posts: 1,079
Rep Power: 20
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.
Tushar@cfd likes this.
akidess is offline   Reply With Quote

Old   March 15, 2011, 04:08
Default
  #4
New Member
 
Join Date: Feb 2010
Posts: 7
Rep Power: 8
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, 08:24
Default
  #5
Senior Member
 
Dr. Alexander Vakhrushev
Join Date: Mar 2009
Posts: 214
Rep Power: 11
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 "Advanced Process Simulation of
Solidification and Melting"

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

Franz-Josef-Str. 18
A - 8700 Leoben
Österreich / Austria
Tel.: +43 3842 - 402 - 3125
http://smmp.unileoben.ac.at

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

Reply

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
transsonic nozzle with rhoSimpleFoam Unseen OpenFOAM Running, Solving & CFD 7 April 16, 2014 03:38
How to write k and epsilon before the abnormal end xiuying OpenFOAM Running, Solving & CFD 8 August 27, 2013 15:33
Floating point exception error Alan OpenFOAM Running, Solving & CFD 10 April 6, 2012 14:02
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 11:16


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