From daced473015f2c24f7bf5f87c3c8bd0b8c31136e Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Fri, 4 Aug 2023 12:37:48 +0200 Subject: [PATCH] move output of fip log to LogOutputHelper --- ebos/eclgenericoutputblackoilmodule.cc | 134 +---------------- ebos/eclgenericoutputblackoilmodule.hh | 5 - opm/simulators/flow/LogOutputHelper.cpp | 182 ++++++++++++++++++++++++ opm/simulators/flow/LogOutputHelper.hpp | 16 +++ 4 files changed, 201 insertions(+), 136 deletions(-) diff --git a/ebos/eclgenericoutputblackoilmodule.cc b/ebos/eclgenericoutputblackoilmodule.cc index aa2f448ab..d17346bf8 100644 --- a/ebos/eclgenericoutputblackoilmodule.cc +++ b/ebos/eclgenericoutputblackoilmodule.cc @@ -271,8 +271,9 @@ outputFipLog(std::map& miscSummaryData, miscSummaryData, regionData); - if (!substep) - outputFipLogImpl(inplace); + if (!substep && !forceDisableFipOutput_) { + logOutput_.fip(inplace, this->initialInplace()); + } return inplace; } @@ -1085,75 +1086,6 @@ pressureUnitConvert_(Scalar& pav) const .from_si(UnitSystem::measure::pressure, pav); } -template -void EclGenericOutputBlackoilModule:: -outputRegionFluidInPlace_(std::unordered_map oip, - std::unordered_map cip, - const Scalar& pav, const int reg) const -{ - if (forceDisableFipOutput_) - return; - - // don't output FIPNUM report if the region has no porv. - if (! (cip[Inplace::Phase::PoreVolume] > Scalar{0})) - return; - - const UnitSystem& units = eclState_.getUnits(); - std::ostringstream ss; - - ss << '\n'; - if (reg == 0) { - ss << "Field total"; - } - else { - ss << "FIPNUM report region " << reg; - } - - ss << " pressure dependent pore volume = " - << std::fixed << std::setprecision(0) - << cip[Inplace::Phase::DynamicPoreVolume] << ' ' - << units.name(UnitSystem::measure::volume) << "\n\n"; - - if (reg == 0) { - ss << " ===================================================\n" - << " : Field Totals :\n"; - } - else { - ss << " ===================================================\n" - << " : FIPNUM report region " - << std::setw(2) << reg << " :\n"; - } - if (units.getType() == UnitSystem::UnitType::UNIT_TYPE_METRIC) { - ss << " : PAV =" << std::setw(14) << pav << " BARSA :\n" - << std::fixed << std::setprecision(0) - << " : PORV =" << std::setw(14) << cip[Inplace::Phase::PoreVolume] << " RM3 :\n"; - if (!reg) { - ss << " : Pressure is weighted by hydrocarbon pore volume :\n" - << " : Porv volumes are taken at reference conditions :\n"; - } - ss << " :--------------- Oil SM3 ---------------:-- Wat SM3 --:--------------- Gas SM3 ---------------:\n"; - } - if (units.getType() == UnitSystem::UnitType::UNIT_TYPE_FIELD) { - ss << " : PAV =" << std::setw(14) << pav << " PSIA :\n" - << std::fixed << std::setprecision(0) - << " : PORV =" << std::setw(14) << cip[Inplace::Phase::PoreVolume] << " RB :\n"; - if (!reg) { - ss << " : Pressure is weighted by hydrocarbon pore volume :\n" - << " : Pore volumes are taken at reference conditions :\n"; - } - ss << " :--------------- Oil STB ---------------:-- Wat STB --:--------------- Gas MSCF ---------------:\n"; - } - ss << " : Liquid Vapour Total : Total : Free Dissolved Total :" << "\n" - << ":------------------------:------------------------------------------:----------------:------------------------------------------:" << "\n" - << ":Currently in place :" << std::setw(14) << cip[Inplace::Phase::OilInLiquidPhase] << std::setw(14) << cip[Inplace::Phase::OilInGasPhase] << std::setw(14) << cip[Inplace::Phase::OIL] << ":" - << std::setw(13) << cip[Inplace::Phase::WATER] << " :" << std::setw(14) << (cip[Inplace::Phase::GasInGasPhase]) << std::setw(14) << cip[Inplace::Phase::GasInLiquidPhase] << std::setw(14) << cip[Inplace::Phase::GAS] << ":\n" - << ":------------------------:------------------------------------------:----------------:------------------------------------------:\n" - << ":Originally in place :" << std::setw(14) << oip[Inplace::Phase::OilInLiquidPhase] << std::setw(14) << oip[Inplace::Phase::OilInGasPhase] << std::setw(14) << oip[Inplace::Phase::OIL] << ":" - << std::setw(13) << oip[Inplace::Phase::WATER] << " :" << std::setw(14) << oip[Inplace::Phase::GasInGasPhase] << std::setw(14) << oip[Inplace::Phase::GasInLiquidPhase] << std::setw(14) << oip[Inplace::Phase::GAS] << ":\n" - << ":========================:==========================================:================:==========================================:\n"; - OpmLog::note(ss.str()); -} - template void EclGenericOutputBlackoilModule:: outputResvFluidInPlace_(std::unordered_map cipr, const int reg) const @@ -1271,66 +1203,6 @@ outputErrorLog(const Parallel::Communication& comm) const ijkString); } -template -void EclGenericOutputBlackoilModule:: -outputFipLogImpl(const Inplace& inplace) const -{ - { - Scalar fieldHydroCarbonPoreVolumeAveragedPressure = - detail::pressureAverage(inplace.get(Inplace::Phase::PressureHydroCarbonPV), - inplace.get(Inplace::Phase::HydroCarbonPV), - inplace.get(Inplace::Phase::PressurePV), - inplace.get(Inplace::Phase::DynamicPoreVolume), - true); - - std::unordered_map initial_values; - std::unordered_map current_values; - - for (const auto& phase : Inplace::phases()) { - initial_values[phase] = this->initialInplace_->get(phase); - current_values[phase] = inplace.get(phase); - } - - current_values[Inplace::Phase::DynamicPoreVolume] = - inplace.get(Inplace::Phase::DynamicPoreVolume); - - fipUnitConvert_(initial_values); - fipUnitConvert_(current_values); - - pressureUnitConvert_(fieldHydroCarbonPoreVolumeAveragedPressure); - outputRegionFluidInPlace_(std::move(initial_values), - std::move(current_values), - fieldHydroCarbonPoreVolumeAveragedPressure); - } - - for (size_t reg = 1; reg <= inplace.max_region("FIPNUM"); ++reg) { - std::unordered_map initial_values; - std::unordered_map current_values; - - for (const auto& phase : Inplace::phases()) { - initial_values[phase] = this->initialInplace_->get("FIPNUM", phase, reg); - current_values[phase] = inplace.get("FIPNUM", phase, reg); - } - - current_values[Inplace::Phase::DynamicPoreVolume] = - inplace.get("FIPNUM", Inplace::Phase::DynamicPoreVolume, reg); - - fipUnitConvert_(initial_values); - fipUnitConvert_(current_values); - - Scalar regHydroCarbonPoreVolumeAveragedPressure = - detail::pressureAverage(inplace.get("FIPNUM", Inplace::Phase::PressureHydroCarbonPV, reg), - inplace.get("FIPNUM", Inplace::Phase::HydroCarbonPV, reg), - inplace.get("FIPNUM", Inplace::Phase::PressurePV, reg), - inplace.get("FIPNUM", Inplace::Phase::DynamicPoreVolume, reg), - true); - pressureUnitConvert_(regHydroCarbonPoreVolumeAveragedPressure); - outputRegionFluidInPlace_(std::move(initial_values), - std::move(current_values), - regHydroCarbonPoreVolumeAveragedPressure, reg); - } -} - template void EclGenericOutputBlackoilModule:: outputFipresvLogImpl(const Inplace& inplace) const diff --git a/ebos/eclgenericoutputblackoilmodule.hh b/ebos/eclgenericoutputblackoilmodule.hh index 20383752d..4b0e793b1 100644 --- a/ebos/eclgenericoutputblackoilmodule.hh +++ b/ebos/eclgenericoutputblackoilmodule.hh @@ -308,14 +308,9 @@ protected: void pressureUnitConvert_(Scalar& pav) const; - void outputRegionFluidInPlace_(std::unordered_map oip, - std::unordered_map cip, - const Scalar& pav, const int reg = 0) const; void outputResvFluidInPlace_(std::unordered_map cipr, const int reg = 0) const; - void outputFipLogImpl(const Inplace& inplace) const; - void outputFipresvLogImpl(const Inplace& inplace) const; void makeRegionSum(Inplace& inplace, diff --git a/opm/simulators/flow/LogOutputHelper.cpp b/opm/simulators/flow/LogOutputHelper.cpp index 6b9eb1236..8b5bd0eda 100644 --- a/opm/simulators/flow/LogOutputHelper.cpp +++ b/opm/simulators/flow/LogOutputHelper.cpp @@ -27,6 +27,8 @@ #include #include +#include + #include #include #include @@ -183,6 +185,67 @@ cumulative(const std::size_t reportStepNum, } } +template +void LogOutputHelper:: +fip(const Inplace& inplace, + const Inplace& initialInplace) const +{ + { + Scalar fieldHydroCarbonPoreVolumeAveragedPressure = + detail::pressureAverage(inplace.get(Inplace::Phase::PressureHydroCarbonPV), + inplace.get(Inplace::Phase::HydroCarbonPV), + inplace.get(Inplace::Phase::PressurePV), + inplace.get(Inplace::Phase::DynamicPoreVolume), + true); + + std::unordered_map initial_values; + std::unordered_map current_values; + + for (const auto& phase : Inplace::phases()) { + initial_values[phase] = initialInplace.get(phase); + current_values[phase] = inplace.get(phase); + } + + current_values[Inplace::Phase::DynamicPoreVolume] = + inplace.get(Inplace::Phase::DynamicPoreVolume); + + this->fipUnitConvert_(initial_values); + this->fipUnitConvert_(current_values); + + this->pressureUnitConvert_(fieldHydroCarbonPoreVolumeAveragedPressure); + this->outputRegionFluidInPlace_(std::move(initial_values), + std::move(current_values), + fieldHydroCarbonPoreVolumeAveragedPressure, 0); + } + + for (std::size_t reg = 1; reg <= inplace.max_region("FIPNUM"); ++reg) { + std::unordered_map initial_values; + std::unordered_map current_values; + + for (const auto& phase : Inplace::phases()) { + initial_values[phase] = initialInplace.get("FIPNUM", phase, reg); + current_values[phase] = inplace.get("FIPNUM", phase, reg); + } + + current_values[Inplace::Phase::DynamicPoreVolume] = + inplace.get("FIPNUM", Inplace::Phase::DynamicPoreVolume, reg); + + this->fipUnitConvert_(initial_values); + this->fipUnitConvert_(current_values); + + Scalar regHydroCarbonPoreVolumeAveragedPressure = + detail::pressureAverage(inplace.get("FIPNUM", Inplace::Phase::PressureHydroCarbonPV, reg), + inplace.get("FIPNUM", Inplace::Phase::HydroCarbonPV, reg), + inplace.get("FIPNUM", Inplace::Phase::PressurePV, reg), + inplace.get("FIPNUM", Inplace::Phase::DynamicPoreVolume, reg), + true); + this->pressureUnitConvert_(regHydroCarbonPoreVolumeAveragedPressure); + this->outputRegionFluidInPlace_(std::move(initial_values), + std::move(current_values), + regHydroCarbonPoreVolumeAveragedPressure, reg); + } +} + template void LogOutputHelper:: injection(const std::size_t reportStepNum, @@ -587,6 +650,125 @@ outputProductionReport_(const std::vector& wellProd, OpmLog::note(ss.str()); } +template +void LogOutputHelper:: +outputRegionFluidInPlace_(std::unordered_map oip, + std::unordered_map cip, + const Scalar pav, + const int reg) const +{ + // don't output FIPNUM report if the region has no porv. + if (! (cip[Inplace::Phase::PoreVolume] > Scalar{0})) { + return; + } + + const UnitSystem& units = eclState_.getUnits(); + std::ostringstream ss; + + ss << '\n'; + if (reg == 0) { + ss << "Field total"; + } else { + ss << "FIPNUM report region " << reg; + } + + ss << " pressure dependent pore volume = " + << std::fixed << std::setprecision(0) + << cip[Inplace::Phase::DynamicPoreVolume] << ' ' + << units.name(UnitSystem::measure::volume) << "\n\n"; + + if (reg == 0) { + ss << " ===================================================\n" + << " : Field Totals :\n"; + } + else { + ss << " ===================================================\n" + << " : FIPNUM report region " + << std::setw(2) << reg << " :\n"; + } + if (units.getType() == UnitSystem::UnitType::UNIT_TYPE_METRIC) { + ss << " : PAV =" << std::setw(14) << pav << " BARSA :\n" + << std::fixed << std::setprecision(0) + << " : PORV =" << std::setw(14) << cip[Inplace::Phase::PoreVolume] << " RM3 :\n"; + if (!reg) { + ss << " : Pressure is weighted by hydrocarbon pore volume :\n" + << " : Porv volumes are taken at reference conditions :\n"; + } + ss << " :--------------- Oil SM3 ---------------:-- Wat SM3 --:--------------- Gas SM3 ---------------:\n"; + } else if (units.getType() == UnitSystem::UnitType::UNIT_TYPE_FIELD) { + ss << " : PAV =" << std::setw(14) << pav << " PSIA :\n" + << std::fixed << std::setprecision(0) + << " : PORV =" << std::setw(14) << cip[Inplace::Phase::PoreVolume] << " RB :\n"; + if (!reg) { + ss << " : Pressure is weighted by hydrocarbon pore volume :\n" + << " : Pore volumes are taken at reference conditions :\n"; + } + ss << " :--------------- Oil STB ---------------:-- Wat STB --:--------------- Gas MSCF ---------------:\n"; + } + ss << " : Liquid Vapour Total : Total : Free Dissolved Total :" << "\n" + << ":------------------------:------------------------------------------:----------------:------------------------------------------:" << "\n" + << ":Currently in place :" << std::setw(14) << cip[Inplace::Phase::OilInLiquidPhase] + << std::setw(14) << cip[Inplace::Phase::OilInGasPhase] + << std::setw(14) << cip[Inplace::Phase::OIL] << ":" + << std::setw(13) << cip[Inplace::Phase::WATER] << " :" + << std::setw(14) << (cip[Inplace::Phase::GasInGasPhase]) + << std::setw(14) << cip[Inplace::Phase::GasInLiquidPhase] + << std::setw(14) << cip[Inplace::Phase::GAS] << ":\n" + << ":------------------------:------------------------------------------:----------------:------------------------------------------:\n" + << ":Originally in place :" << std::setw(14) << oip[Inplace::Phase::OilInLiquidPhase] + << std::setw(14) << oip[Inplace::Phase::OilInGasPhase] + << std::setw(14) << oip[Inplace::Phase::OIL] << ":" + << std::setw(13) << oip[Inplace::Phase::WATER] << " :" + << std::setw(14) << oip[Inplace::Phase::GasInGasPhase] + << std::setw(14) << oip[Inplace::Phase::GasInLiquidPhase] + << std::setw(14) << oip[Inplace::Phase::GAS] << ":\n" + << ":========================:==========================================:================:==========================================:\n"; + OpmLog::note(ss.str()); +} + +template +void LogOutputHelper:: +fipUnitConvert_(std::unordered_map& fip) const +{ + const UnitSystem& units = eclState_.getUnits(); + using M = UnitSystem::measure; + const auto unit_map = std::unordered_map { + {Inplace::Phase::WATER, M::liquid_surface_volume}, + {Inplace::Phase::OIL, M::liquid_surface_volume}, + {Inplace::Phase::OilInLiquidPhase, M::liquid_surface_volume}, + {Inplace::Phase::OilInGasPhase, M::liquid_surface_volume}, + {Inplace::Phase::GAS, M::gas_surface_volume}, + {Inplace::Phase::GasInLiquidPhase, M::gas_surface_volume}, + {Inplace::Phase::GasInGasPhase, M::gas_surface_volume}, + {Inplace::Phase::PoreVolume, M::volume}, + {Inplace::Phase::DynamicPoreVolume, M::volume}, + {Inplace::Phase::WaterResVolume, M::volume}, + {Inplace::Phase::OilResVolume, M::volume}, + {Inplace::Phase::GasResVolume, M::volume}, + {Inplace::Phase::SALT, M::mass}, + {Inplace::Phase::CO2InWaterPhase, M::moles}, + {Inplace::Phase::CO2InGasPhaseInMob,M::moles}, + {Inplace::Phase::CO2InGasPhaseMob, M::moles}, + {Inplace::Phase::WaterInWaterPhase, M::liquid_surface_volume}, + {Inplace::Phase::WaterInGasPhase, M::liquid_surface_volume}, + }; + + for (auto& [phase, value] : fip) { + auto unitPos = unit_map.find(phase); + if (unitPos != unit_map.end()) { + value = units.from_si(unitPos->second, value); + } + } +} + +template +void LogOutputHelper:: +pressureUnitConvert_(Scalar& pav) const +{ + pav = eclState_.getUnits() + .from_si(UnitSystem::measure::pressure, pav); +} + template class LogOutputHelper; } // namespace Opm diff --git a/opm/simulators/flow/LogOutputHelper.hpp b/opm/simulators/flow/LogOutputHelper.hpp index afa8f9f20..4cc9f7553 100644 --- a/opm/simulators/flow/LogOutputHelper.hpp +++ b/opm/simulators/flow/LogOutputHelper.hpp @@ -22,13 +22,17 @@ #ifndef LOG_OUTPUT_HELPER_HPP #define LOG_OUTPUT_HELPER_HPP +#include + #include #include #include +#include namespace Opm { class EclipseState; +class Inplace; class Schedule; class SummaryState; @@ -43,6 +47,10 @@ public: void cumulative(const std::size_t reportStepNum, std::function isDefunct) const; + //! \brief Write fluid-in-place reports to output. + void fip(const Inplace& inplace, + const Inplace& initialInplace) const; + //! \brief Write injection report to output. void injection(const std::size_t reportStepNum, std::function isDefunct) const; @@ -55,12 +63,20 @@ private: void outputCumulativeReport_(const std::vector& wellCum, const std::vector& wellCumNames) const; + void outputRegionFluidInPlace_(std::unordered_map oip, + std::unordered_map cip, + const Scalar pav, + const int reg) const; + void outputInjectionReport_(const std::vector& wellInj, const std::vector& wellInjNames) const; void outputProductionReport_(const std::vector& wellProd, const std::vector& wellProdNames) const; + void fipUnitConvert_(std::unordered_map& fip) const; + void pressureUnitConvert_(Scalar& pav) const; + struct WellCumDataType { enum WCId