diff --git a/CMakeLists_files.cmake b/CMakeLists_files.cmake index a7c2ca0d..c53f1d52 100644 --- a/CMakeLists_files.cmake +++ b/CMakeLists_files.cmake @@ -339,7 +339,6 @@ list (APPEND PUBLIC_HEADER_FILES opm/core/props/BlackoilPhases.hpp opm/core/props/BlackoilPropertiesBasic.hpp opm/core/props/BlackoilPropertiesFromDeck.hpp - opm/core/props/BlackoilPropertiesFromDeck_impl.hpp opm/core/props/BlackoilPropertiesInterface.hpp opm/core/props/IncompPropertiesBasic.hpp opm/core/props/IncompPropertiesFromDeck.hpp diff --git a/opm/core/props/BlackoilPropertiesFromDeck.cpp b/opm/core/props/BlackoilPropertiesFromDeck.cpp index 87bfbad9..8173a0e6 100644 --- a/opm/core/props/BlackoilPropertiesFromDeck.cpp +++ b/opm/core/props/BlackoilPropertiesFromDeck.cpp @@ -19,30 +19,46 @@ #include "config.h" #include +#include #include +#include +#include namespace Opm { + + namespace + { + // Construct explicit mapping from active/compressed to logical cartesian + // indices, either as given in global_cell or as { 0, 1, 2, ....} if null. + std::vector compressedToCartesian(const int num_cells, + const int* global_cell) + { + std::vector retval; + if (global_cell) { + retval.assign(global_cell, global_cell + num_cells); + } else { + retval.resize(num_cells); + std::iota(retval.begin(), retval.end(), 0); + } + return retval; + } + } // anonymous namespace + + BlackoilPropertiesFromDeck::BlackoilPropertiesFromDeck(Opm::DeckConstPtr deck, Opm::EclipseStateConstPtr eclState, const UnstructuredGrid& grid, bool init_rock) { - std::vector compressedToCartesianIdx(grid.number_of_cells); - for (int cellIdx = 0; cellIdx < grid.number_of_cells; ++cellIdx) { - if (grid.global_cell) { - compressedToCartesianIdx[cellIdx] = grid.global_cell[cellIdx]; - } - else { - compressedToCartesianIdx[cellIdx] = cellIdx; - } - } + std::vector compressedToCartesianIdx + = compressedToCartesian(grid.number_of_cells, grid.global_cell); auto materialLawManager = std::make_shared(); materialLawManager->initFromDeck(deck, eclState, compressedToCartesianIdx); init(deck, eclState, materialLawManager, grid.number_of_cells, grid.global_cell, grid.cartdims, - grid.cell_centroids, grid.dimensions, init_rock); + init_rock); } BlackoilPropertiesFromDeck::BlackoilPropertiesFromDeck(Opm::DeckConstPtr deck, @@ -51,21 +67,137 @@ namespace Opm const parameter::ParameterGroup& param, bool init_rock) { - std::vector compressedToCartesianIdx(grid.number_of_cells); - for (int cellIdx = 0; cellIdx < grid.number_of_cells; ++cellIdx) { - if (grid.global_cell) { - compressedToCartesianIdx[cellIdx] = grid.global_cell[cellIdx]; - } - else { - compressedToCartesianIdx[cellIdx] = cellIdx; - } - } + std::vector compressedToCartesianIdx + = compressedToCartesian(grid.number_of_cells, grid.global_cell); auto materialLawManager = std::make_shared(); materialLawManager->initFromDeck(deck, eclState, compressedToCartesianIdx); - init(deck, eclState, materialLawManager, grid.number_of_cells, grid.global_cell, grid.cartdims, grid.cell_centroids, - grid.dimensions, param, init_rock); + init(deck, eclState, materialLawManager, grid.number_of_cells, grid.global_cell, grid.cartdims, param, init_rock); + } + + BlackoilPropertiesFromDeck::BlackoilPropertiesFromDeck(Opm::DeckConstPtr deck, + Opm::EclipseStateConstPtr eclState, + int number_of_cells, + const int* global_cell, + const int* cart_dims, + bool init_rock) + { + std::vector compressedToCartesianIdx + = compressedToCartesian(number_of_cells, global_cell); + + auto materialLawManager = std::make_shared(); + materialLawManager->initFromDeck(deck, eclState, compressedToCartesianIdx); + + init(deck, eclState, materialLawManager, number_of_cells, global_cell, cart_dims, + init_rock); + } + + BlackoilPropertiesFromDeck::BlackoilPropertiesFromDeck(Opm::DeckConstPtr deck, + Opm::EclipseStateConstPtr eclState, + int number_of_cells, + const int* global_cell, + const int* cart_dims, + const parameter::ParameterGroup& param, + bool init_rock) + { + std::vector compressedToCartesianIdx + = compressedToCartesian(number_of_cells, global_cell); + + auto materialLawManager = std::make_shared(); + materialLawManager->initFromDeck(deck, eclState, compressedToCartesianIdx); + + init(deck, + eclState, + materialLawManager, + number_of_cells, + global_cell, + cart_dims, + param, + init_rock); + } + + BlackoilPropertiesFromDeck::BlackoilPropertiesFromDeck(Opm::DeckConstPtr deck, + Opm::EclipseStateConstPtr eclState, + std::shared_ptr materialLawManager, + int number_of_cells, + const int* global_cell, + const int* cart_dims, + const parameter::ParameterGroup& param, + bool init_rock) + { + init(deck, + eclState, + materialLawManager, + number_of_cells, + global_cell, + cart_dims, + param, + init_rock); + } + + inline void BlackoilPropertiesFromDeck::init(Opm::DeckConstPtr deck, + Opm::EclipseStateConstPtr eclState, + std::shared_ptr materialLawManager, + int number_of_cells, + const int* global_cell, + const int* cart_dims, + bool init_rock) + { + // retrieve the cell specific PVT table index from the deck + // and using the grid... + extractPvtTableIndex(cellPvtRegionIdx_, deck, number_of_cells, global_cell); + + if (init_rock){ + rock_.init(eclState, number_of_cells, global_cell, cart_dims); + } + pvt_.init(deck, eclState, /*numSamples=*/0); + SaturationPropsFromDeck* ptr + = new SaturationPropsFromDeck(); + ptr->init(phaseUsageFromDeck(deck), materialLawManager); + satprops_.reset(ptr); + + if (pvt_.numPhases() != satprops_->numPhases()) { + OPM_THROW(std::runtime_error, "BlackoilPropertiesFromDeck::BlackoilPropertiesFromDeck() - Inconsistent number of phases in pvt data (" + << pvt_.numPhases() << ") and saturation-dependent function data (" << satprops_->numPhases() << ")."); + } + } + + inline void BlackoilPropertiesFromDeck::init(Opm::DeckConstPtr deck, + Opm::EclipseStateConstPtr eclState, + std::shared_ptr materialLawManager, + int number_of_cells, + const int* global_cell, + const int* cart_dims, + const parameter::ParameterGroup& param, + bool init_rock) + { + // retrieve the cell specific PVT table index from the deck + // and using the grid... + extractPvtTableIndex(cellPvtRegionIdx_, deck, number_of_cells, global_cell); + + if(init_rock){ + rock_.init(eclState, number_of_cells, global_cell, cart_dims); + } + + const int pvt_samples = param.getDefault("pvt_tab_size", -1); + pvt_.init(deck, eclState, pvt_samples); + + // Unfortunate lack of pointer smartness here... + std::string threephase_model = param.getDefault("threephase_model", "gwseg"); + if (deck->hasKeyword("ENDSCALE") && threephase_model != "gwseg") { + OPM_THROW(std::runtime_error, "Sorry, end point scaling currently available for the 'gwseg' model only."); + } + + SaturationPropsFromDeck* ptr + = new SaturationPropsFromDeck(); + ptr->init(phaseUsageFromDeck(deck), materialLawManager); + satprops_.reset(ptr); + + if (pvt_.numPhases() != satprops_->numPhases()) { + OPM_THROW(std::runtime_error, "BlackoilPropertiesFromDeck::BlackoilPropertiesFromDeck() - Inconsistent number of phases in pvt data (" + << pvt_.numPhases() << ") and saturation-dependent function data (" << satprops_->numPhases() << ")."); + } } BlackoilPropertiesFromDeck::~BlackoilPropertiesFromDeck() diff --git a/opm/core/props/BlackoilPropertiesFromDeck.hpp b/opm/core/props/BlackoilPropertiesFromDeck.hpp index 487b01a4..3aaa601c 100644 --- a/opm/core/props/BlackoilPropertiesFromDeck.hpp +++ b/opm/core/props/BlackoilPropertiesFromDeck.hpp @@ -27,8 +27,6 @@ #include #include -#include - #include #include @@ -71,36 +69,27 @@ namespace Opm const parameter::ParameterGroup& param, bool init_rock=true); - template BlackoilPropertiesFromDeck(Opm::DeckConstPtr deck, Opm::EclipseStateConstPtr eclState, int number_of_cells, const int* global_cell, const int* cart_dims, - const CentroidIterator& begin_cell_centroids, - int dimension, bool init_rock=true); - template BlackoilPropertiesFromDeck(Opm::DeckConstPtr deck, Opm::EclipseStateConstPtr eclState, int number_of_cells, const int* global_cell, const int* cart_dims, - const CentroidIterator& begin_cell_centroids, - int dimension, const parameter::ParameterGroup& param, bool init_rock=true); - template BlackoilPropertiesFromDeck(Opm::DeckConstPtr deck, Opm::EclipseStateConstPtr eclState, std::shared_ptr materialLawManager, int number_of_cells, const int* global_cell, const int* cart_dims, - const CentroidIterator& begin_cell_centroids, - int dimension, const parameter::ParameterGroup& param, bool init_rock=true); @@ -252,25 +241,20 @@ namespace Opm return pvtTableIdx[cellIdx]; } - template void init(Opm::DeckConstPtr deck, Opm::EclipseStateConstPtr eclState, std::shared_ptr materialLawManager, int number_of_cells, const int* global_cell, const int* cart_dims, - const CentroidIterator& begin_cell_centroids, - int dimension, bool init_rock); - template + void init(Opm::DeckConstPtr deck, Opm::EclipseStateConstPtr eclState, std::shared_ptr materialLawManager, int number_of_cells, const int* global_cell, const int* cart_dims, - const CentroidIterator& begin_cell_centroids, - int dimension, const parameter::ParameterGroup& param, bool init_rock); @@ -289,6 +273,4 @@ namespace Opm } // namespace Opm -#include "BlackoilPropertiesFromDeck_impl.hpp" - #endif // OPM_BLACKOILPROPERTIESFROMDECK_HEADER_INCLUDED diff --git a/opm/core/props/BlackoilPropertiesFromDeck_impl.hpp b/opm/core/props/BlackoilPropertiesFromDeck_impl.hpp deleted file mode 100644 index bbdccaaf..00000000 --- a/opm/core/props/BlackoilPropertiesFromDeck_impl.hpp +++ /dev/null @@ -1,160 +0,0 @@ -#include - -namespace Opm -{ - template - BlackoilPropertiesFromDeck::BlackoilPropertiesFromDeck(Opm::DeckConstPtr deck, - Opm::EclipseStateConstPtr eclState, - int number_of_cells, - const int* global_cell, - const int* cart_dims, - const CentroidIterator& begin_cell_centroids, - int dimension, - bool init_rock) - { - std::vector compressedToCartesianIdx(number_of_cells); - for (int cellIdx = 0; cellIdx < number_of_cells; ++cellIdx) { - if (global_cell) { - compressedToCartesianIdx[cellIdx] = global_cell[cellIdx]; - } - else { - compressedToCartesianIdx[cellIdx] = cellIdx; - } - } - auto materialLawManager = std::make_shared(); - materialLawManager->initFromDeck(deck, eclState, compressedToCartesianIdx); - - init(deck, eclState, materialLawManager, number_of_cells, global_cell, cart_dims, begin_cell_centroids, dimension, - init_rock); - } - - template - BlackoilPropertiesFromDeck::BlackoilPropertiesFromDeck(Opm::DeckConstPtr deck, - Opm::EclipseStateConstPtr eclState, - int number_of_cells, - const int* global_cell, - const int* cart_dims, - const CentroidIterator& begin_cell_centroids, - int dimension, - const parameter::ParameterGroup& param, - bool init_rock) - { - std::vector compressedToCartesianIdx(number_of_cells); - for (int cellIdx = 0; cellIdx < number_of_cells; ++cellIdx) { - if (global_cell) { - compressedToCartesianIdx[cellIdx] = global_cell[cellIdx]; - } - else { - compressedToCartesianIdx[cellIdx] = cellIdx; - } - } - auto materialLawManager = std::make_shared(); - materialLawManager->initFromDeck(deck, eclState, compressedToCartesianIdx); - - init(deck, - eclState, - materialLawManager, - number_of_cells, - global_cell, - cart_dims, - begin_cell_centroids, - dimension, - param, - init_rock); - } - - template - BlackoilPropertiesFromDeck::BlackoilPropertiesFromDeck(Opm::DeckConstPtr deck, - Opm::EclipseStateConstPtr eclState, - std::shared_ptr materialLawManager, - int number_of_cells, - const int* global_cell, - const int* cart_dims, - const CentroidIterator& begin_cell_centroids, - int dimension, - const parameter::ParameterGroup& param, - bool init_rock) - { - init(deck, - eclState, - materialLawManager, - number_of_cells, - global_cell, - cart_dims, - begin_cell_centroids, - dimension, - param, - init_rock); - } - - template - inline void BlackoilPropertiesFromDeck::init(Opm::DeckConstPtr deck, - Opm::EclipseStateConstPtr eclState, - std::shared_ptr materialLawManager, - int number_of_cells, - const int* global_cell, - const int* cart_dims, - const CentroidIterator& begin_cell_centroids, - int dimension, - bool init_rock) - { - // retrieve the cell specific PVT table index from the deck - // and using the grid... - extractPvtTableIndex(cellPvtRegionIdx_, deck, number_of_cells, global_cell); - - if (init_rock){ - rock_.init(eclState, number_of_cells, global_cell, cart_dims); - } - pvt_.init(deck, eclState, /*numSamples=*/0); - SaturationPropsFromDeck* ptr - = new SaturationPropsFromDeck(); - ptr->init(phaseUsageFromDeck(deck), materialLawManager); - satprops_.reset(ptr); - - if (pvt_.numPhases() != satprops_->numPhases()) { - OPM_THROW(std::runtime_error, "BlackoilPropertiesFromDeck::BlackoilPropertiesFromDeck() - Inconsistent number of phases in pvt data (" - << pvt_.numPhases() << ") and saturation-dependent function data (" << satprops_->numPhases() << ")."); - } - } - - template - inline void BlackoilPropertiesFromDeck::init(Opm::DeckConstPtr deck, - Opm::EclipseStateConstPtr eclState, - std::shared_ptr materialLawManager, - int number_of_cells, - const int* global_cell, - const int* cart_dims, - const CentroidIterator& begin_cell_centroids, - int dimension, - const parameter::ParameterGroup& param, - bool init_rock) - { - // retrieve the cell specific PVT table index from the deck - // and using the grid... - extractPvtTableIndex(cellPvtRegionIdx_, deck, number_of_cells, global_cell); - - if(init_rock){ - rock_.init(eclState, number_of_cells, global_cell, cart_dims); - } - - const int pvt_samples = param.getDefault("pvt_tab_size", -1); - pvt_.init(deck, eclState, pvt_samples); - - // Unfortunate lack of pointer smartness here... - std::string threephase_model = param.getDefault("threephase_model", "gwseg"); - if (deck->hasKeyword("ENDSCALE") && threephase_model != "gwseg") { - OPM_THROW(std::runtime_error, "Sorry, end point scaling currently available for the 'gwseg' model only."); - } - - SaturationPropsFromDeck* ptr - = new SaturationPropsFromDeck(); - ptr->init(phaseUsageFromDeck(deck), materialLawManager); - satprops_.reset(ptr); - - if (pvt_.numPhases() != satprops_->numPhases()) { - OPM_THROW(std::runtime_error, "BlackoilPropertiesFromDeck::BlackoilPropertiesFromDeck() - Inconsistent number of phases in pvt data (" - << pvt_.numPhases() << ") and saturation-dependent function data (" << satprops_->numPhases() << ")."); - } - } -} - diff --git a/opm/core/props/IncompPropertiesFromDeck.cpp b/opm/core/props/IncompPropertiesFromDeck.cpp index c7d8593b..5a29fbd2 100644 --- a/opm/core/props/IncompPropertiesFromDeck.cpp +++ b/opm/core/props/IncompPropertiesFromDeck.cpp @@ -20,6 +20,7 @@ #include "config.h" #include +#include #include #include #include @@ -45,7 +46,7 @@ namespace Opm } materialLawManager->initFromDeck(deck, eclState, compressedToCartesianIdx); - satprops_.init(deck, eclState, materialLawManager, grid); + satprops_.init(deck, materialLawManager); if (pvt_.numPhases() != satprops_.numPhases()) { OPM_THROW(std::runtime_error, "IncompPropertiesFromDeck::IncompPropertiesFromDeck() - Inconsistent number of phases in pvt data (" << pvt_.numPhases() << ") and saturation-dependent function data (" << satprops_.numPhases() << ")."); diff --git a/opm/core/props/satfunc/SaturationPropsFromDeck.cpp b/opm/core/props/satfunc/SaturationPropsFromDeck.cpp index 8bc8bf64..769ad032 100644 --- a/opm/core/props/satfunc/SaturationPropsFromDeck.cpp +++ b/opm/core/props/satfunc/SaturationPropsFromDeck.cpp @@ -18,6 +18,10 @@ */ #include "config.h" +#include + +#include + #include #include #include @@ -30,11 +34,10 @@ #include #include -#include "SaturationPropsFromDeck.hpp" - namespace Opm { + typedef SaturationPropsFromDeck::MaterialLawManager::MaterialLaw MaterialLaw; // ----------- Methods of SaturationPropsFromDeck --------- @@ -44,17 +47,6 @@ namespace Opm { } - /// Initialize from deck. - void SaturationPropsFromDeck::init(Opm::DeckConstPtr deck, - Opm::EclipseStateConstPtr eclipseState, - std::shared_ptr materialLawManager, - const UnstructuredGrid& grid) - { - this->init(deck, eclipseState, materialLawManager, grid.number_of_cells, - grid.global_cell, grid.cell_centroids, - grid.dimensions); - } - /// Initialize from deck. void SaturationPropsFromDeck::init(const PhaseUsage &phaseUsage, std::shared_ptr materialLawManager) diff --git a/opm/core/props/satfunc/SaturationPropsFromDeck.hpp b/opm/core/props/satfunc/SaturationPropsFromDeck.hpp index 756f6d69..127700fd 100644 --- a/opm/core/props/satfunc/SaturationPropsFromDeck.hpp +++ b/opm/core/props/satfunc/SaturationPropsFromDeck.hpp @@ -29,14 +29,20 @@ #include #include -#include - #include struct UnstructuredGrid; namespace Opm { + + // Forward declaring the EclMaterialLawManager template. + template + class ThreePhaseMaterialTraits; + template + class EclMaterialLawManager; + + /// Interface to saturation functions from deck. class SaturationPropsFromDeck : public SaturationPropsInterface { @@ -46,47 +52,22 @@ namespace Opm /*nonWettingPhaseIdx=*/BlackoilPhases::Liquid, /*gasPhaseIdx=*/BlackoilPhases::Vapour> MaterialTraits; typedef Opm::EclMaterialLawManager MaterialLawManager; - typedef MaterialLawManager::MaterialLaw MaterialLaw; - typedef MaterialLawManager::MaterialLawParams MaterialLawParams; /// Default constructor. SaturationPropsFromDeck(); - /// Initialize from a MaterialLawManager object and a compressed to cartesian cell index map. + /// Initialize from a MaterialLawManager object. + /// \param[in] phaseUsage Phase configuration /// \param[in] materialLawManager An initialized MaterialLawManager object - void init(const PhaseUsage &phaseUsage, + void init(const PhaseUsage& phaseUsage, std::shared_ptr materialLawManager); - /// Initialize from deck and grid. - /// \param[in] deck Deck input parser - /// \param[in] grid Grid to which property object applies, needed for the - /// mapping from cell indices (typically from a processed grid) - /// to logical cartesian indices consistent with the deck. + /// Initialize from deck and MaterialLawManager. + /// \param[in] deck Input deck + /// \param[in] materialLawManager An initialized MaterialLawManager object void init(Opm::DeckConstPtr deck, - Opm::EclipseStateConstPtr eclipseState, - std::shared_ptr materialLawManager, - const UnstructuredGrid& grid); - - /// Initialize from deck and grid. - /// \param[in] deck Deck input parser - /// \param[in] number_of_cells The number of cells of the grid to which property - /// object applies, needed for the - /// mapping from cell indices (typically from a processed - /// grid) to logical cartesian indices consistent with the - /// deck. - /// \param[in] global_cell The mapping from local cell indices of the grid to - /// global cell indices used in the deck. - /// \param[in] begin_cell_centroids Pointer to the first cell_centroid of the grid. - /// \param[in] dimensions The dimensions of the grid. - template - void init(Opm::DeckConstPtr deck, - Opm::EclipseStateConstPtr eclipseState, - std::shared_ptr materialLawManager, - int number_of_cells, - const int* global_cell, - const T& begin_cell_centroids, - int dimensions) + std::shared_ptr materialLawManager) { init(Opm::phaseUsageFromDeck(deck), materialLawManager); }