diff --git a/opm/parser/eclipse/EclipseState/SimulationConfig/ThresholdPressure.cpp b/opm/parser/eclipse/EclipseState/SimulationConfig/ThresholdPressure.cpp index 6e4e5c06d..60a810a4c 100644 --- a/opm/parser/eclipse/EclipseState/SimulationConfig/ThresholdPressure.cpp +++ b/opm/parser/eclipse/EclipseState/SimulationConfig/ThresholdPressure.cpp @@ -32,111 +32,80 @@ namespace Opm { const Eclipse3DProperties& eclipseProperties) { - if (Section::hasRUNSPEC( deck ) && Section::hasSOLUTION( deck )) { - std::shared_ptr runspecSection = std::make_shared( deck ); - std::shared_ptr solutionSection = std::make_shared( deck ); - initThresholdPressure( runspecSection, solutionSection, eclipseProperties ); - } - } + if( !Section::hasRUNSPEC( deck ) || !Section::hasSOLUTION( deck ) ) + return; - - std::pair ThresholdPressure::makeIndex(int r1 , int r2) { - if (r1 < r2) - return std::make_pair(r1,r2); - else - return std::make_pair(r2,r1); - } - - void ThresholdPressure::addPair(int r1 , int r2 , const std::pair& valuePair) { - std::pair indexPair = makeIndex(r1,r2); - m_pressureTable[indexPair] = valuePair; - } - - void ThresholdPressure::addBarrier(int r1 , int r2 , double p) { - std::pair valuePair = std::make_pair(true , p); - addPair( r1,r2, valuePair ); - } - - void ThresholdPressure::addBarrier(int r1 , int r2) { - std::pair valuePair = std::make_pair(false , 0); - addPair( r1,r2, valuePair ); - } - - - void ThresholdPressure::initThresholdPressure(std::shared_ptr runspecSection, - std::shared_ptr solutionSection, - const Eclipse3DProperties& eclipseProperties) { + RUNSPECSection runspecSection( deck ); + SOLUTIONSection solutionSection( deck ); bool thpresOption = false; - const bool thpresKeyword = solutionSection->hasKeyword( ); + const bool thpresKeyword = solutionSection.hasKeyword(); const bool hasEqlnumKeyword = eclipseProperties.hasDeckIntGridProperty( "EQLNUM" ); int maxEqlnum = 0; //Is THPRES option set? - if (runspecSection->hasKeyword( )) { - const auto& eqlopts = runspecSection->getKeyword( ); + if( runspecSection.hasKeyword() ) { + const auto& eqlopts = runspecSection.getKeyword( ); const auto& rec = eqlopts.getRecord(0); - for (size_t i = 0; i < rec.size(); ++i) { - const auto& item = rec.getItem(i); - if (item.hasValue(0)) { - if (item.get< std::string >(0) == "THPRES") { - thpresOption = true; - } else if (item.get< std::string >(0) == "IRREVERS") { - throw std::runtime_error("Cannot use IRREVERS version of THPRES option, not implemented"); - } - } + for( const auto& item : rec ) { + if( !item.hasValue( 0 ) ) continue; + + const auto& opt = item.get< std::string >( 0 ); + if( opt == "IRREVERS" ) + throw std::runtime_error("Cannot use IRREVERS version of THPRES option, not implemented"); + + if( opt == "THPRES" ) + thpresOption = true; } } - //Option is set and keyword is found - if (thpresOption && thpresKeyword) - { - //Find max of eqlnum - if (hasEqlnumKeyword) { - const auto& eqlnumKeyword = eclipseProperties.getIntGridProperty( "EQLNUM" ); - const auto& eqlnum = eqlnumKeyword.getData(); - maxEqlnum = *std::max_element(eqlnum.begin(), eqlnum.end()); + if( thpresOption && !thpresKeyword ) { + throw std::runtime_error("Invalid solution section; " + "the EQLOPTS THPRES option is set in RUNSPEC, " + "but no THPRES keyword is found in SOLUTION." ); + } - if (0 == maxEqlnum) { - throw std::runtime_error("Error in EQLNUM data: all values are 0"); - } - } else { + + //Option is set and keyword is found + if( thpresOption && thpresKeyword ) { + if( !hasEqlnumKeyword ) throw std::runtime_error("Error when internalizing THPRES: EQLNUM keyword not found in deck"); + + //Find max of eqlnum + const auto& eqlnumKeyword = eclipseProperties.getIntGridProperty( "EQLNUM" ); + const auto& eqlnum = eqlnumKeyword.getData(); + maxEqlnum = *std::max_element(eqlnum.begin(), eqlnum.end()); + + if (0 == maxEqlnum) { + throw std::runtime_error("Error in EQLNUM data: all values are 0"); } // Fill threshold pressure table. - const auto& thpres = solutionSection->getKeyword( ); + const auto& thpres = solutionSection.getKeyword( ); - const int numRecords = thpres.size(); - for (int rec_ix = 0; rec_ix < numRecords; ++rec_ix) { - const auto& rec = thpres.getRecord(rec_ix); + for( const auto& rec : thpres ) { const auto& region1Item = rec.getItem(); const auto& region2Item = rec.getItem(); const auto& thpressItem = rec.getItem(); - if (region1Item.hasValue(0) && region2Item.hasValue(0)) { - const int r1 = region1Item.get< int >(0); - const int r2 = region2Item.get< int >(0); - if (r1 > maxEqlnum || r2 > maxEqlnum) { - throw std::runtime_error("Too high region numbers in THPRES keyword"); - } - - if (thpressItem.hasValue(0)) { - addBarrier( r1 , r2 , thpressItem.getSIDouble( 0 ) ); - } else - addBarrier( r1 , r2 ); - } else + if( !region1Item.hasValue( 0 ) || !region2Item.hasValue( 0 ) ) throw std::runtime_error("Missing region data for use of the THPRES keyword"); - } - } else if (thpresOption && !thpresKeyword) { - throw std::runtime_error("Invalid solution section; the EQLOPTS THPRES option is set in RUNSPEC, but no THPRES keyword is found in SOLUTION"); + const int r1 = region1Item.get< int >(0); + const int r2 = region2Item.get< int >(0); + if (r1 > maxEqlnum || r2 > maxEqlnum) { + throw std::runtime_error("Too high region numbers in THPRES keyword"); + } + if (thpressItem.hasValue(0)) { + addBarrier( r1 , r2 , thpressItem.getSIDouble( 0 ) ); + } else + addBarrier( r1 , r2 ); + } } } - bool ThresholdPressure::hasRegionBarrier(int r1 , int r2) const { std::pair indexPair = makeIndex(r1,r2); if (m_pressureTable.find( indexPair ) == m_pressureTable.end()) @@ -165,9 +134,32 @@ namespace Opm { } } + } + std::pair ThresholdPressure::makeIndex(int r1 , int r2) { + if (r1 < r2) + return std::make_pair(r1,r2); + else + return std::make_pair(r2,r1); + } + + void ThresholdPressure::addPair(int r1 , int r2 , const std::pair& valuePair) { + std::pair indexPair = makeIndex(r1,r2); + m_pressureTable[indexPair] = valuePair; + } + + void ThresholdPressure::addBarrier(int r1 , int r2 , double p) { + std::pair valuePair = std::make_pair(true , p); + addPair( r1,r2, valuePair ); + } + + void ThresholdPressure::addBarrier(int r1 , int r2) { + std::pair valuePair = std::make_pair(false , 0); + addPair( r1,r2, valuePair ); + } + size_t ThresholdPressure::size() const { return m_pressureTable.size(); } diff --git a/opm/parser/eclipse/EclipseState/SimulationConfig/ThresholdPressure.hpp b/opm/parser/eclipse/EclipseState/SimulationConfig/ThresholdPressure.hpp index 5f5a9446a..b5ff7e538 100644 --- a/opm/parser/eclipse/EclipseState/SimulationConfig/ThresholdPressure.hpp +++ b/opm/parser/eclipse/EclipseState/SimulationConfig/ThresholdPressure.hpp @@ -23,14 +23,11 @@ #include #include -#include - namespace Opm { class Deck; - class RUNSPECSection; - class SOLUTIONSection; + class Eclipse3DProperties; class ThresholdPressure { @@ -66,11 +63,8 @@ namespace Opm { */ double getThresholdPressure(int r1 , int r2) const; size_t size() const; - private: - void initThresholdPressure(std::shared_ptr runspecSection, - std::shared_ptr solutionSection, - const Eclipse3DProperties& eclipseProperties); + private: static std::pair makeIndex(int r1 , int r2); void addPair(int r1 , int r2 , const std::pair& valuePair); void addBarrier(int r1 , int r2); @@ -79,11 +73,6 @@ namespace Opm { std::vector> m_thresholdPressureTable; std::map , std::pair > m_pressureTable; }; - - - typedef std::shared_ptr ThresholdPressurePtr; - typedef std::shared_ptr ThresholdPressureConstPtr; - } //namespace Opm #endif