CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > OpenFOAM Programming & Development

Reading values from file

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   February 9, 2015, 13:43
Default Reading values from file
  #1
Senior Member
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Leoben (Austria)
Posts: 1,100
Blog Entries: 6
Rep Power: 19
Tobi will become famous soon enough
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
Hi all,

I want to read a file with FOAM classes. I checked out the boundary condition "timeVaryingMappedFixedValue" but I did not get the point how to read a file and store the values in an array (scalarField etc.)

At the moment I created an IFstream:
Code:
const fileName pathToFile = "foobar";

IFstream foo(pathToFile);
But now I do not know how to read that file.


Thanks in advance
Tobi
__________________
Best regards,
Tobias Holzmann

Some interesting OpenFOAM tutorials and videos on www.Holzmann-cfd.de
Tobi is online now   Reply With Quote

Old   February 9, 2015, 16:43
Default
  #2
Senior Member
 
anonymous
Join Date: Aug 2014
Posts: 177
Rep Power: 3
ssss is on a distinguished road
Dear Tobi,

As I can see in the openfoam code (IFstream.H - .C) there are practically no implemented functions for the IFstream class.

Why don't you use the original ifstream C++ class? You can read everything with it.
ssss is offline   Reply With Quote

Old   February 9, 2015, 17:53
Default
  #3
Senior Member
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Leoben (Austria)
Posts: 1,100
Blog Entries: 6
Rep Power: 19
Tobi will become famous soon enough
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
Because I wanna use FOAM classes
But yes as you told, it seems to be no implementation of functions for that file but it sdhould be possible to do sth. like that.
__________________
Best regards,
Tobias Holzmann

Some interesting OpenFOAM tutorials and videos on www.Holzmann-cfd.de
Tobi is online now   Reply With Quote

Old   February 10, 2015, 04:02
Default
  #4
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,133
Rep Power: 20
alexeym will become famous soon enoughalexeym will become famous soon enough
Hi,

Can you please clarify several moments:

1. You'd like to read values into array (i.e. just a sequence of values) or it should be a Field (i.e. values have spatial variations and linked to the mesh)?

2. You'd like to read ASCII file, binary file?

3. What is wrong with ISstream's read method? http://foam.sourceforge.net/docs/cpp...e693cadb1d0305

4. If I am not mistaken there are also overloaded right shift operators.

4. Finally there is DataEntry class which can read values from OpenFOAM's dictionaries/CSV files. Though in this case it's more complicated as the class adds interpolation.
alexeym is offline   Reply With Quote

Old   February 10, 2015, 04:20
Default
  #5
Senior Member
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Leoben (Austria)
Posts: 1,100
Blog Entries: 6
Rep Power: 19
Tobi will become famous soon enough
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
Hi Alex,

thanks for your replay. Did not know why I am not using ISstream. Yesterday I had a look to Doxygen and get the point that ISstream would be a good class (necessary functions available like getLine() ...).

I will test it today in the evening. At least to your questions:

  • The values are like a list of different scalars like:
Code:
#List which has to be read
#
#
1e4
1e2
0
-1e2
-1e5
-3e5

  • This file is read in ascii format but I also has to read binary files


Thanks in advance,
__________________
Best regards,
Tobias Holzmann

Some interesting OpenFOAM tutorials and videos on www.Holzmann-cfd.de
Tobi is online now   Reply With Quote

Old   February 10, 2015, 05:03
Default
  #6
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,133
Rep Power: 20
alexeym will become famous soon enoughalexeym will become famous soon enough
Hi,

Quote:
Originally Posted by Tobi View Post
thanks for your replay. Did not know why I am not using ISstream. Yesterday I had a look to Doxygen and get the point that ISstream would be a good class (necessary functions available like getLine() ...).
IFstream is a child of ISstream (see inheritance diagram: http://foam.sourceforge.net/docs/cpp/a01016.html), so public method of ISstream are available in IFstream.

In case of ASCII files solution if straightforward, read line, if it is not a comment try to parse number.

In case of binary files everything is a little bit more complicated. Read into char buffer, convert into scalar. Though I'm not quite sure that is not an invention of the wheel.

About timeVaryingMappedFixedValue, list is read during construction of this property of the class:

Code:
autoPtr<DataEntry<Type> > offset_;
and then it is used in the code like this

Code:
offset_->value(t)
but as I said earlier DataEntry assumes value pairs (time, value).
alexeym is offline   Reply With Quote

Old   February 10, 2015, 05:37
Default
  #7
Senior Member
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Leoben (Austria)
Posts: 1,100
Blog Entries: 6
Rep Power: 19
Tobi will become famous soon enough
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
Thank you again.
Well I am stupid because I checked the Doxygen and saw that IFstream is a child of ISstream but in the header I checked the wrong class which has no derivation to ISstream. After your hints I checked it again and now I get the lines:
Code:
   82 class IFstream    83 :
    84     public IFstreamAllocator,
    85     public ISstream
    86 {
So then it should be possible to use IFstream and use the ISstream functionallity. I try it today in the evening.
__________________
Best regards,
Tobias Holzmann

Some interesting OpenFOAM tutorials and videos on www.Holzmann-cfd.de
Tobi is online now   Reply With Quote

Reply

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Patches to compile OpenFOAM 2.2 on Mac OS X gschaider OpenFOAM Installation on Windows, Mac and other Unsupported Platforms 133 December 29, 2014 02:40
Problem compiling a custom Lagrangian library brbbhatti OpenFOAM Programming & Development 2 July 7, 2014 11:32
centOS 5.6 : paraFoam not working yossi OpenFOAM Installation 2 October 9, 2013 01:41
writing execFlowFunctionObjects immortality OpenFOAM Post-Processing 30 September 15, 2013 06:16
Axisymmetrical mesh Rasmus Gjesing (Gjesing) OpenFOAM Native Meshers: blockMesh 10 April 2, 2007 14:00


All times are GMT -4. The time now is 16:25.