From 627c3be1f957f568f6bfcc0810bced1d11d43f50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A5rd=20Skaflestad?= Date: Mon, 16 Apr 2012 19:27:34 +0200 Subject: [PATCH 1/4] InjectionSpecification: Split long lines. No functional changes. --- opm/core/InjectionSpecification.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/opm/core/InjectionSpecification.cpp b/opm/core/InjectionSpecification.cpp index 7ed0d2251..da9a50007 100644 --- a/opm/core/InjectionSpecification.cpp +++ b/opm/core/InjectionSpecification.cpp @@ -3,11 +3,15 @@ namespace Opm { InjectionSpecification::InjectionSpecification() - : injector_type_(WATER), control_mode_(NONE), surface_flow_max_rate_(1e100), - reinjection_fraction_target_(0.0), BHP_limit_(1e100), fluid_volume_max_rate_(1e100) + : injector_type_(WATER), + control_mode_(NONE), + surface_flow_max_rate_(1e100), + reinjection_fraction_target_(0.0), + BHP_limit_(1e100), + fluid_volume_max_rate_(1e100) { } -} // namespace Opm \ No newline at end of file +} // namespace Opm From 57d6bc9b035463e888de2a2e7dbc0e48d4dd87a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A5rd=20Skaflestad?= Date: Mon, 16 Apr 2012 19:29:22 +0200 Subject: [PATCH 2/4] InjectionSpecification: Initialise fields in declaration order. --- opm/core/InjectionSpecification.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/opm/core/InjectionSpecification.cpp b/opm/core/InjectionSpecification.cpp index da9a50007..fe6a12535 100644 --- a/opm/core/InjectionSpecification.cpp +++ b/opm/core/InjectionSpecification.cpp @@ -7,8 +7,8 @@ namespace Opm control_mode_(NONE), surface_flow_max_rate_(1e100), reinjection_fraction_target_(0.0), - BHP_limit_(1e100), - fluid_volume_max_rate_(1e100) + fluid_volume_max_rate_(1e100), + BHP_limit_(1e100) { } From 95818d1f022efe15e5e8105a3d7ab9e1a2ab57e2 Mon Sep 17 00:00:00 2001 From: Kjetil Olsen Lye Date: Tue, 17 Apr 2012 08:59:20 +0200 Subject: [PATCH 3/4] Added shutdown of wells when they exceed their limits (if procedure = shut). --- opm/core/WellsGroup.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/opm/core/WellsGroup.cpp b/opm/core/WellsGroup.cpp index 1ab1e0343..3d49f334d 100644 --- a/opm/core/WellsGroup.cpp +++ b/opm/core/WellsGroup.cpp @@ -130,6 +130,7 @@ namespace Opm int number_of_leaf_nodes = numberOfLeafNodes(); + bool shut_down_on_exceed = false; double bhp_target = 1e100; double rate_target = 1e100; switch(wells->type[index_of_well]) { @@ -145,6 +146,7 @@ namespace Opm const ProductionSpecification& prod_spec = prodSpec(); bhp_target = prod_spec.BHP_limit_ / number_of_leaf_nodes; rate_target = prod_spec.fluid_volume_max_rate_ / number_of_leaf_nodes; + shut_down_on_exceed = prodSpec().procedure_ == ProductionSpecification::Well; break; } } @@ -153,12 +155,22 @@ namespace Opm std::cout << "BHP not met" << std::endl; std::cout << "BHP limit was " << bhp_target << std::endl; std::cout << "Actual bhp was " << well_bhp[index_of_well] << std::endl; + + if(shut_down_on_exceed) { + // Shut down well + wells->ctrls->target = 0.0; + } return false; } if(well_rate[index_of_well] - rate_target > epsilon) { std::cout << "well_rate not met" << std::endl; std::cout << "target = " << rate_target << ", well_rate[index_of_well] = " << well_rate[index_of_well] << std::endl; std::cout << "Group name = " << name() << std::endl; + + if(shut_down_on_exceed) { + // Shut down well + wells->ctrls->target = 0.0; + } return false; } return true; From b0b13c71f9791d1e521ef3580db70426fe5a38e0 Mon Sep 17 00:00:00 2001 From: Kjetil Olsen Lye Date: Tue, 17 Apr 2012 09:19:06 +0200 Subject: [PATCH 4/4] Fixed a compilation bug, also adjusted computeWDP slightly to allow for either a saturation vector by grid cells or by well cells --- opm/core/WellsGroup.cpp | 11 ++++++++--- opm/core/utility/miscUtilities.cpp | 22 ++++++++++++++++------ opm/core/utility/miscUtilities.hpp | 6 ++++-- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/opm/core/WellsGroup.cpp b/opm/core/WellsGroup.cpp index 3d49f334d..6bf82b391 100644 --- a/opm/core/WellsGroup.cpp +++ b/opm/core/WellsGroup.cpp @@ -7,6 +7,7 @@ #include #include +#include namespace Opm { @@ -146,7 +147,7 @@ namespace Opm const ProductionSpecification& prod_spec = prodSpec(); bhp_target = prod_spec.BHP_limit_ / number_of_leaf_nodes; rate_target = prod_spec.fluid_volume_max_rate_ / number_of_leaf_nodes; - shut_down_on_exceed = prodSpec().procedure_ == ProductionSpecification::Well; + shut_down_on_exceed = prodSpec().procedure_ == ProductionSpecification::WELL; break; } } @@ -158,7 +159,9 @@ namespace Opm if(shut_down_on_exceed) { // Shut down well - wells->ctrls->target = 0.0; + // Dirty hack for now + struct Wells* non_const_wells = const_cast(wells); + non_const_wells->ctrls[index_of_well]->target[0] = 0.0; } return false; } @@ -169,7 +172,9 @@ namespace Opm if(shut_down_on_exceed) { // Shut down well - wells->ctrls->target = 0.0; + // Dirty hack for now + struct Wells* non_const_wells = const_cast(wells); + non_const_wells->ctrls[index_of_well]->target[0] = 0.0; } return false; } diff --git a/opm/core/utility/miscUtilities.cpp b/opm/core/utility/miscUtilities.cpp index 5dfbbdad4..2ac7f8c5e 100644 --- a/opm/core/utility/miscUtilities.cpp +++ b/opm/core/utility/miscUtilities.cpp @@ -406,12 +406,12 @@ namespace Opm void computeWDP(const Wells& wells, const UnstructuredGrid& grid, const std::vector& saturations, - const std::vector& densities, std::vector& wdp) + const std::vector& densities, std::vector& wdp, bool per_grid_cell) { const size_t np = densities.size(); - + const int nw = wells.number_of_wells; // Simple for now: - for(int i = 0; i < wells.number_of_wells; i++) { + for(int i = 0; i < nw; i++) { double depth_ref = wells.depth_ref[i]; for(int j = wells.well_connpos[i]; j < wells.well_connpos[i+1]; j++) { int cell = wells.well_cells[j]; @@ -421,15 +421,25 @@ namespace Opm double saturation_sum = 0.0; for(size_t p = 0; p < np; p++) { - saturation_sum += saturations[np*cell + p]; + if(per_grid_cell) { + saturation_sum += saturations[i*nw*np + j*np + p]; + } + else { + saturation_sum += saturations[np*cell + p]; + } } if(saturation_sum == 0) { saturation_sum = 1.0; } double density = 0.0; for(size_t p = 0; p < np; p++) { - // Is this a smart way of doing it? - density += saturations[np*cell + p] * densities[p] / saturation_sum; + if(per_grid_cell) { + density += saturations[i*nw*np + j*np + p] * densities[p] / saturation_sum; + } + else { + // Is this a smart way of doing it? + density += saturations[np*cell + p] * densities[p] / saturation_sum; + } } // Is the sign correct? diff --git a/opm/core/utility/miscUtilities.hpp b/opm/core/utility/miscUtilities.hpp index 4334aba97..40e0c6be2 100644 --- a/opm/core/utility/miscUtilities.hpp +++ b/opm/core/utility/miscUtilities.hpp @@ -180,13 +180,15 @@ namespace Opm /// \param[in] wells Wells that need their wdp calculated. /// \param[in] grid The associated grid to make cell lookups. /// \param[in] saturations A vector of weights for each cell for each phase - /// in the grid. So for cell i, + /// in the grid (or well, see per_grid_cell parameter). So for cell i, /// saturations[i*densities.size() + p] should give the weight /// of phase p in cell i. /// \param[in] densities Density for each phase. /// \param[out] wdp Will contain, for each well, the wdp of the well. + /// \param[in] per_grid_cell Whether or not the saturations are per grid cell or per + /// well cell. void computeWDP(const Wells& wells, const UnstructuredGrid& grid, const std::vector& saturations, - const std::vector& densities, std::vector& wdp); + const std::vector& densities, std::vector& wdp, bool per_grid_cell = true); /// Computes (sums) the flow rate for each well. /// \param[in] wells The wells for which the flow rate should be computed.