Use wellcontainer2 (#3255)

Use WellContainer<> to manage members in WellState
This commit is contained in:
Joakim Hove
2021-05-20 16:16:12 +02:00
committed by GitHub
parent b9f916080a
commit 506a349085
14 changed files with 329 additions and 302 deletions

View File

@@ -848,7 +848,7 @@ namespace Opm
}
// Store the perforation pressure for later usage.
auto * perf_press = &well_state.perfPress()[first_perf_];
auto& perf_press = well_state.perfPress(index_of_well_);
perf_press[perf] = well_state.bhp(index_of_well_) + perf_pressure_diffs_[perf];
}
@@ -1271,21 +1271,21 @@ namespace Opm
if (this->isProducer()) {
const double g_total = primary_variables_[WQTotal];
for (int p = 0; p < number_of_phases_; ++p) {
well_state.wellRates()[index_of_well_ * number_of_phases_ + p] = g_total * F[p];
well_state.wellRates(index_of_well_)[p] = g_total * F[p];
}
} else { // injectors
for (int p = 0; p < number_of_phases_; ++p) {
well_state.wellRates()[index_of_well_ * number_of_phases_ + p] = 0.0;
well_state.wellRates(index_of_well_)[p] = 0.0;
}
switch (this->wellEcl().injectorType()) {
case InjectorType::WATER:
well_state.wellRates()[index_of_well_ * number_of_phases_ + pu.phase_pos[Water]] = primary_variables_[WQTotal];
well_state.wellRates(index_of_well_)[pu.phase_pos[Water]] = primary_variables_[WQTotal];
break;
case InjectorType::GAS:
well_state.wellRates()[index_of_well_ * number_of_phases_ + pu.phase_pos[Gas]] = primary_variables_[WQTotal];
well_state.wellRates(index_of_well_)[pu.phase_pos[Gas]] = primary_variables_[WQTotal];
break;
case InjectorType::OIL:
well_state.wellRates()[index_of_well_ * number_of_phases_ + pu.phase_pos[Oil]] = primary_variables_[WQTotal];
well_state.wellRates(index_of_well_)[pu.phase_pos[Oil]] = primary_variables_[WQTotal];
break;
case InjectorType::MULTI:
// Not supported.
@@ -1328,13 +1328,13 @@ namespace Opm
const Opm::PhaseUsage& pu = phaseUsage();
if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)) {
rates[ Water ] = well_state.wellRates()[index_of_well_ * number_of_phases_ + pu.phase_pos[ Water ] ];
rates[ Water ] = well_state.wellRates(index_of_well_)[pu.phase_pos[ Water ] ];
}
if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)) {
rates[ Oil ] = well_state.wellRates()[index_of_well_ * number_of_phases_ + pu.phase_pos[ Oil ] ];
rates[ Oil ] = well_state.wellRates(index_of_well_)[pu.phase_pos[ Oil ] ];
}
if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
rates[ Gas ] = well_state.wellRates()[index_of_well_ * number_of_phases_ + pu.phase_pos[ Gas ] ];
rates[ Gas ] = well_state.wellRates(index_of_well_)[pu.phase_pos[ Gas ] ];
}
const double bhp = well_state.bhp(index_of_well_);
@@ -1665,9 +1665,9 @@ namespace Opm
}
// Compute the average pressure in each well block
const auto * perf_press = &well_state.perfPress()[first_perf_];
const auto& perf_press = well_state.perfPress(w);
auto p_above = this->parallel_well_info_.communicateAboveValues(well_state.bhp(w),
perf_press,
perf_press.data(),
nperf);
for (int perf = 0; perf < nperf; ++perf) {
@@ -1690,14 +1690,12 @@ namespace Opm
if (gasPresent) {
const unsigned gasCompIdx = Indices::canonicalToActiveComponentIndex(FluidSystem::gasCompIdx);
const int gaspos = gasCompIdx + perf * num_components_;
const int gaspos_well = pu.phase_pos[Gas] + w * pu.num_phases;
if (oilPresent) {
const int oilpos_well = pu.phase_pos[Oil] + w * pu.num_phases;
const double oilrate = std::abs(well_state.wellRates()[oilpos_well]); //in order to handle negative rates in producers
const double oilrate = std::abs(well_state.wellRates(w)[pu.phase_pos[Oil]]); //in order to handle negative rates in producers
rvmax_perf[perf] = FluidSystem::gasPvt().saturatedOilVaporizationFactor(fs.pvtRegionIndex(), temperature, p_avg);
if (oilrate > 0) {
const double gasrate = std::abs(well_state.wellRates()[gaspos_well]) - (has_solvent ? well_state.solventWellRate(w) : 0.0);
const double gasrate = std::abs(well_state.wellRates(w)[pu.phase_pos[Gas]]) - (has_solvent ? well_state.solventWellRate(w) : 0.0);
double rv = 0.0;
if (gasrate > 0) {
rv = oilrate / gasrate;
@@ -1718,13 +1716,11 @@ namespace Opm
if (oilPresent) {
const unsigned oilCompIdx = Indices::canonicalToActiveComponentIndex(FluidSystem::oilCompIdx);
const int oilpos = oilCompIdx + perf * num_components_;
const int oilpos_well = pu.phase_pos[Oil] + w * pu.num_phases;
if (gasPresent) {
rsmax_perf[perf] = FluidSystem::oilPvt().saturatedGasDissolutionFactor(fs.pvtRegionIndex(), temperature, p_avg);
const int gaspos_well = pu.phase_pos[Gas] + w * pu.num_phases;
const double gasrate = std::abs(well_state.wellRates()[gaspos_well]) - (has_solvent ? well_state.solventWellRate(w) : 0.0);
const double gasrate = std::abs(well_state.wellRates(w)[pu.phase_pos[Gas]]) - (has_solvent ? well_state.solventWellRate(w) : 0.0);
if (gasrate > 0) {
const double oilrate = std::abs(well_state.wellRates()[oilpos_well]);
const double oilrate = std::abs(well_state.wellRates(w)[pu.phase_pos[Oil]]);
double rs = 0.0;
if (oilrate > 0) {
rs = gasrate / oilrate;
@@ -2423,9 +2419,9 @@ namespace Opm
// Set current control to bhp, and bhp value in state, modify bhp limit in control object.
if (well_ecl_.isInjector()) {
well_state_copy.currentInjectionControls()[index_of_well_] = Well::InjectorCMode::BHP;
well_state_copy.currentInjectionControl(index_of_well_, Well::InjectorCMode::BHP);
} else {
well_state_copy.currentProductionControls()[index_of_well_] = Well::ProducerCMode::BHP;
well_state_copy.currentProductionControl(index_of_well_, Well::ProducerCMode::BHP);
}
well_state_copy.update_bhp(index_of_well_, bhp);
@@ -2507,8 +2503,7 @@ namespace Opm
}
if (this->glift_optimize_only_thp_wells) {
const int well_index = index_of_well_;
const Well::ProducerCMode& control_mode
= well_state.currentProductionControls()[well_index];
auto control_mode = well_state.currentProductionControl(well_index);
if (control_mode != Well::ProducerCMode::THP ) {
gliftDebug("Not THP control", deferred_logger);
return false;
@@ -2691,7 +2686,7 @@ namespace Opm
// does the well have a THP related constraint?
const auto& summaryState = ebosSimulator.vanguard().summaryState();
const Well::ProducerCMode& current_control = well_state.currentProductionControls()[this->index_of_well_];
auto current_control = well_state.currentProductionControl(this->index_of_well_);
if ( !well.Base::wellHasTHPConstraints(summaryState) || current_control == Well::ProducerCMode::BHP ) {
// get the bhp value based on the bhp constraints
const double bhp = well.mostStrictBhpFromBhpLimits(summaryState);
@@ -2721,7 +2716,7 @@ namespace Opm
// the weighted total well rate
double total_well_rate = 0.0;
for (int p = 0; p < np; ++p) {
total_well_rate += scalingFactor(p) * well_state.wellRates()[np * well_index + p];
total_well_rate += scalingFactor(p) * well_state.wellRates(well_index)[p];
}
// Not: for the moment, the first primary variable for the injectors is not G_total. The injection rate
@@ -2729,13 +2724,13 @@ namespace Opm
if (this->isInjector()) {
switch (this->wellEcl().injectorType()) {
case InjectorType::WATER:
primary_variables_[WQTotal] = well_state.wellRates()[np * well_index + pu.phase_pos[Water]];
primary_variables_[WQTotal] = well_state.wellRates(well_index)[pu.phase_pos[Water]];
break;
case InjectorType::GAS:
primary_variables_[WQTotal] = well_state.wellRates()[np * well_index + pu.phase_pos[Gas]];
primary_variables_[WQTotal] = well_state.wellRates(well_index)[pu.phase_pos[Gas]];
break;
case InjectorType::OIL:
primary_variables_[WQTotal] = well_state.wellRates()[np * well_index + pu.phase_pos[Oil]];
primary_variables_[WQTotal] = well_state.wellRates(well_index)[pu.phase_pos[Oil]];
break;
case InjectorType::MULTI:
// Not supported.
@@ -2749,10 +2744,10 @@ namespace Opm
if (std::abs(total_well_rate) > 0.) {
if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)) {
primary_variables_[WFrac] = scalingFactor(pu.phase_pos[Water]) * well_state.wellRates()[np*well_index + pu.phase_pos[Water]] / total_well_rate;
primary_variables_[WFrac] = scalingFactor(pu.phase_pos[Water]) * well_state.wellRates(well_index)[pu.phase_pos[Water]] / total_well_rate;
}
if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
primary_variables_[GFrac] = scalingFactor(pu.phase_pos[Gas]) * (well_state.wellRates()[np*well_index + pu.phase_pos[Gas]]
primary_variables_[GFrac] = scalingFactor(pu.phase_pos[Gas]) * (well_state.wellRates(well_index)[pu.phase_pos[Gas]]
- (has_solvent ? well_state.solventWellRate(well_index) : 0.0) ) / total_well_rate ;
}
if constexpr (has_solvent) {
@@ -3276,7 +3271,7 @@ namespace Opm
}
else if (this->isInjector() )
{
const Opm::Well::InjectorCMode& current = well_state.currentInjectionControls()[well_index];
auto current = well_state.currentInjectionControl(well_index);
switch(current) {
case Well::InjectorCMode::THP:
ctrltype = CR::WellFailure::Type::ControlTHP;
@@ -3301,7 +3296,7 @@ namespace Opm
}
else if (this->isProducer() )
{
const Well::ProducerCMode& current = well_state.currentProductionControls()[well_index];
auto current = well_state.currentProductionControl(well_index);
switch(current) {
case Well::ProducerCMode::THP:
ctrltype = CR::WellFailure::Type::ControlTHP;