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

Writing scalar to file

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 11, 2010, 08:19
Default Writing scalar to file
  #1
New Member
 
Join Date: Aug 2010
Posts: 6
Rep Power: 16
Tobb is on a distinguished road
Hello everybody!

I think I got a comparatively easy problem, but I can't find a solution.

I have a program that calculates the power inserted by an impeller for every time step. But at the moment the value is just displayed bei "Info <<...... " on the screen. I'd like to write it into a file as kind of a list, with the time and the corresponding power value, so that I can easily plot it with gnuplot.

I tried something with a IOdictionary but did'nt get very far. And I don't really know how to handle the list class.

I would be glad if someone could tell me some details oder just show me where I can find an introduction of that topic.

Thank you!
Tobb
Tobb is offline   Reply With Quote

Old   November 11, 2010, 08:51
Default
  #2
Senior Member
 
Laurence R. McGlashan
Join Date: Mar 2009
Posts: 370
Rep Power: 23
l_r_mcglashan will become famous soon enough
To be honest, if you just want a file with 2 columns (Time and power), just use the standard library. Change Info to a file, so something like:

Code:
    std::ofstream file("results.txt");
    file << Time[i] << " " << Power[i] << std::endl;
    file.close();
Where I've assumed Time and Power are lists.
__________________
Laurence R. McGlashan :: Website
l_r_mcglashan is offline   Reply With Quote

Old   November 11, 2010, 09:39
Default
  #3
New Member
 
Join Date: Aug 2010
Posts: 6
Rep Power: 16
Tobb is on a distinguished road
First of all thank you for your answer. But if I got you right, you basically told me how to merge two existing lists into one file.

So I think I have to be more precise. My routine is built as a loop. It reads in the velocity field, calculates the power (using rho, nu and the gradient of U) and than moves on to the next time directory. So I actually don't have any time or power list.

My aim is to add the current time and the corresponding power value to a file after each loop. So the list or the file where the data should be stored doesn't exist right from the start. I have to create it either before starting my program or implement the construction once right at the beginning of the code and than add every entry step by step.

But the construction of a such a list as well as writing data to a file are things I haven't really done before.
I hope I managed to make things clearer now.

Thank you in advance!
Tobb
Tobb is offline   Reply With Quote

Old   November 11, 2010, 09:58
Default
  #4
Senior Member
 
Nima Samkhaniani
Join Date: Sep 2009
Location: Tehran, Iran
Posts: 1,267
Blog Entries: 1
Rep Power: 25
nimasam is on a distinguished road
u can use Info, but save the result in a log file

solver > log

then use foamlog ofcourse you should add new written variable in foamLog data base
so i suggest : search for foamlog
nimasam is offline   Reply With Quote

Old   November 19, 2010, 08:38
Default
  #5
Senior Member
 
Francois
Join Date: Jun 2010
Posts: 107
Rep Power: 21
Fransje will become famous soon enough
Hi Tobb!

If you want a file with only two columns, you could use the makeGraph function! You can specify:
Code:
makeGraph(Time, Power, "Your_Name", path, graphFormat);
And this will create a file Your_name.xy at every timestep, in the timestep directory. If you make sure your Time and Power variable can be stored during the whole run, you might be able to call makeGraph only for the final timestep, and let it print out the two lists in one file instead of at every timestep.

The format can be obtained from your runTime object with the command:
Code:
const word& graphFormat = runTime.graphFormat();
The path can be asked from one of your variables, for instance with:
Code:
U.path();
Good luck!

Kind regards,

Francois.
Fransje is offline   Reply With Quote

Old   November 19, 2010, 12:55
Default
  #6
New Member
 
Join Date: Aug 2010
Posts: 6
Rep Power: 16
Tobb is on a distinguished road
Thank you very much for your hint!
It sounds like this could be what I was looking for. I will try it out after the weekend and let you know whether I was successful or not.
Tobb is offline   Reply With Quote

Old   December 1, 2010, 17:19
Default
  #7
Senior Member
 
Francois
Join Date: Jun 2010
Posts: 107
Rep Power: 21
Fransje will become famous soon enough
You can also replace the graphFormat option directly by (keep the quotes):
  • "raw" -> giving raw xy graph outputs in .xy files.
  • "gnuplot" -> giving gnuplot compatible .gplt files.
  • "jplot" -> giving jplot .dat files.
  • "xmgr" -> giving xmgrace compatible .agr files.

Kind regards,

François.
Fransje 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
[swak4Foam] GroovyBC the dynamic cousin of funkySetFields that lives on the suburb of the mesh gschaider OpenFOAM Community Contributions 300 October 29, 2014 19:00
OpenFOAM Install Script ljsh OpenFOAM Installation 82 October 12, 2009 12:47
DxFoam reader update hjasak OpenFOAM Post-Processing 69 April 24, 2008 02:24
Problem with rhoSimpleFoam matteo_gautero OpenFOAM Running, Solving & CFD 0 February 28, 2008 07:51
Problems With Journal When Writing Forces To File Andrew FLUENT 2 September 23, 2005 03:12


All times are GMT -4. The time now is 02:22.