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

Reading values from file

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

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 9, 2015, 12:43
Default Reading values from file
  #1
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
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
__________________
Keep foaming,
Tobias Holzmann
Tobi is offline   Reply With Quote

Old   February 9, 2015, 15:43
Default
  #2
Senior Member
 
anonymous
Join Date: Aug 2014
Posts: 205
Rep Power: 12
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, 16:53
Default
  #3
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
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.
__________________
Keep foaming,
Tobias Holzmann
Tobi is offline   Reply With Quote

Old   February 10, 2015, 03:02
Default
  #4
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,930
Rep Power: 38
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
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, 03:20
Default
  #5
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
Hi Alex,

thanks for your reply. Did not know why I am not using ISstream. Yesterday I had a look at Doxygen and got 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,
__________________
Keep foaming,
Tobias Holzmann

Last edited by Tobi; November 23, 2018 at 08:19.
Tobi is offline   Reply With Quote

Old   February 10, 2015, 04:03
Default
  #6
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,930
Rep Power: 38
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
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, 04:37
Default
  #7
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
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.
__________________
Keep foaming,
Tobias Holzmann
Tobi is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
[OpenFOAM.org] Patches to compile OpenFOAM 2.2 on Mac OS X gschaider OpenFOAM Installation 136 October 10, 2017 17:25
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
[blockMesh] Axisymmetrical mesh Rasmus Gjesing (Gjesing) OpenFOAM Meshing & Mesh Conversion 10 April 2, 2007 14:00


All times are GMT -4. The time now is 23:35.