From 42fcb4507f95d6f47c93e4d131e7f11043f7fa6e Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Fri, 4 Sep 2020 13:14:45 +0200 Subject: [PATCH] FieldProps::get_global will fill with correct default value --- .../EclipseState/Grid/FieldPropsManager.hpp | 4 +-- .../eclipse/EclipseState/Grid/FieldProps.cpp | 10 ++---- .../eclipse/EclipseState/Grid/FieldProps.hpp | 30 +++++++++-------- .../EclipseState/Grid/FieldPropsManager.cpp | 6 ++-- tests/parser/FieldPropsTests.cpp | 33 +++++++++++++++++-- 5 files changed, 55 insertions(+), 28 deletions(-) diff --git a/opm/parser/eclipse/EclipseState/Grid/FieldPropsManager.hpp b/opm/parser/eclipse/EclipseState/Grid/FieldPropsManager.hpp index 0cdfd6c6f..b82e1d7eb 100644 --- a/opm/parser/eclipse/EclipseState/Grid/FieldPropsManager.hpp +++ b/opm/parser/eclipse/EclipseState/Grid/FieldPropsManager.hpp @@ -217,8 +217,8 @@ private: /* This is exactly like the get() method, but the returned vector will have - global cartesian size, where all inactive cells have been filled with - zeros. + global cartesian size. If the field has a default value that value will be + used for filling in in the inactive cells, otherwise zero is used. */ template std::vector get_global(const std::string& keyword) const; diff --git a/src/opm/parser/eclipse/EclipseState/Grid/FieldProps.cpp b/src/opm/parser/eclipse/EclipseState/Grid/FieldProps.cpp index 4cf96db27..c5e5ddb3c 100644 --- a/src/opm/parser/eclipse/EclipseState/Grid/FieldProps.cpp +++ b/src/opm/parser/eclipse/EclipseState/Grid/FieldProps.cpp @@ -404,7 +404,7 @@ void FieldProps::reset_actnum(const std::vector& new_actnum) { void FieldProps::distribute_toplayer(FieldProps::FieldData& field_data, const std::vector& deck_data, const Box& box) { const std::size_t layer_size = this->nx * this->ny; - FieldProps::FieldData toplayer(layer_size); + FieldProps::FieldData toplayer(field_data.kw_info, layer_size); for (const auto& cell_index : box.index_list()) { if (cell_index.global_index < layer_size) { toplayer.data[cell_index.global_index] = deck_data[cell_index.data_index]; @@ -474,10 +474,8 @@ FieldProps::FieldData& FieldProps::init_get(const std::string& keyword) if (iter != this->double_data.end()) return iter->second; - this->double_data[keyword] = FieldData(this->active_size); const keywords::keyword_info& kw_info = keywords::global_kw_info(keyword); - if (kw_info.scalar_init) - this->double_data[keyword].default_assign(*kw_info.scalar_init); + this->double_data[keyword] = FieldData(kw_info, this->active_size); if (keyword == ParserKeywords::PORV::keywordName) this->init_porv(this->double_data[keyword]); @@ -500,14 +498,12 @@ FieldProps::FieldData& FieldProps::init_get(const std::string& keyword) { if (iter != this->int_data.end()) return iter->second; - this->int_data[keyword] = FieldData(this->active_size); if (keywords::isFipxxx(keyword)) { int default_value = 1; this->int_data[keyword].default_assign(default_value); } else { const keywords::keyword_info& kw_info = keywords::global_kw_info(keyword); - if (kw_info.scalar_init) - this->int_data[keyword].default_assign(*kw_info.scalar_init); + this->int_data[keyword] = FieldData(kw_info, this->active_size); } diff --git a/src/opm/parser/eclipse/EclipseState/Grid/FieldProps.hpp b/src/opm/parser/eclipse/EclipseState/Grid/FieldProps.hpp index 2a25738cc..7d244aa36 100644 --- a/src/opm/parser/eclipse/EclipseState/Grid/FieldProps.hpp +++ b/src/opm/parser/eclipse/EclipseState/Grid/FieldProps.hpp @@ -289,15 +289,19 @@ public: struct FieldData { std::vector data; std::vector value_status; + keywords::keyword_info kw_info; mutable bool all_set; FieldData() = default; - FieldData(std::size_t active_size) : + FieldData(const keywords::keyword_info& info, std::size_t active_size) : data(std::vector(active_size)), value_status(active_size, value::status::uninitialized), + kw_info(info), all_set(false) { + if (info.scalar_init) + this->default_assign( *info.scalar_init ); } @@ -461,27 +465,26 @@ public: std::vector get_global(const std::string& keyword) { const auto& managed_field_data = this->try_get(keyword); const auto& field_data = managed_field_data.field_data(); - if (field_data.global_data) - return *field_data.global_data; - else - return this->global_copy(field_data.data); + const auto& kw_info = keywords::global_kw_info(keyword); + return this->global_copy(field_data.data, kw_info.scalar_init); } template std::vector get_copy(const std::string& keyword, bool global) { bool has0 = this->has(keyword); - const auto& data = this->get(keyword); + const auto& field_data = this->try_get(keyword).field_data(); if (has0) { if (global) - return this->global_copy(data); + return this->global_copy(field_data.data, field_data.kw_info.scalar_init); else - return data; + return field_data.data; } else { - if (global) - return this->global_copy(this->extract(keyword)); - else + if (global) { + const auto& kw_info = keywords::global_kw_info(keyword); + return this->global_copy(this->extract(keyword), kw_info.scalar_init); + } else return this->extract(keyword); } } @@ -500,8 +503,9 @@ public: template - std::vector global_copy(const std::vector& data) const { - std::vector global_data(this->global_size); + std::vector global_copy(const std::vector& data, const std::optional& default_value) const { + T fill_value = default_value.has_value() ? *default_value : 0; + std::vector global_data(this->global_size, fill_value); std::size_t i = 0; for (std::size_t g = 0; g < this->global_size; g++) { if (this->m_actnum[g]) { diff --git a/src/opm/parser/eclipse/EclipseState/Grid/FieldPropsManager.cpp b/src/opm/parser/eclipse/EclipseState/Grid/FieldPropsManager.cpp index 5e4c8703d..0089987c0 100644 --- a/src/opm/parser/eclipse/EclipseState/Grid/FieldPropsManager.cpp +++ b/src/opm/parser/eclipse/EclipseState/Grid/FieldPropsManager.cpp @@ -98,11 +98,11 @@ std::vector FieldPropsManager::actnum() const { } std::vector FieldPropsManager::porv(bool global) const { - const auto& data = this->get("PORV"); + const auto& field_data = this->fp->try_get("PORV").field_data(); if (global) - return this->fp->global_copy(data); + return this->fp->global_copy(field_data.data, field_data.kw_info.scalar_init); else - return data; + return field_data.data; } std::size_t FieldPropsManager::active_size() const { diff --git a/tests/parser/FieldPropsTests.cpp b/tests/parser/FieldPropsTests.cpp index aa2b64d0f..cdb6df67a 100644 --- a/tests/parser/FieldPropsTests.cpp +++ b/tests/parser/FieldPropsTests.cpp @@ -208,7 +208,7 @@ ADDREG BOOST_AUTO_TEST_CASE(ASSIGN) { - FieldProps::FieldData data(100); + FieldProps::FieldData data({}, 100); std::vector wrong_size(50); BOOST_CHECK_THROW( data.default_assign( wrong_size ), std::invalid_argument ); @@ -221,8 +221,7 @@ BOOST_AUTO_TEST_CASE(ASSIGN) { BOOST_CHECK(data.data == ext_data); } - -BOOST_AUTO_TEST_CASE(Defaulted) { +BOOST_AUTO_TEST_CASE(Defaulted1) { std::string deck_string = R"( GRID @@ -249,6 +248,34 @@ NTG } } +BOOST_AUTO_TEST_CASE(Defaulted2) { + std::string deck_string = R"( +GRID + +BOX + 1 10 1 10 1 1 / + +NTG + 100*2 / + +)"; + + std::vector actnum(150, 1); + { + for (std::size_t i = 0; i < 50; i++) + actnum.push_back(0); + } + EclipseGrid grid(EclipseGrid(10,10, 2), actnum); + Deck deck = Parser{}.parseString(deck_string); + FieldPropsManager fpm(deck, Phases{true, true, true}, grid, TableManager()); + const auto& ntg = fpm.get_global_double("NTG"); + + for (std::size_t g=0; g < 100; g++) { + BOOST_CHECK_EQUAL(ntg[g], 2); + BOOST_CHECK_EQUAL(ntg[g + 100], 1); + } +} + BOOST_AUTO_TEST_CASE(PORV) { std::string deck_string = R"( GRID