|
[Sponsors] |
Cannot read 2nd column of data in libforces.so output force.dat file |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
September 1, 2013, 01:39 |
Cannot read 2nd column of data in libforces.so output force.dat file
|
#1 |
Senior Member
musaddeque hossein
Join Date: Mar 2009
Posts: 309
Rep Power: 18 |
Dear all:
I am using libforces.so in control dict. The output is forces.dat file and has the following format: time ((number, number, numer), (number ...etc) the problem is that there is NO spaces between the first pair of parenthesis and the number right after it. As a result, that number cannot be read as a number but has to be read as character. I have a FORTRAN code that reads this file, and I found that it was not possible to read the first number after the double parenthesis as a real. So my only option is to read it as character - which makes this data useless. Can the OpenFOAM creators please rewrite the code so that there is space between the number and the parenthesis?. Also, would it be possible to include the number of lines of data in the file in the first line? something like this: # Time forces((.....)) moment ((......)) lines of data (......) Thanks. Thanks. |
|
September 1, 2013, 07:57 |
|
#2 |
Retired Super Moderator
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,981
Blog Entries: 45
Rep Power: 128 |
Hi Musaddeque,
Why should the developers change the source code, when it works fine as it is? Specially when it is formatted in a way that OpenFOAM itself can easily re-read the data back into memory! Nonetheless, what you might want to ask for is for a way to choose other output formats for the forces function object. Either way, there are several ways you can fix this problem on your side! Some examples:
Bruno
__________________
|
|
September 1, 2013, 08:49 |
|
#3 |
Senior Member
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,903
Rep Power: 37 |
Hi Musaddeque,
Please read and follow the detailed step-by-step guide, which I wrote a couple of weeks ago in this thread: http://www.cfd-online.com/Forums/ope...utput-csv.html Kind regards Niels
__________________
Please note that I do not use the Friend-feature, so do not be offended, if I do not accept a request. |
|
September 1, 2013, 11:58 |
|
#4 | |
Senior Member
musaddeque hossein
Join Date: Mar 2009
Posts: 309
Rep Power: 18 |
Quote:
# Time forces(pressure, viscous, porous) moment(pressure, viscous, porous) 0.00116279 ((0 65.2165 0),(-1.20232e-17 0.00107097 5.21998e-07),(0 0 0)) ((15.435 0 0),(0.000198423 2.02581e-17 8.3249e-17),(0 0 0)) 0.00251938 ((0 86.7929 0),(-1.10799e-16 0.00264427 1.61168e-06),(0 0 0)) ((20.5327 0 0),(0.000532886 -2.13627e-17 -1.9528e-16),(0 0 0)) 0.00410207 ((0 30.7788 0),(-1.1e-16 0.00314398 4.56226e-06),(0 0 0)) ((7.26688 0 0),(0.000714734 -5.21951e-17 6.56713e-17),(0 0 0)) 0.00593798 ((0 -34.7985 0),(-8.21523e-17 0.00205407 -1.62991e-06),(0 0 0)) ((-8.2514 0 0),(0.000595282 -1.95364e-17 -1.90247e-17),(0 0 0)) Now observe the second line: 0.00116279 ((0 65.2165 0), ..... I am using fortran read command as follows: read(......) time, char, char, forceX, forceY, forceZ etc.. Fortran hangs at char, as it cannot distinguish between the "((" and the "0" right after it and gives an error saying bad real number. So now, if I revise the read statement as: read(...) time, char, forceY, forceZ, --- in other words treat "((0" as a char, then fortran will read it as char and move the the next number. I agree that scripts can be written to remove the parenthesis, but it does not permit an elegant solution. At the programming time, all the programmer would have had to do was to add a few spaces between the parenthesis, and between the parenthesis and the number. |
||
September 1, 2013, 14:07 |
|
#5 |
Retired Super Moderator
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,981
Blog Entries: 45
Rep Power: 128 |
Hi Musaddeque,
Well... I had to smile a bit now... I remembered to search in the official bug tracker for OpenFOAM and found this feature request: http://www.openfoam.org/mantisbt/view.php?id=777 I found it by searching in Google with: Code:
site:www.openfoam.org/mantisbt forces output Now, as for the problem you have at the moment, the big question is: how do you want to solve this? I ask this because:
Bruno
__________________
|
|
September 2, 2013, 10:08 |
fortran read of force.dat file
|
#6 |
Senior Member
musaddeque hossein
Join Date: Mar 2009
Posts: 309
Rep Power: 18 |
This is what I wrote to read the lines of data. I am only interested in the x y z forces, so my read line in fortran was as follows:
character(len=20):: charA, double precision::time, force_x, force_y, force_z read(unit=unit_force_dat,fmt=*) do i=1,num_dat read(unit=unit_force_dat,fmt=*) time, charA, force_y write(fout_gplt,100) time*3.13029, force_y/9810.0 end do Now note the data is out put in the following format (skipping the first line): 0.1 ((0 -5.06121 0),(-3.99743e-17 -0.00915985 -0.00028693),(0 0 0)) ((-0.801432 0 0),(-0.0036854 -3.35203e-18 2.30784e-17),(0 0 0)) 0.2 ((0 19.0264 0),(1.57733e-17 0.00228343 -0.000354185),(0 0 0)) ((4.92259 0 0),(0.0023383 7.10629e-18 1.67709e-18),(0 0 0)) 0.3 ((0 11.5462 0),(-7.85821e-18 0.00388275 -0.000954584),(0 0 0)) ((2.82873 0 0),(0.00702285 -4.54422e-18 -1.1446e-18),(0 0 0)) So starting from the left, there is one real number, followed by space, then two parenthesis and then three real numbers. So my read statement should be: read (...) time, charA, charB, forceX, forceY, forceZ But it seems that the real number after the second parenthesis is so close, that fortran gives a "bad real number" error if I use this format. So the "workaround" that I have is to treat the ((0 as char and then read forceY. Perhaps you may have a better suggestion. Thanks Musa |
|
September 7, 2013, 12:02 |
|
#7 |
Retired Super Moderator
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,981
Blog Entries: 45
Rep Power: 128 |
Hi Musaddeque,
I forgot that I haven't actually seriously programmed in FORTRAN for several years now... I'm getting old . Attached is a zip file that demonstrates how you can filter out the stuff you don't need from each line. Since you didn't specify any compiler limitations, nor did you specify the FOTRAN standard, I simply used the one I'm familiar with. To detail some of the aspects to this:
Bruno
__________________
|
|
September 8, 2013, 12:44 |
|
#8 |
Senior Member
musaddeque hossein
Join Date: Mar 2009
Posts: 309
Rep Power: 18 |
very clever! thanks.
|
|
February 21, 2015, 23:08 |
reading force data from interDyMFOAM
|
#9 | |
Senior Member
musaddeque hossein
Join Date: Mar 2009
Posts: 309
Rep Power: 18 |
Quote:
Your test file has space after the first real data and before the parenthesis. However the output from OpenFOAM has a tab. And this tab I cannot overcome! I look forward to your reply |
||
February 21, 2015, 23:43 |
|
#10 | |
Senior Member
musaddeque hossein
Join Date: Mar 2009
Posts: 309
Rep Power: 18 |
Quote:
Sorry for the false alarm. The code works. I randomly put tabs and the code ignored them and got the results. I tell you, if a movie was ever made about the gods of CFD, you would be the one and only star!. Thanks again for your help! |
||
Tags |
force.dat, interdymfoam, libforces.so, sloshingtank2d |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[Other] mesh airfoil NACA0012 | anand_30 | OpenFOAM Meshing & Mesh Conversion | 13 | March 7, 2022 18:22 |
what is swap4foam ?? | AB08 | OpenFOAM | 28 | February 2, 2016 02:22 |
[Commercial meshers] fluentMeshToFoam multidomain mesh conversion problem | Attesz | OpenFOAM Meshing & Mesh Conversion | 12 | May 2, 2013 11:52 |
"parabolicVelocity" in OpenFoam 2.1.0 ? | sawyer86 | OpenFOAM Running, Solving & CFD | 21 | February 7, 2012 12:44 |
DxFoam reader update | hjasak | OpenFOAM Post-Processing | 69 | April 24, 2008 02:24 |