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 Members List Search Today's Posts Mark Forums Read

Like Tree344Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 18, 2020, 23:38
Default
  #161
New Member
 
Join Date: Aug 2020
Posts: 7
Rep Power: 6
Kannan86 is on a distinguished road
Hi Peter,

Thanks a lot for the suggestion.


I changed the script as u said


My Script:
----------------------------------------------------------------------------------------------------------------------------
set xrange [1:*]
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
------------------------------------------------------------------------------------------------------------------------

But, still I am getting error message...

---------------------------------------------------------------------------------------------------------------------------------------------------------------
gnuplot> load "Residuals"
"Residuals" line 11: warning: Skipping data file with no valid points
"Residuals" line 11: warning: Skipping data file with no valid points
"Residuals" line 11: warning: Skipping data file with no valid points
"Residuals" line 11: warning: Skipping data file with no valid points
"Residuals" line 11: warning: Skipping data file with no valid points
"Residuals" line 11: 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 11: x range is invalid
--------------------------------------------------------------------------------------------------------------------------------------------------------------


Plese help me out...
Kannan86 is offline   Reply With Quote

Old   August 19, 2020, 21:59
Default
  #162
Senior Member
 
Peter Hess
Join Date: Apr 2011
Location: Austria
Posts: 250
Rep Power: 17
peterhess is on a distinguished road
I executed your skript on a case of mine.

It works actualy...

I dont see a problem with it.

Regards

Peter
Kannan86 likes this.

Last edited by peterhess; August 20, 2020 at 05:47.
peterhess is offline   Reply With Quote

Old   December 2, 2020, 12:21
Default
  #163
Member
 
Mohammad M F
Join Date: Jan 2016
Location: Washington DC, USA
Posts: 43
Rep Power: 10
mmohaqeqf is on a distinguished road
For those of you who are stuck with plotting residuals from the Windows Subsystem for Linux (bash under windows), please see the following link for some possible solutions:


Plot the residuals using pyFoamPlotWatcher
mmohaqeqf is offline   Reply With Quote

Old   January 21, 2021, 15:47
Default gnuplot not plotting residuals
  #164
New Member
 
Join Date: Dec 2020
Posts: 26
Rep Power: 5
OlivierM is on a distinguished road
Hello,
I have followed your steps but I don't succeed to plot any residuals at all.
Here the error I get:

[
gnuplot> load 'residuals.gnu'
"residuals.gnu" line 10: warning: Skipping data file with no valid points
"residuals.gnu" line 10: warning: Skipping data file with no valid points
"residuals.gnu" line 10: warning: Skipping data file with no valid points
"residuals.gnu" line 10: warning: Skipping data file with no valid points
"residuals.gnu" line 10: warning: Skipping data file with no valid points
"residuals.gnu" line 10: warning: Skipping data file with no valid points

gnuplot> plot "< cat logS | grep 'Solving for Ux' | cut -d' ' -f4 | tr -d ','" title 'Ux' with lines,
"< cat logS | grep 'Solving for Uy' | cut -d' ' -f5 | tr -d ','" title 'Uy' with lines,
"< cat logS | grep 'Solving for Uz' | cut -d' ' -f9 | tr -d ','" title 'Uz' with lines,
"< cat logS | grep 'Solving for omega' | cut -d' ' -f9 | tr -d ','" title 'omega' with lines,
"< cat logS | grep 'Solving for k' | cut -d' ' -f9 | tr -d ','" title 'k' with lines,
"< cat logS | grep 'Solving for p' | cut -d' ' -f9 | tr -d ','" title 'p' with lines

^
"residuals.gnu" line 10: x range is invalid
]

Here is an extract of the 'logS' file:

[
Time = 601

smoothSolver: Solving for Ux, Initial residual = 0.00152791, Final residual = 1.34114e-06, No Iterations 10
smoothSolver: Solving for Uy, Initial residual = 0.00188445, Final residual = 1.40107e-06, No Iterations 11
smoothSolver: Solving for Uz, Initial residual = 0.000782393, Final residual = 6.19569e-07, No Iterations 10
GAMG: Solving for p, Initial residual = 0.0083305, Final residual = 3.68604e-05, No Iterations 4
GAMG: Solving for p, Initial residual = 0.000366117, Final residual = 2.0491e-06, No Iterations 4
time step continuity errors : sum local = 1.35357e-05, global = -1.07648e-06, cumulative = 1.73712
smoothSolver: Solving for omega, Initial residual = 2.75059e-06, Final residual = 7.9774e-09, No Iterations 9
smoothSolver: Solving for k, Initial residual = 0.00298973, Final residual = 2.85537e-06, No Iterations 11
ExecutionTime = 14.02 s ClockTime = 14 s
]


