diff --git a/opm/parser/eclipse/EclipseState/Schedule/Well/WellTestState.hpp b/opm/parser/eclipse/EclipseState/Schedule/Well/WellTestState.hpp index 564da139d..e0f511a29 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/Well/WellTestState.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/Well/WellTestState.hpp @@ -28,6 +28,30 @@ namespace Opm { +namespace { + +template +void pack_vector(BufferType& buffer, const std::vector& v) { + buffer.write(v.size()); + for (const auto& e : v) + e.pack(buffer); +} + +template +void unpack_vector(BufferType& buffer, std::vector& v) { + typename std::vector::size_type size; + buffer.read(size); + for (std::size_t i = 0; i < size; i++) { + T elm; + elm.unpack(buffer); + v.push_back(std::move(elm)); + } +} + +} + + + class WellTestState { public: /* @@ -54,6 +78,32 @@ public: // if no, it is -1, which indicates we do not know the associated WTEST yet, // or there is not associated WTEST request int wtest_report_step; + + bool operator==(const WTestWell& other) const { + return this->name == other.name && + this->closed == other.closed && + this->last_test == other.last_test && + this->num_attempt == other.num_attempt && + this->wtest_report_step == other.wtest_report_step; + } + + template + void pack(BufferType& buffer) const { + buffer.write(this->name); + buffer.write(this->closed); + buffer.write(this->last_test); + buffer.write(this->num_attempt); + buffer.write(this->wtest_report_step); + } + + template + void unpack(BufferType& buffer) { + buffer.read(this->name); + buffer.read(this->closed); + buffer.read(this->last_test); + buffer.read(this->num_attempt); + buffer.read(this->wtest_report_step); + } }; @@ -62,6 +112,29 @@ public: int complnum; double last_test; int num_attempt; + + bool operator==(const ClosedCompletion& other) const { + return this->wellName == other.wellName && + this->complnum == other.complnum && + this->last_test == other.last_test && + this->num_attempt == other.num_attempt; + } + + template + void pack(BufferType& buffer) const { + buffer.write(this->wellName); + buffer.write(this->complnum); + buffer.write(this->last_test); + buffer.write(this->num_attempt); + } + + template + void unpack(BufferType& buffer) { + buffer.read(this->wellName); + buffer.read(this->complnum); + buffer.read(this->last_test); + buffer.read(this->num_attempt); + } }; /* @@ -125,6 +198,23 @@ public: */ double lastTestTime(const std::string& well_name) const; + void clear(); + + template + void pack(BufferType& buffer) const { + pack_vector(buffer, this->wells); + pack_vector(buffer, this->completions); + } + + template + void unpack(BufferType& buffer) { + unpack_vector(buffer, this->wells); + unpack_vector(buffer, this->completions); + } + + bool operator==(const WellTestState& other) const; + + private: std::vector wells; std::vector completions; diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/Well/WellTestState.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/Well/WellTestState.cpp index 6cde59e04..52124f9a9 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/Well/WellTestState.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/Well/WellTestState.cpp @@ -242,6 +242,16 @@ namespace Opm { } } + + bool WellTestState::operator==(const WellTestState& other) const { + return this->wells == other.wells && + this->completions == other.completions; + } + + void WellTestState::clear() { + this->wells.clear(); + this->completions.clear(); + } } diff --git a/tests/MessageBuffer.cpp b/tests/MessageBuffer.cpp new file mode 100644 index 000000000..e0c0f73c4 --- /dev/null +++ b/tests/MessageBuffer.cpp @@ -0,0 +1,60 @@ +/* + Copyright (c) 2020 Equinor ASA + + This file is part of the Open Porous Media project (OPM). + + OPM is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OPM is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with OPM. If not, see . +*/ + +#include + +class MessageBuffer +{ +private: + std::stringstream str_{}; + +public: + template + void read(T& value) + { + this->str_.read(reinterpret_cast(&value), sizeof value); + } + + template + void write(T const& value) + { + this->str_.write(reinterpret_cast(&value), sizeof value); + } + + void write(const std::string& str) + { + const int size = str.size(); + this->write(size); + for (int k = 0; k < size; ++k) { + this->write(str[k]); + } + } + + void read(std::string& str) + { + int size = 0; + this->read(size); + str.resize(size); + for (int k = 0; k < size; ++k) { + this->read(str[k]); + } + } +}; + + diff --git a/tests/parser/WTEST.cpp b/tests/parser/WTEST.cpp index 77f9edb71..bba093eec 100644 --- a/tests/parser/WTEST.cpp +++ b/tests/parser/WTEST.cpp @@ -34,6 +34,8 @@ #include #include +#include "tests/MessageBuffer.cpp" + using namespace Opm; @@ -208,3 +210,25 @@ BOOST_AUTO_TEST_CASE(WTEST_STATE_COMPLETIONS) { + +BOOST_AUTO_TEST_CASE(WTEST_PACK_UNPACK) { + WellTestState st, st2; + st.addClosedCompletion("WELL_NAME", 2, 100); + st.addClosedCompletion("WELL_NAME", 2, 100); + st.addClosedCompletion("WELL_NAME", 3, 100); + st.addClosedCompletion("WELLX", 3, 100); + + st.closeWell("WELL_NAME", WellTestConfig::Reason::ECONOMIC, 100); + st.closeWell("WELL_NAME", WellTestConfig::Reason::PHYSICAL, 100); + st.closeWell("WELLX", WellTestConfig::Reason::PHYSICAL, 100); + + BOOST_CHECK(!(st == st2)); + + MessageBuffer buffer; + st.pack(buffer); + + st2.unpack(buffer); + BOOST_CHECK(st == st2); +} + + diff --git a/tests/test_data_GuideRateValue.cpp b/tests/test_data_GuideRateValue.cpp index c4d1487e5..97f46c314 100644 --- a/tests/test_data_GuideRateValue.cpp +++ b/tests/test_data_GuideRateValue.cpp @@ -23,48 +23,10 @@ #include +#include "tests/MessageBuffer.cpp" + BOOST_AUTO_TEST_SUITE(GuideRate_Values) -namespace { - class MessageBuffer - { - private: - std::stringstream str_{}; - - public: - template - void read(T& value) - { - this->str_.read(reinterpret_cast(&value), sizeof value); - } - - template - void write(T const& value) - { - this->str_.write(reinterpret_cast(&value), sizeof value); - } - - void write(const std::string& str) - { - const int size = str.size(); - this->write(size); - for (int k = 0; k < size; ++k) { - this->write(str[k]); - } - } - - void read(std::string& str) - { - int size = 0; - this->read(size); - str.resize(size); - for (int k = 0; k < size; ++k) { - this->read(str[k]); - } - } - }; -} - BOOST_AUTO_TEST_CASE(Construct) { using GRValue = ::Opm::data::GuideRateValue;