From c693f0f50cb393381dbc22e1c3f034afb1c28efc Mon Sep 17 00:00:00 2001 From: Markus Blatt Date: Fri, 31 Mar 2023 20:11:12 +0200 Subject: [PATCH] Refactor applyEditNncToGridTrans for better reuse with EDINNCR. --- ebos/ecltransmissibility.cc | 42 +++++++++++++++++++++++++------------ ebos/ecltransmissibility.hh | 6 ++++++ 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/ebos/ecltransmissibility.cc b/ebos/ecltransmissibility.cc index 7c806f134..811986b43 100644 --- a/ebos/ecltransmissibility.cc +++ b/ebos/ecltransmissibility.cc @@ -36,6 +36,7 @@ #include "alucartesianindexmapper.hh" #endif // HAVE_DUNE_ALUGRID +#include #include #include #include @@ -888,9 +889,24 @@ template:: applyEditNncToGridTrans_(const std::unordered_map& globalToLocal) { - const auto& nnc_input = eclState_.getInputNNC(); - const auto& editNnc = nnc_input.edit(); - if (editNnc.empty()) + const auto& input = eclState_.getInputNNC(); + applyEditNncToGridTransHelper_(globalToLocal, "EDITNNC", + input.edit(), + [&input](const NNCdata& nnc){ + return input.edit_location(nnc);}, + // Multiply transmissibility with EDITNNC value + [](double& trans, const double& rhs){ trans *= rhs;}); +} + +template +void EclTransmissibility:: +applyEditNncToGridTransHelper_(const std::unordered_map& globalToLocal, + const std::string& keyword, + const std::vector& nncs, + const std::function& getLocation, + const std::function& apply) +{ + if (nncs.empty()) return; const auto& cartDims = cartMapper_.cartesianDimensions(); @@ -902,20 +918,20 @@ applyEditNncToGridTrans_(const std::unordered_map& globalToLoca return fmt::format("({},{},{})", i + 1,j + 1,k + 1); }; - auto print_warning = [&format_ijk, &nnc_input] (const NNCdata& nnc) { - const auto& location = nnc_input.edit_location( nnc ); - auto warning = fmt::format("Problem with EDITNNC keyword\n" + auto print_warning = [&format_ijk, &nncs, &getLocation, &keyword] (const NNCdata& nnc) { + const auto& location = getLocation( nnc ); + auto warning = fmt::format("Problem with {} keyword\n" "In {} line {} \n" - "No NNC defined for connection {} -> {}", location.filename, + "No NNC defined for connection {} -> {}", keyword, location.filename, location.lineno, format_ijk(nnc.cell1), format_ijk(nnc.cell2)); - OpmLog::warning("EDITNNC", warning); + OpmLog::warning(keyword, warning); }; // editNnc is supposed to only reference non-neighboring connections and not // neighboring connections. Use all entries for scaling if there is an NNC. // variable nnc incremented in loop body. - auto nnc = editNnc.begin(); - auto end = editNnc.end(); + auto nnc = nncs.begin(); + auto end = nncs.end(); std::size_t warning_count = 0; while (nnc != end) { auto c1 = nnc->cell1; @@ -944,15 +960,15 @@ applyEditNncToGridTrans_(const std::unordered_map& globalToLoca else { // NNC exists while (nnc!= end && c1==nnc->cell1 && c2==nnc->cell2) { - candidate->second *= nnc->trans; + apply(candidate->second, nnc->trans); ++nnc; } } } if (warning_count > 0) { - auto warning = fmt::format("Problems with EDITNNC keyword\n" - "A total of {} connections not defined in grid", warning_count); + auto warning = fmt::format("Problems with {} keyword\n" + "A total of {} connections not defined in grid", keyword, warning_count); OpmLog::warning(warning); } } diff --git a/ebos/ecltransmissibility.hh b/ebos/ecltransmissibility.hh index 2ad04dee2..e04d58cf8 100644 --- a/ebos/ecltransmissibility.hh +++ b/ebos/ecltransmissibility.hh @@ -42,6 +42,7 @@ namespace Opm { +class KeywordLocation; class EclipseState; struct NNCdata; class TransMult; @@ -200,6 +201,11 @@ protected: /// \brief Multiplies the grid transmissibilities according to EDITNNC. void applyEditNncToGridTrans_(const std::unordered_map& globalToLocal); + void applyEditNncToGridTransHelper_(const std::unordered_map& globalToLocal, + const std::string& keyword, const std::vector& nncs, + const std::function& getLocation, + const std::function& apply); + void extractPermeability_(); void extractPermeability_(const std::function& map);