Is there anyone who can help me understanding this problem ?


Gnuplot is v5.4 installed on W10
OF is v2012 installed on Ubuntu 20.04 WSL2
OlivierM is offline   Reply With Quote

Old   July 22, 2022, 08:08
Default mix/max(T)
  #165
New Member
 
Join Date: May 2022
Posts: 6
Rep Power: 4
ade10 is on a distinguished road
how can i plot the value of max temperature in my domain?
ade10 is offline   Reply With Quote

Old   September 29, 2022, 10:54
Default
  #166
New Member
 
Seyfi Girgin
Join Date: Aug 2015
Posts: 12
Rep Power: 11
seyfigirgin is on a distinguished road
Hi all
In my cases i have the following data

GMRES iteration:0 Residual: value 1 value 2 value 3
GMRES iteration:1 Residual: value 4 value 5 value 6

How can i select the value 2?

Regards
seyfigirgin is offline   Reply With Quote

Old   September 29, 2022, 12:02
Default
  #167
Member
 
Flavio Galeazzo
Join Date: Mar 2009
Location: Karlsruhe, Germany
Posts: 34
Rep Power: 18
flavio_galeazzo is on a distinguished road
You can try this:

plot "< cat log | grep 'GMRES iteration:0' | cut -d' ' -f7 | tr -d ','" title 'Value 2' with lines
flavio_galeazzo is offline   Reply With Quote

Old   September 29, 2022, 12:26
Default
  #168
New Member
 
Seyfi Girgin
Join Date: Aug 2015
Posts: 12
Rep Power: 11
seyfigirgin is on a distinguished road
Quote:
Originally Posted by flavio_galeazzo View Post
You can try this:

plot "< cat log | grep 'GMRES iteration:0' | cut -d' ' -f7 | tr -d ','" title 'Value 2' with lines
Thank you very much

What if they are in the form of

GMRES iteration:0 Residual: (value 1 value 2 value 3)
GMRES iteration:1 Residual: (value 4 value 5 value 6)

and i want to pick up value 1, in that case -f6 or whatever -f number does not work because of the parenthesis i guess. I received "invalid x range" error.

What could be done for this case?
seyfigirgin is offline   Reply With Quote

Old   September 29, 2022, 12:36
Default
  #169
Member
 
Flavio Galeazzo
Join Date: Mar 2009
Location: Karlsruhe, Germany
Posts: 34
Rep Power: 18
flavio_galeazzo is on a distinguished road
Ok, try this instead

plot "< cat log | grep 'GMRES iteration:0' | cut -d' ' -f4 | tr -d '('" title 'Value 1' with lines
flavio_galeazzo is offline   Reply With Quote

Old   October 5, 2022, 15:01
Default
  #170
New Member
 
Tunc
Join Date: Nov 2021
Posts: 9
Rep Power: 4
tuncm18 is on a distinguished road
Quote:
Originally Posted by bioexplore View Post
Hi, can this method applicable to parallel cases?
Yes, you can apply as long as you have merged solution log if I am not wrong.
tuncm18 is offline   Reply With Quote

Old   January 14, 2024, 17:01
Post This thread is long, let's make it longer!
  #171
New Member
 
Diego
Join Date: Dec 2019
Location: Cardiff
Posts: 9
Rep Power: 6
Hip2BL7 is on a distinguished road
Quote:
Originally Posted by wolle1982 View Post
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 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 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
Thank you Wolfgang for this great post. I also made some edits specific to my use case which I thought I'd share in case it helps someone. In particular:
  • Ascii display for remote viewing. Running the command once will plot the residuals once. If you wish to continuously update the plot; I use:
    Code:
    watch -n2 gnuplot residuals.gp
    This allows me to watch residuals in real time remotely, as I often don't have graphical capabilities. I currently have it set quite large ('set term dumb 100 40' -> 100 x 40) but you could easily change this.
  • Supports a single command line log file argument:
    Code:
    gnuplot -e "filename='log.buoyantSimpleFoam'" residuals.gp

An example of the script running:

