From be08d6df2ab13470512acdd910b29991542f90cf Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Fri, 12 Dec 2014 19:47:18 +0100 Subject: [PATCH] Added support for EQUALREG in EclipseState --- .../eclipse/EclipseState/EclipseState.cpp | 71 +++++- .../eclipse/EclipseState/EclipseState.hpp | 1 + .../EclipseState/Grid/tests/CMakeLists.txt | 5 + .../EclipseState/Grid/tests/EqualRegTests.cpp | 223 ++++++++++++++++++ .../share/keywords/000_Eclipse100/E/EQUALREG | 2 +- 5 files changed, 295 insertions(+), 7 deletions(-) create mode 100644 opm/parser/eclipse/EclipseState/Grid/tests/EqualRegTests.cpp diff --git a/opm/parser/eclipse/EclipseState/EclipseState.cpp b/opm/parser/eclipse/EclipseState/EclipseState.cpp index 126f5d7f4..4776fdb13 100644 --- a/opm/parser/eclipse/EclipseState/EclipseState.cpp +++ b/opm/parser/eclipse/EclipseState/EclipseState.cpp @@ -17,9 +17,12 @@ along with OPM. If not, see . */ -#include +#include +#include +#include +#include -#include +#include #include #include #include @@ -28,9 +31,6 @@ #include #include -#include -#include -#include namespace Opm { @@ -110,6 +110,16 @@ namespace Opm { } + static bool isInt(double value) { + double diff = fabs(nearbyint(value) - value); + + if (diff < 1e-6) + return true; + else + return false; + } + + EclipseState::EclipseState(DeckConstPtr deck, LoggerPtr logger) { m_deckUnitSystem = deck->getActiveUnitSystem(); @@ -794,6 +804,9 @@ namespace Opm { if (deckKeyword->name() == "ENDBOX") handleENDBOXKeyword(boxManager); + if (deckKeyword->name() == "EQUALREG") + handleEQUALREGKeyword(deckKeyword , parserLog , enabledTypes); + if (deckKeyword->name() == "MULTIPLY") handleMULTIPLYKeyword(deckKeyword, logger, boxManager, enabledTypes); @@ -824,7 +837,53 @@ namespace Opm { } - void EclipseState::handleMULTIPLYKeyword(DeckKeywordConstPtr deckKeyword, LoggerPtr logger, BoxManager& boxManager, int enabledTypes) { + void EclipseState::handleEQUALREGKeyword(DeckKeywordConstPtr deckKeyword, ParserLogPtr parserLog, int enabledTypes) { + EclipseGridConstPtr grid = getEclipseGrid(); + for (size_t recordIdx = 0; recordIdx < deckKeyword->size(); ++recordIdx) { + DeckRecordConstPtr record = deckKeyword->getRecord(recordIdx); + const std::string& targetArray = record->getItem("ARRAY")->getString(0); + + if (!supportsGridProperty( targetArray , IntProperties + DoubleProperties)) + throw std::invalid_argument("Fatal error processing EQUALREG keyword - invalid/undefined keyword: " + targetArray); + + if (supportsGridProperty( targetArray , enabledTypes)) { + double doubleValue = record->getItem("VALUE")->getRawDouble(0); + int regionValue = record->getItem("REGION_NUMBER")->getInt(0); + const std::string regionArray = MULTREGT::RegionNameFromDeckValue( record->getItem("REGION_NAME")->getString(0) ); + std::shared_ptr > regionProperty = m_intGridProperties->getInitializedKeyword(regionArray); + std::vector mask; + + regionProperty->initMask( regionValue , mask); + + if (m_intGridProperties->supportsKeyword( targetArray )) { + if (enabledTypes & IntProperties) { + if (isInt( doubleValue )) { + std::shared_ptr > targetProperty = m_intGridProperties->getKeyword(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 = m_doubleGridProperties->getKeyword(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::handleMULTIPLYKeyword(DeckKeywordConstPtr deckKeyword, LoggerLogPtr logger, BoxManager& boxManager, int enabledTypes) { for (size_t recordIdx = 0; recordIdx < deckKeyword->size(); ++recordIdx) { DeckRecordConstPtr record = deckKeyword->getRecord(recordIdx); const std::string& field = record->getItem("field")->getString(0); diff --git a/opm/parser/eclipse/EclipseState/EclipseState.hpp b/opm/parser/eclipse/EclipseState/EclipseState.hpp index 22088ac8e..580386b53 100644 --- a/opm/parser/eclipse/EclipseState/EclipseState.hpp +++ b/opm/parser/eclipse/EclipseState/EclipseState.hpp @@ -199,6 +199,7 @@ namespace Opm { void handleENDBOXKeyword(BoxManager& boxManager); void handleEQUALSKeyword(DeckKeywordConstPtr deckKeyword , LoggerPtr logger, BoxManager& boxManager, int enabledTypes); void handleMULTIPLYKeyword(DeckKeywordConstPtr deckKeyword , LoggerPtr logger, BoxManager& boxManager, int enabledTypes); + void handleEQUALREGKeyword(DeckKeywordConstPtr deckKeyword, ParserLogPtr parserLog, int enabledTypes); void setKeywordBox(DeckKeywordConstPtr deckKeyword, size_t recordIdx, LoggerPtr logger, BoxManager& boxManager); diff --git a/opm/parser/eclipse/EclipseState/Grid/tests/CMakeLists.txt b/opm/parser/eclipse/EclipseState/Grid/tests/CMakeLists.txt index 020e9066b..c43cd2ce4 100644 --- a/opm/parser/eclipse/EclipseState/Grid/tests/CMakeLists.txt +++ b/opm/parser/eclipse/EclipseState/Grid/tests/CMakeLists.txt @@ -46,3 +46,8 @@ add_executable(runFaultTests FaultTests.cpp) target_link_libraries(runFaultTests Parser ${Boost_LIBRARIES}) add_test(NAME runFaultTests WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND ${TEST_MEMCHECK_TOOL} ${EXECUTABLE_OUTPUT_PATH}/runFaultTests ) + +add_executable(runEqualRegTests EqualRegTests.cpp) +target_link_libraries(runEqualRegTests Parser ${Boost_LIBRARIES}) +add_test(NAME runEqualRegTests WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND ${TEST_MEMCHECK_TOOL} ${EXECUTABLE_OUTPUT_PATH}/runEqualRegTests ) + diff --git a/opm/parser/eclipse/EclipseState/Grid/tests/EqualRegTests.cpp b/opm/parser/eclipse/EclipseState/Grid/tests/EqualRegTests.cpp new file mode 100644 index 000000000..c9be91544 --- /dev/null +++ b/opm/parser/eclipse/EclipseState/Grid/tests/EqualRegTests.cpp @@ -0,0 +1,223 @@ +/* + Copyright 2014 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 + +#define BOOST_TEST_MODULE EqualRegTests +#include +#include + + +#include + +#include +#include +#include + +#include +#include + + +static Opm::DeckPtr createDeckInvalidArray() { + const char *deckData = + "RUNSPEC\n" + "\n" + "DIMENS\n" + " 10 10 10 /\n" + "GRID\n" + "EQUALREG\n" + " MISSING 10 10 M / \n" + "/\n" + "EDIT\n" + "\n"; + + Opm::ParserPtr parser(new Opm::Parser()); + return parser->parseString(deckData) ; +} + + +static Opm::DeckPtr createDeckInvalidRegion() { + const char *deckData = + "RUNSPEC\n" + "\n" + "DIMENS\n" + " 10 10 10 /\n" + "GRID\n" + "EQUALREG\n" + " MISSING 10 10 MX / \n" + "/\n" + "EDIT\n" + "\n"; + + Opm::ParserPtr parser(new Opm::Parser()); + return parser->parseString(deckData) ; +} + + +static Opm::DeckPtr createDeckInvalidValue() { + const char *deckData = + "RUNSPEC\n" + "\n" + "DIMENS\n" + " 10 10 10 /\n" + "GRID\n" + "EQUALREG\n" + " SATNUM 0.2 10 M / \n" + "/\n" + "EDIT\n" + "\n"; + + Opm::ParserPtr parser(new Opm::Parser()); + return parser->parseString(deckData) ; +} + + +static Opm::DeckPtr createDeckUnInitialized() { + const char *deckData = + "RUNSPEC\n" + "\n" + "DIMENS\n" + " 10 10 10 /\n" + "GRID\n" + "REGIONS\n" + "EQUALREG\n" + " SATNUM 2 10 M / \n" + "/\n" + "EDIT\n" + "\n"; + + Opm::ParserPtr parser(new Opm::Parser()); + return parser->parseString(deckData) ; +} + + +static Opm::DeckPtr createValidIntDeck() { + const char *deckData = + "RUNSPEC\n" + "\n" + "DIMENS\n" + " 5 5 1 /\n" + "GRID\n" + "MULTNUM \n" + "1 1 2 2 2\n" + "1 1 2 2 2\n" + "1 1 2 2 2\n" + "1 1 2 2 2\n" + "1 1 2 2 2\n" + "/\n" + "EQUALREG\n" + " SATNUM 11 1 M / \n" + " SATNUM 20 2 / \n" + "/\n" + "EDIT\n" + "\n"; + + Opm::ParserPtr parser(new Opm::Parser()); + return parser->parseString(deckData) ; +} + + +static Opm::DeckPtr createValidPERMXDeck() { + const char *deckData = + "RUNSPEC\n" + "\n" + "DIMENS\n" + " 5 5 1 /\n" + "GRID\n" + "MULTNUM \n" + "1 1 2 2 2\n" + "1 1 2 2 2\n" + "1 1 2 2 2\n" + "1 1 2 2 2\n" + "1 1 2 2 2\n" + "/\n" + "BOX\n" + " 1 2 1 5 1 1 / \n" + "PERMZ\n" + " 10*1 /\n" + "ENDBOX\n" + "BOX\n" + " 3 5 1 5 1 1 / \n" + "PERMZ\n" + " 15*2 /\n" + "ENDBOX\n" + "EQUALREG\n" + " PERMX 1 1 / \n" + " PERMX 2 2 / \n" + "/\n" + "EDIT\n" + "\n"; + + Opm::ParserPtr parser(new Opm::Parser()); + return parser->parseString(deckData) ; +} + + + + +BOOST_AUTO_TEST_CASE(InvalidArrayThrows) { + Opm::DeckPtr deck = createDeckInvalidArray(); + BOOST_CHECK_THROW( new Opm::EclipseState(deck) , std::invalid_argument ); +} + + +BOOST_AUTO_TEST_CASE(InvalidRegionThrows) { + Opm::DeckPtr deck = createDeckInvalidRegion(); + BOOST_CHECK_THROW( new Opm::EclipseState(deck) , std::invalid_argument ); +} + + +BOOST_AUTO_TEST_CASE(ExpectedIntThrows) { + Opm::DeckPtr deck = createDeckInvalidValue(); + BOOST_CHECK_THROW( new Opm::EclipseState(deck) , std::invalid_argument ); +} + + +BOOST_AUTO_TEST_CASE(UnInitializedVectorThrows) { + Opm::DeckPtr deck = createDeckUnInitialized(); + BOOST_CHECK_THROW( new Opm::EclipseState(deck) , std::invalid_argument ); +} + + +BOOST_AUTO_TEST_CASE(IntSetCorrectly) { + Opm::DeckPtr deck = createValidIntDeck(); + Opm::EclipseState state(deck); + std::shared_ptr > property = state.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)); + else + BOOST_CHECK_EQUAL( 20 , property->iget(i,j,0)); + } + +} + + +BOOST_AUTO_TEST_CASE(UnitAppliedCorrectly) { + Opm::DeckPtr deck = createValidPERMXDeck(); + Opm::EclipseState state(deck); + std::shared_ptr > permx = state.getDoubleGridProperty( "PERMX"); + std::shared_ptr > permz = state.getDoubleGridProperty( "PERMZ"); + for (size_t g=0; g< 25; g++) + BOOST_CHECK_EQUAL( permz->iget(g), permx->iget(g)); +} diff --git a/opm/parser/share/keywords/000_Eclipse100/E/EQUALREG b/opm/parser/share/keywords/000_Eclipse100/E/EQUALREG index 2d4d205b5..3803c8ce5 100644 --- a/opm/parser/share/keywords/000_Eclipse100/E/EQUALREG +++ b/opm/parser/share/keywords/000_Eclipse100/E/EQUALREG @@ -1,4 +1,4 @@ -{"name" : "EQUALREG" , "sections" : ["GRID","EDIT","PROP","REGIONS","SOLUTION"], +{"name" : "EQUALREG" , "sections" : ["GRID","EDIT","PROPS","REGIONS","SOLUTION"], "items" : [{"name" : "ARRAY" , "value_type" : "STRING" , "description" : "The 3D array we will update"}, {"name" : "VALUE" , "value_type" : "DOUBLE" , "description" : "The value we will assign" , "default" : 0} ,