Thursday, October 2, 2014

How To Plot Residuals in OpenFOAM

A sample script.

#!/bin/bash

foamLog log.simpleFoam >/dev/null

gnuplot -persist > /dev/null 2>&1 << EOF
        set logscale y
        set title "Residual vs. Iteration"
        set xlabel "Iteration"
        set ylabel "Residual"
        plot "logs/Ux_0" with lines,\
                "logs/p_0" with lines
EOF

The video:


3 comments:

  1. Nice post. I was reading Gnuplot in action and I came across a nice addition to the shell script to save plots in a given format.

    #!/bin/bash

    foamLog log.simpleFoam >/dev/null

    gnuplot -persist > /dev/null 2>&1 << EOF
    set logscale y
    set title "Residual vs. Iteration"
    set xlabel "Iteration"
    set ylabel "Residual"
    plot "logs/Ux_0" with lines,\
    "logs/p_0" with lines

    call "save_plot" "output_filename" "size 1600,900" # size is an argument and is optional

    EOF

    save_plot file contains the following lines:

    set terminal push
    set terminal pngcairo $1
    set output "$0.png"
    replot
    set output
    set terminal pop

    ReplyDelete
    Replies
    1. Thanks for reading and for that useful script!
      I like your blog, by the way :)

      Delete
    2. Welcome. I'm glad that you liked my blog. I think my blog is plain weird. :D

      Delete