CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM (http://www.cfd-online.com/Forums/openfoam/)
-   -   Plotting Residuals (http://www.cfd-online.com/Forums/openfoam/70186-plotting-residuals.html)

ata November 17, 2009 01:18

Plotting Residuals
 
Hi foamers
I have some problem with residual plotting in OF. I don't know how can I plot residuals that I have saved in log file? Can any one help me?
Thanks

Ata

ata November 17, 2009 02:27

Plotting Residuals
 
Hi
Thanks I got it.

Ata

kumar November 17, 2009 10:18

Hello ,
to plot the residuals you have to first run the foamLog script on your log file, if you are using OF-1.5

just run
FoamLog logfile

it will produce a directory of name logs/. This will contain all the files you need for plotting. Use simple gnuplot script to plot the values.

If you are running a unsteady calculation then you can plot the final residuals files against the times to verify if your equation is converged at all time steps.
bye
hope this helps
K.Suresh kumar

elvis November 17, 2009 11:52

you can use pyfoam for a couple of nice features like plotting residuals
http://openfoamwiki.net/index.php/Co...mPlotRunner.py

grettings

elvis

ata November 29, 2009 03:20

Plotting Residuals
 
Hi every one
When I try to plot residuals with gnuplot I got this error:
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
^
"Residuals", line 10: warning: Skipping data file with no valid points

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
^
"Residuals", line 10: warning: Skipping data file with no valid points

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
^
"Residuals", line 10: warning: Skipping data file with no valid points

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
Can any body help me?
Regards

Ata

ata November 29, 2009 03:22

Plotting Residuals
 
Hi Elvis
Thank you
Can you send me some tutorial.
Thanks

Ata

Marta November 29, 2009 13:55

Hi ata,
I found this piece of advice last month when i needed to find out how to plot the residuals of a simulation. It is taken from another section of this forum, I followed this steps and I managed to plot the residuals, so I think it can help you too.

Tutorial on "How to plot the residuals (and forces) graphically on screen on-the-fly"

Step 1:
Start the calculation and make it write out a log-file. for example
turbFoam >log
"log" is the name of the log-file to be output. It is written into the main-case-folder.

Step 2:
If desired you can open a new console-window of the main-case-folder and follow the text-output by the command
tail -f log
"log" is the name of the log-file to be read in. To stop reading the file constantly just use Crtl+C

Step 3:
To plot the residuals graphically on the screen you can use gnuplot that is delivered with linux already.
Within the main-case-folder you have to put a text file with a name e.g. "Residuals"
(also see attachments).
The file should contain the following gnuplot properties:
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
reread
The pause-command sets the seconds till reload. Deletion makes it faster in some cases.

Execute the command
gnuplot Residuals -
in the main-case-folder.

This way I did not have any errors by gnu plot, maybe it could help you too.

Marta

ata November 29, 2009 15:05

Hi Marta
Thank you very much but I already have seen this tutorial and when I try it I got that error.
Best regards

Ata

lth October 29, 2010 21:10

Fix for "FinalResiduals", line 8: warning:
 
Hi Foamers,

Using output& folder to monitor jobs and FinalResidual was giving similar errors.
------------------------------------
"FinalResiduals", line 8: warning: Skipping data file with no valid points openfoam
"Final Residuals", line 8: x range is invalid
-----------------------------------

By quick switch of names in the FinalResidual code
to "< cat output | ... from "< cat log | ... has it working fine.

Best, Lori

Bertrand November 23, 2010 14:07

Hello Marta,

Thanks a lot for posting this kind of tutorial : makes OF life much easier! ;-)
As I am not really familiar with gnuplot syntax, I was wondering what exactly we need to change in Residuals.txt in order to plot the Courant Number mean and max?

Best regards,

Bertrand

Bertrand November 23, 2010 14:23

OK,

Sorry for the silly question, I'm new to Linux as well, but I just found how to deal with the syntax...

megacrout July 7, 2011 07:44

Quote:

Originally Posted by ata (Post 238095)
Hi Marta
Thank you very much but I already have seen this tutorial and when I try it I got that error.
Ata

Hey ata.

This happens if the Residuals-file contains more terms to look for than there are in the log file (e.g. k or epsilon). Either delete the "reread" command at the end of the Residuals-file (ugly solution) or delete the lines that make gnu look for parameters that it is never going to find.

Tibo

joel.lehikoinen July 8, 2011 02:50

Quote:

Originally Posted by ata (Post 238079)
Hi every one
When I try to plot residuals with gnuplot I got this error:
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
^
"Residuals", line 10: warning: Skipping data file with no valid points
...

Can any body help me?
Regards

Ata

This script doesn't work out of the box for all solvers, you have to modify it, depending on your turbulence model and the algorithm (especially number of loops) you are using. You may need to twiddle with the field specified for the cut command. The best way to check if it works is to just run this command in a terminal:
Code:

cat log | grep 'Solving for Ux' | cut -d' ' -f9
This should output a floating point number followed by a comma. If it doesn't, then you need to see which field it is actually reading (see man pages for cut).

Also, if you are running some other model than k-omega the script will be unable to plot omega (naturally). And if you are running a solver with buoancy, then you need to grep p_rgh instead of p. This script is very handy, it just requires some Unix-fu to get it working.


All times are GMT -4. The time now is 02:44.