Improve error handling for grid keywords

This commit is contained in:
Peter Verveer 2023-06-02 18:24:01 +02:00
parent dd34926062
commit 4b750d1d5d
2 changed files with 62 additions and 18 deletions

View File

@ -78,6 +78,8 @@ namespace Opm {
explicit EclipseGrid(const Deck& deck, const int * actnum = nullptr); explicit EclipseGrid(const Deck& deck, const int * actnum = nullptr);
static bool hasGDFILE(const Deck& deck); static bool hasGDFILE(const Deck& deck);
static bool hasRADIAL(const Deck& deck);
static bool hasSPIDER(const Deck& deck);
static bool hasCylindricalKeywords(const Deck& deck); static bool hasCylindricalKeywords(const Deck& deck);
static bool hasCornerPointKeywords(const Deck&); static bool hasCornerPointKeywords(const Deck&);
static bool hasCartesianKeywords(const Deck&); static bool hasCartesianKeywords(const Deck&);

View File

@ -61,6 +61,7 @@
#include <initializer_list> #include <initializer_list>
#include <numeric> #include <numeric>
#include <tuple> #include <tuple>
#include <map>
#include <fmt/format.h> #include <fmt/format.h>
@ -332,22 +333,59 @@ EclipseGrid::EclipseGrid(const Deck& deck, const int * actnum)
return this->m_circle; return this->m_circle;
} }
void EclipseGrid::initGrid(const Deck& deck, const int* actnum) void EclipseGrid::initGrid(const Deck& deck, const int* actnum)
{ {
if (deck.hasKeyword<ParserKeywords::RADIAL>()) { const std::map<const std::string, const std::string> grid_keyword_messages = {
initCylindricalGrid(deck ); {"COORD", "COORD with ZCORN creates a corner-point grid"},
} else if (deck.hasKeyword<ParserKeywords::SPIDER>()) { {"DEPTHZ", "DEPTHZ with DXV, DYV, DZX creates a cartesian grid"},
initSpiderwebGrid(deck ); {"TOPS", "TOPS with DX/DXV, DY/DYV, DX/DZX creates a cartesian grid"},
} else { {"RADIAL", "RADIAL creates a cylindrical grid"},
if (hasCornerPointKeywords(deck)) { {"SPIDER", "SPIDER creates a spider grid"},
initCornerPointGrid(deck); {"GDFILE", "GDFILE reads a grid from file"}
} else if (hasCartesianKeywords(deck)) { };
initCartesianGrid(deck); std::vector<std::string> grid_keywords_found;
} else if (hasGDFILE(deck)) {
initBinaryGrid(deck); if (hasCornerPointKeywords(deck)) {
} else { grid_keywords_found.push_back("COORD");
throw std::invalid_argument("EclipseGrid needs cornerpoint or cartesian keywords."); } else if (hasDVDEPTHZKeywords(deck)) {
grid_keywords_found.push_back("DEPTHZ");
} else if (hasDTOPSKeywords(deck)) {
grid_keywords_found.push_back("TOPS");
} else if (hasRADIAL(deck)) {
grid_keywords_found.push_back("RADIAL");
} else if (hasSPIDER(deck)) {
grid_keywords_found.push_back("SPIDER");
} else if (hasGDFILE(deck)) {
grid_keywords_found.push_back("GDFILE");
}
if (grid_keywords_found.size() == 0) {
std::string message = "The grid must be specified using one of these options:";
for (const auto& item: grid_keyword_messages) {
message += "\n " + item.second;
} }
throw std::invalid_argument(message);
}
if (grid_keywords_found.size() > 1) {
std::string message = "The specification of the grid is ambiguous:";
for (const auto& item: grid_keywords_found) {
message += "\n " + grid_keyword_messages.at(item);
}
throw std::invalid_argument(message);
}
if (grid_keywords_found[0] == "COORD") {
initCornerPointGrid(deck);
} else if (grid_keywords_found[0] == "DEPTHZ" || grid_keywords_found[0] == "TOPS") {
initCartesianGrid(deck);
} else if (grid_keywords_found[0] == "RADIAL") {
initCylindricalGrid(deck );
} else if (grid_keywords_found[0] == "SPIDER") {
initSpiderwebGrid(deck );
} else if (grid_keywords_found[0] == "GDFILE") {
initBinaryGrid(deck);
} }
if (deck.hasKeyword<ParserKeywords::PINCH>()) { if (deck.hasKeyword<ParserKeywords::PINCH>()) {
@ -1230,13 +1268,17 @@ EclipseGrid::EclipseGrid(const Deck& deck, const int * actnum)
return deck.hasKeyword<ParserKeywords::GDFILE>(); return deck.hasKeyword<ParserKeywords::GDFILE>();
} }
bool EclipseGrid::hasCartesianKeywords(const Deck& deck) {
if (hasDVDEPTHZKeywords( deck )) bool EclipseGrid::hasRADIAL(const Deck& deck) {
return true; return deck.hasKeyword<ParserKeywords::RADIAL>();
else
return hasDTOPSKeywords(deck);
} }
bool EclipseGrid::hasSPIDER(const Deck& deck) {
return deck.hasKeyword<ParserKeywords::SPIDER>();
}
bool EclipseGrid::hasCylindricalKeywords(const Deck& deck) { bool EclipseGrid::hasCylindricalKeywords(const Deck& deck) {
if (deck.hasKeyword<ParserKeywords::INRAD>() && if (deck.hasKeyword<ParserKeywords::INRAD>() &&
deck.hasKeyword<ParserKeywords::TOPS>() && deck.hasKeyword<ParserKeywords::TOPS>() &&