CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Community Contributions

[Tutorials] Tutorial of how to plot residuals !

Register Blogs Community New Posts Updated Threads Search

Like Tree344Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 22, 2017, 23:22
Default Works but?
  #141
Senior Member
 
Peter Hess
Join Date: Apr 2011
Location: Austria
Posts: 250
Rep Power: 17
peterhess is on a distinguished road
Hello Everybody!

Thank for the great feedback.

I tried the code and it works!

I changed the code slightly like this:

set logscale y
set title "Tmax heater"
set ylabel 'Tmax'
set xlabel 'Iteration'
plot "< cat log.chtMultiRegionSimpleFoam | grep 'Min/max' | cut -d' ' -f3 | tr -d ','" title 'Tmax'
pause 1
reread

It works actually but I have a problem.

In my log.chtMultiRegionSimpleFoam file, one iteration looks like this:

Solving for fluid region bottomAir
DILUPBiCG: Solving for Ux, Initial residual = 2.470196e-05, Final residual = 2.969919e-07, No Iterations 1
DILUPBiCG: Solving for Uy, Initial residual = 1.437032e-05, Final residual = 1.604827e-07, No Iterations 1
DILUPBiCG: Solving for Uz, Initial residual = 1.741628e-05, Final residual = 4.959543e-07, No Iterations 1
DILUPBiCG: Solving for h, Initial residual = 0.009048544, Final residual = 5.287758e-05, No Iterations 2
Min/max T:303.7611 304.39
GAMG: Solving for p_rgh, Initial residual = 4.127734e-05, Final residual = 1.326083e-06, No Iterations 1000
time step continuity errors : sum local = 1.355654e-07, global = -4.023393e-19, cumulative = -0.0886042
Min/max rho:1.156752 1.159142

Solving for fluid region topAir
DILUPBiCG: Solving for Ux, Initial residual = 1.136693e-05, Final residual = 3.449505e-08, No Iterations 1
DILUPBiCG: Solving for Uy, Initial residual = 8.489421e-05, Final residual = 1.582533e-07, No Iterations 1
DILUPBiCG: Solving for Uz, Initial residual = 2.811805e-05, Final residual = 3.09551e-08, No Iterations 1
DILUPBiCG: Solving for h, Initial residual = 0.0001787168, Final residual = 1.17763e-06, No Iterations 1
Min/max T:300 304.1752
GAMG: Solving for p_rgh, Initial residual = 0.0001523519, Final residual = 7.043136e-07, No Iterations 2
time step continuity errors : sum local = 3.013158e-07, global = -2.91909e-07, cumulative = -0.08860449
Min/max rho:1.142718 1.158621

Solving for solid region heater
DICPCG: Solving for h, Initial residual = 0.006304606, Final residual = 0.0004823271, No Iterations 1
Min/max T:304.0113 304.3917

Solving for solid region leftSolid
DICPCG: Solving for h, Initial residual = 0.009657879, Final residual = 0.0003739408, No Iterations 1
Min/max T:303.7599 304.1081

Solving for solid region rightSolid
DICPCG: Solving for h, Initial residual = 0.01246801, Final residual = 0.0004664707, No Iterations 1
Min/max T:303.8347 304.1204
ExecutionTime = 453.44 s ClockTime = 454 s

Time = 2000


In this iteration Min/max appears 5 times!

The code above prints the Tmax 5 times...

How could I print just the Min/max for a specific region, lets say for region heater?

For any feedback I would be very thankful!

Regards

Peter

Last edited by peterhess; February 23, 2017 at 00:58.
peterhess is offline   Reply With Quote

Old   February 23, 2017, 06:54
Default
  #142
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by peterhess View Post
Hello Everybody!

Thank for the great feedback.

I tried the code and it works!

I changed the code slightly like this:

set logscale y
set title "Tmax heater"
set ylabel 'Tmax'
set xlabel 'Iteration'
plot "< cat log.chtMultiRegionSimpleFoam | grep 'Min/max' | cut -d' ' -f3 | tr -d ','" title 'Tmax'
pause 1
reread

It works actually but I have a problem.

In my log.chtMultiRegionSimpleFoam file, one iteration looks like this:

