CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM (
-   -   plot of residuals (

hawkeye321 December 6, 2012 10:57

plot of residuals
I am solving a set of equations which are coupled with he (U, V) momentum. The equations are solved in an implicit manner, i.e. in each time step all the equations are solved couple of times (~ 18). So, as you might expect, for each time step my final log file includes residuals at all the the iterations (~18 residual for each time step). Do you have any idea how I can filter this file to get the final residuals at each time step?

mmkr825 December 6, 2012 14:01


Just Follow the steps:

step1. start calculation and make it write out a log-file.
e.g: icoFoam > log &
step2: If desired you can open a new console window of the main case folder (when your case is runniong) and Follow the text -output by the command tail -f log
To stop reading the file constantly just use ctrl-c
step3: By using gnuplot with in the main case folder you have to put a text file with a name "Residuals" having


set logscale y
set title "Residuals"
set ylabel 'Residual'
set xlabel 'Iteration'
plot "< cat log | grep 'Solving for Ux' | cut -d' ' -f9 | tr -d ','" title 'Ux' with lines,\
"< cat log | grep 'Solving for Uy' | cut -d' ' -f9 | tr -d ','" title 'Uy' with lines,\
"< cat log | grep 'Solving for Uz' | cut -d' ' -f9 | tr -d ','" title 'Uz' with lines,\
"< cat log | grep 'Solving for omega' | cut -d' ' -f9 | tr -d ','" title 'omega' with lines,\
"< cat log | grep 'Solving for k' | cut -d' ' -f9 | tr -d ','" title 'k' with lines,\
"< cat log | grep 'Solving for p' | cut -d' ' -f9 | tr -d ','" title 'p' with lines
pause 1

Step4: Execute the command
gnuplot Residuals-
then you can get residuals plot.


hawkeye321 December 6, 2012 18:09


Thanks for your answer, but I have already tried it. It gives me a plot of all the residuals and not the plot of final residual (residual of the final iteration) at each time step.

Lieven December 7, 2012 07:51

Dear Mahdi,

You can run
$ foamLog log

which creates a new directory 'logs' in which you can find all residuals (initial, final, etc.) in separate files for all variables. You can make a plot of the residuals in function of the iteration number or in function of the simulated time. Suppose you want to make a plot of the final residual of Ux, the gnuplot command will look like:

* In function of the simulated time:

plot 'UxFinalRes_0' u 1:2 w l
* In function of the time step:

plot 'UxFinalRes_0' u 0:2 w l
Just out of curiosity, why whould one be interested in the final residual?

Kind regards,


Bernhard December 7, 2012 08:54

You can also use pyFoam:

hawkeye321 December 7, 2012 10:05

Dear Lieven
Thanks for your wonderful comments. I will try it very soon.
The reason that I want to see this plot is that, in my final velocity contours, I have some flow into the wall, which I defiantly because of relatively low residuals (Right???). So, I want to see these plots to make sure my solution has acceptable level of convergence. If you have better ideas, i would love to hear.


All times are GMT -4. The time now is 22:01.