From 42fc0666be31ba775e21eee30af9403f9ec015ce Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Mon, 3 Feb 2020 07:26:25 +0100 Subject: [PATCH] Rst connection - use proper enums for direction and state --- opm/io/eclipse/rst/connection.hpp | 7 ++-- .../EclipseState/Schedule/Well/Connection.hpp | 2 +- src/opm/io/eclipse/rst/connection.cpp | 34 +++++++++++++++++-- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/opm/io/eclipse/rst/connection.hpp b/opm/io/eclipse/rst/connection.hpp index 2cd92ac97..490854c7c 100644 --- a/opm/io/eclipse/rst/connection.hpp +++ b/opm/io/eclipse/rst/connection.hpp @@ -20,6 +20,9 @@ #define RST_CONNECTION #include + +#include + namespace Opm { namespace RestartIO { @@ -30,11 +33,11 @@ struct RstConnection { int insert_index; std::array ijk; - int status; + Connection::State state; int drain_sat_table; int imb_sat_table; int completion; - int dir; + Connection::Direction dir; int segment; float tran; diff --git a/opm/parser/eclipse/EclipseState/Schedule/Well/Connection.hpp b/opm/parser/eclipse/EclipseState/Schedule/Well/Connection.hpp index 2e5ea7095..f0edc850a 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/Well/Connection.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/Well/Connection.hpp @@ -41,7 +41,7 @@ namespace Opm { enum class State { OPEN = 1, SHUT = 2, - AUTO = 3 + AUTO = 3 // Seems like the AUTO state can not be serialized to restart files. }; static const std::string State2String( State enumValue ); diff --git a/src/opm/io/eclipse/rst/connection.cpp b/src/opm/io/eclipse/rst/connection.cpp index 1846b7b92..273913f6b 100644 --- a/src/opm/io/eclipse/rst/connection.cpp +++ b/src/opm/io/eclipse/rst/connection.cpp @@ -26,14 +26,44 @@ namespace VI = ::Opm::RestartIO::Helpers::VectorItems; namespace Opm { namespace RestartIO { +namespace { + +template +T from_int(int); + +template <> +Connection::State from_int(int int_state) { + if (int_state == 1) + return Connection::State::OPEN; + + return Connection::State::SHUT; +} + +template <> +Connection::Direction from_int(int int_dir) { + switch (int_dir) { + case 1: + return Connection::Direction::X; + case 2: + return Connection::Direction::Y; + case 3: + return Connection::Direction::Z; + throw + std::invalid_argument("Can not convert: " + std::to_string(int_dir) + " to string"); + } +} + +} + + RstConnection::RstConnection(const int* icon, const float* scon, const double* xcon) : insert_index(icon[VI::IConn::SeqIndex] - 1), ijk({icon[VI::IConn::CellI] - 1, icon[VI::IConn::CellJ] - 1, icon[VI::IConn::CellK] - 1}), - status(icon[VI::IConn::ConnStat]), + state(from_int(icon[VI::IConn::ConnStat])), drain_sat_table(icon[VI::IConn::Drainage]), imb_sat_table(icon[VI::IConn::Imbibition]), completion(icon[VI::IConn::ComplNum] - 1), - dir(icon[VI::IConn::ConnDir]), + dir(from_int(icon[VI::IConn::ConnDir])), segment(icon[VI::IConn::Segment] - 1), tran(scon[VI::SConn::ConnTrans]), depth(scon[VI::SConn::Depth]),