From 78006cff402ffd8483255d363f021cf9c84e696e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atgeirr=20Fl=C3=B8=20Rasmussen?= Date: Fri, 20 Apr 2012 09:50:36 +0200 Subject: [PATCH] Renamed some enums and functions relating to Wells, and started documenting it. --- opm/core/InjectionSpecification.hpp | 2 +- opm/core/WellsGroup.cpp | 4 +- opm/core/WellsManager.cpp | 22 +++--- opm/core/newwells.h | 108 +++++++++++++++++++--------- opm/core/utility/newwells.c | 16 ++--- 5 files changed, 97 insertions(+), 55 deletions(-) diff --git a/opm/core/InjectionSpecification.hpp b/opm/core/InjectionSpecification.hpp index 3cd164a8..772815b3 100644 --- a/opm/core/InjectionSpecification.hpp +++ b/opm/core/InjectionSpecification.hpp @@ -15,7 +15,7 @@ namespace Opm InjectionSpecification(); - surface_component injector_type_; + SurfaceComponent injector_type_; ControlMode control_mode_; double surface_flow_max_rate_; double reinjection_fraction_target_; diff --git a/opm/core/WellsGroup.cpp b/opm/core/WellsGroup.cpp index 6bf82b39..18bcea2e 100644 --- a/opm/core/WellsGroup.cpp +++ b/opm/core/WellsGroup.cpp @@ -287,7 +287,7 @@ namespace Opm namespace { - surface_component toSurfaceComponent(std::string type) + SurfaceComponent toSurfaceComponent(std::string type) { if (type == "OIL") { return OIL; @@ -298,7 +298,7 @@ namespace Opm if (type == "GAS") { return GAS; } - THROW("Unknown type " << type << ", could not convert to surface_component"); + THROW("Unknown type " << type << ", could not convert to SurfaceComponent"); } InjectionSpecification::ControlMode toInjectionControlMode(std::string type) diff --git a/opm/core/WellsManager.cpp b/opm/core/WellsManager.cpp index dd386d69..f0933649 100644 --- a/opm/core/WellsManager.cpp +++ b/opm/core/WellsManager.cpp @@ -36,11 +36,11 @@ namespace struct WellData { - well_type type; - control_type control; + WellType type; + WellControlType control; double target; double reference_bhp_depth; - surface_component injected_phase; + SurfaceComponent injected_phase; }; @@ -573,7 +573,7 @@ namespace Opm // Set up the Wells struct. - w_ = wells_create(num_wells, num_perfs); + w_ = create_wells(num_wells, num_perfs); if (!w_) { THROW("Failed creating Wells struct."); } @@ -590,28 +590,26 @@ namespace Opm } const double* zfrac = (well_data[w].type == INJECTOR) ? fracs[well_data[w].injected_phase] : 0; - int ok = wells_add(well_data[w].type, well_data[w].reference_bhp_depth, nperf, + int ok = add_wells(well_data[w].type, well_data[w].reference_bhp_depth, nperf, zfrac, &cells[0], &wi[0], w_); if (!ok) { THROW("Failed to add a well."); } // We only append a single control at this point. // TODO: Handle multiple controls. - ok = well_controls_append(well_data[w].control, well_data[w].target, w_->ctrls[w]); + ok = append_well_controls(well_data[w].control, well_data[w].target, w_->ctrls[w]); w_->ctrls[w]->current = 0; if (!ok) { THROW("Failed to add well controls."); } } - - for(size_t i = 0; i < well_collection_.getLeafNodes().size(); i++) { + + // \TODO comment this. + for (size_t i = 0; i < well_collection_.getLeafNodes().size(); i++) { WellNode* node = static_cast(well_collection_.getLeafNodes()[i].get()); - // We know that getLeafNodes() is ordered the same way as they're indexed in w_ node->setWellsPointer(w_, i); } - - } @@ -619,7 +617,7 @@ namespace Opm /// Destructor. WellsManager::~WellsManager() { - wells_destroy(w_); + destroy_wells(w_); } diff --git a/opm/core/newwells.h b/opm/core/newwells.h index 425eefd2..4be7ef4c 100644 --- a/opm/core/newwells.h +++ b/opm/core/newwells.h @@ -24,48 +24,92 @@ extern "C" { #endif -enum well_type { INJECTOR, PRODUCER }; -enum control_type { BHP , RATE }; -enum surface_component { WATER = 0, OIL = 1, GAS = 2 }; +/** Well type indicates desired/expected well behaviour. */ +enum WellType { INJECTOR, PRODUCER }; +/** Type of well control equation or inequality. + * BHP -> bottom hole pressure is specified. + * RATE -> flow rate is specified. + */ +enum WellControlType { BHP , RATE }; +/** Canonical component names and ordering. */ +enum SurfaceComponent { WATER = 0, OIL = 1, GAS = 2 }; -/* Control for single well */ -struct WellControls { - int num; - int cpty; - enum control_type *type; - double *target; - int current; +/** Controls for a single well. + * Each control specifies a well rate or bottom hole pressure. Only + * one control can be active at a time, indicated by current. The + * meaning of each control's target value depends on the control + * type, for BHP controls it is a pressure in Pascal, for RATE + * controls it is a volumetric rate in cubic(meter)/second. The + * active control should be interpreted as an equation, whereas the + * non-active controls should be interpreted as inequalities + * specifying constraints on the solution, where BHP controls yield + * minimum pressures, and RATE controls yield maximum rates. + */ +struct WellControls +{ + int num; /** Number of controls. */ + int cpty; /** Allocated capacity, for internal use only. */ + enum WellControlType *type; /** Array of control types. */ + double *target; /** Array of control targets. */ + int current; /** Index of current active control. */ }; -struct Wells { - int number_of_wells; - int well_cpty; - int perf_cpty; - enum well_type *type; - double *depth_ref; - double *zfrac; /* Surface volume fraction - * (3*number_of_wells) */ - int *well_connpos; - int *well_cells; - double *WI; /* Well index */ - - struct WellControls **ctrls; /* One struct for each well */ +/** Struct encapsulating static information about all wells in a scenario. */ +struct Wells +{ + int number_of_wells; /** Number of wells. */ + int well_cpty; /** Allocated well capacity, for internal use only. */ + int perf_cpty; /** Allocated perforation capacity, for internal use only. */ + enum WellType *type; /** Array of well types. */ + double *depth_ref; /** Array of well bhp reference depths. */ + double *zfrac; /** Component volume fractions for each well, size is (3*number_of_wells). + * This is intended to be used for injection wells. For production wells + * the component fractions will vary and cannot be specified a priori. + */ + int *well_connpos; /** Array of indices into well_cells (and WI). + * For a well w, well_connpos[w] and well_connpos[w+1] yield + * start and one-beyond-end indices into the well_cells array + * for accessing w's perforation cell indices. + */ + int *well_cells; /** Array of perforation cell indices. + * Size is number of perforations (== well_connpos[number_of_wells]). + */ + double *WI; /** Well productivity index, same size and structure as well_cells. */ + struct WellControls **ctrls; /** Well controls, one struct for each well. */ }; -struct CompletionData { - double *gpot; /* Gravity potential */ - double *A; /* RB^{-1} */ - double *phasemob; /* Phase mobility */ + +/** Struct encapsulating dynamic information about all wells in a scenario. + * All arrays in this struct contain data for each perforation, ordered + * the same as Wells::well_cells and Wells:WI. Letting NP be the number + * of perforations, the array sizes are: + * gpot 3*NP + * A 9*NP (matrix in Fortran order). + * phasemob 3*NP + * \TODO: Verify that the sizes are correct, check if we should refactor to handle two phases better. + */ +struct CompletionData +{ + double *gpot; /** Gravity potentials. */ + double *A; /** Volumes to surface-components matrix, A = RB^{-1}. */ + double *phasemob; /** Phase mobilities. */ }; +/** Contruction function initializing a Wells object. + * The arguments may be used to indicate expected capacity needed, + * they will be used internally for pre-allocation. + * \return NULL upon failure, otherwise a valid Wells object with 0 wells. + */ struct Wells * -wells_create(int nwells, int nperf); +create_wells(int nwells_reserve_cap, int nperf_reserve_cap); + +/** */ int -wells_add(enum well_type type , +add_wells(enum WellType type , double depth_ref, int nperf , const double *zfrac , /* Injection fraction or NULL */ @@ -74,15 +118,15 @@ wells_add(enum well_type type , struct Wells *W ); void -wells_destroy(struct Wells *W); +destroy_wells(struct Wells *W); int -well_controls_append(enum control_type type , +append_well_controls(enum WellControlType type , double target, struct WellControls *ctrl ); void -well_controls_clear(struct WellControls *ctrl); +clear_well_controls(struct WellControls *ctrl); #ifdef __cplusplus } diff --git a/opm/core/utility/newwells.c b/opm/core/utility/newwells.c index 4e839505..cf918abb 100644 --- a/opm/core/utility/newwells.c +++ b/opm/core/utility/newwells.c @@ -245,7 +245,7 @@ wells_reserve(int nwells, int nperf, struct Wells *W) /* ---------------------------------------------------------------------- */ struct Wells * -wells_create(int nwells, int nperf) +create_wells(int nwells_reserve_cap, int nperf_reserve_cap) /* ---------------------------------------------------------------------- */ { int ok; @@ -272,13 +272,13 @@ wells_create(int nwells, int nperf) if (ok) { W->well_connpos[0] = 0; - if ((nwells > 0) || (nperf > 0)) { - ok = wells_reserve(nwells, nperf, W); + if ((nwells_reserve_cap > 0) || (nperf_reserve_cap > 0)) { + ok = wells_reserve(nwells_reserve_cap, nperf_reserve_cap, W); } } if (! ok) { - wells_destroy(W); + destroy_wells(W); W = NULL; } } @@ -289,7 +289,7 @@ wells_create(int nwells, int nperf) /* ---------------------------------------------------------------------- */ void -wells_destroy(struct Wells *W) +destroy_wells(struct Wells *W) /* ---------------------------------------------------------------------- */ { int w; @@ -331,7 +331,7 @@ alloc_size(int n, int a, int cpty) /* ---------------------------------------------------------------------- */ int -wells_add(enum well_type type , +add_wells(enum WellType type , double depth_ref, int nperf , const double *zfrac , /* Injection fraction or NULL */ @@ -386,7 +386,7 @@ wells_add(enum well_type type , /* ---------------------------------------------------------------------- */ int -well_controls_append(enum control_type type , +append_well_controls(enum WellControlType type , double target, struct WellControls *ctrl ) /* ---------------------------------------------------------------------- */ @@ -415,7 +415,7 @@ well_controls_append(enum control_type type , /* ---------------------------------------------------------------------- */ void -well_controls_clear(struct WellControls *ctrl) +clear_well_controls(struct WellControls *ctrl) /* ---------------------------------------------------------------------- */ { if (ctrl != NULL) {