Solving for fluid region bottomAir
DILUPBiCG: Solving for Ux, Initial residual = 2.470196e-05, Final residual = 2.969919e-07, No Iterations 1
DILUPBiCG: Solving for Uy, Initial residual = 1.437032e-05, Final residual = 1.604827e-07, No Iterations 1
DILUPBiCG: Solving for Uz, Initial residual = 1.741628e-05, Final residual = 4.959543e-07, No Iterations 1
DILUPBiCG: Solving for h, Initial residual = 0.009048544, Final residual = 5.287758e-05, No Iterations 2
Min/max T:303.7611 304.39
GAMG: Solving for p_rgh, Initial residual = 4.127734e-05, Final residual = 1.326083e-06, No Iterations 1000
time step continuity errors : sum local = 1.355654e-07, global = -4.023393e-19, cumulative = -0.0886042
Min/max rho:1.156752 1.159142

Solving for fluid region topAir
DILUPBiCG: Solving for Ux, Initial residual = 1.136693e-05, Final residual = 3.449505e-08, No Iterations 1
DILUPBiCG: Solving for Uy, Initial residual = 8.489421e-05, Final residual = 1.582533e-07, No Iterations 1
DILUPBiCG: Solving for Uz, Initial residual = 2.811805e-05, Final residual = 3.09551e-08, No Iterations 1
DILUPBiCG: Solving for h, Initial residual = 0.0001787168, Final residual = 1.17763e-06, No Iterations 1
Min/max T:300 304.1752
GAMG: Solving for p_rgh, Initial residual = 0.0001523519, Final residual = 7.043136e-07, No Iterations 2
time step continuity errors : sum local = 3.013158e-07, global = -2.91909e-07, cumulative = -0.08860449
Min/max rho:1.142718 1.158621

Solving for solid region heater
DICPCG: Solving for h, Initial residual = 0.006304606, Final residual = 0.0004823271, No Iterations 1
Min/max T:304.0113 304.3917

Solving for solid region leftSolid
DICPCG: Solving for h, Initial residual = 0.009657879, Final residual = 0.0003739408, No Iterations 1
Min/max T:303.7599 304.1081

Solving for solid region rightSolid
DICPCG: Solving for h, Initial residual = 0.01246801, Final residual = 0.0004664707, No Iterations 1
Min/max T:303.8347 304.1204
ExecutionTime = 453.44 s ClockTime = 454 s

Time = 2000


In this iteration Min/max appears 5 times!

The code above prints the Tmax 5 times...

How could I print just the Min/max for a specific region, lets say for region heater?

For any feedback I would be very thankful!

Regards

Peter
The problem is that you'd have to switch according to the "Solving for fluid region bottomAir" output. Grep is not capable of this. One possibilty would be to write an awk-script (or another scripting language. But awk was made for that kind of stateful text processing). The other would be to use pyFoam (in the current release the plotting utilities automatically recognize cht-Foam and split temperature plots accordingly)

Bernhard
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request
gschaider is offline   Reply With Quote

Old   February 23, 2017, 10:07
Default
  #143
Senior Member
 
Peter Hess
Join Date: Apr 2011
Location: Austria
Posts: 250
Rep Power: 17
peterhess is on a distinguished road
Hello Bernhard,

Thanks for the suggestion.

I will work on it and see whats happends.

Regards

Peter

Last edited by peterhess; February 23, 2017 at 12:03.
peterhess is offline   Reply With Quote

Old   November 20, 2017, 06:40
Default
  #144
New Member
 
Serkan
Join Date: Jun 2017
Location: Belgium
Posts: 6
Rep Power: 9
sersol is on a distinguished road
It still works properly. Thank you so much.
sersol is offline   Reply With Quote

Old   December 6, 2017, 13:08
Default
  #145
Member
 
Honza Höll
Join Date: Mar 2016
Location: Brno, CZ
Posts: 37
Rep Power: 10
indy07cz is on a distinguished road
Hi foamers,
I used some ideas written here and wrote own script to plot residuals vs time on the fly during simulation. My script is for interFoam solver but it can be changed for others.

file residuals.sh prepares input data for gnuplot every n seconds and run gnuplot
file gnupl_input is gnuplot file which defines plot design

Paste these files into case folder, edit files and run ./residuals.sh during simulation. Enjoy.
Attached Images
File Type: jpg screen.jpg (100.6 KB, 105 views)
Attached Files
File Type: gz residuals.tar.gz (655 Bytes, 46 views)
ekrumrick and Hip2BL7 like this.
indy07cz is offline   Reply With Quote

Old   December 8, 2017, 08:01
Default
  #146
Senior Member
 
