CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Post-Processing (http://www.cfd-online.com/Forums/openfoam-post-processing/)
-   -   Here is a script for plotting force files in Gnuplot. (http://www.cfd-online.com/Forums/openfoam-post-processing/101915-here-script-plotting-force-files-gnuplot.html)

lordvon May 17, 2012 02:16

Here is a script for plotting force files in Gnuplot.
 
I did not find a script for plotting the force file outputs (specified in controlDict), so I made one and am sharing it.

It plots whatever forces.dat file is in the same directory as the script. There are some constants and stuff that are my own, and shouldnt be too hard to tweak for your own usage. The 'truncationFactor' cuts off the first (number of lines in forces.dat)/truncationFactor lines in the forces.dat file; this is useful for transient simulations where the first few data points may be unphysically high and mess up the plot scale.

You need to enter in by line what you want to plot in 'forcesProcess' following the command 'plot'. The numbers for each force and moment as variables are just for reference; they are the indexes of each of the force/moment pressure/viscous component as listed in order on each line in the forces.dat file.

Two files, forcesProcess and forcesPlot. Currently forces.dat needs to be in same directory (can easily change to your desired relative directory), and forcesPlot is called from the shell to generate the plot.

forcesPlot:
Code:

#!/bin/bash
truncationFactor=10
name='forces.dat'

y=$(wc $name | cut -d' ' -f3)
start=$[y/truncationFactor]
echo "Lines in force file: $y"
echo "Line to start plot: $start"
sed 's/[()]//g' < $name > processed.dat
sed -i "1,${start}d" processed.dat
gnuplot forcesProcess -

forcesProcess:
Code:

cellDepth=0.00515394
omega=2400*2*pi/60
time=1
xForcePressure=2
xForceViscous=xForcePressure+3
yForcePressure=3
xForceViscous=yForcePressure+3
zForcePressure=4
xForceViscous=zForcePressure+3
xMomentPressure=8
xMomentViscous=xMomentPressure+3
yMomentPressure=9
yMomentViscous=yMomentPressure+3
zMomentPressure=10
zMomentViscous=zMomentPressure+3

plot  "processed.dat" using 1:(($2+$5)/cellDepth) title 'Drag (Newtons)', \
      "processed.dat" using 1:(($3+$6)/cellDepth) title 'Thrust (Newtons)', \
      "processed.dat" using 1:(($10+$13)/cellDepth*omega) title 'Power (Watts)'



All times are GMT -4. The time now is 13:33.