CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (http://www.cfd-online.com/Forums/openfoam-solving/)
-   -   To Plot Residuals on the fly. (http://www.cfd-online.com/Forums/openfoam-solving/111947-plot-residuals-fly.html)

neeraj January 18, 2013 09:02

To Plot Residuals on the fly.
 
Can anyone explain how to plot real time residuals in openfoam 2.1.1. I have seen tutorials for older versions but its not working in 2.1.1

gschaider January 18, 2013 17:14

Quote:

Originally Posted by neeraj (Post 402654)
Can anyone explain how to plot real time residuals in openfoam 2.1.1. I have seen tutorials for older versions but its not working in 2.1.1

It should. All these methods read the standard-output and extract the residuals from it. The format of the residuals has not changed for years (in pyFoam I havn't had to change the pattern since 1.5 I think and I regularly use it for plotting residuals from 1.6 to 2.1)

But maybe if you refer to the method you're using (link on this forum) and the solver you're using someone can enlighten you

chern January 21, 2013 06:26

Needed: Linux, OpenFoam, gnuplot, X (X.org).


1) Run in first terminal shell solver like icoFoam as:

$ icoFoam > log.icoFoam

2) Run in second terminal shell gnuplot as:

$ gnuplot Courant

repeat this step for other plot in third terminal etc.

3) Make additional file for plot graph on runtime OpenFoam.


- If you don't need logscale: comment line "set logscale y" with # in first position as "#set logscale y" or delete line.
- For plotting any other fields in log file you must editing argument grep command ex. "grep 'Courant Number'"
count words in grep string number of field:
"Courant Number mean: 0.000417096 max: 0.124527"
1-"Courant" 2-"Number" 3-"mean:" 5-"max:"
filds No 4 and 6 is mean and max Courant number. Its using in args of cut command: "cut -d' ' -f4"
- If you need draw only one graph: use command plot like:
"plot "< cat log.icoFoam | grep 'Courant Number' | cut -d' ' -f4 | tr -d ','" title 'Courant Number mean' with lines"

- Edit time in seconds in gnuplot command "pause 10" for redraw plot.

- Other commands are trivial



File: log.icoFoam (part of file for example)
------------------------------------
Time = 0.1

Courant Number mean: 0.000417096 max: 0.124527
DILUPBiCG: Solving for Uy, Initial residual = 1, Final residual = 3.59578e-17, No Iterations 1
DICPCG: Solving for p, Initial residual = 1, Final residual = 9.72814e-07, No Iterations 756
time step continuity errors : sum local = 2.66067e-09, global = 5.15345e-14, cumulative = 5.15345e-14
DICPCG: Solving for p, Initial residual = 1.07532e-06, Final residual = 4.96329e-07, No Iterations 1
time step continuity errors : sum local = 1.23062e-09, global = 5.01838e-13, cumulative = 5.53373e-13
ExecutionTime = 4.9 s ClockTime = 5 s
------------------------------------

File: Courant
------------------------------------
set logscale y
set title "Courant"
set ylabel 'Courant'
set xlabel 'Iteration'
plot "< cat log.icoFoam | grep 'Courant Number' | cut -d' ' -f4 | tr -d ','" title 'Courant Number mean' with lines,\
"< cat log.icoFoam | grep 'Courant Number' | cut -d' ' -f6 | tr -d ','" title 'Courant Number max' with lines
pause 10
reread
------------------------------------

File: Residuals
------------------------------------
set logscale y
set title "Residuals"
set ylabel 'Residual'
set xlabel 'Iteration'
plot "< cat log.icoFoam | grep 'Solving for p' | cut -d' ' -f9 | tr -d ','" title 'p' with points
pause 10
reread
------------------------------------

izna October 1, 2013 14:46

hi,

but if i want the iteration at the same time to be plotted so that i can monitor the residuals... what command should i use?

Can you please kindly tell me?

Kind regards
Izna

Logan Page October 2, 2013 06:07

If you want the residuals to be piped to the terminal as well as the log file, while the simulation is running, you can use:
icoFoam 2>&1 | tee log.icoFoam

Then you can use gnuplot (as chern suggested above) or pyFoam to plot the residuals from the log file.

File October 2, 2013 06:23

Hi Izna

I think this is what you're looking for

http://www.cfd-online.com/Forums/ope...residuals.html

Regards
Filip


All times are GMT -4. The time now is 14:54.