Merge pull request #3113 from hakonhagland/fieldprops

Add support for directional relative permeabilties
This commit is contained in:
Tor Harald Sandve 2022-09-26 09:09:52 +02:00 committed by GitHub
commit 7e34f86f42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 179 additions and 10 deletions

View File

@ -365,6 +365,7 @@ list (APPEND TEST_SOURCE_FILES
if(ENABLE_ECL_INPUT) if(ENABLE_ECL_INPUT)
list(APPEND TEST_SOURCE_FILES list(APPEND TEST_SOURCE_FILES
tests/rst_test.cpp tests/rst_test.cpp
tests/test_CopyablePtr.cpp
tests/test_ERsm.cpp tests/test_ERsm.cpp
tests/test_GuideRate.cpp tests/test_GuideRate.cpp
tests/test_RestartFileView.cpp tests/test_RestartFileView.cpp
@ -990,6 +991,7 @@ if(ENABLE_ECL_OUTPUT)
opm/output/eclipse/WriteRPT.hpp opm/output/eclipse/WriteRPT.hpp
opm/output/eclipse/WriteRestartHelpers.hpp opm/output/eclipse/WriteRestartHelpers.hpp
opm/output/OutputWriter.hpp opm/output/OutputWriter.hpp
opm/utility/CopyablePtr.hpp
opm/utility/EModel.hpp opm/utility/EModel.hpp
) )
endif() endif()

View File

@ -28,12 +28,13 @@ namespace Opm {
namespace FaceDir { namespace FaceDir {
enum DirEnum { enum DirEnum {
XPlus = 1, Unknown = 0,
XMinus = 2, XPlus = 1,
YPlus = 4, XMinus = 2,
YMinus = 8, YPlus = 4,
ZPlus = 16, YMinus = 8,
ZMinus = 32 ZPlus = 16,
ZMinus = 32
}; };
/** /**
The MULTREGTScanner will use these values as bitmaps; The MULTREGTScanner will use these values as bitmaps;
@ -43,6 +44,7 @@ namespace Opm {
DirEnum FromString(const std::string& stringValue); DirEnum FromString(const std::string& stringValue);
int FromMULTREGTString(const std::string& stringValue); int FromMULTREGTString(const std::string& stringValue);
const std::string toString(DirEnum dir);
} }
} }

View File

@ -243,7 +243,11 @@ static const std::unordered_map<std::string, keyword_info<int>> int_keywords = {
{"PVTNUM", keyword_info<int>{}.init(1)}, {"PVTNUM", keyword_info<int>{}.init(1)},
{"SATNUM", keyword_info<int>{}.init(1)}, {"SATNUM", keyword_info<int>{}.init(1)},
{"LWSLTNUM", keyword_info<int>{}}, {"LWSLTNUM", keyword_info<int>{}},
{"ROCKNUM", keyword_info<int>{}}}; {"ROCKNUM", keyword_info<int>{}},
{"KRNUMX", keyword_info<int>{}},
{"KRNUMY", keyword_info<int>{}},
{"KRNUMZ", keyword_info<int>{}},
};
} }
namespace SOLUTION { namespace SOLUTION {

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#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 T>
class CopyablePtr {
public:
CopyablePtr() : ptr_(nullptr) {}
CopyablePtr(const CopyablePtr& other) {
if (other) { // other does not contain a nullptr
ptr_ = std::make_unique<T>(*other.get());
}
else {
ptr_ = nullptr;
}
}
// assignment operator
CopyablePtr<T>& operator=(const CopyablePtr<T>& other) {
if (other) {
ptr_ = std::make_unique<T>(*other.get());
}
else {
ptr_ = nullptr;
}
return *this;
}
// assign directly from a unique_ptr
CopyablePtr<T>& operator=(std::unique_ptr<T>&& 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<T> ptr_;
};
} // namespace Utility
} // namespace Opm
#endif

View File

@ -18,10 +18,10 @@
*/ */
#include <stdexcept> #include <stdexcept>
#include <vector>
#include <opm/input/eclipse/EclipseState/Grid/FaceDir.hpp> #include <opm/input/eclipse/EclipseState/Grid/FaceDir.hpp>
#include <fmt/format.h>
namespace Opm { namespace Opm {
@ -72,6 +72,29 @@ namespace Opm {
throw std::invalid_argument("The string " + stringValue + " is not a valid MULTREGT direction value"); throw std::invalid_argument("The string " + stringValue + " is not a valid MULTREGT direction value");
} }
const std::string toString(DirEnum dir)
{
std::vector<std::string> ret;
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, "|"));
}
} }
} }

View File

@ -0,0 +1,67 @@
/*
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 <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#define BOOST_TEST_MODULE CopyablePtrTest
#include <boost/test/unit_test.hpp>
#include <opm/utility/CopyablePtr.hpp>
#include <memory>
namespace {
template <class T>
class A {
using CopyablePtr = Opm::Utility::CopyablePtr<T>;
public:
A() : aptr_{} {}
void assign(T value) {
aptr_ = std::make_unique<T>(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<B> 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<B> 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()