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

How can I load a file.txt in OpenFoam?

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

Like Tree3Likes
  • 1 Post By Marco_poli
  • 1 Post By JimKnopf
  • 1 Post By stanweer

Reply
 
LinkBack Thread Tools Display Modes
Old   May 24, 2012, 15:59
Default How can I load a file.txt in OpenFoam?
  #1
New Member
 
Join Date: May 2012
Posts: 2
Rep Power: 0
Marco_poli is on a distinguished road
Hello,

I have a table containing the y+ u+ k+ and omega+ values for the kOmegaSST turbulence model and this table is stored in a txt file.
I want to modify the kOmegaSST.C and kOmegaSST.H to be able to load this file in the model (for example in a matrix) and take these values if need them. I'm studing a new way to impose the boundary condition but I'm quite new in programming in OpenFoam.
My main questions are:
-How could I initialize a matrix of scalar values?
-How could I load the file.txt and put its values in the matrix?
Any suggestions will be appreciate

Thank you very much
Best regards
Marco
hua1015 likes this.
Marco_poli is offline   Reply With Quote

Old   May 25, 2012, 04:47
Default
  #2
Member
 
Jim Knopf
Join Date: Dec 2010
Posts: 60
Rep Power: 9
JimKnopf is on a distinguished road
File reading:

you can use<fstream> to read in files, like in standard c++

string line;ifstream myfile ("example.txt");
getline (myfile,line);

than convert to what ever you have.

Matrix of scalar values:

What exactly is it you expect to have? A scalarField, like p or a vector field like u?
Or a Matrix of size nxm?

Best Regards,
Jim
mm.abdollahzadeh likes this.
JimKnopf is offline   Reply With Quote

Old   May 26, 2012, 09:17
Default
  #3
New Member
 
Join Date: May 2012
Posts: 2
Rep Power: 0
Marco_poli is on a distinguished road
Thank you very much Jim!

Finally I solve the problem using IFstream as you suggest:

RectangularMatrix<doubleScalar> TABLE(IFstream("table.txt")());

that save the table in a matrix.
If someone is interested the file table.txt must have this shape

2 3
(
( 1 2 3)
( 4 5 6)
)

where in the first line 2 is the number of rows and 3 is the number of columns.
In this way we store the following matrix

[ 1 2 3
4 5 6]

Best Regards
Marco
Marco_poli is offline   Reply With Quote

Old   September 13, 2016, 10:24
Default
  #4
New Member
 
Akash
Join Date: Jun 2014
Location: Oslo
Posts: 29
Rep Power: 5
pakanatiakash is on a distinguished road
Hi

I guess its an old post but I thought its worth asking. I am also in the same situation where I need to read values from tables and use them in solving my equations.

I have a 2x2 matrix -

2 2
(
(-0.01 1.0e10)
(-0.005 8.e10)
);

I read it by following the same routine -

RectangularMatrix<doubleScalar>NucTuc(IFstream("co nstant/innocValues")());

NucTuc is my matrix. Now the question is, after reading the table, how can i access each value. For example I want to access the value -0.01 which is located in 1x1 position, how do I do it?

Thanks!

Akash
pakanatiakash is offline   Reply With Quote

Old   May 10, 2017, 07:24
Default
  #5
New Member
 
Simone Colucci
Join Date: Mar 2016
Location: Pisa (Italy)
Posts: 23
Rep Power: 3
S.Colucci is on a distinguished road
Hi Akash,
did you find a solution to get the values from a RectangularMatrix?
Thanks
Simone
S.Colucci is offline   Reply With Quote

Old   December 21, 2017, 05:59
Default
  #6
New Member
 
shayan tanweer
Join Date: Oct 2016
Location: DELHI,INDIA
Posts: 3
Rep Power: 3
stanweer is on a distinguished road
You can access the element -0.01 as:
NucTuc(0,0);
stanweer is online now   Reply With Quote

Old   January 31, 2018, 23:34
Default
  #7
Senior Member
 
Join Date: Aug 2013
Posts: 333
Rep Power: 7
Antimony is on a distinguished road
Hi,

Just to add on to the last post. I don't think NucTuc(0,0) works. What worked for me was NucTuc[0][0] - the standard C++ way to traverse array/matrices.

Hope this helps.

Cheers,
Antimony
Antimony is offline   Reply With Quote

Old   February 1, 2018, 08:19
Default
  #8
New Member
 
shayan tanweer
Join Date: Oct 2016
Location: DELHI,INDIA
Posts: 3
Rep Power: 3
stanweer is on a distinguished road
Hi Antimony,
I am using OpenFOAM 4.1 and in my case NucTuc(0,0) works perfectly.

best regards,
Shayan Tanweer
Antimony likes this.
stanweer 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
Compiling OpenFOAM on hpc-fe.gbar.dtu.dk kaergaard OpenFOAM Installation 1 June 16, 2011 01:33
createPatch / cyclicGgi / OpenFoam 1.5-dev OFU OpenFOAM Meshing & Mesh Conversion 0 June 16, 2010 04:36
64bitrhel5 OF installation instructions mirko OpenFOAM Installation 2 August 12, 2008 18:07
Adventure of fisrst openfoam installation on Ubuntu 710 jussi OpenFOAM Installation 0 April 24, 2008 14:25
OpenFOAM Training and Workshop Zagreb 2628Jan2006 hjasak OpenFOAM 1 February 2, 2006 22:07


All times are GMT -4. The time now is 10:09.