Added support for COPYREG keyword
This commit is contained in:
@@ -813,6 +813,9 @@ namespace Opm {
|
||||
if (deckKeyword->name() == "MULTIREG")
|
||||
handleMULTIREGKeyword(deckKeyword , parserLog , enabledTypes);
|
||||
|
||||
if (deckKeyword->name() == "COPYREG")
|
||||
handleCOPYREGKeyword(deckKeyword , parserLog , enabledTypes);
|
||||
|
||||
if (deckKeyword->name() == "MULTIPLY")
|
||||
handleMULTIPLYKeyword(deckKeyword, logger, boxManager, enabledTypes);
|
||||
|
||||
@@ -975,6 +978,49 @@ namespace Opm {
|
||||
}
|
||||
|
||||
|
||||
void EclipseState::handleCOPYREGKeyword(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& srcArray = record->getItem("ARRAY")->getString(0);
|
||||
const std::string& targetArray = record->getItem("TARGET_ARRAY")->getString(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")->getInt(0);
|
||||
const std::string regionArray = MULTREGT::RegionNameFromDeckValue( record->getItem("REGION_NAME")->getString(0) );
|
||||
std::shared_ptr<Opm::GridProperty<int> > regionProperty = m_intGridProperties->getInitializedKeyword( regionArray );
|
||||
std::vector<bool> mask;
|
||||
|
||||
regionProperty->initMask( regionValue , mask );
|
||||
|
||||
if (m_intGridProperties->hasKeyword( srcArray )) {
|
||||
std::shared_ptr<Opm::GridProperty<int> > srcProperty = m_intGridProperties->getInitializedKeyword( srcArray );
|
||||
if (supportsGridProperty( targetArray , IntProperties)) {
|
||||
std::shared_ptr<Opm::GridProperty<int> > targetProperty = m_intGridProperties->getKeyword( targetArray );
|
||||
targetProperty->maskedCopy( *srcProperty , mask );
|
||||
} else
|
||||
throw std::invalid_argument("Fatal error processing COPYREG keyword.");
|
||||
} else if (m_doubleGridProperties->hasKeyword( srcArray )) {
|
||||
std::shared_ptr<Opm::GridProperty<double> > srcProperty = m_doubleGridProperties->getInitializedKeyword( srcArray );
|
||||
if (supportsGridProperty( targetArray , DoubleProperties)) {
|
||||
std::shared_ptr<Opm::GridProperty<double> > targetProperty = m_doubleGridProperties->getKeyword( targetArray );
|
||||
targetProperty->maskedCopy( *srcProperty , mask );
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw std::invalid_argument("Fatal error processing COPYREG keyword - invalid/undefined keyword: " + targetArray);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void EclipseState::handleMULTIPLYKeyword(DeckKeywordConstPtr deckKeyword, LoggerPtr logger, BoxManager& boxManager, int enabledTypes) {
|
||||
|
||||
@@ -203,6 +203,7 @@ namespace Opm {
|
||||
void handleEQUALREGKeyword(DeckKeywordConstPtr deckKeyword, LoggerPtr logger, int enabledTypes);
|
||||
void handleMULTIREGKeyword(DeckKeywordConstPtr deckKeyword, LoggerPtr logger, int enabledTypes);
|
||||
void handleADDREGKeyword(DeckKeywordConstPtr deckKeyword, LoggerPtr logger, int enabledTypes);
|
||||
void handleCOPYREGKeyword(DeckKeywordConstPtr deckKeyword, LoggerPtr logger, int enabledTypes);
|
||||
|
||||
void setKeywordBox(DeckKeywordConstPtr deckKeyword, size_t recordIdx, LoggerPtr logger, BoxManager& boxManager);
|
||||
|
||||
|
||||
@@ -59,3 +59,7 @@ add_executable(runADDREGTests ADDREGTests.cpp)
|
||||
target_link_libraries(runADDREGTests Parser ${Boost_LIBRARIES})
|
||||
add_test(NAME runADDREGTests WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND ${TEST_MEMCHECK_TOOL} ${EXECUTABLE_OUTPUT_PATH}/runADDREGTests )
|
||||
|
||||
add_executable(runCopyRegTests CopyRegTests.cpp)
|
||||
target_link_libraries(runCopyRegTests Parser ${Boost_LIBRARIES})
|
||||
add_test(NAME runCopyRegTests WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND ${TEST_MEMCHECK_TOOL} ${EXECUTABLE_OUTPUT_PATH}/runCopyRegTests )
|
||||
|
||||
|
||||
219
opm/parser/eclipse/EclipseState/Grid/tests/CopyRegTests.cpp
Normal file
219
opm/parser/eclipse/EclipseState/Grid/tests/CopyRegTests.cpp
Normal file
@@ -0,0 +1,219 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <cstdio>
|
||||
|
||||
#define BOOST_TEST_MODULE EqualRegTests
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
|
||||
|
||||
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Deck/Section.hpp>
|
||||
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
||||
#include <opm/parser/eclipse/Deck/DeckKeyword.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/EclipseState/Grid/EclipseGrid.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
|
||||
|
||||
|
||||
static Opm::DeckPtr createDeckInvalidArray1() {
|
||||
const char *deckData =
|
||||
"RUNSPEC\n"
|
||||
"\n"
|
||||
"DIMENS\n"
|
||||
" 10 10 10 /\n"
|
||||
"GRID\n"
|
||||
"SATNUM\n"
|
||||
" 1000*1 /\n"
|
||||
"COPYREG\n"
|
||||
" MISSING SATNUM 10 M / \n"
|
||||
"/\n"
|
||||
"EDIT\n"
|
||||
"\n";
|
||||
|
||||
Opm::ParserPtr parser(new Opm::Parser());
|
||||
return parser->parseString(deckData) ;
|
||||
}
|
||||
|
||||
static Opm::DeckPtr createDeckInvalidArray2() {
|
||||
const char *deckData =
|
||||
"RUNSPEC\n"
|
||||
"\n"
|
||||
"DIMENS\n"
|
||||
" 10 10 10 /\n"
|
||||
"GRID\n"
|
||||
"SATNUM\n"
|
||||
" 1000*1 /\n"
|
||||
"COPYREG\n"
|
||||
" SATNUM MISSING 10 M / \n"
|
||||
"/\n"
|
||||
"EDIT\n"
|
||||
"\n";
|
||||
|
||||
Opm::ParserPtr parser(new Opm::Parser());
|
||||
return parser->parseString(deckData) ;
|
||||
}
|
||||
|
||||
|
||||
static Opm::DeckPtr createDeckInvalidTypeMismatch() {
|
||||
const char *deckData =
|
||||
"RUNSPEC\n"
|
||||
"\n"
|
||||
"DIMENS\n"
|
||||
" 10 10 10 /\n"
|
||||
"GRID\n"
|
||||
"SATNUM\n"
|
||||
" 1000*1 /\n"
|
||||
"COPYREG\n"
|
||||
" SATNUM PERMX 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"
|
||||
"SATNUM\n"
|
||||
" 1000*1 /\n"
|
||||
"COPYREG\n"
|
||||
" SATNUM FLUXNUM 10 MX / \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"
|
||||
"COPYREG\n"
|
||||
" SATNUM FLUXNUM 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"
|
||||
"SATNUM\n"
|
||||
" 25*10 /\n"
|
||||
"FLUXNUM\n"
|
||||
" 25*3 /\n"
|
||||
"COPYREG\n"
|
||||
" SATNUM FLUXNUM 1 M / \n"
|
||||
"/\n"
|
||||
"EDIT\n"
|
||||
"\n";
|
||||
|
||||
Opm::ParserPtr parser(new Opm::Parser());
|
||||
return parser->parseString(deckData) ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(InvalidArrayThrows1) {
|
||||
Opm::DeckPtr deck = createDeckInvalidArray1();
|
||||
BOOST_CHECK_THROW( new Opm::EclipseState(deck) , std::invalid_argument );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(InvalidArrayThrows2) {
|
||||
Opm::DeckPtr deck = createDeckInvalidArray2();
|
||||
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(UnInitializedVectorThrows) {
|
||||
Opm::DeckPtr deck = createDeckUnInitialized();
|
||||
BOOST_CHECK_THROW( new Opm::EclipseState(deck) , std::invalid_argument );
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(TypeMismatchThrows) {
|
||||
Opm::DeckPtr deck = createDeckInvalidTypeMismatch();
|
||||
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<Opm::GridProperty<int> > property = state.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));
|
||||
else
|
||||
BOOST_CHECK_EQUAL( 3 , property->iget(i,j,0));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user