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

Reading a arbitrary file in OpenFoam

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 9, 2009, 06:11
Default Reading a arbitrary file in OpenFoam
  #1
Senior Member
 
Dr. Fabian Schlegel
Join Date: Apr 2009
Location: Dresden, Germany
Posts: 222
Rep Power: 18
fs82 is on a distinguished road
Hello,

I have to ask a question concerning IO in OpenFoam. I have to "convert" some date to OpenFoam and after thinking a while about the problem I want to do this in a OpenFoam utility. First I thought lets do it in Fortran but the problem of reading the foam mesh comes up and seems to be very time expensive. So now my question:

I already noticed that there is the possibility of reading a arbitrary List of Scalars from a dictionary. But I am not used to C++ so I am not able to understand at the moment what have to be done to read a List from a dictionary. Is there somewhere a tutorial or a simple example like for new turbulence models? May be someone has done this before and commented the code, that I could understand how to adopt this to my problem?

Fabian
fs82 is offline   Reply With Quote

Old   December 10, 2009, 03:41
Default
  #2
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,714
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
There are lots of cases of reading lists from dictionaries, but if you just have lists you'd probably want to read them directly and not via a dictionary.

It would be best if you gave an indication of what you want to read or parse, and then we might be able to provide suggestions.
olesen is offline   Reply With Quote

Old   December 10, 2009, 06:13
Default
  #3
Senior Member
 
Dr. Fabian Schlegel
Join Date: Apr 2009
Location: Dresden, Germany
Posts: 222
Rep Power: 18
fs82 is on a distinguished road
Thx a lot but I think I found a suitable solution for me in plot3dToFoam.C. There is a way presented how to read in coordinates of a simple block structured mesh and this is easy to adopt to read in data on a block structured equally spaced mesh. Thx for your help.

Fabian
fs82 is offline   Reply With Quote

Old   December 10, 2009, 07:47
Default
  #4
Senior Member
 
Dr. Fabian Schlegel
Join Date: Apr 2009
Location: Dresden, Germany
Posts: 222
Rep Power: 18
fs82 is on a distinguished road
Stop I still have a question. I opened my file in the following way:

fileName dataFile(args.additionalArgs()[0]); // set input argument as filename
IFstream dataStream(dataFile);

But after reading I do not need this file anymore so I want to close it. How do I close the file? There is no function available like dataStream.close()?

Fabian
fs82 is offline   Reply With Quote

Old   May 28, 2010, 10:50
Default
  #5
Senior Member
 
Eelco van Vliet
Join Date: Mar 2009
Location: The Netherlands
Posts: 124
Rep Power: 19
eelcovv is on a distinguished road
Hi Fabian,

I am trying to achieve more or less the same: I want to import an external data field with columns of x y z data and interpolate that on a openFoam field. Preferably with an utility that then writes the new openfoam field to the 0 directory
Have you achieved already what wanted? Perhaps I can use it as well
Thanks
Regards,

Eelco
eelcovv is offline   Reply With Quote

Old   May 28, 2010, 11:35
Default
  #6
Senior Member
 
Ben K
Join Date: Feb 2010
Location: Ottawa, Canada
Posts: 140
Rep Power: 19
benk is on a distinguished road
I also am interersted in this since I need to import data into OpenFOAM for interpolation purposes.

In my case I have experimental data that describes how a diffusion coefficient changes with concentration and temperature. My model solves for both concentration and temperature and so I'd like to be able to import this diffusion data into OpenFOAM and then interpolate in two directions, concentration first and then temperature.
benk is offline   Reply With Quote

Old   May 31, 2010, 03:57
Default
  #7
Senior Member
 
Dr. Fabian Schlegel
Join Date: Apr 2009
Location: Dresden, Germany
Posts: 222
Rep Power: 18
fs82 is on a distinguished road
Hello Guys,

I used the foam Utility plot3dToFoam as an example. I do not use any interpolation because I only read in a scalar which is than averaged over a range of foam cells. So my problem was to find an efficient routine to search for cells on the OpenFoam mesh. But there are ways to interpolate between different meshes in OpenFoam. Please search the forum for this purpose, I am sure you will find something.

kind regards,
Fabian
fs82 is offline   Reply With Quote

Old   June 4, 2010, 08:36
Default source code
  #8
Senior Member
 
Eelco van Vliet
Join Date: Mar 2009
Location: The Netherlands
Posts: 124
Rep Power: 19
eelcovv is on a distinguished road
Hi Fabian,

I am not really experienced in C++ programming. I can understand what happens in Plot3dToFoam, but in this program a plot3d mesh is read and a new mesh is created based on the plot3d mesh.
In my case I want to read the plot3d data (also on a regular grid), but then map the plot3d data on the existing openfoam grid data. Is your code something simular to this ? Would it be possible to post your source so I can use this as an example for my problem?

Regards,

Eelco
eelcovv is offline   Reply With Quote

Old   June 4, 2010, 10:43
Default
  #9
Senior Member
 
Dr. Fabian Schlegel
Join Date: Apr 2009
Location: Dresden, Germany
Posts: 222
Rep Power: 18
fs82 is on a distinguished road
I am sorry but I will not post my source code because it includes many ideas not published up to now and therefore it is still top secret :-D But as I mentioned before my solution seems to be not suitable for you because my mapping scheme is a simple averaging.
I would suggest as a first simple idea to create a mesh for OpenFOAM which has the same regular grid like the data you want to import (use blockmesh oder gambit). Than have a look to plot3dToFoam and read in your datafile together with the created foam mesh. Than loop over all foam cells and find the related point of your data. After you have done so write the created field and use mapFields to map this mesh to your desired simulation mesh. This is not easy to achieve even if you have no real experience in C++ but I am not an C++ expert too. I started learning it last year and with the help of this forum an the dokumentation site of OpenFOAM it was feasible for me and therefore it should be feasible to you too :-D

regards,
Fabian
fs82 is offline   Reply With Quote

Reply


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
problem when converting mesh (made by ICEM) using fluentMeshToFoam Forrest_Lei OpenFOAM 11 October 16, 2009 07:28
Regarding FoamX running Kindly help out hariya03 OpenFOAM Pre-Processing 0 April 18, 2008 05:26
Problem with rhoSimpleFoam matteo_gautero OpenFOAM Running, Solving & CFD 0 February 28, 2008 07:51
gcc and executable file from Mac to Linux simone Marras Main CFD Forum 0 April 8, 2007 16:49
Results saving in CFD hawk Main CFD Forum 16 July 21, 2005 21:51


All times are GMT -4. The time now is 20:48.