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

Plottig residuals with GNUPLOT

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

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 22, 2024, 10:46
Default Plottig residuals with GNUPLOT
  #1
New Member
 
Zeno Brighenti
Join Date: May 2023
Posts: 7
Rep Power: 3
Il_Briga is on a distinguished road
Hello Foamers,


I'm perfectly aware this issue has been treated a lot in the past, but unfortunately, that's my fault, i'm not still able to face it. I run a PISO RSM simulation and i would like to plot the residual with Gnuplot. I've followed this guide (Tutorial of how to plot residuals !) with no results, since unfortunately i'm not a gnuplot expert and no command explanation is given in the aforementioned tutorial:



Code:
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 Rx' | cut -d' ' -f9 | tr -d ','" title 'Rx' with lines,\
"< cat log | grep 'Solving for Ry' | cut -d' ' -f9 | tr -d ','" title 'Ry' with lines,\
"< cat log | grep 'Solving for Rz' | cut -d' ' -f9 | tr -d ','" title 'Rz' with lines,\
"< cat log | grep 'Solving for k' | cut -d' ' -f9 | tr -d ','" title 'k' with lines,\
"< cat log | grep 'Solving for epsilon' | cut -d' ' -f9 | tr -d ','" title 'epsilon' with lines,\
"< cat log | grep 'Solving for p' | cut -d' ' -f9 | tr -d ','" title 'p' with lines
pause 1
reread
While an excerpt of my log file is:


Code:
Courant Number mean: 0.00012169 max: 0.331303
deltaT = 2.70046e-07
Time = 0.00700068s

diagonal:  Solving for rho, Initial residual = 0, Final residual = 0, No Iterations 0
smoothSolver:  Solving for Ux, Initial residual = 0.000485903, Final residual = 4.31859e-09, No Iterations 2
smoothSolver:  Solving for Uy, Initial residual = 0.000129991, Final residual = 8.78841e-10, No Iterations 2
smoothSolver:  Solving for Uz, Initial residual = 0.000491682, Final residual = 4.87483e-09, No Iterations 2
DILUPBiCGStab:  Solving for h, Initial residual = 0.000680715, Final residual = 4.33642e-07, No Iterations 1
GAMG:  Solving for p, Initial residual = 0.000834368, Final residual = 1.86958e-07, No Iterations 1
GAMG:  Solving for p, Initial residual = 1.8936e-06, Final residual = 7.15294e-09, No Iterations 1
GAMG:  Solving for p, Initial residual = 1.10342e-07, Final residual = 1.10342e-07, No Iterations 0
diagonal:  Solving for rho, Initial residual = 0, Final residual = 0, No Iterations 0
time step continuity errors : sum local = 1.82047e-10, global = -1.97094e-13, cumulative = 1.33439e-12
GAMG:  Solving for p, Initial residual = 1.64091e-06, Final residual = 1.74194e-09, No Iterations 1
GAMG:  Solving for p, Initial residual = 3.12903e-08, Final residual = 3.12903e-08, No Iterations 0
GAMG:  Solving for p, Initial residual = 3.12903e-08, Final residual = 3.12903e-08, No Iterations 0
diagonal:  Solving for rho, Initial residual = 0, Final residual = 0, No Iterations 0
time step continuity errors : sum local = 5.16241e-11, global = -1.75414e-14, cumulative = 1.31684e-12
smoothSolver:  Solving for epsilon, Initial residual = 6.2732e-05, Final residual = 3.46349e-09, No Iterations 2
bounding epsilon, min: -6.45685e-05 max: 7.86881e+06 average: 539.917
smoothSolver:  Solving for Rxx, Initial residual = 0.000439767, Final residual = 2.4545e-09, No Iterations 5
smoothSolver:  Solving for Rxy, Initial residual = 0.0144549, Final residual = 3.58382e-09, No Iterations 7
smoothSolver:  Solving for Rxz, Initial residual = 0.011701, Final residual = 6.47263e-09, No Iterations 6
smoothSolver:  Solving for Ryy, Initial residual = 0.000441822, Final residual = 3.08538e-09, No Iterations 5
smoothSolver:  Solving for Ryz, Initial residual = 0.00830103, Final residual = 7.33049e-09, No Iterations 6
smoothSolver:  Solving for Rzz, Initial residual = 0.000434931, Final residual = 2.49343e-09, No Iterations 5
ExecutionTime = 539.768 s  ClockTime = 555 s
The outcome is quite horrible compared with the exact one (get with foamMonitor). Every ideas will be more than welcome!
Attached Images
File Type: jpg Gnuplot.jpg (105.2 KB, 6 views)
File Type: png foamMonitor.png (24.8 KB, 4 views)
Il_Briga is offline   Reply With Quote

Old   October 22, 2024, 12:50
Default
  #2
Senior Member
 
Yann
Join Date: Apr 2012
Location: France
Posts: 1,257
Rep Power: 29
Yann will become famous soon enoughYann will become famous soon enough
Hello,

You need to spend a bit of time to understand how the script is working. I didn't try on this specific case, but tools like chatgpt can be pretty helpful to give you an explanation of what the script is doing.

