static bool allRateWells(const Wells* wells) { if (wells == NULL) { return true; } const int nw = wells->number_of_wells; for (int w = 0; w < nw; ++w) { const WellControls* wc = wells->ctrls[w]; if (well_controls_well_is_open( wc )) { if (well_controls_get_current_type(wc) == BHP) { return false; } } } return true; }
void init(const Wells* wells, const State& state) { // clear old name mapping wellMap_.clear(); wells_.reset( clone_wells( wells ) ); if (wells) { const int nw = wells->number_of_wells; const int np = wells->number_of_phases; bhp_.resize(nw); thp_.resize(nw); temperature_.resize(nw, 273.15 + 20); // standard temperature for now wellrates_.resize(nw * np, 0.0); for (int w = 0; w < nw; ++w) { assert((wells->type[w] == INJECTOR) || (wells->type[w] == PRODUCER)); const WellControls* ctrl = wells->ctrls[w]; const int num_perf_this_well = wells->well_connpos[w + 1] - wells->well_connpos[w]; // setup wellname -> well index mapping { assert( wells->name[ w ] ); std::string name( wells->name[ w ] ); assert( name.size() > 0 ); mapentry_t& wellMapEntry = wellMap_[name]; wellMapEntry[ 0 ] = w; wellMapEntry[ 1 ] = wells->well_connpos[w]; // also store the number of perforations in this well wellMapEntry[ 2 ] = num_perf_this_well; } if ( num_perf_this_well == 0 ) { // No perforations of the well. Initialize to zero. for (int p = 0; p < np; ++p) { wellrates_[np*w + p] = 0.0; } bhp_[w] = 0; thp_[w] = 0; continue; } if (well_controls_well_is_stopped(ctrl)) { // Stopped well: // 1. Rates: assign zero well rates. for (int p = 0; p < np; ++p) { wellrates_[np*w + p] = 0.0; } // 2. Bhp: assign bhp equal to bhp control, if // applicable, otherwise assign equal to // first perforation cell pressure. if (well_controls_get_current_type(ctrl) == BHP) { bhp_[w] = well_controls_get_current_target( ctrl ); } else { const int first_cell = wells->well_cells[wells->well_connpos[w]]; bhp_[w] = state.pressure()[first_cell]; } // 3. Thp: assign thp equal to thp control, if applicable, // otherwise assign equal to bhp value. if (well_controls_get_current_type(ctrl) == THP) { thp_[w] = well_controls_get_current_target( ctrl ); } else { thp_[w] = bhp_[w]; } } else { // Open well: // 1. Rates: initialize well rates to match controls // if type is SURFACE_RATE. Otherwise, we // cannot set the correct value here, so we // assign a small rate with the correct // sign so that any logic depending on that // sign will work as expected. if (well_controls_get_current_type(ctrl) == SURFACE_RATE) { const double rate_target = well_controls_get_current_target(ctrl); const double * distr = well_controls_get_current_distr( ctrl ); for (int p = 0; p < np; ++p) { wellrates_[np*w + p] = rate_target * distr[p]; } } else { const double small_rate = 1e-14; const double sign = (wells->type[w] == INJECTOR) ? 1.0 : -1.0; for (int p = 0; p < np; ++p) { wellrates_[np*w + p] = small_rate * sign; } } // 2. Bhp: initialize bhp to be target pressure if // bhp-controlled well, otherwise set to a // little above or below (depending on if // the well is an injector or producer) // pressure in first perforation cell. if (well_controls_get_current_type(ctrl) == BHP) { bhp_[w] = well_controls_get_current_target( ctrl ); } else { const int first_cell = wells->well_cells[wells->well_connpos[w]]; const double safety_factor = (wells->type[w] == INJECTOR) ? 1.01 : 0.99; bhp_[w] = safety_factor*state.pressure()[first_cell]; } // 3. Thp: assign thp equal to thp control, if applicable, // otherwise assign equal to bhp value. if (well_controls_get_current_type(ctrl) == THP) { thp_[w] = well_controls_get_current_target( ctrl ); } else { thp_[w] = bhp_[w]; } } } // The perforation rates and perforation pressures are // not expected to be consistent with bhp_ and wellrates_ // after init(). perfrates_.resize(wells->well_connpos[nw], 0.0); perfpress_.resize(wells->well_connpos[nw], -1e100); } }