Clean up files and streams for timing output.

Total time will be written to walltime.txt, and single step times to
step_timing.txt (changed suffix from param to txt). This did not work
properly before this fix (step_timing file was overwritten each step).
This commit is contained in:
Atgeirr Flø Rasmussen 2014-08-12 09:28:28 +02:00
parent 120e9d02d4
commit b85ba1bcc0
2 changed files with 8 additions and 16 deletions

View File

@ -163,9 +163,9 @@ try
// Write parameters used for later reference. // Write parameters used for later reference.
bool output = param.getDefault("output", true); bool output = param.getDefault("output", true);
std::ofstream outStream;
std::string output_dir; std::string output_dir;
if (output) { if (output) {
// Create output directory if needed.
output_dir = output_dir =
param.getDefault("output_dir", std::string("output")); param.getDefault("output_dir", std::string("output"));
boost::filesystem::path fpath(output_dir); boost::filesystem::path fpath(output_dir);
@ -175,19 +175,13 @@ try
catch (...) { catch (...) {
OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath); OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath);
} }
std::string filename = output_dir + "/timing.param"; // Write simulation parameters.
outStream.open(filename.c_str(), std::fstream::trunc | std::fstream::out);
// open file to clean it. The file is appended to in SimulatorTwophase
filename = output_dir + "/step_timing.param";
std::fstream step_os(filename.c_str(), std::fstream::trunc | std::fstream::out);
step_os.close();
param.writeParam(output_dir + "/simulation.param"); param.writeParam(output_dir + "/simulation.param");
} }
std::cout << "\n\n================ Starting main simulation loop ===============\n" std::cout << "\n\n================ Starting main simulation loop ===============\n"
<< std::flush; << std::flush;
WellStateFullyImplicitBlackoil well_state;
Opm::TimeMapPtr timeMap(new Opm::TimeMap(deck)); Opm::TimeMapPtr timeMap(new Opm::TimeMap(deck));
SimulatorTimer simtimer; SimulatorTimer simtimer;
@ -217,7 +211,7 @@ try
fullReport.report(std::cout); fullReport.report(std::cout);
if (output) { if (output) {
std::string filename = output_dir + "/walltime.param"; std::string filename = output_dir + "/walltime.txt";
std::fstream tot_os(filename.c_str(),std::fstream::trunc | std::fstream::out); std::fstream tot_os(filename.c_str(),std::fstream::trunc | std::fstream::out);
fullReport.reportParam(tot_os); fullReport.reportParam(tot_os);
warnIfUnusedParams(param); warnIfUnusedParams(param);

View File

@ -255,17 +255,16 @@ namespace Opm
{ {
WellStateFullyImplicitBlackoil well_state; WellStateFullyImplicitBlackoil well_state;
// Main simulation loop. // Create timers and file for writing timing info.
Opm::time::StopWatch solver_timer; Opm::time::StopWatch solver_timer;
double stime = 0.0; double stime = 0.0;
Opm::time::StopWatch step_timer; Opm::time::StopWatch step_timer;
Opm::time::StopWatch total_timer; Opm::time::StopWatch total_timer;
total_timer.start(); total_timer.start();
std::fstream tstep_os; std::string tstep_filename = output_dir_ + "/step_timing.txt";
if (output_) { std::ofstream tstep_os(tstep_filename.c_str());
std::string filename = output_dir_ + "/step_timing.param";
tstep_os.open(filename.c_str(), std::fstream::out | std::fstream::app); // Main simulation loop.
}
while (!timer.done()) { while (!timer.done()) {
// Report timestep and (optionally) write state to disk. // Report timestep and (optionally) write state to disk.
step_timer.start(); step_timer.start();
@ -323,7 +322,6 @@ namespace Opm
} }
outputStateMatlab(grid_, state, timer.currentStepNum(), output_dir_); outputStateMatlab(grid_, state, timer.currentStepNum(), output_dir_);
outputWellStateMatlab(well_state,timer.currentStepNum(), output_dir_); outputWellStateMatlab(well_state,timer.currentStepNum(), output_dir_);
tstep_os.close();
} }
output_writer_.writeTimeStep(timer, state, well_state.basicWellState()); output_writer_.writeTimeStep(timer, state, well_state.basicWellState());