diff --git a/opm/simulators/wells/BlackoilWellModelGeneric.cpp b/opm/simulators/wells/BlackoilWellModelGeneric.cpp index 4d17080b7..c19d664f7 100644 --- a/opm/simulators/wells/BlackoilWellModelGeneric.cpp +++ b/opm/simulators/wells/BlackoilWellModelGeneric.cpp @@ -2065,13 +2065,13 @@ reportGroupSwitching(DeferredLogger& local_deferredLogger) const for (const auto& [grname, grdata] : this->switched_inj_groups_) { const Phase all[] = {Phase::WATER, Phase::OIL, Phase::GAS}; for (Phase phase : all) { + if (!this->prevWGState().group_state.has_injection_control(grname, phase)) { + continue; + } const auto& ctrls = grdata[static_cast>(phase)]; - if (ctrls.empty()) { continue; } - if ( !this->prevWGState().group_state.has_injection_control(grname, phase)) - continue; const Group::InjectionCMode& oldControl = this->prevWGState().group_state.injection_control(grname, phase); @@ -2081,7 +2081,7 @@ reportGroupSwitching(DeferredLogger& local_deferredLogger) const grname, Group::InjectionCMode2String(oldControl), Group::InjectionCMode2String(ctrls.back())); - local_deferredLogger.info(msg); + local_deferredLogger.info(msg); } } } diff --git a/opm/simulators/wells/BlackoilWellModel_impl.hpp b/opm/simulators/wells/BlackoilWellModel_impl.hpp index 2d2a77226..97e78e36a 100644 --- a/opm/simulators/wells/BlackoilWellModel_impl.hpp +++ b/opm/simulators/wells/BlackoilWellModel_impl.hpp @@ -2397,59 +2397,58 @@ namespace Opm { BlackoilWellModel:: computeWellTemperature() { - if (!has_energy_) - return; - - int np = this->numPhases(); - Scalar cellInternalEnergy; - Scalar cellBinv; - Scalar cellDensity; - Scalar perfPhaseRate; - const int nw = this->numLocalWells(); - for (auto wellID = 0*nw; wellID < nw; ++wellID) { - const Well& well = this->wells_ecl_[wellID]; - auto& ws = this->wellState().well(wellID); - if (well.isInjector()){ - if( !(ws.status == WellStatus::STOP)){ - this->wellState().well(wellID).temperature = well.inj_temperature(); - continue; - } - } - - std::array 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)) { + if constexpr (has_energy_) { + int np = this->numPhases(); + Scalar cellInternalEnergy; + Scalar cellBinv; + Scalar cellDensity; + Scalar perfPhaseRate; + const int nw = this->numLocalWells(); + for (auto wellID = 0*nw; wellID < nw; ++wellID) { + const Well& well = this->wells_ecl_[wellID]; + auto& ws = this->wellState().well(wellID); + if (well.isInjector()) { + if (ws.status != WellStatus::STOP) { + this->wellState().well(wellID).temperature = well.inj_temperature(); 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; + + std::array 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; + } + 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; } }