changed: move updateThp to WellBhpThpCalculator

This commit is contained in:
Arne Morten Kvarving 2022-10-19 09:55:14 +02:00
parent a4df84f785
commit 0577516cfe
6 changed files with 61 additions and 100 deletions

View File

@ -1269,51 +1269,6 @@ assembleControlEq(const WellState& well_state,
}
}
template<typename FluidSystem, typename Indices, typename Scalar>
void
MultisegmentWellEval<FluidSystem,Indices,Scalar>::
updateThp(WellState& well_state,
const double rho,
DeferredLogger& deferred_logger) const
{
static constexpr int Gas = BlackoilPhases::Vapour;
static constexpr int Oil = BlackoilPhases::Liquid;
static constexpr int Water = BlackoilPhases::Aqua;
auto& ws = well_state.well(baseif_.indexOfWell());
// When there is no vaild VFP table provided, we set the thp to be zero.
if (!baseif_.isVFPActive(deferred_logger) || baseif_.wellIsStopped()) {
ws.thp = 0;
return;
}
// For THP controlled wells, we know the thp value
bool thp_controlled = baseif_.isInjector() ? ws.injection_cmode == Well::InjectorCMode::THP:
ws.production_cmode == Well::ProducerCMode::THP;
if (thp_controlled) {
return;
}
// the well is under other control types, we calculate the thp based on bhp and rates
std::vector<double> rates(3, 0.0);
const PhaseUsage& pu = baseif_.phaseUsage();
if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)) {
rates[ Water ] = ws.surface_rates[pu.phase_pos[ Water ] ];
}
if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)) {
rates[ Oil ] = ws.surface_rates[pu.phase_pos[ Oil ] ];
}
if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
rates[ Gas ] = ws.surface_rates[pu.phase_pos[ Gas ] ];
}
ws.thp = WellBhpThpCalculator(baseif_).calculateThpFromBhp(rates,
ws.bhp,
rho,
baseif_.wellEcl().alq_value(),
deferred_logger);
}
template<typename FluidSystem, typename Indices, typename Scalar>
void
MultisegmentWellEval<FluidSystem,Indices,Scalar>::
@ -1481,7 +1436,12 @@ updateWellStateFromPrimaryVariables(WellState& well_state,
ws.bhp = segment_pressure[seg];
}
}
updateThp(well_state, rho, deferred_logger);
WellBhpThpCalculator(baseif_).
updateThp(rho, [this]() { return baseif_.wellEcl().alq_value(); },
{FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx),
FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx),
FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)},
well_state, deferred_logger);
}
template<typename FluidSystem, typename Indices, typename Scalar>

View File

@ -221,10 +221,6 @@ protected:
// pressure drop for sub-critical valve (WSEGVALV)
EvalWell pressureDropValve(const int seg) const;
void updateThp(WellState& well_state,
const double rho,
DeferredLogger& deferred_logger) const;
void updateWellStateFromPrimaryVariables(WellState& well_state,
const double rho,
DeferredLogger& deferred_logger) const;

View File

