CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > OpenFOAM Running, Solving & CFD

Tutorial of how to plot residuals !

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree128Likes

Reply
 
LinkBack Thread Tools Display Modes
Old   April 30, 2009, 09:07
Default Tutorial of how to plot residuals !
  #1
Senior Member
 
Wolfgang Heydlauff
Join Date: Mar 2009
Location: Germany
Posts: 136
Rep Power: 8
wolle1982 is on a distinguished road
Hi all,

since apearantly noone has an idea of how to plot the residuals of a calculation on-the-fly, I will give a small manual on that:

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.

Step 4:
Another good indicator for the calculations convergence is the forces-plot. Therefore you have to set the function in the controlDict that calculates the forces and forceCoeffs. See thread Forces in OF15 or attachments.

Be sure to have the properties for gnuplot in the main-case-folder (see attachments).

You have the adapt the folder-name where the forceCoeffs.dat is inside before.

While the calculation runs you also can use the gnuplot command
gnuplot forceCoeffs -
in the main-case-folder. When the forces seem to not change any more, the pressure allocation must be constantly what makes the convergent case proofed.

Step5:
Plotting the real forces is also easy. Proceed identically like in "Step 4" but be sure to set
magUInf 1.0; //free stream velocity magnitude
lRef 1.0; //reference length
Aref 1.632653; //reference area
in the controlDict.

Using the attached text-files, remove the ".txt" first.

Hope that helps somebody.

Greetings,
Wolfgang
Attached Files
File Type: txt forceCoeffs.txt (369 Bytes, 2490 views)
File Type: txt Residuals.txt (656 Bytes, 3340 views)
File Type: txt functions.txt (506 Bytes, 1873 views)
wolle1982 is offline   Reply With Quote

Old   May 7, 2009, 08:23
Default
  #2
Member
 
Marco Müller
Join Date: Mar 2009
Location: Germany
Posts: 94
Rep Power: 8
marico is on a distinguished road
thanks ....................
marico is offline   Reply With Quote

Old   May 7, 2009, 08:32
Default
  #3
Member
 
Marco Müller
Join Date: Mar 2009
Location: Germany
Posts: 94
Rep Power: 8
marico is on a distinguished road
what about having pressure iterations. If I have say 5 pressure loops, the pressure graph "runs" away and plots over 5x instead of x....
marico is offline   Reply With Quote

Old   May 8, 2009, 08:46
Default
  #4
Member
 
Flavio Galeazzo
Join Date: Mar 2009
Location: Karlsruhe, Germany
Posts: 30
Rep Power: 8
flavio_galeazzo is on a distinguished road
Thanks, Wolfgang! Really very useful.
flavio_galeazzo is offline   Reply With Quote

Old   May 9, 2009, 10:28
Thumbs up
  #5
New Member
 
Ashish Nedungadi
Join Date: Mar 2009
Location: Laurel, Maryland, USA
Posts: 13
Rep Power: 8
ashishnedungadi is on a distinguished road
Wolfgang,
Vielen dank! As a newby to OF, I needed this tutorial.

Regards
Ashish
ashishnedungadi is offline   Reply With Quote

Old   May 18, 2009, 06:48
Talking
  #6
New Member
 
Antonin
Join Date: Apr 2009
Location: France
Posts: 7
Rep Power: 8
Antonin is on a distinguished road
Thanks, this tool is very useful.
Antonin is offline   Reply With Quote

Old   June 3, 2009, 04:16
Default
  #7
Member
 
Leonardo Giampani Morita
Join Date: Apr 2009
Location: Paris, France
Posts: 58
Rep Power: 8
leonardo.morita is on a distinguished road
Hello,

What should I add if I wanted to plot the final residuals, not the initial ones?

Thanks!
leonardo.morita is offline   Reply With Quote

Old   June 4, 2009, 05:50
Default
  #8
Member
 
Thomas Wolfanger
Join Date: Mar 2009
Location: South West Germany
Posts: 60
Rep Power: 8
anger is on a distinguished road
Quote:
Originally Posted by marico View Post
what about having pressure iterations. If I have say 5 pressure loops, the pressure graph &quot;runs&quot; away and plots over 5x instead of x....
Hi,

you could change the line extracting the pressure to read:
cat log | grep 'Solving for p' | cut -d' ' -f9 | sed -n 'p;N;N;N;N' | tr -d ','&quot; title 'p' with lines
If you had two pressure iterations, you would change the argument to sed to read 'p;N'.
If the final residual should be plottet, replace f9 at the cut command with f13.

Best,
-Thomas
anger is offline   Reply With Quote

Old   June 4, 2009, 06:46
Default
  #9
Member
 
Leonardo Giampani Morita
Join Date: Apr 2009
Location: Paris, France
Posts: 58
Rep Power: 8
leonardo.morita is on a distinguished road
It works perfectly, thank you very much, Thomas!
By the way, what does f13 mean? Something related to characters?

Regards,

Leonardo
leonardo.morita is offline   Reply With Quote

Old   June 4, 2009, 07:03
Default
  #10
Member
 
