Tutorial of how to plot residuals !
3 Attachment(s)
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 yThe 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 http://www.cfd-online.com/Forums/ope...es-of15-3.html 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 magnitudein the controlDict. Using the attached text-files, remove the ".txt" first. Hope that helps somebody. Greetings, Wolfgang |
thanks ;) ....................
|
what about having pressure iterations. If I have say 5 pressure loops, the pressure graph "runs" away and plots over 5x instead of x....
|
Thanks, Wolfgang! Really very useful.
|
Wolfgang,
Vielen dank! As a newby to OF, I needed this tutorial. Regards Ashish |
Thanks, this tool is very useful.
|
Hello,
What should I add if I wanted to plot the final residuals, not the initial ones? Thanks! |
Quote:
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 ','" 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 |
It works perfectly, thank you very much, Thomas!
By the way, what does f13 mean? Something related to characters? Regards, Leonardo |
Quote:
"man cut" is your friend. Best, -Thomas |
Thanks for this tool Wolfgang - a very useful and important tool.
|
force.txt??
Hi Wolfgang, thanks a lot. However, I guess, maybe you forget to give a attachment about "force.txt" ? :o
|
Thank You
That is a real brilliant addition to OpenFOAM
Thanks and Good Luck |
Quote:
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; http://img136.imageshack.us/img136/8...sidualspnn.jpg - N;N;p: http://img402.imageshack.us/img402/9...sidualsnnp.jpg 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 ;) |
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 |
Another way to do this is to use pyFoam, http://openfoamwiki.net/index.php/Contrib_PyFoam, in particular
Code:
turbFoam > log & Cheers, Andrew |
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 ','" title 'p' with lines (four 'N') OR cat log | grep 'Solving for p' | cut -d' ' -f9 | sed -n 'p;N;N' | tr -d ','" 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 ','" title 'p' with lines ??? What is the differences to three ways?? Thanks |
Quote:
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 |
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. |
the answer is
plot "< cat forces.dat | tr -d '(' | tr -d ')'" using 1:4 stephane |
All times are GMT -4. The time now is 13:24. |