Code:
cat log | grep 'Solving for p' | cut -d' ' -f9 | tr -d ','
This line is a shell command to retrieve the data from your log file. It is searching for the string 'Solving for p', which appears 6 times every timestep. This is why you have way more points for p in your graph. This is related to your PISO setup in fvSolution, where you are probably using some correctors.

Same for solving for Rx, you are retrieving 3 points at each timestep (Rxx Rxy Rxz) and Ry (2 points: Ryy Ryz)

You need to adapt your script to match what your solver is solving, and what you want to see.

I personnally prefer to use a function object (residuals in the foundation branch, solverInfo in the OpenCFD branch) rather than plotting from the log file, but to each his own!

Regards,
Yann
Yann is offline   Reply With Quote

Old   October 22, 2024, 16:43
Default
  #3
Senior Member
 
Domenico Lahaye
Join Date: Dec 2013
Posts: 825
Blog Entries: 1
Rep Power: 19
dlahaye is on a distinguished road
Alternative is to load log-data into into a Jupyter notebook, and do all plotting from there. See attachment.
dlahaye is offline   Reply With Quote

Old   October 24, 2024, 04:46
Default
  #4
New Member
 
Zeno Brighenti
Join Date: May 2023
Posts: 7
Rep Power: 3
Il_Briga is on a distinguished road
Quote:
Originally Posted by dlahaye View Post
Alternative is to load log-data into into a Jupyter notebook, and do all plotting from there. See attachment.
Thank you for your reply, dlahaye. But actually i don't see any attachment ! Did you miss it ?
Il_Briga is offline   Reply With Quote

Old   October 24, 2024, 04:48
Default
  #5
New Member
 
Zeno Brighenti
Join Date: May 2023
Posts: 7
Rep Power: 3
Il_Briga is on a distinguished road
Quote:
Originally Posted by Yann View Post
Hello,

You need to spend a bit of time to understand how the script is working. I didn't try on this specific case, but tools like chatgpt can be pretty helpful to give you an explanation of what the script is doing.

Code:
cat log | grep 'Solving for p' | cut -d' ' -f9 | tr -d ','
This line is a shell command to retrieve the data from your log file. It is searching for the string 'Solving for p', which appears 6 times every timestep. This is why you have way more points for p in your graph. This is related to your PISO setup in fvSolution, where you are probably using some correctors.

Same for solving for Rx, you are retrieving 3 points at each timestep (Rxx Rxy Rxz) and Ry (2 points: Ryy Ryz)

You need to adapt your script to match what your solver is solving, and what you want to see.

I personnally prefer to use a function object (residuals in the foundation branch, solverInfo in the OpenCFD branch) rather than plotting from the log file, but to each his own!

Regards,
Yann
Yeap, i guessed it. But i cannot provide any solution to this. Do you have any idea how to do it? Thank a lot!
Il_Briga is offline   Reply With Quote

Old   October 25, 2024, 04:19
Default
  #6
Senior Member
 
Domenico Lahaye
Join Date: Dec 2013
Posts: 825
Blog Entries: 1
Rep Power: 19
dlahaye is on a distinguished road
Jupyter notebook now online at

https://github.com/ziolai/software/b...-foamLog.ipynb
dlahaye is offline   Reply With Quote

Old   October 26, 2024, 07:00
Default
  #7
Senior Member
 
Yann
Join Date: Apr 2012
Location: France
Posts: 1,257
Rep Power: 29
Yann will become famous soon enoughYann will become famous soon enough
Quote:
Originally Posted by Il_Briga View Post
Yeap, i guessed it. But i cannot provide any solution to this. Do you have any idea how to do it? Thank a lot!
You have to do your homework, google and tools like chatGPT can be pretty handy for that.

For the Reynolds stress, instead of searching for "Solving for Rx", search each components : "Solving for Rxx", "Solving for Rxy", etc...
For the pressure, you need to plot only one value by timestep, for instance the first "Solving for p" of each timestep. So basically you need to filter your log file to output "Solving for p" every 6 lines.

Code:
cat log | grep 'Solving for p' | awk 'NR % 6 == 1'  | cut -d' ' -f9 | tr -d ','
I'm not an awk wizard, I just asked chatGPT
Quote:
awk 'NR % 6 == 1': Filters the output from grep to include only lines where the line number (NR) is 1 modulo 6, effectively giving you every 6th line starting from the first match.
Cheers,
Yann
Yann is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Tutorials] Tutorial of how to plot residuals ! wolle1982 OpenFOAM Community Contributions 172 December 6, 2024 07:20
GnuPlot does not work. ahamed68 OpenFOAM Post-Processing 3 January 29, 2024 06:02
Cannot find functionObject file residuals vava10 OpenFOAM Pre-Processing 2 November 14, 2020 13:21
[PyFoam] PyFoam 0.6.9 wrong path to gnuplot klausb OpenFOAM Community Contributions 5 March 15, 2018 15:28
motorBike Residuals for SST k-omega... and mine JR22 OpenFOAM Running, Solving & CFD 6 August 1, 2013 10:08


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