changed: unify MultisegmentdWell::computePerfRate(Eval|Scalar)

This commit is contained in:
Arne Morten Kvarving 2023-05-07 21:56:09 +02:00
parent 58bed1e30a
commit b55ca83917
2 changed files with 58 additions and 104 deletions

View File

@ -194,27 +194,18 @@ namespace Opm
// compute the pressure difference between the perforation and cell center // compute the pressure difference between the perforation and cell center
void computePerfCellPressDiffs(const Simulator& ebosSimulator); void computePerfCellPressDiffs(const Simulator& ebosSimulator);
void computePerfRateScalar(const IntensiveQuantities& int_quants, template<class Value>
const std::vector<Scalar>& mob_perfcells, void computePerfRate(const IntensiveQuantities& int_quants,
const double Tw, const std::vector<Value>& mob_perfcells,
const int seg, const double Tw,
const int perf, const int seg,
const Scalar& segment_pressure, const int perf,
const bool& allow_cf, const Value& segment_pressure,
std::vector<Scalar>& cq_s, const bool& allow_cf,
DeferredLogger& deferred_logger) const; std::vector<Value>& cq_s,
Value& perf_press,
void computePerfRateEval(const IntensiveQuantities& int_quants, PerforationRates& perf_rates,
const std::vector<EvalWell>& mob_perfcells, DeferredLogger& deferred_logger) const;
const double Tw,
const int seg,
const int perf,
const EvalWell& segment_pressure,
const bool& allow_cf,
std::vector<EvalWell>& cq_s,
EvalWell& perf_press,
PerforationRates& perf_rates,
DeferredLogger& deferred_logger) const;
template<class Value> template<class Value>
void computePerfRate(const Value& pressure_cell, void computePerfRate(const Value& pressure_cell,

View File

@ -395,8 +395,10 @@ namespace Opm
const Scalar seg_pressure = segment_pressure[seg]; const Scalar seg_pressure = segment_pressure[seg];
std::vector<Scalar> cq_s(this->num_components_, 0.); std::vector<Scalar> cq_s(this->num_components_, 0.);
computePerfRateScalar(intQuants, mob, Tw, seg, perf, seg_pressure, Scalar perf_press = 0.0;
allow_cf, cq_s, deferred_logger); PerforationRates perf_rates;
computePerfRate(intQuants, mob, Tw, seg, perf, seg_pressure,
allow_cf, cq_s, perf_press, perf_rates, deferred_logger);
for(int p = 0; p < np; ++p) { for(int p = 0; p < np; ++p) {
well_flux[this->ebosCompIdxToFlowCompIdx(p)] += cq_s[p]; well_flux[this->ebosCompIdxToFlowCompIdx(p)] += cq_s[p];
@ -915,29 +917,46 @@ namespace Opm
} }
template <typename TypeTag> template <typename TypeTag>
template<class Value>
void void
MultisegmentWell<TypeTag>:: MultisegmentWell<TypeTag>::
computePerfRateEval(const IntensiveQuantities& int_quants, computePerfRate(const IntensiveQuantities& int_quants,
const std::vector<EvalWell>& mob_perfcells, const std::vector<Value>& mob_perfcells,
const double Tw, const double Tw,
const int seg, const int seg,
const int perf, const int perf,
const EvalWell& segment_pressure, const Value& segment_pressure,
const bool& allow_cf, const bool& allow_cf,
std::vector<EvalWell>& cq_s, std::vector<Value>& cq_s,
EvalWell& perf_press, Value& perf_press,
PerforationRates& perf_rates, PerforationRates& perf_rates,
DeferredLogger& deferred_logger) const DeferredLogger& deferred_logger) const
{ {
auto obtain = [this](const Eval& value)
{
if constexpr (std::is_same_v<Value, Scalar>) {
return getValue(value);
} else {
return this->extendEval(value);
}
};
auto obtainN = [](const auto& value)
{
if constexpr (std::is_same_v<Value, Scalar>) {
return getValue(value);
} else {
return value;
}
};
const auto& fs = int_quants.fluidState(); const auto& fs = int_quants.fluidState();
const EvalWell pressure_cell = this->extendEval(this->getPerfCellPressure(fs)); const Value pressure_cell = obtain(this->getPerfCellPressure(fs));
const EvalWell rs = this->extendEval(fs.Rs()); const Value rs = obtain(fs.Rs());
const EvalWell rv = this->extendEval(fs.Rv()); const Value rv = obtain(fs.Rv());
// not using number_of_phases_ because of solvent // not using number_of_phases_ because of solvent
std::vector<EvalWell> b_perfcells(this->num_components_, 0.0); std::vector<Value> b_perfcells(this->num_components_, 0.0);
for (unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) { for (unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
if (!FluidSystem::phaseIsActive(phaseIdx)) { if (!FluidSystem::phaseIsActive(phaseIdx)) {
@ -945,12 +964,12 @@ namespace Opm
} }
const unsigned compIdx = Indices::canonicalToActiveComponentIndex(FluidSystem::solventComponentIndex(phaseIdx)); const unsigned compIdx = Indices::canonicalToActiveComponentIndex(FluidSystem::solventComponentIndex(phaseIdx));
b_perfcells[compIdx] = this->extendEval(fs.invB(phaseIdx)); b_perfcells[compIdx] = obtain(fs.invB(phaseIdx));
} }
std::vector<EvalWell> cmix_s(this->numComponents(), 0.0); std::vector<Value> cmix_s(this->numComponents(), 0.0);
for (int comp_idx = 0; comp_idx < this->numComponents(); ++comp_idx) { for (int comp_idx = 0; comp_idx < this->numComponents(); ++comp_idx) {
cmix_s[comp_idx] = this->primary_variables_.surfaceVolumeFraction(seg, comp_idx); cmix_s[comp_idx] = obtainN(this->primary_variables_.surfaceVolumeFraction(seg, comp_idx));
} }
this->computePerfRate(pressure_cell, this->computePerfRate(pressure_cell,
@ -961,66 +980,7 @@ namespace Opm
Tw, Tw,
perf, perf,
segment_pressure, segment_pressure,
this->segments_.density(seg), obtainN(this->segments_.density(seg)),
allow_cf,
cmix_s,
cq_s,
perf_press,
perf_rates,
deferred_logger);
}
template <typename TypeTag>
void
MultisegmentWell<TypeTag>::
computePerfRateScalar(const IntensiveQuantities& int_quants,
const std::vector<Scalar>& mob_perfcells,
const double Tw,
const int seg,
const int perf,
const Scalar& segment_pressure,
const bool& allow_cf,
std::vector<Scalar>& cq_s,
DeferredLogger& deferred_logger) const
{
const auto& fs = int_quants.fluidState();
const Scalar pressure_cell = getValue(this->getPerfCellPressure(fs));
const Scalar rs = getValue(fs.Rs());
const Scalar rv = getValue(fs.Rv());
// not using number_of_phases_ because of solvent
std::vector<Scalar> b_perfcells(this->num_components_, 0.0);
for (unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
if (!FluidSystem::phaseIsActive(phaseIdx)) {
continue;
}
const unsigned compIdx = Indices::canonicalToActiveComponentIndex(FluidSystem::solventComponentIndex(phaseIdx));
b_perfcells[compIdx] = getValue(fs.invB(phaseIdx));
}
std::vector<Scalar> cmix_s(this->numComponents(), 0.0);
for (int comp_idx = 0; comp_idx < this->numComponents(); ++comp_idx) {
cmix_s[comp_idx] = getValue(this->primary_variables_.surfaceVolumeFraction(seg, comp_idx));
}
PerforationRates perf_rates;
Scalar perf_press = 0.0;
this->computePerfRate(pressure_cell,
rs,
rv,
b_perfcells,
mob_perfcells,
Tw,
perf,
segment_pressure,
getValue(this->segments_.density(seg)),
allow_cf, allow_cf,
cmix_s, cmix_s,
cq_s, cq_s,
@ -1548,8 +1508,8 @@ namespace Opm
std::vector<EvalWell> cq_s(this->num_components_, 0.0); std::vector<EvalWell> cq_s(this->num_components_, 0.0);
EvalWell perf_press; EvalWell perf_press;
PerforationRates perfRates; PerforationRates perfRates;
computePerfRateEval(int_quants, mob, Tw, seg, perf, seg_pressure, computePerfRate(int_quants, mob, Tw, seg, perf, seg_pressure,
allow_cf, cq_s, perf_press, perfRates, deferred_logger); allow_cf, cq_s, perf_press, perfRates, deferred_logger);
// updating the solution gas rate and solution oil rate // updating the solution gas rate and solution oil rate
if (this->isProducer()) { if (this->isProducer()) {
@ -1858,7 +1818,10 @@ namespace Opm
const double trans_mult = ebosSimulator.problem().template rockCompTransMultiplier<double>(int_quants, cell_idx); const double trans_mult = ebosSimulator.problem().template rockCompTransMultiplier<double>(int_quants, cell_idx);
const double Tw = this->well_index_[perf] * trans_mult; const double Tw = this->well_index_[perf] * trans_mult;
std::vector<Scalar> cq_s(this->num_components_, 0.0); std::vector<Scalar> cq_s(this->num_components_, 0.0);
computePerfRateScalar(int_quants, mob, Tw, seg, perf, seg_pressure, allow_cf, cq_s, deferred_logger); Scalar perf_press = 0.0;
PerforationRates perf_rates;
computePerfRate(int_quants, mob, Tw, seg, perf, seg_pressure,
allow_cf, cq_s, perf_press, perf_rates, deferred_logger);
for (int comp = 0; comp < this->num_components_; ++comp) { for (int comp = 0; comp < this->num_components_; ++comp) {
well_q_s[comp] += cq_s[comp]; well_q_s[comp] += cq_s[comp];
} }