From bb0164f39f2979549dbac75b66622a24ed71260b Mon Sep 17 00:00:00 2001 From: Liu Ming Date: Mon, 11 Jul 2016 11:47:29 +0800 Subject: [PATCH 1/5] fix well iterations counting bugs. --- opm/autodiff/NonlinearSolver_impl.hpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/opm/autodiff/NonlinearSolver_impl.hpp b/opm/autodiff/NonlinearSolver_impl.hpp index 00a34e3cb..f08113311 100644 --- a/opm/autodiff/NonlinearSolver_impl.hpp +++ b/opm/autodiff/NonlinearSolver_impl.hpp @@ -137,7 +137,11 @@ namespace Opm } converged = report.converged; linIters += report.linear_iterations; - wellIters += report.well_iterations; + if (report.well_iterations != std::numeric_limits::min()) { + wellIters += report.well_iterations; + } else { + wellIters = report.well_iterations; + } ++iteration; } while ( (!converged && (iteration <= maxIter())) || (iteration <= minIter())); From 6af9aee20f4f14b6cfa45ff96143da8855ddccb2 Mon Sep 17 00:00:00 2001 From: Liu Ming Date: Wed, 13 Jul 2016 09:00:15 +0800 Subject: [PATCH 2/5] counting well iterations correctly. --- opm/autodiff/NonlinearSolver_impl.hpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/opm/autodiff/NonlinearSolver_impl.hpp b/opm/autodiff/NonlinearSolver_impl.hpp index f08113311..98963fc67 100644 --- a/opm/autodiff/NonlinearSolver_impl.hpp +++ b/opm/autodiff/NonlinearSolver_impl.hpp @@ -139,8 +139,6 @@ namespace Opm linIters += report.linear_iterations; if (report.well_iterations != std::numeric_limits::min()) { wellIters += report.well_iterations; - } else { - wellIters = report.well_iterations; } ++iteration; } while ( (!converged && (iteration <= maxIter())) || (iteration <= minIter())); @@ -154,10 +152,16 @@ namespace Opm linearIterations_ += linIters; nonlinearIterations_ += iteration - 1; // Since the last one will always be trivial. - wellIterations_ += wellIters; + if (wellIters != 0) { + wellIterations_ += wellIters; + wellIterationsLast_ = wellIters; + } + if (wellIters == 0) { + wellIterations_ = std::numeric_limits::min(); + wellIterationsLast_ = std::numeric_limits::min(); + } linearIterationsLast_ = linIters; nonlinearIterationsLast_ = iteration; - wellIterationsLast_ = wellIters; // Do model-specific post-step actions. model_->afterStep(dt, reservoir_state, well_state); From b43cbe05312a10181c49340b416d5aae3e593f44 Mon Sep 17 00:00:00 2001 From: Liu Ming Date: Thu, 14 Jul 2016 10:25:32 +0800 Subject: [PATCH 3/5] drop useages of std::numeric_limits for counting well iterations. --- opm/autodiff/BlackoilModelBase_impl.hpp | 2 +- opm/autodiff/BlackoilMultiSegmentModel_impl.hpp | 2 +- opm/autodiff/BlackoilTransportModel.hpp | 2 +- opm/autodiff/NonlinearSolver_impl.hpp | 14 +++----------- opm/autodiff/SimulatorBase_impl.hpp | 2 +- 5 files changed, 7 insertions(+), 15 deletions(-) diff --git a/opm/autodiff/BlackoilModelBase_impl.hpp b/opm/autodiff/BlackoilModelBase_impl.hpp index 36627f20d..1c8daf1a9 100644 --- a/opm/autodiff/BlackoilModelBase_impl.hpp +++ b/opm/autodiff/BlackoilModelBase_impl.hpp @@ -775,7 +775,7 @@ namespace detail { asImpl().assembleMassBalanceEq(state); // -------- Well equations ---------- - IterationReport iter_report = {false, false, 0, std::numeric_limits::min()}; + IterationReport iter_report = {false, false, 0, 0}; if ( ! wellsActive() ) { return iter_report; } diff --git a/opm/autodiff/BlackoilMultiSegmentModel_impl.hpp b/opm/autodiff/BlackoilMultiSegmentModel_impl.hpp index cef4df44f..0fc98776b 100644 --- a/opm/autodiff/BlackoilMultiSegmentModel_impl.hpp +++ b/opm/autodiff/BlackoilMultiSegmentModel_impl.hpp @@ -182,7 +182,7 @@ namespace Opm { asImpl().assembleMassBalanceEq(state); // -------- Well equations ---------- - IterationReport iter_report = {false, false, 0, std::numeric_limits::min()}; + IterationReport iter_report = {false, false, 0, 0}; if ( ! wellsActive() ) { return iter_report; } diff --git a/opm/autodiff/BlackoilTransportModel.hpp b/opm/autodiff/BlackoilTransportModel.hpp index 7351cce5f..38af2ecac 100644 --- a/opm/autodiff/BlackoilTransportModel.hpp +++ b/opm/autodiff/BlackoilTransportModel.hpp @@ -124,7 +124,7 @@ namespace Opm { asImpl().assembleMassBalanceEq(state); // -------- Well equations ---------- - IterationReport iter_report = {false, false, 0, std::numeric_limits::min()}; + IterationReport iter_report = {false, false, 0, 0}; if ( ! wellsActive() ) { return iter_report; } diff --git a/opm/autodiff/NonlinearSolver_impl.hpp b/opm/autodiff/NonlinearSolver_impl.hpp index 98963fc67..665a5faab 100644 --- a/opm/autodiff/NonlinearSolver_impl.hpp +++ b/opm/autodiff/NonlinearSolver_impl.hpp @@ -137,9 +137,7 @@ namespace Opm } converged = report.converged; linIters += report.linear_iterations; - if (report.well_iterations != std::numeric_limits::min()) { - wellIters += report.well_iterations; - } + wellIters += report.well_iterations; ++iteration; } while ( (!converged && (iteration <= maxIter())) || (iteration <= minIter())); @@ -152,14 +150,8 @@ namespace Opm linearIterations_ += linIters; nonlinearIterations_ += iteration - 1; // Since the last one will always be trivial. - if (wellIters != 0) { - wellIterations_ += wellIters; - wellIterationsLast_ = wellIters; - } - if (wellIters == 0) { - wellIterations_ = std::numeric_limits::min(); - wellIterationsLast_ = std::numeric_limits::min(); - } + wellIterations_ = wellIters; + wellIterationsLast_ = wellIters; linearIterationsLast_ = linIters; nonlinearIterationsLast_ = iteration; diff --git a/opm/autodiff/SimulatorBase_impl.hpp b/opm/autodiff/SimulatorBase_impl.hpp index 62074387b..17b974278 100644 --- a/opm/autodiff/SimulatorBase_impl.hpp +++ b/opm/autodiff/SimulatorBase_impl.hpp @@ -213,7 +213,7 @@ namespace Opm { std::ostringstream iter_msg; iter_msg << "Stepsize " << (double)unit::convert::to(timer.currentStepLength(), unit::day); - if (solver->wellIterations() != std::numeric_limits::min()) { + if (solver->wellIterations() != 0) { iter_msg << " days well iterations = " << solver->wellIterations() << ", "; } iter_msg << "non-linear iterations = " << solver->nonlinearIterations() From 52d51e856535b3231f6bfbb897cc68449c7933d5 Mon Sep 17 00:00:00 2001 From: Liu Ming Date: Mon, 18 Jul 2016 09:02:30 +0800 Subject: [PATCH 4/5] remove wellIterationsLast_. --- opm/autodiff/NonlinearSolver.hpp | 4 ---- opm/autodiff/NonlinearSolver_impl.hpp | 10 +--------- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/opm/autodiff/NonlinearSolver.hpp b/opm/autodiff/NonlinearSolver.hpp index c69e58725..f2d814a95 100644 --- a/opm/autodiff/NonlinearSolver.hpp +++ b/opm/autodiff/NonlinearSolver.hpp @@ -117,9 +117,6 @@ namespace Opm { /// Number of linear solver iterations used in the last call to step(). int linearIterationsLastStep() const; - /// Number of well iterations used in the last call to step(). - int wellIterationsLastStep() const; - /// Reference to physical model. const PhysicalModel& model() const; @@ -160,7 +157,6 @@ namespace Opm { int wellIterations_; int nonlinearIterationsLast_; int linearIterationsLast_; - int wellIterationsLast_; }; } // namespace Opm diff --git a/opm/autodiff/NonlinearSolver_impl.hpp b/opm/autodiff/NonlinearSolver_impl.hpp index 665a5faab..b6280c0a0 100644 --- a/opm/autodiff/NonlinearSolver_impl.hpp +++ b/opm/autodiff/NonlinearSolver_impl.hpp @@ -36,8 +36,7 @@ namespace Opm linearIterations_(0), wellIterations_(0), nonlinearIterationsLast_(0), - linearIterationsLast_(0), - wellIterationsLast_(0) + linearIterationsLast_(0) { if (!model_) { OPM_THROW(std::logic_error, "Must provide a non-null model argument for NonlinearSolver."); @@ -86,12 +85,6 @@ namespace Opm return linearIterationsLast_; } - template - int NonlinearSolver::wellIterationsLastStep() const - { - return wellIterationsLast_; - } - template int @@ -151,7 +144,6 @@ namespace Opm linearIterations_ += linIters; nonlinearIterations_ += iteration - 1; // Since the last one will always be trivial. wellIterations_ = wellIters; - wellIterationsLast_ = wellIters; linearIterationsLast_ = linIters; nonlinearIterationsLast_ = iteration; From 3f4aa651804b77d43ae10790d87017cbfede4aa8 Mon Sep 17 00:00:00 2001 From: Liu Ming Date: Wed, 20 Jul 2016 10:44:12 +0800 Subject: [PATCH 5/5] add wellIterationsLast_. --- opm/autodiff/NonlinearSolver.hpp | 4 ++++ opm/autodiff/NonlinearSolver_impl.hpp | 11 +++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/opm/autodiff/NonlinearSolver.hpp b/opm/autodiff/NonlinearSolver.hpp index f2d814a95..fdc80ada6 100644 --- a/opm/autodiff/NonlinearSolver.hpp +++ b/opm/autodiff/NonlinearSolver.hpp @@ -117,6 +117,9 @@ namespace Opm { /// Number of linear solver iterations used in the last call to step(). int linearIterationsLastStep() const; + /// Number of well iterations used in all calls to step(). + int wellIterationsLastStep() const; + /// Reference to physical model. const PhysicalModel& model() const; @@ -157,6 +160,7 @@ namespace Opm { int wellIterations_; int nonlinearIterationsLast_; int linearIterationsLast_; + int wellIterationsLast_; }; } // namespace Opm diff --git a/opm/autodiff/NonlinearSolver_impl.hpp b/opm/autodiff/NonlinearSolver_impl.hpp index b6280c0a0..0ed45cce2 100644 --- a/opm/autodiff/NonlinearSolver_impl.hpp +++ b/opm/autodiff/NonlinearSolver_impl.hpp @@ -36,7 +36,8 @@ namespace Opm linearIterations_(0), wellIterations_(0), nonlinearIterationsLast_(0), - linearIterationsLast_(0) + linearIterationsLast_(0), + wellIterationsLast_(0) { if (!model_) { OPM_THROW(std::logic_error, "Must provide a non-null model argument for NonlinearSolver."); @@ -85,6 +86,11 @@ namespace Opm return linearIterationsLast_; } + template + int NonlinearSolver::wellIterationsLastStep() const + { + return wellIterationsLast_; + } template int @@ -143,9 +149,10 @@ namespace Opm linearIterations_ += linIters; nonlinearIterations_ += iteration - 1; // Since the last one will always be trivial. - wellIterations_ = wellIters; + wellIterations_ += wellIters; linearIterationsLast_ = linIters; nonlinearIterationsLast_ = iteration; + wellIterationsLast_ = wellIters; // Do model-specific post-step actions. model_->afterStep(dt, reservoir_state, well_state);