This repository has been archived on 2023-11-20. You can view files and clone it, but cannot push or open issues or pull requests.
foam-extend4.1-coherent-io/bin/plotForces.py

63 lines
1.8 KiB
Python
Raw Normal View History

#!/usr/bin/python
import re
forceRegex=r"([0-9.Ee\-+]+)\s+\(+([0-9.Ee\-+]+)\s([0-9.Ee\-+]+)\s([0-9.Ee\-+]+)\)\s\(([0-9.Ee\-+]+)\s([0-9.Ee\-+]+)\s([0-9 .Ee\-+]+)\)+\s\(+([0-9.Ee\-+]+)\s([0-9.Ee\-+]+)\s([0-9.Ee\-+]+)\)\s\(([0-9.Ee\-+]+)\s([0-9.Ee\-+]+)\s([0-9.Ee\-+]+)\)+"
t = []
fpx = []; fpy = []; fpz = []
fvx = []; fvy = []; fvz = []
mpx = []; mpy = []; mpz = []
mvx = []; mvy = []; mvz = []
pipefile=open('forces/0/forces.dat','r')
lines = pipefile.readlines()
for line in lines:
match=re.search(forceRegex,line)
if match:
t.append(float(match.group(1)))
fpx.append(float(match.group(2)))
fpy.append(float(match.group(3)))
fpz.append(float(match.group(4)))
fvx.append(float(match.group(5)))
fvy.append(float(match.group(6)))
fvz.append(float(match.group(7)))
mpx.append(float(match.group(8)))
mpy.append(float(match.group(9)))
mpz.append(float(match.group(10)))
mvx.append(float(match.group(11)))
mvy.append(float(match.group(12)))
mvz.append(float(match.group(13)))
# combine pressure and viscous forces and moments
fx = fpx
fy = fpy
fz = fpz
mx = mpx
my = mpy
mz = mpz
for i in range(1,len(t)):
fx[i] += fvx[i]
fy[i] += fvy[i]
fz[i] += fvz[i]
mx[i] += mvx[i]
my[i] += mvy[i]
mz[i] += mvz[i]
# plot forces
import pylab
pylab.xlabel('iteration')
pylab.ylabel('force (N)')
pylab.grid(True)
#
pylab.plot(t,fx,'-',label="fx")
pylab.plot(t,fy,'-',label="fy")
pylab.plot(t,fz,'-',label="fz")
#pylab.plot(t,mx,'-',label="mx")
#pylab.plot(t,my,'-',label="my")
#pylab.plot(t,mz,'-',label="mz")
pylab.legend()
pylab.show()