CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (http://www.cfd-online.com/Forums/openfoam-solving/)
-   -   Residual Plotting Script (http://www.cfd-online.com/Forums/openfoam-solving/129844-residual-plotting-script.html)

RodriguezFatz February 14, 2014 05:34

Residual Plotting Script
 
Hi all,

I made some handy script to plot residuals during runtime using gnuplot. It works with SIMPLE and PIMPLE, probably also with other solvers.
First of all, you need to get the OpenFOAM terminal output into a file. This is done by starting OpenFoam with the ">log" command, such as:

mpirun -np 4 pimpleFoam -parallel >log


or just

simple >log

where "log" is the name of the file with the output.
Now, create some new file "plotscript" in the same folder and copy this text into it:
Code:

set logscale y
set title "Residuals"
set ylabel 'Residual'
set xlabel 'Iteration'
set key outside
set grid

nCorrectors=1
nNonOrthogonalCorrectors=3

nCont = nCorrectors
nP = (nNonOrthogonalCorrectors+1)*nCont
nPSkip = nP-1
nContSkip = nCont-1



plot "< cat log | grep 'Solving for Ux' | cut -d' ' -f9 | tr -d ','" title 'Ux' with linespoints,\
"< cat log | grep 'Solving for Uy' | cut -d' ' -f9 | tr -d ','" title 'Uy' with linespoints,\
"< cat log | grep 'Solving for Uz' | cut -d' ' -f9 | tr -d ','" title 'Uz' with linespoints,\
"< cat log | grep 'Solving for k' | cut -d' ' -f9 | tr -d ','" title 'k' with linespoints,\
"< cat log | grep 'Solving for epsilon' | cut -d' ' -f9 | tr -d ','" title 'epsilon' with linespoints,\
"< cat log | grep 'time step continuity errors :' | cut -d' ' -f9 | tr -d ','" every nCont::nContSkip title 'continuity' with linespoints,\
"< cat log | grep 'Solving for p' | cut -d' ' -f9 | tr -d ','" every nP::nPSkip title 'p' with linespoints lc 8
pause 1
xmax = GPVAL_DATA_X_MAX+2
xmin = xmax-40
set xrange [xmin:xmax]
reread

This should be pretty self-explanatory, but if you have any questions please post!
You need to adapt the upper two numbers nCorrectors and nNonOrthogonalCorrectors to your case, because they need to delete all the intermediate steps of the pressure solving.
Also, for long runs I implemented the stuff between "pause 1" and "reread" which will show only the last 40 steps. You can change it to any number or switch off completely by putting a "#" at the beginning of each line. Of course, change "epsilon" to "omega" if you use some k-omega turbulence model.

Have fun,
Philipp.

jherb February 14, 2014 10:42

Using your code I get the following error message:
Code:

"Residuals", line 26: undefined variable: GPVAL_DATA_X_MAX
> gnuplot --version
gnuplot 4.2 patchlevel 3


RodriguezFatz February 14, 2014 11:09

Hi Joachim,

I got two ideas:
i) Your version is too old, I use 4.6
ii) The initial "plot" command did not work. Variable "GPVAL_DATA_X_MAX" is created by gnuplot after a plot was successfully done. Thus, if the lines before didn't work for some reason, also the GPVAL_DATA_X_MAX variable is not known. Does the script run without these three lines?

jherb February 14, 2014 18:40

If I remove the three lines between pause and reread the script works.

RodriguezFatz February 17, 2014 05:27

Hi,

You can start a gnuplot terminal
gnuplot
Then just do some random plot
plot 1
and let gnuplot show all the created variables
show variables all
Does it show the GPVAL_DATA_X_MAX?

jherb February 17, 2014 05:45

Quote:

Originally Posted by RodriguezFatz (Post 475290)
Hi,

You can start a gnuplot terminal
gnuplot
Then just do some random plot
plot 1
and let gnuplot show all the created variables
show variables all
Does it show the GPVAL_DATA_X_MAX?

Thank you for your help.

Actually, no:
Code:

gnuplot> show variables all


        All available variables:
        pi = 3.14159265358979
        NaN = NaN
        GNUTERM = "x11"
        GPVAL_TERM = "x11"
        GPVAL_TERMOPTIONS = ""
        GPVAL_OUTPUT = ""
        GPVAL_VERSION = 4.2
        GPVAL_PATCHLEVEL = "3 "
        GPVAL_COMPILE_OPTIONS = "-READLINE  +LIBREADLINE  +HISTORY  +BACKWARDS_COMPATIBILITY  +BINARY_DATA  \n+GD_PNG  +GD_JPEG  +GD_TTF  +GD_GIF  +ANIMATION  \n+NOCWDRC  +X11  +X11_POLYGON  +MULTIBYTE  +USE_MOUSE  +GNUGRAPH  +HIDDEN3D_QUADTREE  \n+DATASTRINGS  +HISTOGRAMS  +OBJECTS  +STRINGVARS  +MACROS  +THIN_SPLINES  +IMAGE  \n"
        GPVAL_X_MIN = -10.0
        GPVAL_X_MAX = 10.0
        GPVAL_X_REVERSE = 0
        GPVAL_X_LOG = 0.0
        GPVAL_Y_MIN = 0.99
        GPVAL_Y_MAX = 1.01
        GPVAL_Y_REVERSE = 0
        GPVAL_Y_LOG = 0.0
        GPVAL_X2_MIN = -10.0
        GPVAL_X2_MAX = 10.0
        GPVAL_X2_REVERSE = 0
        GPVAL_X2_LOG = 0.0
        GPVAL_Y2_MIN = 0.99
        GPVAL_Y2_MAX = 1.01
        GPVAL_Y2_REVERSE = 0
        GPVAL_Y2_LOG = 0.0
        GPVAL_Z_MIN = -10.0
        GPVAL_Z_MAX = 10.0
        GPVAL_Z_REVERSE = 0
        GPVAL_Z_LOG = 0.0
        GPVAL_CB_MIN = -8.98846567431158e+307
        GPVAL_CB_MAX = 8.98846567431158e+307
        GPVAL_CB_REVERSE = 0
        GPVAL_CB_LOG = 0.0
        GPVAL_T_MIN = -5.0
        GPVAL_T_MAX = 5.0
        GPVAL_T_REVERSE = 0
        GPVAL_T_LOG = 0.0
        GPVAL_U_MIN = -10.0
        GPVAL_U_MAX = 10.0
        GPVAL_U_REVERSE = 0
        GPVAL_U_LOG = 0.0
        GPVAL_V_MIN = -10.0
        GPVAL_V_MAX = 10.0
        GPVAL_V_REVERSE = 0
        GPVAL_V_LOG = 0.0

So I guess, my gnuplot version is too old. I will try a newer one (if I be able to compile it without root access).

jherb February 17, 2014 05:54

Ok, with the current version of gnuplot (4.6.4) it is working.

Thank your for the script.

RodriguezFatz February 17, 2014 05:56

You could have changed the GPVAL_DATA_X_MAX to GPVAL_X_MAX?
Seems like they renamed that in the newer versions...


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