|
[Sponsors] |
March 27, 2006, 19:08 |
I need to restart the solver a
|
#1 |
Senior Member
Xiaofeng Liu
Join Date: Mar 2009
Location: State College, PA, USA
Posts: 118
Rep Power: 17 |
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 mkDir(runTime.path()/"outletAlpha");OFstream outlet1AlphaFile(runTime.path()/"outletAlpha"/"outlet1AlphaLog.dat"); outlet1AlphaFile << bla bla bla
__________________
Xiaofeng Liu, Ph.D., P.E., Assistant Professor Department of Civil and Environmental Engineering Penn State University 223B Sackett Building University Park, PA 16802 Web: http://water.engr.psu.edu/liu/ |
|
March 28, 2006, 09:33 |
Have a look at stream handling
|
#2 |
Senior Member
Hrvoje Jasak
Join Date: Mar 2009
Location: London, England
Posts: 1,907
Rep Power: 33 |
Have a look at stream handling in C++ - there's a flag you can set wehn opening a stream for append.
Hrv
__________________
Hrvoje Jasak Providing commercial FOAM/OpenFOAM and CFD Consulting: http://wikki.co.uk |
|
March 28, 2006, 13:00 |
Google "ifstream C++"
//o
|
#3 |
Senior Member
Eugene de Villiers
Join Date: Mar 2009
Posts: 725
Rep Power: 21 |
Google "ifstream C++"
//open file for append ifstream someStreamName(filename, ios_base::app); |
|
June 20, 2006, 09:51 |
Hello
I used
OFstrean myFil
|
#4 |
New Member
Aurelia Cure
Join Date: Mar 2009
Location: Lund, Sweden
Posts: 18
Rep Power: 17 |
Hello
I used OFstrean myFile(file,ios_base::app) 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 ? Thanks Aurelia |
|
June 20, 2006, 12:47 |
Problem is that the Foam strea
|
#5 |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
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?
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request |
|
June 20, 2006, 18:45 |
There's still absolutely nothi
|
#6 |
Senior Member
Hrvoje Jasak
Join Date: Mar 2009
Location: London, England
Posts: 1,907
Rep Power: 33 |
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... Hrv
__________________
Hrvoje Jasak Providing commercial FOAM/OpenFOAM and CFD Consulting: http://wikki.co.uk |
|
June 21, 2006, 03:20 |
Bernhard and Hrvoje, thanks fo
|
#7 |
New Member
Aurelia Cure
Join Date: Mar 2009
Location: Lund, Sweden
Posts: 18
Rep Power: 17 |
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! Aurelia |
|
June 21, 2006, 06:55 |
I needed the same option. What
|
#8 |
Senior Member
Maka Mohu
Join Date: Mar 2009
Posts: 305
Rep Power: 18 |
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.
regards, Maka. |
|
June 21, 2006, 19:57 |
OK, it looks like this, using
|
#9 |
Senior Member
Hrvoje Jasak
Join Date: Mar 2009
Location: London, England
Posts: 1,907
Rep Power: 33 |
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: OFstream.H OFstream.C regIOobjectWrite.C You will, of course, need to rebuild the whole thing. The files are attached below hrvsStreams.tgz Enjoy, Hrv
__________________
Hrvoje Jasak Providing commercial FOAM/OpenFOAM and CFD Consulting: http://wikki.co.uk |
|
June 22, 2006, 05:40 |
Hrv,
Thank you for the files!
|
#10 |
New Member
Aurelia Cure
Join Date: Mar 2009
Location: Lund, Sweden
Posts: 18
Rep Power: 17 |
Hrv,
Thank you for the files! It really helps me. Aurelia |
|
November 23, 2007, 11:43 |
Dear forum,
I would like al
|
#11 |
Senior Member
Cedric DUPRAT
Join Date: Mar 2009
Location: Nantes, France
Posts: 195
Rep Power: 17 |
Dear forum,
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. Thank you, Cedric |
|
November 23, 2007, 12:42 |
Hi again,
it's ok now, I for
|
#12 |
Senior Member
Cedric DUPRAT
Join Date: Mar 2009
Location: Nantes, France
Posts: 195
Rep Power: 17 |
Hi again,
it's ok now, I forgot to add the files in lnInclude :o) sorry for the disturbance Cedric |
|
November 23, 2007, 12:53 |
Well, this is precisely the re
|
#13 |
Senior Member
Hrvoje Jasak
Join Date: Mar 2009
Location: London, England
Posts: 1,907
Rep Power: 33 |
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.
Enjoy, Hrv
__________________
Hrvoje Jasak Providing commercial FOAM/OpenFOAM and CFD Consulting: http://wikki.co.uk |
|
November 23, 2007, 12:57 |
well, that's right, I get it f
|
#14 |
Senior Member
Cedric DUPRAT
Join Date: Mar 2009
Location: Nantes, France
Posts: 195
Rep Power: 17 |
well, that's right, I get it for future problems
Thanks, Cedric |
|
November 12, 2008, 13:52 |
Hi,
I tried this with openf
|
#15 |
Senior Member
John Deas
Join Date: Mar 2009
Posts: 160
Rep Power: 17 |
Hi,
I tried this with openfoam 1.5 : std::ofstream wallStress ( runTime.path()/"wallStress", ios_base::app ); 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. |
|
April 19, 2009, 17:09 |
|
#16 |
Senior Member
Mark Couwenberg
Join Date: Mar 2009
Location: Netherlands
Posts: 130
Rep Power: 17 |
Hello John,
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? Brgds, Mark |
|
July 2, 2009, 15:34 |
|
#17 |
Member
Cem Albukrek
Join Date: Mar 2009
Posts: 52
Rep Power: 17 |
Hello Mark,
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" stringstream MyStrStream; char* MyChar; MyStrStream << MyWord; MyChar = MyStrStream.str().c_str(); I hope this helps. Best, Cem |
|
September 28, 2009, 10:42 |
|
#18 |
Senior Member
John Deas
Join Date: Mar 2009
Posts: 160
Rep Power: 17 |
Maybe I haven't understood basic things about pointers, but when you create:
Code:
char* MyChar; Code:
MyStrStream.str().c_str(); I also tried this way: Code:
std::stringstream MyStrStream; MyStrStream << runTime.path()/"wallStress"; std::ofstream wallStress ( MyStrStream.str().c_str(), ios_base::app ); Code:
/home/flurec/OpenFOAM/OpenFOAM-1.5/src/OpenFOAM/lnInclude/LListIO.C: In function ‘Foam::Istream& Foam::operator>>(Foam::Istream&, Foam::LList<LListBase, T>&) [with LListBase = Foam::SLListBase, T = Foam::SymmTensor<double>]’: /home/flurec/OpenFOAM/OpenFOAM-1.5/src/OpenFOAM/lnInclude/LListIO.C:51: internal compiler error: Segmentation fault Code:
string MyStrStream(runTime.path()/"wallStress"); std::ofstream wallStress ( MyStrStream.c_str(), ios_base::app ); |
|
June 14, 2010, 04:48 |
Cannot download the files...
|
#19 | |
New Member
Jens Johansson
Join Date: Mar 2009
Posts: 2
Rep Power: 0 |
HI
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? Kind regards Jens Johansson Quote:
|
||
June 14, 2010, 09:21 |
|
#20 |
New Member
Victor Fleischer
Join Date: Nov 2009
Posts: 21
Rep Power: 17 |
I tried it with different versions, but finally it works with
#include <iostream> using namespace std; ... fileName myDir = runTime.path(); .... word tracingFileName="TestName" 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! Victor |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
how to open a cas file in gambit | Michal K | FLUENT | 5 | March 14, 2009 17:37 |
FORTRAN(OPEN->APPEND) | kris | Siemens | 1 | November 30, 2004 08:57 |
where to open the file | jx | FLUENT | 0 | February 19, 2004 13:19 |
Scheme: append to existend file | Ingolf | FLUENT | 0 | November 10, 2003 06:27 |
append data to a file | Wen Long | Main CFD Forum | 1 | April 11, 2002 21:45 |