move checkGroupConstraints into WellGroupConstraints

This commit is contained in:
Arne Morten Kvarving 2022-10-24 09:36:05 +02:00
parent 75dad9f4c4
commit 726e6699da
3 changed files with 87 additions and 76 deletions

View File

@ -123,4 +123,80 @@ checkGroupConstraintsProd(const Group& group,
deferred_logger);
}
bool WellGroupConstraints::
checkGroupConstraints(WellState& well_state,
const GroupState& group_state,
const Schedule& schedule,
const SummaryState& summaryState,
const RateConvFunc& rateConverter,
DeferredLogger& deferred_logger) const
{
const auto& well = well_.wellEcl();
const int well_index = well_.indexOfWell();
auto& ws = well_state.well(well_index);
if (well.isInjector()) {
const auto currentControl = ws.injection_cmode;
if (currentControl != Well::InjectorCMode::GRUP) {
// This checks only the first encountered group limit,
// in theory there could be several, and then we should
// test all but the one currently applied. At that point,
// this if-statement should be removed and we should always
// check, skipping over only the single group parent whose
// control is the active one for the well (if any).
const auto& group = schedule.getGroup(well.groupName(), well_.currentStep());
const double efficiencyFactor = well.getEfficiencyFactor();
const std::pair<bool, double> group_constraint =
this->checkGroupConstraintsInj(group, well_state,
group_state, efficiencyFactor,
schedule, summaryState,
rateConverter,
deferred_logger);
// If a group constraint was broken, we set the current well control to
// be GRUP.
if (group_constraint.first) {
ws.injection_cmode = Well::InjectorCMode::GRUP;
const int np = well_state.numPhases();
for (int p = 0; p<np; ++p) {
ws.surface_rates[p] *= group_constraint.second;
}
}
return group_constraint.first;
}
}
if (well.isProducer( )) {
const auto currentControl = ws.production_cmode;
if (currentControl != Well::ProducerCMode::GRUP) {
// This checks only the first encountered group limit,
// in theory there could be several, and then we should
// test all but the one currently applied. At that point,
// this if-statement should be removed and we should always
// check, skipping over only the single group parent whose
// control is the active one for the well (if any).
const auto& group = schedule.getGroup(well.groupName(), well_.currentStep());
const double efficiencyFactor = well.getEfficiencyFactor();
const std::pair<bool, double> group_constraint =
this->checkGroupConstraintsProd(group, well_state,
group_state, efficiencyFactor,
schedule, summaryState,
rateConverter, deferred_logger);
// If a group constraint was broken, we set the current well control to
// be GRUP.
if (group_constraint.first) {
ws.production_cmode = Well::ProducerCMode::GRUP;
const int np = well_state.numPhases();
for (int p = 0; p<np; ++p) {
ws.surface_rates[p] *= group_constraint.second;
}
}
return group_constraint.first;
}
}
return false;
}
} // namespace Opm

View File

@ -49,6 +49,14 @@ public:
using RateConvFunc = std::function<void(const RegionId, const int, std::vector<double>&)>;
bool checkGroupConstraints(WellState& well_state,
const GroupState& group_state,
const Schedule& schedule,
const SummaryState& summaryState,
const RateConvFunc& rateConverter,
DeferredLogger& deferred_logger) const;
private:
std::pair<bool, double>
checkGroupConstraintsInj(const Group& group,
const WellState& well_state,
@ -69,7 +77,6 @@ public:
const RateConvFunc& rateConverter,
DeferredLogger& deferred_logger) const;
private:
const WellInterfaceGeneric& well_; //!< Reference to well interface
};

View File

@ -336,86 +336,14 @@ checkGroupConstraints(WellState& well_state,
const SummaryState& summaryState,
DeferredLogger& deferred_logger) const
{
const auto& well = well_ecl_;
const int well_index = index_of_well_;
auto& ws = well_state.well(well_index);
auto rCoeff = [this](const int id, const int region, std::vector<double>& coeff)
{
this->rateConverter().calcCoeff(id, region, coeff);
};
if (well.isInjector()) {
const auto currentControl = ws.injection_cmode;
if (currentControl != Well::InjectorCMode::GRUP) {
// This checks only the first encountered group limit,
// in theory there could be several, and then we should
// test all but the one currently applied. At that point,
// this if-statement should be removed and we should always
// check, skipping over only the single group parent whose
// control is the active one for the well (if any).
const auto& group = schedule.getGroup( well.groupName(), current_step_ );
const double efficiencyFactor = well.getEfficiencyFactor();
const std::pair<bool, double> group_constraint =
WellGroupConstraints(*this).
checkGroupConstraintsInj(group,
well_state,
group_state,
efficiencyFactor,
schedule,
summaryState,
rCoeff,
deferred_logger);
// If a group constraint was broken, we set the current well control to
// be GRUP.
if (group_constraint.first) {
ws.injection_cmode = Well::InjectorCMode::GRUP;
const int np = well_state.numPhases();
for (int p = 0; p<np; ++p) {
ws.surface_rates[p] *= group_constraint.second;
}
}
return group_constraint.first;
}
}
if (well.isProducer( )) {
const auto currentControl = ws.production_cmode;
if (currentControl != Well::ProducerCMode::GRUP) {
// This checks only the first encountered group limit,
// in theory there could be several, and then we should
// test all but the one currently applied. At that point,
// this if-statement should be removed and we should always
// check, skipping over only the single group parent whose
// control is the active one for the well (if any).
const auto& group = schedule.getGroup( well.groupName(), current_step_ );
const double efficiencyFactor = well.getEfficiencyFactor();
const std::pair<bool, double> group_constraint =
WellGroupConstraints(*this).
checkGroupConstraintsProd(group,
well_state,
group_state,
efficiencyFactor,
schedule,
summaryState,
rCoeff,
deferred_logger);
// If a group constraint was broken, we set the current well control to
// be GRUP.
if (group_constraint.first) {
ws.production_cmode = Well::ProducerCMode::GRUP;
const int np = well_state.numPhases();
for (int p = 0; p<np; ++p) {
ws.surface_rates[p] *= group_constraint.second;
}
}
return group_constraint.first;
}
}
return false;
return WellGroupConstraints(*this).checkGroupConstraints(well_state, group_state,
schedule, summaryState,
rCoeff, deferred_logger);
}
template <typename FluidSystem>