Code:
loading log.buoyantSimpleFoam...

                                                                                                    
                                                                                                    
                                                Residuals                                           
     1e0 +--------------------------------------------------------------------------------------+   
         |+             +             +              +             +              +            +|   
         |+                                                                           k *******+|   
         |####                                                                        p #######+|   
         |   ##       ###                                                           eps $$$$$$$ |   
    1e-1 |-+  ##     ######  ####                                                             +-|   
         |+    ##   ##    ####  ##     #####                                                   +|   
         |+     ## ##      ##    ###  ##   ##  #####      ###                                  +|   
         |+      ###       ##      ####     ####   ##   ### ##   #####                         +|   
    1e-2 |-+      #        ##       ##        #     #####    #####   ##   ######              +-|   
         |+       #        #        ##                ##      ##      ## ##    #  ##           +|   
         |+                                                            ###     ####            +|   
         |+                                                                     ##             +|   
         |+                                                                                    +|   
    1e-3 |*+                                                                                  +-|   
         |*                                                                                    +|   
         |$**                                                                                  +|   
         |$ **                                                                                 +|   
         |$  **                                                                                 |   
    1e-4 |$$  ****        ******                                                              +-|   
         |+$$    *****  ***    **    ***                                                       +|   
         |+ $        ****       ** *** ***   *****                                             +|   
         |+ $$             $$$   ***     *****   **  ******     ***                            +|   
         |   $$$$$$$    $$$$ $$           **      ****    ** **** ***   *****                   |   
    1e-5 |-+     $$$$$$$$     $$   $$$$$     $$$           ***      *****   **  ****          +-|   
         |+                    $$ $$   $$  $$$ $$     $$$            *       ****              +|   
         |+                     $$$     $$$$    $$ $$$$ $$    $$$$$                            +|   
         |+                      $       $$      $$$     $$ $$$   $$ $$$$$$$                   +|   
    1e-6 |-+                                              $$$      $$$     $$ $$$$$$          +-|   
         |+                                                                 $$$                +|   
         |+                                                                                    +|   
         |+                                                                                    +|   
         |+             +             +              +             +              +            +|   
    1e-7 +--------------------------------------------------------------------------------------+   
         0             5000         10000          15000         20000          25000         30000 
                                                Iteration
I have the residuals.gp file hidden in my home directoy and linked to an alias in my .bashrc, so I can quickly run it and check wherever I may be:

Code:
# run this with the name of the log file, i.e.
#    - ofresiduals log
ofresiduals() {
    gnuplot -e "filename='$1'" ~/.of.residuals.gp
}
Thanks again for this fantastic thread!

Diego
Attached Files
File Type: txt residuals.txt (993 Bytes, 7 views)

Last edited by Hip2BL7; January 14, 2024 at 17:31. Reason: doesn't work with watch! will have to edit...
Hip2BL7 is offline   Reply With Quote

Old   February 20, 2024, 02:55
Lightbulb How to plot residuals in OpenFOAM-v2312 ?
  #172
New Member
 
Mustafa
Join Date: Sep 2020
Posts: 3
Rep Power: 6
mkuzaay is on a distinguished road
To visualize residuals on a logarithmic scale in OpenFOAM version 2312 (OF-v2312), it is necessary to have a solverInfo file defined in the system.

You can refer to example files located at 'etc/caseDicts/postProcessing/numerical' for guidance on setting up the solverInfo file. This file plays a crucial role in enabling the plotting of residuals with logarithmic scaling for a more insightful analysis.

The following bash script can be used to plot the residuals:
Code:
#!/bin/bash

# path
path="postProcessing/solverInfo/0/solverInfo.dat"
result="Residuals.png"

# Extract the data in the relevant columns
awk '{print $1, $4, $9, $14, $19}' $path > extracted_data.txt

# Log Scale Plot
gnuplot <<- GNU
set terminal png size 1200,600 font "Times New Roman, 16"
set output "$result"
set xlabel "Time"
set ylabel "Residual"
set logscale y
set format y "10^{%T}"
set key font "Times New Roman, 16"
set label font "Times New Roman, 16"
set xlabel font "Times New Roman, 16"
set ylabel font "Times New Roman, 16"
set xtics font "Times New Roman, 16"
set ytics font "Times New Roman, 16"

plot "extracted_data.txt" using 1:2 with lines lw 1 title "alpha.water", \
     "extracted_data.txt" using 1:3 with lines lw 1 title "epsilon", \
     "extracted_data.txt" using 1:4 with lines lw 1 title "k", \
     "extracted_data.txt" using 1:5 with lines lw 1 title "p_{rgh}"

GNU
mkuzaay 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
plot residuals in multiregion solver val46 OpenFOAM 4 December 12, 2016 06:06
To Plot Residuals on the fly. neeraj OpenFOAM Running, Solving & CFD 5 October 2, 2013 06:23
[PyFoam] why pyFoamPlotRunner doesn't plot continuity residuals? immortality OpenFOAM Community Contributions 10 May 5, 2013 06:13
plot of residuals hawkeye321 OpenFOAM 5 December 7, 2012 09:05
[Virtualization] OpenFOAM oriented tutorial on using VMware Player - support thread wyldckat OpenFOAM Installation 2 July 11, 2012 16:01


All times are GMT -4. The time now is 10:50.