Changed THPRES implementation
With the current implementation the THPRES pressure table is implemented with a map indexed by the equilibration region indicies for the regions in contact.
This commit is contained in:
parent
e1e2487d5d
commit
f7283eb238
@ -35,8 +35,8 @@ namespace Opm {
|
||||
}
|
||||
|
||||
|
||||
const std::vector<std::pair<bool,double>>& SimulationConfig::getThresholdPressureTable() const {
|
||||
return m_ThresholdPressure->getThresholdPressureTable();
|
||||
std::shared_ptr<const ThresholdPressure> SimulationConfig::getThresholdPressure() const {
|
||||
return m_ThresholdPressure;
|
||||
}
|
||||
|
||||
} //namespace Opm
|
||||
|
@ -32,7 +32,7 @@ namespace Opm {
|
||||
|
||||
SimulationConfig(const ParseMode& parseMode , DeckConstPtr deck, std::shared_ptr<GridProperties<int>> gridProperties);
|
||||
|
||||
const std::vector<std::pair<bool,double>>& getThresholdPressureTable() const;
|
||||
std::shared_ptr<const ThresholdPressure> getThresholdPressure() const;
|
||||
|
||||
|
||||
private:
|
||||
|
@ -16,7 +16,6 @@
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <opm/parser/eclipse/EclipseState/SimulationConfig/ThresholdPressure.hpp>
|
||||
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
||||
#include <opm/parser/eclipse/Deck/Section.hpp>
|
||||
@ -25,7 +24,9 @@
|
||||
|
||||
namespace Opm {
|
||||
|
||||
ThresholdPressure::ThresholdPressure(const ParseMode& parseMode , DeckConstPtr deck, std::shared_ptr<GridProperties<int>> gridProperties) {
|
||||
ThresholdPressure::ThresholdPressure(const ParseMode& parseMode , DeckConstPtr deck, std::shared_ptr<GridProperties<int>> gridProperties)
|
||||
: m_parseMode( parseMode )
|
||||
{
|
||||
|
||||
if (Section::hasRUNSPEC(deck) && Section::hasSOLUTION(deck)) {
|
||||
std::shared_ptr<const RUNSPECSection> runspecSection = std::make_shared<const RUNSPECSection>(deck);
|
||||
@ -35,6 +36,29 @@ namespace Opm {
|
||||
}
|
||||
|
||||
|
||||
std::pair<int,int> 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<bool , double>& valuePair) {
|
||||
std::pair<int,int> indexPair = makeIndex(r1,r2);
|
||||
m_pressureTable[indexPair] = valuePair;
|
||||
}
|
||||
|
||||
void ThresholdPressure::addBarrier(int r1 , int r2 , double p) {
|
||||
std::pair<bool,double> valuePair = std::make_pair(true , p);
|
||||
addPair( r1,r2, valuePair );
|
||||
}
|
||||
|
||||
void ThresholdPressure::addBarrier(int r1 , int r2) {
|
||||
std::pair<bool,double> valuePair = std::make_pair(false , 0);
|
||||
addPair( r1,r2, valuePair );
|
||||
}
|
||||
|
||||
|
||||
void ThresholdPressure::initThresholdPressure(const ParseMode& parseMode,
|
||||
std::shared_ptr<const RUNSPECSection> runspecSection,
|
||||
std::shared_ptr<const SOLUTIONSection> solutionSection,
|
||||
@ -81,8 +105,6 @@ namespace Opm {
|
||||
// Fill threshold pressure table.
|
||||
auto thpres = solutionSection->getKeyword<ParserKeywords::THPRES>( );
|
||||
|
||||
m_thresholdPressureTable.resize(maxEqlnum * maxEqlnum, std::pair<bool, double>(false,0));
|
||||
|
||||
const int numRecords = thpres->size();
|
||||
for (int rec_ix = 0; rec_ix < numRecords; ++rec_ix) {
|
||||
auto rec = thpres->getRecord(rec_ix);
|
||||
@ -91,19 +113,17 @@ namespace Opm {
|
||||
auto thpressItem = rec->getItem<ParserKeywords::THPRES::VALUE>();
|
||||
|
||||
if (region1Item->hasValue(0) && region2Item->hasValue(0)) {
|
||||
const int r1 = region1Item->getInt(0) - 1;
|
||||
const int r2 = region2Item->getInt(0) - 1;
|
||||
if (r1 >= maxEqlnum || r2 >= maxEqlnum) {
|
||||
const int r1 = region1Item->getInt(0);
|
||||
const int r2 = region2Item->getInt(0);
|
||||
if (r1 > maxEqlnum || r2 > maxEqlnum) {
|
||||
throw std::runtime_error("Too high region numbers in THPRES keyword");
|
||||
}
|
||||
|
||||
if (thpressItem->hasValue(0)) {
|
||||
const double p = thpressItem->getSIDouble(0);
|
||||
m_thresholdPressureTable[r1 + maxEqlnum*r2] = std::pair<bool, double>(true,p);
|
||||
m_thresholdPressureTable[r2 + maxEqlnum*r1] = std::pair<bool, double>(true,p);
|
||||
} else {
|
||||
m_thresholdPressureTable[r1 + maxEqlnum*r2] = std::pair<bool, double>(false,0);
|
||||
m_thresholdPressureTable[r2 + maxEqlnum*r1] = std::pair<bool, double>(false,0);
|
||||
}
|
||||
addBarrier( r1 , r2 , p );
|
||||
} else
|
||||
addBarrier( r1 , r2 );
|
||||
} else
|
||||
throw std::runtime_error("Missing region data for use of the THPRES keyword");
|
||||
|
||||
@ -115,9 +135,52 @@ namespace Opm {
|
||||
}
|
||||
|
||||
|
||||
bool ThresholdPressure::hasRegionBarrier(int r1 , int r2) const {
|
||||
std::pair<int,int> indexPair = makeIndex(r1,r2);
|
||||
if (m_pressureTable.find( indexPair ) == m_pressureTable.end())
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
const std::vector<std::pair<bool,double>>& ThresholdPressure::getThresholdPressureTable() const {
|
||||
return m_thresholdPressureTable;
|
||||
|
||||
double ThresholdPressure::getThresholdPressure(int r1 , int r2) const {
|
||||
std::pair<int,int> indexPair = makeIndex(r1,r2);
|
||||
auto iter = m_pressureTable.find( indexPair );
|
||||
if (iter == m_pressureTable.end())
|
||||
return 0.0;
|
||||
else {
|
||||
auto pair_pair = *iter;
|
||||
auto value_pair = pair_pair.second;
|
||||
bool valid = value_pair.first;
|
||||
double value = value_pair.second;
|
||||
if (valid)
|
||||
return value;
|
||||
else {
|
||||
std::string msg = "The THPRES value for regions " + std::to_string(r1) + " and " + std::to_string(r2) + " has not been initialized. Using 0.0";
|
||||
m_parseMode.handleError(ParseMode::INTERNAL_ERROR_UNINITIALIZED_THPRES, msg);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
size_t ThresholdPressure::size() const {
|
||||
return m_pressureTable.size();
|
||||
}
|
||||
|
||||
|
||||
bool ThresholdPressure::hasThresholdPressure(int r1 , int r2) const {
|
||||
std::pair<int,int> indexPair = makeIndex(r1,r2);
|
||||
auto iter = m_pressureTable.find( indexPair );
|
||||
if (iter == m_pressureTable.end())
|
||||
return false;
|
||||
else {
|
||||
auto pair_pair = *iter;
|
||||
auto value_pair = pair_pair.second;
|
||||
return value_pair.first;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -36,19 +36,47 @@ namespace Opm {
|
||||
|
||||
ThresholdPressure(const ParseMode& parseMode , DeckConstPtr deck, std::shared_ptr<GridProperties<int>> gridProperties);
|
||||
|
||||
const std::vector<std::pair<bool,double>>& getThresholdPressureTable() const;
|
||||
|
||||
/*
|
||||
The hasRegionBarrier() method checks if a threshold pressure
|
||||
has been configured between the equilibration regions r1 and
|
||||
r2; i.e. if the deck contains a THPRES record with regions
|
||||
r1 and r2.
|
||||
*/
|
||||
bool hasRegionBarrier(int r1 , int r2) const;
|
||||
|
||||
/*
|
||||
Checks if a threshold presssure has been configured between
|
||||
the equilibration regions r1 and r2; the function will
|
||||
return false either if no THPRES record with r1 and r2 has
|
||||
been configured - or if THPRES record with ra and r2 has
|
||||
defaulted pressure.
|
||||
*/
|
||||
bool hasThresholdPressure(int r1 , int r2) const;
|
||||
|
||||
/*
|
||||
Will return the threshold pressure between equilibration
|
||||
regions r1 and r2; if the pressure has been defaulted the
|
||||
function will raise the error
|
||||
INTERNAL_ERROR_UNINITIALIZED_THPRES - check with
|
||||
hasThresholdPressure(r1,r2) first to be safe.
|
||||
*/
|
||||
double getThresholdPressure(int r1 , int r2) const;
|
||||
size_t size() const;
|
||||
private:
|
||||
|
||||
void initThresholdPressure(const ParseMode& parseMode,
|
||||
std::shared_ptr<const RUNSPECSection> runspecSection,
|
||||
std::shared_ptr<const SOLUTIONSection> solutionSection,
|
||||
std::shared_ptr<GridProperties<int>> gridProperties);
|
||||
|
||||
|
||||
static std::pair<int,int> makeIndex(int r1 , int r2);
|
||||
void addPair(int r1 , int r2 , const std::pair<bool , double>& valuePair);
|
||||
void addBarrier(int r1 , int r2);
|
||||
void addBarrier(int r1 , int r2 , double p);
|
||||
|
||||
std::vector<std::pair<bool,double>> m_thresholdPressureTable;
|
||||
std::map<std::pair<int,int> , std::pair<bool , double> > m_pressureTable;
|
||||
const ParseMode& m_parseMode;
|
||||
};
|
||||
|
||||
|
||||
|
@ -77,8 +77,6 @@ BOOST_AUTO_TEST_CASE(SimulationConfigGetThresholdPressureTableTest) {
|
||||
DeckPtr deck = createDeck(parseMode , inputStr);
|
||||
SimulationConfigConstPtr simulationConfigPtr;
|
||||
BOOST_CHECK_NO_THROW(simulationConfigPtr = std::make_shared<const SimulationConfig>(parseMode , deck, getGridProperties()));
|
||||
const std::vector<std::pair<bool,double>>& thresholdPressureTable = simulationConfigPtr->getThresholdPressureTable();
|
||||
BOOST_CHECK(thresholdPressureTable.size() > 0);
|
||||
}
|
||||
|
||||
|
||||
|
@ -46,6 +46,7 @@ const std::string& inputStr = "RUNSPEC\n"
|
||||
"THPRES\n"
|
||||
"1 2 12.0/\n"
|
||||
"1 3 5.0/\n"
|
||||
"2 3 33.0 /\n"
|
||||
"2 3 7.0/\n"
|
||||
"/\n"
|
||||
"\n";
|
||||
@ -155,19 +156,16 @@ BOOST_AUTO_TEST_CASE(ThresholdPressureTest) {
|
||||
ParseMode parseMode;
|
||||
DeckPtr deck = createDeck(parseMode , inputStr);
|
||||
static std::shared_ptr<GridProperties<int>> gridProperties = getGridProperties();
|
||||
ThresholdPressureConstPtr tresholdPressurePtr = std::make_shared<ThresholdPressure>(parseMode , deck, gridProperties);
|
||||
ThresholdPressureConstPtr thp = std::make_shared<ThresholdPressure>(parseMode , deck, gridProperties);
|
||||
|
||||
const std::vector<std::pair<bool,double>>& thresholdPressureTable = tresholdPressurePtr->getThresholdPressureTable();
|
||||
|
||||
double pressureList[] = {0.0, 1200000.0, 500000.0, 1200000.0, 0.0, 700000.0, 500000.0, 700000.0, 0.0};
|
||||
std::vector<double> wantedResultVec(pressureList, pressureList + sizeof(pressureList) / sizeof(double));
|
||||
BOOST_CHECK_EQUAL( thp->getThresholdPressure(1,2) , 1200000.0 );
|
||||
BOOST_CHECK_EQUAL( thp->getThresholdPressure(2,1) , 1200000.0 );
|
||||
BOOST_CHECK_EQUAL( thp->getThresholdPressure(1,3) , 500000.0 );
|
||||
BOOST_CHECK_EQUAL( thp->getThresholdPressure(3,1) , 500000.0 );
|
||||
BOOST_CHECK_EQUAL( thp->getThresholdPressure(2,3) , 700000.0 );
|
||||
BOOST_CHECK_EQUAL( thp->getThresholdPressure(3,2) , 700000.0 );
|
||||
|
||||
BOOST_CHECK_EQUAL(thresholdPressureTable.size(), wantedResultVec.size());
|
||||
|
||||
for (unsigned i=0; i < thresholdPressureTable.size(); i++) {
|
||||
std::pair<bool, double> item = thresholdPressureTable[i];
|
||||
BOOST_CHECK_EQUAL(item.second, pressureList[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -175,10 +173,8 @@ BOOST_AUTO_TEST_CASE(ThresholdPressureEmptyTest) {
|
||||
ParseMode parseMode;
|
||||
DeckPtr deck = createDeck(parseMode , inputStrNoSolutionSection);
|
||||
static std::shared_ptr<GridProperties<int>> gridProperties = getGridProperties();
|
||||
ThresholdPressureConstPtr tresholdPressurePtr = std::make_shared<ThresholdPressure>(parseMode , deck, gridProperties);
|
||||
const std::vector<std::pair<bool,double>>& thresholdPressureTable = tresholdPressurePtr->getThresholdPressureTable();
|
||||
|
||||
BOOST_CHECK_EQUAL(0, thresholdPressureTable.size());
|
||||
ThresholdPressureConstPtr thresholdPressurePtr = std::make_shared<ThresholdPressure>(parseMode , deck, gridProperties);
|
||||
BOOST_CHECK_EQUAL(0, thresholdPressurePtr->size());
|
||||
}
|
||||
|
||||
|
||||
@ -188,16 +184,13 @@ BOOST_AUTO_TEST_CASE(ThresholdPressureNoTHPREStest) {
|
||||
DeckPtr deck_no_thpres2 = createDeck(parseMode , inputStrTHPRESinRUNSPECnotSoultion);
|
||||
static std::shared_ptr<GridProperties<int>> gridProperties = getGridProperties();
|
||||
|
||||
ThresholdPressureConstPtr tresholdPressurePtr;
|
||||
BOOST_CHECK_NO_THROW(tresholdPressurePtr = std::make_shared<ThresholdPressure>(parseMode , deck_no_thpres, gridProperties));
|
||||
ThresholdPressureConstPtr tresholdPressurePtr2;
|
||||
BOOST_CHECK_NO_THROW(tresholdPressurePtr2 = std::make_shared<ThresholdPressure>(parseMode , deck_no_thpres2, gridProperties));
|
||||
ThresholdPressureConstPtr thresholdPressurePtr;
|
||||
BOOST_CHECK_NO_THROW(thresholdPressurePtr = std::make_shared<ThresholdPressure>(parseMode , deck_no_thpres, gridProperties));
|
||||
ThresholdPressureConstPtr thresholdPressurePtr2;
|
||||
BOOST_CHECK_NO_THROW(thresholdPressurePtr2 = std::make_shared<ThresholdPressure>(parseMode , deck_no_thpres2, gridProperties));
|
||||
|
||||
const std::vector<std::pair<bool,double>>& thresholdPressureTable = tresholdPressurePtr->getThresholdPressureTable();
|
||||
BOOST_CHECK_EQUAL(0, thresholdPressureTable.size());
|
||||
|
||||
const std::vector<std::pair<bool,double>>& thresholdPressureTable2 = tresholdPressurePtr2->getThresholdPressureTable();
|
||||
BOOST_CHECK_EQUAL(0, thresholdPressureTable2.size());
|
||||
BOOST_CHECK_EQUAL(0, thresholdPressurePtr->size());
|
||||
BOOST_CHECK_EQUAL(0, thresholdPressurePtr2->size());
|
||||
}
|
||||
|
||||
|
||||
@ -227,6 +220,34 @@ BOOST_AUTO_TEST_CASE(ThresholdPressureThrowTest) {
|
||||
|
||||
parseMode.update( ParseMode::UNSUPPORTED_INITIAL_THPRES , InputError::IGNORE );
|
||||
BOOST_CHECK_NO_THROW(ThresholdPressure(parseMode,deck_missingPressure, gridProperties));
|
||||
|
||||
|
||||
{
|
||||
ThresholdPressure thp(parseMode , deck_missingPressure , gridProperties );
|
||||
|
||||
BOOST_CHECK_EQUAL( true , thp.hasRegionBarrier(2,3));
|
||||
BOOST_CHECK_EQUAL( false , thp.hasThresholdPressure(2,3));
|
||||
|
||||
parseMode.update( ParseMode::INTERNAL_ERROR_UNINITIALIZED_THPRES , InputError::THROW_EXCEPTION );
|
||||
BOOST_CHECK_THROW( thp.getThresholdPressure(2, 3) , std::invalid_argument);
|
||||
|
||||
parseMode.update( ParseMode::INTERNAL_ERROR_UNINITIALIZED_THPRES , InputError::IGNORE );
|
||||
BOOST_CHECK_EQUAL( 0.0 , thp.getThresholdPressure(2, 3));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(HasPair) {
|
||||
ParseMode parseMode;
|
||||
DeckPtr deck = createDeck(parseMode , inputStr);
|
||||
static std::shared_ptr<GridProperties<int>> gridProperties = getGridProperties();
|
||||
ThresholdPressure thp(parseMode , deck , gridProperties);
|
||||
|
||||
BOOST_CHECK_EQUAL( true , thp.hasRegionBarrier( 1 , 2 ));
|
||||
BOOST_CHECK_EQUAL( false , thp.hasRegionBarrier( 1 , 7 ));
|
||||
BOOST_CHECK_EQUAL( true , thp.hasThresholdPressure( 1, 2 ));
|
||||
BOOST_CHECK_EQUAL( false , thp.hasThresholdPressure( 1, 7 ));
|
||||
BOOST_CHECK_EQUAL( 1200000.0 , thp.getThresholdPressure( 1,2 ));
|
||||
|
||||
}
|
||||
|
||||
|
@ -220,8 +220,8 @@ BOOST_AUTO_TEST_CASE(CreateSimulationConfig) {
|
||||
DeckPtr deck = createDeckSimConfig();
|
||||
EclipseState state(deck, ParseMode());
|
||||
SimulationConfigConstPtr simulationConfig = state.getSimulationConfig();
|
||||
std::vector<std::pair<bool,double>> thresholdPressureTable = simulationConfig->getThresholdPressureTable();
|
||||
BOOST_CHECK_EQUAL(thresholdPressureTable.size(), 9);
|
||||
std::shared_ptr<const ThresholdPressure> thresholdPressure = simulationConfig->getThresholdPressure();
|
||||
BOOST_CHECK_EQUAL(thresholdPressure->size(), 3);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user