Robert
Join Date: May 2015
Location: Bremen, GER
Posts: 292
Rep Power: 12
RobertHB is on a distinguished road
This might be a bit off-topic, but i hope someone can help me. As written multiple times the original residual script works fine. Also for me. Now, as i am running transient simulation i came up with the idea of monitoring my Courant Number using the approach taken in the residual script.
The output i want to plot is:
Code:
Courant Number mean: 0.0108355 max: 0.113549
So my script reads
Code:
plot "< cat piso.log | grep 'Courant Number' | cut -d' ' -f4 | tr -d ','" title 'Co mean' with lines,\
"< cat piso.log | grep 'max:' | cut -d' ' -f8 | tr -d ','" title 'Co max' with lines,
reread
The first line reads the mean CFL value. Check. Accordingly the Co max value should be on the 8th position (read by the 2nd line). But instead an error occurs
Quote:
"CFLno", line 6: warning: Skipping data file with no valid points
failed to get the current screen resources
QXcbConnection: XCB error: 170 (Unknown), sequence: 163, resource id: 90, major code: 146 (Unknown), minor code: 20
[...]
tr: Schreibfehler
cut: Schreibfehler: Datenübergabe unterbrochen (broken pipe)
Can anybode point me to my mistake?

Regards
Robert
RobertHB is offline   Reply With Quote

Old   December 8, 2017, 13:07
Default
  #147
Member
 
Honza Höll
Join Date: Mar 2016
Location: Brno, CZ
Posts: 37
Rep Power: 10
indy07cz is on a distinguished road
Have you tried run second command to separate co max number simply in bash? Try simply cat, then add grep, cut an so on. I think it is on 6th position not 8th.
indy07cz is offline   Reply With Quote

Old   December 12, 2017, 05:16
Smile Revised plot residuals vs time on the fly during simulation
  #148
New Member
 
George XU
Join Date: Dec 2009
Posts: 9
Rep Power: 16
gxuxg is on a distinguished road
Quote:
Originally Posted by indy07cz View Post
Hi foamers,
I used some ideas written here and wrote own script to plot residuals vs time on the fly during simulation. My script is for interFoam solver but it can be changed for others.

file residuals.sh prepares input data for gnuplot every n seconds and run gnuplot
file gnupl_input is gnuplot file which defines plot design

Paste these files into case folder, edit files and run ./residuals.sh during simulation. Enjoy.
I have improved the scripts with regard to residuals curves, with the easy update of line titles.
Revised scripts are updated in case it is useful.
Attached Files
File Type: gz residuals-r.tar.gz (814 Bytes, 32 views)
gxuxg is offline   Reply With Quote

Old   December 13, 2017, 03:55
Default
  #149
Member
 
Honza Höll
Join Date: Mar 2016
Location: Brno, CZ
Posts: 37
Rep Power: 10
indy07cz is on a distinguished road
Hey that's great! What kind of coding (UTF, ...) did you use for residual.sh? I'm not able to open it correctly in Vim or Gedit.
indy07cz is offline   Reply With Quote

Old   December 13, 2017, 04:40
Default
  #150
New Member
 
George XU
Join Date: Dec 2009
Posts: 9
Rep Power: 16
gxuxg is on a distinguished road
Quote:
Originally Posted by indy07cz View Post
Hey that's great! What kind of coding (UTF, ...) did you use for residual.sh? I'm not able to open it correctly in Vim or Gedit.
Sorry, did not notice that the file had crashed.
Here they are.
Attached Files
File Type: gz residuals-r.tar.gz (871 Bytes, 45 views)
gxuxg is offline   Reply With Quote

Old   July 11, 2018, 11:01
Default plot residual
  #151
Member
 
Ben 017
Join Date: Nov 2017
Posts: 70
Rep Power: 9
Ben UWIHANGANYE is on a distinguished road
Hello,

I don't know if this thread is still active, but i have a question

My problem now is the difference between ux uy and P residual plot. why pressure goes up to 2000 while ux and uy ends at 500 iterations.
Could you help me to know why?

You may see my plot of residuals on attached picture


I will be happy to get your support.


Regard!
Attached Images
File Type: png residual.png (65.7 KB, 51 views)
Ben UWIHANGANYE is offline   Reply With Quote

Old   July 11, 2018, 11:42
Default
  #152
Senior Member
 
Peter Hess
Join Date: Apr 2011
Location: Austria
Posts: 250
Rep Power: 17
peterhess is on a distinguished road
Hello!

Why: Well because you have proberly 4 times pressure corrections (nNonOrthogonalCorrectors 3; ) in your PISO in the fvSolution.

The code shown above searches every time for "Solving for Ux, Solving for Ux, Solving for p".

