
[Sponsors] 
February 9, 2011, 06:04 
Residual definition of OpenFoam

#1 
New Member
......
Join Date: Jan 2011
Posts: 2
Rep Power: 0 
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 1e6 yet. Anyway, I found that the initial residual has huge oscillation before it reach the tolerance(actually somewhere about 3e5). 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 

March 13, 2011, 14:30 

#2 
New Member
Join Date: Feb 2011
Posts: 20
Rep Power: 9 
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 

March 14, 2011, 05:39 

#3  
Senior Member
Anton Kidess
Join Date: May 2009
Location: Germany
Posts: 1,280
Rep Power: 23 
Quote:


March 15, 2011, 04:08 

#4 
New Member
Join Date: Feb 2010
Posts: 7
Rep Power: 10 
Hello together,
as far as I understood it, it is a the L1nrom since the magnitudes of the residualvector 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. 

May 13, 2011, 08:24 

#5 
Senior Member

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 nonorthogonal 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_; I tried to get from Code:
gSum(mag(Apsi  tmpField) + mag(source  tmpField)) + matrix_.small_; Code:
// At convergence this simpler method is equivalent to the above // return 2*gSumMag(source) + matrix_.small_; The solution is either to set tol to something around 1e8...1e10 with relTol 0, or use tol 1e12 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 http://smmp.unileoben.ac.at Last edited by makaveli_lcf; May 13, 2011 at 11:38. 

March 16, 2017, 09:28 

#6 
Member
Fredi Cenci
Join Date: Dec 2016
Posts: 33
Rep Power: 3 
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.4585e06, No Iterations 2 DILUPBiCG: Solving for Uy, Initial residual = 0.317289, Final residual = 8.53016e07, 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.53469e07, cumulative = 1.16262e07 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.55957e07, No Iterations 180 time step continuity errors : sum local = 2.53382e09, global = 4.25928e11, cumulative = 1.16219e07 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] Last edited by wyldckat; April 30, 2017 at 11:36. Reason: merged 3 posts on the same topic 

March 18, 2017, 13:07 
function

#7 
Member
Fredi Cenci
Join Date: Dec 2016
Posts: 33
Rep Power: 3 
I didnt find any function to calculate the change of a variable (U,p,omega,k..) between consecutive time steps in all cells.


Thread Tools  
Display Modes  


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 