diff --git a/opm/core/wells/WellsManager_impl.hpp b/opm/core/wells/WellsManager_impl.hpp index b7e48e5f..03ad2813 100644 --- a/opm/core/wells/WellsManager_impl.hpp +++ b/opm/core/wells/WellsManager_impl.hpp @@ -187,7 +187,7 @@ void WellsManager::createWellsFromSpecs(std::vector& wells, size_t const int num_wells = well_data.size(); int num_perfs = 0; - assert(dimensions == 3); + assert (dimensions == 3); for (int w = 0; w < num_wells; ++w) { num_perfs += wellperf_data[w].size(); if (well_data[w].reference_bhp_depth == -1e100) { @@ -195,13 +195,19 @@ void WellsManager::createWellsFromSpecs(std::vector& wells, size_t double min_depth = 1e100; int num_wperfs = wellperf_data[w].size(); for (int perf = 0; perf < num_wperfs; ++perf) { - double depth = UgGridHelpers - ::getCoordinate(UgGridHelpers::increment(begin_cell_centroids, - wellperf_data[w][perf].cell, - dimensions), - 2); + using UgGridHelpers::increment; + using UgGridHelpers::getCoordinate; + + const CC& cc = + increment(begin_cell_centroids, + wellperf_data[w][perf].cell, + dimensions); + + const double depth = getCoordinate(cc, 2); + min_depth = std::min(min_depth, depth); } + well_data[w].reference_bhp_depth = min_depth; } } @@ -215,66 +221,86 @@ void WellsManager::createWellsFromSpecs(std::vector& wells, size_t // Add wells. for (int w = 0; w < num_wells; ++w) { - const int w_num_perf = wellperf_data[w].size(); - std::vector perf_cells(w_num_perf); + const int w_num_perf = wellperf_data[w].size(); + std::vector perf_cells (w_num_perf); std::vector perf_prodind(w_num_perf); + for (int perf = 0; perf < w_num_perf; ++perf) { - perf_cells[perf] = wellperf_data[w][perf].cell; + perf_cells [perf] = wellperf_data[w][perf].cell; perf_prodind[perf] = wellperf_data[w][perf].well_index; } + const double* comp_frac = NULL; + // 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], well_names[w].c_str(), w_); + const 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], + well_names[w].c_str(), + w_); + if (!ok) { - OPM_THROW(std::runtime_error, "Failed adding well " << well_names[w] << " to Wells data structure."); + OPM_THROW(std::runtime_error, + "Failed adding well " + << well_names[w] + << " to Wells data structure."); } } } -template -WellsManager::WellsManager(const Opm::EclipseStateConstPtr eclipseState, - const size_t timeStep, - int number_of_cells, - const int* global_cell, - const int* cart_dims, - int dimensions, - CC begin_cell_centroids, - const C2F& cell_to_faces, - FC begin_face_centroids, - const double* permeability) +template +WellsManager:: +WellsManager(const Opm::EclipseStateConstPtr eclipseState, + const size_t timeStep, + int number_of_cells, + const int* global_cell, + const int* cart_dims, + int dimensions, + CC begin_cell_centroids, + const C2F& cell_to_faces, + FC begin_face_centroids, + const double* permeability) : w_(0) { - init(eclipseState, timeStep, number_of_cells, global_cell, cart_dims, dimensions, - begin_cell_centroids, cell_to_faces, begin_face_centroids, permeability); + init(eclipseState, timeStep, number_of_cells, global_cell, + cart_dims, dimensions, begin_cell_centroids, + cell_to_faces, begin_face_centroids, permeability); } /// Construct wells from deck. -template -void WellsManager::init(const Opm::EclipseStateConstPtr eclipseState, - const size_t timeStep, - int number_of_cells, - const int* global_cell, - const int* cart_dims, - int dimensions, - CC begin_cell_centroids, - const C2F& cell_to_faces, - FC begin_face_centroids, - const double* permeability) +template +void +WellsManager::init(const Opm::EclipseStateConstPtr eclipseState, + const size_t timeStep, + int number_of_cells, + const int* global_cell, + const int* cart_dims, + int dimensions, + CC begin_cell_centroids, + const C2F& cell_to_faces, + FC begin_face_centroids, + const double* permeability) { if (dimensions != 3) { - OPM_THROW(std::runtime_error, "We cannot initialize wells from a deck unless the corresponding grid is 3-dimensional."); + OPM_THROW(std::runtime_error, + "We cannot initialize wells from a deck unless " + "the corresponding grid is 3-dimensional."); } if (eclipseState->getSchedule()->numWells() == 0) { - OPM_MESSAGE("No wells specified in Schedule section, initializing no wells"); + OPM_MESSAGE("No wells specified in Schedule section, " + "initializing no wells"); return; } std::map cartesian_to_compressed; - setupCompressedToCartesian(global_cell, - number_of_cells, cartesian_to_compressed); + setupCompressedToCartesian(global_cell, number_of_cells, + cartesian_to_compressed); // Obtain phase usage data. PhaseUsage pu = phaseUsageFromDeck(eclipseState); @@ -288,8 +314,8 @@ void WellsManager::init(const Opm::EclipseStateConstPtr eclipseState, // For easy lookup: std::map well_names_to_index; - ScheduleConstPtr schedule = eclipseState->getSchedule(); - std::vector wells = schedule->getWells(timeStep); + ScheduleConstPtr schedule = eclipseState->getSchedule(); + std::vector wells = schedule->getWells(timeStep); well_names.reserve(wells.size()); well_data.reserve(wells.size()); @@ -299,24 +325,29 @@ void WellsManager::init(const Opm::EclipseStateConstPtr eclipseState, begin_face_centroids, begin_cell_centroids, dimensions, - well_names, well_data, well_names_to_index, pu, cartesian_to_compressed, permeability); + well_names, well_data, well_names_to_index, + pu, cartesian_to_compressed, permeability); + setupWellControls(wells, timeStep, well_names, pu); { - GroupTreeNodeConstPtr fieldNode = eclipseState->getSchedule()->getGroupTree(timeStep)->getNode("FIELD"); - GroupConstPtr fieldGroup = eclipseState->getSchedule()->getGroup(fieldNode->name()); + GroupTreeNodeConstPtr fieldNode = + schedule->getGroupTree(timeStep)->getNode("FIELD"); + + GroupConstPtr fieldGroup = + schedule->getGroup(fieldNode->name()); + well_collection_.addField(fieldGroup, timeStep, pu); - addChildGroups(fieldNode, eclipseState->getSchedule(), timeStep, pu); + addChildGroups(fieldNode, schedule, timeStep, pu); } - for (auto wellIter = wells.begin(); wellIter != wells.end(); ++wellIter ) { - well_collection_.addWell((*wellIter), timeStep, pu); + for (auto w = wells.begin(), e = wells.end(); w != e; ++w) { + well_collection_.addWell(*w, timeStep, pu); } well_collection_.setWellsPointer(w_); well_collection_.applyGroupControls(); - setupGuideRates(wells, timeStep, well_data, well_names_to_index); // Debug output.