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

Control over Info variable

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

Reply
 
LinkBack Thread Tools Display Modes
Old   May 22, 2013, 10:03
Default Control over Info variable
  #1
New Member
 
Madeleine P. Vincent
Join Date: May 2011
Posts: 28
Rep Power: 6
Madeleine P. Vincent is on a distinguished road
Hi all,

I am adapting OpenFOAM, and I'd like to have control over the Info variable. I'd like to redirect the output to another stream (something other than cout -- a stream that will be created at run time after the global Info variable has been created).

Is this possible?

Regards,
Maddie.
Madeleine P. Vincent is offline   Reply With Quote

Old   May 22, 2013, 10:12
Default
  #2
ngj
Senior Member
 
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Rotterdam, The Netherlands
Posts: 1,593
Rep Power: 24
ngj will become famous soon enoughngj will become famous soon enough
Hi Madeleine,

Is what you want to write to a file?

Kind regards

Niels
ngj is offline   Reply With Quote

Old   May 22, 2013, 11:20
Default
  #3
New Member
 
Madeleine P. Vincent
Join Date: May 2011
Posts: 28
Rep Power: 6
Madeleine P. Vincent is on a distinguished road
Quote:
Originally Posted by ngj View Post
Hi Madeleine,

Is what you want to write to a file?

Kind regards

Niels
Niels,

Yes, I have a file stream that I'm using for logging. It will include a bit more info than what is being sent to Info. But yes, in general, a file stream.
Madeleine P. Vincent is offline   Reply With Quote

Old   May 22, 2013, 12:25
Default
  #4
ngj
Senior Member
 
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Rotterdam, The Netherlands
Posts: 1,593
Rep Power: 24
ngj will become famous soon enoughngj will become famous soon enough
Hi Madeleine,

You can use the standard file streams from C++ or the Ostream class in OpenFoam. The latter has slightly fewer functionalities in some versions than the C++ standard, i.e. I could not get the append functionality to work.

Kind regards

Niels
ngj is offline   Reply With Quote

Old   May 22, 2013, 13:15
Default
  #5
New Member
 
Madeleine P. Vincent
Join Date: May 2011
Posts: 28
Rep Power: 6
Madeleine P. Vincent is on a distinguished road
Quote:
Originally Posted by ngj View Post
Hi Madeleine,

You can use the standard file streams from C++ or the Ostream class in OpenFoam. The latter has slightly fewer functionalities in some versions than the C++ standard, i.e. I could not get the append functionality to work.

Kind regards

Niels

Niels,

but the Info object is global and created automatically. It is then used throughout the code. I'm trying to minimize any changes to the OpenFOAM files.

So, can I stop the OpenFOAM version of Info being created, and create my own instead? Where would that take place?

Or can I "reset" Info (or the underlying stream) to be my stream?

Thanks for your help.

Madeleine.
Madeleine P. Vincent is offline   Reply With Quote

Old   May 22, 2013, 17:03
Default
  #6
ngj
Senior Member
 
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Rotterdam, The Netherlands
Posts: 1,593
Rep Power: 24
ngj will become famous soon enoughngj will become famous soon enough
So what you are saying is that you want to make all standard output stream go to a file instead of going to the screen?

Then I suggest that you do something like this in the command line, when you are running your solver:

Code:
mySolverName > log.run 2> log.err
where the file "log.run" will contain all standard output, while "log.err" will contain all error messages. In this way you do not need to change anything within OF.

Afterward, you can do a lot of text string manipulations to the log-files, if you are interested in specific parts of the log file, e.g. time step as a function of simulated time. Here, the most straight forward would be to use bash scripting with the use of the "sed" and "awk" commands; other users would probably recommend Python.

Kind regards

Niels
ngj is offline   Reply With Quote

Old   May 22, 2013, 18:09
Default
  #7
New Member
 
Madeleine P. Vincent
Join Date: May 2011
Posts: 28
Rep Power: 6
Madeleine P. Vincent is on a distinguished road
Quote:
Originally Posted by ngj View Post
So what you are saying is that you want to make all standard output stream go to a file instead of going to the screen?

Then I suggest that you do something like this in the command line, when you are running your solver:

Code:
mySolverName > log.run 2> log.err
where the file "log.run" will contain all standard output, while "log.err" will contain all error messages. In this way you do not need to change anything within OF.

Afterward, you can do a lot of text string manipulations to the log-files, if you are interested in specific parts of the log file, e.g. time step as a function of simulated time. Here, the most straight forward would be to use bash scripting with the use of the "sed" and "awk" commands; other users would probably recommend Python.

Kind regards

Niels

Hi Niels,

