From 4689dd2af718d687da87bc322f028a514493a3bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atgeirr=20Fl=C3=B8=20Rasmussen?= Date: Fri, 15 Jun 2012 10:51:34 +0200 Subject: [PATCH 01/13] Fix output from SimulatorReport. --- opm/core/simulator/SimulatorReport.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opm/core/simulator/SimulatorReport.cpp b/opm/core/simulator/SimulatorReport.cpp index 3d8e0c048..1fa264597 100644 --- a/opm/core/simulator/SimulatorReport.cpp +++ b/opm/core/simulator/SimulatorReport.cpp @@ -40,7 +40,7 @@ namespace Opm { os << "Total time taken: " << total_time << "\n Pressure time: " << pressure_time - << "\n Transport time: " << total_time << std::endl; + << "\n Transport time: " << transport_time << std::endl; } From 2a631282fc68f8c44aca33edfa2a409e783d09a7 Mon Sep 17 00:00:00 2001 From: Kjetil Olsen Lye Date: Fri, 15 Jun 2012 13:38:07 +0200 Subject: [PATCH 02/13] Added initial shutting of injection wells. --- opm/core/wells/WellsManager.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/opm/core/wells/WellsManager.cpp b/opm/core/wells/WellsManager.cpp index 985df5f81..2bca148ca 100644 --- a/opm/core/wells/WellsManager.cpp +++ b/opm/core/wells/WellsManager.cpp @@ -490,6 +490,10 @@ namespace Opm if (cpos == -1 && mode != InjectionControl::GRUP) { THROW("Control for " << wci_line.control_mode_ << " not specified in well " << well_names[wix]); } + // We need to check if the well is shut or not + if (wci_line.open_shut_flag_ == "SHUT") { + cpos = ~cpos; + } set_current_control(wix, cpos, w_); // Set well component fraction. From c0717c0f7cce366df3a55bb9a22c4132729ed2ac Mon Sep 17 00:00:00 2001 From: Kjetil Olsen Lye Date: Fri, 15 Jun 2012 13:49:58 +0200 Subject: [PATCH 03/13] Added welshut for production wells. Also added wellopen-handling. --- opm/core/wells/WellsManager.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/opm/core/wells/WellsManager.cpp b/opm/core/wells/WellsManager.cpp index 2bca148ca..89f941575 100644 --- a/opm/core/wells/WellsManager.cpp +++ b/opm/core/wells/WellsManager.cpp @@ -618,6 +618,10 @@ namespace Opm if (cpos == -1 && mode != ProductionControl::GRUP) { THROW("Control mode type " << mode << " not present in well " << well_names[wix]); } + // If it's shut, we complement the cpos + if (wcp_line.open_shut_flag_ == "SHUT") { + cpos = ~cpos; // So we can easily retrieve the cpos later + } set_current_control(wix, cpos, w_); } } @@ -677,6 +681,28 @@ namespace Opm */ #endif + if (deck.hasField("WELOPEN")) { + const WELOPEN& welopen = deck.getWELOPEN(); + + for (size_t i = 0; i < welopen.welopen.size(); ++i) { + WelopenLine line = welopen.welopen[i]; + std::string wellname = line.well_; + std::map::const_iterator it = well_names_to_index.find(wellname); + if (it == well_names_to_index.end()) { + THROW("Trying to open well with name: \"" << wellname<<"\" but it's not registered under WELSPECS."); + } + int index = it->second; + + // We don't open already open wells + /// \TODO Should this perhaps be allowed? I.e. should it be if(well_shut) { shutwell(); } else { /* do nothing*/ }? + ASSERT(w_->ctrls[index]->current < 0); + + // We revert back to it's original control. + // Note that this is OK as ~~ = id. + w_->ctrls[index]->current = ~w_->ctrls[index]->current; + + } + } // Build the well_collection_ well group hierarchy. if (deck.hasField("GRUPTREE")) { From 6f227044067d29cbab3178bc6afefe8505263856 Mon Sep 17 00:00:00 2001 From: Kjetil Olsen Lye Date: Fri, 15 Jun 2012 13:57:35 +0200 Subject: [PATCH 04/13] Correct a const error. --- opm/core/wells/WellsManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/opm/core/wells/WellsManager.cpp b/opm/core/wells/WellsManager.cpp index 89f941575..5aa1bded8 100644 --- a/opm/core/wells/WellsManager.cpp +++ b/opm/core/wells/WellsManager.cpp @@ -486,7 +486,7 @@ namespace Opm THROW("Failure occured appending controls for well " << well_names[wix]); } InjectionControl::Mode mode = InjectionControl::mode(wci_line.control_mode_); - const int cpos = control_pos[mode]; + int cpos = control_pos[mode]; if (cpos == -1 && mode != InjectionControl::GRUP) { THROW("Control for " << wci_line.control_mode_ << " not specified in well " << well_names[wix]); } @@ -614,7 +614,7 @@ namespace Opm THROW("Failure occured appending controls for well " << well_names[wix]); } ProductionControl::Mode mode = ProductionControl::mode(wcp_line.control_mode_); - const int cpos = control_pos[mode]; + int cpos = control_pos[mode]; if (cpos == -1 && mode != ProductionControl::GRUP) { THROW("Control mode type " << mode << " not present in well " << well_names[wix]); } From 1a37c410fc77065a516bdff159d90378c2bd4ce3 Mon Sep 17 00:00:00 2001 From: Kjetil Olsen Lye Date: Fri, 15 Jun 2012 14:08:28 +0200 Subject: [PATCH 05/13] Made the grouptree respect the new convention of tilde. --- opm/core/wells/WellsGroup.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/opm/core/wells/WellsGroup.cpp b/opm/core/wells/WellsGroup.cpp index 3da16f776..afa17f12d 100644 --- a/opm/core/wells/WellsGroup.cpp +++ b/opm/core/wells/WellsGroup.cpp @@ -737,7 +737,9 @@ namespace Opm void WellNode::shutWell() { if (shut_well_) { - set_current_control(self_index_, -1, wells_); + // We set the tilde of the current control + // set_current_control(self_index_, -1, wells_); + wells_->ctrls[self_index_]->current = ~ wells_->ctrls[self_index_]->current; } else { const double target = 0.0; @@ -755,7 +757,7 @@ namespace Opm wells_->ctrls[self_index_]->target[group_control_index_] = target; std::copy(distr, distr + np, wells_->ctrls[self_index_]->distr + np * group_control_index_); } - set_current_control(self_index_, -1, wells_); + wells_->ctrls[self_index_]->current = ~ wells_->ctrls[self_index_]->current; } } From 068cbf06054787daa29763805d3acd62af1df8c6 Mon Sep 17 00:00:00 2001 From: Kjetil Olsen Lye Date: Fri, 15 Jun 2012 14:29:43 +0200 Subject: [PATCH 06/13] Handle WellOpen has both open and shut. --- opm/core/wells/WellsManager.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/opm/core/wells/WellsManager.cpp b/opm/core/wells/WellsManager.cpp index 5aa1bded8..2f8eb455e 100644 --- a/opm/core/wells/WellsManager.cpp +++ b/opm/core/wells/WellsManager.cpp @@ -689,18 +689,24 @@ namespace Opm std::string wellname = line.well_; std::map::const_iterator it = well_names_to_index.find(wellname); if (it == well_names_to_index.end()) { - THROW("Trying to open well with name: \"" << wellname<<"\" but it's not registered under WELSPECS."); + THROW("Trying to open/shut well with name: \"" << wellname<<"\" but it's not registered under WELSPECS."); } int index = it->second; - - // We don't open already open wells - /// \TODO Should this perhaps be allowed? I.e. should it be if(well_shut) { shutwell(); } else { /* do nothing*/ }? - ASSERT(w_->ctrls[index]->current < 0); + if (line.openshutflag_ == "SHUT") { + // We don't open already open wells + /// \TODO Should this perhaps be allowed? I.e. should it be if(well_shut) { shutwell(); } else { /* do nothing*/ }? + ASSERT(w_->ctrls[index]->current < 0); + } else if (line.openshutflag_ == "OPEN") { + ASSERT(w_->ctrls[index]->current >= 0); + } else { + THROW("Unknown Open/close keyword: \"" << line.openshutflag_<< "\". Allowed values: OPEN, SHUT."); + } // We revert back to it's original control. // Note that this is OK as ~~ = id. w_->ctrls[index]->current = ~w_->ctrls[index]->current; + } } From dec0e60bd4835f872d9119505b993b7bf43c59fb Mon Sep 17 00:00:00 2001 From: Kjetil Olsen Lye Date: Fri, 15 Jun 2012 15:16:32 +0200 Subject: [PATCH 07/13] Removed errors on trying to open a shut well (or shut an open well). --- opm/core/wells/WellsManager.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/opm/core/wells/WellsManager.cpp b/opm/core/wells/WellsManager.cpp index 2f8eb455e..40a348946 100644 --- a/opm/core/wells/WellsManager.cpp +++ b/opm/core/wells/WellsManager.cpp @@ -693,11 +693,11 @@ namespace Opm } int index = it->second; if (line.openshutflag_ == "SHUT") { - // We don't open already open wells + // We currently don't care if the well is open or not. /// \TODO Should this perhaps be allowed? I.e. should it be if(well_shut) { shutwell(); } else { /* do nothing*/ }? - ASSERT(w_->ctrls[index]->current < 0); + //ASSERT(w_->ctrls[index]->current < 0); } else if (line.openshutflag_ == "OPEN") { - ASSERT(w_->ctrls[index]->current >= 0); + //ASSERT(w_->ctrls[index]->current >= 0); } else { THROW("Unknown Open/close keyword: \"" << line.openshutflag_<< "\". Allowed values: OPEN, SHUT."); } From 6fbf50827f4c5899aa24254a3f50a137d451ee29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A5rd=20Skaflestad?= Date: Mon, 18 Jun 2012 10:15:53 +0200 Subject: [PATCH 08/13] Add support for storing well names in "Wells" structure. The well name must be passed as a parameter to add_well(), so update callers accordingly. --- opm/core/newwells.h | 2 ++ opm/core/wells/WellsManager.cpp | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/opm/core/newwells.h b/opm/core/newwells.h index 710df7c73..e19e8c55e 100644 --- a/opm/core/newwells.h +++ b/opm/core/newwells.h @@ -100,6 +100,7 @@ struct Wells double *WI; /** Well productivity index, same size and structure as well_cells. */ struct WellControls **ctrls; /** Well controls, one set of controls for each well. */ + char **name; /** Well names. One string for each well. */ void *data; /** Internal management structure. */ }; @@ -180,6 +181,7 @@ add_well(enum WellType type , const double *comp_frac, const int *cells , const double *WI , + const char *name , struct Wells *W ); diff --git a/opm/core/wells/WellsManager.cpp b/opm/core/wells/WellsManager.cpp index 40a348946..d883f0367 100644 --- a/opm/core/wells/WellsManager.cpp +++ b/opm/core/wells/WellsManager.cpp @@ -425,7 +425,7 @@ namespace Opm // We initialize all wells with a null component fraction, // and must (for injection wells) overwrite it later. int ok = add_well(well_data[w].type, well_data[w].reference_bhp_depth, w_num_perf, - comp_frac, &perf_cells[0], &perf_prodind[0], w_); + comp_frac, &perf_cells[0], &perf_prodind[0], well_names[w].c_str(), w_); if (!ok) { THROW("Failed adding well " << well_names[w] << " to Wells data structure."); } From 1795e6b1a7d0fb99c273385d228724eae93e761d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A5rd=20Skaflestad?= Date: Mon, 18 Jun 2012 10:18:14 +0200 Subject: [PATCH 09/13] Document add_well()s "name" parameter. Forgotten in cset 728302a69229. --- opm/core/newwells.h | 1 + 1 file changed, 1 insertion(+) diff --git a/opm/core/newwells.h b/opm/core/newwells.h index e19e8c55e..f16675b6c 100644 --- a/opm/core/newwells.h +++ b/opm/core/newwells.h @@ -169,6 +169,7 @@ create_wells(int nphases, int nwells, int nperf); * \param[in] cells Grid cells in which well is perforated. Should * ideally be track ordered. * \param[in] WI Well production index per perforation, or NULL. + * \param[in] name Name of new well. NULL if no name. * \param[in,out] W Existing set of wells to which new well will * be added. * From 5ad262ec845077e7cced8ffcaebd6affec08aab9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A5rd=20Skaflestad?= Date: Mon, 18 Jun 2012 15:21:27 +0200 Subject: [PATCH 10/13] *Control::mode(): Defer keyword look-up to std::find() algorithm. This is simpler than implementing our own version of the same. --- opm/core/wells/WellsManager.cpp | 55 +++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/opm/core/wells/WellsManager.cpp b/opm/core/wells/WellsManager.cpp index d883f0367..a35c8fab0 100644 --- a/opm/core/wells/WellsManager.cpp +++ b/opm/core/wells/WellsManager.cpp @@ -29,6 +29,11 @@ #include #include +#include +#include + +#include +#include // Helper structs and functions for the implementation. @@ -56,21 +61,28 @@ namespace { enum Mode { ORAT, WRAT, GRAT, LRAT, CRAT, RESV, - BHP, THP, GRUP }; + BHP , THP , GRUP }; + Mode mode(const std::string& control) { - const int num_prod_control_modes = 9; - static std::string prod_control_modes[num_prod_control_modes] = + static std::string prod_control_modes[] = {std::string("ORAT"), std::string("WRAT"), std::string("GRAT"), std::string("LRAT"), std::string("CRAT"), std::string("RESV"), - std::string("BHP"), std::string("THP"), std::string("GRUP") }; + std::string("BHP") , std::string("THP") , std::string("GRUP") }; + + static const std::size_t num_prod_control_modes = + sizeof(prod_control_modes) / sizeof(prod_control_modes[0]); + + const std::string* p = + std::find(prod_control_modes, + prod_control_modes + num_prod_control_modes, + control); + int m = -1; - for (int i=0; i= 0) { return static_cast(m); } else { @@ -84,18 +96,23 @@ namespace { enum Mode { RATE, RESV, BHP, THP, GRUP }; + Mode mode(const std::string& control) { - const int num_inje_control_modes = 5; - static std::string inje_control_modes[num_inje_control_modes] = + static std::string inje_control_modes[] = {std::string("RATE"), std::string("RESV"), std::string("BHP"), - std::string("THP"), std::string("GRUP") }; + std::string("THP") , std::string("GRUP") }; + + static const std::size_t num_inje_control_modes = + sizeof(inje_control_modes) / sizeof(inje_control_modes[0]); + + const std::string* p = + std::find(inje_control_modes, + inje_control_modes + num_inje_control_modes, + control); int m = -1; - for (int i=0; i= 0) { @@ -408,10 +425,10 @@ namespace Opm } else { THROW("Unseen well name: " << lines[i].well_ << " first seen in WCONPROD"); } - + } } - + // Add wells. for (int w = 0; w < num_wells; ++w) { const int w_num_perf = wellperf_data[w].size(); From 7fc7972e93c9d315675adcc1ad0053bbb9e2331f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A5rd=20Skaflestad?= Date: Tue, 19 Jun 2012 00:01:30 +0200 Subject: [PATCH 11/13] Sort includes. --- opm/core/wells/WellsManager.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/opm/core/wells/WellsManager.cpp b/opm/core/wells/WellsManager.cpp index a35c8fab0..2735b722f 100644 --- a/opm/core/wells/WellsManager.cpp +++ b/opm/core/wells/WellsManager.cpp @@ -28,11 +28,10 @@ #include #include +#include +#include #include #include -#include - -#include #include From c4342bd16b97b25cbf8efbfadcc8129901f2094e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A5rd=20Skaflestad?= Date: Tue, 19 Jun 2012 00:30:32 +0200 Subject: [PATCH 12/13] *Control::mode(): Defer control-mode look-up to std::map. --- opm/core/wells/WellsManager.cpp | 91 ++++++++++++++++++++------------- 1 file changed, 55 insertions(+), 36 deletions(-) diff --git a/opm/core/wells/WellsManager.cpp b/opm/core/wells/WellsManager.cpp index 2735b722f..b7be00878 100644 --- a/opm/core/wells/WellsManager.cpp +++ b/opm/core/wells/WellsManager.cpp @@ -33,6 +33,9 @@ #include #include #include +#include +#include +#include // Helper structs and functions for the implementation. @@ -62,30 +65,39 @@ namespace LRAT, CRAT, RESV, BHP , THP , GRUP }; + namespace Details { + std::map + init_mode_map() { + std::map m; + + m.insert(std::make_pair("ORAT", ORAT)); + m.insert(std::make_pair("WRAT", WRAT)); + m.insert(std::make_pair("GRAT", GRAT)); + m.insert(std::make_pair("LRAT", LRAT)); + m.insert(std::make_pair("CRAT", CRAT)); + m.insert(std::make_pair("RESV", RESV)); + m.insert(std::make_pair("BHP" , BHP )); + m.insert(std::make_pair("THP" , THP )); + m.insert(std::make_pair("GRUP", GRUP)); + + return m; + } + } // namespace Details + Mode mode(const std::string& control) { - static std::string prod_control_modes[] = - {std::string("ORAT"), std::string("WRAT"), std::string("GRAT"), - std::string("LRAT"), std::string("CRAT"), std::string("RESV"), - std::string("BHP") , std::string("THP") , std::string("GRUP") }; + static std::map + mode_map = Details::init_mode_map(); - static const std::size_t num_prod_control_modes = - sizeof(prod_control_modes) / sizeof(prod_control_modes[0]); + std::map::iterator + p = mode_map.find(control); - const std::string* p = - std::find(prod_control_modes, - prod_control_modes + num_prod_control_modes, - control); - - int m = -1; - if (p != prod_control_modes + num_prod_control_modes) { - m = int(p - prod_control_modes); + if (p != mode_map.end()) { + return p->second; } - - if (m >= 0) { - return static_cast(m); - } else { - THROW("Unknown well control mode = " << control << " in input file"); + else { + THROW("Unknown well control mode = " + << control << " in input file"); } } } // namespace ProductionControl @@ -96,28 +108,35 @@ namespace enum Mode { RATE, RESV, BHP, THP, GRUP }; + namespace Details { + std::map + init_mode_map() { + std::map m; + + m.insert(std::make_pair("RATE", RATE)); + m.insert(std::make_pair("RESV", RESV)); + m.insert(std::make_pair("BHP" , BHP )); + m.insert(std::make_pair("THP" , THP )); + m.insert(std::make_pair("GRUP", GRUP)); + + return m; + } + } // namespace Details + Mode mode(const std::string& control) { - static std::string inje_control_modes[] = - {std::string("RATE"), std::string("RESV"), std::string("BHP"), - std::string("THP") , std::string("GRUP") }; + static std::map + mode_map = Details::init_mode_map(); - static const std::size_t num_inje_control_modes = - sizeof(inje_control_modes) / sizeof(inje_control_modes[0]); + std::map::iterator + p = mode_map.find(control); - const std::string* p = - std::find(inje_control_modes, - inje_control_modes + num_inje_control_modes, - control); - int m = -1; - if (p != inje_control_modes + num_inje_control_modes) { - m = int(p - inje_control_modes); + if (p != mode_map.end()) { + return p->second; } - - if (m >= 0) { - return static_cast(m); - } else { - THROW("Unknown well control mode = " << control << " in input file"); + else { + THROW("Unknown well control mode = " + << control << " in input file"); } } } // namespace InjectionControl From fe9cc7f29a637150b9effad864b5c0ecd3a73700 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A5rd=20Skaflestad?= Date: Tue, 19 Jun 2012 09:34:34 +0200 Subject: [PATCH 13/13] Prune an unused header. --- opm/core/wells/WellsManager.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/opm/core/wells/WellsManager.cpp b/opm/core/wells/WellsManager.cpp index b7be00878..0215b053e 100644 --- a/opm/core/wells/WellsManager.cpp +++ b/opm/core/wells/WellsManager.cpp @@ -32,7 +32,6 @@ #include #include #include -#include #include #include #include