diff --git a/CMakeLists_files.cmake b/CMakeLists_files.cmake index 5e3462c2d..df4f2c755 100644 --- a/CMakeLists_files.cmake +++ b/CMakeLists_files.cmake @@ -52,6 +52,7 @@ list (APPEND MAIN_SOURCE_FILES src/opm/material/components/CO2.cpp src/opm/material/densead/Evaluation.cpp src/opm/material/fluidmatrixinteractions/EclEpsScalingPoints.cpp + src/opm/material/fluidsystems/BlackOilFluidSystem.cpp src/opm/material/fluidsystems/blackoilpvt/DeadOilPvt.cpp src/opm/material/fluidsystems/blackoilpvt/DryGasPvt.cpp src/opm/material/fluidsystems/blackoilpvt/DryHumidGasPvt.cpp @@ -255,7 +256,6 @@ if(ENABLE_ECL_INPUT) src/opm/material/fluidmatrixinteractions/EclEpsGridProperties.cpp src/opm/material/fluidmatrixinteractions/EclHysteresisConfig.cpp src/opm/material/fluidmatrixinteractions/EclMaterialLawManager.cpp - src/opm/material/fluidsystems/BlackOilFluidSystem.cpp src/opm/material/fluidsystems/blackoilpvt/BrineCo2Pvt.cpp src/opm/material/fluidsystems/blackoilpvt/Co2GasPvt.cpp src/opm/material/fluidsystems/blackoilpvt/ConstantCompressibilityBrinePvt.cpp diff --git a/opm/material/fluidsystems/BlackOilFluidSystem.hpp b/opm/material/fluidsystems/BlackOilFluidSystem.hpp index 7592b7590..424602d5c 100644 --- a/opm/material/fluidsystems/BlackOilFluidSystem.hpp +++ b/opm/material/fluidsystems/BlackOilFluidSystem.hpp @@ -41,6 +41,7 @@ #include #include +#include #include #include #include @@ -238,29 +239,7 @@ public: * compressibility must be set. Before the fluid system can be used, initEnd() must * be called to finalize the initialization. */ - static void initBegin(size_t numPvtRegions) - { - isInitialized_ = false; - - enableDissolvedGas_ = true; - enableDissolvedGasInWater_ = false; - enableVaporizedOil_ = false; - enableVaporizedWater_ = false; - enableDiffusion_ = false; - - oilPvt_ = nullptr; - gasPvt_ = nullptr; - waterPvt_ = nullptr; - - surfaceTemperature = 273.15 + 15.56; // [K] - surfacePressure = 1.01325e5; // [Pa] - setReservoirTemperature(surfaceTemperature); - - numActivePhases_ = numPhases; - std::fill_n(&phaseIsActive_[0], numPhases, true); - - resizeArrays_(numPvtRegions); - } + static void initBegin(std::size_t numPvtRegions); /*! * \brief Specify whether the fluid system should consider that the gas component can @@ -334,53 +313,12 @@ public: static void setReferenceDensities(Scalar rhoOil, Scalar rhoWater, Scalar rhoGas, - unsigned regionIdx) - { - referenceDensity_[regionIdx][oilPhaseIdx] = rhoOil; - referenceDensity_[regionIdx][waterPhaseIdx] = rhoWater; - referenceDensity_[regionIdx][gasPhaseIdx] = rhoGas; - } - + unsigned regionIdx); /*! * \brief Finish initializing the black oil fluid system. */ - static void initEnd() - { - // calculate the final 2D functions which are used for interpolation. - size_t numRegions = molarMass_.size(); - for (unsigned regionIdx = 0; regionIdx < numRegions; ++ regionIdx) { - // calculate molar masses - - // water is simple: 18 g/mol - molarMass_[regionIdx][waterCompIdx] = 18e-3; - - if (phaseIsActive(gasPhaseIdx)) { - // for gas, we take the density at standard conditions and assume it to be ideal - Scalar p = surfacePressure; - Scalar T = surfaceTemperature; - Scalar rho_g = referenceDensity_[/*regionIdx=*/0][gasPhaseIdx]; - molarMass_[regionIdx][gasCompIdx] = Constants::R*T*rho_g / p; - } - else - // hydrogen gas. we just set this do avoid NaNs later - molarMass_[regionIdx][gasCompIdx] = 2e-3; - - // finally, for oil phase, we take the molar mass from the spe9 paper - molarMass_[regionIdx][oilCompIdx] = 175e-3; // kg/mol - } - - - int activePhaseIdx = 0; - for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) { - if(phaseIsActive(phaseIdx)){ - canonicalToActivePhaseIdx_[phaseIdx] = activePhaseIdx; - activeToCanonicalPhaseIdx_[activePhaseIdx] = phaseIdx; - activePhaseIdx++; - } - } - isInitialized_ = true; - } + static void initEnd(); static bool isInitialized() { return isInitialized_; } @@ -406,20 +344,7 @@ public: static Scalar surfaceTemperature; //! \copydoc BaseFluidSystem::phaseName - static const char* phaseName(unsigned phaseIdx) - { - switch (phaseIdx) { - case waterPhaseIdx: - return "water"; - case oilPhaseIdx: - return "oil"; - case gasPhaseIdx: - return "gas"; - - default: - throw std::logic_error("Phase index " + std::to_string(phaseIdx) + " is unknown"); - } - } + static const char* phaseName(unsigned phaseIdx); //! \copydoc BaseFluidSystem::isLiquid static bool isLiquid(unsigned phaseIdx) @@ -459,54 +384,13 @@ public: } //! \brief returns the index of "primary" component of a phase (solvent) - static constexpr unsigned solventComponentIndex(unsigned phaseIdx) - { - switch (phaseIdx) { - case waterPhaseIdx: - return waterCompIdx; - case oilPhaseIdx: - return oilCompIdx; - case gasPhaseIdx: - return gasCompIdx; - - default: - throw std::logic_error("Phase index " + std::to_string(phaseIdx) + " is unknown"); - } - } + static unsigned solventComponentIndex(unsigned phaseIdx); //! \brief returns the index of "secondary" component of a phase (solute) - static constexpr unsigned soluteComponentIndex(unsigned phaseIdx) - { - switch (phaseIdx) { - case waterPhaseIdx: - if (enableDissolvedGasInWater()) - return gasCompIdx; - throw std::logic_error("The water phase does not have any solutes in the black oil model!"); - case oilPhaseIdx: - return gasCompIdx; - case gasPhaseIdx: - return oilCompIdx; - - default: - throw std::logic_error("Phase index " + std::to_string(phaseIdx) + " is unknown"); - } - } + static unsigned soluteComponentIndex(unsigned phaseIdx); //! \copydoc BaseFluidSystem::componentName - static const char* componentName(unsigned compIdx) - { - switch (compIdx) { - case waterCompIdx: - return "Water"; - case oilCompIdx: - return "Oil"; - case gasCompIdx: - return "Gas"; - - default: - throw std::logic_error("Component index " + std::to_string(compIdx) + " is unknown"); - } - } + static const char* componentName(unsigned compIdx); //! \copydoc BaseFluidSystem::molarMass static Scalar molarMass(unsigned compIdx, unsigned regionIdx = 0) @@ -537,7 +421,7 @@ public: * * By default, this is 1. */ - static size_t numRegions() + static std::size_t numRegions() { return molarMass_.size(); } /*! @@ -1528,16 +1412,9 @@ public: static void setReservoirTemperature(Scalar value) { reservoirTemperature_ = value; } - static short activeToCanonicalPhaseIdx(unsigned activePhaseIdx) { - assert(activePhaseIdx +#if HAVE_ECL_INPUT #include #include #include +#endif #include namespace Opm { +#if HAVE_ECL_INPUT template void BlackOilFluidSystem:: initFromState(const EclipseState& eclState, const Schedule& schedule) { - size_t numRegions = eclState.runspec().tabdims().getNumPVTTables(); + std::size_t numRegions = eclState.runspec().tabdims().getNumPVTTables(); initBegin(numRegions); numActivePhases_ = 0; @@ -159,6 +162,178 @@ initFromState(const EclipseState& eclState, const Schedule& schedule) } } } +#endif + +template +void BlackOilFluidSystem:: +initBegin(std::size_t numPvtRegions) +{ + isInitialized_ = false; + + enableDissolvedGas_ = true; + enableDissolvedGasInWater_ = false; + enableVaporizedOil_ = false; + enableVaporizedWater_ = false; + enableDiffusion_ = false; + + oilPvt_ = nullptr; + gasPvt_ = nullptr; + waterPvt_ = nullptr; + + surfaceTemperature = 273.15 + 15.56; // [K] + surfacePressure = 1.01325e5; // [Pa] + setReservoirTemperature(surfaceTemperature); + + numActivePhases_ = numPhases; + std::fill_n(&phaseIsActive_[0], numPhases, true); + + resizeArrays_(numPvtRegions); +} + +template +void BlackOilFluidSystem:: +setReferenceDensities(Scalar rhoOil, + Scalar rhoWater, + Scalar rhoGas, + unsigned regionIdx) +{ + referenceDensity_[regionIdx][oilPhaseIdx] = rhoOil; + referenceDensity_[regionIdx][waterPhaseIdx] = rhoWater; + referenceDensity_[regionIdx][gasPhaseIdx] = rhoGas; +} + +template +void BlackOilFluidSystem::initEnd() +{ + // calculate the final 2D functions which are used for interpolation. + std::size_t numRegions = molarMass_.size(); + for (unsigned regionIdx = 0; regionIdx < numRegions; ++ regionIdx) { + // calculate molar masses + + // water is simple: 18 g/mol + molarMass_[regionIdx][waterCompIdx] = 18e-3; + + if (phaseIsActive(gasPhaseIdx)) { + // for gas, we take the density at standard conditions and assume it to be ideal + Scalar p = surfacePressure; + Scalar T = surfaceTemperature; + Scalar rho_g = referenceDensity_[/*regionIdx=*/0][gasPhaseIdx]; + molarMass_[regionIdx][gasCompIdx] = Constants::R*T*rho_g / p; + } + else + // hydrogen gas. we just set this do avoid NaNs later + molarMass_[regionIdx][gasCompIdx] = 2e-3; + + // finally, for oil phase, we take the molar mass from the spe9 paper + molarMass_[regionIdx][oilCompIdx] = 175e-3; // kg/mol + } + + + int activePhaseIdx = 0; + for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) { + if(phaseIsActive(phaseIdx)){ + canonicalToActivePhaseIdx_[phaseIdx] = activePhaseIdx; + activeToCanonicalPhaseIdx_[activePhaseIdx] = phaseIdx; + activePhaseIdx++; + } + } + isInitialized_ = true; +} + +template +const char* BlackOilFluidSystem:: +phaseName(unsigned phaseIdx) +{ + switch (phaseIdx) { + case waterPhaseIdx: + return "water"; + case oilPhaseIdx: + return "oil"; + case gasPhaseIdx: + return "gas"; + + default: + throw std::logic_error(fmt::format("Phase index {} is unknown", phaseIdx)); + } +} + +template +unsigned BlackOilFluidSystem:: +solventComponentIndex(unsigned phaseIdx) +{ + switch (phaseIdx) { + case waterPhaseIdx: + return waterCompIdx; + case oilPhaseIdx: + return oilCompIdx; + case gasPhaseIdx: + return gasCompIdx; + + default: + throw std::logic_error(fmt::format("Phase index {} is unknown", phaseIdx)); + } +} + +template +unsigned BlackOilFluidSystem:: +soluteComponentIndex(unsigned phaseIdx) +{ + switch (phaseIdx) { + case waterPhaseIdx: + if (enableDissolvedGasInWater()) + return gasCompIdx; + throw std::logic_error("The water phase does not have any solutes in the black oil model!"); + case oilPhaseIdx: + return gasCompIdx; + case gasPhaseIdx: + return oilCompIdx; + + default: + throw std::logic_error(fmt::format("Phase index {} is unknown", phaseIdx)); + } +} + +template +const char* BlackOilFluidSystem:: +componentName(unsigned compIdx) +{ + switch (compIdx) { + case waterCompIdx: + return "Water"; + case oilCompIdx: + return "Oil"; + case gasCompIdx: + return "Gas"; + + default: + throw std::logic_error(fmt::format("Component index {} is unknown", compIdx)); + } +} + +template +short BlackOilFluidSystem:: +activeToCanonicalPhaseIdx(unsigned activePhaseIdx) +{ + assert(activePhaseIdx +short BlackOilFluidSystem:: +canonicalToActivePhaseIdx(unsigned phaseIdx) +{ + assert(phaseIdx +void BlackOilFluidSystem:: +resizeArrays_(std::size_t numRegions) +{ + molarMass_.resize(numRegions); + referenceDensity_.resize(numRegions); +} template class BlackOilFluidSystem; template class BlackOilFluidSystem;