yes, I want to make all standard output go to my stream (which has other data coming into, as I'm coupling OpenFOAM with another app). And that stream might Tee out to cout as well - or not, but that's a run-time decision.

However, your solution is not what I'm looking for. I want to combine the OpenFOAM output with other output, and not be restricted to sending it all to cout (or the Info object).

It appears that there isn't an easy (non-invasive) way.

That's really the unfortunate truth of global variables. The have a bad reputation for a reason.

Thanks for your help. I appreciate it.

Madeleine.
Madeleine P. Vincent is offline   Reply With Quote

Old   May 23, 2013, 02:55
Default
  #8
ngj
Senior Member
 
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Rotterdam, The Netherlands
Posts: 1,593
Rep Power: 24
ngj will become famous soon enoughngj will become famous soon enough
Good morning Madeleine,

Let me just address this small comment:

Quote:
Originally Posted by Madeleine P. Vincent View Post
That's really the unfortunate truth of global variables. The have a bad reputation for a reason.
I have been Googling what the std::cout actually is (which Info is related to), and it is an object, not a global variable. At the time of implementation it is the programmers choice, which stream procedure to use, and Info is an obvious choice for many things, because it is overloaded to such an extend that you can almost pass anything and the user will not have to specify a path to a file.

I really do not understand what you want to accomplish in terms of functionality and why the simple ">" operator in the command line does not cover your needs (combined with additional text string manipulation). Instead of changing the basic behaviour of Info, I would strongly encourage you to rethink your strategy.

Kind regards

Niels
ngj is offline   Reply With Quote

Old   May 23, 2013, 05:07
Default
  #9
New Member
 
Madeleine P. Vincent
Join Date: May 2011
Posts: 28
Rep Power: 6
Madeleine P. Vincent is on a distinguished road
Good morning to you Niels,

Well, admittedly, my case is a bit special (different), and so that's why it doesn't fit neatly into the OpenFOAM "way".

Quote:
Originally Posted by ngj View Post
I really do not understand what you want to accomplish in terms of functionality and why the simple ">" operator in the command line does not cover your needs (combined with additional text string manipulation). Instead of changing the basic behaviour of Info, I would strongly encourage you to rethink your strategy.
Let me describe in a bit more detail. I am coupling 2 physics, one that uses an OpenFOAM solver, and another that is a separate software package. I am compiling both into one executable.

The other solver also has a "global" type of output, similar to Info. In my discussions with them, I am running up against the same issue - "why not just do it our way?"

Well, what I'd like is to have output from the each solver go to its own log stream (usually a file stream, but in general it could be any stream). And output from the coupling algorithm (that I am writing) go to its own stream. Finally, a minimum of output (for example, current step number, basic convergence criteria) to the std::cout. In this way, I can monitor the program easily, and keep all the output separate (in 3 files) and where it needs to be.

Using > will just throw all output into one file, which is a mess. Yes, grep / sed / awking is possible. But it seems a kludge to me (developing a bunch of regular expressions). It's an extra step. What happens when the output format of either of the 2 solvers changes? The regex must be re-developed. Dealing with dedicated streams and logs is cleaner - it is the "correct" way to handle the issue.

In addition, I want to have a minimum amount of info going to cout to know that things are still on track. Using tail would work, but again, only sort of. It's kludge to tail a massive log file, trying to make sense of the output from 2 solvers and a coupling algorithm. It's also an extra step.

So, maybe I'm trying too hard to be perfectionist, but those are my reasons.

OpenFOAM makes it a point to not be "an application", but to be a series of tools and libraries. But then they go define a global Info variable and use it in different parts of the code, which makes it tough for me to do exactly what I want.

Thanks for listening.

Madeleine.
Madeleine P. Vincent is offline   Reply With Quote

Old   May 23, 2013, 05:55
Default
  #10
ngj
Senior Member
 
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Rotterdam, The Netherlands
Posts: 1,593
Rep Power: 24
ngj will become famous soon enoughngj will become famous soon enough
Hi Madeleine,

I see what you are trying to accomplish. I have been digging around in the source code to figure out where Info is actually defined. I have found something in the file

Code:
src/OpenFoam/db/error/messageStream.C
where it reads (OF-1.6-ext):

Code:
// Global messageStream definitions

Foam::messageStream Foam::SeriousError
(
    "--> FOAM Serious Error : ",
    messageStream::SERIOUS,
    100
);

Foam::messageStream Foam::Warning
(
    "--> FOAM Warning : ",
    messageStream::WARNING
);

Foam::messageStream Foam::Info("", messageStream::INFO);
and I wonder that if you change the last line to something like

Code:
Foam::messageStream Foam::Info("OF: ", messageStream::INFO);
would give you a really nice term in the beginning of each line that you can use in some regular expressions, such as

Code:
grep "^OF: " log.run > log.run.of
It is still a bit of an additional step in terms of processing, but it will make the script used for splitting the log file considerably easier.

Disclaimer: I have not tried to compile the above suggestion, but it should work.

Kind regards

Niels
ngj is offline   Reply With Quote

Old   May 23, 2013, 07:48
Default
  #11
New Member
 
Madeleine P. Vincent
Join Date: May 2011
Posts: 28
Rep Power: 6
Madeleine P. Vincent is on a distinguished road
Niels,

thanks for the information.

If I am going to change messageStream and recompile (which is what I really wanted to avoid), then I would consider making Info a variable of my own type that I could do what I wanted with (i.e., reset the underlying stream, avoid outputting to cout, etc.)

So I'll have to think about what I want to do before investing a bunch of time.

I may end up using the redirect of global cout to a file in the end... even if it's not exactly what I wanted.

Thanks again for your input.

Madeleine.
Madeleine P. Vincent is offline   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
emag beta feature: charge density charlotte CFX 4 March 22, 2011 10:14
error in COMSOL:'ERROR:6164 Duplicate Variable' bhushas Main CFD Forum 1 May 30, 2008 04:35
OpenFOAM with Cygwin kitchener OpenFOAM Installation 6 April 24, 2006 23:09
Env variable not set gruber2 OpenFOAM Installation 5 December 30, 2005 05:27
Replace periodic by inlet-outlet pair lego CFX 3 November 5, 2002 21:09


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