|
[Sponsors] |
May 22, 2013, 11:03 |
Control over Info variable
|
#1 |
New Member
Madeleine P. Vincent
Join Date: May 2011
Posts: 29
Rep Power: 14 |
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. |
|
May 22, 2013, 11:12 |
|
#2 |
Senior Member
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,900
Rep Power: 37 |
Hi Madeleine,
Is what you want to write to a file? Kind regards Niels |
|
May 22, 2013, 12:20 |
|
#3 |
New Member
Madeleine P. Vincent
Join Date: May 2011
Posts: 29
Rep Power: 14 |
||
May 22, 2013, 13:25 |
|
#4 |
Senior Member
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,900
Rep Power: 37 |
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 |
|
May 22, 2013, 14:15 |
|
#5 | |
New Member
Madeleine P. Vincent
Join Date: May 2011
Posts: 29
Rep Power: 14 |
Quote:
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. |
||
May 22, 2013, 18:03 |
|
#6 |
Senior Member
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,900
Rep Power: 37 |
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 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 |
|
May 22, 2013, 19:09 |
|
#7 | |
New Member
Madeleine P. Vincent
Join Date: May 2011
Posts: 29
Rep Power: 14 |
Quote:
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. |
||
May 23, 2013, 03:55 |
|
#8 | |
Senior Member
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,900
Rep Power: 37 |
Good morning Madeleine,
Let me just address this small comment: Quote:
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 |
||
May 23, 2013, 06:07 |
|
#9 | |
New Member
Madeleine P. Vincent
Join Date: May 2011
Posts: 29
Rep Power: 14 |
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:
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. |
||
May 23, 2013, 06:55 |
|
#10 |
Senior Member
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,900
Rep Power: 37 |
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 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); Code:
Foam::messageStream Foam::Info("OF: ", messageStream::INFO); Code:
grep "^OF: " log.run > log.run.of Disclaimer: I have not tried to compile the above suggestion, but it should work. Kind regards Niels |
|
May 23, 2013, 08:48 |
|
#11 |
New Member
Madeleine P. Vincent
Join Date: May 2011
Posts: 29
Rep Power: 14 |
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. |
|
Thread Tools | Search this Thread |
Display Modes | |
|
|
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 | COMSOL | 1 | May 30, 2008 05:35 |
OpenFOAM with Cygwin | kitchener | OpenFOAM Installation | 6 | April 25, 2006 00: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 |