CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Post-Processing (https://www.cfd-online.com/Forums/openfoam-post-processing/)
-   -   Plotting (Forces) in log file - 2nd match (https://www.cfd-online.com/Forums/openfoam-post-processing/141198-plotting-forces-log-file-2nd-match.html)

haze_1986 September 2, 2014 03:54

Plotting (Forces) in log file - 2nd match
 
I need to plot the Force vector over time using a sixDoFRigidBodyMotion solver.

Using the below script I managed to extract the "attachmentPt - anchor" and plot it with time without problems, but unsure how to extract the force vector using the getstatusoutput with grep command. Can someone enlighten me on this?

Code:


pathname = os.path.abspath('.')
fileName = os.path.join(pathname,'log')

status, data = commands.getstatusoutput('cat ' + fileName + '| grep translationDamper1')
data = data.split('\n')

x = []
y = []
z = []

for i in range(len(data)-1):
    line = data[i]
    line = line.split('(')[1].split(')')[0].split(' ')
    x.append(float(line[0]))
    y.append(float(line[1]))
    z.append(float(line[2]))

Here is the log file with the information I need
Code:


Restraint translationDamper1:  attachmentPt - anchor (0.4 0 0.4) spring length 0.565685424949 force (3.58941192118e-07 0 3.58941192118e-07)
Restraint translationDamper2:  attachmentPt - anchor (-0.4 0 0.4) spring length 0.565685424949 force (-3.58939622026e-07 0 3.58939622026e-07)


ssss September 2, 2014 04:46

Why not just get the index of the where the strings start?

something like int start = searchString(line,"attachment")

Playing with the indices, other way would be playing with the format of the string given, but I don't how does it work in python.

haze_1986 September 2, 2014 04:48

Thanks for the reply, I'm new to python as well and it has been a hit and miss by trial and error for me. Would be good if anyone can help me modifying this line for it to work.
Code:

status, data = commands.getstatusoutput('cat ' + fileName + '| grep translationDamper1')


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