From 99368d73d256664be90a349a3c0a6c4df41fdb33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A5rd=20Skaflestad?= Date: Wed, 2 Sep 2015 10:36:07 +0200 Subject: [PATCH] RegionMapping<>: Support arbitrary region IDs This commit introduces a new public method, activeRegions(), that retrieves those region IDs that contain at least one active cell. We furthermore extend the cells() method to support lookup of arbitrary region IDs. Non-active region IDs produce empty cell ranges. Intended use case is for (const auto& reg : rmap.activeRegions()) { const auto& c = rmap.cells(reg); // use c } --- opm/core/simulator/initStateEquil.hpp | 9 +++------ tests/test_equil.cpp | 17 +++++++---------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/opm/core/simulator/initStateEquil.hpp b/opm/core/simulator/initStateEquil.hpp index ac398b1a9..dc0071003 100644 --- a/opm/core/simulator/initStateEquil.hpp +++ b/opm/core/simulator/initStateEquil.hpp @@ -399,13 +399,10 @@ namespace Opm const Grid& G , const double grav) { - for (typename RMap::RegionId - r = 0, nr = reg.numRegions(); - r < nr; ++r) - { - const typename RMap::CellRange cells = reg.cells(r); - + for (const auto& r : reg.activeRegions()) { + const auto& cells = reg.cells(r); const int repcell = *cells.begin(); + const RhoCalc calc(props, repcell); const EqReg eqreg(rec[r], calc, rs_func_[r], rv_func_[r], diff --git a/tests/test_equil.cpp b/tests/test_equil.cpp index b029f5276..d7436195a 100644 --- a/tests/test_equil.cpp +++ b/tests/test_equil.cpp @@ -307,10 +307,8 @@ BOOST_AUTO_TEST_CASE (RegMapping) Opm::RegionMapping<> eqlmap(eqlnum); PPress ppress(2, PVal(G->number_of_cells, 0)); - for (int r = 0, e = eqlmap.numRegions(); r != e; ++r) - { - const Opm::RegionMapping<>::CellRange& - rng = eqlmap.cells(r); + for (const auto& r : eqlmap.activeRegions()) { + const auto& rng = eqlmap.cells(r); const int rno = r; const double grav = 10; @@ -318,14 +316,13 @@ BOOST_AUTO_TEST_CASE (RegMapping) Opm::Equil::phasePressures(*G, region[rno], rng, grav); PVal::size_type i = 0; - for (Opm::RegionMapping<>::CellRange::const_iterator - c = rng.begin(), ce = rng.end(); - c != ce; ++c, ++i) - { + for (const auto& c : rng) { assert (i < p[0].size()); - ppress[0][*c] = p[0][i]; - ppress[1][*c] = p[1][i]; + ppress[0][c] = p[0][i]; + ppress[1][c] = p[1][i]; + + ++i; } }