|
[Sponsors] |
February 9, 2015, 12:43 |
Reading values from file
|
#1 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51 |
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); Thanks in advance Tobi
__________________
Keep foaming, Tobias Holzmann |
|
February 9, 2015, 15:43 |
|
#2 |
Senior Member
anonymous
Join Date: Aug 2014
Posts: 205
Rep Power: 12 |
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. |
|
February 9, 2015, 16:53 |
|
#3 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51 |
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 |
|
February 10, 2015, 03:02 |
|
#4 |
Senior Member
|
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. |
|
February 10, 2015, 03:20 |
|
#5 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51 |
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:
Code:
#List which has to be read # # 1e4 1e2 0 -1e2 -1e5 -3e5
Thanks in advance,
__________________
Keep foaming, Tobias Holzmann Last edited by Tobi; November 23, 2018 at 08:19. |
|
February 10, 2015, 04:03 |
|
#6 | |
Senior Member
|
Hi,
Quote:
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_; Code:
offset_->value(t) |
||
February 10, 2015, 04:37 |
|
#7 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51 |
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 {
__________________
Keep foaming, Tobias Holzmann |
|
|
|
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 |