mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
make has_polymermw constexpr and use if constexpr to eliminate code
This commit is contained in:
parent
dd04eb128a
commit
268201eeb1
@ -79,12 +79,14 @@ namespace Opm
|
||||
}
|
||||
|
||||
// counting/updating primary variable numbers
|
||||
if (this->has_polymermw && this->isInjector()) {
|
||||
if constexpr (Base::has_polymermw) {
|
||||
if (this->isInjector()) {
|
||||
// adding a primary variable for water perforation rate per connection
|
||||
numWellEq_ += number_of_perforations_;
|
||||
// adding a primary variable for skin pressure per connection
|
||||
numWellEq_ += number_of_perforations_;
|
||||
}
|
||||
}
|
||||
|
||||
// with the updated numWellEq_, we can initialize the primary variables and matrices now
|
||||
primary_variables_.resize(numWellEq_, 0.0);
|
||||
@ -406,11 +408,13 @@ namespace Opm
|
||||
const EvalWell well_pressure = bhp + perf_pressure_diffs_[perf];
|
||||
EvalWell drawdown = pressure - well_pressure;
|
||||
|
||||
if (this->has_polymermw && this->isInjector()) {
|
||||
if constexpr (Base::has_polymermw) {
|
||||
if (this->isInjector()) {
|
||||
const int pskin_index = Bhp + 1 + number_of_perforations_ + perf;
|
||||
const EvalWell& skin_pressure = primary_variables_evaluation_[pskin_index];
|
||||
drawdown += skin_pressure;
|
||||
}
|
||||
}
|
||||
|
||||
// producing perforations
|
||||
if ( drawdown.value() > 0 ) {
|
||||
@ -596,9 +600,11 @@ namespace Opm
|
||||
calculateSinglePerf(ebosSimulator, perf, well_state, connectionRates, cq_s, water_flux_s, cq_s_zfrac_effective, deferred_logger);
|
||||
|
||||
// Equation assembly for this perforation.
|
||||
if (has_polymer && this->has_polymermw && this->isInjector()) {
|
||||
if constexpr (has_polymer && Base::has_polymermw) {
|
||||
if (this->isInjector()) {
|
||||
handleInjectivityEquations(ebosSimulator, well_state, perf, water_flux_s, deferred_logger);
|
||||
}
|
||||
}
|
||||
const int cell_idx = well_cells_[perf];
|
||||
for (int componentIdx = 0; componentIdx < num_components_; ++componentIdx) {
|
||||
// the cq_s entering mass balance equations need to consider the efficiency factors.
|
||||
@ -698,7 +704,8 @@ namespace Opm
|
||||
computePerfRate(intQuants, mob, bhp, Tw, perf, allow_cf,
|
||||
cq_s, perf_dis_gas_rate, perf_vap_oil_rate, deferred_logger);
|
||||
|
||||
if (has_polymer && this->has_polymermw && this->isInjector()) {
|
||||
if constexpr (has_polymer && Base::has_polymermw) {
|
||||
if (this->isInjector()) {
|
||||
// Store the original water flux computed from the reservoir quantities.
|
||||
// It will be required to assemble the injectivity equations.
|
||||
const unsigned water_comp_idx = Indices::canonicalToActiveComponentIndex(FluidSystem::waterCompIdx);
|
||||
@ -707,6 +714,7 @@ namespace Opm
|
||||
// local water velocity primary variable.
|
||||
handleInjectivityRate(ebosSimulator, perf, cq_s);
|
||||
}
|
||||
}
|
||||
|
||||
// updating the solution gas rate and solution oil rate
|
||||
if (this->isProducer()) {
|
||||
@ -790,7 +798,7 @@ namespace Opm
|
||||
cq_s_poly *= well_efficiency_factor_;
|
||||
connectionRates[perf][contiPolymerEqIdx] = Base::restrictEval(cq_s_poly);
|
||||
|
||||
if (this->has_polymermw) {
|
||||
if constexpr (Base::has_polymermw) {
|
||||
updateConnectionRatePolyMW(cq_s_poly, intQuants, well_state, perf, connectionRates, deferred_logger);
|
||||
}
|
||||
}
|
||||
@ -970,9 +978,13 @@ namespace Opm
|
||||
OPM_DEFLOG_THROW(std::runtime_error, "Water is required when polymer is active", deferred_logger);
|
||||
}
|
||||
|
||||
// for the cases related to polymer molecular weight, we assume fully mixing
|
||||
// as a result, the polymer and water share the same viscosity
|
||||
if constexpr (!Base::has_polymermw) {
|
||||
updateWaterMobilityWithPolymer(ebosSimulator, perf, mob, deferred_logger);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -1068,7 +1080,8 @@ namespace Opm
|
||||
updateExtraPrimaryVariables(const BVectorWell& dwells) const
|
||||
{
|
||||
// for the water velocity and skin pressure
|
||||
if (this->has_polymermw && this->isInjector()) {
|
||||
if constexpr (Base::has_polymermw) {
|
||||
if (this->isInjector()) {
|
||||
for (int perf = 0; perf < number_of_perforations_; ++perf) {
|
||||
const int wat_vel_index = Bhp + 1 + perf;
|
||||
const int pskin_index = Bhp + 1 + number_of_perforations_ + perf;
|
||||
@ -1082,6 +1095,7 @@ namespace Opm
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -1284,13 +1298,15 @@ namespace Opm
|
||||
updateThp(well_state, deferred_logger);
|
||||
|
||||
// other primary variables related to polymer injectivity study
|
||||
if (this->has_polymermw && this->isInjector()) {
|
||||
if constexpr (Base::has_polymermw) {
|
||||
if (this->isInjector()) {
|
||||
for (int perf = 0; perf < number_of_perforations_; ++perf) {
|
||||
well_state.perfWaterVelocity()[first_perf_ + perf] = primary_variables_[Bhp + 1 + perf];
|
||||
well_state.perfSkinPressure()[first_perf_ + perf] = primary_variables_[Bhp + 1 + number_of_perforations_ + perf];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -2787,12 +2803,14 @@ namespace Opm
|
||||
primary_variables_[Bhp] = well_state.bhp()[index_of_well_];
|
||||
|
||||
// other primary variables related to polymer injection
|
||||
if (this->has_polymermw && this->isInjector()) {
|
||||
if constexpr (Base::has_polymermw) {
|
||||
if (this->isInjector()) {
|
||||
for (int perf = 0; perf < number_of_perforations_; ++perf) {
|
||||
primary_variables_[Bhp + 1 + perf] = well_state.perfWaterVelocity()[first_perf_ + perf];
|
||||
primary_variables_[Bhp + 1 + number_of_perforations_ + perf] = well_state.perfSkinPressure()[first_perf_ + perf];
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifndef NDEBUG
|
||||
for (double v : primary_variables_) {
|
||||
assert(Opm::isfinite(v));
|
||||
@ -2862,11 +2880,6 @@ namespace Opm
|
||||
std::vector<EvalWell>& mob,
|
||||
Opm::DeferredLogger& deferred_logger) const
|
||||
{
|
||||
// for the cases related to polymer molecular weight, we assume fully mixing
|
||||
// as a result, the polymer and water share the same viscosity
|
||||
if (this->has_polymermw) {
|
||||
return;
|
||||
}
|
||||
const int cell_idx = well_cells_[perf];
|
||||
const auto& int_quant = *(ebos_simulator.model().cachedIntensiveQuantities(cell_idx, /*timeIdx=*/ 0));
|
||||
const EvalWell polymer_concentration = extendEval(int_quant.polymerConcentration());
|
||||
@ -3063,10 +3076,7 @@ namespace Opm
|
||||
const EvalWell& water_velocity,
|
||||
Opm::DeferredLogger& deferred_logger) const
|
||||
{
|
||||
if (!this->has_polymermw) {
|
||||
OPM_DEFLOG_THROW(std::runtime_error, "Polymermw is not activated, "
|
||||
"while injecting skin pressure is requested for well " << name(), deferred_logger);
|
||||
}
|
||||
if constexpr (Base::has_polymermw) {
|
||||
const int water_table_id = well_ecl_.getPolymerProperties().m_skprwattable;
|
||||
if (water_table_id <= 0) {
|
||||
OPM_DEFLOG_THROW(std::runtime_error, "Unused SKPRWAT table id used for well " << name(), deferred_logger);
|
||||
@ -3077,6 +3087,10 @@ namespace Opm
|
||||
EvalWell pskin_water(numWellEq_ + numEq, 0.0);
|
||||
pskin_water = water_table_func.eval(throughput_eval, water_velocity);
|
||||
return pskin_water;
|
||||
} else {
|
||||
OPM_DEFLOG_THROW(std::runtime_error, "Polymermw is not activated, "
|
||||
"while injecting skin pressure is requested for well " << name(), deferred_logger);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -3091,10 +3105,7 @@ namespace Opm
|
||||
const EvalWell& poly_inj_conc,
|
||||
Opm::DeferredLogger& deferred_logger) const
|
||||
{
|
||||
if (!this->has_polymermw) {
|
||||
OPM_DEFLOG_THROW(std::runtime_error, "Polymermw is not activated, "
|
||||
"while injecting skin pressure is requested for well " << name(), deferred_logger);
|
||||
}
|
||||
if constexpr (Base::has_polymermw) {
|
||||
const double sign = water_velocity >= 0. ? 1.0 : -1.0;
|
||||
const EvalWell water_velocity_abs = Opm::abs(water_velocity);
|
||||
if (poly_inj_conc == 0.) {
|
||||
@ -3117,6 +3128,10 @@ namespace Opm
|
||||
const EvalWell pskin_water = pskinwater(throughput, water_velocity_abs, deferred_logger);
|
||||
const EvalWell pskin = pskin_water + (pskin_poly - pskin_water) / reference_concentration * poly_inj_conc;
|
||||
return sign * pskin;
|
||||
} else {
|
||||
OPM_DEFLOG_THROW(std::runtime_error, "Polymermw is not activated, "
|
||||
"while injecting skin pressure is requested for well " << name(), deferred_logger);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -3130,10 +3145,7 @@ namespace Opm
|
||||
const EvalWell& water_velocity,
|
||||
Opm::DeferredLogger& deferred_logger) const
|
||||
{
|
||||
if (!this->has_polymermw) {
|
||||
OPM_DEFLOG_THROW(std::runtime_error, "Polymermw is not activated, "
|
||||
"while injecting polymer molecular weight is requested for well " << name(), deferred_logger);
|
||||
}
|
||||
if constexpr (Base::has_polymermw) {
|
||||
const int table_id = well_ecl_.getPolymerProperties().m_plymwinjtable;
|
||||
const auto& table_func = PolymerModule::getPlymwinjTable(table_id);
|
||||
const EvalWell throughput_eval(numWellEq_ + numEq, throughput);
|
||||
@ -3143,6 +3155,10 @@ namespace Opm
|
||||
}
|
||||
molecular_weight = table_func.eval(throughput_eval, Opm::abs(water_velocity));
|
||||
return molecular_weight;
|
||||
} else {
|
||||
OPM_DEFLOG_THROW(std::runtime_error, "Polymermw is not activated, "
|
||||
"while injecting polymer molecular weight is requested for well " << name(), deferred_logger);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -3154,7 +3170,8 @@ namespace Opm
|
||||
StandardWell<TypeTag>::
|
||||
updateWaterThroughput(const double dt, WellState &well_state) const
|
||||
{
|
||||
if (this->has_polymermw && this->isInjector()) {
|
||||
if constexpr (Base::has_polymermw) {
|
||||
if (this->isInjector()) {
|
||||
for (int perf = 0; perf < number_of_perforations_; ++perf) {
|
||||
const double perf_water_vel = primary_variables_[Bhp + 1 + perf];
|
||||
// we do not consider the formation damage due to water flowing from reservoir into wellbore
|
||||
@ -3164,6 +3181,7 @@ namespace Opm
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -3336,7 +3354,8 @@ namespace Opm
|
||||
// if different types of extra equations are involved, this function needs to be refactored further
|
||||
|
||||
// checking the convergence of the extra equations related to polymer injectivity
|
||||
if (this->has_polymermw && this->isInjector()) {
|
||||
if constexpr (Base::has_polymermw) {
|
||||
if (this->isInjector()) {
|
||||
// checking the convergence of the perforation rates
|
||||
const double wat_vel_tol = 1.e-8;
|
||||
const int dummy_component = -1;
|
||||
@ -3369,6 +3388,7 @@ namespace Opm
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -111,7 +111,7 @@ namespace Opm
|
||||
static const bool has_energy = getPropValue<TypeTag, Properties::EnableEnergy>();
|
||||
static const bool has_temperature = getPropValue<TypeTag, Properties::EnableTemperature>();
|
||||
// flag for polymer molecular weight related
|
||||
static const bool has_polymermw = getPropValue<TypeTag, Properties::EnablePolymerMW>();
|
||||
static constexpr bool has_polymermw = getPropValue<TypeTag, Properties::EnablePolymerMW>();
|
||||
static constexpr bool has_foam = getPropValue<TypeTag, Properties::EnableFoam>();
|
||||
static constexpr bool has_brine = getPropValue<TypeTag, Properties::EnableBrine>();
|
||||
static const int contiSolventEqIdx = Indices::contiSolventEqIdx;
|
||||
|
Loading…
Reference in New Issue
Block a user