The code find in every itteration 1 X Solving for Ux and 1 X Solving for Uy and 4 X Solving for p.

4 X 500 = 2000 !

Solution:

Well, instead of plotting the p and ux, uy on the same graph, I suggest to plot them separately.

Make a file called

plot_U

and use the following code inside:

set title "Residuals"
set ylabel 'Residual_U'
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
pause 1
reread

Make other file called

plot_p

and use the following code inside:

set title "Residuals"
set ylabel 'Residual_p'
set xlabel 'Iteration'
plot "< cat log | grep 'Solving for p' | cut -d' ' -f9 | tr -d ','" title 'p' with lines
pause 1
reread

Start gnuplot by typing:

gnuplot plot_p | gnuplot plot_U

Like that two graphs will be started simultaneously.

Or simply reduce the nNonOrthogonalCorrectors to 0 and plot as before...

Regards

Peter

Last edited by peterhess; July 11, 2018 at 15:03.
peterhess is offline   Reply With Quote

Old   July 11, 2018, 16:13
Default
  #153
Member
 
Ben 017
Join Date: Nov 2017
Posts: 70
Rep Power: 9
Ben UWIHANGANYE is on a distinguished road
I thank 4r the feedback.
That approach is much better though it is not answering my question. Why does pressure residuals goes up to 2000 velocity stop at 500 iteration? (previous post)
Is there a scientific reason?

Thank you!
Ben UWIHANGANYE is offline   Reply With Quote

Old   July 11, 2018, 23:48
Default
  #154
Senior Member
 
Peter Hess
Join Date: Apr 2011
Location: Austria
Posts: 250
Rep Power: 17
peterhess is on a distinguished road
Hello,

I answerd the question in the first section of my post.

It has no scientific reason.

If you take a look to your log file you will see in one itteration something like this:

1: smoothSolver: Solving for Ux, Initial residual = 0.931847, Final residual = 7.06554e-06, No Iterations 21
1: smoothSolver: Solving for Uy, Initial residual = 0.899434, Final residual = 7.32104e-06, No Iterations 20
1: DICPCG: Solving for p, Initial residual = 0.965189, Final residual = 0.0378369, No Iterations 20
2: DICPCG: Solving for p, Initial residual = 0.0197448, Final residual = 0.000760858, No Iterations 4
3: DICPCG: Solving for p, Initial residual = 0.000761143, Final residual = 3.19517e-05, No Iterations 19
4: DICPCG: Solving for p, Initial residual = 3.19457e-05, Final residual = 9.21943e-07, No Iterations 10

That means, in one calculation itteration you are printing 4 times for pressure.

The total number of itterations is 500. The 2000 itterations come from 4 times pressure corrections X 500!

Do the following to see the effect:

Reducing the nNonOrthogonalCorrectors in fvSolution from 3 to 0 will result:

1: smoothSolver: Solving for Ux, Initial residual = 0.931847, Final residual = 7.06554e-06, No Iterations 21
1: smoothSolver: Solving for Uy, Initial residual = 0.899434, Final residual = 7.32104e-06, No Iterations 20
1: DICPCG: Solving for p, Initial residual = 0.965189, Final residual = 0.0378369, No Iterations 20

Like that the counter for the pressure and the velocities are identical!

Regards

Peter
peterhess is offline   Reply With Quote

Old   July 12, 2018, 01:11
Default
  #155
Member
 
Ben 017
Join Date: Nov 2017
Posts: 70
Rep Power: 9
Ben UWIHANGANYE is on a distinguished road
Quote:
Originally Posted by peterhess View Post
Hello,

I answerd the question in the first section of my post.

It has no scientific reason.

If you take a look to your log file you will see in one itteration something like this:

1: smoothSolver: Solving for Ux, Initial residual = 0.931847, Final residual = 7.06554e-06, No Iterations 21
1: smoothSolver: Solving for Uy, Initial residual = 0.899434, Final residual = 7.32104e-06, No Iterations 20
1: DICPCG: Solving for p, Initial residual = 0.965189, Final residual = 0.0378369, No Iterations 20
2: DICPCG: Solving for p, Initial residual = 0.0197448, Final residual = 0.000760858, No Iterations 4
3: DICPCG: Solving for p, Initial residual = 0.000761143, Final residual = 3.19517e-05, No Iterations 19
4: DICPCG: Solving for p, Initial residual = 3.19457e-05, Final residual = 9.21943e-07, No Iterations 10

That means, in one calculation itteration you are printing 4 times for pressure.

