Residuals Log Plot


I need to plot my residuals in log form.


I read around and it seems that BF still doesn’t have the possibility to plot it within BF.

I tried to adding a “ln” component to the values of the residuals, but it it gave me error, perhaps also because I can only collect the last iteration values, not all the iterations ones within BF.
However the “normal” values creat the full plot of all iterations, so is it possible to extract all those values in an easier way than through the file of the case, through BF? Then I could do the log in excel…

I therefore followed the steps expained on this article:

which seems to work until I get to the visualisation: it seems to need “Gnuplot”, I installed the latest version 5.2.4 but it gives me this error:
" [ofuser@default outdoor_airflow]$ foamMonitor -l postProcessing/residuals/0/residuals.dat

"/tmp/tmp.tp8K3gKJCC", line 7: function to plot expected

gnuplot: unable to open display ‘’
gnuplot: X11 aborted."

Please how can I visualise the results with Gnu?
Is it a problem of the version of Gnu (release June 2018) while OF is 1706? Alternatively please?

What is the “residual control” default value in the “SteadyIncompress” component? And what is the residual control component for? If it’s to set the precision of the final resduals, then does the number of the iterations needs to be left empty, as BF will run until the set residuals will be obtained?

I did tests with 600 iterations or less, they do work.
Now I tried 2000 iterations, and it’s the 3rd time that the simulation stops at 672nd iteration. Why is this happening please? Is this connected to the definition of my mesh, and therefore after 672 iterations I don’t get the convergence and therefore it stops? ANy other idea?

Thank you very much.

@TheodorosGalanos @mostapha @devang

I believe your first question is solved now correct? When you get time, share it with the rest so they can also use it in the future.

For question 2, residual control sets the limit (upper limit) for your simulation. It simply means it would keep running until either you reach the final iteration OR you reach a residual error less than your values there (default 10-4).

For question 3, I would guess it’s converging (that’s why it’s stopping at the same point). Hard to tell without a screen of the terminal.

Kind regards,

so, for question 1, this is the way it worked for me, writing in OF:

  1. cd workingDir/butterfly/outdoor_airflow/log
  2. gnuplot

set term png
set logscale y
set out “graph-l.png”
set title “Residuals”
set ylabel ‘Residual’
set xlabel ‘Iteration’
plot “< cat simpleFoam.log | grep ‘Solving for Ux’ | cut -d’ ’ -f9 | tr -d ‘,’” title ‘Ux’ with lines,
“< cat simpleFoam.log | grep ‘Solving for Uy’ | cut -d’ ’ -f9 | tr -d ‘,’” title ‘Uy’ with lines,
“< cat simpleFoam.log | grep ‘Solving for Uz’ | cut -d’ ’ -f9 | tr -d ‘,’” title ‘Uz’ with lines,
“< cat simpleFoam.log | grep ‘Solving for epsilon’ | cut -d’ ’ -f9 | tr -d ‘,’” title ‘epsilon’ with lines,
“< cat simpleFoam.log | grep ‘Solving for k’ | cut -d’ ’ -f9 | tr -d ‘,’” title ‘k’ with lines,
“< cat simpleFoam.log | grep ‘Solving for p’ | cut -d’ ’ -f9 | sed -n ‘p;N;N’ | tr -d ‘,’” title ‘p’ with lines

  1. set out

By deleting the “set logscale y” you get a similar graph for the non logarithmic values, if you want to match the graphic style. This doesn’t require to set anything, e.g. log files, etc, but this string in OF, so I found it great, in case you need to delete the case and don’t want to input all again from zero every time.

For answer 2, Theodore, thank you, I only don’t know how to override the nr of iterations, as what I care is the residual error, so I don’t want BF to stop at the iterations, if the residual erors have not reached the level I want. At the moment I am setting a super high nr of iterations to avoid this, not sure if there is a better way please…?

Answer 3, I actually deleted the case on both machines and re-ran from scratch and results this time matched, so all good.

Thank you.


I am using OpenFOAM 5.x mingw-w64 with Buterfly, and I also had problems to plot the residuals.
I tried to follow the same git.hub post suggested, but I had to add one line in the code: libs            (""): 

libs (“”);
type residuals;
writeControl timeStep;
writeInterval 1;

If someone has the same problem, I thought it was worth sharing the experience.
Best regards,