From 8b0c10182480009e581cb3f8aea01cf2d2e2e4c6 Mon Sep 17 00:00:00 2001 From: Kjetil Olsen Lye Date: Thu, 3 May 2012 15:35:44 +0200 Subject: [PATCH] Made a maximum number of iterations in wells_test --- examples/wells_example.cpp | 2 +- opm/core/WellsGroup.cpp | 28 ++++++++++++++++++---------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/examples/wells_example.cpp b/examples/wells_example.cpp index ccb2a028..32451a7e 100644 --- a/examples/wells_example.cpp +++ b/examples/wells_example.cpp @@ -106,7 +106,7 @@ int main(int argc, char** argv) { } // We approximate (for _testing_ that resflows = surfaceflows) - while (!wells.conditionsMet(well_bhp, well_resflows, well_resflows)) { + for (int iter = 0; iter < 10 && !wells.conditionsMet(well_bhp, well_resflows, well_resflows); ++iter) { std::cout << "Conditions not met for well, trying again" << std::endl; pressure_solver.solve(totmob, omega, src, wdp, bcs.c_bcs(), pressure, face_flux, well_bhp, well_rate_per_cell); std::cout << "Solved" << std::endl; diff --git a/opm/core/WellsGroup.cpp b/opm/core/WellsGroup.cpp index 21a1c6ba..77a32b99 100644 --- a/opm/core/WellsGroup.cpp +++ b/opm/core/WellsGroup.cpp @@ -174,6 +174,9 @@ namespace Opm case ProductionSpecification::GRAT: target = prodSpec().gas_max_rate_; break; + case ProductionSpecification::WRAT: + target = prodSpec().water_max_rate_; + break; case ProductionSpecification::ORAT: target = prodSpec().oil_max_rate_; break; @@ -285,6 +288,7 @@ namespace Opm const double my_guide_rate = productionGuideRate(!forced); if (my_guide_rate == 0.0) { // Nothing to do here + std::cout << "returning" << std::endl; return; } for (size_t i = 0; i < children_.size(); ++i) { @@ -381,6 +385,7 @@ namespace Opm production_mode_violated).first->shutWell(); return false; case ProductionSpecification::RATE: + std::cout << "Applying group control" << std::endl; applyProdGroupControl(production_mode_violated, getTarget(production_mode_violated), true); @@ -439,7 +444,9 @@ namespace Opm case ProductionSpecification::RESV: { const double my_guide_rate = productionGuideRate(true); - ASSERT(my_guide_rate != 0.0); + if (my_guide_rate == 0) { + THROW("Can't apply group control for group " << name() << " as the sum of guide rates for all group controlled wells is zero."); + } for (size_t i = 0; i < children_.size(); ++i ) { // Apply for all children. // Note, we do _not_ want to call the applyProdGroupControl in this object, @@ -471,27 +478,27 @@ namespace Opm case InjectionSpecification::RESV: { const double my_guide_rate = injectionGuideRate(true); - for (size_t i = 0; i < children_.size(); ++i ) { + for (size_t i = 0; i < children_.size(); ++i) { // Apply for all children. // Note, we do _not_ want to call the applyProdGroupControl in this object, // as that would check if we're under group control, something we're not. const double children_guide_rate = children_[i]->injectionGuideRate(true); - children_[i]->applyInjGroupControl(inj_mode, - (children_guide_rate / my_guide_rate) * getTarget(inj_mode), - false); + children_[i]->applyInjGroupControl(inj_mode, + (children_guide_rate / my_guide_rate) * getTarget(inj_mode), + false); } - break; + return; } case InjectionSpecification::REIN: std::cout << "WARNING: Ignoring control type REIN" << std::endl; - break; + return; case InjectionSpecification::FLD: case InjectionSpecification::NONE: // Call all children for (size_t i = 0; i < children_.size(); ++i ) { children_[i]->applyInjGroupControls(); } - break; + return; default: THROW("Unhandled group injection control mode " << inj_mode); } @@ -811,7 +818,8 @@ namespace Opm /// wells under group control double WellNode::productionGuideRate(bool only_group) { - if (only_group || prodSpec().control_mode_ == ProductionSpecification::GRUP) { + if (!only_group || prodSpec().control_mode_ == ProductionSpecification::GRUP) { + std::cout << prodSpec().guide_rate_ << std::endl; return prodSpec().guide_rate_; } return 0.0; @@ -822,7 +830,7 @@ namespace Opm /// wells under group control double WellNode::injectionGuideRate(bool only_group) { - if (only_group || injSpec().control_mode_ == InjectionSpecification::GRUP) { + if (!only_group || injSpec().control_mode_ == InjectionSpecification::GRUP) { return injSpec().guide_rate_; } return 0.0;