From 1a1aaa724b086f1dacab32c2ab1d230e783746e6 Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Thu, 8 Apr 2021 09:14:02 +0200 Subject: [PATCH] Add comparison functions operator== and rst_cmp() to FieldProps --- .../eclipse/EclipseState/Grid/FieldData.hpp | 14 +++ .../EclipseState/Grid/FieldPropsManager.hpp | 3 +- .../eclipse/EclipseState/Grid/Keywords.hpp | 9 ++ .../Grid/SatfuncPropertyInitializers.hpp | 9 ++ .../EclipseState/Grid/TranCalculator.hpp | 11 ++ .../eclipse/EclipseState/Grid/FieldProps.cpp | 100 +++++++++++++++++- .../eclipse/EclipseState/Grid/FieldProps.hpp | 8 ++ .../EclipseState/Grid/FieldPropsManager.cpp | 9 ++ tests/parser/FieldPropsTests.cpp | 22 +++- 9 files changed, 179 insertions(+), 6 deletions(-) diff --git a/opm/parser/eclipse/EclipseState/Grid/FieldData.hpp b/opm/parser/eclipse/EclipseState/Grid/FieldData.hpp index b5e662b50..697d38eb2 100644 --- a/opm/parser/eclipse/EclipseState/Grid/FieldData.hpp +++ b/opm/parser/eclipse/EclipseState/Grid/FieldData.hpp @@ -60,6 +60,15 @@ namespace Fieldprops std::optional> global_value_status; mutable bool all_set; + bool operator==(const FieldData& other) const { + return this->data == other.data && + this->value_status == other.value_status && + this->kw_info == other.kw_info && + this->global_data == other.global_data && + this->global_value_status == other.global_value_status; + } + + FieldData() = default; FieldData(const keywords::keyword_info& info, std::size_t active_size, std::size_t global_size) : @@ -93,6 +102,11 @@ namespace Fieldprops return this->all_set; } + bool valid_default() const { + return std::all_of( this->value_status.begin(), this->value_status.end(), [] (const value::status& status) {return status == value::status::valid_default; }); + } + + void compress(const std::vector& active_map) { Fieldprops::compress(this->data, active_map); Fieldprops::compress(this->value_status, active_map); diff --git a/opm/parser/eclipse/EclipseState/Grid/FieldPropsManager.hpp b/opm/parser/eclipse/EclipseState/Grid/FieldPropsManager.hpp index 7bad332d5..cbae54499 100644 --- a/opm/parser/eclipse/EclipseState/Grid/FieldPropsManager.hpp +++ b/opm/parser/eclipse/EclipseState/Grid/FieldPropsManager.hpp @@ -55,7 +55,8 @@ public: */ std::size_t active_size() const; - + bool operator==(const FieldPropsManager& other) const; + static bool rst_cmp(const FieldPropsManager& full_arg, const FieldPropsManager& rst_arg); /* Because the FieldProps class can autocreate properties the semantics of get() and has() is slightly non intuitve: diff --git a/opm/parser/eclipse/EclipseState/Grid/Keywords.hpp b/opm/parser/eclipse/EclipseState/Grid/Keywords.hpp index 849c8cb59..2c5351340 100644 --- a/opm/parser/eclipse/EclipseState/Grid/Keywords.hpp +++ b/opm/parser/eclipse/EclipseState/Grid/Keywords.hpp @@ -36,6 +36,15 @@ struct keyword_info { bool top = false; bool global = false; + bool operator==(const keyword_info& other) const { + return this->unit == other.unit && + this->scalar_init == other.scalar_init && + this->multiplier == other.multiplier && + this->top == other.top && + this->global == other.global; + } + + keyword_info& init(T init_value) { this->scalar_init = init_value; return *this; diff --git a/opm/parser/eclipse/EclipseState/Grid/SatfuncPropertyInitializers.hpp b/opm/parser/eclipse/EclipseState/Grid/SatfuncPropertyInitializers.hpp index e77e0aaf8..121bda8b6 100644 --- a/opm/parser/eclipse/EclipseState/Grid/SatfuncPropertyInitializers.hpp +++ b/opm/parser/eclipse/EclipseState/Grid/SatfuncPropertyInitializers.hpp @@ -76,6 +76,15 @@ namespace Opm { namespace satfunc { /// region All zero values unless gas is an active phase. std::vector water; } maximum; + + bool operator==(const RawTableEndPoints& other) const { + return this->connate.gas == other.connate.gas && + this->connate.water == other.connate.water && + this->critical.gas == other.critical.gas && + this->critical.water == other.critical.water && + this->maximum.gas == other.maximum.gas && + this->maximum.water == other.maximum.water; + } }; /// Collection of unscaled/raw saturation function value range endpoints diff --git a/opm/parser/eclipse/EclipseState/Grid/TranCalculator.hpp b/opm/parser/eclipse/EclipseState/Grid/TranCalculator.hpp index b8e085782..3279183d5 100644 --- a/opm/parser/eclipse/EclipseState/Grid/TranCalculator.hpp +++ b/opm/parser/eclipse/EclipseState/Grid/TranCalculator.hpp @@ -45,6 +45,11 @@ public: struct TranAction { ScalarOperation op; std::string field; + + bool operator==(const TranAction& other) const { + return this->op == other.op && + this->field == other.field; + } }; @@ -97,6 +102,12 @@ public: } return kw_info; } + + bool operator==(const TranCalculator& other) const { + return this->m_name == other.m_name && + this->actions == other.actions; + } + private: std::string m_name; std::vector actions; diff --git a/src/opm/parser/eclipse/EclipseState/Grid/FieldProps.cpp b/src/opm/parser/eclipse/EclipseState/Grid/FieldProps.cpp index cfbe5043a..7568a5271 100644 --- a/src/opm/parser/eclipse/EclipseState/Grid/FieldProps.cpp +++ b/src/opm/parser/eclipse/EclipseState/Grid/FieldProps.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include @@ -34,7 +35,6 @@ #include #include -#include #include #include #include @@ -43,6 +43,7 @@ #include #include #include +#include #include "FieldProps.hpp" #include "Operate.hpp" @@ -330,6 +331,101 @@ std::vector extract_cell_depth(const EclipseGrid& grid) { return cell_depth; } + + +/* + The rst_compare_data function compares the main std::map> data containers. If one of the containers contains a keyword + *which is fully defaulted* and the other container does not contain said + keyword - the containers are considered to be equal. +*/ +template +bool rst_compare_data(const std::unordered_map>& data1, + const std::unordered_map>& data2) { + std::unordered_set keys; + for (const auto& [key, _] : data1) { + (void)_; + keys.insert(key); + } + + for (const auto& [key, _] : data2) { + (void)_; + keys.insert(key); + } + + for (const auto& key : keys) { + const auto& d1 = data1.find(key); + const auto& d2 = data2.find(key); + + if (d1 == data1.end()) { + if (!d2->second.valid_default()) + return false; + continue; + } + + if (d2 == data2.end()) { + if (!d1->second.valid_default()) + return false; + continue; + } + + if (!(d1->second == d2->second)) + return false; + } + + return true; +} + + +} + + + + + +bool FieldProps::operator==(const FieldProps& other) const { + return this->unit_system == other.unit_system && + this->nx == other.nx && + this->ny == other.ny && + this->nz == other.nz && + this->m_phases == other.m_phases && + this->m_satfuncctrl == other.m_satfuncctrl && + this->m_actnum == other.m_actnum && + this->cell_volume == other.cell_volume && + this->cell_depth == other.cell_depth && + this->m_default_region == other.m_default_region && + this->m_rtep == other.m_rtep && + this->tables == other.tables && + this->int_data == other.int_data && + this->double_data == other.double_data && + this->multregp == other.multregp && + this->tran == other.tran; +} + +bool FieldProps::rst_cmp(const FieldProps& full_arg, const FieldProps& rst_arg) { + + if (!rst_compare_data(full_arg.double_data, rst_arg.double_data)) + return false; + + if (!rst_compare_data(full_arg.int_data, rst_arg.int_data)) + return false; + + if (!UnitSystem::rst_cmp(full_arg.unit_system, rst_arg.unit_system)) + return false; + + return full_arg.nx == rst_arg.nx && + full_arg.ny == rst_arg.ny && + full_arg.nz == rst_arg.nz && + full_arg.m_phases == rst_arg.m_phases && + full_arg.m_satfuncctrl == rst_arg.m_satfuncctrl && + full_arg.m_actnum == rst_arg.m_actnum && + full_arg.cell_volume == rst_arg.cell_volume && + full_arg.cell_depth == rst_arg.cell_depth && + full_arg.m_default_region == rst_arg.m_default_region && + full_arg.m_rtep == rst_arg.m_rtep && + full_arg.tables == rst_arg.tables && + full_arg.multregp == rst_arg.multregp && + full_arg.tran == rst_arg.tran; } @@ -1110,7 +1206,7 @@ void FieldProps::init_satfunc(const std::string& keyword, Fieldprops::FieldData< ? this->get("IMBNUM") : this->get("SATNUM"); - satfunc.default_update(satfunc::init(keyword, this->tables, this->m_phases, *this->m_rtep, this->cell_depth, satreg, endnum)); + satfunc.default_update(satfunc::init(keyword, this->tables, this->m_phases, this->m_rtep.value(), this->cell_depth, satreg, endnum)); } diff --git a/src/opm/parser/eclipse/EclipseState/Grid/FieldProps.hpp b/src/opm/parser/eclipse/EclipseState/Grid/FieldProps.hpp index e9b519dfc..bdd3c090e 100644 --- a/src/opm/parser/eclipse/EclipseState/Grid/FieldProps.hpp +++ b/src/opm/parser/eclipse/EclipseState/Grid/FieldProps.hpp @@ -291,6 +291,12 @@ public: region_name(rn) {} + + bool operator==(const MultregpRecord& other) const { + return this->region_value == other.region_value && + this->multiplier == other.multiplier && + this->region_name == other.region_name; + } }; @@ -478,6 +484,8 @@ public: void apply_tran(const std::string& keyword, std::vector& data); std::vector serialize_tran() const; void deserialize_tran(const std::vector& buffer); + bool operator==(const FieldProps& other) const; + static bool rst_cmp(const FieldProps& full_arg, const FieldProps& rst_arg); private: void scanGRIDSection(const GRIDSection& grid_section); void scanEDITSection(const EDITSection& edit_section); diff --git a/src/opm/parser/eclipse/EclipseState/Grid/FieldPropsManager.cpp b/src/opm/parser/eclipse/EclipseState/Grid/FieldPropsManager.cpp index a2cb4e792..6dbafb024 100644 --- a/src/opm/parser/eclipse/EclipseState/Grid/FieldPropsManager.cpp +++ b/src/opm/parser/eclipse/EclipseState/Grid/FieldPropsManager.cpp @@ -29,6 +29,15 @@ namespace Opm { + +bool FieldPropsManager::operator==(const FieldPropsManager& other) const { + return *this->fp == *other.fp; +} + +bool FieldPropsManager::rst_cmp(const FieldPropsManager& full_arg, const FieldPropsManager& rst_arg) { + return FieldProps::rst_cmp(*full_arg.fp, *rst_arg.fp); +} + FieldPropsManager::FieldPropsManager(const Deck& deck, const Phases& phases, const EclipseGrid& grid_arg, const TableManager& tables) : fp(std::make_shared(deck, phases, grid_arg, tables)) {} diff --git a/tests/parser/FieldPropsTests.cpp b/tests/parser/FieldPropsTests.cpp index e99273a81..865044db0 100644 --- a/tests/parser/FieldPropsTests.cpp +++ b/tests/parser/FieldPropsTests.cpp @@ -2529,7 +2529,7 @@ COPYREG BOOST_CHECK_CLOSE(to_si(multn[g]), permx[g], 1e-5); BOOST_CHECK_EQUAL(permx[g], permy[g]); } - + BOOST_CHECK(permx == fp.get_double("PERMR")); BOOST_CHECK(permy == fp.get_double("PERMTHT")); } @@ -2572,7 +2572,8 @@ COPYREG auto to_si = [&unit_system](double raw_value) { return unit_system.to_si(UnitSystem::measure::permeability, raw_value); }; EclipseGrid grid(10,10, 2); Deck deck1 = Parser{}.parseString(deck_string1); - FieldPropsManager fp(deck1, Phases{true, true, true}, grid, TableManager()); + TableManager tables; + FieldPropsManager fp(deck1, Phases{true, true, true}, grid, tables); const auto& permx = fp.get_double("PERMX"); const auto& permy = fp.get_double("PERMY"); const auto& multn = fp.get_int("MULTNUM"); @@ -2582,5 +2583,20 @@ COPYREG } BOOST_CHECK(permx == fp.get_double("PERMR")); - BOOST_CHECK(permy == fp.get_double("PERMTHT")); + BOOST_CHECK(permy == fp.get_double("PERMTHT")); + + FieldPropsManager fp2(deck1, Phases{true, true, true}, grid, tables); + BOOST_CHECK( fp == fp2 ); + BOOST_CHECK( FieldPropsManager::rst_cmp(fp, fp2) ); + + + const auto& ntg = fp2.get_double("NTG"); + BOOST_CHECK( !(fp == fp2) ); + BOOST_CHECK( FieldPropsManager::rst_cmp(fp, fp2) ); + (void) ntg; + + const auto& satnum = fp.get_int("SATNUM"); + BOOST_CHECK( !(fp == fp2) ); + BOOST_CHECK( FieldPropsManager::rst_cmp(fp, fp2) ); + (void) satnum; }