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

Output (scalar) data on secondary logfile

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By Roxxor91

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 4, 2022, 05:38
Post Output (scalar) data on secondary logfile
  #1
New Member
 
Thomas
Join Date: Jul 2018
Posts: 16
Rep Power: 7
Roxxor91 is on a distinguished road
I'd like to output a scalar value (say for example runTime.value()) to a ASCII text file in real time during a simulation.
My current implementation is:

in main solver:
Code:
fileName outputFile(runTime.path()/"log.custom");
OFstream customLog(outputFile);
dimensionedScalar t("t", dimTime, runTime.value());
at every "outputTime":
Code:
customLog << "Time: " << t.value() << endl;
Doing so, the "log.custom" file gets filled with lines of "Time: 0.xxx" and this is fine. However, if I terminate my solver (with CTRL+C, or the "kill" command), or if I monitor the log file (using "tail -f log.custom"), I always see the log file empty UNTIL the end of the simulation.

On the other hand, if I redirect the standard output to a logfile (i.e. mySolverFoam > log.mySolverFoam), I am able to monitor in real time the output.

Any idea how to get my second log to behave like the standard one?
Roxxor91 is offline   Reply With Quote

Old   October 4, 2022, 13:03
Default
  #2
Senior Member
 
Domenico Lahaye
Join Date: Dec 2013
Posts: 736
Blog Entries: 1
Rep Power: 17
dlahaye is on a distinguished road
I wonder whether you need to use something equivalent to flush, see https://cplusplus.com/reference/ostream/flush-free/
dlahaye is offline   Reply With Quote

Old   October 5, 2022, 10:08
Default
  #3
New Member
 
Thomas
Join Date: Jul 2018
Posts: 16
Rep Power: 7
Roxxor91 is on a distinguished road
Quote:
Originally Posted by dlahaye View Post
I wonder whether you need to use something equivalent to flush, see https://cplusplus.com/reference/ostream/flush-free/
Thanks for your suggestion, it works!
I am surprised flush is not implemented in "OFStream"...


Update: After checking the source of OFstream, there is indeed a flush function that can be called as
Code:
 Info << "test" << nl << flush;
Moreover, the newline and flush methods are combined in "endl" as
Code:
 Info << "test" << endl;
After making sure I used "endl", the flushing does happen, and I get what I wanted. So to the ones reading this, it is possible to stick to OpenFOAM's OFstream objects, and the use of "endl" combines a newline with a flush.
dlahaye likes this.

Last edited by Roxxor91; October 6, 2022 at 05:32.
Roxxor91 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
Non uniform temperature gradient Nabeel Abed OpenFOAM Programming & Development 2 August 20, 2019 08:10
UDF value to large for defined data type Anna73 Fluent UDF and Scheme Programming 9 September 30, 2018 22:18
problem during mpi in server: expected Scalar, found on line 0 the word 'nan' muth OpenFOAM Running, Solving & CFD 3 August 27, 2018 04:18
Division by zero exception - loop over scalarField Pat84 OpenFOAM Programming & Development 6 February 18, 2017 05:57
Run OpenFoam in 2 nodes of a cluster WhiteW OpenFOAM Running, Solving & CFD 16 December 20, 2016 00:51


All times are GMT -4. The time now is 15:41.