Protecting against use of unassigned deck values.

This commit is contained in:
Joakim Hove 2015-01-14 11:41:41 +01:00
parent 7f8ae2a878
commit a5f00298e0

View File

@ -47,13 +47,16 @@ namespace Opm
auto eqlopts = deck->getKeyword("EQLOPTS"); auto eqlopts = deck->getKeyword("EQLOPTS");
auto rec = eqlopts->getRecord(0); auto rec = eqlopts->getRecord(0);
for (size_t i = 0; i < rec->size(); ++i) { for (size_t i = 0; i < rec->size(); ++i) {
if (rec->getItem(i)->getString(0) == "THPRES") { auto item = rec->getItem(i);
if (item->hasValue(0)) {
if (item->getString(0) == "THPRES") {
has_thpres_option = true; has_thpres_option = true;
} else if (rec->getItem(i)->getString(0) == "IRREVERS") { } else if (item->getString(0) == "IRREVERS") {
OPM_THROW(std::runtime_error, "Cannot use IRREVERS version of THPRES option, not implemented."); OPM_THROW(std::runtime_error, "Cannot use IRREVERS version of THPRES option, not implemented.");
} }
} }
} }
}
// Do we have the THPRES keyword? // Do we have the THPRES keyword?
// Check for consistency. // Check for consistency.
@ -77,14 +80,23 @@ namespace Opm
const int num_records = thpres->size(); const int num_records = thpres->size();
for (int rec_ix = 0; rec_ix < num_records; ++rec_ix) { for (int rec_ix = 0; rec_ix < num_records; ++rec_ix) {
auto rec = thpres->getRecord(rec_ix); auto rec = thpres->getRecord(rec_ix);
const int r1 = rec->getItem("REGION1")->getInt(0) - 1; auto region1Item = rec->getItem("REGION1");
const int r2 = rec->getItem("REGION2")->getInt(0) - 1; auto region2Item = rec->getItem("REGION2");
const double p = rec->getItem("THPRES")->getSIDouble(0); auto thpressItem = rec->getItem("THPRES");
if (region1Item->hasValue(0) && region2Item->hasValue(0) && thpressItem->hasValue(0)) {
const int r1 = region1Item->getInt(0) - 1;
const int r2 = region2Item->getInt(0) - 1;
const double p = thpressItem->getSIDouble(0);
if (r1 >= max_eqlnum || r2 >= max_eqlnum) { if (r1 >= max_eqlnum || r2 >= max_eqlnum) {
OPM_THROW(std::runtime_error, "Too high region numbers in THPRES keyword."); OPM_THROW(std::runtime_error, "Too high region numbers in THPRES keyword.");
} }
thp_table[r1 + max_eqlnum*r2] = p; thp_table[r1 + max_eqlnum*r2] = p;
thp_table[r2 + max_eqlnum*r1] = p; thp_table[r2 + max_eqlnum*r1] = p;
} else {
OPM_THROW(std::runtime_error, "Missing data for use of the THPRES keyword.");
}
} }
// Set values for each face. // Set values for each face.