@ -557,52 +557,6 @@ processFractions() const
}
}
template<class FluidSystem, class Indices, class Scalar>
void
StandardWellEval<FluidSystem,Indices,Scalar>::
updateThp(WellState& well_state,
DeferredLogger& deferred_logger) const
{
static constexpr int Gas = WellInterfaceIndices<FluidSystem,Indices,Scalar>::Gas;
static constexpr int Oil = WellInterfaceIndices<FluidSystem,Indices,Scalar>::Oil;
static constexpr int Water = WellInterfaceIndices<FluidSystem,Indices,Scalar>::Water;
auto& ws = well_state.well(baseif_.indexOfWell());
// When there is no vaild VFP table provided, we set the thp to be zero.
if (!baseif_.isVFPActive(deferred_logger) || baseif_.wellIsStopped()) {
ws.thp = 0;
return;
}
// For THP controlled wells, we know the thp value
bool thp_controlled = baseif_.isInjector() ? ws.injection_cmode == Well::InjectorCMode::THP:
ws.production_cmode == Well::ProducerCMode::THP;
if (thp_controlled) {
return;
}
// the well is under other control types, we calculate the thp based on bhp and rates
std::vector<double> rates(3, 0.0);
const PhaseUsage& pu = baseif_.phaseUsage();
if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)) {
rates[ Water ] = ws.surface_rates[pu.phase_pos[ Water ] ];
}
if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)) {
rates[ Oil ] = ws.surface_rates[pu.phase_pos[ Oil ] ];
}
if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
rates[ Gas ] = ws.surface_rates[pu.phase_pos[ Gas ] ];
}
ws.thp = WellBhpThpCalculator(this->baseif_).calculateThpFromBhp(rates,
ws.bhp,
this->getRho(),
this->baseif_.getALQ(well_state),
deferred_logger);
}
template<class FluidSystem, class Indices, class Scalar>
void
StandardWellEval<FluidSystem,Indices,Scalar>::
@ -704,7 +658,13 @@ updateWellStateFromPrimaryVariables(WellState& well_state,
}
}
updateThp(well_state, deferred_logger);
WellBhpThpCalculator(baseif_).
updateThp(this->getRho(),
[this,&well_state]() { return this->baseif_.getALQ(well_state); },
{FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx),
FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx),
FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)},
well_state, deferred_logger);
}
template<class FluidSystem, class Indices, class Scalar>

View File

@ -177,9 +177,6 @@ protected:
void updateWellStateFromPrimaryVariablesPolyMW(WellState& well_state) const;
void updateThp(WellState& well_state,
DeferredLogger& deferred_logger) const;
// total number of the well equations and primary variables
// there might be extra equations be used, numWellEq will be updated during the initialization
int numWellEq_ = numStaticWellEq;

View File

@ -219,6 +219,46 @@ computeBhpAtThpLimitInj(const std::function<std::vector<double>(const double)>&
}
}
void WellBhpThpCalculator::updateThp(const double rho,
const std::function<double()>& alq_value,
const std::array<unsigned,3>& active,
WellState& well_state,
DeferredLogger& deferred_logger) const
{
static constexpr int Gas = BlackoilPhases::Vapour;
static constexpr int Oil = BlackoilPhases::Liquid;
static constexpr int Water = BlackoilPhases::Aqua;
auto& ws = well_state.well(well_.indexOfWell());
// When there is no vaild VFP table provided, we set the thp to be zero.
if (!well_.isVFPActive(deferred_logger) || well_.wellIsStopped()) {
ws.thp = 0;
return;
}
// For THP controlled wells, we know the thp value
bool thp_controlled = well_.isInjector() ? ws.injection_cmode == Well::InjectorCMode::THP:
ws.production_cmode == Well::ProducerCMode::THP;
if (thp_controlled) {
return;
}
// the well is under other control types, we calculate the thp based on bhp and rates
std::vector<double> rates(3, 0.0);
const PhaseUsage& pu = well_.phaseUsage();
if (active[Water]) {
rates[ Water ] = ws.surface_rates[pu.phase_pos[ Water ] ];
}
if (active[Oil]) {
rates[ Oil ] = ws.surface_rates[pu.phase_pos[ Oil ] ];
}
if (active[Gas]) {
rates[ Gas ] = ws.surface_rates[pu.phase_pos[ Gas ] ];
}
ws.thp = this->calculateThpFromBhp(rates, ws.bhp, rho, alq_value(), deferred_logger);
}
template<class ErrorPolicy>
std::optional<double>
WellBhpThpCalculator::

View File

@ -35,6 +35,7 @@ namespace Opm
class DeferredLogger;
class SummaryState;
class WellInterfaceGeneric;
class WellState;
//! \brief Class for computing BHP limits.
class WellBhpThpCalculator {
@ -77,6 +78,13 @@ public:
const bool throwOnError,
DeferredLogger& deferred_logger) const;
//! \brief Update THP.
void updateThp(const double rho,
const std::function<double()>& alq_value,
const std::array<unsigned,3>& active,
WellState& well_state,
DeferredLogger& deferred_logger) const;
private:
//! \brief Compute BHP from THP limit for an injector - implementation.
template<class ErrorPolicy>