Merge pull request #5858 from akva2/blackoilwellmodel_temperature_constexpr

BlackoilWellModel::computeWellTemperature: use if constexpr
This commit is contained in:
Arne Morten Kvarving 2025-01-15 10:41:25 +01:00 committed by GitHub
commit ecc231a2a2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 52 additions and 53 deletions

View File

@ -2065,13 +2065,13 @@ reportGroupSwitching(DeferredLogger& local_deferredLogger) const
for (const auto& [grname, grdata] : this->switched_inj_groups_) { for (const auto& [grname, grdata] : this->switched_inj_groups_) {
const Phase all[] = {Phase::WATER, Phase::OIL, Phase::GAS}; const Phase all[] = {Phase::WATER, Phase::OIL, Phase::GAS};
for (Phase phase : all) { for (Phase phase : all) {
if (!this->prevWGState().group_state.has_injection_control(grname, phase)) {
continue;
}
const auto& ctrls = grdata[static_cast<std::underlying_type_t<Phase>>(phase)]; const auto& ctrls = grdata[static_cast<std::underlying_type_t<Phase>>(phase)];
if (ctrls.empty()) { if (ctrls.empty()) {
continue; continue;
} }
if ( !this->prevWGState().group_state.has_injection_control(grname, phase))
continue;
const Group::InjectionCMode& oldControl = const Group::InjectionCMode& oldControl =
this->prevWGState().group_state.injection_control(grname, phase); this->prevWGState().group_state.injection_control(grname, phase);
@ -2081,7 +2081,7 @@ reportGroupSwitching(DeferredLogger& local_deferredLogger) const
grname, grname,
Group::InjectionCMode2String(oldControl), Group::InjectionCMode2String(oldControl),
Group::InjectionCMode2String(ctrls.back())); Group::InjectionCMode2String(ctrls.back()));
local_deferredLogger.info(msg); local_deferredLogger.info(msg);
} }
} }
} }

View File

@ -2397,59 +2397,58 @@ namespace Opm {
BlackoilWellModel<TypeTag>:: BlackoilWellModel<TypeTag>::
computeWellTemperature() computeWellTemperature()
{ {
if (!has_energy_) if constexpr (has_energy_) {
return; int np = this->numPhases();
Scalar cellInternalEnergy;
int np = this->numPhases(); Scalar cellBinv;
Scalar cellInternalEnergy; Scalar cellDensity;
Scalar cellBinv; Scalar perfPhaseRate;
Scalar cellDensity; const int nw = this->numLocalWells();
Scalar perfPhaseRate; for (auto wellID = 0*nw; wellID < nw; ++wellID) {
const int nw = this->numLocalWells(); const Well& well = this->wells_ecl_[wellID];
for (auto wellID = 0*nw; wellID < nw; ++wellID) { auto& ws = this->wellState().well(wellID);
const Well& well = this->wells_ecl_[wellID]; if (well.isInjector()) {
auto& ws = this->wellState().well(wellID); if (ws.status != WellStatus::STOP) {
if (well.isInjector()){ this->wellState().well(wellID).temperature = well.inj_temperature();
if( !(ws.status == WellStatus::STOP)){
this->wellState().well(wellID).temperature = well.inj_temperature();
continue;
}
}
std::array<Scalar,2> weighted{0.0,0.0};
auto& [weighted_temperature, total_weight] = weighted;
auto& well_info = this->local_parallel_well_info_[wellID].get();
auto& perf_data = ws.perf_data;
auto& perf_phase_rate = perf_data.phase_rates;
using int_type = decltype(this->well_perf_data_[wellID].size());
for (int_type perf = 0, end_perf = this->well_perf_data_[wellID].size(); perf < end_perf; ++perf) {
const int cell_idx = this->well_perf_data_[wellID][perf].cell_index;
const auto& intQuants = simulator_.model().intensiveQuantities(cell_idx, /*timeIdx=*/0);
const auto& fs = intQuants.fluidState();
// we on only have one temperature pr cell any phaseIdx will do
Scalar cellTemperatures = fs.temperature(/*phaseIdx*/0).value();
Scalar weight_factor = 0.0;
for (unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx)
{
if (!FluidSystem::phaseIsActive(phaseIdx)) {
continue; continue;
} }
cellInternalEnergy = fs.enthalpy(phaseIdx).value() - fs.pressure(phaseIdx).value() / fs.density(phaseIdx).value();
cellBinv = fs.invB(phaseIdx).value();
cellDensity = fs.density(phaseIdx).value();
perfPhaseRate = perf_phase_rate[ perf*np + phaseIdx ];
weight_factor += cellDensity * perfPhaseRate/cellBinv * cellInternalEnergy/cellTemperatures;
} }
weight_factor = std::abs(weight_factor)+1e-13;
total_weight += weight_factor; std::array<Scalar,2> weighted{0.0,0.0};
weighted_temperature += weight_factor * cellTemperatures; auto& [weighted_temperature, total_weight] = weighted;
auto& well_info = this->local_parallel_well_info_[wellID].get();
auto& perf_data = ws.perf_data;
auto& perf_phase_rate = perf_data.phase_rates;
using int_type = decltype(this->well_perf_data_[wellID].size());
for (int_type perf = 0, end_perf = this->well_perf_data_[wellID].size(); perf < end_perf; ++perf) {
const int cell_idx = this->well_perf_data_[wellID][perf].cell_index;
const auto& intQuants = simulator_.model().intensiveQuantities(cell_idx, /*timeIdx=*/0);
const auto& fs = intQuants.fluidState();
// we on only have one temperature pr cell any phaseIdx will do
Scalar cellTemperatures = fs.temperature(/*phaseIdx*/0).value();
Scalar weight_factor = 0.0;
for (unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
if (!FluidSystem::phaseIsActive(phaseIdx)) {
continue;
}
cellInternalEnergy = fs.enthalpy(phaseIdx).value() -
fs.pressure(phaseIdx).value() / fs.density(phaseIdx).value();
cellBinv = fs.invB(phaseIdx).value();
cellDensity = fs.density(phaseIdx).value();
perfPhaseRate = perf_phase_rate[perf*np + phaseIdx];
weight_factor += cellDensity * perfPhaseRate / cellBinv * cellInternalEnergy / cellTemperatures;
}
weight_factor = std::abs(weight_factor) + 1e-13;
total_weight += weight_factor;
weighted_temperature += weight_factor * cellTemperatures;
}
well_info.communication().sum(weighted.data(), 2);
this->wellState().well(wellID).temperature = weighted_temperature / total_weight;
} }
well_info.communication().sum(weighted.data(), 2);
this->wellState().well(wellID).temperature = weighted_temperature/total_weight;
} }
} }