|
[Sponsors] |
How to plot a forces.dat file (with all the brackets)? |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
August 25, 2010, 04:46 |
How to plot a forces.dat file (with all the brackets)?
|
#1 |
Senior Member
Charles
Join Date: Apr 2009
Posts: 185
Rep Power: 18 |
The wall forces calculation method in the recent versions of OF work very nicely, but produce a file (by default called forces.dat) with a lot of brackets (or parentheses, if you speak that variant of English). A typical line in the file looks like this:
(((6.57 128.05 364.35) (34.46 2.43 4.29)) (( etc .....) (......) (......))) Now I really like to plot the force history as a means of judging convergence, but this format is not amenable to easy plotting with Gnuplot. One can obviously import into a spreadsheet, but that is mighty tedious. The question is this: Is there an easy way of telling Gnuplot to ignore the brackets, or is there another plotting program that can do it easily? I'm sure that one can give Gnuplot a "plot using " command that can deal with the format .... I just don't seem to get it right! Any advice? |
|
August 26, 2010, 00:26 |
|
#2 |
Senior Member
Pavan
Join Date: May 2009
Location: Melbourne
Posts: 101
Rep Power: 17 |
I plotted my stuff in Excel but only after I'd extracted and compiled all the data into one tab delimited file using a bash script. It's not too difficult. A few hours reading of bash scripting if you have no experience should be good enough.
|
|
August 26, 2010, 10:05 |
|
#3 |
New Member
Malte
Join Date: Mar 2009
Posts: 2
Rep Power: 0 |
Hello,
you could use "sed" to filter your gunplot input. Use following line in gnuplot (the input for gnuplot will be the output of sed): plot "< sed s/[\\(\\)]//g input.dat" using 1:2 Regards, Malte Last edited by sinusmontis; August 26, 2010 at 10:28. |
|
August 26, 2010, 10:24 |
Thanks!
|
#4 |
Senior Member
Charles
Join Date: Apr 2009
Posts: 185
Rep Power: 18 |
Great, thanks for that, it has got me going along the right lines!
|
|
August 27, 2010, 08:34 |
|
#5 |
Senior Member
|
Another solution is to use python to parse and plot, e.g.,
Code:
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.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))) mpy.append(float(match.group(12))) mpz.append(float(match.group(13))) xlabel('time (sec)') ylabel('force (N)') grid() title('Example of using python to parse the force/moment tuples') plot(t,fpx,'o-') Of course, you need numpy and matplotlib loaded for the above example to work. I would also recommend using ipython as it permits an improved interactive environment. If you haven't studied regular-expressions (regex), I would recommend the python regex howto and the book by H.P. Langtangen, "Python Scripting for Computational Science." |
|
February 22, 2012, 16:32 |
typos
|
#6 |
New Member
Gabriele
Join Date: Feb 2012
Posts: 6
Rep Power: 14 |
I found some typos in the python code. The corrected code should be:
Code:
#!/usr/bin/python import pylab 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.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))) pylab.xlabel('time (sec)') pylab.ylabel('force (N)') pylab.grid(True) ##title('Example of using python to parse the force/moment tuples') pylab.plot(t,fpx,'o-') pylab.show() |
|
February 23, 2012, 15:06 |
|
#7 | |
Member
Joe
Join Date: Dec 2011
Location: Groton, CT
Posts: 69
Rep Power: 14 |
Quote:
|
||
July 27, 2013, 15:00 |
|
#8 |
Member
Join Date: May 2010
Posts: 74
Rep Power: 16 |
Thank you very much Malte!! you freed me from huge excel working,
is there some command to read the last row data in one column? because I want to plot the residuals vs time. like plot 'file.dat' using 1$2-last_data_in_column_2), or write command "value=last_data_in_column_2, file.dat" in a script file? every time I have to write "last_data_in_column_2" by hand, this is really boring. thanks you again. Wei |
|
February 15, 2014, 16:00 |
|
#9 |
Senior Member
isabel
Join Date: Apr 2009
Location: Spain
Posts: 171
Rep Power: 17 |
Dear everybody,
I need to represent pressure and viscous forces using gnuplot. This is my forces.dat file: # CofR : (0 0 0) # Time forces(pressure,viscous,porous) moment(pressure,viscous,porous) 1 ((824.789 2197.69 5.61904e-13),(0.00474683 0.000806522 -8.08238e-18),(0 0 0)) ((-54.9423 20.6197 -3230.49),(-2.01631e-05 0.000118671 -0.00011563),(0 0 0)) 2 ((570.161 1591.88 4.32564e-13),(0.0134802 0.00160194 2.91544e-18),(0 0 0)) ((-39.797 14.254 -3401.42),(-4.00486e-05 0.000337004 0.0229561),(0 0 0)) 3 ((-70.8628 -24.5796 5.61076e-14),(0.0221518 0.0019545 2.31609e-18),(0 0 0)) ((0.61449 -1.77157 -2873.97),(-4.88625e-05 0.000553795 0.0440349),(0 0 0)) 4 ((-436.165 -814.382 -2.1011e-13),(0.0287956 0.00371196 -3.41893e-18),(0 0 0)) ((20.3595 -10.9041 -1779.13),(-9.27991e-05 0.00071989 0.0575702),(0 0 0)) 5 ((-337.19 -416.93 -2.2233e-13),(0.0389092 0.00995635 -2.12376e-17),(0 0 0)) ((10.4233 -8.42976 -445.623),(-0.000248909 0.00097273 0.073619),(0 0 0)) .... etcetera (many lines) In order to plot this, I type: plot "./postProcessing/forces/0/forces.dat" using 1:3 with lines title "pressure",\ "./postProcessing/forces/0/forces.dat" using 1:4 with lines title "viscous" And I have this error: plot "./postProcessing/forces/0/forces.dat" using 1:2 with lines title "pressure", "./postProcessing/forces/0/forces.dat" using 1:3 with lines title "viscous" "forces", line 10: warning: Skipping data file with no valid points Nevertheless, if I try using columns 1:3 and 1:4 everything is fine, żis pressure force column 3 and viscous force column 4 or am I wrong? |
|
July 8, 2015, 10:21 |
|
#10 |
Senior Member
Balkrishna Patankar
Join Date: Mar 2009
Location: Pune
Posts: 123
Rep Power: 17 |
Hi Protarius,
The regexp gives empty arrays for my forces.dat file. Is there anyone where I can understand the breakup of the pattern. Thanks, Balkrishna. |
|
July 9, 2015, 04:56 |
|
#11 |
Senior Member
Balkrishna Patankar
Join Date: Mar 2009
Location: Pune
Posts: 123
Rep Power: 17 |
With the way the forces.dat is outputted currently the following code works perfectly for me.
Code:
#!/usr/bin/python import pylab import re #Current Input #1.000000e+00 ((1.460676e+04 -1.948520e+02 9.535164e+02) (2.508036e-02 -6.720399e-05 -3.082446e-04) (0.000000e+00 0.000000e+00 0.000000e+00)) ((1.140514e+04 1.153182e+05 -1.730316e+05) (-3.153913e-03 1.658614e-01 -2.916495e-01\ ) (0.000000e+00 0.000000e+00 0.000000e+00) 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\-+]+)+\)+\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 = []; #Pressure fvx = []; fvy = []; fvz = []; #Viscous fpox = []; fpoy = []; fpoz=[];#Porous mpx = []; mpy = []; mpz = []; #Moment Pressure mvx = []; mvy = []; mvz = []; #Moment Viscous mpox= []; mpoy = [];mpoz = [];#Moment Porous pipefile=open('forces.dat','r') lines = pipefile.readlines() lth=len(lines);print(lth) 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))) fpox.append(float(match.group(8))) fpoy.append(float(match.group(9))) fpoz.append(float(match.group(10))) mpx.append(float(match.group(11))) mpy.append(float(match.group(12))) mpz.append(float(match.group(13))) mvx.append(float(match.group(14))) mvy.append(float(match.group(15))) mvz.append(float(match.group(16))) mpox.append(float(match.group(17))) mpoy.append(float(match.group(18))) mpoz.append(float(match.group(19))) pylab.xlabel('time (sec)') pylab.ylabel('force (N)') pylab.grid(True) #title('Example of using python to parse the force/moment tuples') pylab.plot(t,fpx,'o-') pylab.show() |
|
August 20, 2015, 08:23 |
|
#12 |
Member
Stephanie
Join Date: Feb 2015
Location: Magdeburg, Germany
Posts: 71
Rep Power: 11 |
Helle everyone,
first thank you for the skripts! For me the skript of Gabriele worked wonderful thank you so much! I have small question - in OF I have a deep of 1cm in real it should be 20cm how can I scale the values of forces.dat according to the real deep? Might anyone please give my a hint how I have to modify the python script? I would be very grateful, cos I have no experience with python. Thank you and best regads, Stephie Last edited by stephie; August 20, 2015 at 10:30. |
|
June 19, 2016, 09:23 |
|
#13 |
Member
carno
Join Date: Mar 2009
Posts: 70
Rep Power: 17 |
Just wondering the sign convention in the forces.dat file.
Example: Does +ve sign for moment mean, it is generating moment and vice versa? That means turbines rotor walls patch will have always +ve moments and compressors will have negative moment? Or counterclockwise is positive? Because my fan blades have +ve moment on the relevant axis. |
|
February 2, 2017, 07:50 |
|
#14 |
New Member
Join Date: Oct 2015
Posts: 1
Rep Power: 0 |
Thanks for the hint of using the sed filter in Gnuplot, it works fine!!
|
|
January 11, 2019, 05:44 |
|
#15 |
New Member
Daniel Duque
Join Date: Oct 2018
Posts: 3
Rep Power: 8 |
||
January 16, 2019, 07:44 |
|
#16 |
Senior Member
Nejc
Join Date: Feb 2017
Location: Slovenia
Posts: 196
Rep Power: 9 |
I wrote a few python scripts, if they are of any use to you:
https://damogranlabs.com/2018/09/ope...ing-shortcuts/ |
|
December 17, 2019, 09:26 |
Python 3.7 working version
|
#17 |
Member
Bas Nieuwboer
Join Date: Mar 2013
Posts: 34
Rep Power: 13 |
I was also interested in plotting the forces and came to this tread. For me the method of @balkrishna did not work. It hangs as was mentioned earlier.
I found the work Pete Bechant on github https://gist.github.com/petebachant/6334510 .This was clearly based on this tread, but also did not work for me. However, it was a nice starting point. I distilled the different parts from the code and made a different working regular expression: Code:
import matplotlib.pyplot as plt import re import numpy as np # make regular expressions scalarStr = r"([0-9.eE\-+]+)" vectorStr = r"\(([0-9.eE\-+]+)\s([0-9.eE\-+]+)\s([0-9.eE\-+]+)\)" space = r"\s+" threeVectorStr = r"\({}{}{}{}{}\)".format(vectorStr,space,vectorStr,space,vectorStr) forceRegex = r"{}{}{}{}{}".format(scalarStr,space,threeVectorStr,space,threeVectorStr) t = [] fpx = []; fpy = []; fpz = [] fpox = []; fpoy = []; fpoz = [] fvx = []; fvy = []; fvz = [] mpx = []; mpy = []; mpz = [] mpox = []; mpoy = []; mpoz = [] mvx = []; mvy = []; mvz = [] pipefile = open('./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))) fpox.append(float(match.group(8))) fpoy.append(float(match.group(9))) fpoz.append(float(match.group(10))) mpx.append(float(match.group(11))) mpy.append(float(match.group(12))) mpz.append(float(match.group(13))) mvx.append(float(match.group(14))) mvy.append(float(match.group(15))) mvz.append(float(match.group(16))) mpox.append(float(match.group(17))) mpoy.append(float(match.group(18))) mpoz.append(float(match.group(19))) plt.plot(t,fpz) |
|
Tags |
bracket gnuplot |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
polynomial thermophysical properties II | sebastian | OpenFOAM Running, Solving & CFD | 54 | November 21, 2019 08:12 |
OF 1.6 | Ubuntu 9.10 (64bit) | GLIBCXX_3.4.11 not found | piprus | OpenFOAM Installation | 22 | February 25, 2010 14:43 |
OpenFOAM Install Script | ljsh | OpenFOAM Installation | 82 | October 12, 2009 12:47 |
ParaView Compilation | jakaranda | OpenFOAM Installation | 3 | October 27, 2008 12:46 |
plot in file with journal (text commands) | Asashi | FLUENT | 1 | August 21, 2006 08:08 |