CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Post-Processing

Here is a script for plotting force files in Gnuplot.

Register Blogs Community New Posts Updated Threads Search

Like Tree5Likes
  • 5 Post By lordvon

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 17, 2012, 02:16
Default Here is a script for plotting force files in Gnuplot.
  #1
Senior Member
 
Robert
Join Date: Sep 2010
Posts: 158
Rep Power: 15
lordvon is on a distinguished road
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)'
lordvon is offline   Reply With Quote

Old   August 18, 2021, 13:43
Default
  #2
Member
 
Gabriel Felix
Join Date: May 2021
Location: Brazil
Posts: 35
Rep Power: 5
gabrielfelix is on a distinguished road
I wrote a similar code for plotting residuals, forces or both

You just gotta execute them at terminal:
Code:
./plotResiduals
./plotForces
./plotRF
plotResiduals:
Code:
#!/bin/bash

# Code for plotting residuals

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/Uy_0" with lines,\
"logs/Uz_0" with lines,\
"logs/p_0" with lines

EOF
plotForces:
Code:
#!/bin/bash

foamLog log.simpleFoam >/dev/null

gnuplot -persist > /dev/null 2>&1 << EOF
set logscale x
set title "Forces vs. Iteration"
set xlabel "Iteration"
set ylabel "Forces"
plot '<sed -e "s/[(,)]//g" ./postProcessing/forces/0/force_0.dat' using 1:2 with lines title 'Fx [N]',\
'<sed -e "s/[(,)]//g" ./postProcessing/forces/0/force_0.dat' using 1:3 with lines title 'Fy [N]',\
'<sed -e "s/[(,)]//g" ./postProcessing/forces/0/force_0.dat' using 1:4 with lines title 'Fz [N]'

EOF
plotRF:
Code:
#!/bin/bash

# Code for plotting residuals and forces

foamLog log.simpleFoam >/dev/null

cat ./postProcessing/forces/0/force_0.dat | tr -d "("")" > ./forceClean.dat

gnuplot -persist > /dev/null 2>&1 << EOF

set terminal wxt size 500,600

set multiplot
set size 1,0.5
set origin 0.0,0.5; 
set logscale y
set logscale x
set title "Residual vs. Iteration"
set xlabel "Iteration"
set ylabel "Residual";
plot "logs/Ux_0" with lines,\
"logs/Uy_0" with lines,\
"logs/Uz_0" with lines,\
"logs/p_0" with lines; 


set origin 0.0,0.0; 
unset logscale y
set title "Forces vs. Iteration"
set xlabel "Iteration"
set ylabel "Forces";
plot '<sed -e "s/[(,)]//g" ./postProcessing/forces/0/force_0.dat' using 1:2 with lines title 'Fx [N]',\
'<sed -e "s/[(,)]//g" ./postProcessing/forces/0/force_0.dat' using 1:3 with lines title 'Fy [N]',\
'<sed -e "s/[(,)]//g" ./postProcessing/forces/0/force_0.dat' using 1:4 with lines title 'Fz [N]'
unset multiplot

EOF
gabrielfelix is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Urgently Need the code of Lift force and VM force Kai Yan Main CFD Forum 0 July 16, 2008 07:07
plotting force magnitude force Siemens 6 July 11, 2008 04:19
DEFINE_CG_MOTION and pressure force Teo Fumagalli FLUENT 0 April 11, 2008 10:25
pressure force and viscous force CFD FLUENT 0 March 7, 2006 01:03
Force monitors Phil FLUENT 1 June 4, 2004 02:21


All times are GMT -4. The time now is 04:02.