move (most of) updateWellStateFromPrimaryVariables to StandardWellPrimaryVariables

This commit is contained in:
Arne Morten Kvarving 2022-11-08 07:09:51 +01:00
parent 412e561cd8
commit f55d4334f1
3 changed files with 107 additions and 94 deletions

View File

@ -453,100 +453,7 @@ StandardWellEval<FluidSystem,Indices,Scalar>::
updateWellStateFromPrimaryVariables(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;
const PhaseUsage& pu = baseif_.phaseUsage();
std::vector<double> F(baseif_.numPhases(), 0.0);
[[maybe_unused]] double F_solvent = 0.0;
if ( FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx) ) {
const int oil_pos = pu.phase_pos[Oil];
F[oil_pos] = 1.0;
if ( FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx) ) {
const int water_pos = pu.phase_pos[Water];
F[water_pos] = primary_variables_.value_[WFrac];
F[oil_pos] -= F[water_pos];
}
if ( FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx) ) {
const int gas_pos = pu.phase_pos[Gas];
F[gas_pos] = primary_variables_.value_[GFrac];
F[oil_pos] -= F[gas_pos];
}
if constexpr (Indices::enableSolvent) {
F_solvent = primary_variables_.value_[SFrac];
F[oil_pos] -= F_solvent;
}
}
else if ( FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx) ) {
const int water_pos = pu.phase_pos[Water];
F[water_pos] = 1.0;
if ( FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx) ) {
const int gas_pos = pu.phase_pos[Gas];
F[gas_pos] = primary_variables_.value_[GFrac];
F[water_pos] -= F[gas_pos];
}
}
else if ( FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx) ) {
const int gas_pos = pu.phase_pos[Gas];
F[gas_pos] = 1.0;
}
// convert the fractions to be Q_p / G_total to calculate the phase rates
for (int p = 0; p < baseif_.numPhases(); ++p) {
const double scal = baseif_.scalingFactor(p);
// for injection wells, there should only one non-zero scaling factor
if (scal > 0) {
F[p] /= scal ;
} else {
// this should only happens to injection wells
F[p] = 0.;
}
}
// F_solvent is added to F_gas. This means that well_rate[Gas] also contains solvent.
// More testing is needed to make sure this is correct for well groups and THP.
if constexpr (Indices::enableSolvent){
F_solvent /= baseif_.scalingFactor(Indices::contiSolventEqIdx);
F[pu.phase_pos[Gas]] += F_solvent;
}
auto& ws = well_state.well(baseif_.indexOfWell());
ws.bhp = primary_variables_.value_[Bhp];
// calculate the phase rates based on the primary variables
// for producers, this is not a problem, while not sure for injectors here
if (baseif_.isProducer()) {
const double g_total = primary_variables_.value_[WQTotal];
for (int p = 0; p < baseif_.numPhases(); ++p) {
ws.surface_rates[p] = g_total * F[p];
}
} else { // injectors
for (int p = 0; p < baseif_.numPhases(); ++p) {
ws.surface_rates[p] = 0.0;
}
switch (baseif_.wellEcl().injectorType()) {
case InjectorType::WATER:
ws.surface_rates[pu.phase_pos[Water]] = primary_variables_.value_[WQTotal];
break;
case InjectorType::GAS:
ws.surface_rates[pu.phase_pos[Gas]] = primary_variables_.value_[WQTotal];
break;
case InjectorType::OIL:
ws.surface_rates[pu.phase_pos[Oil]] = primary_variables_.value_[WQTotal];
break;
case InjectorType::MULTI:
// Not supported.
deferred_logger.warning("MULTI_PHASE_INJECTOR_NOT_SUPPORTED",
"Multi phase injectors are not supported, requested for well " + baseif_.name());
break;
}
}
this->primary_variables_.copyToWellState(well_state, deferred_logger);
WellBhpThpCalculator(baseif_).
updateThp(this->getRho(),

View File

@ -32,6 +32,8 @@
#include <opm/models/blackoil/blackoilonephaseindices.hh>
#include <opm/models/blackoil/blackoiltwophaseindices.hh>
#include <opm/simulators/utils/DeferredLogger.hpp>
#include <opm/simulators/wells/WellInterfaceIndices.hpp>
#include <opm/simulators/wells/WellState.hpp>
@ -95,6 +97,106 @@ copyToWellStatePolyMW(WellState& well_state) const
}
}
template<class FluidSystem, class Indices, class Scalar>
void StandardWellPrimaryVariables<FluidSystem,Indices,Scalar>::
copyToWellState(WellState& well_state,
DeferredLogger& deferred_logger) const
{
static constexpr int Water = BlackoilPhases::Aqua;
static constexpr int Oil = BlackoilPhases::Liquid;
static constexpr int Gas = BlackoilPhases::Vapour;
const PhaseUsage& pu = well_.phaseUsage();
std::vector<double> F(well_.numPhases(), 0.0);
[[maybe_unused]] double F_solvent = 0.0;
if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)) {
const int oil_pos = pu.phase_pos[Oil];
F[oil_pos] = 1.0;
if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)) {
const int water_pos = pu.phase_pos[Water];
F[water_pos] = value_[WFrac];
F[oil_pos] -= F[water_pos];
}
if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
const int gas_pos = pu.phase_pos[Gas];
F[gas_pos] = value_[GFrac];
F[oil_pos] -= F[gas_pos];
}
if constexpr (Indices::enableSolvent) {
F_solvent = value_[SFrac];
F[oil_pos] -= F_solvent;
}
}
else if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)) {
const int water_pos = pu.phase_pos[Water];
F[water_pos] = 1.0;
if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
const int gas_pos = pu.phase_pos[Gas];
F[gas_pos] = value_[GFrac];
F[water_pos] -= F[gas_pos];
}
}
else if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
const int gas_pos = pu.phase_pos[Gas];
F[gas_pos] = 1.0;
}
// convert the fractions to be Q_p / G_total to calculate the phase rates
for (int p = 0; p < well_.numPhases(); ++p) {
const double scal = well_.scalingFactor(p);
// for injection wells, there should only one non-zero scaling factor
if (scal > 0) {
F[p] /= scal ;
} else {
// this should only happens to injection wells
F[p] = 0.;
}
}
// F_solvent is added to F_gas. This means that well_rate[Gas] also contains solvent.
// More testing is needed to make sure this is correct for well groups and THP.
if constexpr (Indices::enableSolvent) {
F_solvent /= well_.scalingFactor(Indices::contiSolventEqIdx);
F[pu.phase_pos[Gas]] += F_solvent;
}
auto& ws = well_state.well(well_.indexOfWell());
ws.bhp = value_[Bhp];
// calculate the phase rates based on the primary variables
// for producers, this is not a problem, while not sure for injectors here
if (well_.isProducer()) {
const double g_total = value_[WQTotal];
for (int p = 0; p < well_.numPhases(); ++p) {
ws.surface_rates[p] = g_total * F[p];
}
} else { // injectors
for (int p = 0; p < well_.numPhases(); ++p) {
ws.surface_rates[p] = 0.0;
}
switch (well_.wellEcl().injectorType()) {
case InjectorType::WATER:
ws.surface_rates[pu.phase_pos[Water]] = value_[WQTotal];
break;
case InjectorType::GAS:
ws.surface_rates[pu.phase_pos[Gas]] = value_[WQTotal];
break;
case InjectorType::OIL:
ws.surface_rates[pu.phase_pos[Oil]] = value_[WQTotal];
break;
case InjectorType::MULTI:
// Not supported.
deferred_logger.warning("MULTI_PHASE_INJECTOR_NOT_SUPPORTED",
"Multi phase injectors are not supported, requested for well " + well_.name());
break;
}
}
}
#define INSTANCE(...) \
template class StandardWellPrimaryVariables<BlackOilFluidSystem<double,BlackOilDefaultIndexTraits>,__VA_ARGS__,double>;

View File

@ -32,6 +32,7 @@
namespace Opm
{
class DeferredLogger;
template<class FluidSystem, class Indices, class Scalar> class WellInterfaceIndices;
class WellState;
@ -111,6 +112,9 @@ public:
void updatePolyMW(const BVectorWell& dwells);
//! \brief Copy values to well state.
void copyToWellState(WellState& well_state, DeferredLogger& deferred_logger) const;
//! \brief Copy polymer molecular weight values to well state.
void copyToWellStatePolyMW(WellState& well_state) const;
private: