From cb3b50f4b7369e8174712be857a5f4887f751e14 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 9 Feb 2023 11:28:46 +0100 Subject: [PATCH 1/2] SimulatorReportSingle: use in-class initializers this way there are no explicit ctors, which again means brace initialization works --- .../timestepping/SimulatorReport.cpp | 27 ---------- .../timestepping/SimulatorReport.hpp | 50 +++++++++---------- 2 files changed, 25 insertions(+), 52 deletions(-) diff --git a/opm/simulators/timestepping/SimulatorReport.cpp b/opm/simulators/timestepping/SimulatorReport.cpp index 6b63104cf..70dcc2fc1 100644 --- a/opm/simulators/timestepping/SimulatorReport.cpp +++ b/opm/simulators/timestepping/SimulatorReport.cpp @@ -27,36 +27,9 @@ #include #include #include -#include namespace Opm { - SimulatorReportSingle::SimulatorReportSingle() - : pressure_time(0.0), - transport_time(0.0), - total_time(0.0), - solver_time(0.0), - assemble_time(0.0), - pre_post_time(0.0), - assemble_time_well(0.0), - linear_solve_setup_time(0.0), - linear_solve_time(0.0), - update_time(0.0), - output_write_time(0.0), - total_well_iterations(0), - total_linearizations( 0 ), - total_newton_iterations( 0 ), - total_linear_iterations( 0 ), - min_linear_iterations ( std::numeric_limits::max() ), - max_linear_iterations ( 0 ), - converged(false), - well_group_control_changed(false), - exit_status(EXIT_SUCCESS), - global_time(0), - timestep_length(0.0) - { - } - void SimulatorReportSingle::operator+=(const SimulatorReportSingle& sr) { pressure_time += sr.pressure_time; diff --git a/opm/simulators/timestepping/SimulatorReport.hpp b/opm/simulators/timestepping/SimulatorReport.hpp index 41b2edad2..97199eece 100644 --- a/opm/simulators/timestepping/SimulatorReport.hpp +++ b/opm/simulators/timestepping/SimulatorReport.hpp @@ -19,8 +19,11 @@ #ifndef OPM_SIMULATORREPORT_HEADER_INCLUDED #define OPM_SIMULATORREPORT_HEADER_INCLUDED + #include +#include #include +#include #include namespace Opm @@ -29,35 +32,32 @@ namespace Opm /// A struct for returning timing data from a simulator to its caller. struct SimulatorReportSingle { - double pressure_time; - double transport_time; - double total_time; - double solver_time; - double assemble_time; - double pre_post_time; - double assemble_time_well; - double linear_solve_setup_time; - double linear_solve_time; - double update_time; - double output_write_time; + double pressure_time = 0.0; + double transport_time = 0.0; + double total_time = 0.0; + double solver_time = 0.0; + double assemble_time = 0.0; + double pre_post_time = 0.0; + double assemble_time_well = 0.0; + double linear_solve_setup_time = 0.0; + double linear_solve_time = 0.0; + double update_time = 0.0; + double output_write_time = 0.0; - unsigned int total_well_iterations; - unsigned int total_linearizations; - unsigned int total_newton_iterations; - unsigned int total_linear_iterations; - unsigned int min_linear_iterations; - unsigned int max_linear_iterations; + unsigned int total_well_iterations = 0; + unsigned int total_linearizations = 0; + unsigned int total_newton_iterations = 0; + unsigned int total_linear_iterations = 0; + unsigned int min_linear_iterations = std::numeric_limits::max(); + unsigned int max_linear_iterations = 0; + bool converged = false; + bool well_group_control_changed = false; + int exit_status = EXIT_SUCCESS; - bool converged; - bool well_group_control_changed; - int exit_status; + double global_time = 0.0; + double timestep_length = 0.0; - double global_time; - double timestep_length; - - /// Default constructor initializing all times to 0.0. - SimulatorReportSingle(); /// Increment this report's times by those in sr. void operator+=(const SimulatorReportSingle& sr); /// Print a report suitable for a single simulation step. From 382fd73fcaae74af0236e9cbb53698e9303072da Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 9 Feb 2023 11:32:39 +0100 Subject: [PATCH 2/2] SimulatorReportSingle: pass argument as std::ostream no reason for this to explicitly be an ostringstream --- opm/simulators/timestepping/SimulatorReport.cpp | 7 +++---- opm/simulators/timestepping/SimulatorReport.hpp | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/opm/simulators/timestepping/SimulatorReport.cpp b/opm/simulators/timestepping/SimulatorReport.cpp index 70dcc2fc1..2fb8607e1 100644 --- a/opm/simulators/timestepping/SimulatorReport.cpp +++ b/opm/simulators/timestepping/SimulatorReport.cpp @@ -17,15 +17,14 @@ along with OPM. If not, see . */ -#include "config.h" - +#include #include + #include #include #include #include -#include #include namespace Opm @@ -59,7 +58,7 @@ namespace Opm } - void SimulatorReportSingle::reportStep(std::ostringstream& ss) const + void SimulatorReportSingle::reportStep(std::ostream& ss) const { if (total_well_iterations != 0) { ss << fmt::format("Well its={:2}", total_well_iterations); diff --git a/opm/simulators/timestepping/SimulatorReport.hpp b/opm/simulators/timestepping/SimulatorReport.hpp index 97199eece..3e1e32a3e 100644 --- a/opm/simulators/timestepping/SimulatorReport.hpp +++ b/opm/simulators/timestepping/SimulatorReport.hpp @@ -61,7 +61,7 @@ namespace Opm /// Increment this report's times by those in sr. void operator+=(const SimulatorReportSingle& sr); /// Print a report suitable for a single simulation step. - void reportStep(std::ostringstream& os) const; + void reportStep(std::ostream& os) const; /// Print a report suitable for the end of a fully implicit case, leaving out the pressure/transport time. void reportFullyImplicit(std::ostream& os, const SimulatorReportSingle* failedReport = nullptr) const; };