The total number of itterations is 500. The 2000 itterations come from 4 times pressure corrections X 500!

Do the following to see the effect:

Reducing the nNonOrthogonalCorrectors in fvSolution from 3 to 0 will result:

1: smoothSolver: Solving for Ux, Initial residual = 0.931847, Final residual = 7.06554e-06, No Iterations 21
1: smoothSolver: Solving for Uy, Initial residual = 0.899434, Final residual = 7.32104e-06, No Iterations 20
1: DICPCG: Solving for p, Initial residual = 0.965189, Final residual = 0.0378369, No Iterations 20

Like that the counter for the pressure and the velocities are identical!

Regards

Peter
I am sorry, I did not read the answer entirely.
Do you have an idea about convergence? So far I think it occurs at a certain iteration where the solution is not changing compared to the previous iteration. For my case(earlier posted) I think after 150 iterations the solution was not still changing. hence simulation converged.

Is that true?

Regard!
Ben UWIHANGANYE is offline   Reply With Quote

Old   July 12, 2018, 03:27
Default
  #156
Senior Member
 
Peter Hess
Join Date: Apr 2011
Location: Austria
Posts: 250
Rep Power: 17
peterhess is on a distinguished road
Hello!

Well this is a complatly different topic than the thread in this discussion.

This topic has been discussed so often in the Forum.

Search for those threads and you will find much informations.

Or open a new thread

Regards

Peter
peterhess is offline   Reply With Quote

Old   February 15, 2019, 10:24
Post
  #157
New Member
 
Join Date: Jan 2019
Posts: 10
Rep Power: 7
Kieran is on a distinguished road
Hi everyone,

I've been using this script, and I'm wondering if anyone can help me with non-orthogonal correctors. In this thread a few people have talked about using sed -n 'p;N...' to only plot the first sub-iteration for pressure, which works great, although I have changed the number of non-orthogonal correctors part way through my case, does anyone know how to account for this.

Is it possible to read the first X steps of the log and plot in one way, and then plot the remaining steps in a different way, to adjust for the change in non-orthogonal correctors?

Thanks,

Kieran
Kieran is offline   Reply With Quote

Old   September 29, 2019, 22:23
Red face gnuplot window keeps popping up
  #158
New Member
 
Join Date: Nov 2018
Posts: 2
Rep Power: 0
neznayer is on a distinguished road
Thank you for that plotting solution!
But I have a question: gnuplot window keeps popping up even after the simulation is over. I think thats because it rereads the log every n seconds no matter if simulation is over or not..
How could I tell it to stop if new data isn't added to the log anymore?
neznayer is offline   Reply With Quote

Old   August 18, 2020, 09:51
Default
  #159
New Member
 
Join Date: Aug 2020
Posts: 7
Rep Power: 6
Kannan86 is on a distinguished road


While trying to plot Residuals by following the steps above I am getting an error message like this. Please help me out.





gnuplot> load "Residuals"
"Residuals" line 10: warning: Skipping data file with no valid points
"Residuals" line 10: warning: Skipping data file with no valid points
"Residuals" line 10: warning: Skipping data file with no valid points
"Residuals" line 10: warning: Skipping data file with no valid points
"Residuals" line 10: warning: Skipping data file with no valid points
"Residuals" line 10: warning: Skipping data file with no valid points

gnuplot> 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: x range is invalid
Kannan86 is offline   Reply With Quote

Old   August 18, 2020, 12:41
Default
  #160
Senior Member
 
Peter Hess
Join Date: Apr 2011
Location: Austria
Posts: 250
Rep Power: 17
peterhess is on a distinguished road
I got this error also before...

I dont know why that happens, anyway the probleme could be solved by adding:

set xrange [1:*]

at the start of the skript.

Regards

Peter
Kannan86 likes this.
peterhess is offline   Reply With Quote

Reply


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 Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
plot residuals in multiregion solver val46 OpenFOAM 4 December 12, 2016 07:06
To Plot Residuals on the fly. neeraj OpenFOAM Running, Solving & CFD 5 October 2, 2013 07:23
[PyFoam] why pyFoamPlotRunner doesn't plot continuity residuals? immortality OpenFOAM Community Contributions 10 May 5, 2013 07:13
plot of residuals hawkeye321 OpenFOAM 5 December 7, 2012 10:05
[Virtualization] OpenFOAM oriented tutorial on using VMware Player - support thread wyldckat OpenFOAM Installation 2 July 11, 2012 17:01


All times are GMT -4. The time now is 23:53.