CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   Main CFD Forum (http://www.cfd-online.com/Forums/main/)
-   -   Help with GNUPlot (http://www.cfd-online.com/Forums/main/13524-help-gnuplot.html)

Renato. May 25, 2007 20:23

Help with GNUPlot
 
Hi folks,

I've beem implementing a dynamic convergence monitor for my finite element solver with GNUPlot. The idea is quite simple and is already working. It consists in calling gnuplot with the following script:

------------------- monitor.gnu file --------------------

reset

set size 1.0, 1.0 set origin 0.0, 0.0 set multiplot set grid unset key set logscale y

# Absolute residuous set size 0.5, 0.5 set origin 0.0, 0.5 set title "Absolute Flow residua" set xlabel "Time step (adim)" set ylabel "log (||r||)" plot 'flow-plot.dat' using 1:3 with lines

# Relative residuous set size 0.5, 0.5 set origin 0.5, 0.5 set title "Relative Flow residua" set xlabel "Time step (adim)" set ylabel "log (||r||/||r0||)" plot 'flow-plot.dat' using 1:4 with lines

# Relative solution increment set size 0.5, 0.5 set origin 0.0, 0.0 set title "Relative solution increment" set xlabel "Time step (adim)" set ylabel "log (||du||/||u||)" plot 'flow-plot.dat' using 1:5 with lines

# Linear Tolerance set size 0.5, 0.5 set origin 0.5, 0.0 set title "Linear Tolerance" set xlabel "Time step (adim)" set ylabel "GMRES tolerance" unset logscale y plot 'flow-plot.dat' using 1:6 with lines

pause 1 reread ---------------------------------------------

the script above is called with the command gnuplot monitor.gnu

my program writes the convergence data in "flow-plot.dat" file and the script is continuosly reread to plot the updated data. My problem is that after some, let's say..., 1000 iterations the x axis begins to turn completely squeezed due to the autoscale. My idea is adjust the xmin and xmax range to follow the converge data in a constant offset, e.g., with a constant offset of 50 iterations I'd have the xrange "rolling" to right as a constant window. 0-50, 50-100, 100-150, 150-200, and so on...

Does anyone know how could I do it in GNUplot?

thanks for any help

Renato.


Sergei Chernyshenko May 27, 2007 17:34

Re: Help with GNUPlot
 
Hi, Renato,

Using reread in this way is an interesting idea.

No, I do not know how to do what you want in gnuplot. However, I did some animations with gnuplot under Linux, see

http://www.afm.ses.soton.ac.uk/~sergei/Plotter.f

May be this will help.

Regards Sergei

Renato. May 28, 2007 09:01

Re: Help with GNUPlot
 
Hy Sergei

in fact I had already found your routine googling around. It was my starting point ;o) ... but in my case I chose to write a bunch of information as a table and select the data to be plotted in with the "using x:y" clause. In this way I could use the same data file to create other plots using other softwares such as Excel, etc... . The idea is to write a general tabular data that could be loaded and plotted by gnuplot or any other software (Excel, SigmaPlot, Origin, etc...) and not to write a specific formatted data suited only to gnuplot.

I was thinking about a solution to my problem. It would be easy to do if I had some way to read the data, get the number of lines, and setting the range as

from MAXLINES-OFFSET to MAXLINES

a pseudo-algorithm would be like this:

1. load data 2. get the number of lines 3. set xrange [number of lines]-[offset]:[number of lines] 4. Go ahead with the script described in the last post

here I'm considering "offset" as the number of points that must be plotted in the x axis as exemplified in my last post.

Regards

Renato.


Sergei Chernyshenko May 28, 2007 10:00

Re: Help with GNUPlot
 
Hi, Renato,

What abot your master code repeatedly writing to the disk one more file, with gnuplot commands, and your gnuplot file loading that another file? That would give you a lot of flexibility.

Regards

Sergei

Renato. June 5, 2007 08:06

Re: Help with GNUPlot
 
I've found an interesting way to solve my problem. Look at this:

------------------------------------ reset

nlines = `wc --lines flow-plot.dat | sed "s/ .*//"`-1 offset = 50

set size 1.0, 1.0 set origin 0.0, 0.0 set multiplot set grid unset key unset logscale x set logscale y set xrange [nlines-offset:nlines+offset]

# Absolute residuous set size 0.5, 0.5 set origin 0.0, 0.5 set title "Absolute Flow residua" set xlabel "Global iteration" set ylabel "log (||r||)" plot 'flow-plot.dat' using 1:3 with lines

# Relative residuous set size 0.5, 0.5 set origin 0.5, 0.5 set title "Relative Flow residua" set xlabel "Global iteration" set ylabel "log (||r||/||r0||)" plot 'flow-plot.dat' using 1:4 with lines

# Relative solution increment set size 0.5, 0.5 set origin 0.0, 0.0 set title "Relative solution increment" set xlabel "Global iteration" set ylabel "log (||du||/||u||)" plot 'flow-plot.dat' using 1:5 with lines

# Linear Tolerance set size 0.5, 0.5 set origin 0.5, 0.0 set title "Linear Tolerance" set xlabel "Global iteration" set ylabel "GMRES tolerance" unset logscale y plot 'flow-plot.dat' using 1:6 with lines

pause 1 reread ------------------------------------

Note that I'm using the "wc" command to know the plot x range before plotting it. In this way, I can set the xrange accordingly.

Regards

Renato.


Sergei Chernyshenko June 5, 2007 17:30

Re: Help with GNUPlot
 
Hi, Renato,

Great!

Next time I need to animate something I will try to use your idea. The data file can be on a virtual (RAM) drive so that read/write operations will be fast (I never tried this but it should work).

May be you should describe this idea in some kind of publication, or simply put it on a web-page, as many people would be interested.

Regards

Sergei


Renato. June 6, 2007 19:51

Re: Help with GNUPlot (an easier solution)
 
Hi Sergei

after taking a look in this tutorial http://t16web.lanl.gov/Kawano/gnuplo...le2-e.html#7.2 I realized an easier solution for the same problem:

we can simply use:

plot "< tail -150 datafile.dat"

to dynamically plot only the latest 150 points

Of course, it's only supported on Unix systems because of the tail command.

In my case, I'm running my simulation on a SGI Altix system (IA64/Linux) while plotting the convergence data in a Windows Vista using a X-server and SSH conection, so, my GNUPlot is running on the *nix side.

I hope it can be helpful for other users. I'll post these tics on my site as soon as possible

cheers

Renato.



All times are GMT -4. The time now is 00:35.