Thomas Wolfanger
Join Date: Mar 2009
Location: South West Germany
Posts: 60
Rep Power: 8
anger is on a distinguished road
Quote:
Originally Posted by leonardo.morita View Post
It works perfectly, thank you very much, Thomas!
By the way, what does f13 mean? Something related to characters?

Regards,

Leonardo
f13 means field number 13 in the current set of fields which was created by cutting the line which was extracted by grep into pieces via the cut command.
"man cut" is your friend.

Best,
-Thomas
anger is offline   Reply With Quote

Old   July 8, 2009, 04:36
Default
  #11
Member
 
Bernard Esterhuyse
Join Date: Mar 2009
Location: Pretoria, South Africa
Posts: 50
Rep Power: 8
bernarde is on a distinguished road
Thanks for this tool Wolfgang - a very useful and important tool.
bernarde is offline   Reply With Quote

Old   August 14, 2009, 05:28
Default force.txt??
  #12
Senior Member
 
Sandy Lee
Join Date: Mar 2009
Posts: 207
Rep Power: 9
sandy is on a distinguished road
Hi Wolfgang, thanks a lot. However, I guess, maybe you forget to give a attachment about "force.txt" ?

sandy is offline   Reply With Quote

Old   August 15, 2009, 13:32
Default Thank You
  #13
Senior Member
 
Ahmed
Join Date: Mar 2009
Location: NY
Posts: 248
Rep Power: 9
Ahmed is on a distinguished road
That is a real brilliant addition to OpenFOAM
Thanks and Good Luck
Ahmed is offline   Reply With Quote

Old   September 1, 2009, 10:36
Default
  #14
New Member
 
Patrick Mueller
Join Date: Jun 2009
Location: Kaiserslautern
Posts: 8
Rep Power: 8
PaMuelle is on a distinguished road
Quote:
Originally Posted by anger View Post
Hi,

you could change the line extracting the pressure to read:
cat log | grep 'Solving for p' | cut -d' ' -f9 | sed -n 'p;N;N;N;N' | tr -d ','&quot; title 'p' with lines
If you had two pressure iterations, you would change the argument to sed to read 'p;N'.
If the final residual should be plottet, replace f9 at the cut command with f13.

Best,
-Thomas
Sorry for pushing up such an old topic. I'm currently working with this script, thanks Wolfgang for making my life so much easier!
But I have a little problem of undestanding why in Thomases addittion the first iteration gets plottet and the other four are ignored. Isn't the last of these iterations the most accurate? Or did I just misunderstand the code and it ignores the first iterations and plots the last one?

Greetings,
Patrick

PS:
I just plotted the residuals for both versions (p;N;N vs N;N;p), here are my solutions:
p;N;N;

- N;N;p:

To me, the N;N;p version looks much more wishable and plausible. Btw I know that the residuals look a little bit suspicious after ~30 iterations, it's a problem I'm currently working on
PaMuelle is offline   Reply With Quote

Old   September 1, 2009, 15:54
Default
  #15
Member
 
Thomas Wolfanger
Join Date: Mar 2009
Location: South West Germany
Posts: 60
Rep Power: 8
anger is on a distinguished road
Hello Patrick,

the place where the p lives is the line which is taken into account for further processing; when you have three lines and pipe them through sed with p;N;N only the first one is kept (as far as I remember); if in doubt, just consult the manpages.
As for the residuals, I'm judging convergence only with respect to the initial value of the pressure (or velocity or whatever) residual because the second number gives you the residual after running the inner linear solver; the values calculated there will be changed again and are in no way related to the state of convergence of the whole flow under consideration.

Best regards,
-Thomas
anger is offline   Reply With Quote

Old   September 1, 2009, 21:30
Default
  #16
Member
 
Andrew King
Join Date: Mar 2009
Location: Perth, Western Australia, Australia
Posts: 81
Rep Power: 8
andersking is on a distinguished road
Another way to do this is to use pyFoam, http://openfoamwiki.net/index.php/Contrib_PyFoam, in particular

Code:
turbFoam > log &
pyFoamPlotWatcher.py log
this also plots a number of other things as well (and also provides a number of other useful utilities).

Cheers,
Andrew
__________________
Dr Andrew King
Fluid Dynamics Research Group
Curtin University
andersking is offline   Reply With Quote

Old   September 2, 2009, 00:39
Default
  #17
Senior Member
 
Sandy Lee
Join Date: Mar 2009
Posts: 207
Rep Power: 9
sandy is on a distinguished road
Hi Thomas, I am still stunned. When should I write:

cat log | grep 'Solving for p' | cut -d' ' -f9 | sed -n 'p;N;N;N;N' | tr -d ','&quot; title 'p' with lines (four 'N')

OR

cat log | grep 'Solving for p' | cut -d' ' -f9 | sed -n 'p;N;N' | tr -d ','&quot; title 'p' with lines (just two 'N' ???)

OR

cat log | grep 'Solving for p' | cut -d' ' -f13 | sed -n 'p;N;N;N;N' | tr -d ','&quot; title 'p' with lines ???


What is the differences to three ways?? Thanks
sandy is offline   Reply With Quote

