I need to restart the solver a
I need to restart the solver at some point. Also I write out some log information for postprocessing.
My question is how can I open the old log file to APPEND new lines?
Now I am using:
//outlet concentration log file
if(!dir(runTime.path()/"outletAlpha")) //if the directory doesn't exist
outlet1AlphaFile << bla bla bla
Have a look at stream handling
Have a look at stream handling in C++ - there's a flag you can set wehn opening a stream for append.
Google "ifstream C++" //o
Google "ifstream C++"
//open file for append
ifstream someStreamName(filename, ios_base::app);
Hello I used OFstrean myFil
but get the error "
error: no matching function for call to 'Foam:: OFstream:: OFstream(Foam::fileName&, const std::_Ios_Openmode&)'
/home/aurelia/OpenFOAM/OpenFOAM-1.2/src/OpenFOAM/lnInclude/OFstream.H:107: note: candidates are: Foam:: OFstream:: OFstream(const Foam::fileName&, Foam::IOstream::streamFormat, Foam::IOstream::versionNumber, Foam::IOstream::compressionType)
/home/aurelia/OpenFOAM/OpenFOAM-1.2/src/OpenFOAM/lnInclude/OFstream.H:86: note: Foam:: OFstream:: OFstream(const Foam:: OFstream&)
Should I add something in lnInclude/OFstream.H ?
Problem is that the Foam strea
Problem is that the Foam streams (OFstream,IFStream) look a lot like the standard C++ file-streams (ifstream, ofstream) but are not capable of all the things the std-streams are: for instance appending. When you look at the Doxygen info for OFstream you will find that it doesn't take the ios_base-Parameters.
I guess that is because the Foam-streams are capable of orderly output during parallel computations. The std-streams aren't. So if you need appending use the std::ofstream, it should work as well as long as you don't plan to run your program in parallel.
Note: if I am wrong could someone who has actually looked at the IO-code correct me?
There's still absolutely nothi
There's still absolutely nothing stopping you from making a plain old ofstream and working with that. In fact, the streams will swallow the on-the-fly stream modifiers, but the constructor for append is not there. If you'd really like one, I will add it for you.
The additional stuff will sit in /db/IOstreams/Fstreams/OFstream.H and .C and it's pretty straightforward. Not sure what happens with the ogzstreams (compressed data), but there must be a way out...
Bernhard and Hrvoje, thanks fo
Bernhard and Hrvoje, thanks for your reply
Hrvoje, if you have time to do it, I will appreciate if you could add this constructor for appending because for me, it is far to be straightforward!
I needed the same option. What
I needed the same option. What I do is a simple solution. I log the new run in log.2 file and then append it from linux when I finish the simulation (or before) by log.2 >> log.1 linux command.
OK, it looks like this, using
OK, it looks like this, using the stream modifier on construction - the one below opens the file for append:
OFstream of("hello", ios_base::app);
of << 0 << nl << 1 << nl << 2 << endl;
I changed 3 files, all in the main library:
You will, of course, need to rebuild the whole thing. The files are attached below http://www.cfd-online.com/OpenFOAM_D...hment_icon.gif hrvsStreams.tgz
Hrv, Thank you for the files!
Thank you for the files! It really helps me.
Dear forum, I would like al
I would like also to play with OFstream. cause I would like to print every timestep in one file a value of one home-made parameter.
Is there any thing to modified in Hrvoje.tgz for 1.4.1 version of Foam ?
I ask this because I had some error message when compiling ...
It's just to know if I made a mistake some where or, if I have to change something.
I copy the OFstream .C and .H at the right place, samething for regIOobjectWrite.C but, when compiling, I got some error.
Hi again, it's ok now, I for
it's ok now, I forgot to add the files in lnInclude :o)
sorry for the disturbance
Well, this is precisely the re
Well, this is precisely the reason why we support an open SVN development line: every time you get stuck, you can just go there and see what I've dome to keep the code working between versions.
well, that's right, I get it f
well, that's right, I get it for future problems
Hi, I tried this with openf
I tried this with openfoam 1.5 :
but got this error message:
channelStress.C:75: error: no matching function for call to 'std::basic_ofstream<char,> >::basic_ofstream(Foam::fileName, const std::_Ios_Openmode&)'
/home/flurec/OpenFOAM/ThirdParty/gcc-4.3.1/platforms/linux/bin/../lib/gcc/i686-p c-linux-gnu/4.3.1/../../../../include/c++/4.3.1/fstream:572: note: candidates are: std::basic_ofstream<_chart,>::basic_ofstream(const char*, std::_Ios_Openmode) [with _CharT = char, _Traits = std::char_traits<char>]
/home/flurec/OpenFOAM/ThirdParty/gcc-4.3.1/platforms/linux/bin/../lib/gcc/i686-p c-linux-gnu/4.3.1/../../../../include/c++/4.3.1/fstream:556: note: std::basic_ofstream<_chart,>::basic_ofstream() [with _CharT = char, _Traits = std::char_traits<char>]
/home/flurec/OpenFOAM/ThirdParty/gcc-4.3.1/platforms/linux/bin/../lib/gcc/i686-p c-linux-gnu/4.3.1/../../../../include/c++/4.3.1/iosfwd:89: note: std::basic_ofstream<char,> >::basic_ofstream(const std::basic_ofstream<char,> >&)
make: *** [Make/linuxGccDPOpt/channelStress.o] Error 1
Anybody know how to fix this ? I wouldn't want to modify the OFstream source files as proposed in this thread.
I had the same struggle. It's because ofstream needs the filename either directly entered or as a pointer variable of type const char*. Well, that's nice to know but I also do not know how to work around it. Maybe someone else?
It seems our paths cross quite often when it comes to problems. In case you do not yet have an answer to your problem, here is a dirty work around I have discovered:
The problem with using ofstream is, as you said, the requirement to pass a "char*" type as file name. But how do you extract "char*" from "word" which we predominantly use in OpenFOAM?
word MyWord = "testing"
MyStrStream << MyWord;
MyChar = MyStrStream.str().c_str();
I hope this helps.
Maybe I haven't understood basic things about pointers, but when you create:
I also tried this way:
Cannot download the files...
I am really interested in the files posted here. But when I am not able to download them... I get a *.unk file instead. Any help?
I tried it with different versions, but finally it works with
using namespace std;
fileName myDir = runTime.path();
fileName myFile = myDir/tracingFileName;
std:: ofstream myStream(myFile.c_str(),ios_base::app);
I know, there would be an shorter version, but i just copied these lines out of my solver.
I do not know if you really have to include <iostream>, i did not test it!
|All times are GMT -4. The time now is 15:55.|