From 77886b1307c41c22ec7e3cdcc00265696f708d7e Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Mon, 12 Dec 2022 15:47:47 +0100 Subject: [PATCH] BlackOilFluidSystem: put initFromState in separate compile unit thus encapsulating EclipseState and friends --- CMakeLists_files.cmake | 1 + .../fluidsystems/BlackOilFluidSystem.hpp | 122 +-------------- .../fluidsystems/BlackOilFluidSystem.cpp | 147 ++++++++++++++++++ tests/test_fluidsystems.cpp | 1 + 4 files changed, 156 insertions(+), 115 deletions(-) create mode 100644 src/opm/material/fluidsystems/BlackOilFluidSystem.cpp diff --git a/CMakeLists_files.cmake b/CMakeLists_files.cmake index 34446dbd1..50f33df49 100644 --- a/CMakeLists_files.cmake +++ b/CMakeLists_files.cmake @@ -238,6 +238,7 @@ 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 18ceaa38e..7592b7590 100644 --- a/opm/material/fluidsystems/BlackOilFluidSystem.hpp +++ b/opm/material/fluidsystems/BlackOilFluidSystem.hpp @@ -40,18 +40,18 @@ #include #include -#if HAVE_ECL_INPUT -#include -#include -#include -#endif - #include #include #include #include namespace Opm { + +#if HAVE_ECL_INPUT +class EclipseState; +class Schedule; +#endif + namespace BlackOil { OPM_GENERATE_HAS_MEMBER(Rs, ) // Creates 'HasMember_Rs'. OPM_GENERATE_HAS_MEMBER(Rv, ) // Creates 'HasMember_Rv'. @@ -227,115 +227,7 @@ public: /*! * \brief Initialize the fluid system using an ECL deck object */ - static void initFromState(const EclipseState& eclState, const Schedule& schedule) - { - size_t numRegions = eclState.runspec().tabdims().getNumPVTTables(); - initBegin(numRegions); - - numActivePhases_ = 0; - std::fill_n(&phaseIsActive_[0], numPhases, false); - - - if (eclState.runspec().phases().active(Phase::OIL)) { - phaseIsActive_[oilPhaseIdx] = true; - ++ numActivePhases_; - } - - if (eclState.runspec().phases().active(Phase::GAS)) { - phaseIsActive_[gasPhaseIdx] = true; - ++ numActivePhases_; - } - - if (eclState.runspec().phases().active(Phase::WATER)) { - phaseIsActive_[waterPhaseIdx] = true; - ++ numActivePhases_; - } - - // set the surface conditions using the STCOND keyword - surfaceTemperature = eclState.getTableManager().stCond().temperature; - surfacePressure = eclState.getTableManager().stCond().pressure; - - // The reservoir temperature does not really belong into the table manager. TODO: - // change this in opm-parser - setReservoirTemperature(eclState.getTableManager().rtemp()); - - // this fluidsystem only supports two or three phases - assert(numActivePhases_ >= 1 && numActivePhases_ <= 3); - - setEnableDissolvedGas(eclState.getSimulationConfig().hasDISGAS()); - setEnableVaporizedOil(eclState.getSimulationConfig().hasVAPOIL()); - setEnableVaporizedWater(eclState.getSimulationConfig().hasVAPWAT()); - - if(eclState.getSimulationConfig().hasDISGASW()) { - if(eclState.runspec().co2Storage()) - setEnableDissolvedGasInWater(eclState.getSimulationConfig().hasDISGASW()); - else - throw std::runtime_error("DISGASW only supported in combination with CO2STORE"); - } - - if (phaseIsActive(gasPhaseIdx)) { - gasPvt_ = std::make_shared(); - gasPvt_->initFromState(eclState, schedule); - } - - if (phaseIsActive(oilPhaseIdx)) { - oilPvt_ = std::make_shared(); - oilPvt_->initFromState(eclState, schedule); - } - - if (phaseIsActive(waterPhaseIdx)) { - waterPvt_ = std::make_shared(); - waterPvt_->initFromState(eclState, schedule); - } - - // set the reference densities of all PVT regions - for (unsigned regionIdx = 0; regionIdx < numRegions; ++regionIdx) { - setReferenceDensities(phaseIsActive(oilPhaseIdx)? oilPvt_->oilReferenceDensity(regionIdx):700., - phaseIsActive(waterPhaseIdx)? waterPvt_->waterReferenceDensity(regionIdx):1000., - phaseIsActive(gasPhaseIdx)? gasPvt_->gasReferenceDensity(regionIdx):2., - regionIdx); - } - - // set default molarMass and mappings - initEnd(); - - // use molarMass of CO2 and Brine as default - // when we are using the the CO2STORE option - if (eclState.runspec().co2Storage()) { - for (unsigned regionIdx = 0; regionIdx < numRegions; ++regionIdx) { - if(phaseIsActive(oilPhaseIdx)) // The oil component is used for the brine if OIL is active - molarMass_[regionIdx][oilCompIdx] = BrineCo2Pvt::Brine::molarMass(); - if(phaseIsActive(waterPhaseIdx)) - molarMass_[regionIdx][oilCompIdx] = BrineCo2Pvt::Brine::molarMass(); - assert(phaseIsActive(gasPhaseIdx)); - molarMass_[regionIdx][gasCompIdx] = BrineCo2Pvt::CO2::molarMass(); - } - } - - setEnableDiffusion(eclState.getSimulationConfig().isDiffusive()); - if(enableDiffusion()) { - const auto& diffCoeffTables = eclState.getTableManager().getDiffusionCoefficientTable(); - if(!diffCoeffTables.empty()) { - // if diffusion coefficient table is empty we relay on the PVT model to - // to give us the coefficients. - diffusionCoefficients_.resize(numRegions,{0,0,0,0,0,0,0,0,0}); - assert(diffCoeffTables.size() == numRegions); - for (unsigned regionIdx = 0; regionIdx < numRegions; ++regionIdx) { - const auto& diffCoeffTable = diffCoeffTables[regionIdx]; - molarMass_[regionIdx][oilCompIdx] = diffCoeffTable.oil_mw; - molarMass_[regionIdx][gasCompIdx] = diffCoeffTable.gas_mw; - setDiffusionCoefficient(diffCoeffTable.gas_in_gas, gasCompIdx, gasPhaseIdx, regionIdx); - setDiffusionCoefficient(diffCoeffTable.oil_in_gas, oilCompIdx, gasPhaseIdx, regionIdx); - setDiffusionCoefficient(diffCoeffTable.gas_in_oil, gasCompIdx, oilPhaseIdx, regionIdx); - setDiffusionCoefficient(diffCoeffTable.oil_in_oil, oilCompIdx, oilPhaseIdx, regionIdx); - if(diffCoeffTable.gas_in_oil_cross_phase > 0 || diffCoeffTable.oil_in_oil_cross_phase > 0) { - throw std::runtime_error("Cross phase diffusion is set in the deck, but not implemented in Flow. " - "Please default DIFFC item 7 and item 8 or set it to zero."); - } - } - } - } - } + static void initFromState(const EclipseState& eclState, const Schedule& schedule); #endif // HAVE_ECL_INPUT /*! diff --git a/src/opm/material/fluidsystems/BlackOilFluidSystem.cpp b/src/opm/material/fluidsystems/BlackOilFluidSystem.cpp new file mode 100644 index 000000000..a024424ca --- /dev/null +++ b/src/opm/material/fluidsystems/BlackOilFluidSystem.cpp @@ -0,0 +1,147 @@ +// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- +// vi: set et ts=4 sw=4 sts=4: +/* + This file is part of the Open Porous Media project (OPM). + + OPM is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + OPM is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with OPM. If not, see . + + Consult the COPYING file in the top-level source directory of this + module for the precise wording of the license and the list of + copyright holders. +*/ + +#include +#include + +#include +#include +#include + +namespace Opm { + +template +void BlackOilFluidSystem:: +initFromState(const EclipseState& eclState, const Schedule& schedule) +{ + size_t numRegions = eclState.runspec().tabdims().getNumPVTTables(); + initBegin(numRegions); + + numActivePhases_ = 0; + std::fill_n(&phaseIsActive_[0], numPhases, false); + + if (eclState.runspec().phases().active(Phase::OIL)) { + phaseIsActive_[oilPhaseIdx] = true; + ++numActivePhases_; + } + + if (eclState.runspec().phases().active(Phase::GAS)) { + phaseIsActive_[gasPhaseIdx] = true; + ++numActivePhases_; + } + + if (eclState.runspec().phases().active(Phase::WATER)) { + phaseIsActive_[waterPhaseIdx] = true; + ++numActivePhases_; + } + + // set the surface conditions using the STCOND keyword + surfaceTemperature = eclState.getTableManager().stCond().temperature; + surfacePressure = eclState.getTableManager().stCond().pressure; + + // The reservoir temperature does not really belong into the table manager. TODO: + // change this in opm-parser + setReservoirTemperature(eclState.getTableManager().rtemp()); + + // this fluidsystem only supports two or three phases + assert(numActivePhases_ >= 1 && numActivePhases_ <= 3); + + setEnableDissolvedGas(eclState.getSimulationConfig().hasDISGAS()); + setEnableVaporizedOil(eclState.getSimulationConfig().hasVAPOIL()); + setEnableVaporizedWater(eclState.getSimulationConfig().hasVAPWAT()); + + if (eclState.getSimulationConfig().hasDISGASW()) { + if (eclState.runspec().co2Storage()) + setEnableDissolvedGasInWater(eclState.getSimulationConfig().hasDISGASW()); + else + throw std::runtime_error("DISGASW only supported in combination with CO2STORE"); + } + + if (phaseIsActive(gasPhaseIdx)) { + gasPvt_ = std::make_shared(); + gasPvt_->initFromState(eclState, schedule); + } + + if (phaseIsActive(oilPhaseIdx)) { + oilPvt_ = std::make_shared(); + oilPvt_->initFromState(eclState, schedule); + } + + if (phaseIsActive(waterPhaseIdx)) { + waterPvt_ = std::make_shared(); + waterPvt_->initFromState(eclState, schedule); + } + + // set the reference densities of all PVT regions + for (unsigned regionIdx = 0; regionIdx < numRegions; ++regionIdx) { + setReferenceDensities(oilPvt_ ? oilPvt_->oilReferenceDensity(regionIdx) : 700.0, + waterPvt_ ? waterPvt_->waterReferenceDensity(regionIdx) : 1000.0, + gasPvt_ ? gasPvt_->gasReferenceDensity(regionIdx) : 2.0, + regionIdx); + } + + // set default molarMass and mappings + initEnd(); + + // use molarMass of CO2 and Brine as default + // when we are using the the CO2STORE option + if (eclState.runspec().co2Storage()) { + for (unsigned regionIdx = 0; regionIdx < numRegions; ++regionIdx) { + if (phaseIsActive(oilPhaseIdx)) // The oil component is used for the brine if OIL is active + molarMass_[regionIdx][oilCompIdx] = BrineCo2Pvt::Brine::molarMass(); + if (phaseIsActive(waterPhaseIdx)) + molarMass_[regionIdx][oilCompIdx] = BrineCo2Pvt::Brine::molarMass(); + assert(phaseIsActive(gasPhaseIdx)); + molarMass_[regionIdx][gasCompIdx] = BrineCo2Pvt::CO2::molarMass(); + } + } + + setEnableDiffusion(eclState.getSimulationConfig().isDiffusive()); + if (enableDiffusion()) { + const auto& diffCoeffTables = eclState.getTableManager().getDiffusionCoefficientTable(); + if (!diffCoeffTables.empty()) { + // if diffusion coefficient table is empty we relay on the PVT model to + // to give us the coefficients. + diffusionCoefficients_.resize(numRegions,{0,0,0,0,0,0,0,0,0}); + assert(diffCoeffTables.size() == numRegions); + for (unsigned regionIdx = 0; regionIdx < numRegions; ++regionIdx) { + const auto& diffCoeffTable = diffCoeffTables[regionIdx]; + molarMass_[regionIdx][oilCompIdx] = diffCoeffTable.oil_mw; + molarMass_[regionIdx][gasCompIdx] = diffCoeffTable.gas_mw; + setDiffusionCoefficient(diffCoeffTable.gas_in_gas, gasCompIdx, gasPhaseIdx, regionIdx); + setDiffusionCoefficient(diffCoeffTable.oil_in_gas, oilCompIdx, gasPhaseIdx, regionIdx); + setDiffusionCoefficient(diffCoeffTable.gas_in_oil, gasCompIdx, oilPhaseIdx, regionIdx); + setDiffusionCoefficient(diffCoeffTable.oil_in_oil, oilCompIdx, oilPhaseIdx, regionIdx); + if (diffCoeffTable.gas_in_oil_cross_phase > 0 || diffCoeffTable.oil_in_oil_cross_phase > 0) { + throw std::runtime_error("Cross phase diffusion is set in the deck, but not implemented in Flow. " + "Please default DIFFC item 7 and item 8 or set it to zero."); + } + } + } + } +} + +template class BlackOilFluidSystem; +template class BlackOilFluidSystem; + +} // namespace Opm diff --git a/tests/test_fluidsystems.cpp b/tests/test_fluidsystems.cpp index 8789cc19f..032c2f236 100644 --- a/tests/test_fluidsystems.cpp +++ b/tests/test_fluidsystems.cpp @@ -61,6 +61,7 @@ #include #if HAVE_ECL_INPUT #include +#include #include #endif