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

Writing output of a scalar in each time step

Register Blogs Community New Posts Updated Threads Search

Like Tree4Likes
  • 1 Post By mehranism
  • 3 Post By khedar

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 9, 2017, 10:12
Default Writing output of a scalar in each time step
  #1
New Member
 
mehran
Join Date: Jul 2016
Posts: 5
Rep Power: 10
mehranism is on a distinguished road
Dear Foamers,
I want to write output of a scalar in a .txt file during runTime. all the things are ok and the log file shows correct answer. but in the text file the scalar over writes on its old time value.
can anyone help me to write output of this scalar (yy in this code) and runTime in two separate columns in each time step in the .txt file?

here is the code:
GRBFoam.C
Luttappy likes this.
mehranism is offline   Reply With Quote

Old   July 9, 2017, 13:27
Default
  #2
Senior Member
 
khedar
Join Date: Oct 2016
Posts: 111
Rep Power: 10
khedar is on a distinguished road
You should open the file in append mode to not over write the values. Instead of

Code:
std::ofstream file("results.txt");
 file << runTime.timeName() << " " << yy << std::endl << "\n";
 file << nl << endl;
 file.close();

try this

Code:
std::ofstream file;
  file.open ("results.txt", std::ofstream::out | std::ofstream::app);

 file << runTime.timeName() << " " << yy << std::endl << "\n";
 file << nl << endl;
 file.close();
See doc here:
http://www.cplusplus.com/reference/f...ofstream/open/
Luttappy, mehranism and saeidabdi like this.
khedar is offline   Reply With Quote

Old   July 9, 2017, 14:05
Default
  #3
New Member
 
mehran
Join Date: Jul 2016
Posts: 5
Rep Power: 10
mehranism is on a distinguished road
Quote:
Originally Posted by khedar View Post
You should open the file in append mode to not over write the values. Instead of

Code:
std::ofstream file("results.txt");
 file << runTime.timeName() << " " << yy << std::endl << "\n";
 file << nl << endl;
 file.close();
try this

Code:
std::ofstream file;
  file.open ("results.txt", std::ofstream::out | std::ofstream::app);

 file << runTime.timeName() << " " << yy << std::endl << "\n";
 file << nl << endl;
 file.close();
See doc here:
http://www.cplusplus.com/reference/f...ofstream/open/


thank you so much Khedar. the file must be open before runTime. it helped me so much.
mehranism 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
courant number increases to rather large values 6863523 OpenFOAM Running, Solving & CFD 22 July 6, 2023 00:48
decomposePar problem: Cell 0contains face labels out of range vaina74 OpenFOAM Pre-Processing 37 July 20, 2020 06:38
Division by zero exception - loop over scalarField Pat84 OpenFOAM Programming & Development 6 February 18, 2017 06:57
[snappyHexMesh] crash sHM H25E OpenFOAM Meshing & Mesh Conversion 11 November 10, 2014 12:27
mixerVesselAMI2D's mass is not balancing sharonyue OpenFOAM Running, Solving & CFD 6 June 10, 2013 10:34


All times are GMT -4. The time now is 08:09.