From e48b64c41d33de1f2d13c124ce67953a0fc655b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A5l=20Gr=C3=B8n=C3=A5s=20Drange?= Date: Tue, 8 Mar 2016 17:07:42 +0100 Subject: [PATCH] Substantial edits to Eclipse3DProperties * Removed all references to state, need to fix initPORV * Made TransMult return raw pointer const GridProperty over shared pointer. * Moved getDirectionProperty and hasDirectionProperty out of API ** Removed tests as these methods are no longer public * Moved grid properties stuff to new class * Removed use of deck in SatfuncInitializers, moved to TableManager * Removed shared_ptr for several members of EclipseState and 3DProperties * Moved region-property from EclipseState to Eclipse3DProperties * Moved initGridopts from EclipseState to Eclipse3DProperties * Made several Eclipse3DProperties methods private * Postprocessors take raw pointers, not shared_ptr---these will be phased out * Fixed return reference instead of copy several places ** GridProperties in Eclipse3DProperties are now references, not shared_ptr ** Eclipse3DProperties takes const Deck&, not shared_ptr * Removed obsolete tests --- .gitignore | 3 +- opm/parser/eclipse/CMakeLists.txt | 2 + .../EclipseState/Eclipse3DProperties.cpp | 914 +++++++++++++++ .../EclipseState/Eclipse3DProperties.hpp | 114 ++ .../EclipseState/EclipseProperties.cpp | 894 ++++++++++++++ .../EclipseState/EclipseProperties.hpp | 118 ++ .../eclipse/EclipseState/EclipseState.cpp | 1022 +---------------- .../eclipse/EclipseState/EclipseState.hpp | 87 +- .../EclipseState/Grid/GridProperties.hpp | 310 ++--- .../EclipseState/Grid/GridProperty.cpp | 39 +- .../EclipseState/Grid/GridProperty.hpp | 18 +- .../Grid/GridPropertyInitializers.cpp | 67 +- .../Grid/GridPropertyInitializers.hpp | 57 +- .../EclipseState/Grid/MULTREGTScanner.cpp | 20 +- .../EclipseState/Grid/MULTREGTScanner.hpp | 6 +- .../Grid/SatfuncPropertyInitializers.cpp | 652 +++++++---- .../Grid/SatfuncPropertyInitializers.hpp | 243 +++- .../eclipse/EclipseState/Grid/TransMult.cpp | 29 +- .../eclipse/EclipseState/Grid/TransMult.hpp | 8 +- .../EclipseState/Grid/tests/ADDREGTests.cpp | 18 +- .../EclipseState/Grid/tests/CopyRegTests.cpp | 18 +- .../EclipseState/Grid/tests/EqualRegTests.cpp | 31 +- .../Grid/tests/GridPropertiesTests.cpp | 36 +- .../Grid/tests/GridPropertyTests.cpp | 175 +-- .../Grid/tests/MULTREGTScannerTests.cpp | 56 +- .../EclipseState/Grid/tests/MultiRegTests.cpp | 19 +- .../EclipseState/Grid/tests/PORVTests.cpp | 98 +- .../SatfuncPropertyInitializersTests.cpp | 14 +- .../Grid/tests/TransMultTests.cpp | 9 +- .../EclipseState/IOConfig/IOConfig.hpp | 4 +- .../SimulationConfig/SimulationConfig.cpp | 8 +- .../SimulationConfig/SimulationConfig.hpp | 8 +- .../SimulationConfig/ThresholdPressure.cpp | 21 +- .../SimulationConfig/ThresholdPressure.hpp | 6 +- .../tests/SimulationConfigTest.cpp | 39 +- .../tests/ThresholdPressureTest.cpp | 27 +- .../EclipseState/Tables/TableManager.cpp | 45 +- .../EclipseState/Tables/TableManager.hpp | 27 +- .../Tables/tests/TableManagerTests.cpp | 72 ++ .../EclipseState/tests/EclipseStateTests.cpp | 129 ++- .../eclipse/IntegrationTests/BoxTest.cpp | 64 +- 41 files changed, 3611 insertions(+), 1916 deletions(-) create mode 100644 opm/parser/eclipse/EclipseState/Eclipse3DProperties.cpp create mode 100644 opm/parser/eclipse/EclipseState/Eclipse3DProperties.hpp create mode 100644 opm/parser/eclipse/EclipseState/EclipseProperties.cpp create mode 100644 opm/parser/eclipse/EclipseState/EclipseProperties.hpp diff --git a/.gitignore b/.gitignore index a957f0202..bd1e923eb 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ install .cproject .project /testdata/statoil -.idea \ No newline at end of file +.idea +/Debug/ diff --git a/opm/parser/eclipse/CMakeLists.txt b/opm/parser/eclipse/CMakeLists.txt index 09d479b37..49c59060f 100644 --- a/opm/parser/eclipse/CMakeLists.txt +++ b/opm/parser/eclipse/CMakeLists.txt @@ -70,6 +70,7 @@ ${generator_source} set (state_source EclipseState/EclipseState.cpp +EclipseState/Eclipse3DProperties.cpp EclipseState/Messages.cpp # EclipseState/checkDeck.cpp @@ -169,6 +170,7 @@ Units/Dimension.hpp Units/ConversionFactors.hpp # EclipseState/EclipseState.hpp +EclipseState/Eclipse3DProperties.hpp EclipseState/Messages.hpp # EclipseState/checkDeck.hpp diff --git a/opm/parser/eclipse/EclipseState/Eclipse3DProperties.cpp b/opm/parser/eclipse/EclipseState/Eclipse3DProperties.cpp new file mode 100644 index 000000000..06a52f486 --- /dev/null +++ b/opm/parser/eclipse/EclipseState/Eclipse3DProperties.cpp @@ -0,0 +1,914 @@ +/* + Copyright 2016 Statoil ASA. + + 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 3 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 . + */ + + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace Opm { + + namespace GridPropertyPostProcessor { + + void distTopLayer( std::vector& values, + const TableManager* tableManager, + const EclipseGrid* eclipseGrid, + GridProperties* intGridProperties, + GridProperties* doubleGridProperties) + { + size_t layerSize = eclipseGrid->getNX() * eclipseGrid->getNY(); + size_t gridSize = eclipseGrid->getCartesianSize(); + + for( size_t globalIndex = layerSize; globalIndex < gridSize; globalIndex++ ) { + if( std::isnan( values[ globalIndex ] ) ) + values[globalIndex] = values[globalIndex - layerSize]; + } + } + + /// initPORV uses doubleGridProperties: PORV, PORO, NTG, MULTPV + void initPORV( std::vector& values, + const TableManager* tableManager, + const EclipseGrid* eclipseGrid, + GridProperties* intGridProperties, + GridProperties* doubleGridProperties) + { + /* + Observe that this apply method does not alter the values input + vector, instead it fetches the PORV property one more time, and + then manipulates that. + */ + + const auto& porv = doubleGridProperties->getOrCreateProperty("PORV"); + + if (porv.containsNaN()) { + const auto& poro = doubleGridProperties->getOrCreateProperty("PORO"); + + const auto& ntg = doubleGridProperties->getOrCreateProperty("NTG"); + if (poro.containsNaN()) + throw std::logic_error("Do not have information for the PORV keyword - some defaulted values in PORO"); + else { + const auto& poroData = poro.getData(); + for (size_t globalIndex = 0; globalIndex < porv.getCartesianSize(); globalIndex++) { + if (std::isnan(values[globalIndex])) { + double cell_poro = poroData[globalIndex]; + double cell_ntg = ntg.iget(globalIndex); + double cell_volume = eclipseGrid->getCellVolume(globalIndex); + values[globalIndex] = cell_poro * cell_volume * cell_ntg; + } + } + } + } + + if (doubleGridProperties->hasKeyword("MULTPV")) { + const auto& multpvData = doubleGridProperties->getKeyword("MULTPV").getData(); + for (size_t globalIndex = 0; globalIndex < porv.getCartesianSize(); globalIndex++) { + values[globalIndex] *= multpvData[globalIndex]; + } + } + } + } + + + + + static std::vector< GridProperties< int >::SupportedKeywordInfo > + makeSupportedIntKeywords() { + return {GridProperties< int >::SupportedKeywordInfo( "SATNUM" , 1, "1" ), + GridProperties< int >::SupportedKeywordInfo( "IMBNUM" , 1, "1" ), + GridProperties< int >::SupportedKeywordInfo( "PVTNUM" , 1, "1" ), + GridProperties< int >::SupportedKeywordInfo( "EQLNUM" , 1, "1" ), + GridProperties< int >::SupportedKeywordInfo( "ENDNUM" , 1, "1" ), + GridProperties< int >::SupportedKeywordInfo( "FLUXNUM", 1, "1" ), + GridProperties< int >::SupportedKeywordInfo( "MULTNUM", 1, "1" ), + GridProperties< int >::SupportedKeywordInfo( "FIPNUM" , 1, "1" ), + GridProperties< int >::SupportedKeywordInfo( "MISCNUM", 1, "1" ) + }; + } + + static std::vector< GridProperties< double >::SupportedKeywordInfo > + makeSupportedDoubleKeywords(const TableManager* tableManager, + const EclipseGrid* eclipseGrid, + GridProperties* intGridProperties) + { + GridPropertyInitFunction< double > SGLLookup ( &SGLEndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > ISGLLookup ( &ISGLEndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > SWLLookup ( &SWLEndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > ISWLLookup ( &ISWLEndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > SGULookup ( &SGUEndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > ISGULookup ( &ISGUEndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > SWULookup ( &SWUEndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > ISWULookup ( &ISWUEndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > SGCRLookup ( &SGCREndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > ISGCRLookup ( &ISGCREndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > SOWCRLookup ( &SOWCREndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > ISOWCRLookup ( &ISOWCREndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > SOGCRLookup ( &SOGCREndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > ISOGCRLookup ( &ISOGCREndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > SWCRLookup ( &SWCREndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > ISWCRLookup ( &ISWCREndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + + GridPropertyInitFunction< double > PCWLookup ( &PCWEndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > IPCWLookup ( &IPCWEndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > PCGLookup ( &PCGEndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > IPCGLookup ( &IPCGEndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > KRWLookup ( &KRWEndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > IKRWLookup ( &IKRWEndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > KRWRLookup ( &KRWREndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > IKRWRLookup ( &IKRWREndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > KROLookup ( &KROEndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > IKROLookup ( &IKROEndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > KRORWLookup ( &KRORWEndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > IKRORWLookup ( &IKRORWEndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > KRORGLookup ( &KRORGEndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > IKRORGLookup ( &IKRORGEndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > KRGLookup ( &KRGEndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > IKRGLookup ( &IKRGEndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > KRGRLookup ( &KRGREndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > IKRGRLookup ( &IKRGREndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + + GridPropertyInitFunction< double > tempLookup ( &temperature_lookup, + tableManager, eclipseGrid, intGridProperties, nullptr ); + + GridPropertyPostFunction< double > distributeTopLayer( &GridPropertyPostProcessor::distTopLayer, + tableManager, eclipseGrid, intGridProperties, nullptr ); + + std::vector< GridProperties< double >::SupportedKeywordInfo > supportedDoubleKeywords; + + // keywords to specify the scaled connate gas saturations. + for( const auto& kw : { "SGL", "SGLX", "SGLX-", "SGLY", "SGLY-", "SGLZ", "SGLZ-" } ) + supportedDoubleKeywords.emplace_back( kw, SGLLookup, "1" ); + for( const auto& kw : { "ISGL", "ISGLX", "ISGLX-", "ISGLY", "ISGLY-", "ISGLZ", "ISGLZ-" } ) + supportedDoubleKeywords.emplace_back( kw, ISGLLookup, "1" ); + + // keywords to specify the connate water saturation. + for( const auto& kw : { "SWL", "SWLX", "SWLX-", "SWLY", "SWLY-", "SWLZ", "SWLZ-" } ) + supportedDoubleKeywords.emplace_back( kw, SWLLookup, "1" ); + for( const auto& kw : { "ISWL", "ISWLX", "ISWLX-", "ISWLY", "ISWLY-", "ISWLZ", "ISWLZ-" } ) + supportedDoubleKeywords.emplace_back( kw, ISWLLookup, "1" ); + + // keywords to specify the maximum gas saturation. + for( const auto& kw : { "SGU", "SGUX", "SGUX-", "SGUY", "SGUY-", "SGUZ", "SGUZ-" } ) + supportedDoubleKeywords.emplace_back( kw, SGULookup, "1" ); + for( const auto& kw : { "ISGU", "ISGUX", "ISGUX-", "ISGUY", "ISGUY-", "ISGUZ", "ISGUZ-" } ) + supportedDoubleKeywords.emplace_back( kw, ISGULookup, "1" ); + + // keywords to specify the maximum water saturation. + for( const auto& kw : { "SWU", "SWUX", "SWUX-", "SWUY", "SWUY-", "SWUZ", "SWUZ-" } ) + supportedDoubleKeywords.emplace_back( kw, SWULookup, "1" ); + for( const auto& kw : { "ISWU", "ISWUX", "ISWUX-", "ISWUY", "ISWUY-", "ISWUZ", "ISWUZ-" } ) + supportedDoubleKeywords.emplace_back( kw, ISWULookup, "1" ); + + // keywords to specify the scaled critical gas saturation. + for( const auto& kw : { "SGCR", "SGCRX", "SGCRX-", "SGCRY", "SGCRY-", "SGCRZ", "SGCRZ-" } ) + supportedDoubleKeywords.emplace_back( kw, SGCRLookup, "1" ); + for( const auto& kw : { "ISGCR", "ISGCRX", "ISGCRX-", "ISGCRY", "ISGCRY-", "ISGCRZ", "ISGCRZ-" } ) + supportedDoubleKeywords.emplace_back( kw, ISGCRLookup, "1" ); + + // keywords to specify the scaled critical oil-in-water saturation. + for( const auto& kw : { "SOWCR", "SOWCRX", "SOWCRX-", "SOWCRY", "SOWCRY-", "SOWCRZ", "SOWCRZ-" } ) + supportedDoubleKeywords.emplace_back( kw, SOWCRLookup, "1" ); + for( const auto& kw : { "ISOWCR", "ISOWCRX", "ISOWCRX-", "ISOWCRY", "ISOWCRY-", "ISOWCRZ", "ISOWCRZ-" } ) + supportedDoubleKeywords.emplace_back( kw, ISOWCRLookup, "1" ); + + // keywords to specify the scaled critical oil-in-gas saturation. + for( const auto& kw : { "SOGCR", "SOGCRX", "SOGCRX-", "SOGCRY", "SOGCRY-", "SOGCRZ", "SOGCRZ-" } ) + supportedDoubleKeywords.emplace_back( kw, SOGCRLookup, "1" ); + for( const auto& kw : { "ISOGCR", "ISOGCRX", "ISOGCRX-", "ISOGCRY", "ISOGCRY-", "ISOGCRZ", "ISOGCRZ-" } ) + supportedDoubleKeywords.emplace_back( kw, ISOGCRLookup, "1" ); + + // keywords to specify the scaled critical water saturation. + for( const auto& kw : { "SWCR", "SWCRX", "SWCRX-", "SWCRY", "SWCRY-", "SWCRZ", "SWCRZ-" } ) + supportedDoubleKeywords.emplace_back( kw, SWCRLookup, "1" ); + for( const auto& kw : { "ISWCR", "ISWCRX", "ISWCRX-", "ISWCRY", "ISWCRY-", "ISWCRZ", "ISWCRZ-" } ) + supportedDoubleKeywords.emplace_back( kw, ISWCRLookup, "1" ); + + // keywords to specify the scaled oil-water capillary pressure + for( const auto& kw : { "PCW", "PCWX", "PCWX-", "PCWY", "PCWY-", "PCWZ", "PCWZ-" } ) + supportedDoubleKeywords.emplace_back( kw, PCWLookup, "1" ); + for( const auto& kw : { "IPCW", "IPCWX", "IPCWX-", "IPCWY", "IPCWY-", "IPCWZ", "IPCWZ-" } ) + supportedDoubleKeywords.emplace_back( kw, IPCWLookup, "1" ); + + // keywords to specify the scaled gas-oil capillary pressure + for( const auto& kw : { "PCG", "PCGX", "PCGX-", "PCGY", "PCGY-", "PCGZ", "PCGZ-" } ) + supportedDoubleKeywords.emplace_back( kw, PCGLookup, "1" ); + for( const auto& kw : { "IPCG", "IPCGX", "IPCGX-", "IPCGY", "IPCGY-", "IPCGZ", "IPCGZ-" } ) + supportedDoubleKeywords.emplace_back( kw, IPCGLookup, "1" ); + + // keywords to specify the scaled water relative permeability + for( const auto& kw : { "KRW", "KRWX", "KRWX-", "KRWY", "KRWY-", "KRWZ", "KRWZ-" } ) + supportedDoubleKeywords.emplace_back( kw, KRWLookup, "1" ); + for( const auto& kw : { "IKRW", "IKRWX", "IKRWX-", "IKRWY", "IKRWY-", "IKRWZ", "IKRWZ-" } ) + supportedDoubleKeywords.emplace_back( kw, IKRWLookup, "1" ); + + // keywords to specify the scaled water relative permeability at the critical + // saturation + for( const auto& kw : { "KRWR" , "KRWRX" , "KRWRX-" , "KRWRY" , "KRWRY-" , "KRWRZ" , "KRWRZ-" } ) + supportedDoubleKeywords.emplace_back( kw, KRWRLookup, "1" ); + for( const auto& kw : { "IKRWR" , "IKRWRX" , "IKRWRX-" , "IKRWRY" , "IKRWRY-" , "IKRWRZ" , "IKRWRZ-" } ) + supportedDoubleKeywords.emplace_back( kw, IKRWRLookup, "1" ); + + // keywords to specify the scaled oil relative permeability + for( const auto& kw : { "KRO", "KROX", "KROX-", "KROY", "KROY-", "KROZ", "KROZ-" } ) + supportedDoubleKeywords.emplace_back( kw, KROLookup, "1" ); + for( const auto& kw : { "IKRO", "IKROX", "IKROX-", "IKROY", "IKROY-", "IKROZ", "IKROZ-" } ) + supportedDoubleKeywords.emplace_back( kw, IKROLookup, "1" ); + + // keywords to specify the scaled water relative permeability at the critical + // water saturation + for( const auto& kw : { "KRORW", "KRORWX", "KRORWX-", "KRORWY", "KRORWY-", "KRORWZ", "KRORWZ-" } ) + supportedDoubleKeywords.emplace_back( kw, KRORWLookup, "1" ); + for( const auto& kw : { "IKRORW", "IKRORWX", "IKRORWX-", "IKRORWY", "IKRORWY-", "IKRORWZ", "IKRORWZ-" } ) + supportedDoubleKeywords.emplace_back( kw, IKRORWLookup, "1" ); + + // keywords to specify the scaled water relative permeability at the critical + // water saturation + for( const auto& kw : { "KRORG", "KRORGX", "KRORGX-", "KRORGY", "KRORGY-", "KRORGZ", "KRORGZ-" } ) + supportedDoubleKeywords.emplace_back( kw, KRORGLookup, "1" ); + for( const auto& kw : { "IKRORG", "IKRORGX", "IKRORGX-", "IKRORGY", "IKRORGY-", "IKRORGZ", "IKRORGZ-" } ) + supportedDoubleKeywords.emplace_back( kw, IKRORGLookup, "1" ); + + // keywords to specify the scaled gas relative permeability + for( const auto& kw : { "KRG", "KRGX", "KRGX-", "KRGY", "KRGY-", "KRGZ", "KRGZ-" } ) + supportedDoubleKeywords.emplace_back( kw, KRGLookup, "1" ); + for( const auto& kw : { "IKRG", "IKRGX", "IKRGX-", "IKRGY", "IKRGY-", "IKRGZ", "IKRGZ-" } ) + supportedDoubleKeywords.emplace_back( kw, IKRGLookup, "1" ); + + // keywords to specify the scaled gas relative permeability + for( const auto& kw : { "KRGR", "KRGRX", "KRGRX-", "KRGRY", "KRGRY-", "KRGRZ", "KRGRZ-" } ) + supportedDoubleKeywords.emplace_back( kw, KRGRLookup, "1" ); + for( const auto& kw : { "IKRGR", "IKRGRX", "IKRGRX-", "IKRGRY", "IKRGRY-", "IKRGRZ", "IKRGRZ-" } ) + supportedDoubleKeywords.emplace_back( kw, IKRGRLookup, "1" ); + + + + // cell temperature (E300 only, but makes a lot of sense for E100, too) + supportedDoubleKeywords.emplace_back( "TEMPI", tempLookup, "Temperature" ); + + const double nan = std::numeric_limits::quiet_NaN(); + // porosity + supportedDoubleKeywords.emplace_back( "PORO", nan, distributeTopLayer, "1" ); + + // pore volume multipliers + supportedDoubleKeywords.emplace_back( "MULTPV", 1.0, "1" ); + + // the permeability keywords + for( const auto& kw : { "PERMX", "PERMY", "PERMZ" } ) + supportedDoubleKeywords.emplace_back( kw, nan, distributeTopLayer, "Permeability" ); + + /* E300 only */ + for( const auto& kw : { "PERMXY", "PERMYZ", "PERMZX" } ) + supportedDoubleKeywords.emplace_back( kw, nan, distributeTopLayer, "Permeability" ); + + /* the transmissibility keywords for neighboring connections. note that + * these keywords don't seem to require a post-processor + */ + for( const auto& kw : { "TRANX", "TRANY", "TRANZ" } ) + supportedDoubleKeywords.emplace_back( kw, nan, "Transmissibility" ); + + /* gross-to-net thickness (acts as a multiplier for PORO and the + * permeabilities in the X-Y plane as well as for the well rates.) + */ + supportedDoubleKeywords.emplace_back( "NTG", 1.0, "1" ); + + // transmissibility multipliers + for( const auto& kw : { "MULTX", "MULTY", "MULTZ", "MULTX-", "MULTY-", "MULTZ-" } ) + supportedDoubleKeywords.emplace_back( kw, 1.0, "1" ); + + // initialisation + supportedDoubleKeywords.emplace_back( "SWATINIT", 0.0, "1"); + supportedDoubleKeywords.emplace_back( "THCONR", 0.0, "1"); + + return supportedDoubleKeywords; + } + + + + Eclipse3DProperties::Eclipse3DProperties( const Deck& deck, + std::shared_ptr tableManager, + const EclipseGrid& eclipseGrid) + : + + m_defaultRegion("FLUXNUM"), + m_deckUnitSystem(deck.getActiveUnitSystem()), + // Note that the variants of grid keywords for radial grids are not + // supported. (and hopefully never will be) + // register the grid properties + m_intGridProperties(eclipseGrid, makeSupportedIntKeywords()), + m_doubleGridProperties(eclipseGrid, + makeSupportedDoubleKeywords(tableManager.get(), &eclipseGrid, &m_intGridProperties)) + { + /* + * The EQUALREG, MULTREG, COPYREG, ... keywords are used to manipulate + * vectors based on region values; for instance the statement + * + * EQUALREG + * PORO 0.25 3 / -- Region array not specified + * PERMX 100 3 F / + * / + * + * will set the PORO field to 0.25 for all cells in region 3 and the PERMX + * value to 100 mD for the same cells. The fourth optional argument to the + * EQUALREG keyword is used to indicate which REGION array should be used + * for the selection. + * + * If the REGION array is not indicated (as in the PORO case) above, the + * default region to use in the xxxREG keywords depends on the GRIDOPTS + * keyword: + * + * 1. If GRIDOPTS is present, and the NRMULT item is greater than zero, + * the xxxREG keywords will default to use the MULTNUM region. + * + * 2. If the GRIDOPTS keyword is not present - or the NRMULT item equals + * zero, the xxxREG keywords will default to use the FLUXNUM keyword. + * + * This quite weird behaviour comes from reading the GRIDOPTS and MULTNUM + * documentation, and practical experience with ECLIPSE + * simulations. Ufortunately the documentation of the xxxREG keywords does + * not confirm this. + */ + if (deck.hasKeyword( "GRIDOPTS" )) { + const auto& gridOpts = deck.getKeyword( "GRIDOPTS" ); + const auto& record = gridOpts.getRecord( 0 ); + const auto& nrmult_item = record.getItem( "NRMULT" ); + + if (nrmult_item.get( 0 ) > 0) + m_defaultRegion = "MULTNUM"; // GRIDOPTS and positive NRMULT + } + + + GridPropertyPostFunction< double > initPORV(&GridPropertyPostProcessor::initPORV, + tableManager.get(), + &eclipseGrid, + &m_intGridProperties, + &m_doubleGridProperties); + // pore volume + m_doubleGridProperties.postAddKeyword( "PORV", + std::numeric_limits::quiet_NaN(), + initPORV, + "Volume" ); + + // actually create the grid property objects. we need to first process + // all integer grid properties before the double ones as these may be + // needed in order to initialize the double properties + processGridProperties(deck, eclipseGrid, /*enabledTypes=*/IntProperties); + processGridProperties(deck, eclipseGrid, /*enabledTypes=*/DoubleProperties); + + } + + bool Eclipse3DProperties::supportsGridProperty(const std::string& keyword, + int enabledTypes) const + { + bool result = false; + if (enabledTypes & IntProperties) + result = result || + m_intGridProperties.supportsKeyword( keyword ); + + if (enabledTypes & DoubleProperties) + result = result || + m_doubleGridProperties.supportsKeyword( keyword ); + return result; + } + + + + bool Eclipse3DProperties::hasDeckIntGridProperty(const std::string& keyword) const { + if (!m_intGridProperties.supportsKeyword( keyword )) + throw std::logic_error("Integer grid property " + keyword + " is unsupported!"); + + return m_intGridProperties.hasKeyword( keyword ); + } + + bool Eclipse3DProperties::hasDeckDoubleGridProperty(const std::string& keyword) const { + if (!m_doubleGridProperties.supportsKeyword( keyword )) + throw std::logic_error("Double grid property " + keyword + " is unsupported!"); + + return m_doubleGridProperties.hasKeyword( keyword ); + } + + GridProperties& Eclipse3DProperties::getIntGridProperties() { + return m_intGridProperties; + } + + /// gets properties doubleGridProperties. This does not run any post processors + GridProperties& Eclipse3DProperties::getDoubleGridProperties() { + return m_doubleGridProperties; + } + + /* + 1. The public methods getIntGridProperty & getDoubleGridProperty will + invoke and run the property post processor (if any is registered); the + post processor will only run one time. + + It is important that post processor is not run prematurely, internal + functions in EclipseState should therefore ask for properties by + invoking the getKeyword() method of the m_intGridProperties / + m_doubleGridProperties() directly and not through these methods. + + 2. Observe that this will autocreate a property if it has not been + explicitly added. + */ + const GridProperty& Eclipse3DProperties::getIntGridProperty( const std::string& keyword ) const { + return m_intGridProperties.getKeyword( keyword ); + } + + /// gets property from doubleGridProperty --- and calls the runPostProcessor + const GridProperty& Eclipse3DProperties::getDoubleGridProperty( const std::string& keyword ) const { + auto& gridProperty = const_cast< Eclipse3DProperties* >( this )->m_doubleGridProperties.getKeyword( keyword ); + gridProperty.runPostProcessor(); + return gridProperty; + } + + std::string Eclipse3DProperties::getDefaultRegionKeyword() const { + return m_defaultRegion; + } + + const GridProperty& Eclipse3DProperties::getRegion( const DeckItem& regionItem ) const { + if (regionItem.defaultApplied(0)) + return m_intGridProperties.getKeyword( m_defaultRegion ); + else { + const std::string regionArray = MULTREGT::RegionNameFromDeckValue( regionItem.get< std::string >(0) ); + return m_intGridProperties.getInitializedKeyword( regionArray ); + } + } + + /// Due to the post processor which might be applied to the GridProperty + /// objects it is essential that this method use the m_intGridProperties / + /// m_doubleGridProperties fields directly and *NOT* use the public methods + /// getIntGridProperty / getDoubleGridProperty. + void Eclipse3DProperties::loadGridPropertyFromDeckKeyword(const Box& inputBox, + const DeckKeyword& deckKeyword, + int enabledTypes) + { + const std::string& keyword = deckKeyword.name(); + if (m_intGridProperties.supportsKeyword( keyword )) { + if (enabledTypes & IntProperties) { + auto& gridProperty = m_intGridProperties.getOrCreateProperty( keyword ); + gridProperty.loadFromDeckKeyword( inputBox, deckKeyword ); + } + } else if (m_doubleGridProperties.supportsKeyword( keyword )) { + if (enabledTypes & DoubleProperties) { + auto& gridProperty = m_doubleGridProperties.getOrCreateProperty( keyword ); + gridProperty.loadFromDeckKeyword( inputBox, deckKeyword ); + } + } else { + throw std::logic_error( "Tried to load unsupported grid property from keyword: " + deckKeyword.name() ); + } + } + + static bool isInt(double value) { + return fabs( nearbyint( value ) - value ) < 1e-6; + } + + void Eclipse3DProperties::processGridProperties( const Deck& deck, + const EclipseGrid& eclipseGrid, + int enabledTypes) { + + if (Section::hasGRID(deck)) { + scanSection(GRIDSection(deck), eclipseGrid, enabledTypes); + } + + if (Section::hasEDIT(deck)) { + scanSection(EDITSection(deck), eclipseGrid, enabledTypes); + } + + if (Section::hasPROPS(deck)) { + scanSection(PROPSSection(deck), eclipseGrid, enabledTypes); + } + + if (Section::hasREGIONS(deck)) { + scanSection(REGIONSSection(deck), eclipseGrid, enabledTypes); + } + + if (Section::hasSOLUTION(deck)) { + scanSection(SOLUTIONSection(deck), eclipseGrid, enabledTypes); + } + } + + + + // private method + double Eclipse3DProperties::getSIScaling(const std::string &dimensionString) const + { + return m_deckUnitSystem.getDimension(dimensionString)->getSIScaling(); + } + + void Eclipse3DProperties::scanSection(const Section& section, + const EclipseGrid& eclipseGrid, + int enabledTypes) { + BoxManager boxManager(eclipseGrid.getNX(), + eclipseGrid.getNY(), + eclipseGrid.getNZ()); + + for( const auto& deckKeyword : section ) { + + if (supportsGridProperty(deckKeyword.name(), enabledTypes) ) + loadGridPropertyFromDeckKeyword( *boxManager.getActiveBox(), + deckKeyword, + enabledTypes); + else { + if (deckKeyword.name() == "ADD") + handleADDKeyword(deckKeyword, boxManager, enabledTypes); + + if (deckKeyword.name() == "BOX") + handleBOXKeyword(deckKeyword, boxManager); + + if (deckKeyword.name() == "COPY") + handleCOPYKeyword(deckKeyword, boxManager, enabledTypes); + + if (deckKeyword.name() == "EQUALS") + handleEQUALSKeyword(deckKeyword, boxManager, enabledTypes); + + if (deckKeyword.name() == "MULTIPLY") + handleMULTIPLYKeyword(deckKeyword, boxManager, enabledTypes); + + if (deckKeyword.name() == "ENDBOX") + handleENDBOXKeyword(boxManager); + + if (deckKeyword.name() == "EQUALREG") + handleEQUALREGKeyword(deckKeyword, enabledTypes); + + if (deckKeyword.name() == "ADDREG") + handleADDREGKeyword(deckKeyword, enabledTypes); + + if (deckKeyword.name() == "MULTIREG") + handleMULTIREGKeyword(deckKeyword, enabledTypes); + + if (deckKeyword.name() == "COPYREG") + handleCOPYREGKeyword(deckKeyword, enabledTypes); + + boxManager.endKeyword(); + } + } + boxManager.endSection(); + } + + + void Eclipse3DProperties::handleBOXKeyword( const DeckKeyword& deckKeyword, BoxManager& boxManager) { + const auto& record = deckKeyword.getRecord(0); + int I1 = record.getItem("I1").get< int >(0) - 1; + int I2 = record.getItem("I2").get< int >(0) - 1; + int J1 = record.getItem("J1").get< int >(0) - 1; + int J2 = record.getItem("J2").get< int >(0) - 1; + int K1 = record.getItem("K1").get< int >(0) - 1; + int K2 = record.getItem("K2").get< int >(0) - 1; + + boxManager.setInputBox( I1 , I2 , J1 , J2 , K1 , K2 ); + } + + + void Eclipse3DProperties::handleENDBOXKeyword(BoxManager& boxManager) { + boxManager.endInputBox(); + } + + + void Eclipse3DProperties::handleEQUALREGKeyword( const DeckKeyword& deckKeyword, + int enabledTypes) + { + for( const auto& record : deckKeyword ) { + const std::string& targetArray = record.getItem("ARRAY").get< std::string >(0); + + if (!supportsGridProperty( targetArray , IntProperties + DoubleProperties)) + throw std::invalid_argument("Fatal error processing EQUALREG keyword - invalid/undefined keyword: " + targetArray); + + double doubleValue = record.getItem("VALUE").template get(0); + int regionValue = record.getItem("REGION_NUMBER").template get(0); + auto& regionProperty = getRegion( record.getItem("REGION_NAME") ); + std::vector mask; + + regionProperty.initMask( regionValue , mask); + + if (m_intGridProperties.supportsKeyword( targetArray )) { + if (enabledTypes & IntProperties) { + if (isInt( doubleValue )) { + auto& targetProperty = m_intGridProperties.getOrCreateProperty( targetArray ); + int intValue = static_cast( doubleValue + 0.5 ); + targetProperty.maskedSet( intValue , mask); + } else + throw std::invalid_argument("Fatal error processing EQUALREG keyword - expected integer value for: " + targetArray); + } + } + else if (m_doubleGridProperties.supportsKeyword( targetArray )) { + if (enabledTypes & DoubleProperties) { + auto& targetProperty = m_doubleGridProperties.getOrCreateProperty( targetArray ); + + const std::string& dimensionString = targetProperty.getDimensionString(); + double SIValue = doubleValue * getSIScaling( dimensionString ); + + targetProperty.maskedSet( SIValue , mask); + } + } + else { + throw std::invalid_argument("Fatal error processing EQUALREG keyword - invalid/undefined keyword: " + targetArray); + } + } + } + + + void Eclipse3DProperties::handleADDREGKeyword( const DeckKeyword& deckKeyword, int enabledTypes) { + for( const auto& record : deckKeyword ) { + const std::string& targetArray = record.getItem("ARRAY").get< std::string >(0); + + if (!supportsGridProperty( targetArray , IntProperties + DoubleProperties)) + throw std::invalid_argument("Fatal error processing ADDREG keyword - invalid/undefined keyword: " + targetArray); + + if (supportsGridProperty( targetArray , enabledTypes)) { + double doubleValue = record.getItem("SHIFT").get< double >(0); + int regionValue = record.getItem("REGION_NUMBER").get< int >(0); + auto& regionProperty = getRegion( record.getItem("REGION_NAME") ); + std::vector mask; + + regionProperty.initMask( regionValue , mask); + + if (m_intGridProperties.hasKeyword( targetArray )) { + if (enabledTypes & IntProperties) { + if (isInt( doubleValue )) { + GridProperty& targetProperty = m_intGridProperties.getKeyword(targetArray); + int intValue = static_cast( doubleValue + 0.5 ); + targetProperty.maskedAdd( intValue , mask); + } else + throw std::invalid_argument("Fatal error processing ADDREG keyword - expected integer value for: " + targetArray); + } + } + else if (m_doubleGridProperties.hasKeyword( targetArray )) { + if (enabledTypes & DoubleProperties) { + GridProperty& targetProperty = m_doubleGridProperties.getKeyword(targetArray); + + const std::string& dimensionString = targetProperty.getDimensionString(); + double SIValue = doubleValue * getSIScaling( dimensionString ); + + targetProperty.maskedAdd( SIValue , mask); + } + } + else { + throw std::invalid_argument("Fatal error processing ADDREG keyword - invalid/undefined keyword: " + targetArray); + } + } + } + } + + + + void Eclipse3DProperties::handleMULTIREGKeyword( const DeckKeyword& deckKeyword, int enabledTypes) { + for( const auto& record : deckKeyword ) { + const std::string& targetArray = record.getItem("ARRAY").get< std::string >(0); + + if (!supportsGridProperty( targetArray , IntProperties + DoubleProperties)) + throw std::invalid_argument("Fatal error processing MULTIREG keyword - invalid/undefined keyword: " + targetArray); + + if (supportsGridProperty( targetArray , enabledTypes)) { + double doubleValue = record.getItem("FACTOR").get< double >(0); + int regionValue = record.getItem("REGION_NUMBER").get< int >(0); + auto& regionProperty = getRegion( record.getItem("REGION_NAME") ); + std::vector mask; + + regionProperty.initMask( regionValue , mask); + + if (enabledTypes & IntProperties) { + if (isInt( doubleValue )) { + auto& targetProperty = m_intGridProperties.getOrCreateProperty( targetArray ); + int intValue = static_cast( doubleValue + 0.5 ); + + targetProperty.maskedMultiply( intValue , mask); + } else + throw std::invalid_argument( + "Fatal error processing MULTIREG keyword - expected" + " integer value for: " + targetArray); + } + if (enabledTypes & DoubleProperties) { + auto& targetProperty = m_doubleGridProperties.getOrCreateProperty(targetArray); + targetProperty.maskedMultiply( doubleValue , mask); + } + } + } + } + + + void Eclipse3DProperties::handleCOPYREGKeyword( const DeckKeyword& deckKeyword, int enabledTypes) { + for( const auto& record : deckKeyword ) { + const std::string& srcArray = record.getItem("ARRAY").get< std::string >(0); + const std::string& targetArray = record.getItem("TARGET_ARRAY").get< std::string >(0); + + if (!supportsGridProperty( targetArray , IntProperties + DoubleProperties)) + throw std::invalid_argument("Fatal error processing MULTIREG keyword - invalid/undefined keyword: " + targetArray); + + if (!supportsGridProperty( srcArray , IntProperties + DoubleProperties)) + throw std::invalid_argument("Fatal error processing MULTIREG keyword - invalid/undefined keyword: " + srcArray); + + if (supportsGridProperty( srcArray , enabledTypes)) + { + int regionValue = record.getItem("REGION_NUMBER").get< int >(0); + auto& regionProperty = getRegion( record.getItem("REGION_NAME") ); + std::vector mask; + + regionProperty.initMask( regionValue , mask ); + + if (m_intGridProperties.hasKeyword( srcArray )) { + auto& srcProperty = m_intGridProperties.getInitializedKeyword( srcArray ); + if (supportsGridProperty( targetArray , IntProperties)) { + GridProperty& targetProperty = m_intGridProperties.getOrCreateProperty( targetArray ); + targetProperty.maskedCopy( srcProperty , mask ); + } else + throw std::invalid_argument("Fatal error processing COPYREG keyword."); + } else if (m_doubleGridProperties.hasKeyword( srcArray )) { + const GridProperty& srcProperty = m_doubleGridProperties.getInitializedKeyword( srcArray ); + if (supportsGridProperty( targetArray , DoubleProperties)) { + auto& targetProperty = m_doubleGridProperties.getOrCreateProperty( targetArray ); + targetProperty.maskedCopy( srcProperty , mask ); + } + } + else { + throw std::invalid_argument("Fatal error processing COPYREG keyword - invalid/undefined keyword: " + targetArray); + } + } + } + } + + + + + void Eclipse3DProperties::handleMULTIPLYKeyword( const DeckKeyword& deckKeyword, BoxManager& boxManager, int enabledTypes) { + for( const auto& record : deckKeyword ) { + const std::string& field = record.getItem("field").get< std::string >(0); + double scaleFactor = record.getItem("factor").get< double >(0); + + setKeywordBox(deckKeyword, record, boxManager); + + if (m_intGridProperties.hasKeyword( field )) { + if (enabledTypes & IntProperties) { + int intFactor = static_cast(scaleFactor); + GridProperty& property = m_intGridProperties.getKeyword( field ); + property.scale( intFactor , *boxManager.getActiveBox() ); + } + } else if (m_doubleGridProperties.hasKeyword( field )) { + if (enabledTypes & DoubleProperties) { + GridProperty& property = m_doubleGridProperties.getKeyword( field ); + property.scale( scaleFactor , *boxManager.getActiveBox() ); + } + } else if (!m_intGridProperties.supportsKeyword(field) && + !m_doubleGridProperties.supportsKeyword(field)) + throw std::invalid_argument("Fatal error processing MULTIPLY keyword. Tried to multiply not defined keyword " + field); + } + } + + + /** + The fine print of the manual says the ADD keyword should support + some state dependent semantics regarding endpoint scaling arrays + in the PROPS section. That is not supported. + */ + void Eclipse3DProperties::handleADDKeyword( const DeckKeyword& deckKeyword, BoxManager& boxManager, int enabledTypes) { + for( const auto& record : deckKeyword ) { + const std::string& field = record.getItem("field").get< std::string >(0); + double shiftValue = record.getItem("shift").get< double >(0); + + setKeywordBox(deckKeyword, record, boxManager); + + if (m_intGridProperties.hasKeyword( field )) { + if (enabledTypes & IntProperties) { + int intShift = static_cast(shiftValue); + GridProperty& property = m_intGridProperties.getKeyword( field ); + + property.add( intShift , *boxManager.getActiveBox() ); + } + } else if (m_doubleGridProperties.hasKeyword( field )) { + if (enabledTypes & DoubleProperties) { + GridProperty& property = m_doubleGridProperties.getKeyword( field ); + + double siShiftValue = shiftValue * getSIScaling(property.getDimensionString()); + property.add(siShiftValue , *boxManager.getActiveBox() ); + } + } else if (!m_intGridProperties.supportsKeyword(field) && + !m_doubleGridProperties.supportsKeyword(field)) + throw std::invalid_argument("Fatal error processing ADD keyword. Tried to shift not defined keyword " + field); + } + } + + + void Eclipse3DProperties::handleEQUALSKeyword( const DeckKeyword& deckKeyword, BoxManager& boxManager, int enabledTypes) { + for( const auto& record : deckKeyword ) { + const std::string& field = record.getItem("field").get< std::string >(0); + double value = record.getItem("value").get< double >(0); + + setKeywordBox(deckKeyword, record, boxManager); + + if (m_intGridProperties.supportsKeyword( field )) { + if (enabledTypes & IntProperties) { + int intValue = static_cast(value); + GridProperty& property = m_intGridProperties.getOrCreateProperty( field ); + + property.setScalar( intValue , *boxManager.getActiveBox() ); + } + } else if (m_doubleGridProperties.supportsKeyword( field )) { + + if (enabledTypes & DoubleProperties) { + GridProperty& property = m_doubleGridProperties.getOrCreateProperty( field ); + + double siValue = value * getSIScaling(property.getKeywordInfo().getDimensionString()); + property.setScalar( siValue , *boxManager.getActiveBox() ); + } + } else + throw std::invalid_argument("Fatal error processing EQUALS keyword. Tried to set not defined keyword " + field); + } + } + + + + void Eclipse3DProperties::handleCOPYKeyword( const DeckKeyword& deckKeyword, BoxManager& boxManager, int enabledTypes) { + for( const auto& record : deckKeyword ) { + const std::string& srcField = record.getItem("src").get< std::string >(0); + const std::string& targetField = record.getItem("target").get< std::string >(0); + + setKeywordBox(deckKeyword, record, boxManager); + + if (m_intGridProperties.hasKeyword( srcField )) { + if (enabledTypes & IntProperties) + m_intGridProperties.copyKeyword( srcField , targetField , *boxManager.getActiveBox() ); + } + else if (m_doubleGridProperties.hasKeyword( srcField )) { + if (enabledTypes & DoubleProperties) + m_doubleGridProperties.copyKeyword( srcField , targetField , *boxManager.getActiveBox() ); + } + else + if (!m_intGridProperties.supportsKeyword(srcField) && + !m_doubleGridProperties.supportsKeyword(srcField)) + throw std::invalid_argument("Fatal error processing COPY keyword." + " Tried to copy from not defined keyword " + srcField); + } + } + + // static member function + void Eclipse3DProperties::setKeywordBox( const DeckKeyword& deckKeyword, + const DeckRecord& deckRecord, + BoxManager& boxManager) { + const auto& I1Item = deckRecord.getItem("I1"); + const auto& I2Item = deckRecord.getItem("I2"); + const auto& J1Item = deckRecord.getItem("J1"); + const auto& J2Item = deckRecord.getItem("J2"); + const auto& K1Item = deckRecord.getItem("K1"); + const auto& K2Item = deckRecord.getItem("K2"); + + size_t setCount = 0; + + if (!I1Item.defaultApplied(0)) + setCount++; + + if (!I2Item.defaultApplied(0)) + setCount++; + + if (!J1Item.defaultApplied(0)) + setCount++; + + if (!J2Item.defaultApplied(0)) + setCount++; + + if (!K1Item.defaultApplied(0)) + setCount++; + + if (!K2Item.defaultApplied(0)) + setCount++; + + if (setCount == 6) { + boxManager.setKeywordBox( I1Item.get< int >(0) - 1, + I2Item.get< int >(0) - 1, + J1Item.get< int >(0) - 1, + J2Item.get< int >(0) - 1, + K1Item.get< int >(0) - 1, + K2Item.get< int >(0) - 1); + } else if (setCount != 0) { + std::string msg = "BOX modifiers on keywords must be either " + "specified completely or not at all. Ignoring."; + OpmLog::addMessage(Log::MessageType::Error, + Log::fileMessage(deckKeyword.getFileName(), + deckKeyword.getLineNumber(), + msg)); + } + } +} diff --git a/opm/parser/eclipse/EclipseState/Eclipse3DProperties.hpp b/opm/parser/eclipse/EclipseState/Eclipse3DProperties.hpp new file mode 100644 index 000000000..a870a26fd --- /dev/null +++ b/opm/parser/eclipse/EclipseState/Eclipse3DProperties.hpp @@ -0,0 +1,114 @@ +/* + Copyright 2013 Statoil ASA. + + 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 3 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 . +*/ + +#ifndef OPM_ECLIPSE_PROPERTIES_HPP +#define OPM_ECLIPSE_PROPERTIES_HPP + +#include +#include +#include + +#include +#include + + +namespace Opm { + + class Box; + class BoxManager; + class Deck; + class DeckItem; + class DeckKeyword; + class DeckRecord; + class EclipseGrid; + class EclipseState; + class InitConfig; + class IOConfig; + class Schedule; + class Section; + class TableManager; + class TransMult; + class UnitSystem; + + /// Class representing properties on 3D grid for use in EclipseState. + class Eclipse3DProperties + { + public: + enum EnabledTypes { + IntProperties = 0x01, + DoubleProperties = 0x02, + AllProperties = IntProperties | DoubleProperties + }; + + Eclipse3DProperties(const Deck& deck, + std::shared_ptr tableManager, + const EclipseGrid& eclipseGrid); + + const GridProperty& getRegion(const DeckItem& regionItem) const; + std::string getDefaultRegionKeyword() const; + + const GridProperty& getIntGridProperty ( const std::string& keyword ) const; + const GridProperty& getDoubleGridProperty ( const std::string& keyword ) const; + GridProperties& getIntGridProperties (); + GridProperties& getDoubleGridProperties(); + + bool hasDeckIntGridProperty(const std::string& keyword) const; + bool hasDeckDoubleGridProperty(const std::string& keyword) const; + bool supportsGridProperty(const std::string& keyword, int enabledTypes = AllProperties) const; + + private: + void processGridProperties(const Deck& deck, + const EclipseGrid& eclipseGrid, + int enabledTypes); + + double getSIScaling(const std::string &dimensionString) const; + + void scanSection(const Section& section, + const EclipseGrid& eclipseGrid, + int enabledTypes); + + void handleADDKeyword( const DeckKeyword& deckKeyword, BoxManager& boxManager, int enabledTypes); + void handleBOXKeyword( const DeckKeyword& deckKeyword, BoxManager& boxManager); + void handleCOPYKeyword( const DeckKeyword& deckKeyword, BoxManager& boxManager, int enabledTypes); + void handleENDBOXKeyword( BoxManager& boxManager); + void handleEQUALSKeyword( const DeckKeyword& deckKeyword, BoxManager& boxManager, int enabledTypes); + void handleMULTIPLYKeyword(const DeckKeyword& deckKeyword, BoxManager& boxManager, int enabledTypes); + + void handleADDREGKeyword( const DeckKeyword& deckKeyword, int enabledTypes); + void handleCOPYREGKeyword( const DeckKeyword& deckKeyword, int enabledTypes); + void handleEQUALREGKeyword(const DeckKeyword& deckKeyword, int enabledTypes); + void handleMULTIREGKeyword(const DeckKeyword& deckKeyword, int enabledTypes); + + void loadGridPropertyFromDeckKeyword(const Box& inputBox, + const DeckKeyword& deckKeyword, + int enabledTypes); + + static void setKeywordBox(const DeckKeyword& deckKeyword, const DeckRecord&, BoxManager& boxManager); + + void initProperties( const Deck& deck, + std::shared_ptr tableManager, + const EclipseGrid& eclipseGrid ); + + std::string m_defaultRegion; + const UnitSystem& m_deckUnitSystem; + GridProperties m_intGridProperties; + GridProperties m_doubleGridProperties; + }; +} + +#endif // OPM_ECLIPSE_PROPERTIES_HPP diff --git a/opm/parser/eclipse/EclipseState/EclipseProperties.cpp b/opm/parser/eclipse/EclipseState/EclipseProperties.cpp new file mode 100644 index 000000000..97631241b --- /dev/null +++ b/opm/parser/eclipse/EclipseState/EclipseProperties.cpp @@ -0,0 +1,894 @@ +/* + Copyright 2013 Statoil ASA. + + 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 3 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 . + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace Opm { + + namespace GridPropertyPostProcessor { + + void distTopLayer( std::vector& values, + const TableManager* tableManager, + const EclipseGrid* eclipseGrid, + GridProperties* intGridProperties, + GridProperties* doubleGridProperties) + { + size_t layerSize = eclipseGrid->getNX() * eclipseGrid->getNY(); + size_t gridSize = eclipseGrid->getCartesianSize(); + + for( size_t globalIndex = layerSize; globalIndex < gridSize; globalIndex++ ) { + if( std::isnan( values[ globalIndex ] ) ) + values[globalIndex] = values[globalIndex - layerSize]; + } + } + + /// initPORV uses doubleGridProperties: PORV, PORO, NTG, MULTPV + void initPORV( std::vector& values, + const TableManager* tableManager, + const EclipseGrid* eclipseGrid, + GridProperties* intGridProperties, + GridProperties* doubleGridProperties) + { + /* + Observe that this apply method does not alter the values input + vector, instead it fetches the PORV property one more time, and + then manipulates that. + */ + + const auto& porv = doubleGridProperties->getOrCreateProperty("PORV"); + + if (porv.containsNaN()) { + const auto& poro = doubleGridProperties->getOrCreateProperty("PORO"); + + const auto& ntg = doubleGridProperties->getOrCreateProperty("NTG"); + if (poro.containsNaN()) + throw std::logic_error("Do not have information for the PORV keyword - some defaulted values in PORO"); + else { + const auto& poroData = poro.getData(); + for (size_t globalIndex = 0; globalIndex < porv.getCartesianSize(); globalIndex++) { + if (std::isnan(values[globalIndex])) { + double cell_poro = poroData[globalIndex]; + double cell_ntg = ntg.iget(globalIndex); + double cell_volume = eclipseGrid->getCellVolume(globalIndex); + values[globalIndex] = cell_poro * cell_volume * cell_ntg; + } + } + } + } + + if (doubleGridProperties->hasKeyword("MULTPV")) { + const auto& multpvData = doubleGridProperties->getKeyword("MULTPV").getData(); + for (size_t globalIndex = 0; globalIndex < porv.getCartesianSize(); globalIndex++) { + values[globalIndex] *= multpvData[globalIndex]; + } + } + } + } + + + + + static std::vector< GridProperties< int >::SupportedKeywordInfo > + makeSupportedIntKeywords() { + return {GridProperties< int >::SupportedKeywordInfo( "SATNUM" , 1, "1" ), + GridProperties< int >::SupportedKeywordInfo( "IMBNUM" , 1, "1" ), + GridProperties< int >::SupportedKeywordInfo( "PVTNUM" , 1, "1" ), + GridProperties< int >::SupportedKeywordInfo( "EQLNUM" , 1, "1" ), + GridProperties< int >::SupportedKeywordInfo( "ENDNUM" , 1, "1" ), + GridProperties< int >::SupportedKeywordInfo( "FLUXNUM", 1, "1" ), + GridProperties< int >::SupportedKeywordInfo( "MULTNUM", 1, "1" ), + GridProperties< int >::SupportedKeywordInfo( "FIPNUM" , 1, "1" ), + GridProperties< int >::SupportedKeywordInfo( "MISCNUM", 1, "1" ) + }; + } + + static std::vector< GridProperties< double >::SupportedKeywordInfo > + makeSupportedDoubleKeywords(const TableManager* tableManager, + const EclipseGrid* eclipseGrid, + GridProperties* intGridProperties) + { + GridPropertyInitFunction< double > SGLLookup ( &SGLEndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > ISGLLookup ( &ISGLEndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > SWLLookup ( &SWLEndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > ISWLLookup ( &ISWLEndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > SGULookup ( &SGUEndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > ISGULookup ( &ISGUEndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > SWULookup ( &SWUEndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > ISWULookup ( &ISWUEndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > SGCRLookup ( &SGCREndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > ISGCRLookup ( &ISGCREndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > SOWCRLookup ( &SOWCREndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > ISOWCRLookup ( &ISOWCREndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > SOGCRLookup ( &SOGCREndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > ISOGCRLookup ( &ISOGCREndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > SWCRLookup ( &SWCREndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > ISWCRLookup ( &ISWCREndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + + GridPropertyInitFunction< double > PCWLookup ( &PCWEndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > IPCWLookup ( &IPCWEndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > PCGLookup ( &PCGEndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > IPCGLookup ( &IPCGEndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > KRWLookup ( &KRWEndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > IKRWLookup ( &IKRWEndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > KRWRLookup ( &KRWREndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > IKRWRLookup ( &IKRWREndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > KROLookup ( &KROEndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > IKROLookup ( &IKROEndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > KRORWLookup ( &KRORWEndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > IKRORWLookup ( &IKRORWEndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > KRORGLookup ( &KRORGEndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > IKRORGLookup ( &IKRORGEndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > KRGLookup ( &KRGEndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > IKRGLookup ( &IKRGEndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > KRGRLookup ( &KRGREndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + GridPropertyInitFunction< double > IKRGRLookup ( &IKRGREndpoint, tableManager, eclipseGrid, intGridProperties, nullptr); + + GridPropertyInitFunction< double > tempLookup ( &temperature_lookup, + tableManager, eclipseGrid, intGridProperties, nullptr ); + + GridPropertyPostFunction< double > distributeTopLayer( &GridPropertyPostProcessor::distTopLayer, + tableManager, eclipseGrid, intGridProperties, nullptr ); + + std::vector< GridProperties< double >::SupportedKeywordInfo > supportedDoubleKeywords; + + // keywords to specify the scaled connate gas saturations. + for( const auto& kw : { "SGL", "SGLX", "SGLX-", "SGLY", "SGLY-", "SGLZ", "SGLZ-" } ) + supportedDoubleKeywords.emplace_back( kw, SGLLookup, "1" ); + for( const auto& kw : { "ISGL", "ISGLX", "ISGLX-", "ISGLY", "ISGLY-", "ISGLZ", "ISGLZ-" } ) + supportedDoubleKeywords.emplace_back( kw, ISGLLookup, "1" ); + + // keywords to specify the connate water saturation. + for( const auto& kw : { "SWL", "SWLX", "SWLX-", "SWLY", "SWLY-", "SWLZ", "SWLZ-" } ) + supportedDoubleKeywords.emplace_back( kw, SWLLookup, "1" ); + for( const auto& kw : { "ISWL", "ISWLX", "ISWLX-", "ISWLY", "ISWLY-", "ISWLZ", "ISWLZ-" } ) + supportedDoubleKeywords.emplace_back( kw, ISWLLookup, "1" ); + + // keywords to specify the maximum gas saturation. + for( const auto& kw : { "SGU", "SGUX", "SGUX-", "SGUY", "SGUY-", "SGUZ", "SGUZ-" } ) + supportedDoubleKeywords.emplace_back( kw, SGULookup, "1" ); + for( const auto& kw : { "ISGU", "ISGUX", "ISGUX-", "ISGUY", "ISGUY-", "ISGUZ", "ISGUZ-" } ) + supportedDoubleKeywords.emplace_back( kw, ISGULookup, "1" ); + + // keywords to specify the maximum water saturation. + for( const auto& kw : { "SWU", "SWUX", "SWUX-", "SWUY", "SWUY-", "SWUZ", "SWUZ-" } ) + supportedDoubleKeywords.emplace_back( kw, SWULookup, "1" ); + for( const auto& kw : { "ISWU", "ISWUX", "ISWUX-", "ISWUY", "ISWUY-", "ISWUZ", "ISWUZ-" } ) + supportedDoubleKeywords.emplace_back( kw, ISWULookup, "1" ); + + // keywords to specify the scaled critical gas saturation. + for( const auto& kw : { "SGCR", "SGCRX", "SGCRX-", "SGCRY", "SGCRY-", "SGCRZ", "SGCRZ-" } ) + supportedDoubleKeywords.emplace_back( kw, SGCRLookup, "1" ); + for( const auto& kw : { "ISGCR", "ISGCRX", "ISGCRX-", "ISGCRY", "ISGCRY-", "ISGCRZ", "ISGCRZ-" } ) + supportedDoubleKeywords.emplace_back( kw, ISGCRLookup, "1" ); + + // keywords to specify the scaled critical oil-in-water saturation. + for( const auto& kw : { "SOWCR", "SOWCRX", "SOWCRX-", "SOWCRY", "SOWCRY-", "SOWCRZ", "SOWCRZ-" } ) + supportedDoubleKeywords.emplace_back( kw, SOWCRLookup, "1" ); + for( const auto& kw : { "ISOWCR", "ISOWCRX", "ISOWCRX-", "ISOWCRY", "ISOWCRY-", "ISOWCRZ", "ISOWCRZ-" } ) + supportedDoubleKeywords.emplace_back( kw, ISOWCRLookup, "1" ); + + // keywords to specify the scaled critical oil-in-gas saturation. + for( const auto& kw : { "SOGCR", "SOGCRX", "SOGCRX-", "SOGCRY", "SOGCRY-", "SOGCRZ", "SOGCRZ-" } ) + supportedDoubleKeywords.emplace_back( kw, SOGCRLookup, "1" ); + for( const auto& kw : { "ISOGCR", "ISOGCRX", "ISOGCRX-", "ISOGCRY", "ISOGCRY-", "ISOGCRZ", "ISOGCRZ-" } ) + supportedDoubleKeywords.emplace_back( kw, ISOGCRLookup, "1" ); + + // keywords to specify the scaled critical water saturation. + for( const auto& kw : { "SWCR", "SWCRX", "SWCRX-", "SWCRY", "SWCRY-", "SWCRZ", "SWCRZ-" } ) + supportedDoubleKeywords.emplace_back( kw, SWCRLookup, "1" ); + for( const auto& kw : { "ISWCR", "ISWCRX", "ISWCRX-", "ISWCRY", "ISWCRY-", "ISWCRZ", "ISWCRZ-" } ) + supportedDoubleKeywords.emplace_back( kw, ISWCRLookup, "1" ); + + // keywords to specify the scaled oil-water capillary pressure + for( const auto& kw : { "PCW", "PCWX", "PCWX-", "PCWY", "PCWY-", "PCWZ", "PCWZ-" } ) + supportedDoubleKeywords.emplace_back( kw, PCWLookup, "1" ); + for( const auto& kw : { "IPCW", "IPCWX", "IPCWX-", "IPCWY", "IPCWY-", "IPCWZ", "IPCWZ-" } ) + supportedDoubleKeywords.emplace_back( kw, IPCWLookup, "1" ); + + // keywords to specify the scaled gas-oil capillary pressure + for( const auto& kw : { "PCG", "PCGX", "PCGX-", "PCGY", "PCGY-", "PCGZ", "PCGZ-" } ) + supportedDoubleKeywords.emplace_back( kw, PCGLookup, "1" ); + for( const auto& kw : { "IPCG", "IPCGX", "IPCGX-", "IPCGY", "IPCGY-", "IPCGZ", "IPCGZ-" } ) + supportedDoubleKeywords.emplace_back( kw, IPCGLookup, "1" ); + + // keywords to specify the scaled water relative permeability + for( const auto& kw : { "KRW", "KRWX", "KRWX-", "KRWY", "KRWY-", "KRWZ", "KRWZ-" } ) + supportedDoubleKeywords.emplace_back( kw, KRWLookup, "1" ); + for( const auto& kw : { "IKRW", "IKRWX", "IKRWX-", "IKRWY", "IKRWY-", "IKRWZ", "IKRWZ-" } ) + supportedDoubleKeywords.emplace_back( kw, IKRWLookup, "1" ); + + // keywords to specify the scaled water relative permeability at the critical + // saturation + for( const auto& kw : { "KRWR" , "KRWRX" , "KRWRX-" , "KRWRY" , "KRWRY-" , "KRWRZ" , "KRWRZ-" } ) + supportedDoubleKeywords.emplace_back( kw, KRWRLookup, "1" ); + for( const auto& kw : { "IKRWR" , "IKRWRX" , "IKRWRX-" , "IKRWRY" , "IKRWRY-" , "IKRWRZ" , "IKRWRZ-" } ) + supportedDoubleKeywords.emplace_back( kw, IKRWRLookup, "1" ); + + // keywords to specify the scaled oil relative permeability + for( const auto& kw : { "KRO", "KROX", "KROX-", "KROY", "KROY-", "KROZ", "KROZ-" } ) + supportedDoubleKeywords.emplace_back( kw, KROLookup, "1" ); + for( const auto& kw : { "IKRO", "IKROX", "IKROX-", "IKROY", "IKROY-", "IKROZ", "IKROZ-" } ) + supportedDoubleKeywords.emplace_back( kw, IKROLookup, "1" ); + + // keywords to specify the scaled water relative permeability at the critical + // water saturation + for( const auto& kw : { "KRORW", "KRORWX", "KRORWX-", "KRORWY", "KRORWY-", "KRORWZ", "KRORWZ-" } ) + supportedDoubleKeywords.emplace_back( kw, KRORWLookup, "1" ); + for( const auto& kw : { "IKRORW", "IKRORWX", "IKRORWX-", "IKRORWY", "IKRORWY-", "IKRORWZ", "IKRORWZ-" } ) + supportedDoubleKeywords.emplace_back( kw, IKRORWLookup, "1" ); + + // keywords to specify the scaled water relative permeability at the critical + // water saturation + for( const auto& kw : { "KRORG", "KRORGX", "KRORGX-", "KRORGY", "KRORGY-", "KRORGZ", "KRORGZ-" } ) + supportedDoubleKeywords.emplace_back( kw, KRORGLookup, "1" ); + for( const auto& kw : { "IKRORG", "IKRORGX", "IKRORGX-", "IKRORGY", "IKRORGY-", "IKRORGZ", "IKRORGZ-" } ) + supportedDoubleKeywords.emplace_back( kw, IKRORGLookup, "1" ); + + // keywords to specify the scaled gas relative permeability + for( const auto& kw : { "KRG", "KRGX", "KRGX-", "KRGY", "KRGY-", "KRGZ", "KRGZ-" } ) + supportedDoubleKeywords.emplace_back( kw, KRGLookup, "1" ); + for( const auto& kw : { "IKRG", "IKRGX", "IKRGX-", "IKRGY", "IKRGY-", "IKRGZ", "IKRGZ-" } ) + supportedDoubleKeywords.emplace_back( kw, IKRGLookup, "1" ); + + // keywords to specify the scaled gas relative permeability + for( const auto& kw : { "KRGR", "KRGRX", "KRGRX-", "KRGRY", "KRGRY-", "KRGRZ", "KRGRZ-" } ) + supportedDoubleKeywords.emplace_back( kw, KRGRLookup, "1" ); + for( const auto& kw : { "IKRGR", "IKRGRX", "IKRGRX-", "IKRGRY", "IKRGRY-", "IKRGRZ", "IKRGRZ-" } ) + supportedDoubleKeywords.emplace_back( kw, IKRGRLookup, "1" ); + + + + // cell temperature (E300 only, but makes a lot of sense for E100, too) + supportedDoubleKeywords.emplace_back( "TEMPI", tempLookup, "Temperature" ); + + const double nan = std::numeric_limits::quiet_NaN(); + // porosity + supportedDoubleKeywords.emplace_back( "PORO", nan, distributeTopLayer, "1" ); + + // pore volume multipliers + supportedDoubleKeywords.emplace_back( "MULTPV", 1.0, "1" ); + + // the permeability keywords + for( const auto& kw : { "PERMX", "PERMY", "PERMZ" } ) + supportedDoubleKeywords.emplace_back( kw, nan, distributeTopLayer, "Permeability" ); + + /* E300 only */ + for( const auto& kw : { "PERMXY", "PERMYZ", "PERMZX" } ) + supportedDoubleKeywords.emplace_back( kw, nan, distributeTopLayer, "Permeability" ); + + /* the transmissibility keywords for neighboring connections. note that + * these keywords don't seem to require a post-processor + */ + for( const auto& kw : { "TRANX", "TRANY", "TRANZ" } ) + supportedDoubleKeywords.emplace_back( kw, nan, "Transmissibility" ); + + /* gross-to-net thickness (acts as a multiplier for PORO and the + * permeabilities in the X-Y plane as well as for the well rates.) + */ + supportedDoubleKeywords.emplace_back( "NTG", 1.0, "1" ); + + // transmissibility multipliers + for( const auto& kw : { "MULTX", "MULTY", "MULTZ", "MULTX-", "MULTY-", "MULTZ-" } ) + supportedDoubleKeywords.emplace_back( kw, 1.0, "1" ); + + // initialisation + supportedDoubleKeywords.emplace_back( "SWATINIT", 0.0, "1"); + supportedDoubleKeywords.emplace_back( "THCONR", 0.0, "1"); + + return supportedDoubleKeywords; + } + + + + + + + EclipseProperties::EclipseProperties( const Deck& deck, + std::shared_ptr tableManager, + const EclipseGrid& eclipseGrid) + : + + m_defaultRegion("FLUXNUM"), + m_deckUnitSystem(deck.getActiveUnitSystem()), + // Note that the variants of grid keywords for radial grids are not + // supported. (and hopefully never will be) + // register the grid properties + m_intGridProperties(eclipseGrid, makeSupportedIntKeywords()), + m_doubleGridProperties(eclipseGrid, + makeSupportedDoubleKeywords(tableManager.get(), &eclipseGrid, &m_intGridProperties)) + { + GridPropertyPostFunction< double > initPORV(&GridPropertyPostProcessor::initPORV, + tableManager.get(), + &eclipseGrid, + &m_intGridProperties, + &m_doubleGridProperties); + // pore volume + m_doubleGridProperties.postAddKeyword( "PORV", + std::numeric_limits::quiet_NaN(), + initPORV, + "Volume" ); + + // actually create the grid property objects. we need to first process + // all integer grid properties before the double ones as these may be + // needed in order to initialize the double properties + processGridProperties(deck, eclipseGrid, /*enabledTypes=*/IntProperties); + processGridProperties(deck, eclipseGrid, /*enabledTypes=*/DoubleProperties); + + } + + bool EclipseProperties::supportsGridProperty(const std::string& keyword, + int enabledTypes) const + { + bool result = false; + if (enabledTypes & IntProperties) + result = result || + m_intGridProperties.supportsKeyword( keyword ); + + if (enabledTypes & DoubleProperties) + result = result || + m_doubleGridProperties.supportsKeyword( keyword ); + return result; + } + + + + bool EclipseProperties::hasDeckIntGridProperty(const std::string& keyword) const { + if (!m_intGridProperties.supportsKeyword( keyword )) + throw std::logic_error("Integer grid property " + keyword + " is unsupported!"); + + return m_intGridProperties.hasKeyword( keyword ); + } + + bool EclipseProperties::hasDeckDoubleGridProperty(const std::string& keyword) const { + if (!m_doubleGridProperties.supportsKeyword( keyword )) + throw std::logic_error("Double grid property " + keyword + " is unsupported!"); + + return m_doubleGridProperties.hasKeyword( keyword ); + } + + GridProperties& EclipseProperties::getIntGridProperties() { + return m_intGridProperties; + } + + /// gets properties doubleGridProperties. This does not run any post processors + GridProperties& EclipseProperties::getDoubleGridProperties() { + return m_doubleGridProperties; + } + + /* + 1. The public methods getIntGridProperty & getDoubleGridProperty will + invoke and run the property post processor (if any is registered); the + post processor will only run one time. + + It is important that post processor is not run prematurely, internal + functions in EclipseState should therefore ask for properties by + invoking the getKeyword() method of the m_intGridProperties / + m_doubleGridProperties() directly and not through these methods. + + 2. Observe that this will autocreate a property if it has not been + explicitly added. + */ + const GridProperty& EclipseProperties::getIntGridProperty( const std::string& keyword ) const { + return m_intGridProperties.getKeyword( keyword ); + } + + /// gets property from doubleGridProperty --- and calls the runPostProcessor + const GridProperty& EclipseProperties::getDoubleGridProperty( const std::string& keyword ) const { + auto& gridProperty = const_cast< EclipseProperties* >( this )->m_doubleGridProperties.getKeyword( keyword ); + gridProperty.runPostProcessor(); + return gridProperty; + } + + const GridProperty& EclipseProperties::getDefaultRegion() const { + return m_intGridProperties.getKeyword( m_defaultRegion ); + } + + void EclipseProperties::setDefaultRegionKeyword(std::string defaultRegion) { + m_defaultRegion = defaultRegion; + } + + std::string EclipseProperties::getDefaultRegionKeyword() const { + return m_defaultRegion; + } + + const GridProperty& EclipseProperties::getRegion( const DeckItem& regionItem ) const { + if (regionItem.defaultApplied(0)) + return getDefaultRegion(); + else { + const std::string regionArray = MULTREGT::RegionNameFromDeckValue( regionItem.get< std::string >(0) ); + return m_intGridProperties.getInitializedKeyword( regionArray ); + } + } + + + // this method is only used from EclipseStateTests, could make private? + /// Due to the post processor which might be applied to the GridProperty + /// objects it is essential that this method use the m_intGridProperties / + /// m_doubleGridProperties fields directly and *NOT* use the public methods + /// getIntGridProperty / getDoubleGridProperty. + void EclipseProperties::loadGridPropertyFromDeckKeyword(const Box& inputBox, + const DeckKeyword& deckKeyword, + int enabledTypes) + { + // FIXME PGDR TODO move logic to GridProperties? + const std::string& keyword = deckKeyword.name(); + if (m_intGridProperties.supportsKeyword( keyword )) { + if (enabledTypes & IntProperties) { + GridProperty& gridProperty = m_intGridProperties.getOrCreateProperty( keyword ); + gridProperty.loadFromDeckKeyword( inputBox , deckKeyword ); + } + } else if (m_doubleGridProperties.supportsKeyword( keyword )) { + if (enabledTypes & DoubleProperties) { + GridProperty& gridProperty = m_doubleGridProperties.getOrCreateProperty( keyword ); + gridProperty.loadFromDeckKeyword( inputBox , deckKeyword ); + } + } else { + std::string msg = Log::fileMessage(deckKeyword.getFileName(), + deckKeyword.getLineNumber(), + "Tried to load unsupported grid property from keyword: " + + deckKeyword.name()); + OpmLog::addMessage(Log::MessageType::Error , msg); + } + } + + + static bool isInt(double value) { + return fabs(nearbyint(value) - value) < 1e-6; + } + + + void EclipseProperties::processGridProperties( const Deck& deck, + const EclipseGrid& eclipseGrid, + int enabledTypes) { + + if (Section::hasGRID(deck)) { + scanSection(GRIDSection(deck), eclipseGrid, enabledTypes); + } + + if (Section::hasEDIT(deck)) { + scanSection(EDITSection(deck), eclipseGrid, enabledTypes); + } + + if (Section::hasPROPS(deck)) { + scanSection(PROPSSection(deck), eclipseGrid, enabledTypes); + } + + if (Section::hasREGIONS(deck)) { + scanSection(REGIONSSection(deck), eclipseGrid, enabledTypes); + } + + if (Section::hasSOLUTION(deck)) { + scanSection(SOLUTIONSection(deck), eclipseGrid, enabledTypes); + } + } + + + + // private method + double EclipseProperties::getSIScaling(const std::string &dimensionString) const + { + return m_deckUnitSystem.getDimension(dimensionString)->getSIScaling(); + } + + void EclipseProperties::scanSection(const Section& section, + const EclipseGrid& eclipseGrid, + int enabledTypes) { + BoxManager boxManager(eclipseGrid.getNX(), + eclipseGrid.getNY(), + eclipseGrid.getNZ()); + + for( const auto& deckKeyword : section ) { + + if (supportsGridProperty(deckKeyword.name(), enabledTypes) ) + loadGridPropertyFromDeckKeyword( *boxManager.getActiveBox(), + deckKeyword, + enabledTypes); + else { + if (deckKeyword.name() == "ADD") + handleADDKeyword(deckKeyword, boxManager, enabledTypes); + + if (deckKeyword.name() == "BOX") + handleBOXKeyword(deckKeyword, boxManager); + + if (deckKeyword.name() == "COPY") + handleCOPYKeyword(deckKeyword, boxManager, enabledTypes); + + if (deckKeyword.name() == "EQUALS") + handleEQUALSKeyword(deckKeyword, boxManager, enabledTypes); + + if (deckKeyword.name() == "MULTIPLY") + handleMULTIPLYKeyword(deckKeyword, boxManager, enabledTypes); + + if (deckKeyword.name() == "ENDBOX") + handleENDBOXKeyword(boxManager); + + if (deckKeyword.name() == "EQUALREG") + handleEQUALREGKeyword(deckKeyword, enabledTypes); + + if (deckKeyword.name() == "ADDREG") + handleADDREGKeyword(deckKeyword, enabledTypes); + + if (deckKeyword.name() == "MULTIREG") + handleMULTIREGKeyword(deckKeyword, enabledTypes); + + if (deckKeyword.name() == "COPYREG") + handleCOPYREGKeyword(deckKeyword, enabledTypes); + + boxManager.endKeyword(); + } + } + boxManager.endSection(); + } + + + void EclipseProperties::handleBOXKeyword( const DeckKeyword& deckKeyword, BoxManager& boxManager) { + const auto& record = deckKeyword.getRecord(0); + int I1 = record.getItem("I1").get< int >(0) - 1; + int I2 = record.getItem("I2").get< int >(0) - 1; + int J1 = record.getItem("J1").get< int >(0) - 1; + int J2 = record.getItem("J2").get< int >(0) - 1; + int K1 = record.getItem("K1").get< int >(0) - 1; + int K2 = record.getItem("K2").get< int >(0) - 1; + + boxManager.setInputBox( I1 , I2 , J1 , J2 , K1 , K2 ); + } + + + void EclipseProperties::handleENDBOXKeyword(BoxManager& boxManager) { + boxManager.endInputBox(); + } + + + void EclipseProperties::handleEQUALREGKeyword( const DeckKeyword& deckKeyword, + int enabledTypes) + { + for( const auto& record : deckKeyword ) { + const std::string& targetArray = record.getItem("ARRAY").get< std::string >(0); + + if (!supportsGridProperty( targetArray , IntProperties + DoubleProperties)) + throw std::invalid_argument("Fatal error processing EQUALREG keyword - invalid/undefined keyword: " + targetArray); + + double doubleValue = record.getItem("VALUE").template get(0); + int regionValue = record.getItem("REGION_NUMBER").template get(0); + auto& regionProperty = getRegion( record.getItem("REGION_NAME") ); + std::vector mask; + + regionProperty.initMask( regionValue , mask); + + if (m_intGridProperties.supportsKeyword( targetArray )) { + if (enabledTypes & IntProperties) { + if (isInt( doubleValue )) { + auto& targetProperty = m_intGridProperties.getOrCreateProperty( targetArray ); + int intValue = static_cast( doubleValue + 0.5 ); + targetProperty.maskedSet( intValue , mask); + } else + throw std::invalid_argument("Fatal error processing EQUALREG keyword - expected integer value for: " + targetArray); + } + } + else if (m_doubleGridProperties.supportsKeyword( targetArray )) { + if (enabledTypes & DoubleProperties) { + auto& targetProperty = m_doubleGridProperties.getOrCreateProperty( targetArray ); + + const std::string& dimensionString = targetProperty.getDimensionString(); + double SIValue = doubleValue * getSIScaling( dimensionString ); + + targetProperty.maskedSet( SIValue , mask); + } + } + else { + throw std::invalid_argument("Fatal error processing EQUALREG keyword - invalid/undefined keyword: " + targetArray); + } + } + } + + + void EclipseProperties::handleADDREGKeyword( const DeckKeyword& deckKeyword, int enabledTypes) { + for( const auto& record : deckKeyword ) { + const std::string& targetArray = record.getItem("ARRAY").get< std::string >(0); + + if (!supportsGridProperty( targetArray , IntProperties + DoubleProperties)) + throw std::invalid_argument("Fatal error processing ADDREG keyword - invalid/undefined keyword: " + targetArray); + + if (supportsGridProperty( targetArray , enabledTypes)) { + double doubleValue = record.getItem("SHIFT").get< double >(0); + int regionValue = record.getItem("REGION_NUMBER").get< int >(0); + auto& regionProperty = getRegion( record.getItem("REGION_NAME") ); + std::vector mask; + + regionProperty.initMask( regionValue , mask); + + if (m_intGridProperties.hasKeyword( targetArray )) { + if (enabledTypes & IntProperties) { + if (isInt( doubleValue )) { + GridProperty& targetProperty = m_intGridProperties.getKeyword(targetArray); + int intValue = static_cast( doubleValue + 0.5 ); + targetProperty.maskedAdd( intValue , mask); + } else + throw std::invalid_argument("Fatal error processing ADDREG keyword - expected integer value for: " + targetArray); + } + } + else if (m_doubleGridProperties.hasKeyword( targetArray )) { + if (enabledTypes & DoubleProperties) { + GridProperty& targetProperty = m_doubleGridProperties.getKeyword(targetArray); + + const std::string& dimensionString = targetProperty.getDimensionString(); + double SIValue = doubleValue * getSIScaling( dimensionString ); + + targetProperty.maskedAdd( SIValue , mask); + } + } + else { + throw std::invalid_argument("Fatal error processing ADDREG keyword - invalid/undefined keyword: " + targetArray); + } + } + } + } + + + + void EclipseProperties::handleMULTIREGKeyword( const DeckKeyword& deckKeyword, int enabledTypes) { + for( const auto& record : deckKeyword ) { + const std::string& targetArray = record.getItem("ARRAY").get< std::string >(0); + + if (!supportsGridProperty( targetArray , IntProperties + DoubleProperties)) + throw std::invalid_argument("Fatal error processing MULTIREG keyword - invalid/undefined keyword: " + targetArray); + + if (supportsGridProperty( targetArray , enabledTypes)) { + double doubleValue = record.getItem("FACTOR").get< double >(0); + int regionValue = record.getItem("REGION_NUMBER").get< int >(0); + auto& regionProperty = getRegion( record.getItem("REGION_NAME") ); + std::vector mask; + + regionProperty.initMask( regionValue , mask); + + if (enabledTypes & IntProperties) { + if (isInt( doubleValue )) { + auto& targetProperty = m_intGridProperties.getOrCreateProperty( targetArray ); + int intValue = static_cast( doubleValue + 0.5 ); + targetProperty.maskedMultiply( intValue , mask); + } else + throw std::invalid_argument( + "Fatal error processing MULTIREG keyword - expected" + " integer value for: " + targetArray); + } + if (enabledTypes & DoubleProperties) { + auto& targetProperty = m_doubleGridProperties.getOrCreateProperty(targetArray); + targetProperty.maskedMultiply( doubleValue , mask); + } + } + } + } + + + void EclipseProperties::handleCOPYREGKeyword( const DeckKeyword& deckKeyword, int enabledTypes) { + for( const auto& record : deckKeyword ) { + const std::string& srcArray = record.getItem("ARRAY").get< std::string >(0); + const std::string& targetArray = record.getItem("TARGET_ARRAY").get< std::string >(0); + + if (!supportsGridProperty( targetArray , IntProperties + DoubleProperties)) + throw std::invalid_argument("Fatal error processing MULTIREG keyword - invalid/undefined keyword: " + targetArray); + + if (!supportsGridProperty( srcArray , IntProperties + DoubleProperties)) + throw std::invalid_argument("Fatal error processing MULTIREG keyword - invalid/undefined keyword: " + srcArray); + + if (supportsGridProperty( srcArray , enabledTypes)) + { + int regionValue = record.getItem("REGION_NUMBER").get< int >(0); + auto& regionProperty = getRegion( record.getItem("REGION_NAME") ); + std::vector mask; + + regionProperty.initMask( regionValue , mask ); + + if (m_intGridProperties.hasKeyword( srcArray )) { + auto& srcProperty = m_intGridProperties.getInitializedKeyword( srcArray ); + if (supportsGridProperty( targetArray , IntProperties)) { + GridProperty& targetProperty = m_intGridProperties.getOrCreateProperty( targetArray ); + targetProperty.maskedCopy( srcProperty , mask ); + } else + throw std::invalid_argument("Fatal error processing COPYREG keyword."); + } else if (m_doubleGridProperties.hasKeyword( srcArray )) { + const GridProperty& srcProperty = m_doubleGridProperties.getInitializedKeyword( srcArray ); + if (supportsGridProperty( targetArray , DoubleProperties)) { + auto& targetProperty = m_doubleGridProperties.getOrCreateProperty( targetArray ); + targetProperty.maskedCopy( srcProperty , mask ); + } + } + else { + throw std::invalid_argument("Fatal error processing COPYREG keyword - invalid/undefined keyword: " + targetArray); + } + } + } + } + + + + + void EclipseProperties::handleMULTIPLYKeyword( const DeckKeyword& deckKeyword, BoxManager& boxManager, int enabledTypes) { + for( const auto& record : deckKeyword ) { + const std::string& field = record.getItem("field").get< std::string >(0); + double scaleFactor = record.getItem("factor").get< double >(0); + + setKeywordBox(deckKeyword, record, boxManager); + + if (m_intGridProperties.hasKeyword( field )) { + if (enabledTypes & IntProperties) { + int intFactor = static_cast(scaleFactor); + GridProperty& property = m_intGridProperties.getKeyword( field ); + property.scale( intFactor , *boxManager.getActiveBox() ); + } + } else if (m_doubleGridProperties.hasKeyword( field )) { + if (enabledTypes & DoubleProperties) { + GridProperty& property = m_doubleGridProperties.getKeyword( field ); + property.scale( scaleFactor , *boxManager.getActiveBox() ); + } + } else if (!m_intGridProperties.supportsKeyword(field) && + !m_doubleGridProperties.supportsKeyword(field)) + throw std::invalid_argument("Fatal error processing MULTIPLY keyword. Tried to multiply not defined keyword " + field); + } + } + + + /** + The fine print of the manual says the ADD keyword should support + some state dependent semantics regarding endpoint scaling arrays + in the PROPS section. That is not supported. + */ + void EclipseProperties::handleADDKeyword( const DeckKeyword& deckKeyword, BoxManager& boxManager, int enabledTypes) { + for( const auto& record : deckKeyword ) { + const std::string& field = record.getItem("field").get< std::string >(0); + double shiftValue = record.getItem("shift").get< double >(0); + + setKeywordBox(deckKeyword, record, boxManager); + + if (m_intGridProperties.hasKeyword( field )) { + if (enabledTypes & IntProperties) { + int intShift = static_cast(shiftValue); + GridProperty& property = m_intGridProperties.getKeyword( field ); + + property.add( intShift , *boxManager.getActiveBox() ); + } + } else if (m_doubleGridProperties.hasKeyword( field )) { + if (enabledTypes & DoubleProperties) { + GridProperty& property = m_doubleGridProperties.getKeyword( field ); + + double siShiftValue = shiftValue * getSIScaling(property.getDimensionString()); + property.add(siShiftValue , *boxManager.getActiveBox() ); + } + } else if (!m_intGridProperties.supportsKeyword(field) && + !m_doubleGridProperties.supportsKeyword(field)) + throw std::invalid_argument("Fatal error processing ADD keyword. Tried to shift not defined keyword " + field); + } + } + + + void EclipseProperties::handleEQUALSKeyword( const DeckKeyword& deckKeyword, BoxManager& boxManager, int enabledTypes) { + for( const auto& record : deckKeyword ) { + const std::string& field = record.getItem("field").get< std::string >(0); + double value = record.getItem("value").get< double >(0); + + setKeywordBox(deckKeyword, record, boxManager); + + if (m_intGridProperties.supportsKeyword( field )) { + if (enabledTypes & IntProperties) { + int intValue = static_cast(value); + GridProperty& property = m_intGridProperties.getOrCreateProperty( field ); + + property.setScalar( intValue , *boxManager.getActiveBox() ); + } + } else if (m_doubleGridProperties.supportsKeyword( field )) { + + if (enabledTypes & DoubleProperties) { + GridProperty& property = m_doubleGridProperties.getOrCreateProperty( field ); + + double siValue = value * getSIScaling(property.getKeywordInfo().getDimensionString()); + property.setScalar( siValue , *boxManager.getActiveBox() ); + } + } else + throw std::invalid_argument("Fatal error processing EQUALS keyword. Tried to set not defined keyword " + field); + } + } + + + + void EclipseProperties::handleCOPYKeyword( const DeckKeyword& deckKeyword, BoxManager& boxManager, int enabledTypes) { + for( const auto& record : deckKeyword ) { + const std::string& srcField = record.getItem("src").get< std::string >(0); + const std::string& targetField = record.getItem("target").get< std::string >(0); + + setKeywordBox(deckKeyword, record, boxManager); + + if (m_intGridProperties.hasKeyword( srcField )) { + if (enabledTypes & IntProperties) + m_intGridProperties.copyKeyword( srcField , targetField , *boxManager.getActiveBox() ); + } + else if (m_doubleGridProperties.hasKeyword( srcField )) { + if (enabledTypes & DoubleProperties) + m_doubleGridProperties.copyKeyword( srcField , targetField , *boxManager.getActiveBox() ); + } + else + if (!m_intGridProperties.supportsKeyword(srcField) && + !m_doubleGridProperties.supportsKeyword(srcField)) + throw std::invalid_argument("Fatal error processing COPY keyword." + " Tried to copy from not defined keyword " + srcField); + } + } + + // static member function + void EclipseProperties::setKeywordBox( const DeckKeyword& deckKeyword, + const DeckRecord& deckRecord, + BoxManager& boxManager) { + const auto& I1Item = deckRecord.getItem("I1"); + const auto& I2Item = deckRecord.getItem("I2"); + const auto& J1Item = deckRecord.getItem("J1"); + const auto& J2Item = deckRecord.getItem("J2"); + const auto& K1Item = deckRecord.getItem("K1"); + const auto& K2Item = deckRecord.getItem("K2"); + + size_t setCount = 0; + + if (!I1Item.defaultApplied(0)) + setCount++; + + if (!I2Item.defaultApplied(0)) + setCount++; + + if (!J1Item.defaultApplied(0)) + setCount++; + + if (!J2Item.defaultApplied(0)) + setCount++; + + if (!K1Item.defaultApplied(0)) + setCount++; + + if (!K2Item.defaultApplied(0)) + setCount++; + + if (setCount == 6) { + boxManager.setKeywordBox( I1Item.get< int >(0) - 1, + I2Item.get< int >(0) - 1, + J1Item.get< int >(0) - 1, + J2Item.get< int >(0) - 1, + K1Item.get< int >(0) - 1, + K2Item.get< int >(0) - 1); + } else if (setCount != 0) { + std::string msg = "BOX modifiers on keywords must be either " + "specified completely or not at all. Ignoring."; + OpmLog::addMessage(Log::MessageType::Error, + Log::fileMessage(deckKeyword.getFileName(), + deckKeyword.getLineNumber(), + msg)); + } + } +} diff --git a/opm/parser/eclipse/EclipseState/EclipseProperties.hpp b/opm/parser/eclipse/EclipseState/EclipseProperties.hpp new file mode 100644 index 000000000..aa1e388e7 --- /dev/null +++ b/opm/parser/eclipse/EclipseState/EclipseProperties.hpp @@ -0,0 +1,118 @@ +/* + Copyright 2013 Statoil ASA. + + 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 3 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 . +*/ + +#ifndef OPM_ECLIPSE_PROPERTIES_HPP +#define OPM_ECLIPSE_PROPERTIES_HPP + +#include +#include +#include + +#include +#include + + +namespace Opm { + +// template< typename > class GridProperty; +// template< typename > class GridProperties; + + class Box; + class BoxManager; + class Deck; + class DeckItem; + class DeckKeyword; + class DeckRecord; + class EclipseGrid; + class EclipseState; + class InitConfig; + class IOConfig; + class ParseMode; + class Schedule; + class Section; + class TableManager; + class TransMult; + class UnitSystem; + + class EclipseProperties + { + public: + enum EnabledTypes { + IntProperties = 0x01, + DoubleProperties = 0x02, + AllProperties = IntProperties | DoubleProperties + }; + + EclipseProperties( const Deck& deck, + std::shared_ptr tableManager, + const EclipseGrid& eclipseGrid); + + static void setKeywordBox( const DeckKeyword& deckKeyword, const DeckRecord&, BoxManager& boxManager); + + const GridProperty& getRegion( const DeckItem& regionItem ) const; + const GridProperty& getDefaultRegion() const; + std::string getDefaultRegionKeyword() const; + void setDefaultRegionKeyword(std::string defaultRegionKeyword); + + const GridProperty& getIntGridProperty( const std::string& keyword ) const; + const GridProperty & getDoubleGridProperty( const std::string& keyword ) const; + GridProperties& getIntGridProperties(); + GridProperties& getDoubleGridProperties(); + bool hasDeckIntGridProperty(const std::string& keyword) const; + bool hasDeckDoubleGridProperty(const std::string& keyword) const; + bool supportsGridProperty(const std::string& keyword, int enabledTypes=AllProperties) const; + + private: + void processGridProperties( const Deck& deck, + const EclipseGrid& eclipseGrid, + int enabledTypes); + + double getSIScaling(const std::string &dimensionString) const; + + void scanSection(const Section& section, + const EclipseGrid& eclipseGrid, + int enabledTypes); + + void handleADDKeyword( const DeckKeyword& deckKeyword, BoxManager& boxManager, int enabledTypes); + void handleBOXKeyword( const DeckKeyword& deckKeyword, BoxManager& boxManager); + void handleCOPYKeyword( const DeckKeyword& deckKeyword, BoxManager& boxManager, int enabledTypes); + void handleENDBOXKeyword( BoxManager& boxManager); + void handleEQUALSKeyword( const DeckKeyword& deckKeyword, BoxManager& boxManager, int enabledTypes); + void handleMULTIPLYKeyword(const DeckKeyword& deckKeyword, BoxManager& boxManager, int enabledTypes); + + void handleADDREGKeyword( const DeckKeyword& deckKeyword, int enabledTypes); + void handleCOPYREGKeyword( const DeckKeyword& deckKeyword, int enabledTypes); + void handleEQUALREGKeyword(const DeckKeyword& deckKeyword, int enabledTypes); + void handleMULTIREGKeyword(const DeckKeyword& deckKeyword, int enabledTypes); + + void loadGridPropertyFromDeckKeyword(const Box& inputBox, + const DeckKeyword& deckKeyword, + int enabledTypes = AllProperties); + + void initProperties( const Deck& deck, + std::shared_ptr tableManager, + const EclipseGrid& eclipseGrid ); + + std::string m_defaultRegion; + const UnitSystem& m_deckUnitSystem; + GridProperties m_intGridProperties; + GridProperties m_doubleGridProperties; + }; +} + +#endif // OPM_ECLIPSE_PROPERTIES_HPP diff --git a/opm/parser/eclipse/EclipseState/EclipseState.cpp b/opm/parser/eclipse/EclipseState/EclipseState.cpp index 02edcb910..e469f30c4 100644 --- a/opm/parser/eclipse/EclipseState/EclipseState.cpp +++ b/opm/parser/eclipse/EclipseState/EclipseState.cpp @@ -22,6 +22,8 @@ #include #include +#include +#include #include #include #include @@ -47,85 +49,27 @@ namespace Opm { - namespace GridPropertyPostProcessor { - - void distTopLayer( std::vector& values, const Deck&, const EclipseState& m_eclipseState ) { - EclipseGridConstPtr grid = m_eclipseState.getEclipseGrid(); - size_t layerSize = grid->getNX() * grid->getNY(); - size_t gridSize = grid->getCartesianSize(); - - for( size_t globalIndex = layerSize; globalIndex < gridSize; globalIndex++ ) { - if( std::isnan( values[ globalIndex ] ) ) - values[globalIndex] = values[globalIndex - layerSize]; - } - } - - void initPORV( std::vector& values, const Deck&, const EclipseState& m_eclipseState ) { - EclipseGridConstPtr grid = m_eclipseState.getEclipseGrid(); - /* - Observe that this apply method does not alter the - values input vector, instead it fetches the PORV - property one more time, and then manipulates that. - */ - auto porv = m_eclipseState.getDoubleGridProperty("PORV"); - if (porv->containsNaN()) { - auto poro = m_eclipseState.getDoubleGridProperty("PORO"); - auto ntg = m_eclipseState.getDoubleGridProperty("NTG"); - if (poro->containsNaN()) - throw std::logic_error("Do not have information for the PORV keyword - some defaulted values in PORO"); - else { - const auto& poroData = poro->getData(); - for (size_t globalIndex = 0; globalIndex < porv->getCartesianSize(); globalIndex++) { - if (std::isnan(values[globalIndex])) { - double cell_poro = poroData[globalIndex]; - double cell_ntg = ntg->iget(globalIndex); - double cell_volume = grid->getCellVolume(globalIndex); - values[globalIndex] = cell_poro * cell_volume * cell_ntg; - } - } - } - } - - if (m_eclipseState.hasDeckDoubleGridProperty("MULTPV")) { - auto multpvData = m_eclipseState.getDoubleGridProperty("MULTPV")->getData(); - for (size_t globalIndex = 0; globalIndex < porv->getCartesianSize(); globalIndex++) { - values[globalIndex] *= multpvData[globalIndex]; - } - } - } - } - - - static bool isInt(double value) { - double diff = fabs(nearbyint(value) - value); - - if (diff < 1e-6) - return true; - else - return false; - } - - - EclipseState::EclipseState(DeckConstPtr deck , const ParseContext& parseContext) - : m_deckUnitSystem( deck->getActiveUnitSystem() ), - m_defaultRegion("FLUXNUM"), - m_parseContext( parseContext ) + EclipseState::EclipseState(std::shared_ptr deck, const ParseContext& parseContext) : + m_deckUnitSystem( deck->getActiveUnitSystem() ), + m_parseContext( parseContext), + m_tables( std::make_shared( *deck )), + m_eclipseGrid( new EclipseGrid(deck)), + m_eclipseProperties( *deck, m_tables, *m_eclipseGrid) { - initPhases(deck); - initTables(deck); - initEclipseGrid(deck); - initGridopts(deck); initIOConfig(deck); - initSchedule(deck); + + m_schedule = ScheduleConstPtr( new Schedule(m_parseContext , getEclipseGrid() , deck, m_ioConfig) ); initIOConfigPostSchedule(deck); initTitle(deck); - initProperties(deck); - initInitConfig(deck); - initSimulationConfig(deck); + + m_initConfig = std::make_shared(deck); + m_simulationConfig = std::make_shared(m_parseContext, deck, + m_eclipseProperties.getIntGridProperties() ); + initTransMult(); initFaults(deck); initMULTREGT(deck); - initNNC(deck); + m_nnc = std::make_shared( deck, getEclipseGrid()); } const UnitSystem& EclipseState::getDeckUnitSystem() const { @@ -134,13 +78,17 @@ namespace Opm { EclipseGridConstPtr EclipseState::getEclipseGrid() const { - return m_eclipseGrid; + return m_eclipseProperties->getEclipseGrid(); } + // is only used in EclipseWriter EclipseGridPtr EclipseState::getEclipseGridCopy() const { - return std::make_shared( m_eclipseGrid->c_ptr() ); + return m_eclipseProperties->getEclipseGridCopy(); } + const Eclipse3DProperties& EclipseState::getEclipseProperties() const { + return m_eclipseProperties; + } const MessageContainer& EclipseState::getMessageContainer() const { return m_messageContainer; @@ -156,14 +104,12 @@ namespace Opm { return m_tables; } - const ParseContext& EclipseState::getParseContext() const { return m_parseContext; } - ScheduleConstPtr EclipseState::getSchedule() const { - return schedule; + return m_schedule; } IOConfigConstPtr EclipseState::getIOConfigConst() const { @@ -202,12 +148,6 @@ namespace Opm { return m_title; } - - - void EclipseState::initTables(DeckConstPtr deck) { - m_tables = std::make_shared( *deck ); - } - void EclipseState::initIOConfig(DeckConstPtr deck) { m_ioConfig = std::make_shared(); if (Section::hasGRID(*deck)) { @@ -220,58 +160,39 @@ namespace Opm { } } - // Hmmm - would have thought this should iterate through the SCHEDULE section as well? void EclipseState::initIOConfigPostSchedule(DeckConstPtr deck) { if (Section::hasSOLUTION(*deck)) { std::shared_ptr solutionSection = std::make_shared(*deck); - m_ioConfig->handleSolutionSection(schedule->getTimeMap(), solutionSection); + m_ioConfig->handleSolutionSection(m_schedule->getTimeMap(), solutionSection); } - m_ioConfig->initFirstOutput( *this->schedule ); - } - - void EclipseState::initInitConfig(DeckConstPtr deck){ - m_initConfig = std::make_shared(deck); - } - - void EclipseState::initSimulationConfig(DeckConstPtr deck) { - m_simulationConfig = std::make_shared(m_parseContext , deck , m_intGridProperties); - } - - - void EclipseState::initSchedule(DeckConstPtr deck) { - EclipseGridConstPtr grid = getEclipseGrid(); - schedule = ScheduleConstPtr( new Schedule(m_parseContext , grid , deck, m_ioConfig) ); - } - - void EclipseState::initNNC(DeckConstPtr deck) { - EclipseGridConstPtr grid = getEclipseGrid(); - m_nnc = std::make_shared( deck, grid); + m_ioConfig->initFirstOutput( *m_schedule ); } void EclipseState::initTransMult() { - EclipseGridConstPtr grid = getEclipseGrid(); + EclipseGridConstPtr grid = m_eclipseProperties->getEclipseGrid(); m_transMult = std::make_shared( grid->getNX() , grid->getNY() , grid->getNZ()); + // by obtaining doubleGridProperties we're circumventing the runpostprocessor which is called on state.getkeyword + auto& doubleGp = m_eclipseProperties.getDoubleGridProperties(); + if (m_eclipseProperties.hasDeckDoubleGridProperty("MULTX")) + m_transMult->applyMULT(doubleGp.getKeyword("MULTX"), FaceDir::XPlus); + if (m_eclipseProperties.hasDeckDoubleGridProperty("MULTX-")) + m_transMult->applyMULT(doubleGp.getKeyword("MULTX-"), FaceDir::XMinus); - if (hasDeckDoubleGridProperty("MULTX")) - m_transMult->applyMULT(m_doubleGridProperties->getKeyword("MULTX"), FaceDir::XPlus); - if (hasDeckDoubleGridProperty("MULTX-")) - m_transMult->applyMULT(m_doubleGridProperties->getKeyword("MULTX-"), FaceDir::XMinus); + if (m_eclipseProperties.hasDeckDoubleGridProperty("MULTY")) + m_transMult->applyMULT(doubleGp.getKeyword("MULTY"), FaceDir::YPlus); + if (m_eclipseProperties.hasDeckDoubleGridProperty("MULTY-")) + m_transMult->applyMULT(doubleGp.getKeyword("MULTY-"), FaceDir::YMinus); - if (hasDeckDoubleGridProperty("MULTY")) - m_transMult->applyMULT(m_doubleGridProperties->getKeyword("MULTY"), FaceDir::YPlus); - if (hasDeckDoubleGridProperty("MULTY-")) - m_transMult->applyMULT(m_doubleGridProperties->getKeyword("MULTY-"), FaceDir::YMinus); - - if (hasDeckDoubleGridProperty("MULTZ")) - m_transMult->applyMULT(m_doubleGridProperties->getKeyword("MULTZ"), FaceDir::ZPlus); - if (hasDeckDoubleGridProperty("MULTZ-")) - m_transMult->applyMULT(m_doubleGridProperties->getKeyword("MULTZ-"), FaceDir::ZMinus); + if (m_eclipseProperties.hasDeckDoubleGridProperty("MULTZ")) + m_transMult->applyMULT(doubleGp.getKeyword("MULTZ"), FaceDir::ZPlus); + if (m_eclipseProperties.hasDeckDoubleGridProperty("MULTZ-")) + m_transMult->applyMULT(doubleGp.getKeyword("MULTZ-"), FaceDir::ZMinus); } void EclipseState::initFaults(DeckConstPtr deck) { - EclipseGridConstPtr grid = getEclipseGrid(); + EclipseGridConstPtr grid = m_eclipseProperties->getEclipseGrid(); std::shared_ptr gridSection = std::make_shared( *deck ); m_faults = std::make_shared(gridSection , grid); @@ -304,93 +225,22 @@ namespace Opm { void EclipseState::initMULTREGT(DeckConstPtr deck) { - EclipseGridConstPtr grid = getEclipseGrid(); + EclipseGridConstPtr grid = m_eclipseProperties->getEclipseGrid(); std::vector< const DeckKeyword* > multregtKeywords; if (deck->hasKeyword("MULTREGT")) multregtKeywords = deck->getKeywordList("MULTREGT"); - std::shared_ptr scanner = std::make_shared(m_intGridProperties, multregtKeywords , m_defaultRegion); + std::shared_ptr scanner = + std::make_shared( + m_eclipseProperties.getIntGridProperties(), + multregtKeywords , + m_eclipseProperties.getDefaultRegionKeyword()); + m_transMult->setMultregtScanner( scanner ); } - - - void EclipseState::initEclipseGrid(DeckConstPtr deck) { - m_eclipseGrid = EclipseGridConstPtr( new EclipseGrid(deck)); - } - - - void EclipseState::initGridopts(DeckConstPtr deck) { - if (deck->hasKeyword("GRIDOPTS")) { - /* - The EQUALREG, MULTREG, COPYREG, ... keywords are used to - manipulate vectors based on region values; for instance - the statement - - EQUALREG - PORO 0.25 3 / -- Region array not specified - PERMX 100 3 F / - / - - will set the PORO field to 0.25 for all cells in region - 3 and the PERMX value to 100 mD for the same cells. The - fourth optional argument to the EQUALREG keyword is used - to indicate which REGION array should be used for the - selection. - - If the REGION array is not indicated (as in the PORO - case) above, the default region to use in the xxxREG - keywords depends on the GRIDOPTS keyword: - - 1. If GRIDOPTS is present, and the NRMULT item is - greater than zero, the xxxREG keywords will default - to use the MULTNUM region. - - 2. If the GRIDOPTS keyword is not present - or the - NRMULT item equals zero, the xxxREG keywords will - default to use the FLUXNUM keyword. - - This quite weird behaviour comes from reading the - GRIDOPTS and MULTNUM documentation, and practical - experience with ECLIPSE simulations. Ufortunately the - documentation of the xxxREG keywords does not confirm - this. - */ - - auto gridOpts = deck->getKeyword("GRIDOPTS"); - const auto& record = gridOpts.getRecord(0); - const auto& nrmult_item = record.getItem("NRMULT"); - - if (nrmult_item.get< int >(0) > 0) - m_defaultRegion = "MULTNUM"; - } - } - - - void EclipseState::initPhases(DeckConstPtr deck) { - if (deck->hasKeyword("OIL")) - phases.insert(Phase::PhaseEnum::OIL); - - if (deck->hasKeyword("GAS")) - phases.insert(Phase::PhaseEnum::GAS); - - if (deck->hasKeyword("WATER")) - phases.insert(Phase::PhaseEnum::WATER); - - if (phases.size() < 3) - OpmLog::addMessage(Log::MessageType::Info , "Only " + std::to_string(static_cast(phases.size())) + " fluid phases are enabled"); - } - - size_t EclipseState::getNumPhases() const{ - return phases.size(); - } - - bool EclipseState::hasPhase(enum Phase::PhaseEnum phase) const { - return (phases.count(phase) == 1); - } - - void EclipseState::initTitle(DeckConstPtr deck){ + void EclipseState::initTitle(DeckConstPtr deck) { if (deck->hasKeyword("TITLE")) { const auto& titleKeyword = deck->getKeyword("TITLE"); const auto& item = titleKeyword.getRecord( 0 ).getItem( 0 ); @@ -399,761 +249,6 @@ namespace Opm { } } - - - - - bool EclipseState::supportsGridProperty(const std::string& keyword, int enabledTypes) const { - bool result = false; - if (enabledTypes & IntProperties) - result = result || m_intGridProperties->supportsKeyword( keyword ); - if (enabledTypes & DoubleProperties) - result = result || m_doubleGridProperties->supportsKeyword( keyword ); - return result; - } - - bool EclipseState::hasDeckIntGridProperty(const std::string& keyword) const { - if (!m_intGridProperties->supportsKeyword( keyword )) - throw std::logic_error("Integer grid property " + keyword + " is unsupported!"); - - return m_intGridProperties->hasKeyword( keyword ); - } - - bool EclipseState::hasDeckDoubleGridProperty(const std::string& keyword) const { - if (!m_doubleGridProperties->supportsKeyword( keyword )) - throw std::logic_error("Double grid property " + keyword + " is unsupported!"); - - return m_doubleGridProperties->hasKeyword( keyword ); - } - - - /* - 1. The public methods getIntGridProperty & getDoubleGridProperty - will invoke and run the property post processor (if any is - registered); the post processor will only run one time. - - It is important that post processor is not run prematurely, - internal functions in EclipseState should therefore ask for - properties by invoking the getKeyword() method of the - m_intGridProperties / m_doubleGridProperties() directly and - not through these methods. - - 2. Observe that this will autocreate a property if it has not - been explicitly added. - */ - - std::shared_ptr > EclipseState::getIntGridProperty( const std::string& keyword ) const { - return m_intGridProperties->getKeyword( keyword ); - } - - std::shared_ptr > EclipseState::getDoubleGridProperty( const std::string& keyword ) const { - auto gridProperty = m_doubleGridProperties->getKeyword( keyword ); - - gridProperty->runPostProcessor(); - - return gridProperty; - } - - std::shared_ptr > EclipseState::getDefaultRegion() const { - return m_intGridProperties->getKeyword( m_defaultRegion ); - } - - std::shared_ptr > EclipseState::getRegion( const DeckItem& regionItem ) const { - if (regionItem.defaultApplied(0)) - return getDefaultRegion(); - else { - const std::string regionArray = MULTREGT::RegionNameFromDeckValue( regionItem.get< std::string >(0) ); - return m_intGridProperties->getInitializedKeyword( regionArray ); - } - } - - - - /* - Due to the post processor which might be applied to the - GridProperty objects it is essential that this method use the - m_intGridProperties / m_doubleGridProperties fields directly - and *NOT* use the public methods get< int >GridProperty / - getDoubleGridProperty. - */ - - void EclipseState::loadGridPropertyFromDeckKeyword(std::shared_ptr inputBox, - const DeckKeyword& deckKeyword, - int enabledTypes) { - const std::string& keyword = deckKeyword.name(); - if (m_intGridProperties->supportsKeyword( keyword )) { - if (enabledTypes & IntProperties) { - auto gridProperty = getOrCreateIntProperty_( keyword ); - gridProperty->loadFromDeckKeyword( inputBox , deckKeyword ); - } - } else if (m_doubleGridProperties->supportsKeyword( keyword )) { - if (enabledTypes & DoubleProperties) { - auto gridProperty = getOrCreateDoubleProperty_( keyword ); - gridProperty->loadFromDeckKeyword( inputBox , deckKeyword ); - } - } else { - std::string msg = Log::fileMessage(deckKeyword.getFileName(), - deckKeyword.getLineNumber(), - "Tried to load unsupported grid property from keyword: " + deckKeyword.name()); - OpmLog::addMessage(Log::MessageType::Error , msg); - } - } - - static std::vector< GridProperties< int >::SupportedKeywordInfo > - makeSupportedIntKeywords() { - return { GridProperties< int >::SupportedKeywordInfo( "SATNUM" , 1, "1" ), - GridProperties< int >::SupportedKeywordInfo( "IMBNUM" , 1, "1" ), - GridProperties< int >::SupportedKeywordInfo( "PVTNUM" , 1, "1" ), - GridProperties< int >::SupportedKeywordInfo( "EQLNUM" , 1, "1" ), - GridProperties< int >::SupportedKeywordInfo( "ENDNUM" , 1, "1" ), - GridProperties< int >::SupportedKeywordInfo( "FLUXNUM" , 1 , "1" ), - GridProperties< int >::SupportedKeywordInfo( "MULTNUM", 1 , "1" ), - GridProperties< int >::SupportedKeywordInfo( "FIPNUM" , 1, "1" ), - GridProperties< int >::SupportedKeywordInfo( "MISCNUM", 1, "1" ) - }; - } - - static std::vector< GridProperties< double >::SupportedKeywordInfo > - makeSupportedDoubleKeywords(const Deck& deck, const EclipseState& es) { - GridPropertyInitFunction< double > SGLLookup ( &SGLEndpoint, deck, es ); - GridPropertyInitFunction< double > ISGLLookup ( &ISGLEndpoint, deck, es ); - GridPropertyInitFunction< double > SWLLookup ( &SWLEndpoint, deck, es ); - GridPropertyInitFunction< double > ISWLLookup ( &ISWLEndpoint, deck, es ); - GridPropertyInitFunction< double > SGULookup ( &SGUEndpoint, deck, es ); - GridPropertyInitFunction< double > ISGULookup ( &ISGUEndpoint, deck, es ); - GridPropertyInitFunction< double > SWULookup ( &SWUEndpoint, deck, es ); - GridPropertyInitFunction< double > ISWULookup ( &ISWUEndpoint, deck, es ); - GridPropertyInitFunction< double > SGCRLookup ( &SGCREndpoint, deck, es ); - GridPropertyInitFunction< double > ISGCRLookup ( &ISGCREndpoint, deck, es ); - GridPropertyInitFunction< double > SOWCRLookup ( &SOWCREndpoint, deck, es ); - GridPropertyInitFunction< double > ISOWCRLookup ( &ISOWCREndpoint, deck, es ); - GridPropertyInitFunction< double > SOGCRLookup ( &SOGCREndpoint, deck, es ); - GridPropertyInitFunction< double > ISOGCRLookup ( &ISOGCREndpoint, deck, es ); - GridPropertyInitFunction< double > SWCRLookup ( &SWCREndpoint, deck, es ); - GridPropertyInitFunction< double > ISWCRLookup ( &ISWCREndpoint, deck, es ); - - GridPropertyInitFunction< double > PCWLookup ( &PCWEndpoint, deck, es ); - GridPropertyInitFunction< double > IPCWLookup ( &IPCWEndpoint, deck, es ); - GridPropertyInitFunction< double > PCGLookup ( &PCGEndpoint, deck, es ); - GridPropertyInitFunction< double > IPCGLookup ( &IPCGEndpoint, deck, es ); - GridPropertyInitFunction< double > KRWLookup ( &KRWEndpoint, deck, es ); - GridPropertyInitFunction< double > IKRWLookup ( &IKRWEndpoint, deck, es ); - GridPropertyInitFunction< double > KRWRLookup ( &KRWREndpoint, deck, es ); - GridPropertyInitFunction< double > IKRWRLookup ( &IKRWREndpoint, deck, es ); - GridPropertyInitFunction< double > KROLookup ( &KROEndpoint, deck, es ); - GridPropertyInitFunction< double > IKROLookup ( &IKROEndpoint, deck, es ); - GridPropertyInitFunction< double > KRORWLookup ( &KRORWEndpoint, deck, es ); - GridPropertyInitFunction< double > IKRORWLookup ( &IKRORWEndpoint, deck, es ); - GridPropertyInitFunction< double > KRORGLookup ( &KRORGEndpoint, deck, es ); - GridPropertyInitFunction< double > IKRORGLookup ( &IKRORGEndpoint, deck, es ); - GridPropertyInitFunction< double > KRGLookup ( &KRGEndpoint, deck, es ); - GridPropertyInitFunction< double > IKRGLookup ( &IKRGEndpoint, deck, es ); - GridPropertyInitFunction< double > KRGRLookup ( &KRGREndpoint, deck, es ); - GridPropertyInitFunction< double > IKRGRLookup ( &IKRGREndpoint, deck, es ); - - GridPropertyInitFunction< double > tempLookup ( &temperature_lookup, deck, es ); - GridPropertyPostFunction< double > initPORV ( &GridPropertyPostProcessor::initPORV, deck, es ); - GridPropertyPostFunction< double > distributeTopLayer( &GridPropertyPostProcessor::distTopLayer, deck, es ); - - std::vector< GridProperties< double >::SupportedKeywordInfo > supportedDoubleKeywords; - - // keywords to specify the scaled connate gas saturations. - for( const auto& kw : { "SGL", "SGLX", "SGLX-", "SGLY", "SGLY-", "SGLZ", "SGLZ-" } ) - supportedDoubleKeywords.emplace_back( kw, SGLLookup, "1" ); - for( const auto& kw : { "ISGL", "ISGLX", "ISGLX-", "ISGLY", "ISGLY-", "ISGLZ", "ISGLZ-" } ) - supportedDoubleKeywords.emplace_back( kw, ISGLLookup, "1" ); - - // keywords to specify the connate water saturation. - for( const auto& kw : { "SWL", "SWLX", "SWLX-", "SWLY", "SWLY-", "SWLZ", "SWLZ-" } ) - supportedDoubleKeywords.emplace_back( kw, SWLLookup, "1" ); - for( const auto& kw : { "ISWL", "ISWLX", "ISWLX-", "ISWLY", "ISWLY-", "ISWLZ", "ISWLZ-" } ) - supportedDoubleKeywords.emplace_back( kw, ISWLLookup, "1" ); - - // keywords to specify the maximum gas saturation. - for( const auto& kw : { "SGU", "SGUX", "SGUX-", "SGUY", "SGUY-", "SGUZ", "SGUZ-" } ) - supportedDoubleKeywords.emplace_back( kw, SGULookup, "1" ); - for( const auto& kw : { "ISGU", "ISGUX", "ISGUX-", "ISGUY", "ISGUY-", "ISGUZ", "ISGUZ-" } ) - supportedDoubleKeywords.emplace_back( kw, ISGULookup, "1" ); - - // keywords to specify the maximum water saturation. - for( const auto& kw : { "SWU", "SWUX", "SWUX-", "SWUY", "SWUY-", "SWUZ", "SWUZ-" } ) - supportedDoubleKeywords.emplace_back( kw, SWULookup, "1" ); - for( const auto& kw : { "ISWU", "ISWUX", "ISWUX-", "ISWUY", "ISWUY-", "ISWUZ", "ISWUZ-" } ) - supportedDoubleKeywords.emplace_back( kw, ISWULookup, "1" ); - - // keywords to specify the scaled critical gas saturation. - for( const auto& kw : { "SGCR", "SGCRX", "SGCRX-", "SGCRY", "SGCRY-", "SGCRZ", "SGCRZ-" } ) - supportedDoubleKeywords.emplace_back( kw, SGCRLookup, "1" ); - for( const auto& kw : { "ISGCR", "ISGCRX", "ISGCRX-", "ISGCRY", "ISGCRY-", "ISGCRZ", "ISGCRZ-" } ) - supportedDoubleKeywords.emplace_back( kw, ISGCRLookup, "1" ); - - // keywords to specify the scaled critical oil-in-water saturation. - for( const auto& kw : { "SOWCR", "SOWCRX", "SOWCRX-", "SOWCRY", "SOWCRY-", "SOWCRZ", "SOWCRZ-" } ) - supportedDoubleKeywords.emplace_back( kw, SOWCRLookup, "1" ); - for( const auto& kw : { "ISOWCR", "ISOWCRX", "ISOWCRX-", "ISOWCRY", "ISOWCRY-", "ISOWCRZ", "ISOWCRZ-" } ) - supportedDoubleKeywords.emplace_back( kw, ISOWCRLookup, "1" ); - - // keywords to specify the scaled critical oil-in-gas saturation. - for( const auto& kw : { "SOGCR", "SOGCRX", "SOGCRX-", "SOGCRY", "SOGCRY-", "SOGCRZ", "SOGCRZ-" } ) - supportedDoubleKeywords.emplace_back( kw, SOGCRLookup, "1" ); - for( const auto& kw : { "ISOGCR", "ISOGCRX", "ISOGCRX-", "ISOGCRY", "ISOGCRY-", "ISOGCRZ", "ISOGCRZ-" } ) - supportedDoubleKeywords.emplace_back( kw, ISOGCRLookup, "1" ); - - // keywords to specify the scaled critical water saturation. - for( const auto& kw : { "SWCR", "SWCRX", "SWCRX-", "SWCRY", "SWCRY-", "SWCRZ", "SWCRZ-" } ) - supportedDoubleKeywords.emplace_back( kw, SWCRLookup, "1" ); - for( const auto& kw : { "ISWCR", "ISWCRX", "ISWCRX-", "ISWCRY", "ISWCRY-", "ISWCRZ", "ISWCRZ-" } ) - supportedDoubleKeywords.emplace_back( kw, ISWCRLookup, "1" ); - - // keywords to specify the scaled oil-water capillary pressure - for( const auto& kw : { "PCW", "PCWX", "PCWX-", "PCWY", "PCWY-", "PCWZ", "PCWZ-" } ) - supportedDoubleKeywords.emplace_back( kw, PCWLookup, "1" ); - for( const auto& kw : { "IPCW", "IPCWX", "IPCWX-", "IPCWY", "IPCWY-", "IPCWZ", "IPCWZ-" } ) - supportedDoubleKeywords.emplace_back( kw, IPCWLookup, "1" ); - - // keywords to specify the scaled gas-oil capillary pressure - for( const auto& kw : { "PCG", "PCGX", "PCGX-", "PCGY", "PCGY-", "PCGZ", "PCGZ-" } ) - supportedDoubleKeywords.emplace_back( kw, PCGLookup, "1" ); - for( const auto& kw : { "IPCG", "IPCGX", "IPCGX-", "IPCGY", "IPCGY-", "IPCGZ", "IPCGZ-" } ) - supportedDoubleKeywords.emplace_back( kw, IPCGLookup, "1" ); - - // keywords to specify the scaled water relative permeability - for( const auto& kw : { "KRW", "KRWX", "KRWX-", "KRWY", "KRWY-", "KRWZ", "KRWZ-" } ) - supportedDoubleKeywords.emplace_back( kw, KRWLookup, "1" ); - for( const auto& kw : { "IKRW", "IKRWX", "IKRWX-", "IKRWY", "IKRWY-", "IKRWZ", "IKRWZ-" } ) - supportedDoubleKeywords.emplace_back( kw, IKRWLookup, "1" ); - - // keywords to specify the scaled water relative permeability at the critical - // saturation - for( const auto& kw : { "KRWR" , "KRWRX" , "KRWRX-" , "KRWRY" , "KRWRY-" , "KRWRZ" , "KRWRZ-" } ) - supportedDoubleKeywords.emplace_back( kw, KRWRLookup, "1" ); - for( const auto& kw : { "IKRWR" , "IKRWRX" , "IKRWRX-" , "IKRWRY" , "IKRWRY-" , "IKRWRZ" , "IKRWRZ-" } ) - supportedDoubleKeywords.emplace_back( kw, IKRWRLookup, "1" ); - - // keywords to specify the scaled oil relative permeability - for( const auto& kw : { "KRO", "KROX", "KROX-", "KROY", "KROY-", "KROZ", "KROZ-" } ) - supportedDoubleKeywords.emplace_back( kw, KROLookup, "1" ); - for( const auto& kw : { "IKRO", "IKROX", "IKROX-", "IKROY", "IKROY-", "IKROZ", "IKROZ-" } ) - supportedDoubleKeywords.emplace_back( kw, IKROLookup, "1" ); - - // keywords to specify the scaled water relative permeability at the critical - // water saturation - for( const auto& kw : { "KRORW", "KRORWX", "KRORWX-", "KRORWY", "KRORWY-", "KRORWZ", "KRORWZ-" } ) - supportedDoubleKeywords.emplace_back( kw, KRORWLookup, "1" ); - for( const auto& kw : { "IKRORW", "IKRORWX", "IKRORWX-", "IKRORWY", "IKRORWY-", "IKRORWZ", "IKRORWZ-" } ) - supportedDoubleKeywords.emplace_back( kw, IKRORWLookup, "1" ); - - // keywords to specify the scaled water relative permeability at the critical - // water saturation - for( const auto& kw : { "KRORG", "KRORGX", "KRORGX-", "KRORGY", "KRORGY-", "KRORGZ", "KRORGZ-" } ) - supportedDoubleKeywords.emplace_back( kw, KRORGLookup, "1" ); - for( const auto& kw : { "IKRORG", "IKRORGX", "IKRORGX-", "IKRORGY", "IKRORGY-", "IKRORGZ", "IKRORGZ-" } ) - supportedDoubleKeywords.emplace_back( kw, IKRORGLookup, "1" ); - - // keywords to specify the scaled gas relative permeability - for( const auto& kw : { "KRG", "KRGX", "KRGX-", "KRGY", "KRGY-", "KRGZ", "KRGZ-" } ) - supportedDoubleKeywords.emplace_back( kw, KRGLookup, "1" ); - for( const auto& kw : { "IKRG", "IKRGX", "IKRGX-", "IKRGY", "IKRGY-", "IKRGZ", "IKRGZ-" } ) - supportedDoubleKeywords.emplace_back( kw, IKRGLookup, "1" ); - - // keywords to specify the scaled gas relative permeability - for( const auto& kw : { "KRGR", "KRGRX", "KRGRX-", "KRGRY", "KRGRY-", "KRGRZ", "KRGRZ-" } ) - supportedDoubleKeywords.emplace_back( kw, KRGRLookup, "1" ); - for( const auto& kw : { "IKRGR", "IKRGRX", "IKRGRX-", "IKRGRY", "IKRGRY-", "IKRGRZ", "IKRGRZ-" } ) - supportedDoubleKeywords.emplace_back( kw, IKRGRLookup, "1" ); - - - - // cell temperature (E300 only, but makes a lot of sense for E100, too) - supportedDoubleKeywords.emplace_back( "TEMPI", tempLookup, "Temperature" ); - - double nan = std::numeric_limits::quiet_NaN(); - // porosity - supportedDoubleKeywords.emplace_back( "PORO", nan, distributeTopLayer, "1" ); - - // pore volume - supportedDoubleKeywords.emplace_back( "PORV", nan, initPORV, "Volume" ); - - // pore volume multipliers - supportedDoubleKeywords.emplace_back( "MULTPV", 1.0, "1" ); - - // the permeability keywords - for( const auto& kw : { "PERMX", "PERMY", "PERMZ" } ) - supportedDoubleKeywords.emplace_back( kw, nan, distributeTopLayer, "Permeability" ); - - /* E300 only */ - for( const auto& kw : { "PERMXY", "PERMYZ", "PERMZX" } ) - supportedDoubleKeywords.emplace_back( kw, nan, distributeTopLayer, "Permeability" ); - - /* the transmissibility keywords for neighboring connections. note that - * these keywords don't seem to require a post-processor - */ - for( const auto& kw : { "TRANX", "TRANY", "TRANZ" } ) - supportedDoubleKeywords.emplace_back( kw, nan, "Transmissibility" ); - - /* gross-to-net thickness (acts as a multiplier for PORO and the - * permeabilities in the X-Y plane as well as for the well rates.) - */ - supportedDoubleKeywords.emplace_back( "NTG", 1.0, "1" ); - - // transmissibility multipliers - for( const auto& kw : { "MULTX", "MULTY", "MULTZ", "MULTX-", "MULTY-", "MULTZ-" } ) - supportedDoubleKeywords.emplace_back( kw, 1.0, "1" ); - - // initialisation - supportedDoubleKeywords.emplace_back( "SWATINIT", 0.0, "1"); - supportedDoubleKeywords.emplace_back( "THCONR", 0.0, "1"); - - return supportedDoubleKeywords; - } - - void EclipseState::initProperties(DeckConstPtr deck) { - - // Note that the variants of grid keywords for radial grids - // are not supported. (and hopefully never will be) - - // register the grid properties - m_intGridProperties.reset( new GridProperties< int >( m_eclipseGrid , makeSupportedIntKeywords() ) ); - m_doubleGridProperties.reset( new GridProperties< double >( m_eclipseGrid, makeSupportedDoubleKeywords(*deck, *this) ) ); - - // actually create the grid property objects. we need to first - // process all integer grid properties before the double ones - // as these may be needed in order to initialize the double - // properties - processGridProperties(deck, /*enabledTypes=*/IntProperties); - processGridProperties(deck, /*enabledTypes=*/DoubleProperties); - } - - double EclipseState::getSIScaling(const std::string &dimensionString) const - { - return m_deckUnitSystem.getDimension(dimensionString)->getSIScaling(); - } - - void EclipseState::processGridProperties(Opm::DeckConstPtr deck, int enabledTypes) { - - if (Section::hasGRID(*deck)) { - std::shared_ptr gridSection(new Opm::GRIDSection(*deck) ); - scanSection(gridSection, enabledTypes); - } - - - if (Section::hasEDIT(*deck)) { - std::shared_ptr editSection(new Opm::EDITSection(*deck) ); - scanSection(editSection, enabledTypes); - } - - if (Section::hasPROPS(*deck)) { - std::shared_ptr propsSection(new Opm::PROPSSection(*deck) ); - scanSection(propsSection, enabledTypes); - } - - if (Section::hasREGIONS(*deck)) { - std::shared_ptr regionsSection(new Opm::REGIONSSection(*deck) ); - scanSection(regionsSection, enabledTypes); - } - - if (Section::hasSOLUTION(*deck)) { - std::shared_ptr solutionSection(new Opm::SOLUTIONSection(*deck) ); - scanSection(solutionSection, enabledTypes); - } - } - - void EclipseState::scanSection(std::shared_ptr section, - int enabledTypes) { - BoxManager boxManager(m_eclipseGrid->getNX( ) , m_eclipseGrid->getNY() , m_eclipseGrid->getNZ()); - for( const auto& deckKeyword : *section ) { - - if (supportsGridProperty(deckKeyword.name(), enabledTypes) ) - loadGridPropertyFromDeckKeyword(boxManager.getActiveBox(), deckKeyword, enabledTypes); - else { - if (deckKeyword.name() == "ADD") - handleADDKeyword(deckKeyword, boxManager, enabledTypes); - - if (deckKeyword.name() == "BOX") - handleBOXKeyword(deckKeyword, boxManager); - - if (deckKeyword.name() == "COPY") - handleCOPYKeyword(deckKeyword, boxManager, enabledTypes); - - if (deckKeyword.name() == "EQUALS") - handleEQUALSKeyword(deckKeyword, boxManager, enabledTypes); - - if (deckKeyword.name() == "ENDBOX") - handleENDBOXKeyword(boxManager); - - if (deckKeyword.name() == "EQUALREG") - handleEQUALREGKeyword(deckKeyword , enabledTypes); - - if (deckKeyword.name() == "ADDREG") - handleADDREGKeyword(deckKeyword , enabledTypes); - - if (deckKeyword.name() == "MULTIREG") - handleMULTIREGKeyword(deckKeyword , enabledTypes); - - if (deckKeyword.name() == "COPYREG") - handleCOPYREGKeyword(deckKeyword , enabledTypes); - - if (deckKeyword.name() == "MULTIPLY") - handleMULTIPLYKeyword(deckKeyword, boxManager, enabledTypes); - - boxManager.endKeyword(); - } - } - boxManager.endSection(); - } - - - - - void EclipseState::handleBOXKeyword( const DeckKeyword& deckKeyword, BoxManager& boxManager) { - const auto& record = deckKeyword.getRecord(0); - int I1 = record.getItem("I1").get< int >(0) - 1; - int I2 = record.getItem("I2").get< int >(0) - 1; - int J1 = record.getItem("J1").get< int >(0) - 1; - int J2 = record.getItem("J2").get< int >(0) - 1; - int K1 = record.getItem("K1").get< int >(0) - 1; - int K2 = record.getItem("K2").get< int >(0) - 1; - - boxManager.setInputBox( I1 , I2 , J1 , J2 , K1 , K2 ); - } - - - void EclipseState::handleENDBOXKeyword(BoxManager& boxManager) { - boxManager.endInputBox(); - } - - - void EclipseState::handleEQUALREGKeyword( const DeckKeyword& deckKeyword, int enabledTypes) { - EclipseGridConstPtr grid = getEclipseGrid(); - for( const auto& record : deckKeyword ) { - const std::string& targetArray = record.getItem("ARRAY").get< std::string >(0); - - if (!supportsGridProperty( targetArray , IntProperties + DoubleProperties)) - throw std::invalid_argument("Fatal error processing EQUALREG keyword - invalid/undefined keyword: " + targetArray); - - double doubleValue = record.getItem("VALUE").template get(0); - int regionValue = record.getItem("REGION_NUMBER").template get(0); - std::shared_ptr > regionProperty = getRegion( record.getItem("REGION_NAME") ); - std::vector mask; - - regionProperty->initMask( regionValue , mask); - - if (m_intGridProperties->supportsKeyword( targetArray )) { - if (enabledTypes & IntProperties) { - if (isInt( doubleValue )) { - std::shared_ptr > targetProperty = getOrCreateIntProperty_(targetArray); - int intValue = static_cast( doubleValue + 0.5 ); - targetProperty->maskedSet( intValue , mask); - } else - throw std::invalid_argument("Fatal error processing EQUALREG keyword - expected integer value for: " + targetArray); - } - } - else if (m_doubleGridProperties->supportsKeyword( targetArray )) { - if (enabledTypes & DoubleProperties) { - std::shared_ptr > targetProperty = getOrCreateDoubleProperty_(targetArray); - const std::string& dimensionString = targetProperty->getDimensionString(); - double SIValue = doubleValue * getSIScaling( dimensionString ); - targetProperty->maskedSet( SIValue , mask); - } - } - else { - throw std::invalid_argument("Fatal error processing EQUALREG keyword - invalid/undefined keyword: " + targetArray); - } - } - } - - - void EclipseState::handleADDREGKeyword( const DeckKeyword& deckKeyword, int enabledTypes) { - EclipseGridConstPtr grid = getEclipseGrid(); - for( const auto& record : deckKeyword ) { - const std::string& targetArray = record.getItem("ARRAY").get< std::string >(0); - - if (!supportsGridProperty( targetArray , IntProperties + DoubleProperties)) - throw std::invalid_argument("Fatal error processing ADDREG keyword - invalid/undefined keyword: " + targetArray); - - if (supportsGridProperty( targetArray , enabledTypes)) { - double doubleValue = record.getItem("SHIFT").get< double >(0); - int regionValue = record.getItem("REGION_NUMBER").get< int >(0); - std::shared_ptr > regionProperty = getRegion( record.getItem("REGION_NAME") ); - std::vector mask; - - regionProperty->initMask( regionValue , mask); - - if (m_intGridProperties->hasKeyword( targetArray )) { - if (enabledTypes & IntProperties) { - if (isInt( doubleValue )) { - std::shared_ptr > targetProperty = m_intGridProperties->getKeyword(targetArray); - int intValue = static_cast( doubleValue + 0.5 ); - targetProperty->maskedAdd( intValue , mask); - } else - throw std::invalid_argument("Fatal error processing ADDREG keyword - expected integer value for: " + targetArray); - } - } - else if (m_doubleGridProperties->hasKeyword( targetArray )) { - if (enabledTypes & DoubleProperties) { - std::shared_ptr > targetProperty = m_doubleGridProperties->getKeyword(targetArray); - const std::string& dimensionString = targetProperty->getDimensionString(); - double SIValue = doubleValue * getSIScaling( dimensionString ); - targetProperty->maskedAdd( SIValue , mask); - } - } - else { - throw std::invalid_argument("Fatal error processing ADDREG keyword - invalid/undefined keyword: " + targetArray); - } - } - } - } - - - - - void EclipseState::handleMULTIREGKeyword( const DeckKeyword& deckKeyword, int enabledTypes) { - EclipseGridConstPtr grid = getEclipseGrid(); - for( const auto& record : deckKeyword ) { - const std::string& targetArray = record.getItem("ARRAY").get< std::string >(0); - - if (!supportsGridProperty( targetArray , IntProperties + DoubleProperties)) - throw std::invalid_argument("Fatal error processing MULTIREG keyword - invalid/undefined keyword: " + targetArray); - - if (supportsGridProperty( targetArray , enabledTypes)) { - double doubleValue = record.getItem("FACTOR").get< double >(0); - int regionValue = record.getItem("REGION_NUMBER").get< int >(0); - std::shared_ptr > regionProperty = getRegion( record.getItem("REGION_NAME") ); - std::vector mask; - - regionProperty->initMask( regionValue , mask); - - if (enabledTypes & IntProperties) { - if (isInt( doubleValue )) { - std::shared_ptr > targetProperty = getOrCreateIntProperty_( targetArray ); - int intValue = static_cast( doubleValue + 0.5 ); - targetProperty->maskedMultiply( intValue , mask); - } else - throw std::invalid_argument("Fatal error processing MULTIREG keyword - expected integer value for: " + targetArray); - } - if (enabledTypes & DoubleProperties) { - std::shared_ptr > targetProperty = getOrCreateDoubleProperty_(targetArray); - targetProperty->maskedMultiply( doubleValue , mask); - } - } - } - } - - - void EclipseState::handleCOPYREGKeyword( const DeckKeyword& deckKeyword, int enabledTypes) { - EclipseGridConstPtr grid = getEclipseGrid(); - for( const auto& record : deckKeyword ) { - const std::string& srcArray = record.getItem("ARRAY").get< std::string >(0); - const std::string& targetArray = record.getItem("TARGET_ARRAY").get< std::string >(0); - - if (!supportsGridProperty( targetArray , IntProperties + DoubleProperties)) - throw std::invalid_argument("Fatal error processing MULTIREG keyword - invalid/undefined keyword: " + targetArray); - - if (!supportsGridProperty( srcArray , IntProperties + DoubleProperties)) - throw std::invalid_argument("Fatal error processing MULTIREG keyword - invalid/undefined keyword: " + srcArray); - - if (supportsGridProperty( srcArray , enabledTypes)) { - int regionValue = record.getItem("REGION_NUMBER").get< int >(0); - std::shared_ptr > regionProperty = getRegion( record.getItem("REGION_NAME") ); - std::vector mask; - - regionProperty->initMask( regionValue , mask ); - - if (m_intGridProperties->hasKeyword( srcArray )) { - std::shared_ptr > srcProperty = m_intGridProperties->getInitializedKeyword( srcArray ); - if (supportsGridProperty( targetArray , IntProperties)) { - std::shared_ptr > targetProperty = getOrCreateIntProperty_( targetArray ); - targetProperty->maskedCopy( *srcProperty , mask ); - } else - throw std::invalid_argument("Fatal error processing COPYREG keyword."); - } else if (m_doubleGridProperties->hasKeyword( srcArray )) { - std::shared_ptr > srcProperty = m_doubleGridProperties->getInitializedKeyword( srcArray ); - if (supportsGridProperty( targetArray , DoubleProperties)) { - std::shared_ptr > targetProperty = getOrCreateDoubleProperty_( targetArray ); - targetProperty->maskedCopy( *srcProperty , mask ); - } - } - else { - throw std::invalid_argument("Fatal error processing COPYREG keyword - invalid/undefined keyword: " + targetArray); - } - } - } - } - - - - - void EclipseState::handleMULTIPLYKeyword( const DeckKeyword& deckKeyword, BoxManager& boxManager, int enabledTypes) { - for( const auto& record : deckKeyword ) { - const std::string& field = record.getItem("field").get< std::string >(0); - double scaleFactor = record.getItem("factor").get< double >(0); - - setKeywordBox(deckKeyword, record, boxManager); - - if (m_intGridProperties->hasKeyword( field )) { - if (enabledTypes & IntProperties) { - int intFactor = static_cast(scaleFactor); - std::shared_ptr > property = m_intGridProperties->getKeyword( field ); - - property->scale( intFactor , boxManager.getActiveBox() ); - } - } else if (m_doubleGridProperties->hasKeyword( field )) { - if (enabledTypes & DoubleProperties) { - std::shared_ptr > property = m_doubleGridProperties->getKeyword( field ); - property->scale( scaleFactor , boxManager.getActiveBox() ); - } - } else if (!m_intGridProperties->supportsKeyword(field) && - !m_doubleGridProperties->supportsKeyword(field)) - throw std::invalid_argument("Fatal error processing MULTIPLY keyword. Tried to multiply not defined keyword " + field); - } - } - - - /* - The fine print of the manual says the ADD keyword should support - some state dependent semantics regarding endpoint scaling arrays - in the PROPS section. That is not supported. - */ - void EclipseState::handleADDKeyword( const DeckKeyword& deckKeyword, BoxManager& boxManager, int enabledTypes) { - for( const auto& record : deckKeyword ) { - const std::string& field = record.getItem("field").get< std::string >(0); - double shiftValue = record.getItem("shift").get< double >(0); - - setKeywordBox(deckKeyword, record, boxManager); - - if (m_intGridProperties->hasKeyword( field )) { - if (enabledTypes & IntProperties) { - int intShift = static_cast(shiftValue); - std::shared_ptr > property = m_intGridProperties->getKeyword( field ); - - property->add( intShift , boxManager.getActiveBox() ); - } - } else if (m_doubleGridProperties->hasKeyword( field )) { - if (enabledTypes & DoubleProperties) { - std::shared_ptr > property = m_doubleGridProperties->getKeyword( field ); - - double siShiftValue = shiftValue * getSIScaling(property->getDimensionString()); - property->add(siShiftValue , boxManager.getActiveBox() ); - } - } else if (!m_intGridProperties->supportsKeyword(field) && - !m_doubleGridProperties->supportsKeyword(field)) - throw std::invalid_argument("Fatal error processing ADD keyword. Tried to shift not defined keyword " + field); - - } - } - - - void EclipseState::handleEQUALSKeyword( const DeckKeyword& deckKeyword, BoxManager& boxManager, int enabledTypes) { - for( const auto& record : deckKeyword ) { - const std::string& field = record.getItem("field").get< std::string >(0); - double value = record.getItem("value").get< double >(0); - - setKeywordBox(deckKeyword, record, boxManager); - - if (m_intGridProperties->supportsKeyword( field )) { - if (enabledTypes & IntProperties) { - int intValue = static_cast(value); - std::shared_ptr > property = getOrCreateIntProperty_( field ); - - property->setScalar( intValue , boxManager.getActiveBox() ); - } - } else if (m_doubleGridProperties->supportsKeyword( field )) { - - if (enabledTypes & DoubleProperties) { - std::shared_ptr > property = getOrCreateDoubleProperty_( field ); - - double siValue = value * getSIScaling(property->getKeywordInfo().getDimensionString()); - property->setScalar( siValue , boxManager.getActiveBox() ); - } - } else - throw std::invalid_argument("Fatal error processing EQUALS keyword. Tried to set not defined keyword " + field); - - } - } - - - - void EclipseState::handleCOPYKeyword( const DeckKeyword& deckKeyword, BoxManager& boxManager, int enabledTypes) { - for( const auto& record : deckKeyword ) { - const std::string& srcField = record.getItem("src").get< std::string >(0); - const std::string& targetField = record.getItem("target").get< std::string >(0); - - setKeywordBox(deckKeyword, record, boxManager); - - if (m_intGridProperties->hasKeyword( srcField )) { - if (enabledTypes & IntProperties) - copyIntKeyword( srcField , targetField , boxManager.getActiveBox()); - } - else if (m_doubleGridProperties->hasKeyword( srcField )) { - if (enabledTypes & DoubleProperties) - copyDoubleKeyword( srcField , targetField , boxManager.getActiveBox()); - } - else if (!m_intGridProperties->supportsKeyword(srcField) && - !m_doubleGridProperties->supportsKeyword(srcField)) - throw std::invalid_argument("Fatal error processing COPY keyword. Tried to copy from not defined keyword " + srcField); - } - } - - - void EclipseState::copyIntKeyword(const std::string& srcField , const std::string& targetField , std::shared_ptr inputBox) { - std::shared_ptr > src = m_intGridProperties->getKeyword( srcField ); - std::shared_ptr > target = getOrCreateIntProperty_( targetField ); - - target->copyFrom( *src , inputBox ); - } - - - void EclipseState::copyDoubleKeyword(const std::string& srcField , const std::string& targetField , std::shared_ptr inputBox) { - std::shared_ptr > src = m_doubleGridProperties->getKeyword( srcField ); - std::shared_ptr > target = getOrCreateDoubleProperty_( targetField ); - - target->copyFrom( *src , inputBox ); - } - - - - void EclipseState::setKeywordBox( const DeckKeyword& deckKeyword, const DeckRecord& deckRecord, BoxManager& boxManager) { - const auto& I1Item = deckRecord.getItem("I1"); - const auto& I2Item = deckRecord.getItem("I2"); - const auto& J1Item = deckRecord.getItem("J1"); - const auto& J2Item = deckRecord.getItem("J2"); - const auto& K1Item = deckRecord.getItem("K1"); - const auto& K2Item = deckRecord.getItem("K2"); - - size_t setCount = 0; - - if (!I1Item.defaultApplied(0)) - setCount++; - - if (!I2Item.defaultApplied(0)) - setCount++; - - if (!J1Item.defaultApplied(0)) - setCount++; - - if (!J2Item.defaultApplied(0)) - setCount++; - - if (!K1Item.defaultApplied(0)) - setCount++; - - if (!K2Item.defaultApplied(0)) - setCount++; - - if (setCount == 6) { - boxManager.setKeywordBox( I1Item.get< int >(0) - 1, - I2Item.get< int >(0) - 1, - J1Item.get< int >(0) - 1, - J2Item.get< int >(0) - 1, - K1Item.get< int >(0) - 1, - K2Item.get< int >(0) - 1); - } else if (setCount != 0) { - std::string msg = "BOX modifiers on keywords must be either specified completely or not at all. Ignoring."; - OpmLog::addMessage(Log::MessageType::Error , Log::fileMessage(deckKeyword.getFileName() , deckKeyword.getLineNumber() , msg)); - } - } - - void EclipseState::complainAboutAmbiguousKeyword(DeckConstPtr deck, const std::string& keywordName) const { OpmLog::addMessage(Log::MessageType::Error, "The " + keywordName + " keyword must be unique in the deck. Ignoring all!"); auto keywords = deck->getKeywordList(keywordName); @@ -1164,8 +259,6 @@ namespace Opm { } - - void EclipseState::applyModifierDeck( std::shared_ptr deck) { using namespace ParserKeywords; for (const auto& keyword : *deck) { @@ -1205,21 +298,4 @@ namespace Opm { } } } - - std::shared_ptr > EclipseState::getOrCreateIntProperty_(const std::string name) - { - if (!m_intGridProperties->hasKeyword(name)) { - m_intGridProperties->addKeyword(name); - } - return m_intGridProperties->getKeyword(name); - } - - std::shared_ptr > EclipseState::getOrCreateDoubleProperty_(const std::string name) - { - if (!m_doubleGridProperties->hasKeyword(name)) { - m_doubleGridProperties->addKeyword(name); - } - return m_doubleGridProperties->getKeyword(name); - } - } diff --git a/opm/parser/eclipse/EclipseState/EclipseState.hpp b/opm/parser/eclipse/EclipseState/EclipseState.hpp index fe5fd9b4a..68ddc67d4 100644 --- a/opm/parser/eclipse/EclipseState/EclipseState.hpp +++ b/opm/parser/eclipse/EclipseState/EclipseState.hpp @@ -25,6 +25,7 @@ #include #include +#include #include namespace Opm { @@ -73,105 +74,57 @@ namespace Opm { std::shared_ptr< EclipseGrid > getEclipseGridCopy() const; const MessageContainer& getMessageContainer() const; MessageContainer& getMessageContainer(); - bool hasPhase(enum Phase::PhaseEnum phase) const; std::string getTitle() const; - bool supportsGridProperty(const std::string& keyword, int enabledTypes=AllProperties) const; - - std::shared_ptr > getRegion( const DeckItem& regionItem ) const; - std::shared_ptr > getDefaultRegion() const; - std::shared_ptr > getIntGridProperty( const std::string& keyword ) const; - std::shared_ptr > getDoubleGridProperty( const std::string& keyword ) const; - bool hasDeckIntGridProperty(const std::string& keyword) const; - bool hasDeckDoubleGridProperty(const std::string& keyword) const; - - bool hasIntGridProperty(const std::string& keyword) const __attribute__((deprecated("use hasDeckIntGridProperty() instead"))) - { return hasDeckIntGridProperty(keyword); } - bool hasDoubleGridProperty(const std::string& keyword) const __attribute__((deprecated("use hasDeckDoubleGridProperty() instead"))) - { return hasDeckDoubleGridProperty(keyword); } - - void loadGridPropertyFromDeckKeyword(std::shared_ptr inputBox, - const DeckKeyword& deckKeyword, - int enabledTypes = AllProperties); std::shared_ptr getFaults() const; std::shared_ptr getTransMult() const; std::shared_ptr getNNC() const; bool hasNNC() const; - std::shared_ptr getTableManager() const; - size_t getNumPhases() const; + const Eclipse3DProperties& getEclipseProperties() const; - // the unit system used by the deck. note that it is rarely needed to convert - // units because internally to opm-parser everything is represented by SI - // units... + std::shared_ptr getTableManager() const; + + // the unit system used by the deck. note that it is rarely needed to + // convert units because internally to opm-parser everything is + // represented by SI units... const UnitSystem& getDeckUnitSystem() const; void applyModifierDeck( std::shared_ptr deck); + // TODO this used to be private but since eclipseProperties needs to + // know SIScaling, we need access to either this or to the UnitSystem. + double getSIScaling(const std::string &dimensionString) const; + private: void initTabdims(std::shared_ptr< const Deck > deck); - void initTables(std::shared_ptr< const Deck > deck); void initIOConfig(std::shared_ptr< const Deck > deck); - void initSchedule(std::shared_ptr< const Deck > deck); void initIOConfigPostSchedule(std::shared_ptr< const Deck > deck); - void initInitConfig(std::shared_ptr< const Deck > deck); - void initSimulationConfig(std::shared_ptr< const Deck > deck); - void initEclipseGrid(std::shared_ptr< const Deck > deck); - void initGridopts(std::shared_ptr< const Deck > deck); - void initPhases(std::shared_ptr< const Deck > deck); void initTitle(std::shared_ptr< const Deck > deck); - void initProperties(std::shared_ptr< const Deck > deck); + void initTransMult(); void initFaults(std::shared_ptr< const Deck > deck); - void initNNC(std::shared_ptr< const Deck > deck); - void setMULTFLT(std::shared_ptr section) const; void initMULTREGT(std::shared_ptr< const Deck > deck); - double getSIScaling(const std::string &dimensionString) const; - - void processGridProperties(std::shared_ptr< const Deck > deck, int enabledTypes); - void scanSection(std::shared_ptr section , int enabledTypes); - void handleADDKeyword(const DeckKeyword& deckKeyword , BoxManager& boxManager, int enabledTypes); - void handleBOXKeyword(const DeckKeyword& deckKeyword , BoxManager& boxManager); - void handleCOPYKeyword(const DeckKeyword& deckKeyword , BoxManager& boxManager, int enabledTypes); - void handleENDBOXKeyword(BoxManager& boxManager); - void handleEQUALSKeyword(const DeckKeyword& deckKeyword , BoxManager& boxManager, int enabledTypes); - void handleMULTIPLYKeyword(const DeckKeyword& deckKeyword , BoxManager& boxManager, int enabledTypes); - - void handleEQUALREGKeyword(const DeckKeyword& deckKeyword, int enabledTypes); - void handleMULTIREGKeyword(const DeckKeyword& deckKeyword, int enabledTypes); - void handleADDREGKeyword(const DeckKeyword& deckKeyword , int enabledTypes); - void handleCOPYREGKeyword(const DeckKeyword& deckKeyword , int enabledTypes); - - void setKeywordBox( const DeckKeyword& deckKeyword, const DeckRecord&, BoxManager& boxManager); - - void copyIntKeyword(const std::string& srcField , const std::string& targetField , std::shared_ptr inputBox); - void copyDoubleKeyword(const std::string& srcField , const std::string& targetField , std::shared_ptr inputBox); - void complainAboutAmbiguousKeyword(std::shared_ptr< const Deck > deck, const std::string& keywordName) const; - std::shared_ptr > getOrCreateIntProperty_(const std::string name); - std::shared_ptr > getOrCreateDoubleProperty_(const std::string name); - - std::shared_ptr< const EclipseGrid > m_eclipseGrid; - std::shared_ptr< IOConfig > m_ioConfig; + std::shared_ptr< IOConfig > m_ioConfig; std::shared_ptr< const InitConfig > m_initConfig; - std::shared_ptr< const Schedule > schedule; + std::shared_ptr< const Schedule > m_schedule; std::shared_ptr< const SimulationConfig > m_simulationConfig; - std::shared_ptr m_tables; - std::set phases; std::string m_title; - const UnitSystem& m_deckUnitSystem; - std::shared_ptr > m_intGridProperties; - std::shared_ptr > m_doubleGridProperties; std::shared_ptr m_transMult; std::shared_ptr m_faults; std::shared_ptr m_nnc; - std::string m_defaultRegion; + + const UnitSystem& m_deckUnitSystem; const ParseContext& m_parseContext; + std::shared_ptr m_tables; + std::shared_ptr m_eclipseGrid; + Eclipse3DProperties m_eclipseProperties; MessageContainer m_messageContainer; }; @@ -179,4 +132,4 @@ namespace Opm { typedef std::shared_ptr EclipseStateConstPtr; } -#endif +#endif // OPM_ECLIPSE_STATE_HPP diff --git a/opm/parser/eclipse/EclipseState/Grid/GridProperties.hpp b/opm/parser/eclipse/EclipseState/Grid/GridProperties.hpp index fc917692b..861f91942 100644 --- a/opm/parser/eclipse/EclipseState/Grid/GridProperties.hpp +++ b/opm/parser/eclipse/EclipseState/Grid/GridProperties.hpp @@ -28,163 +28,205 @@ #include #include +#include -/* - This class implements a container (std::unordered_map>) of Gridproperties. Usage is as follows: +/** + This class implements a container (std::unordered_map>) of Gridproperties. Usage is as follows: - 1. Instantiate the class; passing the number of grid cells and the - supported keywords as a list of strings to the constructor. + 1. Instantiate the class; passing the number of grid cells and the supported + keywords as a list of strings to the constructor. - 2. Query the container with the supportsKeyword() and hasKeyword() - methods. + 2. Query the container with the supportsKeyword() and hasKeyword() methods. - 3. When you ask the container to get a keyword with the - getKeyword() method it will automatically create a new - GridProperty object if the container does not have this - property. + 3. When you ask the container to get a keyword with the getKeyword() method + it will automatically create a new GridProperty object if the container + does not have this property. */ namespace Opm { - class EclipseGrid; + class Eclipse3DProperties; -template -class GridProperties { -public: - typedef typename GridProperty::SupportedKeywordInfo SupportedKeywordInfo; + template + class GridProperties { + public: + typedef typename GridProperty::SupportedKeywordInfo SupportedKeywordInfo; - GridProperties(std::shared_ptr eclipseGrid, std::vector< SupportedKeywordInfo >&& supportedKeywords) : - m_eclipseGrid( eclipseGrid ) { - - for (auto iter = supportedKeywords.begin(); iter != supportedKeywords.end(); ++iter) - m_supportedKeywords.emplace( iter->getKeywordName(), std::move( *iter ) ); - } - - - bool supportsKeyword(const std::string& keyword) const { - return m_supportedKeywords.count( keyword ) > 0; - } - - bool hasKeyword(const std::string& keyword) const { - return m_properties.count( keyword ) > 0 && !isAutoGenerated_(keyword); - } - - size_t size() const { - return m_property_list.size(); - } - - std::shared_ptr > getKeyword(const std::string& keyword) const { - if (!hasKeyword(keyword)) - addAutoGeneratedKeyword_(keyword); - - return m_properties.at( keyword ); - } - - std::shared_ptr > getKeyword(size_t index) const { - if (index < size()) - return m_property_list[index]; - else - throw std::invalid_argument("Invalid index"); - } - - - std::shared_ptr > getInitializedKeyword(const std::string& keyword) const { - if (hasKeyword(keyword)) - return m_properties.at( keyword ); - else { - if (supportsKeyword(keyword)) - throw std::invalid_argument("Keyword: " + keyword + " is supported - but not initialized."); - else - throw std::invalid_argument("Keyword: " + keyword + " is not supported."); + GridProperties(const EclipseGrid& eclipseGrid, + std::vector< SupportedKeywordInfo >&& supportedKeywords) : + m_eclipseGrid( eclipseGrid ) + { + for (auto iter = supportedKeywords.begin(); iter != supportedKeywords.end(); ++iter) + m_supportedKeywords.emplace( iter->getKeywordName(), std::move( *iter ) ); + } + + bool supportsKeyword(const std::string& keyword) const { + return m_supportedKeywords.count( keyword ) > 0; + } + + bool hasKeyword(const std::string& keyword) const { + const auto cnt = m_properties.count( keyword ); + const bool positive = cnt > 0; + + return positive && !isAutoGenerated_(keyword); + } + + size_t size() const { + return m_property_list.size(); + } + + const GridProperty& getKeyword(const std::string& keyword) const { + if (!hasKeyword(keyword)) + addAutoGeneratedKeyword_(keyword); + + return *m_properties.at( keyword ); + } + + GridProperty& getKeyword(const std::string& keyword) { + if (!hasKeyword(keyword)) + addAutoGeneratedKeyword_(keyword); + + return *m_properties.at( keyword ); + } + + const GridProperty& getKeyword(size_t index) const { + if (index < size()) + return *m_property_list[index]; + else + throw std::invalid_argument("Invalid index"); + } + + GridProperty& getKeyword(size_t index) { + if (index < size()) + return *m_property_list[index]; + else + throw std::invalid_argument("Invalid index"); } - } - bool addKeyword(const std::string& keywordName) { - if (!supportsKeyword( keywordName )) - throw std::invalid_argument("The keyword: " + keywordName + " is not supported in this container"); + const GridProperty& getInitializedKeyword(const std::string& keyword) const { + if (hasKeyword(keyword)) + return *m_properties.at( keyword ); + else { + if (supportsKeyword(keyword)) + throw std::invalid_argument("Keyword: " + keyword + " is supported - but not initialized."); + else + throw std::invalid_argument("Keyword: " + keyword + " is not supported."); + } + } - if (hasKeyword(keywordName)) - return false; - else { - // if the property was already added auto generated, we just need to make it - // non-auto generated - if (m_autoGeneratedProperties_.count(keywordName)) { - OpmLog::addMessage(Log::MessageType::Warning, - "The keyword "+keywordName+" has been used to calculate the " - "defaults of another keyword before the first time it was " - "explicitly mentioned in the deck. Maybe you need to change " - "the ordering of your keywords (move "+keywordName+" to the " - "front?)."); - m_autoGeneratedProperties_.erase(m_autoGeneratedProperties_.find(keywordName)); + bool addKeyword(const std::string& keywordName) { + if (!supportsKeyword( keywordName )) + throw std::invalid_argument("The keyword: " + keywordName + " is not supported in this container"); + + if (hasKeyword(keywordName)) + return false; + else { + // if the property was already added auto generated, we just need to make it + // non-auto generated + if (m_autoGeneratedProperties_.count(keywordName)) { + OpmLog::addMessage(Log::MessageType::Warning, + "The keyword "+keywordName+" has been used to calculate the " + "defaults of another keyword before the first time it was " + "explicitly mentioned in the deck. Maybe you need to change " + "the ordering of your keywords (move "+keywordName+" to the " + "front?)."); + m_autoGeneratedProperties_.erase(m_autoGeneratedProperties_.find(keywordName)); + return true; + } + + auto supportedKeyword = m_supportedKeywords.at( keywordName ); + int nx = m_eclipseGrid.getNX(); + int ny = m_eclipseGrid.getNY(); + int nz = m_eclipseGrid.getNZ(); + std::shared_ptr > newProperty(new GridProperty(nx , ny , nz , supportedKeyword)); + + m_properties.insert( std::pair > > ( keywordName , newProperty )); + m_property_list.push_back( newProperty ); return true; } - - auto supportedKeyword = m_supportedKeywords.at( keywordName ); - int nx = m_eclipseGrid->getNX(); - int ny = m_eclipseGrid->getNY(); - int nz = m_eclipseGrid->getNZ(); - std::shared_ptr > newProperty(new GridProperty(nx , ny , nz , supportedKeyword)); - - m_properties.insert( std::pair > > ( keywordName , newProperty )); - m_property_list.push_back( newProperty ); - return true; } - } + void copyKeyword(const std::string& srcField , + const std::string& targetField , + const Box& inputBox) { + const auto& src = this->getKeyword( srcField ); + auto& target = this->getOrCreateProperty( targetField ); - template - bool hasKeyword() const { - return hasKeyword( Keyword::keywordName ); - } - - template - std::shared_ptr > getKeyword() const { - return getKeyword( Keyword::keywordName ); - } - - template - std::shared_ptr > getInitializedKeyword() const { - return getInitializedKeyword( Keyword::keywordName ); - } - - - -private: - bool addAutoGeneratedKeyword_(const std::string& keywordName) const { - if (!supportsKeyword( keywordName )) - throw std::invalid_argument("The keyword: " + keywordName + " is not supported in this container"); - - if (m_properties.count( keywordName ) > 0) - return false; // property already exists (if it is auto generated or not doesn't matter) - else { - auto supportedKeyword = m_supportedKeywords.at( keywordName ); - int nx = m_eclipseGrid->getNX(); - int ny = m_eclipseGrid->getNY(); - int nz = m_eclipseGrid->getNZ(); - std::shared_ptr > newProperty(new GridProperty(nx , ny , nz , supportedKeyword)); - - m_autoGeneratedProperties_.insert(keywordName); - - m_properties.insert( std::pair > > ( keywordName , newProperty )); - m_property_list.push_back( newProperty ); - return true; + target.copyFrom( *src , inputBox ); } - } - bool isAutoGenerated_(const std::string& keyword) const { - return m_autoGeneratedProperties_.count(keyword); - } - std::shared_ptr m_eclipseGrid; - std::unordered_map m_supportedKeywords; - mutable std::map > > m_properties; - mutable std::set m_autoGeneratedProperties_; - mutable std::vector > > m_property_list; -}; + template + bool hasKeyword() const { + return hasKeyword( Keyword::keywordName ); + } + template + const GridProperty& getKeyword() const { + return getKeyword( Keyword::keywordName ); + } + + template + const GridProperty& getInitializedKeyword() const { + return getInitializedKeyword( Keyword::keywordName ); + } + + GridProperty& getOrCreateProperty(const std::string name) { + if (!hasKeyword(name)) { + addKeyword(name); + } + return getKeyword(name); + } + + private: + /// this method exists for (friend) Eclipse3DProperties to be allowed initializing PORV keyword + void postAddKeyword(const std::string& name, + const T defaultValue, + GridPropertyPostFunction< T >& postProcessor, + const std::string& dimString ) + { + m_supportedKeywords.emplace(name, + SupportedKeywordInfo( name, + defaultValue, + postProcessor, + dimString )); + } + + bool addAutoGeneratedKeyword_(const std::string& keywordName) const { + if (!supportsKeyword( keywordName )) + throw std::invalid_argument("The keyword: " + keywordName + " is not supported in this container"); + + if (m_properties.count( keywordName ) > 0) + return false; // property already exists (if it is auto generated or not doesn't matter) + else { + auto& supportedKeyword = m_supportedKeywords.at( keywordName ); + int nx = m_eclipseGrid.getNX(); + int ny = m_eclipseGrid.getNY(); + int nz = m_eclipseGrid.getNZ(); + std::shared_ptr > newProperty(new GridProperty(nx , ny , nz , supportedKeyword)); + + m_autoGeneratedProperties_.insert(keywordName); + + m_properties.insert( std::pair > > ( keywordName , newProperty )); + m_property_list.push_back( newProperty ); + return true; + } + } + + bool isAutoGenerated_(const std::string& keyword) const { + return m_autoGeneratedProperties_.count(keyword); + } + + friend class Eclipse3DProperties; // needed for PORV keyword entanglement + const EclipseGrid& m_eclipseGrid; + std::unordered_map m_supportedKeywords; + mutable std::map > > m_properties; + mutable std::set m_autoGeneratedProperties_; + mutable std::vector > > m_property_list; + }; } -#endif +#endif // ECLIPSE_GRIDPROPERTIES_HPP_ diff --git a/opm/parser/eclipse/EclipseState/Grid/GridProperty.cpp b/opm/parser/eclipse/EclipseState/Grid/GridProperty.cpp index bf8348dd4..158dcbcd3 100644 --- a/opm/parser/eclipse/EclipseState/Grid/GridProperty.cpp +++ b/opm/parser/eclipse/EclipseState/Grid/GridProperty.cpp @@ -219,7 +219,7 @@ namespace Opm { template< typename T > void GridProperty< T >::loadFromDeckKeyword( const DeckKeyword& deckKeyword ) { - const auto& deckItem = getDeckItem(deckKeyword); + const DeckItem& deckItem = getDeckItem(deckKeyword); for (size_t dataPointIdx = 0; dataPointIdx < deckItem.size(); ++dataPointIdx) { if (!deckItem.defaultApplied(dataPointIdx)) setDataPoint(dataPointIdx, dataPointIdx, deckItem); @@ -227,12 +227,12 @@ namespace Opm { } template< typename T > - void GridProperty< T >::loadFromDeckKeyword( std::shared_ptr inputBox, const DeckKeyword& deckKeyword) { - if (inputBox->isGlobal()) + void GridProperty< T >::loadFromDeckKeyword( const Box& inputBox, const DeckKeyword& deckKeyword) { + if (inputBox.isGlobal()) loadFromDeckKeyword( deckKeyword ); else { const auto& deckItem = getDeckItem(deckKeyword); - const std::vector& indexList = inputBox->getIndexList(); + const std::vector& indexList = inputBox.getIndexList(); if (indexList.size() == deckItem.size()) { for (size_t sourceIdx = 0; sourceIdx < indexList.size(); sourceIdx++) { size_t targetIdx = indexList[sourceIdx]; @@ -252,12 +252,12 @@ namespace Opm { } template< typename T > - void GridProperty< T >::copyFrom( const GridProperty< T >& src, std::shared_ptr< const Box > inputBox ) { - if (inputBox->isGlobal()) { + void GridProperty< T >::copyFrom( const GridProperty< T >& src, const Box& inputBox ) { + if (inputBox.isGlobal()) { for (size_t i = 0; i < src.getCartesianSize(); ++i) m_data[i] = src.m_data[i]; } else { - const std::vector& indexList = inputBox->getIndexList(); + const std::vector& indexList = inputBox.getIndexList(); for (size_t i = 0; i < indexList.size(); i++) { size_t targetIndex = indexList[i]; m_data[targetIndex] = src.m_data[targetIndex]; @@ -266,12 +266,12 @@ namespace Opm { } template< typename T > - void GridProperty< T >::scale( T scaleFactor, std::shared_ptr< const Box > inputBox ) { - if (inputBox->isGlobal()) { + void GridProperty< T >::scale( T scaleFactor, const Box& inputBox ) { + if (inputBox.isGlobal()) { for (size_t i = 0; i < m_data.size(); ++i) m_data[i] *= scaleFactor; } else { - const std::vector& indexList = inputBox->getIndexList(); + const std::vector& indexList = inputBox.getIndexList(); for (size_t i = 0; i < indexList.size(); i++) { size_t targetIndex = indexList[i]; m_data[targetIndex] *= scaleFactor; @@ -280,12 +280,12 @@ namespace Opm { } template< typename T > - void GridProperty< T >::add( T shiftValue, std::shared_ptr inputBox ) { - if (inputBox->isGlobal()) { + void GridProperty< T >::add( T shiftValue, const Box& inputBox ) { + if (inputBox.isGlobal()) { for (size_t i = 0; i < m_data.size(); ++i) m_data[i] += shiftValue; } else { - const std::vector& indexList = inputBox->getIndexList(); + const std::vector& indexList = inputBox.getIndexList(); for (size_t i = 0; i < indexList.size(); i++) { size_t targetIndex = indexList[i]; m_data[targetIndex] += shiftValue; @@ -294,11 +294,11 @@ namespace Opm { } template< typename T > - void GridProperty< T >::setScalar( T value, std::shared_ptr< const Box > inputBox ) { - if (inputBox->isGlobal()) { + void GridProperty< T >::setScalar( T value, const Box& inputBox ) { + if (inputBox.isGlobal()) { std::fill(m_data.begin(), m_data.end(), value); } else { - const std::vector& indexList = inputBox->getIndexList(); + const std::vector& indexList = inputBox.getIndexList(); for (size_t i = 0; i < indexList.size(); i++) { size_t targetIndex = indexList[i]; m_data[targetIndex] = value; @@ -320,7 +320,6 @@ namespace Opm { template< typename T > void GridProperty< T >::runPostProcessor() { if( this->m_hasRunPostProcessor ) return; - this->m_hasRunPostProcessor = true; this->m_kwInfo.postProcessor()( m_data ); } @@ -333,11 +332,11 @@ namespace Opm { } template< typename T > - ERT::EclKW GridProperty< T >::getEclKW( std::shared_ptr< const EclipseGrid > grid ) const { - ERT::EclKW eclKW( getKeywordName(), grid->getNumActive() ); + ERT::EclKW GridProperty< T >::getEclKW( const EclipseGrid& grid ) const { + ERT::EclKW eclKW( getKeywordName(), grid.getNumActive() ); size_t activeIndex = 0; for (size_t g = 0; g < getCartesianSize(); g++) { - if (grid->cellActive( g )) { + if (grid.cellActive( g )) { eclKW[activeIndex] = iget(g); activeIndex++; } diff --git a/opm/parser/eclipse/EclipseState/Grid/GridProperty.hpp b/opm/parser/eclipse/EclipseState/Grid/GridProperty.hpp index 06da0cf01..756ef24de 100644 --- a/opm/parser/eclipse/EclipseState/Grid/GridProperty.hpp +++ b/opm/parser/eclipse/EclipseState/Grid/GridProperty.hpp @@ -114,19 +114,19 @@ public: void initMask( T value, std::vector& mask ) const; /** - Due to the convention where it is only neceassary to supply the + Due to the convention where it is only necessary to supply the top layer of the petrophysical properties we can unfortunately not enforce that the number of elements elements in the - deckkeyword equals nx*ny*nz. + DeckKeyword equals nx*ny*nz. */ void loadFromDeckKeyword( const DeckKeyword& ); - void loadFromDeckKeyword( std::shared_ptr, const DeckKeyword& ); + void loadFromDeckKeyword( const Box&, const DeckKeyword& ); - void copyFrom( const GridProperty< T >&, std::shared_ptr< const Box > ); - void scale( T scaleFactor, std::shared_ptr< const Box > ); - void add( T shiftValue, std::shared_ptr< const Box > ); - void setScalar( T value, std::shared_ptr< const Box > ); + void copyFrom( const GridProperty< T >&, const Box& ); + void scale( T scaleFactor, const Box& ); + void add( T shiftValue, const Box& ); + void setScalar( T value, const Box& ); const std::string& getKeywordName() const; const SupportedKeywordInfo& getKeywordInfo() const; @@ -134,7 +134,7 @@ public: void runPostProcessor(); ERT::EclKW getEclKW() const; - ERT::EclKW getEclKW( std::shared_ptr< const EclipseGrid > ) const; + ERT::EclKW getEclKW( const EclipseGrid & ) const; /** Will check that all elements in the property are in the closed @@ -147,7 +147,7 @@ private: const DeckItem& getDeckItem( const DeckKeyword& ); void setDataPoint(size_t sourceIdx, size_t targetIdx, const DeckItem& deckItem); - size_t m_nx,m_ny,m_nz; + size_t m_nx, m_ny, m_nz; SupportedKeywordInfo m_kwInfo; std::vector m_data; bool m_hasRunPostProcessor = false; diff --git a/opm/parser/eclipse/EclipseState/Grid/GridPropertyInitializers.cpp b/opm/parser/eclipse/EclipseState/Grid/GridPropertyInitializers.cpp index 554eac232..0aa526d01 100644 --- a/opm/parser/eclipse/EclipseState/Grid/GridPropertyInitializers.cpp +++ b/opm/parser/eclipse/EclipseState/Grid/GridPropertyInitializers.cpp @@ -1,9 +1,25 @@ +/* + 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 3 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 . + */ + #include #include #include #include -#include +#include #include #include #include @@ -21,39 +37,54 @@ namespace Opm { template< typename T > GridPropertyInitFunction< T >::GridPropertyInitFunction( signature fn, - const Deck& d, - const EclipseState& state ) : - f( fn ), deck( &d ), es( &state ) + const TableManager* tables, + const EclipseGrid* grid, + GridProperties* ig_props, + GridProperties* dg_props) + : + f( fn ), + tm ( tables ), + eg ( grid ), + igp ( ig_props ), + dgp ( dg_props ) {} template< typename T > std::vector< T > GridPropertyInitFunction< T >::operator()( size_t size ) const { if( !this->f ) return std::vector< T >( size, this->constant ); - - return (*this->f)( size, *this->deck, *this->es ); + return (*this->f)( size, this->tm, this->eg, this->igp, this->dgp ); } template< typename T > GridPropertyPostFunction< T >::GridPropertyPostFunction( signature fn, - const Deck& d, - const EclipseState& state ) : - f( fn ), deck( &d ), es( &state ) + const TableManager* tables, + const EclipseGrid* grid, + GridProperties* ig_props, + GridProperties* dg_props) + : + f( fn ), + tm ( tables ), + eg ( grid ), + igp ( ig_props ), + dgp ( dg_props ) {} template< typename T > void GridPropertyPostFunction< T >::operator()( std::vector< T >& values ) const { - if( !this->f ) return; - - return (*this->f)( values, *this->deck, *this->es ); + if (!this->f) + return; + return (*this->f)( values, this->tm, this->eg, this->igp, this->dgp ); } std::vector< double > temperature_lookup( size_t size, - const Deck& deck, - const EclipseState& eclipseState ) { + const TableManager* tables, + const EclipseGrid* grid, + GridProperties* ig_props, + GridProperties* dg_props) { - if( !deck.hasKeyword("EQLNUM") ) { + if( !tables->useEqlnum() ) { /* if values are defaulted in the TEMPI keyword, but no * EQLNUM is specified, you will get NaNs */ @@ -62,15 +93,13 @@ namespace Opm { std::vector< double > values( size, 0 ); - auto tables = eclipseState.getTableManager(); - auto eclipseGrid = eclipseState.getEclipseGrid(); const auto& rtempvdTables = tables->getRtempvdTables(); - const std::vector< int >& eqlNum = eclipseState.getIntGridProperty("EQLNUM")->getData(); + const std::vector< int >& eqlNum = ig_props->getKeyword("EQLNUM").getData(); for (size_t cellIdx = 0; cellIdx < eqlNum.size(); ++ cellIdx) { int cellEquilNum = eqlNum[cellIdx]; const RtempvdTable& rtempvdTable = rtempvdTables.getTable(cellEquilNum); - double cellDepth = std::get<2>(eclipseGrid->getCellCenter(cellIdx)); + double cellDepth = std::get<2>(grid->getCellCenter(cellIdx)); values[cellIdx] = rtempvdTable.evaluate("Temperature", cellDepth); } diff --git a/opm/parser/eclipse/EclipseState/Grid/GridPropertyInitializers.hpp b/opm/parser/eclipse/EclipseState/Grid/GridPropertyInitializers.hpp index 915b3d8ff..32f1a122a 100644 --- a/opm/parser/eclipse/EclipseState/Grid/GridPropertyInitializers.hpp +++ b/opm/parser/eclipse/EclipseState/Grid/GridPropertyInitializers.hpp @@ -28,22 +28,29 @@ */ namespace Opm { -class Deck; -class EclipseState; +class EclipseGrid; +class TableManager; +template class GridProperties; + template< typename T > class GridPropertyInitFunction { public: using signature = std::vector< T >(*)( size_t, - const Deck&, - const EclipseState& + const TableManager*, + const EclipseGrid*, + GridProperties* ig_props, + GridProperties* dg_props ); GridPropertyInitFunction( signature, - const Deck&, - const EclipseState& ); + const TableManager*, + const EclipseGrid*, + GridProperties*, + GridProperties* + ); GridPropertyInitFunction( T ); std::vector< T > operator()( size_t ) const; @@ -51,36 +58,50 @@ template< typename T > private: signature f = nullptr; T constant; - const Deck* deck = nullptr; - const EclipseState* es = nullptr; - }; + const TableManager* tm = nullptr; + const EclipseGrid* eg = nullptr; + GridProperties* igp = nullptr; + GridProperties* dgp = nullptr; + }; template< typename T > class GridPropertyPostFunction { public: using signature = void(*)( std::vector< T >&, - const Deck&, - const EclipseState& + const TableManager*, + const EclipseGrid*, + GridProperties*, + GridProperties* ); GridPropertyPostFunction() = default; GridPropertyPostFunction( signature, - const Deck&, - const EclipseState& ); + const TableManager*, + const EclipseGrid*, + GridProperties*, + GridProperties* + ); void operator()( std::vector< T >& ) const; private: signature f = nullptr; - const Deck* deck = nullptr; - const EclipseState* es = nullptr; + const TableManager* tm = nullptr; + const EclipseGrid* eg = nullptr; + GridProperties* igp = nullptr; + GridProperties* dgp = nullptr; + }; // initialize the TEMPI grid property using the temperature vs depth // table (stemming from the TEMPVD or the RTEMPVD keyword) - std::vector< double > temperature_lookup( size_t, const Deck&, const EclipseState& ); - + // std::vector< double > temperature_lookup( size_t, const EclipseState& ); + std::vector< double > temperature_lookup( size_t, + const TableManager*, + const EclipseGrid*, + GridProperties*, + GridProperties*); } -#endif +#endif // ECLIPSE_GRIDPROPERTY_INITIALIZERS_HPP diff --git a/opm/parser/eclipse/EclipseState/Grid/MULTREGTScanner.cpp b/opm/parser/eclipse/EclipseState/Grid/MULTREGTScanner.cpp index 20f535c45..0f53c3879 100644 --- a/opm/parser/eclipse/EclipseState/Grid/MULTREGTScanner.cpp +++ b/opm/parser/eclipse/EclipseState/Grid/MULTREGTScanner.cpp @@ -126,7 +126,9 @@ namespace Opm { Then it will go through the different regions and looking for interface with the wanted region values. */ - MULTREGTScanner::MULTREGTScanner(std::shared_ptr > cellRegionNumbers, const std::vector< const DeckKeyword* >& keywords , const std::string& defaultRegion ) : + MULTREGTScanner::MULTREGTScanner(const GridProperties& cellRegionNumbers, + const std::vector< const DeckKeyword* >& keywords, + const std::string& defaultRegion ) : m_cellRegionNumbers(cellRegionNumbers) { for (size_t idx = 0; idx < keywords.size(); idx++) @@ -134,7 +136,7 @@ namespace Opm { MULTREGTSearchMap searchPairs; for (std::vector::const_iterator record = m_records.begin(); record != m_records.end(); ++record) { - if (cellRegionNumbers->hasKeyword( record->m_region.getValue())) { + if (cellRegionNumbers.hasKeyword( record->m_region.getValue())) { if (record->m_srcRegion.hasValue() && record->m_targetRegion.hasValue()) { int srcRegion = record->m_srcRegion.getValue(); int targetRegion = record->m_targetRegion.getValue(); @@ -232,11 +234,11 @@ namespace Opm { double MULTREGTScanner::getRegionMultiplier(size_t globalIndex1 , size_t globalIndex2, FaceDir::DirEnum faceDir) const { for (auto iter = m_searchMap.begin(); iter != m_searchMap.end(); iter++) { - std::shared_ptr > region = m_cellRegionNumbers->getKeyword( (*iter).first ); + const Opm::GridProperty& region = m_cellRegionNumbers.getKeyword( (*iter).first ); MULTREGTSearchMap map = (*iter).second; - int regionId1 = region->iget(globalIndex1); - int regionId2 = region->iget(globalIndex2); + int regionId1 = region.iget(globalIndex1); + int regionId2 = region.iget(globalIndex2); std::pair pair{regionId1 , regionId2}; @@ -248,10 +250,10 @@ namespace Opm { const MULTREGTRecord * record = map[pair]; bool applyMultiplier = true; - int i1 = globalIndex1%region->getNX(); - int i2 = globalIndex2%region->getNX(); - int j1 = globalIndex1/region->getNX()%region->getNY(); - int j2 = globalIndex2/region->getNX()%region->getNY(); + int i1 = globalIndex1 % region.getNX(); + int i2 = globalIndex2 % region.getNX(); + int j1 = globalIndex1 / region.getNX() % region.getNY(); + int j2 = globalIndex2 / region.getNX() % region.getNY(); if (record->m_nncBehaviour == MULTREGT::NNC){ applyMultiplier = true; diff --git a/opm/parser/eclipse/EclipseState/Grid/MULTREGTScanner.hpp b/opm/parser/eclipse/EclipseState/Grid/MULTREGTScanner.hpp index 35c5d4e4f..097454879 100644 --- a/opm/parser/eclipse/EclipseState/Grid/MULTREGTScanner.hpp +++ b/opm/parser/eclipse/EclipseState/Grid/MULTREGTScanner.hpp @@ -69,7 +69,9 @@ namespace Opm { class MULTREGTScanner { public: - MULTREGTScanner(std::shared_ptr > cellRegionNumbers, const std::vector< const DeckKeyword* >& keywords, const std::string& defaultRegion); + MULTREGTScanner(const GridProperties& cellRegionNumbers, + const std::vector< const DeckKeyword* >& keywords, + const std::string& defaultRegion); double getRegionMultiplier(size_t globalCellIdx1, size_t globalCellIdx2, FaceDir::DirEnum faceDir) const; private: @@ -77,7 +79,7 @@ namespace Opm { void assertKeywordSupported(const DeckKeyword& deckKeyword, const std::string& defaultRegion); std::vector< MULTREGTRecord > m_records; std::map m_searchMap; - std::shared_ptr > m_cellRegionNumbers; + const GridProperties& m_cellRegionNumbers; }; } diff --git a/opm/parser/eclipse/EclipseState/Grid/SatfuncPropertyInitializers.cpp b/opm/parser/eclipse/EclipseState/Grid/SatfuncPropertyInitializers.cpp index 4f54d9376..3df8df263 100644 --- a/opm/parser/eclipse/EclipseState/Grid/SatfuncPropertyInitializers.cpp +++ b/opm/parser/eclipse/EclipseState/Grid/SatfuncPropertyInitializers.cpp @@ -1,6 +1,23 @@ +/* + 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 3 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 . +*/ + + #include -#include +#include #include #include #include @@ -24,18 +41,18 @@ namespace Opm { * can be used to enter relperm and capillary pressure tables. * * If SWOF and SGOF are specified in the deck it return I - * If SWFN, SGFN and SOF3 are specified in the deck it return I + * If SWFN, SGFN and SOF3 are specified in the deck it return II * If keywords are missing or mixed, an error is given. */ enum class SatfuncFamily { none = 0, I = 1, II = 2 }; - static SatfuncFamily getSaturationFunctionFamily( const TableManager& tm ) { - const TableContainer& swofTables = tm.getSwofTables(); - const TableContainer& sgofTables = tm.getSgofTables(); - const TableContainer& slgofTables = tm.getSlgofTables(); - const TableContainer& sof3Tables = tm.getSof3Tables(); - const TableContainer& swfnTables = tm.getSwfnTables(); - const TableContainer& sgfnTables = tm.getSgfnTables(); + static SatfuncFamily getSaturationFunctionFamily( const TableManager* tm ) { + const TableContainer& swofTables = tm->getSwofTables(); + const TableContainer& sgofTables = tm->getSgofTables(); + const TableContainer& slgofTables = tm->getSlgofTables(); + const TableContainer& sof3Tables = tm->getSof3Tables(); + const TableContainer& swfnTables = tm->getSwfnTables(); + const TableContainer& sgfnTables = tm->getSgfnTables(); bool family1 = (!sgofTables.empty() || !slgofTables.empty()) && !swofTables.empty(); @@ -59,10 +76,10 @@ namespace Opm { enum class limit { min, max }; - static std::vector< double > findMinWaterSaturation( const TableManager& tm ) { - const auto num_tables = tm.getTabdims()->getNumSatTables(); - const auto& swofTables = tm.getSwofTables(); - const auto& swfnTables = tm.getSwfnTables(); + static std::vector< double > findMinWaterSaturation( const TableManager* tm ) { + const auto num_tables = tm->getTabdims()->getNumSatTables(); + const auto& swofTables = tm->getSwofTables(); + const auto& swfnTables = tm->getSwfnTables(); const auto famI = [&swofTables]( int i ) { return swofTables.getTable< SwofTable >( i ).getSwColumn().front(); @@ -80,10 +97,10 @@ namespace Opm { } } - static std::vector< double > findMaxWaterSaturation( const TableManager& tm ) { - const auto num_tables = tm.getTabdims()->getNumSatTables(); - const auto& swofTables = tm.getSwofTables(); - const auto& swfnTables = tm.getSwfnTables(); + static std::vector< double > findMaxWaterSaturation( const TableManager* tm ) { + const auto num_tables = tm->getTabdims()->getNumSatTables(); + const auto& swofTables = tm->getSwofTables(); + const auto& swfnTables = tm->getSwfnTables(); const auto famI = [&swofTables]( int i ) { return swofTables.getTable< SwofTable >( i ).getSwColumn().back(); @@ -101,11 +118,11 @@ namespace Opm { } } - static std::vector< double > findMinGasSaturation( const TableManager& tm ) { - const auto num_tables = tm.getTabdims()->getNumSatTables(); - const auto& sgofTables = tm.getSgofTables(); - const auto& slgofTables = tm.getSlgofTables(); - const auto& sgfnTables = tm.getSgfnTables(); + static std::vector< double > findMinGasSaturation( const TableManager* tm ) { + const auto num_tables = tm->getTabdims()->getNumSatTables(); + const auto& sgofTables = tm->getSgofTables(); + const auto& slgofTables = tm->getSlgofTables(); + const auto& sgfnTables = tm->getSgfnTables(); const auto famI_sgof = [&sgofTables]( int i ) { return sgofTables.getTable< SgofTable >( i ).getSgColumn().front(); @@ -141,11 +158,11 @@ namespace Opm { } - static std::vector< double > findMaxGasSaturation( const TableManager& tm ) { - const auto num_tables = tm.getTabdims()->getNumSatTables(); - const auto& sgofTables = tm.getSgofTables(); - const auto& slgofTables = tm.getSlgofTables(); - const auto& sgfnTables = tm.getSgfnTables(); + static std::vector< double > findMaxGasSaturation( const TableManager* tm ) { + const auto num_tables = tm->getTabdims()->getNumSatTables(); + const auto& sgofTables = tm->getSgofTables(); + const auto& slgofTables = tm->getSlgofTables(); + const auto& sgfnTables = tm->getSgfnTables(); const auto famI_sgof = [&sgofTables]( int i ) { return sgofTables.getTable< SgofTable >( i ).getSgColumn().back(); @@ -208,11 +225,11 @@ namespace Opm { return table.getSwColumn()[ index - 1 ]; } - static std::vector< double > findCriticalWater( const TableManager& tm ) { + static std::vector< double > findCriticalWater( const TableManager* tm ) { - const auto num_tables = tm.getTabdims()->getNumSatTables(); - const auto& swofTables = tm.getSwofTables(); - const auto& swfnTables = tm.getSwfnTables(); + const auto num_tables = tm->getTabdims()->getNumSatTables(); + const auto& swofTables = tm->getSwofTables(); + const auto& swfnTables = tm->getSwfnTables(); const auto famI = [&swofTables]( int i ) { return critical_water( swofTables.getTable< SwofTable >( i ) ); @@ -251,12 +268,12 @@ namespace Opm { return slgofTable.getSlColumn()[ index - 1 ]; } - static std::vector< double > findCriticalGas( const TableManager& tm ) { + static std::vector< double > findCriticalGas( const TableManager* tm ) { - const auto num_tables = tm.getTabdims()->getNumSatTables(); - const auto& sgfnTables = tm.getSgfnTables(); - const auto& sgofTables = tm.getSgofTables(); - const auto& slgofTables = tm.getSlgofTables(); + const auto num_tables = tm->getTabdims()->getNumSatTables(); + const auto& sgfnTables = tm->getSgfnTables(); + const auto& sgofTables = tm->getSgofTables(); + const auto& slgofTables = tm->getSlgofTables(); const auto famI_sgof = [&sgofTables]( int i ) { return critical_gas( sgofTables.getTable< SgofTable >( i ) ); @@ -311,10 +328,10 @@ namespace Opm { return sof3Table.getSoColumn()[ index - 1 ]; } - static std::vector< double > findCriticalOilWater( const TableManager& tm ) { - const auto num_tables = tm.getTabdims()->getNumSatTables(); - const auto& swofTables = tm.getSwofTables(); - const auto& sof3Tables= tm.getSof3Tables(); + static std::vector< double > findCriticalOilWater( const TableManager* tm ) { + const auto num_tables = tm->getTabdims()->getNumSatTables(); + const auto& swofTables = tm->getSwofTables(); + const auto& sof3Tables= tm->getSof3Tables(); const auto famI = [&swofTables]( int i ) { return critical_oil_water( swofTables.getTable< SwofTable >( i ) ); @@ -361,12 +378,12 @@ namespace Opm { } - static std::vector< double > findCriticalOilGas( const TableManager& tm ) { + static std::vector< double > findCriticalOilGas( const TableManager* tm ) { - const auto num_tables = tm.getTabdims()->getNumSatTables(); - const auto& sgofTables = tm.getSgofTables(); - const auto& slgofTables = tm.getSlgofTables(); - const auto& sof3Tables = tm.getSof3Tables(); + const auto num_tables = tm->getTabdims()->getNumSatTables(); + const auto& sgofTables = tm->getSgofTables(); + const auto& slgofTables = tm->getSlgofTables(); + const auto& sof3Tables = tm->getSof3Tables(); const auto famI_sgof = [&sgofTables]( int i ) { return critical_oil_gas( sgofTables.getTable< SgofTable >( i ) ); @@ -399,10 +416,10 @@ namespace Opm { } } - static std::vector< double > findMaxKrg( const TableManager& tm ) { - const auto num_tables = tm.getTabdims()->getNumSatTables(); - const auto& sgofTables = tm.getSgofTables(); - const auto& sgfnTables = tm.getSgfnTables(); + static std::vector< double > findMaxKrg( const TableManager* tm ) { + const auto num_tables = tm->getTabdims()->getNumSatTables(); + const auto& sgofTables = tm->getSgofTables(); + const auto& sgfnTables = tm->getSgfnTables(); const auto& famI = [&sgofTables]( int i ) { return sgofTables.getTable< SgofTable >( i ).getKrgColumn().back(); @@ -422,10 +439,10 @@ namespace Opm { } } - static std::vector< double > findKrgr( const TableManager& tm ) { - const auto num_tables = tm.getTabdims()->getNumSatTables(); - const auto& sgofTables = tm.getSgofTables(); - const auto& sgfnTables = tm.getSgfnTables(); + static std::vector< double > findKrgr( const TableManager* tm ) { + const auto num_tables = tm->getTabdims()->getNumSatTables(); + const auto& sgofTables = tm->getSgofTables(); + const auto& sgfnTables = tm->getSgfnTables(); const auto& famI = [&sgofTables]( int i ) { return sgofTables.getTable< SgofTable >( i ).getKrgColumn().front(); @@ -445,10 +462,10 @@ namespace Opm { } } - static std::vector< double > findKrwr( const TableManager& tm ) { - const auto num_tables = tm.getTabdims()->getNumSatTables(); - const auto& swofTables = tm.getSwofTables(); - const auto& swfnTables = tm.getSwfnTables(); + static std::vector< double > findKrwr( const TableManager* tm ) { + const auto num_tables = tm->getTabdims()->getNumSatTables(); + const auto& swofTables = tm->getSwofTables(); + const auto& swfnTables = tm->getSwfnTables(); const auto& famI = [&swofTables]( int i ) { return swofTables.getTable< SwofTable >( i ).getKrwColumn().front(); @@ -468,10 +485,10 @@ namespace Opm { } } - static std::vector< double > findKrorw( const TableManager& tm ) { - const auto num_tables = tm.getTabdims()->getNumSatTables(); - const auto& swofTables = tm.getSwofTables(); - const auto& sof3Tables = tm.getSof3Tables(); + static std::vector< double > findKrorw( const TableManager* tm ) { + const auto num_tables = tm->getTabdims()->getNumSatTables(); + const auto& swofTables = tm->getSwofTables(); + const auto& sof3Tables = tm->getSof3Tables(); const auto& famI = [&swofTables]( int i ) { const auto& swofTable = swofTables.getTable< SwofTable >( i ); @@ -502,10 +519,10 @@ namespace Opm { } } - static std::vector< double > findKrorg( const TableManager& tm ) { - const auto num_tables = tm.getTabdims()->getNumSatTables(); - const auto& sgofTables = tm.getSgofTables(); - const auto& sof3Tables = tm.getSof3Tables(); + static std::vector< double > findKrorg( const TableManager* tm ) { + const auto num_tables = tm->getTabdims()->getNumSatTables(); + const auto& sgofTables = tm->getSgofTables(); + const auto& sof3Tables = tm->getSof3Tables(); const auto& famI = [&sgofTables]( int i ) { const auto& sgofTable = sgofTables.getTable< SgofTable >( i ); @@ -545,10 +562,10 @@ namespace Opm { * is not taken into account which means that some twophase quantity must be * scaled. */ - static std::vector< double > findMaxPcog( const TableManager& tm ) { - const auto num_tables = tm.getTabdims()->getNumSatTables(); - const auto& sgofTables = tm.getSgofTables(); - const auto& sgfnTables = tm.getSgfnTables(); + static std::vector< double > findMaxPcog( const TableManager* tm ) { + const auto num_tables = tm->getTabdims()->getNumSatTables(); + const auto& sgofTables = tm->getSgofTables(); + const auto& sgfnTables = tm->getSgfnTables(); const auto& famI = [&sgofTables]( int i ) { return sgofTables.getTable< SgofTable >( i ).getPcogColumn().front(); @@ -568,10 +585,10 @@ namespace Opm { } } - static std::vector< double > findMaxPcow( const TableManager& tm ) { - const auto num_tables = tm.getTabdims()->getNumSatTables(); - const auto& swofTables = tm.getSwofTables(); - const auto& swfnTables = tm.getSwfnTables(); + static std::vector< double > findMaxPcow( const TableManager* tm ) { + const auto num_tables = tm->getTabdims()->getNumSatTables(); + const auto& swofTables = tm->getSwofTables(); + const auto& swfnTables = tm->getSwfnTables(); const auto& famI = [&swofTables]( int i ) { return swofTables.getTable< SwofTable >( i ).getPcowColumn().front(); @@ -591,10 +608,10 @@ namespace Opm { } } - static std::vector< double > findMaxKro( const TableManager& tm ) { - const auto num_tables = tm.getTabdims()->getNumSatTables(); - const auto& swofTables = tm.getSwofTables(); - const auto& sof3Tables = tm.getSof3Tables(); + static std::vector< double > findMaxKro( const TableManager* tm ) { + const auto num_tables = tm->getTabdims()->getNumSatTables(); + const auto& swofTables = tm->getSwofTables(); + const auto& sof3Tables = tm->getSof3Tables(); const auto& famI = [&swofTables]( int i ) { return swofTables.getTable< SwofTable >( i ).getKrowColumn().front(); @@ -614,10 +631,10 @@ namespace Opm { } } - static std::vector< double > findMaxKrw( const TableManager& tm ) { - const auto num_tables = tm.getTabdims()->getNumSatTables(); - const auto& swofTables = tm.getSwofTables(); - const auto& swfnTables = tm.getSwfnTables(); + static std::vector< double > findMaxKrw( const TableManager* tm ) { + const auto num_tables = tm->getTabdims()->getNumSatTables(); + const auto& swofTables = tm->getSwofTables(); + const auto& swfnTables = tm->getSwfnTables(); const auto& famI = [&swofTables]( int i ) { return swofTables.getTable< SwofTable >( i ).getKrwColumn().back(); @@ -662,37 +679,38 @@ namespace Opm { } static std::vector< double > satnumApply( size_t size, - const std::string& columnName, - const std::vector< double >& fallbackValues, - const Deck& m_deck, - const EclipseState& m_eclipseState, - bool useOneMinusTableValue ) { + const std::string& columnName, + const std::vector< double >& fallbackValues, + const TableManager* tableManager, + const EclipseGrid* eclipseGrid, + GridProperties* intGridProperties, + GridProperties* doubleGridProperties, + bool useOneMinusTableValue ) { + std::vector< double > values( size, 0 ); + auto tabdims = tableManager->getTabdims(); - auto eclipseGrid = m_eclipseState.getEclipseGrid(); - auto tables = m_eclipseState.getTableManager(); - auto tabdims = tables->getTabdims(); - auto satnum = m_eclipseState.getIntGridProperty("SATNUM"); - auto endnum = m_eclipseState.getIntGridProperty("ENDNUM"); + auto& satnum = intGridProperties->getKeyword("SATNUM"); + auto& endnum = intGridProperties->getKeyword("ENDNUM"); int numSatTables = tabdims->getNumSatTables(); - satnum->checkLimits( 1 , numSatTables ); + satnum.checkLimits( 1 , numSatTables ); // All table lookup assumes three-phase model - assert( m_eclipseState.getNumPhases() == 3 ); + assert( tableManager->getNumPhases() == 3 ); // acctually assign the defaults. if the ENPVD keyword was specified in the deck, // this currently cannot be done because we would need the Z-coordinate of the // cell and we would need to know how the simulator wants to interpolate between // sampling points. Both of these are outside the scope of opm-parser, so we just // assign a NaN in this case... - const bool useEnptvd = m_deck.hasKeyword("ENPTVD"); - const auto& enptvdTables = tables->getEnptvdTables(); + const bool useEnptvd = tableManager->useEnptvd(); + const auto& enptvdTables = tableManager->getEnptvdTables(); for( size_t cellIdx = 0; cellIdx < eclipseGrid->getCartesianSize(); cellIdx++ ) { - int satTableIdx = satnum->iget( cellIdx ) - 1; - int endNum = endnum->iget( cellIdx ) - 1; + int satTableIdx = satnum.iget( cellIdx ) - 1; + int endNum = endnum.iget( cellIdx ) - 1; double cellDepth = std::get< 2 >( eclipseGrid->getCellCenter( cellIdx ) ); @@ -708,33 +726,33 @@ namespace Opm { } static std::vector< double > imbnumApply( size_t size, - const std::string& columnName, - const std::vector< double >& fallBackValues, - const Deck& m_deck, - const EclipseState& m_eclipseState, - bool useOneMinusTableValue ) { + const std::string& columnName, + const std::vector< double >& fallBackValues, + const TableManager* tableManager, + const EclipseGrid* eclipseGrid, + GridProperties* intGridProperties, + GridProperties* doubleGridProperties, + bool useOneMinusTableValue ) { std::vector< double > values( size, 0 ); - auto eclipseGrid = m_eclipseState.getEclipseGrid(); - auto tables = m_eclipseState.getTableManager(); - auto imbnum = m_eclipseState.getIntGridProperty("IMBNUM"); - auto endnum = m_eclipseState.getIntGridProperty("ENDNUM"); + auto& imbnum = intGridProperties->getKeyword("IMBNUM"); + auto& endnum = intGridProperties->getKeyword("ENDNUM"); - auto tabdims = tables->getTabdims(); + auto tabdims = tableManager->getTabdims(); const int numSatTables = tabdims->getNumSatTables(); - imbnum->checkLimits( 1 , numSatTables ); + imbnum.checkLimits( 1 , numSatTables ); // acctually assign the defaults. if the ENPVD keyword was specified in the deck, // this currently cannot be done because we would need the Z-coordinate of the // cell and we would need to know how the simulator wants to interpolate between // sampling points. Both of these are outside the scope of opm-parser, so we just // assign a NaN in this case... - const bool useImptvd = m_deck.hasKeyword("IMPTVD"); - const TableContainer& imptvdTables = tables->getImptvdTables(); + const bool useImptvd = tableManager->useImptvd(); + const TableContainer& imptvdTables = tableManager->getImptvdTables(); for( size_t cellIdx = 0; cellIdx < eclipseGrid->getCartesianSize(); cellIdx++ ) { - int imbTableIdx = imbnum->iget( cellIdx ) - 1; - int endNum = endnum->iget( cellIdx ) - 1; + int imbTableIdx = imbnum.iget( cellIdx ) - 1; + int endNum = endnum.iget( cellIdx ) - 1; double cellDepth = std::get< 2 >( eclipseGrid->getCellCenter( cellIdx ) ); values[cellIdx] = selectValue(imptvdTables, @@ -748,174 +766,378 @@ namespace Opm { return values; } - std::vector< double > SGLEndpoint( size_t size, const Deck& deck, const EclipseState& es ) { - const auto min_gas = findMinGasSaturation( *es.getTableManager() ); - return satnumApply( size, "SGCO", min_gas, deck, es, false ); + std::vector< double > SGLEndpoint( size_t size, + const TableManager * tableManager, + const EclipseGrid* eclipseGrid, + GridProperties* intGridProperties, + GridProperties* doubleGridProperties) + { + const auto min_gas = findMinGasSaturation( tableManager ); + return satnumApply( size, "SGCO", min_gas, tableManager, eclipseGrid, + intGridProperties, doubleGridProperties, false ); } - std::vector< double > ISGLEndpoint( size_t size, const Deck& deck, const EclipseState& es ) { - const auto min_gas = findMinGasSaturation( *es.getTableManager() ); - return imbnumApply( size, "SGCO", min_gas, deck, es, false ); + std::vector< double > ISGLEndpoint( size_t size, + const TableManager * tableManager, + const EclipseGrid* eclipseGrid, + GridProperties* intGridProperties, + GridProperties* doubleGridProperties) + { + const auto min_gas = findMinGasSaturation( tableManager ); + return imbnumApply( size, "SGCO", min_gas, tableManager, eclipseGrid, + intGridProperties, doubleGridProperties, false ); } - std::vector< double > SGUEndpoint( size_t size, const Deck& deck, const EclipseState& es ) { - const auto max_gas = findMaxGasSaturation( *es.getTableManager() ); - return satnumApply( size, "SGMAX", max_gas, deck, es, false ); + std::vector< double > SGUEndpoint( size_t size, + const TableManager * tableManager, + const EclipseGrid* eclipseGrid, + GridProperties* intGridProperties, + GridProperties* doubleGridProperties) + { + const auto max_gas = findMaxGasSaturation( tableManager ); + return satnumApply( size, "SGMAX", max_gas, tableManager, eclipseGrid, + intGridProperties, doubleGridProperties, false ); } - std::vector< double > ISGUEndpoint( size_t size, const Deck& deck, const EclipseState& es ) { - const auto max_gas = findMaxGasSaturation( *es.getTableManager() ); - return imbnumApply( size, "SGMAX", max_gas, deck, es, false ); + std::vector< double > ISGUEndpoint( size_t size, + const TableManager * tableManager, + const EclipseGrid* eclipseGrid, + GridProperties* intGridProperties, + GridProperties* doubleGridProperties) + { + const auto max_gas = findMaxGasSaturation( tableManager ); + return imbnumApply( size, "SGMAX", max_gas, tableManager, eclipseGrid, + intGridProperties, doubleGridProperties, false ); } - std::vector< double > SWLEndpoint( size_t size, const Deck& deck, const EclipseState& es ) { - const auto min_water = findMinWaterSaturation( *es.getTableManager() ); - return satnumApply( size, "SWCO", min_water, deck, es, false ); + std::vector< double > SWLEndpoint( size_t size, + const TableManager * tableManager, + const EclipseGrid* eclipseGrid, + GridProperties* intGridProperties, + GridProperties* doubleGridProperties) + { + const auto min_water = findMinWaterSaturation( tableManager ); + return satnumApply( size, "SWCO", min_water, tableManager, eclipseGrid, + intGridProperties, doubleGridProperties, false ); } - std::vector< double > ISWLEndpoint( size_t size, const Deck& deck, const EclipseState& es ) { - const auto min_water = findMinWaterSaturation( *es.getTableManager() ); - return imbnumApply( size, "SWCO", min_water, deck, es, false ); + std::vector< double > ISWLEndpoint( size_t size, + const TableManager * tableManager, + const EclipseGrid * eclipseGrid, + GridProperties* intGridProperties, + GridProperties* doubleGridProperties) + { + const auto min_water = findMinWaterSaturation( tableManager ); + return imbnumApply( size, "SWCO", min_water, tableManager, eclipseGrid, + intGridProperties, doubleGridProperties, false ); } - std::vector< double > SWUEndpoint( size_t size, const Deck& deck, const EclipseState& es ) { - const auto max_water = findMaxWaterSaturation( *es.getTableManager() ); - return satnumApply( size, "SWMAX", max_water, deck, es, true ); + std::vector< double > SWUEndpoint( size_t size, + const TableManager * tableManager, + const EclipseGrid * eclipseGrid, + GridProperties* intGridProperties, + GridProperties* doubleGridProperties) + { + const auto max_water = findMaxWaterSaturation( tableManager ); + return satnumApply( size, "SWMAX", max_water, tableManager, eclipseGrid, + intGridProperties, doubleGridProperties, true ); } - std::vector< double > ISWUEndpoint( size_t size, const Deck& deck, const EclipseState& es ) { - const auto max_water = findMaxWaterSaturation( *es.getTableManager() ); - return imbnumApply( size, "SWMAX", max_water, deck, es, true); + std::vector< double > ISWUEndpoint( size_t size, + const TableManager * tableManager, + const EclipseGrid * eclipseGrid, + GridProperties* intGridProperties, + GridProperties* doubleGridProperties) + { + const auto max_water = findMaxWaterSaturation( tableManager ); + return imbnumApply( size, "SWMAX", max_water, tableManager, eclipseGrid, + intGridProperties, doubleGridProperties, true); } - std::vector< double > SGCREndpoint( size_t size, const Deck& deck, const EclipseState& es ) { - const auto crit_gas = findCriticalGas( *es.getTableManager() ); - return satnumApply( size, "SGCRIT", crit_gas, deck, es, false ); + std::vector< double > SGCREndpoint( size_t size, + const TableManager * tableManager, + const EclipseGrid * eclipseGrid, + GridProperties* intGridProperties, + GridProperties* doubleGridProperties) + { + const auto crit_gas = findCriticalGas( tableManager ); + return satnumApply( size, "SGCRIT", crit_gas, tableManager, eclipseGrid, + intGridProperties, doubleGridProperties, false ); } - std::vector< double > ISGCREndpoint( size_t size, const Deck& deck, const EclipseState& es ) { - const auto crit_gas = findCriticalGas( *es.getTableManager() ); - return imbnumApply( size, "SGCRIT", crit_gas, deck, es, false ); + std::vector< double > ISGCREndpoint( size_t size, + const TableManager * tableManager, + const EclipseGrid * eclipseGrid, + GridProperties* intGridProperties, + GridProperties* doubleGridProperties) + { + const auto crit_gas = findCriticalGas( tableManager ); + return imbnumApply( size, "SGCRIT", crit_gas, tableManager, eclipseGrid, + intGridProperties, doubleGridProperties, false ); } - std::vector< double > SOWCREndpoint( size_t size, const Deck& deck, const EclipseState& es ) { - const auto oil_water = findCriticalOilWater( *es.getTableManager() ); - return satnumApply( size, "SOWCRIT", oil_water, deck, es, false ); + std::vector< double > SOWCREndpoint( size_t size, + const TableManager * tableManager, + const EclipseGrid * eclipseGrid, + GridProperties* intGridProperties, + GridProperties* doubleGridProperties) + { + const auto oil_water = findCriticalOilWater( tableManager ); + return satnumApply( size, "SOWCRIT", oil_water, tableManager, eclipseGrid, + intGridProperties, doubleGridProperties, false ); } - std::vector< double > ISOWCREndpoint( size_t size, const Deck& deck, const EclipseState& es ) { - const auto oil_water = findCriticalOilWater( *es.getTableManager() ); - return imbnumApply( size, "SOWCRIT", oil_water, deck, es, false ); + std::vector< double > ISOWCREndpoint( size_t size, + const TableManager * tableManager, + const EclipseGrid * eclipseGrid, + GridProperties* intGridProperties, + GridProperties* doubleGridProperties +) + { + const auto oil_water = findCriticalOilWater( tableManager ); + return imbnumApply( size, "SOWCRIT", oil_water, tableManager, eclipseGrid, + intGridProperties, doubleGridProperties, false ); } - std::vector< double > SOGCREndpoint( size_t size, const Deck& deck, const EclipseState& es ) { - const auto crit_oil_gas = findCriticalOilGas( *es.getTableManager() ); - return satnumApply( size, "SOGCRIT", crit_oil_gas, deck, es, false ); + std::vector< double > SOGCREndpoint( size_t size, + const TableManager * tableManager, + const EclipseGrid * eclipseGrid, + GridProperties* intGridProperties, + GridProperties* doubleGridProperties) + { + const auto crit_oil_gas = findCriticalOilGas( tableManager ); + return satnumApply( size, "SOGCRIT", crit_oil_gas, tableManager, eclipseGrid, + intGridProperties, doubleGridProperties, false ); } - std::vector< double > ISOGCREndpoint( size_t size, const Deck& deck, const EclipseState& es ) { - const auto crit_oil_gas = findCriticalOilGas( *es.getTableManager() ); - return imbnumApply( size, "SOGCRIT", crit_oil_gas, deck, es, false ); + std::vector< double > ISOGCREndpoint( size_t size, + const TableManager * tableManager, + const EclipseGrid * eclipseGrid, + GridProperties* intGridProperties, + GridProperties* doubleGridProperties) + { + const auto crit_oil_gas = findCriticalOilGas( tableManager ); + return imbnumApply( size, "SOGCRIT", crit_oil_gas, tableManager, eclipseGrid, + intGridProperties, doubleGridProperties, false ); } - std::vector< double > SWCREndpoint( size_t size, const Deck& deck, const EclipseState& es ) { - const auto crit_water = findCriticalWater( *es.getTableManager() ); - return satnumApply( size, "SWCRIT", crit_water, deck, es, false ); + std::vector< double > SWCREndpoint( size_t size, + const TableManager * tableManager, + const EclipseGrid * eclipseGrid, + GridProperties* intGridProperties, + GridProperties* doubleGridProperties) + { + const auto crit_water = findCriticalWater( tableManager ); + return satnumApply( size, "SWCRIT", crit_water, tableManager, eclipseGrid, + intGridProperties, doubleGridProperties, false ); } - std::vector< double > ISWCREndpoint( size_t size, const Deck& deck, const EclipseState& es ) { - const auto crit_water = findCriticalWater( *es.getTableManager() ); - return imbnumApply( size, "SWCRIT", crit_water, deck, es, false ); + std::vector< double > ISWCREndpoint( size_t size, + const TableManager * tableManager, + const EclipseGrid * eclipseGrid, + GridProperties* intGridProperties, + GridProperties* doubleGridProperties) + { + const auto crit_water = findCriticalWater( tableManager ); + return imbnumApply( size, "SWCRIT", crit_water, tableManager, eclipseGrid, + intGridProperties, doubleGridProperties, false ); } - std::vector< double > PCWEndpoint( size_t size, const Deck& deck, const EclipseState& es ) { - const auto max_pcow = findMaxPcow( *es.getTableManager() ); - return satnumApply( size, "PCW", max_pcow, deck, es, false ); + std::vector< double > PCWEndpoint( size_t size, + const TableManager * tableManager, + const EclipseGrid * eclipseGrid, + GridProperties* intGridProperties, + GridProperties* doubleGridProperties) + { + const auto max_pcow = findMaxPcow( tableManager ); + return satnumApply( size, "PCW", max_pcow, tableManager, eclipseGrid, + intGridProperties, doubleGridProperties, false ); } - std::vector< double > IPCWEndpoint( size_t size, const Deck& deck, const EclipseState& es ) { - const auto max_pcow = findMaxPcow( *es.getTableManager() ); - return imbnumApply( size, "IPCW", max_pcow, deck, es, false ); + std::vector< double > IPCWEndpoint( size_t size, + const TableManager * tableManager, + const EclipseGrid * eclipseGrid, + GridProperties* intGridProperties, + GridProperties* doubleGridProperties) + { + const auto max_pcow = findMaxPcow( tableManager ); + return imbnumApply( size, "IPCW", max_pcow, tableManager, eclipseGrid, + intGridProperties, doubleGridProperties, false ); } - std::vector< double > PCGEndpoint( size_t size, const Deck& deck, const EclipseState& es ) { - const auto max_pcog = findMaxPcog( *es.getTableManager() ); - return satnumApply( size, "PCG", max_pcog, deck, es, false ); + std::vector< double > PCGEndpoint( size_t size, + const TableManager * tableManager, + const EclipseGrid * eclipseGrid, + GridProperties* intGridProperties, + GridProperties* doubleGridProperties) + { + const auto max_pcog = findMaxPcog( tableManager ); + return satnumApply( size, "PCG", max_pcog, tableManager, eclipseGrid, + intGridProperties, doubleGridProperties, false ); } - std::vector< double > IPCGEndpoint( size_t size, const Deck& deck, const EclipseState& es ) { - const auto max_pcog = findMaxPcog( *es.getTableManager() ); - return imbnumApply( size, "IPCG", max_pcog, deck, es, false ); + std::vector< double > IPCGEndpoint( size_t size, + const TableManager * tableManager, + const EclipseGrid * eclipseGrid, + GridProperties* intGridProperties, + GridProperties* doubleGridProperties) + { + const auto max_pcog = findMaxPcog( tableManager ); + return imbnumApply( size, "IPCG", max_pcog, tableManager, eclipseGrid, + intGridProperties, doubleGridProperties, false ); } - std::vector< double > KRWEndpoint( size_t size, const Deck& deck, const EclipseState& es ) { - const auto max_krw = findMaxKrw( *es.getTableManager() ); - return satnumApply( size, "KRW", max_krw, deck, es, false ); + std::vector< double > KRWEndpoint( size_t size, + const TableManager * tableManager, + const EclipseGrid * eclipseGrid, + GridProperties* intGridProperties, + GridProperties* doubleGridProperties) + { + const auto max_krw = findMaxKrw( tableManager ); + return satnumApply( size, "KRW", max_krw, tableManager, eclipseGrid, + intGridProperties, doubleGridProperties, false ); } - std::vector< double > IKRWEndpoint( size_t size, const Deck& deck, const EclipseState& es ) { - const auto krwr = findKrwr( *es.getTableManager() ); - return imbnumApply( size, "IKRW", krwr, deck, es, false ); + std::vector< double > IKRWEndpoint( size_t size, + const TableManager * tableManager, + const EclipseGrid * eclipseGrid, + GridProperties* intGridProperties, + GridProperties* doubleGridProperties) + { + const auto krwr = findKrwr( tableManager ); + return imbnumApply( size, "IKRW", krwr, tableManager, eclipseGrid, + intGridProperties, doubleGridProperties, false ); } - std::vector< double > KRWREndpoint( size_t size, const Deck& deck, const EclipseState& es ) { - const auto krwr = findKrwr( *es.getTableManager() ); - return satnumApply( size, "KRWR", krwr, deck, es, false ); + std::vector< double > KRWREndpoint( size_t size, + const TableManager * tableManager, + const EclipseGrid * eclipseGrid, + GridProperties* intGridProperties, + GridProperties* doubleGridProperties) + { + const auto krwr = findKrwr( tableManager ); + return satnumApply( size, "KRWR", krwr, tableManager, eclipseGrid, + intGridProperties, doubleGridProperties, false ); } - std::vector< double > IKRWREndpoint( size_t size, const Deck& deck, const EclipseState& es ) { - const auto krwr = findKrwr( *es.getTableManager() ); - return imbnumApply( size, "IKRWR", krwr, deck, es, false ); + std::vector< double > IKRWREndpoint( size_t size, + const TableManager * tableManager, + const EclipseGrid * eclipseGrid, + GridProperties* intGridProperties, + GridProperties* doubleGridProperties) + { + const auto krwr = findKrwr( tableManager ); + return imbnumApply( size, "IKRWR", krwr, tableManager, eclipseGrid, + intGridProperties, doubleGridProperties, false ); } - std::vector< double > KROEndpoint( size_t size, const Deck& deck, const EclipseState& es ) { - const auto max_kro = findMaxKro( *es.getTableManager() ); - return satnumApply( size, "KRO", max_kro, deck, es, false ); + std::vector< double > KROEndpoint( size_t size, + const TableManager * tableManager, + const EclipseGrid * eclipseGrid, + GridProperties* intGridProperties, + GridProperties* doubleGridProperties) + { + const auto max_kro = findMaxKro( tableManager ); + return satnumApply( size, "KRO", max_kro, tableManager, eclipseGrid, + intGridProperties, doubleGridProperties, false ); } - std::vector< double > IKROEndpoint( size_t size, const Deck& deck, const EclipseState& es ) { - const auto max_kro = findMaxKro( *es.getTableManager() ); - return imbnumApply( size, "IKRO", max_kro, deck, es, false ); + std::vector< double > IKROEndpoint( size_t size, + const TableManager * tableManager, + const EclipseGrid * eclipseGrid, + GridProperties* intGridProperties, + GridProperties* doubleGridProperties) + { + const auto max_kro = findMaxKro( tableManager ); + return imbnumApply( size, "IKRO", max_kro, tableManager, eclipseGrid, + intGridProperties, doubleGridProperties, false ); } - std::vector< double > KRORWEndpoint( size_t size, const Deck& deck, const EclipseState& es ) { - const auto krorw = findKrorw( *es.getTableManager() ); - return satnumApply( size, "KRORW", krorw, deck, es, false ); + std::vector< double > KRORWEndpoint( size_t size, + const TableManager * tableManager, + const EclipseGrid * eclipseGrid, + GridProperties* intGridProperties, + GridProperties* doubleGridProperties) + { + const auto krorw = findKrorw( tableManager ); + return satnumApply( size, "KRORW", krorw, tableManager, eclipseGrid, + intGridProperties, doubleGridProperties, false ); } - std::vector< double > IKRORWEndpoint( size_t size, const Deck& deck, const EclipseState& es ) { - const auto krorw = findKrorw( *es.getTableManager() ); - return imbnumApply( size, "IKRORW", krorw, deck, es, false ); + std::vector< double > IKRORWEndpoint( size_t size, + const TableManager * tableManager, + const EclipseGrid * eclipseGrid, + GridProperties* intGridProperties, + GridProperties* doubleGridProperties) + { + const auto krorw = findKrorw( tableManager ); + return imbnumApply( size, "IKRORW", krorw, tableManager, eclipseGrid, + intGridProperties, doubleGridProperties, false ); } - std::vector< double > KRORGEndpoint( size_t size, const Deck& deck, const EclipseState& es ) { - const auto krorg = findKrorg( *es.getTableManager() ); - return satnumApply( size, "KRORG", krorg, deck, es, false ); + std::vector< double > KRORGEndpoint( size_t size, + const TableManager * tableManager, + const EclipseGrid * eclipseGrid, + GridProperties* intGridProperties, + GridProperties* doubleGridProperties) + { + const auto krorg = findKrorg( tableManager ); + return satnumApply( size, "KRORG", krorg, tableManager, eclipseGrid, + intGridProperties, doubleGridProperties, false ); } - std::vector< double > IKRORGEndpoint( size_t size, const Deck& deck, const EclipseState& es ) { - const auto krorg = findKrorg( *es.getTableManager() ); - return imbnumApply( size, "IKRORG", krorg, deck, es, false ); + std::vector< double > IKRORGEndpoint( size_t size, + const TableManager * tableManager, + const EclipseGrid * eclipseGrid, + GridProperties* intGridProperties, + GridProperties* doubleGridProperties) + { + const auto krorg = findKrorg( tableManager ); + return imbnumApply( size, "IKRORG", krorg, tableManager, eclipseGrid, + intGridProperties, doubleGridProperties, false ); } - std::vector< double > KRGEndpoint( size_t size, const Deck& deck, const EclipseState& es ) { - const auto max_krg = findMaxKrg( *es.getTableManager() ); - return satnumApply( size, "KRG", max_krg, deck, es, false ); + std::vector< double > KRGEndpoint( size_t size, + const TableManager * tableManager, + const EclipseGrid * eclipseGrid, + GridProperties* intGridProperties, + GridProperties* doubleGridProperties) + { + const auto max_krg = findMaxKrg( tableManager ); + return satnumApply( size, "KRG", max_krg, tableManager, eclipseGrid, + intGridProperties, doubleGridProperties, false ); } - std::vector< double > IKRGEndpoint( size_t size, const Deck& deck, const EclipseState& es ) { - const auto max_krg = findMaxKrg( *es.getTableManager() ); - return imbnumApply( size, "IKRG", max_krg, deck, es, false ); + std::vector< double > IKRGEndpoint( size_t size, + const TableManager * tableManager, + const EclipseGrid * eclipseGrid, + GridProperties* intGridProperties, + GridProperties* doubleGridProperties) + { + const auto max_krg = findMaxKrg( tableManager ); + return imbnumApply( size, "IKRG", max_krg, tableManager, eclipseGrid, + intGridProperties, doubleGridProperties, false ); } - std::vector< double > KRGREndpoint( size_t size, const Deck& deck, const EclipseState& es ) { - const auto krgr = findKrgr( *es.getTableManager() ); - return satnumApply( size, "KRGR", krgr, deck, es, false ); + std::vector< double > KRGREndpoint( size_t size, + const TableManager * tableManager, + const EclipseGrid * eclipseGrid, + GridProperties* intGridProperties, + GridProperties* doubleGridProperties) + { + const auto krgr = findKrgr( tableManager ); + return satnumApply( size, "KRGR", krgr, tableManager, eclipseGrid, + intGridProperties, doubleGridProperties, false ); } - std::vector< double > IKRGREndpoint( size_t size, const Deck& deck, const EclipseState& es ) { - const auto krgr = findKrgr( *es.getTableManager() ); - return imbnumApply( size, "IKRGR", krgr, deck, es, false ); + std::vector< double > IKRGREndpoint( size_t size, + const TableManager * tableManager, + const EclipseGrid* eclipseGrid, + GridProperties* intGridProperties, + GridProperties* doubleGridProperties) + { + const auto krgr = findKrgr( tableManager ); + return imbnumApply( size, "IKRGR", krgr, tableManager, eclipseGrid, + intGridProperties, doubleGridProperties, false ); } - } diff --git a/opm/parser/eclipse/EclipseState/Grid/SatfuncPropertyInitializers.hpp b/opm/parser/eclipse/EclipseState/Grid/SatfuncPropertyInitializers.hpp index d8c519d10..61192938c 100644 --- a/opm/parser/eclipse/EclipseState/Grid/SatfuncPropertyInitializers.hpp +++ b/opm/parser/eclipse/EclipseState/Grid/SatfuncPropertyInitializers.hpp @@ -22,46 +22,215 @@ #include #include +#include + namespace Opm { - class Deck; - class EclipseState; + class EclipseGrid; + class TableManager; - std::vector< double > SGLEndpoint( size_t, const Deck&, const EclipseState& ); - std::vector< double > ISGLEndpoint( size_t, const Deck&, const EclipseState& ); - std::vector< double > SGUEndpoint( size_t, const Deck&, const EclipseState& ); - std::vector< double > ISGUEndpoint( size_t, const Deck&, const EclipseState& ); - std::vector< double > SWLEndpoint( size_t, const Deck&, const EclipseState& ); - std::vector< double > ISWLEndpoint( size_t, const Deck&, const EclipseState& ); - std::vector< double > SWUEndpoint( size_t, const Deck&, const EclipseState& ); - std::vector< double > ISWUEndpoint( size_t, const Deck&, const EclipseState& ); - std::vector< double > SGCREndpoint( size_t, const Deck&, const EclipseState& ); - std::vector< double > ISGCREndpoint( size_t, const Deck&, const EclipseState& ); - std::vector< double > SOWCREndpoint( size_t, const Deck&, const EclipseState& ); - std::vector< double > ISOWCREndpoint( size_t, const Deck&, const EclipseState& ); - std::vector< double > SOGCREndpoint( size_t, const Deck&, const EclipseState& ); - std::vector< double > ISOGCREndpoint( size_t, const Deck&, const EclipseState& ); - std::vector< double > SWCREndpoint( size_t, const Deck&, const EclipseState& ); - std::vector< double > ISWCREndpoint( size_t, const Deck&, const EclipseState& ); - std::vector< double > PCWEndpoint( size_t, const Deck&, const EclipseState& ); - std::vector< double > IPCWEndpoint( size_t, const Deck&, const EclipseState& ); - std::vector< double > PCGEndpoint( size_t, const Deck&, const EclipseState& ); - std::vector< double > IPCGEndpoint( size_t, const Deck&, const EclipseState& ); - std::vector< double > KRWEndpoint( size_t, const Deck&, const EclipseState& ); - std::vector< double > IKRWEndpoint( size_t, const Deck&, const EclipseState& ); - std::vector< double > KRWREndpoint( size_t, const Deck&, const EclipseState& ); - std::vector< double > IKRWREndpoint( size_t, const Deck&, const EclipseState& ); - std::vector< double > KROEndpoint( size_t, const Deck&, const EclipseState& ); - std::vector< double > IKROEndpoint( size_t, const Deck&, const EclipseState& ); - std::vector< double > KRORWEndpoint( size_t, const Deck&, const EclipseState& ); - std::vector< double > IKRORWEndpoint( size_t, const Deck&, const EclipseState& ); - std::vector< double > KRORGEndpoint( size_t, const Deck&, const EclipseState& ); - std::vector< double > IKRORGEndpoint( size_t, const Deck&, const EclipseState& ); - std::vector< double > KRGEndpoint( size_t, const Deck&, const EclipseState& ); - std::vector< double > IKRGEndpoint( size_t, const Deck&, const EclipseState& ); - std::vector< double > KRGREndpoint( size_t, const Deck&, const EclipseState& ); - std::vector< double > IKRGREndpoint( size_t, const Deck&, const EclipseState& ); + std::vector SGLEndpoint(size_t, + const TableManager*, + const EclipseGrid*, + GridProperties*, + GridProperties*); + std::vector ISGLEndpoint(size_t, + const TableManager*, + const EclipseGrid*, + GridProperties*, + GridProperties*); + + std::vector SGUEndpoint(size_t, + const TableManager*, + const EclipseGrid*, + GridProperties*, + GridProperties*); + + std::vector ISGUEndpoint(size_t, const TableManager*, + const EclipseGrid*, + GridProperties*, + GridProperties*); + + std::vector SWLEndpoint(size_t, + const TableManager*, + const EclipseGrid*, + GridProperties*, + GridProperties*); + + std::vector ISWLEndpoint(size_t, + const TableManager*, + const EclipseGrid*, + GridProperties*, + GridProperties*); + + std::vector SWUEndpoint(size_t, + const TableManager*, + const EclipseGrid*, + GridProperties*, + GridProperties*); + + std::vector ISWUEndpoint(size_t, + const TableManager*, + const EclipseGrid*, + GridProperties*, + GridProperties*); + + std::vector SGCREndpoint(size_t, + const TableManager*, + const EclipseGrid*, + GridProperties*, + GridProperties*); + + std::vector ISGCREndpoint(size_t, + const TableManager*, + const EclipseGrid*, + GridProperties*, + GridProperties*); + + std::vector SOWCREndpoint(size_t, + const TableManager*, + const EclipseGrid*, + GridProperties*, + GridProperties*); + + std::vector ISOWCREndpoint(size_t, + const TableManager*, + const EclipseGrid*, + GridProperties*, + GridProperties*); + + std::vector SOGCREndpoint(size_t, + const TableManager*, + const EclipseGrid*, + GridProperties*, + GridProperties*); + + std::vector ISOGCREndpoint(size_t, + const TableManager*, + const EclipseGrid*, + GridProperties*, + GridProperties*); + + std::vector SWCREndpoint(size_t, + const TableManager*, + const EclipseGrid*, + GridProperties*, + GridProperties*); + + std::vector ISWCREndpoint(size_t, + const TableManager*, + const EclipseGrid*, + GridProperties*, + GridProperties*); + + std::vector PCWEndpoint(size_t, + const TableManager*, + const EclipseGrid*, + GridProperties*, + GridProperties*); + + std::vector IPCWEndpoint(size_t, + const TableManager*, + const EclipseGrid*, + GridProperties*, + GridProperties*); + + std::vector PCGEndpoint(size_t, + const TableManager*, + const EclipseGrid*, + GridProperties*, + GridProperties*); + + std::vector IPCGEndpoint(size_t, + const TableManager*, + const EclipseGrid*, + GridProperties*, + GridProperties*); + + std::vector KRWEndpoint(size_t, + const TableManager*, + const EclipseGrid*, + GridProperties*, + GridProperties*); + + std::vector IKRWEndpoint(size_t, + const TableManager*, + const EclipseGrid*, + GridProperties*, + GridProperties*); + + std::vector KRWREndpoint(size_t, + const TableManager*, + const EclipseGrid*, + GridProperties*, + GridProperties*); + + std::vector IKRWREndpoint(size_t, + const TableManager*, + const EclipseGrid*, + GridProperties*, + GridProperties*); + + std::vector KROEndpoint(size_t, + const TableManager*, + const EclipseGrid*, + GridProperties*, + GridProperties*); + + std::vector IKROEndpoint(size_t, + const TableManager*, + const EclipseGrid*, + GridProperties*, + GridProperties*); + + std::vector KRORWEndpoint(size_t, + const TableManager*, + const EclipseGrid*, + GridProperties*, + GridProperties*); + + std::vector IKRORWEndpoint(size_t, + const TableManager*, + const EclipseGrid*, + GridProperties*, + GridProperties*); + + std::vector KRORGEndpoint(size_t, + const TableManager*, + const EclipseGrid*, + GridProperties*, + GridProperties*); + + std::vector IKRORGEndpoint(size_t, + const TableManager*, + const EclipseGrid*, + GridProperties*, + GridProperties*); + + std::vector KRGEndpoint(size_t, + const TableManager*, + const EclipseGrid*, + GridProperties*, + GridProperties*); + + std::vector IKRGEndpoint(size_t, + const TableManager*, + const EclipseGrid*, + GridProperties*, + GridProperties*); + + std::vector KRGREndpoint(size_t, + const TableManager*, + const EclipseGrid*, + GridProperties*, + GridProperties*); + + std::vector IKRGREndpoint(size_t, + const TableManager*, + const EclipseGrid*, + GridProperties*, + GridProperties*); } -#endif +#endif // ECLIPSE_SATFUNCPROPERTY_INITIALIZERS_HPP diff --git a/opm/parser/eclipse/EclipseState/Grid/TransMult.cpp b/opm/parser/eclipse/EclipseState/Grid/TransMult.cpp index f2def482c..5de89efd4 100644 --- a/opm/parser/eclipse/EclipseState/Grid/TransMult.cpp +++ b/opm/parser/eclipse/EclipseState/Grid/TransMult.cpp @@ -64,8 +64,7 @@ namespace Opm { double TransMult::getMultiplier__(size_t globalIndex, FaceDir::DirEnum faceDir) const { if (hasDirectionProperty( faceDir )) { - std::shared_ptr > property = m_trans.at(faceDir); - return property->iget( globalIndex ); + return m_trans.at(faceDir).iget( globalIndex ); } else return 1.0; } @@ -82,37 +81,31 @@ namespace Opm { return m_multregtScanner->getRegionMultiplier(globalCellIndex1, globalCellIndex2, faceDir); } - bool TransMult::hasDirectionProperty(FaceDir::DirEnum faceDir) const { - if (m_trans.count(faceDir) == 1) - return true; - else - return false; + return m_trans.count(faceDir) == 1; } void TransMult::insertNewProperty(FaceDir::DirEnum faceDir) { GridPropertySupportedKeywordInfo kwInfo(m_names[faceDir] , 1.0 , "1"); - std::shared_ptr > property = std::make_shared >( m_nx , m_ny , m_nz , kwInfo ); - std::pair > > pair(faceDir , property); - - m_trans.insert( pair ); + GridProperty< double > prop( m_nx, m_ny, m_nz, kwInfo ); + m_trans.emplace( faceDir, std::move( prop ) ); } - std::shared_ptr > TransMult::getDirectionProperty(FaceDir::DirEnum faceDir) { + GridProperty& TransMult::getDirectionProperty(FaceDir::DirEnum faceDir) { if (m_trans.count(faceDir) == 0) insertNewProperty(faceDir); return m_trans.at( faceDir ); } - void TransMult::applyMULT(std::shared_ptr > srcProp, FaceDir::DirEnum faceDir) + void TransMult::applyMULT(const GridProperty& srcProp, FaceDir::DirEnum faceDir) { - std::shared_ptr > dstProp = getDirectionProperty(faceDir); + auto& dstProp = getDirectionProperty(faceDir); - const std::vector &srcData = srcProp->getData(); + const std::vector &srcData = srcProp.getData(); for (size_t i = 0; i < srcData.size(); ++i) - dstProp->multiplyValueAtIndex(i, srcData[i]); + dstProp.multiplyValueAtIndex(i, srcData[i]); } @@ -122,11 +115,11 @@ namespace Opm { for (auto face_iter = fault->begin(); face_iter != fault->end(); ++face_iter) { std::shared_ptr face = *face_iter; FaceDir::DirEnum faceDir = face->getDir(); - std::shared_ptr > multProperty = getDirectionProperty(faceDir); + auto& multProperty = getDirectionProperty(faceDir); for (auto cell_iter = face->begin(); cell_iter != face->end(); ++cell_iter) { size_t globalIndex = *cell_iter; - multProperty->multiplyValueAtIndex( globalIndex , transMult); + multProperty.multiplyValueAtIndex( globalIndex , transMult); } } } diff --git a/opm/parser/eclipse/EclipseState/Grid/TransMult.hpp b/opm/parser/eclipse/EclipseState/Grid/TransMult.hpp index bb23a6f8f..2e7a1b707 100644 --- a/opm/parser/eclipse/EclipseState/Grid/TransMult.hpp +++ b/opm/parser/eclipse/EclipseState/Grid/TransMult.hpp @@ -50,9 +50,7 @@ namespace Opm { double getMultiplier(size_t globalIndex, FaceDir::DirEnum faceDir) const; double getMultiplier(size_t i , size_t j , size_t k, FaceDir::DirEnum faceDir) const; double getRegionMultiplier( size_t globalCellIndex1, size_t globalCellIndex2, FaceDir::DirEnum faceDir) const; - bool hasDirectionProperty(FaceDir::DirEnum faceDir) const; - std::shared_ptr > getDirectionProperty(FaceDir::DirEnum faceDir); - void applyMULT(std::shared_ptr > srcMultProp, FaceDir::DirEnum faceDir); + void applyMULT(const GridProperty& srcMultProp, FaceDir::DirEnum faceDir); void applyMULTFLT( std::shared_ptr faults); void applyMULTFLT( std::shared_ptr fault); void setMultregtScanner(std::shared_ptr multregtScanner); @@ -62,9 +60,11 @@ namespace Opm { void assertIJK(size_t i , size_t j , size_t k) const; double getMultiplier__(size_t globalIndex , FaceDir::DirEnum faceDir) const; void insertNewProperty(FaceDir::DirEnum faceDir); + bool hasDirectionProperty(FaceDir::DirEnum faceDir) const; + GridProperty& getDirectionProperty(FaceDir::DirEnum faceDir); size_t m_nx , m_ny , m_nz; - std::map > > m_trans; + std::map > m_trans; std::map m_names; std::shared_ptr m_multregtScanner; }; diff --git a/opm/parser/eclipse/EclipseState/Grid/tests/ADDREGTests.cpp b/opm/parser/eclipse/EclipseState/Grid/tests/ADDREGTests.cpp index a70f2e15b..6a43fc941 100644 --- a/opm/parser/eclipse/EclipseState/Grid/tests/ADDREGTests.cpp +++ b/opm/parser/eclipse/EclipseState/Grid/tests/ADDREGTests.cpp @@ -35,9 +35,10 @@ #include #include +#include +#include #include #include -#include static Opm::DeckPtr createDeckInvalidArray() { @@ -249,13 +250,13 @@ BOOST_AUTO_TEST_CASE(UnInitializedVectorThrows) { BOOST_AUTO_TEST_CASE(IntSetCorrectly) { Opm::DeckPtr deck = createValidIntDeck(); Opm::EclipseState state(deck , Opm::ParseContext()); - std::shared_ptr > property = state.getIntGridProperty( "SATNUM"); + const auto& property = state.getEclipseProperties().getIntGridProperty( "SATNUM"); for (size_t j=0; j< 5; j++) for (size_t i = 0; i < 5; i++) { if (i < 2) - BOOST_CHECK_EQUAL( 12 , property->iget(i,j,0)); + BOOST_CHECK_EQUAL( 12 , property.iget(i,j,0)); else - BOOST_CHECK_EQUAL( 21 , property->iget(i,j,0)); + BOOST_CHECK_EQUAL( 21 , property.iget(i,j,0)); } } @@ -263,14 +264,15 @@ BOOST_AUTO_TEST_CASE(IntSetCorrectly) { BOOST_AUTO_TEST_CASE(UnitAppliedCorrectly) { Opm::DeckPtr deck = createValidPERMXDeck(); - Opm::EclipseState state(deck , Opm::ParseContext()); - std::shared_ptr > permx = state.getDoubleGridProperty( "PERMX"); + const Opm::EclipseState state( deck, Opm::ParseContext() ); + const auto& props = state.getEclipseProperties(); + const auto& permx = props.getDoubleGridProperty( "PERMX"); for (size_t j=0; j< 5; j++) for (size_t i = 0; i < 5; i++) { if (i < 2) - BOOST_CHECK_EQUAL( 2 * Opm::Metric::Permeability , permx->iget(i,j,0)); + BOOST_CHECK_CLOSE( 2 * Opm::Metric::Permeability , permx.iget(i,j,0), 0.0001); else - BOOST_CHECK_EQUAL( 4 * Opm::Metric::Permeability , permx->iget(i,j,0)); + BOOST_CHECK_CLOSE( 4 * Opm::Metric::Permeability , permx.iget(i,j,0), 0.0001); } } diff --git a/opm/parser/eclipse/EclipseState/Grid/tests/CopyRegTests.cpp b/opm/parser/eclipse/EclipseState/Grid/tests/CopyRegTests.cpp index 9e3ad829d..e0e35d9ad 100644 --- a/opm/parser/eclipse/EclipseState/Grid/tests/CopyRegTests.cpp +++ b/opm/parser/eclipse/EclipseState/Grid/tests/CopyRegTests.cpp @@ -34,9 +34,11 @@ #include #include +#include +#include #include #include -#include + static Opm::DeckPtr createDeckInvalidArray1() { @@ -196,26 +198,20 @@ BOOST_AUTO_TEST_CASE(UnInitializedVectorThrows) { BOOST_CHECK_THROW( new Opm::EclipseState( deck, Opm::ParseContext()) , std::invalid_argument ); } - BOOST_AUTO_TEST_CASE(TypeMismatchThrows) { Opm::DeckPtr deck = createDeckInvalidTypeMismatch(); BOOST_CHECK_THROW( new Opm::EclipseState( deck, Opm::ParseContext()) , std::invalid_argument ); } - - BOOST_AUTO_TEST_CASE(IntSetCorrectly) { Opm::DeckPtr deck = createValidIntDeck(); Opm::EclipseState state(deck , Opm::ParseContext() ); - std::shared_ptr > property = state.getIntGridProperty( "FLUXNUM"); - for (size_t j=0; j< 5; j++) + auto& property = state.getEclipseProperties().getIntGridProperty("FLUXNUM"); + for (size_t j = 0; j < 5; j++) for (size_t i = 0; i < 5; i++) { if (i < 2) - BOOST_CHECK_EQUAL( 10 , property->iget(i,j,0)); + BOOST_CHECK_EQUAL(10, property.iget(i, j, 0)); else - BOOST_CHECK_EQUAL( 3 , property->iget(i,j,0)); + BOOST_CHECK_EQUAL(3 , property.iget(i, j, 0)); } - } - - diff --git a/opm/parser/eclipse/EclipseState/Grid/tests/EqualRegTests.cpp b/opm/parser/eclipse/EclipseState/Grid/tests/EqualRegTests.cpp index e89520733..0546aaa21 100644 --- a/opm/parser/eclipse/EclipseState/Grid/tests/EqualRegTests.cpp +++ b/opm/parser/eclipse/EclipseState/Grid/tests/EqualRegTests.cpp @@ -34,9 +34,10 @@ #include #include +#include +#include #include #include -#include static Opm::DeckPtr createDeckInvalidArray() { @@ -202,42 +203,40 @@ BOOST_AUTO_TEST_CASE(InvalidRegionThrows) { BOOST_CHECK_THROW( new Opm::EclipseState( deck, Opm::ParseContext()) , std::invalid_argument ); } - BOOST_AUTO_TEST_CASE(ExpectedIntThrows) { Opm::DeckPtr deck = createDeckInvalidValue(); BOOST_CHECK_THROW( new Opm::EclipseState( deck, Opm::ParseContext()) , std::invalid_argument ); } - BOOST_AUTO_TEST_CASE(UnInitializedVectorThrows) { Opm::DeckPtr deck = createDeckUnInitialized(); BOOST_CHECK_THROW( new Opm::EclipseState( deck, Opm::ParseContext()) , std::invalid_argument ); } - BOOST_AUTO_TEST_CASE(IntSetCorrectly) { Opm::DeckPtr deck = createValidIntDeck(); Opm::EclipseState state(deck , Opm::ParseContext()); - std::shared_ptr > property = state.getIntGridProperty( "SATNUM"); - for (size_t j=0; j< 5; j++) + auto& property = state.getEclipseProperties().getIntGridProperty("SATNUM"); + for (size_t j = 0; j < 5; j++) for (size_t i = 0; i < 5; i++) { if (i < 2) - BOOST_CHECK_EQUAL( 11 , property->iget(i,j,0)); + BOOST_CHECK_EQUAL(11, property.iget(i, j, 0)); else - BOOST_CHECK_EQUAL( 20 , property->iget(i,j,0)); + BOOST_CHECK_EQUAL(20, property.iget(i, j, 0)); } } - BOOST_AUTO_TEST_CASE(UnitAppliedCorrectly) { Opm::DeckPtr deck = createValidPERMXDeck(); - Opm::EclipseState state(deck , Opm::ParseContext()); - std::shared_ptr > permx = state.getDoubleGridProperty( "PERMX"); - std::shared_ptr > permy = state.getDoubleGridProperty( "PERMY"); - std::shared_ptr > permz = state.getDoubleGridProperty( "PERMZ"); - for (size_t g=0; g< 25; g++) { - BOOST_CHECK_EQUAL( permz->iget(g), permx->iget(g)); - BOOST_CHECK_EQUAL( permy->iget(g), permx->iget(g)); + Opm::EclipseState state(deck, Opm::ParseContext()); + const auto& props = state.getEclipseProperties(); + + const auto& permx = props.getDoubleGridProperty("PERMX"); + const auto& permy = props.getDoubleGridProperty("PERMY"); + const auto& permz = props.getDoubleGridProperty("PERMZ"); + for (size_t g = 0; g < 25; g++) { + BOOST_CHECK_EQUAL(permz.iget(g), permx.iget(g)); + BOOST_CHECK_EQUAL(permy.iget(g), permx.iget(g)); } } diff --git a/opm/parser/eclipse/EclipseState/Grid/tests/GridPropertiesTests.cpp b/opm/parser/eclipse/EclipseState/Grid/tests/GridPropertiesTests.cpp index 4aa704226..f72e112a4 100644 --- a/opm/parser/eclipse/EclipseState/Grid/tests/GridPropertiesTests.cpp +++ b/opm/parser/eclipse/EclipseState/Grid/tests/GridPropertiesTests.cpp @@ -28,13 +28,14 @@ #include #include - #include #include #include #include +#include +#include #include @@ -45,8 +46,8 @@ BOOST_AUTO_TEST_CASE(Empty) { SupportedKeywordInfo("FIPNUM" , 2, "1") }; - std::shared_ptr grid = std::make_shared(10,7,9); - Opm::GridProperties gridProperties( grid, std::move( supportedKeywords ) ); + const Opm::EclipseGrid grid(10, 7, 9); + Opm::GridProperties gridProperties(grid, std::move(supportedKeywords)); BOOST_CHECK( gridProperties.supportsKeyword("SATNUM") ); BOOST_CHECK( gridProperties.supportsKeyword("FIPNUM") ); @@ -65,10 +66,10 @@ BOOST_AUTO_TEST_CASE(addKeyword) { std::vector supportedKeywords = { SupportedKeywordInfo("SATNUM" , 0, "1") }; - std::shared_ptr grid = std::make_shared(10,7,9); - Opm::GridProperties gridProperties( grid , std::move( supportedKeywords ) ); + Opm::EclipseGrid grid(10, 7, 9); + Opm::GridProperties gridProperties(grid, std::move(supportedKeywords)); - BOOST_CHECK_THROW( gridProperties.addKeyword("NOT-SUPPORTED") , std::invalid_argument); + BOOST_CHECK_THROW(gridProperties.addKeyword("NOT-SUPPORTED"), std::invalid_argument); BOOST_CHECK( gridProperties.addKeyword("SATNUM")); BOOST_CHECK( !gridProperties.addKeyword("SATNUM")); @@ -81,8 +82,8 @@ BOOST_AUTO_TEST_CASE(hasKeyword) { std::vector supportedKeywords = { SupportedKeywordInfo("SATNUM" , 0, "1") }; - std::shared_ptr grid = std::make_shared(10,7,9); - Opm::GridProperties gridProperties( grid, std::move( supportedKeywords ) ); + const Opm::EclipseGrid grid(10, 7, 9); + Opm::GridProperties gridProperties(grid, std::move(supportedKeywords)); // calling getKeyword() should not change the semantics of hasKeyword()! BOOST_CHECK(!gridProperties.hasKeyword("SATNUM")); @@ -96,17 +97,18 @@ BOOST_AUTO_TEST_CASE(getKeyword) { std::vector supportedKeywords = { SupportedKeywordInfo("SATNUM" , 0, "1") }; - std::shared_ptr grid = std::make_shared(10,7,9); + const Opm::EclipseGrid grid(10, 7, 9); Opm::GridProperties gridProperties( grid, std::move( supportedKeywords ) ); - std::shared_ptr > satnum1 = gridProperties.getKeyword("SATNUM"); - std::shared_ptr > satnum2 = gridProperties.getKeyword("SATNUM"); - std::shared_ptr > satnum3 = gridProperties.getKeyword(0); + const Opm::GridProperty& satnum1 = gridProperties.getKeyword( "SATNUM" ); + const Opm::GridProperty& satnum2 = gridProperties.getKeyword( "SATNUM" ); + const Opm::GridProperty& satnum3 = gridProperties.getKeyword( size_t( 0 ) ); - BOOST_CHECK_EQUAL( 1 , gridProperties.size() ); - BOOST_CHECK_EQUAL( satnum1.get() , satnum2.get()); - BOOST_CHECK_EQUAL( satnum1.get() , satnum3.get()); - BOOST_CHECK_THROW( gridProperties.getKeyword("NOT-SUPPORTED") , std::invalid_argument ); - BOOST_CHECK_THROW( gridProperties.getKeyword(3) , std::invalid_argument ); + BOOST_CHECK_EQUAL( 1, gridProperties.size() ); + BOOST_CHECK_EQUAL( &satnum1, &satnum2 ); + BOOST_CHECK_EQUAL( &satnum1, &satnum3 ); + + BOOST_CHECK_THROW( gridProperties.getKeyword( "NOT-SUPPORTED" ), std::invalid_argument ); + BOOST_CHECK_THROW( gridProperties.getKeyword( 3 ), std::invalid_argument ); } diff --git a/opm/parser/eclipse/EclipseState/Grid/tests/GridPropertyTests.cpp b/opm/parser/eclipse/EclipseState/Grid/tests/GridPropertyTests.cpp index 216a275b6..868a290a3 100644 --- a/opm/parser/eclipse/EclipseState/Grid/tests/GridPropertyTests.cpp +++ b/opm/parser/eclipse/EclipseState/Grid/tests/GridPropertyTests.cpp @@ -37,9 +37,12 @@ #include #include #include +#include #include #include #include +#include +#include static const Opm::DeckKeyword createSATNUMKeyword( ) { const char *deckData = @@ -154,24 +157,23 @@ BOOST_AUTO_TEST_CASE(SetFromDeckKeyword) { } } - BOOST_AUTO_TEST_CASE(copy) { typedef Opm::GridProperty::SupportedKeywordInfo SupportedKeywordInfo; - SupportedKeywordInfo keywordInfo1("P1" , 0, "1"); - SupportedKeywordInfo keywordInfo2("P2" , 9, "1"); - Opm::GridProperty prop1( 4 , 4 , 2 , keywordInfo1); - Opm::GridProperty prop2( 4 , 4 , 2 , keywordInfo2); + SupportedKeywordInfo keywordInfo1("P1", 0, "1"); + SupportedKeywordInfo keywordInfo2("P2", 9, "1"); + Opm::GridProperty prop1(4, 4, 2, keywordInfo1); + Opm::GridProperty prop2(4, 4, 2, keywordInfo2); - Opm::Box global(4,4,2); - std::shared_ptr layer0 = std::make_shared(global , 0,3,0,3,0,0); + Opm::Box global(4, 4, 2); + Opm::Box layer0(global, 0, 3, 0, 3, 0, 0); - prop2.copyFrom(prop1 , layer0); + prop2.copyFrom(prop1, layer0); - for (size_t j=0; j < 4; j++) { - for (size_t i=0; i < 4; i++) { + for (size_t j = 0; j < 4; j++) { + for (size_t i = 0; i < 4; i++) { - BOOST_CHECK_EQUAL( prop2.iget(i,j,0) , 0 ); - BOOST_CHECK_EQUAL( prop2.iget(i,j,1) , 9 ); + BOOST_CHECK_EQUAL(prop2.iget(i, j, 0), 0); + BOOST_CHECK_EQUAL(prop2.iget(i, j, 1), 9); } } } @@ -179,69 +181,67 @@ BOOST_AUTO_TEST_CASE(copy) { BOOST_AUTO_TEST_CASE(SCALE) { typedef Opm::GridProperty::SupportedKeywordInfo SupportedKeywordInfo; - SupportedKeywordInfo keywordInfo1("P1" , 1, "1"); - SupportedKeywordInfo keywordInfo2("P2" , 9, "1"); + SupportedKeywordInfo keywordInfo1( "P1", 1, "1" ); + SupportedKeywordInfo keywordInfo2( "P2", 9, "1" ); - Opm::GridProperty prop1( 4 , 4 , 2 , keywordInfo1); - Opm::GridProperty prop2( 4 , 4 , 2 , keywordInfo2); + Opm::GridProperty prop1( 4, 4, 2, keywordInfo1 ); + Opm::GridProperty prop2( 4, 4, 2, keywordInfo2 ); - std::shared_ptr global = std::make_shared(4,4,2); - std::shared_ptr layer0 = std::make_shared(*global , 0,3,0,3,0,0); + Opm::Box global( 4, 4, 2 ); + Opm::Box layer0( global, 0, 3, 0, 3, 0, 0 ); - prop2.copyFrom(prop1 , layer0); - prop2.scale( 2 , global ); - prop2.scale( 2 , layer0 ); + prop2.copyFrom( prop1, layer0 ); + prop2.scale( 2, global ); + prop2.scale( 2, layer0 ); - for (size_t j=0; j < 4; j++) { - for (size_t i=0; i < 4; i++) { + for (size_t j = 0; j < 4; j++) { + for (size_t i = 0; i < 4; i++) { - BOOST_CHECK_EQUAL( prop2.iget(i,j,0) , 4 ); - BOOST_CHECK_EQUAL( prop2.iget(i,j,1) , 18 ); + BOOST_CHECK_EQUAL( prop2.iget( i, j, 0 ), 4 ); + BOOST_CHECK_EQUAL( prop2.iget( i, j, 1 ), 18 ); } } } - BOOST_AUTO_TEST_CASE(SET) { typedef Opm::GridProperty::SupportedKeywordInfo SupportedKeywordInfo; - SupportedKeywordInfo keywordInfo("P1" , 1, "1"); - Opm::GridProperty prop( 4 , 4 , 2 , keywordInfo); + SupportedKeywordInfo keywordInfo( "P1", 1, "1" ); + Opm::GridProperty prop( 4, 4, 2, keywordInfo ); - std::shared_ptr global = std::make_shared(4,4,2); - std::shared_ptr layer0 = std::make_shared(*global , 0,3,0,3,0,0); + Opm::Box global( 4, 4, 2 ); + Opm::Box layer0( global, 0, 3, 0, 3, 0, 0 ); - prop.setScalar( 2 , global ); - prop.setScalar( 4 , layer0 ); + prop.setScalar( 2, global ); + prop.setScalar( 4, layer0 ); - for (size_t j=0; j < 4; j++) { - for (size_t i=0; i < 4; i++) { + for (size_t j = 0; j < 4; j++) { + for (size_t i = 0; i < 4; i++) { - BOOST_CHECK_EQUAL( prop.iget(i,j,0) , 4 ); - BOOST_CHECK_EQUAL( prop.iget(i,j,1) , 2 ); + BOOST_CHECK_EQUAL( prop.iget( i, j, 0 ), 4 ); + BOOST_CHECK_EQUAL( prop.iget( i, j, 1 ), 2 ); } } } - BOOST_AUTO_TEST_CASE(ADD) { typedef Opm::GridProperty::SupportedKeywordInfo SupportedKeywordInfo; - SupportedKeywordInfo keywordInfo1("P1" , 1, "1"); - SupportedKeywordInfo keywordInfo2("P2" , 9, "1"); - Opm::GridProperty prop1( 4 , 4 , 2 , keywordInfo1); - Opm::GridProperty prop2( 4 , 4 , 2 , keywordInfo2); + SupportedKeywordInfo keywordInfo1( "P1", 1, "1" ); + SupportedKeywordInfo keywordInfo2( "P2", 9, "1" ); + Opm::GridProperty prop1( 4, 4, 2, keywordInfo1 ); + Opm::GridProperty prop2( 4, 4, 2, keywordInfo2 ); - std::shared_ptr global = std::make_shared(4,4,2); - std::shared_ptr layer0 = std::make_shared(*global , 0,3,0,3,0,0); + Opm::Box global( 4, 4, 2 ); + Opm::Box layer0( global, 0, 3, 0, 3, 0, 0 ); - prop2.copyFrom(prop1 , layer0); - prop2.add( 2 , global ); - prop2.add( 2 , layer0 ); + prop2.copyFrom( prop1, layer0 ); + prop2.add( 2, global ); + prop2.add( 2, layer0 ); - for (size_t j=0; j < 4; j++) { - for (size_t i=0; i < 4; i++) { + for (size_t j = 0; j < 4; j++) { + for (size_t i = 0; i < 4; i++) { - BOOST_CHECK_EQUAL( prop2.iget(i,j,0) , 5 ); - BOOST_CHECK_EQUAL( prop2.iget(i,j,1) , 11 ); + BOOST_CHECK_EQUAL( prop2.iget( i, j, 0 ), 5 ); + BOOST_CHECK_EQUAL( prop2.iget( i, j, 1 ), 11 ); } } } @@ -353,38 +353,44 @@ BOOST_AUTO_TEST_CASE(GridPropertyInitialization) { auto deck = parser->parseString(deckString, parseContext); - auto eclipseState = std::make_shared(deck , parseContext); + Opm::EclipseState eclipseState(deck, parseContext); + const auto& props = eclipseState.getEclipseProperties(); // make sure that EclipseState throws if it is bugged about an _unsupported_ keyword - BOOST_CHECK_THROW(eclipseState->hasDeckIntGridProperty("ISWU"), std::logic_error); - BOOST_CHECK_THROW(eclipseState->hasDeckDoubleGridProperty("FLUXNUM"), std::logic_error); + BOOST_CHECK_THROW(props.hasDeckIntGridProperty("ISWU"), std::logic_error); + BOOST_CHECK_THROW(props.hasDeckDoubleGridProperty("FLUXNUM"), std::logic_error); - // make sure that EclipseState does not throw if it is asked for a supported grid - // property that is not contained in the deck - BOOST_CHECK(!eclipseState->hasDeckDoubleGridProperty("ISWU")); - BOOST_CHECK(!eclipseState->hasDeckIntGridProperty("FLUXNUM")); + // make sure that EclipseState does not throw if it is asked for a supported + // grid property that is not contained in the deck + BOOST_CHECK(!props.hasDeckDoubleGridProperty("ISWU")); + BOOST_CHECK(!props.hasDeckIntGridProperty("FLUXNUM")); - BOOST_CHECK(eclipseState->hasDeckIntGridProperty("SATNUM")); - BOOST_CHECK(eclipseState->hasDeckIntGridProperty("IMBNUM")); + BOOST_CHECK(props.hasDeckIntGridProperty("SATNUM")); + BOOST_CHECK(props.hasDeckIntGridProperty("IMBNUM")); - BOOST_CHECK(eclipseState->hasDeckDoubleGridProperty("SWU")); - BOOST_CHECK(eclipseState->hasDeckDoubleGridProperty("ISGU")); - BOOST_CHECK(eclipseState->hasDeckDoubleGridProperty("SGCR")); - BOOST_CHECK(eclipseState->hasDeckDoubleGridProperty("ISGCR")); + BOOST_CHECK(props.hasDeckDoubleGridProperty("SWU")); + BOOST_CHECK(props.hasDeckDoubleGridProperty("ISGU")); + BOOST_CHECK(props.hasDeckDoubleGridProperty("SGCR")); + BOOST_CHECK(props.hasDeckDoubleGridProperty("ISGCR")); - const auto& swuPropData = eclipseState->getDoubleGridProperty("SWU")->getData(); + const auto& swuPropData = props.getDoubleGridProperty("SWU").getData(); BOOST_CHECK_EQUAL(swuPropData[0 * 3*3], 0.93); BOOST_CHECK_EQUAL(swuPropData[1 * 3*3], 0.852); BOOST_CHECK_EQUAL(swuPropData[2 * 3*3], 0.801); - const auto& sguPropData = eclipseState->getDoubleGridProperty("ISGU")->getData(); + const auto& sguPropData = props.getDoubleGridProperty("ISGU").getData(); BOOST_CHECK_EQUAL(sguPropData[0 * 3*3], 0.9); BOOST_CHECK_EQUAL(sguPropData[1 * 3*3], 0.85); BOOST_CHECK_EQUAL(sguPropData[2 * 3*3], 0.80); } -void TestPostProcessorMul(std::vector< double >& values, const Opm::Deck&, const Opm::EclipseState& ) { +void TestPostProcessorMul(std::vector< double >& values, + const Opm::TableManager*, + const Opm::EclipseGrid*, + Opm::GridProperties*, + Opm::GridProperties*) +{ for( size_t g = 0; g < values.size(); g++ ) values[g] *= 2.0; } @@ -421,39 +427,44 @@ BOOST_AUTO_TEST_CASE(GridPropertyPostProcessors) { typedef Opm::GridPropertySupportedKeywordInfo SupportedKeywordInfo; Opm::DeckPtr deck = createDeck(); - Opm::EclipseState st( deck, Opm::ParseContext() ) ; - std::shared_ptr grid = std::make_shared(deck); + Opm::EclipseGrid grid(deck); + std::shared_ptr tm = std::make_shared(*deck); + Opm::Eclipse3DProperties props(*deck, tm, grid); SupportedKeywordInfo kwInfo1("MULTPV" , 1.0 , "1"); - Opm::GridPropertyPostFunction< double > gfunc( &TestPostProcessorMul, *deck, st ); + Opm::GridPropertyPostFunction< double > gfunc( &TestPostProcessorMul, + tm.get(), + &grid, + &props.getIntGridProperties(), + &props.getDoubleGridProperties() ); + SupportedKeywordInfo kwInfo2("PORO", 1.0, gfunc, "1"); std::vector supportedKeywords = { kwInfo1, kwInfo2 }; Opm::GridProperties properties(grid, std::move( supportedKeywords ) ); { - auto poro = properties.getKeyword("PORO"); - auto multpv = properties.getKeyword("MULTPV"); + auto& poro = properties.getKeyword("PORO"); + auto& multpv = properties.getKeyword("MULTPV"); - poro->loadFromDeckKeyword( deck->getKeyword("PORO" , 0)); - multpv->loadFromDeckKeyword( deck->getKeyword("MULTPV" , 0)); + poro.loadFromDeckKeyword( deck->getKeyword("PORO" , 0)); + multpv.loadFromDeckKeyword( deck->getKeyword("MULTPV" , 0)); - poro->runPostProcessor(); - multpv->runPostProcessor(); + poro.runPostProcessor(); + multpv.runPostProcessor(); for (size_t g = 0; g < 1000; g++) { - BOOST_CHECK_EQUAL( multpv->iget(g) , 0.10 ); - BOOST_CHECK_EQUAL( poro->iget(g) , 0.20 ); + BOOST_CHECK_EQUAL( multpv.iget(g) , 0.10 ); + BOOST_CHECK_EQUAL( poro.iget(g) , 0.20 ); } - poro->runPostProcessor(); - multpv->runPostProcessor(); + poro.runPostProcessor(); + multpv.runPostProcessor(); for (size_t g = 0; g < 1000; g++) { - BOOST_CHECK_EQUAL( multpv->iget(g) , 0.10 ); - BOOST_CHECK_EQUAL( poro->iget(g) , 0.20 ); + BOOST_CHECK_EQUAL( multpv.iget(g) , 0.10 ); + BOOST_CHECK_EQUAL( poro.iget(g) , 0.20 ); } - } } diff --git a/opm/parser/eclipse/EclipseState/Grid/tests/MULTREGTScannerTests.cpp b/opm/parser/eclipse/EclipseState/Grid/tests/MULTREGTScannerTests.cpp index b5fc37f53..3514ced9d 100644 --- a/opm/parser/eclipse/EclipseState/Grid/tests/MULTREGTScannerTests.cpp +++ b/opm/parser/eclipse/EclipseState/Grid/tests/MULTREGTScannerTests.cpp @@ -32,7 +32,9 @@ #include #include +#include #include +#include #include #include #include @@ -109,26 +111,26 @@ BOOST_AUTO_TEST_CASE(InvalidInput) { Opm::DeckPtr deck = createInvalidMULTREGTDeck(); - std::shared_ptr grid = std::make_shared( deck ); - std::shared_ptr > gridProperties = std::make_shared >(grid, std::move( supportedKeywords ) ); + Opm::EclipseGrid grid( deck ); + Opm::GridProperties gridProperties( grid, std::move( supportedKeywords ) ); // Invalid direction - std::vector< const Opm::DeckKeyword* > keywords0; - const auto& multregtKeyword0 = deck->getKeyword("MULTREGT",0); + std::vector keywords0; + const auto& multregtKeyword0 = deck->getKeyword( "MULTREGT", 0 ); keywords0.push_back( &multregtKeyword0 ); - BOOST_CHECK_THROW( Opm::MULTREGTScanner scanner(gridProperties, keywords0, "MULTNUM"); , std::invalid_argument); + BOOST_CHECK_THROW( Opm::MULTREGTScanner scanner( gridProperties, keywords0, "MULTNUM" ); , std::invalid_argument ); // Not supported region - std::vector< const Opm::DeckKeyword* > keywords1; - const auto& multregtKeyword1 = deck->getKeyword("MULTREGT",1); + std::vector keywords1; + const auto& multregtKeyword1 = deck->getKeyword( "MULTREGT", 1 ); keywords1.push_back( &multregtKeyword1 ); - BOOST_CHECK_THROW( Opm::MULTREGTScanner scanner(gridProperties,keywords1,"MULTNUM"); , std::invalid_argument); + BOOST_CHECK_THROW( Opm::MULTREGTScanner scanner( gridProperties, keywords1, "MULTNUM" ); , std::invalid_argument ); // The keyword is ok; but it refers to a region which is not in the deck. - std::vector< const Opm::DeckKeyword* > keywords2; - const auto& multregtKeyword2 = deck->getKeyword("MULTREGT",2); + std::vector keywords2; + const auto& multregtKeyword2 = deck->getKeyword( "MULTREGT", 2 ); keywords2.push_back( &multregtKeyword2 ); - BOOST_CHECK_THROW( Opm::MULTREGTScanner scanner(gridProperties,keywords2,"MULTNUM"); , std::logic_error); + BOOST_CHECK_THROW( Opm::MULTREGTScanner scanner( gridProperties, keywords2, "MULTNUM" ); , std::logic_error ); } @@ -176,34 +178,32 @@ BOOST_AUTO_TEST_CASE(NotSupported) { }; Opm::DeckPtr deck = createNotSupportedMULTREGTDeck(); - std::shared_ptr grid = std::make_shared( deck ); - std::shared_ptr > gridProperties = std::make_shared >(grid, std::move( supportedKeywords ) ); + Opm::EclipseGrid grid( deck ); + Opm::GridProperties gridProperties( grid, std::move( supportedKeywords ) ); // Not support NOAQUNNC behaviour - std::vector< const Opm::DeckKeyword* > keywords0; - const auto& multregtKeyword0 = deck->getKeyword("MULTREGT",0); + std::vector keywords0; + const auto& multregtKeyword0 = deck->getKeyword( "MULTREGT", 0 ); keywords0.push_back( &multregtKeyword0 ); - BOOST_CHECK_THROW( Opm::MULTREGTScanner scanner(gridProperties,keywords0,"MULTNUM"); , std::invalid_argument); + BOOST_CHECK_THROW( Opm::MULTREGTScanner scanner( gridProperties, keywords0, "MULTNUM" ); , std::invalid_argument ); // Defaulted from value - not supported - std::vector< const Opm::DeckKeyword* > keywords1; - const auto& multregtKeyword1 = deck->getKeyword("MULTREGT",1); + std::vector keywords1; + const auto& multregtKeyword1 = deck->getKeyword( "MULTREGT", 1 ); keywords1.push_back( &multregtKeyword1 ); - BOOST_CHECK_THROW( Opm::MULTREGTScanner scanner(gridProperties,keywords1,"MULTNUM"); , std::invalid_argument); + BOOST_CHECK_THROW( Opm::MULTREGTScanner scanner( gridProperties, keywords1, "MULTNUM" ); , std::invalid_argument ); // Defaulted to value - not supported - std::vector< const Opm::DeckKeyword* > keywords2; - const auto& multregtKeyword2 = deck->getKeyword("MULTREGT",2); + std::vector keywords2; + const auto& multregtKeyword2 = deck->getKeyword( "MULTREGT", 2 ); keywords2.push_back( &multregtKeyword2 ); - BOOST_CHECK_THROW( Opm::MULTREGTScanner scanner(gridProperties,keywords2,"MULTNUM"); , std::invalid_argument); - + BOOST_CHECK_THROW( Opm::MULTREGTScanner scanner( gridProperties, keywords2, "MULTNUM" ); , std::invalid_argument ); // srcValue == targetValue - not supported - std::vector< const Opm::DeckKeyword* > keywords3; - const Opm::DeckKeyword& multregtKeyword3 = deck->getKeyword("MULTREGT",3); + std::vector keywords3; + const Opm::DeckKeyword& multregtKeyword3 = deck->getKeyword( "MULTREGT", 3 ); keywords3.push_back( &multregtKeyword3 ); - BOOST_CHECK_THROW( Opm::MULTREGTScanner scanner(gridProperties,keywords3 , "MULTNUM"); , std::invalid_argument); - + BOOST_CHECK_THROW( Opm::MULTREGTScanner scanner( gridProperties, keywords3, "MULTNUM" ); , std::invalid_argument ); } static Opm::DeckPtr createCopyMULTNUMDeck() { @@ -232,8 +232,6 @@ static Opm::DeckPtr createCopyMULTNUMDeck() { return parser->parseString(deckData, Opm::ParseContext()) ; } - - BOOST_AUTO_TEST_CASE(MULTREGT_COPY_MULTNUM) { Opm::DeckPtr deck = createCopyMULTNUMDeck(); Opm::EclipseState state(deck , Opm::ParseContext()); diff --git a/opm/parser/eclipse/EclipseState/Grid/tests/MultiRegTests.cpp b/opm/parser/eclipse/EclipseState/Grid/tests/MultiRegTests.cpp index 4107670ac..969f71cc6 100644 --- a/opm/parser/eclipse/EclipseState/Grid/tests/MultiRegTests.cpp +++ b/opm/parser/eclipse/EclipseState/Grid/tests/MultiRegTests.cpp @@ -25,18 +25,16 @@ #define BOOST_TEST_MODULE MultiRegTests #include #include - - #include #include #include #include #include - +#include +#include #include #include -#include static Opm::DeckPtr createDeckInvalidArray() { @@ -201,25 +199,20 @@ BOOST_AUTO_TEST_CASE(MissingRegionVectorThrows) { BOOST_CHECK_THROW( new Opm::EclipseState( deck, Opm::ParseContext()) , std::invalid_argument ); } - BOOST_AUTO_TEST_CASE(UnInitializedVectorThrows) { Opm::DeckPtr deck = createDeckUnInitialized(); BOOST_CHECK_THROW( new Opm::EclipseState( deck, Opm::ParseContext()) , std::invalid_argument ); } - BOOST_AUTO_TEST_CASE(IntSetCorrectly) { Opm::DeckPtr deck = createValidIntDeck(); Opm::EclipseState state(deck , Opm::ParseContext()); - std::shared_ptr > property = state.getIntGridProperty( "SATNUM"); - for (size_t j=0; j< 5; j++) + const auto& property = state.getEclipseProperties().getIntGridProperty("SATNUM"); + for (size_t j = 0; j < 5; j++) for (size_t i = 0; i < 5; i++) { if (i < 2) - BOOST_CHECK_EQUAL( 11 , property->iget(i,j,0)); + BOOST_CHECK_EQUAL(11, property.iget(i, j, 0)); else - BOOST_CHECK_EQUAL( 40 , property->iget(i,j,0)); + BOOST_CHECK_EQUAL(40, property.iget(i, j, 0)); } - } - - diff --git a/opm/parser/eclipse/EclipseState/Grid/tests/PORVTests.cpp b/opm/parser/eclipse/EclipseState/Grid/tests/PORVTests.cpp index f3fdf1e64..b918f9d74 100644 --- a/opm/parser/eclipse/EclipseState/Grid/tests/PORVTests.cpp +++ b/opm/parser/eclipse/EclipseState/Grid/tests/PORVTests.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -228,97 +229,103 @@ static Opm::DeckPtr createDeckWithNTG() { BOOST_AUTO_TEST_CASE(PORV_cartesianDeck) { /* Check that an exception is raised if we try to create a PORV field without PORO. */ Opm::DeckPtr deck = createCARTDeck(); - auto state = std::make_shared(deck , Opm::ParseContext()); - auto poro = state->getDoubleGridProperty("PORO"); - BOOST_CHECK( poro->containsNaN() ); - BOOST_CHECK_THROW( state->getDoubleGridProperty("PORV") , std::logic_error ); + Opm::EclipseState state(deck, Opm::ParseContext()); + const auto& props = state.getEclipseProperties(); + const auto& poro = props.getDoubleGridProperty("PORO"); + BOOST_CHECK(poro.containsNaN()); + BOOST_CHECK_THROW(props.getDoubleGridProperty("PORV"), std::logic_error); } BOOST_AUTO_TEST_CASE(PORV_initFromPoro) { /* Check that the PORV field is correctly calculated from PORO. */ Opm::DeckPtr deck = createDeckWithPORO(); - auto state = std::make_shared(deck , Opm::ParseContext()); - auto poro = state->getDoubleGridProperty("PORO"); - BOOST_CHECK( !poro->containsNaN() ); + Opm::EclipseState state(deck, Opm::ParseContext()); + const auto& props = state.getEclipseProperties(); + const auto& poro = props.getDoubleGridProperty("PORO"); + BOOST_CHECK( !poro.containsNaN() ); - auto porv = state->getDoubleGridProperty("PORV"); + const auto& porv = props.getDoubleGridProperty("PORV"); double cell_volume = 0.25 * 0.25 * 0.25; - BOOST_CHECK_CLOSE( cell_volume * 0.10 , porv->iget(0,0,0) , 0.001); - BOOST_CHECK_CLOSE( cell_volume * 0.10 , porv->iget(9,9,0) , 0.001); + BOOST_CHECK_CLOSE( cell_volume * 0.10 , porv.iget(0,0,0) , 0.001); + BOOST_CHECK_CLOSE( cell_volume * 0.10 , porv.iget(9,9,0) , 0.001); - BOOST_CHECK_CLOSE( cell_volume * 0.50 , porv->iget(0,0,4) , 0.001); - BOOST_CHECK_CLOSE( cell_volume * 0.50 , porv->iget(9,9,4) , 0.001); + BOOST_CHECK_CLOSE( cell_volume * 0.50 , porv.iget(0,0,4) , 0.001); + BOOST_CHECK_CLOSE( cell_volume * 0.50 , porv.iget(9,9,4) , 0.001); - BOOST_CHECK_CLOSE( cell_volume * 1.00 , porv->iget(0,0,9) , 0.001); - BOOST_CHECK_CLOSE( cell_volume * 1.00 , porv->iget(9,9,9) , 0.001); + BOOST_CHECK_CLOSE( cell_volume * 1.00 , porv.iget(0,0,9) , 0.001); + BOOST_CHECK_CLOSE( cell_volume * 1.00 , porv.iget(9,9,9) , 0.001); } BOOST_AUTO_TEST_CASE(PORV_initFromPoroWithCellVolume) { /* Check that explicit PORV and CellVOlume * PORO can be combined. */ Opm::DeckPtr deck = createDeckWithPORVPORO(); - auto state = std::make_shared(deck, Opm::ParseContext()); - auto porv = state->getDoubleGridProperty("PORV"); + Opm::EclipseState state(deck, Opm::ParseContext()); + const auto& props = state.getEclipseProperties(); + const auto& porv = props.getDoubleGridProperty("PORV"); double cell_volume = 0.25 * 0.25 * 0.25; - BOOST_CHECK_CLOSE( 77.0 , porv->iget(0,0,0) , 0.001); - BOOST_CHECK_CLOSE( 77.0 , porv->iget(9,9,0) , 0.001); + BOOST_CHECK_CLOSE( 77.0 , porv.iget(0,0,0) , 0.001); + BOOST_CHECK_CLOSE( 77.0 , porv.iget(9,9,0) , 0.001); - BOOST_CHECK_CLOSE( cell_volume * 0.50 , porv->iget(0,0,4) , 0.001); - BOOST_CHECK_CLOSE( cell_volume * 0.50 , porv->iget(9,9,4) , 0.001); + BOOST_CHECK_CLOSE( cell_volume * 0.50 , porv.iget(0,0,4) , 0.001); + BOOST_CHECK_CLOSE( cell_volume * 0.50 , porv.iget(9,9,4) , 0.001); - BOOST_CHECK_CLOSE( cell_volume * 1.00 , porv->iget(0,0,9) , 0.001); - BOOST_CHECK_CLOSE( cell_volume * 1.00 , porv->iget(9,9,9) , 0.001); + BOOST_CHECK_CLOSE( cell_volume * 1.00 , porv.iget(0,0,9) , 0.001); + BOOST_CHECK_CLOSE( cell_volume * 1.00 , porv.iget(9,9,9) , 0.001); } BOOST_AUTO_TEST_CASE(PORV_multpv) { /* Check that MULTPV is correctly accounted for. */ Opm::DeckPtr deck = createDeckWithMULTPV(); - auto state = std::make_shared(deck , Opm::ParseContext()); - auto porv = state->getDoubleGridProperty("PORV"); + Opm::EclipseState state(deck, Opm::ParseContext()); + const auto& props = state.getEclipseProperties(); + const auto& porv = props.getDoubleGridProperty("PORV"); double cell_volume = 0.25 * 0.25 * 0.25; - BOOST_CHECK_CLOSE( 770.0 , porv->iget(0,0,0) , 0.001); - BOOST_CHECK_CLOSE( 770.0 , porv->iget(4,4,0) , 0.001); - BOOST_CHECK_CLOSE( 77.0 , porv->iget(9,9,0) , 0.001); + BOOST_CHECK_CLOSE( 770.0 , porv.iget(0,0,0) , 0.001); + BOOST_CHECK_CLOSE( 770.0 , porv.iget(4,4,0) , 0.001); + BOOST_CHECK_CLOSE( 77.0 , porv.iget(9,9,0) , 0.001); - BOOST_CHECK_CLOSE( cell_volume * 0.50 , porv->iget(0,0,4) , 0.001); - BOOST_CHECK_CLOSE( cell_volume * 0.50 , porv->iget(9,9,4) , 0.001); + BOOST_CHECK_CLOSE( cell_volume * 0.50 , porv.iget(0,0,4) , 0.001); + BOOST_CHECK_CLOSE( cell_volume * 0.50 , porv.iget(9,9,4) , 0.001); - BOOST_CHECK_CLOSE( cell_volume * 0.90 , porv->iget(0,0,8) , 0.001); - BOOST_CHECK_CLOSE( cell_volume * 0.90 , porv->iget(9,9,8) , 0.001); + BOOST_CHECK_CLOSE( cell_volume * 0.90 , porv.iget(0,0,8) , 0.001); + BOOST_CHECK_CLOSE( cell_volume * 0.90 , porv.iget(9,9,8) , 0.001); - BOOST_CHECK_CLOSE( cell_volume * 10.00 , porv->iget(0,0,9) , 0.001); - BOOST_CHECK_CLOSE( cell_volume * 10.00 , porv->iget(9,9,9) , 0.001); + BOOST_CHECK_CLOSE( cell_volume * 10.00 , porv.iget(0,0,9) , 0.001); + BOOST_CHECK_CLOSE( cell_volume * 10.00 , porv.iget(9,9,9) , 0.001); } BOOST_AUTO_TEST_CASE(PORV_mutipleBoxAndMultpv) { /* Check that MULTIPLE Boxed PORV and MULTPV statements work */ Opm::DeckPtr deck = createDeckWithBOXPORV(); - auto state = std::make_shared(deck , Opm::ParseContext()); - auto porv = state->getDoubleGridProperty("PORV"); + Opm::EclipseState state(deck, Opm::ParseContext()); + const auto& props = state.getEclipseProperties(); + const auto& porv = props.getDoubleGridProperty("PORV"); - BOOST_CHECK_CLOSE( 1234.56 , porv->iget(0,0,0) , 0.001); - BOOST_CHECK_CLOSE( 1234.56 , porv->iget(9,9,9) , 0.001); + BOOST_CHECK_CLOSE( 1234.56 , porv.iget(0,0,0) , 0.001); + BOOST_CHECK_CLOSE( 1234.56 , porv.iget(9,9,9) , 0.001); - BOOST_CHECK_CLOSE( 7890.12 , porv->iget(1,1,1) , 0.001); - BOOST_CHECK_CLOSE( 7890.12 , porv->iget(2,2,2) , 0.001); + BOOST_CHECK_CLOSE( 7890.12 , porv.iget(1,1,1) , 0.001); + BOOST_CHECK_CLOSE( 7890.12 , porv.iget(2,2,2) , 0.001); } BOOST_AUTO_TEST_CASE(PORV_multpvAndNtg) { /* Check that MULTIPLE Boxed PORV and MULTPV statements work and NTG */ Opm::DeckPtr deck = createDeckWithNTG(); - auto state = std::make_shared(deck , Opm::ParseContext()); - auto porv = state->getDoubleGridProperty("PORV"); + Opm::EclipseState state(deck, Opm::ParseContext()); + const auto& props = state.getEclipseProperties(); + const auto& porv = props.getDoubleGridProperty("PORV"); double cell_volume = 0.25 * 0.25 * 0.25; double poro = 0.20; double multpv = 10; double NTG = 2; double PORV = 10; - BOOST_CHECK_CLOSE( PORV * multpv , porv->iget(0,0,0) , 0.001); - BOOST_CHECK_CLOSE( cell_volume * poro*multpv*NTG , porv->iget(9,9,9) , 0.001); + BOOST_CHECK_CLOSE( PORV * multpv , porv.iget(0,0,0) , 0.001); + BOOST_CHECK_CLOSE( cell_volume * poro*multpv*NTG , porv.iget(9,9,9) , 0.001); } @@ -343,6 +350,7 @@ static Opm::DeckPtr createDeckNakedGRID() { BOOST_AUTO_TEST_CASE(NAKED_GRID_THROWS) { /* Check that MULTIPLE Boxed PORV and MULTPV statements work and NTG */ Opm::DeckPtr deck = createDeckNakedGRID(); - auto state = std::make_shared(deck , Opm::ParseContext()); - BOOST_CHECK_THROW( state->getDoubleGridProperty("PORV") , std::invalid_argument ); + Opm::EclipseState state(deck, Opm::ParseContext()); + const auto& props = state.getEclipseProperties(); + BOOST_CHECK_THROW( props.getDoubleGridProperty("PORV") , std::invalid_argument ); } diff --git a/opm/parser/eclipse/EclipseState/Grid/tests/SatfuncPropertyInitializersTests.cpp b/opm/parser/eclipse/EclipseState/Grid/tests/SatfuncPropertyInitializersTests.cpp index 613bc004e..1b42f140b 100644 --- a/opm/parser/eclipse/EclipseState/Grid/tests/SatfuncPropertyInitializersTests.cpp +++ b/opm/parser/eclipse/EclipseState/Grid/tests/SatfuncPropertyInitializersTests.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -34,11 +35,10 @@ using namespace Opm; void check_property(EclipseState eclState1, EclipseState eclState2, const std::string& propertyName) { - const std::vector data1 = eclState1.getDoubleGridProperty(propertyName)->getData(); - const std::vector data2 = eclState2.getDoubleGridProperty(propertyName)->getData(); - - BOOST_CHECK_CLOSE(data1[0], data2[0],1e-12); + const std::vector data1 = eclState1.getEclipseProperties().getDoubleGridProperty(propertyName).getData(); + const std::vector data2 = eclState2.getEclipseProperties().getDoubleGridProperty(propertyName).getData(); + BOOST_CHECK_CLOSE(data1[0], data2[0],1e-12); } BOOST_AUTO_TEST_CASE(SaturationFunctionFamilyTests) { @@ -139,10 +139,8 @@ BOOST_AUTO_TEST_CASE(SaturationFunctionFamilyTests) { strcat(familyMixDeck , deckdefault); strcat(familyMixDeck , family1); strcat(familyMixDeck , family2); + DeckPtr deckMix = parser->parseString(familyMixDeck, parseContext) ; EclipseState stateMix(deckMix, parseContext); - BOOST_CHECK_THROW(stateMix.getDoubleGridProperty("SGCR") , std::invalid_argument); - + BOOST_CHECK_THROW(stateMix.getEclipseProperties().getDoubleGridProperty("SGCR") , std::invalid_argument); } - - diff --git a/opm/parser/eclipse/EclipseState/Grid/tests/TransMultTests.cpp b/opm/parser/eclipse/EclipseState/Grid/tests/TransMultTests.cpp index 4c3af098d..650feb51c 100644 --- a/opm/parser/eclipse/EclipseState/Grid/tests/TransMultTests.cpp +++ b/opm/parser/eclipse/EclipseState/Grid/tests/TransMultTests.cpp @@ -25,7 +25,7 @@ #include #include - +#include #include #include @@ -40,11 +40,4 @@ BOOST_AUTO_TEST_CASE(Empty) { BOOST_CHECK_EQUAL( transMult.getMultiplier(9,9,9, Opm::FaceDir::YMinus) , 1.0 ); BOOST_CHECK_EQUAL( transMult.getMultiplier(100 , Opm::FaceDir::ZMinus) , 1.0 ); - - BOOST_CHECK( !transMult.hasDirectionProperty( Opm::FaceDir::XPlus )); - BOOST_CHECK( !transMult.hasDirectionProperty( Opm::FaceDir::ZMinus )); - - std::shared_ptr > mult = transMult.getDirectionProperty( Opm::FaceDir::ZPlus ); - BOOST_CHECK_EQUAL( mult->getKeywordName() , "MULTZ"); - BOOST_CHECK( transMult.hasDirectionProperty( Opm::FaceDir::ZPlus )); } diff --git a/opm/parser/eclipse/EclipseState/IOConfig/IOConfig.hpp b/opm/parser/eclipse/EclipseState/IOConfig/IOConfig.hpp index bc954b6eb..4cfa53e54 100644 --- a/opm/parser/eclipse/EclipseState/IOConfig/IOConfig.hpp +++ b/opm/parser/eclipse/EclipseState/IOConfig/IOConfig.hpp @@ -180,8 +180,8 @@ namespace Opm { bool m_FMTOUT; std::string m_eclipse_input_path; bool m_ignore_RPTSCHED_RESTART; - int m_first_restart_step; - int m_first_rft_step; + int m_first_restart_step = 0; + int m_first_rft_step = 0; struct restartConfig { diff --git a/opm/parser/eclipse/EclipseState/SimulationConfig/SimulationConfig.cpp b/opm/parser/eclipse/EclipseState/SimulationConfig/SimulationConfig.cpp index acf434861..87a40e5d0 100644 --- a/opm/parser/eclipse/EclipseState/SimulationConfig/SimulationConfig.cpp +++ b/opm/parser/eclipse/EclipseState/SimulationConfig/SimulationConfig.cpp @@ -45,7 +45,9 @@ namespace Opm { - SimulationConfig::SimulationConfig(const ParseContext& parseContext , DeckConstPtr deck, std::shared_ptr> gridProperties) : + SimulationConfig::SimulationConfig(const ParseContext& parseContext, + DeckConstPtr deck, + GridProperties& gridProperties) : m_useCPR(false), m_DISGAS(false), m_VAPOIL(false) @@ -71,7 +73,9 @@ namespace Opm { } - void SimulationConfig::initThresholdPressure(const ParseContext& parseContext, DeckConstPtr deck, std::shared_ptr> gridProperties) { + void SimulationConfig::initThresholdPressure(const ParseContext& parseContext, + DeckConstPtr deck, + GridProperties& gridProperties) { m_ThresholdPressure = std::make_shared(parseContext , deck, gridProperties); } diff --git a/opm/parser/eclipse/EclipseState/SimulationConfig/SimulationConfig.hpp b/opm/parser/eclipse/EclipseState/SimulationConfig/SimulationConfig.hpp index 223239158..7329cf4ae 100644 --- a/opm/parser/eclipse/EclipseState/SimulationConfig/SimulationConfig.hpp +++ b/opm/parser/eclipse/EclipseState/SimulationConfig/SimulationConfig.hpp @@ -33,7 +33,9 @@ namespace Opm { public: - SimulationConfig(const ParseContext& parseContext , DeckConstPtr deck, std::shared_ptr> gridProperties); + SimulationConfig(const ParseContext& parseContext, + DeckConstPtr deck, + GridProperties& gridProperties); std::shared_ptr getThresholdPressure() const; bool hasThresholdPressure() const; @@ -43,7 +45,9 @@ namespace Opm { private: - void initThresholdPressure(const ParseContext& parseContext , DeckConstPtr deck, std::shared_ptr> gridProperties); + void initThresholdPressure(const ParseContext& parseContext, + DeckConstPtr deck, + GridProperties& gridProperties); std::shared_ptr< const ThresholdPressure > m_ThresholdPressure; bool m_useCPR; diff --git a/opm/parser/eclipse/EclipseState/SimulationConfig/ThresholdPressure.cpp b/opm/parser/eclipse/EclipseState/SimulationConfig/ThresholdPressure.cpp index 0a9215d2a..ce490cd40 100644 --- a/opm/parser/eclipse/EclipseState/SimulationConfig/ThresholdPressure.cpp +++ b/opm/parser/eclipse/EclipseState/SimulationConfig/ThresholdPressure.cpp @@ -29,14 +29,15 @@ namespace Opm { - ThresholdPressure::ThresholdPressure(const ParseContext& parseContext , DeckConstPtr deck, std::shared_ptr> gridProperties) - : m_parseContext( parseContext ) + ThresholdPressure::ThresholdPressure(const ParseContext& parseContext, DeckConstPtr deck, + GridProperties& gridProperties) : + m_parseContext( parseContext ) { - if (Section::hasRUNSPEC(*deck) && Section::hasSOLUTION(*deck)) { - std::shared_ptr runspecSection = std::make_shared(*deck); - std::shared_ptr solutionSection = std::make_shared(*deck); - initThresholdPressure(parseContext , runspecSection, solutionSection, gridProperties); + if (Section::hasRUNSPEC( *deck ) && Section::hasSOLUTION( *deck )) { + std::shared_ptr runspecSection = std::make_shared( *deck ); + std::shared_ptr solutionSection = std::make_shared( *deck ); + initThresholdPressure( parseContext, runspecSection, solutionSection, gridProperties ); } } @@ -67,11 +68,11 @@ namespace Opm { void ThresholdPressure::initThresholdPressure(const ParseContext& /* parseContext */, std::shared_ptr runspecSection, std::shared_ptr solutionSection, - std::shared_ptr> gridProperties) { + GridProperties& gridProperties) { bool thpresOption = false; const bool thpresKeyword = solutionSection->hasKeyword( ); - const bool hasEqlnumKeyword = gridProperties->hasKeyword( ); + const bool hasEqlnumKeyword = gridProperties.hasKeyword( ); int maxEqlnum = 0; //Is THPRES option set? @@ -95,8 +96,8 @@ namespace Opm { { //Find max of eqlnum if (hasEqlnumKeyword) { - const auto& eqlnumKeyword = gridProperties->getKeyword( ); - const auto& eqlnum = eqlnumKeyword->getData(); + const auto& eqlnumKeyword = gridProperties.getKeyword( ); + const auto& eqlnum = eqlnumKeyword.getData(); maxEqlnum = *std::max_element(eqlnum.begin(), eqlnum.end()); if (0 == maxEqlnum) { diff --git a/opm/parser/eclipse/EclipseState/SimulationConfig/ThresholdPressure.hpp b/opm/parser/eclipse/EclipseState/SimulationConfig/ThresholdPressure.hpp index 306efd6cc..229faf1a8 100644 --- a/opm/parser/eclipse/EclipseState/SimulationConfig/ThresholdPressure.hpp +++ b/opm/parser/eclipse/EclipseState/SimulationConfig/ThresholdPressure.hpp @@ -36,7 +36,9 @@ namespace Opm { public: - ThresholdPressure(const ParseContext& parseContext , std::shared_ptr< const Deck > deck, std::shared_ptr> gridProperties); + ThresholdPressure(const ParseContext& parseContext, + std::shared_ptr< const Deck > deck, + GridProperties& gridProperties); /* @@ -69,7 +71,7 @@ namespace Opm { void initThresholdPressure(const ParseContext& parseContext, std::shared_ptr runspecSection, std::shared_ptr solutionSection, - std::shared_ptr> gridProperties); + GridProperties& gridProperties); static std::pair makeIndex(int r1 , int r2); void addPair(int r1 , int r2 , const std::pair& valuePair); diff --git a/opm/parser/eclipse/EclipseState/SimulationConfig/tests/SimulationConfigTest.cpp b/opm/parser/eclipse/EclipseState/SimulationConfig/tests/SimulationConfigTest.cpp index 9b070f42d..690ec2faf 100644 --- a/opm/parser/eclipse/EclipseState/SimulationConfig/tests/SimulationConfigTest.cpp +++ b/opm/parser/eclipse/EclipseState/SimulationConfig/tests/SimulationConfigTest.cpp @@ -105,50 +105,51 @@ const std::string& inputStr_vap_dis = "RUNSPEC\n" "REGIONS\n" "\n"; -static DeckPtr createDeck(const ParseContext& parseContext , const std::string& input) { +static DeckPtr createDeck(const ParseContext& parseContext, const std::string& input) { Opm::Parser parser; return parser.parseString(input, parseContext); } - -static std::shared_ptr> getGridProperties() { +static GridProperties getGridProperties() { GridPropertySupportedKeywordInfo kwInfo = GridPropertySupportedKeywordInfo("EQLNUM", 3, ""); std::vector> supportedKeywordsVec; supportedKeywordsVec.push_back(kwInfo); - EclipseGridConstPtr eclipseGrid = std::make_shared(3, 3, 3); - std::shared_ptr> gridProperties = std::make_shared>(eclipseGrid, std::move(supportedKeywordsVec)); - gridProperties->addKeyword("EQLNUM"); + const EclipseGrid eclipseGrid(3, 3, 3); + GridProperties gridProperties(eclipseGrid, std::move(supportedKeywordsVec)); + gridProperties.addKeyword("EQLNUM"); return gridProperties; } - BOOST_AUTO_TEST_CASE(SimulationConfigGetThresholdPressureTableTest) { ParseContext parseContext; - DeckPtr deck = createDeck(parseContext , inputStr); + auto gp = getGridProperties(); + DeckPtr deck = createDeck(parseContext, inputStr); SimulationConfigConstPtr simulationConfigPtr; - BOOST_CHECK_NO_THROW(simulationConfigPtr = std::make_shared(parseContext , deck, getGridProperties())); + BOOST_CHECK_NO_THROW( simulationConfigPtr = std::make_shared( parseContext, deck, gp ) ); } - BOOST_AUTO_TEST_CASE(SimulationConfigNOTHPRES) { ParseContext parseContext; + auto gp = getGridProperties(); DeckPtr deck = createDeck(parseContext , inputStr_noTHPRES); - SimulationConfig simulationConfig(parseContext , deck, getGridProperties()); + SimulationConfig simulationConfig(parseContext , deck, gp); BOOST_CHECK_EQUAL( false , simulationConfig.hasThresholdPressure()); } BOOST_AUTO_TEST_CASE(SimulationConfigCPRNotUsed) { ParseContext parseContext; + auto gp = getGridProperties(); DeckPtr deck = createDeck(parseContext , inputStr_noTHPRES); - SimulationConfig simulationConfig(parseContext , deck, getGridProperties()); + SimulationConfig simulationConfig(parseContext , deck, gp); BOOST_CHECK_EQUAL( false , simulationConfig.useCPR()); } BOOST_AUTO_TEST_CASE(SimulationConfigCPRUsed) { ParseContext parseContext; + auto gp = getGridProperties(); DeckPtr deck = createDeck(parseContext , inputStr_cpr); SUMMARYSection summary(*deck); - SimulationConfig simulationConfig(parseContext , deck, getGridProperties()); + SimulationConfig simulationConfig(parseContext , deck, gp); BOOST_CHECK_EQUAL( true , simulationConfig.useCPR()); BOOST_CHECK_EQUAL( false , summary.hasKeyword("CPR")); } @@ -156,9 +157,10 @@ BOOST_AUTO_TEST_CASE(SimulationConfigCPRUsed) { BOOST_AUTO_TEST_CASE(SimulationConfigCPRInSUMMARYSection) { ParseContext parseContext; + auto gp = getGridProperties(); DeckPtr deck = createDeck(parseContext , inputStr_cpr_in_SUMMARY); SUMMARYSection summary(*deck); - SimulationConfig simulationConfig(parseContext , deck, getGridProperties()); + SimulationConfig simulationConfig(parseContext , deck, gp); BOOST_CHECK_EQUAL( false , simulationConfig.useCPR()); BOOST_CHECK_EQUAL( true , summary.hasKeyword("CPR")); } @@ -166,9 +168,10 @@ BOOST_AUTO_TEST_CASE(SimulationConfigCPRInSUMMARYSection) { BOOST_AUTO_TEST_CASE(SimulationConfigCPRBoth) { ParseContext parseContext; + auto gp = getGridProperties(); DeckPtr deck = createDeck(parseContext , inputStr_cpr_BOTH); SUMMARYSection summary(*deck); - SimulationConfig simulationConfig(parseContext , deck, getGridProperties()); + SimulationConfig simulationConfig(parseContext , deck, gp); BOOST_CHECK_EQUAL( true , simulationConfig.useCPR()); BOOST_CHECK_EQUAL( true , summary.hasKeyword("CPR")); @@ -190,13 +193,15 @@ BOOST_AUTO_TEST_CASE(SimulationConfigCPRRUnspecWithData) { BOOST_AUTO_TEST_CASE(SimulationConfig_VAPOIL_DISGAS) { ParseContext parseContext; + auto gp1 = getGridProperties(); DeckPtr deck = createDeck(parseContext , inputStr); - SimulationConfig simulationConfig(parseContext , deck, getGridProperties()); + SimulationConfig simulationConfig(parseContext , deck, gp1); BOOST_CHECK_EQUAL( false , simulationConfig.hasDISGAS()); BOOST_CHECK_EQUAL( false , simulationConfig.hasVAPOIL()); + auto gp2 = getGridProperties(); DeckPtr deck_vd = createDeck(parseContext, inputStr_vap_dis); - SimulationConfig simulationConfig_vd(parseContext , deck_vd, getGridProperties()); + SimulationConfig simulationConfig_vd(parseContext , deck_vd, gp2); BOOST_CHECK_EQUAL( true , simulationConfig_vd.hasDISGAS()); BOOST_CHECK_EQUAL( true , simulationConfig_vd.hasVAPOIL()); } diff --git a/opm/parser/eclipse/EclipseState/SimulationConfig/tests/ThresholdPressureTest.cpp b/opm/parser/eclipse/EclipseState/SimulationConfig/tests/ThresholdPressureTest.cpp index 9a44e1462..75ae7bc33 100644 --- a/opm/parser/eclipse/EclipseState/SimulationConfig/tests/ThresholdPressureTest.cpp +++ b/opm/parser/eclipse/EclipseState/SimulationConfig/tests/ThresholdPressureTest.cpp @@ -32,6 +32,7 @@ #include #include #include + #include #include @@ -139,23 +140,21 @@ static DeckPtr createDeck(const ParseContext& parseContext , const std::string& return parser.parseString(input , parseContext); } - -static std::shared_ptr> getGridProperties(int defaultEqlnum = 3, bool addKeyword = true) { - GridPropertySupportedKeywordInfo kwInfo = GridPropertySupportedKeywordInfo("EQLNUM", defaultEqlnum, ""); +static GridProperties getGridProperties(int defaultEqlnum = 3, bool addKeyword = true) { + GridPropertySupportedKeywordInfo kwInfo = GridPropertySupportedKeywordInfo( "EQLNUM", defaultEqlnum, "" ); std::vector> supportedKeywordsVec( 1, kwInfo ); - EclipseGridConstPtr eclipseGrid = std::make_shared(3, 3, 3); - std::shared_ptr> gridProperties = std::make_shared>(eclipseGrid, std::move( supportedKeywordsVec ) ); + const EclipseGrid eclipseGrid( 3, 3, 3 ); + GridProperties gridProperties( eclipseGrid, std::move( supportedKeywordsVec ) ); if (addKeyword) { - gridProperties->addKeyword("EQLNUM"); + gridProperties.addKeyword( "EQLNUM" ); } return gridProperties; } - BOOST_AUTO_TEST_CASE(ThresholdPressureTest) { ParseContext parseContext; DeckPtr deck = createDeck(parseContext , inputStr); - static std::shared_ptr> gridProperties = getGridProperties(); + auto gridProperties = getGridProperties(); ThresholdPressureConstPtr thp = std::make_shared(parseContext , deck, gridProperties); @@ -172,7 +171,7 @@ BOOST_AUTO_TEST_CASE(ThresholdPressureTest) { BOOST_AUTO_TEST_CASE(ThresholdPressureEmptyTest) { ParseContext parseContext; DeckPtr deck = createDeck(parseContext , inputStrNoSolutionSection); - static std::shared_ptr> gridProperties = getGridProperties(); + auto gridProperties = getGridProperties(); ThresholdPressureConstPtr thresholdPressurePtr = std::make_shared(parseContext , deck, gridProperties); BOOST_CHECK_EQUAL(0, thresholdPressurePtr->size()); } @@ -182,7 +181,7 @@ BOOST_AUTO_TEST_CASE(ThresholdPressureNoTHPREStest) { ParseContext parseContext; DeckPtr deck_no_thpres = createDeck(parseContext , inputStrNoTHPRESinSolutionNorRUNSPEC); DeckPtr deck_no_thpres2 = createDeck(parseContext , inputStrTHPRESinRUNSPECnotSoultion); - static std::shared_ptr> gridProperties = getGridProperties(); + auto gridProperties = getGridProperties(); ThresholdPressureConstPtr thresholdPressurePtr; BOOST_CHECK_NO_THROW(thresholdPressurePtr = std::make_shared(parseContext , deck_no_thpres, gridProperties)); @@ -202,7 +201,7 @@ BOOST_AUTO_TEST_CASE(ThresholdPressureThrowTest) { DeckPtr deck_highRegNum = createDeck(parseContext , inputStrTooHighRegionNumbers); DeckPtr deck_missingData = createDeck(parseContext , inputStrMissingData); DeckPtr deck_missingPressure = createDeck(parseContext , inputStrMissingPressure); - static std::shared_ptr> gridProperties = getGridProperties(); + auto gridProperties = getGridProperties(); BOOST_CHECK_THROW(std::make_shared(parseContext,deck_irrevers, gridProperties), std::runtime_error); BOOST_CHECK_THROW(std::make_shared(parseContext,deck_inconsistency, gridProperties), std::runtime_error); @@ -210,11 +209,11 @@ BOOST_AUTO_TEST_CASE(ThresholdPressureThrowTest) { BOOST_CHECK_THROW(std::make_shared(parseContext,deck_missingData, gridProperties), std::runtime_error); { - static std::shared_ptr> gridPropertiesEQLNUMkeywordNotAdded = getGridProperties(3, false); + auto gridPropertiesEQLNUMkeywordNotAdded = getGridProperties(3, false); BOOST_CHECK_THROW(std::make_shared(parseContext , deck, gridPropertiesEQLNUMkeywordNotAdded), std::runtime_error); } { - static std::shared_ptr> gridPropertiesEQLNUMall0 = getGridProperties(0); + auto gridPropertiesEQLNUMall0 = getGridProperties(0); BOOST_CHECK_THROW(std::make_shared(parseContext , deck, gridPropertiesEQLNUMall0), std::runtime_error); } @@ -240,7 +239,7 @@ BOOST_AUTO_TEST_CASE(ThresholdPressureThrowTest) { BOOST_AUTO_TEST_CASE(HasPair) { ParseContext parseContext; DeckPtr deck = createDeck(parseContext , inputStr); - static std::shared_ptr> gridProperties = getGridProperties(); + auto gridProperties = getGridProperties(); ThresholdPressure thp(parseContext , deck , gridProperties); BOOST_CHECK_EQUAL( true , thp.hasRegionBarrier( 1 , 2 )); diff --git a/opm/parser/eclipse/EclipseState/Tables/TableManager.cpp b/opm/parser/eclipse/EclipseState/Tables/TableManager.cpp index 7fea2a465..fc5b72398 100644 --- a/opm/parser/eclipse/EclipseState/Tables/TableManager.cpp +++ b/opm/parser/eclipse/EclipseState/Tables/TableManager.cpp @@ -30,6 +30,7 @@ #include #include +#include // Phase::PhaseEnum #include #include #include @@ -73,7 +74,13 @@ namespace Opm { - TableManager::TableManager( const Deck& deck ) { + TableManager::TableManager( const Deck& deck ) + : + hasImptvd (deck.hasKeyword("IMPTVD")), + hasEnptvd (deck.hasKeyword("ENPTVD")), + hasEqlnum (deck.hasKeyword("EQLNUM")) + { + initPhases( deck ); initDims( deck ); initSimpleTables( deck ); initFullTables(deck, "PVTG", m_pvtgTables); @@ -83,6 +90,28 @@ namespace Opm { initVFPInjTables(deck, m_vfpinjTables); } + void TableManager::initPhases(const Deck& deck) { + if (deck.hasKeyword("OIL")) + phases.insert(Phase::PhaseEnum::OIL); + + if (deck.hasKeyword("GAS")) + phases.insert(Phase::PhaseEnum::GAS); + + if (deck.hasKeyword("WATER")) + phases.insert(Phase::PhaseEnum::WATER); + + if (phases.size() < 3) + OpmLog::addMessage(Log::MessageType::Info , "Only " + std::to_string(static_cast(phases.size())) + " fluid phases are enabled"); + } + + size_t TableManager::getNumPhases() const{ + return phases.size(); + } + + bool TableManager::hasPhase(enum Phase::PhaseEnum phase) const { + return (phases.count(phase) == 1); + } + void TableManager::initDims(const Deck& deck) { using namespace Opm::ParserKeywords; @@ -665,6 +694,18 @@ namespace Opm { return m_vfpinjTables; } + const bool TableManager::useImptvd() const { + return hasImptvd; + } + + const bool TableManager::useEnptvd() const { + return hasEnptvd; + } + + const bool TableManager::useEqlnum() const { + return hasEqlnum; + } + void TableManager::complainAboutAmbiguousKeyword(const Deck& deck, const std::string& keywordName) const { OpmLog::addMessage(Log::MessageType::Error, "The " + keywordName + " keyword must be unique in the deck. Ignoring all!"); @@ -675,5 +716,3 @@ namespace Opm { } } } - - diff --git a/opm/parser/eclipse/EclipseState/Tables/TableManager.hpp b/opm/parser/eclipse/EclipseState/Tables/TableManager.hpp index ceef3347b..371e44a5c 100644 --- a/opm/parser/eclipse/EclipseState/Tables/TableManager.hpp +++ b/opm/parser/eclipse/EclipseState/Tables/TableManager.hpp @@ -20,10 +20,14 @@ #ifndef OPM_TABLE_MANAGER_HPP #define OPM_TABLE_MANAGER_HPP +#include + #include #include #include +#include // Phase::PhaseEnum + #include #include @@ -101,6 +105,21 @@ namespace Opm { const std::vector& getPvtoTables() const; const std::map& getVFPProdTables() const; const std::map& getVFPInjTables() const; + + bool hasPhase(enum Phase::PhaseEnum phase) const; + + /// number of phases, [gas, oil, water] = 3 + size_t getNumPhases() const; + + /// deck has keyword "IMPTVD" --- Imbition end-point versus depth tables + const bool useImptvd() const; + + /// deck has keyword "ENPTVD" --- Saturation end-point versus depth tables + const bool useEnptvd() const; + + /// deck has keyword "EQLNUM" --- Equilibriation region numbers + const bool useEqlnum() const; + private: TableContainer& forceGetTables( const std::string& tableName , size_t numTables); @@ -109,6 +128,7 @@ namespace Opm { void addTables( const std::string& tableName , size_t numTables); void initSimpleTables(const Deck& deck); void initRTempTables(const Deck& deck); + void initPhases(const Deck& deck); void initDims(const Deck& deck); void initRocktabTables(const Deck& deck); void initGasvisctTables(const Deck& deck); @@ -119,7 +139,6 @@ namespace Opm { void initVFPInjTables(const Deck& deck, std::map& tableMap); - void initPlymaxTables(const Deck& deck); void initPlyrockTables(const Deck& deck); void initPlyshlogTables(const Deck& deck); @@ -218,6 +237,12 @@ namespace Opm { std::shared_ptr m_regdims; std::shared_ptr m_tabdims; std::shared_ptr m_eqldims; + + std::set phases; + + const bool hasImptvd;// if deck has keyword IMPTVD + const bool hasEnptvd;// if deck has keyword ENPTVD + const bool hasEqlnum;// if deck has keyword EQLNUM }; } diff --git a/opm/parser/eclipse/EclipseState/Tables/tests/TableManagerTests.cpp b/opm/parser/eclipse/EclipseState/Tables/tests/TableManagerTests.cpp index cdd2e61ad..6ac68dfcb 100644 --- a/opm/parser/eclipse/EclipseState/Tables/tests/TableManagerTests.cpp +++ b/opm/parser/eclipse/EclipseState/Tables/tests/TableManagerTests.cpp @@ -64,14 +64,86 @@ std::shared_ptr createSingleRecordDeck() { } +std::shared_ptr createSingleRecordDeckWithVd() { + const char *deckData = + "RUNSPEC\n" + "ENDSCALE\n" + "2* 1 2 /\n" + "PROPS\n" + "TABDIMS\n" + " 2 /\n" + "\n" + "SWFN\n" + "0.22 .0 7.0 \n" + "0.3 .0 4.0 \n" + "0.5 .24 2.5 \n" + "0.8 .65 1.0 \n" + "0.9 .83 .5 \n" + "1.0 1.00 .0 /\n" + "/\n" + "IMPTVD\n" + "3000.0 6*0.1 0.31 1*0.1\n" + "9000.0 6*0.1 0.32 1*0.1/\n" + "ENPTVD\n" + "3000.0 0.20 0.20 1.0 0.0 0.04 1.0 0.18 0.22\n" + "9000.0 0.22 0.22 1.0 0.0 0.04 1.0 0.18 0.22 /"; + + Opm::ParserPtr parser(new Opm::Parser); + Opm::DeckConstPtr deck(parser->parseString(deckData, Opm::ParseContext())); + return deck; +} + + +std::shared_ptr createSingleRecordDeckWithVd() { + const char *deckData = + "RUNSPEC\n" + "ENDSCALE\n" + "2* 1 2 /\n" + "PROPS\n" + "TABDIMS\n" + " 2 /\n" + "\n" + "SWFN\n" + "0.22 .0 7.0 \n" + "0.3 .0 4.0 \n" + "0.5 .24 2.5 \n" + "0.8 .65 1.0 \n" + "0.9 .83 .5 \n" + "1.0 1.00 .0 /\n" + "/\n" + "IMPTVD\n" + "3000.0 6*0.1 0.31 1*0.1\n" + "9000.0 6*0.1 0.32 1*0.1/\n" + "ENPTVD\n" + "3000.0 0.20 0.20 1.0 0.0 0.04 1.0 0.18 0.22\n" + "9000.0 0.22 0.22 1.0 0.0 0.04 1.0 0.18 0.22 /"; + + Opm::ParserPtr parser(new Opm::Parser); + Opm::DeckConstPtr deck(parser->parseString(deckData, Opm::ParseMode())); + return deck; +} + + BOOST_AUTO_TEST_CASE( CreateTables ) { std::shared_ptr deck = createSingleRecordDeck(); Opm::TableManager tables(*deck); auto tabdims = tables.getTabdims(); BOOST_CHECK_EQUAL( tabdims->getNumSatTables() , 2 ); + BOOST_CHECK( !tables.useImptvd() ); + BOOST_CHECK( !tables.useEnptvd() ); } +BOOST_AUTO_TEST_CASE( CreateTablesWithVd ) { + std::shared_ptr deck = createSingleRecordDeckWithVd(); + Opm::TableManager tables(*deck); + auto tabdims = tables.getTabdims(); + BOOST_CHECK_EQUAL( tabdims->getNumSatTables() , 2 ); + BOOST_CHECK( tables.useImptvd() ); + BOOST_CHECK( tables.useEnptvd() ); +} + + /*****************************************************************/ diff --git a/opm/parser/eclipse/EclipseState/tests/EclipseStateTests.cpp b/opm/parser/eclipse/EclipseState/tests/EclipseStateTests.cpp index 1b22e94f9..51d289c1e 100644 --- a/opm/parser/eclipse/EclipseState/tests/EclipseStateTests.cpp +++ b/opm/parser/eclipse/EclipseState/tests/EclipseStateTests.cpp @@ -29,21 +29,23 @@ #include #include -#include #include #include #include #include +#include #include #include #include #include #include +#include #include #include #include #include +#include #include #include #include @@ -95,25 +97,22 @@ static DeckPtr createDeckTOP() { return parser->parseString(deckData, ParseContext()) ; } - - BOOST_AUTO_TEST_CASE(GetPOROTOPBased) { DeckPtr deck = createDeckTOP(); EclipseState state(deck , ParseContext()); + auto& props = state.getEclipseProperties(); - std::shared_ptr > poro = state.getDoubleGridProperty( "PORO" ); - std::shared_ptr > permx = state.getDoubleGridProperty( "PERMX" ); + const GridProperty& poro = props.getDoubleGridProperty( "PORO" ); + const GridProperty& permx = props.getDoubleGridProperty( "PERMX" ); - BOOST_CHECK_EQUAL(1000U , poro->getCartesianSize() ); - BOOST_CHECK_EQUAL(1000U , permx->getCartesianSize() ); - for (size_t i=0; i < poro->getCartesianSize(); i++) { - BOOST_CHECK_EQUAL( 0.10 , poro->iget(i) ); - BOOST_CHECK_EQUAL( 0.25 * Metric::Permeability , permx->iget(i) ); + BOOST_CHECK_EQUAL(1000U , poro.getCartesianSize() ); + BOOST_CHECK_EQUAL(1000U , permx.getCartesianSize() ); + for (size_t i=0; i < poro.getCartesianSize(); i++) { + BOOST_CHECK_EQUAL( 0.10 , poro.iget(i) ); + BOOST_CHECK_EQUAL( 0.25 * Metric::Permeability , permx.iget(i) ); } - } - static DeckPtr createDeck() { const char *deckData = "RUNSPEC\n" @@ -183,6 +182,11 @@ static DeckPtr createDeckNoFaults() { return parser->parseString(deckData, ParseContext()) ; } +BOOST_AUTO_TEST_CASE(GetProperties) { + DeckPtr deck = createDeck(); + EclipseState state(deck , ParseContext()); + BOOST_CHECK(state.getEclipseProperties()); +} BOOST_AUTO_TEST_CASE(CreateSchedule) { DeckPtr deck = createDeck(); @@ -226,8 +230,11 @@ BOOST_AUTO_TEST_CASE(CreateSimulationConfig) { DeckPtr deck = createDeckSimConfig(); EclipseState state(deck, ParseContext()); - SimulationConfigConstPtr simulationConfig = state.getSimulationConfig(); - std::shared_ptr thresholdPressure = simulationConfig->getThresholdPressure(); + SimulationConfigConstPtr simConf = state.getSimulationConfig(); + + BOOST_CHECK( simConf->hasThresholdPressure() ); + + std::shared_ptr thresholdPressure = simConf->getThresholdPressure(); BOOST_CHECK_EQUAL(thresholdPressure->size(), 3); } @@ -235,89 +242,75 @@ BOOST_AUTO_TEST_CASE(CreateSimulationConfig) { BOOST_AUTO_TEST_CASE(PhasesCorrect) { DeckPtr deck = createDeck(); - EclipseState state(deck, ParseContext()); - - BOOST_CHECK( state.hasPhase( Phase::PhaseEnum::OIL )); - BOOST_CHECK( state.hasPhase( Phase::PhaseEnum::GAS )); - BOOST_CHECK( !state.hasPhase( Phase::PhaseEnum::WATER )); + EclipseState state( deck, ParseContext() ); + const TableManager& tm = *state.getTableManager(); + BOOST_CHECK( tm.hasPhase( Phase::PhaseEnum::OIL )); + BOOST_CHECK( tm.hasPhase( Phase::PhaseEnum::GAS )); + BOOST_CHECK( !(tm.hasPhase( Phase::PhaseEnum::WATER ))); } - BOOST_AUTO_TEST_CASE(TitleCorrect) { DeckPtr deck = createDeck(); EclipseState state(deck, ParseContext()); - BOOST_CHECK_EQUAL( state.getTitle(), "The title"); + BOOST_CHECK_EQUAL( state.getTitle(), "The title" ); } - BOOST_AUTO_TEST_CASE(IntProperties) { DeckPtr deck = createDeck(); EclipseState state(deck, ParseContext()); - - BOOST_CHECK_EQUAL( false , state.supportsGridProperty("NONO")); - BOOST_CHECK_EQUAL( true , state.supportsGridProperty("SATNUM")); - BOOST_CHECK_EQUAL( true , state.hasDeckIntGridProperty("SATNUM")); + BOOST_CHECK( ! state.getEclipseProperties().supportsGridProperty( "NONO" ) ); + BOOST_CHECK( state.getEclipseProperties().supportsGridProperty( "SATNUM" ) ); + BOOST_CHECK( state.getEclipseProperties().hasDeckIntGridProperty( "SATNUM" ) ); } - - -BOOST_AUTO_TEST_CASE(PropertiesNotSupportedThrows) { - std::shared_ptr counter = std::make_shared(Log::MessageType::Error); - OpmLog::addBackend("COUNTER" , counter); +BOOST_AUTO_TEST_CASE(PropertiesNotSupportsFalse) { DeckPtr deck = createDeck(); - EclipseState state(deck , ParseContext()); - const auto& swat = deck->getKeyword("SWAT"); - BOOST_CHECK_EQUAL( false , state.supportsGridProperty("SWAT")); - state.loadGridPropertyFromDeckKeyword(std::make_shared(10,10,10), swat); - BOOST_CHECK_EQUAL( 1 , counter->numMessages(Log::MessageType::Error) ); + EclipseState state( deck, ParseContext() ); + const auto& props = state.getEclipseProperties(); + BOOST_CHECK( ! props.supportsGridProperty( "SWAT" ) ); } - BOOST_AUTO_TEST_CASE(GetProperty) { DeckPtr deck = createDeck(); EclipseState state(deck, ParseContext()); - std::shared_ptr > satNUM = state.getIntGridProperty( "SATNUM" ); + const auto& satNUM = state.getEclipseProperties().getIntGridProperty( "SATNUM" ); - BOOST_CHECK_EQUAL(1000U , satNUM->getCartesianSize() ); - for (size_t i=0; i < satNUM->getCartesianSize(); i++) - BOOST_CHECK_EQUAL( 2 , satNUM->iget(i) ); + BOOST_CHECK_EQUAL(1000U , satNUM.getCartesianSize() ); + for (size_t i=0; i < satNUM.getCartesianSize(); i++) + BOOST_CHECK_EQUAL( 2 , satNUM.iget(i) ); - BOOST_CHECK_THROW( satNUM->iget(100000) , std::invalid_argument); + BOOST_CHECK_THROW( satNUM.iget(100000) , std::invalid_argument); } - BOOST_AUTO_TEST_CASE(GetTransMult) { DeckPtr deck = createDeck(); EclipseState state(deck, ParseContext()); std::shared_ptr transMult = state.getTransMult(); - - BOOST_CHECK_EQUAL( 1.0 , transMult->getMultiplier(1,0,0,FaceDir::XPlus)); - BOOST_CHECK_THROW(transMult->getMultiplier(1000 , FaceDir::XPlus) , std::invalid_argument); + BOOST_CHECK_EQUAL( 1.0, transMult->getMultiplier( 1, 0, 0, FaceDir::XPlus ) ); + BOOST_CHECK_THROW( transMult->getMultiplier( 1000, FaceDir::XPlus ), std::invalid_argument ); } - - BOOST_AUTO_TEST_CASE(GetFaults) { DeckPtr deck = createDeck(); EclipseState state(deck , ParseContext()); std::shared_ptr faults = state.getFaults(); - BOOST_CHECK( faults->hasFault("F1") ); - BOOST_CHECK( faults->hasFault("F2") ); + BOOST_CHECK( faults->hasFault( "F1" ) ); + BOOST_CHECK( faults->hasFault( "F2" ) ); - std::shared_ptr F1 = faults->getFault("F1"); - std::shared_ptr F2 = faults->getFault("F2"); + std::shared_ptr F1 = faults->getFault( "F1" ); + std::shared_ptr F2 = faults->getFault( "F2" ); - BOOST_CHECK_EQUAL( 0.50 , F1->getTransMult()); - BOOST_CHECK_EQUAL( 0.25 , F2->getTransMult()); + BOOST_CHECK_EQUAL( 0.50, F1->getTransMult() ); + BOOST_CHECK_EQUAL( 0.25, F2->getTransMult() ); std::shared_ptr transMult = state.getTransMult(); - BOOST_CHECK_EQUAL( transMult->getMultiplier(0 , 0 , 0 , FaceDir::XPlus) , 0.50 ); - BOOST_CHECK_EQUAL( transMult->getMultiplier(4 , 3 , 0 , FaceDir::XMinus) , 0.25 ); - BOOST_CHECK_EQUAL( transMult->getMultiplier(4 , 3 , 0 , FaceDir::ZPlus) , 1.00 ); + BOOST_CHECK_EQUAL( transMult->getMultiplier( 0, 0, 0, FaceDir::XPlus ), 0.50 ); + BOOST_CHECK_EQUAL( transMult->getMultiplier( 4, 3, 0, FaceDir::XMinus ), 0.25 ); + BOOST_CHECK_EQUAL( transMult->getMultiplier( 4, 3, 0, FaceDir::ZPlus ), 1.00 ); } @@ -403,22 +396,28 @@ static DeckPtr createDeckWithGridOpts() { BOOST_AUTO_TEST_CASE(NoGridOptsDefaultRegion) { DeckPtr deck = createDeckNoGridOpts(); EclipseState state(deck, ParseContext()); - auto multnum = state.getIntGridProperty("MULTNUM"); - auto fluxnum = state.getIntGridProperty("FLUXNUM"); - auto def_property = state.getDefaultRegion(); + const auto& props = state.getEclipseProperties(); + const auto& multnum = props.getIntGridProperty("MULTNUM"); + const auto& fluxnum = props.getIntGridProperty("FLUXNUM"); + const auto default_kw = props.getDefaultRegionKeyword(); + const auto& def_pro = props.getIntGridProperty(default_kw); - BOOST_CHECK_EQUAL( fluxnum , def_property ); + BOOST_CHECK_EQUAL( &fluxnum , &def_pro ); + BOOST_CHECK_NE( &fluxnum , &multnum ); } BOOST_AUTO_TEST_CASE(WithGridOptsDefaultRegion) { DeckPtr deck = createDeckWithGridOpts(); EclipseState state(deck, ParseContext()); - auto multnum = state.getIntGridProperty("MULTNUM"); - auto fluxnum = state.getIntGridProperty("FLUXNUM"); - auto def_property = state.getDefaultRegion(); + const auto& props = state.getEclipseProperties(); + const auto& multnum = props.getIntGridProperty("MULTNUM"); + const auto& fluxnum = props.getIntGridProperty("FLUXNUM"); + const auto default_kw = props.getDefaultRegionKeyword(); + const auto& def_pro = props.getIntGridProperty(default_kw); - BOOST_CHECK_EQUAL( multnum , def_property ); + BOOST_CHECK_EQUAL( &multnum , &def_pro ); + BOOST_CHECK_NE( &fluxnum , &multnum ); } diff --git a/opm/parser/eclipse/IntegrationTests/BoxTest.cpp b/opm/parser/eclipse/IntegrationTests/BoxTest.cpp index ffd3243d0..707fc3a90 100644 --- a/opm/parser/eclipse/IntegrationTests/BoxTest.cpp +++ b/opm/parser/eclipse/IntegrationTests/BoxTest.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -50,19 +51,19 @@ EclipseState makeState(const std::string& fileName) { BOOST_AUTO_TEST_CASE( PERMX ) { - EclipseState state = makeState("testdata/integration_tests/BOX/BOXTEST1" ); - std::shared_ptr > permx = state.getDoubleGridProperty("PERMX"); - std::shared_ptr > permy = state.getDoubleGridProperty("PERMY"); - std::shared_ptr > permz = state.getDoubleGridProperty("PERMZ"); - size_t i,j,k; + EclipseState state = makeState( "testdata/integration_tests/BOX/BOXTEST1" ); + const auto& permx = state.getEclipseProperties().getDoubleGridProperty( "PERMX" ); + const auto& permy = state.getEclipseProperties().getDoubleGridProperty( "PERMY" ); + const auto& permz = state.getEclipseProperties().getDoubleGridProperty( "PERMZ" ); + size_t i, j, k; std::shared_ptr grid = state.getEclipseGrid(); for (k = 0; k < grid->getNZ(); k++) { for (j = 0; j < grid->getNY(); j++) { for (i = 0; i < grid->getNX(); i++) { - BOOST_CHECK_CLOSE( permx->iget(i,j,k) * 0.25 , permz->iget(i,j,k) , 0.001); - BOOST_CHECK_EQUAL( permx->iget(i,j,k) * 2 , permy->iget(i,j,k)); + BOOST_CHECK_CLOSE( permx.iget( i, j, k ) * 0.25, permz.iget( i, j, k ), 0.001 ); + BOOST_CHECK_EQUAL( permx.iget( i, j, k ) * 2, permy.iget( i, j, k ) ); } } @@ -72,20 +73,20 @@ BOOST_AUTO_TEST_CASE( PERMX ) { BOOST_AUTO_TEST_CASE( PARSE_BOX_OK ) { - EclipseState state = makeState("testdata/integration_tests/BOX/BOXTEST1"); - std::shared_ptr > satnum = state.getIntGridProperty("SATNUM"); + EclipseState state = makeState( "testdata/integration_tests/BOX/BOXTEST1" ); + const auto& satnum = state.getEclipseProperties().getIntGridProperty( "SATNUM" ); { - size_t i,j,k; + size_t i, j, k; std::shared_ptr grid = state.getEclipseGrid(); for (k = 0; k < grid->getNZ(); k++) { for (j = 0; j < grid->getNY(); j++) { for (i = 0; i < grid->getNX(); i++) { - size_t g = i + j*grid->getNX() + k * grid->getNX() * grid->getNY(); + size_t g = i + j * grid->getNX() + k * grid->getNX() * grid->getNY(); if (i <= 1 && j <= 1 && k <= 1) - BOOST_CHECK_EQUAL(satnum->iget(g) , 10); + BOOST_CHECK_EQUAL( satnum.iget( g ), 10 ); else - BOOST_CHECK_EQUAL(satnum->iget(g) , 2); + BOOST_CHECK_EQUAL( satnum.iget( g ), 2 ); } } @@ -93,24 +94,22 @@ BOOST_AUTO_TEST_CASE( PARSE_BOX_OK ) { } } - - BOOST_AUTO_TEST_CASE( PARSE_MULTIPLY_COPY ) { - EclipseState state = makeState("testdata/integration_tests/BOX/BOXTEST1"); - std::shared_ptr > satnum = state.getIntGridProperty("SATNUM"); - std::shared_ptr > fipnum = state.getIntGridProperty("FIPNUM"); - size_t i,j,k; + EclipseState state = makeState( "testdata/integration_tests/BOX/BOXTEST1" ); + const auto& satnum = state.getEclipseProperties().getIntGridProperty( "SATNUM" ); + const auto& fipnum = state.getEclipseProperties().getIntGridProperty( "FIPNUM" ); + size_t i, j, k; std::shared_ptr grid = state.getEclipseGrid(); for (k = 0; k < grid->getNZ(); k++) { for (j = 0; j < grid->getNY(); j++) { for (i = 0; i < grid->getNX(); i++) { - size_t g = i + j*grid->getNX() + k * grid->getNX() * grid->getNY(); + size_t g = i + j * grid->getNX() + k * grid->getNX() * grid->getNY(); if (i <= 1 && j <= 1 && k <= 1) - BOOST_CHECK_EQUAL(4*satnum->iget(g) , fipnum->iget(g)); + BOOST_CHECK_EQUAL( 4 * satnum.iget( g ), fipnum.iget( g ) ); else - BOOST_CHECK_EQUAL(2*satnum->iget(i,j,k) , fipnum->iget(i,j,k)); + BOOST_CHECK_EQUAL( 2 * satnum.iget( i, j, k ), fipnum.iget( i, j, k ) ); } } @@ -124,28 +123,23 @@ BOOST_AUTO_TEST_CASE( KEYWORD_BOX_TOO_SMALL) { BOOST_CHECK_THROW( makeState("testdata/integration_tests/BOX/BOXTEST3") , std::invalid_argument); } - - BOOST_AUTO_TEST_CASE( EQUAL ) { - EclipseState state = makeState("testdata/integration_tests/BOX/BOXTEST1"); - std::shared_ptr > pvtnum = state.getIntGridProperty("PVTNUM"); - std::shared_ptr > eqlnum = state.getIntGridProperty("EQLNUM"); - std::shared_ptr > poro = state.getDoubleGridProperty("PORO"); - size_t i,j,k; + EclipseState state = makeState( "testdata/integration_tests/BOX/BOXTEST1" ); + const auto& pvtnum = state.getEclipseProperties().getIntGridProperty( "PVTNUM" ); + const auto& eqlnum = state.getEclipseProperties().getIntGridProperty( "EQLNUM" ); + const auto& poro = state.getEclipseProperties().getDoubleGridProperty( "PORO" ); + size_t i, j, k; std::shared_ptr grid = state.getEclipseGrid(); for (k = 0; k < grid->getNZ(); k++) { for (j = 0; j < grid->getNY(); j++) { for (i = 0; i < grid->getNX(); i++) { - BOOST_CHECK_EQUAL( pvtnum->iget(i,j,k) , k ); - BOOST_CHECK_EQUAL( eqlnum->iget(i,j,k) , 77 + 2 * k ); - BOOST_CHECK_EQUAL( poro->iget(i,j,k) , 0.25 ); + BOOST_CHECK_EQUAL( pvtnum.iget( i, j, k ), k ); + BOOST_CHECK_EQUAL( eqlnum.iget( i, j, k ), 77 + 2 * k ); + BOOST_CHECK_EQUAL( poro.iget( i, j, k ), 0.25 ); } } } } - - -