Added writing of timings in param format

This commit is contained in:
Halvor Møll Nilsen 2012-08-21 09:57:36 +02:00
parent 9a44eababc
commit 29c6be6752
5 changed files with 52 additions and 9 deletions

View File

@ -170,8 +170,10 @@ main(int argc, char** argv)
// 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 epoch_os;
std::string output_dir;
if (output) { if (output) {
std::string 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);
try { try {
@ -179,8 +181,15 @@ main(int argc, char** argv)
} }
catch (...) { catch (...) {
THROW("Creating directories failed: " << fpath); THROW("Creating directories failed: " << fpath);
} }
param.writeParam(output_dir + "/spu_2p.param"); std::string filename = output_dir + "/epoch_timing.param";
epoch_os.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");
} }
@ -259,13 +268,24 @@ main(int argc, char** argv)
warnIfUnusedParams(param); warnIfUnusedParams(param);
} }
SimulatorReport epoch_rep = simulator.run(simtimer, state, well_state); SimulatorReport epoch_rep = simulator.run(simtimer, state, well_state);
if(output){
epoch_rep.reportParam(epoch_os);
}
// Update total timing report and remember step number. // Update total timing report and remember step number.
rep += epoch_rep; rep += epoch_rep;
step = simtimer.currentStepNum(); step = simtimer.currentStepNum();
} }
} }
epoch_os.close();
std::cout << "\n\n================ End of simulation ===============\n\n"; std::cout << "\n\n================ End of simulation ===============\n\n";
rep.report(std::cout); rep.report(std::cout);
if (output) {
std::string filename = output_dir + "/walltime.param";
std::fstream tot_os(filename.c_str(),std::fstream::trunc | std::fstream::out);
rep.reportParam(tot_os);
tot_os.close();
}
} }

View File

@ -493,7 +493,7 @@ main(int argc, char** argv)
// Write parameters used for later reference. // Write parameters used for later reference.
if (output) { if (output) {
param.writeParam(output_dir + "/spu_2p.param"); param.writeParam(output_dir + "/simulation.param");
} }
// Main simulation loop. // Main simulation loop.

View File

@ -42,6 +42,12 @@ namespace Opm
<< "\n Pressure time: " << pressure_time << "\n Pressure time: " << pressure_time
<< "\n Transport time: " << transport_time << std::endl; << "\n Transport time: " << transport_time << std::endl;
} }
void SimulatorReport::reportParam(std::ostream& os)
{
os << "/timing/total_time=" << total_time
<< "\n/timing/pressure/total_time=" << pressure_time
<< "\n/timing/transport/total_time=" << transport_time << std::endl;
}
} // namespace Opm } // namespace Opm

View File

@ -38,6 +38,7 @@ namespace Opm
void operator+=(const SimulatorReport& sr); void operator+=(const SimulatorReport& sr);
/// Print a report to the given stream. /// Print a report to the given stream.
void report(std::ostream& os); void report(std::ostream& os);
void reportParam(std::ostream& os);
}; };
} // namespace Opm } // namespace Opm

View File

@ -306,6 +306,7 @@ namespace Opm
double ptime = 0.0; double ptime = 0.0;
Opm::time::StopWatch transport_timer; Opm::time::StopWatch transport_timer;
double ttime = 0.0; double ttime = 0.0;
Opm::time::StopWatch step_timer;
Opm::time::StopWatch total_timer; Opm::time::StopWatch total_timer;
total_timer.start(); total_timer.start();
double init_satvol[2] = { 0.0 }; double init_satvol[2] = { 0.0 };
@ -326,8 +327,14 @@ namespace Opm
well_resflows_phase.resize((wells_->number_of_phases)*(wells_->number_of_wells), 0.0); well_resflows_phase.resize((wells_->number_of_phases)*(wells_->number_of_wells), 0.0);
wellreport.push(props_, *wells_, state.saturation(), 0.0, well_state.bhp(), well_state.perfRates()); wellreport.push(props_, *wells_, state.saturation(), 0.0, well_state.bhp(), well_state.perfRates());
} }
std::fstream tstep_os;
if(output_){
std::string filename = output_dir_ + "/step_timing.param";
tstep_os.open(filename.c_str(), std::fstream::out | std::fstream::app);
}
for (; !timer.done(); ++timer) { for (; !timer.done(); ++timer) {
// Report timestep and (optionally) write state to disk. // Report timestep and (optionally) write state to disk.
step_timer.start();
timer.report(std::cout); timer.report(std::cout);
if (output_ && (timer.currentStepNum() % output_interval_ == 0)) { if (output_ && (timer.currentStepNum() % output_interval_ == 0)) {
if (output_vtk_) { if (output_vtk_) {
@ -335,7 +342,8 @@ namespace Opm
} }
outputStateMatlab(grid_, state, timer.currentStepNum(), output_dir_); outputStateMatlab(grid_, state, timer.currentStepNum(), output_dir_);
} }
SimulatorReport sreport;
// Solve pressure. // Solve pressure.
do { do {
pressure_timer.start(); pressure_timer.start();
@ -344,6 +352,7 @@ namespace Opm
double pt = pressure_timer.secsSinceStart(); double pt = pressure_timer.secsSinceStart();
std::cout << "Pressure solver took: " << pt << " seconds." << std::endl; std::cout << "Pressure solver took: " << pt << " seconds." << std::endl;
ptime += pt; ptime += pt;
sreport.pressure_time = pt;
} while (false); } while (false);
// Update pore volumes if rock is compressible. // Update pore volumes if rock is compressible.
@ -372,9 +381,9 @@ namespace Opm
} }
transport_timer.stop(); transport_timer.stop();
double tt = transport_timer.secsSinceStart(); double tt = transport_timer.secsSinceStart();
sreport.transport_time = tt;
std::cout << "Transport solver took: " << tt << " seconds." << std::endl; std::cout << "Transport solver took: " << tt << " seconds." << std::endl;
ttime += tt; ttime += tt;
// Report volume balances. // Report volume balances.
Opm::computeSaturatedVol(porevol, state.saturation(), satvol); Opm::computeSaturatedVol(porevol, state.saturation(), satvol);
tot_injected[0] += injected[0]; tot_injected[0] += injected[0];
@ -416,6 +425,12 @@ namespace Opm
timer.currentTime() + timer.currentStepLength(), timer.currentTime() + timer.currentStepLength(),
well_state.bhp(), well_state.perfRates()); well_state.bhp(), well_state.perfRates());
} }
sreport.total_time = step_timer.secsSinceStart();
if(output_){
sreport.reportParam(tstep_os);
}
} }
if (output_) { if (output_) {
@ -427,6 +442,7 @@ namespace Opm
if (wells_) { if (wells_) {
outputWellReport(wellreport, output_dir_); outputWellReport(wellreport, output_dir_);
} }
tstep_os.close();
} }
total_timer.stop(); total_timer.stop();
@ -434,7 +450,7 @@ namespace Opm
SimulatorReport report; SimulatorReport report;
report.pressure_time = ptime; report.pressure_time = ptime;
report.transport_time = ttime; report.transport_time = ttime;
report.total_time = total_timer.secsSinceStart(); report.total_time = total_timer.secsSinceStart();
return report; return report;
} }