Old   September 2, 2009, 01:35
Default
  #18
New Member
 
Patrick Mueller
Join Date: Jun 2009
Location: Kaiserslautern
Posts: 8
Rep Power: 8
PaMuelle is on a distinguished road
Quote:
Originally Posted by sandy View Post
Hi Thomas, I am still stunned. When should I write:

cat log | grep 'Solving for p' | cut -d' ' -f9 | sed -n 'p;N;N;N;N' | tr -d ','&quot; title 'p' with lines (four 'N')

OR

cat log | grep 'Solving for p' | cut -d' ' -f9 | sed -n 'p;N;N' | tr -d ','&quot; title 'p' with lines (just two 'N' ???)

OR

cat log | grep 'Solving for p' | cut -d' ' -f13 | sed -n 'p;N;N;N;N' | tr -d ','&quot; title 'p' with lines ???


What is the differences to three ways?? Thanks
Hi Sandy,

at first you determine which field you need. f13 means that you use the 13th field in the row, while you start counting with the comma after "solving for p". e.g. GAMG: Solving for p, Initial residual = 0.193462, Final residual = 1.37372e-05, No Iterations 8
The 9th field in this example would be the number 1.37e-05. The 13th would be the field after "8", which in my case doesn't exist. (Fields are seperated by an spare field, this is defined by: "by cut -d' '") Therefore you have to check your logfile and decide which field you want to plot. In the normal case this would be the 9th (-> f9).
The number of "N" you have to write is determined by the number of iterations for p per timestep. In my case GAMG iterated p three times, so I have to ignore two iterations and write two Ns. In Thomases case, p is iterated five times, so he writes four Ns.
I hope I could help you and didn't write too confusing, my first coffee still isn't done

Greetings
PaMuelle is offline   Reply With Quote

Old   October 19, 2009, 08:35
Default
  #19
Senior Member
 
stephane sanchi
Join Date: Mar 2009
Posts: 300
Rep Power: 9
openfoam_user is on a distinguished road
Dear Wolfgang, dear OF users,

Your utility for plotting the residuals works fine !

But I have difficulties in plotting the forces.

I have the following file. What is the gnuplot command to plot Time versus viscous force in Z-direction ?

# Time forces(pressure, viscous) moment(pressure, viscous)
1 (((1004.63 -5494.47 -84811.2) (-0.0374886 -0.0406053 198.671)) ((892.014 943.938 -82187.3) (-0.0179318 -0.0364229 -76.003)))
2 (((644.515 -3547.57 -121082) (-0.0537444 0.172973 204.824)) ((510.954 640.954 -73474.2) (-0.0724901 -0.0655304 -74.3758)))
3 (((25.51 -475.303 -90723.7) (-0.0715687 0.446436 209.538)) ((-67.716 124.304 -30308.4) (-0.115215 -0.0974344 -72.0424)))
4 (((-535.122 1943.6 -44831) (-0.0842006 0.560531 210.419)) ((-442.742 -316.419 10907.2) (-0.107376 -0.103469 -70.0699)))
5 (((-633.929 2570.15 4849.92) (-0.0969208 0.553209 210.327)) ((-433.453 -408.939 29814.8) (-0.0604264 -0.0826774 -69.0365)))
6 (((-334.82 1661.22 28439.5) (-0.0418605 0.582708 213.964)) ((-203.231 -256.368 24363.6) (-0.0309029 -0.00757822 -68.957)))
7 (((160.717 261.099 30270.3) (-0.156219 0.117149 220.562)) ((78.173 -8.60102 6858.77) (0.0489021 0.00722051 -70.0195)))
8 (((517.415 -791.764 17582.5) (-0.283258 -0.337861 224.95)) ((246.292 212.329 -9360.35) (0.0700387 -0.0303728 -71.5801)))
9 (((495.253 -1062.81 -5910.24) (-0.500476 -0.331616 224.337)) ((226.706 241.192 -16497.8) (0.0157957 -0.105875 -72.9496)))
10 (((229.94 -659.331 -22150.2) (-0.548931 -0.219443 220.292)) ((99.4034 139.613 -14183.1) (-0.0509668 -0.171714 -73.6661)))

Regards,

Stephane.
openfoam_user is offline   Reply With Quote

Old   October 20, 2009, 08:33
Default
  #20
Senior Member
 
stephane sanchi
Join Date: Mar 2009
Posts: 300
Rep Power: 9
openfoam_user is on a distinguished road
the answer is

plot "< cat forces.dat | tr -d '(' | tr -d ')'" using 1:4

stephane
karamiag likes this.
openfoam_user is offline   Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
URGENT: plot residuals for complete simulation?? Khan FLUENT 1 February 1, 2007 13:35
Convergence - scaled vs unscaled residuals HS FLUENT 1 November 7, 2005 06:45
fluent: residuals Madhukar Rapaka FLUENT 1 October 14, 2005 10:28
graph plot anindya Main CFD Forum 2 September 17, 2003 12:00
residuals Karl CFX 2 June 24, 2003 23:13


All times are GMT -4. The time now is 04:17.