|
[Sponsors] |
January 29, 2007, 06:23 |
Real-time residual and results plotting
|
#1 |
Guest
Posts: n/a
|
Hello, I'd like to know how to plot the residual into a graphics in real-time during the running of my own code. It's a code written in C, compiled with gcc and run as an executable, and the only way I have now to view the diagram of the residual is printing out the values and only afterwards to view them through octave/gnuplot or matlab.
Anyone worte a script to let the executable communicate with a visualization tool? Thanks a lot Simone |
|
January 29, 2007, 07:00 |
Re: Real-time residual and results plotting
|
#2 |
Guest
Posts: n/a
|
You could use pgplot.
http://www.astro.caltech.edu/~tjp/pgplot/ I use a much simpler solution. From my code I run gnuplot (use the system subroutine which is available in both fortran and C) to generate a png file of the residue plot. I open the png file with xv or display (part of imagemagick); the image display gets updated automatically whenever the png file is modified. |
|
January 29, 2007, 07:19 |
Re: Real-time residual and results plotting
|
#3 |
Guest
Posts: n/a
|
Thank you very much for the hint. Ill work on it starting from your suggestion. In case I want to use your way, calling gnuplot from C, would it be called as: system(gnuplot 'filename') ?
thanks again simone |
|
January 29, 2007, 07:24 |
Re: Real-time residual and results plotting
|
#4 |
Guest
Posts: n/a
|
Found this some time ago:
c Fortran-gnuplot interaction for real-time animation using named pipe c c This is a simple example of how gnuplot can be used to create c real-time animation of data produced by running fortran 77 code. c c I put it in the searchable directory in a hope that it can be useful, c but no guarantees of any kind: use it at your own risk. Too many c frames per second can hang you system heavily. c c To understand how it works, you need to know what a named pipe is, and what c plot '-' means in gnuplot: read the manuals. c c And, PLEASE, if you know why a.out > FIFOfile works c but just a.out does not c even though the gnuplot commands are written to the pipe and not c to the standard output, send me an explanation to c chernysh@soton.ac.uk (Sergei Chernyshenko) or c by other means, see http://www.afm.ses.soton.ac.uk/ -> People. c c How to use: c c at the linux command prompt, type mkfifo FIFOfile c compile this file and name the executable a.out . c in an xterm window type gnuplot < FIFOfile c in another window type a.out > FIFOfile c enjoy c c do not use too many frames per second, the computer may hang. c c second(x) gives the CPU time in seconds. Replace if unavailable. nframe=0 open(1,file='FIFOfile', status='unknown') write(1,*) 'set xrange [-10:10]' write(1,*) 'set yrange [-2:2]' write(1,*)'set title \'Demonstrating animation Fortran-gnuplot' 1 ,' via named pipe\'' close(1) 1 call second(x) c 15 frames per second: if(15*x.gt.nframe) then nframe=nframe+1 open(1,file='FIFOfile', status='unknown') write(1,*) 'plot sin(x-',x,'),',' \'-\' w lp' write(1,*) 0.2 write(1,*) 0.3 write(1,*) 0.4 write(1,*) 0.5 i=(x/10) i=i*10 write(1,*) (x-i)/10. write(1,*) 0.7 write(1,*) 0.8 write(1,*) 0.9 write(1,*) 'e' close(1) endif goto 1 stop end |
|
January 29, 2007, 07:31 |
Re: Real-time residual and results plotting
|
#5 |
Guest
Posts: n/a
|
Very useful, thanks
s. |
|
January 29, 2007, 07:35 |
Re: Real-time residual and results plotting
|
#6 |
Guest
Posts: n/a
|
Say you have put all your gnuplot commands in file "plot.gnu". In C you would run gnuplot as
system("gnuplot plot.gnu"); Suppose gnuplot generates plot.png You open it in xv as xv -poll plot.png & or in display as display -update 10 plot.png & You can also start the image viewer from within your C code. |
|
January 29, 2007, 07:57 |
Re: Real-time residual and results plotting
|
#7 |
Guest
Posts: n/a
|
I try this and let you know. Supposedly then this same thing would work also if I generate my plots with octave? For exemple I could view a vector field step by step during the exsecution of my C code?
system("octave plot.gnu"); |
|
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
transsonic nozzle with rhoSimpleFoam | Unseen | OpenFOAM Running, Solving & CFD | 8 | July 1, 2022 06:54 |
Extrusion with OpenFoam problem No. Iterations 0 | Lord Kelvin | OpenFOAM Running, Solving & CFD | 8 | March 28, 2016 11:08 |
Moving mesh | Niklas Wikstrom (Wikstrom) | OpenFOAM Running, Solving & CFD | 122 | June 15, 2014 06:20 |
Orifice Plate with a fully developed flow - Problems with convergence | jonmec | OpenFOAM Running, Solving & CFD | 3 | July 28, 2011 05:24 |
SimpleFoam k and epsilon bounded | nedved | OpenFOAM Running, Solving & CFD | 1 | November 25, 2008 20:21 |