Merge pull request #841 from pgdr/mixed-case
Supporting reading and writing mixed case properties
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
*/
|
||||
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
|
||||
#include <boost/algorithm/string/join.hpp>
|
||||
@@ -34,10 +35,9 @@
|
||||
#include <opm/parser/eclipse/EclipseState/Tables/TableManager.hpp>
|
||||
#include <opm/parser/eclipse/Units/Dimension.hpp>
|
||||
#include <opm/parser/eclipse/Units/UnitSystem.hpp>
|
||||
#include <opm/parser/eclipse/Utility/String.hpp>
|
||||
|
||||
namespace Opm {
|
||||
|
||||
|
||||
namespace GridPropertyPostProcessor {
|
||||
|
||||
void distTopLayer( std::vector<double>& values,
|
||||
@@ -424,28 +424,32 @@ namespace Opm {
|
||||
}
|
||||
|
||||
bool Eclipse3DProperties::supportsGridProperty(const std::string& keyword) const {
|
||||
return m_doubleGridProperties.supportsKeyword( keyword ) || m_intGridProperties.supportsKeyword( keyword );
|
||||
auto kw = uppercase(keyword);
|
||||
return m_doubleGridProperties.supportsKeyword( kw ) || m_intGridProperties.supportsKeyword( kw );
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Eclipse3DProperties::hasDeckIntGridProperty(const std::string& keyword) const {
|
||||
if (!m_intGridProperties.supportsKeyword( keyword ))
|
||||
throw std::logic_error("Integer grid property " + keyword + " is unsupported!");
|
||||
auto kw = uppercase(keyword);
|
||||
if (!m_intGridProperties.supportsKeyword( kw ))
|
||||
throw std::logic_error("Integer grid property " + kw + " is unsupported!");
|
||||
|
||||
return m_intGridProperties.hasKeyword( keyword );
|
||||
return m_intGridProperties.hasKeyword( kw );
|
||||
}
|
||||
|
||||
bool Eclipse3DProperties::hasDeckDoubleGridProperty(const std::string& keyword) const {
|
||||
if (!m_doubleGridProperties.supportsKeyword( keyword ))
|
||||
throw std::logic_error("Double grid property " + keyword + " is unsupported!");
|
||||
auto kw = uppercase(keyword);
|
||||
if (!m_doubleGridProperties.supportsKeyword( kw ))
|
||||
throw std::logic_error("Double grid property " + kw + " is unsupported!");
|
||||
|
||||
return m_doubleGridProperties.hasKeyword( keyword );
|
||||
return m_doubleGridProperties.hasKeyword( kw );
|
||||
}
|
||||
|
||||
|
||||
const GridProperty<int>& Eclipse3DProperties::getIntGridProperty( const std::string& keyword ) const {
|
||||
auto& gridProperty = const_cast< Eclipse3DProperties* >( this )->m_intGridProperties.getKeyword( keyword );
|
||||
auto kw = uppercase(keyword);
|
||||
auto& gridProperty = const_cast< Eclipse3DProperties* >( this )->m_intGridProperties.getKeyword( kw );
|
||||
gridProperty.runPostProcessor();
|
||||
return gridProperty;
|
||||
}
|
||||
@@ -454,7 +458,8 @@ namespace Opm {
|
||||
|
||||
/// gets property from doubleGridProperty --- and calls the runPostProcessor
|
||||
const GridProperty<double>& Eclipse3DProperties::getDoubleGridProperty( const std::string& keyword ) const {
|
||||
auto& gridProperty = const_cast< Eclipse3DProperties* >( this )->m_doubleGridProperties.getKeyword( keyword );
|
||||
auto kw = uppercase(keyword);
|
||||
auto& gridProperty = const_cast< Eclipse3DProperties* >( this )->m_doubleGridProperties.getKeyword( kw );
|
||||
gridProperty.runPostProcessor();
|
||||
return gridProperty;
|
||||
}
|
||||
@@ -472,7 +477,8 @@ namespace Opm {
|
||||
}
|
||||
}
|
||||
|
||||
std::vector< int > Eclipse3DProperties::getRegions( const std::string& kw ) const {
|
||||
std::vector< int > Eclipse3DProperties::getRegions( const std::string& keyword ) const {
|
||||
auto kw = uppercase(keyword);
|
||||
if( !this->hasDeckIntGridProperty( kw ) ) return {};
|
||||
|
||||
const auto& property = this->getIntGridProperty( kw );
|
||||
@@ -704,7 +710,7 @@ namespace Opm {
|
||||
|
||||
void Eclipse3DProperties::handleADDREGKeyword( const DeckKeyword& deckKeyword) {
|
||||
for( const auto& record : deckKeyword ) {
|
||||
const std::string& targetArray = record.getItem("ARRAY").get< std::string >(0);
|
||||
const std::string targetArray = uppercase(record.getItem("ARRAY").get< std::string >(0));
|
||||
const auto& regionProperty = getRegion( record.getItem("REGION_NAME") );
|
||||
|
||||
if (m_intGridProperties.hasKeyword( targetArray ))
|
||||
@@ -720,7 +726,7 @@ namespace Opm {
|
||||
|
||||
void Eclipse3DProperties::handleMULTIREGKeyword( const DeckKeyword& deckKeyword) {
|
||||
for( const auto& record : deckKeyword ) {
|
||||
const std::string& targetArray = record.getItem("ARRAY").get< std::string >(0);
|
||||
const std::string targetArray = uppercase(record.getItem("ARRAY").get< std::string >(0));
|
||||
const auto& regionProperty = getRegion( record.getItem("REGION_NAME") );
|
||||
|
||||
if (m_intGridProperties.supportsKeyword( targetArray ))
|
||||
@@ -735,7 +741,7 @@ namespace Opm {
|
||||
|
||||
void Eclipse3DProperties::handleCOPYREGKeyword( const DeckKeyword& deckKeyword) {
|
||||
for( const auto& record : deckKeyword ) {
|
||||
const std::string& srcArray = record.getItem("ARRAY").get< std::string >(0);
|
||||
const std::string srcArray = uppercase(record.getItem("ARRAY").get< std::string >(0));
|
||||
const auto& regionProperty = getRegion( record.getItem("REGION_NAME") );
|
||||
|
||||
if (m_intGridProperties.hasKeyword( srcArray ))
|
||||
@@ -752,7 +758,7 @@ namespace Opm {
|
||||
|
||||
void Eclipse3DProperties::handleMULTIPLYKeyword( const DeckKeyword& deckKeyword, BoxManager& boxManager) {
|
||||
for( const auto& record : deckKeyword ) {
|
||||
const std::string& field = record.getItem("field").get< std::string >(0);
|
||||
const std::string field = uppercase(record.getItem("field").get< std::string >(0));
|
||||
|
||||
if (m_doubleGridProperties.hasKeyword( field ))
|
||||
m_doubleGridProperties.handleMULTIPLYRecord( record , boxManager );
|
||||
@@ -772,7 +778,7 @@ namespace Opm {
|
||||
*/
|
||||
void Eclipse3DProperties::handleADDKeyword( const DeckKeyword& deckKeyword, BoxManager& boxManager) {
|
||||
for( const auto& record : deckKeyword ) {
|
||||
const std::string& field = record.getItem("field").get< std::string >(0);
|
||||
const std::string field = uppercase(record.getItem("field").get< std::string >(0));
|
||||
|
||||
if (m_doubleGridProperties.hasKeyword( field ))
|
||||
m_doubleGridProperties.handleADDRecord( record , boxManager );
|
||||
@@ -787,7 +793,7 @@ namespace Opm {
|
||||
|
||||
void Eclipse3DProperties::handleCOPYKeyword( const DeckKeyword& deckKeyword, BoxManager& boxManager) {
|
||||
for( const auto& record : deckKeyword ) {
|
||||
const std::string& field = record.getItem("src").get< std::string >(0);
|
||||
const std::string field = uppercase(record.getItem("src").get< std::string >(0));
|
||||
|
||||
if (m_doubleGridProperties.hasKeyword( field ))
|
||||
m_doubleGridProperties.handleCOPYRecord( record , boxManager );
|
||||
@@ -802,7 +808,7 @@ namespace Opm {
|
||||
|
||||
void Eclipse3DProperties::handleEQUALSKeyword( const DeckKeyword& deckKeyword, BoxManager& boxManager) {
|
||||
for( const auto& record : deckKeyword ) {
|
||||
const std::string& field = record.getItem("field").get< std::string >(0);
|
||||
const std::string field = uppercase(record.getItem("field").get< std::string >(0));
|
||||
|
||||
if (m_doubleGridProperties.supportsKeyword( field ))
|
||||
m_doubleGridProperties.handleEQUALSRecord( record , boxManager );
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#include <opm/parser/eclipse/EclipseState/Grid/GridProperty.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Grid/GridProperties.hpp>
|
||||
#include <opm/parser/eclipse/Utility/String.hpp>
|
||||
|
||||
namespace Opm {
|
||||
|
||||
@@ -143,10 +144,12 @@ namespace Opm {
|
||||
|
||||
template< typename T >
|
||||
bool GridProperties<T>::hasKeyword(const std::string& keyword) const {
|
||||
const auto cnt = m_properties.count( keyword );
|
||||
const std::string kw = uppercase(keyword);
|
||||
|
||||
const auto cnt = m_properties.count( kw );
|
||||
const bool positive = cnt > 0;
|
||||
|
||||
return positive && !isAutoGenerated_(keyword);
|
||||
return positive && !isAutoGenerated_(kw);
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
@@ -157,10 +160,12 @@ namespace Opm {
|
||||
|
||||
template< typename T >
|
||||
const GridProperty<T>& GridProperties<T>::getKeyword(const std::string& keyword) const {
|
||||
if (!hasKeyword(keyword))
|
||||
addAutoGeneratedKeyword_(keyword);
|
||||
const std::string kw = uppercase(keyword);
|
||||
|
||||
GridProperty<T>& property = (*m_properties.at( keyword ));
|
||||
if (!hasKeyword(kw))
|
||||
addAutoGeneratedKeyword_(kw);
|
||||
|
||||
GridProperty<T>& property = (*m_properties.at( kw ));
|
||||
property.runPostProcessor( );
|
||||
return property;
|
||||
}
|
||||
@@ -169,43 +174,46 @@ namespace Opm {
|
||||
|
||||
template< typename T >
|
||||
const GridProperty<T>& GridProperties<T>::getInitializedKeyword(const std::string& keyword) const {
|
||||
if (hasKeyword(keyword))
|
||||
return *m_properties.at( keyword );
|
||||
const std::string kw = uppercase(keyword);
|
||||
if (hasKeyword(kw))
|
||||
return *m_properties.at( kw );
|
||||
else {
|
||||
if (supportsKeyword(keyword))
|
||||
throw std::invalid_argument("Keyword: " + keyword + " is supported - but not initialized.");
|
||||
if (supportsKeyword(kw))
|
||||
throw std::invalid_argument("Keyword: " + kw + " is supported - but not initialized.");
|
||||
else
|
||||
throw std::invalid_argument("Keyword: " + keyword + " is not supported.");
|
||||
throw std::invalid_argument("Keyword: " + kw + " is not supported.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template< typename T >
|
||||
bool GridProperties<T>::addKeyword(const std::string& keywordName) {
|
||||
if (!supportsKeyword( keywordName ))
|
||||
throw std::invalid_argument("The keyword: " + keywordName + " is not supported in this container");
|
||||
const std::string kw = uppercase(keywordName);
|
||||
|
||||
if (hasKeyword(keywordName))
|
||||
if (!supportsKeyword( kw ))
|
||||
throw std::invalid_argument("The keyword: " + kw + " is not supported in this container");
|
||||
|
||||
if (hasKeyword(kw))
|
||||
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)) {
|
||||
m_messages.warning("The keyword "+keywordName+" has been used to calculate the "
|
||||
if (m_autoGeneratedProperties.count(kw)) {
|
||||
m_messages.warning("The keyword "+kw+" 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));
|
||||
"the ordering of your keywords (move "+kw+" to the front?).");
|
||||
m_autoGeneratedProperties.erase(m_autoGeneratedProperties.find(kw));
|
||||
return true;
|
||||
}
|
||||
|
||||
auto supportedKeyword = m_supportedKeywords.at( keywordName );
|
||||
auto supportedKeyword = m_supportedKeywords.at( kw );
|
||||
int nx = m_eclipseGrid.getNX();
|
||||
int ny = m_eclipseGrid.getNY();
|
||||
int nz = m_eclipseGrid.getNZ();
|
||||
std::shared_ptr<GridProperty<T> > newProperty(new GridProperty<T>(nx , ny , nz , supportedKeyword));
|
||||
|
||||
m_properties.insert( std::pair<std::string , std::shared_ptr<GridProperty<T> > > ( keywordName , newProperty ));
|
||||
m_properties.insert( std::pair<std::string , std::shared_ptr<GridProperty<T> > > ( kw , newProperty ));
|
||||
m_property_list.push_back( newProperty );
|
||||
return true;
|
||||
}
|
||||
@@ -227,10 +235,11 @@ namespace Opm {
|
||||
|
||||
template< typename T >
|
||||
GridProperty<T>& GridProperties<T>::getOrCreateProperty(const std::string name) {
|
||||
if (!hasKeyword(name)) {
|
||||
addKeyword(name);
|
||||
const std::string kw = uppercase(name);
|
||||
if (!hasKeyword(kw)) {
|
||||
addKeyword(kw);
|
||||
}
|
||||
return getKeyword(name);
|
||||
return getKeyword(kw);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -382,10 +391,12 @@ namespace Opm {
|
||||
|
||||
template< typename T >
|
||||
GridProperty<T>& GridProperties<T>::getKeyword(const std::string& keyword) {
|
||||
if (!hasKeyword(keyword))
|
||||
addAutoGeneratedKeyword_(keyword);
|
||||
const std::string kw = uppercase(keyword);
|
||||
|
||||
return *m_properties.at( keyword );
|
||||
if (!hasKeyword(kw))
|
||||
addAutoGeneratedKeyword_(kw);
|
||||
|
||||
return *m_properties.at( kw );
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
|
||||
@@ -64,7 +64,7 @@ static Opm::DeckPtr createDeck() {
|
||||
"\n"
|
||||
"PROPS\n"
|
||||
"REGIONS\n"
|
||||
"SWAT\n"
|
||||
"swat\n"
|
||||
"1000*1 /\n"
|
||||
"SATNUM\n"
|
||||
"1000*2 /\n"
|
||||
@@ -93,7 +93,7 @@ static Opm::DeckPtr createValidIntDeck() {
|
||||
" 25*1 \n"
|
||||
"/\n"
|
||||
"ADDREG\n"
|
||||
" SATNUM 11 1 M / \n"
|
||||
" satnum 11 1 M / \n"
|
||||
" SATNUM 20 2 / \n"
|
||||
"/\n"
|
||||
"EDIT\n"
|
||||
@@ -172,7 +172,7 @@ BOOST_AUTO_TEST_CASE(SupportsProperty) {
|
||||
// int props
|
||||
"ACTNUM", "SATNUM", "IMBNUM", "PVTNUM", "EQLNUM", "ENDNUM", "FLUXNUM", "MULTNUM", "FIPNUM", "MISCNUM", "OPERNUM",
|
||||
// double props
|
||||
"TEMPI", "MULTPV", "PERMX", "PERMY", "PERMZ", "SWATINIT", "THCONR", "NTG"
|
||||
"TEMPI", "MULTPV", "PERMX", "permy", "PERMZ", "SWATINIT", "THCONR", "NTG"
|
||||
};
|
||||
|
||||
for (auto keyword : keywordList)
|
||||
@@ -193,14 +193,14 @@ BOOST_AUTO_TEST_CASE(UnsupportedKeywordsThrows) {
|
||||
BOOST_CHECK_THROW(s.props.getIntGridProperty("NONO"), std::logic_error);
|
||||
BOOST_CHECK_THROW(s.props.getDoubleGridProperty("NONO"), std::logic_error);
|
||||
|
||||
BOOST_CHECK_NO_THROW(s.props.hasDeckIntGridProperty("FLUXNUM"));
|
||||
BOOST_CHECK_NO_THROW(s.props.hasDeckIntGridProperty("FluxNUM"));
|
||||
BOOST_CHECK_NO_THROW(s.props.supportsGridProperty("NONO"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(IntGridProperty) {
|
||||
Setup s(createDeck());
|
||||
int cnt = 0;
|
||||
for (auto x : s.props.getIntGridProperty("SATNUM").getData()) {
|
||||
for (auto x : s.props.getIntGridProperty("SaTNuM").getData()) {
|
||||
BOOST_CHECK_EQUAL(x, 2);
|
||||
cnt++;
|
||||
}
|
||||
@@ -225,7 +225,7 @@ BOOST_AUTO_TEST_CASE(AddregIntSetCorrectly) {
|
||||
BOOST_AUTO_TEST_CASE(PermxUnitAppliedCorrectly) {
|
||||
Opm::DeckPtr deck = createValidPERMXDeck();
|
||||
Setup s(deck);
|
||||
const auto& permx = s.props.getDoubleGridProperty("PERMX");
|
||||
const auto& permx = s.props.getDoubleGridProperty("PermX");
|
||||
|
||||
for (size_t j = 0; j < 5; j++)
|
||||
for (size_t i = 0; i < 5; i++) {
|
||||
|
||||
Reference in New Issue
Block a user