0

I am doing a heat transfer simulation into a cube and plotting the evolution through time with a 2D heatmap at mid-depth of the cube.

Here is a screenshot of the .gif heatmap animation launched with "Image Viewer":

enter image description here

I want to display on the .gif animation the current simulation time at each iteration, that is to say on each image, with Gnuplot. Indeed, the delta time is 0.001 s, so I want to display something like " Time = 0.001 s" ... "Time = 0.002 s" and so on.

My dataset is something like this:

  x      z       t      T
0.000  0.000  0.000  373.000
0.000  0.005  0.000  298.000
0.000  0.015  0.000  298.000
            ...
0.000  0.985  0.000  298.000
0.000  0.995  0.000  298.000
0.000  1.000  0.000  373.000

            ...
0.015  0.000  0.001  373.000
0.015  0.005  0.001  292.000
0.015  0.015  0.001  283.000
0.015  0.025  0.001  283.000
           ....
0.015  0.985  0.001  283.000
0.015  0.995  0.001  292.000
0.015  1.000  0.001  373.000
           ...
0.615  0.000  0.004  373.000
0.615  0.005  0.004  309.900
0.615  0.015  0.004  287.100
0.615  0.025  0.004  283.300
           ...

And here is the .plt code for Gnuplot:

set view map scale 1
set size square
set xlabel("x (m)")
set ylabel("z (m)")
set zlabel("T")
set xrange [-0.01:1.01]
set yrange [-0.01:1.01]
set title "Heat transfert 3D at mid depth of a cube"
set cblabel "T (K)"

set hidden3d
set palette rgb 33,13,10 
set cbrange [283:373] # colobar range

set pm3d implicit at s 
set pm3d corners2color max 

set term gif animate delay 100 

set output "para_heat_3D_insta_4_0.gif"

stats "plot_para_heat_3D_insta.dat"

do for [i=1:int(STATS_blocks)]{
    splot "plot_para_heat_3D_insta.dat" index (i-1) using 1:2:4 with pm3d notitle 

}

set output

Is someone has an idea and could help me? Thanks in advance.

Jejouze
  • 23
  • 6

1 Answers1

1

Solution using current version of gnuplot (5.4)

DATA = "plot_para_heat_3D_insta.dat"
set key center at screen 0.5, 0.95
set key samplen 0

do for [i=1:int(STATS_blocks)]{
    splot DATA index (i-1) using 1:2:(t=$3,$4) with pm3d title sprintf("time = %g",t)

}

This will set the variable t to the content of column 3 for every point evaluated. After all points have been evaluated the column 3 value of the last point is still sitting in t so you can use it to construct a title for the plot.

If you have an earlier version of gnuplot

the same trick is possible but it requires an extra dummy plot command that loads t but doesn't plot anything.

do for [i=1:int(STATS_blocks)]{
    splot DATA index (i-1) every 1::1::1 using (t=$3):(NaN):(NaN) notitle, \
          DATA index (i-1) using 1:2:4 with pm3d title sprintf("time = %g",t)
}
Ethan
  • 13,715
  • 2
  • 12
  • 21
  • Thanks for your answer. I have the 5.2 version of Gnuplot and the first proposition seems to work but the time = 0 is replaced by time = NaN, so I don't have the display of the last time. I don't know why ...? But the second proposition works perfectly! Thanks! – Jejouze Jan 13 '22 at 19:03
  • 1
    The key is that version 5.4 evaluates the title *after* the plot, whereas earlier versions evaluated the title *before* the plot. If you think about the value of `t` before and after each plot, the reason for two different solutions is explained. – Ethan Jan 13 '22 at 21:34