From 29c6be6752d4e186a662396cb242993f5dbae437 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halvor=20M=C3=B8ll=20Nilsen?= Date: Tue, 21 Aug 2012 09:57:36 +0200 Subject: [PATCH] Added writing of timings in param format --- examples/sim_2p_incomp_reorder.cpp | 30 ++++++++++++++++++++---- examples/spu_2p.cpp | 2 +- opm/core/simulator/SimulatorReport.cpp | 6 +++++ opm/core/simulator/SimulatorReport.hpp | 1 + opm/core/simulator/SimulatorTwophase.cpp | 22 ++++++++++++++--- 5 files changed, 52 insertions(+), 9 deletions(-) diff --git a/examples/sim_2p_incomp_reorder.cpp b/examples/sim_2p_incomp_reorder.cpp index eba5dbb7..c3f7136a 100644 --- a/examples/sim_2p_incomp_reorder.cpp +++ b/examples/sim_2p_incomp_reorder.cpp @@ -170,8 +170,10 @@ main(int argc, char** argv) // Write parameters used for later reference. bool output = param.getDefault("output", true); + std::ofstream epoch_os; + std::string output_dir; if (output) { - std::string output_dir = + output_dir = param.getDefault("output_dir", std::string("output")); boost::filesystem::path fpath(output_dir); try { @@ -179,8 +181,15 @@ main(int argc, char** argv) } catch (...) { 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); } SimulatorReport epoch_rep = simulator.run(simtimer, state, well_state); - + if(output){ + epoch_rep.reportParam(epoch_os); + } // Update total timing report and remember step number. rep += epoch_rep; step = simtimer.currentStepNum(); } } - + + epoch_os.close(); std::cout << "\n\n================ End of simulation ===============\n\n"; 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(); + } + } diff --git a/examples/spu_2p.cpp b/examples/spu_2p.cpp index 2c6eea43..25cd3f6f 100644 --- a/examples/spu_2p.cpp +++ b/examples/spu_2p.cpp @@ -493,7 +493,7 @@ main(int argc, char** argv) // Write parameters used for later reference. if (output) { - param.writeParam(output_dir + "/spu_2p.param"); + param.writeParam(output_dir + "/simulation.param"); } // Main simulation loop. diff --git a/opm/core/simulator/SimulatorReport.cpp b/opm/core/simulator/SimulatorReport.cpp index 1fa26459..76326260 100644 --- a/opm/core/simulator/SimulatorReport.cpp +++ b/opm/core/simulator/SimulatorReport.cpp @@ -42,6 +42,12 @@ namespace Opm << "\n Pressure time: " << pressure_time << "\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 diff --git a/opm/core/simulator/SimulatorReport.hpp b/opm/core/simulator/SimulatorReport.hpp index a763156c..8e7cb2e8 100644 --- a/opm/core/simulator/SimulatorReport.hpp +++ b/opm/core/simulator/SimulatorReport.hpp @@ -38,6 +38,7 @@ namespace Opm void operator+=(const SimulatorReport& sr); /// Print a report to the given stream. void report(std::ostream& os); + void reportParam(std::ostream& os); }; } // namespace Opm diff --git a/opm/core/simulator/SimulatorTwophase.cpp b/opm/core/simulator/SimulatorTwophase.cpp index 84668b2a..9b5ac0e2 100644 --- a/opm/core/simulator/SimulatorTwophase.cpp +++ b/opm/core/simulator/SimulatorTwophase.cpp @@ -306,6 +306,7 @@ namespace Opm double ptime = 0.0; Opm::time::StopWatch transport_timer; double ttime = 0.0; + Opm::time::StopWatch step_timer; Opm::time::StopWatch total_timer; total_timer.start(); 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); 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) { // Report timestep and (optionally) write state to disk. + step_timer.start(); timer.report(std::cout); if (output_ && (timer.currentStepNum() % output_interval_ == 0)) { if (output_vtk_) { @@ -335,7 +342,8 @@ namespace Opm } outputStateMatlab(grid_, state, timer.currentStepNum(), output_dir_); } - + SimulatorReport sreport; + // Solve pressure. do { pressure_timer.start(); @@ -344,6 +352,7 @@ namespace Opm double pt = pressure_timer.secsSinceStart(); std::cout << "Pressure solver took: " << pt << " seconds." << std::endl; ptime += pt; + sreport.pressure_time = pt; } while (false); // Update pore volumes if rock is compressible. @@ -372,9 +381,9 @@ namespace Opm } transport_timer.stop(); double tt = transport_timer.secsSinceStart(); + sreport.transport_time = tt; std::cout << "Transport solver took: " << tt << " seconds." << std::endl; ttime += tt; - // Report volume balances. Opm::computeSaturatedVol(porevol, state.saturation(), satvol); tot_injected[0] += injected[0]; @@ -416,6 +425,12 @@ namespace Opm timer.currentTime() + timer.currentStepLength(), well_state.bhp(), well_state.perfRates()); } + sreport.total_time = step_timer.secsSinceStart(); + if(output_){ + sreport.reportParam(tstep_os); + } + + } if (output_) { @@ -427,6 +442,7 @@ namespace Opm if (wells_) { outputWellReport(wellreport, output_dir_); } + tstep_os.close(); } total_timer.stop(); @@ -434,7 +450,7 @@ namespace Opm SimulatorReport report; report.pressure_time = ptime; report.transport_time = ttime; - report.total_time = total_timer.secsSinceStart(); + report.total_time = total_timer.secsSinceStart(); return report; }