From 14f9c416130c11b4156f9f86487f7c7675a7896e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20H=C3=A6gland?= Date: Fri, 1 Jul 2022 08:13:40 +0200 Subject: [PATCH 1/5] Add KRNUM to recognized field props --- opm/input/eclipse/EclipseState/Grid/FieldProps.hpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/opm/input/eclipse/EclipseState/Grid/FieldProps.hpp b/opm/input/eclipse/EclipseState/Grid/FieldProps.hpp index b379ce29b..0bbc17834 100644 --- a/opm/input/eclipse/EclipseState/Grid/FieldProps.hpp +++ b/opm/input/eclipse/EclipseState/Grid/FieldProps.hpp @@ -243,7 +243,11 @@ static const std::unordered_map> int_keywords = { {"PVTNUM", keyword_info{}.init(1)}, {"SATNUM", keyword_info{}.init(1)}, {"LWSLTNUM", keyword_info{}}, - {"ROCKNUM", keyword_info{}}}; + {"ROCKNUM", keyword_info{}}, + {"KRNUMX", keyword_info{}}, + {"KRNUMY", keyword_info{}}, + {"KRNUMZ", keyword_info{}}, + }; } namespace SOLUTION { From 63f5dbdb8114a3895b173bb3b1272c5aa7613ab1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20H=C3=A6gland?= Date: Thu, 25 Aug 2022 21:40:59 +0200 Subject: [PATCH 2/5] Add debugging output method to FaceDir --- .../eclipse/EclipseState/Grid/FaceDir.hpp | 1 + .../eclipse/EclipseState/Grid/FaceDir.cpp | 22 +++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/opm/input/eclipse/EclipseState/Grid/FaceDir.hpp b/opm/input/eclipse/EclipseState/Grid/FaceDir.hpp index f49b71a09..8200bd7ab 100644 --- a/opm/input/eclipse/EclipseState/Grid/FaceDir.hpp +++ b/opm/input/eclipse/EclipseState/Grid/FaceDir.hpp @@ -43,6 +43,7 @@ namespace Opm { DirEnum FromString(const std::string& stringValue); int FromMULTREGTString(const std::string& stringValue); + const std::string toString(DirEnum dir); } } diff --git a/src/opm/input/eclipse/EclipseState/Grid/FaceDir.cpp b/src/opm/input/eclipse/EclipseState/Grid/FaceDir.cpp index 1addc8ba4..a88f00708 100644 --- a/src/opm/input/eclipse/EclipseState/Grid/FaceDir.cpp +++ b/src/opm/input/eclipse/EclipseState/Grid/FaceDir.cpp @@ -20,7 +20,7 @@ #include #include - +#include namespace Opm { @@ -72,6 +72,24 @@ namespace Opm { throw std::invalid_argument("The string " + stringValue + " is not a valid MULTREGT direction value"); } - + const std::string toString(DirEnum dir) + { + std::vector ret; + if (dir & DirEnum::XPlus) + ret.push_back("X+"); + if (dir & DirEnum::XMinus) + ret.push_back("X-"); + if (dir & DirEnum::YPlus) + ret.push_back("Y+"); + if (dir & DirEnum::YMinus) + ret.push_back("Y-"); + if (dir & DirEnum::ZPlus) + ret.push_back("Z+"); + if (dir & DirEnum::ZMinus) + ret.push_back("Z-"); + if (ret.size() == 0) + throw std::runtime_error("This should not happen"); + return fmt::format("{}",fmt::join(ret, "|")); + } } } From 9e143482cfca1532823f908764e25b036ae04bdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20H=C3=A6gland?= Date: Wed, 14 Sep 2022 15:33:03 +0200 Subject: [PATCH 3/5] Add a unknown value to the facedir enum This is will be used by code in opm-models and opm-simulators to identify a face direction that is not known or not important. --- .../eclipse/EclipseState/Grid/FaceDir.hpp | 13 ++++---- .../eclipse/EclipseState/Grid/FaceDir.cpp | 31 +++++++++++-------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/opm/input/eclipse/EclipseState/Grid/FaceDir.hpp b/opm/input/eclipse/EclipseState/Grid/FaceDir.hpp index 8200bd7ab..c5d913993 100644 --- a/opm/input/eclipse/EclipseState/Grid/FaceDir.hpp +++ b/opm/input/eclipse/EclipseState/Grid/FaceDir.hpp @@ -28,12 +28,13 @@ namespace Opm { namespace FaceDir { enum DirEnum { - XPlus = 1, - XMinus = 2, - YPlus = 4, - YMinus = 8, - ZPlus = 16, - ZMinus = 32 + Unknown = 0, + XPlus = 1, + XMinus = 2, + YPlus = 4, + YMinus = 8, + ZPlus = 16, + ZMinus = 32 }; /** The MULTREGTScanner will use these values as bitmaps; diff --git a/src/opm/input/eclipse/EclipseState/Grid/FaceDir.cpp b/src/opm/input/eclipse/EclipseState/Grid/FaceDir.cpp index a88f00708..977b7ae21 100644 --- a/src/opm/input/eclipse/EclipseState/Grid/FaceDir.cpp +++ b/src/opm/input/eclipse/EclipseState/Grid/FaceDir.cpp @@ -18,11 +18,11 @@ */ #include +#include #include #include - namespace Opm { namespace FaceDir { @@ -75,18 +75,23 @@ namespace Opm { const std::string toString(DirEnum dir) { std::vector ret; - if (dir & DirEnum::XPlus) - ret.push_back("X+"); - if (dir & DirEnum::XMinus) - ret.push_back("X-"); - if (dir & DirEnum::YPlus) - ret.push_back("Y+"); - if (dir & DirEnum::YMinus) - ret.push_back("Y-"); - if (dir & DirEnum::ZPlus) - ret.push_back("Z+"); - if (dir & DirEnum::ZMinus) - ret.push_back("Z-"); + if (dir == DirEnum::Unknown) { + ret.push_back("Unknown"); + } + else { + if (dir & DirEnum::XPlus) + ret.push_back("X+"); + if (dir & DirEnum::XMinus) + ret.push_back("X-"); + if (dir & DirEnum::YPlus) + ret.push_back("Y+"); + if (dir & DirEnum::YMinus) + ret.push_back("Y-"); + if (dir & DirEnum::ZPlus) + ret.push_back("Z+"); + if (dir & DirEnum::ZMinus) + ret.push_back("Z-"); + } if (ret.size() == 0) throw std::runtime_error("This should not happen"); return fmt::format("{}",fmt::join(ret, "|")); From 5086d5d74e871e67dfcb45aad38a23bbb435ace2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20H=C3=A6gland?= Date: Tue, 20 Sep 2022 01:30:16 +0200 Subject: [PATCH 4/5] Add a CopyablePtr class Adds a template class that wraps a std::unique_ptr and makes it copyable. See pull #714 in opm-models for a use case. --- CMakeLists_files.cmake | 2 ++ opm/utility/CopyablePtr.hpp | 71 +++++++++++++++++++++++++++++++++++++ tests/test_CopyablePtr.cpp | 66 ++++++++++++++++++++++++++++++++++ 3 files changed, 139 insertions(+) create mode 100644 opm/utility/CopyablePtr.hpp create mode 100644 tests/test_CopyablePtr.cpp diff --git a/CMakeLists_files.cmake b/CMakeLists_files.cmake index 23b05ffba..57881d5de 100644 --- a/CMakeLists_files.cmake +++ b/CMakeLists_files.cmake @@ -365,6 +365,7 @@ list (APPEND TEST_SOURCE_FILES if(ENABLE_ECL_INPUT) list(APPEND TEST_SOURCE_FILES tests/rst_test.cpp + tests/test_CopyablePtr.cpp tests/test_ERsm.cpp tests/test_GuideRate.cpp tests/test_RestartFileView.cpp @@ -988,6 +989,7 @@ if(ENABLE_ECL_OUTPUT) opm/output/eclipse/WriteRPT.hpp opm/output/eclipse/WriteRestartHelpers.hpp opm/output/OutputWriter.hpp + opm/utility/CopyablePtr.hpp opm/utility/EModel.hpp ) endif() diff --git a/opm/utility/CopyablePtr.hpp b/opm/utility/CopyablePtr.hpp new file mode 100644 index 000000000..ab06371c5 --- /dev/null +++ b/opm/utility/CopyablePtr.hpp @@ -0,0 +1,71 @@ +/* + Copyright 2022 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 . +*/ + +#ifndef OPM_COPYABLE_PTR_HPP +#define OPM_COPYABLE_PTR_HPP +namespace Opm { +namespace Utility { +// Wraps std::unique_ptr and makes it copyable. +// +// WARNING: This template should not be used with polymorphic classes. +// That would require a virtual clone() method to be implemented. +// It will only ever copy the static class type of the pointed to class. +template +class CopyablePtr { +public: + CopyablePtr() : ptr_(nullptr) {} + CopyablePtr(const CopyablePtr& other) { + if (other) { // other does not contain a nullptr + ptr_ = std::make_unique(*other.get()); + } + else { + ptr_ = nullptr; + } + } + // assignment operator + CopyablePtr& operator=(const CopyablePtr& other) { + if (other) { + ptr_ = std::make_unique(*other.get()); + } + else { + ptr_ = nullptr; + } + return *this; + } + // assign directly from a unique_ptr + CopyablePtr& operator=(std::unique_ptr&& uptr) { + ptr_ = std::move(uptr); + return *this; + } + // member access operator + T* operator->() const {return ptr_.get(); } + // boolean context operator + explicit operator bool() const noexcept { + return ptr_ ? true : false; + } + // get a pointer to the stored value + T* get() const {return ptr_.get();} + T* release() const {return ptr_.release();} +private: + std::unique_ptr ptr_; +}; + +} // namespace Utility +} // namespace Opm +#endif \ No newline at end of file diff --git a/tests/test_CopyablePtr.cpp b/tests/test_CopyablePtr.cpp new file mode 100644 index 000000000..c92a4b0b5 --- /dev/null +++ b/tests/test_CopyablePtr.cpp @@ -0,0 +1,66 @@ +/* + Copyright 2022 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 + +#define BOOST_TEST_MODULE CopyablePtrTest +#include + +#include + +#include + +namespace { +template +class A { + using CopyablePtr = Opm::Utility::CopyablePtr; +public: + A() : aptr_{} {} + void assign(T value) { + aptr_ = std::make_unique(value); + } + const CopyablePtr& get_aptr() const {return aptr_;} +private: + CopyablePtr aptr_; +}; + +struct B { + double a; + int b; + int getb() {return b;} +}; +} // namespace + +BOOST_AUTO_TEST_SUITE () + +BOOST_AUTO_TEST_CASE (copyable) +{ + A a1 {}; + a1.assign(B{1.1,2}); + BOOST_CHECK_MESSAGE(a1.get_aptr().get()->a == 1.1, "Able to assign new value to pointer"); + A a2 = a1; + BOOST_CHECK_MESSAGE(a2.get_aptr().get()->a == 1.1, "Able to copy construct a new pointer"); + a1.assign(B{1.3,3}); + BOOST_CHECK_MESSAGE(a1.get_aptr().get()->a == 1.3, "Able to access new value to pointer"); + BOOST_CHECK_MESSAGE(a2.get_aptr().get()->b == 2, "Copied value not affected by parent modification"); + BOOST_CHECK_MESSAGE(a1.get_aptr().get()->getb() == 3, "Member access operator works"); + BOOST_CHECK_MESSAGE(a1.get_aptr(), "Boolean context operator works"); +} + +BOOST_AUTO_TEST_SUITE_END() From 34ea7f3662b50016d4845966df8b8a7de0b23f60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20H=C3=A6gland?= Date: Wed, 21 Sep 2022 15:47:41 +0200 Subject: [PATCH 5/5] Add one more test --- tests/test_CopyablePtr.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_CopyablePtr.cpp b/tests/test_CopyablePtr.cpp index c92a4b0b5..733d0a3e2 100644 --- a/tests/test_CopyablePtr.cpp +++ b/tests/test_CopyablePtr.cpp @@ -52,6 +52,7 @@ BOOST_AUTO_TEST_SUITE () BOOST_AUTO_TEST_CASE (copyable) { A a1 {}; + BOOST_CHECK_MESSAGE(!a1.get_aptr(), "Boolean context operator works. Initialization with nullptr works"); a1.assign(B{1.1,2}); BOOST_CHECK_MESSAGE(a1.get_aptr().get()->a == 1.1, "Able to assign new value to pointer"); A a2 = a1;